@copilotkit/react-core 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +69 -11
- package/CHANGELOG.md +6 -0
- package/LICENSE +21 -0
- package/dist/chunk-7IPFT6UY.mjs +115 -0
- package/dist/chunk-7IPFT6UY.mjs.map +1 -0
- package/dist/chunk-7TCGEDGA.mjs +19 -0
- package/dist/chunk-7TCGEDGA.mjs.map +1 -0
- package/dist/chunk-BVQRDAR7.mjs +3 -0
- package/dist/chunk-BVQRDAR7.mjs.map +1 -0
- package/dist/chunk-EFZPSZWO.mjs +3 -0
- package/dist/chunk-EFZPSZWO.mjs.map +1 -0
- package/dist/chunk-GJUAS6I7.mjs +80 -0
- package/dist/chunk-GJUAS6I7.mjs.map +1 -0
- package/dist/chunk-JD7BAH7U.mjs +3 -0
- package/dist/chunk-JD7BAH7U.mjs.map +1 -0
- package/dist/chunk-MRXNTQOX.mjs +55 -0
- package/dist/chunk-MRXNTQOX.mjs.map +1 -0
- package/dist/chunk-OMI7JPW5.mjs +30 -0
- package/dist/chunk-OMI7JPW5.mjs.map +1 -0
- package/dist/chunk-UABEP4UT.mjs +22 -0
- package/dist/chunk-UABEP4UT.mjs.map +1 -0
- package/dist/chunk-VNRDQJXW.mjs +3 -0
- package/dist/chunk-VNRDQJXW.mjs.map +1 -0
- package/dist/chunk-YVXQVXMS.mjs +111 -0
- package/dist/chunk-YVXQVXMS.mjs.map +1 -0
- package/dist/components/copilot-provider.d.ts +7 -0
- package/dist/components/copilot-provider.mjs +6 -0
- package/dist/components/copilot-provider.mjs.map +1 -0
- package/dist/components/index.d.ts +2 -0
- package/dist/components/index.mjs +7 -0
- package/dist/components/index.mjs.map +1 -0
- package/dist/context/copilot-context.d.ts +19 -0
- package/dist/context/copilot-context.mjs +4 -0
- package/dist/context/copilot-context.mjs.map +1 -0
- package/dist/context/index.d.ts +6 -0
- package/dist/context/index.mjs +5 -0
- package/dist/context/index.mjs.map +1 -0
- package/dist/hooks/index.d.ts +5 -0
- package/dist/hooks/index.mjs +8 -0
- package/dist/hooks/index.mjs.map +1 -0
- package/dist/hooks/use-copilot-chat.d.ts +18 -0
- package/dist/hooks/use-copilot-chat.mjs +5 -0
- package/dist/hooks/use-copilot-chat.mjs.map +1 -0
- package/dist/hooks/use-make-copilot-actionable.d.ts +5 -0
- package/dist/hooks/use-make-copilot-actionable.mjs +5 -0
- package/dist/hooks/use-make-copilot-actionable.mjs.map +1 -0
- package/dist/hooks/use-make-copilot-readable.d.ts +3 -0
- package/dist/hooks/use-make-copilot-readable.mjs +5 -0
- package/dist/hooks/use-make-copilot-readable.mjs.map +1 -0
- package/dist/hooks/use-tree.d.ts +17 -0
- package/dist/hooks/use-tree.mjs +4 -0
- package/dist/hooks/use-tree.mjs.map +1 -0
- package/dist/index.d.ts +10 -55
- package/dist/index.mjs +13 -26
- package/dist/index.mjs.map +1 -0
- package/dist/types/annotated-function.d.ts +24 -0
- package/dist/types/annotated-function.mjs +3 -0
- package/dist/types/annotated-function.mjs.map +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.mjs +3 -0
- package/dist/types/index.mjs.map +1 -0
- package/package.json +8 -8
- package/src/components/copilot-provider.tsx +60 -55
- package/src/components/index.ts +1 -1
- package/src/context/copilot-context.tsx +20 -20
- package/src/context/index.ts +2 -2
- package/src/hooks/index.ts +5 -5
- package/src/hooks/use-copilot-chat.ts +43 -39
- package/src/hooks/use-make-copilot-actionable.ts +13 -13
- package/src/hooks/use-make-copilot-readable.ts +11 -11
- package/src/hooks/use-tree.ts +87 -76
- package/src/index.tsx +4 -4
- package/src/types/annotated-function.ts +23 -10
- package/src/types/index.ts +2 -2
- package/tsup.config.ts +3 -5
- package/dist/index.js +0 -32
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/hooks/use-tree.ts"],"names":[],"mappings":";;;;;;AAAA,SAAS,cAAc;AACvB,SAA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C;AAEL,QAAM,YAAY,MAAc;AAC9B,QAAI,SAAS;AACb,SAAK;AAAA,MACH,CAAC,MAAM,UACJ,UAAU;AAAA,QACT;AAAA,QACA,GAAG,8BAA8B,OAAO,CAAC;AAAA,MAC3C;AAAA,IACJ;AACA,WAAO;AAAA,EACT;AAEA,SAAO,EAAE,MAAM,YAAY,WAAW,cAAc;AACtD;AAEA,IAAO,mBAAQ","sourcesContent":["import { nanoid } from \"nanoid\";\nimport { useReducer, useCallback } from \"react\";\n\nexport type TreeNodeId = string;\n\nexport interface TreeNode {\n id: TreeNodeId;\n value: string;\n children: TreeNode[];\n parentId?: TreeNodeId;\n}\n\nexport type Tree = TreeNode[];\n\nexport interface UseTreeReturn {\n tree: Tree;\n addElement: (value: string, parentId?: TreeNodeId) => TreeNodeId;\n printTree: () => 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 throw new Error(\"Indentation level not supported\");\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 node.children.forEach(\n (child, index) =>\n (output += printNode(\n child,\n `${prefix}${treeIndentationRepresentation(index, indentLevel + 1)}. `,\n indentLevel + 1\n ))\n );\n return output;\n};\n\n// Action types\ntype Action =\n | { type: \"ADD_NODE\"; value: string; parentId?: string; id: string }\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 };\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, parentId?: string): TreeNodeId => {\n const newNodeId = nanoid(); // Generate new ID outside of dispatch\n dispatch({ type: \"ADD_NODE\", value, parentId, id: newNodeId });\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 = (): string => {\n let output = \"\";\n tree.forEach(\n (node, index) =>\n (output += printNode(\n node,\n `${treeIndentationRepresentation(index, 0)}. `\n ))\n );\n return output;\n };\n\n return { tree, addElement, printTree, removeElement };\n};\n\nexport default useTree;\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { AnnotatedFunction } from '../types/annotated-function.js';
|
|
3
|
+
import { TreeNodeId } from '../hooks/use-tree.js';
|
|
4
|
+
import { ChatCompletionFunctions } from 'openai-edge/types/api';
|
|
5
|
+
import { FunctionCallHandler } from 'ai';
|
|
6
|
+
|
|
7
|
+
interface CopilotContextParams {
|
|
8
|
+
entryPoints: Record<string, AnnotatedFunction<any[]>>;
|
|
9
|
+
getChatCompletionFunctionDescriptions: () => ChatCompletionFunctions[];
|
|
10
|
+
getFunctionCallHandler: () => FunctionCallHandler;
|
|
11
|
+
setEntryPoint: (id: string, entryPoint: AnnotatedFunction<any[]>) => void;
|
|
12
|
+
removeEntryPoint: (id: string) => void;
|
|
13
|
+
getContextString: () => string;
|
|
14
|
+
addContext: (context: string, parentId?: string) => TreeNodeId;
|
|
15
|
+
removeContext: (id: TreeNodeId) => void;
|
|
16
|
+
}
|
|
17
|
+
declare const CopilotContext: React.Context<CopilotContextParams>;
|
|
18
|
+
|
|
19
|
+
export { CopilotContext, CopilotContextParams };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { UseCopilotChatOptions, UseCopilotChatReturn, useCopilotChat } from './use-copilot-chat.js';
|
|
2
|
+
export { useMakeCopilotActionable } from './use-make-copilot-actionable.js';
|
|
3
|
+
export { useMakeCopilotReadable } from './use-make-copilot-readable.js';
|
|
4
|
+
import 'ai';
|
|
5
|
+
import '../types/annotated-function.js';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import '../chunk-BVQRDAR7.mjs';
|
|
2
|
+
export { useMakeCopilotReadable } from '../chunk-7TCGEDGA.mjs';
|
|
3
|
+
export { useCopilotChat } from '../chunk-GJUAS6I7.mjs';
|
|
4
|
+
export { useMakeCopilotActionable } from '../chunk-OMI7JPW5.mjs';
|
|
5
|
+
import '../chunk-UABEP4UT.mjs';
|
|
6
|
+
import '../chunk-MRXNTQOX.mjs';
|
|
7
|
+
//# sourceMappingURL=out.js.map
|
|
8
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { UseChatOptions, Message, CreateMessage, ChatRequestOptions } from 'ai';
|
|
2
|
+
|
|
3
|
+
interface UseCopilotChatOptions extends UseChatOptions {
|
|
4
|
+
makeSystemMessage?: (contextString: string) => string;
|
|
5
|
+
}
|
|
6
|
+
interface UseCopilotChatReturn {
|
|
7
|
+
visibleMessages: Message[];
|
|
8
|
+
append: (message: Message | CreateMessage, chatRequestOptions?: ChatRequestOptions) => Promise<string | null | undefined>;
|
|
9
|
+
reload: (chatRequestOptions?: ChatRequestOptions) => Promise<string | null | undefined>;
|
|
10
|
+
stop: () => void;
|
|
11
|
+
isLoading: boolean;
|
|
12
|
+
input: string;
|
|
13
|
+
setInput: React.Dispatch<React.SetStateAction<string>>;
|
|
14
|
+
}
|
|
15
|
+
declare function useCopilotChat({ makeSystemMessage, ...options }: UseCopilotChatOptions): UseCopilotChatReturn;
|
|
16
|
+
declare function defaultSystemMessage(contextString: string): string;
|
|
17
|
+
|
|
18
|
+
export { UseCopilotChatOptions, UseCopilotChatReturn, defaultSystemMessage, useCopilotChat };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
type TreeNodeId = string;
|
|
2
|
+
interface TreeNode {
|
|
3
|
+
id: TreeNodeId;
|
|
4
|
+
value: string;
|
|
5
|
+
children: TreeNode[];
|
|
6
|
+
parentId?: TreeNodeId;
|
|
7
|
+
}
|
|
8
|
+
type Tree = TreeNode[];
|
|
9
|
+
interface UseTreeReturn {
|
|
10
|
+
tree: Tree;
|
|
11
|
+
addElement: (value: string, parentId?: TreeNodeId) => TreeNodeId;
|
|
12
|
+
printTree: () => string;
|
|
13
|
+
removeElement: (id: TreeNodeId) => void;
|
|
14
|
+
}
|
|
15
|
+
declare const useTree: () => UseTreeReturn;
|
|
16
|
+
|
|
17
|
+
export { Tree, TreeNode, TreeNodeId, UseTreeReturn, useTree as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,55 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
type: string;
|
|
12
|
-
description: string;
|
|
13
|
-
allowedValues?: any[];
|
|
14
|
-
required: boolean;
|
|
15
|
-
}
|
|
16
|
-
interface AnnotatedFunction<Inputs extends any[]> {
|
|
17
|
-
name: string;
|
|
18
|
-
description: string;
|
|
19
|
-
argumentAnnotations: AnnotatedFunctionArgument[];
|
|
20
|
-
implementation: (...args: Inputs) => Promise<void>;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
type TreeNodeId = string;
|
|
24
|
-
|
|
25
|
-
interface CopilotContextParams {
|
|
26
|
-
entryPoints: Record<string, AnnotatedFunction<any[]>>;
|
|
27
|
-
getChatCompletionFunctions: () => ChatCompletionFunctions[];
|
|
28
|
-
getFunctionCallHandler: () => FunctionCallHandler;
|
|
29
|
-
setEntryPoint: (id: string, entryPoint: AnnotatedFunction<any[]>) => void;
|
|
30
|
-
removeEntryPoint: (id: string) => void;
|
|
31
|
-
getContextString: () => string;
|
|
32
|
-
addContext: (context: string, parentId?: string) => TreeNodeId;
|
|
33
|
-
removeContext: (id: TreeNodeId) => void;
|
|
34
|
-
}
|
|
35
|
-
declare const CopilotContext: React$1.Context<CopilotContextParams>;
|
|
36
|
-
|
|
37
|
-
interface UseCopilotChatOptions extends UseChatOptions {
|
|
38
|
-
makeSystemMessage?: (contextString: string) => string;
|
|
39
|
-
}
|
|
40
|
-
interface UseCopilotChatReturn {
|
|
41
|
-
visibleMessages: Message[];
|
|
42
|
-
append: (message: Message | CreateMessage, chatRequestOptions?: ChatRequestOptions) => Promise<string | null | undefined>;
|
|
43
|
-
reload: (chatRequestOptions?: ChatRequestOptions) => Promise<string | null | undefined>;
|
|
44
|
-
stop: () => void;
|
|
45
|
-
isLoading: boolean;
|
|
46
|
-
input: string;
|
|
47
|
-
setInput: React.Dispatch<React.SetStateAction<string>>;
|
|
48
|
-
}
|
|
49
|
-
declare function useCopilotChat({ makeSystemMessage, ...options }: UseCopilotChatOptions): UseCopilotChatReturn;
|
|
50
|
-
|
|
51
|
-
declare function useMakeCopilotActionable<ActionInput extends any[]>(annotatedFunction: AnnotatedFunction<ActionInput>, dependencies: any[]): void;
|
|
52
|
-
|
|
53
|
-
declare function useMakeCopilotReadable(information: string, parentId?: string): string | undefined;
|
|
54
|
-
|
|
55
|
-
export { AnnotatedFunction, AnnotatedFunctionArgument, CopilotContext, CopilotContextParams, CopilotProvider, UseCopilotChatOptions, UseCopilotChatReturn, useCopilotChat, useMakeCopilotActionable, useMakeCopilotReadable };
|
|
1
|
+
export { CopilotProvider } from './components/copilot-provider.js';
|
|
2
|
+
export { CopilotContext, CopilotContextParams } from './context/copilot-context.js';
|
|
3
|
+
export { UseCopilotChatOptions, UseCopilotChatReturn, useCopilotChat } from './hooks/use-copilot-chat.js';
|
|
4
|
+
export { useMakeCopilotActionable } from './hooks/use-make-copilot-actionable.js';
|
|
5
|
+
export { useMakeCopilotReadable } from './hooks/use-make-copilot-readable.js';
|
|
6
|
+
export { AnnotatedFunction, AnnotatedFunctionArgument } from './types/annotated-function.js';
|
|
7
|
+
import 'react';
|
|
8
|
+
import './hooks/use-tree.js';
|
|
9
|
+
import 'openai-edge/types/api';
|
|
10
|
+
import 'ai';
|
package/dist/index.mjs
CHANGED
|
@@ -1,26 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
The user has provided you with the following context:
|
|
16
|
-
\`\`\`
|
|
17
|
-
${e}
|
|
18
|
-
\`\`\`
|
|
19
|
-
|
|
20
|
-
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.
|
|
21
|
-
|
|
22
|
-
Please assist them as best you can.
|
|
23
|
-
If you are not sure how to proceed to best fulfill their requests, please ask them for more information.
|
|
24
|
-
`}function ae(e,t){let n=useRef(nanoid()),{setEntryPoint:o,removeEntryPoint:r}=useContext(d),i=useMemo(()=>({name:e.name,description:e.description,argumentAnnotations:e.argumentAnnotations,implementation:e.implementation}),t);useEffect(()=>(o(n.current,i),()=>{r(n.current);}),[i,o,r]);}function de(e,t){let{addContext:n,removeContext:o}=useContext(d),r=useRef();return useEffect(()=>{let i=n(e,t);return r.current=i,()=>{o(i);}},[e,t,n,o]),r.current}
|
|
25
|
-
|
|
26
|
-
export { d as CopilotContext, B as CopilotProvider, Z as useCopilotChat, ae as useMakeCopilotActionable, de as useMakeCopilotReadable };
|
|
1
|
+
import './chunk-EFZPSZWO.mjs';
|
|
2
|
+
import './chunk-JD7BAH7U.mjs';
|
|
3
|
+
export { CopilotProvider } from './chunk-7IPFT6UY.mjs';
|
|
4
|
+
import './chunk-YVXQVXMS.mjs';
|
|
5
|
+
import './chunk-VNRDQJXW.mjs';
|
|
6
|
+
import './chunk-BVQRDAR7.mjs';
|
|
7
|
+
export { useMakeCopilotReadable } from './chunk-7TCGEDGA.mjs';
|
|
8
|
+
export { useCopilotChat } from './chunk-GJUAS6I7.mjs';
|
|
9
|
+
export { useMakeCopilotActionable } from './chunk-OMI7JPW5.mjs';
|
|
10
|
+
export { CopilotContext } from './chunk-UABEP4UT.mjs';
|
|
11
|
+
import './chunk-MRXNTQOX.mjs';
|
|
12
|
+
//# sourceMappingURL=out.js.map
|
|
13
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
interface AnnotatedFunctionSimpleArgument {
|
|
2
|
+
name: string;
|
|
3
|
+
type: "string" | "number" | "boolean" | "object";
|
|
4
|
+
description: string;
|
|
5
|
+
required: boolean;
|
|
6
|
+
}
|
|
7
|
+
interface AnnotatedFunctionArrayArgument {
|
|
8
|
+
name: string;
|
|
9
|
+
type: "array";
|
|
10
|
+
items: {
|
|
11
|
+
type: string;
|
|
12
|
+
};
|
|
13
|
+
description: string;
|
|
14
|
+
required: boolean;
|
|
15
|
+
}
|
|
16
|
+
type AnnotatedFunctionArgument = AnnotatedFunctionSimpleArgument | AnnotatedFunctionArrayArgument;
|
|
17
|
+
interface AnnotatedFunction<Inputs extends any[]> {
|
|
18
|
+
name: string;
|
|
19
|
+
description: string;
|
|
20
|
+
argumentAnnotations: AnnotatedFunctionArgument[];
|
|
21
|
+
implementation: (...args: Inputs) => Promise<void>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export { AnnotatedFunction, AnnotatedFunctionArgument, AnnotatedFunctionArrayArgument, AnnotatedFunctionSimpleArgument };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { AnnotatedFunction, AnnotatedFunctionArgument } from './annotated-function.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.
|
|
7
|
+
"version": "0.4.0",
|
|
8
8
|
"sideEffects": false,
|
|
9
|
-
"main": "./dist/index.
|
|
9
|
+
"main": "./dist/index.js",
|
|
10
10
|
"module": "./dist/index.mjs",
|
|
11
11
|
"exports": "./dist/index.mjs",
|
|
12
12
|
"types": "./dist/index.d.ts",
|
|
@@ -18,19 +18,19 @@
|
|
|
18
18
|
"@types/react": "^18.2.5",
|
|
19
19
|
"eslint": "^7.32.0",
|
|
20
20
|
"react": "^18.2.0",
|
|
21
|
-
"tsup": "^6.
|
|
21
|
+
"tsup": "^6.5.0",
|
|
22
22
|
"typescript": "^4.9.4",
|
|
23
|
-
"
|
|
24
|
-
"
|
|
23
|
+
"tsconfig": "0.2.0",
|
|
24
|
+
"eslint-config-custom": "0.1.0"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"ai": "^2.1.
|
|
27
|
+
"ai": "^2.1.22",
|
|
28
28
|
"nanoid": "^4.0.2",
|
|
29
29
|
"openai-edge": "^1.2.0"
|
|
30
30
|
},
|
|
31
31
|
"scripts": {
|
|
32
|
-
"build": "tsup
|
|
33
|
-
"dev": "tsup
|
|
32
|
+
"build": "tsup --treeshake",
|
|
33
|
+
"dev": "tsup --watch --no-splitting",
|
|
34
34
|
"check-types": "tsc --noEmit",
|
|
35
35
|
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist && rm -rf .next"
|
|
36
36
|
}
|
|
@@ -1,113 +1,116 @@
|
|
|
1
|
-
|
|
2
|
-
import React, { useState, ReactNode, useCallback } from
|
|
3
|
-
import { AnnotatedFunction } from
|
|
4
|
-
import useTree from
|
|
5
|
-
import { CopilotContext } from
|
|
6
|
-
import { FunctionCallHandler } from
|
|
7
|
-
import { ChatCompletionFunctions } from
|
|
1
|
+
"use client";
|
|
2
|
+
import React, { useState, ReactNode, useCallback } from "react";
|
|
3
|
+
import { AnnotatedFunction } from "../types/annotated-function";
|
|
4
|
+
import useTree from "../hooks/use-tree";
|
|
5
|
+
import { CopilotContext } from "../context/copilot-context";
|
|
6
|
+
import { FunctionCallHandler } from "ai";
|
|
7
|
+
import { ChatCompletionFunctions } from "openai-edge/types/api";
|
|
8
8
|
|
|
9
9
|
export function CopilotProvider({
|
|
10
|
-
children
|
|
10
|
+
children,
|
|
11
11
|
}: {
|
|
12
|
-
children: ReactNode
|
|
12
|
+
children: ReactNode;
|
|
13
13
|
}): JSX.Element {
|
|
14
14
|
const [entryPoints, setEntryPoints] = useState<
|
|
15
15
|
Record<string, AnnotatedFunction<any[]>>
|
|
16
|
-
>({})
|
|
16
|
+
>({});
|
|
17
17
|
|
|
18
|
-
const { addElement, removeElement, printTree } = useTree()
|
|
18
|
+
const { addElement, removeElement, printTree } = useTree();
|
|
19
19
|
|
|
20
20
|
const setEntryPoint = useCallback(
|
|
21
21
|
(id: string, entryPoint: AnnotatedFunction<any[]>) => {
|
|
22
|
-
setEntryPoints(prevPoints => {
|
|
22
|
+
setEntryPoints((prevPoints) => {
|
|
23
23
|
return {
|
|
24
24
|
...prevPoints,
|
|
25
|
-
[id]: entryPoint
|
|
26
|
-
}
|
|
27
|
-
})
|
|
25
|
+
[id]: entryPoint,
|
|
26
|
+
};
|
|
27
|
+
});
|
|
28
28
|
},
|
|
29
29
|
[]
|
|
30
|
-
)
|
|
30
|
+
);
|
|
31
31
|
|
|
32
32
|
const removeEntryPoint = useCallback((id: string) => {
|
|
33
|
-
setEntryPoints(prevPoints => {
|
|
34
|
-
const newPoints = { ...prevPoints }
|
|
35
|
-
delete newPoints[id]
|
|
36
|
-
return newPoints
|
|
37
|
-
})
|
|
38
|
-
}, [])
|
|
33
|
+
setEntryPoints((prevPoints) => {
|
|
34
|
+
const newPoints = { ...prevPoints };
|
|
35
|
+
delete newPoints[id];
|
|
36
|
+
return newPoints;
|
|
37
|
+
});
|
|
38
|
+
}, []);
|
|
39
39
|
|
|
40
40
|
const getContextString = useCallback(() => {
|
|
41
|
-
return printTree()
|
|
42
|
-
}, [printTree])
|
|
41
|
+
return printTree();
|
|
42
|
+
}, [printTree]);
|
|
43
43
|
|
|
44
44
|
const addContext = useCallback(
|
|
45
45
|
(context: string, parentId?: string) => {
|
|
46
|
-
return addElement(context, parentId)
|
|
46
|
+
return addElement(context, parentId);
|
|
47
47
|
},
|
|
48
48
|
[addElement]
|
|
49
|
-
)
|
|
49
|
+
);
|
|
50
50
|
|
|
51
51
|
const removeContext = useCallback(
|
|
52
52
|
(id: string) => {
|
|
53
|
-
removeElement(id)
|
|
53
|
+
removeElement(id);
|
|
54
54
|
},
|
|
55
55
|
[removeElement]
|
|
56
|
-
)
|
|
56
|
+
);
|
|
57
57
|
|
|
58
|
-
const
|
|
59
|
-
return entryPointsToChatCompletionFunctions(Object.values(entryPoints))
|
|
60
|
-
}, [entryPoints])
|
|
58
|
+
const getChatCompletionFunctionDescriptions = useCallback(() => {
|
|
59
|
+
return entryPointsToChatCompletionFunctions(Object.values(entryPoints));
|
|
60
|
+
}, [entryPoints]);
|
|
61
61
|
|
|
62
62
|
const getFunctionCallHandler = useCallback(() => {
|
|
63
|
-
return entryPointsToFunctionCallHandler(Object.values(entryPoints))
|
|
64
|
-
}, [entryPoints])
|
|
63
|
+
return entryPointsToFunctionCallHandler(Object.values(entryPoints));
|
|
64
|
+
}, [entryPoints]);
|
|
65
65
|
|
|
66
66
|
return (
|
|
67
67
|
<CopilotContext.Provider
|
|
68
68
|
value={{
|
|
69
69
|
entryPoints,
|
|
70
|
-
|
|
70
|
+
getChatCompletionFunctionDescriptions,
|
|
71
71
|
getFunctionCallHandler,
|
|
72
72
|
setEntryPoint,
|
|
73
73
|
removeEntryPoint,
|
|
74
74
|
getContextString,
|
|
75
75
|
addContext,
|
|
76
|
-
removeContext
|
|
76
|
+
removeContext,
|
|
77
77
|
}}
|
|
78
78
|
>
|
|
79
79
|
{children}
|
|
80
80
|
</CopilotContext.Provider>
|
|
81
|
-
)
|
|
81
|
+
);
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
function entryPointsToFunctionCallHandler(
|
|
85
85
|
entryPoints: AnnotatedFunction<any[]>[]
|
|
86
86
|
): FunctionCallHandler {
|
|
87
87
|
return async (chatMessages, functionCall) => {
|
|
88
|
-
let entrypointsByFunctionName: Record<
|
|
88
|
+
let entrypointsByFunctionName: Record<
|
|
89
|
+
string,
|
|
90
|
+
AnnotatedFunction<any[]>
|
|
91
|
+
> = {};
|
|
89
92
|
for (let entryPoint of entryPoints) {
|
|
90
|
-
entrypointsByFunctionName[entryPoint.name] = entryPoint
|
|
93
|
+
entrypointsByFunctionName[entryPoint.name] = entryPoint;
|
|
91
94
|
}
|
|
92
95
|
|
|
93
96
|
const entryPointFunction =
|
|
94
|
-
entrypointsByFunctionName[functionCall.name ||
|
|
97
|
+
entrypointsByFunctionName[functionCall.name || ""];
|
|
95
98
|
if (entryPointFunction) {
|
|
96
|
-
let parsedFunctionCallArguments: Record<string, any>[] = []
|
|
99
|
+
let parsedFunctionCallArguments: Record<string, any>[] = [];
|
|
97
100
|
if (functionCall.arguments) {
|
|
98
|
-
parsedFunctionCallArguments = JSON.parse(functionCall.arguments)
|
|
101
|
+
parsedFunctionCallArguments = JSON.parse(functionCall.arguments);
|
|
99
102
|
}
|
|
100
103
|
|
|
101
|
-
const paramsInCorrectOrder: any[] = []
|
|
104
|
+
const paramsInCorrectOrder: any[] = [];
|
|
102
105
|
for (let arg of entryPointFunction.argumentAnnotations) {
|
|
103
106
|
paramsInCorrectOrder.push(
|
|
104
107
|
parsedFunctionCallArguments[
|
|
105
108
|
arg.name as keyof typeof parsedFunctionCallArguments
|
|
106
109
|
]
|
|
107
|
-
)
|
|
110
|
+
);
|
|
108
111
|
}
|
|
109
112
|
|
|
110
|
-
await entryPointFunction.implementation(...paramsInCorrectOrder)
|
|
113
|
+
await entryPointFunction.implementation(...paramsInCorrectOrder);
|
|
111
114
|
|
|
112
115
|
// commented out becasue for now we don't want to return anything
|
|
113
116
|
// const result = await entryPointFunction.implementation(
|
|
@@ -127,28 +130,30 @@ function entryPointsToFunctionCallHandler(
|
|
|
127
130
|
|
|
128
131
|
// return functionResponse;
|
|
129
132
|
}
|
|
130
|
-
}
|
|
133
|
+
};
|
|
131
134
|
}
|
|
132
135
|
|
|
133
136
|
function entryPointsToChatCompletionFunctions(
|
|
134
137
|
entryPoints: AnnotatedFunction<any[]>[]
|
|
135
138
|
): ChatCompletionFunctions[] {
|
|
136
|
-
return entryPoints.map(annotatedFunctionToChatCompletionFunction)
|
|
139
|
+
return entryPoints.map(annotatedFunctionToChatCompletionFunction);
|
|
137
140
|
}
|
|
138
141
|
|
|
139
142
|
function annotatedFunctionToChatCompletionFunction(
|
|
140
143
|
annotatedFunction: AnnotatedFunction<any[]>
|
|
141
144
|
): ChatCompletionFunctions {
|
|
142
145
|
// Create the parameters object based on the argumentAnnotations
|
|
143
|
-
let parameters: { [key: string]: any } = {}
|
|
146
|
+
let parameters: { [key: string]: any } = {};
|
|
144
147
|
for (let arg of annotatedFunction.argumentAnnotations) {
|
|
145
|
-
|
|
148
|
+
// isolate the args we should forward inline
|
|
149
|
+
let { name, required, ...forwardedArgs } = arg;
|
|
150
|
+
parameters[arg.name] = forwardedArgs;
|
|
146
151
|
}
|
|
147
152
|
|
|
148
|
-
let requiredParameterNames: string[] = []
|
|
153
|
+
let requiredParameterNames: string[] = [];
|
|
149
154
|
for (let arg of annotatedFunction.argumentAnnotations) {
|
|
150
155
|
if (arg.required) {
|
|
151
|
-
requiredParameterNames.push(arg.name)
|
|
156
|
+
requiredParameterNames.push(arg.name);
|
|
152
157
|
}
|
|
153
158
|
}
|
|
154
159
|
|
|
@@ -157,11 +162,11 @@ function annotatedFunctionToChatCompletionFunction(
|
|
|
157
162
|
name: annotatedFunction.name,
|
|
158
163
|
description: annotatedFunction.description,
|
|
159
164
|
parameters: {
|
|
160
|
-
type:
|
|
165
|
+
type: "object",
|
|
161
166
|
properties: parameters,
|
|
162
|
-
required: requiredParameterNames
|
|
163
|
-
}
|
|
164
|
-
}
|
|
167
|
+
required: requiredParameterNames,
|
|
168
|
+
},
|
|
169
|
+
};
|
|
165
170
|
|
|
166
|
-
return chatCompletionFunction
|
|
171
|
+
return chatCompletionFunction;
|
|
167
172
|
}
|
package/src/components/index.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { CopilotProvider } from
|
|
1
|
+
export { CopilotProvider } from "./copilot-provider";
|