@copilotkit/react-core 0.11.0-alpha.6 → 0.11.0-alpha.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/.turbo/turbo-build.log +38 -78
  2. package/CHANGELOG.md +6 -0
  3. package/package.json +2 -2
  4. package/dist/components/copilot-provider.js +0 -447
  5. package/dist/components/copilot-provider.js.map +0 -1
  6. package/dist/components/index.js +0 -447
  7. package/dist/components/index.js.map +0 -1
  8. package/dist/context/copilot-context.js +0 -52
  9. package/dist/context/copilot-context.js.map +0 -1
  10. package/dist/context/index.js +0 -52
  11. package/dist/context/index.js.map +0 -1
  12. package/dist/hooks/index.js +0 -205
  13. package/dist/hooks/index.js.map +0 -1
  14. package/dist/hooks/use-copilot-chat.js +0 -156
  15. package/dist/hooks/use-copilot-chat.js.map +0 -1
  16. package/dist/hooks/use-flat-category-store.js +0 -78
  17. package/dist/hooks/use-flat-category-store.js.map +0 -1
  18. package/dist/hooks/use-make-copilot-actionable.js +0 -67
  19. package/dist/hooks/use-make-copilot-actionable.js.map +0 -1
  20. package/dist/hooks/use-make-copilot-document-readable.js +0 -56
  21. package/dist/hooks/use-make-copilot-document-readable.js.map +0 -1
  22. package/dist/hooks/use-make-copilot-readable.js +0 -56
  23. package/dist/hooks/use-make-copilot-readable.js.map +0 -1
  24. package/dist/hooks/use-tree.js +0 -161
  25. package/dist/hooks/use-tree.js.map +0 -1
  26. package/dist/index.js +0 -579
  27. package/dist/index.js.map +0 -1
  28. package/dist/types/annotated-function.js +0 -4
  29. package/dist/types/annotated-function.js.map +0 -1
  30. package/dist/types/document-pointer.js +0 -4
  31. package/dist/types/document-pointer.js.map +0 -1
  32. package/dist/types/index.js +0 -4
  33. package/dist/types/index.js.map +0 -1
  34. package/dist/utils/utils.js +0 -4
  35. package/dist/utils/utils.js.map +0 -1
  36. package/dist/utils/utils.test.js +0 -10
  37. package/dist/utils/utils.test.js.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/components/copilot-provider.tsx","../../src/context/copilot-context.tsx","../../src/hooks/use-tree.ts","../../src/hooks/use-flat-category-store.ts"],"names":["useCallback","nanoid","useReducer","setsHaveIntersection"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,SAAoB,eAAAA,cAAa,gBAAgB;;;ACCjD,OAAO,WAAW;AAHlB;AAmFA,IAAM,sBAA4C;AAAA,EAChD,aAAa,CAAC;AAAA,EACd,eAAe,MAAM;AAAA,EAAC;AAAA,EACtB,kBAAkB,MAAM;AAAA,EAAC;AAAA,EACzB,uCAAuC,MAAM,sBAAsB,CAAC,CAAC;AAAA,EACrE,wBAAwB,MAAM,sBAAsB,MAAY;AAAA,EAAC,EAAC;AAAA,EAElE,kBAAkB,CAAC,cAAiC,sBAAsB,EAAE;AAAA,EAC5E,YAAY,MAAM;AAAA,EAClB,eAAe,MAAM;AAAA,EAAC;AAAA,EAEtB,qBAAqB,MAAM,sBAAsB,CAAC,CAAC;AAAA,EACnD,oBAAoB,MAAM,sBAAsB,EAAE;AAAA,EAClD,uBAAuB,MAAM;AAAA,EAAC;AAAA,EAE9B,kBAAkB,IAAK,MAAkC;AAAA,IACvD,IAAI,kBAA0B;AAC5B,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAAA,IACA,IAAI,UAAkC;AACpC,aAAO,CAAC;AAAA,IACV;AAAA,IACA,IAAI,OAA4B;AAC9B,aAAO,CAAC;AAAA,IACV;AAAA,EACF,EAAG;AACL;AAEO,IAAM,iBACX,MAAM,cAAoC,mBAAmB;AAE/D,SAAS,sBAAyB,OAAa;AAC7C,QAAM,IAAI;AAAA,IACR;AAAA,EACF;AACA,SAAO;AACT;;;ACzHA,SAAS,cAAc;AACvB,SAAS,aAAa,kBAAkB;AAsCxC,IAAM,aAAa,CAAC,OAAa,OAAyB;AACxD,SAAO,MAAM,OAAO,CAAC,QAAc,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6BAAqB;AAAA,UACnB,4BACE,IAAI;AAAA,QAER;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,SA3MhB,IA2M+C,IAAlB,0BAAkB,IAAlB,CAAnB,QAAM;AACZ,eAAW,IAAI,QAAQ;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\";\nimport { FunctionCallHandler } from \"ai\";\nimport { ReactNode, 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 } from \"../types\";\nimport useFlatCategoryStore from \"../hooks/use-flat-category-store\";\n\nexport function CopilotProvider({\n chatApiEndpoint,\n headers,\n body,\n children,\n}: {\n chatApiEndpoint: string;\n headers?: Record<string, string>;\n body?: Record<string, any>;\n children: ReactNode;\n}): JSX.Element {\n const [entryPoints, setEntryPoints] = useState<\n Record<string, AnnotatedFunction<any[]>>\n >({});\n\n const { addElement, removeElement, printTree } = useTree();\n const {\n addElement: addDocument,\n removeElement: removeDocument,\n allElements: allDocuments,\n } = useFlatCategoryStore<DocumentPointer>();\n\n const setEntryPoint = useCallback(\n (id: string, entryPoint: AnnotatedFunction<any[]>) => {\n setEntryPoints((prevPoints) => {\n return {\n ...prevPoints,\n [id]: entryPoint,\n };\n });\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[] = [\"global\"]) => {\n const documentsString = documents\n .map((document) => {\n return `${document.name} (${\n document.sourceApplication\n }):\\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 (context: string, parentId?: string, categories: string[] = [\"global\"]) => {\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[] = [\"global\"]) => {\n return allDocuments(categories);\n },\n [allDocuments]\n );\n\n const addDocumentContext = useCallback(\n (documentPointer: DocumentPointer, categories: string[] = [\"global\"]) => {\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 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: {\n chatApiEndpoint,\n headers: headers || {},\n body: body || {},\n },\n }}\n >\n {children}\n </CopilotContext.Provider>\n );\n}\n\nfunction entryPointsToFunctionCallHandler(\n entryPoints: AnnotatedFunction<any[]>[]\n): FunctionCallHandler {\n return async (chatMessages, functionCall) => {\n let entrypointsByFunctionName: Record<\n string,\n AnnotatedFunction<any[]>\n > = {};\n for (let entryPoint of entryPoints) {\n entrypointsByFunctionName[entryPoint.name] = entryPoint;\n }\n\n const entryPointFunction =\n entrypointsByFunctionName[functionCall.name || \"\"];\n if (entryPointFunction) {\n let parsedFunctionCallArguments: Record<string, any>[] = [];\n if (functionCall.arguments) {\n parsedFunctionCallArguments = JSON.parse(functionCall.arguments);\n }\n\n const paramsInCorrectOrder: any[] = [];\n for (let arg of entryPointFunction.argumentAnnotations) {\n paramsInCorrectOrder.push(\n parsedFunctionCallArguments[\n arg.name as keyof typeof parsedFunctionCallArguments\n ]\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","\"use client\";\n\nimport { FunctionCallHandler } from \"ai\";\nimport React from \"react\";\nimport { TreeNodeId } from \"../hooks/use-tree\";\nimport { AnnotatedFunction } from \"../types/annotated-function\";\nimport { ChatCompletionCreateParams } from \"openai/resources/chat\";\nimport { DocumentPointer } from \"../types\";\n\n/**\n * Interface for the configuration of the Copilot API.\n */\nexport interface CopilotApiConfig {\n /**\n * The endpoint for the chat API.\n */\n chatApiEndpoint: string;\n\n /**\n * additional headers to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'Authorization': 'Bearer your_token_here'\n * }\n * ```\n */\n headers: Record<string, string>;\n\n /**\n * Additional body params to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'message': 'Hello, world!'\n * }\n * ```\n */\n body: Record<string, any>;\n}\n\nexport function copilotApiConfigExtrapolator(config: CopilotApiConfig) {\n return {\n get chatApiEndpoint(): string {\n return `${config.chatApiEndpoint}`;\n },\n };\n}\n\nexport interface CopilotContextParams {\n // function-calling\n entryPoints: Record<string, AnnotatedFunction<any[]>>;\n setEntryPoint: (id: string, entryPoint: AnnotatedFunction<any[]>) => void;\n removeEntryPoint: (id: string) => void;\n getChatCompletionFunctionDescriptions: () => ChatCompletionCreateParams.Function[];\n getFunctionCallHandler: () => FunctionCallHandler;\n\n // text context\n getContextString: (\n documents: DocumentPointer[],\n categories?: string[]\n ) => string;\n addContext: (\n context: string,\n parentId?: string,\n categories?: string[]\n ) => TreeNodeId;\n removeContext: (id: TreeNodeId) => void;\n\n // document context\n getDocumentsContext: (categories?: string[]) => DocumentPointer[];\n addDocumentContext: (\n documentPointer: DocumentPointer,\n categories?: string[]\n ) => TreeNodeId;\n removeDocumentContext: (documentId: string) => void;\n\n // api endpoints\n copilotApiConfig: CopilotApiConfig;\n}\n\nconst emptyCopilotContext: CopilotContextParams = {\n entryPoints: {},\n setEntryPoint: () => {},\n removeEntryPoint: () => {},\n getChatCompletionFunctionDescriptions: () => returnAndThrowInDebug([]),\n getFunctionCallHandler: () => returnAndThrowInDebug(async () => {}),\n\n getContextString: (documents: DocumentPointer[]) => returnAndThrowInDebug(\"\"),\n addContext: () => \"\",\n removeContext: () => {},\n\n getDocumentsContext: () => returnAndThrowInDebug([]),\n addDocumentContext: () => returnAndThrowInDebug(\"\"),\n removeDocumentContext: () => {},\n\n copilotApiConfig: new (class implements CopilotApiConfig {\n get chatApiEndpoint(): string {\n throw new Error(\n \"Remember to wrap your app in a `<CopilotProvider> {...} </CopilotProvider>` !!!\"\n );\n }\n get headers(): Record<string, string> {\n return {};\n }\n get body(): Record<string, any> {\n return {};\n }\n })(),\n};\n\nexport const CopilotContext =\n React.createContext<CopilotContextParams>(emptyCopilotContext);\n\nfunction returnAndThrowInDebug<T>(value: T): T {\n throw new Error(\n \"Remember to wrap your app in a `<CopilotProvider> {...} </CopilotProvider>` !!!\"\n );\n return value;\n}\n","import { nanoid } from \"nanoid\";\nimport { useCallback, useReducer } from \"react\";\n\nexport type TreeNodeId = string;\n\nexport interface TreeNode {\n id: TreeNodeId;\n value: string;\n children: TreeNode[];\n parentId?: TreeNodeId;\n categories: Set<string>;\n}\n\nexport type Tree = TreeNode[];\n\nexport interface UseTreeReturn {\n tree: Tree;\n addElement: (\n value: string,\n categories: string[],\n parentId?: TreeNodeId\n ) => TreeNodeId;\n printTree: (categories: string[]) => string;\n removeElement: (id: TreeNodeId) => void;\n}\n\nconst findNode = (nodes: Tree, id: TreeNodeId): TreeNode | undefined => {\n for (const node of nodes) {\n if (node.id === id) {\n return node;\n }\n const result = findNode(node.children, id);\n if (result) {\n return result;\n }\n }\n return undefined;\n};\n\nconst removeNode = (nodes: Tree, id: TreeNodeId): Tree => {\n return nodes.reduce((result: Tree, node) => {\n if (node.id !== id) {\n const newNode = { ...node, children: removeNode(node.children, id) };\n result.push(newNode);\n }\n return result;\n }, []);\n};\n\nconst addNode = (\n nodes: Tree,\n newNode: TreeNode,\n parentId?: TreeNodeId\n): Tree => {\n if (!parentId) {\n return [...nodes, newNode];\n }\n return nodes.map((node) => {\n if (node.id === parentId) {\n return { ...node, children: [...node.children, newNode] };\n } else if (node.children.length) {\n return { ...node, children: addNode(node.children, newNode, parentId) };\n }\n return node;\n });\n};\n\nconst treeIndentationRepresentation = (\n index: number,\n indentLevel: number\n): string => {\n if (indentLevel === 0) {\n return (index + 1).toString();\n } else if (indentLevel === 1) {\n return String.fromCharCode(65 + index); // 65 is the ASCII value for 'A'\n } else if (indentLevel === 2) {\n return String.fromCharCode(97 + index); // 97 is the ASCII value for 'a'\n } else {\n return \"-\";\n }\n};\n\nconst printNode = (node: TreeNode, prefix = \"\", indentLevel = 0): string => {\n const indent = \" \".repeat(3).repeat(indentLevel);\n\n const prefixPlusIndentLength = prefix.length + indent.length;\n const subsequentLinesPrefix = \" \".repeat(prefixPlusIndentLength);\n\n const valueLines = node.value.split(\"\\n\");\n\n const outputFirstLine = `${indent}${prefix}${valueLines[0]}`;\n const outputSubsequentLines = valueLines\n .slice(1)\n .map((line) => `${subsequentLinesPrefix}${line}`)\n .join(\"\\n\");\n\n let output = `${outputFirstLine}\\n`;\n if (outputSubsequentLines) {\n output += `${outputSubsequentLines}\\n`;\n }\n\n const childPrePrefix = \" \".repeat(prefix.length);\n\n node.children.forEach(\n (child, index) =>\n (output += printNode(\n child,\n `${childPrePrefix}${treeIndentationRepresentation(\n index,\n indentLevel + 1\n )}. `,\n indentLevel + 1\n ))\n );\n return output;\n};\n\n// Action types\ntype Action =\n | {\n type: \"ADD_NODE\";\n value: string;\n parentId?: string;\n id: string;\n categories: string[];\n }\n | { type: \"REMOVE_NODE\"; id: string };\n\n// Reducer function\nfunction treeReducer(state: Tree, action: Action): Tree {\n switch (action.type) {\n case \"ADD_NODE\": {\n const { value, parentId, id: newNodeId } = action;\n const newNode: TreeNode = {\n id: newNodeId,\n value,\n children: [],\n categories: new Set(action.categories),\n };\n\n try {\n return addNode(state, newNode, parentId);\n } catch (error) {\n console.error(`Error while adding node with id ${newNodeId}: ${error}`);\n return state;\n }\n }\n case \"REMOVE_NODE\":\n return removeNode(state, action.id);\n default:\n return state;\n }\n}\n\n// useTree hook\nconst useTree = (): UseTreeReturn => {\n const [tree, dispatch] = useReducer(treeReducer, []);\n\n const addElement = useCallback(\n (value: string, categories: string[], parentId?: string): TreeNodeId => {\n const newNodeId = nanoid(); // Generate new ID outside of dispatch\n dispatch({\n type: \"ADD_NODE\",\n value,\n parentId,\n id: newNodeId,\n categories: categories,\n });\n return newNodeId; // Return the new ID\n },\n []\n );\n\n const removeElement = useCallback((id: TreeNodeId): void => {\n dispatch({ type: \"REMOVE_NODE\", id });\n }, []);\n\n const printTree = useCallback(\n (categories: string[]): string => {\n const categoriesSet = new Set(categories);\n\n let output = \"\";\n tree.forEach((node, index) => {\n // if the node does not have any of the desired categories, continue to the next node\n if (!setsHaveIntersection(categoriesSet, node.categories)) {\n return;\n }\n\n // add a new line before each node except the first one\n if (index !== 0) {\n output += \"\\n\";\n }\n\n output += printNode(\n node,\n `${treeIndentationRepresentation(index, 0)}. `\n );\n });\n return output;\n },\n [tree]\n );\n\n return { tree, addElement, printTree, removeElement };\n};\n\nexport default useTree;\n\nfunction setsHaveIntersection<T>(setA: Set<T>, setB: Set<T>): boolean {\n const [smallerSet, largerSet] =\n setA.size <= setB.size ? [setA, setB] : [setB, setA];\n\n for (let item of smallerSet) {\n if (largerSet.has(item)) {\n return true;\n }\n }\n\n return false;\n}\n","import { nanoid } from \"nanoid\";\nimport { useCallback, useReducer } from \"react\";\n\nexport type FlatCategoryStoreId = string;\n\nexport interface UseFlatCategoryStoreReturn<T> {\n addElement: (value: T, categories: string[]) => FlatCategoryStoreId;\n removeElement: (id: FlatCategoryStoreId) => void;\n allElements: (categories: string[]) => T[];\n}\n\ninterface FlatCategoryStoreElement<T> {\n id: FlatCategoryStoreId;\n value: T;\n categories: Set<string>;\n}\n\nconst useFlatCategoryStore = <T>(): UseFlatCategoryStoreReturn<T> => {\n const [elements, dispatch] = useReducer<\n React.Reducer<\n Map<FlatCategoryStoreId, FlatCategoryStoreElement<T>>,\n Action<T>\n >\n >(\n flatCategoryStoreReducer,\n new Map<FlatCategoryStoreId, FlatCategoryStoreElement<T>>()\n );\n\n const addElement = useCallback(\n (value: T, categories: string[]): FlatCategoryStoreId => {\n const newId = nanoid();\n dispatch({\n type: \"ADD_ELEMENT\",\n value,\n id: newId,\n categories,\n });\n return newId;\n },\n []\n );\n\n const removeElement = useCallback((id: FlatCategoryStoreId): void => {\n dispatch({ type: \"REMOVE_ELEMENT\", id });\n }, []);\n\n const allElements = useCallback(\n (categories: string[]): T[] => {\n const categoriesSet = new Set(categories);\n const result: T[] = [];\n elements.forEach((element) => {\n if (setsHaveIntersection(categoriesSet, element.categories)) {\n result.push(element.value);\n }\n });\n return result;\n },\n [elements]\n );\n\n return { addElement, removeElement, allElements };\n};\n\nexport default useFlatCategoryStore;\n\n// Action types\ntype Action<T> =\n | {\n type: \"ADD_ELEMENT\";\n value: T;\n id: FlatCategoryStoreId;\n categories: string[];\n }\n | { type: \"REMOVE_ELEMENT\"; id: FlatCategoryStoreId };\n\n// Reducer\nfunction flatCategoryStoreReducer<T>(\n state: Map<FlatCategoryStoreId, FlatCategoryStoreElement<T>>,\n action: Action<T>\n): Map<FlatCategoryStoreId, FlatCategoryStoreElement<T>> {\n switch (action.type) {\n case \"ADD_ELEMENT\": {\n const { value, id, categories } = action;\n const newElement: FlatCategoryStoreElement<T> = {\n id,\n value,\n categories: new Set(categories),\n };\n const newState = new Map(state);\n newState.set(id, newElement);\n return newState;\n }\n case \"REMOVE_ELEMENT\": {\n const newState = new Map(state);\n newState.delete(action.id);\n return newState;\n }\n default:\n return state;\n }\n}\n\nfunction setsHaveIntersection<T>(setA: Set<T>, setB: Set<T>): boolean {\n const [smallerSet, largerSet] =\n setA.size <= setB.size ? [setA, setB] : [setB, setA];\n\n for (let item of smallerSet) {\n if (largerSet.has(item)) {\n return true;\n }\n }\n\n return false;\n}\n"]}
@@ -1,447 +0,0 @@
1
- 'use strict';
2
-
3
- var React = require('react');
4
- var nanoid = require('nanoid');
5
- var jsxRuntime = require('react/jsx-runtime');
6
-
7
- var __defProp = Object.defineProperty;
8
- var __defProps = Object.defineProperties;
9
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
10
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
11
- var __hasOwnProp = Object.prototype.hasOwnProperty;
12
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
13
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
14
- var __spreadValues = (a, b) => {
15
- for (var prop in b || (b = {}))
16
- if (__hasOwnProp.call(b, prop))
17
- __defNormalProp(a, prop, b[prop]);
18
- if (__getOwnPropSymbols)
19
- for (var prop of __getOwnPropSymbols(b)) {
20
- if (__propIsEnum.call(b, prop))
21
- __defNormalProp(a, prop, b[prop]);
22
- }
23
- return a;
24
- };
25
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
26
- var __objRest = (source, exclude) => {
27
- var target = {};
28
- for (var prop in source)
29
- if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
30
- target[prop] = source[prop];
31
- if (source != null && __getOwnPropSymbols)
32
- for (var prop of __getOwnPropSymbols(source)) {
33
- if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
34
- target[prop] = source[prop];
35
- }
36
- return target;
37
- };
38
- var __async = (__this, __arguments, generator) => {
39
- return new Promise((resolve, reject) => {
40
- var fulfilled = (value) => {
41
- try {
42
- step(generator.next(value));
43
- } catch (e) {
44
- reject(e);
45
- }
46
- };
47
- var rejected = (value) => {
48
- try {
49
- step(generator.throw(value));
50
- } catch (e) {
51
- reject(e);
52
- }
53
- };
54
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
55
- step((generator = generator.apply(__this, __arguments)).next());
56
- });
57
- };
58
- var emptyCopilotContext = {
59
- entryPoints: {},
60
- setEntryPoint: () => {
61
- },
62
- removeEntryPoint: () => {
63
- },
64
- getChatCompletionFunctionDescriptions: () => returnAndThrowInDebug(),
65
- getFunctionCallHandler: () => returnAndThrowInDebug(),
66
- getContextString: (documents) => returnAndThrowInDebug(),
67
- addContext: () => "",
68
- removeContext: () => {
69
- },
70
- getDocumentsContext: () => returnAndThrowInDebug(),
71
- addDocumentContext: () => returnAndThrowInDebug(),
72
- removeDocumentContext: () => {
73
- },
74
- copilotApiConfig: new class {
75
- get chatApiEndpoint() {
76
- throw new Error(
77
- "Remember to wrap your app in a `<CopilotProvider> {...} </CopilotProvider>` !!!"
78
- );
79
- }
80
- get headers() {
81
- return {};
82
- }
83
- get body() {
84
- return {};
85
- }
86
- }()
87
- };
88
- var CopilotContext = React.createContext(emptyCopilotContext);
89
- function returnAndThrowInDebug(value) {
90
- throw new Error(
91
- "Remember to wrap your app in a `<CopilotProvider> {...} </CopilotProvider>` !!!"
92
- );
93
- }
94
- var removeNode = (nodes, id) => {
95
- return nodes.reduce((result, node) => {
96
- if (node.id !== id) {
97
- const newNode = __spreadProps(__spreadValues({}, node), { children: removeNode(node.children, id) });
98
- result.push(newNode);
99
- }
100
- return result;
101
- }, []);
102
- };
103
- var addNode = (nodes, newNode, parentId) => {
104
- if (!parentId) {
105
- return [...nodes, newNode];
106
- }
107
- return nodes.map((node) => {
108
- if (node.id === parentId) {
109
- return __spreadProps(__spreadValues({}, node), { children: [...node.children, newNode] });
110
- } else if (node.children.length) {
111
- return __spreadProps(__spreadValues({}, node), { children: addNode(node.children, newNode, parentId) });
112
- }
113
- return node;
114
- });
115
- };
116
- var treeIndentationRepresentation = (index, indentLevel) => {
117
- if (indentLevel === 0) {
118
- return (index + 1).toString();
119
- } else if (indentLevel === 1) {
120
- return String.fromCharCode(65 + index);
121
- } else if (indentLevel === 2) {
122
- return String.fromCharCode(97 + index);
123
- } else {
124
- return "-";
125
- }
126
- };
127
- var printNode = (node, prefix = "", indentLevel = 0) => {
128
- const indent = " ".repeat(3).repeat(indentLevel);
129
- const prefixPlusIndentLength = prefix.length + indent.length;
130
- const subsequentLinesPrefix = " ".repeat(prefixPlusIndentLength);
131
- const valueLines = node.value.split("\n");
132
- const outputFirstLine = `${indent}${prefix}${valueLines[0]}`;
133
- const outputSubsequentLines = valueLines.slice(1).map((line) => `${subsequentLinesPrefix}${line}`).join("\n");
134
- let output = `${outputFirstLine}
135
- `;
136
- if (outputSubsequentLines) {
137
- output += `${outputSubsequentLines}
138
- `;
139
- }
140
- const childPrePrefix = " ".repeat(prefix.length);
141
- node.children.forEach(
142
- (child, index) => output += printNode(
143
- child,
144
- `${childPrePrefix}${treeIndentationRepresentation(
145
- index,
146
- indentLevel + 1
147
- )}. `,
148
- indentLevel + 1
149
- )
150
- );
151
- return output;
152
- };
153
- function treeReducer(state, action) {
154
- switch (action.type) {
155
- case "ADD_NODE": {
156
- const { value, parentId, id: newNodeId } = action;
157
- const newNode = {
158
- id: newNodeId,
159
- value,
160
- children: [],
161
- categories: new Set(action.categories)
162
- };
163
- try {
164
- return addNode(state, newNode, parentId);
165
- } catch (error) {
166
- console.error(`Error while adding node with id ${newNodeId}: ${error}`);
167
- return state;
168
- }
169
- }
170
- case "REMOVE_NODE":
171
- return removeNode(state, action.id);
172
- default:
173
- return state;
174
- }
175
- }
176
- var useTree = () => {
177
- const [tree, dispatch] = React.useReducer(treeReducer, []);
178
- const addElement = React.useCallback(
179
- (value, categories, parentId) => {
180
- const newNodeId = nanoid.nanoid();
181
- dispatch({
182
- type: "ADD_NODE",
183
- value,
184
- parentId,
185
- id: newNodeId,
186
- categories
187
- });
188
- return newNodeId;
189
- },
190
- []
191
- );
192
- const removeElement = React.useCallback((id) => {
193
- dispatch({ type: "REMOVE_NODE", id });
194
- }, []);
195
- const printTree = React.useCallback(
196
- (categories) => {
197
- const categoriesSet = new Set(categories);
198
- let output = "";
199
- tree.forEach((node, index) => {
200
- if (!setsHaveIntersection(categoriesSet, node.categories)) {
201
- return;
202
- }
203
- if (index !== 0) {
204
- output += "\n";
205
- }
206
- output += printNode(
207
- node,
208
- `${treeIndentationRepresentation(index, 0)}. `
209
- );
210
- });
211
- return output;
212
- },
213
- [tree]
214
- );
215
- return { tree, addElement, printTree, removeElement };
216
- };
217
- var use_tree_default = useTree;
218
- function setsHaveIntersection(setA, setB) {
219
- const [smallerSet, largerSet] = setA.size <= setB.size ? [setA, setB] : [setB, setA];
220
- for (let item of smallerSet) {
221
- if (largerSet.has(item)) {
222
- return true;
223
- }
224
- }
225
- return false;
226
- }
227
- var useFlatCategoryStore = () => {
228
- const [elements, dispatch] = React.useReducer(
229
- flatCategoryStoreReducer,
230
- /* @__PURE__ */ new Map()
231
- );
232
- const addElement = React.useCallback(
233
- (value, categories) => {
234
- const newId = nanoid.nanoid();
235
- dispatch({
236
- type: "ADD_ELEMENT",
237
- value,
238
- id: newId,
239
- categories
240
- });
241
- return newId;
242
- },
243
- []
244
- );
245
- const removeElement = React.useCallback((id) => {
246
- dispatch({ type: "REMOVE_ELEMENT", id });
247
- }, []);
248
- const allElements = React.useCallback(
249
- (categories) => {
250
- const categoriesSet = new Set(categories);
251
- const result = [];
252
- elements.forEach((element) => {
253
- if (setsHaveIntersection2(categoriesSet, element.categories)) {
254
- result.push(element.value);
255
- }
256
- });
257
- return result;
258
- },
259
- [elements]
260
- );
261
- return { addElement, removeElement, allElements };
262
- };
263
- var use_flat_category_store_default = useFlatCategoryStore;
264
- function flatCategoryStoreReducer(state, action) {
265
- switch (action.type) {
266
- case "ADD_ELEMENT": {
267
- const { value, id, categories } = action;
268
- const newElement = {
269
- id,
270
- value,
271
- categories: new Set(categories)
272
- };
273
- const newState = new Map(state);
274
- newState.set(id, newElement);
275
- return newState;
276
- }
277
- case "REMOVE_ELEMENT": {
278
- const newState = new Map(state);
279
- newState.delete(action.id);
280
- return newState;
281
- }
282
- default:
283
- return state;
284
- }
285
- }
286
- function setsHaveIntersection2(setA, setB) {
287
- const [smallerSet, largerSet] = setA.size <= setB.size ? [setA, setB] : [setB, setA];
288
- for (let item of smallerSet) {
289
- if (largerSet.has(item)) {
290
- return true;
291
- }
292
- }
293
- return false;
294
- }
295
- function CopilotProvider({
296
- chatApiEndpoint,
297
- headers,
298
- body,
299
- children
300
- }) {
301
- const [entryPoints, setEntryPoints] = React.useState({});
302
- const { addElement, removeElement, printTree } = use_tree_default();
303
- const {
304
- addElement: addDocument,
305
- removeElement: removeDocument,
306
- allElements: allDocuments
307
- } = use_flat_category_store_default();
308
- const setEntryPoint = React.useCallback(
309
- (id, entryPoint) => {
310
- setEntryPoints((prevPoints) => {
311
- return __spreadProps(__spreadValues({}, prevPoints), {
312
- [id]: entryPoint
313
- });
314
- });
315
- },
316
- []
317
- );
318
- const removeEntryPoint = React.useCallback((id) => {
319
- setEntryPoints((prevPoints) => {
320
- const newPoints = __spreadValues({}, prevPoints);
321
- delete newPoints[id];
322
- return newPoints;
323
- });
324
- }, []);
325
- const getContextString = React.useCallback(
326
- (documents, categories = ["global"]) => {
327
- const documentsString = documents.map((document) => {
328
- return `${document.name} (${document.sourceApplication}):
329
- ${document.getContents()}`;
330
- }).join("\n\n");
331
- const nonDocumentStrings = printTree(categories);
332
- return `${documentsString}
333
-
334
- ${nonDocumentStrings}`;
335
- },
336
- [printTree]
337
- );
338
- const addContext = React.useCallback(
339
- (context, parentId, categories = ["global"]) => {
340
- return addElement(context, categories, parentId);
341
- },
342
- [addElement]
343
- );
344
- const removeContext = React.useCallback(
345
- (id) => {
346
- removeElement(id);
347
- },
348
- [removeElement]
349
- );
350
- const getChatCompletionFunctionDescriptions = React.useCallback(() => {
351
- return entryPointsToChatCompletionFunctions(Object.values(entryPoints));
352
- }, [entryPoints]);
353
- const getFunctionCallHandler = React.useCallback(() => {
354
- return entryPointsToFunctionCallHandler(Object.values(entryPoints));
355
- }, [entryPoints]);
356
- const getDocumentsContext = React.useCallback(
357
- (categories = ["global"]) => {
358
- return allDocuments(categories);
359
- },
360
- [allDocuments]
361
- );
362
- const addDocumentContext = React.useCallback(
363
- (documentPointer, categories = ["global"]) => {
364
- return addDocument(documentPointer, categories);
365
- },
366
- [addDocument]
367
- );
368
- const removeDocumentContext = React.useCallback(
369
- (documentId) => {
370
- removeDocument(documentId);
371
- },
372
- [removeDocument]
373
- );
374
- return /* @__PURE__ */ jsxRuntime.jsx(CopilotContext.Provider, {
375
- value: {
376
- entryPoints,
377
- getChatCompletionFunctionDescriptions,
378
- getFunctionCallHandler,
379
- setEntryPoint,
380
- removeEntryPoint,
381
- getContextString,
382
- addContext,
383
- removeContext,
384
- getDocumentsContext,
385
- addDocumentContext,
386
- removeDocumentContext,
387
- copilotApiConfig: {
388
- chatApiEndpoint,
389
- headers: headers || {},
390
- body: body || {}
391
- }
392
- },
393
- children
394
- });
395
- }
396
- function entryPointsToFunctionCallHandler(entryPoints) {
397
- return (chatMessages, functionCall) => __async(this, null, function* () {
398
- let entrypointsByFunctionName = {};
399
- for (let entryPoint of entryPoints) {
400
- entrypointsByFunctionName[entryPoint.name] = entryPoint;
401
- }
402
- const entryPointFunction = entrypointsByFunctionName[functionCall.name || ""];
403
- if (entryPointFunction) {
404
- let parsedFunctionCallArguments = [];
405
- if (functionCall.arguments) {
406
- parsedFunctionCallArguments = JSON.parse(functionCall.arguments);
407
- }
408
- const paramsInCorrectOrder = [];
409
- for (let arg of entryPointFunction.argumentAnnotations) {
410
- paramsInCorrectOrder.push(
411
- parsedFunctionCallArguments[arg.name]
412
- );
413
- }
414
- yield entryPointFunction.implementation(...paramsInCorrectOrder);
415
- }
416
- });
417
- }
418
- function entryPointsToChatCompletionFunctions(entryPoints) {
419
- return entryPoints.map(annotatedFunctionToChatCompletionFunction);
420
- }
421
- function annotatedFunctionToChatCompletionFunction(annotatedFunction) {
422
- let parameters = {};
423
- for (let arg of annotatedFunction.argumentAnnotations) {
424
- let _a = arg, forwardedArgs = __objRest(_a, ["name", "required"]);
425
- parameters[arg.name] = forwardedArgs;
426
- }
427
- let requiredParameterNames = [];
428
- for (let arg of annotatedFunction.argumentAnnotations) {
429
- if (arg.required) {
430
- requiredParameterNames.push(arg.name);
431
- }
432
- }
433
- let chatCompletionFunction = {
434
- name: annotatedFunction.name,
435
- description: annotatedFunction.description,
436
- parameters: {
437
- type: "object",
438
- properties: parameters,
439
- required: requiredParameterNames
440
- }
441
- };
442
- return chatCompletionFunction;
443
- }
444
-
445
- exports.CopilotProvider = CopilotProvider;
446
- //# sourceMappingURL=out.js.map
447
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/components/copilot-provider.tsx","../../src/context/copilot-context.tsx","../../src/hooks/use-tree.ts","../../src/hooks/use-flat-category-store.ts"],"names":["useCallback","nanoid","useReducer","setsHaveIntersection"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,SAAoB,eAAAA,cAAa,gBAAgB;;;ACCjD,OAAO,WAAW;AAHlB;AAmFA,IAAM,sBAA4C;AAAA,EAChD,aAAa,CAAC;AAAA,EACd,eAAe,MAAM;AAAA,EAAC;AAAA,EACtB,kBAAkB,MAAM;AAAA,EAAC;AAAA,EACzB,uCAAuC,MAAM,sBAAsB,CAAC,CAAC;AAAA,EACrE,wBAAwB,MAAM,sBAAsB,MAAY;AAAA,EAAC,EAAC;AAAA,EAElE,kBAAkB,CAAC,cAAiC,sBAAsB,EAAE;AAAA,EAC5E,YAAY,MAAM;AAAA,EAClB,eAAe,MAAM;AAAA,EAAC;AAAA,EAEtB,qBAAqB,MAAM,sBAAsB,CAAC,CAAC;AAAA,EACnD,oBAAoB,MAAM,sBAAsB,EAAE;AAAA,EAClD,uBAAuB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["\"use client\";\nimport { FunctionCallHandler } from \"ai\";\nimport { ReactNode, 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 } from \"../types\";\nimport useFlatCategoryStore from \"../hooks/use-flat-category-store\";\n\nexport function CopilotProvider({\n chatApiEndpoint,\n headers,\n body,\n children,\n}: {\n chatApiEndpoint: string;\n headers?: Record<string, string>;\n body?: Record<string, any>;\n children: ReactNode;\n}): JSX.Element {\n const [entryPoints, setEntryPoints] = useState<\n Record<string, AnnotatedFunction<any[]>>\n >({});\n\n const { addElement, removeElement, printTree } = useTree();\n const {\n addElement: addDocument,\n removeElement: removeDocument,\n allElements: allDocuments,\n } = useFlatCategoryStore<DocumentPointer>();\n\n const setEntryPoint = useCallback(\n (id: string, entryPoint: AnnotatedFunction<any[]>) => {\n setEntryPoints((prevPoints) => {\n return {\n ...prevPoints,\n [id]: entryPoint,\n };\n });\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[] = [\"global\"]) => {\n const documentsString = documents\n .map((document) => {\n return `${document.name} (${\n document.sourceApplication\n }):\\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 (context: string, parentId?: string, categories: string[] = [\"global\"]) => {\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[] = [\"global\"]) => {\n return allDocuments(categories);\n },\n [allDocuments]\n );\n\n const addDocumentContext = useCallback(\n (documentPointer: DocumentPointer, categories: string[] = [\"global\"]) => {\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 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: {\n chatApiEndpoint,\n headers: headers || {},\n body: body || {},\n },\n }}\n >\n {children}\n </CopilotContext.Provider>\n );\n}\n\nfunction entryPointsToFunctionCallHandler(\n entryPoints: AnnotatedFunction<any[]>[]\n): FunctionCallHandler {\n return async (chatMessages, functionCall) => {\n let entrypointsByFunctionName: Record<\n string,\n AnnotatedFunction<any[]>\n > = {};\n for (let entryPoint of entryPoints) {\n entrypointsByFunctionName[entryPoint.name] = entryPoint;\n }\n\n const entryPointFunction =\n entrypointsByFunctionName[functionCall.name || \"\"];\n if (entryPointFunction) {\n let parsedFunctionCallArguments: Record<string, any>[] = [];\n if (functionCall.arguments) {\n parsedFunctionCallArguments = JSON.parse(functionCall.arguments);\n }\n\n const paramsInCorrectOrder: any[] = [];\n for (let arg of entryPointFunction.argumentAnnotations) {\n paramsInCorrectOrder.push(\n parsedFunctionCallArguments[\n arg.name as keyof typeof parsedFunctionCallArguments\n ]\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","\"use client\";\n\nimport { FunctionCallHandler } from \"ai\";\nimport React from \"react\";\nimport { TreeNodeId } from \"../hooks/use-tree\";\nimport { AnnotatedFunction } from \"../types/annotated-function\";\nimport { ChatCompletionCreateParams } from \"openai/resources/chat\";\nimport { DocumentPointer } from \"../types\";\n\n/**\n * Interface for the configuration of the Copilot API.\n */\nexport interface CopilotApiConfig {\n /**\n * The endpoint for the chat API.\n */\n chatApiEndpoint: string;\n\n /**\n * additional headers to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'Authorization': 'Bearer your_token_here'\n * }\n * ```\n */\n headers: Record<string, string>;\n\n /**\n * Additional body params to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'message': 'Hello, world!'\n * }\n * ```\n */\n body: Record<string, any>;\n}\n\nexport function copilotApiConfigExtrapolator(config: CopilotApiConfig) {\n return {\n get chatApiEndpoint(): string {\n return `${config.chatApiEndpoint}`;\n },\n };\n}\n\nexport interface CopilotContextParams {\n // function-calling\n entryPoints: Record<string, AnnotatedFunction<any[]>>;\n setEntryPoint: (id: string, entryPoint: AnnotatedFunction<any[]>) => void;\n removeEntryPoint: (id: string) => void;\n getChatCompletionFunctionDescriptions: () => ChatCompletionCreateParams.Function[];\n getFunctionCallHandler: () => FunctionCallHandler;\n\n // text context\n getContextString: (\n documents: DocumentPointer[],\n categories?: string[]\n ) => string;\n addContext: (\n context: string,\n parentId?: string,\n categories?: string[]\n ) => TreeNodeId;\n removeContext: (id: TreeNodeId) => void;\n\n // document context\n getDocumentsContext: (categories?: string[]) => DocumentPointer[];\n addDocumentContext: (\n documentPointer: DocumentPointer,\n categories?: string[]\n ) => TreeNodeId;\n removeDocumentContext: (documentId: string) => void;\n\n // api endpoints\n copilotApiConfig: CopilotApiConfig;\n}\n\nconst emptyCopilotContext: CopilotContextParams = {\n entryPoints: {},\n setEntryPoint: () => {},\n removeEntryPoint: () => {},\n getChatCompletionFunctionDescriptions: () => returnAndThrowInDebug([]),\n getFunctionCallHandler: () => returnAndThrowInDebug(async () => {}),\n\n getContextString: (documents: DocumentPointer[]) => returnAndThrowInDebug(\"\"),\n addContext: () => \"\",\n removeContext: () => {},\n\n getDocumentsContext: () => returnAndThrowInDebug([]),\n addDocumentContext: () => returnAndThrowInDebug(\"\"),\n removeDocumentContext: () => {},\n\n copilotApiConfig: new (class implements CopilotApiConfig {\n get chatApiEndpoint(): string {\n throw new Error(\n \"Remember to wrap your app in a `<CopilotProvider> {...} </CopilotProvider>` !!!\"\n );\n }\n get headers(): Record<string, string> {\n return {};\n }\n get body(): Record<string, any> {\n return {};\n }\n })(),\n};\n\nexport const CopilotContext =\n React.createContext<CopilotContextParams>(emptyCopilotContext);\n\nfunction returnAndThrowInDebug<T>(value: T): T {\n throw new Error(\n \"Remember to wrap your app in a `<CopilotProvider> {...} </CopilotProvider>` !!!\"\n );\n return value;\n}\n","import { nanoid } from \"nanoid\";\nimport { useCallback, useReducer } from \"react\";\n\nexport type TreeNodeId = string;\n\nexport interface TreeNode {\n id: TreeNodeId;\n value: string;\n children: TreeNode[];\n parentId?: TreeNodeId;\n categories: Set<string>;\n}\n\nexport type Tree = TreeNode[];\n\nexport interface UseTreeReturn {\n tree: Tree;\n addElement: (\n value: string,\n categories: string[],\n parentId?: TreeNodeId\n ) => TreeNodeId;\n printTree: (categories: string[]) => string;\n removeElement: (id: TreeNodeId) => void;\n}\n\nconst findNode = (nodes: Tree, id: TreeNodeId): TreeNode | undefined => {\n for (const node of nodes) {\n if (node.id === id) {\n return node;\n }\n const result = findNode(node.children, id);\n if (result) {\n return result;\n }\n }\n return undefined;\n};\n\nconst removeNode = (nodes: Tree, id: TreeNodeId): Tree => {\n return nodes.reduce((result: Tree, node) => {\n if (node.id !== id) {\n const newNode = { ...node, children: removeNode(node.children, id) };\n result.push(newNode);\n }\n return result;\n }, []);\n};\n\nconst addNode = (\n nodes: Tree,\n newNode: TreeNode,\n parentId?: TreeNodeId\n): Tree => {\n if (!parentId) {\n return [...nodes, newNode];\n }\n return nodes.map((node) => {\n if (node.id === parentId) {\n return { ...node, children: [...node.children, newNode] };\n } else if (node.children.length) {\n return { ...node, children: addNode(node.children, newNode, parentId) };\n }\n return node;\n });\n};\n\nconst treeIndentationRepresentation = (\n index: number,\n indentLevel: number\n): string => {\n if (indentLevel === 0) {\n return (index + 1).toString();\n } else if (indentLevel === 1) {\n return String.fromCharCode(65 + index); // 65 is the ASCII value for 'A'\n } else if (indentLevel === 2) {\n return String.fromCharCode(97 + index); // 97 is the ASCII value for 'a'\n } else {\n return \"-\";\n }\n};\n\nconst printNode = (node: TreeNode, prefix = \"\", indentLevel = 0): string => {\n const indent = \" \".repeat(3).repeat(indentLevel);\n\n const prefixPlusIndentLength = prefix.length + indent.length;\n const subsequentLinesPrefix = \" \".repeat(prefixPlusIndentLength);\n\n const valueLines = node.value.split(\"\\n\");\n\n const outputFirstLine = `${indent}${prefix}${valueLines[0]}`;\n const outputSubsequentLines = valueLines\n .slice(1)\n .map((line) => `${subsequentLinesPrefix}${line}`)\n .join(\"\\n\");\n\n let output = `${outputFirstLine}\\n`;\n if (outputSubsequentLines) {\n output += `${outputSubsequentLines}\\n`;\n }\n\n const childPrePrefix = \" \".repeat(prefix.length);\n\n node.children.forEach(\n (child, index) =>\n (output += printNode(\n child,\n `${childPrePrefix}${treeIndentationRepresentation(\n index,\n indentLevel + 1\n )}. `,\n indentLevel + 1\n ))\n );\n return output;\n};\n\n// Action types\ntype Action =\n | {\n type: \"ADD_NODE\";\n value: string;\n parentId?: string;\n id: string;\n categories: string[];\n }\n | { type: \"REMOVE_NODE\"; id: string };\n\n// Reducer function\nfunction treeReducer(state: Tree, action: Action): Tree {\n switch (action.type) {\n case \"ADD_NODE\": {\n const { value, parentId, id: newNodeId } = action;\n const newNode: TreeNode = {\n id: newNodeId,\n value,\n children: [],\n categories: new Set(action.categories),\n };\n\n try {\n return addNode(state, newNode, parentId);\n } catch (error) {\n console.error(`Error while adding node with id ${newNodeId}: ${error}`);\n return state;\n }\n }\n case \"REMOVE_NODE\":\n return removeNode(state, action.id);\n default:\n return state;\n }\n}\n\n// useTree hook\nconst useTree = (): UseTreeReturn => {\n const [tree, dispatch] = useReducer(treeReducer, []);\n\n const addElement = useCallback(\n (value: string, categories: string[], parentId?: string): TreeNodeId => {\n const newNodeId = nanoid(); // Generate new ID outside of dispatch\n dispatch({\n type: \"ADD_NODE\",\n value,\n parentId,\n id: newNodeId,\n categories: categories,\n });\n return newNodeId; // Return the new ID\n },\n []\n );\n\n const removeElement = useCallback((id: TreeNodeId): void => {\n dispatch({ type: \"REMOVE_NODE\", id });\n }, []);\n\n const printTree = useCallback(\n (categories: string[]): string => {\n const categoriesSet = new Set(categories);\n\n let output = \"\";\n tree.forEach((node, index) => {\n // if the node does not have any of the desired categories, continue to the next node\n if (!setsHaveIntersection(categoriesSet, node.categories)) {\n return;\n }\n\n // add a new line before each node except the first one\n if (index !== 0) {\n output += \"\\n\";\n }\n\n output += printNode(\n node,\n `${treeIndentationRepresentation(index, 0)}. `\n );\n });\n return output;\n },\n [tree]\n );\n\n return { tree, addElement, printTree, removeElement };\n};\n\nexport default useTree;\n\nfunction setsHaveIntersection<T>(setA: Set<T>, setB: Set<T>): boolean {\n const [smallerSet, largerSet] =\n setA.size <= setB.size ? [setA, setB] : [setB, setA];\n\n for (let item of smallerSet) {\n if (largerSet.has(item)) {\n return true;\n }\n }\n\n return false;\n}\n","import { nanoid } from \"nanoid\";\nimport { useCallback, useReducer } from \"react\";\n\nexport type FlatCategoryStoreId = string;\n\nexport interface UseFlatCategoryStoreReturn<T> {\n addElement: (value: T, categories: string[]) => FlatCategoryStoreId;\n removeElement: (id: FlatCategoryStoreId) => void;\n allElements: (categories: string[]) => T[];\n}\n\ninterface FlatCategoryStoreElement<T> {\n id: FlatCategoryStoreId;\n value: T;\n categories: Set<string>;\n}\n\nconst useFlatCategoryStore = <T>(): UseFlatCategoryStoreReturn<T> => {\n const [elements, dispatch] = useReducer<\n React.Reducer<\n Map<FlatCategoryStoreId, FlatCategoryStoreElement<T>>,\n Action<T>\n >\n >(\n flatCategoryStoreReducer,\n new Map<FlatCategoryStoreId, FlatCategoryStoreElement<T>>()\n );\n\n const addElement = useCallback(\n (value: T, categories: string[]): FlatCategoryStoreId => {\n const newId = nanoid();\n dispatch({\n type: \"ADD_ELEMENT\",\n value,\n id: newId,\n categories,\n });\n return newId;\n },\n []\n );\n\n const removeElement = useCallback((id: FlatCategoryStoreId): void => {\n dispatch({ type: \"REMOVE_ELEMENT\", id });\n }, []);\n\n const allElements = useCallback(\n (categories: string[]): T[] => {\n const categoriesSet = new Set(categories);\n const result: T[] = [];\n elements.forEach((element) => {\n if (setsHaveIntersection(categoriesSet, element.categories)) {\n result.push(element.value);\n }\n });\n return result;\n },\n [elements]\n );\n\n return { addElement, removeElement, allElements };\n};\n\nexport default useFlatCategoryStore;\n\n// Action types\ntype Action<T> =\n | {\n type: \"ADD_ELEMENT\";\n value: T;\n id: FlatCategoryStoreId;\n categories: string[];\n }\n | { type: \"REMOVE_ELEMENT\"; id: FlatCategoryStoreId };\n\n// Reducer\nfunction flatCategoryStoreReducer<T>(\n state: Map<FlatCategoryStoreId, FlatCategoryStoreElement<T>>,\n action: Action<T>\n): Map<FlatCategoryStoreId, FlatCategoryStoreElement<T>> {\n switch (action.type) {\n case \"ADD_ELEMENT\": {\n const { value, id, categories } = action;\n const newElement: FlatCategoryStoreElement<T> = {\n id,\n value,\n categories: new Set(categories),\n };\n const newState = new Map(state);\n newState.set(id, newElement);\n return newState;\n }\n case \"REMOVE_ELEMENT\": {\n const newState = new Map(state);\n newState.delete(action.id);\n return newState;\n }\n default:\n return state;\n }\n}\n\nfunction setsHaveIntersection<T>(setA: Set<T>, setB: Set<T>): boolean {\n const [smallerSet, largerSet] =\n setA.size <= setB.size ? [setA, setB] : [setB, setA];\n\n for (let item of smallerSet) {\n if (largerSet.has(item)) {\n return true;\n }\n }\n\n return false;\n}\n"]}
@@ -1,52 +0,0 @@
1
- 'use strict';
2
-
3
- var React = require('react');
4
-
5
- function copilotApiConfigExtrapolator(config) {
6
- return {
7
- get chatApiEndpoint() {
8
- return `${config.chatApiEndpoint}`;
9
- }
10
- };
11
- }
12
- var emptyCopilotContext = {
13
- entryPoints: {},
14
- setEntryPoint: () => {
15
- },
16
- removeEntryPoint: () => {
17
- },
18
- getChatCompletionFunctionDescriptions: () => returnAndThrowInDebug(),
19
- getFunctionCallHandler: () => returnAndThrowInDebug(),
20
- getContextString: (documents) => returnAndThrowInDebug(),
21
- addContext: () => "",
22
- removeContext: () => {
23
- },
24
- getDocumentsContext: () => returnAndThrowInDebug(),
25
- addDocumentContext: () => returnAndThrowInDebug(),
26
- removeDocumentContext: () => {
27
- },
28
- copilotApiConfig: new class {
29
- get chatApiEndpoint() {
30
- throw new Error(
31
- "Remember to wrap your app in a `<CopilotProvider> {...} </CopilotProvider>` !!!"
32
- );
33
- }
34
- get headers() {
35
- return {};
36
- }
37
- get body() {
38
- return {};
39
- }
40
- }()
41
- };
42
- var CopilotContext = React.createContext(emptyCopilotContext);
43
- function returnAndThrowInDebug(value) {
44
- throw new Error(
45
- "Remember to wrap your app in a `<CopilotProvider> {...} </CopilotProvider>` !!!"
46
- );
47
- }
48
-
49
- exports.CopilotContext = CopilotContext;
50
- exports.copilotApiConfigExtrapolator = copilotApiConfigExtrapolator;
51
- //# sourceMappingURL=out.js.map
52
- //# sourceMappingURL=copilot-context.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/context/copilot-context.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAGA,OAAO,WAAW;AAHlB;AA2CO,SAAS,6BAA6B,QAA0B;AACrE,SAAO;AAAA,IACL,IAAI,kBAA0B;AAC5B,aAAO,GAAG,OAAO;AAAA,IACnB;AAAA,EACF;AACF;AAkCA,IAAM,sBAA4C;AAAA,EAChD,aAAa,CAAC;AAAA,EACd,eAAe,MAAM;AAAA,EAAC;AAAA,EACtB,kBAAkB,MAAM;AAAA,EAAC;AAAA,EACzB,uCAAuC,MAAM,sBAAsB,CAAC,CAAC;AAAA,EACrE,wBAAwB,MAAM,sBAAsB,MAAY;AAAA,EAAC,EAAC;AAAA,EAElE,kBAAkB,CAAC,cAAiC,sBAAsB,EAAE;AAAA,EAC5E,YAAY,MAAM;AAAA,EAClB,eAAe,MAAM;AAAA,EAAC;AAAA,EAEtB,qBAAqB,MAAM,sBAAsB,CAAC,CAAC;AAAA,EACnD,oBAAoB,MAAM,sBAAsB,EAAE;AAAA,EAClD,uBAAuB,MAAM;AAAA,EAAC;AAAA,EAE9B,kBAAkB,IAAK,MAAkC;AAAA,IACvD,IAAI,kBAA0B;AAC5B,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAAA,IACA,IAAI,UAAkC;AACpC,aAAO,CAAC;AAAA,IACV;AAAA,IACA,IAAI,OAA4B;AAC9B,aAAO,CAAC;AAAA,IACV;AAAA,EACF,EAAG;AACL;AAEO,IAAM,iBACX,MAAM,cAAoC,mBAAmB;AAE/D,SAAS,sBAAyB,OAAa;AAC7C,QAAM,IAAI;AAAA,IACR;AAAA,EACF;AACA,SAAO;AACT","sourcesContent":["\"use client\";\n\nimport { FunctionCallHandler } from \"ai\";\nimport React from \"react\";\nimport { TreeNodeId } from \"../hooks/use-tree\";\nimport { AnnotatedFunction } from \"../types/annotated-function\";\nimport { ChatCompletionCreateParams } from \"openai/resources/chat\";\nimport { DocumentPointer } from \"../types\";\n\n/**\n * Interface for the configuration of the Copilot API.\n */\nexport interface CopilotApiConfig {\n /**\n * The endpoint for the chat API.\n */\n chatApiEndpoint: string;\n\n /**\n * additional headers to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'Authorization': 'Bearer your_token_here'\n * }\n * ```\n */\n headers: Record<string, string>;\n\n /**\n * Additional body params to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'message': 'Hello, world!'\n * }\n * ```\n */\n body: Record<string, any>;\n}\n\nexport function copilotApiConfigExtrapolator(config: CopilotApiConfig) {\n return {\n get chatApiEndpoint(): string {\n return `${config.chatApiEndpoint}`;\n },\n };\n}\n\nexport interface CopilotContextParams {\n // function-calling\n entryPoints: Record<string, AnnotatedFunction<any[]>>;\n setEntryPoint: (id: string, entryPoint: AnnotatedFunction<any[]>) => void;\n removeEntryPoint: (id: string) => void;\n getChatCompletionFunctionDescriptions: () => ChatCompletionCreateParams.Function[];\n getFunctionCallHandler: () => FunctionCallHandler;\n\n // text context\n getContextString: (\n documents: DocumentPointer[],\n categories?: string[]\n ) => string;\n addContext: (\n context: string,\n parentId?: string,\n categories?: string[]\n ) => TreeNodeId;\n removeContext: (id: TreeNodeId) => void;\n\n // document context\n getDocumentsContext: (categories?: string[]) => DocumentPointer[];\n addDocumentContext: (\n documentPointer: DocumentPointer,\n categories?: string[]\n ) => TreeNodeId;\n removeDocumentContext: (documentId: string) => void;\n\n // api endpoints\n copilotApiConfig: CopilotApiConfig;\n}\n\nconst emptyCopilotContext: CopilotContextParams = {\n entryPoints: {},\n setEntryPoint: () => {},\n removeEntryPoint: () => {},\n getChatCompletionFunctionDescriptions: () => returnAndThrowInDebug([]),\n getFunctionCallHandler: () => returnAndThrowInDebug(async () => {}),\n\n getContextString: (documents: DocumentPointer[]) => returnAndThrowInDebug(\"\"),\n addContext: () => \"\",\n removeContext: () => {},\n\n getDocumentsContext: () => returnAndThrowInDebug([]),\n addDocumentContext: () => returnAndThrowInDebug(\"\"),\n removeDocumentContext: () => {},\n\n copilotApiConfig: new (class implements CopilotApiConfig {\n get chatApiEndpoint(): string {\n throw new Error(\n \"Remember to wrap your app in a `<CopilotProvider> {...} </CopilotProvider>` !!!\"\n );\n }\n get headers(): Record<string, string> {\n return {};\n }\n get body(): Record<string, any> {\n return {};\n }\n })(),\n};\n\nexport const CopilotContext =\n React.createContext<CopilotContextParams>(emptyCopilotContext);\n\nfunction returnAndThrowInDebug<T>(value: T): T {\n throw new Error(\n \"Remember to wrap your app in a `<CopilotProvider> {...} </CopilotProvider>` !!!\"\n );\n return value;\n}\n"]}