@copilotkit/react-core 1.1.3-feat-runtime-remote-actions.2 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -21
- package/dist/chunk-5JB4B2SV.mjs +1 -0
- package/dist/{chunk-VCEOT4GG.mjs → chunk-AIW2RAN2.mjs} +6 -35
- package/dist/chunk-AIW2RAN2.mjs.map +1 -0
- package/dist/{chunk-RBNULK3U.mjs → chunk-CFCRJA63.mjs} +5 -39
- package/dist/chunk-CFCRJA63.mjs.map +1 -0
- package/dist/{chunk-3U22BXKC.mjs → chunk-EVK5346D.mjs} +3 -4
- package/dist/chunk-EVK5346D.mjs.map +1 -0
- package/dist/{chunk-A37GANOW.mjs → chunk-GSL4ZHUB.mjs} +4 -4
- package/dist/chunk-GSL4ZHUB.mjs.map +1 -0
- package/dist/{chunk-TCZBK3HZ.mjs → chunk-HUC6EZVP.mjs} +4 -7
- package/dist/chunk-HUC6EZVP.mjs.map +1 -0
- package/dist/{chunk-CODXG6KU.mjs → chunk-LB53QWLY.mjs} +2 -2
- package/dist/{chunk-J2YXDQHR.mjs → chunk-LB7ULLSU.mjs} +3 -14
- package/dist/chunk-LB7ULLSU.mjs.map +1 -0
- package/dist/{chunk-RWPGGPW5.mjs → chunk-PZOEBYWP.mjs} +11 -63
- package/dist/chunk-PZOEBYWP.mjs.map +1 -0
- package/dist/{chunk-326LK7LX.mjs → chunk-QR4XKQOA.mjs} +2 -2
- package/dist/components/copilot-provider/copilotkit-props.d.ts +0 -4
- package/dist/components/copilot-provider/copilotkit-props.js.map +1 -1
- package/dist/components/copilot-provider/copilotkit.js +5 -50
- package/dist/components/copilot-provider/copilotkit.js.map +1 -1
- package/dist/components/copilot-provider/copilotkit.mjs +2 -2
- package/dist/components/copilot-provider/index.js +5 -50
- package/dist/components/copilot-provider/index.js.map +1 -1
- package/dist/components/copilot-provider/index.mjs +2 -2
- package/dist/components/index.js +5 -50
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +2 -2
- package/dist/context/copilot-context.d.ts +2 -21
- package/dist/context/copilot-context.js +2 -13
- package/dist/context/copilot-context.js.map +1 -1
- package/dist/context/copilot-context.mjs +1 -1
- package/dist/context/index.d.ts +0 -2
- package/dist/context/index.js +2 -13
- package/dist/context/index.js.map +1 -1
- package/dist/context/index.mjs +1 -1
- package/dist/hooks/index.d.ts +0 -4
- package/dist/hooks/index.js +21 -224
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +8 -17
- package/dist/hooks/use-chat.d.ts +4 -26
- package/dist/hooks/use-chat.js +9 -58
- package/dist/hooks/use-chat.js.map +1 -1
- package/dist/hooks/use-chat.mjs +1 -1
- package/dist/hooks/use-copilot-action.js +4 -15
- package/dist/hooks/use-copilot-action.js.map +1 -1
- package/dist/hooks/use-copilot-action.mjs +2 -2
- package/dist/hooks/use-copilot-chat.js +13 -101
- package/dist/hooks/use-copilot-chat.js.map +1 -1
- package/dist/hooks/use-copilot-chat.mjs +4 -4
- package/dist/hooks/use-copilot-readable.js +2 -13
- package/dist/hooks/use-copilot-readable.js.map +1 -1
- package/dist/hooks/use-copilot-readable.mjs +2 -2
- package/dist/hooks/use-make-copilot-document-readable.js +2 -13
- 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 +0 -4
- package/dist/index.js +31 -268
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +12 -20
- package/dist/lib/copilot-task.d.ts +0 -2
- package/dist/lib/copilot-task.js +1 -1
- package/dist/lib/copilot-task.js.map +1 -1
- package/dist/lib/copilot-task.mjs +3 -3
- package/dist/lib/index.d.ts +0 -2
- package/dist/lib/index.js +1 -1
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +3 -3
- package/dist/utils/extract.d.ts +0 -2
- package/dist/utils/extract.js +1 -1
- package/dist/utils/extract.js.map +1 -1
- package/dist/utils/extract.mjs +3 -3
- package/dist/utils/index.d.ts +0 -2
- package/dist/utils/index.js +1 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/index.mjs +3 -3
- package/package.json +5 -5
- package/src/components/copilot-provider/copilotkit-props.tsx +0 -5
- package/src/components/copilot-provider/copilotkit.tsx +3 -45
- package/src/context/copilot-context.tsx +2 -39
- package/src/hooks/index.ts +0 -2
- package/src/hooks/use-chat.ts +11 -111
- package/src/hooks/use-copilot-action.ts +2 -2
- package/src/hooks/use-copilot-chat.ts +0 -31
- package/src/lib/copilot-task.ts +1 -2
- package/src/utils/extract.ts +2 -7
- package/dist/chunk-3U22BXKC.mjs.map +0 -1
- package/dist/chunk-A37GANOW.mjs.map +0 -1
- package/dist/chunk-BWYAGPEF.mjs +0 -1
- package/dist/chunk-J2YXDQHR.mjs.map +0 -1
- package/dist/chunk-Q4TTTAXQ.mjs +0 -87
- package/dist/chunk-Q4TTTAXQ.mjs.map +0 -1
- package/dist/chunk-RBNULK3U.mjs.map +0 -1
- package/dist/chunk-RWPGGPW5.mjs.map +0 -1
- package/dist/chunk-STUXJ3BN.mjs +0 -44
- package/dist/chunk-STUXJ3BN.mjs.map +0 -1
- package/dist/chunk-TCZBK3HZ.mjs.map +0 -1
- package/dist/chunk-VCEOT4GG.mjs.map +0 -1
- package/dist/hooks/use-coagent-action.d.ts +0 -5
- package/dist/hooks/use-coagent-action.js +0 -156
- package/dist/hooks/use-coagent-action.js.map +0 -1
- package/dist/hooks/use-coagent-action.mjs +0 -9
- package/dist/hooks/use-coagent-action.mjs.map +0 -1
- package/dist/hooks/use-coagent.d.ts +0 -27
- package/dist/hooks/use-coagent.js +0 -219
- package/dist/hooks/use-coagent.js.map +0 -1
- package/dist/hooks/use-coagent.mjs +0 -10
- package/dist/hooks/use-coagent.mjs.map +0 -1
- package/dist/types/coagent-action.d.ts +0 -17
- 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/src/hooks/use-coagent-action.ts +0 -44
- package/src/hooks/use-coagent.ts +0 -133
- package/src/types/coagent-action.ts +0 -17
- package/src/types/coagent-state.ts +0 -9
- /package/dist/{chunk-BWYAGPEF.mjs.map → chunk-5JB4B2SV.mjs.map} +0 -0
- /package/dist/{chunk-CODXG6KU.mjs.map → chunk-LB53QWLY.mjs.map} +0 -0
- /package/dist/{chunk-326LK7LX.mjs.map → chunk-QR4XKQOA.mjs.map} +0 -0
package/dist/index.js
CHANGED
|
@@ -86,8 +86,6 @@ __export(src_exports, {
|
|
|
86
86
|
CopilotTask: () => CopilotTask,
|
|
87
87
|
defaultCopilotContextCategories: () => defaultCopilotContextCategories,
|
|
88
88
|
extract: () => extract,
|
|
89
|
-
useCoAgent: () => useCoAgent,
|
|
90
|
-
useCoAgentAction: () => useCoAgentAction,
|
|
91
89
|
useCopilotAction: () => useCopilotAction,
|
|
92
90
|
useCopilotChat: () => useCopilotChat,
|
|
93
91
|
useCopilotContext: () => useCopilotContext,
|
|
@@ -107,12 +105,7 @@ var emptyCopilotContext = {
|
|
|
107
105
|
},
|
|
108
106
|
removeAction: () => {
|
|
109
107
|
},
|
|
110
|
-
|
|
111
|
-
setCoagentAction: () => {
|
|
112
|
-
},
|
|
113
|
-
removeCoagentAction: () => {
|
|
114
|
-
},
|
|
115
|
-
chatComponentsCache: { current: { actions: {}, coagentActions: {} } },
|
|
108
|
+
chatComponentsCache: { current: {} },
|
|
116
109
|
getContextString: (documents, categories) => returnAndThrowInDebug(""),
|
|
117
110
|
addContext: () => "",
|
|
118
111
|
removeContext: () => {
|
|
@@ -145,13 +138,7 @@ var emptyCopilotContext = {
|
|
|
145
138
|
},
|
|
146
139
|
removeChatSuggestionConfiguration: () => {
|
|
147
140
|
},
|
|
148
|
-
showDevConsole: "auto"
|
|
149
|
-
coagentStates: {},
|
|
150
|
-
setCoagentStates: () => {
|
|
151
|
-
},
|
|
152
|
-
agentSession: null,
|
|
153
|
-
setAgentSession: () => {
|
|
154
|
-
}
|
|
141
|
+
showDevConsole: "auto"
|
|
155
142
|
};
|
|
156
143
|
var CopilotContext = import_react.default.createContext(emptyCopilotContext);
|
|
157
144
|
function useCopilotContext() {
|
|
@@ -379,11 +366,7 @@ function CopilotKit(_a) {
|
|
|
379
366
|
}
|
|
380
367
|
const chatApiEndpoint = props.runtimeUrl || import_shared3.COPILOT_CLOUD_CHAT_URL;
|
|
381
368
|
const [actions, setActions] = (0, import_react4.useState)({});
|
|
382
|
-
const
|
|
383
|
-
const chatComponentsCache = (0, import_react4.useRef)({
|
|
384
|
-
actions: {},
|
|
385
|
-
coagentActions: {}
|
|
386
|
-
});
|
|
369
|
+
const chatComponentsCache = (0, import_react4.useRef)({});
|
|
387
370
|
const { addElement, removeElement, printTree } = use_tree_default();
|
|
388
371
|
const [messages, setMessages] = (0, import_react4.useState)([]);
|
|
389
372
|
const [isLoading, setIsLoading] = (0, import_react4.useState)(false);
|
|
@@ -407,20 +390,6 @@ function CopilotKit(_a) {
|
|
|
407
390
|
return newPoints;
|
|
408
391
|
});
|
|
409
392
|
}, []);
|
|
410
|
-
const setCoagentAction = (0, import_react4.useCallback)((id, action) => {
|
|
411
|
-
setCoagentActions((prevPoints) => {
|
|
412
|
-
return __spreadProps(__spreadValues({}, prevPoints), {
|
|
413
|
-
[id]: action
|
|
414
|
-
});
|
|
415
|
-
});
|
|
416
|
-
}, []);
|
|
417
|
-
const removeCoagentAction = (0, import_react4.useCallback)((id) => {
|
|
418
|
-
setCoagentActions((prevPoints) => {
|
|
419
|
-
const newPoints = __spreadValues({}, prevPoints);
|
|
420
|
-
delete newPoints[id];
|
|
421
|
-
return newPoints;
|
|
422
|
-
});
|
|
423
|
-
}, []);
|
|
424
393
|
const getContextString = (0, import_react4.useCallback)(
|
|
425
394
|
(documents, categories) => {
|
|
426
395
|
const documentsString = documents.map((document) => {
|
|
@@ -511,14 +480,6 @@ ${nonDocumentStrings}`;
|
|
|
511
480
|
return rest;
|
|
512
481
|
});
|
|
513
482
|
};
|
|
514
|
-
const [coagentStates, setCoagentStates] = (0, import_react4.useState)({});
|
|
515
|
-
let initialAgentSession = null;
|
|
516
|
-
if (props.agent) {
|
|
517
|
-
initialAgentSession = {
|
|
518
|
-
agentName: props.agent
|
|
519
|
-
};
|
|
520
|
-
}
|
|
521
|
-
const [agentSession, setAgentSession] = (0, import_react4.useState)(initialAgentSession);
|
|
522
483
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
523
484
|
CopilotContext.Provider,
|
|
524
485
|
{
|
|
@@ -528,9 +489,6 @@ ${nonDocumentStrings}`;
|
|
|
528
489
|
getFunctionCallHandler,
|
|
529
490
|
setAction,
|
|
530
491
|
removeAction,
|
|
531
|
-
coagentActions,
|
|
532
|
-
setCoagentAction,
|
|
533
|
-
removeCoagentAction,
|
|
534
492
|
getContextString,
|
|
535
493
|
addContext,
|
|
536
494
|
removeContext,
|
|
@@ -547,11 +505,7 @@ ${nonDocumentStrings}`;
|
|
|
547
505
|
removeChatSuggestionConfiguration,
|
|
548
506
|
chatInstructions,
|
|
549
507
|
setChatInstructions,
|
|
550
|
-
showDevConsole: props.showDevConsole === void 0 ? "auto" : props.showDevConsole
|
|
551
|
-
coagentStates,
|
|
552
|
-
setCoagentStates,
|
|
553
|
-
agentSession,
|
|
554
|
-
setAgentSession
|
|
508
|
+
showDevConsole: props.showDevConsole === void 0 ? "auto" : props.showDevConsole
|
|
555
509
|
},
|
|
556
510
|
children
|
|
557
511
|
}
|
|
@@ -569,9 +523,8 @@ function entryPointsToFunctionCallHandler(actions) {
|
|
|
569
523
|
if (action) {
|
|
570
524
|
yield new Promise((resolve, reject) => {
|
|
571
525
|
(0, import_react_dom.flushSync)(() => __async(this, null, function* () {
|
|
572
|
-
var _a;
|
|
573
526
|
try {
|
|
574
|
-
result = yield
|
|
527
|
+
result = yield action.handler(args);
|
|
575
528
|
resolve();
|
|
576
529
|
} catch (error) {
|
|
577
530
|
reject(error);
|
|
@@ -602,12 +555,7 @@ function useChat(options) {
|
|
|
602
555
|
initialMessages,
|
|
603
556
|
isLoading,
|
|
604
557
|
actions,
|
|
605
|
-
onFunctionCall
|
|
606
|
-
onCoagentAction,
|
|
607
|
-
setCoagentStates,
|
|
608
|
-
coagentStates,
|
|
609
|
-
agentSession,
|
|
610
|
-
setAgentSession
|
|
558
|
+
onFunctionCall
|
|
611
559
|
} = options;
|
|
612
560
|
const abortControllerRef = (0, import_react5.useRef)();
|
|
613
561
|
const threadIdRef = (0, import_react5.useRef)(null);
|
|
@@ -636,7 +584,7 @@ function useChat(options) {
|
|
|
636
584
|
const messagesWithContext = [systemMessage, ...initialMessages || [], ...previousMessages];
|
|
637
585
|
const stream = import_runtime_client_gql.CopilotRuntimeClient.asStream(
|
|
638
586
|
runtimeClient.generateCopilotResponse({
|
|
639
|
-
data: __spreadProps(__spreadValues(
|
|
587
|
+
data: __spreadProps(__spreadValues({
|
|
640
588
|
frontend: {
|
|
641
589
|
actions: actions.map((action) => ({
|
|
642
590
|
name: action.name,
|
|
@@ -647,7 +595,7 @@ function useChat(options) {
|
|
|
647
595
|
},
|
|
648
596
|
threadId: threadIdRef.current,
|
|
649
597
|
runId: runIdRef.current,
|
|
650
|
-
messages: (0, import_runtime_client_gql.convertMessagesToGqlInput)(
|
|
598
|
+
messages: (0, import_runtime_client_gql.convertMessagesToGqlInput)(messagesWithContext)
|
|
651
599
|
}, copilotConfig.cloud ? {
|
|
652
600
|
cloud: __spreadValues({}, ((_c = (_b = (_a = copilotConfig.cloud.guardrails) == null ? void 0 : _a.input) == null ? void 0 : _b.restrictToTopic) == null ? void 0 : _c.enabled) ? {
|
|
653
601
|
guardrails: {
|
|
@@ -661,13 +609,6 @@ function useChat(options) {
|
|
|
661
609
|
metadata: {
|
|
662
610
|
requestType: import_runtime_client_gql.CopilotRequestType.Chat
|
|
663
611
|
}
|
|
664
|
-
}), agentSession ? {
|
|
665
|
-
agentSession
|
|
666
|
-
} : {}), {
|
|
667
|
-
agentStates: Object.values(coagentStates).map((state) => ({
|
|
668
|
-
agentName: state.name,
|
|
669
|
-
state: JSON.stringify(state.state)
|
|
670
|
-
}))
|
|
671
612
|
}),
|
|
672
613
|
properties: copilotConfig.properties,
|
|
673
614
|
signal: (_d = abortControllerRef.current) == null ? void 0 : _d.signal
|
|
@@ -675,8 +616,7 @@ function useChat(options) {
|
|
|
675
616
|
);
|
|
676
617
|
const guardrailsEnabled = ((_g = (_f = (_e = copilotConfig.cloud) == null ? void 0 : _e.guardrails) == null ? void 0 : _f.input) == null ? void 0 : _g.restrictToTopic.enabled) || false;
|
|
677
618
|
const reader = stream.getReader();
|
|
678
|
-
let
|
|
679
|
-
let executedCoagentActions = [];
|
|
619
|
+
let results = {};
|
|
680
620
|
try {
|
|
681
621
|
while (true) {
|
|
682
622
|
const { done, value } = yield reader.read();
|
|
@@ -688,9 +628,7 @@ function useChat(options) {
|
|
|
688
628
|
}
|
|
689
629
|
threadIdRef.current = value.generateCopilotResponse.threadId || null;
|
|
690
630
|
runIdRef.current = value.generateCopilotResponse.runId || null;
|
|
691
|
-
const messages2 = (0, import_runtime_client_gql.convertGqlOutputToMessages)(
|
|
692
|
-
(0, import_runtime_client_gql.filterAdjacentAgentStateMessages)(value.generateCopilotResponse.messages)
|
|
693
|
-
);
|
|
631
|
+
const messages2 = (0, import_runtime_client_gql.convertGqlOutputToMessages)(value.generateCopilotResponse.messages);
|
|
694
632
|
if (messages2.length === 0) {
|
|
695
633
|
continue;
|
|
696
634
|
}
|
|
@@ -706,7 +644,7 @@ function useChat(options) {
|
|
|
706
644
|
for (const message of messages2) {
|
|
707
645
|
newMessages.push(message);
|
|
708
646
|
if (message instanceof import_runtime_client_gql.ActionExecutionMessage && message.status.code !== import_runtime_client_gql.MessageStatusCode.Pending && message.scope === "client" && onFunctionCall) {
|
|
709
|
-
if (!(message.id in
|
|
647
|
+
if (!(message.id in results)) {
|
|
710
648
|
if (guardrailsEnabled && value.generateCopilotResponse.status === void 0) {
|
|
711
649
|
break;
|
|
712
650
|
}
|
|
@@ -715,50 +653,16 @@ function useChat(options) {
|
|
|
715
653
|
name: message.name,
|
|
716
654
|
args: message.arguments
|
|
717
655
|
});
|
|
718
|
-
|
|
656
|
+
results[message.id] = result;
|
|
719
657
|
}
|
|
720
658
|
newMessages.push(
|
|
721
659
|
new import_runtime_client_gql.ResultMessage({
|
|
722
|
-
result: import_runtime_client_gql.ResultMessage.encodeResult(
|
|
660
|
+
result: import_runtime_client_gql.ResultMessage.encodeResult(results[message.id]),
|
|
723
661
|
actionExecutionId: message.id,
|
|
724
662
|
actionName: message.name
|
|
725
663
|
})
|
|
726
664
|
);
|
|
727
665
|
}
|
|
728
|
-
if (message instanceof import_runtime_client_gql.AgentStateMessage && !message.active && !executedCoagentActions.includes(message.id) && onCoagentAction) {
|
|
729
|
-
if (guardrailsEnabled && value.generateCopilotResponse.status === void 0) {
|
|
730
|
-
break;
|
|
731
|
-
}
|
|
732
|
-
yield onCoagentAction({
|
|
733
|
-
name: message.agentName,
|
|
734
|
-
nodeName: message.nodeName,
|
|
735
|
-
state: message.state
|
|
736
|
-
});
|
|
737
|
-
executedCoagentActions.push(message.id);
|
|
738
|
-
}
|
|
739
|
-
}
|
|
740
|
-
const lastAgentStateMessage = [...messages2].reverse().find((message) => message instanceof import_runtime_client_gql.AgentStateMessage);
|
|
741
|
-
if (lastAgentStateMessage) {
|
|
742
|
-
if (lastAgentStateMessage.running) {
|
|
743
|
-
setCoagentStates((prevAgentStates) => __spreadProps(__spreadValues({}, prevAgentStates), {
|
|
744
|
-
[lastAgentStateMessage.agentName]: {
|
|
745
|
-
name: lastAgentStateMessage.agentName,
|
|
746
|
-
state: lastAgentStateMessage.state,
|
|
747
|
-
running: lastAgentStateMessage.running,
|
|
748
|
-
active: lastAgentStateMessage.active,
|
|
749
|
-
threadId: lastAgentStateMessage.threadId,
|
|
750
|
-
nodeName: lastAgentStateMessage.nodeName,
|
|
751
|
-
runId: lastAgentStateMessage.runId
|
|
752
|
-
}
|
|
753
|
-
}));
|
|
754
|
-
setAgentSession({
|
|
755
|
-
threadId: lastAgentStateMessage.threadId,
|
|
756
|
-
agentName: lastAgentStateMessage.agentName,
|
|
757
|
-
nodeName: lastAgentStateMessage.nodeName
|
|
758
|
-
});
|
|
759
|
-
} else {
|
|
760
|
-
setAgentSession(null);
|
|
761
|
-
}
|
|
762
666
|
}
|
|
763
667
|
}
|
|
764
668
|
if (newMessages.length > 0) {
|
|
@@ -767,7 +671,7 @@ function useChat(options) {
|
|
|
767
671
|
}
|
|
768
672
|
if (
|
|
769
673
|
// if we have client side results
|
|
770
|
-
Object.values(
|
|
674
|
+
Object.values(results).length || // or the last message we received is a result
|
|
771
675
|
newMessages.length && newMessages[newMessages.length - 1] instanceof import_runtime_client_gql.ResultMessage
|
|
772
676
|
) {
|
|
773
677
|
yield new Promise((resolve) => setTimeout(resolve, 10));
|
|
@@ -829,12 +733,7 @@ function useCopilotChat(_a = {}) {
|
|
|
829
733
|
isLoading,
|
|
830
734
|
setIsLoading,
|
|
831
735
|
chatInstructions,
|
|
832
|
-
actions
|
|
833
|
-
coagentStates,
|
|
834
|
-
setCoagentStates,
|
|
835
|
-
coagentActions,
|
|
836
|
-
agentSession,
|
|
837
|
-
setAgentSession
|
|
736
|
+
actions
|
|
838
737
|
} = useCopilotContext();
|
|
839
738
|
const latestGetContextString = useUpdatedRef(getContextString);
|
|
840
739
|
const deleteMessage = (0, import_react6.useCallback)(
|
|
@@ -851,39 +750,16 @@ function useCopilotChat(_a = {}) {
|
|
|
851
750
|
role: import_runtime_client_gql2.Role.System
|
|
852
751
|
});
|
|
853
752
|
}, [getContextString, makeSystemMessage2, chatInstructions]);
|
|
854
|
-
const onCoagentAction = (0, import_react6.useCallback)(
|
|
855
|
-
(args) => __async(this, null, function* () {
|
|
856
|
-
var _a2;
|
|
857
|
-
const { name, nodeName, state } = args;
|
|
858
|
-
let action = Object.values(coagentActions).find(
|
|
859
|
-
(action2) => action2.name === name && action2.nodeName === nodeName
|
|
860
|
-
);
|
|
861
|
-
if (!action) {
|
|
862
|
-
action = Object.values(coagentActions).find(
|
|
863
|
-
(action2) => action2.name === name && !action2.nodeName
|
|
864
|
-
);
|
|
865
|
-
}
|
|
866
|
-
if (action) {
|
|
867
|
-
yield (_a2 = action.handler) == null ? void 0 : _a2.call(action, { state, nodeName });
|
|
868
|
-
}
|
|
869
|
-
}),
|
|
870
|
-
[coagentActions]
|
|
871
|
-
);
|
|
872
753
|
const { append, reload, stop } = useChat(__spreadProps(__spreadValues({}, options), {
|
|
873
754
|
actions: Object.values(actions),
|
|
874
755
|
copilotConfig: copilotApiConfig,
|
|
875
756
|
initialMessages: options.initialMessages || [],
|
|
876
757
|
onFunctionCall: getFunctionCallHandler(),
|
|
877
|
-
onCoagentAction,
|
|
878
758
|
messages,
|
|
879
759
|
setMessages,
|
|
880
760
|
makeSystemMessageCallback,
|
|
881
761
|
isLoading,
|
|
882
|
-
setIsLoading
|
|
883
|
-
coagentStates,
|
|
884
|
-
setCoagentStates,
|
|
885
|
-
agentSession,
|
|
886
|
-
setAgentSession
|
|
762
|
+
setIsLoading
|
|
887
763
|
}));
|
|
888
764
|
const latestAppend = useUpdatedRef(append);
|
|
889
765
|
const latestAppendFunc = (0, import_react6.useCallback)(
|
|
@@ -966,7 +842,7 @@ function useCopilotAction(action, dependencies) {
|
|
|
966
842
|
actions[idRef.current].handler = action.handler;
|
|
967
843
|
if (typeof action.render === "function") {
|
|
968
844
|
if (chatComponentsCache.current !== null) {
|
|
969
|
-
chatComponentsCache.current
|
|
845
|
+
chatComponentsCache.current[action.name] = action.render;
|
|
970
846
|
}
|
|
971
847
|
}
|
|
972
848
|
}
|
|
@@ -977,7 +853,7 @@ function useCopilotAction(action, dependencies) {
|
|
|
977
853
|
}
|
|
978
854
|
setAction(idRef.current, action);
|
|
979
855
|
if (chatComponentsCache.current !== null && action.render !== void 0) {
|
|
980
|
-
chatComponentsCache.current
|
|
856
|
+
chatComponentsCache.current[action.name] = action.render;
|
|
981
857
|
}
|
|
982
858
|
return () => {
|
|
983
859
|
removeAction(idRef.current);
|
|
@@ -998,48 +874,12 @@ function useCopilotAction(action, dependencies) {
|
|
|
998
874
|
]);
|
|
999
875
|
}
|
|
1000
876
|
|
|
1001
|
-
// src/hooks/use-coagent-action.ts
|
|
1002
|
-
var import_react8 = require("react");
|
|
1003
|
-
var import_shared6 = require("@copilotkit/shared");
|
|
1004
|
-
function useCoAgentAction(action, dependencies) {
|
|
1005
|
-
const { setCoagentAction, removeCoagentAction, coagentActions, chatComponentsCache } = (0, import_react8.useContext)(CopilotContext);
|
|
1006
|
-
const idRef = (0, import_react8.useRef)((0, import_shared6.randomId)());
|
|
1007
|
-
const key = `${action.name}-${action.nodeName || "global"}`;
|
|
1008
|
-
if (dependencies === void 0) {
|
|
1009
|
-
if (coagentActions[idRef.current]) {
|
|
1010
|
-
coagentActions[idRef.current].handler = action.handler;
|
|
1011
|
-
if (typeof action.render === "function") {
|
|
1012
|
-
if (chatComponentsCache.current !== null) {
|
|
1013
|
-
chatComponentsCache.current.coagentActions[key] = action.render;
|
|
1014
|
-
}
|
|
1015
|
-
}
|
|
1016
|
-
}
|
|
1017
|
-
}
|
|
1018
|
-
(0, import_react8.useEffect)(() => {
|
|
1019
|
-
setCoagentAction(idRef.current, action);
|
|
1020
|
-
if (chatComponentsCache.current !== null && action.render !== void 0) {
|
|
1021
|
-
chatComponentsCache.current.coagentActions[key] = action.render;
|
|
1022
|
-
}
|
|
1023
|
-
return () => {
|
|
1024
|
-
removeCoagentAction(idRef.current);
|
|
1025
|
-
};
|
|
1026
|
-
}, [
|
|
1027
|
-
setCoagentAction,
|
|
1028
|
-
removeCoagentAction,
|
|
1029
|
-
action.name,
|
|
1030
|
-
// include render only if it's a string
|
|
1031
|
-
typeof action.render === "string" ? action.render : void 0,
|
|
1032
|
-
// dependencies set by the developer
|
|
1033
|
-
...dependencies || []
|
|
1034
|
-
]);
|
|
1035
|
-
}
|
|
1036
|
-
|
|
1037
877
|
// src/hooks/use-make-copilot-document-readable.ts
|
|
1038
|
-
var
|
|
878
|
+
var import_react8 = require("react");
|
|
1039
879
|
function useMakeCopilotDocumentReadable(document, categories, dependencies = []) {
|
|
1040
880
|
const { addDocumentContext, removeDocumentContext } = useCopilotContext();
|
|
1041
|
-
const idRef = (0,
|
|
1042
|
-
(0,
|
|
881
|
+
const idRef = (0, import_react8.useRef)();
|
|
882
|
+
(0, import_react8.useEffect)(() => {
|
|
1043
883
|
const id = addDocumentContext(document, categories);
|
|
1044
884
|
idRef.current = id;
|
|
1045
885
|
return () => {
|
|
@@ -1050,16 +890,16 @@ function useMakeCopilotDocumentReadable(document, categories, dependencies = [])
|
|
|
1050
890
|
}
|
|
1051
891
|
|
|
1052
892
|
// src/hooks/use-copilot-readable.ts
|
|
1053
|
-
var
|
|
893
|
+
var import_react9 = require("react");
|
|
1054
894
|
function convertToJSON(description, value) {
|
|
1055
895
|
return `${description}: ${typeof value === "string" ? value : JSON.stringify(value)}`;
|
|
1056
896
|
}
|
|
1057
897
|
function useCopilotReadable({ description, value, parentId, categories, convert }, dependencies) {
|
|
1058
898
|
const { addContext, removeContext } = useCopilotContext();
|
|
1059
|
-
const idRef = (0,
|
|
899
|
+
const idRef = (0, import_react9.useRef)();
|
|
1060
900
|
convert = convert || convertToJSON;
|
|
1061
901
|
const information = convert(description, value);
|
|
1062
|
-
(0,
|
|
902
|
+
(0, import_react9.useEffect)(() => {
|
|
1063
903
|
const id = addContext(information, parentId, categories);
|
|
1064
904
|
idRef.current = id;
|
|
1065
905
|
return () => {
|
|
@@ -1069,84 +909,9 @@ function useCopilotReadable({ description, value, parentId, categories, convert
|
|
|
1069
909
|
return idRef.current;
|
|
1070
910
|
}
|
|
1071
911
|
|
|
1072
|
-
// src/hooks/use-coagent.ts
|
|
1073
|
-
var import_react11 = require("react");
|
|
1074
|
-
function useCoAgent(options) {
|
|
1075
|
-
const isExternalStateManagement = (options2) => {
|
|
1076
|
-
return "state" in options2 && "setState" in options2;
|
|
1077
|
-
};
|
|
1078
|
-
const { name } = options;
|
|
1079
|
-
const isInternalStateManagementWithInitial = (options2) => {
|
|
1080
|
-
return "initialState" in options2;
|
|
1081
|
-
};
|
|
1082
|
-
const { coagentStates, setCoagentStates } = useCopilotContext();
|
|
1083
|
-
const getCoagentState = (coagentStates2, name2) => {
|
|
1084
|
-
if (coagentStates2[name2]) {
|
|
1085
|
-
return coagentStates2[name2];
|
|
1086
|
-
} else {
|
|
1087
|
-
return {
|
|
1088
|
-
name: name2,
|
|
1089
|
-
state: isInternalStateManagementWithInitial(options) ? options.initialState : {},
|
|
1090
|
-
running: false,
|
|
1091
|
-
active: false,
|
|
1092
|
-
threadId: void 0,
|
|
1093
|
-
nodeName: void 0,
|
|
1094
|
-
runId: void 0
|
|
1095
|
-
};
|
|
1096
|
-
}
|
|
1097
|
-
};
|
|
1098
|
-
const setState = (newState) => {
|
|
1099
|
-
setCoagentStates((prevAgentStates) => {
|
|
1100
|
-
let coagentState2 = getCoagentState(prevAgentStates, name);
|
|
1101
|
-
const updatedState = typeof newState === "function" ? newState(coagentState2.state) : newState;
|
|
1102
|
-
return __spreadProps(__spreadValues({}, prevAgentStates), {
|
|
1103
|
-
[name]: __spreadProps(__spreadValues({}, coagentState2), {
|
|
1104
|
-
state: updatedState
|
|
1105
|
-
})
|
|
1106
|
-
});
|
|
1107
|
-
});
|
|
1108
|
-
};
|
|
1109
|
-
const coagentState = getCoagentState(coagentStates, name);
|
|
1110
|
-
const state = isExternalStateManagement(options) ? options.state : coagentState.state;
|
|
1111
|
-
(0, import_react11.useEffect)(() => {
|
|
1112
|
-
if (isExternalStateManagement(options)) {
|
|
1113
|
-
setState(options.state);
|
|
1114
|
-
} else if (coagentStates[name] === void 0) {
|
|
1115
|
-
setState(options.initialState === void 0 ? {} : options.initialState);
|
|
1116
|
-
}
|
|
1117
|
-
}, [isExternalStateManagement(options) ? JSON.stringify(options.state) : void 0]);
|
|
1118
|
-
return {
|
|
1119
|
-
name,
|
|
1120
|
-
nodeName: coagentState.nodeName,
|
|
1121
|
-
state,
|
|
1122
|
-
setState,
|
|
1123
|
-
running: coagentState.running,
|
|
1124
|
-
start: () => {
|
|
1125
|
-
startAgent(name);
|
|
1126
|
-
},
|
|
1127
|
-
stop: () => {
|
|
1128
|
-
stopAgent(name);
|
|
1129
|
-
}
|
|
1130
|
-
};
|
|
1131
|
-
}
|
|
1132
|
-
function startAgent(name) {
|
|
1133
|
-
const { setAgentSession } = useCopilotContext();
|
|
1134
|
-
setAgentSession({
|
|
1135
|
-
agentName: name
|
|
1136
|
-
});
|
|
1137
|
-
}
|
|
1138
|
-
function stopAgent(name) {
|
|
1139
|
-
const { agentSession, setAgentSession } = useCopilotContext();
|
|
1140
|
-
if (agentSession && agentSession.agentName === name) {
|
|
1141
|
-
setAgentSession(null);
|
|
1142
|
-
} else {
|
|
1143
|
-
console.warn(`No agent session found for ${name}`);
|
|
1144
|
-
}
|
|
1145
|
-
}
|
|
1146
|
-
|
|
1147
912
|
// src/lib/copilot-task.ts
|
|
1148
913
|
var import_runtime_client_gql3 = require("@copilotkit/runtime-client-gql");
|
|
1149
|
-
var
|
|
914
|
+
var import_shared6 = require("@copilotkit/shared");
|
|
1150
915
|
var CopilotTask = class {
|
|
1151
916
|
constructor(config) {
|
|
1152
917
|
this.instructions = config.instructions;
|
|
@@ -1190,11 +955,11 @@ var CopilotTask = class {
|
|
|
1190
955
|
actions: Object.values(actions).map((action) => ({
|
|
1191
956
|
name: action.name,
|
|
1192
957
|
description: action.description || "",
|
|
1193
|
-
jsonSchema: JSON.stringify((0,
|
|
958
|
+
jsonSchema: JSON.stringify((0, import_shared6.actionParametersToJsonSchema)(action.parameters || []))
|
|
1194
959
|
})),
|
|
1195
960
|
url: window.location.href
|
|
1196
961
|
},
|
|
1197
|
-
messages: (0, import_runtime_client_gql3.convertMessagesToGqlInput)(
|
|
962
|
+
messages: (0, import_runtime_client_gql3.convertMessagesToGqlInput)(messages),
|
|
1198
963
|
metadata: {
|
|
1199
964
|
requestType: import_runtime_client_gql3.CopilotRequestType.Task
|
|
1200
965
|
},
|
|
@@ -1245,7 +1010,7 @@ ${instructions}
|
|
|
1245
1010
|
}
|
|
1246
1011
|
|
|
1247
1012
|
// src/utils/extract.ts
|
|
1248
|
-
var
|
|
1013
|
+
var import_shared7 = require("@copilotkit/shared");
|
|
1249
1014
|
var import_runtime_client_gql4 = require("@copilotkit/runtime-client-gql");
|
|
1250
1015
|
var import_runtime_client_gql5 = require("@copilotkit/runtime-client-gql");
|
|
1251
1016
|
var import_runtime_client_gql6 = require("@copilotkit/runtime-client-gql");
|
|
@@ -1281,7 +1046,7 @@ function extract(_0) {
|
|
|
1281
1046
|
content: makeSystemMessage(contextString, instructions),
|
|
1282
1047
|
role: import_runtime_client_gql4.Role.System
|
|
1283
1048
|
});
|
|
1284
|
-
const headers = __spreadValues(__spreadValues({}, context.copilotApiConfig.headers || {}), context.copilotApiConfig.publicApiKey ? { [
|
|
1049
|
+
const headers = __spreadValues(__spreadValues({}, context.copilotApiConfig.headers || {}), context.copilotApiConfig.publicApiKey ? { [import_shared7.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: context.copilotApiConfig.publicApiKey } : {});
|
|
1285
1050
|
const runtimeClient = new import_runtime_client_gql5.CopilotRuntimeClient({
|
|
1286
1051
|
url: context.copilotApiConfig.chatApiEndpoint,
|
|
1287
1052
|
publicApiKey: context.copilotApiConfig.publicApiKey,
|
|
@@ -1296,13 +1061,13 @@ function extract(_0) {
|
|
|
1296
1061
|
{
|
|
1297
1062
|
name: action.name,
|
|
1298
1063
|
description: action.description || "",
|
|
1299
|
-
jsonSchema: JSON.stringify((0,
|
|
1064
|
+
jsonSchema: JSON.stringify((0, import_shared7.actionParametersToJsonSchema)(action.parameters || []))
|
|
1300
1065
|
}
|
|
1301
1066
|
],
|
|
1302
1067
|
url: window.location.href
|
|
1303
1068
|
},
|
|
1304
1069
|
messages: (0, import_runtime_client_gql6.convertMessagesToGqlInput)(
|
|
1305
|
-
includeMessages ? [systemMessage, ...
|
|
1070
|
+
includeMessages ? [systemMessage, ...messages] : [systemMessage]
|
|
1306
1071
|
),
|
|
1307
1072
|
metadata: {
|
|
1308
1073
|
requestType
|
|
@@ -1383,8 +1148,6 @@ Any additional messages provided are for providing context only and should not b
|
|
|
1383
1148
|
CopilotTask,
|
|
1384
1149
|
defaultCopilotContextCategories,
|
|
1385
1150
|
extract,
|
|
1386
|
-
useCoAgent,
|
|
1387
|
-
useCoAgentAction,
|
|
1388
1151
|
useCopilotAction,
|
|
1389
1152
|
useCopilotChat,
|
|
1390
1153
|
useCopilotContext,
|