@copilotkit/react-core 1.9.2-next.19 → 1.9.2-next.20
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 +18 -0
- package/dist/{chunk-XJ34ATKP.mjs → chunk-FN3UA2ZE.mjs} +2 -2
- package/dist/{chunk-7EJ4IWSA.mjs → chunk-K42OD3J6.mjs} +2 -2
- package/dist/{chunk-5DODGOMM.mjs → chunk-MTAJI7HV.mjs} +77 -45
- package/dist/chunk-MTAJI7HV.mjs.map +1 -0
- package/dist/{chunk-WR3XTNHJ.mjs → chunk-NJA5ZLAZ.mjs} +26 -7
- package/dist/chunk-NJA5ZLAZ.mjs.map +1 -0
- package/dist/{chunk-5PE2XROA.mjs → chunk-UGJGKBFB.mjs} +2 -2
- package/dist/{chunk-BHGYBOR3.mjs → chunk-ZOMEQ3XC.mjs} +2 -2
- package/dist/hooks/index.js +102 -51
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +6 -6
- package/dist/hooks/use-chat.js +170 -138
- package/dist/hooks/use-chat.js.map +1 -1
- package/dist/hooks/use-chat.mjs +1 -1
- package/dist/hooks/use-coagent.js +77 -45
- package/dist/hooks/use-coagent.js.map +1 -1
- package/dist/hooks/use-coagent.mjs +3 -3
- package/dist/hooks/use-copilot-action.js +25 -6
- package/dist/hooks/use-copilot-action.js.map +1 -1
- package/dist/hooks/use-copilot-action.mjs +1 -1
- package/dist/hooks/use-copilot-authenticated-action.js +25 -6
- package/dist/hooks/use-copilot-authenticated-action.js.map +1 -1
- package/dist/hooks/use-copilot-authenticated-action.mjs +2 -2
- package/dist/hooks/use-copilot-chat.js +77 -45
- package/dist/hooks/use-copilot-chat.js.map +1 -1
- package/dist/hooks/use-copilot-chat.mjs +2 -2
- package/dist/hooks/use-langgraph-interrupt.js +77 -45
- package/dist/hooks/use-langgraph-interrupt.js.map +1 -1
- package/dist/hooks/use-langgraph-interrupt.mjs +3 -3
- package/dist/index.js +101 -50
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +6 -6
- package/package.json +3 -3
- package/src/hooks/use-chat.ts +110 -46
- package/src/hooks/use-copilot-action.ts +51 -9
- package/dist/chunk-5DODGOMM.mjs.map +0 -1
- package/dist/chunk-WR3XTNHJ.mjs.map +0 -1
- /package/dist/{chunk-XJ34ATKP.mjs.map → chunk-FN3UA2ZE.mjs.map} +0 -0
- /package/dist/{chunk-7EJ4IWSA.mjs.map → chunk-K42OD3J6.mjs.map} +0 -0
- /package/dist/{chunk-5PE2XROA.mjs.map → chunk-UGJGKBFB.mjs.map} +0 -0
- /package/dist/{chunk-BHGYBOR3.mjs.map → chunk-ZOMEQ3XC.mjs.map} +0 -0
package/dist/hooks/index.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
} from "../chunk-VDADWRS3.mjs";
|
|
5
5
|
import {
|
|
6
6
|
useLangGraphInterrupt
|
|
7
|
-
} from "../chunk-
|
|
7
|
+
} from "../chunk-UGJGKBFB.mjs";
|
|
8
8
|
import {
|
|
9
9
|
useMakeCopilotDocumentReadable
|
|
10
10
|
} from "../chunk-36MGCCPZ.mjs";
|
|
@@ -16,19 +16,19 @@ import {
|
|
|
16
16
|
startAgent,
|
|
17
17
|
stopAgent,
|
|
18
18
|
useCoAgent
|
|
19
|
-
} from "../chunk-
|
|
19
|
+
} from "../chunk-ZOMEQ3XC.mjs";
|
|
20
20
|
import {
|
|
21
21
|
useCopilotAdditionalInstructions
|
|
22
22
|
} from "../chunk-BVK7PLK6.mjs";
|
|
23
23
|
import {
|
|
24
24
|
useCopilotAuthenticatedAction_c
|
|
25
|
-
} from "../chunk-
|
|
25
|
+
} from "../chunk-FN3UA2ZE.mjs";
|
|
26
26
|
import {
|
|
27
27
|
useCopilotAction
|
|
28
|
-
} from "../chunk-
|
|
28
|
+
} from "../chunk-NJA5ZLAZ.mjs";
|
|
29
29
|
import {
|
|
30
30
|
useCopilotChat
|
|
31
|
-
} from "../chunk-
|
|
31
|
+
} from "../chunk-K42OD3J6.mjs";
|
|
32
32
|
import {
|
|
33
33
|
useCopilotReadable
|
|
34
34
|
} from "../chunk-5BSUSFHM.mjs";
|
|
@@ -41,7 +41,7 @@ import "../chunk-PMAFHQ7P.mjs";
|
|
|
41
41
|
import "../chunk-57K2ZJ5F.mjs";
|
|
42
42
|
import "../chunk-YPSGKPDA.mjs";
|
|
43
43
|
import "../chunk-DCTJZ742.mjs";
|
|
44
|
-
import "../chunk-
|
|
44
|
+
import "../chunk-MTAJI7HV.mjs";
|
|
45
45
|
import "../chunk-4CEQJ2X6.mjs";
|
|
46
46
|
import "../chunk-3OQM3NEK.mjs";
|
|
47
47
|
import "../chunk-O7ARI5CV.mjs";
|
package/dist/hooks/use-chat.js
CHANGED
|
@@ -83,6 +83,7 @@ __export(use_chat_exports, {
|
|
|
83
83
|
});
|
|
84
84
|
module.exports = __toCommonJS(use_chat_exports);
|
|
85
85
|
var import_react5 = require("react");
|
|
86
|
+
var import_react_dom = require("react-dom");
|
|
86
87
|
var import_shared4 = require("@copilotkit/shared");
|
|
87
88
|
var import_runtime_client_gql3 = require("@copilotkit/runtime-client-gql");
|
|
88
89
|
|
|
@@ -111,16 +112,104 @@ function processActionsForRuntimeRequest(actions) {
|
|
|
111
112
|
return filteredActions;
|
|
112
113
|
}
|
|
113
114
|
|
|
115
|
+
// src/context/copilot-context.tsx
|
|
116
|
+
var import_react = __toESM(require("react"));
|
|
117
|
+
var emptyCopilotContext = {
|
|
118
|
+
actions: {},
|
|
119
|
+
setAction: () => {
|
|
120
|
+
},
|
|
121
|
+
removeAction: () => {
|
|
122
|
+
},
|
|
123
|
+
coAgentStateRenders: {},
|
|
124
|
+
setCoAgentStateRender: () => {
|
|
125
|
+
},
|
|
126
|
+
removeCoAgentStateRender: () => {
|
|
127
|
+
},
|
|
128
|
+
chatComponentsCache: { current: { actions: {}, coAgentStateRenders: {} } },
|
|
129
|
+
getContextString: (documents, categories) => returnAndThrowInDebug(""),
|
|
130
|
+
addContext: () => "",
|
|
131
|
+
removeContext: () => {
|
|
132
|
+
},
|
|
133
|
+
getAllContext: () => [],
|
|
134
|
+
getFunctionCallHandler: () => returnAndThrowInDebug(() => __async(void 0, null, function* () {
|
|
135
|
+
})),
|
|
136
|
+
isLoading: false,
|
|
137
|
+
setIsLoading: () => returnAndThrowInDebug(false),
|
|
138
|
+
chatInstructions: "",
|
|
139
|
+
setChatInstructions: () => returnAndThrowInDebug(""),
|
|
140
|
+
additionalInstructions: [],
|
|
141
|
+
setAdditionalInstructions: () => returnAndThrowInDebug([]),
|
|
142
|
+
getDocumentsContext: (categories) => returnAndThrowInDebug([]),
|
|
143
|
+
addDocumentContext: () => returnAndThrowInDebug(""),
|
|
144
|
+
removeDocumentContext: () => {
|
|
145
|
+
},
|
|
146
|
+
runtimeClient: {},
|
|
147
|
+
copilotApiConfig: new class {
|
|
148
|
+
get chatApiEndpoint() {
|
|
149
|
+
throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
|
|
150
|
+
}
|
|
151
|
+
get headers() {
|
|
152
|
+
return {};
|
|
153
|
+
}
|
|
154
|
+
get body() {
|
|
155
|
+
return {};
|
|
156
|
+
}
|
|
157
|
+
}(),
|
|
158
|
+
chatSuggestionConfiguration: {},
|
|
159
|
+
addChatSuggestionConfiguration: () => {
|
|
160
|
+
},
|
|
161
|
+
removeChatSuggestionConfiguration: () => {
|
|
162
|
+
},
|
|
163
|
+
showDevConsole: false,
|
|
164
|
+
coagentStates: {},
|
|
165
|
+
setCoagentStates: () => {
|
|
166
|
+
},
|
|
167
|
+
coagentStatesRef: { current: {} },
|
|
168
|
+
setCoagentStatesWithRef: () => {
|
|
169
|
+
},
|
|
170
|
+
agentSession: null,
|
|
171
|
+
setAgentSession: () => {
|
|
172
|
+
},
|
|
173
|
+
forwardedParameters: {},
|
|
174
|
+
agentLock: null,
|
|
175
|
+
threadId: "",
|
|
176
|
+
setThreadId: () => {
|
|
177
|
+
},
|
|
178
|
+
runId: null,
|
|
179
|
+
setRunId: () => {
|
|
180
|
+
},
|
|
181
|
+
chatAbortControllerRef: { current: null },
|
|
182
|
+
availableAgents: [],
|
|
183
|
+
extensions: {},
|
|
184
|
+
setExtensions: () => {
|
|
185
|
+
},
|
|
186
|
+
langGraphInterruptAction: null,
|
|
187
|
+
setLangGraphInterruptAction: () => null,
|
|
188
|
+
removeLangGraphInterruptAction: () => null,
|
|
189
|
+
onError: void 0
|
|
190
|
+
};
|
|
191
|
+
var CopilotContext = import_react.default.createContext(emptyCopilotContext);
|
|
192
|
+
function useCopilotContext() {
|
|
193
|
+
const context = import_react.default.useContext(CopilotContext);
|
|
194
|
+
if (context === emptyCopilotContext) {
|
|
195
|
+
throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
|
|
196
|
+
}
|
|
197
|
+
return context;
|
|
198
|
+
}
|
|
199
|
+
function returnAndThrowInDebug(_value) {
|
|
200
|
+
throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
|
|
201
|
+
}
|
|
202
|
+
|
|
114
203
|
// src/hooks/use-copilot-runtime-client.ts
|
|
115
204
|
var import_runtime_client_gql2 = require("@copilotkit/runtime-client-gql");
|
|
116
205
|
|
|
117
206
|
// src/components/toast/toast-provider.tsx
|
|
118
|
-
var
|
|
207
|
+
var import_react2 = require("react");
|
|
119
208
|
var import_shared2 = require("@copilotkit/shared");
|
|
120
209
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
121
|
-
var ToastContext = (0,
|
|
210
|
+
var ToastContext = (0, import_react2.createContext)(void 0);
|
|
122
211
|
function useToast() {
|
|
123
|
-
const context = (0,
|
|
212
|
+
const context = (0, import_react2.useContext)(ToastContext);
|
|
124
213
|
if (!context) {
|
|
125
214
|
throw new Error("useToast must be used within a ToastProvider");
|
|
126
215
|
}
|
|
@@ -128,7 +217,7 @@ function useToast() {
|
|
|
128
217
|
}
|
|
129
218
|
|
|
130
219
|
// src/hooks/use-copilot-runtime-client.ts
|
|
131
|
-
var
|
|
220
|
+
var import_react3 = require("react");
|
|
132
221
|
var import_shared3 = require("@copilotkit/shared");
|
|
133
222
|
|
|
134
223
|
// src/utils/dev-console.ts
|
|
@@ -140,7 +229,7 @@ function shouldShowDevConsole(showDevConsole) {
|
|
|
140
229
|
var useCopilotRuntimeClient = (options) => {
|
|
141
230
|
const { setBannerError } = useToast();
|
|
142
231
|
const _a = options, { showDevConsole, onError } = _a, runtimeOptions = __objRest(_a, ["showDevConsole", "onError"]);
|
|
143
|
-
const lastStructuredErrorRef = (0,
|
|
232
|
+
const lastStructuredErrorRef = (0, import_react3.useRef)(null);
|
|
144
233
|
const traceUIError = (error, originalError) => __async(void 0, null, function* () {
|
|
145
234
|
if (!onError || !runtimeOptions.publicApiKey)
|
|
146
235
|
return;
|
|
@@ -168,7 +257,7 @@ var useCopilotRuntimeClient = (options) => {
|
|
|
168
257
|
console.error("Error in onError handler:", error2);
|
|
169
258
|
}
|
|
170
259
|
});
|
|
171
|
-
const runtimeClient = (0,
|
|
260
|
+
const runtimeClient = (0, import_react3.useMemo)(() => {
|
|
172
261
|
return new import_runtime_client_gql2.CopilotRuntimeClient(__spreadProps(__spreadValues({}, runtimeOptions), {
|
|
173
262
|
handleGQLErrors: (error) => {
|
|
174
263
|
var _a2;
|
|
@@ -256,94 +345,6 @@ function createStructuredError(gqlError) {
|
|
|
256
345
|
return null;
|
|
257
346
|
}
|
|
258
347
|
|
|
259
|
-
// src/context/copilot-context.tsx
|
|
260
|
-
var import_react3 = __toESM(require("react"));
|
|
261
|
-
var emptyCopilotContext = {
|
|
262
|
-
actions: {},
|
|
263
|
-
setAction: () => {
|
|
264
|
-
},
|
|
265
|
-
removeAction: () => {
|
|
266
|
-
},
|
|
267
|
-
coAgentStateRenders: {},
|
|
268
|
-
setCoAgentStateRender: () => {
|
|
269
|
-
},
|
|
270
|
-
removeCoAgentStateRender: () => {
|
|
271
|
-
},
|
|
272
|
-
chatComponentsCache: { current: { actions: {}, coAgentStateRenders: {} } },
|
|
273
|
-
getContextString: (documents, categories) => returnAndThrowInDebug(""),
|
|
274
|
-
addContext: () => "",
|
|
275
|
-
removeContext: () => {
|
|
276
|
-
},
|
|
277
|
-
getAllContext: () => [],
|
|
278
|
-
getFunctionCallHandler: () => returnAndThrowInDebug(() => __async(void 0, null, function* () {
|
|
279
|
-
})),
|
|
280
|
-
isLoading: false,
|
|
281
|
-
setIsLoading: () => returnAndThrowInDebug(false),
|
|
282
|
-
chatInstructions: "",
|
|
283
|
-
setChatInstructions: () => returnAndThrowInDebug(""),
|
|
284
|
-
additionalInstructions: [],
|
|
285
|
-
setAdditionalInstructions: () => returnAndThrowInDebug([]),
|
|
286
|
-
getDocumentsContext: (categories) => returnAndThrowInDebug([]),
|
|
287
|
-
addDocumentContext: () => returnAndThrowInDebug(""),
|
|
288
|
-
removeDocumentContext: () => {
|
|
289
|
-
},
|
|
290
|
-
runtimeClient: {},
|
|
291
|
-
copilotApiConfig: new class {
|
|
292
|
-
get chatApiEndpoint() {
|
|
293
|
-
throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
|
|
294
|
-
}
|
|
295
|
-
get headers() {
|
|
296
|
-
return {};
|
|
297
|
-
}
|
|
298
|
-
get body() {
|
|
299
|
-
return {};
|
|
300
|
-
}
|
|
301
|
-
}(),
|
|
302
|
-
chatSuggestionConfiguration: {},
|
|
303
|
-
addChatSuggestionConfiguration: () => {
|
|
304
|
-
},
|
|
305
|
-
removeChatSuggestionConfiguration: () => {
|
|
306
|
-
},
|
|
307
|
-
showDevConsole: false,
|
|
308
|
-
coagentStates: {},
|
|
309
|
-
setCoagentStates: () => {
|
|
310
|
-
},
|
|
311
|
-
coagentStatesRef: { current: {} },
|
|
312
|
-
setCoagentStatesWithRef: () => {
|
|
313
|
-
},
|
|
314
|
-
agentSession: null,
|
|
315
|
-
setAgentSession: () => {
|
|
316
|
-
},
|
|
317
|
-
forwardedParameters: {},
|
|
318
|
-
agentLock: null,
|
|
319
|
-
threadId: "",
|
|
320
|
-
setThreadId: () => {
|
|
321
|
-
},
|
|
322
|
-
runId: null,
|
|
323
|
-
setRunId: () => {
|
|
324
|
-
},
|
|
325
|
-
chatAbortControllerRef: { current: null },
|
|
326
|
-
availableAgents: [],
|
|
327
|
-
extensions: {},
|
|
328
|
-
setExtensions: () => {
|
|
329
|
-
},
|
|
330
|
-
langGraphInterruptAction: null,
|
|
331
|
-
setLangGraphInterruptAction: () => null,
|
|
332
|
-
removeLangGraphInterruptAction: () => null,
|
|
333
|
-
onError: void 0
|
|
334
|
-
};
|
|
335
|
-
var CopilotContext = import_react3.default.createContext(emptyCopilotContext);
|
|
336
|
-
function useCopilotContext() {
|
|
337
|
-
const context = import_react3.default.useContext(CopilotContext);
|
|
338
|
-
if (context === emptyCopilotContext) {
|
|
339
|
-
throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
|
|
340
|
-
}
|
|
341
|
-
return context;
|
|
342
|
-
}
|
|
343
|
-
function returnAndThrowInDebug(_value) {
|
|
344
|
-
throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
|
|
345
|
-
}
|
|
346
|
-
|
|
347
348
|
// src/components/error-boundary/error-utils.tsx
|
|
348
349
|
var import_react4 = require("react");
|
|
349
350
|
|
|
@@ -777,6 +778,39 @@ function useChat(options) {
|
|
|
777
778
|
newMessages
|
|
778
779
|
);
|
|
779
780
|
let didExecuteAction = false;
|
|
781
|
+
const executeActionFromMessage = (currentAction, actionMessage) => __async(this, null, function* () {
|
|
782
|
+
var _a2;
|
|
783
|
+
const isInterruptAction = interruptMessages.find((m) => m.id === actionMessage.id);
|
|
784
|
+
followUp = (_a2 = currentAction == null ? void 0 : currentAction.followUp) != null ? _a2 : !isInterruptAction;
|
|
785
|
+
if (currentAction == null ? void 0 : currentAction._setActivatingMessageId) {
|
|
786
|
+
currentAction._setActivatingMessageId(actionMessage.id);
|
|
787
|
+
}
|
|
788
|
+
const resultMessage = yield executeAction({
|
|
789
|
+
onFunctionCall,
|
|
790
|
+
message: actionMessage,
|
|
791
|
+
chatAbortControllerRef,
|
|
792
|
+
onError: (error) => {
|
|
793
|
+
addErrorToast([error]);
|
|
794
|
+
console.error(`Failed to execute action ${actionMessage.name}: ${error}`);
|
|
795
|
+
},
|
|
796
|
+
setMessages,
|
|
797
|
+
getFinalMessages: () => finalMessages,
|
|
798
|
+
isRenderAndWait: (currentAction == null ? void 0 : currentAction._isRenderAndWait) || false
|
|
799
|
+
});
|
|
800
|
+
didExecuteAction = true;
|
|
801
|
+
const messageIndex = finalMessages.findIndex((msg) => msg.id === actionMessage.id);
|
|
802
|
+
finalMessages.splice(messageIndex + 1, 0, resultMessage);
|
|
803
|
+
if (currentAction == null ? void 0 : currentAction._isRenderAndWait) {
|
|
804
|
+
const messagesForImmediateUpdate = [...finalMessages];
|
|
805
|
+
(0, import_react_dom.flushSync)(() => {
|
|
806
|
+
setMessages(messagesForImmediateUpdate);
|
|
807
|
+
});
|
|
808
|
+
}
|
|
809
|
+
if (currentAction == null ? void 0 : currentAction._setActivatingMessageId) {
|
|
810
|
+
currentAction._setActivatingMessageId(null);
|
|
811
|
+
}
|
|
812
|
+
return resultMessage;
|
|
813
|
+
});
|
|
780
814
|
if (onFunctionCall) {
|
|
781
815
|
const lastMessages = [];
|
|
782
816
|
for (let i = finalMessages.length - 1; i >= 0; i--) {
|
|
@@ -793,37 +827,28 @@ function useChat(options) {
|
|
|
793
827
|
(action2) => action2.name === message.name
|
|
794
828
|
);
|
|
795
829
|
const currentResultMessagePairedFeAction = message.isResultMessage() ? getPairedFeAction(actions, message) : null;
|
|
796
|
-
const executeActionFromMessage = (action2, message2) => __async(this, null, function* () {
|
|
797
|
-
var _a2;
|
|
798
|
-
const isInterruptAction = interruptMessages.find((m) => m.id === message2.id);
|
|
799
|
-
followUp = (_a2 = action2 == null ? void 0 : action2.followUp) != null ? _a2 : !isInterruptAction;
|
|
800
|
-
const resultMessage = yield executeAction({
|
|
801
|
-
onFunctionCall,
|
|
802
|
-
previousMessages,
|
|
803
|
-
message: message2,
|
|
804
|
-
chatAbortControllerRef,
|
|
805
|
-
onError: (error) => {
|
|
806
|
-
addErrorToast([error]);
|
|
807
|
-
console.error(`Failed to execute action ${message2.name}: ${error}`);
|
|
808
|
-
}
|
|
809
|
-
});
|
|
810
|
-
didExecuteAction = true;
|
|
811
|
-
const messageIndex = finalMessages.findIndex((msg) => msg.id === message2.id);
|
|
812
|
-
finalMessages.splice(messageIndex + 1, 0, resultMessage);
|
|
813
|
-
return resultMessage;
|
|
814
|
-
});
|
|
815
830
|
if (action && message.isActionExecutionMessage()) {
|
|
816
|
-
const
|
|
817
|
-
const
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
831
|
+
const isRenderAndWaitAction = (action == null ? void 0 : action._isRenderAndWait) || false;
|
|
832
|
+
const alreadyProcessed = isRenderAndWaitAction && finalMessages.some(
|
|
833
|
+
(fm) => fm.isResultMessage() && fm.actionExecutionId === message.id
|
|
834
|
+
);
|
|
835
|
+
if (alreadyProcessed) {
|
|
836
|
+
} else {
|
|
837
|
+
const resultMessage = yield executeActionFromMessage(
|
|
838
|
+
action,
|
|
839
|
+
message
|
|
840
|
+
);
|
|
841
|
+
const pairedFeAction = getPairedFeAction(actions, resultMessage);
|
|
842
|
+
if (pairedFeAction) {
|
|
843
|
+
const newExecutionMessage = new import_runtime_client_gql3.ActionExecutionMessage({
|
|
844
|
+
name: pairedFeAction.name,
|
|
845
|
+
arguments: (0, import_shared4.parseJson)(resultMessage.result, resultMessage.result),
|
|
846
|
+
status: message.status,
|
|
847
|
+
createdAt: message.createdAt,
|
|
848
|
+
parentMessageId: message.parentMessageId
|
|
849
|
+
});
|
|
850
|
+
yield executeActionFromMessage(pairedFeAction, newExecutionMessage);
|
|
851
|
+
}
|
|
827
852
|
}
|
|
828
853
|
} else if (message.isResultMessage() && currentResultMessagePairedFeAction) {
|
|
829
854
|
const newExecutionMessage = new import_runtime_client_gql3.ActionExecutionMessage({
|
|
@@ -841,13 +866,9 @@ function useChat(options) {
|
|
|
841
866
|
}
|
|
842
867
|
setMessages(finalMessages);
|
|
843
868
|
}
|
|
844
|
-
if (
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
(didExecuteAction || // the last message is a server side result
|
|
848
|
-
!isAgentRun && finalMessages.length && finalMessages[finalMessages.length - 1].isResultMessage()) && // the user did not stop generation
|
|
849
|
-
!((_r = chatAbortControllerRef.current) == null ? void 0 : _r.signal.aborted)
|
|
850
|
-
) {
|
|
869
|
+
if (followUp !== false && (didExecuteAction || // the last message is a server side result
|
|
870
|
+
!isAgentRun && finalMessages.length && finalMessages[finalMessages.length - 1].isResultMessage()) && // the user did not stop generation
|
|
871
|
+
!((_r = chatAbortControllerRef.current) == null ? void 0 : _r.signal.aborted)) {
|
|
851
872
|
yield new Promise((resolve) => setTimeout(resolve, 10));
|
|
852
873
|
return yield runChatCompletionRef.current(finalMessages);
|
|
853
874
|
} else if ((_s = chatAbortControllerRef.current) == null ? void 0 : _s.signal.aborted) {
|
|
@@ -1018,20 +1039,31 @@ function constructFinalMessages(syncedMessages, previousMessages, newMessages) {
|
|
|
1018
1039
|
function executeAction(_0) {
|
|
1019
1040
|
return __async(this, arguments, function* ({
|
|
1020
1041
|
onFunctionCall,
|
|
1021
|
-
previousMessages,
|
|
1022
1042
|
message,
|
|
1023
1043
|
chatAbortControllerRef,
|
|
1024
|
-
onError
|
|
1044
|
+
onError,
|
|
1045
|
+
setMessages,
|
|
1046
|
+
getFinalMessages,
|
|
1047
|
+
isRenderAndWait
|
|
1025
1048
|
}) {
|
|
1026
1049
|
let result;
|
|
1027
1050
|
let error = null;
|
|
1051
|
+
const currentMessagesForHandler = getFinalMessages();
|
|
1052
|
+
const handlerReturnedPromise = onFunctionCall({
|
|
1053
|
+
messages: currentMessagesForHandler,
|
|
1054
|
+
name: message.name,
|
|
1055
|
+
args: message.arguments
|
|
1056
|
+
});
|
|
1057
|
+
if (isRenderAndWait) {
|
|
1058
|
+
const currentMessagesForRender = getFinalMessages();
|
|
1059
|
+
(0, import_react_dom.flushSync)(() => {
|
|
1060
|
+
setMessages([...currentMessagesForRender]);
|
|
1061
|
+
});
|
|
1062
|
+
}
|
|
1028
1063
|
try {
|
|
1029
1064
|
result = yield Promise.race([
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
name: message.name,
|
|
1033
|
-
args: message.arguments
|
|
1034
|
-
}),
|
|
1065
|
+
handlerReturnedPromise,
|
|
1066
|
+
// Await the promise returned by the handler
|
|
1035
1067
|
new Promise(
|
|
1036
1068
|
(resolve) => {
|
|
1037
1069
|
var _a;
|