@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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/openai-assistants/index.ts","../../src/openai-assistants/hooks/use-copilot-chat-v2.ts","../../src/openai-assistants/utils/process-message-stream.ts","../../src/context/copilot-context.tsx","../../src/components/copilot-provider/copilotkit.tsx"],"sourcesContent":["export * from \"./hooks\";\nexport * from \"./utils\";\n","import { useContext, useMemo, useState } from \"react\";\nimport { processMessageStream } from \"../utils\";\nimport { Message, parseStreamPart } from \"@copilotkit/shared\";\nimport { CopilotContext } from \"../../context\";\nimport { defaultCopilotContextCategories } from \"../../components\";\n\nexport type AssistantStatus = \"in_progress\" | \"awaiting_message\";\n\nexport interface RequestForwardingOptions {\n /**\n * The credentials mode to be used for the fetch request.\n * Possible values are: 'omit', 'same-origin', 'include'.\n * Defaults to 'same-origin'.\n */\n credentials?: RequestCredentials;\n /**\n * HTTP headers to be sent with the API request.\n */\n headers?: Record<string, string> | Headers;\n /**\n * Extra body object to be sent with the API request.\n * @example\n * Send a `sessionId` to the API along with the messages.\n * ```js\n * useChat({\n * body: {\n * sessionId: '123',\n * }\n * })\n * ```\n */\n body?: object;\n}\nexport interface UseCopilotChatOptionsV2 extends RequestForwardingOptions {\n makeSystemMessage?: (contextString: string) => string;\n threadId?: string | undefined;\n}\n\nexport interface UseCopilotChatV2Result {\n messages: Message[];\n input: string;\n handleInputChange: (e: any) => void;\n submitMessage: (e: any) => Promise<void>;\n status: AssistantStatus;\n error: unknown;\n}\n\nexport function useCopilotChatV2(options: UseCopilotChatOptionsV2): UseCopilotChatV2Result {\n const {\n getContextString,\n getChatCompletionFunctionDescriptions,\n getFunctionCallHandler,\n copilotApiConfig,\n } = useContext(CopilotContext);\n\n const [messages, setMessages] = useState<Message[]>([]);\n const [input, setInput] = useState(\"\");\n const [threadId, setThreadId] = useState<string | undefined>(undefined);\n const [status, setStatus] = useState<AssistantStatus>(\"awaiting_message\");\n const [error, setError] = useState<unknown | undefined>(undefined);\n\n const systemMessage: Message = useMemo(() => {\n const systemMessageMaker = options.makeSystemMessage || defaultSystemMessage;\n const contextString = getContextString([], defaultCopilotContextCategories); // TODO: make the context categories configurable\n\n return {\n id: \"system\",\n content: systemMessageMaker(contextString),\n role: \"system\",\n };\n }, [getContextString, options.makeSystemMessage]);\n\n const handleInputChange = (e: any) => {\n setInput(e.target.value);\n };\n\n const submitMessage = async (e: any) => {\n e.preventDefault();\n\n if (input === \"\") {\n return;\n }\n\n setStatus(\"in_progress\");\n\n setMessages((messages) => [...messages, { id: \"\", role: \"user\", content: input }]);\n\n setInput(\"\");\n\n const apiUrl = copilotApiConfig.chatApiEndpointV2;\n\n const functions = getChatCompletionFunctionDescriptions();\n\n const result = await fetch(apiUrl, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n ...copilotApiConfig.headers,\n ...options.headers,\n },\n body: JSON.stringify({\n // always use user-provided threadId when available:\n threadId: options.threadId ?? threadId ?? null,\n message: input,\n ...(functions.length > 0 && { functions: functions }),\n ...copilotApiConfig.body,\n ...options.body,\n }),\n });\n\n if (result.body == null) {\n throw new Error(\"The response body is empty.\");\n }\n\n await processMessageStream(result.body.getReader(), (message: string) => {\n try {\n const { type, value } = parseStreamPart(message);\n\n switch (type) {\n case \"assistant_message\": {\n // append message:\n setMessages((messages) => [\n ...messages,\n {\n id: value.id,\n role: value.role,\n content: value.content[0].text.value,\n },\n ]);\n break;\n }\n\n case \"assistant_control_data\": {\n setThreadId(value.threadId);\n\n // set id of last message:\n setMessages((messages) => {\n const lastMessage = messages[messages.length - 1];\n lastMessage.id = value.messageId;\n return [...messages.slice(0, messages.length - 1), lastMessage];\n });\n\n break;\n }\n\n case \"error\": {\n setError(value);\n break;\n }\n }\n } catch (error) {\n setError(error);\n }\n });\n\n setStatus(\"awaiting_message\");\n };\n\n return {\n messages,\n input,\n handleInputChange,\n submitMessage,\n status,\n error,\n };\n}\n\nexport function defaultSystemMessage(contextString: string): string {\n return `\nPlease act as an efficient, competent, conscientious, and industrious professional assistant.\n\nHelp 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.\nAlways be polite and respectful, and prefer brevity over verbosity.\n\nThe user has provided you with the following context:\n\\`\\`\\`\n${contextString}\n\\`\\`\\`\n\nThey have also provided you with functions you can call to initiate actions on their behalf, or functions you can call to receive more information.\n\nPlease assist them as best you can.\n\nYou can ask them for clarifying questions if needed, but don't be annoying about it. If you can reasonably 'fill in the blanks' yourself, do so.\n\nIf you would like to call a function, call it without saying anything else.\n`;\n}\n","export async function processMessageStream(\n reader: ReadableStreamDefaultReader<Uint8Array>,\n processMessage: (message: string) => void | Promise<void>,\n) {\n const decoder = new TextDecoder();\n let buffer = \"\";\n while (true) {\n const { done, value } = await reader.read();\n\n if (done) {\n if (buffer.length > 0) {\n processMessage(buffer);\n }\n break;\n }\n\n buffer += decoder.decode(value, { stream: true });\n\n let endIndex: number;\n while ((endIndex = buffer.indexOf(\"\\n\")) !== -1) {\n processMessage(buffer.substring(0, endIndex).trim());\n buffer = buffer.substring(endIndex + 1); // Remove the processed instruction + delimiter\n }\n }\n}\n","import {\n CopilotCloudConfig,\n FunctionCallHandler,\n Message,\n ToolDefinition,\n} 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 public API key for Copilot Cloud.\n */\n publicApiKey?: string;\n\n /**\n * The configuration for Copilot Cloud.\n */\n cloud?: CopilotCloudConfig;\n\n /**\n * The endpoint for the chat API.\n */\n chatApiEndpoint: string;\n\n /**\n * The endpoint for the chat API v2.\n */\n chatApiEndpointV2: string;\n\n /**\n * additional headers to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'Authorization': 'Bearer your_token_here'\n * }\n * ```\n */\n headers: Record<string, string>;\n\n /**\n * Additional body params to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'message': 'Hello, world!'\n * }\n * ```\n */\n body: Record<string, any>;\n\n /**\n * Backend only props that will be combined to body params to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'user_id': 'user_id'\n * }\n * ```\n */\n backendOnlyProps?: Record<string, any>;\n}\n\nexport type InChatRenderFunction = (props: ActionRenderProps<any>) => string | JSX.Element;\n\nexport interface CopilotContextParams {\n // function-calling\n entryPoints: Record<string, FrontendAction<any>>;\n setEntryPoint: (id: string, entryPoint: FrontendAction<any>) => void;\n removeEntryPoint: (id: string) => void;\n chatComponentsCache: React.RefObject<Record<string, InChatRenderFunction | string>>;\n getChatCompletionFunctionDescriptions: (\n customEntryPoints?: Record<string, FrontendAction<any>>,\n ) => ToolDefinition[];\n getFunctionCallHandler: (\n customEntryPoints?: Record<string, FrontendAction<any>>,\n ) => FunctionCallHandler;\n\n messages: Message[];\n setMessages: React.Dispatch<React.SetStateAction<Message[]>>;\n\n // text context\n addContext: (context: string, parentId?: string, categories?: string[]) => TreeNodeId;\n removeContext: (id: TreeNodeId) => void;\n getContextString: (documents: DocumentPointer[], categories: string[]) => string;\n\n // document context\n addDocumentContext: (documentPointer: DocumentPointer, categories?: string[]) => TreeNodeId;\n removeDocumentContext: (documentId: string) => void;\n getDocumentsContext: (categories: string[]) => DocumentPointer[];\n\n // api endpoints\n copilotApiConfig: CopilotApiConfig;\n}\n\nconst emptyCopilotContext: CopilotContextParams = {\n entryPoints: {},\n setEntryPoint: () => {},\n removeEntryPoint: () => {},\n getChatCompletionFunctionDescriptions: () => returnAndThrowInDebug([]),\n getFunctionCallHandler: () => returnAndThrowInDebug(async () => {}),\n chatComponentsCache: { current: {} },\n getContextString: (documents: DocumentPointer[], categories: string[]) =>\n returnAndThrowInDebug(\"\"),\n addContext: () => \"\",\n removeContext: () => {},\n messages: [],\n setMessages: () => returnAndThrowInDebug([]),\n\n getDocumentsContext: (categories: string[]) => returnAndThrowInDebug([]),\n addDocumentContext: () => returnAndThrowInDebug(\"\"),\n removeDocumentContext: () => {},\n\n copilotApiConfig: new (class implements CopilotApiConfig {\n get chatApiEndpoint(): string {\n throw new Error(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n }\n get chatApiEndpointV2(): string {\n throw new Error(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n }\n get headers(): Record<string, string> {\n return {};\n }\n get body(): Record<string, any> {\n return {};\n }\n })(),\n};\n\nexport const CopilotContext = React.createContext<CopilotContextParams>(emptyCopilotContext);\n\nexport function useCopilotContext(): CopilotContextParams {\n return React.useContext(CopilotContext);\n}\n\nfunction returnAndThrowInDebug<T>(value: T): T {\n throw new Error(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n return value;\n}\n","import { Ref, useCallback, useRef, useState } from \"react\";\nimport {\n CopilotContext,\n CopilotApiConfig,\n InChatRenderFunction,\n} from \"../../context/copilot-context\";\nimport useTree from \"../../hooks/use-tree\";\nimport { DocumentPointer } from \"../../types\";\nimport {\n COPILOT_CLOUD_CHAT_URL,\n CopilotCloudConfig,\n FunctionCallHandler,\n Message,\n actionToChatCompletionFunction,\n} from \"@copilotkit/shared\";\nimport { FrontendAction } from \"../../types/frontend-action\";\nimport useFlatCategoryStore from \"../../hooks/use-flat-category-store\";\nimport { CopilotKitProps } from \"./copilotkit-props\";\nimport { ToolDefinition } from \"@copilotkit/shared\";\n\n/**\n * The CopilotKit component.\n * This component provides the Copilot context to its children.\n * It can be configured either with a chat API endpoint or a CopilotApiConfig.\n *\n * NOTE: The backend can use OpenAI, or you can bring your own LLM.\n * For examples of the backend api implementation, see `examples/next-openai` usage (under `src/api/copilotkit`),\n * or read the documentation at https://docs.copilotkit.ai\n * In particular, Getting-Started > Quickstart-Backend: https://docs.copilotkit.ai/getting-started/quickstart-backend\n *\n * Example usage:\n * ```\n * <CopilotKit url=\"https://your.copilotkit.api\">\n * <App />\n * </CopilotKit>\n * ```\n *\n * @param props - The props for the component.\n * @returns The CopilotKit component.\n */\nexport function CopilotKit({ children, ...props }: CopilotKitProps) {\n // Compute all the functions and properties that we need to pass\n // to the CopilotContext.\n\n if (!props.url && !props.publicApiKey) {\n throw new Error(\"Please provide either a url or a publicApiKey to the CopilotKit component.\");\n }\n\n const chatApiEndpoint = props.url || COPILOT_CLOUD_CHAT_URL;\n\n const [entryPoints, setEntryPoints] = useState<Record<string, FrontendAction<any>>>({});\n const chatComponentsCache = useRef<Record<string, InChatRenderFunction | string>>({});\n const { addElement, removeElement, printTree } = useTree();\n const [messages, setMessages] = useState<Message[]>([]);\n\n const {\n addElement: addDocument,\n removeElement: removeDocument,\n allElements: allDocuments,\n } = useFlatCategoryStore<DocumentPointer>();\n\n const setEntryPoint = useCallback((id: string, entryPoint: FrontendAction<any>) => {\n setEntryPoints((prevPoints) => {\n return {\n ...prevPoints,\n [id]: entryPoint,\n };\n });\n }, []);\n\n const removeEntryPoint = useCallback((id: string) => {\n setEntryPoints((prevPoints) => {\n const newPoints = { ...prevPoints };\n delete newPoints[id];\n return newPoints;\n });\n }, []);\n\n const getContextString = useCallback(\n (documents: DocumentPointer[], categories: string[]) => {\n const documentsString = documents\n .map((document) => {\n return `${document.name} (${document.sourceApplication}):\\n${document.getContents()}`;\n })\n .join(\"\\n\\n\");\n\n const nonDocumentStrings = printTree(categories);\n\n return `${documentsString}\\n\\n${nonDocumentStrings}`;\n },\n [printTree],\n );\n\n const addContext = useCallback(\n (\n context: string,\n parentId?: string,\n categories: string[] = defaultCopilotContextCategories,\n ) => {\n return addElement(context, categories, parentId);\n },\n [addElement],\n );\n\n const removeContext = useCallback(\n (id: string) => {\n removeElement(id);\n },\n [removeElement],\n );\n\n const getChatCompletionFunctionDescriptions = useCallback(\n (customEntryPoints?: Record<string, FrontendAction<any>>) => {\n return entryPointsToChatCompletionFunctions(Object.values(customEntryPoints || entryPoints));\n },\n [entryPoints],\n );\n\n const getFunctionCallHandler = useCallback(\n (customEntryPoints?: Record<string, FrontendAction<any>>) => {\n return entryPointsToFunctionCallHandler(Object.values(customEntryPoints || entryPoints));\n },\n [entryPoints],\n );\n\n const getDocumentsContext = useCallback(\n (categories: string[]) => {\n return allDocuments(categories);\n },\n [allDocuments],\n );\n\n const addDocumentContext = useCallback(\n (documentPointer: DocumentPointer, categories: string[] = defaultCopilotContextCategories) => {\n return addDocument(documentPointer, categories);\n },\n [addDocument],\n );\n\n const removeDocumentContext = useCallback(\n (documentId: string) => {\n removeDocument(documentId);\n },\n [removeDocument],\n );\n\n if (!props.publicApiKey) {\n if (props.cloudRestrictToTopic) {\n throw new Error(\n \"To use the cloudRestrictToTopic feature, please sign up at https://copilotkit.ai and provide a publicApiKey.\",\n );\n }\n }\n\n let cloud: CopilotCloudConfig | undefined = undefined;\n if (props.publicApiKey) {\n cloud = {\n guardrails: {\n input: {\n restrictToTopic: {\n enabled: props.cloudRestrictToTopic ? true : false,\n validTopics: props.cloudRestrictToTopic?.validTopics || [],\n invalidTopics: props.cloudRestrictToTopic?.invalidTopics || [],\n },\n },\n },\n };\n }\n\n // get the appropriate CopilotApiConfig from the props\n const copilotApiConfig: CopilotApiConfig = {\n publicApiKey: props.publicApiKey,\n ...(cloud ? { cloud } : {}),\n chatApiEndpoint: chatApiEndpoint,\n chatApiEndpointV2: `${props.url}/v2`,\n headers: props.headers || {},\n body: {\n ...props.body,\n ...props.backendOnlyProps,\n },\n };\n\n return (\n <CopilotContext.Provider\n value={{\n entryPoints,\n chatComponentsCache,\n getChatCompletionFunctionDescriptions,\n getFunctionCallHandler,\n setEntryPoint,\n removeEntryPoint,\n getContextString,\n addContext,\n removeContext,\n getDocumentsContext,\n addDocumentContext,\n removeDocumentContext,\n copilotApiConfig: copilotApiConfig,\n messages,\n setMessages,\n }}\n >\n {children}\n </CopilotContext.Provider>\n );\n}\n\nexport const defaultCopilotContextCategories = [\"global\"];\n\nfunction entryPointsToChatCompletionFunctions(actions: FrontendAction<any>[]): ToolDefinition[] {\n return actions.map(actionToChatCompletionFunction);\n}\n\nfunction entryPointsToFunctionCallHandler(actions: FrontendAction<any>[]): FunctionCallHandler {\n return async (chatMessages, functionCall) => {\n let actionsByFunctionName: Record<string, FrontendAction<any>> = {};\n for (let action of actions) {\n actionsByFunctionName[action.name] = action;\n }\n\n const action = actionsByFunctionName[functionCall.name || \"\"];\n if (action) {\n let functionCallArguments: Record<string, any>[] = [];\n if (functionCall.arguments) {\n functionCallArguments = JSON.parse(functionCall.arguments);\n }\n return await action.handler(functionCallArguments);\n }\n };\n}\n"],"mappings":"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","names":["import_react","import_shared","React","import_react","messages","error"]}
|
|
1
|
+
{"version":3,"sources":["../../src/openai-assistants/index.ts","../../src/openai-assistants/hooks/use-copilot-chat-v2.ts","../../src/openai-assistants/utils/process-message-stream.ts","../../src/context/copilot-context.tsx","../../src/components/copilot-provider/copilotkit.tsx"],"sourcesContent":["export * from \"./hooks\";\nexport * from \"./utils\";\n","import { useContext, useMemo, useState } from \"react\";\nimport { processMessageStream } from \"../utils\";\nimport { Message, parseStreamPart } from \"@copilotkit/shared\";\nimport { CopilotContext } from \"../../context\";\nimport { defaultCopilotContextCategories } from \"../../components\";\n\nexport type AssistantStatus = \"in_progress\" | \"awaiting_message\";\n\nexport interface RequestForwardingOptions {\n /**\n * The credentials mode to be used for the fetch request.\n * Possible values are: 'omit', 'same-origin', 'include'.\n * Defaults to 'same-origin'.\n */\n credentials?: RequestCredentials;\n /**\n * HTTP headers to be sent with the API request.\n */\n headers?: Record<string, string> | Headers;\n /**\n * Extra body object to be sent with the API request.\n * @example\n * Send a `sessionId` to the API along with the messages.\n * ```js\n * useChat({\n * body: {\n * sessionId: '123',\n * }\n * })\n * ```\n */\n body?: object;\n}\nexport interface UseCopilotChatOptionsV2 extends RequestForwardingOptions {\n makeSystemMessage?: (contextString: string) => string;\n threadId?: string | undefined;\n}\n\nexport interface UseCopilotChatV2Result {\n messages: Message[];\n input: string;\n handleInputChange: (e: any) => void;\n submitMessage: (e: any) => Promise<void>;\n status: AssistantStatus;\n error: unknown;\n}\n\nexport function useCopilotChatV2(options: UseCopilotChatOptionsV2): UseCopilotChatV2Result {\n const {\n getContextString,\n getChatCompletionFunctionDescriptions,\n getFunctionCallHandler,\n copilotApiConfig,\n } = useContext(CopilotContext);\n\n const [messages, setMessages] = useState<Message[]>([]);\n const [input, setInput] = useState(\"\");\n const [threadId, setThreadId] = useState<string | undefined>(undefined);\n const [status, setStatus] = useState<AssistantStatus>(\"awaiting_message\");\n const [error, setError] = useState<unknown | undefined>(undefined);\n\n const systemMessage: Message = useMemo(() => {\n const systemMessageMaker = options.makeSystemMessage || defaultSystemMessage;\n const contextString = getContextString([], defaultCopilotContextCategories); // TODO: make the context categories configurable\n\n return {\n id: \"system\",\n content: systemMessageMaker(contextString),\n role: \"system\",\n };\n }, [getContextString, options.makeSystemMessage]);\n\n const handleInputChange = (e: any) => {\n setInput(e.target.value);\n };\n\n const submitMessage = async (e: any) => {\n e.preventDefault();\n\n if (input === \"\") {\n return;\n }\n\n setStatus(\"in_progress\");\n\n setMessages((messages) => [...messages, { id: \"\", role: \"user\", content: input }]);\n\n setInput(\"\");\n\n const apiUrl = copilotApiConfig.chatApiEndpointV2;\n\n const functions = getChatCompletionFunctionDescriptions();\n\n const result = await fetch(apiUrl, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n ...copilotApiConfig.headers,\n ...options.headers,\n },\n body: JSON.stringify({\n // always use user-provided threadId when available:\n threadId: options.threadId ?? threadId ?? null,\n message: input,\n ...(functions.length > 0 && { functions: functions }),\n ...copilotApiConfig.body,\n ...options.body,\n }),\n });\n\n if (result.body == null) {\n throw new Error(\"The response body is empty.\");\n }\n\n await processMessageStream(result.body.getReader(), (message: string) => {\n try {\n const { type, value } = parseStreamPart(message);\n\n switch (type) {\n case \"assistant_message\": {\n // append message:\n setMessages((messages) => [\n ...messages,\n {\n id: value.id,\n role: value.role,\n content: value.content[0].text.value,\n },\n ]);\n break;\n }\n\n case \"assistant_control_data\": {\n setThreadId(value.threadId);\n\n // set id of last message:\n setMessages((messages) => {\n const lastMessage = messages[messages.length - 1];\n lastMessage.id = value.messageId;\n return [...messages.slice(0, messages.length - 1), lastMessage];\n });\n\n break;\n }\n\n case \"error\": {\n setError(value);\n break;\n }\n }\n } catch (error) {\n setError(error);\n }\n });\n\n setStatus(\"awaiting_message\");\n };\n\n return {\n messages,\n input,\n handleInputChange,\n submitMessage,\n status,\n error,\n };\n}\n\nexport function defaultSystemMessage(contextString: string): string {\n return `\nPlease act as an efficient, competent, conscientious, and industrious professional assistant.\n\nHelp 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.\nAlways be polite and respectful, and prefer brevity over verbosity.\n\nThe user has provided you with the following context:\n\\`\\`\\`\n${contextString}\n\\`\\`\\`\n\nThey have also provided you with functions you can call to initiate actions on their behalf, or functions you can call to receive more information.\n\nPlease assist them as best you can.\n\nYou can ask them for clarifying questions if needed, but don't be annoying about it. If you can reasonably 'fill in the blanks' yourself, do so.\n\nIf you would like to call a function, call it without saying anything else.\n`;\n}\n","export async function processMessageStream(\n reader: ReadableStreamDefaultReader<Uint8Array>,\n processMessage: (message: string) => void | Promise<void>,\n) {\n const decoder = new TextDecoder();\n let buffer = \"\";\n while (true) {\n const { done, value } = await reader.read();\n\n if (done) {\n if (buffer.length > 0) {\n processMessage(buffer);\n }\n break;\n }\n\n buffer += decoder.decode(value, { stream: true });\n\n let endIndex: number;\n while ((endIndex = buffer.indexOf(\"\\n\")) !== -1) {\n processMessage(buffer.substring(0, endIndex).trim());\n buffer = buffer.substring(endIndex + 1); // Remove the processed instruction + delimiter\n }\n }\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","import { Ref, useCallback, useRef, useState } from \"react\";\nimport {\n CopilotContext,\n CopilotApiConfig,\n InChatRenderFunction,\n} from \"../../context/copilot-context\";\nimport useTree from \"../../hooks/use-tree\";\nimport { DocumentPointer } from \"../../types\";\nimport { FunctionCallHandler, actionToChatCompletionFunction } from \"@copilotkit/shared\";\nimport { FrontendAction } from \"../../types/frontend-action\";\nimport useFlatCategoryStore from \"../../hooks/use-flat-category-store\";\nimport { StandardCopilotApiConfig } from \"./standard-copilot-api-config\";\nimport { CopilotKitProps } from \"./copilotkit-props\";\nimport { ToolDefinition } from \"@copilotkit/shared\";\n\n/**\n * The CopilotKit component.\n * This component provides the Copilot context to its children.\n * It can be configured either with a chat API endpoint or a CopilotApiConfig.\n *\n * NOTE: The backend can use OpenAI, or you can bring your own LLM.\n * For examples of the backend api implementation, see `examples/next-openai` usage (under `src/api/copilotkit`),\n * or read the documentation at https://docs.copilotkit.ai\n * In particular, Getting-Started > Quickstart-Backend: https://docs.copilotkit.ai/getting-started/quickstart-backend\n *\n * Example usage:\n * ```\n * <CopilotKit url=\"https://your.copilotkit.api\">\n * <App />\n * </CopilotKit>\n * ```\n *\n * or\n *\n * ```\n * const copilotApiConfig = new StandardCopilotApiConfig(\n * \"https://your.copilotkit.api/v1\",\n * \"https://your.copilotkit.api/v2\",\n * {},\n * {}\n * );\n *\n * // ...\n *\n * <CopilotKit chatApiConfig={copilotApiConfig}>\n * <App />\n * </CopilotKit>\n * ```\n *\n * @param props - The props for the component.\n * @returns The CopilotKit component.\n */\nexport function CopilotKit({ children, ...props }: CopilotKitProps) {\n // Compute all the functions and properties that we need to pass\n // to the CopilotContext.\n\n const [entryPoints, setEntryPoints] = useState<Record<string, FrontendAction<any>>>({});\n const chatComponentsCache = useRef<Record<string, InChatRenderFunction | string>>({});\n const { addElement, removeElement, printTree } = useTree();\n\n const {\n addElement: addDocument,\n removeElement: removeDocument,\n allElements: allDocuments,\n } = useFlatCategoryStore<DocumentPointer>();\n\n const setEntryPoint = useCallback((id: string, entryPoint: FrontendAction<any>) => {\n setEntryPoints((prevPoints) => {\n return {\n ...prevPoints,\n [id]: entryPoint,\n };\n });\n }, []);\n\n const removeEntryPoint = useCallback((id: string) => {\n setEntryPoints((prevPoints) => {\n const newPoints = { ...prevPoints };\n delete newPoints[id];\n return newPoints;\n });\n }, []);\n\n const getContextString = useCallback(\n (documents: DocumentPointer[], categories: string[]) => {\n const documentsString = documents\n .map((document) => {\n return `${document.name} (${document.sourceApplication}):\\n${document.getContents()}`;\n })\n .join(\"\\n\\n\");\n\n const nonDocumentStrings = printTree(categories);\n\n return `${documentsString}\\n\\n${nonDocumentStrings}`;\n },\n [printTree],\n );\n\n const addContext = useCallback(\n (\n context: string,\n parentId?: string,\n categories: string[] = defaultCopilotContextCategories,\n ) => {\n return addElement(context, categories, parentId);\n },\n [addElement],\n );\n\n const removeContext = useCallback(\n (id: string) => {\n removeElement(id);\n },\n [removeElement],\n );\n\n const getChatCompletionFunctionDescriptions = useCallback(\n (customEntryPoints?: Record<string, FrontendAction<any>>) => {\n return entryPointsToChatCompletionFunctions(Object.values(customEntryPoints || entryPoints));\n },\n [entryPoints],\n );\n\n const getFunctionCallHandler = useCallback(\n (customEntryPoints?: Record<string, FrontendAction<any>>) => {\n return entryPointsToFunctionCallHandler(Object.values(customEntryPoints || entryPoints));\n },\n [entryPoints],\n );\n\n const getDocumentsContext = useCallback(\n (categories: string[]) => {\n return allDocuments(categories);\n },\n [allDocuments],\n );\n\n const addDocumentContext = useCallback(\n (documentPointer: DocumentPointer, categories: string[] = defaultCopilotContextCategories) => {\n return addDocument(documentPointer, categories);\n },\n [addDocument],\n );\n\n const removeDocumentContext = useCallback(\n (documentId: string) => {\n removeDocument(documentId);\n },\n [removeDocument],\n );\n\n // get the appropriate CopilotApiConfig from the props\n const copilotApiConfig: CopilotApiConfig = new StandardCopilotApiConfig(\n props.url,\n `${props.url}/v2`,\n props.headers || {},\n {\n ...props.body,\n ...props.backendOnlyProps,\n },\n );\n\n return (\n <CopilotContext.Provider\n value={{\n entryPoints,\n chatComponentsCache,\n getChatCompletionFunctionDescriptions,\n getFunctionCallHandler,\n setEntryPoint,\n removeEntryPoint,\n getContextString,\n addContext,\n removeContext,\n getDocumentsContext,\n addDocumentContext,\n removeDocumentContext,\n copilotApiConfig: copilotApiConfig,\n }}\n >\n {children}\n </CopilotContext.Provider>\n );\n}\n\nexport const defaultCopilotContextCategories = [\"global\"];\n\nfunction entryPointsToChatCompletionFunctions(actions: FrontendAction<any>[]): ToolDefinition[] {\n return actions.map(actionToChatCompletionFunction);\n}\n\nfunction entryPointsToFunctionCallHandler(actions: FrontendAction<any>[]): FunctionCallHandler {\n return async (chatMessages, functionCall) => {\n let actionsByFunctionName: Record<string, FrontendAction<any>> = {};\n for (let action of actions) {\n actionsByFunctionName[action.name] = action;\n }\n\n const action = actionsByFunctionName[functionCall.name || \"\"];\n if (action) {\n let functionCallArguments: Record<string, any>[] = [];\n if (functionCall.arguments) {\n functionCallArguments = JSON.parse(functionCall.arguments);\n }\n return await action.handler(functionCallArguments);\n }\n };\n}\n"],"mappings":"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","names":["import_react","import_shared","React","import_react","messages","error"]}
|
|
@@ -2,7 +2,7 @@ import "../chunk-7GFKOIO7.mjs";
|
|
|
2
2
|
import "../chunk-BABVSMJR.mjs";
|
|
3
3
|
import {
|
|
4
4
|
useCopilotChatV2
|
|
5
|
-
} from "../chunk-
|
|
5
|
+
} from "../chunk-FCEPEM4B.mjs";
|
|
6
6
|
import "../chunk-FRAKUJWH.mjs";
|
|
7
7
|
import {
|
|
8
8
|
processMessageStream
|
|
@@ -10,10 +10,11 @@ import {
|
|
|
10
10
|
import "../chunk-VNRDQJXW.mjs";
|
|
11
11
|
import "../chunk-JD7BAH7U.mjs";
|
|
12
12
|
import "../chunk-SPCZTZCY.mjs";
|
|
13
|
-
import "../chunk-
|
|
13
|
+
import "../chunk-H3FQWB4B.mjs";
|
|
14
|
+
import "../chunk-F2JIAPZQ.mjs";
|
|
14
15
|
import "../chunk-YULKJPY3.mjs";
|
|
15
16
|
import "../chunk-VUY2K2DI.mjs";
|
|
16
|
-
import "../chunk-
|
|
17
|
+
import "../chunk-KIKHLN4X.mjs";
|
|
17
18
|
import "../chunk-MRXNTQOX.mjs";
|
|
18
19
|
export {
|
|
19
20
|
processMessageStream,
|
|
@@ -82,11 +82,11 @@ function fetchChatCompletion(_0) {
|
|
|
82
82
|
headers: __spreadValues(__spreadValues({
|
|
83
83
|
"Content-Type": "application/json"
|
|
84
84
|
}, copilotConfig.headers), headers ? __spreadValues({}, headers) : {}),
|
|
85
|
-
body: JSON.stringify(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(
|
|
85
|
+
body: JSON.stringify(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({
|
|
86
86
|
model,
|
|
87
87
|
messages: cleanedMessages,
|
|
88
88
|
stream: true
|
|
89
|
-
}, tools.length ? { tools } : {}), temperature ? { temperature } : {}), tools.length != 0 ? { tool_choice: "auto" } : {}), copilotConfig.body), copilotConfig.backendOnlyProps), excludeBackendOnlyProps(copilotConfig)), body ? __spreadValues({}, body) : {})
|
|
89
|
+
}, tools.length ? { tools } : {}), temperature ? { temperature } : {}), tools.length != 0 ? { tool_choice: "auto" } : {}), copilotConfig.body), copilotConfig.backendOnlyProps), excludeBackendOnlyProps(copilotConfig)), body ? __spreadValues({}, body) : {})),
|
|
90
90
|
signal
|
|
91
91
|
});
|
|
92
92
|
return response;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/fetch-chat-completion.ts"],"sourcesContent":["import {\n Message,\n ToolDefinition,\n ChatCompletionEvent,\n decodeChatCompletion,\n parseChatCompletion,\n decodeChatCompletionAsText,\n EXCLUDE_FROM_FORWARD_PROPS_KEYS,\n} from \"@copilotkit/shared\";\nimport { CopilotApiConfig } from \"../context\";\n\nexport interface FetchChatCompletionParams {\n copilotConfig: CopilotApiConfig;\n model?: string;\n messages: Message[];\n tools?: ToolDefinition[];\n temperature?: number;\n maxTokens?: number;\n headers?: Record<string, string> | Headers;\n body?: object;\n signal?: AbortSignal;\n}\n\nexport async function fetchChatCompletion({\n copilotConfig,\n model,\n messages,\n tools,\n temperature,\n headers,\n body,\n signal,\n}: FetchChatCompletionParams): Promise<Response> {\n temperature ||= 0.5;\n tools ||= [];\n\n // clean up any extra properties from messages\n const cleanedMessages = messages.map((message) => {\n const { content, role, name, function_call } = message;\n return { content, role, name, function_call };\n });\n\n const response = await fetch(copilotConfig.chatApiEndpoint, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n ...copilotConfig.headers,\n ...(headers ? { ...headers } : {}),\n },\n body: JSON.stringify({\n model,\n messages: cleanedMessages,\n stream: true,\n ...(tools.length ? { tools } : {}),\n ...(temperature ? { temperature } : {}),\n ...(tools.length != 0 ? { tool_choice: \"auto\" } : {}),\n ...copilotConfig.body,\n ...copilotConfig.backendOnlyProps,\n ...excludeBackendOnlyProps(copilotConfig),\n ...(body ? { ...body } : {}),\n
|
|
1
|
+
{"version":3,"sources":["../../src/utils/fetch-chat-completion.ts"],"sourcesContent":["import {\n Message,\n ToolDefinition,\n ChatCompletionEvent,\n decodeChatCompletion,\n parseChatCompletion,\n decodeChatCompletionAsText,\n EXCLUDE_FROM_FORWARD_PROPS_KEYS,\n} from \"@copilotkit/shared\";\nimport { CopilotApiConfig } from \"../context\";\n\nexport interface FetchChatCompletionParams {\n copilotConfig: CopilotApiConfig;\n model?: string;\n messages: Message[];\n tools?: ToolDefinition[];\n temperature?: number;\n maxTokens?: number;\n headers?: Record<string, string> | Headers;\n body?: object;\n signal?: AbortSignal;\n}\n\nexport async function fetchChatCompletion({\n copilotConfig,\n model,\n messages,\n tools,\n temperature,\n headers,\n body,\n signal,\n}: FetchChatCompletionParams): Promise<Response> {\n temperature ||= 0.5;\n tools ||= [];\n\n // clean up any extra properties from messages\n const cleanedMessages = messages.map((message) => {\n const { content, role, name, function_call } = message;\n return { content, role, name, function_call };\n });\n\n const response = await fetch(copilotConfig.chatApiEndpoint, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n ...copilotConfig.headers,\n ...(headers ? { ...headers } : {}),\n },\n body: JSON.stringify({\n model,\n messages: cleanedMessages,\n stream: true,\n ...(tools.length ? { tools } : {}),\n ...(temperature ? { temperature } : {}),\n ...(tools.length != 0 ? { tool_choice: \"auto\" } : {}),\n ...copilotConfig.body,\n ...copilotConfig.backendOnlyProps,\n ...excludeBackendOnlyProps(copilotConfig),\n ...(body ? { ...body } : {}),\n }),\n signal,\n });\n\n return response;\n}\n\nfunction excludeBackendOnlyProps(copilotConfig: any) {\n const backendOnlyProps = copilotConfig.backendOnlyProps ?? {};\n if (Object.keys(backendOnlyProps).length > 0) {\n return {\n [EXCLUDE_FROM_FORWARD_PROPS_KEYS]: Object.keys(backendOnlyProps),\n };\n } else {\n return {};\n }\n}\n\nexport interface DecodedChatCompletionResponse extends Response {\n events: ReadableStream<ChatCompletionEvent> | null;\n}\n\nexport async function fetchAndDecodeChatCompletion(\n params: FetchChatCompletionParams,\n): Promise<DecodedChatCompletionResponse> {\n const response = await fetchChatCompletion(params);\n if (!response.ok || !response.body) {\n (response as any).events = null;\n } else {\n const events = await decodeChatCompletion(parseChatCompletion(response.body));\n (response as any).events = events;\n }\n return response as any;\n}\n\nexport interface DecodedChatCompletionResponseAsText extends Response {\n events: ReadableStream<string> | null;\n}\n\nexport async function fetchAndDecodeChatCompletionAsText(\n params: FetchChatCompletionParams,\n): Promise<DecodedChatCompletionResponseAsText> {\n const response = await fetchChatCompletion(params);\n if (!response.ok || !response.body) {\n (response as any).events = null;\n } else {\n const events = await decodeChatCompletionAsText(\n decodeChatCompletion(parseChatCompletion(response.body)),\n );\n (response as any).events = events;\n }\n\n return response as any;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAQO;AAeP,SAAsB,oBAAoB,IASO;AAAA,6CATP;AAAA,IACxC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAAiD;AAC/C,kCAAgB;AAChB,sBAAU,CAAC;AAGX,UAAM,kBAAkB,SAAS,IAAI,CAAC,YAAY;AAChD,YAAM,EAAE,SAAS,MAAM,MAAM,cAAc,IAAI;AAC/C,aAAO,EAAE,SAAS,MAAM,MAAM,cAAc;AAAA,IAC9C,CAAC;AAED,UAAM,WAAW,MAAM,MAAM,cAAc,iBAAiB;AAAA,MAC1D,QAAQ;AAAA,MACR,SAAS;AAAA,QACP,gBAAgB;AAAA,SACb,cAAc,UACb,UAAU,mBAAK,WAAY,CAAC;AAAA,MAElC,MAAM,KAAK,UAAU;AAAA,QACnB;AAAA,QACA,UAAU;AAAA,QACV,QAAQ;AAAA,SACJ,MAAM,SAAS,EAAE,MAAM,IAAI,CAAC,IAC5B,cAAc,EAAE,YAAY,IAAI,CAAC,IACjC,MAAM,UAAU,IAAI,EAAE,aAAa,OAAO,IAAI,CAAC,IAChD,cAAc,OACd,cAAc,mBACd,wBAAwB,aAAa,IACpC,OAAO,mBAAK,QAAS,CAAC,EAC3B;AAAA,MACD;AAAA,IACF,CAAC;AAED,WAAO;AAAA,EACT;AAAA;AAEA,SAAS,wBAAwB,eAAoB;AAnErD;AAoEE,QAAM,oBAAmB,mBAAc,qBAAd,YAAkC,CAAC;AAC5D,MAAI,OAAO,KAAK,gBAAgB,EAAE,SAAS,GAAG;AAC5C,WAAO;AAAA,MACL,CAAC,6CAA+B,GAAG,OAAO,KAAK,gBAAgB;AAAA,IACjE;AAAA,EACF,OAAO;AACL,WAAO,CAAC;AAAA,EACV;AACF;AAMA,SAAsB,6BACpB,QACwC;AAAA;AACxC,UAAM,WAAW,MAAM,oBAAoB,MAAM;AACjD,QAAI,CAAC,SAAS,MAAM,CAAC,SAAS,MAAM;AAClC,MAAC,SAAiB,SAAS;AAAA,IAC7B,OAAO;AACL,YAAM,SAAS,UAAM,wCAAqB,mCAAoB,SAAS,IAAI,CAAC;AAC5E,MAAC,SAAiB,SAAS;AAAA,IAC7B;AACA,WAAO;AAAA,EACT;AAAA;AAMA,SAAsB,mCACpB,QAC8C;AAAA;AAC9C,UAAM,WAAW,MAAM,oBAAoB,MAAM;AACjD,QAAI,CAAC,SAAS,MAAM,CAAC,SAAS,MAAM;AAClC,MAAC,SAAiB,SAAS;AAAA,IAC7B,OAAO;AACL,YAAM,SAAS,UAAM;AAAA,YACnB,wCAAqB,mCAAoB,SAAS,IAAI,CAAC;AAAA,MACzD;AACA,MAAC,SAAiB,SAAS;AAAA,IAC7B;AAEA,WAAO;AAAA,EACT;AAAA;","names":[]}
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.25.0-
|
|
7
|
+
"version": "0.25.0-multi-feature-usecopilotreadable.3",
|
|
8
8
|
"sideEffects": false,
|
|
9
9
|
"main": "./dist/index.js",
|
|
10
10
|
"module": "./dist/index.mjs",
|
|
@@ -29,13 +29,13 @@
|
|
|
29
29
|
"ts-jest": "^29.1.1",
|
|
30
30
|
"tsup": "^6.7.0",
|
|
31
31
|
"typescript": "^5.2.3",
|
|
32
|
-
"
|
|
33
|
-
"
|
|
32
|
+
"tsconfig": "0.14.0-multi-feature-usecopilotreadable.3",
|
|
33
|
+
"eslint-config-custom": "0.10.0-multi-feature-usecopilotreadable.3"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"nanoid": "^4.0.2",
|
|
37
37
|
"untruncate-json": "^0.0.1",
|
|
38
|
-
"@copilotkit/shared": "0.9.0-
|
|
38
|
+
"@copilotkit/shared": "0.9.0-multi-feature-usecopilotreadable.3"
|
|
39
39
|
},
|
|
40
40
|
"scripts": {
|
|
41
41
|
"build": "tsup --clean",
|
|
@@ -5,23 +5,10 @@ import { ReactNode } from "react";
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
export interface CopilotKitProps {
|
|
8
|
-
/**
|
|
9
|
-
* The public API key for Copilot Cloud.
|
|
10
|
-
*/
|
|
11
|
-
publicApiKey?: string;
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Cloud feature: Restrict to a specific topic.
|
|
15
|
-
*/
|
|
16
|
-
cloudRestrictToTopic?: {
|
|
17
|
-
validTopics: string[];
|
|
18
|
-
invalidTopics?: string[];
|
|
19
|
-
};
|
|
20
|
-
|
|
21
8
|
/**
|
|
22
9
|
* The endpoint for the chat API.
|
|
23
10
|
*/
|
|
24
|
-
url
|
|
11
|
+
url: string;
|
|
25
12
|
|
|
26
13
|
/**
|
|
27
14
|
* additional headers to be sent with the request
|
|
@@ -6,15 +6,10 @@ import {
|
|
|
6
6
|
} from "../../context/copilot-context";
|
|
7
7
|
import useTree from "../../hooks/use-tree";
|
|
8
8
|
import { DocumentPointer } from "../../types";
|
|
9
|
-
import {
|
|
10
|
-
COPILOT_CLOUD_CHAT_URL,
|
|
11
|
-
CopilotCloudConfig,
|
|
12
|
-
FunctionCallHandler,
|
|
13
|
-
Message,
|
|
14
|
-
actionToChatCompletionFunction,
|
|
15
|
-
} from "@copilotkit/shared";
|
|
9
|
+
import { FunctionCallHandler, actionToChatCompletionFunction } from "@copilotkit/shared";
|
|
16
10
|
import { FrontendAction } from "../../types/frontend-action";
|
|
17
11
|
import useFlatCategoryStore from "../../hooks/use-flat-category-store";
|
|
12
|
+
import { StandardCopilotApiConfig } from "./standard-copilot-api-config";
|
|
18
13
|
import { CopilotKitProps } from "./copilotkit-props";
|
|
19
14
|
import { ToolDefinition } from "@copilotkit/shared";
|
|
20
15
|
|
|
@@ -35,6 +30,23 @@ import { ToolDefinition } from "@copilotkit/shared";
|
|
|
35
30
|
* </CopilotKit>
|
|
36
31
|
* ```
|
|
37
32
|
*
|
|
33
|
+
* or
|
|
34
|
+
*
|
|
35
|
+
* ```
|
|
36
|
+
* const copilotApiConfig = new StandardCopilotApiConfig(
|
|
37
|
+
* "https://your.copilotkit.api/v1",
|
|
38
|
+
* "https://your.copilotkit.api/v2",
|
|
39
|
+
* {},
|
|
40
|
+
* {}
|
|
41
|
+
* );
|
|
42
|
+
*
|
|
43
|
+
* // ...
|
|
44
|
+
*
|
|
45
|
+
* <CopilotKit chatApiConfig={copilotApiConfig}>
|
|
46
|
+
* <App />
|
|
47
|
+
* </CopilotKit>
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
38
50
|
* @param props - The props for the component.
|
|
39
51
|
* @returns The CopilotKit component.
|
|
40
52
|
*/
|
|
@@ -42,16 +54,9 @@ export function CopilotKit({ children, ...props }: CopilotKitProps) {
|
|
|
42
54
|
// Compute all the functions and properties that we need to pass
|
|
43
55
|
// to the CopilotContext.
|
|
44
56
|
|
|
45
|
-
if (!props.url && !props.publicApiKey) {
|
|
46
|
-
throw new Error("Please provide either a url or a publicApiKey to the CopilotKit component.");
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const chatApiEndpoint = props.url || COPILOT_CLOUD_CHAT_URL;
|
|
50
|
-
|
|
51
57
|
const [entryPoints, setEntryPoints] = useState<Record<string, FrontendAction<any>>>({});
|
|
52
58
|
const chatComponentsCache = useRef<Record<string, InChatRenderFunction | string>>({});
|
|
53
59
|
const { addElement, removeElement, printTree } = useTree();
|
|
54
|
-
const [messages, setMessages] = useState<Message[]>([]);
|
|
55
60
|
|
|
56
61
|
const {
|
|
57
62
|
addElement: addDocument,
|
|
@@ -144,41 +149,16 @@ export function CopilotKit({ children, ...props }: CopilotKitProps) {
|
|
|
144
149
|
[removeDocument],
|
|
145
150
|
);
|
|
146
151
|
|
|
147
|
-
if (!props.publicApiKey) {
|
|
148
|
-
if (props.cloudRestrictToTopic) {
|
|
149
|
-
throw new Error(
|
|
150
|
-
"To use the cloudRestrictToTopic feature, please sign up at https://copilotkit.ai and provide a publicApiKey.",
|
|
151
|
-
);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
let cloud: CopilotCloudConfig | undefined = undefined;
|
|
156
|
-
if (props.publicApiKey) {
|
|
157
|
-
cloud = {
|
|
158
|
-
guardrails: {
|
|
159
|
-
input: {
|
|
160
|
-
restrictToTopic: {
|
|
161
|
-
enabled: props.cloudRestrictToTopic ? true : false,
|
|
162
|
-
validTopics: props.cloudRestrictToTopic?.validTopics || [],
|
|
163
|
-
invalidTopics: props.cloudRestrictToTopic?.invalidTopics || [],
|
|
164
|
-
},
|
|
165
|
-
},
|
|
166
|
-
},
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
|
|
170
152
|
// get the appropriate CopilotApiConfig from the props
|
|
171
|
-
const copilotApiConfig: CopilotApiConfig =
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
headers: props.headers || {},
|
|
177
|
-
body: {
|
|
153
|
+
const copilotApiConfig: CopilotApiConfig = new StandardCopilotApiConfig(
|
|
154
|
+
props.url,
|
|
155
|
+
`${props.url}/v2`,
|
|
156
|
+
props.headers || {},
|
|
157
|
+
{
|
|
178
158
|
...props.body,
|
|
179
159
|
...props.backendOnlyProps,
|
|
180
160
|
},
|
|
181
|
-
|
|
161
|
+
);
|
|
182
162
|
|
|
183
163
|
return (
|
|
184
164
|
<CopilotContext.Provider
|
|
@@ -196,8 +176,6 @@ export function CopilotKit({ children, ...props }: CopilotKitProps) {
|
|
|
196
176
|
addDocumentContext,
|
|
197
177
|
removeDocumentContext,
|
|
198
178
|
copilotApiConfig: copilotApiConfig,
|
|
199
|
-
messages,
|
|
200
|
-
setMessages,
|
|
201
179
|
}}
|
|
202
180
|
>
|
|
203
181
|
{children}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { CopilotApiConfig } from "../../context/copilot-context";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A standard implementation of the CopilotApiConfig interface.
|
|
5
|
+
*
|
|
6
|
+
* Pass in the base URL of the chat API, the headers to be sent with each request, and the body to be sent with each request.
|
|
7
|
+
* The rest of the CopilotApiConfig interface is implemented by default.
|
|
8
|
+
*
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
export class StandardCopilotApiConfig implements CopilotApiConfig {
|
|
12
|
+
chatApiEndpoint: string;
|
|
13
|
+
chatApiEndpointV2: string;
|
|
14
|
+
headers: Record<string, string>;
|
|
15
|
+
body: Record<string, any>;
|
|
16
|
+
|
|
17
|
+
constructor(
|
|
18
|
+
chatApiEndpoint: string,
|
|
19
|
+
chatApiEndpointV2: string,
|
|
20
|
+
headers: Record<string, string>,
|
|
21
|
+
body: Record<string, any>,
|
|
22
|
+
) {
|
|
23
|
+
this.chatApiEndpoint = chatApiEndpoint;
|
|
24
|
+
this.chatApiEndpointV2 = chatApiEndpointV2;
|
|
25
|
+
this.headers = headers;
|
|
26
|
+
this.body = body;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
CopilotCloudConfig,
|
|
3
|
-
FunctionCallHandler,
|
|
4
|
-
Message,
|
|
5
|
-
ToolDefinition,
|
|
6
|
-
} from "@copilotkit/shared";
|
|
1
|
+
import { FunctionCallHandler, ToolDefinition } from "@copilotkit/shared";
|
|
7
2
|
import { ActionRenderProps, FrontendAction } from "../types/frontend-action";
|
|
8
3
|
import React, { Ref } from "react";
|
|
9
4
|
import { TreeNodeId } from "../hooks/use-tree";
|
|
@@ -13,16 +8,6 @@ import { DocumentPointer } from "../types";
|
|
|
13
8
|
* Interface for the configuration of the Copilot API.
|
|
14
9
|
*/
|
|
15
10
|
export interface CopilotApiConfig {
|
|
16
|
-
/**
|
|
17
|
-
* The public API key for Copilot Cloud.
|
|
18
|
-
*/
|
|
19
|
-
publicApiKey?: string;
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* The configuration for Copilot Cloud.
|
|
23
|
-
*/
|
|
24
|
-
cloud?: CopilotCloudConfig;
|
|
25
|
-
|
|
26
11
|
/**
|
|
27
12
|
* The endpoint for the chat API.
|
|
28
13
|
*/
|
|
@@ -85,9 +70,6 @@ export interface CopilotContextParams {
|
|
|
85
70
|
customEntryPoints?: Record<string, FrontendAction<any>>,
|
|
86
71
|
) => FunctionCallHandler;
|
|
87
72
|
|
|
88
|
-
messages: Message[];
|
|
89
|
-
setMessages: React.Dispatch<React.SetStateAction<Message[]>>;
|
|
90
|
-
|
|
91
73
|
// text context
|
|
92
74
|
addContext: (context: string, parentId?: string, categories?: string[]) => TreeNodeId;
|
|
93
75
|
removeContext: (id: TreeNodeId) => void;
|
|
@@ -113,8 +95,6 @@ const emptyCopilotContext: CopilotContextParams = {
|
|
|
113
95
|
returnAndThrowInDebug(""),
|
|
114
96
|
addContext: () => "",
|
|
115
97
|
removeContext: () => {},
|
|
116
|
-
messages: [],
|
|
117
|
-
setMessages: () => returnAndThrowInDebug([]),
|
|
118
98
|
|
|
119
99
|
getDocumentsContext: (categories: string[]) => returnAndThrowInDebug([]),
|
|
120
100
|
addDocumentContext: () => returnAndThrowInDebug(""),
|
package/src/hooks/index.ts
CHANGED
|
@@ -7,3 +7,4 @@ export { useCopilotAction } from "./use-copilot-action";
|
|
|
7
7
|
export { useMakeCopilotReadable } from "./use-make-copilot-readable";
|
|
8
8
|
export { useMakeCopilotDocumentReadable } from "./use-make-copilot-document-readable";
|
|
9
9
|
export { type UseChatHelpers } from "./use-chat";
|
|
10
|
+
export { useCopilotReadable } from "./use-copilot-readable";
|
package/src/hooks/use-chat.ts
CHANGED
|
@@ -5,7 +5,6 @@ import {
|
|
|
5
5
|
FunctionCallHandler,
|
|
6
6
|
encodeResult,
|
|
7
7
|
FunctionCall,
|
|
8
|
-
COPILOT_CLOUD_PUBLIC_API_KEY_HEADER,
|
|
9
8
|
} from "@copilotkit/shared";
|
|
10
9
|
|
|
11
10
|
import { nanoid } from "nanoid";
|
|
@@ -59,6 +58,8 @@ export type UseChatOptions = {
|
|
|
59
58
|
};
|
|
60
59
|
|
|
61
60
|
export type UseChatHelpers = {
|
|
61
|
+
/** Current messages in the chat */
|
|
62
|
+
messages: Message[];
|
|
62
63
|
/**
|
|
63
64
|
* Append a user message to the chat list. This triggers the API call to fetch
|
|
64
65
|
* the assistant's response.
|
|
@@ -85,28 +86,15 @@ export type UseChatHelpers = {
|
|
|
85
86
|
|
|
86
87
|
export type UseChatOptionsWithCopilotConfig = UseChatOptions & {
|
|
87
88
|
copilotConfig: CopilotApiConfig;
|
|
88
|
-
/**
|
|
89
|
-
* The current list of messages in the chat.
|
|
90
|
-
*/
|
|
91
|
-
messages: Message[];
|
|
92
|
-
/**
|
|
93
|
-
* The setState-powered method to update the chat messages.
|
|
94
|
-
*/
|
|
95
|
-
setMessages: React.Dispatch<React.SetStateAction<Message[]>>;
|
|
96
89
|
};
|
|
97
90
|
|
|
98
91
|
export function useChat(options: UseChatOptionsWithCopilotConfig): UseChatHelpers {
|
|
99
|
-
const
|
|
92
|
+
const [messages, setMessages] = useState<Message[]>([]);
|
|
100
93
|
const [input, setInput] = useState("");
|
|
101
94
|
const [isLoading, setIsLoading] = useState(false);
|
|
102
95
|
const abortControllerRef = useRef<AbortController>();
|
|
103
96
|
const threadIdRef = useRef<string | null>(null);
|
|
104
97
|
const runIdRef = useRef<string | null>(null);
|
|
105
|
-
const publicApiKey = options.copilotConfig.publicApiKey;
|
|
106
|
-
const headers = {
|
|
107
|
-
...(options.headers || {}),
|
|
108
|
-
...(publicApiKey ? { [COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey } : {}),
|
|
109
|
-
};
|
|
110
98
|
|
|
111
99
|
const runChatCompletion = async (messages: Message[]): Promise<Message[]> => {
|
|
112
100
|
setIsLoading(true);
|
|
@@ -138,7 +126,7 @@ export function useChat(options: UseChatOptionsWithCopilotConfig): UseChatHelper
|
|
|
138
126
|
copilotConfig: { ...options.copilotConfig, body: copilotConfigBody },
|
|
139
127
|
messages: messagesWithContext,
|
|
140
128
|
tools: options.tools,
|
|
141
|
-
headers: headers,
|
|
129
|
+
headers: options.headers,
|
|
142
130
|
signal: abortController.signal,
|
|
143
131
|
});
|
|
144
132
|
|
|
@@ -151,6 +139,16 @@ export function useChat(options: UseChatOptionsWithCopilotConfig): UseChatHelper
|
|
|
151
139
|
}
|
|
152
140
|
|
|
153
141
|
if (!response.events) {
|
|
142
|
+
setMessages([
|
|
143
|
+
...messages,
|
|
144
|
+
{
|
|
145
|
+
id: nanoid(),
|
|
146
|
+
createdAt: new Date(),
|
|
147
|
+
content: response.statusText,
|
|
148
|
+
role: "assistant",
|
|
149
|
+
},
|
|
150
|
+
]);
|
|
151
|
+
setIsLoading(false);
|
|
154
152
|
throw new Error("Failed to fetch chat completion");
|
|
155
153
|
}
|
|
156
154
|
|
|
@@ -308,6 +306,7 @@ export function useChat(options: UseChatOptionsWithCopilotConfig): UseChatHelper
|
|
|
308
306
|
};
|
|
309
307
|
|
|
310
308
|
return {
|
|
309
|
+
messages,
|
|
311
310
|
append,
|
|
312
311
|
reload,
|
|
313
312
|
stop,
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { useRef, useContext, useEffect } from "react";
|
|
2
|
+
import { FrontendAction } from "../types/frontend-action";
|
|
3
|
+
import { CopilotContext } from "../context/copilot-context";
|
|
4
|
+
import { nanoid } from "nanoid";
|
|
5
|
+
|
|
6
|
+
// We implement useCopilotActionImplementation dependency handling so that
|
|
7
|
+
// the developer has the option to not provide any dependencies.
|
|
8
|
+
// In this case, we assume they want to update the handler on each rerender.
|
|
9
|
+
// To avoid getting stuck in an infinite loop, we update the handler directly,
|
|
10
|
+
// skipping React state updates.
|
|
11
|
+
// This is ok in this case, because the handler is not part of any UI that
|
|
12
|
+
// needs to be updated.
|
|
13
|
+
// useCallback, useMemo or other memoization techniques are not suitable here,
|
|
14
|
+
// because they will cause a infinite rerender loop.
|
|
15
|
+
export function useCopilotActionImplementation<T extends Array<any> = []>(
|
|
16
|
+
action: FrontendAction<T>,
|
|
17
|
+
dependencies?: any[],
|
|
18
|
+
): void {
|
|
19
|
+
const { setEntryPoint, removeEntryPoint, entryPoints, chatComponentsCache } =
|
|
20
|
+
useContext(CopilotContext);
|
|
21
|
+
const idRef = useRef<string>(nanoid());
|
|
22
|
+
|
|
23
|
+
// If the developer doesn't provide dependencies, we assume they want to
|
|
24
|
+
// update handler and render function when the action object changes.
|
|
25
|
+
// This ensures that any captured variables in the handler are up to date.
|
|
26
|
+
if (dependencies === undefined) {
|
|
27
|
+
if (entryPoints[idRef.current]) {
|
|
28
|
+
entryPoints[idRef.current].handler = action.handler;
|
|
29
|
+
if (typeof action.render === "function") {
|
|
30
|
+
if (chatComponentsCache.current !== null) {
|
|
31
|
+
chatComponentsCache.current[action.name] = action.render;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
setEntryPoint(idRef.current, action);
|
|
39
|
+
if (chatComponentsCache.current !== null && action.render !== undefined) {
|
|
40
|
+
chatComponentsCache.current[action.name] = action.render;
|
|
41
|
+
}
|
|
42
|
+
return () => {
|
|
43
|
+
// NOTE: For now, we don't remove the chatComponentsCache entry when the action is removed.
|
|
44
|
+
// This is because we currently don't have access to the messages array in CopilotContext.
|
|
45
|
+
removeEntryPoint(idRef.current);
|
|
46
|
+
};
|
|
47
|
+
}, [
|
|
48
|
+
setEntryPoint,
|
|
49
|
+
removeEntryPoint,
|
|
50
|
+
action.description,
|
|
51
|
+
action.name,
|
|
52
|
+
// This should be faster than deep equality checking
|
|
53
|
+
// In addition, all major JS engines guarantee the order of object keys
|
|
54
|
+
JSON.stringify(action.parameters),
|
|
55
|
+
// include render only if it's a string
|
|
56
|
+
typeof action.render === "string" ? action.render : undefined,
|
|
57
|
+
// dependencies set by the developer
|
|
58
|
+
...(dependencies || []),
|
|
59
|
+
]);
|
|
60
|
+
}
|
|
@@ -1,63 +1,13 @@
|
|
|
1
|
-
import { useRef, useContext, useEffect } from "react";
|
|
2
|
-
import { FrontendAction } from "../types/frontend-action";
|
|
3
|
-
import { CopilotContext } from "../context/copilot-context";
|
|
4
|
-
import { nanoid } from "nanoid";
|
|
5
1
|
import { Parameter } from "@copilotkit/shared";
|
|
2
|
+
import { FrontendAction } from "../types/frontend-action";
|
|
3
|
+
import { useCopilotActionImplementation } from "./use-copilot-action-implementation";
|
|
6
4
|
|
|
7
|
-
//
|
|
8
|
-
// the
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
// needs to be updated.
|
|
14
|
-
// useCallback, useMemo or other memoization techniques are not suitable here,
|
|
15
|
-
// because they will cause a infinite rerender loop.
|
|
16
|
-
export function useCopilotAction<const T extends Parameter[] | [] = []>(
|
|
17
|
-
action: FrontendAction<T>,
|
|
18
|
-
dependencies?: any[],
|
|
19
|
-
): void {
|
|
20
|
-
const { setEntryPoint, removeEntryPoint, entryPoints, chatComponentsCache } =
|
|
21
|
-
useContext(CopilotContext);
|
|
22
|
-
const idRef = useRef<string>(nanoid());
|
|
23
|
-
|
|
24
|
-
// If the developer doesn't provide dependencies, we assume they want to
|
|
25
|
-
// update handler and render function when the action object changes.
|
|
26
|
-
// This ensures that any captured variables in the handler are up to date.
|
|
27
|
-
if (dependencies === undefined) {
|
|
28
|
-
if (entryPoints[idRef.current]) {
|
|
29
|
-
entryPoints[idRef.current].handler = action.handler;
|
|
30
|
-
if (typeof action.render === "function") {
|
|
31
|
-
if (chatComponentsCache.current !== null) {
|
|
32
|
-
chatComponentsCache.current[action.name] = action.render;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
useEffect(() => {
|
|
39
|
-
setEntryPoint(idRef.current, action);
|
|
40
|
-
if (chatComponentsCache.current !== null && action.render !== undefined) {
|
|
41
|
-
chatComponentsCache.current[action.name] = action.render;
|
|
42
|
-
}
|
|
43
|
-
return () => {
|
|
44
|
-
// NOTE: For now, we don't remove the chatComponentsCache entry when the action is removed.
|
|
45
|
-
// This is because we currently don't have access to the messages array in CopilotContext.
|
|
46
|
-
removeEntryPoint(idRef.current);
|
|
47
|
-
};
|
|
48
|
-
}, [
|
|
49
|
-
setEntryPoint,
|
|
50
|
-
removeEntryPoint,
|
|
51
|
-
action.description,
|
|
52
|
-
action.name,
|
|
53
|
-
// This should be faster than deep equality checking
|
|
54
|
-
// In addition, all major JS engines guarantee the order of object keys
|
|
55
|
-
JSON.stringify(action.parameters),
|
|
56
|
-
// include render only if it's a string
|
|
57
|
-
typeof action.render === "string" ? action.render : undefined,
|
|
58
|
-
// dependencies set by the developer
|
|
59
|
-
...(dependencies || []),
|
|
60
|
-
]);
|
|
5
|
+
// Prettier chokes on the `const` in the function signature
|
|
6
|
+
// To have the main implementation checked by prettier, we split
|
|
7
|
+
// this into a separate file
|
|
8
|
+
// prettier-ignore
|
|
9
|
+
export function useCopilotAction<const T extends Parameter[] | [] = []>(action: FrontendAction<T>, dependencies?: any[]): void {
|
|
10
|
+
return useCopilotActionImplementation(action, dependencies);
|
|
61
11
|
}
|
|
62
12
|
|
|
63
13
|
// Usage Example:
|
|
@@ -89,3 +39,5 @@ export function useCopilotAction<const T extends Parameter[] | [] = []>(
|
|
|
89
39
|
// console.log("No parameters provided.");
|
|
90
40
|
// },
|
|
91
41
|
// });
|
|
42
|
+
|
|
43
|
+
// https://community.openai.com/t/function-call-complex-arrays-as-parameters/295648/3
|