@copilotkit/react-ui 1.3.16-mme-copilot-suggestions.0 → 1.3.16-mme-improve-langsmith.1
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 +15 -5
- package/dist/{chunk-DTI5DZSK.mjs → chunk-3EYL2DRG.mjs} +5 -5
- package/dist/{chunk-T7DQWLTN.mjs → chunk-3JNDMHS4.mjs} +2 -2
- package/dist/{chunk-PIK3RYPJ.mjs → chunk-AX7CAT7V.mjs} +2 -2
- package/dist/{chunk-UYT3USIS.mjs → chunk-NLIDKNNS.mjs} +5 -5
- package/dist/{chunk-W3TDOLUY.mjs → chunk-RS6UPR5N.mjs} +8 -8
- package/dist/chunk-T26KLXLH.mjs +1 -0
- package/dist/{chunk-HGQFDT5I.mjs → chunk-Z2UZSN3K.mjs} +1 -1
- package/dist/chunk-Z2UZSN3K.mjs.map +1 -0
- package/dist/components/chat/Chat.mjs +5 -5
- package/dist/components/chat/Modal.mjs +6 -6
- package/dist/components/chat/Popup.mjs +7 -7
- package/dist/components/chat/Sidebar.mjs +7 -7
- package/dist/components/chat/index.mjs +8 -8
- package/dist/components/chat/messages/RenderTextMessage.mjs +1 -1
- package/dist/components/dev-console/console.mjs +2 -2
- package/dist/components/dev-console/index.mjs +2 -2
- package/dist/components/index.mjs +8 -8
- package/dist/hooks/index.d.ts +0 -2
- package/dist/hooks/index.js +2 -135
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +3 -7
- package/dist/hooks/use-copilot-chat-suggestions.d.ts +3 -1
- package/dist/hooks/use-copilot-chat-suggestions.js.map +1 -1
- package/dist/hooks/use-copilot-chat-suggestions.mjs +1 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.js +2 -98
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +11 -15
- package/package.json +7 -7
- package/src/hooks/index.ts +0 -1
- package/src/hooks/use-copilot-chat-suggestions.tsx +3 -1
- package/dist/chunk-HGQFDT5I.mjs.map +0 -1
- package/dist/chunk-K5JLXNIN.mjs +0 -108
- package/dist/chunk-K5JLXNIN.mjs.map +0 -1
- package/dist/chunk-RJ54B6VE.mjs +0 -1
- package/dist/hooks/use-copilot-suggestions.d.ts +0 -79
- package/dist/hooks/use-copilot-suggestions.js +0 -159
- package/dist/hooks/use-copilot-suggestions.js.map +0 -1
- package/dist/hooks/use-copilot-suggestions.mjs +0 -8
- package/dist/hooks/use-copilot-suggestions.mjs.map +0 -1
- package/src/hooks/use-copilot-suggestions.ts +0 -189
- /package/dist/{chunk-DTI5DZSK.mjs.map → chunk-3EYL2DRG.mjs.map} +0 -0
- /package/dist/{chunk-T7DQWLTN.mjs.map → chunk-3JNDMHS4.mjs.map} +0 -0
- /package/dist/{chunk-PIK3RYPJ.mjs.map → chunk-AX7CAT7V.mjs.map} +0 -0
- /package/dist/{chunk-UYT3USIS.mjs.map → chunk-NLIDKNNS.mjs.map} +0 -0
- /package/dist/{chunk-W3TDOLUY.mjs.map → chunk-RS6UPR5N.mjs.map} +0 -0
- /package/dist/{chunk-RJ54B6VE.mjs.map → chunk-T26KLXLH.mjs.map} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,14 +1,24 @@
|
|
|
1
1
|
# ui
|
|
2
2
|
|
|
3
|
-
## 1.3.16-mme-
|
|
3
|
+
## 1.3.16-mme-improve-langsmith.1
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
|
-
-
|
|
7
|
+
- Ensure the last message is sent to LangSmith
|
|
8
8
|
- Updated dependencies
|
|
9
|
-
- @copilotkit/
|
|
10
|
-
- @copilotkit/
|
|
11
|
-
- @copilotkit/shared@1.3.16-mme-
|
|
9
|
+
- @copilotkit/runtime-client-gql@1.3.16-mme-improve-langsmith.1
|
|
10
|
+
- @copilotkit/react-core@1.3.16-mme-improve-langsmith.1
|
|
11
|
+
- @copilotkit/shared@1.3.16-mme-improve-langsmith.1
|
|
12
|
+
|
|
13
|
+
## 1.3.16-mme-improve-langsmith.0
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- Improve LangSmith support
|
|
18
|
+
- Updated dependencies
|
|
19
|
+
- @copilotkit/react-core@1.3.16-mme-improve-langsmith.0
|
|
20
|
+
- @copilotkit/runtime-client-gql@1.3.16-mme-improve-langsmith.0
|
|
21
|
+
- @copilotkit/shared@1.3.16-mme-improve-langsmith.0
|
|
12
22
|
|
|
13
23
|
## 1.3.15
|
|
14
24
|
|
|
@@ -9,16 +9,16 @@ import {
|
|
|
9
9
|
} from "./chunk-RQNJNK2W.mjs";
|
|
10
10
|
import {
|
|
11
11
|
CopilotChat
|
|
12
|
-
} from "./chunk-
|
|
13
|
-
import {
|
|
14
|
-
ResponseButton
|
|
15
|
-
} from "./chunk-3XAXY2Z3.mjs";
|
|
12
|
+
} from "./chunk-NLIDKNNS.mjs";
|
|
16
13
|
import {
|
|
17
14
|
Input
|
|
18
15
|
} from "./chunk-4LUMV4YO.mjs";
|
|
19
16
|
import {
|
|
20
17
|
Messages
|
|
21
18
|
} from "./chunk-CPMIEVKK.mjs";
|
|
19
|
+
import {
|
|
20
|
+
ResponseButton
|
|
21
|
+
} from "./chunk-3XAXY2Z3.mjs";
|
|
22
22
|
import {
|
|
23
23
|
ChatContextProvider
|
|
24
24
|
} from "./chunk-CBBFRI3Q.mjs";
|
|
@@ -88,4 +88,4 @@ var CopilotModal = ({
|
|
|
88
88
|
export {
|
|
89
89
|
CopilotModal
|
|
90
90
|
};
|
|
91
|
-
//# sourceMappingURL=chunk-
|
|
91
|
+
//# sourceMappingURL=chunk-3EYL2DRG.mjs.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CopilotModal
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-3EYL2DRG.mjs";
|
|
4
4
|
import {
|
|
5
5
|
__spreadProps,
|
|
6
6
|
__spreadValues
|
|
@@ -27,4 +27,4 @@ function CopilotSidebar(props) {
|
|
|
27
27
|
export {
|
|
28
28
|
CopilotSidebar
|
|
29
29
|
};
|
|
30
|
-
//# sourceMappingURL=chunk-
|
|
30
|
+
//# sourceMappingURL=chunk-3JNDMHS4.mjs.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CopilotModal
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-3EYL2DRG.mjs";
|
|
4
4
|
import {
|
|
5
5
|
__spreadProps,
|
|
6
6
|
__spreadValues
|
|
@@ -18,4 +18,4 @@ function CopilotPopup(props) {
|
|
|
18
18
|
export {
|
|
19
19
|
CopilotPopup
|
|
20
20
|
};
|
|
21
|
-
//# sourceMappingURL=chunk-
|
|
21
|
+
//# sourceMappingURL=chunk-AX7CAT7V.mjs.map
|
|
@@ -10,22 +10,22 @@ import {
|
|
|
10
10
|
import {
|
|
11
11
|
RenderTextMessage
|
|
12
12
|
} from "./chunk-RU73BEZM.mjs";
|
|
13
|
-
import {
|
|
14
|
-
ResponseButton
|
|
15
|
-
} from "./chunk-3XAXY2Z3.mjs";
|
|
16
13
|
import {
|
|
17
14
|
Suggestion,
|
|
18
15
|
reloadSuggestions
|
|
19
16
|
} from "./chunk-RJCZRKTV.mjs";
|
|
20
17
|
import {
|
|
21
18
|
CopilotDevConsole
|
|
22
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-RS6UPR5N.mjs";
|
|
23
20
|
import {
|
|
24
21
|
Input
|
|
25
22
|
} from "./chunk-4LUMV4YO.mjs";
|
|
26
23
|
import {
|
|
27
24
|
Messages
|
|
28
25
|
} from "./chunk-CPMIEVKK.mjs";
|
|
26
|
+
import {
|
|
27
|
+
ResponseButton
|
|
28
|
+
} from "./chunk-3XAXY2Z3.mjs";
|
|
29
29
|
import {
|
|
30
30
|
ChatContext,
|
|
31
31
|
ChatContextProvider
|
|
@@ -198,4 +198,4 @@ export {
|
|
|
198
198
|
WrappedCopilotChat,
|
|
199
199
|
useCopilotChatLogic
|
|
200
200
|
};
|
|
201
|
-
//# sourceMappingURL=chunk-
|
|
201
|
+
//# sourceMappingURL=chunk-NLIDKNNS.mjs.map
|
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
CheckIcon,
|
|
3
|
-
ChevronDownIcon,
|
|
4
|
-
CopilotKitIcon,
|
|
5
|
-
ExclamationMarkIcon,
|
|
6
|
-
ExclamationMarkTriangleIcon
|
|
7
|
-
} from "./chunk-OTPAZXVR.mjs";
|
|
8
1
|
import {
|
|
9
2
|
getPublishedCopilotKitVersion,
|
|
10
3
|
logActions,
|
|
@@ -12,6 +5,13 @@ import {
|
|
|
12
5
|
logReadables,
|
|
13
6
|
shouldShowDevConsole
|
|
14
7
|
} from "./chunk-4FIGRRFS.mjs";
|
|
8
|
+
import {
|
|
9
|
+
CheckIcon,
|
|
10
|
+
ChevronDownIcon,
|
|
11
|
+
CopilotKitIcon,
|
|
12
|
+
ExclamationMarkIcon,
|
|
13
|
+
ExclamationMarkTriangleIcon
|
|
14
|
+
} from "./chunk-OTPAZXVR.mjs";
|
|
15
15
|
import {
|
|
16
16
|
SmallSpinnerIcon
|
|
17
17
|
} from "./chunk-FZC7X5PK.mjs";
|
|
@@ -225,4 +225,4 @@ export {
|
|
|
225
225
|
CopilotDevConsole,
|
|
226
226
|
DebugMenuButton
|
|
227
227
|
};
|
|
228
|
-
//# sourceMappingURL=chunk-
|
|
228
|
+
//# sourceMappingURL=chunk-RS6UPR5N.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=chunk-T26KLXLH.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
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 * `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 * <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":";AA6DA,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":[]}
|
|
@@ -2,23 +2,23 @@ import {
|
|
|
2
2
|
CopilotChat,
|
|
3
3
|
WrappedCopilotChat,
|
|
4
4
|
useCopilotChatLogic
|
|
5
|
-
} from "../../chunk-
|
|
5
|
+
} from "../../chunk-NLIDKNNS.mjs";
|
|
6
6
|
import "../../chunk-V7W6IM2V.mjs";
|
|
7
7
|
import "../../chunk-OMTPWC7T.mjs";
|
|
8
8
|
import "../../chunk-ZABXREBH.mjs";
|
|
9
9
|
import "../../chunk-6INMITFA.mjs";
|
|
10
10
|
import "../../chunk-RU73BEZM.mjs";
|
|
11
|
-
import "../../chunk-3XAXY2Z3.mjs";
|
|
12
11
|
import "../../chunk-RJCZRKTV.mjs";
|
|
13
|
-
import "../../chunk-
|
|
14
|
-
import "../../chunk-OTPAZXVR.mjs";
|
|
12
|
+
import "../../chunk-RS6UPR5N.mjs";
|
|
15
13
|
import "../../chunk-4FIGRRFS.mjs";
|
|
14
|
+
import "../../chunk-OTPAZXVR.mjs";
|
|
16
15
|
import "../../chunk-4LUMV4YO.mjs";
|
|
17
16
|
import "../../chunk-YQFVRDNC.mjs";
|
|
18
17
|
import "../../chunk-YQ3D5IQV.mjs";
|
|
19
|
-
import "../../chunk-UPTB2MVO.mjs";
|
|
20
18
|
import "../../chunk-CPMIEVKK.mjs";
|
|
19
|
+
import "../../chunk-3XAXY2Z3.mjs";
|
|
21
20
|
import "../../chunk-CBBFRI3Q.mjs";
|
|
21
|
+
import "../../chunk-UPTB2MVO.mjs";
|
|
22
22
|
import "../../chunk-FZC7X5PK.mjs";
|
|
23
23
|
import "../../chunk-54JAUBUJ.mjs";
|
|
24
24
|
import "../../chunk-S5MBUNGN.mjs";
|
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CopilotModal
|
|
3
|
-
} from "../../chunk-
|
|
3
|
+
} from "../../chunk-3EYL2DRG.mjs";
|
|
4
4
|
import "../../chunk-YAGE7RCE.mjs";
|
|
5
5
|
import "../../chunk-VEC45H6Q.mjs";
|
|
6
6
|
import "../../chunk-RQNJNK2W.mjs";
|
|
7
|
-
import "../../chunk-
|
|
7
|
+
import "../../chunk-NLIDKNNS.mjs";
|
|
8
8
|
import "../../chunk-V7W6IM2V.mjs";
|
|
9
9
|
import "../../chunk-OMTPWC7T.mjs";
|
|
10
10
|
import "../../chunk-ZABXREBH.mjs";
|
|
11
11
|
import "../../chunk-6INMITFA.mjs";
|
|
12
12
|
import "../../chunk-RU73BEZM.mjs";
|
|
13
|
-
import "../../chunk-3XAXY2Z3.mjs";
|
|
14
13
|
import "../../chunk-RJCZRKTV.mjs";
|
|
15
|
-
import "../../chunk-
|
|
16
|
-
import "../../chunk-OTPAZXVR.mjs";
|
|
14
|
+
import "../../chunk-RS6UPR5N.mjs";
|
|
17
15
|
import "../../chunk-4FIGRRFS.mjs";
|
|
16
|
+
import "../../chunk-OTPAZXVR.mjs";
|
|
18
17
|
import "../../chunk-4LUMV4YO.mjs";
|
|
19
18
|
import "../../chunk-YQFVRDNC.mjs";
|
|
20
19
|
import "../../chunk-YQ3D5IQV.mjs";
|
|
21
|
-
import "../../chunk-UPTB2MVO.mjs";
|
|
22
20
|
import "../../chunk-CPMIEVKK.mjs";
|
|
21
|
+
import "../../chunk-3XAXY2Z3.mjs";
|
|
23
22
|
import "../../chunk-CBBFRI3Q.mjs";
|
|
23
|
+
import "../../chunk-UPTB2MVO.mjs";
|
|
24
24
|
import "../../chunk-FZC7X5PK.mjs";
|
|
25
25
|
import "../../chunk-54JAUBUJ.mjs";
|
|
26
26
|
import "../../chunk-S5MBUNGN.mjs";
|
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CopilotPopup
|
|
3
|
-
} from "../../chunk-
|
|
4
|
-
import "../../chunk-
|
|
3
|
+
} from "../../chunk-AX7CAT7V.mjs";
|
|
4
|
+
import "../../chunk-3EYL2DRG.mjs";
|
|
5
5
|
import "../../chunk-YAGE7RCE.mjs";
|
|
6
6
|
import "../../chunk-VEC45H6Q.mjs";
|
|
7
7
|
import "../../chunk-RQNJNK2W.mjs";
|
|
8
|
-
import "../../chunk-
|
|
8
|
+
import "../../chunk-NLIDKNNS.mjs";
|
|
9
9
|
import "../../chunk-V7W6IM2V.mjs";
|
|
10
10
|
import "../../chunk-OMTPWC7T.mjs";
|
|
11
11
|
import "../../chunk-ZABXREBH.mjs";
|
|
12
12
|
import "../../chunk-6INMITFA.mjs";
|
|
13
13
|
import "../../chunk-RU73BEZM.mjs";
|
|
14
|
-
import "../../chunk-3XAXY2Z3.mjs";
|
|
15
14
|
import "../../chunk-RJCZRKTV.mjs";
|
|
16
|
-
import "../../chunk-
|
|
17
|
-
import "../../chunk-OTPAZXVR.mjs";
|
|
15
|
+
import "../../chunk-RS6UPR5N.mjs";
|
|
18
16
|
import "../../chunk-4FIGRRFS.mjs";
|
|
17
|
+
import "../../chunk-OTPAZXVR.mjs";
|
|
19
18
|
import "../../chunk-4LUMV4YO.mjs";
|
|
20
19
|
import "../../chunk-YQFVRDNC.mjs";
|
|
21
20
|
import "../../chunk-YQ3D5IQV.mjs";
|
|
22
|
-
import "../../chunk-UPTB2MVO.mjs";
|
|
23
21
|
import "../../chunk-CPMIEVKK.mjs";
|
|
22
|
+
import "../../chunk-3XAXY2Z3.mjs";
|
|
24
23
|
import "../../chunk-CBBFRI3Q.mjs";
|
|
24
|
+
import "../../chunk-UPTB2MVO.mjs";
|
|
25
25
|
import "../../chunk-FZC7X5PK.mjs";
|
|
26
26
|
import "../../chunk-54JAUBUJ.mjs";
|
|
27
27
|
import "../../chunk-S5MBUNGN.mjs";
|
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CopilotSidebar
|
|
3
|
-
} from "../../chunk-
|
|
4
|
-
import "../../chunk-
|
|
3
|
+
} from "../../chunk-3JNDMHS4.mjs";
|
|
4
|
+
import "../../chunk-3EYL2DRG.mjs";
|
|
5
5
|
import "../../chunk-YAGE7RCE.mjs";
|
|
6
6
|
import "../../chunk-VEC45H6Q.mjs";
|
|
7
7
|
import "../../chunk-RQNJNK2W.mjs";
|
|
8
|
-
import "../../chunk-
|
|
8
|
+
import "../../chunk-NLIDKNNS.mjs";
|
|
9
9
|
import "../../chunk-V7W6IM2V.mjs";
|
|
10
10
|
import "../../chunk-OMTPWC7T.mjs";
|
|
11
11
|
import "../../chunk-ZABXREBH.mjs";
|
|
12
12
|
import "../../chunk-6INMITFA.mjs";
|
|
13
13
|
import "../../chunk-RU73BEZM.mjs";
|
|
14
|
-
import "../../chunk-3XAXY2Z3.mjs";
|
|
15
14
|
import "../../chunk-RJCZRKTV.mjs";
|
|
16
|
-
import "../../chunk-
|
|
17
|
-
import "../../chunk-OTPAZXVR.mjs";
|
|
15
|
+
import "../../chunk-RS6UPR5N.mjs";
|
|
18
16
|
import "../../chunk-4FIGRRFS.mjs";
|
|
17
|
+
import "../../chunk-OTPAZXVR.mjs";
|
|
19
18
|
import "../../chunk-4LUMV4YO.mjs";
|
|
20
19
|
import "../../chunk-YQFVRDNC.mjs";
|
|
21
20
|
import "../../chunk-YQ3D5IQV.mjs";
|
|
22
|
-
import "../../chunk-UPTB2MVO.mjs";
|
|
23
21
|
import "../../chunk-CPMIEVKK.mjs";
|
|
22
|
+
import "../../chunk-3XAXY2Z3.mjs";
|
|
24
23
|
import "../../chunk-CBBFRI3Q.mjs";
|
|
24
|
+
import "../../chunk-UPTB2MVO.mjs";
|
|
25
25
|
import "../../chunk-FZC7X5PK.mjs";
|
|
26
26
|
import "../../chunk-54JAUBUJ.mjs";
|
|
27
27
|
import "../../chunk-S5MBUNGN.mjs";
|
|
@@ -1,36 +1,36 @@
|
|
|
1
1
|
import "../../chunk-MRFF7GSQ.mjs";
|
|
2
2
|
import {
|
|
3
3
|
CopilotSidebar
|
|
4
|
-
} from "../../chunk-
|
|
4
|
+
} from "../../chunk-3JNDMHS4.mjs";
|
|
5
5
|
import "../../chunk-WB3YULQ4.mjs";
|
|
6
6
|
import {
|
|
7
7
|
CopilotPopup
|
|
8
|
-
} from "../../chunk-
|
|
9
|
-
import "../../chunk-
|
|
8
|
+
} from "../../chunk-AX7CAT7V.mjs";
|
|
9
|
+
import "../../chunk-3EYL2DRG.mjs";
|
|
10
10
|
import "../../chunk-YAGE7RCE.mjs";
|
|
11
11
|
import "../../chunk-VEC45H6Q.mjs";
|
|
12
12
|
import "../../chunk-RQNJNK2W.mjs";
|
|
13
13
|
import {
|
|
14
14
|
CopilotChat
|
|
15
|
-
} from "../../chunk-
|
|
15
|
+
} from "../../chunk-NLIDKNNS.mjs";
|
|
16
16
|
import "../../chunk-V7W6IM2V.mjs";
|
|
17
17
|
import "../../chunk-OMTPWC7T.mjs";
|
|
18
18
|
import "../../chunk-ZABXREBH.mjs";
|
|
19
19
|
import "../../chunk-6INMITFA.mjs";
|
|
20
20
|
import "../../chunk-RU73BEZM.mjs";
|
|
21
|
-
import "../../chunk-3XAXY2Z3.mjs";
|
|
22
21
|
import "../../chunk-RJCZRKTV.mjs";
|
|
23
|
-
import "../../chunk-
|
|
24
|
-
import "../../chunk-OTPAZXVR.mjs";
|
|
22
|
+
import "../../chunk-RS6UPR5N.mjs";
|
|
25
23
|
import "../../chunk-4FIGRRFS.mjs";
|
|
24
|
+
import "../../chunk-OTPAZXVR.mjs";
|
|
26
25
|
import "../../chunk-4LUMV4YO.mjs";
|
|
27
26
|
import "../../chunk-YQFVRDNC.mjs";
|
|
28
27
|
import "../../chunk-YQ3D5IQV.mjs";
|
|
29
|
-
import "../../chunk-UPTB2MVO.mjs";
|
|
30
28
|
import "../../chunk-CPMIEVKK.mjs";
|
|
29
|
+
import "../../chunk-3XAXY2Z3.mjs";
|
|
31
30
|
import {
|
|
32
31
|
useChatContext
|
|
33
32
|
} from "../../chunk-CBBFRI3Q.mjs";
|
|
33
|
+
import "../../chunk-UPTB2MVO.mjs";
|
|
34
34
|
import "../../chunk-FZC7X5PK.mjs";
|
|
35
35
|
import "../../chunk-54JAUBUJ.mjs";
|
|
36
36
|
import "../../chunk-S5MBUNGN.mjs";
|
|
@@ -2,8 +2,8 @@ import {
|
|
|
2
2
|
RenderTextMessage
|
|
3
3
|
} from "../../../chunk-RU73BEZM.mjs";
|
|
4
4
|
import "../../../chunk-YQ3D5IQV.mjs";
|
|
5
|
-
import "../../../chunk-UPTB2MVO.mjs";
|
|
6
5
|
import "../../../chunk-CBBFRI3Q.mjs";
|
|
6
|
+
import "../../../chunk-UPTB2MVO.mjs";
|
|
7
7
|
import "../../../chunk-FZC7X5PK.mjs";
|
|
8
8
|
import "../../../chunk-54JAUBUJ.mjs";
|
|
9
9
|
import "../../../chunk-MRXNTQOX.mjs";
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
import {
|
|
3
3
|
CopilotDevConsole,
|
|
4
4
|
DebugMenuButton
|
|
5
|
-
} from "../../chunk-
|
|
6
|
-
import "../../chunk-OTPAZXVR.mjs";
|
|
5
|
+
} from "../../chunk-RS6UPR5N.mjs";
|
|
7
6
|
import "../../chunk-4FIGRRFS.mjs";
|
|
7
|
+
import "../../chunk-OTPAZXVR.mjs";
|
|
8
8
|
import "../../chunk-FZC7X5PK.mjs";
|
|
9
9
|
import "../../chunk-MRXNTQOX.mjs";
|
|
10
10
|
export {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import "../../chunk-V7W6IM2V.mjs";
|
|
2
2
|
import {
|
|
3
3
|
CopilotDevConsole
|
|
4
|
-
} from "../../chunk-
|
|
5
|
-
import "../../chunk-OTPAZXVR.mjs";
|
|
4
|
+
} from "../../chunk-RS6UPR5N.mjs";
|
|
6
5
|
import {
|
|
7
6
|
shouldShowDevConsole
|
|
8
7
|
} from "../../chunk-4FIGRRFS.mjs";
|
|
8
|
+
import "../../chunk-OTPAZXVR.mjs";
|
|
9
9
|
import "../../chunk-FZC7X5PK.mjs";
|
|
10
10
|
import "../../chunk-MRXNTQOX.mjs";
|
|
11
11
|
export {
|
|
@@ -2,36 +2,36 @@ import "../chunk-JD7BAH7U.mjs";
|
|
|
2
2
|
import "../chunk-MRFF7GSQ.mjs";
|
|
3
3
|
import {
|
|
4
4
|
CopilotSidebar
|
|
5
|
-
} from "../chunk-
|
|
5
|
+
} from "../chunk-3JNDMHS4.mjs";
|
|
6
6
|
import "../chunk-WB3YULQ4.mjs";
|
|
7
7
|
import {
|
|
8
8
|
CopilotPopup
|
|
9
|
-
} from "../chunk-
|
|
10
|
-
import "../chunk-
|
|
9
|
+
} from "../chunk-AX7CAT7V.mjs";
|
|
10
|
+
import "../chunk-3EYL2DRG.mjs";
|
|
11
11
|
import "../chunk-YAGE7RCE.mjs";
|
|
12
12
|
import "../chunk-VEC45H6Q.mjs";
|
|
13
13
|
import "../chunk-RQNJNK2W.mjs";
|
|
14
14
|
import {
|
|
15
15
|
CopilotChat
|
|
16
|
-
} from "../chunk-
|
|
16
|
+
} from "../chunk-NLIDKNNS.mjs";
|
|
17
17
|
import "../chunk-V7W6IM2V.mjs";
|
|
18
18
|
import "../chunk-OMTPWC7T.mjs";
|
|
19
19
|
import "../chunk-ZABXREBH.mjs";
|
|
20
20
|
import "../chunk-6INMITFA.mjs";
|
|
21
21
|
import "../chunk-RU73BEZM.mjs";
|
|
22
|
-
import "../chunk-3XAXY2Z3.mjs";
|
|
23
22
|
import "../chunk-RJCZRKTV.mjs";
|
|
24
|
-
import "../chunk-
|
|
25
|
-
import "../chunk-OTPAZXVR.mjs";
|
|
23
|
+
import "../chunk-RS6UPR5N.mjs";
|
|
26
24
|
import "../chunk-4FIGRRFS.mjs";
|
|
25
|
+
import "../chunk-OTPAZXVR.mjs";
|
|
27
26
|
import "../chunk-4LUMV4YO.mjs";
|
|
28
27
|
import "../chunk-YQFVRDNC.mjs";
|
|
29
28
|
import "../chunk-YQ3D5IQV.mjs";
|
|
30
|
-
import "../chunk-UPTB2MVO.mjs";
|
|
31
29
|
import "../chunk-CPMIEVKK.mjs";
|
|
30
|
+
import "../chunk-3XAXY2Z3.mjs";
|
|
32
31
|
import {
|
|
33
32
|
useChatContext
|
|
34
33
|
} from "../chunk-CBBFRI3Q.mjs";
|
|
34
|
+
import "../chunk-UPTB2MVO.mjs";
|
|
35
35
|
import "../chunk-FZC7X5PK.mjs";
|
|
36
36
|
import "../chunk-54JAUBUJ.mjs";
|
|
37
37
|
import "../chunk-S5MBUNGN.mjs";
|
package/dist/hooks/index.d.ts
CHANGED
package/dist/hooks/index.js
CHANGED
|
@@ -1,25 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
|
-
var __defProps = Object.defineProperties;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
5
|
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
6
|
var __export = (target, all) => {
|
|
24
7
|
for (var name in all)
|
|
25
8
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -33,32 +16,11 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
33
16
|
return to;
|
|
34
17
|
};
|
|
35
18
|
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
19
|
|
|
57
20
|
// src/hooks/index.ts
|
|
58
21
|
var hooks_exports = {};
|
|
59
22
|
__export(hooks_exports, {
|
|
60
|
-
useCopilotChatSuggestions: () => useCopilotChatSuggestions
|
|
61
|
-
useCopilotSuggestions: () => useCopilotSuggestions
|
|
23
|
+
useCopilotChatSuggestions: () => useCopilotChatSuggestions
|
|
62
24
|
});
|
|
63
25
|
module.exports = __toCommonJS(hooks_exports);
|
|
64
26
|
|
|
@@ -86,103 +48,8 @@ function useCopilotChatSuggestions({
|
|
|
86
48
|
};
|
|
87
49
|
}, [...dependencies, instructions, minSuggestions, maxSuggestions, className]);
|
|
88
50
|
}
|
|
89
|
-
|
|
90
|
-
// src/hooks/use-copilot-suggestions.ts
|
|
91
|
-
var import_react2 = require("react");
|
|
92
|
-
var import_react_core2 = require("@copilotkit/react-core");
|
|
93
|
-
var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
|
|
94
|
-
function useCopilotSuggestions({
|
|
95
|
-
instructions,
|
|
96
|
-
parameters,
|
|
97
|
-
value,
|
|
98
|
-
enabled = true,
|
|
99
|
-
debounceTime = 1e3
|
|
100
|
-
}, dependencies = []) {
|
|
101
|
-
const suggestionsAbortControllerRef = (0, import_react2.useRef)(null);
|
|
102
|
-
const debounceTimerRef = (0, import_react2.useRef)();
|
|
103
|
-
const [suggestions, setSuggestions] = (0, import_react2.useState)({
|
|
104
|
-
suggestions: void 0,
|
|
105
|
-
isAvailable: false,
|
|
106
|
-
isLoading: false
|
|
107
|
-
});
|
|
108
|
-
const isFirstRunRef = (0, import_react2.useRef)(true);
|
|
109
|
-
const abortSuggestions = (0, import_react2.useCallback)(() => {
|
|
110
|
-
var _a;
|
|
111
|
-
(_a = suggestionsAbortControllerRef.current) == null ? void 0 : _a.abort();
|
|
112
|
-
suggestionsAbortControllerRef.current = null;
|
|
113
|
-
}, []);
|
|
114
|
-
const generalContext = (0, import_react_core2.useCopilotContext)();
|
|
115
|
-
const messagesContext = (0, import_react_core2.useCopilotMessagesContext)();
|
|
116
|
-
const context = __spreadValues(__spreadValues({}, generalContext), messagesContext);
|
|
117
|
-
(0, import_react2.useEffect)(() => {
|
|
118
|
-
abortSuggestions();
|
|
119
|
-
if (!enabled) {
|
|
120
|
-
setSuggestions({ suggestions: void 0, isAvailable: false, isLoading: false });
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
if (JSON.stringify(value) === JSON.stringify(suggestions.suggestions)) {
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
debounceTimerRef.current = setTimeout(
|
|
127
|
-
() => __async(this, null, function* () {
|
|
128
|
-
isFirstRunRef.current = false;
|
|
129
|
-
suggestionsAbortControllerRef.current = new AbortController();
|
|
130
|
-
setSuggestions(__spreadProps(__spreadValues({}, suggestions), { isLoading: true }));
|
|
131
|
-
yield reloadSuggestions(
|
|
132
|
-
context,
|
|
133
|
-
instructions,
|
|
134
|
-
parameters,
|
|
135
|
-
value,
|
|
136
|
-
suggestionsAbortControllerRef,
|
|
137
|
-
setSuggestions
|
|
138
|
-
);
|
|
139
|
-
}),
|
|
140
|
-
isFirstRunRef.current === true ? 0 : debounceTime
|
|
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
|
-
return suggestions;
|
|
154
|
-
}
|
|
155
|
-
function reloadSuggestions(context, instructions, parameters, value, abortControllerRef, setSuggestions) {
|
|
156
|
-
return __async(this, null, function* () {
|
|
157
|
-
const abortController = abortControllerRef.current;
|
|
158
|
-
let fullInstructions = `It's your task to generate suggestions based on the application context.`;
|
|
159
|
-
if (instructions) {
|
|
160
|
-
fullInstructions += `
|
|
161
|
-
|
|
162
|
-
In addition, follow these specific instructions: ${instructions}`;
|
|
163
|
-
}
|
|
164
|
-
if (value) {
|
|
165
|
-
fullInstructions += `
|
|
166
|
-
|
|
167
|
-
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.`;
|
|
168
|
-
}
|
|
169
|
-
yield (0, import_react_core2.extract)({
|
|
170
|
-
context,
|
|
171
|
-
instructions: fullInstructions,
|
|
172
|
-
parameters,
|
|
173
|
-
abortSignal: abortController == null ? void 0 : abortController.signal,
|
|
174
|
-
requestType: import_runtime_client_gql.CopilotRequestType.Task,
|
|
175
|
-
stream({ args, status }) {
|
|
176
|
-
if (status === "complete") {
|
|
177
|
-
setSuggestions({ suggestions: args, isAvailable: true, isLoading: false });
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
});
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
51
|
// Annotate the CommonJS export names for ESM import in node:
|
|
184
52
|
0 && (module.exports = {
|
|
185
|
-
useCopilotChatSuggestions
|
|
186
|
-
useCopilotSuggestions
|
|
53
|
+
useCopilotChatSuggestions
|
|
187
54
|
});
|
|
188
55
|
//# sourceMappingURL=index.js.map
|
package/dist/hooks/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/hooks/index.ts","../../src/hooks/use-copilot-chat-suggestions.tsx","../../src/hooks/use-copilot-suggestions.ts"],"sourcesContent":["export * from \"./use-copilot-chat-suggestions\";\nexport * from \"./use-copilot-suggestions\";\n","/**\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","/**\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: 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":"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","names":["import_react","import_react_core"]}
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/index.ts","../../src/hooks/use-copilot-chat-suggestions.tsx"],"sourcesContent":["export * from \"./use-copilot-chat-suggestions\";\n","/**\n * <Callout type=\"warning\">\n * useCopilotChatSuggestions is experimental. The interface is not final and\n * can change without notice.\n * </Callout>\n *\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 * <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":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;AC6DA,mBAA0B;AAC1B,wBAAkC;AAClC,oBAAyB;AAuBlB,SAAS,0BACd;AAAA,EACE;AAAA,EACA;AAAA,EACA,iBAAiB;AAAA,EACjB,iBAAiB;AACnB,GACA,eAAsB,CAAC,GACvB;AACA,QAAM,cAAU,qCAAkB;AAElC,8BAAU,MAAM;AACd,UAAM,SAAK,wBAAS;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":[]}
|