@copilotkit/react-core 1.50.0-beta.7 → 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.
Files changed (62) hide show
  1. package/CHANGELOG.md +19 -2
  2. package/dist/{chunk-EKDPRKZT.mjs → chunk-3775VM7Y.mjs} +14 -26
  3. package/dist/chunk-3775VM7Y.mjs.map +1 -0
  4. package/dist/{chunk-BLDHD6Q2.mjs → chunk-7SHWECGN.mjs} +2 -2
  5. package/dist/{chunk-QSNZUI5G.mjs → chunk-B5ELMVT7.mjs} +2 -2
  6. package/dist/{chunk-WV57GREG.mjs → chunk-FYMZKPOL.mjs} +6 -6
  7. package/dist/chunk-XDFVCQD3.mjs +27 -0
  8. package/dist/chunk-XDFVCQD3.mjs.map +1 -0
  9. package/dist/{chunk-KYY2WZSR.mjs → chunk-YJGPIN3R.mjs} +2 -2
  10. package/dist/chunk-Z6JV2LRY.mjs +37 -0
  11. package/dist/chunk-Z6JV2LRY.mjs.map +1 -0
  12. package/dist/components/copilot-provider/copilotkit.mjs +7 -7
  13. package/dist/components/copilot-provider/index.mjs +7 -7
  14. package/dist/components/index.mjs +7 -7
  15. package/dist/hooks/index.d.ts +1 -1
  16. package/dist/hooks/index.js +146 -151
  17. package/dist/hooks/index.js.map +1 -1
  18. package/dist/hooks/index.mjs +24 -24
  19. package/dist/hooks/use-copilot-chat-headless_c.js +39 -82
  20. package/dist/hooks/use-copilot-chat-headless_c.js.map +1 -1
  21. package/dist/hooks/use-copilot-chat-headless_c.mjs +3 -4
  22. package/dist/hooks/{use-configure-chat-suggestions.d.ts → use-copilot-chat-suggestions.d.ts} +2 -3
  23. package/dist/hooks/{use-configure-chat-suggestions.js → use-copilot-chat-suggestions.js} +10 -29
  24. package/dist/hooks/use-copilot-chat-suggestions.js.map +1 -0
  25. package/dist/hooks/use-copilot-chat-suggestions.mjs +8 -0
  26. package/dist/hooks/use-copilot-chat.js +37 -80
  27. package/dist/hooks/use-copilot-chat.js.map +1 -1
  28. package/dist/hooks/use-copilot-chat.mjs +3 -4
  29. package/dist/hooks/use-copilot-chat_internal.d.ts +17 -0
  30. package/dist/hooks/use-copilot-chat_internal.js +37 -80
  31. package/dist/hooks/use-copilot-chat_internal.js.map +1 -1
  32. package/dist/hooks/use-copilot-chat_internal.mjs +2 -3
  33. package/dist/hooks/use-copilot-readable.d.ts +1 -1
  34. package/dist/hooks/use-copilot-readable.js +29 -6
  35. package/dist/hooks/use-copilot-readable.js.map +1 -1
  36. package/dist/hooks/use-copilot-readable.mjs +1 -1
  37. package/dist/index.d.ts +1 -1
  38. package/dist/index.js +139 -144
  39. package/dist/index.js.map +1 -1
  40. package/dist/index.mjs +35 -35
  41. package/dist/lib/copilot-task.mjs +8 -8
  42. package/dist/lib/index.mjs +8 -8
  43. package/dist/types/index.mjs +1 -1
  44. package/dist/utils/index.mjs +3 -3
  45. package/package.json +5 -5
  46. package/src/hooks/index.ts +2 -2
  47. package/src/hooks/use-copilot-chat-suggestions.tsx +124 -0
  48. package/src/hooks/use-copilot-chat_internal.ts +29 -29
  49. package/src/hooks/use-copilot-readable.ts +30 -13
  50. package/dist/chunk-2CYJN455.mjs +0 -14
  51. package/dist/chunk-2CYJN455.mjs.map +0 -1
  52. package/dist/chunk-EKDPRKZT.mjs.map +0 -1
  53. package/dist/chunk-FBVI3LQ6.mjs +0 -48
  54. package/dist/chunk-FBVI3LQ6.mjs.map +0 -1
  55. package/dist/hooks/use-configure-chat-suggestions.js.map +0 -1
  56. package/dist/hooks/use-configure-chat-suggestions.mjs +0 -8
  57. package/src/hooks/use-configure-chat-suggestions.tsx +0 -86
  58. /package/dist/{chunk-BLDHD6Q2.mjs.map → chunk-7SHWECGN.mjs.map} +0 -0
  59. /package/dist/{chunk-QSNZUI5G.mjs.map → chunk-B5ELMVT7.mjs.map} +0 -0
  60. /package/dist/{chunk-WV57GREG.mjs.map → chunk-FYMZKPOL.mjs.map} +0 -0
  61. /package/dist/{chunk-KYY2WZSR.mjs.map → chunk-YJGPIN3R.mjs.map} +0 -0
  62. /package/dist/hooks/{use-configure-chat-suggestions.mjs.map → use-copilot-chat-suggestions.mjs.map} +0 -0
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 import_react27 = require("react");
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 import_react28 = require("@copilotkitnext/react");
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, import_react28.useCopilotKit)();
3716
+ const { copilotkit } = (0, import_react26.useCopilotKit)();
3768
3717
  const { threadId, agentSession } = useCopilotContext();
3769
- const existingConfig = (0, import_react28.useCopilotChatConfiguration)();
3770
- const [agentAvailable, setAgentAvailable] = (0, import_react27.useState)(false);
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, import_react28.useAgent)({ agentId: resolvedAgentId });
3774
- (0, import_react27.useEffect)(() => {
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, import_react27.useCallback)(
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, import_react27.useCallback)(
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, import_react28.useSuggestions)({ agentId: resolvedAgentId });
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, import_react27.useCallback)(
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, import_react27.useCallback)(() => {
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, import_react27.useCallback)(() => {
3853
+ const latestResetFunc = (0, import_react25.useCallback)(() => {
3906
3854
  return latestReset.current();
3907
3855
  }, [latestReset]);
3908
3856
  const lazyToolRendered = useLazyToolRenderer();
3909
- const renderCustomMessage = (0, import_react28.useRenderCustomMessages)();
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, import_react27.useMemo)(() => {
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: currentSuggestions.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: currentSuggestions.isLoading,
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, import_react27.useRef)(value);
3981
- (0, import_react27.useEffect)(() => {
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, import_react27.useMemo)(() => {
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, import_react27.createElement)(CoAgentStateRenderBridge, bridgeProps);
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 import_react29 = require("react");
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, import_react29.useEffect)(() => {
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 import_react36 = require("react");
4072
+ var import_react34 = require("react");
4116
4073
 
4117
4074
  // src/hooks/use-frontend-tool.ts
4118
- var import_react30 = __toESM(require("react"));
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 import_react31 = require("@copilotkitnext/react");
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 () => import_react30.default.createElement(
4132
- import_react30.default.Fragment,
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 import_react30.default.createElement(import_react30.default.Fragment, null, rendered);
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, import_react31.useFrontendTool)({
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 import_react32 = require("react");
4161
- var import_react33 = require("@copilotkitnext/react");
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, import_react33.useCopilotKit)();
4165
- const hasAddedRef = (0, import_react32.useRef)(false);
4166
- (0, import_react32.useEffect)(() => {
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, import_react33.defineToolCallRenderer)({
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, import_react33.defineToolCallRenderer)({
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 import_react34 = require("@copilotkitnext/react");
4162
+ var import_react32 = require("@copilotkitnext/react");
4206
4163
  var import_core = require("@copilotkitnext/core");
4207
- var import_react35 = __toESM(require("react"));
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, import_react35.useRef)(null);
4213
- (0, import_react35.useEffect)(() => {
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 import_react35.default.createElement(import_react35.default.Fragment, null, render);
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 import_react35.default.createElement(import_react35.default.Fragment, null, rendered);
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, import_react34.useHumanInTheLoop)({
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, import_react36.useState)(getActionConfig(action));
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 import_react37 = require("react");
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, import_react37.useContext)(CopilotContext);
4295
+ const { chatComponentsCache, availableAgents } = (0, import_react35.useContext)(CopilotContext);
4339
4296
  const { setCoAgentStateRender, removeCoAgentStateRender, coAgentStateRenders } = useCoAgentStateRenders();
4340
- const idRef = (0, import_react37.useRef)((0, import_shared21.randomId)());
4297
+ const idRef = (0, import_react35.useRef)((0, import_shared21.randomId)());
4341
4298
  const { setBannerError, addToast } = useToast();
4342
- (0, import_react37.useEffect)(() => {
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, import_react37.useEffect)(() => {
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, import_react37.useEffect)(() => {
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 import_react38 = require("react");
4364
+ var import_react36 = require("react");
4408
4365
  function useMakeCopilotDocumentReadable(document2, categories, dependencies = []) {
4409
4366
  const { addDocumentContext, removeDocumentContext } = useCopilotContext();
4410
- const idRef = (0, import_react38.useRef)(void 0);
4411
- (0, import_react38.useEffect)(() => {
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,23 +4376,46 @@ function useMakeCopilotDocumentReadable(document2, categories, dependencies = []
4419
4376
  }
4420
4377
 
4421
4378
  // src/hooks/use-copilot-readable.ts
4422
- var import_react39 = require("@copilotkitnext/react");
4423
- function useCopilotReadable({ description, value }, dependencies) {
4424
- (0, import_react39.useAgentContext)({
4425
- description,
4426
- value
4427
- });
4428
- return;
4379
+ var import_react37 = require("@copilotkitnext/react");
4380
+ var import_react38 = require("react");
4381
+ function useCopilotReadable({ description, value, convert, available }, dependencies) {
4382
+ const { copilotkit } = (0, import_react37.useCopilotKit)();
4383
+ const ctxIdRef = (0, import_react38.useRef)(void 0);
4384
+ (0, import_react38.useEffect)(() => {
4385
+ if (!copilotkit)
4386
+ return;
4387
+ const found = Object.entries(copilotkit.context).find(([id, ctxItem]) => {
4388
+ return JSON.stringify({ description, value }) == JSON.stringify(ctxItem);
4389
+ });
4390
+ if (found) {
4391
+ ctxIdRef.current = found[0];
4392
+ if (available === "disabled")
4393
+ copilotkit.removeContext(ctxIdRef.current);
4394
+ return;
4395
+ }
4396
+ if (!found && available === "disabled")
4397
+ return;
4398
+ ctxIdRef.current = copilotkit.addContext({
4399
+ description,
4400
+ value: (convert != null ? convert : JSON.stringify)(value)
4401
+ });
4402
+ return () => {
4403
+ if (!ctxIdRef.current)
4404
+ return;
4405
+ copilotkit.removeContext(ctxIdRef.current);
4406
+ };
4407
+ }, [description, value, convert]);
4408
+ return ctxIdRef.current;
4429
4409
  }
4430
4410
 
4431
4411
  // src/hooks/use-coagent.ts
4432
- var import_react40 = require("react");
4433
- var import_react41 = require("@copilotkitnext/react");
4412
+ var import_react39 = require("react");
4413
+ var import_react40 = require("@copilotkitnext/react");
4434
4414
  function useCoAgent(options) {
4435
- const { agent } = (0, import_react41.useAgent)({ agentId: options.name });
4436
- const { copilotkit } = (0, import_react41.useCopilotKit)();
4415
+ const { agent } = (0, import_react40.useAgent)({ agentId: options.name });
4416
+ const { copilotkit } = (0, import_react40.useCopilotKit)();
4437
4417
  const nodeName = useAgentNodeName(options.name);
4438
- const handleStateUpdate = (0, import_react40.useCallback)(
4418
+ const handleStateUpdate = (0, import_react39.useCallback)(
4439
4419
  (newState) => {
4440
4420
  if (!agent)
4441
4421
  return;
@@ -4448,7 +4428,7 @@ function useCoAgent(options) {
4448
4428
  },
4449
4429
  [agent == null ? void 0 : agent.state, agent == null ? void 0 : agent.setState]
4450
4430
  );
4451
- (0, import_react40.useEffect)(() => {
4431
+ (0, import_react39.useEffect)(() => {
4452
4432
  var _a;
4453
4433
  if (!options.config && !options.configurable)
4454
4434
  return;
@@ -4460,22 +4440,22 @@ function useCoAgent(options) {
4460
4440
  }
4461
4441
  copilotkit.setProperties(config);
4462
4442
  }, [options.config, options.configurable]);
4463
- const externalStateStr = (0, import_react40.useMemo)(
4443
+ const externalStateStr = (0, import_react39.useMemo)(
4464
4444
  () => isExternalStateManagement(options) ? JSON.stringify(options.state) : void 0,
4465
4445
  [isExternalStateManagement(options) ? JSON.stringify(options.state) : void 0]
4466
4446
  );
4467
- (0, import_react40.useEffect)(() => {
4447
+ (0, import_react39.useEffect)(() => {
4468
4448
  if ((agent == null ? void 0 : agent.state) && isExternalStateManagement(options) && JSON.stringify(options.state) !== JSON.stringify(agent.state)) {
4469
4449
  handleStateUpdate(options.state);
4470
4450
  }
4471
4451
  }, [agent, externalStateStr, handleStateUpdate]);
4472
- const hasStateValues = (0, import_react40.useCallback)((value) => {
4452
+ const hasStateValues = (0, import_react39.useCallback)((value) => {
4473
4453
  return Boolean(value && Object.keys(value).length);
4474
4454
  }, []);
4475
- const initialStateRef = (0, import_react40.useRef)(
4455
+ const initialStateRef = (0, import_react39.useRef)(
4476
4456
  isExternalStateManagement(options) ? options.state : "initialState" in options ? options.initialState : void 0
4477
4457
  );
4478
- (0, import_react40.useEffect)(() => {
4458
+ (0, import_react39.useEffect)(() => {
4479
4459
  if (isExternalStateManagement(options)) {
4480
4460
  initialStateRef.current = options.state;
4481
4461
  } else if ("initialState" in options) {
@@ -4484,7 +4464,7 @@ function useCoAgent(options) {
4484
4464
  }, [
4485
4465
  isExternalStateManagement(options) ? JSON.stringify(options.state) : "initialState" in options ? JSON.stringify(options.initialState) : void 0
4486
4466
  ]);
4487
- (0, import_react40.useEffect)(() => {
4467
+ (0, import_react39.useEffect)(() => {
4488
4468
  if (!agent)
4489
4469
  return;
4490
4470
  const subscriber = {
@@ -4512,7 +4492,7 @@ function useCoAgent(options) {
4512
4492
  subscription.unsubscribe();
4513
4493
  };
4514
4494
  }, [agent, handleStateUpdate, hasStateValues]);
4515
- return (0, import_react40.useMemo)(() => {
4495
+ return (0, import_react39.useMemo)(() => {
4516
4496
  var _a, _b, _c;
4517
4497
  if (!agent) {
4518
4498
  const noop = () => {
@@ -4568,12 +4548,12 @@ var isExternalStateManagement = (options) => {
4568
4548
 
4569
4549
  // src/hooks/use-copilot-runtime-client.ts
4570
4550
  var import_runtime_client_gql3 = require("@copilotkit/runtime-client-gql");
4571
- var import_react42 = require("react");
4551
+ var import_react41 = require("react");
4572
4552
  var import_shared22 = require("@copilotkit/shared");
4573
4553
  var useCopilotRuntimeClient = (options) => {
4574
4554
  const { setBannerError } = useToast();
4575
4555
  const _a = options, { showDevConsole, onError } = _a, runtimeOptions = __objRest(_a, ["showDevConsole", "onError"]);
4576
- const lastStructuredErrorRef = (0, import_react42.useRef)(null);
4556
+ const lastStructuredErrorRef = (0, import_react41.useRef)(null);
4577
4557
  const traceUIError = (error, originalError) => __async(void 0, null, function* () {
4578
4558
  try {
4579
4559
  const errorEvent = {
@@ -4599,7 +4579,7 @@ var useCopilotRuntimeClient = (options) => {
4599
4579
  console.error("Error in onError handler:", error2);
4600
4580
  }
4601
4581
  });
4602
- const runtimeClient = (0, import_react42.useMemo)(() => {
4582
+ const runtimeClient = (0, import_react41.useMemo)(() => {
4603
4583
  return new import_runtime_client_gql3.CopilotRuntimeClient(__spreadProps(__spreadValues({}, runtimeOptions), {
4604
4584
  handleGQLErrors: (error) => {
4605
4585
  var _a2;
@@ -4678,28 +4658,28 @@ function createStructuredError(gqlError) {
4678
4658
  }
4679
4659
 
4680
4660
  // src/hooks/use-copilot-authenticated-action.ts
4681
- var import_react43 = require("react");
4682
- var import_react44 = __toESM(require("react"));
4661
+ var import_react42 = require("react");
4662
+ var import_react43 = __toESM(require("react"));
4683
4663
  function useCopilotAuthenticatedAction_c(action, dependencies) {
4684
4664
  const { authConfig_c, authStates_c, setAuthStates_c } = useCopilotContext();
4685
- const pendingActionRef = (0, import_react43.useRef)(null);
4686
- const executeAction = (0, import_react43.useCallback)(
4665
+ const pendingActionRef = (0, import_react42.useRef)(null);
4666
+ const executeAction = (0, import_react42.useCallback)(
4687
4667
  (props) => {
4688
4668
  if (typeof action.render === "function") {
4689
4669
  return action.render(props);
4690
4670
  }
4691
- return action.render || import_react44.default.createElement(import_react43.Fragment);
4671
+ return action.render || import_react43.default.createElement(import_react42.Fragment);
4692
4672
  },
4693
4673
  [action]
4694
4674
  );
4695
- const wrappedRender = (0, import_react43.useCallback)(
4675
+ const wrappedRender = (0, import_react42.useCallback)(
4696
4676
  (props) => {
4697
4677
  const isAuthenticated = Object.values(authStates_c || {}).some(
4698
4678
  (state) => state.status === "authenticated"
4699
4679
  );
4700
4680
  if (!isAuthenticated) {
4701
4681
  pendingActionRef.current = props;
4702
- return (authConfig_c == null ? void 0 : authConfig_c.SignInComponent) ? import_react44.default.createElement(authConfig_c.SignInComponent, {
4682
+ return (authConfig_c == null ? void 0 : authConfig_c.SignInComponent) ? import_react43.default.createElement(authConfig_c.SignInComponent, {
4703
4683
  onSignInComplete: (authState) => {
4704
4684
  setAuthStates_c == null ? void 0 : setAuthStates_c((prev) => __spreadProps(__spreadValues({}, prev), { [action.name]: authState }));
4705
4685
  if (pendingActionRef.current) {
@@ -4707,7 +4687,7 @@ function useCopilotAuthenticatedAction_c(action, dependencies) {
4707
4687
  pendingActionRef.current = null;
4708
4688
  }
4709
4689
  }
4710
- }) : import_react44.default.createElement(import_react43.Fragment);
4690
+ }) : import_react43.default.createElement(import_react42.Fragment);
4711
4691
  }
4712
4692
  return executeAction(props);
4713
4693
  },
@@ -4722,13 +4702,13 @@ function useCopilotAuthenticatedAction_c(action, dependencies) {
4722
4702
  }
4723
4703
 
4724
4704
  // src/hooks/use-langgraph-interrupt.ts
4725
- var import_react45 = require("react");
4705
+ var import_react44 = require("react");
4726
4706
  var import_shared23 = require("@copilotkit/shared");
4727
4707
  function useLangGraphInterrupt(action, dependencies) {
4728
- const { setInterruptAction, removeInterruptAction, interruptActions, threadId } = (0, import_react45.useContext)(CopilotContext);
4708
+ const { setInterruptAction, removeInterruptAction, interruptActions, threadId } = (0, import_react44.useContext)(CopilotContext);
4729
4709
  const { addToast } = useToast();
4730
4710
  const actionId = (0, import_shared23.dataToUUID)(action, "lgAction");
4731
- (0, import_react45.useEffect)(() => {
4711
+ (0, import_react44.useEffect)(() => {
4732
4712
  if (!action)
4733
4713
  return;
4734
4714
  setInterruptAction(__spreadProps(__spreadValues({}, action), { id: actionId }));
@@ -4739,10 +4719,10 @@ function useLangGraphInterrupt(action, dependencies) {
4739
4719
  }
4740
4720
 
4741
4721
  // src/hooks/use-copilot-additional-instructions.ts
4742
- var import_react46 = require("react");
4722
+ var import_react45 = require("react");
4743
4723
  function useCopilotAdditionalInstructions({ instructions, available = "enabled" }, dependencies) {
4744
4724
  const { setAdditionalInstructions } = useCopilotContext();
4745
- (0, import_react46.useEffect)(() => {
4725
+ (0, import_react45.useEffect)(() => {
4746
4726
  if (available === "disabled")
4747
4727
  return;
4748
4728
  setAdditionalInstructions((prevInstructions) => [...prevInstructions || [], instructions]);
@@ -4759,6 +4739,21 @@ function useDefaultTool(tool, dependencies) {
4759
4739
  useCopilotAction(__spreadProps(__spreadValues({}, tool), { name: "*" }), dependencies);
4760
4740
  }
4761
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
+
4762
4757
  // src/lib/copilot-task.ts
4763
4758
  var import_runtime_client_gql5 = require("@copilotkit/runtime-client-gql");
4764
4759
 
@@ -4898,13 +4893,13 @@ ${instructions}
4898
4893
  useCoAgent,
4899
4894
  useCoAgentStateRender,
4900
4895
  useCoAgentStateRenders,
4901
- useConfigureChatSuggestions,
4902
4896
  useCopilotAction,
4903
4897
  useCopilotAdditionalInstructions,
4904
4898
  useCopilotAuthenticatedAction_c,
4905
4899
  useCopilotChat,
4906
4900
  useCopilotChatHeadless_c,
4907
4901
  useCopilotChatInternal,
4902
+ useCopilotChatSuggestions,
4908
4903
  useCopilotContext,
4909
4904
  useCopilotMessagesContext,
4910
4905
  useCopilotReadable,