@copilotkit/react-core 1.50.0-beta.0 → 1.50.0-beta.10
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 +93 -0
- package/dist/{chunk-UJBV5GAG.mjs → chunk-3775VM7Y.mjs} +32 -65
- package/dist/chunk-3775VM7Y.mjs.map +1 -0
- package/dist/{chunk-3GURHDG7.mjs → chunk-4HRUQH6U.mjs} +3 -3
- package/dist/{chunk-7BYHZLPL.mjs → chunk-4RRMC7L2.mjs} +4 -4
- package/dist/chunk-4RRMC7L2.mjs.map +1 -0
- package/dist/{chunk-D3QSYDJR.mjs → chunk-7IBF6RBW.mjs} +2 -2
- package/dist/{chunk-GMI4KO4X.mjs → chunk-7SHWECGN.mjs} +2 -2
- package/dist/{chunk-OVYFRPSN.mjs → chunk-ABWT4DRT.mjs} +2 -2
- package/dist/{chunk-WVLHXIFP.mjs → chunk-AFNWX62Q.mjs} +2 -2
- package/dist/{chunk-WVLHXIFP.mjs.map → chunk-AFNWX62Q.mjs.map} +1 -1
- package/dist/{chunk-JRT5BJF3.mjs → chunk-B5ELMVT7.mjs} +2 -2
- package/dist/{chunk-TXI72QHK.mjs → chunk-EG56H77V.mjs} +2 -2
- package/dist/{chunk-DCHSCK62.mjs → chunk-FYMZKPOL.mjs} +36 -42
- package/dist/chunk-FYMZKPOL.mjs.map +1 -0
- package/dist/{chunk-FBD24VEH.mjs → chunk-HE22TZMF.mjs} +2 -2
- package/dist/{chunk-FBD24VEH.mjs.map → chunk-HE22TZMF.mjs.map} +1 -1
- package/dist/chunk-I76HKHPJ.mjs +32 -0
- package/dist/chunk-I76HKHPJ.mjs.map +1 -0
- package/dist/{chunk-LHKZJ2ND.mjs → chunk-PMWUKW3Z.mjs} +3 -3
- package/dist/{chunk-NROJOTQP.mjs → chunk-QNUAXSDP.mjs} +9 -6
- package/dist/chunk-QNUAXSDP.mjs.map +1 -0
- package/dist/{chunk-NG26QEGF.mjs → chunk-T2VBHAAP.mjs} +9 -3
- package/dist/chunk-T2VBHAAP.mjs.map +1 -0
- package/dist/{chunk-QU6NONOD.mjs → chunk-U2ZRVVKT.mjs} +2 -2
- package/dist/{chunk-R4MR43UQ.mjs → chunk-VV56AVPB.mjs} +33 -9
- package/dist/chunk-VV56AVPB.mjs.map +1 -0
- package/dist/{chunk-5X5DJRQQ.mjs → chunk-WF65O6HX.mjs} +2 -7
- package/dist/chunk-WF65O6HX.mjs.map +1 -0
- package/dist/chunk-XDFVCQD3.mjs +27 -0
- package/dist/chunk-XDFVCQD3.mjs.map +1 -0
- package/dist/{chunk-WMJVBMUX.mjs → chunk-YCG6SNAU.mjs} +2 -2
- package/dist/{chunk-3R423LZT.mjs → chunk-YJGPIN3R.mjs} +3 -3
- package/dist/{chunk-BR5YEYZJ.mjs → chunk-YTQHRJUA.mjs} +2 -2
- package/dist/chunk-Z6JV2LRY.mjs +37 -0
- package/dist/chunk-Z6JV2LRY.mjs.map +1 -0
- package/dist/{chunk-24SCZAB4.mjs → chunk-ZYTXB6HH.mjs} +22 -14
- package/dist/chunk-ZYTXB6HH.mjs.map +1 -0
- package/dist/components/CopilotListeners.js +13 -146
- package/dist/components/CopilotListeners.js.map +1 -1
- package/dist/components/CopilotListeners.mjs +1 -6
- package/dist/components/copilot-provider/copilot-messages.js +1 -1
- package/dist/components/copilot-provider/copilot-messages.js.map +1 -1
- package/dist/components/copilot-provider/copilot-messages.mjs +2 -2
- package/dist/components/copilot-provider/copilotkit-props.d.ts +1 -1
- package/dist/components/copilot-provider/copilotkit.d.ts +1 -1
- package/dist/components/copilot-provider/copilotkit.js +35 -40
- package/dist/components/copilot-provider/copilotkit.js.map +1 -1
- package/dist/components/copilot-provider/copilotkit.mjs +9 -9
- package/dist/components/copilot-provider/index.d.ts +1 -1
- package/dist/components/copilot-provider/index.js +35 -40
- package/dist/components/copilot-provider/index.js.map +1 -1
- package/dist/components/copilot-provider/index.mjs +9 -9
- package/dist/components/dev-console/console-trigger.js +1 -1
- package/dist/components/dev-console/console-trigger.js.map +1 -1
- package/dist/components/dev-console/console-trigger.mjs +3 -3
- package/dist/components/dev-console/developer-console-modal.js +1 -1
- package/dist/components/dev-console/developer-console-modal.js.map +1 -1
- package/dist/components/dev-console/developer-console-modal.mjs +2 -2
- package/dist/components/index.d.ts +1 -1
- package/dist/components/index.js +35 -40
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +9 -9
- package/dist/context/copilot-context.d.ts +1 -1
- package/dist/context/copilot-context.js +1 -1
- package/dist/context/copilot-context.js.map +1 -1
- package/dist/context/copilot-context.mjs +1 -1
- package/dist/context/index.d.ts +1 -1
- package/dist/context/index.js +1 -1
- package/dist/context/index.js.map +1 -1
- package/dist/context/index.mjs +1 -1
- package/dist/{copilot-context-1cd70a3f.d.ts → copilot-context-ec77e921.d.ts} +3 -3
- package/dist/hooks/index.d.ts +2 -2
- package/dist/hooks/index.js +254 -219
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +24 -23
- package/dist/hooks/use-agent-nodename.d.ts +3 -0
- package/dist/hooks/use-agent-nodename.js +56 -0
- package/dist/hooks/use-agent-nodename.js.map +1 -0
- package/dist/hooks/use-agent-nodename.mjs +8 -0
- package/dist/hooks/use-coagent-state-render-bridge.js +8 -5
- package/dist/hooks/use-coagent-state-render-bridge.js.map +1 -1
- package/dist/hooks/use-coagent-state-render-bridge.mjs +2 -2
- package/dist/hooks/use-coagent-state-render.js +1 -1
- package/dist/hooks/use-coagent-state-render.js.map +1 -1
- package/dist/hooks/use-coagent-state-render.mjs +2 -2
- package/dist/hooks/use-coagent.js +58 -21
- package/dist/hooks/use-coagent.js.map +1 -1
- package/dist/hooks/use-coagent.mjs +2 -1
- package/dist/hooks/use-copilot-action.js +5 -1
- package/dist/hooks/use-copilot-action.js.map +1 -1
- package/dist/hooks/use-copilot-action.mjs +2 -2
- package/dist/hooks/use-copilot-additional-instructions.js +1 -1
- package/dist/hooks/use-copilot-additional-instructions.js.map +1 -1
- package/dist/hooks/use-copilot-additional-instructions.mjs +2 -2
- package/dist/hooks/use-copilot-authenticated-action.js +6 -2
- package/dist/hooks/use-copilot-authenticated-action.js.map +1 -1
- package/dist/hooks/use-copilot-authenticated-action.mjs +4 -4
- package/dist/hooks/use-copilot-chat-headless_c.js +128 -140
- package/dist/hooks/use-copilot-chat-headless_c.js.map +1 -1
- package/dist/hooks/use-copilot-chat-headless_c.mjs +6 -6
- package/dist/hooks/{use-configure-chat-suggestions.d.ts → use-copilot-chat-suggestions.d.ts} +2 -3
- package/dist/hooks/use-copilot-chat-suggestions.js +60 -0
- package/dist/hooks/use-copilot-chat-suggestions.js.map +1 -0
- package/dist/hooks/use-copilot-chat-suggestions.mjs +8 -0
- package/dist/hooks/use-copilot-chat-suggestions.mjs.map +1 -0
- package/dist/hooks/use-copilot-chat.js +126 -138
- package/dist/hooks/use-copilot-chat.js.map +1 -1
- package/dist/hooks/use-copilot-chat.mjs +6 -6
- package/dist/hooks/use-copilot-chat_internal.d.ts +18 -1
- package/dist/hooks/use-copilot-chat_internal.js +126 -138
- package/dist/hooks/use-copilot-chat_internal.js.map +1 -1
- package/dist/hooks/use-copilot-chat_internal.mjs +5 -5
- package/dist/hooks/use-copilot-readable.d.ts +1 -1
- package/dist/hooks/use-copilot-readable.js +29 -5
- package/dist/hooks/use-copilot-readable.js.map +1 -1
- package/dist/hooks/use-copilot-readable.mjs +1 -1
- package/dist/hooks/use-default-tool.js +5 -1
- package/dist/hooks/use-default-tool.js.map +1 -1
- package/dist/hooks/use-default-tool.mjs +3 -3
- package/dist/hooks/use-frontend-tool.js +5 -1
- package/dist/hooks/use-frontend-tool.js.map +1 -1
- package/dist/hooks/use-frontend-tool.mjs +1 -1
- package/dist/hooks/use-langgraph-interrupt-render.js +77 -13
- package/dist/hooks/use-langgraph-interrupt-render.js.map +1 -1
- package/dist/hooks/use-langgraph-interrupt-render.mjs +3 -2
- package/dist/hooks/use-langgraph-interrupt.d.ts +1 -1
- package/dist/hooks/use-langgraph-interrupt.js +3 -3
- package/dist/hooks/use-langgraph-interrupt.js.map +1 -1
- package/dist/hooks/use-langgraph-interrupt.mjs +2 -2
- package/dist/hooks/use-make-copilot-document-readable.js +1 -1
- package/dist/hooks/use-make-copilot-document-readable.js.map +1 -1
- package/dist/hooks/use-make-copilot-document-readable.mjs +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +273 -246
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +34 -33
- package/dist/lib/copilot-task.d.ts +1 -1
- package/dist/lib/copilot-task.js.map +1 -1
- package/dist/lib/copilot-task.mjs +10 -10
- package/dist/lib/index.d.ts +1 -1
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +10 -10
- package/dist/types/index.d.ts +1 -1
- package/dist/types/interrupt-action.d.ts +1 -1
- package/dist/types/interrupt-action.js.map +1 -1
- package/dist/utils/index.mjs +3 -3
- package/dist/v2/index.css +4 -0
- package/dist/v2/index.css.map +1 -0
- package/dist/v2/index.js.map +1 -1
- package/dist/v2/index.mjs +2 -0
- package/dist/v2/index.mjs.map +1 -1
- package/jest.config.js +12 -0
- package/package.json +27 -24
- package/src/components/CopilotListeners.tsx +1 -2
- package/src/components/copilot-provider/copilot-messages.tsx +0 -41
- package/src/components/copilot-provider/copilotkit.tsx +31 -31
- package/src/context/copilot-context.tsx +2 -2
- package/src/hooks/__tests__/use-coagent-config.test.ts +189 -129
- package/src/hooks/index.ts +2 -2
- package/src/hooks/use-agent-nodename.ts +30 -0
- package/src/hooks/use-coagent-state-render-bridge.tsx +22 -22
- package/src/hooks/use-coagent.ts +22 -13
- package/src/hooks/use-copilot-chat-suggestions.tsx +124 -0
- package/src/hooks/use-copilot-chat_internal.ts +78 -78
- package/src/hooks/use-copilot-readable.ts +30 -12
- package/src/hooks/use-frontend-tool.ts +10 -2
- package/src/hooks/use-langgraph-interrupt-render.ts +25 -7
- package/src/hooks/use-langgraph-interrupt.ts +2 -3
- package/src/types/interrupt-action.ts +2 -5
- package/src/v2/index.ts +2 -0
- package/tsup.config.ts +1 -1
- package/dist/chunk-24SCZAB4.mjs.map +0 -1
- package/dist/chunk-5X5DJRQQ.mjs.map +0 -1
- package/dist/chunk-7BYHZLPL.mjs.map +0 -1
- package/dist/chunk-CB7CRBDG.mjs +0 -48
- package/dist/chunk-CB7CRBDG.mjs.map +0 -1
- package/dist/chunk-DCHSCK62.mjs.map +0 -1
- package/dist/chunk-IUSKVYUI.mjs +0 -13
- package/dist/chunk-IUSKVYUI.mjs.map +0 -1
- package/dist/chunk-NG26QEGF.mjs.map +0 -1
- package/dist/chunk-NROJOTQP.mjs.map +0 -1
- package/dist/chunk-R4MR43UQ.mjs.map +0 -1
- package/dist/chunk-UJBV5GAG.mjs.map +0 -1
- package/dist/hooks/use-configure-chat-suggestions.js +0 -210
- package/dist/hooks/use-configure-chat-suggestions.js.map +0 -1
- package/dist/hooks/use-configure-chat-suggestions.mjs +0 -13
- package/src/hooks/use-configure-chat-suggestions.tsx +0 -85
- /package/dist/{chunk-3GURHDG7.mjs.map → chunk-4HRUQH6U.mjs.map} +0 -0
- /package/dist/{chunk-D3QSYDJR.mjs.map → chunk-7IBF6RBW.mjs.map} +0 -0
- /package/dist/{chunk-GMI4KO4X.mjs.map → chunk-7SHWECGN.mjs.map} +0 -0
- /package/dist/{chunk-OVYFRPSN.mjs.map → chunk-ABWT4DRT.mjs.map} +0 -0
- /package/dist/{chunk-JRT5BJF3.mjs.map → chunk-B5ELMVT7.mjs.map} +0 -0
- /package/dist/{chunk-TXI72QHK.mjs.map → chunk-EG56H77V.mjs.map} +0 -0
- /package/dist/{chunk-LHKZJ2ND.mjs.map → chunk-PMWUKW3Z.mjs.map} +0 -0
- /package/dist/{chunk-QU6NONOD.mjs.map → chunk-U2ZRVVKT.mjs.map} +0 -0
- /package/dist/{chunk-WMJVBMUX.mjs.map → chunk-YCG6SNAU.mjs.map} +0 -0
- /package/dist/{chunk-3R423LZT.mjs.map → chunk-YJGPIN3R.mjs.map} +0 -0
- /package/dist/{chunk-BR5YEYZJ.mjs.map → chunk-YTQHRJUA.mjs.map} +0 -0
- /package/dist/hooks/{use-configure-chat-suggestions.mjs.map → use-agent-nodename.mjs.map} +0 -0
- /package/src/v2/{styles.css → index.css} +0 -0
|
@@ -83,7 +83,7 @@ __export(use_copilot_chat_headless_c_exports, {
|
|
|
83
83
|
useCopilotChatHeadless_c: () => useCopilotChatHeadless_c
|
|
84
84
|
});
|
|
85
85
|
module.exports = __toCommonJS(use_copilot_chat_headless_c_exports);
|
|
86
|
-
var
|
|
86
|
+
var import_react15 = require("react");
|
|
87
87
|
|
|
88
88
|
// src/context/copilot-context.tsx
|
|
89
89
|
var import_react = __toESM(require("react"));
|
|
@@ -161,7 +161,7 @@ var emptyCopilotContext = {
|
|
|
161
161
|
interruptEventQueue: {},
|
|
162
162
|
addInterruptEvent: () => {
|
|
163
163
|
},
|
|
164
|
-
|
|
164
|
+
resolveInterruptEvent: () => {
|
|
165
165
|
},
|
|
166
166
|
onError: () => {
|
|
167
167
|
},
|
|
@@ -187,7 +187,7 @@ function returnAndThrowInDebug(_value) {
|
|
|
187
187
|
}
|
|
188
188
|
|
|
189
189
|
// src/hooks/use-copilot-chat_internal.ts
|
|
190
|
-
var
|
|
190
|
+
var import_react13 = require("react");
|
|
191
191
|
|
|
192
192
|
// src/components/error-boundary/error-utils.tsx
|
|
193
193
|
var import_react3 = require("react");
|
|
@@ -335,24 +335,60 @@ function useCoAgentStateRenders() {
|
|
|
335
335
|
}
|
|
336
336
|
|
|
337
337
|
// src/hooks/use-langgraph-interrupt-render.ts
|
|
338
|
-
var
|
|
338
|
+
var import_react7 = __toESM(require("react"));
|
|
339
339
|
var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
|
|
340
340
|
var import_shared2 = require("@copilotkit/shared");
|
|
341
|
+
|
|
342
|
+
// src/hooks/use-agent-nodename.ts
|
|
343
|
+
var import_react5 = require("react");
|
|
344
|
+
var import_react6 = require("@copilotkitnext/react");
|
|
345
|
+
function useAgentNodeName(agentName) {
|
|
346
|
+
const { agent } = (0, import_react6.useAgent)({ agentId: agentName });
|
|
347
|
+
const nodeNameRef = (0, import_react5.useRef)("start");
|
|
348
|
+
(0, import_react5.useEffect)(() => {
|
|
349
|
+
if (!agent)
|
|
350
|
+
return;
|
|
351
|
+
const subscriber = {
|
|
352
|
+
onStepStartedEvent: ({ event }) => {
|
|
353
|
+
nodeNameRef.current = event.stepName;
|
|
354
|
+
},
|
|
355
|
+
onRunStartedEvent: () => {
|
|
356
|
+
nodeNameRef.current = "start";
|
|
357
|
+
},
|
|
358
|
+
onRunFinishedEvent: () => {
|
|
359
|
+
nodeNameRef.current = "end";
|
|
360
|
+
}
|
|
361
|
+
};
|
|
362
|
+
const subscription = agent.subscribe(subscriber);
|
|
363
|
+
return () => {
|
|
364
|
+
subscription.unsubscribe();
|
|
365
|
+
};
|
|
366
|
+
}, [agent]);
|
|
367
|
+
return nodeNameRef.current;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
// src/hooks/use-langgraph-interrupt-render.ts
|
|
371
|
+
var import_react8 = require("@copilotkitnext/react");
|
|
341
372
|
var InterruptRenderer = ({ event, result, render, resolve }) => {
|
|
342
373
|
return render({ event, result, resolve });
|
|
343
374
|
};
|
|
344
375
|
function useLangGraphInterruptRender(agent) {
|
|
376
|
+
var _a;
|
|
345
377
|
const {
|
|
346
378
|
interruptActions,
|
|
347
379
|
agentSession,
|
|
348
380
|
threadId,
|
|
349
381
|
interruptEventQueue,
|
|
350
382
|
addInterruptEvent,
|
|
351
|
-
|
|
383
|
+
resolveInterruptEvent
|
|
352
384
|
} = useCopilotContext();
|
|
353
|
-
(0,
|
|
385
|
+
const existingConfig = (0, import_react8.useCopilotChatConfiguration)();
|
|
386
|
+
const resolvedAgentId = (_a = existingConfig == null ? void 0 : existingConfig.agentId) != null ? _a : "default";
|
|
387
|
+
const nodeName = useAgentNodeName(resolvedAgentId);
|
|
388
|
+
(0, import_react7.useEffect)(() => {
|
|
354
389
|
if (!agent)
|
|
355
390
|
return;
|
|
391
|
+
let localInterrupt = null;
|
|
356
392
|
const subscriber = {
|
|
357
393
|
onCustomEvent: ({ event }) => {
|
|
358
394
|
if (event.name === "on_interrupt") {
|
|
@@ -361,12 +397,21 @@ function useLangGraphInterruptRender(agent) {
|
|
|
361
397
|
type: event.type,
|
|
362
398
|
value: (0, import_shared2.parseJson)(event.value, event.value)
|
|
363
399
|
};
|
|
364
|
-
const eventId = (0, import_shared2.dataToUUID)(
|
|
365
|
-
|
|
400
|
+
const eventId = (0, import_shared2.dataToUUID)(eventData, "interruptEvents");
|
|
401
|
+
localInterrupt = {
|
|
366
402
|
eventId,
|
|
367
403
|
threadId,
|
|
368
404
|
event: eventData
|
|
369
|
-
}
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
},
|
|
408
|
+
onRunStartedEvent: () => {
|
|
409
|
+
localInterrupt = null;
|
|
410
|
+
},
|
|
411
|
+
onRunFinalized: () => {
|
|
412
|
+
if (localInterrupt) {
|
|
413
|
+
addInterruptEvent(localInterrupt);
|
|
414
|
+
localInterrupt = null;
|
|
370
415
|
}
|
|
371
416
|
}
|
|
372
417
|
};
|
|
@@ -375,7 +420,7 @@ function useLangGraphInterruptRender(agent) {
|
|
|
375
420
|
unsubscribe();
|
|
376
421
|
};
|
|
377
422
|
}, [agent, threadId]);
|
|
378
|
-
const handleResolve = (0,
|
|
423
|
+
const handleResolve = (0, import_react7.useCallback)(
|
|
379
424
|
(eventId, response) => {
|
|
380
425
|
agent == null ? void 0 : agent.runAgent({
|
|
381
426
|
forwardedProps: {
|
|
@@ -384,15 +429,15 @@ function useLangGraphInterruptRender(agent) {
|
|
|
384
429
|
}
|
|
385
430
|
}
|
|
386
431
|
});
|
|
387
|
-
|
|
432
|
+
resolveInterruptEvent(threadId, eventId, response != null ? response : "");
|
|
388
433
|
},
|
|
389
434
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
390
435
|
[agent, threadId]
|
|
391
436
|
);
|
|
392
|
-
return (0,
|
|
437
|
+
return (0, import_react7.useMemo)(() => {
|
|
393
438
|
const eventQueue = interruptEventQueue[threadId] || [];
|
|
394
439
|
const currentQueuedEvent = eventQueue.find((qe) => !qe.event.response);
|
|
395
|
-
if (!currentQueuedEvent)
|
|
440
|
+
if (!currentQueuedEvent || !agentSession)
|
|
396
441
|
return null;
|
|
397
442
|
const allActions = Object.values(interruptActions);
|
|
398
443
|
const matchingAction = allActions.find((action) => {
|
|
@@ -400,7 +445,9 @@ function useLangGraphInterruptRender(agent) {
|
|
|
400
445
|
return true;
|
|
401
446
|
return action.enabled({
|
|
402
447
|
eventValue: currentQueuedEvent.event.value,
|
|
403
|
-
agentMetadata: agentSession
|
|
448
|
+
agentMetadata: __spreadProps(__spreadValues({}, agentSession), {
|
|
449
|
+
nodeName
|
|
450
|
+
})
|
|
404
451
|
});
|
|
405
452
|
});
|
|
406
453
|
if (!matchingAction)
|
|
@@ -418,7 +465,7 @@ function useLangGraphInterruptRender(agent) {
|
|
|
418
465
|
}
|
|
419
466
|
if (!render)
|
|
420
467
|
return null;
|
|
421
|
-
return
|
|
468
|
+
return import_react7.default.createElement(InterruptRenderer, {
|
|
422
469
|
event: currentQueuedEvent.event,
|
|
423
470
|
result,
|
|
424
471
|
render,
|
|
@@ -428,14 +475,14 @@ function useLangGraphInterruptRender(agent) {
|
|
|
428
475
|
}
|
|
429
476
|
|
|
430
477
|
// src/hooks/use-copilot-chat_internal.ts
|
|
431
|
-
var
|
|
478
|
+
var import_react14 = require("@copilotkitnext/react");
|
|
432
479
|
|
|
433
480
|
// src/hooks/use-lazy-tool-renderer.tsx
|
|
434
|
-
var
|
|
435
|
-
var
|
|
481
|
+
var import_react9 = require("@copilotkitnext/react");
|
|
482
|
+
var import_react10 = require("react");
|
|
436
483
|
function useLazyToolRenderer() {
|
|
437
|
-
const renderToolCall = (0,
|
|
438
|
-
return (0,
|
|
484
|
+
const renderToolCall = (0, import_react9.useRenderToolCall)();
|
|
485
|
+
return (0, import_react10.useCallback)(
|
|
439
486
|
(message, messages) => {
|
|
440
487
|
var _a;
|
|
441
488
|
if (!((_a = message == null ? void 0 : message.toolCalls) == null ? void 0 : _a.length))
|
|
@@ -455,39 +502,7 @@ function useLazyToolRenderer() {
|
|
|
455
502
|
);
|
|
456
503
|
}
|
|
457
504
|
|
|
458
|
-
//
|
|
459
|
-
var import_react8 = require("@copilotkitnext/react");
|
|
460
|
-
var import_react9 = require("react");
|
|
461
|
-
function useConfigureChatSuggestions(config, dependencies = []) {
|
|
462
|
-
const { agentSession } = useCopilotContext();
|
|
463
|
-
const { copilotkit } = (0, import_react8.useCopilotKit)();
|
|
464
|
-
const available = config.available === "enabled" ? "always" : config.available;
|
|
465
|
-
const finalSuggestionConfig = __spreadProps(__spreadValues({}, config), {
|
|
466
|
-
available,
|
|
467
|
-
consumerAgentId: agentSession == null ? void 0 : agentSession.agentName
|
|
468
|
-
// Use chatConfig.agentId here
|
|
469
|
-
});
|
|
470
|
-
(0, import_react8.useConfigureSuggestions)(finalSuggestionConfig, { deps: dependencies });
|
|
471
|
-
const result = (0, import_react8.useSuggestions)({ agentId: agentSession == null ? void 0 : agentSession.agentName });
|
|
472
|
-
(0, import_react9.useEffect)(() => {
|
|
473
|
-
if (finalSuggestionConfig.available === "disabled")
|
|
474
|
-
return;
|
|
475
|
-
const subscription = copilotkit.subscribe({
|
|
476
|
-
onAgentsChanged: () => {
|
|
477
|
-
const agent = copilotkit.getAgent(agentSession == null ? void 0 : agentSession.agentName);
|
|
478
|
-
if (agent && !agent.isRunning && !result.suggestions.length) {
|
|
479
|
-
copilotkit.reloadSuggestions(agentSession == null ? void 0 : agentSession.agentName);
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
});
|
|
483
|
-
return () => {
|
|
484
|
-
subscription.unsubscribe();
|
|
485
|
-
};
|
|
486
|
-
}, []);
|
|
487
|
-
return result;
|
|
488
|
-
}
|
|
489
|
-
|
|
490
|
-
// ../../node_modules/.pnpm/@ag-ui+core@0.0.42-alpha.1/node_modules/@ag-ui/core/dist/index.mjs
|
|
505
|
+
// ../../node_modules/.pnpm/@ag-ui+core@0.0.42/node_modules/@ag-ui/core/dist/index.mjs
|
|
491
506
|
var import_zod = require("zod");
|
|
492
507
|
var import_zod2 = require("zod");
|
|
493
508
|
var FunctionCallSchema = import_zod.z.object({
|
|
@@ -893,10 +908,12 @@ var EventSchemas = import_zod2.z.discriminatedUnion("type", [
|
|
|
893
908
|
]);
|
|
894
909
|
|
|
895
910
|
// src/hooks/use-coagent-state-render-bridge.tsx
|
|
896
|
-
var
|
|
897
|
-
var
|
|
911
|
+
var import_react11 = require("@copilotkitnext/react");
|
|
912
|
+
var import_react12 = require("react");
|
|
898
913
|
var import_shared3 = require("@copilotkit/shared");
|
|
899
914
|
function getStateWithoutConstantKeys(state) {
|
|
915
|
+
if (!state)
|
|
916
|
+
return {};
|
|
900
917
|
const _a = state, { messages, tools, copilotkit } = _a, stateWithoutConstantKeys = __objRest(_a, ["messages", "tools", "copilotkit"]);
|
|
901
918
|
return stateWithoutConstantKeys;
|
|
902
919
|
}
|
|
@@ -919,11 +936,11 @@ function useCoagentStateRenderBridge(agentId, props) {
|
|
|
919
936
|
var _a;
|
|
920
937
|
const { stateSnapshot, messageIndexInRun, message } = props;
|
|
921
938
|
const { coAgentStateRenders, claimsRef } = useCoAgentStateRenders();
|
|
922
|
-
const { agent } = (0,
|
|
923
|
-
const [nodeName, setNodeName] = (0,
|
|
939
|
+
const { agent } = (0, import_react11.useAgent)({ agentId });
|
|
940
|
+
const [nodeName, setNodeName] = (0, import_react12.useState)(void 0);
|
|
924
941
|
const runId = (_a = props.runId) != null ? _a : message.runId;
|
|
925
942
|
const effectiveRunId = runId || "pending";
|
|
926
|
-
(0,
|
|
943
|
+
(0, import_react12.useEffect)(() => {
|
|
927
944
|
if (!agent)
|
|
928
945
|
return;
|
|
929
946
|
const subscriber = {
|
|
@@ -943,10 +960,7 @@ function useCoagentStateRenderBridge(agentId, props) {
|
|
|
943
960
|
unsubscribe();
|
|
944
961
|
};
|
|
945
962
|
}, [agentId, nodeName]);
|
|
946
|
-
|
|
947
|
-
return null;
|
|
948
|
-
}
|
|
949
|
-
const getStateRender = (0, import_react11.useCallback)(
|
|
963
|
+
const getStateRender = (0, import_react12.useCallback)(
|
|
950
964
|
(messageId) => {
|
|
951
965
|
return Object.entries(coAgentStateRenders).find(([stateRenderId, stateRender]) => {
|
|
952
966
|
if (claimsRef.current[messageId]) {
|
|
@@ -973,7 +987,7 @@ function useCoagentStateRenderBridge(agentId, props) {
|
|
|
973
987
|
return canRender;
|
|
974
988
|
}
|
|
975
989
|
const renderClaimedByOtherMessage = Object.values(claimsRef.current).find(
|
|
976
|
-
(c) => c.stateRenderId === stateRenderId && (0, import_shared3.dataToUUID)(
|
|
990
|
+
(c) => c.stateRenderId === stateRenderId && (0, import_shared3.dataToUUID)(getStateWithoutConstantKeys(c.stateSnapshot)) === (0, import_shared3.dataToUUID)(getStateWithoutConstantKeys(renderSnapshot))
|
|
977
991
|
);
|
|
978
992
|
if (renderClaimedByOtherMessage) {
|
|
979
993
|
if (renderSnapshot && renderClaimedByOtherMessage.stateSnapshot && !areStatesEquals(renderClaimedByOtherMessage.stateSnapshot, renderSnapshot)) {
|
|
@@ -988,8 +1002,11 @@ function useCoagentStateRenderBridge(agentId, props) {
|
|
|
988
1002
|
claimsRef.current[messageId] = { stateRenderId, runId: runId2 };
|
|
989
1003
|
return true;
|
|
990
1004
|
};
|
|
991
|
-
return (0,
|
|
1005
|
+
return (0, import_react12.useMemo)(() => {
|
|
992
1006
|
var _a2, _b, _c;
|
|
1007
|
+
if (messageIndexInRun !== 0) {
|
|
1008
|
+
return null;
|
|
1009
|
+
}
|
|
993
1010
|
const [stateRenderId, stateRender] = (_a2 = getStateRender(message.id)) != null ? _a2 : [];
|
|
994
1011
|
if (!stateRender || !stateRenderId) {
|
|
995
1012
|
return null;
|
|
@@ -1036,7 +1053,8 @@ function useCoagentStateRenderBridge(agentId, props) {
|
|
|
1036
1053
|
agent == null ? void 0 : agent.isRunning,
|
|
1037
1054
|
nodeName,
|
|
1038
1055
|
effectiveRunId,
|
|
1039
|
-
message.id
|
|
1056
|
+
message.id,
|
|
1057
|
+
messageIndexInRun
|
|
1040
1058
|
]);
|
|
1041
1059
|
}
|
|
1042
1060
|
function CoAgentStateRenderBridge(props) {
|
|
@@ -1044,35 +1062,17 @@ function CoAgentStateRenderBridge(props) {
|
|
|
1044
1062
|
}
|
|
1045
1063
|
|
|
1046
1064
|
// src/hooks/use-copilot-chat_internal.ts
|
|
1047
|
-
function useConfigureSuggestions2(suggestions) {
|
|
1048
|
-
let suggestionsConfig;
|
|
1049
|
-
if (Array.isArray(suggestions)) {
|
|
1050
|
-
suggestionsConfig = {
|
|
1051
|
-
suggestions,
|
|
1052
|
-
available: "always"
|
|
1053
|
-
};
|
|
1054
|
-
} else if (suggestions === "auto") {
|
|
1055
|
-
suggestionsConfig = {
|
|
1056
|
-
available: suggestions === "auto" ? "always" : "disabled",
|
|
1057
|
-
instructions: "Suggest what the user could say next. Provide clear, highly relevant suggestions. Do not literally suggest function calls."
|
|
1058
|
-
};
|
|
1059
|
-
} else {
|
|
1060
|
-
suggestionsConfig = { available: "disabled" };
|
|
1061
|
-
}
|
|
1062
|
-
useConfigureChatSuggestions(suggestionsConfig);
|
|
1063
|
-
}
|
|
1064
1065
|
function useCopilotChatInternal({
|
|
1065
1066
|
suggestions
|
|
1066
1067
|
} = {}) {
|
|
1067
|
-
var _a, _b, _c
|
|
1068
|
-
const { copilotkit } = (0,
|
|
1068
|
+
var _a, _b, _c;
|
|
1069
|
+
const { copilotkit } = (0, import_react14.useCopilotKit)();
|
|
1069
1070
|
const { threadId, agentSession } = useCopilotContext();
|
|
1070
|
-
const existingConfig = (0,
|
|
1071
|
-
const [agentAvailable, setAgentAvailable] = (0,
|
|
1072
|
-
|
|
1073
|
-
const
|
|
1074
|
-
|
|
1075
|
-
(0, import_react12.useEffect)(() => {
|
|
1071
|
+
const existingConfig = (0, import_react14.useCopilotChatConfiguration)();
|
|
1072
|
+
const [agentAvailable, setAgentAvailable] = (0, import_react13.useState)(false);
|
|
1073
|
+
const resolvedAgentId = (_a = existingConfig == null ? void 0 : existingConfig.agentId) != null ? _a : "default";
|
|
1074
|
+
const { agent } = (0, import_react14.useAgent)({ agentId: resolvedAgentId });
|
|
1075
|
+
(0, import_react13.useEffect)(() => {
|
|
1076
1076
|
const connect = (agent2) => __async(this, null, function* () {
|
|
1077
1077
|
setAgentAvailable(false);
|
|
1078
1078
|
try {
|
|
@@ -1097,7 +1097,7 @@ function useCopilotChatInternal({
|
|
|
1097
1097
|
agent == null ? void 0 : agent.setMessages([]);
|
|
1098
1098
|
agent == null ? void 0 : agent.setState(null);
|
|
1099
1099
|
};
|
|
1100
|
-
const deleteMessage = (0,
|
|
1100
|
+
const deleteMessage = (0, import_react13.useCallback)(
|
|
1101
1101
|
(messageId) => {
|
|
1102
1102
|
var _a2;
|
|
1103
1103
|
const filteredMessages = ((_a2 = agent == null ? void 0 : agent.messages) != null ? _a2 : []).filter(
|
|
@@ -1108,13 +1108,13 @@ function useCopilotChatInternal({
|
|
|
1108
1108
|
[agent == null ? void 0 : agent.setMessages, agent == null ? void 0 : agent.messages]
|
|
1109
1109
|
);
|
|
1110
1110
|
const latestDelete = useUpdatedRef(deleteMessage);
|
|
1111
|
-
const latestDeleteFunc = (0,
|
|
1111
|
+
const latestDeleteFunc = (0, import_react13.useCallback)(
|
|
1112
1112
|
(messageId) => {
|
|
1113
1113
|
return latestDelete.current(messageId);
|
|
1114
1114
|
},
|
|
1115
1115
|
[latestDelete]
|
|
1116
1116
|
);
|
|
1117
|
-
const currentSuggestions = (0,
|
|
1117
|
+
const currentSuggestions = (0, import_react14.useSuggestions)({ agentId: resolvedAgentId });
|
|
1118
1118
|
const reload = useAsyncCallback(
|
|
1119
1119
|
(reloadMessageId) => __async(this, null, function* () {
|
|
1120
1120
|
var _a2;
|
|
@@ -1181,16 +1181,15 @@ function useCopilotChatInternal({
|
|
|
1181
1181
|
}),
|
|
1182
1182
|
[latestSendMessageFunc]
|
|
1183
1183
|
);
|
|
1184
|
-
const
|
|
1185
|
-
const latestSetMessagesFunc = (0, import_react12.useCallback)(
|
|
1184
|
+
const latestSetMessagesFunc = (0, import_react13.useCallback)(
|
|
1186
1185
|
(messages) => {
|
|
1187
1186
|
var _a2, _b2;
|
|
1188
1187
|
if (messages.every((message) => message instanceof import_runtime_client_gql2.Message)) {
|
|
1189
|
-
return (_a2 =
|
|
1188
|
+
return (_a2 = agent == null ? void 0 : agent.setMessages) == null ? void 0 : _a2.call(agent, (0, import_runtime_client_gql2.gqlToAGUI)(messages));
|
|
1190
1189
|
}
|
|
1191
|
-
return (_b2 =
|
|
1190
|
+
return (_b2 = agent == null ? void 0 : agent.setMessages) == null ? void 0 : _b2.call(agent, messages);
|
|
1192
1191
|
},
|
|
1193
|
-
[
|
|
1192
|
+
[agent == null ? void 0 : agent.setMessages, agent]
|
|
1194
1193
|
);
|
|
1195
1194
|
const latestReload = useUpdatedRef(reload);
|
|
1196
1195
|
const latestReloadFunc = useAsyncCallback(
|
|
@@ -1199,25 +1198,24 @@ function useCopilotChatInternal({
|
|
|
1199
1198
|
}),
|
|
1200
1199
|
[latestReload]
|
|
1201
1200
|
);
|
|
1202
|
-
const
|
|
1203
|
-
const latestStopFunc = (0, import_react12.useCallback)(() => {
|
|
1201
|
+
const latestStopFunc = (0, import_react13.useCallback)(() => {
|
|
1204
1202
|
var _a2;
|
|
1205
|
-
return (_a2 =
|
|
1206
|
-
}, [
|
|
1203
|
+
return (_a2 = agent == null ? void 0 : agent.abortRun) == null ? void 0 : _a2.call(agent);
|
|
1204
|
+
}, [agent == null ? void 0 : agent.abortRun]);
|
|
1207
1205
|
const latestReset = useUpdatedRef(reset);
|
|
1208
|
-
const latestResetFunc = (0,
|
|
1206
|
+
const latestResetFunc = (0, import_react13.useCallback)(() => {
|
|
1209
1207
|
return latestReset.current();
|
|
1210
1208
|
}, [latestReset]);
|
|
1211
1209
|
const lazyToolRendered = useLazyToolRenderer();
|
|
1212
|
-
const renderCustomMessage = (0,
|
|
1210
|
+
const renderCustomMessage = (0, import_react14.useRenderCustomMessages)();
|
|
1213
1211
|
const legacyCustomMessageRenderer = useLegacyCoagentRenderer({
|
|
1214
1212
|
copilotkit,
|
|
1215
1213
|
agent,
|
|
1216
1214
|
agentId: resolvedAgentId,
|
|
1217
|
-
threadId: (
|
|
1215
|
+
threadId: (_b = existingConfig == null ? void 0 : existingConfig.threadId) != null ? _b : threadId
|
|
1218
1216
|
});
|
|
1219
|
-
const allMessages = (
|
|
1220
|
-
const resolvedMessages = (0,
|
|
1217
|
+
const allMessages = (_c = agent == null ? void 0 : agent.messages) != null ? _c : [];
|
|
1218
|
+
const resolvedMessages = (0, import_react13.useMemo)(() => {
|
|
1221
1219
|
let processedMessages = allMessages.map((message) => {
|
|
1222
1220
|
if (message.role !== "assistant") {
|
|
1223
1221
|
return message;
|
|
@@ -1245,33 +1243,24 @@ function useCopilotChatInternal({
|
|
|
1245
1243
|
return message;
|
|
1246
1244
|
});
|
|
1247
1245
|
const hasAssistantMessages = processedMessages.some((msg) => msg.role === "assistant");
|
|
1248
|
-
if (legacyCustomMessageRenderer && !hasAssistantMessages) {
|
|
1249
|
-
const placeholderId = `coagent-state-render-${resolvedAgentId}`;
|
|
1250
|
-
const placeholderMessage = {
|
|
1251
|
-
id: placeholderId,
|
|
1252
|
-
role: "assistant",
|
|
1253
|
-
content: "",
|
|
1254
|
-
name: "coagent-state-render"
|
|
1255
|
-
};
|
|
1256
|
-
processedMessages = [
|
|
1257
|
-
...processedMessages,
|
|
1258
|
-
__spreadProps(__spreadValues({}, placeholderMessage), {
|
|
1259
|
-
generativeUI: () => legacyCustomMessageRenderer({
|
|
1260
|
-
message: placeholderMessage,
|
|
1261
|
-
position: "before"
|
|
1262
|
-
})
|
|
1263
|
-
})
|
|
1264
|
-
];
|
|
1265
|
-
}
|
|
1266
1246
|
return processedMessages;
|
|
1267
1247
|
}, [
|
|
1268
1248
|
agent == null ? void 0 : agent.messages,
|
|
1269
1249
|
lazyToolRendered,
|
|
1270
1250
|
allMessages,
|
|
1271
1251
|
renderCustomMessage,
|
|
1272
|
-
legacyCustomMessageRenderer,
|
|
1252
|
+
// legacyCustomMessageRenderer,
|
|
1273
1253
|
resolvedAgentId
|
|
1274
1254
|
]);
|
|
1255
|
+
const renderedSuggestions = (0, import_react13.useMemo)(() => {
|
|
1256
|
+
if (Array.isArray(suggestions)) {
|
|
1257
|
+
return {
|
|
1258
|
+
suggestions: suggestions.map((s) => __spreadProps(__spreadValues({}, s), { isLoading: false })),
|
|
1259
|
+
isLoading: false
|
|
1260
|
+
};
|
|
1261
|
+
}
|
|
1262
|
+
return currentSuggestions;
|
|
1263
|
+
}, [suggestions, currentSuggestions]);
|
|
1275
1264
|
return {
|
|
1276
1265
|
messages: resolvedMessages,
|
|
1277
1266
|
sendMessage: latestSendMessageFunc,
|
|
@@ -1281,25 +1270,25 @@ function useCopilotChatInternal({
|
|
|
1281
1270
|
stopGeneration: latestStopFunc,
|
|
1282
1271
|
reset: latestResetFunc,
|
|
1283
1272
|
deleteMessage: latestDeleteFunc,
|
|
1284
|
-
isAvailable:
|
|
1273
|
+
isAvailable: agentAvailable,
|
|
1285
1274
|
isLoading: Boolean(agent == null ? void 0 : agent.isRunning),
|
|
1286
1275
|
// mcpServers,
|
|
1287
1276
|
// setMcpServers,
|
|
1288
|
-
suggestions:
|
|
1277
|
+
suggestions: renderedSuggestions.suggestions,
|
|
1289
1278
|
setSuggestions: (suggestions2) => copilotkit.addSuggestionsConfig({ suggestions: suggestions2 }),
|
|
1290
1279
|
generateSuggestions: () => __async(this, null, function* () {
|
|
1291
1280
|
return copilotkit.reloadSuggestions(resolvedAgentId);
|
|
1292
1281
|
}),
|
|
1293
1282
|
resetSuggestions: () => copilotkit.clearSuggestions(resolvedAgentId),
|
|
1294
|
-
isLoadingSuggestions:
|
|
1283
|
+
isLoadingSuggestions: renderedSuggestions.isLoading,
|
|
1295
1284
|
interrupt,
|
|
1296
1285
|
agent,
|
|
1297
1286
|
threadId
|
|
1298
1287
|
};
|
|
1299
1288
|
}
|
|
1300
1289
|
function useUpdatedRef(value) {
|
|
1301
|
-
const ref = (0,
|
|
1302
|
-
(0,
|
|
1290
|
+
const ref = (0, import_react13.useRef)(value);
|
|
1291
|
+
(0, import_react13.useEffect)(() => {
|
|
1303
1292
|
ref.current = value;
|
|
1304
1293
|
}, [value]);
|
|
1305
1294
|
return ref;
|
|
@@ -1310,20 +1299,19 @@ function useLegacyCoagentRenderer({
|
|
|
1310
1299
|
agentId,
|
|
1311
1300
|
threadId
|
|
1312
1301
|
}) {
|
|
1313
|
-
return (0,
|
|
1302
|
+
return (0, import_react13.useMemo)(() => {
|
|
1314
1303
|
if (!copilotkit || !agent) {
|
|
1315
1304
|
return null;
|
|
1316
1305
|
}
|
|
1317
1306
|
return ({ message, position }) => {
|
|
1318
1307
|
var _a;
|
|
1319
1308
|
const effectiveThreadId = (_a = threadId != null ? threadId : agent.threadId) != null ? _a : "default";
|
|
1320
|
-
const existingRunId = copilotkit.getRunIdForMessage(
|
|
1321
|
-
agentId,
|
|
1322
|
-
effectiveThreadId,
|
|
1323
|
-
message.id
|
|
1324
|
-
);
|
|
1309
|
+
const existingRunId = copilotkit.getRunIdForMessage(agentId, effectiveThreadId, message.id);
|
|
1325
1310
|
const runId = existingRunId || `pending:${message.id}`;
|
|
1326
|
-
const messageIndex = Math.max(
|
|
1311
|
+
const messageIndex = Math.max(
|
|
1312
|
+
agent.messages.findIndex((msg) => msg.id === message.id),
|
|
1313
|
+
0
|
|
1314
|
+
);
|
|
1327
1315
|
const bridgeProps = {
|
|
1328
1316
|
message,
|
|
1329
1317
|
position,
|
|
@@ -1334,7 +1322,7 @@ function useLegacyCoagentRenderer({
|
|
|
1334
1322
|
agentId,
|
|
1335
1323
|
stateSnapshot: message.state
|
|
1336
1324
|
};
|
|
1337
|
-
return (0,
|
|
1325
|
+
return (0, import_react13.createElement)(CoAgentStateRenderBridge, bridgeProps);
|
|
1338
1326
|
};
|
|
1339
1327
|
}, [agent, agentId, copilotkit, threadId]);
|
|
1340
1328
|
}
|
|
@@ -1406,7 +1394,7 @@ function useCopilotChatHeadless_c(options = {}) {
|
|
|
1406
1394
|
const { copilotApiConfig, setBannerError } = useCopilotContext();
|
|
1407
1395
|
const hasPublicApiKey = Boolean(copilotApiConfig.publicApiKey);
|
|
1408
1396
|
const internalResult = useCopilotChatInternal(options);
|
|
1409
|
-
(0,
|
|
1397
|
+
(0, import_react15.useEffect)(() => {
|
|
1410
1398
|
if (!hasPublicApiKey) {
|
|
1411
1399
|
setBannerError(
|
|
1412
1400
|
new import_shared4.CopilotKitError({
|