@copilotkit/react-core 1.50.1 → 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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # ui
2
2
 
3
+ ## 1.50.2-next.0
4
+
5
+ ### Patch Changes
6
+
7
+ - @copilotkit/runtime-client-gql@1.50.2-next.0
8
+ - @copilotkit/shared@1.50.2-next.0
9
+
3
10
  ## 1.50.1
4
11
 
5
12
  ### Patch Changes
@@ -117,4 +117,4 @@ ${instructions}
117
117
  export {
118
118
  CopilotTask
119
119
  };
120
- //# sourceMappingURL=chunk-LCZZ7YGZ.mjs.map
120
+ //# sourceMappingURL=chunk-3V5TOYKW.mjs.map
@@ -0,0 +1 @@
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/src/v1.x/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;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AA8BA,IAAM,cAAN,MAA2B;AAAA,EAMhC,YAAY,QAA2B;AACrC,SAAK,eAAe,OAAO;AAC3B,SAAK,UAAU,OAAO,WAAW,CAAC;AAClC,SAAK,yBAAyB,OAAO,2BAA2B;AAChE,SAAK,wBAAwB,OAAO,0BAA0B;AAC9D,SAAK,sBAAsB,OAAO;AAAA,EACpC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOM,IAAI,SAA+B,MAAyB;AAAA;AA5GpE;AA6GI,YAAM,UAAU,KAAK,wBAAwB,OAAO,OAAO,CAAC,GAAG,QAAQ,OAAO,IAAI,CAAC;AAGnF,iBAAW,MAAM,KAAK,SAAS;AAC7B,gBAAQ,GAAG,IAAI,IAAI;AAAA,MACrB;AAEA,UAAI,gBAAgB;AAEpB,UAAI,MAAM;AACR,yBAAiB,OAAO,SAAS,WAAW,OAAO,KAAK,UAAU,IAAI,KAAK;AAAA,MAC7E;AAEA,UAAI,KAAK,wBAAwB;AAC/B,yBAAiB,QAAQ,iBAAiB,CAAC,GAAG,+BAA+B;AAAA,MAC/E;AAEA,YAAM,gBAAgB,IAAI,YAAY;AAAA,QACpC,SAAS,kBAAkB,eAAe,KAAK,YAAY;AAAA,QAC3D,MAAM,KAAK;AAAA,MACb,CAAC;AAED,YAAM,WAAsB,CAAC,aAAa;AAE1C,YAAM,gBAAgB,IAAI,qBAAqB;AAAA,QAC7C,KAAK,QAAQ,iBAAiB;AAAA,QAC9B,cAAc,QAAQ,iBAAiB;AAAA,QACvC,SAAS,QAAQ,iBAAiB;AAAA,QAClC,aAAa,QAAQ,iBAAiB;AAAA,MACxC,CAAC;AAED,YAAM,WAAW,MAAM,cACpB,wBAAwB;AAAA,QACvB,MAAM;AAAA,UACJ,UAAU;AAAA,YACR,SAAS,gCAAgC,OAAO,OAAO,OAAO,CAAC;AAAA,YAC/D,KAAK,OAAO,SAAS;AAAA,UACvB;AAAA,UACA,UAAU,0BAA0B,yBAAyB,QAAQ,CAAC;AAAA,UACtE,UAAU;AAAA,YACR,aAAa,mBAAmB;AAAA,UAClC;AAAA,UACA,qBAAqB;AAAA;AAAA,YAEnB,YAAY;AAAA,cACR,UAAK,wBAAL,YAA4B,CAAC;AAAA,QAErC;AAAA,QACA,YAAY,QAAQ,iBAAiB;AAAA,MACvC,CAAC,EACA,UAAU;AAEb,YAAM,sBAAsB,QAAQ,uBAAuB,OAAO;AAClE,YAAM,gBAAgB;AAAA,UACpB,oBAAS,SAAT,mBAAe,4BAAf,mBAAwC,aAAY,CAAC;AAAA,MACvD,EAAE,OAAO,CAAC,MAAmC,EAAE,yBAAyB,CAAC;AAEzE,iBAAW,gBAAgB,eAAe;AACxC,cAAM,oBAAoB;AAAA,UACxB;AAAA,UACA,MAAM,aAAa;AAAA,UACnB,MAAM,aAAa;AAAA,QACrB,CAAC;AAAA,MACH;AAAA,IACF;AAAA;AACF;AAEA,SAAS,kBAAkB,eAAuB,cAA8B;AAC9E,SAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQP;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYA;AAAA;AAAA;AAGF;","names":[]}
@@ -4,9 +4,9 @@ import {
4
4
  defaultCopilotContextCategories
5
5
  } from "../../chunk-4YZA2BZC.mjs";
6
6
  import "../../chunk-LHERIF3L.mjs";
7
- import "../../chunk-HE22TZMF.mjs";
8
7
  import "../../chunk-CYDWEPFL.mjs";
9
8
  import "../../chunk-2IDV5OHF.mjs";
9
+ import "../../chunk-HE22TZMF.mjs";
10
10
  import "../../chunk-ICIK2BSB.mjs";
11
11
  import "../../chunk-RKTVJRK7.mjs";
12
12
  import "../../chunk-PMAFHQ7P.mjs";
@@ -4,9 +4,9 @@ import {
4
4
  defaultCopilotContextCategories
5
5
  } from "../../chunk-4YZA2BZC.mjs";
6
6
  import "../../chunk-LHERIF3L.mjs";
7
- import "../../chunk-HE22TZMF.mjs";
8
7
  import "../../chunk-CYDWEPFL.mjs";
9
8
  import "../../chunk-2IDV5OHF.mjs";
9
+ import "../../chunk-HE22TZMF.mjs";
10
10
  import "../../chunk-ICIK2BSB.mjs";
11
11
  import "../../chunk-RKTVJRK7.mjs";
12
12
  import "../../chunk-PMAFHQ7P.mjs";
@@ -5,9 +5,9 @@ import {
5
5
  defaultCopilotContextCategories
6
6
  } from "../chunk-4YZA2BZC.mjs";
7
7
  import "../chunk-LHERIF3L.mjs";
8
- import "../chunk-HE22TZMF.mjs";
9
8
  import "../chunk-CYDWEPFL.mjs";
10
9
  import "../chunk-2IDV5OHF.mjs";
10
+ import "../chunk-HE22TZMF.mjs";
11
11
  import "../chunk-ICIK2BSB.mjs";
12
12
  import "../chunk-RKTVJRK7.mjs";
13
13
  import "../chunk-PMAFHQ7P.mjs";
@@ -1,19 +1,34 @@
1
1
  import "../chunk-A6NKSGH3.mjs";
2
+ import {
3
+ useMakeCopilotDocumentReadable
4
+ } from "../chunk-7IBF6RBW.mjs";
5
+ import {
6
+ useCopilotRuntimeClient
7
+ } from "../chunk-6ESSSQ7Q.mjs";
2
8
  import {
3
9
  useDefaultTool
4
10
  } from "../chunk-BUSWSDYO.mjs";
5
11
  import {
6
12
  useLangGraphInterrupt
7
13
  } from "../chunk-4RRMC7L2.mjs";
8
- import {
9
- useMakeCopilotDocumentReadable
10
- } from "../chunk-7IBF6RBW.mjs";
11
14
  import {
12
15
  useCopilotAdditionalInstructions
13
16
  } from "../chunk-ABWT4DRT.mjs";
14
17
  import {
15
18
  useCopilotAuthenticatedAction_c
16
19
  } from "../chunk-E7SE25ZU.mjs";
20
+ import {
21
+ useCopilotAction
22
+ } from "../chunk-GPEJNVE5.mjs";
23
+ import {
24
+ useRenderToolCall
25
+ } from "../chunk-NBK4KBLX.mjs";
26
+ import {
27
+ useFrontendTool
28
+ } from "../chunk-CDUIA2WM.mjs";
29
+ import {
30
+ useHumanInTheLoop
31
+ } from "../chunk-7DTB7S5V.mjs";
17
32
  import {
18
33
  useCopilotChatHeadless_c
19
34
  } from "../chunk-FQFXYAV7.mjs";
@@ -35,9 +50,6 @@ import {
35
50
  import {
36
51
  useCopilotReadable
37
52
  } from "../chunk-Z6JV2LRY.mjs";
38
- import {
39
- useCopilotRuntimeClient
40
- } from "../chunk-6ESSSQ7Q.mjs";
41
53
  import {
42
54
  useCoAgentStateRender
43
55
  } from "../chunk-YTQHRJUA.mjs";
@@ -45,18 +57,6 @@ import {
45
57
  useCoAgent
46
58
  } from "../chunk-ZYTXB6HH.mjs";
47
59
  import "../chunk-I76HKHPJ.mjs";
48
- import {
49
- useCopilotAction
50
- } from "../chunk-GPEJNVE5.mjs";
51
- import {
52
- useRenderToolCall
53
- } from "../chunk-NBK4KBLX.mjs";
54
- import {
55
- useFrontendTool
56
- } from "../chunk-CDUIA2WM.mjs";
57
- import {
58
- useHumanInTheLoop
59
- } from "../chunk-7DTB7S5V.mjs";
60
60
  import "../chunk-6PUNP7CD.mjs";
61
61
  import "../chunk-O7ARI5CV.mjs";
62
62
  import "../chunk-QNUAXSDP.mjs";
@@ -0,0 +1,36 @@
1
+ import { useSuggestions } from '@copilotkitnext/react';
2
+ import { StaticSuggestionsConfig, Suggestion } from '@copilotkitnext/core';
3
+
4
+ type StaticSuggestionInput = Omit<Suggestion, "isLoading"> & Partial<Pick<Suggestion, "isLoading">>;
5
+ type StaticSuggestionsConfigInput = Omit<StaticSuggestionsConfig, "suggestions"> & {
6
+ suggestions: StaticSuggestionInput[];
7
+ };
8
+ type DynamicSuggestionsConfigInput = {
9
+ /**
10
+ * A prompt or instructions for the GPT to generate suggestions.
11
+ */
12
+ instructions: string;
13
+ /**
14
+ * The minimum number of suggestions to generate. Defaults to `1`.
15
+ * @default 1
16
+ */
17
+ minSuggestions?: number;
18
+ /**
19
+ * The maximum number of suggestions to generate. Defaults to `3`.
20
+ * @default 1
21
+ */
22
+ maxSuggestions?: number;
23
+ /**
24
+ * Whether the suggestions are available. Defaults to `enabled`.
25
+ * @default enabled
26
+ */
27
+ available?: "enabled" | "disabled" | "always" | "before-first-message" | "after-first-message";
28
+ /**
29
+ * An optional class name to apply to the suggestions.
30
+ */
31
+ className?: string;
32
+ };
33
+ type UseCopilotChatSuggestionsConfiguration = DynamicSuggestionsConfigInput | StaticSuggestionsConfigInput;
34
+ declare function useConfigureChatSuggestions(config: UseCopilotChatSuggestionsConfiguration, dependencies?: any[]): ReturnType<typeof useSuggestions>;
35
+
36
+ export { UseCopilotChatSuggestionsConfiguration, useConfigureChatSuggestions };
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __defProps = Object.defineProperties;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
10
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11
+ var __spreadValues = (a, b) => {
12
+ for (var prop in b || (b = {}))
13
+ if (__hasOwnProp.call(b, prop))
14
+ __defNormalProp(a, prop, b[prop]);
15
+ if (__getOwnPropSymbols)
16
+ for (var prop of __getOwnPropSymbols(b)) {
17
+ if (__propIsEnum.call(b, prop))
18
+ __defNormalProp(a, prop, b[prop]);
19
+ }
20
+ return a;
21
+ };
22
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
23
+ var __export = (target, all) => {
24
+ for (var name in all)
25
+ __defProp(target, name, { get: all[name], enumerable: true });
26
+ };
27
+ var __copyProps = (to, from, except, desc) => {
28
+ if (from && typeof from === "object" || typeof from === "function") {
29
+ for (let key of __getOwnPropNames(from))
30
+ if (!__hasOwnProp.call(to, key) && key !== except)
31
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
32
+ }
33
+ return to;
34
+ };
35
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
36
+
37
+ // src/hooks/use-configure-chat-suggestions.tsx
38
+ var use_configure_chat_suggestions_exports = {};
39
+ __export(use_configure_chat_suggestions_exports, {
40
+ useConfigureChatSuggestions: () => useConfigureChatSuggestions
41
+ });
42
+ module.exports = __toCommonJS(use_configure_chat_suggestions_exports);
43
+ var import_react = require("@copilotkitnext/react");
44
+ var import_react2 = require("react");
45
+ function useConfigureChatSuggestions(config, dependencies = []) {
46
+ var _a;
47
+ const existingConfig = (0, import_react.useCopilotChatConfiguration)();
48
+ const resolvedAgentId = (_a = existingConfig == null ? void 0 : existingConfig.agentId) != null ? _a : "default";
49
+ const { copilotkit } = (0, import_react.useCopilotKit)();
50
+ const available = config.available === "enabled" ? "always" : config.available;
51
+ const finalSuggestionConfig = __spreadProps(__spreadValues({}, config), {
52
+ available,
53
+ consumerAgentId: resolvedAgentId
54
+ // Use chatConfig.agentId here
55
+ });
56
+ (0, import_react.useConfigureSuggestions)(finalSuggestionConfig, dependencies);
57
+ const result = (0, import_react.useSuggestions)({ agentId: resolvedAgentId });
58
+ (0, import_react2.useEffect)(() => {
59
+ if (finalSuggestionConfig.available === "disabled")
60
+ return;
61
+ const subscription = copilotkit.subscribe({
62
+ onAgentsChanged: () => {
63
+ const agent = copilotkit.getAgent(resolvedAgentId);
64
+ if (agent && !agent.isRunning && !result.suggestions.length) {
65
+ copilotkit.reloadSuggestions(resolvedAgentId);
66
+ }
67
+ }
68
+ });
69
+ return () => {
70
+ subscription.unsubscribe();
71
+ };
72
+ }, [resolvedAgentId]);
73
+ return result;
74
+ }
75
+ // Annotate the CommonJS export names for ESM import in node:
76
+ 0 && (module.exports = {
77
+ useConfigureChatSuggestions
78
+ });
79
+ //# sourceMappingURL=use-configure-chat-suggestions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/hooks/use-configure-chat-suggestions.tsx"],"sourcesContent":["import {\n useConfigureSuggestions,\n useCopilotChatConfiguration,\n useCopilotKit,\n useSuggestions,\n} from \"@copilotkitnext/react\";\nimport { StaticSuggestionsConfig, Suggestion } from \"@copilotkitnext/core\";\nimport { useCopilotContext } from \"../context\";\nimport { useEffect, useMemo } from \"react\";\n\ntype StaticSuggestionInput = Omit<Suggestion, \"isLoading\"> & Partial<Pick<Suggestion, \"isLoading\">>;\n\ntype StaticSuggestionsConfigInput = Omit<StaticSuggestionsConfig, \"suggestions\"> & {\n suggestions: StaticSuggestionInput[];\n};\n\ntype DynamicSuggestionsConfigInput = {\n /**\n * A prompt or instructions for the GPT to generate suggestions.\n */\n instructions: string;\n /**\n * The minimum number of suggestions to generate. Defaults to `1`.\n * @default 1\n */\n minSuggestions?: number;\n /**\n * The maximum number of suggestions to generate. Defaults to `3`.\n * @default 1\n */\n maxSuggestions?: number;\n\n /**\n * Whether the suggestions are available. Defaults to `enabled`.\n * @default enabled\n */\n available?: \"enabled\" | \"disabled\" | \"always\" | \"before-first-message\" | \"after-first-message\";\n\n /**\n * An optional class name to apply to the suggestions.\n */\n className?: string;\n};\n\nexport type UseCopilotChatSuggestionsConfiguration =\n | DynamicSuggestionsConfigInput\n | StaticSuggestionsConfigInput;\n\nexport function useConfigureChatSuggestions(\n config: UseCopilotChatSuggestionsConfiguration,\n dependencies: any[] = [],\n): ReturnType<typeof useSuggestions> {\n const existingConfig = useCopilotChatConfiguration();\n const resolvedAgentId = existingConfig?.agentId ?? \"default\";\n const { copilotkit } = useCopilotKit();\n\n const available = config.available === \"enabled\" ? \"always\" : config.available;\n\n const finalSuggestionConfig = {\n ...config,\n available,\n consumerAgentId: resolvedAgentId, // Use chatConfig.agentId here\n };\n useConfigureSuggestions(finalSuggestionConfig, dependencies);\n\n const result = useSuggestions({ agentId: resolvedAgentId });\n\n useEffect(() => {\n if (finalSuggestionConfig.available === \"disabled\") return;\n const subscription = copilotkit.subscribe({\n onAgentsChanged: () => {\n // When agents change, check if our target agent now exists and reload\n const agent = copilotkit.getAgent(resolvedAgentId);\n if (agent && !agent.isRunning && !result.suggestions.length) {\n copilotkit.reloadSuggestions(resolvedAgentId);\n }\n },\n });\n\n return () => {\n subscription.unsubscribe();\n };\n }, [resolvedAgentId]);\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAKO;AAGP,IAAAA,gBAAmC;AAwC5B,SAAS,4BACd,QACA,eAAsB,CAAC,GACY;AAnDrC;AAoDE,QAAM,qBAAiB,0CAA4B;AACnD,QAAM,mBAAkB,sDAAgB,YAAhB,YAA2B;AACnD,QAAM,EAAE,WAAW,QAAI,4BAAc;AAErC,QAAM,YAAY,OAAO,cAAc,YAAY,WAAW,OAAO;AAErE,QAAM,wBAAwB,iCACzB,SADyB;AAAA,IAE5B;AAAA,IACA,iBAAiB;AAAA;AAAA,EACnB;AACA,4CAAwB,uBAAuB,YAAY;AAE3D,QAAM,aAAS,6BAAe,EAAE,SAAS,gBAAgB,CAAC;AAE1D,+BAAU,MAAM;AACd,QAAI,sBAAsB,cAAc;AAAY;AACpD,UAAM,eAAe,WAAW,UAAU;AAAA,MACxC,iBAAiB,MAAM;AAErB,cAAM,QAAQ,WAAW,SAAS,eAAe;AACjD,YAAI,SAAS,CAAC,MAAM,aAAa,CAAC,OAAO,YAAY,QAAQ;AAC3D,qBAAW,kBAAkB,eAAe;AAAA,QAC9C;AAAA,MACF;AAAA,IACF,CAAC;AAED,WAAO,MAAM;AACX,mBAAa,YAAY;AAAA,IAC3B;AAAA,EACF,GAAG,CAAC,eAAe,CAAC;AAEpB,SAAO;AACT;","names":["import_react"]}
@@ -0,0 +1,47 @@
1
+ import {
2
+ __spreadProps,
3
+ __spreadValues
4
+ } from "../chunk-SKC7AJIV.mjs";
5
+
6
+ // src/hooks/use-configure-chat-suggestions.tsx
7
+ import {
8
+ useConfigureSuggestions,
9
+ useCopilotChatConfiguration,
10
+ useCopilotKit,
11
+ useSuggestions
12
+ } from "@copilotkitnext/react";
13
+ import { useEffect } from "react";
14
+ function useConfigureChatSuggestions(config, dependencies = []) {
15
+ var _a;
16
+ const existingConfig = useCopilotChatConfiguration();
17
+ const resolvedAgentId = (_a = existingConfig == null ? void 0 : existingConfig.agentId) != null ? _a : "default";
18
+ const { copilotkit } = useCopilotKit();
19
+ const available = config.available === "enabled" ? "always" : config.available;
20
+ const finalSuggestionConfig = __spreadProps(__spreadValues({}, config), {
21
+ available,
22
+ consumerAgentId: resolvedAgentId
23
+ // Use chatConfig.agentId here
24
+ });
25
+ useConfigureSuggestions(finalSuggestionConfig, dependencies);
26
+ const result = useSuggestions({ agentId: resolvedAgentId });
27
+ useEffect(() => {
28
+ if (finalSuggestionConfig.available === "disabled")
29
+ return;
30
+ const subscription = copilotkit.subscribe({
31
+ onAgentsChanged: () => {
32
+ const agent = copilotkit.getAgent(resolvedAgentId);
33
+ if (agent && !agent.isRunning && !result.suggestions.length) {
34
+ copilotkit.reloadSuggestions(resolvedAgentId);
35
+ }
36
+ }
37
+ });
38
+ return () => {
39
+ subscription.unsubscribe();
40
+ };
41
+ }, [resolvedAgentId]);
42
+ return result;
43
+ }
44
+ export {
45
+ useConfigureChatSuggestions
46
+ };
47
+ //# sourceMappingURL=use-configure-chat-suggestions.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/hooks/use-configure-chat-suggestions.tsx"],"sourcesContent":["import {\n useConfigureSuggestions,\n useCopilotChatConfiguration,\n useCopilotKit,\n useSuggestions,\n} from \"@copilotkitnext/react\";\nimport { StaticSuggestionsConfig, Suggestion } from \"@copilotkitnext/core\";\nimport { useCopilotContext } from \"../context\";\nimport { useEffect, useMemo } from \"react\";\n\ntype StaticSuggestionInput = Omit<Suggestion, \"isLoading\"> & Partial<Pick<Suggestion, \"isLoading\">>;\n\ntype StaticSuggestionsConfigInput = Omit<StaticSuggestionsConfig, \"suggestions\"> & {\n suggestions: StaticSuggestionInput[];\n};\n\ntype DynamicSuggestionsConfigInput = {\n /**\n * A prompt or instructions for the GPT to generate suggestions.\n */\n instructions: string;\n /**\n * The minimum number of suggestions to generate. Defaults to `1`.\n * @default 1\n */\n minSuggestions?: number;\n /**\n * The maximum number of suggestions to generate. Defaults to `3`.\n * @default 1\n */\n maxSuggestions?: number;\n\n /**\n * Whether the suggestions are available. Defaults to `enabled`.\n * @default enabled\n */\n available?: \"enabled\" | \"disabled\" | \"always\" | \"before-first-message\" | \"after-first-message\";\n\n /**\n * An optional class name to apply to the suggestions.\n */\n className?: string;\n};\n\nexport type UseCopilotChatSuggestionsConfiguration =\n | DynamicSuggestionsConfigInput\n | StaticSuggestionsConfigInput;\n\nexport function useConfigureChatSuggestions(\n config: UseCopilotChatSuggestionsConfiguration,\n dependencies: any[] = [],\n): ReturnType<typeof useSuggestions> {\n const existingConfig = useCopilotChatConfiguration();\n const resolvedAgentId = existingConfig?.agentId ?? \"default\";\n const { copilotkit } = useCopilotKit();\n\n const available = config.available === \"enabled\" ? \"always\" : config.available;\n\n const finalSuggestionConfig = {\n ...config,\n available,\n consumerAgentId: resolvedAgentId, // Use chatConfig.agentId here\n };\n useConfigureSuggestions(finalSuggestionConfig, dependencies);\n\n const result = useSuggestions({ agentId: resolvedAgentId });\n\n useEffect(() => {\n if (finalSuggestionConfig.available === \"disabled\") return;\n const subscription = copilotkit.subscribe({\n onAgentsChanged: () => {\n // When agents change, check if our target agent now exists and reload\n const agent = copilotkit.getAgent(resolvedAgentId);\n if (agent && !agent.isRunning && !result.suggestions.length) {\n copilotkit.reloadSuggestions(resolvedAgentId);\n }\n },\n });\n\n return () => {\n subscription.unsubscribe();\n };\n }, [resolvedAgentId]);\n\n return result;\n}\n"],"mappings":";;;;;;AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAGP,SAAS,iBAA0B;AAwC5B,SAAS,4BACd,QACA,eAAsB,CAAC,GACY;AAnDrC;AAoDE,QAAM,iBAAiB,4BAA4B;AACnD,QAAM,mBAAkB,sDAAgB,YAAhB,YAA2B;AACnD,QAAM,EAAE,WAAW,IAAI,cAAc;AAErC,QAAM,YAAY,OAAO,cAAc,YAAY,WAAW,OAAO;AAErE,QAAM,wBAAwB,iCACzB,SADyB;AAAA,IAE5B;AAAA,IACA,iBAAiB;AAAA;AAAA,EACnB;AACA,0BAAwB,uBAAuB,YAAY;AAE3D,QAAM,SAAS,eAAe,EAAE,SAAS,gBAAgB,CAAC;AAE1D,YAAU,MAAM;AACd,QAAI,sBAAsB,cAAc;AAAY;AACpD,UAAM,eAAe,WAAW,UAAU;AAAA,MACxC,iBAAiB,MAAM;AAErB,cAAM,QAAQ,WAAW,SAAS,eAAe;AACjD,YAAI,SAAS,CAAC,MAAM,aAAa,CAAC,OAAO,YAAY,QAAQ;AAC3D,qBAAW,kBAAkB,eAAe;AAAA,QAC9C;AAAA,MACF;AAAA,IACF,CAAC;AAED,WAAO,MAAM;AACX,mBAAa,YAAY;AAAA,IAC3B;AAAA,EACF,GAAG,CAAC,eAAe,CAAC;AAEpB,SAAO;AACT;","names":[]}