@copilotkit/react-core
Advanced tools
| import { StandardCopilotApiConfig } from './chunk-F2JIAPZQ.mjs'; | ||
| import { use_tree_default } from './chunk-VUY2K2DI.mjs'; | ||
| import { use_flat_category_store_default } from './chunk-YULKJPY3.mjs'; | ||
| import { CopilotContext } from './chunk-6A4PCNMZ.mjs'; | ||
| import { __objRest, __spreadProps, __spreadValues, __async } from './chunk-MRXNTQOX.mjs'; | ||
| import { useState, useCallback } from 'react'; | ||
| import { jsx } from 'react/jsx-runtime'; | ||
| function CopilotProvider(_a) { | ||
| var _b = _a, { children } = _b, props = __objRest(_b, ["children"]); | ||
| const [entryPoints, setEntryPoints] = useState({}); | ||
| const { addElement, removeElement, printTree } = use_tree_default(); | ||
| const { | ||
| addElement: addDocument, | ||
| removeElement: removeDocument, | ||
| allElements: allDocuments | ||
| } = use_flat_category_store_default(); | ||
| const setEntryPoint = useCallback((id, entryPoint) => { | ||
| setEntryPoints((prevPoints) => { | ||
| return __spreadProps(__spreadValues({}, prevPoints), { | ||
| [id]: entryPoint | ||
| }); | ||
| }); | ||
| }, []); | ||
| const removeEntryPoint = useCallback((id) => { | ||
| setEntryPoints((prevPoints) => { | ||
| const newPoints = __spreadValues({}, prevPoints); | ||
| delete newPoints[id]; | ||
| return newPoints; | ||
| }); | ||
| }, []); | ||
| const getContextString = useCallback( | ||
| (documents, categories) => { | ||
| const documentsString = documents.map((document) => { | ||
| return `${document.name} (${document.sourceApplication}): | ||
| ${document.getContents()}`; | ||
| }).join("\n\n"); | ||
| const nonDocumentStrings = printTree(categories); | ||
| return `${documentsString} | ||
| ${nonDocumentStrings}`; | ||
| }, | ||
| [printTree] | ||
| ); | ||
| const addContext = useCallback( | ||
| (context, parentId, categories = defaultCopilotContextCategories) => { | ||
| return addElement(context, categories, parentId); | ||
| }, | ||
| [addElement] | ||
| ); | ||
| const removeContext = useCallback( | ||
| (id) => { | ||
| removeElement(id); | ||
| }, | ||
| [removeElement] | ||
| ); | ||
| const getChatCompletionFunctionDescriptions = useCallback(() => { | ||
| return entryPointsToChatCompletionFunctions(Object.values(entryPoints)); | ||
| }, [entryPoints]); | ||
| const getFunctionCallHandler = useCallback(() => { | ||
| return entryPointsToFunctionCallHandler(Object.values(entryPoints)); | ||
| }, [entryPoints]); | ||
| const getDocumentsContext = useCallback( | ||
| (categories) => { | ||
| return allDocuments(categories); | ||
| }, | ||
| [allDocuments] | ||
| ); | ||
| const addDocumentContext = useCallback( | ||
| (documentPointer, categories = defaultCopilotContextCategories) => { | ||
| return addDocument(documentPointer, categories); | ||
| }, | ||
| [addDocument] | ||
| ); | ||
| const removeDocumentContext = useCallback( | ||
| (documentId) => { | ||
| removeDocument(documentId); | ||
| }, | ||
| [removeDocument] | ||
| ); | ||
| let copilotApiConfig; | ||
| if ("chatApiEndpoint" in props) { | ||
| copilotApiConfig = new StandardCopilotApiConfig( | ||
| props.chatApiEndpoint, | ||
| props.chatApiEndpointV2 || `${props.chatApiEndpoint}/v2`, | ||
| {}, | ||
| {} | ||
| ); | ||
| } else { | ||
| copilotApiConfig = props.chatApiConfig; | ||
| } | ||
| return /* @__PURE__ */ jsx( | ||
| CopilotContext.Provider, | ||
| { | ||
| value: { | ||
| entryPoints, | ||
| getChatCompletionFunctionDescriptions, | ||
| getFunctionCallHandler, | ||
| setEntryPoint, | ||
| removeEntryPoint, | ||
| getContextString, | ||
| addContext, | ||
| removeContext, | ||
| getDocumentsContext, | ||
| addDocumentContext, | ||
| removeDocumentContext, | ||
| copilotApiConfig | ||
| }, | ||
| children | ||
| } | ||
| ); | ||
| } | ||
| var defaultCopilotContextCategories = ["global"]; | ||
| function entryPointsToFunctionCallHandler(entryPoints) { | ||
| return (chatMessages, functionCall) => __async(this, null, function* () { | ||
| let entrypointsByFunctionName = {}; | ||
| for (let entryPoint of entryPoints) { | ||
| entrypointsByFunctionName[entryPoint.name] = entryPoint; | ||
| } | ||
| const entryPointFunction = entrypointsByFunctionName[functionCall.name || ""]; | ||
| if (entryPointFunction) { | ||
| let functionCallArguments = []; | ||
| if (functionCall.arguments) { | ||
| functionCallArguments = JSON.parse(functionCall.arguments); | ||
| } | ||
| const paramsInCorrectOrder = []; | ||
| for (let arg of entryPointFunction.argumentAnnotations) { | ||
| paramsInCorrectOrder.push( | ||
| functionCallArguments[arg.name] | ||
| ); | ||
| } | ||
| yield entryPointFunction.implementation(...paramsInCorrectOrder); | ||
| } | ||
| }); | ||
| } | ||
| function entryPointsToChatCompletionFunctions(entryPoints) { | ||
| return entryPoints.map(annotatedFunctionToChatCompletionFunction); | ||
| } | ||
| function annotatedFunctionToChatCompletionFunction(annotatedFunction) { | ||
| let parameters = {}; | ||
| for (let arg of annotatedFunction.argumentAnnotations) { | ||
| let _a = arg, forwardedArgs = __objRest(_a, ["name", "required"]); | ||
| parameters[arg.name] = forwardedArgs; | ||
| } | ||
| let requiredParameterNames = []; | ||
| for (let arg of annotatedFunction.argumentAnnotations) { | ||
| if (arg.required) { | ||
| requiredParameterNames.push(arg.name); | ||
| } | ||
| } | ||
| let chatCompletionFunction = { | ||
| name: annotatedFunction.name, | ||
| description: annotatedFunction.description, | ||
| parameters: { | ||
| type: "object", | ||
| properties: parameters, | ||
| required: requiredParameterNames | ||
| } | ||
| }; | ||
| return chatCompletionFunction; | ||
| } | ||
| export { CopilotProvider, defaultCopilotContextCategories }; | ||
| //# sourceMappingURL=out.js.map | ||
| //# sourceMappingURL=chunk-D4NQCVHE.mjs.map |
| {"version":3,"sources":["../src/components/copilot-provider/copilot-provider.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAEA,SAAS,aAAa,gBAAgB;AA0JlC;AA3GG,SAAS,gBAAgB,IAA2D;AAA3D,eAAE,WAjDlC,IAiDgC,IAAe,kBAAf,IAAe,CAAb;AAIhC,QAAM,CAAC,aAAa,cAAc,IAAI,SAAmD,CAAC,CAAC;AAE3F,QAAM,EAAE,YAAY,eAAe,UAAU,IAAI,iBAAQ;AAEzD,QAAM;AAAA,IACJ,YAAY;AAAA,IACZ,eAAe;AAAA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AI,IAA0C;AAAA,QACtE;AAAA,MACF;AAEA,YAAM,mBAAmB,eAAe,GAAG,oBAAoB;AAAA,IAmBjE;AAAA,EACF;AACF;AAEA,SAAS,qCACP,aACuC;AACvC,SAAO,YAAY,IAAI,yCAAyC;AAClE;AAEA,SAAS,0CACP,mBACqC;AAErC,MAAI,aAAqC,CAAC;AAC1C,WAAS,OAAO,kBAAkB,qBAAqB;AAErD,QAA2C,UAArC,QAAM,SA9OhB,IA8O+C,IAAlB,0BAAkB,IAAlB,CAAnB,QAAM;AACZ,eAAW,IAAI,IAAI,IAAI;AAAA,EACzB;AAEA,MAAI,yBAAmC,CAAC;AACxC,WAAS,OAAO,kBAAkB,qBAAqB;AACrD,QAAI,IAAI,UAAU;AAChB,6BAAuB,KAAK,IAAI,IAAI;AAAA,IACtC;AAAA,EACF;AAGA,MAAI,yBAA8D;AAAA,IAChE,MAAM,kBAAkB;AAAA,IACxB,aAAa,kBAAkB;AAAA,IAC/B,YAAY;AAAA,MACV,MAAM;AAAA,MACN,YAAY;AAAA,MACZ,UAAU;AAAA,IACZ;AAAA,EACF;AAEA,SAAO;AACT","sourcesContent":["\"use client\";\n\nimport { useCallback, useState } from \"react\";\nimport { CopilotContext, CopilotApiConfig } from \"../../context/copilot-context\";\nimport useTree from \"../../hooks/use-tree\";\nimport { AnnotatedFunction } from \"../../types/annotated-function\";\nimport { ChatCompletionCreateParams } from \"openai/resources/chat\";\nimport { DocumentPointer, FunctionCallHandler } from \"../../types\";\nimport useFlatCategoryStore from \"../../hooks/use-flat-category-store\";\nimport { StandardCopilotApiConfig } from \"./standard-copilot-api-config\";\nimport { CopilotProviderProps } from \"./copilot-provider-props\";\n\n/**\n * The CopilotProvider 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 * <CopilotProvider chatApiEndpoint=\"https://your.copilotkit.api\">\n * <App />\n * </CopilotProvider>\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 * <CopilotProvider chatApiConfig={copilotApiConfig}>\n * <App />\n * </CopilotProvider>\n * ```\n *\n * @param props - The props for the component.\n * @returns The CopilotProvider component.\n */\nexport function CopilotProvider({ children, ...props }: CopilotProviderProps): JSX.Element {\n // Compute all the functions and properties that we need to pass\n // to the CopilotContext.\n\n const [entryPoints, setEntryPoints] = useState<Record<string, AnnotatedFunction<any[]>>>({});\n\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: AnnotatedFunction<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 return entryPointsToChatCompletionFunctions(Object.values(entryPoints));\n }, [entryPoints]);\n\n const getFunctionCallHandler = useCallback(() => {\n return entryPointsToFunctionCallHandler(Object.values(entryPoints));\n }, [entryPoints]);\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 let copilotApiConfig: CopilotApiConfig;\n if (\"chatApiEndpoint\" in props) {\n copilotApiConfig = new StandardCopilotApiConfig(\n props.chatApiEndpoint,\n props.chatApiEndpointV2 || `${props.chatApiEndpoint}/v2`,\n {},\n {},\n );\n } else {\n copilotApiConfig = props.chatApiConfig;\n }\n\n return (\n <CopilotContext.Provider\n value={{\n entryPoints,\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 entryPointsToFunctionCallHandler(\n entryPoints: AnnotatedFunction<any[]>[],\n): FunctionCallHandler {\n return async (chatMessages, functionCall) => {\n let entrypointsByFunctionName: Record<string, AnnotatedFunction<any[]>> = {};\n for (let entryPoint of entryPoints) {\n entrypointsByFunctionName[entryPoint.name] = entryPoint;\n }\n\n const entryPointFunction = entrypointsByFunctionName[functionCall.name || \"\"];\n if (entryPointFunction) {\n let functionCallArguments: Record<string, any>[] = [];\n if (functionCall.arguments) {\n functionCallArguments = JSON.parse(functionCall.arguments);\n }\n\n const paramsInCorrectOrder: any[] = [];\n for (let arg of entryPointFunction.argumentAnnotations) {\n paramsInCorrectOrder.push(\n functionCallArguments[arg.name as keyof typeof functionCallArguments],\n );\n }\n\n await entryPointFunction.implementation(...paramsInCorrectOrder);\n\n // commented out becasue for now we don't want to return anything\n // const result = await entryPointFunction.implementation(\n // ...parsedFunctionCallArguments\n // );\n // const functionResponse: ChatRequest = {\n // messages: [\n // ...chatMessages,\n // {\n // id: nanoid(),\n // name: functionCall.name,\n // role: 'function' as const,\n // content: JSON.stringify(result),\n // },\n // ],\n // };\n\n // return functionResponse;\n }\n };\n}\n\nfunction entryPointsToChatCompletionFunctions(\n entryPoints: AnnotatedFunction<any[]>[],\n): ChatCompletionCreateParams.Function[] {\n return entryPoints.map(annotatedFunctionToChatCompletionFunction);\n}\n\nfunction annotatedFunctionToChatCompletionFunction(\n annotatedFunction: AnnotatedFunction<any[]>,\n): ChatCompletionCreateParams.Function {\n // Create the parameters object based on the argumentAnnotations\n let parameters: { [key: string]: any } = {};\n for (let arg of annotatedFunction.argumentAnnotations) {\n // isolate the args we should forward inline\n let { name, required, ...forwardedArgs } = arg;\n parameters[arg.name] = forwardedArgs;\n }\n\n let requiredParameterNames: string[] = [];\n for (let arg of annotatedFunction.argumentAnnotations) {\n if (arg.required) {\n requiredParameterNames.push(arg.name);\n }\n }\n\n // Create the ChatCompletionFunctions object\n let chatCompletionFunction: ChatCompletionCreateParams.Function = {\n name: annotatedFunction.name,\n description: annotatedFunction.description,\n parameters: {\n type: \"object\",\n properties: parameters,\n required: requiredParameterNames,\n },\n };\n\n return chatCompletionFunction;\n}\n"]} |
| import { defaultCopilotContextCategories } from './chunk-D4NQCVHE.mjs'; | ||
| import { useChat } from './chunk-LMZN4NSM.mjs'; | ||
| import { CopilotContext } from './chunk-6A4PCNMZ.mjs'; | ||
| import { __objRest, __spreadProps, __spreadValues } from './chunk-MRXNTQOX.mjs'; | ||
| import { useContext, useMemo } from 'react'; | ||
| function useCopilotChat(_a) { | ||
| var _b = _a, { | ||
| makeSystemMessage, | ||
| additionalInstructions | ||
| } = _b, options = __objRest(_b, [ | ||
| "makeSystemMessage", | ||
| "additionalInstructions" | ||
| ]); | ||
| const { | ||
| getContextString, | ||
| getChatCompletionFunctionDescriptions, | ||
| getFunctionCallHandler, | ||
| copilotApiConfig | ||
| } = useContext(CopilotContext); | ||
| const systemMessage = useMemo(() => { | ||
| const systemMessageMaker = makeSystemMessage || defaultSystemMessage; | ||
| const contextString = getContextString([], defaultCopilotContextCategories); | ||
| return { | ||
| id: "system", | ||
| content: systemMessageMaker(contextString, additionalInstructions), | ||
| role: "system" | ||
| }; | ||
| }, [getContextString, makeSystemMessage]); | ||
| const functionDescriptions = useMemo(() => { | ||
| return getChatCompletionFunctionDescriptions(); | ||
| }, [getChatCompletionFunctionDescriptions]); | ||
| const { messages, append, reload, stop, isLoading, input, setInput } = useChat(__spreadProps(__spreadValues({}, options), { | ||
| copilotConfig: copilotApiConfig, | ||
| id: options.id, | ||
| initialMessages: [systemMessage].concat(options.initialMessages || []), | ||
| functions: functionDescriptions, | ||
| onFunctionCall: getFunctionCallHandler(), | ||
| headers: __spreadValues({}, options.headers), | ||
| body: __spreadValues({}, options.body) | ||
| })); | ||
| const visibleMessages = messages.filter( | ||
| (message) => message.role === "user" || message.role === "assistant" | ||
| ); | ||
| return { | ||
| visibleMessages, | ||
| append, | ||
| reload, | ||
| stop, | ||
| isLoading, | ||
| input, | ||
| setInput | ||
| }; | ||
| } | ||
| function defaultSystemMessage(contextString, additionalInstructions) { | ||
| return ` | ||
| Please act as an efficient, competent, conscientious, and industrious professional assistant. | ||
| Help the user achieve their goals, and you do so in a way that is as efficient as possible, without unnecessary fluff, but also without sacrificing professionalism. | ||
| Always be polite and respectful, and prefer brevity over verbosity. | ||
| The user has provided you with the following context: | ||
| \`\`\` | ||
| ${contextString} | ||
| \`\`\` | ||
| They have also provided you with functions you can call to initiate actions on their behalf, or functions you can call to receive more information. | ||
| Please assist them as best you can. | ||
| You 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. | ||
| If you would like to call a function, call it without saying anything else. | ||
| ` + (additionalInstructions ? ` | ||
| ${additionalInstructions}` : ""); | ||
| } | ||
| export { defaultSystemMessage, useCopilotChat }; | ||
| //# sourceMappingURL=out.js.map | ||
| //# sourceMappingURL=chunk-FY7XNRJP.mjs.map |
| {"version":3,"sources":["../src/hooks/use-copilot-chat.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,SAAS,SAAS,kBAAkB;AAsB7B,SAAS,eAAe,IAIiB;AAJjB,eAC7B;AAAA;AAAA,IACA;AAAA,EAxBF,IAsB+B,IAG1B,oBAH0B,IAG1B;AAAA,IAFH;AAAA,IACA;AAAA;AAGA,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI,WAAW,cAAc;AAE7B,QAAM,gBAAyB,QAAQ,MAAM;AAC3C,UAAM,qBAAqB,qBAAqB;AAChD,UAAM,gBAAgB,iBAAiB,CAAC,GAAG,+BAA+B;AAE1E,WAAO;AAAA,MACL,IAAI;AAAA,MACJ,SAAS,mBAAmB,eAAe,sBAAsB;AAAA,MACjE,MAAM;AAAA,IACR;AAAA,EACF,GAAG,CAAC,kBAAkB,iBAAiB,CAAC;AAExC,QAAM,uBAA8D,QAAQ,MAAM;AAChF,WAAO,sCAAsC;AAAA,EAC/C,GAAG,CAAC,qCAAqC,CAAC;AAE1C,QAAM,EAAE,UAAU,QAAQ,QAAQ,MAAM,WAAW,OAAO,SAAS,IAAI,QAAQ,iCAC1E,UAD0E;AAAA,IAE7E,eAAe;AAAA,IACf,IAAI,QAAQ;AAAA,IACZ,iBAAiB,CAAC,aAAa,EAAE,OAAO,QAAQ,mBAAmB,CAAC,CAAC;AAAA,IACrE,WAAW;AAAA,IACX,gBAAgB,uBAAuB;AAAA,IACvC,SAAS,mBAAK,QAAQ;AAAA,IACtB,MAAM,mBACD,QAAQ;AAAA,EAEf,EAAC;AAED,QAAM,kBAAkB,SAAS;AAAA,IAC/B,CAAC,YAAY,QAAQ,SAAS,UAAU,QAAQ,SAAS;AAAA,EAC3D;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAEO,SAAS,qBACd,eACA,wBACQ;AACR,SACE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,KAUG,yBAAyB;AAAA;AAAA,EAAO,2BAA2B;AAEhE","sourcesContent":["import { useMemo, useContext } from \"react\";\nimport { CopilotContext, CopilotContextParams } from \"../context/copilot-context\";\nimport { Message, SystemMessageFunction } from \"../types\";\nimport { UseChatOptions, useChat } from \"./use-chat\";\nimport { defaultCopilotContextCategories } from \"../components\";\nimport { ChatCompletionCreateParams } from \"openai/resources/chat\";\n\nexport interface UseCopilotChatOptions extends UseChatOptions {\n makeSystemMessage?: SystemMessageFunction;\n additionalInstructions?: string;\n}\n\nexport interface UseCopilotChatReturn {\n visibleMessages: Message[];\n append: (message: Message) => Promise<void>;\n reload: () => Promise<void>;\n stop: () => void;\n isLoading: boolean;\n input: string;\n setInput: React.Dispatch<React.SetStateAction<string>>;\n}\n\nexport function useCopilotChat({\n makeSystemMessage,\n additionalInstructions,\n ...options\n}: UseCopilotChatOptions): UseCopilotChatReturn {\n const {\n getContextString,\n getChatCompletionFunctionDescriptions,\n getFunctionCallHandler,\n copilotApiConfig,\n } = useContext(CopilotContext);\n\n const systemMessage: Message = useMemo(() => {\n const systemMessageMaker = makeSystemMessage || defaultSystemMessage;\n const contextString = getContextString([], defaultCopilotContextCategories); // TODO: make the context categories configurable\n\n return {\n id: \"system\",\n content: systemMessageMaker(contextString, additionalInstructions),\n role: \"system\",\n };\n }, [getContextString, makeSystemMessage]);\n\n const functionDescriptions: ChatCompletionCreateParams.Function[] = useMemo(() => {\n return getChatCompletionFunctionDescriptions();\n }, [getChatCompletionFunctionDescriptions]);\n\n const { messages, append, reload, stop, isLoading, input, setInput } = useChat({\n ...options,\n copilotConfig: copilotApiConfig,\n id: options.id,\n initialMessages: [systemMessage].concat(options.initialMessages || []),\n functions: functionDescriptions,\n onFunctionCall: getFunctionCallHandler(),\n headers: { ...options.headers },\n body: {\n ...options.body,\n },\n });\n\n const visibleMessages = messages.filter(\n (message) => message.role === \"user\" || message.role === \"assistant\",\n );\n\n return {\n visibleMessages,\n append,\n reload,\n stop,\n isLoading,\n input,\n setInput,\n };\n}\n\nexport function defaultSystemMessage(\n contextString: string,\n additionalInstructions?: string,\n): string {\n return (\n `\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` + (additionalInstructions ? `\\n\\n${additionalInstructions}` : \"\")\n );\n}\n"]} |
| import { processMessageStream } from './chunk-MZ5UN3BY.mjs'; | ||
| import { defaultCopilotContextCategories } from './chunk-D4NQCVHE.mjs'; | ||
| import { CopilotContext } from './chunk-6A4PCNMZ.mjs'; | ||
| import { __async, __spreadValues } from './chunk-MRXNTQOX.mjs'; | ||
| import { useContext, useState, useMemo } from 'react'; | ||
| import { parseStreamPart } from '@copilotkit/shared'; | ||
| function useCopilotChatV2(options) { | ||
| const { | ||
| getContextString, | ||
| getChatCompletionFunctionDescriptions, | ||
| getFunctionCallHandler, | ||
| copilotApiConfig | ||
| } = useContext(CopilotContext); | ||
| const [messages, setMessages] = useState([]); | ||
| const [input, setInput] = useState(""); | ||
| const [threadId, setThreadId] = useState(void 0); | ||
| const [status, setStatus] = useState("awaiting_message"); | ||
| const [error, setError] = useState(void 0); | ||
| useMemo(() => { | ||
| const systemMessageMaker = options.makeSystemMessage || defaultSystemMessage; | ||
| const contextString = getContextString([], defaultCopilotContextCategories); | ||
| return { | ||
| id: "system", | ||
| content: systemMessageMaker(contextString), | ||
| role: "system" | ||
| }; | ||
| }, [getContextString, options.makeSystemMessage]); | ||
| const handleInputChange = (e) => { | ||
| setInput(e.target.value); | ||
| }; | ||
| const submitMessage = (e) => __async(this, null, function* () { | ||
| var _a, _b; | ||
| e.preventDefault(); | ||
| if (input === "") { | ||
| return; | ||
| } | ||
| setStatus("in_progress"); | ||
| setMessages((messages2) => [...messages2, { id: "", role: "user", content: input }]); | ||
| setInput(""); | ||
| const apiUrl = copilotApiConfig.chatApiEndpointV2; | ||
| const functions = getChatCompletionFunctionDescriptions(); | ||
| const result = yield fetch(apiUrl, { | ||
| method: "POST", | ||
| headers: __spreadValues(__spreadValues({ | ||
| "Content-Type": "application/json" | ||
| }, copilotApiConfig.headers), options.headers), | ||
| body: JSON.stringify(__spreadValues(__spreadValues(__spreadValues({ | ||
| // always use user-provided threadId when available: | ||
| threadId: (_b = (_a = options.threadId) != null ? _a : threadId) != null ? _b : null, | ||
| message: input | ||
| }, functions.length > 0 && { functions }), copilotApiConfig.body), options.body)) | ||
| }); | ||
| if (result.body == null) { | ||
| throw new Error("The response body is empty."); | ||
| } | ||
| yield processMessageStream(result.body.getReader(), (message) => { | ||
| try { | ||
| const { type, value } = parseStreamPart(message); | ||
| switch (type) { | ||
| case "assistant_message": { | ||
| setMessages((messages2) => [ | ||
| ...messages2, | ||
| { | ||
| id: value.id, | ||
| role: value.role, | ||
| content: value.content[0].text.value | ||
| } | ||
| ]); | ||
| break; | ||
| } | ||
| case "assistant_control_data": { | ||
| setThreadId(value.threadId); | ||
| setMessages((messages2) => { | ||
| const lastMessage = messages2[messages2.length - 1]; | ||
| lastMessage.id = value.messageId; | ||
| return [...messages2.slice(0, messages2.length - 1), lastMessage]; | ||
| }); | ||
| break; | ||
| } | ||
| case "error": { | ||
| setError(value); | ||
| break; | ||
| } | ||
| } | ||
| } catch (error2) { | ||
| setError(error2); | ||
| } | ||
| }); | ||
| setStatus("awaiting_message"); | ||
| }); | ||
| return { | ||
| messages, | ||
| input, | ||
| handleInputChange, | ||
| submitMessage, | ||
| status, | ||
| error | ||
| }; | ||
| } | ||
| function defaultSystemMessage(contextString) { | ||
| return ` | ||
| Please act as an efficient, competent, conscientious, and industrious professional assistant. | ||
| Help the user achieve their goals, and you do so in a way that is as efficient as possible, without unnecessary fluff, but also without sacrificing professionalism. | ||
| Always be polite and respectful, and prefer brevity over verbosity. | ||
| The user has provided you with the following context: | ||
| \`\`\` | ||
| ${contextString} | ||
| \`\`\` | ||
| They have also provided you with functions you can call to initiate actions on their behalf, or functions you can call to receive more information. | ||
| Please assist them as best you can. | ||
| You 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. | ||
| If you would like to call a function, call it without saying anything else. | ||
| `; | ||
| } | ||
| export { defaultSystemMessage, useCopilotChatV2 }; | ||
| //# sourceMappingURL=out.js.map | ||
| //# sourceMappingURL=chunk-P34OLW2N.mjs.map |
| {"version":3,"sources":["../src/openai-assistants/hooks/use-copilot-chat-v2.ts"],"names":["messages","error"],"mappings":";;;;;;;;;;;;;;;AAAA,SAAS,YAAY,SAAS,gBAAgB;AAE9C,SAAkB,uBAAuB;AA6ClC,SAAS,iBAAiB,SAA0D;AACzF,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI,WAAW,cAAc;AAE7B,QAAM,CAAC,UAAU,WAAW,IAAI,SAAoB,CAAC,CAAC;AACtD,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAS,EAAE;AACrC,QAAM,CAAC,UAAU,WAAW,IAAI,SAA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,EAAE,MAAM,MAAM,IAAI,gBAAgB,OAAO;AAE/C,gBAAQ,MAAM;AAAA,UACZ,KAAK,qBAAqB;AAExB,wBAAY,CAACA,cAAa;AAAA,cACxB,GAAGA;AAAA,cACH;AAAA,gBACE,IAAI,MAAM;AAAA,gBACV,MAAM,MAAM;AAAA,gBACZ,SAAS,MAAM,QAAQ,CAAC,EAAE,KAAK;AAAA,cACjC;AAAA,YACF,CAAC;AACD;AAAA,UACF;AAAA,UAEA,KAAK,0BAA0B;AAC7B,wBAAY,MAAM,QAAQ;AAG1B,wBAAY,CAACA,cAAa;AACxB,oBAAM,cAAcA,UAASA,UAAS,SAAS,CAAC;AAChD,0BAAY,KAAK,MAAM;AACvB,qBAAO,CAAC,GAAGA,UAAS,MAAM,GAAGA,UAAS,SAAS,CAAC,GAAG,WAAW;AAAA,YAChE,CAAC;AAED;AAAA,UACF;AAAA,UAEA,KAAK,SAAS;AACZ,qBAAS,KAAK;AACd;AAAA,UACF;AAAA,QACF;AAAA,MACF,SAASC,QAAP;AACA,iBAASA,MAAK;AAAA,MAChB;AAAA,IACF,CAAC;AAED,cAAU,kBAAkB;AAAA,EAC9B;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAEO,SAAS,qBAAqB,eAA+B;AAClE,SAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQP;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAWF","sourcesContent":["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"]} |
| type SystemMessageFunction = (contextString: string, additionalInstructions?: string) => string; | ||
| export { SystemMessageFunction }; |
| //# sourceMappingURL=out.js.map | ||
| //# sourceMappingURL=system-message.mjs.map |
| {"version":3,"sources":[],"names":[],"mappings":""} |
| export type SystemMessageFunction = ( | ||
| contextString: string, | ||
| additionalInstructions?: string, | ||
| ) => string; |
+96
-96
| > @copilotkit/react-core@0.17.1 build /Users/ataibarkai/LocalGit/Recursively.ai/CopilotKit/CopilotKit/packages/react-core | ||
| > @copilotkit/react-core@0.18.0-alpha.0 build /Users/ataibarkai/LocalGit/Recursively.ai/CopilotKit/CopilotKit/packages/react-core | ||
| > tsup --treeshake | ||
| CLI Building entry: src/index.tsx, src/context/copilot-context.tsx, src/context/index.ts, src/components/index.ts, src/hooks/index.ts, src/hooks/use-chat.ts, src/hooks/use-copilot-chat.ts, src/hooks/use-flat-category-store.ts, src/hooks/use-make-copilot-actionable.ts, src/hooks/use-make-copilot-document-readable.ts, src/hooks/use-make-copilot-readable.ts, src/hooks/use-tree.ts, src/openai/chat-completion-client.ts, src/openai/chat-completion-stream.ts, src/openai/chat-completion-transport.ts, src/openai/index.tsx, src/openai-assistants/index.ts, src/types/annotated-function.ts, src/types/base.ts, src/types/document-pointer.ts, src/types/index.ts, src/types/message.ts, src/utils/utils.test.ts, src/utils/utils.ts, src/components/copilot-provider/copilot-provider-props.tsx, src/components/copilot-provider/copilot-provider.tsx, src/components/copilot-provider/index.ts, src/components/copilot-provider/standard-copilot-api-config.tsx, src/openai-assistants/hooks/index.ts, src/openai-assistants/hooks/use-assistants.ts, src/openai-assistants/hooks/use-copilot-chat-v2.ts, src/openai-assistants/utils/index.ts, src/openai-assistants/utils/process-message-stream.ts | ||
| CLI Building entry: src/index.tsx, src/components/index.ts, src/hooks/index.ts, src/hooks/use-chat.ts, src/hooks/use-copilot-chat.ts, src/hooks/use-flat-category-store.ts, src/hooks/use-make-copilot-actionable.ts, src/hooks/use-make-copilot-document-readable.ts, src/hooks/use-make-copilot-readable.ts, src/hooks/use-tree.ts, src/context/copilot-context.tsx, src/context/index.ts, src/utils/utils.test.ts, src/utils/utils.ts, src/openai-assistants/index.ts, src/openai/chat-completion-client.ts, src/openai/chat-completion-stream.ts, src/openai/chat-completion-transport.ts, src/openai/index.tsx, src/types/annotated-function.ts, src/types/base.ts, src/types/document-pointer.ts, src/types/index.ts, src/types/system-message.ts, src/components/copilot-provider/copilot-provider-props.tsx, src/components/copilot-provider/copilot-provider.tsx, src/components/copilot-provider/index.ts, src/components/copilot-provider/standard-copilot-api-config.tsx, src/openai-assistants/hooks/index.ts, src/openai-assistants/hooks/use-assistants.ts, src/openai-assistants/hooks/use-copilot-chat-v2.ts, src/openai-assistants/utils/index.ts, src/openai-assistants/utils/process-message-stream.ts | ||
| CLI Using tsconfig: tsconfig.json | ||
@@ -15,6 +15,6 @@ CLI tsup v6.7.0 | ||
| Module level directives cause errors when bundled, "use client" in "dist/openai-assistants/hooks/use-assistants.mjs" was ignored. | ||
| Module level directives cause errors when bundled, "use client" in "dist/hooks/use-make-copilot-readable.mjs" was ignored. | ||
| Module level directives cause errors when bundled, "use client" in "dist/context/copilot-context.mjs" was ignored. | ||
| Module level directives cause errors when bundled, "use client" in "dist/hooks/use-make-copilot-actionable.mjs" was ignored. | ||
| Module level directives cause errors when bundled, "use client" in "dist/hooks/use-make-copilot-document-readable.mjs" was ignored. | ||
| Module level directives cause errors when bundled, "use client" in "dist/hooks/use-make-copilot-readable.mjs" was ignored. | ||
| Module level directives cause errors when bundled, "use client" in "dist/context/copilot-context.mjs" was ignored. | ||
| Generated an empty chunk: "copilot-provider-props". | ||
@@ -24,9 +24,9 @@ Generated an empty chunk: "annotated-function". | ||
| Generated an empty chunk: "document-pointer". | ||
| Generated an empty chunk: "message". | ||
| Generated an empty chunk: "system-message". | ||
| Generated an empty chunk: "utils". | ||
| Generated an empty chunk: "chunk-PUFR5OAI". | ||
| Generated an empty chunk: "chunk-EFZPSZWO". | ||
| Generated an empty chunk: "chunk-7GFKOIO7". | ||
| Generated an empty chunk: "chunk-BABVSMJR". | ||
| Generated an empty chunk: "chunk-FRAKUJWH". | ||
| Generated an empty chunk: "chunk-EFZPSZWO". | ||
| Generated an empty chunk: "chunk-PUFR5OAI". | ||
| Generated an empty chunk: "chunk-VNRDQJXW". | ||
@@ -36,126 +36,126 @@ Generated an empty chunk: "chunk-5UGLWBZJ". | ||
| Generated an empty chunk: "chunk-SPCZTZCY". | ||
| ESM dist/chunk-7GFKOIO7.mjs 76.00 B | ||
| ESM dist/chunk-PUFR5OAI.mjs 76.00 B | ||
| ESM dist/types/index.mjs 98.00 B | ||
| ESM dist/hooks/use-make-copilot-readable.mjs 214.00 B | ||
| ESM dist/context/copilot-context.mjs 164.00 B | ||
| ESM dist/openai/chat-completion-stream.mjs 209.00 B | ||
| ESM dist/openai-assistants/index.mjs 570.00 B | ||
| ESM dist/openai/chat-completion-client.mjs 209.00 B | ||
| ESM dist/context/copilot-context.mjs 164.00 B | ||
| ESM dist/components/index.mjs 380.00 B | ||
| ESM dist/types/index.mjs 98.00 B | ||
| ESM dist/hooks/use-make-copilot-actionable.mjs 218.00 B | ||
| ESM dist/chunk-BABVSMJR.mjs 76.00 B | ||
| ESM dist/chunk-PUFR5OAI.mjs 76.00 B | ||
| ESM dist/chunk-FRAKUJWH.mjs 76.00 B | ||
| ESM dist/chunk-EFZPSZWO.mjs 76.00 B | ||
| ESM dist/chunk-7GFKOIO7.mjs 76.00 B | ||
| ESM dist/chunk-VNRDQJXW.mjs 76.00 B | ||
| ESM dist/chunk-5UGLWBZJ.mjs 76.00 B | ||
| ESM dist/chunk-JD7BAH7U.mjs 76.00 B | ||
| ESM dist/chunk-F2JIAPZQ.mjs 435.00 B | ||
| ESM dist/chunk-SPCZTZCY.mjs 76.00 B | ||
| ESM dist/chunk-MRXNTQOX.mjs 1.92 KB | ||
| ESM dist/chunk-F2JIAPZQ.mjs 435.00 B | ||
| ESM dist/hooks/use-make-copilot-document-readable.mjs 231.00 B | ||
| ESM dist/hooks/use-make-copilot-readable.mjs 214.00 B | ||
| ESM dist/openai/chat-completion-stream.mjs 209.00 B | ||
| ESM dist/chunk-TU4DNDO7.mjs 4.33 KB | ||
| ESM dist/openai/chat-completion-transport.mjs 183.00 B | ||
| ESM dist/chunk-EFZPSZWO.mjs 76.00 B | ||
| ESM dist/openai/index.mjs 224.00 B | ||
| ESM dist/hooks/use-tree.mjs 170.00 B | ||
| ESM dist/chunk-BABVSMJR.mjs 76.00 B | ||
| ESM dist/index.mjs 1.11 KB | ||
| ESM dist/context/index.mjs 186.00 B | ||
| ESM dist/chunk-MZ5UN3BY.mjs 830.00 B | ||
| ESM dist/chunk-6SOQYBNX.mjs 1.24 KB | ||
| ESM dist/chunk-FP4EXCGS.mjs 954.00 B | ||
| ESM dist/hooks/use-tree.mjs 170.00 B | ||
| ESM dist/chunk-7P4OYNP3.mjs 677.00 B | ||
| ESM dist/chunk-FRAKUJWH.mjs 76.00 B | ||
| ESM dist/chunk-5UGLWBZJ.mjs 76.00 B | ||
| ESM dist/chunk-HW5IH6PV.mjs 626.00 B | ||
| ESM dist/hooks/use-chat.mjs 214.00 B | ||
| ESM dist/chunk-SFQOMKM2.mjs 2.71 KB | ||
| ESM dist/chunk-QTET3FBV.mjs 5.18 KB | ||
| ESM dist/chunk-6A4PCNMZ.mjs 1.30 KB | ||
| ESM dist/context/index.mjs 186.00 B | ||
| ESM dist/hooks/index.mjs 708.00 B | ||
| ESM dist/chunk-FY7XNRJP.mjs 2.88 KB | ||
| ESM dist/hooks/use-copilot-chat.mjs 507.00 B | ||
| ESM dist/chunk-VUY2K2DI.mjs 3.89 KB | ||
| ESM dist/chunk-JD7BAH7U.mjs 76.00 B | ||
| ESM dist/chunk-LMZN4NSM.mjs 3.69 KB | ||
| ESM dist/chunk-VK25FIML.mjs 4.48 KB | ||
| ESM dist/chunk-TKXPMMND.mjs 5.33 KB | ||
| ESM dist/chunk-VK25FIML.mjs 4.48 KB | ||
| ESM dist/chunk-FP4EXCGS.mjs 954.00 B | ||
| ESM dist/hooks/use-make-copilot-actionable.mjs 218.00 B | ||
| ESM dist/chunk-YULKJPY3.mjs 1.87 KB | ||
| ESM dist/hooks/use-flat-category-store.mjs 200.00 B | ||
| ESM dist/chunk-YULKJPY3.mjs 1.87 KB | ||
| ESM dist/hooks/use-copilot-chat.mjs 507.00 B | ||
| ESM dist/chunk-VUY2K2DI.mjs 3.89 KB | ||
| ESM dist/hooks/index.mjs 708.00 B | ||
| ESM dist/openai/chat-completion-transport.mjs 183.00 B | ||
| ESM dist/openai/index.mjs 224.00 B | ||
| ESM dist/chunk-D4NQCVHE.mjs 5.18 KB | ||
| ESM dist/openai/chat-completion-client.mjs 209.00 B | ||
| ESM dist/chunk-6SOQYBNX.mjs 1.24 KB | ||
| ESM dist/chunk-7P4OYNP3.mjs 677.00 B | ||
| ESM dist/chunk-6A4PCNMZ.mjs 1.30 KB | ||
| ESM dist/chunk-P34OLW2N.mjs 4.33 KB | ||
| ESM dist/hooks/use-make-copilot-document-readable.mjs 231.00 B | ||
| ESM dist/components/copilot-provider/copilot-provider-props.mjs 84.00 B | ||
| ESM dist/utils/utils.test.mjs 202.00 B | ||
| ESM dist/components/copilot-provider/copilot-provider-props.mjs 84.00 B | ||
| ESM dist/openai-assistants/utils/process-message-stream.mjs 183.00 B | ||
| ESM dist/openai-assistants/hooks/index.mjs 547.00 B | ||
| ESM dist/openai-assistants/hooks/use-assistants.mjs 2.55 KB | ||
| ESM dist/types/system-message.mjs 76.00 B | ||
| ESM dist/types/document-pointer.mjs 78.00 B | ||
| ESM dist/types/annotated-function.mjs 80.00 B | ||
| ESM dist/types/message.mjs 69.00 B | ||
| ESM dist/utils/utils.mjs 67.00 B | ||
| ESM dist/types/base.mjs 66.00 B | ||
| ESM dist/components/copilot-provider/copilot-provider.mjs 345.00 B | ||
| ESM dist/components/copilot-provider/index.mjs 369.00 B | ||
| ESM dist/utils/utils.mjs 67.00 B | ||
| ESM dist/components/copilot-provider/standard-copilot-api-config.mjs 192.00 B | ||
| ESM dist/types/document-pointer.mjs 78.00 B | ||
| ESM dist/components/copilot-provider/index.mjs 369.00 B | ||
| ESM dist/openai-assistants/utils/index.mjs 201.00 B | ||
| ESM dist/openai-assistants/hooks/use-assistants.mjs 2.55 KB | ||
| ESM dist/chunk-7GFKOIO7.mjs.map 51.00 B | ||
| ESM dist/openai/chat-completion-client.mjs.map 51.00 B | ||
| ESM dist/openai-assistants/hooks/use-copilot-chat-v2.mjs 548.00 B | ||
| ESM dist/openai-assistants/hooks/index.mjs 547.00 B | ||
| ESM dist/chunk-PUFR5OAI.mjs.map 51.00 B | ||
| ESM dist/types/index.mjs.map 51.00 B | ||
| ESM dist/context/copilot-context.mjs.map 51.00 B | ||
| ESM dist/hooks/use-make-copilot-readable.mjs.map 51.00 B | ||
| ESM dist/openai/chat-completion-stream.mjs.map 51.00 B | ||
| ESM dist/openai-assistants/index.mjs.map 51.00 B | ||
| ESM dist/context/copilot-context.mjs.map 51.00 B | ||
| ESM dist/components/index.mjs.map 51.00 B | ||
| ESM dist/hooks/use-make-copilot-actionable.mjs.map 51.00 B | ||
| ESM dist/chunk-BABVSMJR.mjs.map 51.00 B | ||
| ESM dist/chunk-PUFR5OAI.mjs.map 51.00 B | ||
| ESM dist/chunk-FRAKUJWH.mjs.map 51.00 B | ||
| ESM dist/chunk-EFZPSZWO.mjs.map 51.00 B | ||
| ESM dist/chunk-VNRDQJXW.mjs.map 51.00 B | ||
| ESM dist/chunk-5UGLWBZJ.mjs.map 51.00 B | ||
| ESM dist/chunk-7GFKOIO7.mjs.map 51.00 B | ||
| ESM dist/chunk-SPCZTZCY.mjs.map 51.00 B | ||
| ESM dist/chunk-F2JIAPZQ.mjs.map 1.12 KB | ||
| ESM dist/hooks/use-make-copilot-readable.mjs.map 51.00 B | ||
| ESM dist/openai/chat-completion-stream.mjs.map 51.00 B | ||
| ESM dist/chunk-TU4DNDO7.mjs.map 7.90 KB | ||
| ESM dist/chunk-VNRDQJXW.mjs.map 51.00 B | ||
| ESM dist/chunk-EFZPSZWO.mjs.map 51.00 B | ||
| ESM dist/openai/chat-completion-transport.mjs.map 51.00 B | ||
| ESM dist/chunk-MRXNTQOX.mjs.map 71.00 B | ||
| ESM dist/index.mjs.map 51.00 B | ||
| ESM dist/context/index.mjs.map 51.00 B | ||
| ESM dist/chunk-MZ5UN3BY.mjs.map 1.26 KB | ||
| ESM dist/chunk-6SOQYBNX.mjs.map 2.07 KB | ||
| ESM dist/chunk-FP4EXCGS.mjs.map 1.67 KB | ||
| ESM dist/chunk-7P4OYNP3.mjs.map 1.42 KB | ||
| ESM dist/chunk-FRAKUJWH.mjs.map 51.00 B | ||
| ESM dist/hooks/use-chat.mjs.map 51.00 B | ||
| ESM dist/hooks/use-tree.mjs.map 51.00 B | ||
| ESM dist/chunk-SFQOMKM2.mjs.map 4.37 KB | ||
| ESM dist/chunk-QTET3FBV.mjs.map 11.03 KB | ||
| ESM dist/context/index.mjs.map 51.00 B | ||
| ESM dist/chunk-HW5IH6PV.mjs.map 1.47 KB | ||
| ESM dist/chunk-BABVSMJR.mjs.map 51.00 B | ||
| ESM dist/chunk-5UGLWBZJ.mjs.map 51.00 B | ||
| ESM dist/chunk-VK25FIML.mjs.map 7.84 KB | ||
| ESM dist/chunk-FY7XNRJP.mjs.map 4.65 KB | ||
| ESM dist/chunk-LMZN4NSM.mjs.map 8.47 KB | ||
| ESM dist/chunk-TKXPMMND.mjs.map 9.93 KB | ||
| ESM dist/chunk-VK25FIML.mjs.map 7.84 KB | ||
| ESM dist/hooks/use-flat-category-store.mjs.map 51.00 B | ||
| ESM dist/chunk-YULKJPY3.mjs.map 4.21 KB | ||
| ESM dist/types/index.mjs.map 51.00 B | ||
| ESM dist/openai/index.mjs.map 51.00 B | ||
| ESM dist/hooks/use-copilot-chat.mjs.map 51.00 B | ||
| ESM dist/hooks/use-make-copilot-document-readable.mjs.map 51.00 B | ||
| ESM dist/chunk-FP4EXCGS.mjs.map 1.67 KB | ||
| ESM dist/hooks/use-tree.mjs.map 51.00 B | ||
| ESM dist/hooks/use-make-copilot-actionable.mjs.map 51.00 B | ||
| ESM dist/chunk-VUY2K2DI.mjs.map 8.27 KB | ||
| ESM dist/chunk-MRXNTQOX.mjs.map 71.00 B | ||
| ESM dist/chunk-YULKJPY3.mjs.map 4.21 KB | ||
| ESM dist/openai/chat-completion-client.mjs.map 51.00 B | ||
| ESM dist/hooks/index.mjs.map 51.00 B | ||
| ESM dist/hooks/use-flat-category-store.mjs.map 51.00 B | ||
| ESM dist/chunk-JD7BAH7U.mjs.map 51.00 B | ||
| ESM dist/chunk-6SOQYBNX.mjs.map 2.07 KB | ||
| ESM dist/chunk-7P4OYNP3.mjs.map 1.42 KB | ||
| ESM dist/chunk-D4NQCVHE.mjs.map 11.03 KB | ||
| ESM dist/chunk-TKXPMMND.mjs.map 9.93 KB | ||
| ESM dist/chunk-P34OLW2N.mjs.map 7.90 KB | ||
| ESM dist/chunk-6A4PCNMZ.mjs.map 4.26 KB | ||
| ESM dist/openai/chat-completion-transport.mjs.map 51.00 B | ||
| ESM dist/chunk-HW5IH6PV.mjs.map 1.47 KB | ||
| ESM dist/openai/index.mjs.map 51.00 B | ||
| ESM dist/hooks/use-make-copilot-document-readable.mjs.map 51.00 B | ||
| ESM dist/components/copilot-provider/copilot-provider-props.mjs.map 51.00 B | ||
| ESM dist/utils/utils.test.mjs.map 351.00 B | ||
| ESM dist/components/copilot-provider/copilot-provider-props.mjs.map 51.00 B | ||
| ESM dist/openai-assistants/utils/process-message-stream.mjs.map 51.00 B | ||
| ESM dist/chunk-JD7BAH7U.mjs.map 51.00 B | ||
| ESM dist/openai-assistants/hooks/use-assistants.mjs.map 4.67 KB | ||
| ESM dist/types/system-message.mjs.map 51.00 B | ||
| ESM dist/types/document-pointer.mjs.map 51.00 B | ||
| ESM dist/components/copilot-provider/copilot-provider.mjs.map 51.00 B | ||
| ESM dist/types/annotated-function.mjs.map 51.00 B | ||
| ESM dist/types/message.mjs.map 51.00 B | ||
| ESM dist/types/base.mjs.map 51.00 B | ||
| ESM dist/utils/utils.mjs.map 51.00 B | ||
| ESM dist/types/base.mjs.map 51.00 B | ||
| ESM dist/components/copilot-provider/copilot-provider.mjs.map 51.00 B | ||
| ESM dist/components/copilot-provider/index.mjs.map 51.00 B | ||
| ESM dist/openai-assistants/utils/index.mjs.map 51.00 B | ||
| ESM dist/openai-assistants/hooks/use-copilot-chat-v2.mjs.map 51.00 B | ||
| ESM dist/components/copilot-provider/standard-copilot-api-config.mjs.map 51.00 B | ||
| ESM dist/types/document-pointer.mjs.map 51.00 B | ||
| ESM dist/openai-assistants/utils/index.mjs.map 51.00 B | ||
| ESM dist/openai-assistants/hooks/use-assistants.mjs.map 4.67 KB | ||
| ESM dist/openai-assistants/hooks/index.mjs.map 51.00 B | ||
| ESM dist/openai-assistants/hooks/use-copilot-chat-v2.mjs.map 51.00 B | ||
| ESM dist/components/copilot-provider/index.mjs.map 51.00 B | ||
| ESM ⚡️ Build success in 149ms | ||
| ESM ⚡️ Build success in 139ms | ||
| DTS Build start | ||
| DTS ⚡️ Build success in 2992ms | ||
| DTS dist/index.d.ts 1.61 KB | ||
| DTS ⚡️ Build success in 2854ms | ||
| DTS dist/index.d.ts 1.68 KB | ||
| DTS dist/components/copilot-provider/copilot-provider.d.ts 1.55 KB | ||
| DTS dist/components/copilot-provider/copilot-provider-props.d.ts 1.52 KB | ||
| DTS dist/context/copilot-context.d.ts 1.98 KB | ||
| DTS dist/hooks/use-copilot-chat.d.ts 955.00 B | ||
| DTS dist/hooks/use-copilot-chat.d.ts 1.08 KB | ||
| DTS dist/hooks/use-make-copilot-actionable.d.ts 255.00 B | ||
@@ -168,2 +168,3 @@ DTS dist/hooks/use-make-copilot-readable.d.ts 598.00 B | ||
| DTS dist/types/base.d.ts 1.96 KB | ||
| DTS dist/types/system-message.d.ts 132.00 B | ||
| DTS dist/openai-assistants/hooks/use-copilot-chat-v2.d.ts 1.41 KB | ||
@@ -174,13 +175,12 @@ DTS dist/openai-assistants/utils/process-message-stream.d.ts 196.00 B | ||
| DTS dist/hooks/use-tree.d.ts 543.00 B | ||
| DTS dist/context/index.d.ts 281.00 B | ||
| DTS dist/components/index.d.ts 482.00 B | ||
| DTS dist/hooks/index.d.ts 608.00 B | ||
| DTS dist/hooks/index.d.ts 645.00 B | ||
| DTS dist/hooks/use-flat-category-store.d.ts 424.00 B | ||
| DTS dist/context/index.d.ts 281.00 B | ||
| DTS dist/utils/utils.test.d.ts 12.00 B | ||
| DTS dist/utils/utils.d.ts 12.00 B | ||
| DTS dist/openai-assistants/index.d.ts 262.00 B | ||
| DTS dist/openai/chat-completion-client.d.ts 1.44 KB | ||
| DTS dist/openai/index.d.ts 438.00 B | ||
| DTS dist/openai-assistants/index.d.ts 262.00 B | ||
| DTS dist/types/index.d.ts 233.00 B | ||
| DTS dist/types/message.d.ts 12.00 B | ||
| DTS dist/utils/utils.test.d.ts 12.00 B | ||
| DTS dist/utils/utils.d.ts 12.00 B | ||
| DTS dist/types/index.d.ts 294.00 B | ||
| DTS dist/components/copilot-provider/index.d.ts 463.00 B | ||
@@ -187,0 +187,0 @@ DTS dist/components/copilot-provider/standard-copilot-api-config.d.ts 911.00 B |
+12
-1
| # ui | ||
| ## 0.18.0-alpha.1 | ||
| ### Minor Changes | ||
| - new sidebar ui | ||
| ### Patch Changes | ||
| - Updated dependencies | ||
| - @copilotkit/shared@0.2.0-alpha.0 | ||
| ## 0.18.0-alpha.0 | ||
@@ -7,3 +18,3 @@ | ||
| - propagate makeSystemMessage through CopilotSidebarUIProvider | ||
| - New Copilot ui | ||
@@ -10,0 +21,0 @@ ## 0.17.1 |
@@ -1,8 +0,8 @@ | ||
| export { CopilotProvider, defaultCopilotContextCategories } from '../../chunk-QTET3FBV.mjs'; | ||
| export { CopilotProvider, defaultCopilotContextCategories } from '../../chunk-D4NQCVHE.mjs'; | ||
| import '../../chunk-F2JIAPZQ.mjs'; | ||
| import '../../chunk-VUY2K2DI.mjs'; | ||
| import '../../chunk-YULKJPY3.mjs'; | ||
| import '../../chunk-6A4PCNMZ.mjs'; | ||
| import '../../chunk-YULKJPY3.mjs'; | ||
| import '../../chunk-MRXNTQOX.mjs'; | ||
| //# sourceMappingURL=out.js.map | ||
| //# sourceMappingURL=copilot-provider.mjs.map |
| import '../../chunk-SPCZTZCY.mjs'; | ||
| export { CopilotProvider, defaultCopilotContextCategories } from '../../chunk-QTET3FBV.mjs'; | ||
| export { CopilotProvider, defaultCopilotContextCategories } from '../../chunk-D4NQCVHE.mjs'; | ||
| import '../../chunk-F2JIAPZQ.mjs'; | ||
| import '../../chunk-VUY2K2DI.mjs'; | ||
| import '../../chunk-YULKJPY3.mjs'; | ||
| import '../../chunk-6A4PCNMZ.mjs'; | ||
| import '../../chunk-YULKJPY3.mjs'; | ||
| import '../../chunk-MRXNTQOX.mjs'; | ||
| //# sourceMappingURL=out.js.map | ||
| //# sourceMappingURL=index.mjs.map |
| import '../chunk-JD7BAH7U.mjs'; | ||
| import '../chunk-SPCZTZCY.mjs'; | ||
| export { CopilotProvider, defaultCopilotContextCategories } from '../chunk-QTET3FBV.mjs'; | ||
| export { CopilotProvider, defaultCopilotContextCategories } from '../chunk-D4NQCVHE.mjs'; | ||
| import '../chunk-F2JIAPZQ.mjs'; | ||
| import '../chunk-VUY2K2DI.mjs'; | ||
| import '../chunk-YULKJPY3.mjs'; | ||
| import '../chunk-6A4PCNMZ.mjs'; | ||
| import '../chunk-YULKJPY3.mjs'; | ||
| import '../chunk-MRXNTQOX.mjs'; | ||
| //# sourceMappingURL=out.js.map | ||
| //# sourceMappingURL=index.mjs.map |
@@ -7,2 +7,3 @@ export { UseCopilotChatOptions, UseCopilotChatReturn, useCopilotChat } from './use-copilot-chat.js'; | ||
| import '../types/base.js'; | ||
| import '../types/system-message.js'; | ||
| import '../context/copilot-context.js'; | ||
@@ -9,0 +10,0 @@ import '../types/annotated-function.js'; |
| import '../chunk-5UGLWBZJ.mjs'; | ||
| export { useMakeCopilotActionable } from '../chunk-FP4EXCGS.mjs'; | ||
| export { useMakeCopilotDocumentReadable } from '../chunk-7P4OYNP3.mjs'; | ||
| export { useMakeCopilotReadable } from '../chunk-HW5IH6PV.mjs'; | ||
| export { useCopilotChat } from '../chunk-SFQOMKM2.mjs'; | ||
| export { useCopilotChat } from '../chunk-FY7XNRJP.mjs'; | ||
| import '../chunk-JD7BAH7U.mjs'; | ||
| import '../chunk-SPCZTZCY.mjs'; | ||
| import '../chunk-QTET3FBV.mjs'; | ||
| import '../chunk-D4NQCVHE.mjs'; | ||
| import '../chunk-F2JIAPZQ.mjs'; | ||
| import '../chunk-VUY2K2DI.mjs'; | ||
| import '../chunk-6A4PCNMZ.mjs'; | ||
| import '../chunk-LMZN4NSM.mjs'; | ||
@@ -16,4 +13,7 @@ import '../chunk-TKXPMMND.mjs'; | ||
| import '../chunk-YULKJPY3.mjs'; | ||
| export { useMakeCopilotActionable } from '../chunk-FP4EXCGS.mjs'; | ||
| export { useMakeCopilotDocumentReadable } from '../chunk-7P4OYNP3.mjs'; | ||
| import '../chunk-6A4PCNMZ.mjs'; | ||
| import '../chunk-MRXNTQOX.mjs'; | ||
| //# sourceMappingURL=out.js.map | ||
| //# sourceMappingURL=index.mjs.map |
| import { Message } from '../types/base.js'; | ||
| import { SystemMessageFunction } from '../types/system-message.js'; | ||
| import { UseChatOptions } from './use-chat.js'; | ||
@@ -11,3 +12,4 @@ import '../context/copilot-context.js'; | ||
| interface UseCopilotChatOptions extends UseChatOptions { | ||
| makeSystemMessage?: (contextString: string) => string; | ||
| makeSystemMessage?: SystemMessageFunction; | ||
| additionalInstructions?: string; | ||
| } | ||
@@ -23,5 +25,5 @@ interface UseCopilotChatReturn { | ||
| } | ||
| declare function useCopilotChat({ makeSystemMessage, ...options }: UseCopilotChatOptions): UseCopilotChatReturn; | ||
| declare function defaultSystemMessage(contextString: string): string; | ||
| declare function useCopilotChat({ makeSystemMessage, additionalInstructions, ...options }: UseCopilotChatOptions): UseCopilotChatReturn; | ||
| declare function defaultSystemMessage(contextString: string, additionalInstructions?: string): string; | ||
| export { UseCopilotChatOptions, UseCopilotChatReturn, defaultSystemMessage, useCopilotChat }; |
@@ -1,8 +0,7 @@ | ||
| export { defaultSystemMessage, useCopilotChat } from '../chunk-SFQOMKM2.mjs'; | ||
| export { defaultSystemMessage, useCopilotChat } from '../chunk-FY7XNRJP.mjs'; | ||
| import '../chunk-JD7BAH7U.mjs'; | ||
| import '../chunk-SPCZTZCY.mjs'; | ||
| import '../chunk-QTET3FBV.mjs'; | ||
| import '../chunk-D4NQCVHE.mjs'; | ||
| import '../chunk-F2JIAPZQ.mjs'; | ||
| import '../chunk-VUY2K2DI.mjs'; | ||
| import '../chunk-6A4PCNMZ.mjs'; | ||
| import '../chunk-LMZN4NSM.mjs'; | ||
@@ -12,4 +11,5 @@ import '../chunk-TKXPMMND.mjs'; | ||
| import '../chunk-YULKJPY3.mjs'; | ||
| import '../chunk-6A4PCNMZ.mjs'; | ||
| import '../chunk-MRXNTQOX.mjs'; | ||
| //# sourceMappingURL=out.js.map | ||
| //# sourceMappingURL=use-copilot-chat.mjs.map |
+1
-0
@@ -12,2 +12,3 @@ export { CopilotProvider, defaultCopilotContextCategories } from './components/copilot-provider/copilot-provider.js'; | ||
| export { Function, FunctionCall, FunctionCallHandler, Message, Role } from './types/base.js'; | ||
| export { SystemMessageFunction } from './types/system-message.js'; | ||
| export { AssistantStatus, RequestForwardingOptions, UseCopilotChatOptionsV2, UseCopilotChatV2Result, useCopilotChatV2 } from './openai-assistants/hooks/use-copilot-chat-v2.js'; | ||
@@ -14,0 +15,0 @@ export { processMessageStream } from './openai-assistants/utils/process-message-stream.js'; |
+9
-9
@@ -0,21 +1,18 @@ | ||
| import './chunk-PUFR5OAI.mjs'; | ||
| export { ChatCompletionStream } from './chunk-6SOQYBNX.mjs'; | ||
| import './chunk-EFZPSZWO.mjs'; | ||
| import './chunk-7GFKOIO7.mjs'; | ||
| import './chunk-BABVSMJR.mjs'; | ||
| export { useCopilotChatV2 } from './chunk-TU4DNDO7.mjs'; | ||
| export { useCopilotChatV2 } from './chunk-P34OLW2N.mjs'; | ||
| import './chunk-FRAKUJWH.mjs'; | ||
| export { processMessageStream } from './chunk-MZ5UN3BY.mjs'; | ||
| import './chunk-EFZPSZWO.mjs'; | ||
| import './chunk-PUFR5OAI.mjs'; | ||
| export { ChatCompletionStream } from './chunk-6SOQYBNX.mjs'; | ||
| import './chunk-VNRDQJXW.mjs'; | ||
| import './chunk-5UGLWBZJ.mjs'; | ||
| export { useMakeCopilotActionable } from './chunk-FP4EXCGS.mjs'; | ||
| export { useMakeCopilotDocumentReadable } from './chunk-7P4OYNP3.mjs'; | ||
| export { useMakeCopilotReadable } from './chunk-HW5IH6PV.mjs'; | ||
| export { useCopilotChat } from './chunk-SFQOMKM2.mjs'; | ||
| export { useCopilotChat } from './chunk-FY7XNRJP.mjs'; | ||
| import './chunk-JD7BAH7U.mjs'; | ||
| import './chunk-SPCZTZCY.mjs'; | ||
| export { CopilotProvider, defaultCopilotContextCategories } from './chunk-QTET3FBV.mjs'; | ||
| export { CopilotProvider, defaultCopilotContextCategories } from './chunk-D4NQCVHE.mjs'; | ||
| import './chunk-F2JIAPZQ.mjs'; | ||
| import './chunk-VUY2K2DI.mjs'; | ||
| export { CopilotContext } from './chunk-6A4PCNMZ.mjs'; | ||
| import './chunk-LMZN4NSM.mjs'; | ||
@@ -25,4 +22,7 @@ import './chunk-TKXPMMND.mjs'; | ||
| import './chunk-YULKJPY3.mjs'; | ||
| export { useMakeCopilotActionable } from './chunk-FP4EXCGS.mjs'; | ||
| export { useMakeCopilotDocumentReadable } from './chunk-7P4OYNP3.mjs'; | ||
| export { CopilotContext } from './chunk-6A4PCNMZ.mjs'; | ||
| import './chunk-MRXNTQOX.mjs'; | ||
| //# sourceMappingURL=out.js.map | ||
| //# sourceMappingURL=index.mjs.map |
| import '../../chunk-BABVSMJR.mjs'; | ||
| export { useCopilotChatV2 } from '../../chunk-TU4DNDO7.mjs'; | ||
| export { useCopilotChatV2 } from '../../chunk-P34OLW2N.mjs'; | ||
| import '../../chunk-FRAKUJWH.mjs'; | ||
@@ -8,9 +8,9 @@ import '../../chunk-MZ5UN3BY.mjs'; | ||
| import '../../chunk-SPCZTZCY.mjs'; | ||
| import '../../chunk-QTET3FBV.mjs'; | ||
| import '../../chunk-D4NQCVHE.mjs'; | ||
| import '../../chunk-F2JIAPZQ.mjs'; | ||
| import '../../chunk-VUY2K2DI.mjs'; | ||
| import '../../chunk-YULKJPY3.mjs'; | ||
| import '../../chunk-6A4PCNMZ.mjs'; | ||
| import '../../chunk-YULKJPY3.mjs'; | ||
| import '../../chunk-MRXNTQOX.mjs'; | ||
| //# sourceMappingURL=out.js.map | ||
| //# sourceMappingURL=index.mjs.map |
@@ -1,2 +0,2 @@ | ||
| export { defaultSystemMessage, useCopilotChatV2 } from '../../chunk-TU4DNDO7.mjs'; | ||
| export { defaultSystemMessage, useCopilotChatV2 } from '../../chunk-P34OLW2N.mjs'; | ||
| import '../../chunk-FRAKUJWH.mjs'; | ||
@@ -7,9 +7,9 @@ import '../../chunk-MZ5UN3BY.mjs'; | ||
| import '../../chunk-SPCZTZCY.mjs'; | ||
| import '../../chunk-QTET3FBV.mjs'; | ||
| import '../../chunk-D4NQCVHE.mjs'; | ||
| import '../../chunk-F2JIAPZQ.mjs'; | ||
| import '../../chunk-VUY2K2DI.mjs'; | ||
| import '../../chunk-YULKJPY3.mjs'; | ||
| import '../../chunk-6A4PCNMZ.mjs'; | ||
| import '../../chunk-YULKJPY3.mjs'; | ||
| import '../../chunk-MRXNTQOX.mjs'; | ||
| //# sourceMappingURL=out.js.map | ||
| //# sourceMappingURL=use-copilot-chat-v2.mjs.map |
| import '../chunk-7GFKOIO7.mjs'; | ||
| import '../chunk-BABVSMJR.mjs'; | ||
| export { useCopilotChatV2 } from '../chunk-TU4DNDO7.mjs'; | ||
| export { useCopilotChatV2 } from '../chunk-P34OLW2N.mjs'; | ||
| import '../chunk-FRAKUJWH.mjs'; | ||
@@ -9,9 +9,9 @@ export { processMessageStream } from '../chunk-MZ5UN3BY.mjs'; | ||
| import '../chunk-SPCZTZCY.mjs'; | ||
| import '../chunk-QTET3FBV.mjs'; | ||
| import '../chunk-D4NQCVHE.mjs'; | ||
| import '../chunk-F2JIAPZQ.mjs'; | ||
| import '../chunk-VUY2K2DI.mjs'; | ||
| import '../chunk-YULKJPY3.mjs'; | ||
| import '../chunk-6A4PCNMZ.mjs'; | ||
| import '../chunk-YULKJPY3.mjs'; | ||
| import '../chunk-MRXNTQOX.mjs'; | ||
| //# sourceMappingURL=out.js.map | ||
| //# sourceMappingURL=index.mjs.map |
| export { AnnotatedFunction, AnnotatedFunctionArgument } from './annotated-function.js'; | ||
| export { DocumentPointer } from './document-pointer.js'; | ||
| export { Function, FunctionCall, FunctionCallHandler, Message, Role } from './base.js'; | ||
| export { SystemMessageFunction } from './system-message.js'; |
+4
-4
@@ -7,3 +7,3 @@ { | ||
| }, | ||
| "version": "0.18.0-alpha.0", | ||
| "version": "0.18.0-alpha.1", | ||
| "sideEffects": false, | ||
@@ -27,4 +27,4 @@ "main": "./dist/index.js", | ||
| "typescript": "^5.1.3", | ||
| "eslint-config-custom": "0.2.0", | ||
| "tsconfig": "0.6.0" | ||
| "tsconfig": "0.7.0-alpha.0", | ||
| "eslint-config-custom": "0.3.0-alpha.0" | ||
| }, | ||
@@ -35,3 +35,3 @@ "dependencies": { | ||
| "openai": "^4.6.0", | ||
| "@copilotkit/shared": "0.1.1" | ||
| "@copilotkit/shared": "0.2.0-alpha.0" | ||
| }, | ||
@@ -38,0 +38,0 @@ "scripts": { |
| import { useMemo, useContext } from "react"; | ||
| import { CopilotContext, CopilotContextParams } from "../context/copilot-context"; | ||
| import { Message } from "../types"; | ||
| import { Message, SystemMessageFunction } from "../types"; | ||
| import { UseChatOptions, useChat } from "./use-chat"; | ||
@@ -9,3 +9,4 @@ import { defaultCopilotContextCategories } from "../components"; | ||
| export interface UseCopilotChatOptions extends UseChatOptions { | ||
| makeSystemMessage?: (contextString: string) => string; | ||
| makeSystemMessage?: SystemMessageFunction; | ||
| additionalInstructions?: string; | ||
| } | ||
@@ -25,2 +26,3 @@ | ||
| makeSystemMessage, | ||
| additionalInstructions, | ||
| ...options | ||
@@ -41,3 +43,3 @@ }: UseCopilotChatOptions): UseCopilotChatReturn { | ||
| id: "system", | ||
| content: systemMessageMaker(contextString), | ||
| content: systemMessageMaker(contextString, additionalInstructions), | ||
| role: "system", | ||
@@ -79,4 +81,8 @@ }; | ||
| export function defaultSystemMessage(contextString: string): string { | ||
| return ` | ||
| export function defaultSystemMessage( | ||
| contextString: string, | ||
| additionalInstructions?: string, | ||
| ): string { | ||
| return ( | ||
| ` | ||
| Please act as an efficient, competent, conscientious, and industrious professional assistant. | ||
@@ -99,3 +105,4 @@ | ||
| If you would like to call a function, call it without saying anything else. | ||
| `; | ||
| ` + (additionalInstructions ? `\n\n${additionalInstructions}` : "") | ||
| ); | ||
| } |
@@ -5,1 +5,2 @@ export type { AnnotatedFunctionArgument } from "./annotated-function"; | ||
| export type { Role, Message, Function, FunctionCall, FunctionCallHandler } from "./base"; | ||
| export type { SystemMessageFunction } from "./system-message"; |
| import { StandardCopilotApiConfig } from './chunk-F2JIAPZQ.mjs'; | ||
| import { use_tree_default } from './chunk-VUY2K2DI.mjs'; | ||
| import { CopilotContext } from './chunk-6A4PCNMZ.mjs'; | ||
| import { use_flat_category_store_default } from './chunk-YULKJPY3.mjs'; | ||
| import { __objRest, __spreadProps, __spreadValues, __async } from './chunk-MRXNTQOX.mjs'; | ||
| import { useState, useCallback } from 'react'; | ||
| import { jsx } from 'react/jsx-runtime'; | ||
| function CopilotProvider(_a) { | ||
| var _b = _a, { children } = _b, props = __objRest(_b, ["children"]); | ||
| const [entryPoints, setEntryPoints] = useState({}); | ||
| const { addElement, removeElement, printTree } = use_tree_default(); | ||
| const { | ||
| addElement: addDocument, | ||
| removeElement: removeDocument, | ||
| allElements: allDocuments | ||
| } = use_flat_category_store_default(); | ||
| const setEntryPoint = useCallback((id, entryPoint) => { | ||
| setEntryPoints((prevPoints) => { | ||
| return __spreadProps(__spreadValues({}, prevPoints), { | ||
| [id]: entryPoint | ||
| }); | ||
| }); | ||
| }, []); | ||
| const removeEntryPoint = useCallback((id) => { | ||
| setEntryPoints((prevPoints) => { | ||
| const newPoints = __spreadValues({}, prevPoints); | ||
| delete newPoints[id]; | ||
| return newPoints; | ||
| }); | ||
| }, []); | ||
| const getContextString = useCallback( | ||
| (documents, categories) => { | ||
| const documentsString = documents.map((document) => { | ||
| return `${document.name} (${document.sourceApplication}): | ||
| ${document.getContents()}`; | ||
| }).join("\n\n"); | ||
| const nonDocumentStrings = printTree(categories); | ||
| return `${documentsString} | ||
| ${nonDocumentStrings}`; | ||
| }, | ||
| [printTree] | ||
| ); | ||
| const addContext = useCallback( | ||
| (context, parentId, categories = defaultCopilotContextCategories) => { | ||
| return addElement(context, categories, parentId); | ||
| }, | ||
| [addElement] | ||
| ); | ||
| const removeContext = useCallback( | ||
| (id) => { | ||
| removeElement(id); | ||
| }, | ||
| [removeElement] | ||
| ); | ||
| const getChatCompletionFunctionDescriptions = useCallback(() => { | ||
| return entryPointsToChatCompletionFunctions(Object.values(entryPoints)); | ||
| }, [entryPoints]); | ||
| const getFunctionCallHandler = useCallback(() => { | ||
| return entryPointsToFunctionCallHandler(Object.values(entryPoints)); | ||
| }, [entryPoints]); | ||
| const getDocumentsContext = useCallback( | ||
| (categories) => { | ||
| return allDocuments(categories); | ||
| }, | ||
| [allDocuments] | ||
| ); | ||
| const addDocumentContext = useCallback( | ||
| (documentPointer, categories = defaultCopilotContextCategories) => { | ||
| return addDocument(documentPointer, categories); | ||
| }, | ||
| [addDocument] | ||
| ); | ||
| const removeDocumentContext = useCallback( | ||
| (documentId) => { | ||
| removeDocument(documentId); | ||
| }, | ||
| [removeDocument] | ||
| ); | ||
| let copilotApiConfig; | ||
| if ("chatApiEndpoint" in props) { | ||
| copilotApiConfig = new StandardCopilotApiConfig( | ||
| props.chatApiEndpoint, | ||
| props.chatApiEndpointV2 || `${props.chatApiEndpoint}/v2`, | ||
| {}, | ||
| {} | ||
| ); | ||
| } else { | ||
| copilotApiConfig = props.chatApiConfig; | ||
| } | ||
| return /* @__PURE__ */ jsx( | ||
| CopilotContext.Provider, | ||
| { | ||
| value: { | ||
| entryPoints, | ||
| getChatCompletionFunctionDescriptions, | ||
| getFunctionCallHandler, | ||
| setEntryPoint, | ||
| removeEntryPoint, | ||
| getContextString, | ||
| addContext, | ||
| removeContext, | ||
| getDocumentsContext, | ||
| addDocumentContext, | ||
| removeDocumentContext, | ||
| copilotApiConfig | ||
| }, | ||
| children | ||
| } | ||
| ); | ||
| } | ||
| var defaultCopilotContextCategories = ["global"]; | ||
| function entryPointsToFunctionCallHandler(entryPoints) { | ||
| return (chatMessages, functionCall) => __async(this, null, function* () { | ||
| let entrypointsByFunctionName = {}; | ||
| for (let entryPoint of entryPoints) { | ||
| entrypointsByFunctionName[entryPoint.name] = entryPoint; | ||
| } | ||
| const entryPointFunction = entrypointsByFunctionName[functionCall.name || ""]; | ||
| if (entryPointFunction) { | ||
| let functionCallArguments = []; | ||
| if (functionCall.arguments) { | ||
| functionCallArguments = JSON.parse(functionCall.arguments); | ||
| } | ||
| const paramsInCorrectOrder = []; | ||
| for (let arg of entryPointFunction.argumentAnnotations) { | ||
| paramsInCorrectOrder.push( | ||
| functionCallArguments[arg.name] | ||
| ); | ||
| } | ||
| yield entryPointFunction.implementation(...paramsInCorrectOrder); | ||
| } | ||
| }); | ||
| } | ||
| function entryPointsToChatCompletionFunctions(entryPoints) { | ||
| return entryPoints.map(annotatedFunctionToChatCompletionFunction); | ||
| } | ||
| function annotatedFunctionToChatCompletionFunction(annotatedFunction) { | ||
| let parameters = {}; | ||
| for (let arg of annotatedFunction.argumentAnnotations) { | ||
| let _a = arg, forwardedArgs = __objRest(_a, ["name", "required"]); | ||
| parameters[arg.name] = forwardedArgs; | ||
| } | ||
| let requiredParameterNames = []; | ||
| for (let arg of annotatedFunction.argumentAnnotations) { | ||
| if (arg.required) { | ||
| requiredParameterNames.push(arg.name); | ||
| } | ||
| } | ||
| let chatCompletionFunction = { | ||
| name: annotatedFunction.name, | ||
| description: annotatedFunction.description, | ||
| parameters: { | ||
| type: "object", | ||
| properties: parameters, | ||
| required: requiredParameterNames | ||
| } | ||
| }; | ||
| return chatCompletionFunction; | ||
| } | ||
| export { CopilotProvider, defaultCopilotContextCategories }; | ||
| //# sourceMappingURL=out.js.map | ||
| //# sourceMappingURL=chunk-QTET3FBV.mjs.map |
| {"version":3,"sources":["../src/components/copilot-provider/copilot-provider.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAEA,SAAS,aAAa,gBAAgB;AA0JlC;AA3GG,SAAS,gBAAgB,IAA2D;AAA3D,eAAE,WAjDlC,IAiDgC,IAAe,kBAAf,IAAe,CAAb;AAIhC,QAAM,CAAC,aAAa,cAAc,IAAI,SAAmD,CAAC,CAAC;AAE3F,QAAM,EAAE,YAAY,eAAe,UAAU,IAAI,iBAAQ;AAEzD,QAAM;AAAA,IACJ,YAAY;AAAA,IACZ,eAAe;AAAA,IACf,aAAa;AAAA,EACf,IAAI,gCAAsC;AAE1C,QAAM,gBAAgB,YAAY,CAAC,IAAY,eAAyC;AACtF,mBAAe,CAAC,eAAe;AAC7B,aAAO,iCACF,aADE;AAAA,QAEL,CAAC,EAAE,GAAG;AAAA,MACR;AAAA,IACF,CAAC;AAAA,EACH,GAAG,CAAC,CAAC;AAEL,QAAM,mBAAmB,YAAY,CAAC,OAAe;AACnD,mBAAe,CAAC,eAAe;AAC7B,YAAM,YAAY,mBAAK;AACvB,aAAO,UAAU,EAAE;AACnB,aAAO;AAAA,IACT,CAAC;AAAA,EACH,GAAG,CAAC,CAAC;AAEL,QAAM,mBAAmB;AAAA,IACvB,CAAC,WAA8B,eAAyB;AACtD,YAAM,kBAAkB,UACrB,IAAI,CAAC,aAAa;AACjB,eAAO,GAAG,SAAS,SAAS,SAAS;AAAA,EAAwB,SAAS,YAAY;AAAA,MACpF,CAAC,EACA,KAAK,MAAM;AAEd,YAAM,qBAAqB,UAAU,UAAU;AAE/C,aAAO,GAAG;AAAA;AAAA,EAAsB;AAAA,IAClC;AAAA,IACA,C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;AAEA,SAAO;AACT","sourcesContent":["\"use client\";\n\nimport { useCallback, useState } from \"react\";\nimport { CopilotContext, CopilotApiConfig } from \"../../context/copilot-context\";\nimport useTree from \"../../hooks/use-tree\";\nimport { AnnotatedFunction } from \"../../types/annotated-function\";\nimport { ChatCompletionCreateParams } from \"openai/resources/chat\";\nimport { DocumentPointer, FunctionCallHandler } from \"../../types\";\nimport useFlatCategoryStore from \"../../hooks/use-flat-category-store\";\nimport { StandardCopilotApiConfig } from \"./standard-copilot-api-config\";\nimport { CopilotProviderProps } from \"./copilot-provider-props\";\n\n/**\n * The CopilotProvider 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 * <CopilotProvider chatApiEndpoint=\"https://your.copilotkit.api\">\n * <App />\n * </CopilotProvider>\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 * <CopilotProvider chatApiConfig={copilotApiConfig}>\n * <App />\n * </CopilotProvider>\n * ```\n *\n * @param props - The props for the component.\n * @returns The CopilotProvider component.\n */\nexport function CopilotProvider({ children, ...props }: CopilotProviderProps): JSX.Element {\n // Compute all the functions and properties that we need to pass\n // to the CopilotContext.\n\n const [entryPoints, setEntryPoints] = useState<Record<string, AnnotatedFunction<any[]>>>({});\n\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: AnnotatedFunction<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 return entryPointsToChatCompletionFunctions(Object.values(entryPoints));\n }, [entryPoints]);\n\n const getFunctionCallHandler = useCallback(() => {\n return entryPointsToFunctionCallHandler(Object.values(entryPoints));\n }, [entryPoints]);\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 let copilotApiConfig: CopilotApiConfig;\n if (\"chatApiEndpoint\" in props) {\n copilotApiConfig = new StandardCopilotApiConfig(\n props.chatApiEndpoint,\n props.chatApiEndpointV2 || `${props.chatApiEndpoint}/v2`,\n {},\n {},\n );\n } else {\n copilotApiConfig = props.chatApiConfig;\n }\n\n return (\n <CopilotContext.Provider\n value={{\n entryPoints,\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 entryPointsToFunctionCallHandler(\n entryPoints: AnnotatedFunction<any[]>[],\n): FunctionCallHandler {\n return async (chatMessages, functionCall) => {\n let entrypointsByFunctionName: Record<string, AnnotatedFunction<any[]>> = {};\n for (let entryPoint of entryPoints) {\n entrypointsByFunctionName[entryPoint.name] = entryPoint;\n }\n\n const entryPointFunction = entrypointsByFunctionName[functionCall.name || \"\"];\n if (entryPointFunction) {\n let functionCallArguments: Record<string, any>[] = [];\n if (functionCall.arguments) {\n functionCallArguments = JSON.parse(functionCall.arguments);\n }\n\n const paramsInCorrectOrder: any[] = [];\n for (let arg of entryPointFunction.argumentAnnotations) {\n paramsInCorrectOrder.push(\n functionCallArguments[arg.name as keyof typeof functionCallArguments],\n );\n }\n\n await entryPointFunction.implementation(...paramsInCorrectOrder);\n\n // commented out becasue for now we don't want to return anything\n // const result = await entryPointFunction.implementation(\n // ...parsedFunctionCallArguments\n // );\n // const functionResponse: ChatRequest = {\n // messages: [\n // ...chatMessages,\n // {\n // id: nanoid(),\n // name: functionCall.name,\n // role: 'function' as const,\n // content: JSON.stringify(result),\n // },\n // ],\n // };\n\n // return functionResponse;\n }\n };\n}\n\nfunction entryPointsToChatCompletionFunctions(\n entryPoints: AnnotatedFunction<any[]>[],\n): ChatCompletionCreateParams.Function[] {\n return entryPoints.map(annotatedFunctionToChatCompletionFunction);\n}\n\nfunction annotatedFunctionToChatCompletionFunction(\n annotatedFunction: AnnotatedFunction<any[]>,\n): ChatCompletionCreateParams.Function {\n // Create the parameters object based on the argumentAnnotations\n let parameters: { [key: string]: any } = {};\n for (let arg of annotatedFunction.argumentAnnotations) {\n // isolate the args we should forward inline\n let { name, required, ...forwardedArgs } = arg;\n parameters[arg.name] = forwardedArgs;\n }\n\n let requiredParameterNames: string[] = [];\n for (let arg of annotatedFunction.argumentAnnotations) {\n if (arg.required) {\n requiredParameterNames.push(arg.name);\n }\n }\n\n // Create the ChatCompletionFunctions object\n let chatCompletionFunction: ChatCompletionCreateParams.Function = {\n name: annotatedFunction.name,\n description: annotatedFunction.description,\n parameters: {\n type: \"object\",\n properties: parameters,\n required: requiredParameterNames,\n },\n };\n\n return chatCompletionFunction;\n}\n"]} |
| import { defaultCopilotContextCategories } from './chunk-QTET3FBV.mjs'; | ||
| import { CopilotContext } from './chunk-6A4PCNMZ.mjs'; | ||
| import { useChat } from './chunk-LMZN4NSM.mjs'; | ||
| import { __objRest, __spreadProps, __spreadValues } from './chunk-MRXNTQOX.mjs'; | ||
| import { useContext, useMemo } from 'react'; | ||
| function useCopilotChat(_a) { | ||
| var _b = _a, { | ||
| makeSystemMessage | ||
| } = _b, options = __objRest(_b, [ | ||
| "makeSystemMessage" | ||
| ]); | ||
| const { | ||
| getContextString, | ||
| getChatCompletionFunctionDescriptions, | ||
| getFunctionCallHandler, | ||
| copilotApiConfig | ||
| } = useContext(CopilotContext); | ||
| const systemMessage = useMemo(() => { | ||
| const systemMessageMaker = makeSystemMessage || defaultSystemMessage; | ||
| const contextString = getContextString([], defaultCopilotContextCategories); | ||
| return { | ||
| id: "system", | ||
| content: systemMessageMaker(contextString), | ||
| role: "system" | ||
| }; | ||
| }, [getContextString, makeSystemMessage]); | ||
| const functionDescriptions = useMemo(() => { | ||
| return getChatCompletionFunctionDescriptions(); | ||
| }, [getChatCompletionFunctionDescriptions]); | ||
| const { messages, append, reload, stop, isLoading, input, setInput } = useChat(__spreadProps(__spreadValues({}, options), { | ||
| copilotConfig: copilotApiConfig, | ||
| id: options.id, | ||
| initialMessages: [systemMessage].concat(options.initialMessages || []), | ||
| functions: functionDescriptions, | ||
| onFunctionCall: getFunctionCallHandler(), | ||
| headers: __spreadValues({}, options.headers), | ||
| body: __spreadValues({}, options.body) | ||
| })); | ||
| const visibleMessages = messages.filter( | ||
| (message) => message.role === "user" || message.role === "assistant" | ||
| ); | ||
| return { | ||
| visibleMessages, | ||
| append, | ||
| reload, | ||
| stop, | ||
| isLoading, | ||
| input, | ||
| setInput | ||
| }; | ||
| } | ||
| function defaultSystemMessage(contextString) { | ||
| return ` | ||
| Please act as an efficient, competent, conscientious, and industrious professional assistant. | ||
| Help the user achieve their goals, and you do so in a way that is as efficient as possible, without unnecessary fluff, but also without sacrificing professionalism. | ||
| Always be polite and respectful, and prefer brevity over verbosity. | ||
| The user has provided you with the following context: | ||
| \`\`\` | ||
| ${contextString} | ||
| \`\`\` | ||
| They have also provided you with functions you can call to initiate actions on their behalf, or functions you can call to receive more information. | ||
| Please assist them as best you can. | ||
| You 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. | ||
| If you would like to call a function, call it without saying anything else. | ||
| `; | ||
| } | ||
| export { defaultSystemMessage, useCopilotChat }; | ||
| //# sourceMappingURL=out.js.map | ||
| //# sourceMappingURL=chunk-SFQOMKM2.mjs.map |
| {"version":3,"sources":["../src/hooks/use-copilot-chat.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,SAAS,SAAS,kBAAkB;AAqB7B,SAAS,eAAe,IAGiB;AAHjB,eAC7B;AAAA;AAAA,EAtBF,IAqB+B,IAE1B,oBAF0B,IAE1B;AAAA,IADH;AAAA;AAGA,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI,WAAW,cAAc;AAE7B,QAAM,gBAAyB,QAAQ,MAAM;AAC3C,UAAM,qBAAqB,qBAAqB;AAChD,UAAM,gBAAgB,iBAAiB,CAAC,GAAG,+BAA+B;AAE1E,WAAO;AAAA,MACL,IAAI;AAAA,MACJ,SAAS,mBAAmB,aAAa;AAAA,MACzC,MAAM;AAAA,IACR;AAAA,EACF,GAAG,CAAC,kBAAkB,iBAAiB,CAAC;AAExC,QAAM,uBAA8D,QAAQ,MAAM;AAChF,WAAO,sCAAsC;AAAA,EAC/C,GAAG,CAAC,qCAAqC,CAAC;AAE1C,QAAM,EAAE,UAAU,QAAQ,QAAQ,MAAM,WAAW,OAAO,SAAS,IAAI,QAAQ,iCAC1E,UAD0E;AAAA,IAE7E,eAAe;AAAA,IACf,IAAI,QAAQ;AAAA,IACZ,iBAAiB,CAAC,aAAa,EAAE,OAAO,QAAQ,mBAAmB,CAAC,CAAC;AAAA,IACrE,WAAW;AAAA,IACX,gBAAgB,uBAAuB;AAAA,IACvC,SAAS,mBAAK,QAAQ;AAAA,IACtB,MAAM,mBACD,QAAQ;AAAA,EAEf,EAAC;AAED,QAAM,kBAAkB,SAAS;AAAA,IAC/B,CAAC,YAAY,QAAQ,SAAS,UAAU,QAAQ,SAAS;AAAA,EAC3D;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAEO,SAAS,qBAAqB,eAA+B;AAClE,SAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQP;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAWF","sourcesContent":["import { useMemo, useContext } from \"react\";\nimport { CopilotContext, CopilotContextParams } from \"../context/copilot-context\";\nimport { Message } from \"../types\";\nimport { UseChatOptions, useChat } from \"./use-chat\";\nimport { defaultCopilotContextCategories } from \"../components\";\nimport { ChatCompletionCreateParams } from \"openai/resources/chat\";\n\nexport interface UseCopilotChatOptions extends UseChatOptions {\n makeSystemMessage?: (contextString: string) => string;\n}\n\nexport interface UseCopilotChatReturn {\n visibleMessages: Message[];\n append: (message: Message) => Promise<void>;\n reload: () => Promise<void>;\n stop: () => void;\n isLoading: boolean;\n input: string;\n setInput: React.Dispatch<React.SetStateAction<string>>;\n}\n\nexport function useCopilotChat({\n makeSystemMessage,\n ...options\n}: UseCopilotChatOptions): UseCopilotChatReturn {\n const {\n getContextString,\n getChatCompletionFunctionDescriptions,\n getFunctionCallHandler,\n copilotApiConfig,\n } = useContext(CopilotContext);\n\n const systemMessage: Message = useMemo(() => {\n const systemMessageMaker = 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, makeSystemMessage]);\n\n const functionDescriptions: ChatCompletionCreateParams.Function[] = useMemo(() => {\n return getChatCompletionFunctionDescriptions();\n }, [getChatCompletionFunctionDescriptions]);\n\n const { messages, append, reload, stop, isLoading, input, setInput } = useChat({\n ...options,\n copilotConfig: copilotApiConfig,\n id: options.id,\n initialMessages: [systemMessage].concat(options.initialMessages || []),\n functions: functionDescriptions,\n onFunctionCall: getFunctionCallHandler(),\n headers: { ...options.headers },\n body: {\n ...options.body,\n },\n });\n\n const visibleMessages = messages.filter(\n (message) => message.role === \"user\" || message.role === \"assistant\",\n );\n\n return {\n visibleMessages,\n append,\n reload,\n stop,\n isLoading,\n input,\n setInput,\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"]} |
| import { processMessageStream } from './chunk-MZ5UN3BY.mjs'; | ||
| import { defaultCopilotContextCategories } from './chunk-QTET3FBV.mjs'; | ||
| import { CopilotContext } from './chunk-6A4PCNMZ.mjs'; | ||
| import { __async, __spreadValues } from './chunk-MRXNTQOX.mjs'; | ||
| import { useContext, useState, useMemo } from 'react'; | ||
| import { parseStreamPart } from '@copilotkit/shared'; | ||
| function useCopilotChatV2(options) { | ||
| const { | ||
| getContextString, | ||
| getChatCompletionFunctionDescriptions, | ||
| getFunctionCallHandler, | ||
| copilotApiConfig | ||
| } = useContext(CopilotContext); | ||
| const [messages, setMessages] = useState([]); | ||
| const [input, setInput] = useState(""); | ||
| const [threadId, setThreadId] = useState(void 0); | ||
| const [status, setStatus] = useState("awaiting_message"); | ||
| const [error, setError] = useState(void 0); | ||
| useMemo(() => { | ||
| const systemMessageMaker = options.makeSystemMessage || defaultSystemMessage; | ||
| const contextString = getContextString([], defaultCopilotContextCategories); | ||
| return { | ||
| id: "system", | ||
| content: systemMessageMaker(contextString), | ||
| role: "system" | ||
| }; | ||
| }, [getContextString, options.makeSystemMessage]); | ||
| const handleInputChange = (e) => { | ||
| setInput(e.target.value); | ||
| }; | ||
| const submitMessage = (e) => __async(this, null, function* () { | ||
| var _a, _b; | ||
| e.preventDefault(); | ||
| if (input === "") { | ||
| return; | ||
| } | ||
| setStatus("in_progress"); | ||
| setMessages((messages2) => [...messages2, { id: "", role: "user", content: input }]); | ||
| setInput(""); | ||
| const apiUrl = copilotApiConfig.chatApiEndpointV2; | ||
| const functions = getChatCompletionFunctionDescriptions(); | ||
| const result = yield fetch(apiUrl, { | ||
| method: "POST", | ||
| headers: __spreadValues(__spreadValues({ | ||
| "Content-Type": "application/json" | ||
| }, copilotApiConfig.headers), options.headers), | ||
| body: JSON.stringify(__spreadValues(__spreadValues(__spreadValues({ | ||
| // always use user-provided threadId when available: | ||
| threadId: (_b = (_a = options.threadId) != null ? _a : threadId) != null ? _b : null, | ||
| message: input | ||
| }, functions.length > 0 && { functions }), copilotApiConfig.body), options.body)) | ||
| }); | ||
| if (result.body == null) { | ||
| throw new Error("The response body is empty."); | ||
| } | ||
| yield processMessageStream(result.body.getReader(), (message) => { | ||
| try { | ||
| const { type, value } = parseStreamPart(message); | ||
| switch (type) { | ||
| case "assistant_message": { | ||
| setMessages((messages2) => [ | ||
| ...messages2, | ||
| { | ||
| id: value.id, | ||
| role: value.role, | ||
| content: value.content[0].text.value | ||
| } | ||
| ]); | ||
| break; | ||
| } | ||
| case "assistant_control_data": { | ||
| setThreadId(value.threadId); | ||
| setMessages((messages2) => { | ||
| const lastMessage = messages2[messages2.length - 1]; | ||
| lastMessage.id = value.messageId; | ||
| return [...messages2.slice(0, messages2.length - 1), lastMessage]; | ||
| }); | ||
| break; | ||
| } | ||
| case "error": { | ||
| setError(value); | ||
| break; | ||
| } | ||
| } | ||
| } catch (error2) { | ||
| setError(error2); | ||
| } | ||
| }); | ||
| setStatus("awaiting_message"); | ||
| }); | ||
| return { | ||
| messages, | ||
| input, | ||
| handleInputChange, | ||
| submitMessage, | ||
| status, | ||
| error | ||
| }; | ||
| } | ||
| function defaultSystemMessage(contextString) { | ||
| return ` | ||
| Please act as an efficient, competent, conscientious, and industrious professional assistant. | ||
| Help the user achieve their goals, and you do so in a way that is as efficient as possible, without unnecessary fluff, but also without sacrificing professionalism. | ||
| Always be polite and respectful, and prefer brevity over verbosity. | ||
| The user has provided you with the following context: | ||
| \`\`\` | ||
| ${contextString} | ||
| \`\`\` | ||
| They have also provided you with functions you can call to initiate actions on their behalf, or functions you can call to receive more information. | ||
| Please assist them as best you can. | ||
| You 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. | ||
| If you would like to call a function, call it without saying anything else. | ||
| `; | ||
| } | ||
| export { defaultSystemMessage, useCopilotChatV2 }; | ||
| //# sourceMappingURL=out.js.map | ||
| //# sourceMappingURL=chunk-TU4DNDO7.mjs.map |
| {"version":3,"sources":["../src/openai-assistants/hooks/use-copilot-chat-v2.ts"],"names":["messages","error"],"mappings":";;;;;;;;;;;;;;;AAAA,SAAS,YAAY,SAAS,gBAAgB;AAE9C,SAAkB,u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;AAWF","sourcesContent":["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 { } |
| //# sourceMappingURL=out.js.map | ||
| //# sourceMappingURL=message.mjs.map |
| {"version":3,"sources":[],"names":[],"mappings":""} |
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
246557
0.58%4009
0.53%+ Added
- Removed