@copilotkit/react-core 0.3.0 → 0.5.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 +13 -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
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,19 +1,77 @@
|
|
|
1
1
|
|
|
2
|
-
> @copilotkit/react-core@0.
|
|
3
|
-
> tsup
|
|
2
|
+
> @copilotkit/react-core@0.4.0 build /Users/ataibarkai/LocalGit/Recursively.ai/CopilotKit/packages/react-core
|
|
3
|
+
> tsup --treeshake
|
|
4
4
|
|
|
5
|
-
CLI Building entry: src/index.tsx
|
|
5
|
+
CLI Building entry: src/index.tsx, src/components/copilot-provider.tsx, src/components/index.ts, src/context/copilot-context.tsx, src/context/index.ts, src/hooks/index.ts, src/hooks/use-copilot-chat.ts, src/hooks/use-make-copilot-actionable.ts, src/hooks/use-make-copilot-readable.ts, src/hooks/use-tree.ts, src/types/annotated-function.ts, src/types/index.ts
|
|
6
6
|
CLI Using tsconfig: tsconfig.json
|
|
7
7
|
CLI tsup v6.5.0
|
|
8
|
-
CLI Using tsup config: /Users/ataibarkai/LocalGit/Recursively.ai/
|
|
8
|
+
CLI Using tsup config: /Users/ataibarkai/LocalGit/Recursively.ai/CopilotKit/packages/react-core/tsup.config.ts
|
|
9
9
|
CLI Target: es6
|
|
10
10
|
CLI Cleaning output folder
|
|
11
11
|
ESM Build start
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
Generated an empty chunk: "annotated-function".
|
|
13
|
+
Generated an empty chunk: "chunk-EFZPSZWO".
|
|
14
|
+
Generated an empty chunk: "chunk-JD7BAH7U".
|
|
15
|
+
Generated an empty chunk: "chunk-VNRDQJXW".
|
|
16
|
+
Generated an empty chunk: "chunk-BVQRDAR7".
|
|
17
|
+
ESM dist/chunk-JD7BAH7U.mjs 76.00 B
|
|
18
|
+
ESM dist/hooks/use-make-copilot-readable.mjs 214.00 B
|
|
19
|
+
ESM dist/types/index.mjs 98.00 B
|
|
20
|
+
ESM dist/components/copilot-provider.mjs 230.00 B
|
|
21
|
+
ESM dist/context/index.mjs 186.00 B
|
|
22
|
+
ESM dist/index.mjs 546.00 B
|
|
23
|
+
ESM dist/chunk-EFZPSZWO.mjs 76.00 B
|
|
24
|
+
ESM dist/chunk-BVQRDAR7.mjs 76.00 B
|
|
25
|
+
ESM dist/chunk-7IPFT6UY.mjs 3.56 KB
|
|
26
|
+
ESM dist/chunk-VNRDQJXW.mjs 76.00 B
|
|
27
|
+
ESM dist/chunk-YVXQVXMS.mjs 3.28 KB
|
|
28
|
+
ESM dist/components/index.mjs 251.00 B
|
|
29
|
+
ESM dist/chunk-7TCGEDGA.mjs 602.00 B
|
|
30
|
+
ESM dist/chunk-MRXNTQOX.mjs 1.92 KB
|
|
31
|
+
ESM dist/hooks/index.mjs 348.00 B
|
|
32
|
+
ESM dist/hooks/use-tree.mjs 170.00 B
|
|
33
|
+
ESM dist/chunk-UABEP4UT.mjs 570.00 B
|
|
34
|
+
ESM dist/chunk-GJUAS6I7.mjs 2.59 KB
|
|
35
|
+
ESM dist/hooks/use-make-copilot-actionable.mjs 218.00 B
|
|
36
|
+
ESM dist/hooks/use-copilot-chat.mjs 219.00 B
|
|
37
|
+
ESM dist/chunk-OMI7JPW5.mjs 972.00 B
|
|
38
|
+
ESM dist/context/copilot-context.mjs 164.00 B
|
|
39
|
+
ESM dist/types/annotated-function.mjs 80.00 B
|
|
40
|
+
ESM dist/chunk-JD7BAH7U.mjs.map 51.00 B
|
|
41
|
+
ESM dist/hooks/use-make-copilot-readable.mjs.map 51.00 B
|
|
42
|
+
ESM dist/components/copilot-provider.mjs.map 51.00 B
|
|
43
|
+
ESM dist/index.mjs.map 51.00 B
|
|
44
|
+
ESM dist/chunk-VNRDQJXW.mjs.map 51.00 B
|
|
45
|
+
ESM dist/chunk-7IPFT6UY.mjs.map 7.04 KB
|
|
46
|
+
ESM dist/chunk-BVQRDAR7.mjs.map 51.00 B
|
|
47
|
+
ESM dist/chunk-YVXQVXMS.mjs.map 6.82 KB
|
|
48
|
+
ESM dist/types/index.mjs.map 51.00 B
|
|
49
|
+
ESM dist/chunk-7TCGEDGA.mjs.map 1015.00 B
|
|
50
|
+
ESM dist/chunk-MRXNTQOX.mjs.map 71.00 B
|
|
51
|
+
ESM dist/chunk-UABEP4UT.mjs.map 1.59 KB
|
|
52
|
+
ESM dist/chunk-EFZPSZWO.mjs.map 51.00 B
|
|
53
|
+
ESM dist/hooks/use-tree.mjs.map 51.00 B
|
|
54
|
+
ESM dist/chunk-GJUAS6I7.mjs.map 4.43 KB
|
|
55
|
+
ESM dist/hooks/index.mjs.map 51.00 B
|
|
56
|
+
ESM dist/context/index.mjs.map 51.00 B
|
|
57
|
+
ESM dist/hooks/use-make-copilot-actionable.mjs.map 51.00 B
|
|
58
|
+
ESM dist/hooks/use-copilot-chat.mjs.map 51.00 B
|
|
59
|
+
ESM dist/chunk-OMI7JPW5.mjs.map 1.70 KB
|
|
60
|
+
ESM dist/components/index.mjs.map 51.00 B
|
|
61
|
+
ESM dist/context/copilot-context.mjs.map 51.00 B
|
|
62
|
+
ESM dist/types/annotated-function.mjs.map 51.00 B
|
|
63
|
+
ESM ⚡️ Build success in 82ms
|
|
17
64
|
DTS Build start
|
|
18
|
-
DTS ⚡️ Build success in
|
|
19
|
-
DTS dist/index.d.ts
|
|
65
|
+
DTS ⚡️ Build success in 487ms
|
|
66
|
+
DTS dist/index.d.ts 607.00 B
|
|
67
|
+
DTS dist/components/copilot-provider.d.ts 157.00 B
|
|
68
|
+
DTS dist/context/copilot-context.d.ts 868.00 B
|
|
69
|
+
DTS dist/hooks/use-copilot-chat.d.ts 890.00 B
|
|
70
|
+
DTS dist/hooks/use-make-copilot-actionable.d.ts 255.00 B
|
|
71
|
+
DTS dist/hooks/use-make-copilot-readable.d.ts 137.00 B
|
|
72
|
+
DTS dist/types/annotated-function.d.ts 767.00 B
|
|
73
|
+
DTS dist/hooks/use-tree.d.ts 472.00 B
|
|
74
|
+
DTS dist/components/index.d.ts 73.00 B
|
|
75
|
+
DTS dist/context/index.d.ts 210.00 B
|
|
76
|
+
DTS dist/hooks/index.d.ts 305.00 B
|
|
77
|
+
DTS dist/types/index.d.ts 88.00 B
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# ui
|
|
2
2
|
|
|
3
|
+
## 0.5.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- bring private packages back into the void
|
|
8
|
+
- added tsconfig and eslint-config-custom to copilotkit scope
|
|
9
|
+
|
|
10
|
+
## 0.4.0
|
|
11
|
+
|
|
12
|
+
### Minor Changes
|
|
13
|
+
|
|
14
|
+
- first beta release
|
|
15
|
+
|
|
3
16
|
## 0.3.0
|
|
4
17
|
|
|
5
18
|
### Minor Changes
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Atai Barkai
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { use_tree_default } from './chunk-YVXQVXMS.mjs';
|
|
2
|
+
import { CopilotContext } from './chunk-UABEP4UT.mjs';
|
|
3
|
+
import { __spreadProps, __spreadValues, __async, __objRest } from './chunk-MRXNTQOX.mjs';
|
|
4
|
+
import { useState, useCallback } from 'react';
|
|
5
|
+
import { jsx } from 'react/jsx-runtime';
|
|
6
|
+
|
|
7
|
+
function CopilotProvider({
|
|
8
|
+
children
|
|
9
|
+
}) {
|
|
10
|
+
const [entryPoints, setEntryPoints] = useState({});
|
|
11
|
+
const { addElement, removeElement, printTree } = use_tree_default();
|
|
12
|
+
const setEntryPoint = useCallback(
|
|
13
|
+
(id, entryPoint) => {
|
|
14
|
+
setEntryPoints((prevPoints) => {
|
|
15
|
+
return __spreadProps(__spreadValues({}, prevPoints), {
|
|
16
|
+
[id]: entryPoint
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
},
|
|
20
|
+
[]
|
|
21
|
+
);
|
|
22
|
+
const removeEntryPoint = useCallback((id) => {
|
|
23
|
+
setEntryPoints((prevPoints) => {
|
|
24
|
+
const newPoints = __spreadValues({}, prevPoints);
|
|
25
|
+
delete newPoints[id];
|
|
26
|
+
return newPoints;
|
|
27
|
+
});
|
|
28
|
+
}, []);
|
|
29
|
+
const getContextString = useCallback(() => {
|
|
30
|
+
return printTree();
|
|
31
|
+
}, [printTree]);
|
|
32
|
+
const addContext = useCallback(
|
|
33
|
+
(context, parentId) => {
|
|
34
|
+
return addElement(context, parentId);
|
|
35
|
+
},
|
|
36
|
+
[addElement]
|
|
37
|
+
);
|
|
38
|
+
const removeContext = useCallback(
|
|
39
|
+
(id) => {
|
|
40
|
+
removeElement(id);
|
|
41
|
+
},
|
|
42
|
+
[removeElement]
|
|
43
|
+
);
|
|
44
|
+
const getChatCompletionFunctionDescriptions = useCallback(() => {
|
|
45
|
+
return entryPointsToChatCompletionFunctions(Object.values(entryPoints));
|
|
46
|
+
}, [entryPoints]);
|
|
47
|
+
const getFunctionCallHandler = useCallback(() => {
|
|
48
|
+
return entryPointsToFunctionCallHandler(Object.values(entryPoints));
|
|
49
|
+
}, [entryPoints]);
|
|
50
|
+
return /* @__PURE__ */ jsx(CopilotContext.Provider, {
|
|
51
|
+
value: {
|
|
52
|
+
entryPoints,
|
|
53
|
+
getChatCompletionFunctionDescriptions,
|
|
54
|
+
getFunctionCallHandler,
|
|
55
|
+
setEntryPoint,
|
|
56
|
+
removeEntryPoint,
|
|
57
|
+
getContextString,
|
|
58
|
+
addContext,
|
|
59
|
+
removeContext
|
|
60
|
+
},
|
|
61
|
+
children
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
function entryPointsToFunctionCallHandler(entryPoints) {
|
|
65
|
+
return (chatMessages, functionCall) => __async(this, null, function* () {
|
|
66
|
+
let entrypointsByFunctionName = {};
|
|
67
|
+
for (let entryPoint of entryPoints) {
|
|
68
|
+
entrypointsByFunctionName[entryPoint.name] = entryPoint;
|
|
69
|
+
}
|
|
70
|
+
const entryPointFunction = entrypointsByFunctionName[functionCall.name || ""];
|
|
71
|
+
if (entryPointFunction) {
|
|
72
|
+
let parsedFunctionCallArguments = [];
|
|
73
|
+
if (functionCall.arguments) {
|
|
74
|
+
parsedFunctionCallArguments = JSON.parse(functionCall.arguments);
|
|
75
|
+
}
|
|
76
|
+
const paramsInCorrectOrder = [];
|
|
77
|
+
for (let arg of entryPointFunction.argumentAnnotations) {
|
|
78
|
+
paramsInCorrectOrder.push(
|
|
79
|
+
parsedFunctionCallArguments[arg.name]
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
yield entryPointFunction.implementation(...paramsInCorrectOrder);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
function entryPointsToChatCompletionFunctions(entryPoints) {
|
|
87
|
+
return entryPoints.map(annotatedFunctionToChatCompletionFunction);
|
|
88
|
+
}
|
|
89
|
+
function annotatedFunctionToChatCompletionFunction(annotatedFunction) {
|
|
90
|
+
let parameters = {};
|
|
91
|
+
for (let arg of annotatedFunction.argumentAnnotations) {
|
|
92
|
+
let _a = arg, forwardedArgs = __objRest(_a, ["name", "required"]);
|
|
93
|
+
parameters[arg.name] = forwardedArgs;
|
|
94
|
+
}
|
|
95
|
+
let requiredParameterNames = [];
|
|
96
|
+
for (let arg of annotatedFunction.argumentAnnotations) {
|
|
97
|
+
if (arg.required) {
|
|
98
|
+
requiredParameterNames.push(arg.name);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
let chatCompletionFunction = {
|
|
102
|
+
name: annotatedFunction.name,
|
|
103
|
+
description: annotatedFunction.description,
|
|
104
|
+
parameters: {
|
|
105
|
+
type: "object",
|
|
106
|
+
properties: parameters,
|
|
107
|
+
required: requiredParameterNames
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
return chatCompletionFunction;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export { CopilotProvider };
|
|
114
|
+
//# sourceMappingURL=out.js.map
|
|
115
|
+
//# sourceMappingURL=chunk-7IPFT6UY.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/copilot-provider.tsx"],"names":[],"mappings":"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","sourcesContent":["\"use client\";\nimport React, { useState, ReactNode, useCallback } from \"react\";\nimport { AnnotatedFunction } from \"../types/annotated-function\";\nimport useTree from \"../hooks/use-tree\";\nimport { CopilotContext } from \"../context/copilot-context\";\nimport { FunctionCallHandler } from \"ai\";\nimport { ChatCompletionFunctions } from \"openai-edge/types/api\";\n\nexport function CopilotProvider({\n children,\n}: {\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\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 return printTree();\n }, [printTree]);\n\n const addContext = useCallback(\n (context: string, parentId?: string) => {\n return addElement(context, 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 return (\n <CopilotContext.Provider\n value={{\n entryPoints,\n getChatCompletionFunctionDescriptions,\n getFunctionCallHandler,\n setEntryPoint,\n removeEntryPoint,\n getContextString,\n addContext,\n removeContext,\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): ChatCompletionFunctions[] {\n return entryPoints.map(annotatedFunctionToChatCompletionFunction);\n}\n\nfunction annotatedFunctionToChatCompletionFunction(\n annotatedFunction: AnnotatedFunction<any[]>\n): ChatCompletionFunctions {\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: ChatCompletionFunctions = {\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"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { CopilotContext } from './chunk-UABEP4UT.mjs';
|
|
2
|
+
import { useContext, useRef, useEffect } from 'react';
|
|
3
|
+
|
|
4
|
+
function useMakeCopilotReadable(information, parentId) {
|
|
5
|
+
const { addContext, removeContext } = useContext(CopilotContext);
|
|
6
|
+
const idRef = useRef();
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
const id = addContext(information, parentId);
|
|
9
|
+
idRef.current = id;
|
|
10
|
+
return () => {
|
|
11
|
+
removeContext(id);
|
|
12
|
+
};
|
|
13
|
+
}, [information, parentId, addContext, removeContext]);
|
|
14
|
+
return idRef.current;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { useMakeCopilotReadable };
|
|
18
|
+
//# sourceMappingURL=out.js.map
|
|
19
|
+
//# sourceMappingURL=chunk-7TCGEDGA.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/hooks/use-make-copilot-readable.ts"],"names":[],"mappings":";;;;;AAEA,SAAS,QAAQ,YAAY,iBAAiB;AAF9C;AAKO,SAAS,uBACd,aACA,UACoB;AACpB,QAAM,EAAE,YAAY,cAAc,IAAI,WAAW,cAAc;AAC/D,QAAM,QAAQ,OAAe;AAE7B,YAAU,MAAM;AACd,UAAM,KAAK,WAAW,aAAa,QAAQ;AAC3C,UAAM,UAAU;AAEhB,WAAO,MAAM;AACX,oBAAc,EAAE;AAAA,IAClB;AAAA,EACF,GAAG,CAAC,aAAa,UAAU,YAAY,aAAa,CAAC;AAErD,SAAO,MAAM;AACf","sourcesContent":["\"use client\";\n\nimport { useRef, useContext, useEffect } from \"react\";\nimport { CopilotContext } from \"../context/copilot-context\";\n\nexport function useMakeCopilotReadable(\n information: string,\n parentId?: string\n): string | undefined {\n const { addContext, removeContext } = useContext(CopilotContext);\n const idRef = useRef<string>();\n\n useEffect(() => {\n const id = addContext(information, parentId);\n idRef.current = id;\n\n return () => {\n removeContext(id);\n };\n }, [information, parentId, addContext, removeContext]);\n\n return idRef.current;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { CopilotContext } from './chunk-UABEP4UT.mjs';
|
|
2
|
+
import { __objRest } from './chunk-MRXNTQOX.mjs';
|
|
3
|
+
import { useContext, useMemo } from 'react';
|
|
4
|
+
import { useChat } from 'ai/react';
|
|
5
|
+
|
|
6
|
+
function useCopilotChat(_a) {
|
|
7
|
+
var _b = _a, {
|
|
8
|
+
makeSystemMessage
|
|
9
|
+
} = _b, options = __objRest(_b, [
|
|
10
|
+
"makeSystemMessage"
|
|
11
|
+
]);
|
|
12
|
+
const {
|
|
13
|
+
getContextString,
|
|
14
|
+
getChatCompletionFunctionDescriptions,
|
|
15
|
+
getFunctionCallHandler
|
|
16
|
+
} = useContext(CopilotContext);
|
|
17
|
+
const systemMessage = useMemo(() => {
|
|
18
|
+
const systemMessageMaker = makeSystemMessage || defaultSystemMessage;
|
|
19
|
+
const contextString = getContextString();
|
|
20
|
+
return {
|
|
21
|
+
id: "system",
|
|
22
|
+
content: systemMessageMaker(contextString),
|
|
23
|
+
role: "system"
|
|
24
|
+
};
|
|
25
|
+
}, [getContextString, makeSystemMessage]);
|
|
26
|
+
const initialMessagesWithContext = [systemMessage].concat(
|
|
27
|
+
options.initialMessages || []
|
|
28
|
+
);
|
|
29
|
+
const functionDescriptions = useMemo(() => {
|
|
30
|
+
return getChatCompletionFunctionDescriptions();
|
|
31
|
+
}, [getChatCompletionFunctionDescriptions]);
|
|
32
|
+
const { messages, append, reload, stop, isLoading, input, setInput } = useChat({
|
|
33
|
+
id: options.id,
|
|
34
|
+
initialMessages: initialMessagesWithContext,
|
|
35
|
+
experimental_onFunctionCall: getFunctionCallHandler(),
|
|
36
|
+
body: {
|
|
37
|
+
id: options.id,
|
|
38
|
+
previewToken,
|
|
39
|
+
copilotkit_manually_passed_function_descriptions: functionDescriptions
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
const visibleMessages = messages.filter(
|
|
43
|
+
(message) => message.role === "user" || message.role === "assistant"
|
|
44
|
+
);
|
|
45
|
+
return {
|
|
46
|
+
visibleMessages,
|
|
47
|
+
append,
|
|
48
|
+
reload,
|
|
49
|
+
stop,
|
|
50
|
+
isLoading,
|
|
51
|
+
input,
|
|
52
|
+
setInput
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
var previewToken = "TODO123";
|
|
56
|
+
function defaultSystemMessage(contextString) {
|
|
57
|
+
return `
|
|
58
|
+
Please act as an efficient, competent, conscientious, and industrious professional assistant.
|
|
59
|
+
|
|
60
|
+
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.
|
|
61
|
+
Always be polite and respectful, and prefer brevity over verbosity.
|
|
62
|
+
|
|
63
|
+
The user has provided you with the following context:
|
|
64
|
+
\`\`\`
|
|
65
|
+
${contextString}
|
|
66
|
+
\`\`\`
|
|
67
|
+
|
|
68
|
+
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.
|
|
69
|
+
|
|
70
|
+
Please assist them as best you can.
|
|
71
|
+
|
|
72
|
+
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.
|
|
73
|
+
|
|
74
|
+
If you would like to call a function, call it without saying anything else.
|
|
75
|
+
`;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export { defaultSystemMessage, useCopilotChat };
|
|
79
|
+
//# sourceMappingURL=out.js.map
|
|
80
|
+
//# sourceMappingURL=chunk-GJUAS6I7.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/hooks/use-copilot-chat.ts"],"names":[],"mappings":";;;;;;;;AAAA,SAAS,SAAS,kBAAkB;AAKpC,SAAS,eAAe;AAuBjB,SAAS,eAAe,IAGiB;AAHjB,eAC7B;AAAA;AAAA,EA7BF,IA4B+B,IAE1B,oBAF0B,IAE1B;AAAA,IADH;AAAA;AAGA,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI,WAAW,cAAc;AAE7B,QAAM,gBAAyB,QAAQ,MAAM;AAC3C,UAAM,qBAAqB,qBAAqB;AAChD,UAAM,gBAAgB,iBAAiB;AAEvC,WAAO;AAAA,MACL,IAAI;AAAA,MACJ,SAAS,mBAAmB,aAAa;AAAA,MACzC,MAAM;AAAA,IACR;AAAA,EACF,GAAG,CAAC,kBAAkB,iBAAiB,CAAC;AAExC,QAAM,6BAA6B,CAAC,aAAa,EAAE;AAAA,IACjD,QAAQ,mBAAmB,CAAC;AAAA,EAC9B;AAEA,QAAM,uBAAuB,QAAQ,MAAM;AACzC,WAAO,sCAAsC;AAAA,EAC/C,GAAG,CAAC,qCAAqC,CAAC;AAE1C,QAAM,EAAE,UAAU,QAAQ,QAAQ,MAAM,WAAW,OAAO,SAAS,IACjE,QAAQ;AAAA,IACN,IAAI,QAAQ;AAAA,IACZ,iBAAiB;AAAA,IACjB,6BAA6B,uBAAuB;AAAA,IACpD,MAAM;AAAA,MACJ,IAAI,QAAQ;AAAA,MACZ;AAAA,MACA,kDAAkD;AAAA,IACpD;AAAA,EACF,CAAC;AAEH,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;AAEA,IAAM,eAAe;AAEd,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 {\n CopilotContext,\n CopilotContextParams,\n} from \"../context/copilot-context\";\nimport { useChat } from \"ai/react\";\nimport { ChatRequestOptions, CreateMessage, Message } from \"ai\";\nimport { UseChatOptions } from \"ai\";\n\nexport interface UseCopilotChatOptions extends UseChatOptions {\n makeSystemMessage?: (contextString: string) => string;\n}\n\nexport interface UseCopilotChatReturn {\n visibleMessages: Message[];\n append: (\n message: Message | CreateMessage,\n chatRequestOptions?: ChatRequestOptions\n ) => Promise<string | null | undefined>;\n reload: (\n chatRequestOptions?: ChatRequestOptions\n ) => Promise<string | null | undefined>;\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 } = useContext(CopilotContext);\n\n const systemMessage: Message = useMemo(() => {\n const systemMessageMaker = makeSystemMessage || defaultSystemMessage;\n const contextString = getContextString();\n\n return {\n id: \"system\",\n content: systemMessageMaker(contextString),\n role: \"system\",\n };\n }, [getContextString, makeSystemMessage]);\n\n const initialMessagesWithContext = [systemMessage].concat(\n options.initialMessages || []\n );\n\n const functionDescriptions = useMemo(() => {\n return getChatCompletionFunctionDescriptions();\n }, [getChatCompletionFunctionDescriptions]);\n\n const { messages, append, reload, stop, isLoading, input, setInput } =\n useChat({\n id: options.id,\n initialMessages: initialMessagesWithContext,\n experimental_onFunctionCall: getFunctionCallHandler(),\n body: {\n id: options.id,\n previewToken,\n copilotkit_manually_passed_function_descriptions: functionDescriptions,\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\nconst previewToken = \"TODO123\";\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"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
var __objRest = (source, exclude) => {
|
|
21
|
+
var target = {};
|
|
22
|
+
for (var prop in source)
|
|
23
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
24
|
+
target[prop] = source[prop];
|
|
25
|
+
if (source != null && __getOwnPropSymbols)
|
|
26
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
27
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
28
|
+
target[prop] = source[prop];
|
|
29
|
+
}
|
|
30
|
+
return target;
|
|
31
|
+
};
|
|
32
|
+
var __async = (__this, __arguments, generator) => {
|
|
33
|
+
return new Promise((resolve, reject) => {
|
|
34
|
+
var fulfilled = (value) => {
|
|
35
|
+
try {
|
|
36
|
+
step(generator.next(value));
|
|
37
|
+
} catch (e) {
|
|
38
|
+
reject(e);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
var rejected = (value) => {
|
|
42
|
+
try {
|
|
43
|
+
step(generator.throw(value));
|
|
44
|
+
} catch (e) {
|
|
45
|
+
reject(e);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
49
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export { __async, __objRest, __spreadProps, __spreadValues };
|
|
54
|
+
//# sourceMappingURL=out.js.map
|
|
55
|
+
//# sourceMappingURL=chunk-MRXNTQOX.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { CopilotContext } from './chunk-UABEP4UT.mjs';
|
|
2
|
+
import { useRef, useContext, useMemo, useEffect } from 'react';
|
|
3
|
+
import { nanoid } from 'nanoid';
|
|
4
|
+
|
|
5
|
+
function useMakeCopilotActionable(annotatedFunction, dependencies) {
|
|
6
|
+
const idRef = useRef(nanoid());
|
|
7
|
+
const { setEntryPoint, removeEntryPoint } = useContext(CopilotContext);
|
|
8
|
+
const memoizedAnnotatedFunction = useMemo(
|
|
9
|
+
() => ({
|
|
10
|
+
name: annotatedFunction.name,
|
|
11
|
+
description: annotatedFunction.description,
|
|
12
|
+
argumentAnnotations: annotatedFunction.argumentAnnotations,
|
|
13
|
+
implementation: annotatedFunction.implementation
|
|
14
|
+
}),
|
|
15
|
+
dependencies
|
|
16
|
+
);
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
setEntryPoint(
|
|
19
|
+
idRef.current,
|
|
20
|
+
memoizedAnnotatedFunction
|
|
21
|
+
);
|
|
22
|
+
return () => {
|
|
23
|
+
removeEntryPoint(idRef.current);
|
|
24
|
+
};
|
|
25
|
+
}, [memoizedAnnotatedFunction, setEntryPoint, removeEntryPoint]);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export { useMakeCopilotActionable };
|
|
29
|
+
//# sourceMappingURL=out.js.map
|
|
30
|
+
//# sourceMappingURL=chunk-OMI7JPW5.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/hooks/use-make-copilot-actionable.ts"],"names":[],"mappings":";;;;;AAEA,SAAS,QAAQ,YAAY,WAAW,eAAe;AAGvD,SAAS,cAAc;AALvB;AAOO,SAAS,yBACd,mBACA,cACA;AACA,QAAM,QAAQ,OAAO,OAAO,CAAC;AAC7B,QAAM,EAAE,eAAe,iBAAiB,IAAI,WAAW,cAAc;AAErE,QAAM,4BAA4D;AAAA,IAChE,OAAO;AAAA,MACL,MAAM,kBAAkB;AAAA,MACxB,aAAa,kBAAkB;AAAA,MAC/B,qBAAqB,kBAAkB;AAAA,MACvC,gBAAgB,kBAAkB;AAAA,IACpC;AAAA,IACA;AAAA,EACF;AAEA,YAAU,MAAM;AACd;AAAA,MACE,MAAM;AAAA,MACN;AAAA,IACF;AAEA,WAAO,MAAM;AACX,uBAAiB,MAAM,OAAO;AAAA,IAChC;AAAA,EACF,GAAG,CAAC,2BAA2B,eAAe,gBAAgB,CAAC;AACjE","sourcesContent":["\"use client\";\n\nimport { useRef, useContext, useEffect, useMemo } from \"react\";\nimport { CopilotContext } from \"../context/copilot-context\";\nimport { AnnotatedFunction } from \"../types/annotated-function\";\nimport { nanoid } from \"nanoid\";\n\nexport function useMakeCopilotActionable<ActionInput extends any[]>(\n annotatedFunction: AnnotatedFunction<ActionInput>,\n dependencies: any[]\n) {\n const idRef = useRef(nanoid()); // generate a unique id\n const { setEntryPoint, removeEntryPoint } = useContext(CopilotContext);\n\n const memoizedAnnotatedFunction: AnnotatedFunction<ActionInput> = useMemo(\n () => ({\n name: annotatedFunction.name,\n description: annotatedFunction.description,\n argumentAnnotations: annotatedFunction.argumentAnnotations,\n implementation: annotatedFunction.implementation,\n }),\n dependencies\n );\n\n useEffect(() => {\n setEntryPoint(\n idRef.current,\n memoizedAnnotatedFunction as AnnotatedFunction<any[]>\n );\n\n return () => {\n removeEntryPoint(idRef.current);\n };\n }, [memoizedAnnotatedFunction, setEntryPoint, removeEntryPoint]);\n}\n"]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { __async } from './chunk-MRXNTQOX.mjs';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
|
|
4
|
+
var emptyCopilotContext = {
|
|
5
|
+
entryPoints: {},
|
|
6
|
+
getChatCompletionFunctionDescriptions: () => [],
|
|
7
|
+
getFunctionCallHandler: () => () => __async(void 0, null, function* () {
|
|
8
|
+
}),
|
|
9
|
+
setEntryPoint: () => {
|
|
10
|
+
},
|
|
11
|
+
removeEntryPoint: () => {
|
|
12
|
+
},
|
|
13
|
+
getContextString: () => "",
|
|
14
|
+
addContext: () => "",
|
|
15
|
+
removeContext: () => {
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
var CopilotContext = React.createContext(emptyCopilotContext);
|
|
19
|
+
|
|
20
|
+
export { CopilotContext };
|
|
21
|
+
//# sourceMappingURL=out.js.map
|
|
22
|
+
//# sourceMappingURL=chunk-UABEP4UT.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/context/copilot-context.tsx"],"names":[],"mappings":";;;;;AAEA,OAAO,WAAW;AAFlB;AAoBA,IAAM,sBAA4C;AAAA,EAChD,aAAa,CAAC;AAAA,EACd,uCAAuC,MAAM,CAAC;AAAA,EAC9C,wBAAwB,MAAM,MAAY;AAAA,EAAC;AAAA,EAC3C,eAAe,MAAM;AAAA,EAAC;AAAA,EACtB,kBAAkB,MAAM;AAAA,EAAC;AAAA,EACzB,kBAAkB,MAAM;AAAA,EACxB,YAAY,MAAM;AAAA,EAClB,eAAe,MAAM;AAAA,EAAC;AACxB;AAEO,IAAM,iBACX,MAAM,cAAoC,mBAAmB","sourcesContent":["\"use client\";\n\nimport React from \"react\";\nimport { AnnotatedFunction } from \"../types/annotated-function\";\nimport { TreeNodeId } from \"../hooks/use-tree\";\nimport { ChatCompletionFunctions } from \"openai-edge/types/api\";\nimport { FunctionCallHandler } from \"ai\";\n\nexport interface CopilotContextParams {\n entryPoints: Record<string, AnnotatedFunction<any[]>>;\n getChatCompletionFunctionDescriptions: () => ChatCompletionFunctions[];\n getFunctionCallHandler: () => FunctionCallHandler;\n setEntryPoint: (id: string, entryPoint: AnnotatedFunction<any[]>) => void;\n removeEntryPoint: (id: string) => void;\n\n getContextString: () => string;\n addContext: (context: string, parentId?: string) => TreeNodeId;\n removeContext: (id: TreeNodeId) => void;\n}\n\nconst emptyCopilotContext: CopilotContextParams = {\n entryPoints: {},\n getChatCompletionFunctionDescriptions: () => [],\n getFunctionCallHandler: () => async () => {},\n setEntryPoint: () => {},\n removeEntryPoint: () => {},\n getContextString: () => \"\",\n addContext: () => \"\",\n removeContext: () => {},\n};\n\nexport const CopilotContext =\n React.createContext<CopilotContextParams>(emptyCopilotContext);\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { __spreadProps, __spreadValues } from './chunk-MRXNTQOX.mjs';
|
|
2
|
+
import { nanoid } from 'nanoid';
|
|
3
|
+
import { useReducer, useCallback } from 'react';
|
|
4
|
+
|
|
5
|
+
var removeNode = (nodes, id) => {
|
|
6
|
+
return nodes.reduce((result, node) => {
|
|
7
|
+
if (node.id !== id) {
|
|
8
|
+
const newNode = __spreadProps(__spreadValues({}, node), { children: removeNode(node.children, id) });
|
|
9
|
+
result.push(newNode);
|
|
10
|
+
}
|
|
11
|
+
return result;
|
|
12
|
+
}, []);
|
|
13
|
+
};
|
|
14
|
+
var addNode = (nodes, newNode, parentId) => {
|
|
15
|
+
if (!parentId) {
|
|
16
|
+
return [...nodes, newNode];
|
|
17
|
+
}
|
|
18
|
+
return nodes.map((node) => {
|
|
19
|
+
if (node.id === parentId) {
|
|
20
|
+
return __spreadProps(__spreadValues({}, node), { children: [...node.children, newNode] });
|
|
21
|
+
} else if (node.children.length) {
|
|
22
|
+
return __spreadProps(__spreadValues({}, node), { children: addNode(node.children, newNode, parentId) });
|
|
23
|
+
}
|
|
24
|
+
return node;
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
var treeIndentationRepresentation = (index, indentLevel) => {
|
|
28
|
+
if (indentLevel === 0) {
|
|
29
|
+
return (index + 1).toString();
|
|
30
|
+
} else if (indentLevel === 1) {
|
|
31
|
+
return String.fromCharCode(65 + index);
|
|
32
|
+
} else if (indentLevel === 2) {
|
|
33
|
+
return String.fromCharCode(97 + index);
|
|
34
|
+
} else {
|
|
35
|
+
throw new Error("Indentation level not supported");
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var printNode = (node, prefix = "", indentLevel = 0) => {
|
|
39
|
+
const indent = " ".repeat(3).repeat(indentLevel);
|
|
40
|
+
const prefixPlusIndentLength = prefix.length + indent.length;
|
|
41
|
+
const subsequentLinesPrefix = " ".repeat(prefixPlusIndentLength);
|
|
42
|
+
const valueLines = node.value.split("\n");
|
|
43
|
+
const outputFirstLine = `${indent}${prefix}${valueLines[0]}`;
|
|
44
|
+
const outputSubsequentLines = valueLines.slice(1).map((line) => `${subsequentLinesPrefix}${line}`).join("\n");
|
|
45
|
+
let output = `${outputFirstLine}
|
|
46
|
+
`;
|
|
47
|
+
if (outputSubsequentLines) {
|
|
48
|
+
output += `${outputSubsequentLines}
|
|
49
|
+
`;
|
|
50
|
+
}
|
|
51
|
+
node.children.forEach(
|
|
52
|
+
(child, index) => output += printNode(
|
|
53
|
+
child,
|
|
54
|
+
`${prefix}${treeIndentationRepresentation(index, indentLevel + 1)}. `,
|
|
55
|
+
indentLevel + 1
|
|
56
|
+
)
|
|
57
|
+
);
|
|
58
|
+
return output;
|
|
59
|
+
};
|
|
60
|
+
function treeReducer(state, action) {
|
|
61
|
+
switch (action.type) {
|
|
62
|
+
case "ADD_NODE": {
|
|
63
|
+
const { value, parentId, id: newNodeId } = action;
|
|
64
|
+
const newNode = {
|
|
65
|
+
id: newNodeId,
|
|
66
|
+
value,
|
|
67
|
+
children: []
|
|
68
|
+
};
|
|
69
|
+
try {
|
|
70
|
+
return addNode(state, newNode, parentId);
|
|
71
|
+
} catch (error) {
|
|
72
|
+
console.error(`Error while adding node with id ${newNodeId}: ${error}`);
|
|
73
|
+
return state;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
case "REMOVE_NODE":
|
|
77
|
+
return removeNode(state, action.id);
|
|
78
|
+
default:
|
|
79
|
+
return state;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
var useTree = () => {
|
|
83
|
+
const [tree, dispatch] = useReducer(treeReducer, []);
|
|
84
|
+
const addElement = useCallback(
|
|
85
|
+
(value, parentId) => {
|
|
86
|
+
const newNodeId = nanoid();
|
|
87
|
+
dispatch({ type: "ADD_NODE", value, parentId, id: newNodeId });
|
|
88
|
+
return newNodeId;
|
|
89
|
+
},
|
|
90
|
+
[]
|
|
91
|
+
);
|
|
92
|
+
const removeElement = useCallback((id) => {
|
|
93
|
+
dispatch({ type: "REMOVE_NODE", id });
|
|
94
|
+
}, []);
|
|
95
|
+
const printTree = () => {
|
|
96
|
+
let output = "";
|
|
97
|
+
tree.forEach(
|
|
98
|
+
(node, index) => output += printNode(
|
|
99
|
+
node,
|
|
100
|
+
`${treeIndentationRepresentation(index, 0)}. `
|
|
101
|
+
)
|
|
102
|
+
);
|
|
103
|
+
return output;
|
|
104
|
+
};
|
|
105
|
+
return { tree, addElement, printTree, removeElement };
|
|
106
|
+
};
|
|
107
|
+
var use_tree_default = useTree;
|
|
108
|
+
|
|
109
|
+
export { use_tree_default };
|
|
110
|
+
//# sourceMappingURL=out.js.map
|
|
111
|
+
//# sourceMappingURL=chunk-YVXQVXMS.mjs.map
|