@copilotkit/react-core 1.5.8 → 1.5.10-next.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/CHANGELOG.md +27 -0
- package/dist/chunk-22XKTBPF.mjs +61 -0
- package/dist/chunk-22XKTBPF.mjs.map +1 -0
- package/dist/chunk-2KT73RVG.mjs +482 -0
- package/dist/chunk-2KT73RVG.mjs.map +1 -0
- package/dist/chunk-3GQPEN4M.mjs +160 -0
- package/dist/chunk-3GQPEN4M.mjs.map +1 -0
- package/dist/chunk-5FHSUKQL.mjs +70 -0
- package/dist/chunk-5FHSUKQL.mjs.map +1 -0
- package/dist/chunk-6BQVZFNO.mjs +35 -0
- package/dist/chunk-6BQVZFNO.mjs.map +1 -0
- package/dist/chunk-6U3UH3KO.mjs +140 -0
- package/dist/chunk-6U3UH3KO.mjs.map +1 -0
- package/dist/chunk-DCTJZ742.mjs +22 -0
- package/dist/chunk-DCTJZ742.mjs.map +1 -0
- package/dist/chunk-EFZPSZWO.mjs +1 -0
- package/dist/chunk-EFZPSZWO.mjs.map +1 -0
- package/dist/chunk-EWKJMQOF.mjs +107 -0
- package/dist/chunk-EWKJMQOF.mjs.map +1 -0
- package/dist/chunk-FQ53HQYZ.mjs +28 -0
- package/dist/chunk-FQ53HQYZ.mjs.map +1 -0
- package/dist/chunk-HIUT2NLX.mjs +23 -0
- package/dist/chunk-HIUT2NLX.mjs.map +1 -0
- package/dist/chunk-LHKIIAUQ.mjs +59 -0
- package/dist/chunk-LHKIIAUQ.mjs.map +1 -0
- package/dist/chunk-LNI2Z45S.mjs +242 -0
- package/dist/chunk-LNI2Z45S.mjs.map +1 -0
- package/dist/chunk-LUGEI4YQ.mjs +1 -0
- package/dist/chunk-LUGEI4YQ.mjs.map +1 -0
- package/dist/chunk-MLAS4QUR.mjs +18 -0
- package/dist/chunk-MLAS4QUR.mjs.map +1 -0
- package/dist/chunk-NR2BTA6Z.mjs +1 -0
- package/dist/chunk-NR2BTA6Z.mjs.map +1 -0
- package/dist/chunk-O7ARI5CV.mjs +31 -0
- package/dist/chunk-O7ARI5CV.mjs.map +1 -0
- package/dist/chunk-SKC7AJIV.mjs +61 -0
- package/dist/chunk-SKC7AJIV.mjs.map +1 -0
- package/dist/chunk-VGOFRULA.mjs +401 -0
- package/dist/chunk-VGOFRULA.mjs.map +1 -0
- package/dist/chunk-VNTDIJSG.mjs +37 -0
- package/dist/chunk-VNTDIJSG.mjs.map +1 -0
- package/dist/chunk-WXREY7UP.mjs +87 -0
- package/dist/chunk-WXREY7UP.mjs.map +1 -0
- package/dist/chunk-X36DNILG.mjs +215 -0
- package/dist/chunk-X36DNILG.mjs.map +1 -0
- package/dist/chunk-XERJQUHA.mjs +31 -0
- package/dist/chunk-XERJQUHA.mjs.map +1 -0
- package/dist/chunk-XOQMISG3.mjs +120 -0
- package/dist/chunk-XOQMISG3.mjs.map +1 -0
- package/dist/chunk-XXR4QFAQ.mjs +29 -0
- package/dist/chunk-XXR4QFAQ.mjs.map +1 -0
- package/dist/chunk-YPSGKPDA.mjs +1 -0
- package/dist/chunk-YPSGKPDA.mjs.map +1 -0
- package/dist/components/copilot-provider/copilot-messages.d.ts +16 -0
- package/dist/components/copilot-provider/copilot-messages.js +80 -0
- package/dist/components/copilot-provider/copilot-messages.js.map +1 -0
- package/dist/components/copilot-provider/copilot-messages.mjs +9 -0
- package/dist/components/copilot-provider/copilot-messages.mjs.map +1 -0
- package/dist/components/copilot-provider/copilotkit-props.d.ts +93 -0
- package/dist/components/copilot-provider/copilotkit-props.js +19 -0
- package/dist/components/copilot-provider/copilotkit-props.js.map +1 -0
- package/dist/components/copilot-provider/copilotkit-props.mjs +1 -0
- package/dist/components/copilot-provider/copilotkit-props.mjs.map +1 -0
- package/dist/components/copilot-provider/copilotkit.d.ts +18 -0
- package/dist/components/copilot-provider/copilotkit.js +990 -0
- package/dist/components/copilot-provider/copilotkit.js.map +1 -0
- package/dist/components/copilot-provider/copilotkit.mjs +22 -0
- package/dist/components/copilot-provider/copilotkit.mjs.map +1 -0
- package/dist/components/copilot-provider/index.d.ts +13 -0
- package/dist/components/copilot-provider/index.js +990 -0
- package/dist/components/copilot-provider/index.js.map +1 -0
- package/dist/components/copilot-provider/index.mjs +20 -0
- package/dist/components/copilot-provider/index.mjs.map +1 -0
- package/dist/components/error-boundary/error-boundary.d.ts +22 -0
- package/dist/components/error-boundary/error-boundary.js +183 -0
- package/dist/components/error-boundary/error-boundary.js.map +1 -0
- package/dist/components/error-boundary/error-boundary.mjs +12 -0
- package/dist/components/error-boundary/error-boundary.mjs.map +1 -0
- package/dist/components/error-boundary/error-utils.d.ts +11 -0
- package/dist/components/error-boundary/error-utils.js +177 -0
- package/dist/components/error-boundary/error-utils.js.map +1 -0
- package/dist/components/error-boundary/error-utils.mjs +13 -0
- package/dist/components/error-boundary/error-utils.mjs.map +1 -0
- package/dist/components/index.d.ts +13 -0
- package/dist/components/index.js +990 -0
- package/dist/components/index.js.map +1 -0
- package/dist/components/index.mjs +20 -0
- package/dist/components/index.mjs.map +1 -0
- package/dist/components/toast/exclamation-mark-icon.d.ts +9 -0
- package/dist/components/toast/exclamation-mark-icon.js +55 -0
- package/dist/components/toast/exclamation-mark-icon.js.map +1 -0
- package/dist/components/toast/exclamation-mark-icon.mjs +8 -0
- package/dist/components/toast/exclamation-mark-icon.mjs.map +1 -0
- package/dist/components/toast/toast-provider.d.ts +30 -0
- package/dist/components/toast/toast-provider.js +269 -0
- package/dist/components/toast/toast-provider.js.map +1 -0
- package/dist/components/toast/toast-provider.mjs +11 -0
- package/dist/components/toast/toast-provider.mjs.map +1 -0
- package/dist/context/copilot-context.d.ts +142 -0
- package/dist/context/copilot-context.js +138 -0
- package/dist/context/copilot-context.js.map +1 -0
- package/dist/context/copilot-context.mjs +10 -0
- package/dist/context/copilot-context.mjs.map +1 -0
- package/dist/context/copilot-messages-context.d.ts +15 -0
- package/dist/context/copilot-messages-context.js +57 -0
- package/dist/context/copilot-messages-context.js.map +1 -0
- package/dist/context/copilot-messages-context.mjs +10 -0
- package/dist/context/copilot-messages-context.mjs.map +1 -0
- package/dist/context/index.d.ts +11 -0
- package/dist/context/index.js +161 -0
- package/dist/context/index.js.map +1 -0
- package/dist/context/index.mjs +17 -0
- package/dist/context/index.mjs.map +1 -0
- package/dist/hooks/index.d.ts +21 -0
- package/dist/hooks/index.js +1303 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/index.mjs +56 -0
- package/dist/hooks/index.mjs.map +1 -0
- package/dist/hooks/use-chat.d.ts +124 -0
- package/dist/hooks/use-chat.js +608 -0
- package/dist/hooks/use-chat.js.map +1 -0
- package/dist/hooks/use-chat.mjs +12 -0
- package/dist/hooks/use-chat.mjs.map +1 -0
- package/dist/hooks/use-coagent-state-render.d.ts +60 -0
- package/dist/hooks/use-coagent-state-render.js +195 -0
- package/dist/hooks/use-coagent-state-render.js.map +1 -0
- package/dist/hooks/use-coagent-state-render.mjs +11 -0
- package/dist/hooks/use-coagent-state-render.mjs.map +1 -0
- package/dist/hooks/use-coagent.d.ts +199 -0
- package/dist/hooks/use-coagent.js +1064 -0
- package/dist/hooks/use-coagent.js.map +1 -0
- package/dist/hooks/use-coagent.mjs +29 -0
- package/dist/hooks/use-coagent.mjs.map +1 -0
- package/dist/hooks/use-copilot-action.d.ts +140 -0
- package/dist/hooks/use-copilot-action.js +369 -0
- package/dist/hooks/use-copilot-action.js.map +1 -0
- package/dist/hooks/use-copilot-action.mjs +11 -0
- package/dist/hooks/use-copilot-action.mjs.map +1 -0
- package/dist/hooks/use-copilot-authenticated-action.d.ts +8 -0
- package/dist/hooks/use-copilot-authenticated-action.js +418 -0
- package/dist/hooks/use-copilot-authenticated-action.js.map +1 -0
- package/dist/hooks/use-copilot-authenticated-action.mjs +12 -0
- package/dist/hooks/use-copilot-authenticated-action.mjs.map +1 -0
- package/dist/hooks/use-copilot-chat.d.ts +38 -0
- package/dist/hooks/use-copilot-chat.js +928 -0
- package/dist/hooks/use-copilot-chat.js.map +1 -0
- package/dist/hooks/use-copilot-chat.mjs +24 -0
- package/dist/hooks/use-copilot-chat.mjs.map +1 -0
- package/dist/hooks/use-copilot-readable.d.ts +33 -0
- package/dist/hooks/use-copilot-readable.js +158 -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-copilot-runtime-client.d.ts +5 -0
- package/dist/hooks/use-copilot-runtime-client.js +182 -0
- package/dist/hooks/use-copilot-runtime-client.js.map +1 -0
- package/dist/hooks/use-copilot-runtime-client.mjs +10 -0
- package/dist/hooks/use-copilot-runtime-client.mjs.map +1 -0
- package/dist/hooks/use-flat-category-store.d.ts +9 -0
- package/dist/hooks/use-flat-category-store.js +90 -0
- package/dist/hooks/use-flat-category-store.js.map +1 -0
- package/dist/hooks/use-flat-category-store.mjs +8 -0
- package/dist/hooks/use-flat-category-store.mjs.map +1 -0
- package/dist/hooks/use-make-copilot-document-readable.d.ts +12 -0
- package/dist/hooks/use-make-copilot-document-readable.js +153 -0
- package/dist/hooks/use-make-copilot-document-readable.js.map +1 -0
- package/dist/hooks/use-make-copilot-document-readable.mjs +9 -0
- package/dist/hooks/use-make-copilot-document-readable.mjs.map +1 -0
- package/dist/hooks/use-tree.d.ts +18 -0
- package/dist/hooks/use-tree.js +172 -0
- package/dist/hooks/use-tree.js.map +1 -0
- package/dist/hooks/use-tree.mjs +8 -0
- package/dist/hooks/use-tree.mjs.map +1 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.js +2224 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +83 -0
- package/dist/index.mjs.map +1 -0
- package/dist/lib/copilot-task.d.ts +97 -0
- package/dist/lib/copilot-task.js +195 -0
- package/dist/lib/copilot-task.js.map +1 -0
- package/dist/lib/copilot-task.mjs +20 -0
- package/dist/lib/copilot-task.mjs.map +1 -0
- package/dist/lib/index.d.ts +11 -0
- package/dist/lib/index.js +197 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/lib/index.mjs +21 -0
- package/dist/lib/index.mjs.map +1 -0
- package/dist/types/chat-suggestion-configuration.d.ts +22 -0
- package/dist/types/chat-suggestion-configuration.js +19 -0
- package/dist/types/chat-suggestion-configuration.js.map +1 -0
- package/dist/types/chat-suggestion-configuration.mjs +1 -0
- package/dist/types/chat-suggestion-configuration.mjs.map +1 -0
- package/dist/types/coagent-action.d.ts +29 -0
- package/dist/types/coagent-action.js +19 -0
- package/dist/types/coagent-action.js.map +1 -0
- package/dist/types/coagent-action.mjs +1 -0
- package/dist/types/coagent-action.mjs.map +1 -0
- package/dist/types/coagent-state.d.ts +11 -0
- package/dist/types/coagent-state.js +19 -0
- package/dist/types/coagent-state.js.map +1 -0
- package/dist/types/coagent-state.mjs +1 -0
- package/dist/types/coagent-state.mjs.map +1 -0
- package/dist/types/document-pointer.d.ts +9 -0
- package/dist/types/document-pointer.js +19 -0
- package/dist/types/document-pointer.js.map +1 -0
- package/dist/types/document-pointer.mjs +1 -0
- package/dist/types/document-pointer.mjs.map +1 -0
- package/dist/types/frontend-action.d.ts +126 -0
- package/dist/types/frontend-action.js +53 -0
- package/dist/types/frontend-action.js.map +1 -0
- package/dist/types/frontend-action.mjs +8 -0
- package/dist/types/frontend-action.mjs.map +1 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/index.js +19 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/index.mjs +2 -0
- package/dist/types/index.mjs.map +1 -0
- package/dist/types/system-message.d.ts +3 -0
- package/dist/types/system-message.js +19 -0
- package/dist/types/system-message.js.map +1 -0
- package/dist/types/system-message.mjs +1 -0
- package/dist/types/system-message.mjs.map +1 -0
- package/dist/utils/dev-console.d.ts +3 -0
- package/dist/utils/dev-console.js +42 -0
- package/dist/utils/dev-console.js.map +1 -0
- package/dist/utils/dev-console.mjs +8 -0
- package/dist/utils/dev-console.mjs.map +1 -0
- package/dist/utils/extract.d.ts +43 -0
- package/dist/utils/extract.js +208 -0
- package/dist/utils/extract.js.map +1 -0
- package/dist/utils/extract.mjs +18 -0
- package/dist/utils/extract.mjs.map +1 -0
- package/dist/utils/index.d.ts +13 -0
- package/dist/utils/index.js +226 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/index.mjs +21 -0
- package/dist/utils/index.mjs.map +1 -0
- package/dist/utils/utils.d.ts +2 -0
- package/dist/utils/utils.js +19 -0
- package/dist/utils/utils.js.map +1 -0
- package/dist/utils/utils.mjs +1 -0
- package/dist/utils/utils.mjs.map +1 -0
- package/dist/utils/utils.test.d.ts +2 -0
- package/dist/utils/utils.test.js +9 -0
- package/dist/utils/utils.test.js.map +1 -0
- package/dist/utils/utils.test.mjs +7 -0
- package/dist/utils/utils.test.mjs.map +1 -0
- package/package.json +3 -3
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
10
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
11
|
+
var __spreadValues = (a, b) => {
|
|
12
|
+
for (var prop in b || (b = {}))
|
|
13
|
+
if (__hasOwnProp.call(b, prop))
|
|
14
|
+
__defNormalProp(a, prop, b[prop]);
|
|
15
|
+
if (__getOwnPropSymbols)
|
|
16
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
17
|
+
if (__propIsEnum.call(b, prop))
|
|
18
|
+
__defNormalProp(a, prop, b[prop]);
|
|
19
|
+
}
|
|
20
|
+
return a;
|
|
21
|
+
};
|
|
22
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
23
|
+
var __export = (target, all) => {
|
|
24
|
+
for (var name in all)
|
|
25
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
26
|
+
};
|
|
27
|
+
var __copyProps = (to, from, except, desc) => {
|
|
28
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
29
|
+
for (let key of __getOwnPropNames(from))
|
|
30
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
31
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
32
|
+
}
|
|
33
|
+
return to;
|
|
34
|
+
};
|
|
35
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
36
|
+
|
|
37
|
+
// src/hooks/use-tree.ts
|
|
38
|
+
var use_tree_exports = {};
|
|
39
|
+
__export(use_tree_exports, {
|
|
40
|
+
default: () => use_tree_default
|
|
41
|
+
});
|
|
42
|
+
module.exports = __toCommonJS(use_tree_exports);
|
|
43
|
+
var import_shared = require("@copilotkit/shared");
|
|
44
|
+
var import_react = require("react");
|
|
45
|
+
var removeNode = (nodes, id) => {
|
|
46
|
+
return nodes.reduce((result, node) => {
|
|
47
|
+
if (node.id !== id) {
|
|
48
|
+
const newNode = __spreadProps(__spreadValues({}, node), { children: removeNode(node.children, id) });
|
|
49
|
+
result.push(newNode);
|
|
50
|
+
}
|
|
51
|
+
return result;
|
|
52
|
+
}, []);
|
|
53
|
+
};
|
|
54
|
+
var addNode = (nodes, newNode, parentId) => {
|
|
55
|
+
if (!parentId) {
|
|
56
|
+
return [...nodes, newNode];
|
|
57
|
+
}
|
|
58
|
+
return nodes.map((node) => {
|
|
59
|
+
if (node.id === parentId) {
|
|
60
|
+
return __spreadProps(__spreadValues({}, node), { children: [...node.children, newNode] });
|
|
61
|
+
} else if (node.children.length) {
|
|
62
|
+
return __spreadProps(__spreadValues({}, node), { children: addNode(node.children, newNode, parentId) });
|
|
63
|
+
}
|
|
64
|
+
return node;
|
|
65
|
+
});
|
|
66
|
+
};
|
|
67
|
+
var treeIndentationRepresentation = (index, indentLevel) => {
|
|
68
|
+
if (indentLevel === 0) {
|
|
69
|
+
return (index + 1).toString();
|
|
70
|
+
} else if (indentLevel === 1) {
|
|
71
|
+
return String.fromCharCode(65 + index);
|
|
72
|
+
} else if (indentLevel === 2) {
|
|
73
|
+
return String.fromCharCode(97 + index);
|
|
74
|
+
} else {
|
|
75
|
+
return "-";
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
var printNode = (node, prefix = "", indentLevel = 0) => {
|
|
79
|
+
const indent = " ".repeat(3).repeat(indentLevel);
|
|
80
|
+
const prefixPlusIndentLength = prefix.length + indent.length;
|
|
81
|
+
const subsequentLinesPrefix = " ".repeat(prefixPlusIndentLength);
|
|
82
|
+
const valueLines = node.value.split("\n");
|
|
83
|
+
const outputFirstLine = `${indent}${prefix}${valueLines[0]}`;
|
|
84
|
+
const outputSubsequentLines = valueLines.slice(1).map((line) => `${subsequentLinesPrefix}${line}`).join("\n");
|
|
85
|
+
let output = `${outputFirstLine}
|
|
86
|
+
`;
|
|
87
|
+
if (outputSubsequentLines) {
|
|
88
|
+
output += `${outputSubsequentLines}
|
|
89
|
+
`;
|
|
90
|
+
}
|
|
91
|
+
const childPrePrefix = " ".repeat(prefix.length);
|
|
92
|
+
node.children.forEach(
|
|
93
|
+
(child, index) => output += printNode(
|
|
94
|
+
child,
|
|
95
|
+
`${childPrePrefix}${treeIndentationRepresentation(index, indentLevel + 1)}. `,
|
|
96
|
+
indentLevel + 1
|
|
97
|
+
)
|
|
98
|
+
);
|
|
99
|
+
return output;
|
|
100
|
+
};
|
|
101
|
+
function treeReducer(state, action) {
|
|
102
|
+
switch (action.type) {
|
|
103
|
+
case "ADD_NODE": {
|
|
104
|
+
const { value, parentId, id: newNodeId } = action;
|
|
105
|
+
const newNode = {
|
|
106
|
+
id: newNodeId,
|
|
107
|
+
value,
|
|
108
|
+
children: [],
|
|
109
|
+
categories: new Set(action.categories)
|
|
110
|
+
};
|
|
111
|
+
try {
|
|
112
|
+
return addNode(state, newNode, parentId);
|
|
113
|
+
} catch (error) {
|
|
114
|
+
console.error(`Error while adding node with id ${newNodeId}: ${error}`);
|
|
115
|
+
return state;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
case "REMOVE_NODE":
|
|
119
|
+
return removeNode(state, action.id);
|
|
120
|
+
default:
|
|
121
|
+
return state;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
var useTree = () => {
|
|
125
|
+
const [tree, dispatch] = (0, import_react.useReducer)(treeReducer, []);
|
|
126
|
+
const addElement = (0, import_react.useCallback)(
|
|
127
|
+
(value, categories, parentId) => {
|
|
128
|
+
const newNodeId = (0, import_shared.randomId)();
|
|
129
|
+
dispatch({
|
|
130
|
+
type: "ADD_NODE",
|
|
131
|
+
value,
|
|
132
|
+
parentId,
|
|
133
|
+
id: newNodeId,
|
|
134
|
+
categories
|
|
135
|
+
});
|
|
136
|
+
return newNodeId;
|
|
137
|
+
},
|
|
138
|
+
[]
|
|
139
|
+
);
|
|
140
|
+
const removeElement = (0, import_react.useCallback)((id) => {
|
|
141
|
+
dispatch({ type: "REMOVE_NODE", id });
|
|
142
|
+
}, []);
|
|
143
|
+
const printTree = (0, import_react.useCallback)(
|
|
144
|
+
(categories) => {
|
|
145
|
+
const categoriesSet = new Set(categories);
|
|
146
|
+
let output = "";
|
|
147
|
+
tree.forEach((node, index) => {
|
|
148
|
+
if (!setsHaveIntersection(categoriesSet, node.categories)) {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
if (index !== 0) {
|
|
152
|
+
output += "\n";
|
|
153
|
+
}
|
|
154
|
+
output += printNode(node, `${treeIndentationRepresentation(index, 0)}. `);
|
|
155
|
+
});
|
|
156
|
+
return output;
|
|
157
|
+
},
|
|
158
|
+
[tree]
|
|
159
|
+
);
|
|
160
|
+
return { tree, addElement, printTree, removeElement };
|
|
161
|
+
};
|
|
162
|
+
var use_tree_default = useTree;
|
|
163
|
+
function setsHaveIntersection(setA, setB) {
|
|
164
|
+
const [smallerSet, largerSet] = setA.size <= setB.size ? [setA, setB] : [setB, setA];
|
|
165
|
+
for (let item of smallerSet) {
|
|
166
|
+
if (largerSet.has(item)) {
|
|
167
|
+
return true;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
//# sourceMappingURL=use-tree.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/use-tree.ts"],"sourcesContent":["import { randomId } from \"@copilotkit/shared\";\nimport { useCallback, useReducer } from \"react\";\n\nexport type TreeNodeId = string;\n\nexport interface TreeNode {\n id: TreeNodeId;\n value: string;\n children: TreeNode[];\n parentId?: TreeNodeId;\n categories: Set<string>;\n}\n\nexport type Tree = TreeNode[];\n\nexport interface UseTreeReturn {\n tree: Tree;\n addElement: (value: string, categories: string[], parentId?: TreeNodeId) => TreeNodeId;\n printTree: (categories: string[]) => string;\n removeElement: (id: TreeNodeId) => void;\n}\n\nconst findNode = (nodes: Tree, id: TreeNodeId): TreeNode | undefined => {\n for (const node of nodes) {\n if (node.id === id) {\n return node;\n }\n const result = findNode(node.children, id);\n if (result) {\n return result;\n }\n }\n return undefined;\n};\n\nconst removeNode = (nodes: Tree, id: TreeNodeId): Tree => {\n return nodes.reduce((result: Tree, node) => {\n if (node.id !== id) {\n const newNode = { ...node, children: removeNode(node.children, id) };\n result.push(newNode);\n }\n return result;\n }, []);\n};\n\nconst addNode = (nodes: Tree, newNode: TreeNode, parentId?: TreeNodeId): 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 = (index: number, indentLevel: number): string => {\n if (indentLevel === 0) {\n return (index + 1).toString();\n } else if (indentLevel === 1) {\n return String.fromCharCode(65 + index); // 65 is the ASCII value for 'A'\n } else if (indentLevel === 2) {\n return String.fromCharCode(97 + index); // 97 is the ASCII value for 'a'\n } else {\n return \"-\";\n }\n};\n\nconst printNode = (node: TreeNode, prefix = \"\", indentLevel = 0): string => {\n const indent = \" \".repeat(3).repeat(indentLevel);\n\n const prefixPlusIndentLength = prefix.length + indent.length;\n const subsequentLinesPrefix = \" \".repeat(prefixPlusIndentLength);\n\n const valueLines = node.value.split(\"\\n\");\n\n const outputFirstLine = `${indent}${prefix}${valueLines[0]}`;\n const outputSubsequentLines = valueLines\n .slice(1)\n .map((line) => `${subsequentLinesPrefix}${line}`)\n .join(\"\\n\");\n\n let output = `${outputFirstLine}\\n`;\n if (outputSubsequentLines) {\n output += `${outputSubsequentLines}\\n`;\n }\n\n const childPrePrefix = \" \".repeat(prefix.length);\n\n node.children.forEach(\n (child, index) =>\n (output += printNode(\n child,\n `${childPrePrefix}${treeIndentationRepresentation(index, indentLevel + 1)}. `,\n indentLevel + 1,\n )),\n );\n return output;\n};\n\n// Action types\ntype Action =\n | {\n type: \"ADD_NODE\";\n value: string;\n parentId?: string;\n id: string;\n categories: string[];\n }\n | { type: \"REMOVE_NODE\"; id: string };\n\n// Reducer function\nfunction treeReducer(state: Tree, action: Action): Tree {\n switch (action.type) {\n case \"ADD_NODE\": {\n const { value, parentId, id: newNodeId } = action;\n const newNode: TreeNode = {\n id: newNodeId,\n value,\n children: [],\n categories: new Set(action.categories),\n };\n\n try {\n return addNode(state, newNode, parentId);\n } catch (error) {\n console.error(`Error while adding node with id ${newNodeId}: ${error}`);\n return state;\n }\n }\n case \"REMOVE_NODE\":\n return removeNode(state, action.id);\n default:\n return state;\n }\n}\n\n// useTree hook\nconst useTree = (): UseTreeReturn => {\n const [tree, dispatch] = useReducer(treeReducer, []);\n\n const addElement = useCallback(\n (value: string, categories: string[], parentId?: string): TreeNodeId => {\n const newNodeId = randomId(); // Generate new ID outside of dispatch\n dispatch({\n type: \"ADD_NODE\",\n value,\n parentId,\n id: newNodeId,\n categories: categories,\n });\n return newNodeId; // Return the new ID\n },\n [],\n );\n\n const removeElement = useCallback((id: TreeNodeId): void => {\n dispatch({ type: \"REMOVE_NODE\", id });\n }, []);\n\n const printTree = useCallback(\n (categories: string[]): string => {\n const categoriesSet = new Set(categories);\n\n let output = \"\";\n tree.forEach((node, index) => {\n // if the node does not have any of the desired categories, continue to the next node\n if (!setsHaveIntersection(categoriesSet, node.categories)) {\n return;\n }\n\n // add a new line before each node except the first one\n if (index !== 0) {\n output += \"\\n\";\n }\n\n output += printNode(node, `${treeIndentationRepresentation(index, 0)}. `);\n });\n return output;\n },\n [tree],\n );\n\n return { tree, addElement, printTree, removeElement };\n};\n\nexport default useTree;\n\nfunction setsHaveIntersection<T>(setA: Set<T>, setB: Set<T>): boolean {\n const [smallerSet, largerSet] = setA.size <= setB.size ? [setA, setB] : [setB, setA];\n\n for (let item of smallerSet) {\n if (largerSet.has(item)) {\n return true;\n }\n }\n\n return false;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAyB;AACzB,mBAAwC;AAkCxC,IAAM,aAAa,CAAC,OAAa,OAAyB;AACxD,SAAO,MAAM,OAAO,CAAC,QAAc,SAAS;AAC1C,QAAI,KAAK,OAAO,IAAI;AAClB,YAAM,UAAU,iCAAK,OAAL,EAAW,UAAU,WAAW,KAAK,UAAU,EAAE,EAAE;AACnE,aAAO,KAAK,OAAO;AAAA,IACrB;AACA,WAAO;AAAA,EACT,GAAG,CAAC,CAAC;AACP;AAEA,IAAM,UAAU,CAAC,OAAa,SAAmB,aAAgC;AAC/E,MAAI,CAAC,UAAU;AACb,WAAO,CAAC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AACf,oBAAU;AAAA,QACZ;AAEA,kBAAU,UAAU,MAAM,GAAG,8BAA8B,OAAO,CAAC,KAAK;AAAA,MAC1E,CAAC;AACD,aAAO;AAAA,IACT;AAAA,IACA,CAAC,IAAI;AAAA,EACP;AAEA,SAAO,EAAE,MAAM,YAAY,WAAW,cAAc;AACtD;AAEA,IAAO,mBAAQ;AAEf,SAAS,qBAAwB,MAAc,MAAuB;AACpE,QAAM,CAAC,YAAY,SAAS,IAAI,KAAK,QAAQ,KAAK,OAAO,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM,IAAI;AAEnF,WAAS,QAAQ,YAAY;AAC3B,QAAI,UAAU,IAAI,IAAI,GAAG;AACvB,aAAO;AAAA,IACT;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export { CopilotKit, defaultCopilotContextCategories } from './components/copilot-provider/copilotkit.js';
|
|
2
|
+
export { CopilotKitProps } from './components/copilot-provider/copilotkit-props.js';
|
|
3
|
+
export { CoagentInChatRenderFunction, CopilotApiConfig, CopilotContext, CopilotContextParams, useCopilotContext } from './context/copilot-context.js';
|
|
4
|
+
export { CopilotMessagesContext, CopilotMessagesContextParams, useCopilotMessagesContext } from './context/copilot-messages-context.js';
|
|
5
|
+
export { UseCopilotChatOptions, UseCopilotChatReturn, useCopilotChat } from './hooks/use-copilot-chat.js';
|
|
6
|
+
export { useCopilotAction } from './hooks/use-copilot-action.js';
|
|
7
|
+
export { useCoAgentStateRender } from './hooks/use-coagent-state-render.js';
|
|
8
|
+
export { useMakeCopilotDocumentReadable } from './hooks/use-make-copilot-document-readable.js';
|
|
9
|
+
export { UseChatHelpers } from './hooks/use-chat.js';
|
|
10
|
+
export { useCopilotReadable } from './hooks/use-copilot-readable.js';
|
|
11
|
+
export { HintFunction, runAgent, startAgent, stopAgent, useCoAgent } from './hooks/use-coagent.js';
|
|
12
|
+
export { useCopilotRuntimeClient } from './hooks/use-copilot-runtime-client.js';
|
|
13
|
+
export { useCopilotAuthenticatedAction } from './hooks/use-copilot-authenticated-action.js';
|
|
14
|
+
export { DocumentPointer } from './types/document-pointer.js';
|
|
15
|
+
export { SystemMessageFunction } from './types/system-message.js';
|
|
16
|
+
export { ActionRenderProps, CatchAllActionRenderProps, RenderFunctionStatus } from './types/frontend-action.js';
|
|
17
|
+
export { CopilotChatSuggestionConfiguration } from './types/chat-suggestion-configuration.js';
|
|
18
|
+
export { CopilotTask, CopilotTaskConfig } from './lib/copilot-task.js';
|
|
19
|
+
export { extract } from './utils/extract.js';
|
|
20
|
+
export { shouldShowDevConsole } from './utils/dev-console.js';
|
|
21
|
+
import 'react/jsx-runtime';
|
|
22
|
+
import '@copilotkit/runtime-client-gql';
|
|
23
|
+
import 'react';
|
|
24
|
+
import '@copilotkit/shared';
|
|
25
|
+
import './hooks/use-tree.js';
|
|
26
|
+
import './types/coagent-action.js';
|
|
27
|
+
import './types/coagent-state.js';
|