@copilotkit/react-core 1.50.0-beta.8 → 1.50.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.
Files changed (77) hide show
  1. package/CHANGELOG.md +192 -0
  2. package/dist/{chunk-KYY2WZSR.mjs → chunk-5J7RRLRO.mjs} +2 -2
  3. package/dist/{chunk-ZU6ZBX4E.mjs → chunk-CO6V4G7P.mjs} +17 -9
  4. package/dist/chunk-CO6V4G7P.mjs.map +1 -0
  5. package/dist/{chunk-Y2L7KDVW.mjs → chunk-HQTDDA6V.mjs} +2 -2
  6. package/dist/chunk-LDEWO5XH.mjs +328 -0
  7. package/dist/chunk-LDEWO5XH.mjs.map +1 -0
  8. package/dist/chunk-XDFVCQD3.mjs +27 -0
  9. package/dist/chunk-XDFVCQD3.mjs.map +1 -0
  10. package/dist/{chunk-RQ6LWR6S.mjs → chunk-Z6JV2LRY.mjs} +1 -1
  11. package/dist/chunk-Z6JV2LRY.mjs.map +1 -0
  12. package/dist/{chunk-BLDHD6Q2.mjs → chunk-ZE4JVTEP.mjs} +2 -2
  13. package/dist/components/copilot-provider/copilotkit-props.d.ts +6 -0
  14. package/dist/components/copilot-provider/copilotkit-props.js.map +1 -1
  15. package/dist/components/copilot-provider/copilotkit.js +127 -1150
  16. package/dist/components/copilot-provider/copilotkit.js.map +1 -1
  17. package/dist/components/copilot-provider/copilotkit.mjs +3 -6
  18. package/dist/components/copilot-provider/index.js +127 -1150
  19. package/dist/components/copilot-provider/index.js.map +1 -1
  20. package/dist/components/copilot-provider/index.mjs +3 -6
  21. package/dist/components/dev-console/console-trigger.mjs +225 -5
  22. package/dist/components/dev-console/console-trigger.mjs.map +1 -1
  23. package/dist/components/index.js +127 -1150
  24. package/dist/components/index.js.map +1 -1
  25. package/dist/components/index.mjs +3 -6
  26. package/dist/hooks/index.d.ts +1 -1
  27. package/dist/hooks/index.js +124 -554
  28. package/dist/hooks/index.js.map +1 -1
  29. package/dist/hooks/index.mjs +19 -19
  30. package/dist/hooks/use-copilot-chat-headless_c.js +42 -487
  31. package/dist/hooks/use-copilot-chat-headless_c.js.map +1 -1
  32. package/dist/hooks/use-copilot-chat-headless_c.mjs +2 -3
  33. package/dist/hooks/{use-configure-chat-suggestions.d.ts → use-copilot-chat-suggestions.d.ts} +2 -3
  34. package/dist/hooks/{use-configure-chat-suggestions.js → use-copilot-chat-suggestions.js} +10 -29
  35. package/dist/hooks/use-copilot-chat-suggestions.js.map +1 -0
  36. package/dist/hooks/use-copilot-chat-suggestions.mjs +8 -0
  37. package/dist/hooks/use-copilot-chat.js +40 -485
  38. package/dist/hooks/use-copilot-chat.js.map +1 -1
  39. package/dist/hooks/use-copilot-chat.mjs +2 -3
  40. package/dist/hooks/use-copilot-chat_internal.d.ts +17 -0
  41. package/dist/hooks/use-copilot-chat_internal.js +40 -485
  42. package/dist/hooks/use-copilot-chat_internal.js.map +1 -1
  43. package/dist/hooks/use-copilot-chat_internal.mjs +1 -2
  44. package/dist/hooks/use-copilot-readable.d.ts +2 -3
  45. package/dist/hooks/use-copilot-readable.js.map +1 -1
  46. package/dist/hooks/use-copilot-readable.mjs +1 -1
  47. package/dist/index.d.ts +1 -1
  48. package/dist/index.js +300 -1746
  49. package/dist/index.js.map +1 -1
  50. package/dist/index.mjs +24 -27
  51. package/dist/lib/copilot-task.js.map +1 -1
  52. package/dist/lib/copilot-task.mjs +4 -7
  53. package/dist/lib/index.js.map +1 -1
  54. package/dist/lib/index.mjs +4 -7
  55. package/dist/types/index.mjs +1 -1
  56. package/package.json +8 -8
  57. package/src/components/copilot-provider/copilotkit-props.tsx +7 -0
  58. package/src/components/copilot-provider/copilotkit.tsx +13 -5
  59. package/src/hooks/index.ts +2 -2
  60. package/src/hooks/use-copilot-chat-suggestions.tsx +124 -0
  61. package/src/hooks/use-copilot-chat_internal.ts +29 -29
  62. package/src/hooks/use-copilot-readable.ts +2 -4
  63. package/dist/chunk-EKDPRKZT.mjs +0 -746
  64. package/dist/chunk-EKDPRKZT.mjs.map +0 -1
  65. package/dist/chunk-FBVI3LQ6.mjs +0 -48
  66. package/dist/chunk-FBVI3LQ6.mjs.map +0 -1
  67. package/dist/chunk-PMWUKW3Z.mjs +0 -231
  68. package/dist/chunk-PMWUKW3Z.mjs.map +0 -1
  69. package/dist/chunk-RQ6LWR6S.mjs.map +0 -1
  70. package/dist/chunk-ZU6ZBX4E.mjs.map +0 -1
  71. package/dist/hooks/use-configure-chat-suggestions.js.map +0 -1
  72. package/dist/hooks/use-configure-chat-suggestions.mjs +0 -8
  73. package/src/hooks/use-configure-chat-suggestions.tsx +0 -86
  74. /package/dist/{chunk-KYY2WZSR.mjs.map → chunk-5J7RRLRO.mjs.map} +0 -0
  75. /package/dist/{chunk-Y2L7KDVW.mjs.map → chunk-HQTDDA6V.mjs.map} +0 -0
  76. /package/dist/{chunk-BLDHD6Q2.mjs.map → chunk-ZE4JVTEP.mjs.map} +0 -0
  77. /package/dist/hooks/{use-configure-chat-suggestions.mjs.map → use-copilot-chat-suggestions.mjs.map} +0 -0
@@ -15,7 +15,11 @@
15
15
  */
16
16
 
17
17
  import { useCallback, useEffect, useMemo, useRef, useState, SetStateAction } from "react";
18
- import { CopilotChatConfigurationProvider, CopilotKitProvider } from "@copilotkitnext/react";
18
+ import {
19
+ CopilotChatConfigurationProvider,
20
+ CopilotKitInspector,
21
+ CopilotKitProvider as CopilotKitNextProvider,
22
+ } from "@copilotkitnext/react";
19
23
  import {
20
24
  CopilotContext,
21
25
  CopilotApiConfig,
@@ -53,7 +57,6 @@ import {
53
57
  LangGraphInterruptActionSetterArgs,
54
58
  QueuedInterruptEvent,
55
59
  } from "../../types/interrupt-action";
56
- import { ConsoleTrigger } from "../dev-console/console-trigger";
57
60
  import { CoAgentStateRendersProvider } from "../../context/coagent-state-renders-context";
58
61
  import { CoAgentStateRenderBridge } from "../../hooks/use-coagent-state-render-bridge";
59
62
  import { ThreadsProvider, useThreads } from "../../context/threads-context";
@@ -61,6 +64,7 @@ import { CopilotListeners } from "../CopilotListeners";
61
64
 
62
65
  export function CopilotKit({ children, ...props }: CopilotKitProps) {
63
66
  const enabled = shouldShowDevConsole(props.showDevConsole);
67
+ const showInspector = shouldShowDevConsole(props.enableInspector);
64
68
 
65
69
  // Use API key if provided, otherwise use the license key
66
70
  const publicApiKey = props.publicApiKey || props.publicLicenseKey;
@@ -71,9 +75,14 @@ export function CopilotKit({ children, ...props }: CopilotKitProps) {
71
75
  <ToastProvider enabled={enabled}>
72
76
  <CopilotErrorBoundary publicApiKey={publicApiKey} showUsageBanner={enabled}>
73
77
  <ThreadsProvider threadId={props.threadId}>
74
- <CopilotKitProvider {...props} renderCustomMessages={renderArr} useSingleEndpoint={true}>
78
+ <CopilotKitNextProvider
79
+ {...props}
80
+ showDevConsole={showInspector}
81
+ renderCustomMessages={renderArr}
82
+ useSingleEndpoint={true}
83
+ >
75
84
  <CopilotKitInternal {...props}>{children}</CopilotKitInternal>
76
- </CopilotKitProvider>
85
+ </CopilotKitNextProvider>
77
86
  </ThreadsProvider>
78
87
  </CopilotErrorBoundary>
79
88
  </ToastProvider>
@@ -587,7 +596,6 @@ export function CopilotKitInternal(cpkProps: CopilotKitProps) {
587
596
  <MessagesTapProvider>
588
597
  <CopilotMessages>
589
598
  {memoizedChildren}
590
- {showDevConsole && <ConsoleTrigger />}
591
599
  <RegisteredActionsRenderer />
592
600
  </CopilotMessages>
593
601
  </MessagesTapProvider>
@@ -24,6 +24,6 @@ export { useRenderToolCall } from "./use-render-tool-call";
24
24
  export { useDefaultTool } from "./use-default-tool";
25
25
  export { useLazyToolRenderer } from "./use-lazy-tool-renderer";
26
26
  export {
27
- useConfigureChatSuggestions,
27
+ useCopilotChatSuggestions,
28
28
  type UseCopilotChatSuggestionsConfiguration,
29
- } from "./use-configure-chat-suggestions";
29
+ } from "./use-copilot-chat-suggestions";
@@ -0,0 +1,124 @@
1
+ /**
2
+ * <Callout type="warning">
3
+ * useCopilotChatSuggestions is experimental. The interface is not final and
4
+ * can change without notice.
5
+ * </Callout>
6
+ *
7
+ * `useCopilotReadable` is a React hook that provides app-state and other information
8
+ * to the Copilot. Optionally, the hook can also handle hierarchical state within your
9
+ * application, passing these parent-child relationships to the Copilot.
10
+ *
11
+ * <br/>
12
+ * <img src="https://cdn.copilotkit.ai/docs/copilotkit/images/use-copilot-chat-suggestions/use-copilot-chat-suggestions.gif" width="500" />
13
+ *
14
+ * ## Usage
15
+ *
16
+ * ### Install Dependencies
17
+ *
18
+ * This component is part of the [@copilotkit/react-ui](https://npmjs.com/package/@copilotkit/react-ui) package.
19
+ *
20
+ * ```shell npm2yarn \"@copilotkit/react-ui"\
21
+ * npm install @copilotkit/react-core @copilotkit/react-ui
22
+ * ```
23
+ *
24
+ * ### Simple Usage
25
+ *
26
+ * ```tsx
27
+ * import { useCopilotChatSuggestions } from "@copilotkit/react-ui";
28
+ *
29
+ * export function MyComponent() {
30
+ * const [employees, setEmployees] = useState([]);
31
+ *
32
+ * useCopilotChatSuggestions({
33
+ * instructions: `The following employees are on duty: ${JSON.stringify(employees)}`,
34
+ * });
35
+ * }
36
+ * ```
37
+ *
38
+ * ### Dependency Management
39
+ *
40
+ * ```tsx
41
+ * import { useCopilotChatSuggestions } from "@copilotkit/react-ui";
42
+ *
43
+ * export function MyComponent() {
44
+ * useCopilotChatSuggestions(
45
+ * {
46
+ * instructions: "Suggest the most relevant next actions.",
47
+ * },
48
+ * [appState],
49
+ * );
50
+ * }
51
+ * ```
52
+ *
53
+ * In the example above, the suggestions are generated based on the given instructions.
54
+ * The hook monitors `appState`, and updates suggestions accordingly whenever it changes.
55
+ *
56
+ * ### Behavior and Lifecycle
57
+ *
58
+ * The hook registers the configuration with the chat context upon component mount and
59
+ * removes it on unmount, ensuring a clean and efficient lifecycle management.
60
+ */
61
+ import {
62
+ useConfigureSuggestions,
63
+ useCopilotChatConfiguration,
64
+ useCopilotKit,
65
+ useSuggestions,
66
+ } from "@copilotkitnext/react";
67
+ import { useEffect } from "react";
68
+ import { StaticSuggestionsConfig, Suggestion } from "@copilotkitnext/core";
69
+
70
+ type StaticSuggestionInput = Omit<Suggestion, "isLoading"> & Partial<Pick<Suggestion, "isLoading">>;
71
+
72
+ type StaticSuggestionsConfigInput = Omit<StaticSuggestionsConfig, "suggestions"> & {
73
+ suggestions: StaticSuggestionInput[];
74
+ };
75
+
76
+ type DynamicSuggestionsConfigInput = {
77
+ /**
78
+ * A prompt or instructions for the GPT to generate suggestions.
79
+ */
80
+ instructions: string;
81
+ /**
82
+ * The minimum number of suggestions to generate. Defaults to `1`.
83
+ * @default 1
84
+ */
85
+ minSuggestions?: number;
86
+ /**
87
+ * The maximum number of suggestions to generate. Defaults to `3`.
88
+ * @default 1
89
+ */
90
+ maxSuggestions?: number;
91
+
92
+ /**
93
+ * Whether the suggestions are available. Defaults to `enabled`.
94
+ * @default enabled
95
+ */
96
+ available?: "enabled" | "disabled" | "always" | "before-first-message" | "after-first-message";
97
+
98
+ /**
99
+ * An optional class name to apply to the suggestions.
100
+ */
101
+ className?: string;
102
+ };
103
+
104
+ export type UseCopilotChatSuggestionsConfiguration =
105
+ | DynamicSuggestionsConfigInput
106
+ | StaticSuggestionsConfigInput;
107
+
108
+ export function useCopilotChatSuggestions(
109
+ config: UseCopilotChatSuggestionsConfiguration,
110
+ dependencies: any[] = [],
111
+ ) {
112
+ const existingConfig = useCopilotChatConfiguration();
113
+ const resolvedAgentId = existingConfig?.agentId ?? "default";
114
+
115
+ const available =
116
+ (config.available === "enabled" ? "always" : config.available) ?? "before-first-message";
117
+
118
+ const finalSuggestionConfig = {
119
+ ...config,
120
+ available,
121
+ consumerAgentId: resolvedAgentId, // Use chatConfig.agentId here
122
+ };
123
+ useConfigureSuggestions(finalSuggestionConfig, dependencies);
124
+ }
@@ -14,10 +14,6 @@ import {
14
14
  } from "@copilotkitnext/react";
15
15
  import { Suggestion } from "@copilotkitnext/core";
16
16
  import { useLazyToolRenderer } from "./use-lazy-tool-renderer";
17
- import {
18
- useConfigureChatSuggestions,
19
- UseCopilotChatSuggestionsConfiguration,
20
- } from "./use-configure-chat-suggestions";
21
17
  import { AbstractAgent, AGUIConnectNotImplementedError } from "@ag-ui/client";
22
18
  import {
23
19
  CoAgentStateRenderBridge,
@@ -71,7 +67,23 @@ export interface UseCopilotChatOptions {
71
67
  * Disables inclusion of CopilotKit’s default system message. When true, no system message is sent (this also suppresses any custom message from <code>makeSystemMessage</code>).
72
68
  */
73
69
  disableSystemMessage?: boolean;
74
-
70
+ /**
71
+ * Controls the behavior of suggestions in the chat interface.
72
+ *
73
+ * `auto` (default) - Suggestions are generated automatically:
74
+ * - When the chat is first opened (empty state)
75
+ * - After each message exchange completes
76
+ * - Uses configuration from `useCopilotChatSuggestions` hooks
77
+ *
78
+ * `manual` - Suggestions are controlled programmatically:
79
+ * - Use `setSuggestions()` to set custom suggestions
80
+ * - Use `generateSuggestions()` to trigger AI generation
81
+ * - Access via `useCopilotChat` hook
82
+ *
83
+ * `SuggestionItem[]` - Static suggestions array:
84
+ * - Always shows the same suggestions
85
+ * - No AI generation involved
86
+ */
75
87
  suggestions?: ChatSuggestions;
76
88
  }
77
89
 
@@ -258,27 +270,6 @@ export interface UseCopilotChatReturn {
258
270
  threadId?: string;
259
271
  }
260
272
 
261
- function useConfigureSuggestions(suggestions?: UseCopilotChatOptions["suggestions"]) {
262
- let suggestionsConfig: UseCopilotChatSuggestionsConfiguration;
263
-
264
- if (Array.isArray(suggestions)) {
265
- suggestionsConfig = {
266
- suggestions,
267
- available: "always",
268
- };
269
- } else if (suggestions === "auto") {
270
- suggestionsConfig = {
271
- available: suggestions === "auto" ? "always" : "disabled",
272
- instructions:
273
- "Suggest what the user could say next. Provide clear, highly relevant suggestions. Do not literally suggest function calls.",
274
- };
275
- } else {
276
- suggestionsConfig = { available: "disabled" } as UseCopilotChatSuggestionsConfiguration;
277
- }
278
-
279
- useConfigureChatSuggestions(suggestionsConfig);
280
- }
281
-
282
273
  export function useCopilotChatInternal({
283
274
  suggestions,
284
275
  }: UseCopilotChatOptions = {}): UseCopilotChatReturn {
@@ -286,7 +277,6 @@ export function useCopilotChatInternal({
286
277
  const { threadId, agentSession } = useCopilotContext();
287
278
  const existingConfig = useCopilotChatConfiguration();
288
279
  const [agentAvailable, setAgentAvailable] = useState(false);
289
- useConfigureSuggestions(suggestions);
290
280
 
291
281
  // Apply priority: props > existing config > defaults
292
282
  const resolvedAgentId = existingConfig?.agentId ?? "default";
@@ -523,6 +513,16 @@ export function useCopilotChatInternal({
523
513
  resolvedAgentId,
524
514
  ]);
525
515
 
516
+ const renderedSuggestions = useMemo(() => {
517
+ if (Array.isArray(suggestions)) {
518
+ return {
519
+ suggestions: suggestions.map((s) => ({ ...s, isLoading: false })),
520
+ isLoading: false,
521
+ };
522
+ }
523
+ return currentSuggestions;
524
+ }, [suggestions, currentSuggestions]);
525
+
526
526
  // @ts-ignore
527
527
  return {
528
528
  messages: resolvedMessages,
@@ -537,12 +537,12 @@ export function useCopilotChatInternal({
537
537
  isLoading: Boolean(agent?.isRunning),
538
538
  // mcpServers,
539
539
  // setMcpServers,
540
- suggestions: currentSuggestions.suggestions,
540
+ suggestions: renderedSuggestions.suggestions,
541
541
  setSuggestions: (suggestions: Omit<Suggestion, "isLoading">[]) =>
542
542
  copilotkit.addSuggestionsConfig({ suggestions }),
543
543
  generateSuggestions: async () => copilotkit.reloadSuggestions(resolvedAgentId),
544
544
  resetSuggestions: () => copilotkit.clearSuggestions(resolvedAgentId),
545
- isLoadingSuggestions: currentSuggestions.isLoading,
545
+ isLoadingSuggestions: renderedSuggestions.isLoading,
546
546
  interrupt,
547
547
  agent,
548
548
  threadId,
@@ -64,8 +64,6 @@
64
64
  import { useCopilotKit } from "@copilotkitnext/react";
65
65
  import { useEffect, useRef } from "react";
66
66
 
67
- type DataType = object | number | string | boolean | null | undefined;
68
-
69
67
  /**
70
68
  * Options for the useCopilotReadable hook.
71
69
  */
@@ -77,7 +75,7 @@ export interface UseCopilotReadableOptions {
77
75
  /**
78
76
  * The value to be added to the Copilot context. Object values are automatically stringified.
79
77
  */
80
- value: DataType | Record<string, any> | DataType[];
78
+ value: any;
81
79
  /**
82
80
  * The ID of the parent context, if any.
83
81
  */
@@ -97,7 +95,7 @@ export interface UseCopilotReadableOptions {
97
95
  * A custom conversion function to use to serialize the value to a string. If not provided, the value
98
96
  * will be serialized using `JSON.stringify`.
99
97
  */
100
- convert?: (value: any) => string;
98
+ convert?: (description: string, value: any) => string;
101
99
  }
102
100
 
103
101
  /**