@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
package/dist/hooks/use-chat.js
DELETED
|
@@ -1,360 +0,0 @@
|
|
|
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
|
-
var __async = (__this, __arguments, generator) => {
|
|
37
|
-
return new Promise((resolve, reject) => {
|
|
38
|
-
var fulfilled = (value) => {
|
|
39
|
-
try {
|
|
40
|
-
step(generator.next(value));
|
|
41
|
-
} catch (e) {
|
|
42
|
-
reject(e);
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
var rejected = (value) => {
|
|
46
|
-
try {
|
|
47
|
-
step(generator.throw(value));
|
|
48
|
-
} catch (e) {
|
|
49
|
-
reject(e);
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
53
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
54
|
-
});
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
// src/hooks/use-chat.ts
|
|
58
|
-
var use_chat_exports = {};
|
|
59
|
-
__export(use_chat_exports, {
|
|
60
|
-
useChat: () => useChat
|
|
61
|
-
});
|
|
62
|
-
module.exports = __toCommonJS(use_chat_exports);
|
|
63
|
-
var import_react3 = require("react");
|
|
64
|
-
var import_shared = require("@copilotkit/shared");
|
|
65
|
-
var import_runtime_client_gql2 = require("@copilotkit/runtime-client-gql");
|
|
66
|
-
|
|
67
|
-
// src/components/toast/toast-provider.tsx
|
|
68
|
-
var import_react = require("react");
|
|
69
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
70
|
-
var ToastContext = (0, import_react.createContext)(void 0);
|
|
71
|
-
function useToast() {
|
|
72
|
-
const context = (0, import_react.useContext)(ToastContext);
|
|
73
|
-
if (!context) {
|
|
74
|
-
throw new Error("useToast must be used within a ToastProvider");
|
|
75
|
-
}
|
|
76
|
-
return context;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// src/hooks/use-copilot-runtime-client.ts
|
|
80
|
-
var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
|
|
81
|
-
var import_react2 = require("react");
|
|
82
|
-
var useCopilotRuntimeClient = (options) => {
|
|
83
|
-
const { addGraphQLErrorsToast } = useToast();
|
|
84
|
-
const runtimeClient = (0, import_react2.useMemo)(() => {
|
|
85
|
-
return new import_runtime_client_gql.CopilotRuntimeClient(__spreadProps(__spreadValues({}, options), {
|
|
86
|
-
handleGQLErrors: (error) => {
|
|
87
|
-
if (error.graphQLErrors.length) {
|
|
88
|
-
addGraphQLErrorsToast(error.graphQLErrors);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}));
|
|
92
|
-
}, [options, addGraphQLErrorsToast]);
|
|
93
|
-
return runtimeClient;
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
// src/hooks/use-chat.ts
|
|
97
|
-
function useChat(options) {
|
|
98
|
-
const {
|
|
99
|
-
messages,
|
|
100
|
-
setMessages,
|
|
101
|
-
makeSystemMessageCallback,
|
|
102
|
-
copilotConfig,
|
|
103
|
-
setIsLoading,
|
|
104
|
-
initialMessages,
|
|
105
|
-
isLoading,
|
|
106
|
-
actions,
|
|
107
|
-
onFunctionCall,
|
|
108
|
-
onCoAgentStateRender,
|
|
109
|
-
setCoagentStates,
|
|
110
|
-
coagentStates,
|
|
111
|
-
agentSession,
|
|
112
|
-
setAgentSession
|
|
113
|
-
} = options;
|
|
114
|
-
const abortControllerRef = (0, import_react3.useRef)();
|
|
115
|
-
const threadIdRef = (0, import_react3.useRef)(null);
|
|
116
|
-
const runIdRef = (0, import_react3.useRef)(null);
|
|
117
|
-
const { addGraphQLErrorsToast } = useToast();
|
|
118
|
-
const runChatCompletionRef = (0, import_react3.useRef)();
|
|
119
|
-
const coagentStatesRef = (0, import_react3.useRef)(coagentStates);
|
|
120
|
-
coagentStatesRef.current = coagentStates;
|
|
121
|
-
const agentSessionRef = (0, import_react3.useRef)(agentSession);
|
|
122
|
-
agentSessionRef.current = agentSession;
|
|
123
|
-
const publicApiKey = copilotConfig.publicApiKey;
|
|
124
|
-
const headers = __spreadValues(__spreadValues({}, copilotConfig.headers || {}), publicApiKey ? { [import_shared.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey } : {});
|
|
125
|
-
const runtimeClient = useCopilotRuntimeClient({
|
|
126
|
-
url: copilotConfig.chatApiEndpoint,
|
|
127
|
-
publicApiKey: copilotConfig.publicApiKey,
|
|
128
|
-
headers,
|
|
129
|
-
credentials: copilotConfig.credentials
|
|
130
|
-
});
|
|
131
|
-
const runChatCompletion = (previousMessages) => __async(this, null, function* () {
|
|
132
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
133
|
-
setIsLoading(true);
|
|
134
|
-
let newMessages = [
|
|
135
|
-
new import_runtime_client_gql2.TextMessage({
|
|
136
|
-
content: "",
|
|
137
|
-
role: import_runtime_client_gql2.Role.Assistant
|
|
138
|
-
})
|
|
139
|
-
];
|
|
140
|
-
const abortController = new AbortController();
|
|
141
|
-
abortControllerRef.current = abortController;
|
|
142
|
-
setMessages([...previousMessages, ...newMessages]);
|
|
143
|
-
const systemMessage = makeSystemMessageCallback();
|
|
144
|
-
const messagesWithContext = [systemMessage, ...initialMessages || [], ...previousMessages];
|
|
145
|
-
const stream = runtimeClient.asStream(
|
|
146
|
-
runtimeClient.generateCopilotResponse({
|
|
147
|
-
data: __spreadProps(__spreadValues(__spreadProps(__spreadValues({
|
|
148
|
-
frontend: {
|
|
149
|
-
actions: actions.filter(
|
|
150
|
-
(action) => action.available !== import_runtime_client_gql2.ActionInputAvailability.Disabled || !action.disabled
|
|
151
|
-
).map((action) => {
|
|
152
|
-
let available = import_runtime_client_gql2.ActionInputAvailability.Enabled;
|
|
153
|
-
if (action.disabled) {
|
|
154
|
-
available = import_runtime_client_gql2.ActionInputAvailability.Disabled;
|
|
155
|
-
} else if (action.available === "disabled") {
|
|
156
|
-
available = import_runtime_client_gql2.ActionInputAvailability.Disabled;
|
|
157
|
-
} else if (action.available === "remote") {
|
|
158
|
-
available = import_runtime_client_gql2.ActionInputAvailability.Remote;
|
|
159
|
-
}
|
|
160
|
-
return {
|
|
161
|
-
name: action.name,
|
|
162
|
-
description: action.description || "",
|
|
163
|
-
jsonSchema: JSON.stringify((0, import_shared.actionParametersToJsonSchema)(action.parameters || [])),
|
|
164
|
-
available
|
|
165
|
-
};
|
|
166
|
-
}),
|
|
167
|
-
url: window.location.href
|
|
168
|
-
},
|
|
169
|
-
threadId: threadIdRef.current,
|
|
170
|
-
runId: runIdRef.current,
|
|
171
|
-
messages: (0, import_runtime_client_gql2.convertMessagesToGqlInput)((0, import_runtime_client_gql2.filterAgentStateMessages)(messagesWithContext))
|
|
172
|
-
}, copilotConfig.cloud ? {
|
|
173
|
-
cloud: __spreadValues({}, ((_c = (_b = (_a = copilotConfig.cloud.guardrails) == null ? void 0 : _a.input) == null ? void 0 : _b.restrictToTopic) == null ? void 0 : _c.enabled) ? {
|
|
174
|
-
guardrails: {
|
|
175
|
-
inputValidationRules: {
|
|
176
|
-
allowList: copilotConfig.cloud.guardrails.input.restrictToTopic.validTopics,
|
|
177
|
-
denyList: copilotConfig.cloud.guardrails.input.restrictToTopic.invalidTopics
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
} : {})
|
|
181
|
-
} : {}), {
|
|
182
|
-
metadata: {
|
|
183
|
-
requestType: import_runtime_client_gql2.CopilotRequestType.Chat
|
|
184
|
-
}
|
|
185
|
-
}), agentSessionRef.current ? {
|
|
186
|
-
agentSession: agentSessionRef.current
|
|
187
|
-
} : {}), {
|
|
188
|
-
agentStates: Object.values(coagentStatesRef.current).map((state) => ({
|
|
189
|
-
agentName: state.name,
|
|
190
|
-
state: JSON.stringify(state.state)
|
|
191
|
-
}))
|
|
192
|
-
}),
|
|
193
|
-
properties: copilotConfig.properties,
|
|
194
|
-
signal: (_d = abortControllerRef.current) == null ? void 0 : _d.signal
|
|
195
|
-
})
|
|
196
|
-
);
|
|
197
|
-
const guardrailsEnabled = ((_g = (_f = (_e = copilotConfig.cloud) == null ? void 0 : _e.guardrails) == null ? void 0 : _f.input) == null ? void 0 : _g.restrictToTopic.enabled) || false;
|
|
198
|
-
const reader = stream.getReader();
|
|
199
|
-
let actionResults = {};
|
|
200
|
-
let executedCoAgentStateRenders = [];
|
|
201
|
-
let followUp = void 0;
|
|
202
|
-
try {
|
|
203
|
-
while (true) {
|
|
204
|
-
let done, value;
|
|
205
|
-
try {
|
|
206
|
-
const readResult = yield reader.read();
|
|
207
|
-
done = readResult.done;
|
|
208
|
-
value = readResult.value;
|
|
209
|
-
} catch (readError) {
|
|
210
|
-
break;
|
|
211
|
-
}
|
|
212
|
-
if (done) {
|
|
213
|
-
break;
|
|
214
|
-
}
|
|
215
|
-
if (!(value == null ? void 0 : value.generateCopilotResponse)) {
|
|
216
|
-
continue;
|
|
217
|
-
}
|
|
218
|
-
threadIdRef.current = value.generateCopilotResponse.threadId || null;
|
|
219
|
-
runIdRef.current = value.generateCopilotResponse.runId || null;
|
|
220
|
-
const messages2 = (0, import_runtime_client_gql2.convertGqlOutputToMessages)(
|
|
221
|
-
(0, import_runtime_client_gql2.filterAdjacentAgentStateMessages)(value.generateCopilotResponse.messages)
|
|
222
|
-
);
|
|
223
|
-
if (messages2.length === 0) {
|
|
224
|
-
continue;
|
|
225
|
-
}
|
|
226
|
-
newMessages = [];
|
|
227
|
-
if (((_h = value.generateCopilotResponse.status) == null ? void 0 : _h.__typename) === "FailedResponseStatus" && value.generateCopilotResponse.status.reason === "GUARDRAILS_VALIDATION_FAILED") {
|
|
228
|
-
newMessages = [
|
|
229
|
-
new import_runtime_client_gql2.TextMessage({
|
|
230
|
-
role: import_runtime_client_gql2.MessageRole.Assistant,
|
|
231
|
-
content: ((_i = value.generateCopilotResponse.status.details) == null ? void 0 : _i.guardrailsReason) || ""
|
|
232
|
-
})
|
|
233
|
-
];
|
|
234
|
-
} else {
|
|
235
|
-
for (const message of messages2) {
|
|
236
|
-
newMessages.push(message);
|
|
237
|
-
if (message.isActionExecutionMessage() && message.status.code !== import_runtime_client_gql2.MessageStatusCode.Pending && message.scope === "client" && onFunctionCall) {
|
|
238
|
-
if (!(message.id in actionResults)) {
|
|
239
|
-
if (guardrailsEnabled && value.generateCopilotResponse.status === void 0) {
|
|
240
|
-
break;
|
|
241
|
-
}
|
|
242
|
-
try {
|
|
243
|
-
setMessages([...previousMessages, ...newMessages]);
|
|
244
|
-
const action = actions.find((action2) => action2.name === message.name);
|
|
245
|
-
if (action) {
|
|
246
|
-
followUp = action.followUp;
|
|
247
|
-
}
|
|
248
|
-
const result = yield onFunctionCall({
|
|
249
|
-
messages: previousMessages,
|
|
250
|
-
name: message.name,
|
|
251
|
-
args: message.arguments
|
|
252
|
-
});
|
|
253
|
-
actionResults[message.id] = result;
|
|
254
|
-
} catch (e) {
|
|
255
|
-
actionResults[message.id] = `Failed to execute action ${message.name}`;
|
|
256
|
-
console.error(`Failed to execute action ${message.name}: ${e}`);
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
newMessages.push(
|
|
260
|
-
new import_runtime_client_gql2.ResultMessage({
|
|
261
|
-
result: import_runtime_client_gql2.ResultMessage.encodeResult(actionResults[message.id]),
|
|
262
|
-
actionExecutionId: message.id,
|
|
263
|
-
actionName: message.name
|
|
264
|
-
})
|
|
265
|
-
);
|
|
266
|
-
}
|
|
267
|
-
if (message.isAgentStateMessage() && !message.active && !executedCoAgentStateRenders.includes(message.id) && onCoAgentStateRender) {
|
|
268
|
-
if (guardrailsEnabled && value.generateCopilotResponse.status === void 0) {
|
|
269
|
-
break;
|
|
270
|
-
}
|
|
271
|
-
yield onCoAgentStateRender({
|
|
272
|
-
name: message.agentName,
|
|
273
|
-
nodeName: message.nodeName,
|
|
274
|
-
state: message.state
|
|
275
|
-
});
|
|
276
|
-
executedCoAgentStateRenders.push(message.id);
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
const lastAgentStateMessage = [...messages2].reverse().find((message) => message.isAgentStateMessage());
|
|
280
|
-
if (lastAgentStateMessage) {
|
|
281
|
-
setCoagentStates((prevAgentStates) => __spreadProps(__spreadValues({}, prevAgentStates), {
|
|
282
|
-
[lastAgentStateMessage.agentName]: {
|
|
283
|
-
name: lastAgentStateMessage.agentName,
|
|
284
|
-
state: lastAgentStateMessage.state,
|
|
285
|
-
running: lastAgentStateMessage.running,
|
|
286
|
-
active: lastAgentStateMessage.active,
|
|
287
|
-
threadId: lastAgentStateMessage.threadId,
|
|
288
|
-
nodeName: lastAgentStateMessage.nodeName,
|
|
289
|
-
runId: lastAgentStateMessage.runId
|
|
290
|
-
}
|
|
291
|
-
}));
|
|
292
|
-
if (lastAgentStateMessage.running) {
|
|
293
|
-
setAgentSession({
|
|
294
|
-
threadId: lastAgentStateMessage.threadId,
|
|
295
|
-
agentName: lastAgentStateMessage.agentName,
|
|
296
|
-
nodeName: lastAgentStateMessage.nodeName
|
|
297
|
-
});
|
|
298
|
-
} else {
|
|
299
|
-
setAgentSession(null);
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
if (newMessages.length > 0) {
|
|
304
|
-
setMessages([...previousMessages, ...newMessages]);
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
if (
|
|
308
|
-
// if followUp is not explicitly false
|
|
309
|
-
followUp !== false && // if we have client side results
|
|
310
|
-
(Object.values(actionResults).length || // or the last message we received is a result
|
|
311
|
-
newMessages.length && newMessages[newMessages.length - 1].isResultMessage())
|
|
312
|
-
) {
|
|
313
|
-
yield new Promise((resolve) => setTimeout(resolve, 10));
|
|
314
|
-
return yield runChatCompletionRef.current([...previousMessages, ...newMessages]);
|
|
315
|
-
} else {
|
|
316
|
-
return newMessages.slice();
|
|
317
|
-
}
|
|
318
|
-
} finally {
|
|
319
|
-
setIsLoading(false);
|
|
320
|
-
}
|
|
321
|
-
});
|
|
322
|
-
runChatCompletionRef.current = runChatCompletion;
|
|
323
|
-
const runChatCompletionAndHandleFunctionCall = (messages2) => __async(this, null, function* () {
|
|
324
|
-
yield runChatCompletionRef.current(messages2);
|
|
325
|
-
});
|
|
326
|
-
const append = (message) => __async(this, null, function* () {
|
|
327
|
-
if (isLoading) {
|
|
328
|
-
return;
|
|
329
|
-
}
|
|
330
|
-
const newMessages = [...messages, message];
|
|
331
|
-
setMessages(newMessages);
|
|
332
|
-
return runChatCompletionAndHandleFunctionCall(newMessages);
|
|
333
|
-
});
|
|
334
|
-
const reload = () => __async(this, null, function* () {
|
|
335
|
-
if (isLoading || messages.length === 0) {
|
|
336
|
-
return;
|
|
337
|
-
}
|
|
338
|
-
let newMessages = [...messages];
|
|
339
|
-
const lastMessage = messages[messages.length - 1];
|
|
340
|
-
if (lastMessage.isTextMessage() && lastMessage.role === "assistant") {
|
|
341
|
-
newMessages = newMessages.slice(0, -1);
|
|
342
|
-
}
|
|
343
|
-
setMessages(newMessages);
|
|
344
|
-
return runChatCompletionAndHandleFunctionCall(newMessages);
|
|
345
|
-
});
|
|
346
|
-
const stop = () => {
|
|
347
|
-
var _a;
|
|
348
|
-
(_a = abortControllerRef.current) == null ? void 0 : _a.abort();
|
|
349
|
-
};
|
|
350
|
-
return {
|
|
351
|
-
append,
|
|
352
|
-
reload,
|
|
353
|
-
stop
|
|
354
|
-
};
|
|
355
|
-
}
|
|
356
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
357
|
-
0 && (module.exports = {
|
|
358
|
-
useChat
|
|
359
|
-
});
|
|
360
|
-
//# sourceMappingURL=use-chat.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/hooks/use-chat.ts","../../src/components/toast/toast-provider.tsx","../../src/hooks/use-copilot-runtime-client.ts"],"sourcesContent":["import { useRef } from \"react\";\nimport {\n FunctionCallHandler,\n COPILOT_CLOUD_PUBLIC_API_KEY_HEADER,\n actionParametersToJsonSchema,\n CoAgentStateRenderHandler,\n} from \"@copilotkit/shared\";\nimport {\n Message,\n TextMessage,\n ResultMessage,\n convertMessagesToGqlInput,\n filterAdjacentAgentStateMessages,\n filterAgentStateMessages,\n convertGqlOutputToMessages,\n MessageStatusCode,\n MessageRole,\n Role,\n CopilotRequestType,\n ActionInputAvailability,\n} from \"@copilotkit/runtime-client-gql\";\n\nimport { CopilotApiConfig } from \"../context\";\nimport { FrontendAction } from \"../types/frontend-action\";\nimport { CoagentState } from \"../types/coagent-state\";\nimport { AgentSession } from \"../context/copilot-context\";\nimport { useToast } from \"../components/toast/toast-provider\";\nimport { useCopilotRuntimeClient } from \"./use-copilot-runtime-client\";\n\nexport type UseChatOptions = {\n /**\n * System messages of the chat. Defaults to an empty array.\n */\n initialMessages?: Message[];\n /**\n * Callback function to be called when a function call is received.\n * If the function returns a `ChatRequest` object, the request will be sent\n * automatically to the API and will be used to update the chat.\n */\n onFunctionCall?: FunctionCallHandler;\n\n /**\n * Callback function to be called when a coagent action is received.\n */\n onCoAgentStateRender?: CoAgentStateRenderHandler;\n\n /**\n * Function definitions to be sent to the API.\n */\n actions: FrontendAction<any>[];\n\n /**\n * The CopilotKit API configuration.\n */\n copilotConfig: CopilotApiConfig;\n\n /**\n * The current list of messages in the chat.\n */\n messages: Message[];\n /**\n * The setState-powered method to update the chat messages.\n */\n setMessages: React.Dispatch<React.SetStateAction<Message[]>>;\n\n /**\n * A callback to get the latest system message.\n */\n makeSystemMessageCallback: () => TextMessage;\n\n /**\n * Whether the API request is in progress\n */\n isLoading: boolean;\n\n /**\n * setState-powered method to update the isChatLoading value\n */\n setIsLoading: React.Dispatch<React.SetStateAction<boolean>>;\n\n /**\n * The current list of coagent states.\n */\n coagentStates: Record<string, CoagentState>;\n\n /**\n * setState-powered method to update the agent states\n */\n setCoagentStates: React.Dispatch<React.SetStateAction<Record<string, CoagentState>>>;\n\n /**\n * The current agent session.\n */\n agentSession: AgentSession | null;\n\n /**\n * setState-powered method to update the agent session\n */\n setAgentSession: React.Dispatch<React.SetStateAction<AgentSession | null>>;\n};\n\nexport type UseChatHelpers = {\n /**\n * Append a user message to the chat list. This triggers the API call to fetch\n * the assistant's response.\n * @param message The message to append\n */\n append: (message: Message) => Promise<void>;\n /**\n * Reload the last AI chat response for the given chat history. If the last\n * message isn't from the assistant, it will request the API to generate a\n * new response.\n */\n reload: () => Promise<void>;\n /**\n * Abort the current request immediately, keep the generated tokens if any.\n */\n stop: () => void;\n};\n\nexport function useChat(options: UseChatOptions): UseChatHelpers {\n const {\n messages,\n setMessages,\n makeSystemMessageCallback,\n copilotConfig,\n setIsLoading,\n initialMessages,\n isLoading,\n actions,\n onFunctionCall,\n onCoAgentStateRender,\n setCoagentStates,\n coagentStates,\n agentSession,\n setAgentSession,\n } = options;\n\n const abortControllerRef = useRef<AbortController>();\n const threadIdRef = useRef<string | null>(null);\n const runIdRef = useRef<string | null>(null);\n const { addGraphQLErrorsToast } = useToast();\n\n const runChatCompletionRef = useRef<(previousMessages: Message[]) => Promise<Message[]>>();\n // We need to keep a ref of coagent states because of renderAndWait - making sure\n // the latest state is sent to the API\n // This is a workaround and needs to be addressed in the future\n const coagentStatesRef = useRef<Record<string, CoagentState>>(coagentStates);\n coagentStatesRef.current = coagentStates;\n const agentSessionRef = useRef<AgentSession | null>(agentSession);\n agentSessionRef.current = agentSession;\n\n const publicApiKey = copilotConfig.publicApiKey;\n\n const headers = {\n ...(copilotConfig.headers || {}),\n ...(publicApiKey ? { [COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey } : {}),\n };\n\n const runtimeClient = useCopilotRuntimeClient({\n url: copilotConfig.chatApiEndpoint,\n publicApiKey: copilotConfig.publicApiKey,\n headers,\n credentials: copilotConfig.credentials,\n });\n\n const runChatCompletion = async (previousMessages: Message[]): Promise<Message[]> => {\n setIsLoading(true);\n\n // this message is just a placeholder. It will disappear once the first real message\n // is received\n let newMessages: Message[] = [\n new TextMessage({\n content: \"\",\n role: Role.Assistant,\n }),\n ];\n const abortController = new AbortController();\n abortControllerRef.current = abortController;\n\n setMessages([...previousMessages, ...newMessages]);\n\n const systemMessage = makeSystemMessageCallback();\n\n const messagesWithContext = [systemMessage, ...(initialMessages || []), ...previousMessages];\n\n const stream = runtimeClient.asStream(\n runtimeClient.generateCopilotResponse({\n data: {\n frontend: {\n actions: actions\n .filter(\n (action) =>\n action.available !== ActionInputAvailability.Disabled || !action.disabled,\n )\n .map((action) => {\n let available: ActionInputAvailability | undefined =\n ActionInputAvailability.Enabled;\n if (action.disabled) {\n available = ActionInputAvailability.Disabled;\n } else if (action.available === \"disabled\") {\n available = ActionInputAvailability.Disabled;\n } else if (action.available === \"remote\") {\n available = ActionInputAvailability.Remote;\n }\n return {\n name: action.name,\n description: action.description || \"\",\n jsonSchema: JSON.stringify(actionParametersToJsonSchema(action.parameters || [])),\n available,\n };\n }),\n url: window.location.href,\n },\n threadId: threadIdRef.current,\n runId: runIdRef.current,\n messages: convertMessagesToGqlInput(filterAgentStateMessages(messagesWithContext)),\n ...(copilotConfig.cloud\n ? {\n cloud: {\n ...(copilotConfig.cloud.guardrails?.input?.restrictToTopic?.enabled\n ? {\n guardrails: {\n inputValidationRules: {\n allowList:\n copilotConfig.cloud.guardrails.input.restrictToTopic.validTopics,\n denyList:\n copilotConfig.cloud.guardrails.input.restrictToTopic.invalidTopics,\n },\n },\n }\n : {}),\n },\n }\n : {}),\n metadata: {\n requestType: CopilotRequestType.Chat,\n },\n ...(agentSessionRef.current\n ? {\n agentSession: agentSessionRef.current,\n }\n : {}),\n agentStates: Object.values(coagentStatesRef.current).map((state) => ({\n agentName: state.name,\n state: JSON.stringify(state.state),\n })),\n },\n properties: copilotConfig.properties,\n signal: abortControllerRef.current?.signal,\n }),\n );\n\n const guardrailsEnabled =\n copilotConfig.cloud?.guardrails?.input?.restrictToTopic.enabled || false;\n\n const reader = stream.getReader();\n\n let actionResults: { [id: string]: string } = {};\n let executedCoAgentStateRenders: string[] = [];\n let followUp: FrontendAction[\"followUp\"] = undefined;\n\n try {\n while (true) {\n let done, value;\n\n try {\n const readResult = await reader.read();\n done = readResult.done;\n value = readResult.value;\n } catch (readError) {\n break;\n }\n\n if (done) {\n break;\n }\n\n if (!value?.generateCopilotResponse) {\n continue;\n }\n\n threadIdRef.current = value.generateCopilotResponse.threadId || null;\n runIdRef.current = value.generateCopilotResponse.runId || null;\n\n const messages = convertGqlOutputToMessages(\n filterAdjacentAgentStateMessages(value.generateCopilotResponse.messages),\n );\n\n if (messages.length === 0) {\n continue;\n }\n\n newMessages = [];\n\n // request failed, display error message\n if (\n value.generateCopilotResponse.status?.__typename === \"FailedResponseStatus\" &&\n value.generateCopilotResponse.status.reason === \"GUARDRAILS_VALIDATION_FAILED\"\n ) {\n newMessages = [\n new TextMessage({\n role: MessageRole.Assistant,\n content: value.generateCopilotResponse.status.details?.guardrailsReason || \"\",\n }),\n ];\n }\n\n // add messages to the chat\n else {\n for (const message of messages) {\n newMessages.push(message);\n // execute regular action executions\n if (\n message.isActionExecutionMessage() &&\n message.status.code !== MessageStatusCode.Pending &&\n message.scope === \"client\" &&\n onFunctionCall\n ) {\n if (!(message.id in actionResults)) {\n // Do not execute a function call if guardrails are enabled but the status is not known\n if (guardrailsEnabled && value.generateCopilotResponse.status === undefined) {\n break;\n }\n // execute action\n try {\n // We update the message state before calling the handler so that the render\n // function can be called with `executing` state\n setMessages([...previousMessages, ...newMessages]);\n\n const action = actions.find((action) => action.name === message.name);\n\n if (action) {\n followUp = action.followUp;\n }\n\n const result = await onFunctionCall({\n messages: previousMessages,\n name: message.name,\n args: message.arguments,\n });\n actionResults[message.id] = result;\n } catch (e) {\n actionResults[message.id] = `Failed to execute action ${message.name}`;\n console.error(`Failed to execute action ${message.name}: ${e}`);\n }\n }\n // add the result message\n newMessages.push(\n new ResultMessage({\n result: ResultMessage.encodeResult(actionResults[message.id]),\n actionExecutionId: message.id,\n actionName: message.name,\n }),\n );\n }\n // execute coagent actions\n if (\n message.isAgentStateMessage() &&\n !message.active &&\n !executedCoAgentStateRenders.includes(message.id) &&\n onCoAgentStateRender\n ) {\n // Do not execute a coagent action if guardrails are enabled but the status is not known\n if (guardrailsEnabled && value.generateCopilotResponse.status === undefined) {\n break;\n }\n // execute coagent action\n await onCoAgentStateRender({\n name: message.agentName,\n nodeName: message.nodeName,\n state: message.state,\n });\n executedCoAgentStateRenders.push(message.id);\n }\n }\n\n const lastAgentStateMessage = [...messages]\n .reverse()\n .find((message) => message.isAgentStateMessage());\n\n if (lastAgentStateMessage) {\n setCoagentStates((prevAgentStates) => ({\n ...prevAgentStates,\n [lastAgentStateMessage.agentName]: {\n name: lastAgentStateMessage.agentName,\n state: lastAgentStateMessage.state,\n running: lastAgentStateMessage.running,\n active: lastAgentStateMessage.active,\n threadId: lastAgentStateMessage.threadId,\n nodeName: lastAgentStateMessage.nodeName,\n runId: lastAgentStateMessage.runId,\n },\n }));\n if (lastAgentStateMessage.running) {\n setAgentSession({\n threadId: lastAgentStateMessage.threadId,\n agentName: lastAgentStateMessage.agentName,\n nodeName: lastAgentStateMessage.nodeName,\n });\n } else {\n setAgentSession(null);\n }\n }\n }\n\n if (newMessages.length > 0) {\n // Update message state\n setMessages([...previousMessages, ...newMessages]);\n }\n }\n\n if (\n // if followUp is not explicitly false\n followUp !== false &&\n // if we have client side results\n (Object.values(actionResults).length ||\n // or the last message we received is a result\n (newMessages.length && newMessages[newMessages.length - 1].isResultMessage()))\n ) {\n // run the completion again and return the result\n\n // wait for next tick to make sure all the react state updates\n // - tried using react-dom's flushSync, but it did not work\n await new Promise((resolve) => setTimeout(resolve, 10));\n\n return await runChatCompletionRef.current!([...previousMessages, ...newMessages]);\n } else {\n return newMessages.slice();\n }\n } finally {\n setIsLoading(false);\n }\n };\n\n runChatCompletionRef.current = runChatCompletion;\n\n const runChatCompletionAndHandleFunctionCall = async (messages: Message[]): Promise<void> => {\n await runChatCompletionRef.current!(messages);\n };\n\n const append = async (message: Message): Promise<void> => {\n if (isLoading) {\n return;\n }\n\n const newMessages = [...messages, message];\n setMessages(newMessages);\n return runChatCompletionAndHandleFunctionCall(newMessages);\n };\n\n const reload = async (): Promise<void> => {\n if (isLoading || messages.length === 0) {\n return;\n }\n let newMessages = [...messages];\n const lastMessage = messages[messages.length - 1];\n\n if (lastMessage.isTextMessage() && lastMessage.role === \"assistant\") {\n newMessages = newMessages.slice(0, -1);\n }\n\n setMessages(newMessages);\n\n return runChatCompletionAndHandleFunctionCall(newMessages);\n };\n\n const stop = (): void => {\n abortControllerRef.current?.abort();\n };\n\n return {\n append,\n reload,\n stop,\n };\n}\n","import { useCopilotContext } from \"../../context\";\nimport { GraphQLError } from \"@copilotkit/runtime-client-gql\";\nimport React, { createContext, useContext, useState, useCallback } from \"react\";\nimport { ExclamationMarkIcon } from \"./exclamation-mark-icon\";\n\ninterface Toast {\n id: string;\n message: string | React.ReactNode;\n type: \"info\" | \"success\" | \"warning\" | \"error\";\n duration?: number;\n}\n\ninterface ToastContextValue {\n toasts: Toast[];\n addToast: (toast: Omit<Toast, \"id\">) => void;\n addGraphQLErrorsToast: (errors: GraphQLError[]) => void;\n removeToast: (id: string) => void;\n enabled: boolean;\n}\n\nconst ToastContext = createContext<ToastContextValue | undefined>(undefined);\n\nexport function useToast() {\n const context = useContext(ToastContext);\n if (!context) {\n throw new Error(\"useToast must be used within a ToastProvider\");\n }\n return context;\n}\n\nexport function ToastProvider({\n enabled,\n children,\n}: {\n enabled: boolean;\n children: React.ReactNode;\n}) {\n const [toasts, setToasts] = useState<Toast[]>([]);\n const addToast = useCallback((toast: Omit<Toast, \"id\">) => {\n const id = Math.random().toString(36).substring(2, 9);\n\n setToasts((currentToasts) => [...currentToasts, { ...toast, id }]);\n\n if (toast.duration) {\n setTimeout(() => {\n removeToast(id);\n }, toast.duration);\n }\n }, []);\n\n const addGraphQLErrorsToast = useCallback((errors: GraphQLError[]) => {\n // We do not display these errors unless we are in dev mode.\n // if (!showDevConsole) {\n // return;\n // }\n\n const errorsToRender = errors.map((error, idx) => {\n const message = error.message;\n const code = error.extensions?.code as string;\n\n return (\n <div\n key={idx}\n style={{\n marginTop: idx === 0 ? 0 : 10,\n marginBottom: 14,\n }}\n >\n <ExclamationMarkIcon style={{ marginBottom: 4 }} />\n\n {code && (\n <div\n style={{\n fontWeight: \"600\",\n marginBottom: 4,\n }}\n >\n Copilot Cloud Error:{\" \"}\n <span style={{ fontFamily: \"monospace\", fontWeight: \"normal\" }}>{code}</span>\n </div>\n )}\n <div>{message}</div>\n </div>\n );\n });\n\n addToast({\n type: \"error\",\n message: (\n <div\n style={{\n fontSize: \"13px\",\n maxWidth: \"600px\",\n }}\n >\n {errorsToRender}\n <div style={{ fontSize: \"11px\", opacity: 0.75 }}>\n NOTE: This is a Copilot Cloud error, and it only displays during local development.\n </div>\n </div>\n ),\n });\n }, []);\n\n const removeToast = useCallback((id: string) => {\n setToasts((currentToasts) => currentToasts.filter((toast) => toast.id !== id));\n }, []);\n\n const value = {\n toasts,\n addToast,\n addGraphQLErrorsToast,\n removeToast,\n enabled,\n };\n\n return (\n <ToastContext.Provider value={value}>\n <div\n style={{\n position: \"fixed\",\n bottom: \"1rem\",\n left: \"50%\",\n transform: \"translateX(-50%)\",\n zIndex: 50,\n display: \"flex\",\n flexDirection: \"column\",\n gap: \"0.5rem\",\n }}\n >\n {toasts.length > 1 && (\n <div style={{ textAlign: \"right\" }}>\n <button\n onClick={() => setToasts([])}\n style={{\n padding: \"4px 8px\",\n fontSize: \"12px\",\n cursor: \"pointer\",\n background: \"white\",\n border: \"1px solid rgba(0,0,0,0.2)\",\n borderRadius: \"4px\",\n }}\n >\n Close All\n </button>\n </div>\n )}\n {toasts.map((toast) => (\n <Toast\n key={toast.id}\n message={toast.message}\n type={toast.type}\n onClose={() => removeToast(toast.id)}\n />\n ))}\n </div>\n {children}\n </ToastContext.Provider>\n );\n}\n\nfunction Toast({\n message,\n type = \"info\",\n onClose,\n}: {\n message: string | React.ReactNode;\n type: \"info\" | \"success\" | \"warning\" | \"error\";\n onClose: () => void;\n}) {\n const bgColors = {\n info: \"#3b82f6\",\n success: \"#22c55e\",\n warning: \"#eab308\",\n error: \"#ef4444\",\n };\n\n return (\n <div\n style={{\n backgroundColor: bgColors[type],\n color: \"white\",\n padding: \"0.5rem 1rem\",\n borderRadius: \"0.25rem\",\n boxShadow: \"0 2px 4px rgba(0,0,0,0.1)\",\n position: \"relative\",\n minWidth: \"200px\",\n }}\n >\n <div>{message}</div>\n <button\n onClick={onClose}\n style={{\n position: \"absolute\",\n top: \"0\",\n right: \"0\",\n background: \"none\",\n border: \"none\",\n color: \"white\",\n cursor: \"pointer\",\n padding: \"0.5rem\",\n fontSize: \"1rem\",\n }}\n >\n ✕\n </button>\n </div>\n );\n}\n","import {\n CopilotRuntimeClient,\n CopilotRuntimeClientOptions,\n GraphQLError,\n} from \"@copilotkit/runtime-client-gql\";\nimport { useToast } from \"../components/toast/toast-provider\";\nimport { useMemo } from \"react\";\n\nexport const useCopilotRuntimeClient = (options: CopilotRuntimeClientOptions) => {\n const { addGraphQLErrorsToast } = useToast();\n\n const runtimeClient = useMemo(() => {\n return new CopilotRuntimeClient({\n ...options,\n handleGQLErrors: (error) => {\n if ((error as any).graphQLErrors.length) {\n addGraphQLErrorsToast((error as any).graphQLErrors as GraphQLError[]);\n }\n },\n });\n }, [options, addGraphQLErrorsToast]);\n\n return runtimeClient;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,gBAAuB;AACvB,oBAKO;AACP,IAAAC,6BAaO;;;AClBP,mBAAwE;AAkE9D;AAhDV,IAAM,mBAAe,4BAA6C,MAAS;AAEpE,SAAS,WAAW;AACzB,QAAM,cAAU,yBAAW,YAAY;AACvC,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,8CAA8C;AAAA,EAChE;AACA,SAAO;AACT;;;AC5BA,gCAIO;AAEP,IAAAC,gBAAwB;AAEjB,IAAM,0BAA0B,CAAC,YAAyC;AAC/E,QAAM,EAAE,sBAAsB,IAAI,SAAS;AAE3C,QAAM,oBAAgB,uBAAQ,MAAM;AAClC,WAAO,IAAI,+CAAqB,iCAC3B,UAD2B;AAAA,MAE9B,iBAAiB,CAAC,UAAU;AAC1B,YAAK,MAAc,cAAc,QAAQ;AACvC,gCAAuB,MAAc,aAA+B;AAAA,QACtE;AAAA,MACF;AAAA,IACF,EAAC;AAAA,EACH,GAAG,CAAC,SAAS,qBAAqB,CAAC;AAEnC,SAA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C,gBAAY,WAAW;AACvB,WAAO,uCAAuC,WAAW;AAAA,EAC3D;AAEA,QAAM,SAAS,MAA2B;AACxC,QAAI,aAAa,SAAS,WAAW,GAAG;AACtC;AAAA,IACF;AACA,QAAI,cAAc,CAAC,GAAG,QAAQ;AAC9B,UAAM,cAAc,SAAS,SAAS,SAAS,CAAC;AAEhD,QAAI,YAAY,cAAc,KAAK,YAAY,SAAS,aAAa;AACnE,oBAAc,YAAY,MAAM,GAAG,EAAE;AAAA,IACvC;AAEA,gBAAY,WAAW;AAEvB,WAAO,uCAAuC,WAAW;AAAA,EAC3D;AAEA,QAAM,OAAO,MAAY;AAnd3B;AAodI,6BAAmB,YAAnB,mBAA4B;AAAA,EAC9B;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":["import_react","import_runtime_client_gql","import_react","messages","action"]}
|
package/dist/hooks/use-chat.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { CoAgentStateRender } from '../types/coagent-action.js';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* <Callout type="info">
|
|
5
|
-
* Usage of this hook assumes some additional setup in your application, for more information
|
|
6
|
-
* on that see the CoAgents <span className="text-blue-500">[Agentic Generative UI documentation](/coagents/chat-ui/render-agent-state)</span>.
|
|
7
|
-
* </Callout>
|
|
8
|
-
*
|
|
9
|
-
* The useCoAgentStateRender hook allows you to render UI components or text based on a Agentic Copilot's state.
|
|
10
|
-
* This is particularly useful for showing intermediate state or progress during Agentic Copilot operations.
|
|
11
|
-
*
|
|
12
|
-
* ## Usage
|
|
13
|
-
*
|
|
14
|
-
* ### Simple Usage
|
|
15
|
-
*
|
|
16
|
-
* ```tsx
|
|
17
|
-
* import { useCoagentStateRender } from "@copilotkit/react-core";
|
|
18
|
-
*
|
|
19
|
-
* type YourAgentState = {
|
|
20
|
-
* agent_state_property: string;
|
|
21
|
-
* }
|
|
22
|
-
*
|
|
23
|
-
* useCoagentStateRender<YourAgentState>({
|
|
24
|
-
* name: "basic_agent",
|
|
25
|
-
* nodeName: "optionally_specify_a_specific_node",
|
|
26
|
-
* render: ({ status, state, nodeName }) => {
|
|
27
|
-
* return (
|
|
28
|
-
* <YourComponent
|
|
29
|
-
* agentStateProperty={state.agent_state_property}
|
|
30
|
-
* status={status}
|
|
31
|
-
* nodeName={nodeName}
|
|
32
|
-
* />
|
|
33
|
-
* );
|
|
34
|
-
* },
|
|
35
|
-
* });
|
|
36
|
-
* ```
|
|
37
|
-
*
|
|
38
|
-
* This allows for you to render UI components or text based on what is happening within the agent.
|
|
39
|
-
*
|
|
40
|
-
* ### Example
|
|
41
|
-
* A great example of this is in our Perplexity Clone where we render the progress of an agent's internet search as it is happening.
|
|
42
|
-
* You can play around with it below or learn how to build it with its [demo](/coagents/videos/perplexity-clone).
|
|
43
|
-
*
|
|
44
|
-
* <Callout type="info">
|
|
45
|
-
* This example is hosted on Vercel and may take a few seconds to load.
|
|
46
|
-
* </Callout>
|
|
47
|
-
*
|
|
48
|
-
* <iframe src="https://examples-coagents-ai-researcher-ui.vercel.app/" className="w-full rounded-lg border h-[700px] my-4" />
|
|
49
|
-
*/
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* This hook is used to render agent state with custom UI components or text. This is particularly
|
|
53
|
-
* useful for showing intermediate state or progress during Agentic Copilot operations.
|
|
54
|
-
* To get started using rendering intermediate state through this hook, checkout the documentation.
|
|
55
|
-
*
|
|
56
|
-
* https://docs.copilotkit.ai/coagents/chat-ui/render-agent-state.
|
|
57
|
-
*/
|
|
58
|
-
declare function useCoAgentStateRender<T = any>(action: CoAgentStateRender<T>, dependencies?: any[]): void;
|
|
59
|
-
|
|
60
|
-
export { useCoAgentStateRender };
|
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var __async = (__this, __arguments, generator) => {
|
|
30
|
-
return new Promise((resolve, reject) => {
|
|
31
|
-
var fulfilled = (value) => {
|
|
32
|
-
try {
|
|
33
|
-
step(generator.next(value));
|
|
34
|
-
} catch (e) {
|
|
35
|
-
reject(e);
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
var rejected = (value) => {
|
|
39
|
-
try {
|
|
40
|
-
step(generator.throw(value));
|
|
41
|
-
} catch (e) {
|
|
42
|
-
reject(e);
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
46
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
47
|
-
});
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
// src/hooks/use-coagent-state-render.ts
|
|
51
|
-
var use_coagent_state_render_exports = {};
|
|
52
|
-
__export(use_coagent_state_render_exports, {
|
|
53
|
-
useCoAgentStateRender: () => useCoAgentStateRender
|
|
54
|
-
});
|
|
55
|
-
module.exports = __toCommonJS(use_coagent_state_render_exports);
|
|
56
|
-
var import_react2 = require("react");
|
|
57
|
-
|
|
58
|
-
// src/context/copilot-context.tsx
|
|
59
|
-
var import_react = __toESM(require("react"));
|
|
60
|
-
var emptyCopilotContext = {
|
|
61
|
-
actions: {},
|
|
62
|
-
setAction: () => {
|
|
63
|
-
},
|
|
64
|
-
removeAction: () => {
|
|
65
|
-
},
|
|
66
|
-
coAgentStateRenders: {},
|
|
67
|
-
setCoAgentStateRender: () => {
|
|
68
|
-
},
|
|
69
|
-
removeCoAgentStateRender: () => {
|
|
70
|
-
},
|
|
71
|
-
chatComponentsCache: { current: { actions: {}, coAgentStateRenders: {} } },
|
|
72
|
-
getContextString: (documents, categories) => returnAndThrowInDebug(""),
|
|
73
|
-
addContext: () => "",
|
|
74
|
-
removeContext: () => {
|
|
75
|
-
},
|
|
76
|
-
getFunctionCallHandler: () => returnAndThrowInDebug(() => __async(void 0, null, function* () {
|
|
77
|
-
})),
|
|
78
|
-
isLoading: false,
|
|
79
|
-
setIsLoading: () => returnAndThrowInDebug(false),
|
|
80
|
-
chatInstructions: "",
|
|
81
|
-
setChatInstructions: () => returnAndThrowInDebug(""),
|
|
82
|
-
getDocumentsContext: (categories) => returnAndThrowInDebug([]),
|
|
83
|
-
addDocumentContext: () => returnAndThrowInDebug(""),
|
|
84
|
-
removeDocumentContext: () => {
|
|
85
|
-
},
|
|
86
|
-
runtimeClient: {},
|
|
87
|
-
copilotApiConfig: new class {
|
|
88
|
-
get chatApiEndpoint() {
|
|
89
|
-
throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
|
|
90
|
-
}
|
|
91
|
-
get headers() {
|
|
92
|
-
return {};
|
|
93
|
-
}
|
|
94
|
-
get body() {
|
|
95
|
-
return {};
|
|
96
|
-
}
|
|
97
|
-
}(),
|
|
98
|
-
chatSuggestionConfiguration: {},
|
|
99
|
-
addChatSuggestionConfiguration: () => {
|
|
100
|
-
},
|
|
101
|
-
removeChatSuggestionConfiguration: () => {
|
|
102
|
-
},
|
|
103
|
-
showDevConsole: "auto",
|
|
104
|
-
coagentStates: {},
|
|
105
|
-
setCoagentStates: () => {
|
|
106
|
-
},
|
|
107
|
-
agentSession: null,
|
|
108
|
-
setAgentSession: () => {
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
var CopilotContext = import_react.default.createContext(emptyCopilotContext);
|
|
112
|
-
function returnAndThrowInDebug(value) {
|
|
113
|
-
throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
|
|
114
|
-
return value;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// src/hooks/use-coagent-state-render.ts
|
|
118
|
-
var import_shared = require("@copilotkit/shared");
|
|
119
|
-
function useCoAgentStateRender(action, dependencies) {
|
|
120
|
-
const {
|
|
121
|
-
setCoAgentStateRender,
|
|
122
|
-
removeCoAgentStateRender,
|
|
123
|
-
coAgentStateRenders,
|
|
124
|
-
chatComponentsCache
|
|
125
|
-
} = (0, import_react2.useContext)(CopilotContext);
|
|
126
|
-
const idRef = (0, import_react2.useRef)((0, import_shared.randomId)());
|
|
127
|
-
const key = `${action.name}-${action.nodeName || "global"}`;
|
|
128
|
-
if (dependencies === void 0) {
|
|
129
|
-
if (coAgentStateRenders[idRef.current]) {
|
|
130
|
-
coAgentStateRenders[idRef.current].handler = action.handler;
|
|
131
|
-
if (typeof action.render === "function") {
|
|
132
|
-
if (chatComponentsCache.current !== null) {
|
|
133
|
-
chatComponentsCache.current.coAgentStateRenders[key] = action.render;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
(0, import_react2.useEffect)(() => {
|
|
139
|
-
setCoAgentStateRender(idRef.current, action);
|
|
140
|
-
if (chatComponentsCache.current !== null && action.render !== void 0) {
|
|
141
|
-
chatComponentsCache.current.coAgentStateRenders[key] = action.render;
|
|
142
|
-
}
|
|
143
|
-
return () => {
|
|
144
|
-
removeCoAgentStateRender(idRef.current);
|
|
145
|
-
};
|
|
146
|
-
}, [
|
|
147
|
-
setCoAgentStateRender,
|
|
148
|
-
removeCoAgentStateRender,
|
|
149
|
-
action.name,
|
|
150
|
-
// include render only if it's a string
|
|
151
|
-
typeof action.render === "string" ? action.render : void 0,
|
|
152
|
-
// dependencies set by the developer
|
|
153
|
-
...dependencies || []
|
|
154
|
-
]);
|
|
155
|
-
}
|
|
156
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
157
|
-
0 && (module.exports = {
|
|
158
|
-
useCoAgentStateRender
|
|
159
|
-
});
|
|
160
|
-
//# sourceMappingURL=use-coagent-state-render.js.map
|