@copilotkit/react-core 0.25.0-multi-release-alpha.0 → 0.25.0-multi-feature-usecopilotreadable.4
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 +165 -162
- package/CHANGELOG.md +47 -3
- package/dist/chunk-5L5PJJNT.mjs +28 -0
- package/dist/chunk-5L5PJJNT.mjs.map +1 -0
- package/dist/{chunk-GVLCTSXW.mjs → chunk-BCKOSVRB.mjs} +2 -2
- package/dist/{chunk-KJQZ2VEU.mjs → chunk-EABGYUTZ.mjs} +1 -1
- package/dist/chunk-EABGYUTZ.mjs.map +1 -0
- package/dist/chunk-EYKDJBDE.mjs +1 -0
- package/dist/{chunk-QGRMN7L3.mjs → chunk-L45P674M.mjs} +4 -4
- package/dist/chunk-L45P674M.mjs.map +1 -0
- package/dist/{chunk-AEUR5JBT.mjs → chunk-X3FZ6GTK.mjs} +11 -1
- package/dist/chunk-X3FZ6GTK.mjs.map +1 -0
- package/dist/components/copilot-provider/copilotkit.mjs +9 -435
- package/dist/components/copilot-provider/copilotkit.mjs.map +1 -1
- package/dist/components/copilot-provider/index.mjs +10 -435
- 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 +11 -435
- package/dist/components/index.mjs.map +1 -1
- package/dist/context/copilot-context.mjs +5 -64
- package/dist/context/copilot-context.mjs.map +1 -1
- package/dist/context/index.mjs +6 -64
- package/dist/context/index.mjs.map +1 -1
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/index.js +22 -0
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +29 -528
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/hooks/use-chat.mjs +4 -295
- package/dist/hooks/use-chat.mjs.map +1 -1
- package/dist/hooks/use-copilot-action-implementation.mjs +5 -102
- package/dist/hooks/use-copilot-action-implementation.mjs.map +1 -1
- package/dist/hooks/use-copilot-action.mjs +6 -107
- package/dist/hooks/use-copilot-action.mjs.map +1 -1
- package/dist/hooks/use-copilot-chat.mjs +13 -430
- package/dist/hooks/use-copilot-chat.mjs.map +1 -1
- package/dist/hooks/use-copilot-readable.d.ts +33 -0
- package/dist/hooks/use-copilot-readable.js +121 -0
- package/dist/hooks/use-copilot-readable.js.map +1 -0
- package/dist/hooks/use-copilot-readable.mjs +9 -0
- package/dist/hooks/use-copilot-readable.mjs.map +1 -0
- 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 -88
- package/dist/hooks/use-make-copilot-actionable.mjs.map +1 -1
- package/dist/hooks/use-make-copilot-document-readable.mjs +5 -78
- package/dist/hooks/use-make-copilot-document-readable.mjs.map +1 -1
- package/dist/hooks/use-make-copilot-readable.d.ts +1 -5
- package/dist/hooks/use-make-copilot-readable.js.map +1 -1
- package/dist/hooks/use-make-copilot-readable.mjs +5 -78
- 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.d.ts +1 -0
- package/dist/index.js +33 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +54 -1113
- package/dist/index.mjs.map +1 -1
- package/dist/lib/copilot-task.d.ts +7 -2
- package/dist/lib/copilot-task.js +3 -3
- package/dist/lib/copilot-task.js.map +1 -1
- package/dist/lib/copilot-task.mjs +11 -192
- package/dist/lib/copilot-task.mjs.map +1 -1
- package/dist/lib/index.js +3 -3
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +12 -192
- package/dist/lib/index.mjs.map +1 -1
- package/dist/openai-assistants/hooks/index.mjs +15 -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 +15 -228
- package/dist/openai-assistants/hooks/use-copilot-chat-v2.mjs.map +1 -1
- package/dist/openai-assistants/index.mjs +18 -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 -112
- package/dist/utils/fetch-chat-completion.mjs.map +1 -1
- package/package.json +4 -4
- package/src/hooks/index.ts +1 -0
- package/src/hooks/use-copilot-readable.ts +60 -0
- package/src/hooks/use-make-copilot-readable.ts +1 -5
- package/src/lib/copilot-task.ts +12 -5
- package/dist/chunk-AEUR5JBT.mjs.map +0 -1
- package/dist/chunk-IOP6JX34.mjs +0 -1
- package/dist/chunk-KJQZ2VEU.mjs.map +0 -1
- package/dist/chunk-QGRMN7L3.mjs.map +0 -1
- /package/dist/{chunk-GVLCTSXW.mjs.map → chunk-BCKOSVRB.mjs.map} +0 -0
- /package/dist/{chunk-IOP6JX34.mjs.map → chunk-EYKDJBDE.mjs.map} +0 -0
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.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export { useCopilotAction } from './hooks/use-copilot-action.js';
|
|
|
7
7
|
export { useMakeCopilotReadable } from './hooks/use-make-copilot-readable.js';
|
|
8
8
|
export { useMakeCopilotDocumentReadable } from './hooks/use-make-copilot-document-readable.js';
|
|
9
9
|
export { UseChatHelpers } from './hooks/use-chat.js';
|
|
10
|
+
export { useCopilotReadable } from './hooks/use-copilot-readable.js';
|
|
10
11
|
export { DocumentPointer } from './types/document-pointer.js';
|
|
11
12
|
export { SystemMessageFunction } from './types/system-message.js';
|
|
12
13
|
export { ActionRenderProps, RenderFunctionStatus } from './types/frontend-action.js';
|
package/dist/index.js
CHANGED
|
@@ -92,6 +92,7 @@ __export(src_exports, {
|
|
|
92
92
|
useCopilotChat: () => useCopilotChat,
|
|
93
93
|
useCopilotChatV2: () => useCopilotChatV2,
|
|
94
94
|
useCopilotContext: () => useCopilotContext,
|
|
95
|
+
useCopilotReadable: () => useCopilotReadable,
|
|
95
96
|
useMakeCopilotActionable: () => useMakeCopilotActionable,
|
|
96
97
|
useMakeCopilotDocumentReadable: () => useMakeCopilotDocumentReadable,
|
|
97
98
|
useMakeCopilotReadable: () => useMakeCopilotReadable
|
|
@@ -924,8 +925,28 @@ function useMakeCopilotDocumentReadable(document, categories, dependencies = [])
|
|
|
924
925
|
return idRef.current;
|
|
925
926
|
}
|
|
926
927
|
|
|
927
|
-
// src/
|
|
928
|
+
// src/hooks/use-copilot-readable.ts
|
|
928
929
|
var import_react11 = require("react");
|
|
930
|
+
function convertToJSON(description, value) {
|
|
931
|
+
return `${description}: ${typeof value === "string" ? value : JSON.stringify(value)}`;
|
|
932
|
+
}
|
|
933
|
+
function useCopilotReadable({ description, value, parentId, categories, convert }, dependencies) {
|
|
934
|
+
const { addContext, removeContext } = (0, import_react11.useContext)(CopilotContext);
|
|
935
|
+
const idRef = (0, import_react11.useRef)();
|
|
936
|
+
convert = convert || convertToJSON;
|
|
937
|
+
const information = convert(description, value);
|
|
938
|
+
(0, import_react11.useEffect)(() => {
|
|
939
|
+
const id = addContext(information, parentId, categories);
|
|
940
|
+
idRef.current = id;
|
|
941
|
+
return () => {
|
|
942
|
+
removeContext(id);
|
|
943
|
+
};
|
|
944
|
+
}, [information, parentId, addContext, removeContext, ...dependencies || []]);
|
|
945
|
+
return idRef.current;
|
|
946
|
+
}
|
|
947
|
+
|
|
948
|
+
// src/openai-assistants/hooks/use-copilot-chat-v2.ts
|
|
949
|
+
var import_react12 = require("react");
|
|
929
950
|
|
|
930
951
|
// src/openai-assistants/utils/process-message-stream.ts
|
|
931
952
|
function processMessageStream(reader, processMessage) {
|
|
@@ -958,13 +979,13 @@ function useCopilotChatV2(options) {
|
|
|
958
979
|
getChatCompletionFunctionDescriptions,
|
|
959
980
|
getFunctionCallHandler,
|
|
960
981
|
copilotApiConfig
|
|
961
|
-
} = (0,
|
|
962
|
-
const [messages, setMessages] = (0,
|
|
963
|
-
const [input, setInput] = (0,
|
|
964
|
-
const [threadId, setThreadId] = (0,
|
|
965
|
-
const [status, setStatus] = (0,
|
|
966
|
-
const [error, setError] = (0,
|
|
967
|
-
const systemMessage = (0,
|
|
982
|
+
} = (0, import_react12.useContext)(CopilotContext);
|
|
983
|
+
const [messages, setMessages] = (0, import_react12.useState)([]);
|
|
984
|
+
const [input, setInput] = (0, import_react12.useState)("");
|
|
985
|
+
const [threadId, setThreadId] = (0, import_react12.useState)(void 0);
|
|
986
|
+
const [status, setStatus] = (0, import_react12.useState)("awaiting_message");
|
|
987
|
+
const [error, setError] = (0, import_react12.useState)(void 0);
|
|
988
|
+
const systemMessage = (0, import_react12.useMemo)(() => {
|
|
968
989
|
const systemMessageMaker = options.makeSystemMessage || defaultSystemMessage2;
|
|
969
990
|
const contextString = getContextString([], defaultCopilotContextCategories);
|
|
970
991
|
return {
|
|
@@ -1072,12 +1093,12 @@ var CopilotTask = class {
|
|
|
1072
1093
|
constructor(config) {
|
|
1073
1094
|
this.instructions = config.instructions;
|
|
1074
1095
|
this.actions = config.actions || [];
|
|
1075
|
-
this.includeCopilotReadable = config.includeCopilotReadable
|
|
1076
|
-
this.
|
|
1096
|
+
this.includeCopilotReadable = config.includeCopilotReadable !== false;
|
|
1097
|
+
this.includeCopilotActions = config.includeCopilotActions !== false && config.includeCopilotActionable !== false;
|
|
1077
1098
|
}
|
|
1078
1099
|
run(context, data) {
|
|
1079
1100
|
return __async(this, null, function* () {
|
|
1080
|
-
const entryPoints = this.
|
|
1101
|
+
const entryPoints = this.includeCopilotActions ? Object.assign({}, context.entryPoints) : {};
|
|
1081
1102
|
for (const fn of this.actions) {
|
|
1082
1103
|
entryPoints[fn.name] = fn;
|
|
1083
1104
|
}
|
|
@@ -1168,6 +1189,7 @@ ${instructions}
|
|
|
1168
1189
|
useCopilotChat,
|
|
1169
1190
|
useCopilotChatV2,
|
|
1170
1191
|
useCopilotContext,
|
|
1192
|
+
useCopilotReadable,
|
|
1171
1193
|
useMakeCopilotActionable,
|
|
1172
1194
|
useMakeCopilotDocumentReadable,
|
|
1173
1195
|
useMakeCopilotReadable
|