@copilotkit/react-ui 1.3.16-mme-copilot-suggestions.1 → 1.3.16-mme-reset-chat.2

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 +20 -10
  2. package/dist/{chunk-DTI5DZSK.mjs → chunk-3EYL2DRG.mjs} +5 -5
  3. package/dist/{chunk-T7DQWLTN.mjs → chunk-3JNDMHS4.mjs} +2 -2
  4. package/dist/{chunk-PIK3RYPJ.mjs → chunk-AX7CAT7V.mjs} +2 -2
  5. package/dist/{chunk-UYT3USIS.mjs → chunk-NLIDKNNS.mjs} +5 -5
  6. package/dist/{chunk-W3TDOLUY.mjs → chunk-RS6UPR5N.mjs} +8 -8
  7. package/dist/chunk-T26KLXLH.mjs +1 -0
  8. package/dist/{chunk-HGQFDT5I.mjs → chunk-Z2UZSN3K.mjs} +1 -1
  9. package/dist/chunk-Z2UZSN3K.mjs.map +1 -0
  10. package/dist/components/chat/Chat.mjs +5 -5
  11. package/dist/components/chat/Modal.mjs +6 -6
  12. package/dist/components/chat/Popup.mjs +7 -7
  13. package/dist/components/chat/Sidebar.mjs +7 -7
  14. package/dist/components/chat/index.mjs +8 -8
  15. package/dist/components/chat/messages/RenderTextMessage.mjs +1 -1
  16. package/dist/components/dev-console/console.mjs +2 -2
  17. package/dist/components/dev-console/index.mjs +2 -2
  18. package/dist/components/index.mjs +8 -8
  19. package/dist/hooks/index.d.ts +0 -2
  20. package/dist/hooks/index.js +2 -136
  21. package/dist/hooks/index.js.map +1 -1
  22. package/dist/hooks/index.mjs +3 -7
  23. package/dist/hooks/use-copilot-chat-suggestions.d.ts +3 -1
  24. package/dist/hooks/use-copilot-chat-suggestions.js.map +1 -1
  25. package/dist/hooks/use-copilot-chat-suggestions.mjs +1 -1
  26. package/dist/index.d.ts +0 -2
  27. package/dist/index.js +2 -99
  28. package/dist/index.js.map +1 -1
  29. package/dist/index.mjs +11 -15
  30. package/package.json +7 -7
  31. package/src/hooks/index.ts +0 -1
  32. package/src/hooks/use-copilot-chat-suggestions.tsx +3 -1
  33. package/dist/chunk-G7A3YV3L.mjs +0 -109
  34. package/dist/chunk-G7A3YV3L.mjs.map +0 -1
  35. package/dist/chunk-HGQFDT5I.mjs.map +0 -1
  36. package/dist/chunk-RJ54B6VE.mjs +0 -1
  37. package/dist/hooks/use-copilot-suggestions.d.ts +0 -79
  38. package/dist/hooks/use-copilot-suggestions.js +0 -160
  39. package/dist/hooks/use-copilot-suggestions.js.map +0 -1
  40. package/dist/hooks/use-copilot-suggestions.mjs +0 -8
  41. package/dist/hooks/use-copilot-suggestions.mjs.map +0 -1
  42. package/src/hooks/use-copilot-suggestions.ts +0 -190
  43. /package/dist/{chunk-DTI5DZSK.mjs.map → chunk-3EYL2DRG.mjs.map} +0 -0
  44. /package/dist/{chunk-T7DQWLTN.mjs.map → chunk-3JNDMHS4.mjs.map} +0 -0
  45. /package/dist/{chunk-PIK3RYPJ.mjs.map → chunk-AX7CAT7V.mjs.map} +0 -0
  46. /package/dist/{chunk-UYT3USIS.mjs.map → chunk-NLIDKNNS.mjs.map} +0 -0
  47. /package/dist/{chunk-W3TDOLUY.mjs.map → chunk-RS6UPR5N.mjs.map} +0 -0
  48. /package/dist/{chunk-RJ54B6VE.mjs.map → chunk-T26KLXLH.mjs.map} +0 -0
package/dist/index.mjs CHANGED
@@ -4,45 +4,42 @@ import "./chunk-JD7BAH7U.mjs";
4
4
  import "./chunk-MRFF7GSQ.mjs";
5
5
  import {
6
6
  CopilotSidebar
7
- } from "./chunk-T7DQWLTN.mjs";
7
+ } from "./chunk-3JNDMHS4.mjs";
8
8
  import "./chunk-WB3YULQ4.mjs";
9
9
  import {
10
10
  CopilotPopup
11
- } from "./chunk-PIK3RYPJ.mjs";
12
- import "./chunk-DTI5DZSK.mjs";
11
+ } from "./chunk-AX7CAT7V.mjs";
12
+ import "./chunk-3EYL2DRG.mjs";
13
13
  import "./chunk-YAGE7RCE.mjs";
14
14
  import "./chunk-VEC45H6Q.mjs";
15
15
  import "./chunk-RQNJNK2W.mjs";
16
16
  import {
17
17
  CopilotChat
18
- } from "./chunk-UYT3USIS.mjs";
18
+ } from "./chunk-NLIDKNNS.mjs";
19
19
  import "./chunk-V7W6IM2V.mjs";
20
20
  import "./chunk-OMTPWC7T.mjs";
21
21
  import "./chunk-ZABXREBH.mjs";
22
22
  import "./chunk-6INMITFA.mjs";
23
23
  import "./chunk-RU73BEZM.mjs";
24
- import "./chunk-3XAXY2Z3.mjs";
25
24
  import "./chunk-RJCZRKTV.mjs";
26
- import "./chunk-W3TDOLUY.mjs";
27
- import "./chunk-OTPAZXVR.mjs";
25
+ import "./chunk-RS6UPR5N.mjs";
28
26
  import "./chunk-4FIGRRFS.mjs";
27
+ import "./chunk-OTPAZXVR.mjs";
29
28
  import "./chunk-4LUMV4YO.mjs";
30
29
  import "./chunk-YQFVRDNC.mjs";
31
30
  import "./chunk-YQ3D5IQV.mjs";
32
- import "./chunk-UPTB2MVO.mjs";
33
31
  import "./chunk-CPMIEVKK.mjs";
32
+ import "./chunk-3XAXY2Z3.mjs";
34
33
  import {
35
34
  useChatContext
36
35
  } from "./chunk-CBBFRI3Q.mjs";
36
+ import "./chunk-UPTB2MVO.mjs";
37
37
  import "./chunk-FZC7X5PK.mjs";
38
38
  import "./chunk-IU3WTXLQ.mjs";
39
- import "./chunk-RJ54B6VE.mjs";
39
+ import "./chunk-T26KLXLH.mjs";
40
40
  import {
41
41
  useCopilotChatSuggestions
42
- } from "./chunk-HGQFDT5I.mjs";
43
- import {
44
- useCopilotSuggestions
45
- } from "./chunk-G7A3YV3L.mjs";
42
+ } from "./chunk-Z2UZSN3K.mjs";
46
43
  import "./chunk-54JAUBUJ.mjs";
47
44
  import "./chunk-S5MBUNGN.mjs";
48
45
  import "./chunk-MRXNTQOX.mjs";
@@ -51,7 +48,6 @@ export {
51
48
  CopilotPopup,
52
49
  CopilotSidebar,
53
50
  useChatContext,
54
- useCopilotChatSuggestions,
55
- useCopilotSuggestions
51
+ useCopilotChatSuggestions
56
52
  };
57
53
  //# sourceMappingURL=index.mjs.map
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "publishConfig": {
10
10
  "access": "public"
11
11
  },
12
- "version": "1.3.16-mme-copilot-suggestions.1",
12
+ "version": "1.3.16-mme-reset-chat.2",
13
13
  "sideEffects": [
14
14
  "**/*.css"
15
15
  ],
@@ -40,9 +40,9 @@
40
40
  "ts-jest": "^29.1.1",
41
41
  "tsup": "^6.7.0",
42
42
  "typescript": "^5.2.3",
43
- "eslint-config-custom": "1.3.16-mme-copilot-suggestions.1",
44
- "tailwind-config": "1.3.16-mme-copilot-suggestions.1",
45
- "tsconfig": "1.3.16-mme-copilot-suggestions.1"
43
+ "eslint-config-custom": "1.3.16-mme-reset-chat.2",
44
+ "tailwind-config": "1.3.16-mme-reset-chat.2",
45
+ "tsconfig": "1.3.16-mme-reset-chat.2"
46
46
  },
47
47
  "dependencies": {
48
48
  "@headlessui/react": "^2.1.3",
@@ -50,9 +50,9 @@
50
50
  "react-syntax-highlighter": "^15.5.0",
51
51
  "remark-gfm": "^3.0.1",
52
52
  "remark-math": "^5.1.1",
53
- "@copilotkit/react-core": "1.3.16-mme-copilot-suggestions.1",
54
- "@copilotkit/runtime-client-gql": "1.3.16-mme-copilot-suggestions.1",
55
- "@copilotkit/shared": "1.3.16-mme-copilot-suggestions.1"
53
+ "@copilotkit/react-core": "1.3.16-mme-reset-chat.2",
54
+ "@copilotkit/runtime-client-gql": "1.3.16-mme-reset-chat.2",
55
+ "@copilotkit/shared": "1.3.16-mme-reset-chat.2"
56
56
  },
57
57
  "keywords": [
58
58
  "copilotkit",
@@ -1,2 +1 @@
1
1
  export * from "./use-copilot-chat-suggestions";
2
- export * from "./use-copilot-suggestions";
@@ -4,7 +4,9 @@
4
4
  * can change without notice.
5
5
  * </Callout>
6
6
  *
7
- * `useCopilotChatSuggestions` is a React hook that provides auto-suggestions in the Copilot chat.
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.
8
10
  *
9
11
  * <br/>
10
12
  * <img src="/images/use-copilot-chat-suggestions/use-copilot-chat-suggestions.gif" width="500" />
@@ -1,109 +0,0 @@
1
- import {
2
- __async,
3
- __spreadProps,
4
- __spreadValues
5
- } from "./chunk-MRXNTQOX.mjs";
6
-
7
- // src/hooks/use-copilot-suggestions.ts
8
- import { useEffect, useState, useRef, useCallback } from "react";
9
- import {
10
- extract,
11
- useCopilotContext,
12
- useCopilotMessagesContext
13
- } from "@copilotkit/react-core";
14
- import { CopilotRequestType } from "@copilotkit/runtime-client-gql";
15
- function useCopilotSuggestions({
16
- instructions,
17
- parameters,
18
- value,
19
- enabled = true,
20
- debounceTime = 1e3
21
- }, dependencies = []) {
22
- const suggestionsAbortControllerRef = useRef(null);
23
- const debounceTimerRef = useRef();
24
- const [suggestions, setSuggestions] = useState({
25
- suggestions: void 0,
26
- isAvailable: false,
27
- isLoading: false
28
- });
29
- const isFirstRunRef = useRef(true);
30
- const abortSuggestions = useCallback(() => {
31
- var _a;
32
- (_a = suggestionsAbortControllerRef.current) == null ? void 0 : _a.abort();
33
- suggestionsAbortControllerRef.current = null;
34
- }, []);
35
- const generalContext = useCopilotContext();
36
- const messagesContext = useCopilotMessagesContext();
37
- const context = __spreadValues(__spreadValues({}, generalContext), messagesContext);
38
- useEffect(() => {
39
- abortSuggestions();
40
- if (!enabled) {
41
- setSuggestions({ suggestions: void 0, isAvailable: false, isLoading: false });
42
- return;
43
- }
44
- if (JSON.stringify(value) === JSON.stringify(suggestions.suggestions)) {
45
- return;
46
- }
47
- debounceTimerRef.current = setTimeout(
48
- () => __async(this, null, function* () {
49
- isFirstRunRef.current = false;
50
- suggestionsAbortControllerRef.current = new AbortController();
51
- setSuggestions(__spreadProps(__spreadValues({}, suggestions), { isLoading: true }));
52
- yield reloadSuggestions(
53
- context,
54
- instructions,
55
- parameters,
56
- value,
57
- suggestionsAbortControllerRef,
58
- setSuggestions
59
- );
60
- }),
61
- isFirstRunRef.current === true ? 0 : debounceTime
62
- );
63
- return () => {
64
- clearTimeout(debounceTimerRef.current);
65
- };
66
- }, [
67
- instructions,
68
- JSON.stringify(parameters),
69
- JSON.stringify(value),
70
- enabled,
71
- debounceTime,
72
- ...dependencies
73
- ]);
74
- return suggestions;
75
- }
76
- function reloadSuggestions(context, instructions, parameters, value, abortControllerRef, setSuggestions) {
77
- return __async(this, null, function* () {
78
- const abortController = abortControllerRef.current;
79
- let fullInstructions = `It's your task to generate suggestions based on the application context.`;
80
- if (instructions) {
81
- fullInstructions += `
82
-
83
- In addition, follow these specific instructions: ${instructions}`;
84
- }
85
- if (value) {
86
- fullInstructions += `
87
-
88
- The current value of the parameter is: ${JSON.stringify(value)}.If it makes sense to complete the existing data, i.e. expand string values, add new elements to arrays, etc., do so. Otherwise, generate a new value.`;
89
- }
90
- yield extract({
91
- context,
92
- instructions: instructions || "",
93
- data: fullInstructions,
94
- parameters,
95
- abortSignal: abortController == null ? void 0 : abortController.signal,
96
- requestType: CopilotRequestType.Task,
97
- stream({ args, status }) {
98
- if (status === "complete") {
99
- setSuggestions({ suggestions: args, isAvailable: true, isLoading: false });
100
- }
101
- }
102
- });
103
- });
104
- }
105
-
106
- export {
107
- useCopilotSuggestions
108
- };
109
- //# sourceMappingURL=chunk-G7A3YV3L.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/hooks/use-copilot-suggestions.ts"],"sourcesContent":["/**\n * <Callout type=\"warning\">\n * useCopilotSuggestions is experimental. The interface is not final and\n * can change without notice.\n * </Callout>\n *\n * `useCopilotSuggestions` is a React hook that provides auto-suggestions that can be added to any\n * UI component.\n *\n * ## Usage\n *\n * ### Install Dependencies\n *\n * This component is part of the [@copilotkit/react-ui](https://npmjs.com/package/@copilotkit/react-ui) package.\n *\n * ```shell npm2yarn \\\"@copilotkit/react-ui\"\\\n * npm install @copilotkit/react-core @copilotkit/react-ui\n * ```\n *\n * ### Simple Usage\n *\n * ```tsx\n * TODO\n * ```\n *\n * ### Dependency Management\n *\n * ```tsx\n * TODO\n * }\n * ```\n *\n * In the example above, the suggestions are generated based on the given instructions.\n * The hook monitors `appState`, and updates suggestions accordingly whenever it changes.\n *\n * ### Behavior and Lifecycle\n *\n * The hook registers the configuration with the chat context upon component mount and\n * removes it on unmount, ensuring a clean and efficient lifecycle management.\n */\n\nimport { useEffect, useState, useRef, useCallback } from \"react\";\nimport {\n CopilotContextParams,\n CopilotMessagesContextParams,\n extract,\n useCopilotContext,\n useCopilotMessagesContext,\n} from \"@copilotkit/react-core\";\nimport { MappedParameterTypes, Parameter, randomId } from \"@copilotkit/shared\";\nimport { CopilotRequestType } from \"@copilotkit/runtime-client-gql\";\n\nexport interface UseCopilotSuggestionsConfiguration<T extends Parameter[] = []> {\n /**\n * A prompt or instructions for the GPT to generate suggestions.\n */\n instructions?: string;\n\n /**\n * The data to pass to the suggestions.\n */\n parameters: T;\n\n /**\n * The current value of the parameter.\n */\n value?: Partial<MappedParameterTypes<T>>;\n\n /**\n * Whether the suggestions are enabled.\n * @default true\n */\n enabled?: boolean;\n\n /**\n * The debounce time in milliseconds.\n * @default 1000\n */\n debounceTime?: number;\n}\nexport type SuggestionsResult<T extends Parameter[]> =\n | { suggestions: undefined; isAvailable: false; isLoading: boolean }\n | { suggestions: MappedParameterTypes<T>; isAvailable: true; isLoading: boolean };\n\nexport function useCopilotSuggestions<const T extends Parameter[]>(\n {\n instructions,\n parameters,\n value,\n enabled = true,\n debounceTime = 1000,\n }: UseCopilotSuggestionsConfiguration<T>,\n dependencies: any[] = [],\n): SuggestionsResult<T> {\n const suggestionsAbortControllerRef = useRef<AbortController | null>(null);\n const debounceTimerRef = useRef<any>();\n const [suggestions, setSuggestions] = useState<SuggestionsResult<T>>({\n suggestions: undefined,\n isAvailable: false,\n isLoading: false,\n });\n const isFirstRunRef = useRef(true);\n\n const abortSuggestions = useCallback(() => {\n suggestionsAbortControllerRef.current?.abort();\n suggestionsAbortControllerRef.current = null;\n }, []);\n\n const generalContext = useCopilotContext();\n const messagesContext = useCopilotMessagesContext();\n const context = { ...generalContext, ...messagesContext };\n\n useEffect(() => {\n abortSuggestions();\n if (!enabled) {\n setSuggestions({ suggestions: undefined, isAvailable: false, isLoading: false });\n return;\n }\n\n // if value is the same as the last suggestions, don't reload\n if (JSON.stringify(value) === JSON.stringify(suggestions.suggestions)) {\n return;\n }\n\n debounceTimerRef.current = setTimeout(\n async () => {\n isFirstRunRef.current = false;\n suggestionsAbortControllerRef.current = new AbortController();\n setSuggestions({ ...suggestions, isLoading: true });\n await reloadSuggestions(\n context,\n instructions,\n parameters,\n value,\n suggestionsAbortControllerRef,\n setSuggestions,\n );\n },\n isFirstRunRef.current === true ? 0 : debounceTime,\n );\n\n return () => {\n clearTimeout(debounceTimerRef.current);\n };\n }, [\n instructions,\n JSON.stringify(parameters),\n JSON.stringify(value),\n enabled,\n debounceTime,\n ...dependencies,\n ]);\n\n return suggestions;\n}\n\nasync function reloadSuggestions(\n context: CopilotContextParams & CopilotMessagesContextParams,\n instructions: string | undefined,\n parameters: Parameter[],\n value: any,\n abortControllerRef: React.MutableRefObject<AbortController | null>,\n setSuggestions: (suggestions: any) => void,\n) {\n const abortController = abortControllerRef.current;\n let fullInstructions = `It's your task to generate suggestions based on the application context.`;\n if (instructions) {\n fullInstructions += `\\n\\nIn addition, follow these specific instructions: ${instructions}`;\n }\n if (value) {\n fullInstructions +=\n `\\n\\nThe current value of the parameter is: ${JSON.stringify(value)}.` +\n `If it makes sense to complete the existing data, i.e. expand string values, add new elements to arrays, etc., do so. ` +\n `Otherwise, generate a new value.`;\n }\n\n await extract({\n context,\n instructions: instructions || \"\",\n data: fullInstructions,\n parameters,\n abortSignal: abortController?.signal,\n requestType: CopilotRequestType.Task,\n stream({ args, status }) {\n if (status === \"complete\") {\n setSuggestions({ suggestions: args, isAvailable: true, isLoading: false });\n }\n },\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IACvC;AAAA,EACF,GAAG;AAAA,IACD;AAAA,IACA,KAAK,UAAU,UAAU;AAAA,IACzB,KAAK,UAAU,KAAK;AAAA,IACpB;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EACL,CAAC;AAED,SAAO;AACT;AAEA,SAAe,kBACb,SACA,cACA,YACA,OACA,oBACA,gBACA;AAAA;AACA,UAAM,kBAAkB,mBAAmB;AAC3C,QAAI,mBAAmB;AACvB,QAAI,cAAc;AAChB,0BAAoB;AAAA;AAAA,mDAAwD;AAAA,IAC9E;AACA,QAAI,OAAO;AACT,0BACE;AAAA;AAAA,yCAA8C,KAAK,UAAU,KAAK;AAAA,IAGtE;AAEA,UAAM,QAAQ;AAAA,MACZ;AAAA,MACA,cAAc,gBAAgB;AAAA,MAC9B,MAAM;AAAA,MACN;AAAA,MACA,aAAa,mDAAiB;AAAA,MAC9B,aAAa,mBAAmB;AAAA,MAChC,OAAO,EAAE,MAAM,OAAO,GAAG;AACvB,YAAI,WAAW,YAAY;AACzB,yBAAe,EAAE,aAAa,MAAM,aAAa,MAAM,WAAW,MAAM,CAAC;AAAA,QAC3E;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH;AAAA;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/hooks/use-copilot-chat-suggestions.tsx"],"sourcesContent":["/**\n * <Callout type=\"warning\">\n * useCopilotChatSuggestions is experimental. The interface is not final and\n * can change without notice.\n * </Callout>\n *\n * `useCopilotChatSuggestions` is a React hook that provides auto-suggestions in the Copilot chat.\n *\n * <br/>\n * <img src=\"/images/use-copilot-chat-suggestions/use-copilot-chat-suggestions.gif\" width=\"500\" />\n *\n * ## Usage\n *\n * ### Install Dependencies\n *\n * This component is part of the [@copilotkit/react-ui](https://npmjs.com/package/@copilotkit/react-ui) package.\n *\n * ```shell npm2yarn \\\"@copilotkit/react-ui\"\\\n * npm install @copilotkit/react-core @copilotkit/react-ui\n * ```\n *\n * ### Simple Usage\n *\n * ```tsx\n * import { useCopilotChatSuggestions } from \"@copilotkit/react-ui\";\n *\n * export function MyComponent() {\n * const [employees, setEmployees] = useState([]);\n *\n * useCopilotChatSuggestions({\n * instructions: `The following employees are on duty: ${JSON.stringify(employees)}`,\n * });\n * }\n * ```\n *\n * ### Dependency Management\n *\n * ```tsx\n * import { useCopilotChatSuggestions } from \"@copilotkit/react-ui\";\n *\n * export function MyComponent() {\n * useCopilotChatSuggestions(\n * {\n * instructions: \"Suggest the most relevant next actions.\",\n * },\n * [appState],\n * );\n * }\n * ```\n *\n * In the example above, the suggestions are generated based on the given instructions.\n * The hook monitors `appState`, and updates suggestions accordingly whenever it changes.\n *\n * ### Behavior and Lifecycle\n *\n * The hook registers the configuration with the chat context upon component mount and\n * removes it on unmount, ensuring a clean and efficient lifecycle management.\n */\n\nimport { useEffect } from \"react\";\nimport { useCopilotContext } from \"@copilotkit/react-core\";\nimport { randomId } from \"@copilotkit/shared\";\n\ninterface UseCopilotChatSuggestionsConfiguration {\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 * An optional class name to apply to the suggestions.\n */\n className?: string;\n}\n\nexport function useCopilotChatSuggestions(\n {\n instructions,\n className,\n minSuggestions = 1,\n maxSuggestions = 3,\n }: UseCopilotChatSuggestionsConfiguration,\n dependencies: any[] = [],\n) {\n const context = useCopilotContext();\n\n useEffect(() => {\n const id = randomId();\n\n context.addChatSuggestionConfiguration(id, {\n instructions,\n minSuggestions,\n maxSuggestions,\n className,\n });\n\n return () => {\n context.removeChatSuggestionConfiguration(id);\n };\n }, [...dependencies, instructions, minSuggestions, maxSuggestions, className]);\n}\n"],"mappings":";AA2DA,SAAS,iBAAiB;AAC1B,SAAS,yBAAyB;AAClC,SAAS,gBAAgB;AAuBlB,SAAS,0BACd;AAAA,EACE;AAAA,EACA;AAAA,EACA,iBAAiB;AAAA,EACjB,iBAAiB;AACnB,GACA,eAAsB,CAAC,GACvB;AACA,QAAM,UAAU,kBAAkB;AAElC,YAAU,MAAM;AACd,UAAM,KAAK,SAAS;AAEpB,YAAQ,+BAA+B,IAAI;AAAA,MACzC;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC;AAED,WAAO,MAAM;AACX,cAAQ,kCAAkC,EAAE;AAAA,IAC9C;AAAA,EACF,GAAG,CAAC,GAAG,cAAc,cAAc,gBAAgB,gBAAgB,SAAS,CAAC;AAC/E;","names":[]}
@@ -1 +0,0 @@
1
- //# sourceMappingURL=chunk-RJ54B6VE.mjs.map
@@ -1,79 +0,0 @@
1
- import { Parameter, MappedParameterTypes } from '@copilotkit/shared';
2
-
3
- /**
4
- * <Callout type="warning">
5
- * useCopilotSuggestions is experimental. The interface is not final and
6
- * can change without notice.
7
- * </Callout>
8
- *
9
- * `useCopilotSuggestions` is a React hook that provides auto-suggestions that can be added to any
10
- * UI component.
11
- *
12
- * ## Usage
13
- *
14
- * ### Install Dependencies
15
- *
16
- * This component is part of the [@copilotkit/react-ui](https://npmjs.com/package/@copilotkit/react-ui) package.
17
- *
18
- * ```shell npm2yarn \"@copilotkit/react-ui"\
19
- * npm install @copilotkit/react-core @copilotkit/react-ui
20
- * ```
21
- *
22
- * ### Simple Usage
23
- *
24
- * ```tsx
25
- * TODO
26
- * ```
27
- *
28
- * ### Dependency Management
29
- *
30
- * ```tsx
31
- * TODO
32
- * }
33
- * ```
34
- *
35
- * In the example above, the suggestions are generated based on the given instructions.
36
- * The hook monitors `appState`, and updates suggestions accordingly whenever it changes.
37
- *
38
- * ### Behavior and Lifecycle
39
- *
40
- * The hook registers the configuration with the chat context upon component mount and
41
- * removes it on unmount, ensuring a clean and efficient lifecycle management.
42
- */
43
-
44
- interface UseCopilotSuggestionsConfiguration<T extends Parameter[] = []> {
45
- /**
46
- * A prompt or instructions for the GPT to generate suggestions.
47
- */
48
- instructions?: string;
49
- /**
50
- * The data to pass to the suggestions.
51
- */
52
- parameters: T;
53
- /**
54
- * The current value of the parameter.
55
- */
56
- value?: Partial<MappedParameterTypes<T>>;
57
- /**
58
- * Whether the suggestions are enabled.
59
- * @default true
60
- */
61
- enabled?: boolean;
62
- /**
63
- * The debounce time in milliseconds.
64
- * @default 1000
65
- */
66
- debounceTime?: number;
67
- }
68
- type SuggestionsResult<T extends Parameter[]> = {
69
- suggestions: undefined;
70
- isAvailable: false;
71
- isLoading: boolean;
72
- } | {
73
- suggestions: MappedParameterTypes<T>;
74
- isAvailable: true;
75
- isLoading: boolean;
76
- };
77
- declare function useCopilotSuggestions<const T extends Parameter[]>({ instructions, parameters, value, enabled, debounceTime, }: UseCopilotSuggestionsConfiguration<T>, dependencies?: any[]): SuggestionsResult<T>;
78
-
79
- export { SuggestionsResult, UseCopilotSuggestionsConfiguration, useCopilotSuggestions };
@@ -1,160 +0,0 @@
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
- var __async = (__this, __arguments, generator) => {
37
- return new Promise((resolve, reject) => {
38
- var fulfilled = (value) => {
39
- try {
40
- step(generator.next(value));
41
- } catch (e) {
42
- reject(e);
43
- }
44
- };
45
- var rejected = (value) => {
46
- try {
47
- step(generator.throw(value));
48
- } catch (e) {
49
- reject(e);
50
- }
51
- };
52
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
53
- step((generator = generator.apply(__this, __arguments)).next());
54
- });
55
- };
56
-
57
- // src/hooks/use-copilot-suggestions.ts
58
- var use_copilot_suggestions_exports = {};
59
- __export(use_copilot_suggestions_exports, {
60
- useCopilotSuggestions: () => useCopilotSuggestions
61
- });
62
- module.exports = __toCommonJS(use_copilot_suggestions_exports);
63
- var import_react = require("react");
64
- var import_react_core = require("@copilotkit/react-core");
65
- var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
66
- function useCopilotSuggestions({
67
- instructions,
68
- parameters,
69
- value,
70
- enabled = true,
71
- debounceTime = 1e3
72
- }, dependencies = []) {
73
- const suggestionsAbortControllerRef = (0, import_react.useRef)(null);
74
- const debounceTimerRef = (0, import_react.useRef)();
75
- const [suggestions, setSuggestions] = (0, import_react.useState)({
76
- suggestions: void 0,
77
- isAvailable: false,
78
- isLoading: false
79
- });
80
- const isFirstRunRef = (0, import_react.useRef)(true);
81
- const abortSuggestions = (0, import_react.useCallback)(() => {
82
- var _a;
83
- (_a = suggestionsAbortControllerRef.current) == null ? void 0 : _a.abort();
84
- suggestionsAbortControllerRef.current = null;
85
- }, []);
86
- const generalContext = (0, import_react_core.useCopilotContext)();
87
- const messagesContext = (0, import_react_core.useCopilotMessagesContext)();
88
- const context = __spreadValues(__spreadValues({}, generalContext), messagesContext);
89
- (0, import_react.useEffect)(() => {
90
- abortSuggestions();
91
- if (!enabled) {
92
- setSuggestions({ suggestions: void 0, isAvailable: false, isLoading: false });
93
- return;
94
- }
95
- if (JSON.stringify(value) === JSON.stringify(suggestions.suggestions)) {
96
- return;
97
- }
98
- debounceTimerRef.current = setTimeout(
99
- () => __async(this, null, function* () {
100
- isFirstRunRef.current = false;
101
- suggestionsAbortControllerRef.current = new AbortController();
102
- setSuggestions(__spreadProps(__spreadValues({}, suggestions), { isLoading: true }));
103
- yield reloadSuggestions(
104
- context,
105
- instructions,
106
- parameters,
107
- value,
108
- suggestionsAbortControllerRef,
109
- setSuggestions
110
- );
111
- }),
112
- isFirstRunRef.current === true ? 0 : debounceTime
113
- );
114
- return () => {
115
- clearTimeout(debounceTimerRef.current);
116
- };
117
- }, [
118
- instructions,
119
- JSON.stringify(parameters),
120
- JSON.stringify(value),
121
- enabled,
122
- debounceTime,
123
- ...dependencies
124
- ]);
125
- return suggestions;
126
- }
127
- function reloadSuggestions(context, instructions, parameters, value, abortControllerRef, setSuggestions) {
128
- return __async(this, null, function* () {
129
- const abortController = abortControllerRef.current;
130
- let fullInstructions = `It's your task to generate suggestions based on the application context.`;
131
- if (instructions) {
132
- fullInstructions += `
133
-
134
- In addition, follow these specific instructions: ${instructions}`;
135
- }
136
- if (value) {
137
- fullInstructions += `
138
-
139
- The current value of the parameter is: ${JSON.stringify(value)}.If it makes sense to complete the existing data, i.e. expand string values, add new elements to arrays, etc., do so. Otherwise, generate a new value.`;
140
- }
141
- yield (0, import_react_core.extract)({
142
- context,
143
- instructions: instructions || "",
144
- data: fullInstructions,
145
- parameters,
146
- abortSignal: abortController == null ? void 0 : abortController.signal,
147
- requestType: import_runtime_client_gql.CopilotRequestType.Task,
148
- stream({ args, status }) {
149
- if (status === "complete") {
150
- setSuggestions({ suggestions: args, isAvailable: true, isLoading: false });
151
- }
152
- }
153
- });
154
- });
155
- }
156
- // Annotate the CommonJS export names for ESM import in node:
157
- 0 && (module.exports = {
158
- useCopilotSuggestions
159
- });
160
- //# sourceMappingURL=use-copilot-suggestions.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/hooks/use-copilot-suggestions.ts"],"sourcesContent":["/**\n * <Callout type=\"warning\">\n * useCopilotSuggestions is experimental. The interface is not final and\n * can change without notice.\n * </Callout>\n *\n * `useCopilotSuggestions` is a React hook that provides auto-suggestions that can be added to any\n * UI component.\n *\n * ## Usage\n *\n * ### Install Dependencies\n *\n * This component is part of the [@copilotkit/react-ui](https://npmjs.com/package/@copilotkit/react-ui) package.\n *\n * ```shell npm2yarn \\\"@copilotkit/react-ui\"\\\n * npm install @copilotkit/react-core @copilotkit/react-ui\n * ```\n *\n * ### Simple Usage\n *\n * ```tsx\n * TODO\n * ```\n *\n * ### Dependency Management\n *\n * ```tsx\n * TODO\n * }\n * ```\n *\n * In the example above, the suggestions are generated based on the given instructions.\n * The hook monitors `appState`, and updates suggestions accordingly whenever it changes.\n *\n * ### Behavior and Lifecycle\n *\n * The hook registers the configuration with the chat context upon component mount and\n * removes it on unmount, ensuring a clean and efficient lifecycle management.\n */\n\nimport { useEffect, useState, useRef, useCallback } from \"react\";\nimport {\n CopilotContextParams,\n CopilotMessagesContextParams,\n extract,\n useCopilotContext,\n useCopilotMessagesContext,\n} from \"@copilotkit/react-core\";\nimport { MappedParameterTypes, Parameter, randomId } from \"@copilotkit/shared\";\nimport { CopilotRequestType } from \"@copilotkit/runtime-client-gql\";\n\nexport interface UseCopilotSuggestionsConfiguration<T extends Parameter[] = []> {\n /**\n * A prompt or instructions for the GPT to generate suggestions.\n */\n instructions?: string;\n\n /**\n * The data to pass to the suggestions.\n */\n parameters: T;\n\n /**\n * The current value of the parameter.\n */\n value?: Partial<MappedParameterTypes<T>>;\n\n /**\n * Whether the suggestions are enabled.\n * @default true\n */\n enabled?: boolean;\n\n /**\n * The debounce time in milliseconds.\n * @default 1000\n */\n debounceTime?: number;\n}\nexport type SuggestionsResult<T extends Parameter[]> =\n | { suggestions: undefined; isAvailable: false; isLoading: boolean }\n | { suggestions: MappedParameterTypes<T>; isAvailable: true; isLoading: boolean };\n\nexport function useCopilotSuggestions<const T extends Parameter[]>(\n {\n instructions,\n parameters,\n value,\n enabled = true,\n debounceTime = 1000,\n }: UseCopilotSuggestionsConfiguration<T>,\n dependencies: any[] = [],\n): SuggestionsResult<T> {\n const suggestionsAbortControllerRef = useRef<AbortController | null>(null);\n const debounceTimerRef = useRef<any>();\n const [suggestions, setSuggestions] = useState<SuggestionsResult<T>>({\n suggestions: undefined,\n isAvailable: false,\n isLoading: false,\n });\n const isFirstRunRef = useRef(true);\n\n const abortSuggestions = useCallback(() => {\n suggestionsAbortControllerRef.current?.abort();\n suggestionsAbortControllerRef.current = null;\n }, []);\n\n const generalContext = useCopilotContext();\n const messagesContext = useCopilotMessagesContext();\n const context = { ...generalContext, ...messagesContext };\n\n useEffect(() => {\n abortSuggestions();\n if (!enabled) {\n setSuggestions({ suggestions: undefined, isAvailable: false, isLoading: false });\n return;\n }\n\n // if value is the same as the last suggestions, don't reload\n if (JSON.stringify(value) === JSON.stringify(suggestions.suggestions)) {\n return;\n }\n\n debounceTimerRef.current = setTimeout(\n async () => {\n isFirstRunRef.current = false;\n suggestionsAbortControllerRef.current = new AbortController();\n setSuggestions({ ...suggestions, isLoading: true });\n await reloadSuggestions(\n context,\n instructions,\n parameters,\n value,\n suggestionsAbortControllerRef,\n setSuggestions,\n );\n },\n isFirstRunRef.current === true ? 0 : debounceTime,\n );\n\n return () => {\n clearTimeout(debounceTimerRef.current);\n };\n }, [\n instructions,\n JSON.stringify(parameters),\n JSON.stringify(value),\n enabled,\n debounceTime,\n ...dependencies,\n ]);\n\n return suggestions;\n}\n\nasync function reloadSuggestions(\n context: CopilotContextParams & CopilotMessagesContextParams,\n instructions: string | undefined,\n parameters: Parameter[],\n value: any,\n abortControllerRef: React.MutableRefObject<AbortController | null>,\n setSuggestions: (suggestions: any) => void,\n) {\n const abortController = abortControllerRef.current;\n let fullInstructions = `It's your task to generate suggestions based on the application context.`;\n if (instructions) {\n fullInstructions += `\\n\\nIn addition, follow these specific instructions: ${instructions}`;\n }\n if (value) {\n fullInstructions +=\n `\\n\\nThe current value of the parameter is: ${JSON.stringify(value)}.` +\n `If it makes sense to complete the existing data, i.e. expand string values, add new elements to arrays, etc., do so. ` +\n `Otherwise, generate a new value.`;\n }\n\n await extract({\n context,\n instructions: instructions || \"\",\n data: fullInstructions,\n parameters,\n abortSignal: abortController?.signal,\n requestType: CopilotRequestType.Task,\n stream({ args, status }) {\n if (status === \"complete\") {\n setSuggestions({ suggestions: args, isAvailable: true, isLoading: false });\n }\n },\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAyCA,mBAAyD;AACzD,wBAMO;AAEP,gCAAmC;AAkC5B,SAAS,sBACd;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA,UAAU;AAAA,EACV,eAAe;AACjB,GACA,eAAsB,CAAC,GACD;AACtB,QAAM,oCAAgC,qBAA+B,IAAI;AACzE,QAAM,uBAAmB,qBAAY;AACrC,QAAM,CAAC,aAAa,cAAc,QAAI,uBAA+B;AAAA,IACnE,aAAa;AAAA,IACb,aAAa;AAAA,IACb,WAAW;AAAA,EACb,CAAC;AACD,QAAM,oBAAgB,qBAAO,IAAI;AAEjC,QAAM,uBAAmB,0BAAY,MAAM;AAvG7C;AAwGI,wCAA8B,YAA9B,mBAAuC;AACvC,kCAA8B,UAAU;AAAA,EAC1C,GAAG,CAAC,CAAC;AAEL,QAAM,qBAAiB,qCAAkB;AACzC,QAAM,sBAAk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,yBAAe,EAAE,aAAa,MAAM,aAAa,MAAM,WAAW,MAAM,CAAC;AAAA,QAC3E;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH;AAAA;","names":[]}
@@ -1,8 +0,0 @@
1
- import {
2
- useCopilotSuggestions
3
- } from "../chunk-G7A3YV3L.mjs";
4
- import "../chunk-MRXNTQOX.mjs";
5
- export {
6
- useCopilotSuggestions
7
- };
8
- //# sourceMappingURL=use-copilot-suggestions.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}