@copilotkit/react-core 1.50.0-beta.8 → 1.50.0-beta.9
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 +12 -0
- package/dist/{chunk-EKDPRKZT.mjs → chunk-3775VM7Y.mjs} +14 -26
- package/dist/chunk-3775VM7Y.mjs.map +1 -0
- package/dist/{chunk-BLDHD6Q2.mjs → chunk-7SHWECGN.mjs} +2 -2
- package/dist/{chunk-Y2L7KDVW.mjs → chunk-B5ELMVT7.mjs} +2 -2
- package/dist/{chunk-ZU6ZBX4E.mjs → chunk-FYMZKPOL.mjs} +4 -4
- package/dist/chunk-XDFVCQD3.mjs +27 -0
- package/dist/chunk-XDFVCQD3.mjs.map +1 -0
- package/dist/{chunk-KYY2WZSR.mjs → chunk-YJGPIN3R.mjs} +2 -2
- package/dist/{chunk-RQ6LWR6S.mjs → chunk-Z6JV2LRY.mjs} +1 -1
- package/dist/chunk-Z6JV2LRY.mjs.map +1 -0
- package/dist/components/copilot-provider/copilotkit.mjs +4 -4
- package/dist/components/copilot-provider/index.mjs +4 -4
- package/dist/components/index.mjs +4 -4
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/index.js +121 -149
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +24 -24
- package/dist/hooks/use-copilot-chat-headless_c.js +39 -82
- package/dist/hooks/use-copilot-chat-headless_c.js.map +1 -1
- package/dist/hooks/use-copilot-chat-headless_c.mjs +3 -4
- package/dist/hooks/{use-configure-chat-suggestions.d.ts → use-copilot-chat-suggestions.d.ts} +2 -3
- package/dist/hooks/{use-configure-chat-suggestions.js → use-copilot-chat-suggestions.js} +10 -29
- 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.js +37 -80
- package/dist/hooks/use-copilot-chat.js.map +1 -1
- package/dist/hooks/use-copilot-chat.mjs +3 -4
- package/dist/hooks/use-copilot-chat_internal.d.ts +17 -0
- package/dist/hooks/use-copilot-chat_internal.js +37 -80
- package/dist/hooks/use-copilot-chat_internal.js.map +1 -1
- package/dist/hooks/use-copilot-chat_internal.mjs +2 -3
- package/dist/hooks/use-copilot-readable.d.ts +2 -3
- package/dist/hooks/use-copilot-readable.js.map +1 -1
- package/dist/hooks/use-copilot-readable.mjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +114 -142
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +32 -32
- package/dist/lib/copilot-task.mjs +5 -5
- package/dist/lib/index.mjs +5 -5
- package/dist/types/index.mjs +1 -1
- package/dist/utils/index.mjs +3 -3
- package/package.json +5 -5
- package/src/hooks/index.ts +2 -2
- package/src/hooks/use-copilot-chat-suggestions.tsx +124 -0
- package/src/hooks/use-copilot-chat_internal.ts +29 -29
- package/src/hooks/use-copilot-readable.ts +2 -4
- package/dist/chunk-EKDPRKZT.mjs.map +0 -1
- package/dist/chunk-FBVI3LQ6.mjs +0 -48
- package/dist/chunk-FBVI3LQ6.mjs.map +0 -1
- package/dist/chunk-RQ6LWR6S.mjs.map +0 -1
- package/dist/hooks/use-configure-chat-suggestions.js.map +0 -1
- package/dist/hooks/use-configure-chat-suggestions.mjs +0 -8
- package/src/hooks/use-configure-chat-suggestions.tsx +0 -86
- /package/dist/{chunk-BLDHD6Q2.mjs.map → chunk-7SHWECGN.mjs.map} +0 -0
- /package/dist/{chunk-Y2L7KDVW.mjs.map → chunk-B5ELMVT7.mjs.map} +0 -0
- /package/dist/{chunk-ZU6ZBX4E.mjs.map → chunk-FYMZKPOL.mjs.map} +0 -0
- /package/dist/{chunk-KYY2WZSR.mjs.map → chunk-YJGPIN3R.mjs.map} +0 -0
- /package/dist/hooks/{use-configure-chat-suggestions.mjs.map → use-copilot-chat-suggestions.mjs.map} +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -23,7 +23,7 @@ export { useHumanInTheLoop } from './hooks/use-human-in-the-loop.js';
|
|
|
23
23
|
export { useRenderToolCall } from './hooks/use-render-tool-call.js';
|
|
24
24
|
export { useDefaultTool } from './hooks/use-default-tool.js';
|
|
25
25
|
export { useLazyToolRenderer } from './hooks/use-lazy-tool-renderer.js';
|
|
26
|
-
export { UseCopilotChatSuggestionsConfiguration,
|
|
26
|
+
export { UseCopilotChatSuggestionsConfiguration, useCopilotChatSuggestions } from './hooks/use-copilot-chat-suggestions.js';
|
|
27
27
|
export { DocumentPointer } from './types/document-pointer.js';
|
|
28
28
|
export { SystemMessageFunction } from './types/system-message.js';
|
|
29
29
|
export { ActionRenderProps, ActionRenderPropsNoArgs, ActionRenderPropsNoArgsWait, ActionRenderPropsWait, CatchAllActionRenderProps, CatchAllFrontendAction, FrontendAction, FrontendActionAvailability, RenderFunctionStatus } from './types/frontend-action.js';
|
package/dist/index.js
CHANGED
|
@@ -95,13 +95,13 @@ __export(src_exports, {
|
|
|
95
95
|
useCoAgent: () => useCoAgent,
|
|
96
96
|
useCoAgentStateRender: () => useCoAgentStateRender,
|
|
97
97
|
useCoAgentStateRenders: () => useCoAgentStateRenders,
|
|
98
|
-
useConfigureChatSuggestions: () => useConfigureChatSuggestions,
|
|
99
98
|
useCopilotAction: () => useCopilotAction,
|
|
100
99
|
useCopilotAdditionalInstructions: () => useCopilotAdditionalInstructions,
|
|
101
100
|
useCopilotAuthenticatedAction_c: () => useCopilotAuthenticatedAction_c,
|
|
102
101
|
useCopilotChat: () => useCopilotChat,
|
|
103
102
|
useCopilotChatHeadless_c: () => useCopilotChatHeadless_c,
|
|
104
103
|
useCopilotChatInternal: () => useCopilotChatInternal,
|
|
104
|
+
useCopilotChatSuggestions: () => useCopilotChatSuggestions,
|
|
105
105
|
useCopilotContext: () => useCopilotContext,
|
|
106
106
|
useCopilotMessagesContext: () => useCopilotMessagesContext,
|
|
107
107
|
useCopilotReadable: () => useCopilotReadable,
|
|
@@ -3132,7 +3132,7 @@ function validateProps(props) {
|
|
|
3132
3132
|
}
|
|
3133
3133
|
|
|
3134
3134
|
// src/hooks/use-copilot-chat_internal.ts
|
|
3135
|
-
var
|
|
3135
|
+
var import_react25 = require("react");
|
|
3136
3136
|
var import_runtime_client_gql2 = require("@copilotkit/runtime-client-gql");
|
|
3137
3137
|
|
|
3138
3138
|
// src/hooks/use-langgraph-interrupt-render.ts
|
|
@@ -3276,7 +3276,7 @@ function useLangGraphInterruptRender(agent) {
|
|
|
3276
3276
|
}
|
|
3277
3277
|
|
|
3278
3278
|
// src/hooks/use-copilot-chat_internal.ts
|
|
3279
|
-
var
|
|
3279
|
+
var import_react26 = require("@copilotkitnext/react");
|
|
3280
3280
|
|
|
3281
3281
|
// src/hooks/use-lazy-tool-renderer.tsx
|
|
3282
3282
|
var import_react23 = require("@copilotkitnext/react");
|
|
@@ -3303,40 +3303,6 @@ function useLazyToolRenderer() {
|
|
|
3303
3303
|
);
|
|
3304
3304
|
}
|
|
3305
3305
|
|
|
3306
|
-
// src/hooks/use-configure-chat-suggestions.tsx
|
|
3307
|
-
var import_react25 = require("@copilotkitnext/react");
|
|
3308
|
-
var import_react26 = require("react");
|
|
3309
|
-
function useConfigureChatSuggestions(config, dependencies = []) {
|
|
3310
|
-
var _a;
|
|
3311
|
-
const existingConfig = (0, import_react25.useCopilotChatConfiguration)();
|
|
3312
|
-
const resolvedAgentId = (_a = existingConfig == null ? void 0 : existingConfig.agentId) != null ? _a : "default";
|
|
3313
|
-
const { copilotkit } = (0, import_react25.useCopilotKit)();
|
|
3314
|
-
const available = config.available === "enabled" ? "always" : config.available;
|
|
3315
|
-
const finalSuggestionConfig = __spreadProps(__spreadValues({}, config), {
|
|
3316
|
-
available,
|
|
3317
|
-
consumerAgentId: resolvedAgentId
|
|
3318
|
-
// Use chatConfig.agentId here
|
|
3319
|
-
});
|
|
3320
|
-
(0, import_react25.useConfigureSuggestions)(finalSuggestionConfig, dependencies);
|
|
3321
|
-
const result = (0, import_react25.useSuggestions)({ agentId: resolvedAgentId });
|
|
3322
|
-
(0, import_react26.useEffect)(() => {
|
|
3323
|
-
if (finalSuggestionConfig.available === "disabled")
|
|
3324
|
-
return;
|
|
3325
|
-
const subscription = copilotkit.subscribe({
|
|
3326
|
-
onAgentsChanged: () => {
|
|
3327
|
-
const agent = copilotkit.getAgent(resolvedAgentId);
|
|
3328
|
-
if (agent && !agent.isRunning && !result.suggestions.length) {
|
|
3329
|
-
copilotkit.reloadSuggestions(resolvedAgentId);
|
|
3330
|
-
}
|
|
3331
|
-
}
|
|
3332
|
-
});
|
|
3333
|
-
return () => {
|
|
3334
|
-
subscription.unsubscribe();
|
|
3335
|
-
};
|
|
3336
|
-
}, [resolvedAgentId]);
|
|
3337
|
-
return result;
|
|
3338
|
-
}
|
|
3339
|
-
|
|
3340
3306
|
// ../../node_modules/.pnpm/@ag-ui+core@0.0.42/node_modules/@ag-ui/core/dist/index.mjs
|
|
3341
3307
|
var import_zod = require("zod");
|
|
3342
3308
|
var import_zod2 = require("zod");
|
|
@@ -3743,35 +3709,17 @@ var EventSchemas = import_zod2.z.discriminatedUnion("type", [
|
|
|
3743
3709
|
]);
|
|
3744
3710
|
|
|
3745
3711
|
// src/hooks/use-copilot-chat_internal.ts
|
|
3746
|
-
function useConfigureSuggestions2(suggestions) {
|
|
3747
|
-
let suggestionsConfig;
|
|
3748
|
-
if (Array.isArray(suggestions)) {
|
|
3749
|
-
suggestionsConfig = {
|
|
3750
|
-
suggestions,
|
|
3751
|
-
available: "always"
|
|
3752
|
-
};
|
|
3753
|
-
} else if (suggestions === "auto") {
|
|
3754
|
-
suggestionsConfig = {
|
|
3755
|
-
available: suggestions === "auto" ? "always" : "disabled",
|
|
3756
|
-
instructions: "Suggest what the user could say next. Provide clear, highly relevant suggestions. Do not literally suggest function calls."
|
|
3757
|
-
};
|
|
3758
|
-
} else {
|
|
3759
|
-
suggestionsConfig = { available: "disabled" };
|
|
3760
|
-
}
|
|
3761
|
-
useConfigureChatSuggestions(suggestionsConfig);
|
|
3762
|
-
}
|
|
3763
3712
|
function useCopilotChatInternal({
|
|
3764
3713
|
suggestions
|
|
3765
3714
|
} = {}) {
|
|
3766
3715
|
var _a, _b, _c;
|
|
3767
|
-
const { copilotkit } = (0,
|
|
3716
|
+
const { copilotkit } = (0, import_react26.useCopilotKit)();
|
|
3768
3717
|
const { threadId, agentSession } = useCopilotContext();
|
|
3769
|
-
const existingConfig = (0,
|
|
3770
|
-
const [agentAvailable, setAgentAvailable] = (0,
|
|
3771
|
-
useConfigureSuggestions2(suggestions);
|
|
3718
|
+
const existingConfig = (0, import_react26.useCopilotChatConfiguration)();
|
|
3719
|
+
const [agentAvailable, setAgentAvailable] = (0, import_react25.useState)(false);
|
|
3772
3720
|
const resolvedAgentId = (_a = existingConfig == null ? void 0 : existingConfig.agentId) != null ? _a : "default";
|
|
3773
|
-
const { agent } = (0,
|
|
3774
|
-
(0,
|
|
3721
|
+
const { agent } = (0, import_react26.useAgent)({ agentId: resolvedAgentId });
|
|
3722
|
+
(0, import_react25.useEffect)(() => {
|
|
3775
3723
|
const connect = (agent2) => __async(this, null, function* () {
|
|
3776
3724
|
setAgentAvailable(false);
|
|
3777
3725
|
try {
|
|
@@ -3796,7 +3744,7 @@ function useCopilotChatInternal({
|
|
|
3796
3744
|
agent == null ? void 0 : agent.setMessages([]);
|
|
3797
3745
|
agent == null ? void 0 : agent.setState(null);
|
|
3798
3746
|
};
|
|
3799
|
-
const deleteMessage = (0,
|
|
3747
|
+
const deleteMessage = (0, import_react25.useCallback)(
|
|
3800
3748
|
(messageId) => {
|
|
3801
3749
|
var _a2;
|
|
3802
3750
|
const filteredMessages = ((_a2 = agent == null ? void 0 : agent.messages) != null ? _a2 : []).filter(
|
|
@@ -3807,13 +3755,13 @@ function useCopilotChatInternal({
|
|
|
3807
3755
|
[agent == null ? void 0 : agent.setMessages, agent == null ? void 0 : agent.messages]
|
|
3808
3756
|
);
|
|
3809
3757
|
const latestDelete = useUpdatedRef(deleteMessage);
|
|
3810
|
-
const latestDeleteFunc = (0,
|
|
3758
|
+
const latestDeleteFunc = (0, import_react25.useCallback)(
|
|
3811
3759
|
(messageId) => {
|
|
3812
3760
|
return latestDelete.current(messageId);
|
|
3813
3761
|
},
|
|
3814
3762
|
[latestDelete]
|
|
3815
3763
|
);
|
|
3816
|
-
const currentSuggestions = (0,
|
|
3764
|
+
const currentSuggestions = (0, import_react26.useSuggestions)({ agentId: resolvedAgentId });
|
|
3817
3765
|
const reload = useAsyncCallback(
|
|
3818
3766
|
(reloadMessageId) => __async(this, null, function* () {
|
|
3819
3767
|
var _a2;
|
|
@@ -3880,7 +3828,7 @@ function useCopilotChatInternal({
|
|
|
3880
3828
|
}),
|
|
3881
3829
|
[latestSendMessageFunc]
|
|
3882
3830
|
);
|
|
3883
|
-
const latestSetMessagesFunc = (0,
|
|
3831
|
+
const latestSetMessagesFunc = (0, import_react25.useCallback)(
|
|
3884
3832
|
(messages) => {
|
|
3885
3833
|
var _a2, _b2;
|
|
3886
3834
|
if (messages.every((message) => message instanceof import_runtime_client_gql2.Message)) {
|
|
@@ -3897,16 +3845,16 @@ function useCopilotChatInternal({
|
|
|
3897
3845
|
}),
|
|
3898
3846
|
[latestReload]
|
|
3899
3847
|
);
|
|
3900
|
-
const latestStopFunc = (0,
|
|
3848
|
+
const latestStopFunc = (0, import_react25.useCallback)(() => {
|
|
3901
3849
|
var _a2;
|
|
3902
3850
|
return (_a2 = agent == null ? void 0 : agent.abortRun) == null ? void 0 : _a2.call(agent);
|
|
3903
3851
|
}, [agent == null ? void 0 : agent.abortRun]);
|
|
3904
3852
|
const latestReset = useUpdatedRef(reset);
|
|
3905
|
-
const latestResetFunc = (0,
|
|
3853
|
+
const latestResetFunc = (0, import_react25.useCallback)(() => {
|
|
3906
3854
|
return latestReset.current();
|
|
3907
3855
|
}, [latestReset]);
|
|
3908
3856
|
const lazyToolRendered = useLazyToolRenderer();
|
|
3909
|
-
const renderCustomMessage = (0,
|
|
3857
|
+
const renderCustomMessage = (0, import_react26.useRenderCustomMessages)();
|
|
3910
3858
|
const legacyCustomMessageRenderer = useLegacyCoagentRenderer({
|
|
3911
3859
|
copilotkit,
|
|
3912
3860
|
agent,
|
|
@@ -3914,7 +3862,7 @@ function useCopilotChatInternal({
|
|
|
3914
3862
|
threadId: (_b = existingConfig == null ? void 0 : existingConfig.threadId) != null ? _b : threadId
|
|
3915
3863
|
});
|
|
3916
3864
|
const allMessages = (_c = agent == null ? void 0 : agent.messages) != null ? _c : [];
|
|
3917
|
-
const resolvedMessages = (0,
|
|
3865
|
+
const resolvedMessages = (0, import_react25.useMemo)(() => {
|
|
3918
3866
|
let processedMessages = allMessages.map((message) => {
|
|
3919
3867
|
if (message.role !== "assistant") {
|
|
3920
3868
|
return message;
|
|
@@ -3951,6 +3899,15 @@ function useCopilotChatInternal({
|
|
|
3951
3899
|
// legacyCustomMessageRenderer,
|
|
3952
3900
|
resolvedAgentId
|
|
3953
3901
|
]);
|
|
3902
|
+
const renderedSuggestions = (0, import_react25.useMemo)(() => {
|
|
3903
|
+
if (Array.isArray(suggestions)) {
|
|
3904
|
+
return {
|
|
3905
|
+
suggestions: suggestions.map((s) => __spreadProps(__spreadValues({}, s), { isLoading: false })),
|
|
3906
|
+
isLoading: false
|
|
3907
|
+
};
|
|
3908
|
+
}
|
|
3909
|
+
return currentSuggestions;
|
|
3910
|
+
}, [suggestions, currentSuggestions]);
|
|
3954
3911
|
return {
|
|
3955
3912
|
messages: resolvedMessages,
|
|
3956
3913
|
sendMessage: latestSendMessageFunc,
|
|
@@ -3964,21 +3921,21 @@ function useCopilotChatInternal({
|
|
|
3964
3921
|
isLoading: Boolean(agent == null ? void 0 : agent.isRunning),
|
|
3965
3922
|
// mcpServers,
|
|
3966
3923
|
// setMcpServers,
|
|
3967
|
-
suggestions:
|
|
3924
|
+
suggestions: renderedSuggestions.suggestions,
|
|
3968
3925
|
setSuggestions: (suggestions2) => copilotkit.addSuggestionsConfig({ suggestions: suggestions2 }),
|
|
3969
3926
|
generateSuggestions: () => __async(this, null, function* () {
|
|
3970
3927
|
return copilotkit.reloadSuggestions(resolvedAgentId);
|
|
3971
3928
|
}),
|
|
3972
3929
|
resetSuggestions: () => copilotkit.clearSuggestions(resolvedAgentId),
|
|
3973
|
-
isLoadingSuggestions:
|
|
3930
|
+
isLoadingSuggestions: renderedSuggestions.isLoading,
|
|
3974
3931
|
interrupt,
|
|
3975
3932
|
agent,
|
|
3976
3933
|
threadId
|
|
3977
3934
|
};
|
|
3978
3935
|
}
|
|
3979
3936
|
function useUpdatedRef(value) {
|
|
3980
|
-
const ref = (0,
|
|
3981
|
-
(0,
|
|
3937
|
+
const ref = (0, import_react25.useRef)(value);
|
|
3938
|
+
(0, import_react25.useEffect)(() => {
|
|
3982
3939
|
ref.current = value;
|
|
3983
3940
|
}, [value]);
|
|
3984
3941
|
return ref;
|
|
@@ -3989,7 +3946,7 @@ function useLegacyCoagentRenderer({
|
|
|
3989
3946
|
agentId,
|
|
3990
3947
|
threadId
|
|
3991
3948
|
}) {
|
|
3992
|
-
return (0,
|
|
3949
|
+
return (0, import_react25.useMemo)(() => {
|
|
3993
3950
|
if (!copilotkit || !agent) {
|
|
3994
3951
|
return null;
|
|
3995
3952
|
}
|
|
@@ -4012,7 +3969,7 @@ function useLegacyCoagentRenderer({
|
|
|
4012
3969
|
agentId,
|
|
4013
3970
|
stateSnapshot: message.state
|
|
4014
3971
|
};
|
|
4015
|
-
return (0,
|
|
3972
|
+
return (0, import_react25.createElement)(CoAgentStateRenderBridge, bridgeProps);
|
|
4016
3973
|
};
|
|
4017
3974
|
}, [agent, agentId, copilotkit, threadId]);
|
|
4018
3975
|
}
|
|
@@ -4046,7 +4003,7 @@ function useCopilotChat(options = {}) {
|
|
|
4046
4003
|
}
|
|
4047
4004
|
|
|
4048
4005
|
// src/hooks/use-copilot-chat-headless_c.ts
|
|
4049
|
-
var
|
|
4006
|
+
var import_react27 = require("react");
|
|
4050
4007
|
var import_shared15 = require("@copilotkit/shared");
|
|
4051
4008
|
var createNonFunctionalReturn = () => ({
|
|
4052
4009
|
visibleMessages: [],
|
|
@@ -4087,7 +4044,7 @@ function useCopilotChatHeadless_c(options = {}) {
|
|
|
4087
4044
|
const { copilotApiConfig, setBannerError } = useCopilotContext();
|
|
4088
4045
|
const hasPublicApiKey = Boolean(copilotApiConfig.publicApiKey);
|
|
4089
4046
|
const internalResult = useCopilotChatInternal(options);
|
|
4090
|
-
(0,
|
|
4047
|
+
(0, import_react27.useEffect)(() => {
|
|
4091
4048
|
if (!hasPublicApiKey) {
|
|
4092
4049
|
setBannerError(
|
|
4093
4050
|
new import_shared15.CopilotKitError({
|
|
@@ -4112,13 +4069,13 @@ function useCopilotChatHeadless_c(options = {}) {
|
|
|
4112
4069
|
}
|
|
4113
4070
|
|
|
4114
4071
|
// src/hooks/use-copilot-action.ts
|
|
4115
|
-
var
|
|
4072
|
+
var import_react34 = require("react");
|
|
4116
4073
|
|
|
4117
4074
|
// src/hooks/use-frontend-tool.ts
|
|
4118
|
-
var
|
|
4075
|
+
var import_react28 = __toESM(require("react"));
|
|
4119
4076
|
var import_shared16 = require("@copilotkit/shared");
|
|
4120
4077
|
var import_shared17 = require("@copilotkit/shared");
|
|
4121
|
-
var
|
|
4078
|
+
var import_react29 = require("@copilotkitnext/react");
|
|
4122
4079
|
function useFrontendTool(tool, dependencies) {
|
|
4123
4080
|
const { name, description, parameters, render, followUp } = tool;
|
|
4124
4081
|
const zodParameters = (0, import_shared16.getZodParameters)(parameters);
|
|
@@ -4128,8 +4085,8 @@ function useFrontendTool(tool, dependencies) {
|
|
|
4128
4085
|
}
|
|
4129
4086
|
if (typeof render === "string") {
|
|
4130
4087
|
const staticRender = render;
|
|
4131
|
-
return () =>
|
|
4132
|
-
|
|
4088
|
+
return () => import_react28.default.createElement(
|
|
4089
|
+
import_react28.default.Fragment,
|
|
4133
4090
|
null,
|
|
4134
4091
|
staticRender
|
|
4135
4092
|
);
|
|
@@ -4140,12 +4097,12 @@ function useFrontendTool(tool, dependencies) {
|
|
|
4140
4097
|
});
|
|
4141
4098
|
const rendered = render(renderArgs);
|
|
4142
4099
|
if (typeof rendered === "string") {
|
|
4143
|
-
return
|
|
4100
|
+
return import_react28.default.createElement(import_react28.default.Fragment, null, rendered);
|
|
4144
4101
|
}
|
|
4145
4102
|
return rendered != null ? rendered : null;
|
|
4146
4103
|
};
|
|
4147
4104
|
})();
|
|
4148
|
-
(0,
|
|
4105
|
+
(0, import_react29.useFrontendTool)({
|
|
4149
4106
|
name,
|
|
4150
4107
|
description,
|
|
4151
4108
|
parameters: zodParameters,
|
|
@@ -4157,23 +4114,23 @@ function useFrontendTool(tool, dependencies) {
|
|
|
4157
4114
|
|
|
4158
4115
|
// src/hooks/use-render-tool-call.ts
|
|
4159
4116
|
var import_shared18 = require("@copilotkit/shared");
|
|
4160
|
-
var
|
|
4161
|
-
var
|
|
4117
|
+
var import_react30 = require("react");
|
|
4118
|
+
var import_react31 = require("@copilotkitnext/react");
|
|
4162
4119
|
var import_shared19 = require("@copilotkit/shared");
|
|
4163
4120
|
function useRenderToolCall2(tool, dependencies) {
|
|
4164
|
-
const { copilotkit } = (0,
|
|
4165
|
-
const hasAddedRef = (0,
|
|
4166
|
-
(0,
|
|
4121
|
+
const { copilotkit } = (0, import_react31.useCopilotKit)();
|
|
4122
|
+
const hasAddedRef = (0, import_react30.useRef)(false);
|
|
4123
|
+
(0, import_react30.useEffect)(() => {
|
|
4167
4124
|
const { name, parameters, render } = tool;
|
|
4168
4125
|
const zodParameters = (0, import_shared18.getZodParameters)(parameters);
|
|
4169
|
-
const renderToolCall = name === "*" ? (0,
|
|
4126
|
+
const renderToolCall = name === "*" ? (0, import_react31.defineToolCallRenderer)({
|
|
4170
4127
|
name: "*",
|
|
4171
4128
|
render: (args) => {
|
|
4172
4129
|
return render(__spreadProps(__spreadValues({}, args), {
|
|
4173
4130
|
result: args.result ? (0, import_shared19.parseJson)(args.result, args.result) : args.result
|
|
4174
4131
|
}));
|
|
4175
4132
|
}
|
|
4176
|
-
}) : (0,
|
|
4133
|
+
}) : (0, import_react31.defineToolCallRenderer)({
|
|
4177
4134
|
name,
|
|
4178
4135
|
args: zodParameters,
|
|
4179
4136
|
render: (args) => {
|
|
@@ -4202,18 +4159,18 @@ function useRenderToolCall2(tool, dependencies) {
|
|
|
4202
4159
|
|
|
4203
4160
|
// src/hooks/use-human-in-the-loop.ts
|
|
4204
4161
|
var import_shared20 = require("@copilotkit/shared");
|
|
4205
|
-
var
|
|
4162
|
+
var import_react32 = require("@copilotkitnext/react");
|
|
4206
4163
|
var import_core = require("@copilotkitnext/core");
|
|
4207
|
-
var
|
|
4164
|
+
var import_react33 = __toESM(require("react"));
|
|
4208
4165
|
function useHumanInTheLoop(tool, dependencies) {
|
|
4209
4166
|
const _a = tool, { render } = _a, toolRest = __objRest(_a, ["render"]);
|
|
4210
4167
|
const { name, description, parameters, followUp } = toolRest;
|
|
4211
4168
|
const zodParameters = (0, import_shared20.getZodParameters)(parameters);
|
|
4212
|
-
const renderRef = (0,
|
|
4213
|
-
(0,
|
|
4169
|
+
const renderRef = (0, import_react33.useRef)(null);
|
|
4170
|
+
(0, import_react33.useEffect)(() => {
|
|
4214
4171
|
renderRef.current = (args) => {
|
|
4215
4172
|
if (typeof render === "string") {
|
|
4216
|
-
return
|
|
4173
|
+
return import_react33.default.createElement(import_react33.default.Fragment, null, render);
|
|
4217
4174
|
}
|
|
4218
4175
|
if (!render) {
|
|
4219
4176
|
return null;
|
|
@@ -4253,12 +4210,12 @@ function useHumanInTheLoop(tool, dependencies) {
|
|
|
4253
4210
|
})();
|
|
4254
4211
|
const rendered = render(renderProps);
|
|
4255
4212
|
if (typeof rendered === "string") {
|
|
4256
|
-
return
|
|
4213
|
+
return import_react33.default.createElement(import_react33.default.Fragment, null, rendered);
|
|
4257
4214
|
}
|
|
4258
4215
|
return rendered != null ? rendered : null;
|
|
4259
4216
|
};
|
|
4260
4217
|
}, [render, ...dependencies != null ? dependencies : []]);
|
|
4261
|
-
(0,
|
|
4218
|
+
(0, import_react32.useHumanInTheLoop)({
|
|
4262
4219
|
name,
|
|
4263
4220
|
description,
|
|
4264
4221
|
followUp,
|
|
@@ -4314,7 +4271,7 @@ function getActionConfig(action) {
|
|
|
4314
4271
|
throw new Error("Invalid action configuration");
|
|
4315
4272
|
}
|
|
4316
4273
|
function useCopilotAction(action, dependencies) {
|
|
4317
|
-
const [initialActionConfig] = (0,
|
|
4274
|
+
const [initialActionConfig] = (0, import_react34.useState)(getActionConfig(action));
|
|
4318
4275
|
const currentActionConfig = getActionConfig(action);
|
|
4319
4276
|
if (initialActionConfig.type !== currentActionConfig.type) {
|
|
4320
4277
|
throw new Error("Action configuration changed between renders");
|
|
@@ -4332,14 +4289,14 @@ function useCopilotAction(action, dependencies) {
|
|
|
4332
4289
|
}
|
|
4333
4290
|
|
|
4334
4291
|
// src/hooks/use-coagent-state-render.ts
|
|
4335
|
-
var
|
|
4292
|
+
var import_react35 = require("react");
|
|
4336
4293
|
var import_shared21 = require("@copilotkit/shared");
|
|
4337
4294
|
function useCoAgentStateRender(action, dependencies) {
|
|
4338
|
-
const { chatComponentsCache, availableAgents } = (0,
|
|
4295
|
+
const { chatComponentsCache, availableAgents } = (0, import_react35.useContext)(CopilotContext);
|
|
4339
4296
|
const { setCoAgentStateRender, removeCoAgentStateRender, coAgentStateRenders } = useCoAgentStateRenders();
|
|
4340
|
-
const idRef = (0,
|
|
4297
|
+
const idRef = (0, import_react35.useRef)((0, import_shared21.randomId)());
|
|
4341
4298
|
const { setBannerError, addToast } = useToast();
|
|
4342
|
-
(0,
|
|
4299
|
+
(0, import_react35.useEffect)(() => {
|
|
4343
4300
|
if ((availableAgents == null ? void 0 : availableAgents.length) && !availableAgents.some((a) => a.name === action.name)) {
|
|
4344
4301
|
const message = `(useCoAgentStateRender): Agent "${action.name}" not found. Make sure the agent exists and is properly configured.`;
|
|
4345
4302
|
const agentError = new import_shared21.CopilotKitAgentDiscoveryError({
|
|
@@ -4360,7 +4317,7 @@ function useCoAgentStateRender(action, dependencies) {
|
|
|
4360
4317
|
}
|
|
4361
4318
|
}
|
|
4362
4319
|
}
|
|
4363
|
-
(0,
|
|
4320
|
+
(0, import_react35.useEffect)(() => {
|
|
4364
4321
|
const currentId = idRef.current;
|
|
4365
4322
|
const hasDuplicate = Object.entries(coAgentStateRenders).some(([id, otherAction]) => {
|
|
4366
4323
|
if (id === currentId)
|
|
@@ -4384,7 +4341,7 @@ function useCoAgentStateRender(action, dependencies) {
|
|
|
4384
4341
|
});
|
|
4385
4342
|
}
|
|
4386
4343
|
}, [coAgentStateRenders]);
|
|
4387
|
-
(0,
|
|
4344
|
+
(0, import_react35.useEffect)(() => {
|
|
4388
4345
|
setCoAgentStateRender(idRef.current, action);
|
|
4389
4346
|
if (chatComponentsCache.current !== null && action.render !== void 0) {
|
|
4390
4347
|
chatComponentsCache.current.coAgentStateRenders[key] = action.render;
|
|
@@ -4404,11 +4361,11 @@ function useCoAgentStateRender(action, dependencies) {
|
|
|
4404
4361
|
}
|
|
4405
4362
|
|
|
4406
4363
|
// src/hooks/use-make-copilot-document-readable.ts
|
|
4407
|
-
var
|
|
4364
|
+
var import_react36 = require("react");
|
|
4408
4365
|
function useMakeCopilotDocumentReadable(document2, categories, dependencies = []) {
|
|
4409
4366
|
const { addDocumentContext, removeDocumentContext } = useCopilotContext();
|
|
4410
|
-
const idRef = (0,
|
|
4411
|
-
(0,
|
|
4367
|
+
const idRef = (0, import_react36.useRef)(void 0);
|
|
4368
|
+
(0, import_react36.useEffect)(() => {
|
|
4412
4369
|
const id = addDocumentContext(document2, categories);
|
|
4413
4370
|
idRef.current = id;
|
|
4414
4371
|
return () => {
|
|
@@ -4419,12 +4376,12 @@ function useMakeCopilotDocumentReadable(document2, categories, dependencies = []
|
|
|
4419
4376
|
}
|
|
4420
4377
|
|
|
4421
4378
|
// src/hooks/use-copilot-readable.ts
|
|
4422
|
-
var
|
|
4423
|
-
var
|
|
4379
|
+
var import_react37 = require("@copilotkitnext/react");
|
|
4380
|
+
var import_react38 = require("react");
|
|
4424
4381
|
function useCopilotReadable({ description, value, convert, available }, dependencies) {
|
|
4425
|
-
const { copilotkit } = (0,
|
|
4426
|
-
const ctxIdRef = (0,
|
|
4427
|
-
(0,
|
|
4382
|
+
const { copilotkit } = (0, import_react37.useCopilotKit)();
|
|
4383
|
+
const ctxIdRef = (0, import_react38.useRef)(void 0);
|
|
4384
|
+
(0, import_react38.useEffect)(() => {
|
|
4428
4385
|
if (!copilotkit)
|
|
4429
4386
|
return;
|
|
4430
4387
|
const found = Object.entries(copilotkit.context).find(([id, ctxItem]) => {
|
|
@@ -4452,13 +4409,13 @@ function useCopilotReadable({ description, value, convert, available }, dependen
|
|
|
4452
4409
|
}
|
|
4453
4410
|
|
|
4454
4411
|
// src/hooks/use-coagent.ts
|
|
4455
|
-
var
|
|
4456
|
-
var
|
|
4412
|
+
var import_react39 = require("react");
|
|
4413
|
+
var import_react40 = require("@copilotkitnext/react");
|
|
4457
4414
|
function useCoAgent(options) {
|
|
4458
|
-
const { agent } = (0,
|
|
4459
|
-
const { copilotkit } = (0,
|
|
4415
|
+
const { agent } = (0, import_react40.useAgent)({ agentId: options.name });
|
|
4416
|
+
const { copilotkit } = (0, import_react40.useCopilotKit)();
|
|
4460
4417
|
const nodeName = useAgentNodeName(options.name);
|
|
4461
|
-
const handleStateUpdate = (0,
|
|
4418
|
+
const handleStateUpdate = (0, import_react39.useCallback)(
|
|
4462
4419
|
(newState) => {
|
|
4463
4420
|
if (!agent)
|
|
4464
4421
|
return;
|
|
@@ -4471,7 +4428,7 @@ function useCoAgent(options) {
|
|
|
4471
4428
|
},
|
|
4472
4429
|
[agent == null ? void 0 : agent.state, agent == null ? void 0 : agent.setState]
|
|
4473
4430
|
);
|
|
4474
|
-
(0,
|
|
4431
|
+
(0, import_react39.useEffect)(() => {
|
|
4475
4432
|
var _a;
|
|
4476
4433
|
if (!options.config && !options.configurable)
|
|
4477
4434
|
return;
|
|
@@ -4483,22 +4440,22 @@ function useCoAgent(options) {
|
|
|
4483
4440
|
}
|
|
4484
4441
|
copilotkit.setProperties(config);
|
|
4485
4442
|
}, [options.config, options.configurable]);
|
|
4486
|
-
const externalStateStr = (0,
|
|
4443
|
+
const externalStateStr = (0, import_react39.useMemo)(
|
|
4487
4444
|
() => isExternalStateManagement(options) ? JSON.stringify(options.state) : void 0,
|
|
4488
4445
|
[isExternalStateManagement(options) ? JSON.stringify(options.state) : void 0]
|
|
4489
4446
|
);
|
|
4490
|
-
(0,
|
|
4447
|
+
(0, import_react39.useEffect)(() => {
|
|
4491
4448
|
if ((agent == null ? void 0 : agent.state) && isExternalStateManagement(options) && JSON.stringify(options.state) !== JSON.stringify(agent.state)) {
|
|
4492
4449
|
handleStateUpdate(options.state);
|
|
4493
4450
|
}
|
|
4494
4451
|
}, [agent, externalStateStr, handleStateUpdate]);
|
|
4495
|
-
const hasStateValues = (0,
|
|
4452
|
+
const hasStateValues = (0, import_react39.useCallback)((value) => {
|
|
4496
4453
|
return Boolean(value && Object.keys(value).length);
|
|
4497
4454
|
}, []);
|
|
4498
|
-
const initialStateRef = (0,
|
|
4455
|
+
const initialStateRef = (0, import_react39.useRef)(
|
|
4499
4456
|
isExternalStateManagement(options) ? options.state : "initialState" in options ? options.initialState : void 0
|
|
4500
4457
|
);
|
|
4501
|
-
(0,
|
|
4458
|
+
(0, import_react39.useEffect)(() => {
|
|
4502
4459
|
if (isExternalStateManagement(options)) {
|
|
4503
4460
|
initialStateRef.current = options.state;
|
|
4504
4461
|
} else if ("initialState" in options) {
|
|
@@ -4507,7 +4464,7 @@ function useCoAgent(options) {
|
|
|
4507
4464
|
}, [
|
|
4508
4465
|
isExternalStateManagement(options) ? JSON.stringify(options.state) : "initialState" in options ? JSON.stringify(options.initialState) : void 0
|
|
4509
4466
|
]);
|
|
4510
|
-
(0,
|
|
4467
|
+
(0, import_react39.useEffect)(() => {
|
|
4511
4468
|
if (!agent)
|
|
4512
4469
|
return;
|
|
4513
4470
|
const subscriber = {
|
|
@@ -4535,7 +4492,7 @@ function useCoAgent(options) {
|
|
|
4535
4492
|
subscription.unsubscribe();
|
|
4536
4493
|
};
|
|
4537
4494
|
}, [agent, handleStateUpdate, hasStateValues]);
|
|
4538
|
-
return (0,
|
|
4495
|
+
return (0, import_react39.useMemo)(() => {
|
|
4539
4496
|
var _a, _b, _c;
|
|
4540
4497
|
if (!agent) {
|
|
4541
4498
|
const noop = () => {
|
|
@@ -4591,12 +4548,12 @@ var isExternalStateManagement = (options) => {
|
|
|
4591
4548
|
|
|
4592
4549
|
// src/hooks/use-copilot-runtime-client.ts
|
|
4593
4550
|
var import_runtime_client_gql3 = require("@copilotkit/runtime-client-gql");
|
|
4594
|
-
var
|
|
4551
|
+
var import_react41 = require("react");
|
|
4595
4552
|
var import_shared22 = require("@copilotkit/shared");
|
|
4596
4553
|
var useCopilotRuntimeClient = (options) => {
|
|
4597
4554
|
const { setBannerError } = useToast();
|
|
4598
4555
|
const _a = options, { showDevConsole, onError } = _a, runtimeOptions = __objRest(_a, ["showDevConsole", "onError"]);
|
|
4599
|
-
const lastStructuredErrorRef = (0,
|
|
4556
|
+
const lastStructuredErrorRef = (0, import_react41.useRef)(null);
|
|
4600
4557
|
const traceUIError = (error, originalError) => __async(void 0, null, function* () {
|
|
4601
4558
|
try {
|
|
4602
4559
|
const errorEvent = {
|
|
@@ -4622,7 +4579,7 @@ var useCopilotRuntimeClient = (options) => {
|
|
|
4622
4579
|
console.error("Error in onError handler:", error2);
|
|
4623
4580
|
}
|
|
4624
4581
|
});
|
|
4625
|
-
const runtimeClient = (0,
|
|
4582
|
+
const runtimeClient = (0, import_react41.useMemo)(() => {
|
|
4626
4583
|
return new import_runtime_client_gql3.CopilotRuntimeClient(__spreadProps(__spreadValues({}, runtimeOptions), {
|
|
4627
4584
|
handleGQLErrors: (error) => {
|
|
4628
4585
|
var _a2;
|
|
@@ -4701,28 +4658,28 @@ function createStructuredError(gqlError) {
|
|
|
4701
4658
|
}
|
|
4702
4659
|
|
|
4703
4660
|
// src/hooks/use-copilot-authenticated-action.ts
|
|
4704
|
-
var
|
|
4705
|
-
var
|
|
4661
|
+
var import_react42 = require("react");
|
|
4662
|
+
var import_react43 = __toESM(require("react"));
|
|
4706
4663
|
function useCopilotAuthenticatedAction_c(action, dependencies) {
|
|
4707
4664
|
const { authConfig_c, authStates_c, setAuthStates_c } = useCopilotContext();
|
|
4708
|
-
const pendingActionRef = (0,
|
|
4709
|
-
const executeAction = (0,
|
|
4665
|
+
const pendingActionRef = (0, import_react42.useRef)(null);
|
|
4666
|
+
const executeAction = (0, import_react42.useCallback)(
|
|
4710
4667
|
(props) => {
|
|
4711
4668
|
if (typeof action.render === "function") {
|
|
4712
4669
|
return action.render(props);
|
|
4713
4670
|
}
|
|
4714
|
-
return action.render ||
|
|
4671
|
+
return action.render || import_react43.default.createElement(import_react42.Fragment);
|
|
4715
4672
|
},
|
|
4716
4673
|
[action]
|
|
4717
4674
|
);
|
|
4718
|
-
const wrappedRender = (0,
|
|
4675
|
+
const wrappedRender = (0, import_react42.useCallback)(
|
|
4719
4676
|
(props) => {
|
|
4720
4677
|
const isAuthenticated = Object.values(authStates_c || {}).some(
|
|
4721
4678
|
(state) => state.status === "authenticated"
|
|
4722
4679
|
);
|
|
4723
4680
|
if (!isAuthenticated) {
|
|
4724
4681
|
pendingActionRef.current = props;
|
|
4725
|
-
return (authConfig_c == null ? void 0 : authConfig_c.SignInComponent) ?
|
|
4682
|
+
return (authConfig_c == null ? void 0 : authConfig_c.SignInComponent) ? import_react43.default.createElement(authConfig_c.SignInComponent, {
|
|
4726
4683
|
onSignInComplete: (authState) => {
|
|
4727
4684
|
setAuthStates_c == null ? void 0 : setAuthStates_c((prev) => __spreadProps(__spreadValues({}, prev), { [action.name]: authState }));
|
|
4728
4685
|
if (pendingActionRef.current) {
|
|
@@ -4730,7 +4687,7 @@ function useCopilotAuthenticatedAction_c(action, dependencies) {
|
|
|
4730
4687
|
pendingActionRef.current = null;
|
|
4731
4688
|
}
|
|
4732
4689
|
}
|
|
4733
|
-
}) :
|
|
4690
|
+
}) : import_react43.default.createElement(import_react42.Fragment);
|
|
4734
4691
|
}
|
|
4735
4692
|
return executeAction(props);
|
|
4736
4693
|
},
|
|
@@ -4745,13 +4702,13 @@ function useCopilotAuthenticatedAction_c(action, dependencies) {
|
|
|
4745
4702
|
}
|
|
4746
4703
|
|
|
4747
4704
|
// src/hooks/use-langgraph-interrupt.ts
|
|
4748
|
-
var
|
|
4705
|
+
var import_react44 = require("react");
|
|
4749
4706
|
var import_shared23 = require("@copilotkit/shared");
|
|
4750
4707
|
function useLangGraphInterrupt(action, dependencies) {
|
|
4751
|
-
const { setInterruptAction, removeInterruptAction, interruptActions, threadId } = (0,
|
|
4708
|
+
const { setInterruptAction, removeInterruptAction, interruptActions, threadId } = (0, import_react44.useContext)(CopilotContext);
|
|
4752
4709
|
const { addToast } = useToast();
|
|
4753
4710
|
const actionId = (0, import_shared23.dataToUUID)(action, "lgAction");
|
|
4754
|
-
(0,
|
|
4711
|
+
(0, import_react44.useEffect)(() => {
|
|
4755
4712
|
if (!action)
|
|
4756
4713
|
return;
|
|
4757
4714
|
setInterruptAction(__spreadProps(__spreadValues({}, action), { id: actionId }));
|
|
@@ -4762,10 +4719,10 @@ function useLangGraphInterrupt(action, dependencies) {
|
|
|
4762
4719
|
}
|
|
4763
4720
|
|
|
4764
4721
|
// src/hooks/use-copilot-additional-instructions.ts
|
|
4765
|
-
var
|
|
4722
|
+
var import_react45 = require("react");
|
|
4766
4723
|
function useCopilotAdditionalInstructions({ instructions, available = "enabled" }, dependencies) {
|
|
4767
4724
|
const { setAdditionalInstructions } = useCopilotContext();
|
|
4768
|
-
(0,
|
|
4725
|
+
(0, import_react45.useEffect)(() => {
|
|
4769
4726
|
if (available === "disabled")
|
|
4770
4727
|
return;
|
|
4771
4728
|
setAdditionalInstructions((prevInstructions) => [...prevInstructions || [], instructions]);
|
|
@@ -4782,6 +4739,21 @@ function useDefaultTool(tool, dependencies) {
|
|
|
4782
4739
|
useCopilotAction(__spreadProps(__spreadValues({}, tool), { name: "*" }), dependencies);
|
|
4783
4740
|
}
|
|
4784
4741
|
|
|
4742
|
+
// src/hooks/use-copilot-chat-suggestions.tsx
|
|
4743
|
+
var import_react46 = require("@copilotkitnext/react");
|
|
4744
|
+
function useCopilotChatSuggestions(config, dependencies = []) {
|
|
4745
|
+
var _a, _b;
|
|
4746
|
+
const existingConfig = (0, import_react46.useCopilotChatConfiguration)();
|
|
4747
|
+
const resolvedAgentId = (_a = existingConfig == null ? void 0 : existingConfig.agentId) != null ? _a : "default";
|
|
4748
|
+
const available = (_b = config.available === "enabled" ? "always" : config.available) != null ? _b : "before-first-message";
|
|
4749
|
+
const finalSuggestionConfig = __spreadProps(__spreadValues({}, config), {
|
|
4750
|
+
available,
|
|
4751
|
+
consumerAgentId: resolvedAgentId
|
|
4752
|
+
// Use chatConfig.agentId here
|
|
4753
|
+
});
|
|
4754
|
+
(0, import_react46.useConfigureSuggestions)(finalSuggestionConfig, dependencies);
|
|
4755
|
+
}
|
|
4756
|
+
|
|
4785
4757
|
// src/lib/copilot-task.ts
|
|
4786
4758
|
var import_runtime_client_gql5 = require("@copilotkit/runtime-client-gql");
|
|
4787
4759
|
|
|
@@ -4921,13 +4893,13 @@ ${instructions}
|
|
|
4921
4893
|
useCoAgent,
|
|
4922
4894
|
useCoAgentStateRender,
|
|
4923
4895
|
useCoAgentStateRenders,
|
|
4924
|
-
useConfigureChatSuggestions,
|
|
4925
4896
|
useCopilotAction,
|
|
4926
4897
|
useCopilotAdditionalInstructions,
|
|
4927
4898
|
useCopilotAuthenticatedAction_c,
|
|
4928
4899
|
useCopilotChat,
|
|
4929
4900
|
useCopilotChatHeadless_c,
|
|
4930
4901
|
useCopilotChatInternal,
|
|
4902
|
+
useCopilotChatSuggestions,
|
|
4931
4903
|
useCopilotContext,
|
|
4932
4904
|
useCopilotMessagesContext,
|
|
4933
4905
|
useCopilotReadable,
|