@copilotkit/react-core 0.20.0-demofixes.2 → 0.20.0-tools.1
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 +143 -147
- package/CHANGELOG.md +3 -14
- package/dist/{chunk-KZNQLITJ.mjs → chunk-AVLJ3AWG.mjs} +2 -2
- package/dist/{chunk-ABXVFQLN.mjs → chunk-NW27C3BV.mjs} +39 -7
- package/dist/chunk-NW27C3BV.mjs.map +1 -0
- package/dist/components/copilot-provider/copilotkit.mjs +8 -439
- package/dist/components/copilot-provider/copilotkit.mjs.map +1 -1
- package/dist/components/copilot-provider/index.mjs +9 -439
- package/dist/components/copilot-provider/index.mjs.map +1 -1
- package/dist/components/copilot-provider/standard-copilot-api-config.mjs +4 -9
- package/dist/components/copilot-provider/standard-copilot-api-config.mjs.map +1 -1
- package/dist/components/index.mjs +10 -439
- package/dist/components/index.mjs.map +1 -1
- package/dist/context/copilot-context.mjs +5 -63
- package/dist/context/copilot-context.mjs.map +1 -1
- package/dist/context/index.mjs +6 -63
- package/dist/context/index.mjs.map +1 -1
- package/dist/hooks/index.js +39 -7
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +21 -392
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/hooks/use-chat.js +38 -6
- package/dist/hooks/use-chat.js.map +1 -1
- package/dist/hooks/use-chat.mjs +4 -204
- package/dist/hooks/use-chat.mjs.map +1 -1
- package/dist/hooks/use-copilot-chat.js +39 -7
- package/dist/hooks/use-copilot-chat.js.map +1 -1
- package/dist/hooks/use-copilot-chat.mjs +13 -340
- package/dist/hooks/use-copilot-chat.mjs.map +1 -1
- package/dist/hooks/use-flat-category-store.mjs +4 -65
- package/dist/hooks/use-flat-category-store.mjs.map +1 -1
- package/dist/hooks/use-make-copilot-actionable.mjs +5 -85
- package/dist/hooks/use-make-copilot-actionable.mjs.map +1 -1
- package/dist/hooks/use-make-copilot-document-readable.mjs +5 -77
- package/dist/hooks/use-make-copilot-document-readable.mjs.map +1 -1
- package/dist/hooks/use-make-copilot-readable.mjs +5 -77
- package/dist/hooks/use-make-copilot-readable.mjs.map +1 -1
- package/dist/hooks/use-tree.mjs +4 -150
- package/dist/hooks/use-tree.mjs.map +1 -1
- package/dist/index.js +40 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +46 -979
- package/dist/index.mjs.map +1 -1
- package/dist/lib/copilot-task.mjs +11 -183
- package/dist/lib/copilot-task.mjs.map +1 -1
- package/dist/lib/index.mjs +12 -183
- package/dist/lib/index.mjs.map +1 -1
- package/dist/openai-assistants/hooks/index.mjs +14 -228
- package/dist/openai-assistants/hooks/index.mjs.map +1 -1
- package/dist/openai-assistants/hooks/use-assistants.mjs +7 -45
- package/dist/openai-assistants/hooks/use-assistants.mjs.map +1 -1
- package/dist/openai-assistants/hooks/use-copilot-chat-v2.mjs +14 -228
- package/dist/openai-assistants/hooks/use-copilot-chat-v2.mjs.map +1 -1
- package/dist/openai-assistants/index.mjs +17 -228
- package/dist/openai-assistants/index.mjs.map +1 -1
- package/dist/openai-assistants/utils/index.mjs +5 -43
- package/dist/openai-assistants/utils/index.mjs.map +1 -1
- package/dist/openai-assistants/utils/process-message-stream.mjs +4 -43
- package/dist/openai-assistants/utils/process-message-stream.mjs.map +1 -1
- package/dist/types/index.mjs +1 -0
- package/dist/utils/fetch-chat-completion.mjs +5 -99
- package/dist/utils/fetch-chat-completion.mjs.map +1 -1
- package/package.json +4 -4
- package/src/hooks/use-chat.ts +57 -6
- package/dist/chunk-ABXVFQLN.mjs.map +0 -1
- /package/dist/{chunk-KZNQLITJ.mjs.map → chunk-AVLJ3AWG.mjs.map} +0 -0
|
@@ -1,81 +1,9 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
} catch (e) {
|
|
8
|
-
reject(e);
|
|
9
|
-
}
|
|
10
|
-
};
|
|
11
|
-
var rejected = (value) => {
|
|
12
|
-
try {
|
|
13
|
-
step(generator.throw(value));
|
|
14
|
-
} catch (e) {
|
|
15
|
-
reject(e);
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
19
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
// src/hooks/use-make-copilot-document-readable.ts
|
|
24
|
-
import { useContext, useEffect, useRef } from "react";
|
|
25
|
-
|
|
26
|
-
// src/context/copilot-context.tsx
|
|
27
|
-
import React from "react";
|
|
28
|
-
var emptyCopilotContext = {
|
|
29
|
-
entryPoints: {},
|
|
30
|
-
setEntryPoint: () => {
|
|
31
|
-
},
|
|
32
|
-
removeEntryPoint: () => {
|
|
33
|
-
},
|
|
34
|
-
getChatCompletionFunctionDescriptions: () => returnAndThrowInDebug([]),
|
|
35
|
-
getFunctionCallHandler: () => returnAndThrowInDebug(() => __async(void 0, null, function* () {
|
|
36
|
-
})),
|
|
37
|
-
getContextString: (documents, categories) => returnAndThrowInDebug(""),
|
|
38
|
-
addContext: () => "",
|
|
39
|
-
removeContext: () => {
|
|
40
|
-
},
|
|
41
|
-
getDocumentsContext: (categories) => returnAndThrowInDebug([]),
|
|
42
|
-
addDocumentContext: () => returnAndThrowInDebug(""),
|
|
43
|
-
removeDocumentContext: () => {
|
|
44
|
-
},
|
|
45
|
-
copilotApiConfig: new class {
|
|
46
|
-
get chatApiEndpoint() {
|
|
47
|
-
throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
|
|
48
|
-
}
|
|
49
|
-
get chatApiEndpointV2() {
|
|
50
|
-
throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
|
|
51
|
-
}
|
|
52
|
-
get headers() {
|
|
53
|
-
return {};
|
|
54
|
-
}
|
|
55
|
-
get body() {
|
|
56
|
-
return {};
|
|
57
|
-
}
|
|
58
|
-
}()
|
|
59
|
-
};
|
|
60
|
-
var CopilotContext = React.createContext(emptyCopilotContext);
|
|
61
|
-
function returnAndThrowInDebug(value) {
|
|
62
|
-
throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
|
|
63
|
-
return value;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// src/hooks/use-make-copilot-document-readable.ts
|
|
67
|
-
function useMakeCopilotDocumentReadable(document, categories, dependencies = []) {
|
|
68
|
-
const { addDocumentContext, removeDocumentContext } = useContext(CopilotContext);
|
|
69
|
-
const idRef = useRef();
|
|
70
|
-
useEffect(() => {
|
|
71
|
-
const id = addDocumentContext(document, categories);
|
|
72
|
-
idRef.current = id;
|
|
73
|
-
return () => {
|
|
74
|
-
removeDocumentContext(id);
|
|
75
|
-
};
|
|
76
|
-
}, [addDocumentContext, removeDocumentContext, ...dependencies]);
|
|
77
|
-
return idRef.current;
|
|
78
|
-
}
|
|
2
|
+
import {
|
|
3
|
+
useMakeCopilotDocumentReadable
|
|
4
|
+
} from "../chunk-XBLCD24W.mjs";
|
|
5
|
+
import "../chunk-4OWTRVNI.mjs";
|
|
6
|
+
import "../chunk-MRXNTQOX.mjs";
|
|
79
7
|
export {
|
|
80
8
|
useMakeCopilotDocumentReadable
|
|
81
9
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1,81 +1,9 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
} catch (e) {
|
|
8
|
-
reject(e);
|
|
9
|
-
}
|
|
10
|
-
};
|
|
11
|
-
var rejected = (value) => {
|
|
12
|
-
try {
|
|
13
|
-
step(generator.throw(value));
|
|
14
|
-
} catch (e) {
|
|
15
|
-
reject(e);
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
19
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
// src/hooks/use-make-copilot-readable.ts
|
|
24
|
-
import { useContext, useEffect, useRef } from "react";
|
|
25
|
-
|
|
26
|
-
// src/context/copilot-context.tsx
|
|
27
|
-
import React from "react";
|
|
28
|
-
var emptyCopilotContext = {
|
|
29
|
-
entryPoints: {},
|
|
30
|
-
setEntryPoint: () => {
|
|
31
|
-
},
|
|
32
|
-
removeEntryPoint: () => {
|
|
33
|
-
},
|
|
34
|
-
getChatCompletionFunctionDescriptions: () => returnAndThrowInDebug([]),
|
|
35
|
-
getFunctionCallHandler: () => returnAndThrowInDebug(() => __async(void 0, null, function* () {
|
|
36
|
-
})),
|
|
37
|
-
getContextString: (documents, categories) => returnAndThrowInDebug(""),
|
|
38
|
-
addContext: () => "",
|
|
39
|
-
removeContext: () => {
|
|
40
|
-
},
|
|
41
|
-
getDocumentsContext: (categories) => returnAndThrowInDebug([]),
|
|
42
|
-
addDocumentContext: () => returnAndThrowInDebug(""),
|
|
43
|
-
removeDocumentContext: () => {
|
|
44
|
-
},
|
|
45
|
-
copilotApiConfig: new class {
|
|
46
|
-
get chatApiEndpoint() {
|
|
47
|
-
throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
|
|
48
|
-
}
|
|
49
|
-
get chatApiEndpointV2() {
|
|
50
|
-
throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
|
|
51
|
-
}
|
|
52
|
-
get headers() {
|
|
53
|
-
return {};
|
|
54
|
-
}
|
|
55
|
-
get body() {
|
|
56
|
-
return {};
|
|
57
|
-
}
|
|
58
|
-
}()
|
|
59
|
-
};
|
|
60
|
-
var CopilotContext = React.createContext(emptyCopilotContext);
|
|
61
|
-
function returnAndThrowInDebug(value) {
|
|
62
|
-
throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
|
|
63
|
-
return value;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// src/hooks/use-make-copilot-readable.ts
|
|
67
|
-
function useMakeCopilotReadable(information, parentId, categories) {
|
|
68
|
-
const { addContext, removeContext } = useContext(CopilotContext);
|
|
69
|
-
const idRef = useRef();
|
|
70
|
-
useEffect(() => {
|
|
71
|
-
const id = addContext(information, parentId, categories);
|
|
72
|
-
idRef.current = id;
|
|
73
|
-
return () => {
|
|
74
|
-
removeContext(id);
|
|
75
|
-
};
|
|
76
|
-
}, [information, parentId, addContext, removeContext]);
|
|
77
|
-
return idRef.current;
|
|
78
|
-
}
|
|
2
|
+
import {
|
|
3
|
+
useMakeCopilotReadable
|
|
4
|
+
} from "../chunk-CPEUPJQJ.mjs";
|
|
5
|
+
import "../chunk-4OWTRVNI.mjs";
|
|
6
|
+
import "../chunk-MRXNTQOX.mjs";
|
|
79
7
|
export {
|
|
80
8
|
useMakeCopilotReadable
|
|
81
9
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/hooks/use-tree.mjs
CHANGED
|
@@ -1,153 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
|
|
21
|
-
// src/hooks/use-tree.ts
|
|
22
|
-
import { nanoid } from "nanoid";
|
|
23
|
-
import { useCallback, useReducer } from "react";
|
|
24
|
-
var removeNode = (nodes, id) => {
|
|
25
|
-
return nodes.reduce((result, node) => {
|
|
26
|
-
if (node.id !== id) {
|
|
27
|
-
const newNode = __spreadProps(__spreadValues({}, node), { children: removeNode(node.children, id) });
|
|
28
|
-
result.push(newNode);
|
|
29
|
-
}
|
|
30
|
-
return result;
|
|
31
|
-
}, []);
|
|
32
|
-
};
|
|
33
|
-
var addNode = (nodes, newNode, parentId) => {
|
|
34
|
-
if (!parentId) {
|
|
35
|
-
return [...nodes, newNode];
|
|
36
|
-
}
|
|
37
|
-
return nodes.map((node) => {
|
|
38
|
-
if (node.id === parentId) {
|
|
39
|
-
return __spreadProps(__spreadValues({}, node), { children: [...node.children, newNode] });
|
|
40
|
-
} else if (node.children.length) {
|
|
41
|
-
return __spreadProps(__spreadValues({}, node), { children: addNode(node.children, newNode, parentId) });
|
|
42
|
-
}
|
|
43
|
-
return node;
|
|
44
|
-
});
|
|
45
|
-
};
|
|
46
|
-
var treeIndentationRepresentation = (index, indentLevel) => {
|
|
47
|
-
if (indentLevel === 0) {
|
|
48
|
-
return (index + 1).toString();
|
|
49
|
-
} else if (indentLevel === 1) {
|
|
50
|
-
return String.fromCharCode(65 + index);
|
|
51
|
-
} else if (indentLevel === 2) {
|
|
52
|
-
return String.fromCharCode(97 + index);
|
|
53
|
-
} else {
|
|
54
|
-
return "-";
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
var printNode = (node, prefix = "", indentLevel = 0) => {
|
|
58
|
-
const indent = " ".repeat(3).repeat(indentLevel);
|
|
59
|
-
const prefixPlusIndentLength = prefix.length + indent.length;
|
|
60
|
-
const subsequentLinesPrefix = " ".repeat(prefixPlusIndentLength);
|
|
61
|
-
const valueLines = node.value.split("\n");
|
|
62
|
-
const outputFirstLine = `${indent}${prefix}${valueLines[0]}`;
|
|
63
|
-
const outputSubsequentLines = valueLines.slice(1).map((line) => `${subsequentLinesPrefix}${line}`).join("\n");
|
|
64
|
-
let output = `${outputFirstLine}
|
|
65
|
-
`;
|
|
66
|
-
if (outputSubsequentLines) {
|
|
67
|
-
output += `${outputSubsequentLines}
|
|
68
|
-
`;
|
|
69
|
-
}
|
|
70
|
-
const childPrePrefix = " ".repeat(prefix.length);
|
|
71
|
-
node.children.forEach(
|
|
72
|
-
(child, index) => output += printNode(
|
|
73
|
-
child,
|
|
74
|
-
`${childPrePrefix}${treeIndentationRepresentation(index, indentLevel + 1)}. `,
|
|
75
|
-
indentLevel + 1
|
|
76
|
-
)
|
|
77
|
-
);
|
|
78
|
-
return output;
|
|
79
|
-
};
|
|
80
|
-
function treeReducer(state, action) {
|
|
81
|
-
switch (action.type) {
|
|
82
|
-
case "ADD_NODE": {
|
|
83
|
-
const { value, parentId, id: newNodeId } = action;
|
|
84
|
-
const newNode = {
|
|
85
|
-
id: newNodeId,
|
|
86
|
-
value,
|
|
87
|
-
children: [],
|
|
88
|
-
categories: new Set(action.categories)
|
|
89
|
-
};
|
|
90
|
-
try {
|
|
91
|
-
return addNode(state, newNode, parentId);
|
|
92
|
-
} catch (error) {
|
|
93
|
-
console.error(`Error while adding node with id ${newNodeId}: ${error}`);
|
|
94
|
-
return state;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
case "REMOVE_NODE":
|
|
98
|
-
return removeNode(state, action.id);
|
|
99
|
-
default:
|
|
100
|
-
return state;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
var useTree = () => {
|
|
104
|
-
const [tree, dispatch] = useReducer(treeReducer, []);
|
|
105
|
-
const addElement = useCallback(
|
|
106
|
-
(value, categories, parentId) => {
|
|
107
|
-
const newNodeId = nanoid();
|
|
108
|
-
dispatch({
|
|
109
|
-
type: "ADD_NODE",
|
|
110
|
-
value,
|
|
111
|
-
parentId,
|
|
112
|
-
id: newNodeId,
|
|
113
|
-
categories
|
|
114
|
-
});
|
|
115
|
-
return newNodeId;
|
|
116
|
-
},
|
|
117
|
-
[]
|
|
118
|
-
);
|
|
119
|
-
const removeElement = useCallback((id) => {
|
|
120
|
-
dispatch({ type: "REMOVE_NODE", id });
|
|
121
|
-
}, []);
|
|
122
|
-
const printTree = useCallback(
|
|
123
|
-
(categories) => {
|
|
124
|
-
const categoriesSet = new Set(categories);
|
|
125
|
-
let output = "";
|
|
126
|
-
tree.forEach((node, index) => {
|
|
127
|
-
if (!setsHaveIntersection(categoriesSet, node.categories)) {
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
if (index !== 0) {
|
|
131
|
-
output += "\n";
|
|
132
|
-
}
|
|
133
|
-
output += printNode(node, `${treeIndentationRepresentation(index, 0)}. `);
|
|
134
|
-
});
|
|
135
|
-
return output;
|
|
136
|
-
},
|
|
137
|
-
[tree]
|
|
138
|
-
);
|
|
139
|
-
return { tree, addElement, printTree, removeElement };
|
|
140
|
-
};
|
|
141
|
-
var use_tree_default = useTree;
|
|
142
|
-
function setsHaveIntersection(setA, setB) {
|
|
143
|
-
const [smallerSet, largerSet] = setA.size <= setB.size ? [setA, setB] : [setB, setA];
|
|
144
|
-
for (let item of smallerSet) {
|
|
145
|
-
if (largerSet.has(item)) {
|
|
146
|
-
return true;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
return false;
|
|
150
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
use_tree_default
|
|
3
|
+
} from "../chunk-VUY2K2DI.mjs";
|
|
4
|
+
import "../chunk-MRXNTQOX.mjs";
|
|
151
5
|
export {
|
|
152
6
|
use_tree_default as default
|
|
153
7
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/index.js
CHANGED
|
@@ -491,6 +491,7 @@ var import_react6 = require("react");
|
|
|
491
491
|
|
|
492
492
|
// src/hooks/use-chat.ts
|
|
493
493
|
var import_react5 = require("react");
|
|
494
|
+
var import_shared3 = require("@copilotkit/shared");
|
|
494
495
|
var import_nanoid3 = require("nanoid");
|
|
495
496
|
|
|
496
497
|
// src/utils/fetch-chat-completion.ts
|
|
@@ -557,7 +558,6 @@ function useChat(options) {
|
|
|
557
558
|
const [isLoading, setIsLoading] = (0, import_react5.useState)(false);
|
|
558
559
|
const abortControllerRef = (0, import_react5.useRef)();
|
|
559
560
|
const runChatCompletion = (messages2) => __async(this, null, function* () {
|
|
560
|
-
var _a;
|
|
561
561
|
setIsLoading(true);
|
|
562
562
|
const newMessages = [
|
|
563
563
|
{
|
|
@@ -582,15 +582,16 @@ function useChat(options) {
|
|
|
582
582
|
throw new Error("Failed to fetch chat completion");
|
|
583
583
|
}
|
|
584
584
|
const reader = response.events.getReader();
|
|
585
|
+
let feedback = false;
|
|
585
586
|
try {
|
|
586
587
|
while (true) {
|
|
587
588
|
const { done, value } = yield reader.read();
|
|
588
589
|
if (done) {
|
|
589
|
-
|
|
590
|
+
break;
|
|
590
591
|
}
|
|
591
592
|
let currentMessage = Object.assign({}, newMessages[newMessages.length - 1]);
|
|
592
593
|
if (value.type === "content") {
|
|
593
|
-
if (currentMessage.function_call) {
|
|
594
|
+
if (currentMessage.function_call || currentMessage.role === "function") {
|
|
594
595
|
currentMessage = {
|
|
595
596
|
id: (0, import_nanoid3.nanoid)(),
|
|
596
597
|
createdAt: /* @__PURE__ */ new Date(),
|
|
@@ -602,8 +603,18 @@ function useChat(options) {
|
|
|
602
603
|
currentMessage.content += value.content;
|
|
603
604
|
newMessages[newMessages.length - 1] = currentMessage;
|
|
604
605
|
setMessages([...messages2, ...newMessages]);
|
|
606
|
+
} else if (value.type === "result") {
|
|
607
|
+
currentMessage = {
|
|
608
|
+
id: (0, import_nanoid3.nanoid)(),
|
|
609
|
+
role: "function",
|
|
610
|
+
content: value.content,
|
|
611
|
+
name: value.name
|
|
612
|
+
};
|
|
613
|
+
newMessages.push(currentMessage);
|
|
614
|
+
setMessages([...messages2, ...newMessages]);
|
|
615
|
+
feedback = true;
|
|
605
616
|
} else if (value.type === "function") {
|
|
606
|
-
if (currentMessage.content != "" || currentMessage.function_call) {
|
|
617
|
+
if (currentMessage.content != "" || currentMessage.function_call || currentMessage.role == "function") {
|
|
607
618
|
currentMessage = {
|
|
608
619
|
id: (0, import_nanoid3.nanoid)(),
|
|
609
620
|
createdAt: /* @__PURE__ */ new Date(),
|
|
@@ -614,13 +625,34 @@ function useChat(options) {
|
|
|
614
625
|
}
|
|
615
626
|
currentMessage.function_call = {
|
|
616
627
|
name: value.name,
|
|
617
|
-
arguments: JSON.stringify(value.arguments)
|
|
628
|
+
arguments: JSON.stringify(value.arguments),
|
|
629
|
+
scope: value.scope
|
|
618
630
|
};
|
|
619
631
|
newMessages[newMessages.length - 1] = currentMessage;
|
|
620
632
|
setMessages([...messages2, ...newMessages]);
|
|
621
|
-
|
|
633
|
+
try {
|
|
634
|
+
if (options.onFunctionCall && value.scope === "client") {
|
|
635
|
+
const result = yield options.onFunctionCall(messages2, currentMessage.function_call);
|
|
636
|
+
currentMessage = {
|
|
637
|
+
id: (0, import_nanoid3.nanoid)(),
|
|
638
|
+
role: "function",
|
|
639
|
+
content: (0, import_shared3.encodeResult)(result),
|
|
640
|
+
name: currentMessage.function_call.name
|
|
641
|
+
};
|
|
642
|
+
newMessages.push(currentMessage);
|
|
643
|
+
setMessages([...messages2, ...newMessages]);
|
|
644
|
+
feedback = true;
|
|
645
|
+
}
|
|
646
|
+
} catch (error) {
|
|
647
|
+
console.error("Failed to execute function call", error);
|
|
648
|
+
}
|
|
622
649
|
}
|
|
623
650
|
}
|
|
651
|
+
if (feedback) {
|
|
652
|
+
return yield runChatCompletion([...messages2, ...newMessages]);
|
|
653
|
+
} else {
|
|
654
|
+
return newMessages.slice();
|
|
655
|
+
}
|
|
624
656
|
} finally {
|
|
625
657
|
setIsLoading(false);
|
|
626
658
|
}
|
|
@@ -816,7 +848,7 @@ function processMessageStream(reader, processMessage) {
|
|
|
816
848
|
}
|
|
817
849
|
|
|
818
850
|
// src/openai-assistants/hooks/use-copilot-chat-v2.ts
|
|
819
|
-
var
|
|
851
|
+
var import_shared4 = require("@copilotkit/shared");
|
|
820
852
|
function useCopilotChatV2(options) {
|
|
821
853
|
const {
|
|
822
854
|
getContextString,
|
|
@@ -868,7 +900,7 @@ function useCopilotChatV2(options) {
|
|
|
868
900
|
}
|
|
869
901
|
yield processMessageStream(result.body.getReader(), (message) => {
|
|
870
902
|
try {
|
|
871
|
-
const { type, value } = (0,
|
|
903
|
+
const { type, value } = (0, import_shared4.parseStreamPart)(message);
|
|
872
904
|
switch (type) {
|
|
873
905
|
case "assistant_message": {
|
|
874
906
|
setMessages((messages2) => [
|