@copilotkit/react-core 1.50.1-next.3 → 1.50.2-next.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 (48) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/{chunk-3FHX5RLS.mjs → chunk-3V5TOYKW.mjs} +2 -2
  3. package/dist/chunk-3V5TOYKW.mjs.map +1 -0
  4. package/dist/{chunk-RB2TXKFP.mjs → chunk-4YZA2BZC.mjs} +13 -13
  5. package/dist/{chunk-IZGUA5WC.mjs → chunk-53K6WNJG.mjs} +2 -2
  6. package/dist/{chunk-F62YUR4R.mjs → chunk-FQFXYAV7.mjs} +2 -2
  7. package/dist/{chunk-INPM7YKW.mjs → chunk-HE22TZMF.mjs} +4 -4
  8. package/dist/{chunk-SNON4QA6.mjs → chunk-LHERIF3L.mjs} +4 -4
  9. package/dist/{chunk-CGKXLHL3.mjs → chunk-LSHFN2Y5.mjs} +4 -4
  10. package/dist/{chunk-3MHWEKFN.mjs → chunk-YCG6SNAU.mjs} +4 -4
  11. package/dist/components/copilot-provider/copilot-messages.mjs +2 -2
  12. package/dist/components/copilot-provider/copilotkit.mjs +8 -8
  13. package/dist/components/copilot-provider/index.mjs +8 -8
  14. package/dist/components/dev-console/console-trigger.mjs +2 -2
  15. package/dist/components/dev-console/developer-console-modal.mjs +2 -2
  16. package/dist/components/error-boundary/error-boundary.mjs +2 -2
  17. package/dist/components/index.mjs +8 -8
  18. package/dist/context/index.mjs +4 -4
  19. package/dist/hooks/index.mjs +19 -19
  20. package/dist/hooks/use-coagent-state-render-bridge.mjs +1 -1
  21. package/dist/hooks/use-configure-chat-suggestions.d.ts +36 -0
  22. package/dist/hooks/use-configure-chat-suggestions.js +79 -0
  23. package/dist/hooks/use-configure-chat-suggestions.js.map +1 -0
  24. package/dist/hooks/use-configure-chat-suggestions.mjs +47 -0
  25. package/dist/hooks/use-configure-chat-suggestions.mjs.map +1 -0
  26. package/dist/hooks/use-copilot-chat-headless_c.mjs +6 -6
  27. package/dist/hooks/use-copilot-chat.mjs +6 -6
  28. package/dist/hooks/use-copilot-chat_internal.mjs +5 -5
  29. package/dist/hooks/use-langgraph-interrupt-render.mjs +1 -1
  30. package/dist/index.js.map +1 -1
  31. package/dist/index.mjs +43 -43
  32. package/dist/lib/copilot-task.d.ts +1 -1
  33. package/dist/lib/copilot-task.js.map +1 -1
  34. package/dist/lib/copilot-task.mjs +9 -9
  35. package/dist/lib/index.js.map +1 -1
  36. package/dist/lib/index.mjs +9 -9
  37. package/package.json +3 -3
  38. package/src/hooks/use-configure-chat-suggestions.tsx +86 -0
  39. package/src/lib/copilot-task.ts +1 -1
  40. package/tsup.config.ts +1 -1
  41. package/dist/chunk-3FHX5RLS.mjs.map +0 -1
  42. /package/dist/{chunk-RB2TXKFP.mjs.map → chunk-4YZA2BZC.mjs.map} +0 -0
  43. /package/dist/{chunk-IZGUA5WC.mjs.map → chunk-53K6WNJG.mjs.map} +0 -0
  44. /package/dist/{chunk-F62YUR4R.mjs.map → chunk-FQFXYAV7.mjs.map} +0 -0
  45. /package/dist/{chunk-INPM7YKW.mjs.map → chunk-HE22TZMF.mjs.map} +0 -0
  46. /package/dist/{chunk-SNON4QA6.mjs.map → chunk-LHERIF3L.mjs.map} +0 -0
  47. /package/dist/{chunk-CGKXLHL3.mjs.map → chunk-LSHFN2Y5.mjs.map} +0 -0
  48. /package/dist/{chunk-3MHWEKFN.mjs.map → chunk-YCG6SNAU.mjs.map} +0 -0
@@ -0,0 +1,86 @@
1
+ import {
2
+ useConfigureSuggestions,
3
+ useCopilotChatConfiguration,
4
+ useCopilotKit,
5
+ useSuggestions,
6
+ } from "@copilotkitnext/react";
7
+ import { StaticSuggestionsConfig, Suggestion } from "@copilotkitnext/core";
8
+ import { useCopilotContext } from "../context";
9
+ import { useEffect, useMemo } from "react";
10
+
11
+ type StaticSuggestionInput = Omit<Suggestion, "isLoading"> & Partial<Pick<Suggestion, "isLoading">>;
12
+
13
+ type StaticSuggestionsConfigInput = Omit<StaticSuggestionsConfig, "suggestions"> & {
14
+ suggestions: StaticSuggestionInput[];
15
+ };
16
+
17
+ type DynamicSuggestionsConfigInput = {
18
+ /**
19
+ * A prompt or instructions for the GPT to generate suggestions.
20
+ */
21
+ instructions: string;
22
+ /**
23
+ * The minimum number of suggestions to generate. Defaults to `1`.
24
+ * @default 1
25
+ */
26
+ minSuggestions?: number;
27
+ /**
28
+ * The maximum number of suggestions to generate. Defaults to `3`.
29
+ * @default 1
30
+ */
31
+ maxSuggestions?: number;
32
+
33
+ /**
34
+ * Whether the suggestions are available. Defaults to `enabled`.
35
+ * @default enabled
36
+ */
37
+ available?: "enabled" | "disabled" | "always" | "before-first-message" | "after-first-message";
38
+
39
+ /**
40
+ * An optional class name to apply to the suggestions.
41
+ */
42
+ className?: string;
43
+ };
44
+
45
+ export type UseCopilotChatSuggestionsConfiguration =
46
+ | DynamicSuggestionsConfigInput
47
+ | StaticSuggestionsConfigInput;
48
+
49
+ export function useConfigureChatSuggestions(
50
+ config: UseCopilotChatSuggestionsConfiguration,
51
+ dependencies: any[] = [],
52
+ ): ReturnType<typeof useSuggestions> {
53
+ const existingConfig = useCopilotChatConfiguration();
54
+ const resolvedAgentId = existingConfig?.agentId ?? "default";
55
+ const { copilotkit } = useCopilotKit();
56
+
57
+ const available = config.available === "enabled" ? "always" : config.available;
58
+
59
+ const finalSuggestionConfig = {
60
+ ...config,
61
+ available,
62
+ consumerAgentId: resolvedAgentId, // Use chatConfig.agentId here
63
+ };
64
+ useConfigureSuggestions(finalSuggestionConfig, dependencies);
65
+
66
+ const result = useSuggestions({ agentId: resolvedAgentId });
67
+
68
+ useEffect(() => {
69
+ if (finalSuggestionConfig.available === "disabled") return;
70
+ const subscription = copilotkit.subscribe({
71
+ onAgentsChanged: () => {
72
+ // When agents change, check if our target agent now exists and reload
73
+ const agent = copilotkit.getAgent(resolvedAgentId);
74
+ if (agent && !agent.isRunning && !result.suggestions.length) {
75
+ copilotkit.reloadSuggestions(resolvedAgentId);
76
+ }
77
+ },
78
+ });
79
+
80
+ return () => {
81
+ subscription.unsubscribe();
82
+ };
83
+ }, [resolvedAgentId]);
84
+
85
+ return result;
86
+ }
@@ -43,7 +43,7 @@
43
43
  * }
44
44
  * ```
45
45
  *
46
- * Have a look at the [Presentation Example App](https://github.com/CopilotKit/CopilotKit/blob/main/CopilotKit/examples/next-openai/src/app/presentation/page.tsx) for a more complete example.
46
+ * Have a look at the [Presentation Example App](https://github.com/CopilotKit/CopilotKit/blob/main/src/v1.x/examples/next-openai/src/app/presentation/page.tsx) for a more complete example.
47
47
  */
48
48
 
49
49
  import {
package/tsup.config.ts CHANGED
@@ -10,7 +10,7 @@ export default defineConfig((options: Options) => ({
10
10
  format: ["esm", "cjs"],
11
11
  dts: true,
12
12
  minify: false,
13
- external: ["react"],
13
+ external: ["react", "@copilotkitnext/core", "@copilotkitnext/react"],
14
14
  sourcemap: true,
15
15
  ...options,
16
16
  }));
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/lib/copilot-task.ts"],"sourcesContent":["/**\n * This class is used to execute one-off tasks, for example on button press. It can use the context available via [useCopilotReadable](/reference/hooks/useCopilotReadable) and the actions provided by [useCopilotAction](/reference/hooks/useCopilotAction), or you can provide your own context and actions.\n *\n * ## Example\n * In the simplest case, use CopilotTask in the context of your app by giving it instructions on what to do.\n *\n * ```tsx\n * import { CopilotTask, useCopilotContext } from \"@copilotkit/react-core\";\n *\n * export function MyComponent() {\n * const context = useCopilotContext();\n *\n * const task = new CopilotTask({\n * instructions: \"Set a random message\",\n * actions: [\n * {\n * name: \"setMessage\",\n * description: \"Set the message.\",\n * argumentAnnotations: [\n * {\n * name: \"message\",\n * type: \"string\",\n * description:\n * \"A message to display.\",\n * required: true,\n * },\n * ],\n * }\n * ]\n * });\n *\n * const executeTask = async () => {\n * await task.run(context, action);\n * }\n *\n * return (\n * <>\n * <button onClick={executeTask}>\n * Execute task\n * </button>\n * </>\n * )\n * }\n * ```\n *\n * Have a look at the [Presentation Example App](https://github.com/CopilotKit/CopilotKit/blob/main/CopilotKit/examples/next-openai/src/app/presentation/page.tsx) for a more complete example.\n */\n\nimport {\n ActionExecutionMessage,\n CopilotRuntimeClient,\n Message,\n Role,\n TextMessage,\n convertGqlOutputToMessages,\n convertMessagesToGqlInput,\n filterAgentStateMessages,\n CopilotRequestType,\n ForwardedParametersInput,\n} from \"@copilotkit/runtime-client-gql\";\nimport { FrontendAction, processActionsForRuntimeRequest } from \"../types/frontend-action\";\nimport { CopilotContextParams } from \"../context\";\nimport { defaultCopilotContextCategories } from \"../components\";\n\nexport interface CopilotTaskConfig {\n /**\n * The instructions to be given to the assistant.\n */\n instructions: string;\n /**\n * An array of action definitions that can be called.\n */\n actions?: FrontendAction<any>[];\n /**\n * Whether to include the copilot readable context in the task.\n */\n includeCopilotReadable?: boolean;\n\n /**\n * Whether to include actions defined via useCopilotAction in the task.\n */\n includeCopilotActions?: boolean;\n\n /**\n * The forwarded parameters to use for the task.\n */\n forwardedParameters?: ForwardedParametersInput;\n}\n\nexport class CopilotTask<T = any> {\n private instructions: string;\n private actions: FrontendAction<any>[];\n private includeCopilotReadable: boolean;\n private includeCopilotActions: boolean;\n private forwardedParameters?: ForwardedParametersInput;\n constructor(config: CopilotTaskConfig) {\n this.instructions = config.instructions;\n this.actions = config.actions || [];\n this.includeCopilotReadable = config.includeCopilotReadable !== false;\n this.includeCopilotActions = config.includeCopilotActions !== false;\n this.forwardedParameters = config.forwardedParameters;\n }\n\n /**\n * Run the task.\n * @param context The CopilotContext to use for the task. Use `useCopilotContext` to obtain the current context.\n * @param data The data to use for the task.\n */\n async run(context: CopilotContextParams, data?: T): Promise<void> {\n const actions = this.includeCopilotActions ? Object.assign({}, context.actions) : {};\n\n // merge functions into entry points\n for (const fn of this.actions) {\n actions[fn.name] = fn;\n }\n\n let contextString = \"\";\n\n if (data) {\n contextString = (typeof data === \"string\" ? data : JSON.stringify(data)) + \"\\n\\n\";\n }\n\n if (this.includeCopilotReadable) {\n contextString += context.getContextString([], defaultCopilotContextCategories);\n }\n\n const systemMessage = new TextMessage({\n content: taskSystemMessage(contextString, this.instructions),\n role: Role.System,\n });\n\n const messages: Message[] = [systemMessage];\n\n const runtimeClient = new CopilotRuntimeClient({\n url: context.copilotApiConfig.chatApiEndpoint,\n publicApiKey: context.copilotApiConfig.publicApiKey,\n headers: context.copilotApiConfig.headers,\n credentials: context.copilotApiConfig.credentials,\n });\n\n const response = await runtimeClient\n .generateCopilotResponse({\n data: {\n frontend: {\n actions: processActionsForRuntimeRequest(Object.values(actions)),\n url: window.location.href,\n },\n messages: convertMessagesToGqlInput(filterAgentStateMessages(messages)),\n metadata: {\n requestType: CopilotRequestType.Task,\n },\n forwardedParameters: {\n // if forwardedParameters is provided, use it\n toolChoice: \"required\",\n ...(this.forwardedParameters ?? {}),\n },\n },\n properties: context.copilotApiConfig.properties,\n })\n .toPromise();\n\n const functionCallHandler = context.getFunctionCallHandler(actions);\n const functionCalls = convertGqlOutputToMessages(\n response.data?.generateCopilotResponse?.messages || [],\n ).filter((m): m is ActionExecutionMessage => m.isActionExecutionMessage());\n\n for (const functionCall of functionCalls) {\n await functionCallHandler({\n messages,\n name: functionCall.name,\n args: functionCall.arguments,\n });\n }\n }\n}\n\nfunction taskSystemMessage(contextString: string, instructions: string): string {\n return `\nPlease act as an efficient, competent, conscientious, and industrious professional assistant.\n\nHelp the user achieve their goals, and you do so in a way that is as efficient as possible, without unnecessary fluff, but also without sacrificing professionalism.\nAlways be polite and respectful, and prefer brevity over verbosity.\n\nThe user has provided you with the following context:\n\\`\\`\\`\n${contextString}\n\\`\\`\\`\n\nThey have also provided you with functions you can call to initiate actions on their behalf.\n\nPlease assist them as best you can.\n\nThis is not a conversation, so please do not ask questions. Just call a function without saying anything else.\n\nThe user has given you the following task to complete:\n\n\\`\\`\\`\n${instructions}\n\\`\\`\\`\n`;\n}\n"],"mappings":";;;;;;;;;;;;AAgDA;AAAA,EAEE;AAAA,EAEA;AA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