@copilotkit/react-core 1.1.3-feat-runtime-remote-actions.1 → 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 -12
- package/dist/chunk-5JB4B2SV.mjs +1 -0
- package/dist/{chunk-HABY7NLH.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-XSZDVRPW.mjs → chunk-PZOEBYWP.mjs} +11 -62
- 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 -223
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +12 -21
- package/dist/hooks/use-chat.d.ts +4 -26
- package/dist/hooks/use-chat.js +9 -57
- 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 -100
- 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 -267
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +16 -24
- 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 -106
- 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-HABY7NLH.mjs.map +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-STUXJ3BN.mjs +0 -44
- package/dist/chunk-STUXJ3BN.mjs.map +0 -1
- package/dist/chunk-TCZBK3HZ.mjs.map +0 -1
- package/dist/chunk-XSZDVRPW.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
|
}
|
|
@@ -705,30 +643,8 @@ function useChat(options) {
|
|
|
705
643
|
} else {
|
|
706
644
|
for (const message of messages2) {
|
|
707
645
|
newMessages.push(message);
|
|
708
|
-
if (message instanceof import_runtime_client_gql.AgentStateMessage) {
|
|
709
|
-
if (message.running) {
|
|
710
|
-
setCoagentStates((prevAgentStates) => __spreadProps(__spreadValues({}, prevAgentStates), {
|
|
711
|
-
[message.agentName]: {
|
|
712
|
-
name: message.agentName,
|
|
713
|
-
state: message.state,
|
|
714
|
-
running: message.running,
|
|
715
|
-
active: message.active,
|
|
716
|
-
threadId: message.threadId,
|
|
717
|
-
nodeName: message.nodeName,
|
|
718
|
-
runId: message.runId
|
|
719
|
-
}
|
|
720
|
-
}));
|
|
721
|
-
setAgentSession({
|
|
722
|
-
threadId: message.threadId,
|
|
723
|
-
agentName: message.agentName,
|
|
724
|
-
nodeName: message.nodeName
|
|
725
|
-
});
|
|
726
|
-
} else {
|
|
727
|
-
setAgentSession(null);
|
|
728
|
-
}
|
|
729
|
-
}
|
|
730
646
|
if (message instanceof import_runtime_client_gql.ActionExecutionMessage && message.status.code !== import_runtime_client_gql.MessageStatusCode.Pending && message.scope === "client" && onFunctionCall) {
|
|
731
|
-
if (!(message.id in
|
|
647
|
+
if (!(message.id in results)) {
|
|
732
648
|
if (guardrailsEnabled && value.generateCopilotResponse.status === void 0) {
|
|
733
649
|
break;
|
|
734
650
|
}
|
|
@@ -737,27 +653,16 @@ function useChat(options) {
|
|
|
737
653
|
name: message.name,
|
|
738
654
|
args: message.arguments
|
|
739
655
|
});
|
|
740
|
-
|
|
656
|
+
results[message.id] = result;
|
|
741
657
|
}
|
|
742
658
|
newMessages.push(
|
|
743
659
|
new import_runtime_client_gql.ResultMessage({
|
|
744
|
-
result: import_runtime_client_gql.ResultMessage.encodeResult(
|
|
660
|
+
result: import_runtime_client_gql.ResultMessage.encodeResult(results[message.id]),
|
|
745
661
|
actionExecutionId: message.id,
|
|
746
662
|
actionName: message.name
|
|
747
663
|
})
|
|
748
664
|
);
|
|
749
665
|
}
|
|
750
|
-
if (message instanceof import_runtime_client_gql.AgentStateMessage && !message.active && !executedCoagentActions.includes(message.id) && onCoagentAction) {
|
|
751
|
-
if (guardrailsEnabled && value.generateCopilotResponse.status === void 0) {
|
|
752
|
-
break;
|
|
753
|
-
}
|
|
754
|
-
yield onCoagentAction({
|
|
755
|
-
name: message.agentName,
|
|
756
|
-
nodeName: message.nodeName,
|
|
757
|
-
state: message.state
|
|
758
|
-
});
|
|
759
|
-
executedCoagentActions.push(message.id);
|
|
760
|
-
}
|
|
761
666
|
}
|
|
762
667
|
}
|
|
763
668
|
if (newMessages.length > 0) {
|
|
@@ -766,7 +671,7 @@ function useChat(options) {
|
|
|
766
671
|
}
|
|
767
672
|
if (
|
|
768
673
|
// if we have client side results
|
|
769
|
-
Object.values(
|
|
674
|
+
Object.values(results).length || // or the last message we received is a result
|
|
770
675
|
newMessages.length && newMessages[newMessages.length - 1] instanceof import_runtime_client_gql.ResultMessage
|
|
771
676
|
) {
|
|
772
677
|
yield new Promise((resolve) => setTimeout(resolve, 10));
|
|
@@ -828,12 +733,7 @@ function useCopilotChat(_a = {}) {
|
|
|
828
733
|
isLoading,
|
|
829
734
|
setIsLoading,
|
|
830
735
|
chatInstructions,
|
|
831
|
-
actions
|
|
832
|
-
coagentStates,
|
|
833
|
-
setCoagentStates,
|
|
834
|
-
coagentActions,
|
|
835
|
-
agentSession,
|
|
836
|
-
setAgentSession
|
|
736
|
+
actions
|
|
837
737
|
} = useCopilotContext();
|
|
838
738
|
const latestGetContextString = useUpdatedRef(getContextString);
|
|
839
739
|
const deleteMessage = (0, import_react6.useCallback)(
|
|
@@ -850,39 +750,16 @@ function useCopilotChat(_a = {}) {
|
|
|
850
750
|
role: import_runtime_client_gql2.Role.System
|
|
851
751
|
});
|
|
852
752
|
}, [getContextString, makeSystemMessage2, chatInstructions]);
|
|
853
|
-
const onCoagentAction = (0, import_react6.useCallback)(
|
|
854
|
-
(args) => __async(this, null, function* () {
|
|
855
|
-
var _a2;
|
|
856
|
-
const { name, nodeName, state } = args;
|
|
857
|
-
let action = Object.values(coagentActions).find(
|
|
858
|
-
(action2) => action2.name === name && action2.nodeName === nodeName
|
|
859
|
-
);
|
|
860
|
-
if (!action) {
|
|
861
|
-
action = Object.values(coagentActions).find(
|
|
862
|
-
(action2) => action2.name === name && !action2.nodeName
|
|
863
|
-
);
|
|
864
|
-
}
|
|
865
|
-
if (action) {
|
|
866
|
-
yield (_a2 = action.handler) == null ? void 0 : _a2.call(action, { state, nodeName });
|
|
867
|
-
}
|
|
868
|
-
}),
|
|
869
|
-
[coagentActions]
|
|
870
|
-
);
|
|
871
753
|
const { append, reload, stop } = useChat(__spreadProps(__spreadValues({}, options), {
|
|
872
754
|
actions: Object.values(actions),
|
|
873
755
|
copilotConfig: copilotApiConfig,
|
|
874
756
|
initialMessages: options.initialMessages || [],
|
|
875
757
|
onFunctionCall: getFunctionCallHandler(),
|
|
876
|
-
onCoagentAction,
|
|
877
758
|
messages,
|
|
878
759
|
setMessages,
|
|
879
760
|
makeSystemMessageCallback,
|
|
880
761
|
isLoading,
|
|
881
|
-
setIsLoading
|
|
882
|
-
coagentStates,
|
|
883
|
-
setCoagentStates,
|
|
884
|
-
agentSession,
|
|
885
|
-
setAgentSession
|
|
762
|
+
setIsLoading
|
|
886
763
|
}));
|
|
887
764
|
const latestAppend = useUpdatedRef(append);
|
|
888
765
|
const latestAppendFunc = (0, import_react6.useCallback)(
|
|
@@ -965,7 +842,7 @@ function useCopilotAction(action, dependencies) {
|
|
|
965
842
|
actions[idRef.current].handler = action.handler;
|
|
966
843
|
if (typeof action.render === "function") {
|
|
967
844
|
if (chatComponentsCache.current !== null) {
|
|
968
|
-
chatComponentsCache.current
|
|
845
|
+
chatComponentsCache.current[action.name] = action.render;
|
|
969
846
|
}
|
|
970
847
|
}
|
|
971
848
|
}
|
|
@@ -976,7 +853,7 @@ function useCopilotAction(action, dependencies) {
|
|
|
976
853
|
}
|
|
977
854
|
setAction(idRef.current, action);
|
|
978
855
|
if (chatComponentsCache.current !== null && action.render !== void 0) {
|
|
979
|
-
chatComponentsCache.current
|
|
856
|
+
chatComponentsCache.current[action.name] = action.render;
|
|
980
857
|
}
|
|
981
858
|
return () => {
|
|
982
859
|
removeAction(idRef.current);
|
|
@@ -997,48 +874,12 @@ function useCopilotAction(action, dependencies) {
|
|
|
997
874
|
]);
|
|
998
875
|
}
|
|
999
876
|
|
|
1000
|
-
// src/hooks/use-coagent-action.ts
|
|
1001
|
-
var import_react8 = require("react");
|
|
1002
|
-
var import_shared6 = require("@copilotkit/shared");
|
|
1003
|
-
function useCoAgentAction(action, dependencies) {
|
|
1004
|
-
const { setCoagentAction, removeCoagentAction, coagentActions, chatComponentsCache } = (0, import_react8.useContext)(CopilotContext);
|
|
1005
|
-
const idRef = (0, import_react8.useRef)((0, import_shared6.randomId)());
|
|
1006
|
-
const key = `${action.name}-${action.nodeName || "global"}`;
|
|
1007
|
-
if (dependencies === void 0) {
|
|
1008
|
-
if (coagentActions[idRef.current]) {
|
|
1009
|
-
coagentActions[idRef.current].handler = action.handler;
|
|
1010
|
-
if (typeof action.render === "function") {
|
|
1011
|
-
if (chatComponentsCache.current !== null) {
|
|
1012
|
-
chatComponentsCache.current.coagentActions[key] = action.render;
|
|
1013
|
-
}
|
|
1014
|
-
}
|
|
1015
|
-
}
|
|
1016
|
-
}
|
|
1017
|
-
(0, import_react8.useEffect)(() => {
|
|
1018
|
-
setCoagentAction(idRef.current, action);
|
|
1019
|
-
if (chatComponentsCache.current !== null && action.render !== void 0) {
|
|
1020
|
-
chatComponentsCache.current.coagentActions[key] = action.render;
|
|
1021
|
-
}
|
|
1022
|
-
return () => {
|
|
1023
|
-
removeCoagentAction(idRef.current);
|
|
1024
|
-
};
|
|
1025
|
-
}, [
|
|
1026
|
-
setCoagentAction,
|
|
1027
|
-
removeCoagentAction,
|
|
1028
|
-
action.name,
|
|
1029
|
-
// include render only if it's a string
|
|
1030
|
-
typeof action.render === "string" ? action.render : void 0,
|
|
1031
|
-
// dependencies set by the developer
|
|
1032
|
-
...dependencies || []
|
|
1033
|
-
]);
|
|
1034
|
-
}
|
|
1035
|
-
|
|
1036
877
|
// src/hooks/use-make-copilot-document-readable.ts
|
|
1037
|
-
var
|
|
878
|
+
var import_react8 = require("react");
|
|
1038
879
|
function useMakeCopilotDocumentReadable(document, categories, dependencies = []) {
|
|
1039
880
|
const { addDocumentContext, removeDocumentContext } = useCopilotContext();
|
|
1040
|
-
const idRef = (0,
|
|
1041
|
-
(0,
|
|
881
|
+
const idRef = (0, import_react8.useRef)();
|
|
882
|
+
(0, import_react8.useEffect)(() => {
|
|
1042
883
|
const id = addDocumentContext(document, categories);
|
|
1043
884
|
idRef.current = id;
|
|
1044
885
|
return () => {
|
|
@@ -1049,16 +890,16 @@ function useMakeCopilotDocumentReadable(document, categories, dependencies = [])
|
|
|
1049
890
|
}
|
|
1050
891
|
|
|
1051
892
|
// src/hooks/use-copilot-readable.ts
|
|
1052
|
-
var
|
|
893
|
+
var import_react9 = require("react");
|
|
1053
894
|
function convertToJSON(description, value) {
|
|
1054
895
|
return `${description}: ${typeof value === "string" ? value : JSON.stringify(value)}`;
|
|
1055
896
|
}
|
|
1056
897
|
function useCopilotReadable({ description, value, parentId, categories, convert }, dependencies) {
|
|
1057
898
|
const { addContext, removeContext } = useCopilotContext();
|
|
1058
|
-
const idRef = (0,
|
|
899
|
+
const idRef = (0, import_react9.useRef)();
|
|
1059
900
|
convert = convert || convertToJSON;
|
|
1060
901
|
const information = convert(description, value);
|
|
1061
|
-
(0,
|
|
902
|
+
(0, import_react9.useEffect)(() => {
|
|
1062
903
|
const id = addContext(information, parentId, categories);
|
|
1063
904
|
idRef.current = id;
|
|
1064
905
|
return () => {
|
|
@@ -1068,84 +909,9 @@ function useCopilotReadable({ description, value, parentId, categories, convert
|
|
|
1068
909
|
return idRef.current;
|
|
1069
910
|
}
|
|
1070
911
|
|
|
1071
|
-
// src/hooks/use-coagent.ts
|
|
1072
|
-
var import_react11 = require("react");
|
|
1073
|
-
function useCoAgent(options) {
|
|
1074
|
-
const isExternalStateManagement = (options2) => {
|
|
1075
|
-
return "state" in options2 && "setState" in options2;
|
|
1076
|
-
};
|
|
1077
|
-
const { name } = options;
|
|
1078
|
-
const isInternalStateManagementWithInitial = (options2) => {
|
|
1079
|
-
return "initialState" in options2;
|
|
1080
|
-
};
|
|
1081
|
-
const { coagentStates, setCoagentStates } = useCopilotContext();
|
|
1082
|
-
const getCoagentState = (coagentStates2, name2) => {
|
|
1083
|
-
if (coagentStates2[name2]) {
|
|
1084
|
-
return coagentStates2[name2];
|
|
1085
|
-
} else {
|
|
1086
|
-
return {
|
|
1087
|
-
name: name2,
|
|
1088
|
-
state: isInternalStateManagementWithInitial(options) ? options.initialState : {},
|
|
1089
|
-
running: false,
|
|
1090
|
-
active: false,
|
|
1091
|
-
threadId: void 0,
|
|
1092
|
-
nodeName: void 0,
|
|
1093
|
-
runId: void 0
|
|
1094
|
-
};
|
|
1095
|
-
}
|
|
1096
|
-
};
|
|
1097
|
-
const setState = (newState) => {
|
|
1098
|
-
setCoagentStates((prevAgentStates) => {
|
|
1099
|
-
let coagentState2 = getCoagentState(prevAgentStates, name);
|
|
1100
|
-
const updatedState = typeof newState === "function" ? newState(coagentState2.state) : newState;
|
|
1101
|
-
return __spreadProps(__spreadValues({}, prevAgentStates), {
|
|
1102
|
-
[name]: __spreadProps(__spreadValues({}, coagentState2), {
|
|
1103
|
-
state: updatedState
|
|
1104
|
-
})
|
|
1105
|
-
});
|
|
1106
|
-
});
|
|
1107
|
-
};
|
|
1108
|
-
const coagentState = getCoagentState(coagentStates, name);
|
|
1109
|
-
const state = isExternalStateManagement(options) ? options.state : coagentState.state;
|
|
1110
|
-
(0, import_react11.useEffect)(() => {
|
|
1111
|
-
if (isExternalStateManagement(options)) {
|
|
1112
|
-
setState(options.state);
|
|
1113
|
-
} else if (coagentStates[name] === void 0) {
|
|
1114
|
-
setState(options.initialState === void 0 ? {} : options.initialState);
|
|
1115
|
-
}
|
|
1116
|
-
}, [isExternalStateManagement(options) ? JSON.stringify(options.state) : void 0]);
|
|
1117
|
-
return {
|
|
1118
|
-
name,
|
|
1119
|
-
nodeName: coagentState.nodeName,
|
|
1120
|
-
state,
|
|
1121
|
-
setState,
|
|
1122
|
-
running: coagentState.running,
|
|
1123
|
-
start: () => {
|
|
1124
|
-
startAgent(name);
|
|
1125
|
-
},
|
|
1126
|
-
stop: () => {
|
|
1127
|
-
stopAgent(name);
|
|
1128
|
-
}
|
|
1129
|
-
};
|
|
1130
|
-
}
|
|
1131
|
-
function startAgent(name) {
|
|
1132
|
-
const { setAgentSession } = useCopilotContext();
|
|
1133
|
-
setAgentSession({
|
|
1134
|
-
agentName: name
|
|
1135
|
-
});
|
|
1136
|
-
}
|
|
1137
|
-
function stopAgent(name) {
|
|
1138
|
-
const { agentSession, setAgentSession } = useCopilotContext();
|
|
1139
|
-
if (agentSession && agentSession.agentName === name) {
|
|
1140
|
-
setAgentSession(null);
|
|
1141
|
-
} else {
|
|
1142
|
-
console.warn(`No agent session found for ${name}`);
|
|
1143
|
-
}
|
|
1144
|
-
}
|
|
1145
|
-
|
|
1146
912
|
// src/lib/copilot-task.ts
|
|
1147
913
|
var import_runtime_client_gql3 = require("@copilotkit/runtime-client-gql");
|
|
1148
|
-
var
|
|
914
|
+
var import_shared6 = require("@copilotkit/shared");
|
|
1149
915
|
var CopilotTask = class {
|
|
1150
916
|
constructor(config) {
|
|
1151
917
|
this.instructions = config.instructions;
|
|
@@ -1189,11 +955,11 @@ var CopilotTask = class {
|
|
|
1189
955
|
actions: Object.values(actions).map((action) => ({
|
|
1190
956
|
name: action.name,
|
|
1191
957
|
description: action.description || "",
|
|
1192
|
-
jsonSchema: JSON.stringify((0,
|
|
958
|
+
jsonSchema: JSON.stringify((0, import_shared6.actionParametersToJsonSchema)(action.parameters || []))
|
|
1193
959
|
})),
|
|
1194
960
|
url: window.location.href
|
|
1195
961
|
},
|
|
1196
|
-
messages: (0, import_runtime_client_gql3.convertMessagesToGqlInput)(
|
|
962
|
+
messages: (0, import_runtime_client_gql3.convertMessagesToGqlInput)(messages),
|
|
1197
963
|
metadata: {
|
|
1198
964
|
requestType: import_runtime_client_gql3.CopilotRequestType.Task
|
|
1199
965
|
},
|
|
@@ -1244,7 +1010,7 @@ ${instructions}
|
|
|
1244
1010
|
}
|
|
1245
1011
|
|
|
1246
1012
|
// src/utils/extract.ts
|
|
1247
|
-
var
|
|
1013
|
+
var import_shared7 = require("@copilotkit/shared");
|
|
1248
1014
|
var import_runtime_client_gql4 = require("@copilotkit/runtime-client-gql");
|
|
1249
1015
|
var import_runtime_client_gql5 = require("@copilotkit/runtime-client-gql");
|
|
1250
1016
|
var import_runtime_client_gql6 = require("@copilotkit/runtime-client-gql");
|
|
@@ -1280,7 +1046,7 @@ function extract(_0) {
|
|
|
1280
1046
|
content: makeSystemMessage(contextString, instructions),
|
|
1281
1047
|
role: import_runtime_client_gql4.Role.System
|
|
1282
1048
|
});
|
|
1283
|
-
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 } : {});
|
|
1284
1050
|
const runtimeClient = new import_runtime_client_gql5.CopilotRuntimeClient({
|
|
1285
1051
|
url: context.copilotApiConfig.chatApiEndpoint,
|
|
1286
1052
|
publicApiKey: context.copilotApiConfig.publicApiKey,
|
|
@@ -1295,13 +1061,13 @@ function extract(_0) {
|
|
|
1295
1061
|
{
|
|
1296
1062
|
name: action.name,
|
|
1297
1063
|
description: action.description || "",
|
|
1298
|
-
jsonSchema: JSON.stringify((0,
|
|
1064
|
+
jsonSchema: JSON.stringify((0, import_shared7.actionParametersToJsonSchema)(action.parameters || []))
|
|
1299
1065
|
}
|
|
1300
1066
|
],
|
|
1301
1067
|
url: window.location.href
|
|
1302
1068
|
},
|
|
1303
1069
|
messages: (0, import_runtime_client_gql6.convertMessagesToGqlInput)(
|
|
1304
|
-
includeMessages ? [systemMessage, ...
|
|
1070
|
+
includeMessages ? [systemMessage, ...messages] : [systemMessage]
|
|
1305
1071
|
),
|
|
1306
1072
|
metadata: {
|
|
1307
1073
|
requestType
|
|
@@ -1382,8 +1148,6 @@ Any additional messages provided are for providing context only and should not b
|
|
|
1382
1148
|
CopilotTask,
|
|
1383
1149
|
defaultCopilotContextCategories,
|
|
1384
1150
|
extract,
|
|
1385
|
-
useCoAgent,
|
|
1386
|
-
useCoAgentAction,
|
|
1387
1151
|
useCopilotAction,
|
|
1388
1152
|
useCopilotChat,
|
|
1389
1153
|
useCopilotContext,
|