@copilotkit/react-core 0.25.0-mme-cloud.4 → 0.25.0-multi-feature-usecopilotreadable.3
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 +237 -216
- package/CHANGELOG.md +12 -23
- package/dist/{chunk-CGT3AVYT.mjs → chunk-3WKJ25L3.mjs} +3 -3
- package/dist/chunk-3WKJ25L3.mjs.map +1 -0
- package/dist/chunk-5L5PJJNT.mjs +28 -0
- package/dist/chunk-5L5PJJNT.mjs.map +1 -0
- package/dist/{chunk-IR5I4Q6R.mjs → chunk-75RLNHDB.mjs} +5 -5
- package/dist/chunk-75RLNHDB.mjs.map +1 -0
- package/dist/{chunk-SFV4PSJM.mjs → chunk-BCKOSVRB.mjs} +7 -11
- package/dist/chunk-BCKOSVRB.mjs.map +1 -0
- package/dist/{chunk-6ARSX7BW.mjs → chunk-BGB5G33N.mjs} +2 -2
- package/dist/{chunk-NQKBX6UJ.mjs → chunk-EABGYUTZ.mjs} +2 -2
- package/dist/chunk-EABGYUTZ.mjs.map +1 -0
- package/dist/chunk-EYKDJBDE.mjs +1 -0
- package/dist/chunk-F2JIAPZQ.mjs +14 -0
- package/dist/chunk-F2JIAPZQ.mjs.map +1 -0
- package/dist/{chunk-DW3HRHJB.mjs → chunk-FCEPEM4B.mjs} +3 -3
- package/dist/{chunk-VYD7RO32.mjs → chunk-H3FQWB4B.mjs} +13 -44
- package/dist/chunk-H3FQWB4B.mjs.map +1 -0
- package/dist/{chunk-PC6FY3LD.mjs → chunk-H6V2C2AN.mjs} +2 -2
- package/dist/chunk-ISKBWE4O.mjs +13 -0
- package/dist/chunk-ISKBWE4O.mjs.map +1 -0
- package/dist/{chunk-O35YOIHC.mjs → chunk-KIKHLN4X.mjs} +1 -3
- package/dist/chunk-KIKHLN4X.mjs.map +1 -0
- package/dist/{chunk-UNYZRMB2.mjs → chunk-L45P674M.mjs} +6 -6
- package/dist/chunk-L45P674M.mjs.map +1 -0
- package/dist/{chunk-MESZST5T.mjs → chunk-X3FZ6GTK.mjs} +16 -8
- package/dist/chunk-X3FZ6GTK.mjs.map +1 -0
- package/dist/components/copilot-provider/copilotkit-props.d.ts +1 -12
- package/dist/components/copilot-provider/copilotkit-props.js.map +1 -1
- package/dist/components/copilot-provider/copilotkit.d.ts +17 -0
- package/dist/components/copilot-provider/copilotkit.js +17 -40
- package/dist/components/copilot-provider/copilotkit.js.map +1 -1
- package/dist/components/copilot-provider/copilotkit.mjs +3 -2
- package/dist/components/copilot-provider/index.js +17 -40
- package/dist/components/copilot-provider/index.js.map +1 -1
- package/dist/components/copilot-provider/index.mjs +3 -2
- package/dist/components/copilot-provider/standard-copilot-api-config.d.ts +23 -0
- package/dist/components/copilot-provider/standard-copilot-api-config.js +38 -0
- package/dist/components/copilot-provider/standard-copilot-api-config.js.map +1 -0
- package/dist/components/copilot-provider/standard-copilot-api-config.mjs +8 -0
- package/dist/components/copilot-provider/standard-copilot-api-config.mjs.map +1 -0
- package/dist/components/index.js +17 -40
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +3 -2
- package/dist/context/copilot-context.d.ts +1 -11
- package/dist/context/copilot-context.js +0 -2
- package/dist/context/copilot-context.js.map +1 -1
- package/dist/context/copilot-context.mjs +1 -1
- package/dist/context/index.js +0 -2
- package/dist/context/index.js.map +1 -1
- package/dist/context/index.mjs +1 -1
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/index.js +47 -17
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +20 -14
- package/dist/hooks/use-chat.d.ts +2 -8
- package/dist/hooks/use-chat.js +15 -6
- package/dist/hooks/use-chat.js.map +1 -1
- package/dist/hooks/use-chat.mjs +2 -2
- package/dist/hooks/use-copilot-action-implementation.d.ts +7 -0
- package/dist/hooks/use-copilot-action-implementation.js +140 -0
- package/dist/hooks/use-copilot-action-implementation.js.map +1 -0
- package/dist/hooks/use-copilot-action-implementation.mjs +9 -0
- package/dist/hooks/use-copilot-action-implementation.mjs.map +1 -0
- package/dist/hooks/use-copilot-action.d.ts +1 -1
- package/dist/hooks/use-copilot-action.js +9 -4
- package/dist/hooks/use-copilot-action.js.map +1 -1
- package/dist/hooks/use-copilot-action.mjs +3 -2
- package/dist/hooks/use-copilot-chat.js +18 -15
- package/dist/hooks/use-copilot-chat.js.map +1 -1
- package/dist/hooks/use-copilot-chat.mjs +6 -5
- package/dist/hooks/use-copilot-readable.d.ts +33 -0
- package/dist/hooks/use-copilot-readable.js +121 -0
- package/dist/hooks/use-copilot-readable.js.map +1 -0
- package/dist/hooks/use-copilot-readable.mjs +9 -0
- package/dist/hooks/use-copilot-readable.mjs.map +1 -0
- package/dist/hooks/use-make-copilot-actionable.js +0 -2
- 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 +0 -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.d.ts +1 -5
- package/dist/hooks/use-make-copilot-readable.js +0 -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 +1 -0
- package/dist/index.js +75 -66
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +25 -19
- package/dist/lib/copilot-task.d.ts +7 -2
- package/dist/lib/copilot-task.js +5 -5
- package/dist/lib/copilot-task.js.map +1 -1
- package/dist/lib/copilot-task.mjs +5 -4
- package/dist/lib/index.js +5 -5
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +5 -4
- package/dist/openai-assistants/hooks/index.js +0 -2
- package/dist/openai-assistants/hooks/index.js.map +1 -1
- package/dist/openai-assistants/hooks/index.mjs +4 -3
- package/dist/openai-assistants/hooks/use-copilot-chat-v2.js +0 -2
- package/dist/openai-assistants/hooks/use-copilot-chat-v2.js.map +1 -1
- package/dist/openai-assistants/hooks/use-copilot-chat-v2.mjs +4 -3
- package/dist/openai-assistants/index.js +0 -2
- package/dist/openai-assistants/index.js.map +1 -1
- package/dist/openai-assistants/index.mjs +4 -3
- package/dist/utils/fetch-chat-completion.js +2 -2
- package/dist/utils/fetch-chat-completion.js.map +1 -1
- package/dist/utils/fetch-chat-completion.mjs +1 -1
- package/package.json +4 -4
- package/src/components/copilot-provider/copilotkit-props.tsx +1 -14
- package/src/components/copilot-provider/copilotkit.tsx +25 -47
- package/src/components/copilot-provider/standard-copilot-api-config.tsx +28 -0
- package/src/context/copilot-context.tsx +1 -21
- package/src/hooks/index.ts +1 -0
- package/src/hooks/use-chat.ts +15 -16
- package/src/hooks/use-copilot-action-implementation.ts +60 -0
- package/src/hooks/use-copilot-action.ts +10 -58
- package/src/hooks/use-copilot-chat.ts +1 -5
- package/src/hooks/use-copilot-readable.ts +60 -0
- package/src/hooks/use-make-copilot-readable.ts +1 -5
- package/src/lib/copilot-task.ts +12 -5
- package/src/utils/fetch-chat-completion.ts +0 -1
- package/dist/chunk-CGT3AVYT.mjs.map +0 -1
- package/dist/chunk-IOP6JX34.mjs +0 -1
- package/dist/chunk-IR5I4Q6R.mjs.map +0 -1
- package/dist/chunk-MESZST5T.mjs.map +0 -1
- package/dist/chunk-NQKBX6UJ.mjs.map +0 -1
- package/dist/chunk-O35YOIHC.mjs.map +0 -1
- package/dist/chunk-SFV4PSJM.mjs.map +0 -1
- package/dist/chunk-UNYZRMB2.mjs.map +0 -1
- package/dist/chunk-VYD7RO32.mjs.map +0 -1
- /package/dist/{chunk-6ARSX7BW.mjs.map → chunk-BGB5G33N.mjs.map} +0 -0
- /package/dist/{chunk-IOP6JX34.mjs.map → chunk-EYKDJBDE.mjs.map} +0 -0
- /package/dist/{chunk-DW3HRHJB.mjs.map → chunk-FCEPEM4B.mjs.map} +0 -0
- /package/dist/{chunk-PC6FY3LD.mjs.map → chunk-H6V2C2AN.mjs.map} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -71,8 +71,6 @@ var emptyCopilotContext = {
|
|
|
71
71
|
addContext: () => "",
|
|
72
72
|
removeContext: () => {
|
|
73
73
|
},
|
|
74
|
-
messages: [],
|
|
75
|
-
setMessages: () => returnAndThrowInDebug([]),
|
|
76
74
|
getDocumentsContext: (categories) => returnAndThrowInDebug([]),
|
|
77
75
|
addDocumentContext: () => returnAndThrowInDebug(""),
|
|
78
76
|
removeDocumentContext: () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/hooks/use-make-copilot-actionable.ts","../../src/context/copilot-context.tsx"],"sourcesContent":["import { useRef, useContext, useEffect, useMemo } from \"react\";\nimport { CopilotContext } from \"../context/copilot-context\";\nimport { AnnotatedFunction } from \"@copilotkit/shared\";\nimport { nanoid } from \"nanoid\";\nimport { annotatedFunctionToAction } from \"@copilotkit/shared\";\n\n/**\n * @deprecated Use the useCopilotAction function instead.\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 const action = annotatedFunctionToAction(memoizedAnnotatedFunction as AnnotatedFunction<any[]>);\n setEntryPoint(idRef.current, action);\n\n return () => {\n removeEntryPoint(idRef.current);\n };\n }, [memoizedAnnotatedFunction, setEntryPoint, removeEntryPoint]);\n}\n","import {
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/use-make-copilot-actionable.ts","../../src/context/copilot-context.tsx"],"sourcesContent":["import { useRef, useContext, useEffect, useMemo } from \"react\";\nimport { CopilotContext } from \"../context/copilot-context\";\nimport { AnnotatedFunction } from \"@copilotkit/shared\";\nimport { nanoid } from \"nanoid\";\nimport { annotatedFunctionToAction } from \"@copilotkit/shared\";\n\n/**\n * @deprecated Use the useCopilotAction function instead.\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 const action = annotatedFunctionToAction(memoizedAnnotatedFunction as AnnotatedFunction<any[]>);\n setEntryPoint(idRef.current, action);\n\n return () => {\n removeEntryPoint(idRef.current);\n };\n }, [memoizedAnnotatedFunction, setEntryPoint, removeEntryPoint]);\n}\n","import { FunctionCallHandler, ToolDefinition } from \"@copilotkit/shared\";\nimport { ActionRenderProps, FrontendAction } from \"../types/frontend-action\";\nimport React, { Ref } from \"react\";\nimport { TreeNodeId } from \"../hooks/use-tree\";\nimport { DocumentPointer } from \"../types\";\n\n/**\n * Interface for the configuration of the Copilot API.\n */\nexport interface CopilotApiConfig {\n /**\n * The endpoint for the chat API.\n */\n chatApiEndpoint: string;\n\n /**\n * The endpoint for the chat API v2.\n */\n chatApiEndpointV2: string;\n\n /**\n * additional headers to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'Authorization': 'Bearer your_token_here'\n * }\n * ```\n */\n headers: Record<string, string>;\n\n /**\n * Additional body params to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'message': 'Hello, world!'\n * }\n * ```\n */\n body: Record<string, any>;\n\n /**\n * Backend only props that will be combined to body params to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'user_id': 'user_id'\n * }\n * ```\n */\n backendOnlyProps?: Record<string, any>;\n}\n\nexport type InChatRenderFunction = (props: ActionRenderProps<any>) => string | JSX.Element;\n\nexport interface CopilotContextParams {\n // function-calling\n entryPoints: Record<string, FrontendAction<any>>;\n setEntryPoint: (id: string, entryPoint: FrontendAction<any>) => void;\n removeEntryPoint: (id: string) => void;\n chatComponentsCache: React.RefObject<Record<string, InChatRenderFunction | string>>;\n getChatCompletionFunctionDescriptions: (\n customEntryPoints?: Record<string, FrontendAction<any>>,\n ) => ToolDefinition[];\n getFunctionCallHandler: (\n customEntryPoints?: Record<string, FrontendAction<any>>,\n ) => FunctionCallHandler;\n\n // text context\n addContext: (context: string, parentId?: string, categories?: string[]) => TreeNodeId;\n removeContext: (id: TreeNodeId) => void;\n getContextString: (documents: DocumentPointer[], categories: string[]) => string;\n\n // document context\n addDocumentContext: (documentPointer: DocumentPointer, categories?: string[]) => TreeNodeId;\n removeDocumentContext: (documentId: string) => void;\n getDocumentsContext: (categories: string[]) => DocumentPointer[];\n\n // api endpoints\n copilotApiConfig: CopilotApiConfig;\n}\n\nconst emptyCopilotContext: CopilotContextParams = {\n entryPoints: {},\n setEntryPoint: () => {},\n removeEntryPoint: () => {},\n getChatCompletionFunctionDescriptions: () => returnAndThrowInDebug([]),\n getFunctionCallHandler: () => returnAndThrowInDebug(async () => {}),\n chatComponentsCache: { current: {} },\n getContextString: (documents: DocumentPointer[], categories: string[]) =>\n returnAndThrowInDebug(\"\"),\n addContext: () => \"\",\n removeContext: () => {},\n\n getDocumentsContext: (categories: string[]) => returnAndThrowInDebug([]),\n addDocumentContext: () => returnAndThrowInDebug(\"\"),\n removeDocumentContext: () => {},\n\n copilotApiConfig: new (class implements CopilotApiConfig {\n get chatApiEndpoint(): string {\n throw new Error(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n }\n get chatApiEndpointV2(): string {\n throw new Error(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n }\n get headers(): Record<string, string> {\n return {};\n }\n get body(): Record<string, any> {\n return {};\n }\n })(),\n};\n\nexport const CopilotContext = React.createContext<CopilotContextParams>(emptyCopilotContext);\n\nexport function useCopilotContext(): CopilotContextParams {\n return React.useContext(CopilotContext);\n}\n\nfunction returnAndThrowInDebug<T>(value: T): T {\n throw new Error(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n return value;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,gBAAuD;;;ACEvD,mBAA2B;AAoF3B,IAAM,sBAA4C;AAAA,EAChD,aAAa,CAAC;AAAA,EACd,eAAe,MAAM;AAAA,EAAC;AAAA,EACtB,kBAAkB,MAAM;AAAA,EAAC;AAAA,EACzB,uCAAuC,MAAM,sBAAsB,CAAC,CAAC;AAAA,EACrE,wBAAwB,MAAM,sBAAsB,MAAY;AAAA,EAAC,EAAC;AAAA,EAClE,qBAAqB,EAAE,SAAS,CAAC,EAAE;AAAA,EACnC,kBAAkB,CAAC,WAA8B,eAC/C,sBAAsB,EAAE;AAAA,EAC1B,YAAY,MAAM;AAAA,EAClB,eAAe,MAAM;AAAA,EAAC;AAAA,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;;;AD5HA,oBAAuB;AACvB,oBAA0C;AAKnC,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,UAAM,aAAS,yCAA0B,yBAAqD;AAC9F,kBAAc,MAAM,SAAS,MAAM;AAEnC,WAAO,MAAM;AACX,uBAAiB,MAAM,OAAO;AAAA,IAChC;AAAA,EACF,GAAG,CAAC,2BAA2B,eAAe,gBAAgB,CAAC;AACjE;","names":["import_react","React"]}
|
|
@@ -71,8 +71,6 @@ var emptyCopilotContext = {
|
|
|
71
71
|
addContext: () => "",
|
|
72
72
|
removeContext: () => {
|
|
73
73
|
},
|
|
74
|
-
messages: [],
|
|
75
|
-
setMessages: () => returnAndThrowInDebug([]),
|
|
76
74
|
getDocumentsContext: (categories) => returnAndThrowInDebug([]),
|
|
77
75
|
addDocumentContext: () => returnAndThrowInDebug(""),
|
|
78
76
|
removeDocumentContext: () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/hooks/use-make-copilot-document-readable.ts","../../src/context/copilot-context.tsx"],"sourcesContent":["import { useContext, useEffect, useRef } from \"react\";\nimport { CopilotContext } from \"../context/copilot-context\";\nimport { DocumentPointer } from \"../types\";\n\n/**\n * Makes a document readable by Copilot.\n * @param document The document to make readable.\n * @param categories The categories to associate with the document.\n * @param dependencies The dependencies to use for the effect.\n * @returns The id of the document.\n */\nexport function useMakeCopilotDocumentReadable(\n document: DocumentPointer,\n categories?: string[],\n dependencies: any[] = [],\n): string | undefined {\n const { addDocumentContext, removeDocumentContext } = useContext(CopilotContext);\n const idRef = useRef<string>();\n\n useEffect(() => {\n const id = addDocumentContext(document, categories);\n idRef.current = id;\n\n return () => {\n removeDocumentContext(id);\n };\n }, [addDocumentContext, removeDocumentContext, ...dependencies]);\n\n return idRef.current;\n}\n","import {
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/use-make-copilot-document-readable.ts","../../src/context/copilot-context.tsx"],"sourcesContent":["import { useContext, useEffect, useRef } from \"react\";\nimport { CopilotContext } from \"../context/copilot-context\";\nimport { DocumentPointer } from \"../types\";\n\n/**\n * Makes a document readable by Copilot.\n * @param document The document to make readable.\n * @param categories The categories to associate with the document.\n * @param dependencies The dependencies to use for the effect.\n * @returns The id of the document.\n */\nexport function useMakeCopilotDocumentReadable(\n document: DocumentPointer,\n categories?: string[],\n dependencies: any[] = [],\n): string | undefined {\n const { addDocumentContext, removeDocumentContext } = useContext(CopilotContext);\n const idRef = useRef<string>();\n\n useEffect(() => {\n const id = addDocumentContext(document, categories);\n idRef.current = id;\n\n return () => {\n removeDocumentContext(id);\n };\n }, [addDocumentContext, removeDocumentContext, ...dependencies]);\n\n return idRef.current;\n}\n","import { FunctionCallHandler, ToolDefinition } from \"@copilotkit/shared\";\nimport { ActionRenderProps, FrontendAction } from \"../types/frontend-action\";\nimport React, { Ref } from \"react\";\nimport { TreeNodeId } from \"../hooks/use-tree\";\nimport { DocumentPointer } from \"../types\";\n\n/**\n * Interface for the configuration of the Copilot API.\n */\nexport interface CopilotApiConfig {\n /**\n * The endpoint for the chat API.\n */\n chatApiEndpoint: string;\n\n /**\n * The endpoint for the chat API v2.\n */\n chatApiEndpointV2: string;\n\n /**\n * additional headers to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'Authorization': 'Bearer your_token_here'\n * }\n * ```\n */\n headers: Record<string, string>;\n\n /**\n * Additional body params to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'message': 'Hello, world!'\n * }\n * ```\n */\n body: Record<string, any>;\n\n /**\n * Backend only props that will be combined to body params to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'user_id': 'user_id'\n * }\n * ```\n */\n backendOnlyProps?: Record<string, any>;\n}\n\nexport type InChatRenderFunction = (props: ActionRenderProps<any>) => string | JSX.Element;\n\nexport interface CopilotContextParams {\n // function-calling\n entryPoints: Record<string, FrontendAction<any>>;\n setEntryPoint: (id: string, entryPoint: FrontendAction<any>) => void;\n removeEntryPoint: (id: string) => void;\n chatComponentsCache: React.RefObject<Record<string, InChatRenderFunction | string>>;\n getChatCompletionFunctionDescriptions: (\n customEntryPoints?: Record<string, FrontendAction<any>>,\n ) => ToolDefinition[];\n getFunctionCallHandler: (\n customEntryPoints?: Record<string, FrontendAction<any>>,\n ) => FunctionCallHandler;\n\n // text context\n addContext: (context: string, parentId?: string, categories?: string[]) => TreeNodeId;\n removeContext: (id: TreeNodeId) => void;\n getContextString: (documents: DocumentPointer[], categories: string[]) => string;\n\n // document context\n addDocumentContext: (documentPointer: DocumentPointer, categories?: string[]) => TreeNodeId;\n removeDocumentContext: (documentId: string) => void;\n getDocumentsContext: (categories: string[]) => DocumentPointer[];\n\n // api endpoints\n copilotApiConfig: CopilotApiConfig;\n}\n\nconst emptyCopilotContext: CopilotContextParams = {\n entryPoints: {},\n setEntryPoint: () => {},\n removeEntryPoint: () => {},\n getChatCompletionFunctionDescriptions: () => returnAndThrowInDebug([]),\n getFunctionCallHandler: () => returnAndThrowInDebug(async () => {}),\n chatComponentsCache: { current: {} },\n getContextString: (documents: DocumentPointer[], categories: string[]) =>\n returnAndThrowInDebug(\"\"),\n addContext: () => \"\",\n removeContext: () => {},\n\n getDocumentsContext: (categories: string[]) => returnAndThrowInDebug([]),\n addDocumentContext: () => returnAndThrowInDebug(\"\"),\n removeDocumentContext: () => {},\n\n copilotApiConfig: new (class implements CopilotApiConfig {\n get chatApiEndpoint(): string {\n throw new Error(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n }\n get chatApiEndpointV2(): string {\n throw new Error(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n }\n get headers(): Record<string, string> {\n return {};\n }\n get body(): Record<string, any> {\n return {};\n }\n })(),\n};\n\nexport const CopilotContext = React.createContext<CopilotContextParams>(emptyCopilotContext);\n\nexport function useCopilotContext(): CopilotContextParams {\n return React.useContext(CopilotContext);\n}\n\nfunction returnAndThrowInDebug<T>(value: T): T {\n throw new Error(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n return value;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,gBAA8C;;;ACE9C,mBAA2B;AAoF3B,IAAM,sBAA4C;AAAA,EAChD,aAAa,CAAC;AAAA,EACd,eAAe,MAAM;AAAA,EAAC;AAAA,EACtB,kBAAkB,MAAM;AAAA,EAAC;AAAA,EACzB,uCAAuC,MAAM,sBAAsB,CAAC,CAAC;AAAA,EACrE,wBAAwB,MAAM,sBAAsB,MAAY;AAAA,EAAC,EAAC;AAAA,EAClE,qBAAqB,EAAE,SAAS,CAAC,EAAE;AAAA,EACnC,kBAAkB,CAAC,WAA8B,eAC/C,sBAAsB,EAAE;AAAA,EAC1B,YAAY,MAAM;AAAA,EAClB,eAAe,MAAM;AAAA,EAAC;AAAA,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;;;ADpHO,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,9 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* @param information - The information to be added to the Copilot context.
|
|
4
|
-
* @param parentId - The ID of the parent context, if any.
|
|
5
|
-
* @param categories - An array of categories to control which context are visible where. Particularly useful with CopilotTextarea (see `useMakeAutosuggestionFunction`)
|
|
6
|
-
* @returns The ID of the added context.
|
|
2
|
+
* @deprecated Use the useCopilotReadable function instead.
|
|
7
3
|
*/
|
|
8
4
|
declare function useMakeCopilotReadable(information: string, parentId?: string, categories?: string[]): string | undefined;
|
|
9
5
|
|
|
@@ -71,8 +71,6 @@ var emptyCopilotContext = {
|
|
|
71
71
|
addContext: () => "",
|
|
72
72
|
removeContext: () => {
|
|
73
73
|
},
|
|
74
|
-
messages: [],
|
|
75
|
-
setMessages: () => returnAndThrowInDebug([]),
|
|
76
74
|
getDocumentsContext: (categories) => returnAndThrowInDebug([]),
|
|
77
75
|
addDocumentContext: () => returnAndThrowInDebug(""),
|
|
78
76
|
removeDocumentContext: () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/hooks/use-make-copilot-readable.ts","../../src/context/copilot-context.tsx"],"sourcesContent":["import { useContext, useEffect, useRef } from \"react\";\nimport { CopilotContext } from \"../context/copilot-context\";\n\n/**\n *
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/use-make-copilot-readable.ts","../../src/context/copilot-context.tsx"],"sourcesContent":["import { useContext, useEffect, useRef } from \"react\";\nimport { CopilotContext } from \"../context/copilot-context\";\n\n/**\n * @deprecated Use the useCopilotReadable function instead.\n */\nexport function useMakeCopilotReadable(\n information: string,\n parentId?: string,\n categories?: string[],\n): string | undefined {\n const { addContext, removeContext } = useContext(CopilotContext);\n const idRef = useRef<string>();\n\n useEffect(() => {\n const id = addContext(information, parentId, categories);\n idRef.current = id;\n\n return () => {\n removeContext(id);\n };\n }, [information, parentId, addContext, removeContext]);\n\n return idRef.current;\n}\n","import { FunctionCallHandler, ToolDefinition } from \"@copilotkit/shared\";\nimport { ActionRenderProps, FrontendAction } from \"../types/frontend-action\";\nimport React, { Ref } from \"react\";\nimport { TreeNodeId } from \"../hooks/use-tree\";\nimport { DocumentPointer } from \"../types\";\n\n/**\n * Interface for the configuration of the Copilot API.\n */\nexport interface CopilotApiConfig {\n /**\n * The endpoint for the chat API.\n */\n chatApiEndpoint: string;\n\n /**\n * The endpoint for the chat API v2.\n */\n chatApiEndpointV2: string;\n\n /**\n * additional headers to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'Authorization': 'Bearer your_token_here'\n * }\n * ```\n */\n headers: Record<string, string>;\n\n /**\n * Additional body params to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'message': 'Hello, world!'\n * }\n * ```\n */\n body: Record<string, any>;\n\n /**\n * Backend only props that will be combined to body params to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'user_id': 'user_id'\n * }\n * ```\n */\n backendOnlyProps?: Record<string, any>;\n}\n\nexport type InChatRenderFunction = (props: ActionRenderProps<any>) => string | JSX.Element;\n\nexport interface CopilotContextParams {\n // function-calling\n entryPoints: Record<string, FrontendAction<any>>;\n setEntryPoint: (id: string, entryPoint: FrontendAction<any>) => void;\n removeEntryPoint: (id: string) => void;\n chatComponentsCache: React.RefObject<Record<string, InChatRenderFunction | string>>;\n getChatCompletionFunctionDescriptions: (\n customEntryPoints?: Record<string, FrontendAction<any>>,\n ) => ToolDefinition[];\n getFunctionCallHandler: (\n customEntryPoints?: Record<string, FrontendAction<any>>,\n ) => FunctionCallHandler;\n\n // text context\n addContext: (context: string, parentId?: string, categories?: string[]) => TreeNodeId;\n removeContext: (id: TreeNodeId) => void;\n getContextString: (documents: DocumentPointer[], categories: string[]) => string;\n\n // document context\n addDocumentContext: (documentPointer: DocumentPointer, categories?: string[]) => TreeNodeId;\n removeDocumentContext: (documentId: string) => void;\n getDocumentsContext: (categories: string[]) => DocumentPointer[];\n\n // api endpoints\n copilotApiConfig: CopilotApiConfig;\n}\n\nconst emptyCopilotContext: CopilotContextParams = {\n entryPoints: {},\n setEntryPoint: () => {},\n removeEntryPoint: () => {},\n getChatCompletionFunctionDescriptions: () => returnAndThrowInDebug([]),\n getFunctionCallHandler: () => returnAndThrowInDebug(async () => {}),\n chatComponentsCache: { current: {} },\n getContextString: (documents: DocumentPointer[], categories: string[]) =>\n returnAndThrowInDebug(\"\"),\n addContext: () => \"\",\n removeContext: () => {},\n\n getDocumentsContext: (categories: string[]) => returnAndThrowInDebug([]),\n addDocumentContext: () => returnAndThrowInDebug(\"\"),\n removeDocumentContext: () => {},\n\n copilotApiConfig: new (class implements CopilotApiConfig {\n get chatApiEndpoint(): string {\n throw new Error(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n }\n get chatApiEndpointV2(): string {\n throw new Error(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n }\n get headers(): Record<string, string> {\n return {};\n }\n get body(): Record<string, any> {\n return {};\n }\n })(),\n};\n\nexport const CopilotContext = React.createContext<CopilotContextParams>(emptyCopilotContext);\n\nexport function useCopilotContext(): CopilotContextParams {\n return React.useContext(CopilotContext);\n}\n\nfunction returnAndThrowInDebug<T>(value: T): T {\n throw new Error(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n return value;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,gBAA8C;;;ACE9C,mBAA2B;AAoF3B,IAAM,sBAA4C;AAAA,EAChD,aAAa,CAAC;AAAA,EACd,eAAe,MAAM;AAAA,EAAC;AAAA,EACtB,kBAAkB,MAAM;AAAA,EAAC;AAAA,EACzB,uCAAuC,MAAM,sBAAsB,CAAC,CAAC;AAAA,EACrE,wBAAwB,MAAM,sBAAsB,MAAY;AAAA,EAAC,EAAC;AAAA,EAClE,qBAAqB,EAAE,SAAS,CAAC,EAAE;AAAA,EACnC,kBAAkB,CAAC,WAA8B,eAC/C,sBAAsB,EAAE;AAAA,EAC1B,YAAY,MAAM;AAAA,EAClB,eAAe,MAAM;AAAA,EAAC;AAAA,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;;;ADzHO,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
|
@@ -7,6 +7,7 @@ export { useCopilotAction } from './hooks/use-copilot-action.js';
|
|
|
7
7
|
export { useMakeCopilotReadable } from './hooks/use-make-copilot-readable.js';
|
|
8
8
|
export { useMakeCopilotDocumentReadable } from './hooks/use-make-copilot-document-readable.js';
|
|
9
9
|
export { UseChatHelpers } from './hooks/use-chat.js';
|
|
10
|
+
export { useCopilotReadable } from './hooks/use-copilot-readable.js';
|
|
10
11
|
export { DocumentPointer } from './types/document-pointer.js';
|
|
11
12
|
export { SystemMessageFunction } from './types/system-message.js';
|
|
12
13
|
export { ActionRenderProps, RenderFunctionStatus } from './types/frontend-action.js';
|
package/dist/index.js
CHANGED
|
@@ -92,6 +92,7 @@ __export(src_exports, {
|
|
|
92
92
|
useCopilotChat: () => useCopilotChat,
|
|
93
93
|
useCopilotChatV2: () => useCopilotChatV2,
|
|
94
94
|
useCopilotContext: () => useCopilotContext,
|
|
95
|
+
useCopilotReadable: () => useCopilotReadable,
|
|
95
96
|
useMakeCopilotActionable: () => useMakeCopilotActionable,
|
|
96
97
|
useMakeCopilotDocumentReadable: () => useMakeCopilotDocumentReadable,
|
|
97
98
|
useMakeCopilotReadable: () => useMakeCopilotReadable
|
|
@@ -117,8 +118,6 @@ var emptyCopilotContext = {
|
|
|
117
118
|
addContext: () => "",
|
|
118
119
|
removeContext: () => {
|
|
119
120
|
},
|
|
120
|
-
messages: [],
|
|
121
|
-
setMessages: () => returnAndThrowInDebug([]),
|
|
122
121
|
getDocumentsContext: (categories) => returnAndThrowInDebug([]),
|
|
123
122
|
addDocumentContext: () => returnAndThrowInDebug(""),
|
|
124
123
|
removeDocumentContext: () => {
|
|
@@ -347,19 +346,23 @@ function setsHaveIntersection2(setA, setB) {
|
|
|
347
346
|
return false;
|
|
348
347
|
}
|
|
349
348
|
|
|
349
|
+
// src/components/copilot-provider/standard-copilot-api-config.tsx
|
|
350
|
+
var StandardCopilotApiConfig = class {
|
|
351
|
+
constructor(chatApiEndpoint, chatApiEndpointV2, headers, body) {
|
|
352
|
+
this.chatApiEndpoint = chatApiEndpoint;
|
|
353
|
+
this.chatApiEndpointV2 = chatApiEndpointV2;
|
|
354
|
+
this.headers = headers;
|
|
355
|
+
this.body = body;
|
|
356
|
+
}
|
|
357
|
+
};
|
|
358
|
+
|
|
350
359
|
// src/components/copilot-provider/copilotkit.tsx
|
|
351
360
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
352
361
|
function CopilotKit(_a) {
|
|
353
362
|
var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
|
|
354
|
-
var _a2, _b2;
|
|
355
|
-
if (!props.url && !props.publicApiKey) {
|
|
356
|
-
throw new Error("Please provide either a url or a publicApiKey to the CopilotKit component.");
|
|
357
|
-
}
|
|
358
|
-
const chatApiEndpoint = props.url || import_shared.COPILOT_CLOUD_CHAT_URL;
|
|
359
363
|
const [entryPoints, setEntryPoints] = (0, import_react4.useState)({});
|
|
360
364
|
const chatComponentsCache = (0, import_react4.useRef)({});
|
|
361
365
|
const { addElement, removeElement, printTree } = use_tree_default();
|
|
362
|
-
const [messages, setMessages] = (0, import_react4.useState)([]);
|
|
363
366
|
const {
|
|
364
367
|
addElement: addDocument,
|
|
365
368
|
removeElement: removeDocument,
|
|
@@ -434,35 +437,12 @@ ${nonDocumentStrings}`;
|
|
|
434
437
|
},
|
|
435
438
|
[removeDocument]
|
|
436
439
|
);
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
}
|
|
444
|
-
let cloud = void 0;
|
|
445
|
-
if (props.publicApiKey) {
|
|
446
|
-
cloud = {
|
|
447
|
-
guardrails: {
|
|
448
|
-
input: {
|
|
449
|
-
restrictToTopic: {
|
|
450
|
-
enabled: props.cloudRestrictToTopic ? true : false,
|
|
451
|
-
validTopics: ((_a2 = props.cloudRestrictToTopic) == null ? void 0 : _a2.validTopics) || [],
|
|
452
|
-
invalidTopics: ((_b2 = props.cloudRestrictToTopic) == null ? void 0 : _b2.invalidTopics) || []
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
|
-
};
|
|
457
|
-
}
|
|
458
|
-
const copilotApiConfig = __spreadProps(__spreadValues({
|
|
459
|
-
publicApiKey: props.publicApiKey
|
|
460
|
-
}, cloud ? { cloud } : {}), {
|
|
461
|
-
chatApiEndpoint,
|
|
462
|
-
chatApiEndpointV2: `${props.url}/v2`,
|
|
463
|
-
headers: props.headers || {},
|
|
464
|
-
body: __spreadValues(__spreadValues({}, props.body), props.backendOnlyProps)
|
|
465
|
-
});
|
|
440
|
+
const copilotApiConfig = new StandardCopilotApiConfig(
|
|
441
|
+
props.url,
|
|
442
|
+
`${props.url}/v2`,
|
|
443
|
+
props.headers || {},
|
|
444
|
+
__spreadValues(__spreadValues({}, props.body), props.backendOnlyProps)
|
|
445
|
+
);
|
|
466
446
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
467
447
|
CopilotContext.Provider,
|
|
468
448
|
{
|
|
@@ -479,9 +459,7 @@ ${nonDocumentStrings}`;
|
|
|
479
459
|
getDocumentsContext,
|
|
480
460
|
addDocumentContext,
|
|
481
461
|
removeDocumentContext,
|
|
482
|
-
copilotApiConfig
|
|
483
|
-
messages,
|
|
484
|
-
setMessages
|
|
462
|
+
copilotApiConfig
|
|
485
463
|
},
|
|
486
464
|
children
|
|
487
465
|
}
|
|
@@ -540,11 +518,11 @@ function fetchChatCompletion(_0) {
|
|
|
540
518
|
headers: __spreadValues(__spreadValues({
|
|
541
519
|
"Content-Type": "application/json"
|
|
542
520
|
}, copilotConfig.headers), headers ? __spreadValues({}, headers) : {}),
|
|
543
|
-
body: JSON.stringify(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(
|
|
521
|
+
body: JSON.stringify(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({
|
|
544
522
|
model,
|
|
545
523
|
messages: cleanedMessages,
|
|
546
524
|
stream: true
|
|
547
|
-
}, tools.length ? { tools } : {}), temperature ? { temperature } : {}), tools.length != 0 ? { tool_choice: "auto" } : {}), copilotConfig.body), copilotConfig.backendOnlyProps), excludeBackendOnlyProps(copilotConfig)), body ? __spreadValues({}, body) : {})
|
|
525
|
+
}, tools.length ? { tools } : {}), temperature ? { temperature } : {}), tools.length != 0 ? { tool_choice: "auto" } : {}), copilotConfig.body), copilotConfig.backendOnlyProps), excludeBackendOnlyProps(copilotConfig)), body ? __spreadValues({}, body) : {})),
|
|
548
526
|
signal
|
|
549
527
|
});
|
|
550
528
|
return response;
|
|
@@ -591,14 +569,12 @@ function fetchAndDecodeChatCompletionAsText(params) {
|
|
|
591
569
|
// src/hooks/use-chat.ts
|
|
592
570
|
var import_untruncate_json = __toESM(require("untruncate-json"));
|
|
593
571
|
function useChat(options) {
|
|
594
|
-
const
|
|
572
|
+
const [messages, setMessages] = (0, import_react5.useState)([]);
|
|
595
573
|
const [input, setInput] = (0, import_react5.useState)("");
|
|
596
574
|
const [isLoading, setIsLoading] = (0, import_react5.useState)(false);
|
|
597
575
|
const abortControllerRef = (0, import_react5.useRef)();
|
|
598
576
|
const threadIdRef = (0, import_react5.useRef)(null);
|
|
599
577
|
const runIdRef = (0, import_react5.useRef)(null);
|
|
600
|
-
const publicApiKey = options.copilotConfig.publicApiKey;
|
|
601
|
-
const headers = __spreadValues(__spreadValues({}, options.headers || {}), publicApiKey ? { [import_shared3.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey } : {});
|
|
602
578
|
const runChatCompletion = (messages2) => __async(this, null, function* () {
|
|
603
579
|
setIsLoading(true);
|
|
604
580
|
const newMessages = [
|
|
@@ -624,7 +600,7 @@ function useChat(options) {
|
|
|
624
600
|
copilotConfig: __spreadProps(__spreadValues({}, options.copilotConfig), { body: copilotConfigBody }),
|
|
625
601
|
messages: messagesWithContext,
|
|
626
602
|
tools: options.tools,
|
|
627
|
-
headers,
|
|
603
|
+
headers: options.headers,
|
|
628
604
|
signal: abortController.signal
|
|
629
605
|
});
|
|
630
606
|
if (response.headers.get("threadid")) {
|
|
@@ -634,6 +610,16 @@ function useChat(options) {
|
|
|
634
610
|
runIdRef.current = response.headers.get("runid");
|
|
635
611
|
}
|
|
636
612
|
if (!response.events) {
|
|
613
|
+
setMessages([
|
|
614
|
+
...messages2,
|
|
615
|
+
{
|
|
616
|
+
id: (0, import_nanoid3.nanoid)(),
|
|
617
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
618
|
+
content: response.statusText,
|
|
619
|
+
role: "assistant"
|
|
620
|
+
}
|
|
621
|
+
]);
|
|
622
|
+
setIsLoading(false);
|
|
637
623
|
throw new Error("Failed to fetch chat completion");
|
|
638
624
|
}
|
|
639
625
|
const reader = response.events.getReader();
|
|
@@ -757,6 +743,7 @@ function useChat(options) {
|
|
|
757
743
|
(_a = abortControllerRef.current) == null ? void 0 : _a.abort();
|
|
758
744
|
};
|
|
759
745
|
return {
|
|
746
|
+
messages,
|
|
760
747
|
append,
|
|
761
748
|
reload,
|
|
762
749
|
stop,
|
|
@@ -779,9 +766,7 @@ function useCopilotChat(_a) {
|
|
|
779
766
|
getContextString,
|
|
780
767
|
getChatCompletionFunctionDescriptions,
|
|
781
768
|
getFunctionCallHandler,
|
|
782
|
-
copilotApiConfig
|
|
783
|
-
messages,
|
|
784
|
-
setMessages
|
|
769
|
+
copilotApiConfig
|
|
785
770
|
} = (0, import_react6.useContext)(CopilotContext);
|
|
786
771
|
const systemMessage = (0, import_react6.useMemo)(() => {
|
|
787
772
|
const systemMessageMaker = makeSystemMessage || defaultSystemMessage;
|
|
@@ -795,16 +780,14 @@ function useCopilotChat(_a) {
|
|
|
795
780
|
const functionDescriptions = (0, import_react6.useMemo)(() => {
|
|
796
781
|
return getChatCompletionFunctionDescriptions();
|
|
797
782
|
}, [getChatCompletionFunctionDescriptions]);
|
|
798
|
-
const { append, reload, stop, isLoading, input, setInput } = useChat(__spreadProps(__spreadValues({}, options), {
|
|
783
|
+
const { messages, append, reload, stop, isLoading, input, setInput } = useChat(__spreadProps(__spreadValues({}, options), {
|
|
799
784
|
copilotConfig: copilotApiConfig,
|
|
800
785
|
id: options.id,
|
|
801
786
|
initialMessages: [systemMessage].concat(options.initialMessages || []),
|
|
802
787
|
tools: functionDescriptions,
|
|
803
788
|
onFunctionCall: getFunctionCallHandler(),
|
|
804
789
|
headers: __spreadValues({}, options.headers),
|
|
805
|
-
body: __spreadValues({}, options.body)
|
|
806
|
-
messages,
|
|
807
|
-
setMessages
|
|
790
|
+
body: __spreadValues({}, options.body)
|
|
808
791
|
}));
|
|
809
792
|
const visibleMessages = messages.filter(
|
|
810
793
|
(message) => message.role === "user" || message.role === "assistant" || message.role === "function"
|
|
@@ -868,10 +851,10 @@ function useMakeCopilotActionable(annotatedFunction, dependencies) {
|
|
|
868
851
|
}, [memoizedAnnotatedFunction, setEntryPoint, removeEntryPoint]);
|
|
869
852
|
}
|
|
870
853
|
|
|
871
|
-
// src/hooks/use-copilot-action.ts
|
|
854
|
+
// src/hooks/use-copilot-action-implementation.ts
|
|
872
855
|
var import_react8 = require("react");
|
|
873
856
|
var import_nanoid5 = require("nanoid");
|
|
874
|
-
function
|
|
857
|
+
function useCopilotActionImplementation(action, dependencies) {
|
|
875
858
|
const { setEntryPoint, removeEntryPoint, entryPoints, chatComponentsCache } = (0, import_react8.useContext)(CopilotContext);
|
|
876
859
|
const idRef = (0, import_react8.useRef)((0, import_nanoid5.nanoid)());
|
|
877
860
|
if (dependencies === void 0) {
|
|
@@ -907,6 +890,11 @@ function useCopilotAction(action, dependencies) {
|
|
|
907
890
|
]);
|
|
908
891
|
}
|
|
909
892
|
|
|
893
|
+
// src/hooks/use-copilot-action.ts
|
|
894
|
+
function useCopilotAction(action, dependencies) {
|
|
895
|
+
return useCopilotActionImplementation(action, dependencies);
|
|
896
|
+
}
|
|
897
|
+
|
|
910
898
|
// src/hooks/use-make-copilot-readable.ts
|
|
911
899
|
var import_react9 = require("react");
|
|
912
900
|
function useMakeCopilotReadable(information, parentId, categories) {
|
|
@@ -937,8 +925,28 @@ function useMakeCopilotDocumentReadable(document, categories, dependencies = [])
|
|
|
937
925
|
return idRef.current;
|
|
938
926
|
}
|
|
939
927
|
|
|
940
|
-
// src/
|
|
928
|
+
// src/hooks/use-copilot-readable.ts
|
|
941
929
|
var import_react11 = require("react");
|
|
930
|
+
function convertToJSON(description, value) {
|
|
931
|
+
return `${description}: ${typeof value === "string" ? value : JSON.stringify(value)}`;
|
|
932
|
+
}
|
|
933
|
+
function useCopilotReadable({ description, value, parentId, categories, convert }, dependencies) {
|
|
934
|
+
const { addContext, removeContext } = (0, import_react11.useContext)(CopilotContext);
|
|
935
|
+
const idRef = (0, import_react11.useRef)();
|
|
936
|
+
convert = convert || convertToJSON;
|
|
937
|
+
const information = convert(description, value);
|
|
938
|
+
(0, import_react11.useEffect)(() => {
|
|
939
|
+
const id = addContext(information, parentId, categories);
|
|
940
|
+
idRef.current = id;
|
|
941
|
+
return () => {
|
|
942
|
+
removeContext(id);
|
|
943
|
+
};
|
|
944
|
+
}, [information, parentId, addContext, removeContext, ...dependencies || []]);
|
|
945
|
+
return idRef.current;
|
|
946
|
+
}
|
|
947
|
+
|
|
948
|
+
// src/openai-assistants/hooks/use-copilot-chat-v2.ts
|
|
949
|
+
var import_react12 = require("react");
|
|
942
950
|
|
|
943
951
|
// src/openai-assistants/utils/process-message-stream.ts
|
|
944
952
|
function processMessageStream(reader, processMessage) {
|
|
@@ -971,13 +979,13 @@ function useCopilotChatV2(options) {
|
|
|
971
979
|
getChatCompletionFunctionDescriptions,
|
|
972
980
|
getFunctionCallHandler,
|
|
973
981
|
copilotApiConfig
|
|
974
|
-
} = (0,
|
|
975
|
-
const [messages, setMessages] = (0,
|
|
976
|
-
const [input, setInput] = (0,
|
|
977
|
-
const [threadId, setThreadId] = (0,
|
|
978
|
-
const [status, setStatus] = (0,
|
|
979
|
-
const [error, setError] = (0,
|
|
980
|
-
const systemMessage = (0,
|
|
982
|
+
} = (0, import_react12.useContext)(CopilotContext);
|
|
983
|
+
const [messages, setMessages] = (0, import_react12.useState)([]);
|
|
984
|
+
const [input, setInput] = (0, import_react12.useState)("");
|
|
985
|
+
const [threadId, setThreadId] = (0, import_react12.useState)(void 0);
|
|
986
|
+
const [status, setStatus] = (0, import_react12.useState)("awaiting_message");
|
|
987
|
+
const [error, setError] = (0, import_react12.useState)(void 0);
|
|
988
|
+
const systemMessage = (0, import_react12.useMemo)(() => {
|
|
981
989
|
const systemMessageMaker = options.makeSystemMessage || defaultSystemMessage2;
|
|
982
990
|
const contextString = getContextString([], defaultCopilotContextCategories);
|
|
983
991
|
return {
|
|
@@ -1085,12 +1093,12 @@ var CopilotTask = class {
|
|
|
1085
1093
|
constructor(config) {
|
|
1086
1094
|
this.instructions = config.instructions;
|
|
1087
1095
|
this.actions = config.actions || [];
|
|
1088
|
-
this.includeCopilotReadable = config.includeCopilotReadable
|
|
1089
|
-
this.
|
|
1096
|
+
this.includeCopilotReadable = config.includeCopilotReadable !== false;
|
|
1097
|
+
this.includeCopilotActions = config.includeCopilotActions !== false && config.includeCopilotActionable !== false;
|
|
1090
1098
|
}
|
|
1091
1099
|
run(context, data) {
|
|
1092
1100
|
return __async(this, null, function* () {
|
|
1093
|
-
const entryPoints = this.
|
|
1101
|
+
const entryPoints = this.includeCopilotActions ? Object.assign({}, context.entryPoints) : {};
|
|
1094
1102
|
for (const fn of this.actions) {
|
|
1095
1103
|
entryPoints[fn.name] = fn;
|
|
1096
1104
|
}
|
|
@@ -1181,6 +1189,7 @@ ${instructions}
|
|
|
1181
1189
|
useCopilotChat,
|
|
1182
1190
|
useCopilotChatV2,
|
|
1183
1191
|
useCopilotContext,
|
|
1192
|
+
useCopilotReadable,
|
|
1184
1193
|
useMakeCopilotActionable,
|
|
1185
1194
|
useMakeCopilotDocumentReadable,
|
|
1186
1195
|
useMakeCopilotReadable
|