@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
@@ -1,190 +0,0 @@
1
- /**
2
- * <Callout type="warning">
3
- * useCopilotSuggestions is experimental. The interface is not final and
4
- * can change without notice.
5
- * </Callout>
6
- *
7
- * `useCopilotSuggestions` is a React hook that provides auto-suggestions that can be added to any
8
- * UI component.
9
- *
10
- * ## Usage
11
- *
12
- * ### Install Dependencies
13
- *
14
- * This component is part of the [@copilotkit/react-ui](https://npmjs.com/package/@copilotkit/react-ui) package.
15
- *
16
- * ```shell npm2yarn \"@copilotkit/react-ui"\
17
- * npm install @copilotkit/react-core @copilotkit/react-ui
18
- * ```
19
- *
20
- * ### Simple Usage
21
- *
22
- * ```tsx
23
- * TODO
24
- * ```
25
- *
26
- * ### Dependency Management
27
- *
28
- * ```tsx
29
- * TODO
30
- * }
31
- * ```
32
- *
33
- * In the example above, the suggestions are generated based on the given instructions.
34
- * The hook monitors `appState`, and updates suggestions accordingly whenever it changes.
35
- *
36
- * ### Behavior and Lifecycle
37
- *
38
- * The hook registers the configuration with the chat context upon component mount and
39
- * removes it on unmount, ensuring a clean and efficient lifecycle management.
40
- */
41
-
42
- import { useEffect, useState, useRef, useCallback } from "react";
43
- import {
44
- CopilotContextParams,
45
- CopilotMessagesContextParams,
46
- extract,
47
- useCopilotContext,
48
- useCopilotMessagesContext,
49
- } from "@copilotkit/react-core";
50
- import { MappedParameterTypes, Parameter, randomId } from "@copilotkit/shared";
51
- import { CopilotRequestType } from "@copilotkit/runtime-client-gql";
52
-
53
- export interface UseCopilotSuggestionsConfiguration<T extends Parameter[] = []> {
54
- /**
55
- * A prompt or instructions for the GPT to generate suggestions.
56
- */
57
- instructions?: string;
58
-
59
- /**
60
- * The data to pass to the suggestions.
61
- */
62
- parameters: T;
63
-
64
- /**
65
- * The current value of the parameter.
66
- */
67
- value?: Partial<MappedParameterTypes<T>>;
68
-
69
- /**
70
- * Whether the suggestions are enabled.
71
- * @default true
72
- */
73
- enabled?: boolean;
74
-
75
- /**
76
- * The debounce time in milliseconds.
77
- * @default 1000
78
- */
79
- debounceTime?: number;
80
- }
81
- export type SuggestionsResult<T extends Parameter[]> =
82
- | { suggestions: undefined; isAvailable: false; isLoading: boolean }
83
- | { suggestions: MappedParameterTypes<T>; isAvailable: true; isLoading: boolean };
84
-
85
- export function useCopilotSuggestions<const T extends Parameter[]>(
86
- {
87
- instructions,
88
- parameters,
89
- value,
90
- enabled = true,
91
- debounceTime = 1000,
92
- }: UseCopilotSuggestionsConfiguration<T>,
93
- dependencies: any[] = [],
94
- ): SuggestionsResult<T> {
95
- const suggestionsAbortControllerRef = useRef<AbortController | null>(null);
96
- const debounceTimerRef = useRef<any>();
97
- const [suggestions, setSuggestions] = useState<SuggestionsResult<T>>({
98
- suggestions: undefined,
99
- isAvailable: false,
100
- isLoading: false,
101
- });
102
- const isFirstRunRef = useRef(true);
103
-
104
- const abortSuggestions = useCallback(() => {
105
- suggestionsAbortControllerRef.current?.abort();
106
- suggestionsAbortControllerRef.current = null;
107
- }, []);
108
-
109
- const generalContext = useCopilotContext();
110
- const messagesContext = useCopilotMessagesContext();
111
- const context = { ...generalContext, ...messagesContext };
112
-
113
- useEffect(() => {
114
- abortSuggestions();
115
- if (!enabled) {
116
- setSuggestions({ suggestions: undefined, isAvailable: false, isLoading: false });
117
- return;
118
- }
119
-
120
- // if value is the same as the last suggestions, don't reload
121
- if (JSON.stringify(value) === JSON.stringify(suggestions.suggestions)) {
122
- return;
123
- }
124
-
125
- debounceTimerRef.current = setTimeout(
126
- async () => {
127
- isFirstRunRef.current = false;
128
- suggestionsAbortControllerRef.current = new AbortController();
129
- setSuggestions({ ...suggestions, isLoading: true });
130
- await reloadSuggestions(
131
- context,
132
- instructions,
133
- parameters,
134
- value,
135
- suggestionsAbortControllerRef,
136
- setSuggestions,
137
- );
138
- },
139
- isFirstRunRef.current === true ? 0 : debounceTime,
140
- );
141
-
142
- return () => {
143
- clearTimeout(debounceTimerRef.current);
144
- };
145
- }, [
146
- instructions,
147
- JSON.stringify(parameters),
148
- JSON.stringify(value),
149
- enabled,
150
- debounceTime,
151
- ...dependencies,
152
- ]);
153
-
154
- return suggestions;
155
- }
156
-
157
- async function reloadSuggestions(
158
- context: CopilotContextParams & CopilotMessagesContextParams,
159
- instructions: string | undefined,
160
- parameters: Parameter[],
161
- value: any,
162
- abortControllerRef: React.MutableRefObject<AbortController | null>,
163
- setSuggestions: (suggestions: any) => void,
164
- ) {
165
- const abortController = abortControllerRef.current;
166
- let fullInstructions = `It's your task to generate suggestions based on the application context.`;
167
- if (instructions) {
168
- fullInstructions += `\n\nIn addition, follow these specific instructions: ${instructions}`;
169
- }
170
- if (value) {
171
- fullInstructions +=
172
- `\n\nThe current value of the parameter is: ${JSON.stringify(value)}.` +
173
- `If it makes sense to complete the existing data, i.e. expand string values, add new elements to arrays, etc., do so. ` +
174
- `Otherwise, generate a new value.`;
175
- }
176
-
177
- await extract({
178
- context,
179
- instructions: instructions || "",
180
- data: fullInstructions,
181
- parameters,
182
- abortSignal: abortController?.signal,
183
- requestType: CopilotRequestType.Task,
184
- stream({ args, status }) {
185
- if (status === "complete") {
186
- setSuggestions({ suggestions: args, isAvailable: true, isLoading: false });
187
- }
188
- },
189
- });
190
- }