@copilotkit/react-core 1.5.1-next.3 → 1.5.1-next.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/CHANGELOG.md +11 -2
- package/package.json +5 -5
- package/dist/chunk-2KCEHGSI.mjs +0 -192
- package/dist/chunk-2KCEHGSI.mjs.map +0 -1
- package/dist/chunk-5FHSUKQL.mjs +0 -70
- package/dist/chunk-5FHSUKQL.mjs.map +0 -1
- package/dist/chunk-6OR25P32.mjs +0 -426
- package/dist/chunk-6OR25P32.mjs.map +0 -1
- package/dist/chunk-6U3UH3KO.mjs +0 -140
- package/dist/chunk-6U3UH3KO.mjs.map +0 -1
- package/dist/chunk-DCTJZ742.mjs +0 -22
- package/dist/chunk-DCTJZ742.mjs.map +0 -1
- package/dist/chunk-DDVXFNYA.mjs +0 -126
- package/dist/chunk-DDVXFNYA.mjs.map +0 -1
- package/dist/chunk-EFZPSZWO.mjs +0 -1
- package/dist/chunk-EFZPSZWO.mjs.map +0 -1
- package/dist/chunk-FXHKK52V.mjs +0 -119
- package/dist/chunk-FXHKK52V.mjs.map +0 -1
- package/dist/chunk-H4VZMKR6.mjs +0 -23
- package/dist/chunk-H4VZMKR6.mjs.map +0 -1
- package/dist/chunk-H7LSKIDK.mjs +0 -167
- package/dist/chunk-H7LSKIDK.mjs.map +0 -1
- package/dist/chunk-JDQCJCAQ.mjs +0 -295
- package/dist/chunk-JDQCJCAQ.mjs.map +0 -1
- package/dist/chunk-L34MHAXR.mjs +0 -1
- package/dist/chunk-L34MHAXR.mjs.map +0 -1
- package/dist/chunk-LODRWFMB.mjs +0 -75
- package/dist/chunk-LODRWFMB.mjs.map +0 -1
- package/dist/chunk-LUGEI4YQ.mjs +0 -1
- package/dist/chunk-LUGEI4YQ.mjs.map +0 -1
- package/dist/chunk-MLAS4QUR.mjs +0 -18
- package/dist/chunk-MLAS4QUR.mjs.map +0 -1
- package/dist/chunk-MWZO6TUR.mjs +0 -91
- package/dist/chunk-MWZO6TUR.mjs.map +0 -1
- package/dist/chunk-O7ARI5CV.mjs +0 -31
- package/dist/chunk-O7ARI5CV.mjs.map +0 -1
- package/dist/chunk-ODN4H66E.mjs +0 -31
- package/dist/chunk-ODN4H66E.mjs.map +0 -1
- package/dist/chunk-QDGDXRRJ.mjs +0 -28
- package/dist/chunk-QDGDXRRJ.mjs.map +0 -1
- package/dist/chunk-SKC7AJIV.mjs +0 -61
- package/dist/chunk-SKC7AJIV.mjs.map +0 -1
- package/dist/chunk-XINZBP3J.mjs +0 -49
- package/dist/chunk-XINZBP3J.mjs.map +0 -1
- package/dist/chunk-XXR4QFAQ.mjs +0 -29
- package/dist/chunk-XXR4QFAQ.mjs.map +0 -1
- package/dist/chunk-YPSGKPDA.mjs +0 -1
- package/dist/chunk-YPSGKPDA.mjs.map +0 -1
- package/dist/components/copilot-provider/copilot-messages.d.ts +0 -7
- package/dist/components/copilot-provider/copilot-messages.js +0 -80
- package/dist/components/copilot-provider/copilot-messages.js.map +0 -1
- package/dist/components/copilot-provider/copilot-messages.mjs +0 -9
- package/dist/components/copilot-provider/copilot-messages.mjs.map +0 -1
- package/dist/components/copilot-provider/copilotkit-props.d.ts +0 -72
- package/dist/components/copilot-provider/copilotkit-props.js +0 -19
- package/dist/components/copilot-provider/copilotkit-props.js.map +0 -1
- package/dist/components/copilot-provider/copilotkit-props.mjs +0 -1
- package/dist/components/copilot-provider/copilotkit-props.mjs.map +0 -1
- package/dist/components/copilot-provider/copilotkit.d.ts +0 -9
- package/dist/components/copilot-provider/copilotkit.js +0 -861
- package/dist/components/copilot-provider/copilotkit.js.map +0 -1
- package/dist/components/copilot-provider/copilotkit.mjs +0 -21
- package/dist/components/copilot-provider/copilotkit.mjs.map +0 -1
- package/dist/components/copilot-provider/index.d.ts +0 -4
- package/dist/components/copilot-provider/index.js +0 -861
- package/dist/components/copilot-provider/index.js.map +0 -1
- package/dist/components/copilot-provider/index.mjs +0 -19
- package/dist/components/copilot-provider/index.mjs.map +0 -1
- package/dist/components/index.d.ts +0 -4
- package/dist/components/index.js +0 -861
- package/dist/components/index.js.map +0 -1
- package/dist/components/index.mjs +0 -19
- package/dist/components/index.mjs.map +0 -1
- package/dist/components/toast/exclamation-mark-icon.d.ts +0 -9
- package/dist/components/toast/exclamation-mark-icon.js +0 -55
- package/dist/components/toast/exclamation-mark-icon.js.map +0 -1
- package/dist/components/toast/exclamation-mark-icon.mjs +0 -8
- package/dist/components/toast/exclamation-mark-icon.mjs.map +0 -1
- package/dist/components/toast/toast-provider.d.ts +0 -29
- package/dist/components/toast/toast-provider.js +0 -255
- package/dist/components/toast/toast-provider.js.map +0 -1
- package/dist/components/toast/toast-provider.mjs +0 -11
- package/dist/components/toast/toast-provider.mjs.map +0 -1
- package/dist/context/copilot-context.d.ts +0 -109
- package/dist/context/copilot-context.js +0 -126
- package/dist/context/copilot-context.js.map +0 -1
- package/dist/context/copilot-context.mjs +0 -10
- package/dist/context/copilot-context.mjs.map +0 -1
- package/dist/context/copilot-messages-context.d.ts +0 -15
- package/dist/context/copilot-messages-context.js +0 -57
- package/dist/context/copilot-messages-context.js.map +0 -1
- package/dist/context/copilot-messages-context.mjs +0 -10
- package/dist/context/copilot-messages-context.mjs.map +0 -1
- package/dist/context/index.d.ts +0 -11
- package/dist/context/index.js +0 -149
- package/dist/context/index.js.map +0 -1
- package/dist/context/index.mjs +0 -17
- package/dist/context/index.mjs.map +0 -1
- package/dist/hooks/index.d.ts +0 -19
- package/dist/hooks/index.js +0 -897
- package/dist/hooks/index.js.map +0 -1
- package/dist/hooks/index.mjs +0 -44
- package/dist/hooks/index.mjs.map +0 -1
- package/dist/hooks/use-chat.d.ts +0 -92
- package/dist/hooks/use-chat.js +0 -360
- package/dist/hooks/use-chat.js.map +0 -1
- package/dist/hooks/use-chat.mjs +0 -11
- package/dist/hooks/use-chat.mjs.map +0 -1
- package/dist/hooks/use-coagent-state-render.d.ts +0 -60
- package/dist/hooks/use-coagent-state-render.js +0 -160
- package/dist/hooks/use-coagent-state-render.js.map +0 -1
- package/dist/hooks/use-coagent-state-render.mjs +0 -9
- package/dist/hooks/use-coagent-state-render.mjs.map +0 -1
- package/dist/hooks/use-coagent.d.ts +0 -186
- package/dist/hooks/use-coagent.js +0 -726
- package/dist/hooks/use-coagent.js.map +0 -1
- package/dist/hooks/use-coagent.mjs +0 -21
- package/dist/hooks/use-coagent.mjs.map +0 -1
- package/dist/hooks/use-copilot-action.d.ts +0 -130
- package/dist/hooks/use-copilot-action.js +0 -219
- package/dist/hooks/use-copilot-action.js.map +0 -1
- package/dist/hooks/use-copilot-action.mjs +0 -9
- package/dist/hooks/use-copilot-action.mjs.map +0 -1
- package/dist/hooks/use-copilot-chat.d.ts +0 -36
- package/dist/hooks/use-copilot-chat.js +0 -623
- package/dist/hooks/use-copilot-chat.js.map +0 -1
- package/dist/hooks/use-copilot-chat.mjs +0 -22
- package/dist/hooks/use-copilot-chat.mjs.map +0 -1
- package/dist/hooks/use-copilot-readable.d.ts +0 -33
- package/dist/hooks/use-copilot-readable.js +0 -146
- package/dist/hooks/use-copilot-readable.js.map +0 -1
- package/dist/hooks/use-copilot-readable.mjs +0 -9
- package/dist/hooks/use-copilot-readable.mjs.map +0 -1
- package/dist/hooks/use-copilot-runtime-client.d.ts +0 -5
- package/dist/hooks/use-copilot-runtime-client.js +0 -76
- package/dist/hooks/use-copilot-runtime-client.js.map +0 -1
- package/dist/hooks/use-copilot-runtime-client.mjs +0 -10
- package/dist/hooks/use-copilot-runtime-client.mjs.map +0 -1
- package/dist/hooks/use-flat-category-store.d.ts +0 -9
- package/dist/hooks/use-flat-category-store.js +0 -90
- package/dist/hooks/use-flat-category-store.js.map +0 -1
- package/dist/hooks/use-flat-category-store.mjs +0 -8
- package/dist/hooks/use-flat-category-store.mjs.map +0 -1
- package/dist/hooks/use-make-copilot-document-readable.d.ts +0 -12
- package/dist/hooks/use-make-copilot-document-readable.js +0 -141
- package/dist/hooks/use-make-copilot-document-readable.js.map +0 -1
- package/dist/hooks/use-make-copilot-document-readable.mjs +0 -9
- package/dist/hooks/use-make-copilot-document-readable.mjs.map +0 -1
- package/dist/hooks/use-tree.d.ts +0 -18
- package/dist/hooks/use-tree.js +0 -172
- package/dist/hooks/use-tree.js.map +0 -1
- package/dist/hooks/use-tree.mjs +0 -8
- package/dist/hooks/use-tree.mjs.map +0 -1
- package/dist/index.d.ts +0 -26
- package/dist/index.js +0 -1810
- package/dist/index.js.map +0 -1
- package/dist/index.mjs +0 -71
- package/dist/index.mjs.map +0 -1
- package/dist/lib/copilot-task.d.ts +0 -92
- package/dist/lib/copilot-task.js +0 -157
- package/dist/lib/copilot-task.js.map +0 -1
- package/dist/lib/copilot-task.mjs +0 -18
- package/dist/lib/copilot-task.mjs.map +0 -1
- package/dist/lib/index.d.ts +0 -11
- package/dist/lib/index.js +0 -159
- package/dist/lib/index.js.map +0 -1
- package/dist/lib/index.mjs +0 -19
- package/dist/lib/index.mjs.map +0 -1
- package/dist/types/chat-suggestion-configuration.d.ts +0 -22
- package/dist/types/chat-suggestion-configuration.js +0 -19
- package/dist/types/chat-suggestion-configuration.js.map +0 -1
- package/dist/types/chat-suggestion-configuration.mjs +0 -1
- package/dist/types/chat-suggestion-configuration.mjs.map +0 -1
- package/dist/types/coagent-action.d.ts +0 -29
- package/dist/types/coagent-action.js +0 -19
- package/dist/types/coagent-action.js.map +0 -1
- package/dist/types/coagent-action.mjs +0 -1
- package/dist/types/coagent-action.mjs.map +0 -1
- package/dist/types/coagent-state.d.ts +0 -11
- package/dist/types/coagent-state.js +0 -19
- package/dist/types/coagent-state.js.map +0 -1
- package/dist/types/coagent-state.mjs +0 -1
- package/dist/types/coagent-state.mjs.map +0 -1
- package/dist/types/document-pointer.d.ts +0 -9
- package/dist/types/document-pointer.js +0 -19
- package/dist/types/document-pointer.js.map +0 -1
- package/dist/types/document-pointer.mjs +0 -1
- package/dist/types/document-pointer.mjs.map +0 -1
- package/dist/types/frontend-action.d.ts +0 -107
- package/dist/types/frontend-action.js +0 -19
- package/dist/types/frontend-action.js.map +0 -1
- package/dist/types/frontend-action.mjs +0 -1
- package/dist/types/frontend-action.mjs.map +0 -1
- package/dist/types/index.d.ts +0 -6
- package/dist/types/index.js +0 -19
- package/dist/types/index.js.map +0 -1
- package/dist/types/index.mjs +0 -2
- package/dist/types/index.mjs.map +0 -1
- package/dist/types/system-message.d.ts +0 -3
- package/dist/types/system-message.js +0 -19
- package/dist/types/system-message.js.map +0 -1
- package/dist/types/system-message.mjs +0 -1
- package/dist/types/system-message.mjs.map +0 -1
- package/dist/utils/dev-console.d.ts +0 -3
- package/dist/utils/dev-console.js +0 -42
- package/dist/utils/dev-console.js.map +0 -1
- package/dist/utils/dev-console.mjs +0 -8
- package/dist/utils/dev-console.mjs.map +0 -1
- package/dist/utils/extract.d.ts +0 -42
- package/dist/utils/extract.js +0 -190
- package/dist/utils/extract.js.map +0 -1
- package/dist/utils/extract.mjs +0 -17
- package/dist/utils/extract.mjs.map +0 -1
- package/dist/utils/index.d.ts +0 -13
- package/dist/utils/index.js +0 -208
- package/dist/utils/index.js.map +0 -1
- package/dist/utils/index.mjs +0 -20
- package/dist/utils/index.mjs.map +0 -1
- package/dist/utils/utils.d.ts +0 -2
- package/dist/utils/utils.js +0 -19
- package/dist/utils/utils.js.map +0 -1
- package/dist/utils/utils.mjs +0 -1
- package/dist/utils/utils.mjs.map +0 -1
- package/dist/utils/utils.test.d.ts +0 -2
- package/dist/utils/utils.test.js +0 -9
- package/dist/utils/utils.test.js.map +0 -1
- package/dist/utils/utils.test.mjs +0 -7
- package/dist/utils/utils.test.mjs.map +0 -1
|
@@ -1,726 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __defProps = Object.defineProperties;
|
|
5
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
7
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
9
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
10
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
12
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
13
|
-
var __spreadValues = (a, b) => {
|
|
14
|
-
for (var prop in b || (b = {}))
|
|
15
|
-
if (__hasOwnProp.call(b, prop))
|
|
16
|
-
__defNormalProp(a, prop, b[prop]);
|
|
17
|
-
if (__getOwnPropSymbols)
|
|
18
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
19
|
-
if (__propIsEnum.call(b, prop))
|
|
20
|
-
__defNormalProp(a, prop, b[prop]);
|
|
21
|
-
}
|
|
22
|
-
return a;
|
|
23
|
-
};
|
|
24
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
25
|
-
var __objRest = (source, exclude) => {
|
|
26
|
-
var target = {};
|
|
27
|
-
for (var prop in source)
|
|
28
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
29
|
-
target[prop] = source[prop];
|
|
30
|
-
if (source != null && __getOwnPropSymbols)
|
|
31
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
32
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
33
|
-
target[prop] = source[prop];
|
|
34
|
-
}
|
|
35
|
-
return target;
|
|
36
|
-
};
|
|
37
|
-
var __export = (target, all) => {
|
|
38
|
-
for (var name in all)
|
|
39
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
40
|
-
};
|
|
41
|
-
var __copyProps = (to, from, except, desc) => {
|
|
42
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
43
|
-
for (let key of __getOwnPropNames(from))
|
|
44
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
45
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
46
|
-
}
|
|
47
|
-
return to;
|
|
48
|
-
};
|
|
49
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
50
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
51
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
52
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
53
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
54
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
55
|
-
mod
|
|
56
|
-
));
|
|
57
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
58
|
-
var __async = (__this, __arguments, generator) => {
|
|
59
|
-
return new Promise((resolve, reject) => {
|
|
60
|
-
var fulfilled = (value) => {
|
|
61
|
-
try {
|
|
62
|
-
step(generator.next(value));
|
|
63
|
-
} catch (e) {
|
|
64
|
-
reject(e);
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
var rejected = (value) => {
|
|
68
|
-
try {
|
|
69
|
-
step(generator.throw(value));
|
|
70
|
-
} catch (e) {
|
|
71
|
-
reject(e);
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
75
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
76
|
-
});
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
// src/hooks/use-coagent.ts
|
|
80
|
-
var use_coagent_exports = {};
|
|
81
|
-
__export(use_coagent_exports, {
|
|
82
|
-
useCoAgent: () => useCoAgent
|
|
83
|
-
});
|
|
84
|
-
module.exports = __toCommonJS(use_coagent_exports);
|
|
85
|
-
var import_react8 = require("react");
|
|
86
|
-
|
|
87
|
-
// src/context/copilot-context.tsx
|
|
88
|
-
var import_react = __toESM(require("react"));
|
|
89
|
-
var emptyCopilotContext = {
|
|
90
|
-
actions: {},
|
|
91
|
-
setAction: () => {
|
|
92
|
-
},
|
|
93
|
-
removeAction: () => {
|
|
94
|
-
},
|
|
95
|
-
coAgentStateRenders: {},
|
|
96
|
-
setCoAgentStateRender: () => {
|
|
97
|
-
},
|
|
98
|
-
removeCoAgentStateRender: () => {
|
|
99
|
-
},
|
|
100
|
-
chatComponentsCache: { current: { actions: {}, coAgentStateRenders: {} } },
|
|
101
|
-
getContextString: (documents, categories) => returnAndThrowInDebug(""),
|
|
102
|
-
addContext: () => "",
|
|
103
|
-
removeContext: () => {
|
|
104
|
-
},
|
|
105
|
-
getFunctionCallHandler: () => returnAndThrowInDebug(() => __async(void 0, null, function* () {
|
|
106
|
-
})),
|
|
107
|
-
isLoading: false,
|
|
108
|
-
setIsLoading: () => returnAndThrowInDebug(false),
|
|
109
|
-
chatInstructions: "",
|
|
110
|
-
setChatInstructions: () => returnAndThrowInDebug(""),
|
|
111
|
-
getDocumentsContext: (categories) => returnAndThrowInDebug([]),
|
|
112
|
-
addDocumentContext: () => returnAndThrowInDebug(""),
|
|
113
|
-
removeDocumentContext: () => {
|
|
114
|
-
},
|
|
115
|
-
runtimeClient: {},
|
|
116
|
-
copilotApiConfig: new class {
|
|
117
|
-
get chatApiEndpoint() {
|
|
118
|
-
throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
|
|
119
|
-
}
|
|
120
|
-
get headers() {
|
|
121
|
-
return {};
|
|
122
|
-
}
|
|
123
|
-
get body() {
|
|
124
|
-
return {};
|
|
125
|
-
}
|
|
126
|
-
}(),
|
|
127
|
-
chatSuggestionConfiguration: {},
|
|
128
|
-
addChatSuggestionConfiguration: () => {
|
|
129
|
-
},
|
|
130
|
-
removeChatSuggestionConfiguration: () => {
|
|
131
|
-
},
|
|
132
|
-
showDevConsole: "auto",
|
|
133
|
-
coagentStates: {},
|
|
134
|
-
setCoagentStates: () => {
|
|
135
|
-
},
|
|
136
|
-
agentSession: null,
|
|
137
|
-
setAgentSession: () => {
|
|
138
|
-
}
|
|
139
|
-
};
|
|
140
|
-
var CopilotContext = import_react.default.createContext(emptyCopilotContext);
|
|
141
|
-
function useCopilotContext() {
|
|
142
|
-
const context = import_react.default.useContext(CopilotContext);
|
|
143
|
-
if (context === emptyCopilotContext) {
|
|
144
|
-
throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
|
|
145
|
-
}
|
|
146
|
-
return context;
|
|
147
|
-
}
|
|
148
|
-
function returnAndThrowInDebug(value) {
|
|
149
|
-
throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
|
|
150
|
-
return value;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// src/context/copilot-messages-context.tsx
|
|
154
|
-
var import_react2 = __toESM(require("react"));
|
|
155
|
-
var emptyCopilotContext2 = {
|
|
156
|
-
messages: [],
|
|
157
|
-
setMessages: () => []
|
|
158
|
-
};
|
|
159
|
-
var CopilotMessagesContext = import_react2.default.createContext(emptyCopilotContext2);
|
|
160
|
-
function useCopilotMessagesContext() {
|
|
161
|
-
const context = import_react2.default.useContext(CopilotMessagesContext);
|
|
162
|
-
if (context === emptyCopilotContext2) {
|
|
163
|
-
throw new Error(
|
|
164
|
-
"A messages consuming component was not wrapped with `<CopilotMessages> {...} </CopilotMessages>`"
|
|
165
|
-
);
|
|
166
|
-
}
|
|
167
|
-
return context;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
// src/hooks/use-copilot-chat.ts
|
|
171
|
-
var import_react7 = require("react");
|
|
172
|
-
var import_runtime_client_gql3 = require("@copilotkit/runtime-client-gql");
|
|
173
|
-
|
|
174
|
-
// src/hooks/use-chat.ts
|
|
175
|
-
var import_react5 = require("react");
|
|
176
|
-
var import_shared = require("@copilotkit/shared");
|
|
177
|
-
var import_runtime_client_gql2 = require("@copilotkit/runtime-client-gql");
|
|
178
|
-
|
|
179
|
-
// src/components/toast/toast-provider.tsx
|
|
180
|
-
var import_react3 = require("react");
|
|
181
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
182
|
-
var ToastContext = (0, import_react3.createContext)(void 0);
|
|
183
|
-
function useToast() {
|
|
184
|
-
const context = (0, import_react3.useContext)(ToastContext);
|
|
185
|
-
if (!context) {
|
|
186
|
-
throw new Error("useToast must be used within a ToastProvider");
|
|
187
|
-
}
|
|
188
|
-
return context;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
// src/hooks/use-copilot-runtime-client.ts
|
|
192
|
-
var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
|
|
193
|
-
var import_react4 = require("react");
|
|
194
|
-
var useCopilotRuntimeClient = (options) => {
|
|
195
|
-
const { addGraphQLErrorsToast } = useToast();
|
|
196
|
-
const runtimeClient = (0, import_react4.useMemo)(() => {
|
|
197
|
-
return new import_runtime_client_gql.CopilotRuntimeClient(__spreadProps(__spreadValues({}, options), {
|
|
198
|
-
handleGQLErrors: (error) => {
|
|
199
|
-
if (error.graphQLErrors.length) {
|
|
200
|
-
addGraphQLErrorsToast(error.graphQLErrors);
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
}));
|
|
204
|
-
}, [options, addGraphQLErrorsToast]);
|
|
205
|
-
return runtimeClient;
|
|
206
|
-
};
|
|
207
|
-
|
|
208
|
-
// src/hooks/use-chat.ts
|
|
209
|
-
function useChat(options) {
|
|
210
|
-
const {
|
|
211
|
-
messages,
|
|
212
|
-
setMessages,
|
|
213
|
-
makeSystemMessageCallback,
|
|
214
|
-
copilotConfig,
|
|
215
|
-
setIsLoading,
|
|
216
|
-
initialMessages,
|
|
217
|
-
isLoading,
|
|
218
|
-
actions,
|
|
219
|
-
onFunctionCall,
|
|
220
|
-
onCoAgentStateRender,
|
|
221
|
-
setCoagentStates,
|
|
222
|
-
coagentStates,
|
|
223
|
-
agentSession,
|
|
224
|
-
setAgentSession
|
|
225
|
-
} = options;
|
|
226
|
-
const abortControllerRef = (0, import_react5.useRef)();
|
|
227
|
-
const threadIdRef = (0, import_react5.useRef)(null);
|
|
228
|
-
const runIdRef = (0, import_react5.useRef)(null);
|
|
229
|
-
const { addGraphQLErrorsToast } = useToast();
|
|
230
|
-
const runChatCompletionRef = (0, import_react5.useRef)();
|
|
231
|
-
const coagentStatesRef = (0, import_react5.useRef)(coagentStates);
|
|
232
|
-
coagentStatesRef.current = coagentStates;
|
|
233
|
-
const agentSessionRef = (0, import_react5.useRef)(agentSession);
|
|
234
|
-
agentSessionRef.current = agentSession;
|
|
235
|
-
const publicApiKey = copilotConfig.publicApiKey;
|
|
236
|
-
const headers = __spreadValues(__spreadValues({}, copilotConfig.headers || {}), publicApiKey ? { [import_shared.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey } : {});
|
|
237
|
-
const runtimeClient = useCopilotRuntimeClient({
|
|
238
|
-
url: copilotConfig.chatApiEndpoint,
|
|
239
|
-
publicApiKey: copilotConfig.publicApiKey,
|
|
240
|
-
headers,
|
|
241
|
-
credentials: copilotConfig.credentials
|
|
242
|
-
});
|
|
243
|
-
const runChatCompletion = (previousMessages) => __async(this, null, function* () {
|
|
244
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
245
|
-
setIsLoading(true);
|
|
246
|
-
let newMessages = [
|
|
247
|
-
new import_runtime_client_gql2.TextMessage({
|
|
248
|
-
content: "",
|
|
249
|
-
role: import_runtime_client_gql2.Role.Assistant
|
|
250
|
-
})
|
|
251
|
-
];
|
|
252
|
-
const abortController = new AbortController();
|
|
253
|
-
abortControllerRef.current = abortController;
|
|
254
|
-
setMessages([...previousMessages, ...newMessages]);
|
|
255
|
-
const systemMessage = makeSystemMessageCallback();
|
|
256
|
-
const messagesWithContext = [systemMessage, ...initialMessages || [], ...previousMessages];
|
|
257
|
-
const stream = runtimeClient.asStream(
|
|
258
|
-
runtimeClient.generateCopilotResponse({
|
|
259
|
-
data: __spreadProps(__spreadValues(__spreadProps(__spreadValues({
|
|
260
|
-
frontend: {
|
|
261
|
-
actions: actions.filter(
|
|
262
|
-
(action) => action.available !== import_runtime_client_gql2.ActionInputAvailability.Disabled || !action.disabled
|
|
263
|
-
).map((action) => {
|
|
264
|
-
let available = import_runtime_client_gql2.ActionInputAvailability.Enabled;
|
|
265
|
-
if (action.disabled) {
|
|
266
|
-
available = import_runtime_client_gql2.ActionInputAvailability.Disabled;
|
|
267
|
-
} else if (action.available === "disabled") {
|
|
268
|
-
available = import_runtime_client_gql2.ActionInputAvailability.Disabled;
|
|
269
|
-
} else if (action.available === "remote") {
|
|
270
|
-
available = import_runtime_client_gql2.ActionInputAvailability.Remote;
|
|
271
|
-
}
|
|
272
|
-
return {
|
|
273
|
-
name: action.name,
|
|
274
|
-
description: action.description || "",
|
|
275
|
-
jsonSchema: JSON.stringify((0, import_shared.actionParametersToJsonSchema)(action.parameters || [])),
|
|
276
|
-
available
|
|
277
|
-
};
|
|
278
|
-
}),
|
|
279
|
-
url: window.location.href
|
|
280
|
-
},
|
|
281
|
-
threadId: threadIdRef.current,
|
|
282
|
-
runId: runIdRef.current,
|
|
283
|
-
messages: (0, import_runtime_client_gql2.convertMessagesToGqlInput)((0, import_runtime_client_gql2.filterAgentStateMessages)(messagesWithContext))
|
|
284
|
-
}, copilotConfig.cloud ? {
|
|
285
|
-
cloud: __spreadValues({}, ((_c = (_b = (_a = copilotConfig.cloud.guardrails) == null ? void 0 : _a.input) == null ? void 0 : _b.restrictToTopic) == null ? void 0 : _c.enabled) ? {
|
|
286
|
-
guardrails: {
|
|
287
|
-
inputValidationRules: {
|
|
288
|
-
allowList: copilotConfig.cloud.guardrails.input.restrictToTopic.validTopics,
|
|
289
|
-
denyList: copilotConfig.cloud.guardrails.input.restrictToTopic.invalidTopics
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
} : {})
|
|
293
|
-
} : {}), {
|
|
294
|
-
metadata: {
|
|
295
|
-
requestType: import_runtime_client_gql2.CopilotRequestType.Chat
|
|
296
|
-
}
|
|
297
|
-
}), agentSessionRef.current ? {
|
|
298
|
-
agentSession: agentSessionRef.current
|
|
299
|
-
} : {}), {
|
|
300
|
-
agentStates: Object.values(coagentStatesRef.current).map((state) => ({
|
|
301
|
-
agentName: state.name,
|
|
302
|
-
state: JSON.stringify(state.state)
|
|
303
|
-
}))
|
|
304
|
-
}),
|
|
305
|
-
properties: copilotConfig.properties,
|
|
306
|
-
signal: (_d = abortControllerRef.current) == null ? void 0 : _d.signal
|
|
307
|
-
})
|
|
308
|
-
);
|
|
309
|
-
const guardrailsEnabled = ((_g = (_f = (_e = copilotConfig.cloud) == null ? void 0 : _e.guardrails) == null ? void 0 : _f.input) == null ? void 0 : _g.restrictToTopic.enabled) || false;
|
|
310
|
-
const reader = stream.getReader();
|
|
311
|
-
let actionResults = {};
|
|
312
|
-
let executedCoAgentStateRenders = [];
|
|
313
|
-
let followUp = void 0;
|
|
314
|
-
try {
|
|
315
|
-
while (true) {
|
|
316
|
-
let done, value;
|
|
317
|
-
try {
|
|
318
|
-
const readResult = yield reader.read();
|
|
319
|
-
done = readResult.done;
|
|
320
|
-
value = readResult.value;
|
|
321
|
-
} catch (readError) {
|
|
322
|
-
break;
|
|
323
|
-
}
|
|
324
|
-
if (done) {
|
|
325
|
-
break;
|
|
326
|
-
}
|
|
327
|
-
if (!(value == null ? void 0 : value.generateCopilotResponse)) {
|
|
328
|
-
continue;
|
|
329
|
-
}
|
|
330
|
-
threadIdRef.current = value.generateCopilotResponse.threadId || null;
|
|
331
|
-
runIdRef.current = value.generateCopilotResponse.runId || null;
|
|
332
|
-
const messages2 = (0, import_runtime_client_gql2.convertGqlOutputToMessages)(
|
|
333
|
-
(0, import_runtime_client_gql2.filterAdjacentAgentStateMessages)(value.generateCopilotResponse.messages)
|
|
334
|
-
);
|
|
335
|
-
if (messages2.length === 0) {
|
|
336
|
-
continue;
|
|
337
|
-
}
|
|
338
|
-
newMessages = [];
|
|
339
|
-
if (((_h = value.generateCopilotResponse.status) == null ? void 0 : _h.__typename) === "FailedResponseStatus" && value.generateCopilotResponse.status.reason === "GUARDRAILS_VALIDATION_FAILED") {
|
|
340
|
-
newMessages = [
|
|
341
|
-
new import_runtime_client_gql2.TextMessage({
|
|
342
|
-
role: import_runtime_client_gql2.MessageRole.Assistant,
|
|
343
|
-
content: ((_i = value.generateCopilotResponse.status.details) == null ? void 0 : _i.guardrailsReason) || ""
|
|
344
|
-
})
|
|
345
|
-
];
|
|
346
|
-
} else {
|
|
347
|
-
for (const message of messages2) {
|
|
348
|
-
newMessages.push(message);
|
|
349
|
-
if (message.isActionExecutionMessage() && message.status.code !== import_runtime_client_gql2.MessageStatusCode.Pending && message.scope === "client" && onFunctionCall) {
|
|
350
|
-
if (!(message.id in actionResults)) {
|
|
351
|
-
if (guardrailsEnabled && value.generateCopilotResponse.status === void 0) {
|
|
352
|
-
break;
|
|
353
|
-
}
|
|
354
|
-
try {
|
|
355
|
-
setMessages([...previousMessages, ...newMessages]);
|
|
356
|
-
const action = actions.find((action2) => action2.name === message.name);
|
|
357
|
-
if (action) {
|
|
358
|
-
followUp = action.followUp;
|
|
359
|
-
}
|
|
360
|
-
const result = yield onFunctionCall({
|
|
361
|
-
messages: previousMessages,
|
|
362
|
-
name: message.name,
|
|
363
|
-
args: message.arguments
|
|
364
|
-
});
|
|
365
|
-
actionResults[message.id] = result;
|
|
366
|
-
} catch (e) {
|
|
367
|
-
actionResults[message.id] = `Failed to execute action ${message.name}`;
|
|
368
|
-
console.error(`Failed to execute action ${message.name}: ${e}`);
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
newMessages.push(
|
|
372
|
-
new import_runtime_client_gql2.ResultMessage({
|
|
373
|
-
result: import_runtime_client_gql2.ResultMessage.encodeResult(actionResults[message.id]),
|
|
374
|
-
actionExecutionId: message.id,
|
|
375
|
-
actionName: message.name
|
|
376
|
-
})
|
|
377
|
-
);
|
|
378
|
-
}
|
|
379
|
-
if (message.isAgentStateMessage() && !message.active && !executedCoAgentStateRenders.includes(message.id) && onCoAgentStateRender) {
|
|
380
|
-
if (guardrailsEnabled && value.generateCopilotResponse.status === void 0) {
|
|
381
|
-
break;
|
|
382
|
-
}
|
|
383
|
-
yield onCoAgentStateRender({
|
|
384
|
-
name: message.agentName,
|
|
385
|
-
nodeName: message.nodeName,
|
|
386
|
-
state: message.state
|
|
387
|
-
});
|
|
388
|
-
executedCoAgentStateRenders.push(message.id);
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
const lastAgentStateMessage = [...messages2].reverse().find((message) => message.isAgentStateMessage());
|
|
392
|
-
if (lastAgentStateMessage) {
|
|
393
|
-
setCoagentStates((prevAgentStates) => __spreadProps(__spreadValues({}, prevAgentStates), {
|
|
394
|
-
[lastAgentStateMessage.agentName]: {
|
|
395
|
-
name: lastAgentStateMessage.agentName,
|
|
396
|
-
state: lastAgentStateMessage.state,
|
|
397
|
-
running: lastAgentStateMessage.running,
|
|
398
|
-
active: lastAgentStateMessage.active,
|
|
399
|
-
threadId: lastAgentStateMessage.threadId,
|
|
400
|
-
nodeName: lastAgentStateMessage.nodeName,
|
|
401
|
-
runId: lastAgentStateMessage.runId
|
|
402
|
-
}
|
|
403
|
-
}));
|
|
404
|
-
if (lastAgentStateMessage.running) {
|
|
405
|
-
setAgentSession({
|
|
406
|
-
threadId: lastAgentStateMessage.threadId,
|
|
407
|
-
agentName: lastAgentStateMessage.agentName,
|
|
408
|
-
nodeName: lastAgentStateMessage.nodeName
|
|
409
|
-
});
|
|
410
|
-
} else {
|
|
411
|
-
setAgentSession(null);
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
if (newMessages.length > 0) {
|
|
416
|
-
setMessages([...previousMessages, ...newMessages]);
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
if (
|
|
420
|
-
// if followUp is not explicitly false
|
|
421
|
-
followUp !== false && // if we have client side results
|
|
422
|
-
(Object.values(actionResults).length || // or the last message we received is a result
|
|
423
|
-
newMessages.length && newMessages[newMessages.length - 1].isResultMessage())
|
|
424
|
-
) {
|
|
425
|
-
yield new Promise((resolve) => setTimeout(resolve, 10));
|
|
426
|
-
return yield runChatCompletionRef.current([...previousMessages, ...newMessages]);
|
|
427
|
-
} else {
|
|
428
|
-
return newMessages.slice();
|
|
429
|
-
}
|
|
430
|
-
} finally {
|
|
431
|
-
setIsLoading(false);
|
|
432
|
-
}
|
|
433
|
-
});
|
|
434
|
-
runChatCompletionRef.current = runChatCompletion;
|
|
435
|
-
const runChatCompletionAndHandleFunctionCall = (messages2) => __async(this, null, function* () {
|
|
436
|
-
yield runChatCompletionRef.current(messages2);
|
|
437
|
-
});
|
|
438
|
-
const append = (message) => __async(this, null, function* () {
|
|
439
|
-
if (isLoading) {
|
|
440
|
-
return;
|
|
441
|
-
}
|
|
442
|
-
const newMessages = [...messages, message];
|
|
443
|
-
setMessages(newMessages);
|
|
444
|
-
return runChatCompletionAndHandleFunctionCall(newMessages);
|
|
445
|
-
});
|
|
446
|
-
const reload = () => __async(this, null, function* () {
|
|
447
|
-
if (isLoading || messages.length === 0) {
|
|
448
|
-
return;
|
|
449
|
-
}
|
|
450
|
-
let newMessages = [...messages];
|
|
451
|
-
const lastMessage = messages[messages.length - 1];
|
|
452
|
-
if (lastMessage.isTextMessage() && lastMessage.role === "assistant") {
|
|
453
|
-
newMessages = newMessages.slice(0, -1);
|
|
454
|
-
}
|
|
455
|
-
setMessages(newMessages);
|
|
456
|
-
return runChatCompletionAndHandleFunctionCall(newMessages);
|
|
457
|
-
});
|
|
458
|
-
const stop = () => {
|
|
459
|
-
var _a;
|
|
460
|
-
(_a = abortControllerRef.current) == null ? void 0 : _a.abort();
|
|
461
|
-
};
|
|
462
|
-
return {
|
|
463
|
-
append,
|
|
464
|
-
reload,
|
|
465
|
-
stop
|
|
466
|
-
};
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
// src/components/copilot-provider/copilotkit.tsx
|
|
470
|
-
var import_react6 = require("react");
|
|
471
|
-
var import_react_dom = require("react-dom");
|
|
472
|
-
var import_shared2 = require("@copilotkit/shared");
|
|
473
|
-
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
474
|
-
var defaultCopilotContextCategories = ["global"];
|
|
475
|
-
|
|
476
|
-
// src/hooks/use-copilot-chat.ts
|
|
477
|
-
function useCopilotChat(_a = {}) {
|
|
478
|
-
var _b = _a, {
|
|
479
|
-
makeSystemMessage
|
|
480
|
-
} = _b, options = __objRest(_b, [
|
|
481
|
-
"makeSystemMessage"
|
|
482
|
-
]);
|
|
483
|
-
const {
|
|
484
|
-
getContextString,
|
|
485
|
-
getFunctionCallHandler,
|
|
486
|
-
copilotApiConfig,
|
|
487
|
-
isLoading,
|
|
488
|
-
setIsLoading,
|
|
489
|
-
chatInstructions,
|
|
490
|
-
actions,
|
|
491
|
-
coagentStates,
|
|
492
|
-
setCoagentStates,
|
|
493
|
-
coAgentStateRenders,
|
|
494
|
-
agentSession,
|
|
495
|
-
setAgentSession
|
|
496
|
-
} = useCopilotContext();
|
|
497
|
-
const { messages, setMessages } = useCopilotMessagesContext();
|
|
498
|
-
const latestGetContextString = useUpdatedRef(getContextString);
|
|
499
|
-
const deleteMessage = (0, import_react7.useCallback)(
|
|
500
|
-
(messageId) => {
|
|
501
|
-
setMessages((prev) => prev.filter((message) => message.id !== messageId));
|
|
502
|
-
},
|
|
503
|
-
[setMessages]
|
|
504
|
-
);
|
|
505
|
-
const makeSystemMessageCallback = (0, import_react7.useCallback)(() => {
|
|
506
|
-
const systemMessageMaker = makeSystemMessage || defaultSystemMessage;
|
|
507
|
-
const contextString = latestGetContextString.current([], defaultCopilotContextCategories);
|
|
508
|
-
return new import_runtime_client_gql3.TextMessage({
|
|
509
|
-
content: systemMessageMaker(contextString, chatInstructions),
|
|
510
|
-
role: import_runtime_client_gql3.Role.System
|
|
511
|
-
});
|
|
512
|
-
}, [getContextString, makeSystemMessage, chatInstructions]);
|
|
513
|
-
const onCoAgentStateRender = (0, import_react7.useCallback)(
|
|
514
|
-
(args) => __async(this, null, function* () {
|
|
515
|
-
var _a2;
|
|
516
|
-
const { name, nodeName, state } = args;
|
|
517
|
-
let action = Object.values(coAgentStateRenders).find(
|
|
518
|
-
(action2) => action2.name === name && action2.nodeName === nodeName
|
|
519
|
-
);
|
|
520
|
-
if (!action) {
|
|
521
|
-
action = Object.values(coAgentStateRenders).find(
|
|
522
|
-
(action2) => action2.name === name && !action2.nodeName
|
|
523
|
-
);
|
|
524
|
-
}
|
|
525
|
-
if (action) {
|
|
526
|
-
yield (_a2 = action.handler) == null ? void 0 : _a2.call(action, { state, nodeName });
|
|
527
|
-
}
|
|
528
|
-
}),
|
|
529
|
-
[coAgentStateRenders]
|
|
530
|
-
);
|
|
531
|
-
const { append, reload, stop } = useChat(__spreadProps(__spreadValues({}, options), {
|
|
532
|
-
actions: Object.values(actions),
|
|
533
|
-
copilotConfig: copilotApiConfig,
|
|
534
|
-
initialMessages: options.initialMessages || [],
|
|
535
|
-
onFunctionCall: getFunctionCallHandler(),
|
|
536
|
-
onCoAgentStateRender,
|
|
537
|
-
messages,
|
|
538
|
-
setMessages,
|
|
539
|
-
makeSystemMessageCallback,
|
|
540
|
-
isLoading,
|
|
541
|
-
setIsLoading,
|
|
542
|
-
coagentStates,
|
|
543
|
-
setCoagentStates,
|
|
544
|
-
agentSession,
|
|
545
|
-
setAgentSession
|
|
546
|
-
}));
|
|
547
|
-
const latestAppend = useUpdatedRef(append);
|
|
548
|
-
const latestAppendFunc = (0, import_react7.useCallback)(
|
|
549
|
-
(message) => {
|
|
550
|
-
return latestAppend.current(message);
|
|
551
|
-
},
|
|
552
|
-
[latestAppend]
|
|
553
|
-
);
|
|
554
|
-
const latestReload = useUpdatedRef(reload);
|
|
555
|
-
const latestReloadFunc = (0, import_react7.useCallback)(() => {
|
|
556
|
-
return latestReload.current();
|
|
557
|
-
}, [latestReload]);
|
|
558
|
-
const latestStop = useUpdatedRef(stop);
|
|
559
|
-
const latestStopFunc = (0, import_react7.useCallback)(() => {
|
|
560
|
-
return latestStop.current();
|
|
561
|
-
}, [latestStop]);
|
|
562
|
-
const latestDelete = useUpdatedRef(deleteMessage);
|
|
563
|
-
const latestDeleteFunc = (0, import_react7.useCallback)(
|
|
564
|
-
(messageId) => {
|
|
565
|
-
return latestDelete.current(messageId);
|
|
566
|
-
},
|
|
567
|
-
[latestDelete]
|
|
568
|
-
);
|
|
569
|
-
const latestSetMessages = useUpdatedRef(setMessages);
|
|
570
|
-
const latestSetMessagesFunc = (0, import_react7.useCallback)(
|
|
571
|
-
(messages2) => {
|
|
572
|
-
return latestSetMessages.current(messages2);
|
|
573
|
-
},
|
|
574
|
-
[latestSetMessages]
|
|
575
|
-
);
|
|
576
|
-
return {
|
|
577
|
-
visibleMessages: messages,
|
|
578
|
-
appendMessage: latestAppendFunc,
|
|
579
|
-
setMessages: latestSetMessagesFunc,
|
|
580
|
-
reloadMessages: latestReloadFunc,
|
|
581
|
-
stopGeneration: latestStopFunc,
|
|
582
|
-
deleteMessage: latestDeleteFunc,
|
|
583
|
-
isLoading
|
|
584
|
-
};
|
|
585
|
-
}
|
|
586
|
-
function useUpdatedRef(value) {
|
|
587
|
-
const ref = (0, import_react7.useRef)(value);
|
|
588
|
-
(0, import_react7.useEffect)(() => {
|
|
589
|
-
ref.current = value;
|
|
590
|
-
}, [value]);
|
|
591
|
-
return ref;
|
|
592
|
-
}
|
|
593
|
-
function defaultSystemMessage(contextString, additionalInstructions) {
|
|
594
|
-
return `
|
|
595
|
-
Please act as an efficient, competent, conscientious, and industrious professional assistant.
|
|
596
|
-
|
|
597
|
-
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.
|
|
598
|
-
Always be polite and respectful, and prefer brevity over verbosity.
|
|
599
|
-
|
|
600
|
-
The user has provided you with the following context:
|
|
601
|
-
\`\`\`
|
|
602
|
-
${contextString}
|
|
603
|
-
\`\`\`
|
|
604
|
-
|
|
605
|
-
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.
|
|
606
|
-
|
|
607
|
-
Please assist them as best you can.
|
|
608
|
-
|
|
609
|
-
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.
|
|
610
|
-
|
|
611
|
-
If you would like to call a function, call it without saying anything else.
|
|
612
|
-
` + (additionalInstructions ? `
|
|
613
|
-
|
|
614
|
-
${additionalInstructions}` : "");
|
|
615
|
-
}
|
|
616
|
-
|
|
617
|
-
// src/hooks/use-coagent.ts
|
|
618
|
-
function useCoAgent(options) {
|
|
619
|
-
const isExternalStateManagement = (options2) => {
|
|
620
|
-
return "state" in options2 && "setState" in options2;
|
|
621
|
-
};
|
|
622
|
-
const { name } = options;
|
|
623
|
-
const isInternalStateManagementWithInitial = (options2) => {
|
|
624
|
-
return "initialState" in options2;
|
|
625
|
-
};
|
|
626
|
-
const generalContext = useCopilotContext();
|
|
627
|
-
const messagesContext = useCopilotMessagesContext();
|
|
628
|
-
const context = __spreadValues(__spreadValues({}, generalContext), messagesContext);
|
|
629
|
-
const { coagentStates, setCoagentStates } = context;
|
|
630
|
-
const { appendMessage } = useCopilotChat();
|
|
631
|
-
const getCoagentState = (coagentStates2, name2) => {
|
|
632
|
-
if (coagentStates2[name2]) {
|
|
633
|
-
return coagentStates2[name2];
|
|
634
|
-
} else {
|
|
635
|
-
return {
|
|
636
|
-
name: name2,
|
|
637
|
-
state: isInternalStateManagementWithInitial(options) ? options.initialState : {},
|
|
638
|
-
running: false,
|
|
639
|
-
active: false,
|
|
640
|
-
threadId: void 0,
|
|
641
|
-
nodeName: void 0,
|
|
642
|
-
runId: void 0
|
|
643
|
-
};
|
|
644
|
-
}
|
|
645
|
-
};
|
|
646
|
-
const setState = (newState) => {
|
|
647
|
-
setCoagentStates((prevAgentStates) => {
|
|
648
|
-
let coagentState2 = getCoagentState(prevAgentStates, name);
|
|
649
|
-
const updatedState = typeof newState === "function" ? newState(coagentState2.state) : newState;
|
|
650
|
-
return __spreadProps(__spreadValues({}, prevAgentStates), {
|
|
651
|
-
[name]: __spreadProps(__spreadValues({}, coagentState2), {
|
|
652
|
-
state: updatedState
|
|
653
|
-
})
|
|
654
|
-
});
|
|
655
|
-
});
|
|
656
|
-
};
|
|
657
|
-
const coagentState = getCoagentState(coagentStates, name);
|
|
658
|
-
const state = isExternalStateManagement(options) ? options.state : coagentState.state;
|
|
659
|
-
(0, import_react8.useEffect)(() => {
|
|
660
|
-
if (isExternalStateManagement(options)) {
|
|
661
|
-
setState(options.state);
|
|
662
|
-
} else if (coagentStates[name] === void 0) {
|
|
663
|
-
setState(options.initialState === void 0 ? {} : options.initialState);
|
|
664
|
-
}
|
|
665
|
-
}, [isExternalStateManagement(options) ? JSON.stringify(options.state) : void 0]);
|
|
666
|
-
return {
|
|
667
|
-
name,
|
|
668
|
-
nodeName: coagentState.nodeName,
|
|
669
|
-
state,
|
|
670
|
-
setState,
|
|
671
|
-
running: coagentState.running,
|
|
672
|
-
start: () => {
|
|
673
|
-
startAgent(name, context);
|
|
674
|
-
},
|
|
675
|
-
stop: () => {
|
|
676
|
-
stopAgent(name, context);
|
|
677
|
-
},
|
|
678
|
-
run: (hint) => {
|
|
679
|
-
return runAgent(name, context, appendMessage, hint);
|
|
680
|
-
}
|
|
681
|
-
};
|
|
682
|
-
}
|
|
683
|
-
function startAgent(name, context) {
|
|
684
|
-
const { setAgentSession } = context;
|
|
685
|
-
setAgentSession({
|
|
686
|
-
agentName: name
|
|
687
|
-
});
|
|
688
|
-
}
|
|
689
|
-
function stopAgent(name, context) {
|
|
690
|
-
const { agentSession, setAgentSession } = context;
|
|
691
|
-
if (agentSession && agentSession.agentName === name) {
|
|
692
|
-
setAgentSession(null);
|
|
693
|
-
} else {
|
|
694
|
-
console.warn(`No agent session found for ${name}`);
|
|
695
|
-
}
|
|
696
|
-
}
|
|
697
|
-
function runAgent(name, context, appendMessage, hint) {
|
|
698
|
-
return __async(this, null, function* () {
|
|
699
|
-
var _a, _b;
|
|
700
|
-
const { agentSession, setAgentSession } = context;
|
|
701
|
-
if (!agentSession || agentSession.agentName !== name) {
|
|
702
|
-
setAgentSession({
|
|
703
|
-
agentName: name
|
|
704
|
-
});
|
|
705
|
-
}
|
|
706
|
-
let previousState = null;
|
|
707
|
-
for (let i = context.messages.length - 1; i >= 0; i--) {
|
|
708
|
-
const message = context.messages[i];
|
|
709
|
-
if (message.isAgentStateMessage() && message.agentName === name) {
|
|
710
|
-
previousState = message.state;
|
|
711
|
-
}
|
|
712
|
-
}
|
|
713
|
-
let state = ((_b = (_a = context.coagentStates) == null ? void 0 : _a[name]) == null ? void 0 : _b.state) || {};
|
|
714
|
-
if (hint) {
|
|
715
|
-
const hintMessage = hint({ previousState, currentState: state });
|
|
716
|
-
if (hintMessage) {
|
|
717
|
-
yield appendMessage(hintMessage);
|
|
718
|
-
}
|
|
719
|
-
}
|
|
720
|
-
});
|
|
721
|
-
}
|
|
722
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
723
|
-
0 && (module.exports = {
|
|
724
|
-
useCoAgent
|
|
725
|
-
});
|
|
726
|
-
//# sourceMappingURL=use-coagent.js.map
|