@copilotkit/react-core 1.50.0-beta.8 → 1.50.0-beta.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/CHANGELOG.md +12 -0
  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-Y2L7KDVW.mjs → chunk-B5ELMVT7.mjs} +2 -2
  6. package/dist/{chunk-ZU6ZBX4E.mjs → chunk-FYMZKPOL.mjs} +4 -4
  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-RQ6LWR6S.mjs → chunk-Z6JV2LRY.mjs} +1 -1
  11. package/dist/chunk-Z6JV2LRY.mjs.map +1 -0
  12. package/dist/components/copilot-provider/copilotkit.mjs +4 -4
  13. package/dist/components/copilot-provider/index.mjs +4 -4
  14. package/dist/components/index.mjs +4 -4
  15. package/dist/hooks/index.d.ts +1 -1
  16. package/dist/hooks/index.js +121 -149
  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 +2 -3
  34. package/dist/hooks/use-copilot-readable.js.map +1 -1
  35. package/dist/hooks/use-copilot-readable.mjs +1 -1
  36. package/dist/index.d.ts +1 -1
  37. package/dist/index.js +114 -142
  38. package/dist/index.js.map +1 -1
  39. package/dist/index.mjs +32 -32
  40. package/dist/lib/copilot-task.mjs +5 -5
  41. package/dist/lib/index.mjs +5 -5
  42. package/dist/types/index.mjs +1 -1
  43. package/dist/utils/index.mjs +3 -3
  44. package/package.json +5 -5
  45. package/src/hooks/index.ts +2 -2
  46. package/src/hooks/use-copilot-chat-suggestions.tsx +124 -0
  47. package/src/hooks/use-copilot-chat_internal.ts +29 -29
  48. package/src/hooks/use-copilot-readable.ts +2 -4
  49. package/dist/chunk-EKDPRKZT.mjs.map +0 -1
  50. package/dist/chunk-FBVI3LQ6.mjs +0 -48
  51. package/dist/chunk-FBVI3LQ6.mjs.map +0 -1
  52. package/dist/chunk-RQ6LWR6S.mjs.map +0 -1
  53. package/dist/hooks/use-configure-chat-suggestions.js.map +0 -1
  54. package/dist/hooks/use-configure-chat-suggestions.mjs +0 -8
  55. package/src/hooks/use-configure-chat-suggestions.tsx +0 -86
  56. /package/dist/{chunk-BLDHD6Q2.mjs.map → chunk-7SHWECGN.mjs.map} +0 -0
  57. /package/dist/{chunk-Y2L7KDVW.mjs.map → chunk-B5ELMVT7.mjs.map} +0 -0
  58. /package/dist/{chunk-ZU6ZBX4E.mjs.map → chunk-FYMZKPOL.mjs.map} +0 -0
  59. /package/dist/{chunk-KYY2WZSR.mjs.map → chunk-YJGPIN3R.mjs.map} +0 -0
  60. /package/dist/hooks/{use-configure-chat-suggestions.mjs.map → use-copilot-chat-suggestions.mjs.map} +0 -0
@@ -1 +0,0 @@
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":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/hooks/use-copilot-readable.ts"],"sourcesContent":["/**\n * `useCopilotReadable` is a React hook that provides app-state and other information\n * to the Copilot. Optionally, the hook can also handle hierarchical state within your\n * application, passing these parent-child relationships to the Copilot.\n *\n * ## Usage\n *\n * ### Simple Usage\n *\n * In its most basic usage, useCopilotReadable accepts a single string argument\n * representing any piece of app state, making it available for the Copilot to use\n * as context when responding to user input.\n *\n * ```tsx\n * import { useCopilotReadable } from \"@copilotkit/react-core\";\n *\n * export function MyComponent() {\n * const [employees, setEmployees] = useState([]);\n *\n * useCopilotReadable({\n * description: \"The list of employees\",\n * value: employees,\n * });\n * }\n * ```\n *\n * ### Nested Components\n *\n * Optionally, you can maintain the hierarchical structure of information by passing\n * `parentId`. This allows you to use `useCopilotReadable` in nested components:\n *\n * ```tsx /employeeContextId/1 {17,23}\n * import { useCopilotReadable } from \"@copilotkit/react-core\";\n *\n * function Employee(props: EmployeeProps) {\n * const { employeeName, workProfile, metadata } = props;\n *\n * // propagate any information to copilot\n * const employeeContextId = useCopilotReadable({\n * description: \"Employee name\",\n * value: employeeName\n * });\n *\n * // Pass a parentID to maintain a hierarchical structure.\n * // Especially useful with child React components, list elements, etc.\n * useCopilotReadable({\n * description: \"Work profile\",\n * value: workProfile.description(),\n * parentId: employeeContextId\n * });\n *\n * useCopilotReadable({\n * description: \"Employee metadata\",\n * value: metadata.description(),\n * parentId: employeeContextId\n * });\n *\n * return (\n * // Render as usual...\n * );\n * }\n * ```\n */\nimport { useCopilotKit } from \"@copilotkitnext/react\";\nimport { useEffect, useRef } from \"react\";\n\ntype DataType = object | number | string | boolean | null | undefined;\n\n/**\n * Options for the useCopilotReadable hook.\n */\nexport interface UseCopilotReadableOptions {\n /**\n * The description of the information to be added to the Copilot context.\n */\n description: string;\n /**\n * The value to be added to the Copilot context. Object values are automatically stringified.\n */\n value: DataType | Record<string, any> | DataType[];\n /**\n * The ID of the parent context, if any.\n */\n parentId?: string;\n /**\n * An array of categories to control which context are visible where. Particularly useful\n * with CopilotTextarea (see `useMakeAutosuggestionFunction`)\n */\n categories?: string[];\n\n /**\n * Whether the context is available to the Copilot.\n */\n available?: \"enabled\" | \"disabled\";\n\n /**\n * A custom conversion function to use to serialize the value to a string. If not provided, the value\n * will be serialized using `JSON.stringify`.\n */\n convert?: (value: any) => string;\n}\n\n/**\n * Adds the given information to the Copilot context to make it readable by Copilot.\n */\nexport function useCopilotReadable(\n { description, value, convert, available }: UseCopilotReadableOptions,\n dependencies?: any[],\n): string | undefined {\n const { copilotkit } = useCopilotKit();\n const ctxIdRef = useRef<string | undefined>(undefined);\n useEffect(() => {\n if (!copilotkit) return;\n\n const found = Object.entries(copilotkit.context).find(([id, ctxItem]) => {\n return JSON.stringify({ description, value }) == JSON.stringify(ctxItem);\n });\n if (found) {\n ctxIdRef.current = found[0];\n if (available === \"disabled\") copilotkit.removeContext(ctxIdRef.current);\n return;\n }\n if (!found && available === \"disabled\") return;\n\n ctxIdRef.current = copilotkit.addContext({\n description,\n value: (convert ?? JSON.stringify)(value),\n });\n\n return () => {\n if (!ctxIdRef.current) return;\n copilotkit.removeContext(ctxIdRef.current);\n };\n }, [description, value, convert]);\n\n return ctxIdRef.current;\n}\n"],"mappings":";AA+DA,SAAS,qBAAqB;AAC9B,SAAS,WAAW,cAAc;AAyC3B,SAAS,mBACd,EAAE,aAAa,OAAO,SAAS,UAAU,GACzC,cACoB;AACpB,QAAM,EAAE,WAAW,IAAI,cAAc;AACrC,QAAM,WAAW,OAA2B,MAAS;AACrD,YAAU,MAAM;AACd,QAAI,CAAC;AAAY;AAEjB,UAAM,QAAQ,OAAO,QAAQ,WAAW,OAAO,EAAE,KAAK,CAAC,CAAC,IAAI,OAAO,MAAM;AACvE,aAAO,KAAK,UAAU,EAAE,aAAa,MAAM,CAAC,KAAK,KAAK,UAAU,OAAO;AAAA,IACzE,CAAC;AACD,QAAI,OAAO;AACT,eAAS,UAAU,MAAM,CAAC;AAC1B,UAAI,cAAc;AAAY,mBAAW,cAAc,SAAS,OAAO;AACvE;AAAA,IACF;AACA,QAAI,CAAC,SAAS,cAAc;AAAY;AAExC,aAAS,UAAU,WAAW,WAAW;AAAA,MACvC;AAAA,MACA,QAAQ,4BAAW,KAAK,WAAW,KAAK;AAAA,IAC1C,CAAC;AAED,WAAO,MAAM;AACX,UAAI,CAAC,SAAS;AAAS;AACvB,iBAAW,cAAc,SAAS,OAAO;AAAA,IAC3C;AAAA,EACF,GAAG,CAAC,aAAa,OAAO,OAAO,CAAC;AAEhC,SAAO,SAAS;AAClB;","names":[]}
@@ -1 +0,0 @@
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"]}
@@ -1,8 +0,0 @@
1
- import {
2
- useConfigureChatSuggestions
3
- } from "../chunk-FBVI3LQ6.mjs";
4
- import "../chunk-SKC7AJIV.mjs";
5
- export {
6
- useConfigureChatSuggestions
7
- };
8
- //# sourceMappingURL=use-configure-chat-suggestions.mjs.map
@@ -1,86 +0,0 @@
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
- }