@copilotkit/react-core 1.50.0-beta.7 → 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.
- package/CHANGELOG.md +19 -2
- package/dist/{chunk-EKDPRKZT.mjs → chunk-3775VM7Y.mjs} +14 -26
- package/dist/chunk-3775VM7Y.mjs.map +1 -0
- package/dist/{chunk-BLDHD6Q2.mjs → chunk-7SHWECGN.mjs} +2 -2
- package/dist/{chunk-QSNZUI5G.mjs → chunk-B5ELMVT7.mjs} +2 -2
- package/dist/{chunk-WV57GREG.mjs → chunk-FYMZKPOL.mjs} +6 -6
- package/dist/chunk-XDFVCQD3.mjs +27 -0
- package/dist/chunk-XDFVCQD3.mjs.map +1 -0
- package/dist/{chunk-KYY2WZSR.mjs → chunk-YJGPIN3R.mjs} +2 -2
- package/dist/chunk-Z6JV2LRY.mjs +37 -0
- package/dist/chunk-Z6JV2LRY.mjs.map +1 -0
- package/dist/components/copilot-provider/copilotkit.mjs +7 -7
- package/dist/components/copilot-provider/index.mjs +7 -7
- package/dist/components/index.mjs +7 -7
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/index.js +146 -151
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +24 -24
- package/dist/hooks/use-copilot-chat-headless_c.js +39 -82
- package/dist/hooks/use-copilot-chat-headless_c.js.map +1 -1
- package/dist/hooks/use-copilot-chat-headless_c.mjs +3 -4
- package/dist/hooks/{use-configure-chat-suggestions.d.ts → use-copilot-chat-suggestions.d.ts} +2 -3
- package/dist/hooks/{use-configure-chat-suggestions.js → use-copilot-chat-suggestions.js} +10 -29
- package/dist/hooks/use-copilot-chat-suggestions.js.map +1 -0
- package/dist/hooks/use-copilot-chat-suggestions.mjs +8 -0
- package/dist/hooks/use-copilot-chat.js +37 -80
- package/dist/hooks/use-copilot-chat.js.map +1 -1
- package/dist/hooks/use-copilot-chat.mjs +3 -4
- package/dist/hooks/use-copilot-chat_internal.d.ts +17 -0
- package/dist/hooks/use-copilot-chat_internal.js +37 -80
- package/dist/hooks/use-copilot-chat_internal.js.map +1 -1
- package/dist/hooks/use-copilot-chat_internal.mjs +2 -3
- package/dist/hooks/use-copilot-readable.d.ts +1 -1
- package/dist/hooks/use-copilot-readable.js +29 -6
- package/dist/hooks/use-copilot-readable.js.map +1 -1
- package/dist/hooks/use-copilot-readable.mjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +139 -144
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +35 -35
- package/dist/lib/copilot-task.mjs +8 -8
- package/dist/lib/index.mjs +8 -8
- package/dist/types/index.mjs +1 -1
- package/dist/utils/index.mjs +3 -3
- package/package.json +5 -5
- package/src/hooks/index.ts +2 -2
- package/src/hooks/use-copilot-chat-suggestions.tsx +124 -0
- package/src/hooks/use-copilot-chat_internal.ts +29 -29
- package/src/hooks/use-copilot-readable.ts +30 -13
- package/dist/chunk-2CYJN455.mjs +0 -14
- package/dist/chunk-2CYJN455.mjs.map +0 -1
- package/dist/chunk-EKDPRKZT.mjs.map +0 -1
- package/dist/chunk-FBVI3LQ6.mjs +0 -48
- package/dist/chunk-FBVI3LQ6.mjs.map +0 -1
- package/dist/hooks/use-configure-chat-suggestions.js.map +0 -1
- package/dist/hooks/use-configure-chat-suggestions.mjs +0 -8
- package/src/hooks/use-configure-chat-suggestions.tsx +0 -86
- /package/dist/{chunk-BLDHD6Q2.mjs.map → chunk-7SHWECGN.mjs.map} +0 -0
- /package/dist/{chunk-QSNZUI5G.mjs.map → chunk-B5ELMVT7.mjs.map} +0 -0
- /package/dist/{chunk-WV57GREG.mjs.map → chunk-FYMZKPOL.mjs.map} +0 -0
- /package/dist/{chunk-KYY2WZSR.mjs.map → chunk-YJGPIN3R.mjs.map} +0 -0
- /package/dist/hooks/{use-configure-chat-suggestions.mjs.map → use-copilot-chat-suggestions.mjs.map} +0 -0
package/dist/index.mjs
CHANGED
|
@@ -1,22 +1,34 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import "./chunk-FD6FGKYY.mjs";
|
|
3
|
-
import "./chunk-6YOKPWQ7.mjs";
|
|
4
3
|
import "./chunk-36KQV2NA.mjs";
|
|
4
|
+
import "./chunk-6YOKPWQ7.mjs";
|
|
5
5
|
import "./chunk-LUGEI4YQ.mjs";
|
|
6
6
|
import {
|
|
7
7
|
CopilotTask
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-B5ELMVT7.mjs";
|
|
9
9
|
import "./chunk-4CEQJ2X6.mjs";
|
|
10
10
|
import "./chunk-A6NKSGH3.mjs";
|
|
11
|
-
import {
|
|
12
|
-
useDefaultTool
|
|
13
|
-
} from "./chunk-U2ZRVVKT.mjs";
|
|
14
11
|
import {
|
|
15
12
|
useLangGraphInterrupt
|
|
16
13
|
} from "./chunk-4RRMC7L2.mjs";
|
|
17
14
|
import {
|
|
18
15
|
useMakeCopilotDocumentReadable
|
|
19
16
|
} from "./chunk-7IBF6RBW.mjs";
|
|
17
|
+
import {
|
|
18
|
+
useCopilotReadable
|
|
19
|
+
} from "./chunk-Z6JV2LRY.mjs";
|
|
20
|
+
import {
|
|
21
|
+
useCopilotRuntimeClient
|
|
22
|
+
} from "./chunk-6ESSSQ7Q.mjs";
|
|
23
|
+
import {
|
|
24
|
+
useDefaultTool
|
|
25
|
+
} from "./chunk-U2ZRVVKT.mjs";
|
|
26
|
+
import {
|
|
27
|
+
useCoAgentStateRender
|
|
28
|
+
} from "./chunk-YTQHRJUA.mjs";
|
|
29
|
+
import {
|
|
30
|
+
useCoAgent
|
|
31
|
+
} from "./chunk-ZYTXB6HH.mjs";
|
|
20
32
|
import {
|
|
21
33
|
useCopilotAdditionalInstructions
|
|
22
34
|
} from "./chunk-ABWT4DRT.mjs";
|
|
@@ -37,56 +49,44 @@ import {
|
|
|
37
49
|
} from "./chunk-7DTB7S5V.mjs";
|
|
38
50
|
import {
|
|
39
51
|
useCopilotChatHeadless_c
|
|
40
|
-
} from "./chunk-
|
|
52
|
+
} from "./chunk-YJGPIN3R.mjs";
|
|
53
|
+
import {
|
|
54
|
+
useCopilotChatSuggestions
|
|
55
|
+
} from "./chunk-XDFVCQD3.mjs";
|
|
41
56
|
import {
|
|
42
57
|
useCopilotChat
|
|
43
|
-
} from "./chunk-
|
|
58
|
+
} from "./chunk-7SHWECGN.mjs";
|
|
44
59
|
import {
|
|
45
60
|
useCopilotChatInternal
|
|
46
|
-
} from "./chunk-
|
|
47
|
-
import {
|
|
48
|
-
useLangGraphInterruptRender
|
|
49
|
-
} from "./chunk-VV56AVPB.mjs";
|
|
61
|
+
} from "./chunk-3775VM7Y.mjs";
|
|
50
62
|
import {
|
|
51
63
|
useLazyToolRenderer
|
|
52
64
|
} from "./chunk-ZVF5Q6IH.mjs";
|
|
53
65
|
import {
|
|
54
|
-
|
|
55
|
-
} from "./chunk-
|
|
56
|
-
import {
|
|
57
|
-
useCopilotRuntimeClient
|
|
58
|
-
} from "./chunk-6ESSSQ7Q.mjs";
|
|
59
|
-
import {
|
|
60
|
-
useCoAgentStateRender
|
|
61
|
-
} from "./chunk-YTQHRJUA.mjs";
|
|
62
|
-
import {
|
|
63
|
-
useCoAgent
|
|
64
|
-
} from "./chunk-ZYTXB6HH.mjs";
|
|
66
|
+
useLangGraphInterruptRender
|
|
67
|
+
} from "./chunk-VV56AVPB.mjs";
|
|
65
68
|
import "./chunk-I76HKHPJ.mjs";
|
|
66
|
-
import {
|
|
67
|
-
useConfigureChatSuggestions
|
|
68
|
-
} from "./chunk-FBVI3LQ6.mjs";
|
|
69
69
|
import "./chunk-JD7BAH7U.mjs";
|
|
70
70
|
import "./chunk-SPCZTZCY.mjs";
|
|
71
71
|
import {
|
|
72
72
|
CopilotKit,
|
|
73
73
|
defaultCopilotContextCategories
|
|
74
|
-
} from "./chunk-
|
|
75
|
-
import "./chunk-
|
|
76
|
-
import
|
|
77
|
-
SUGGESTION_RETRY_CONFIG
|
|
78
|
-
} from "./chunk-2IDV5OHF.mjs";
|
|
74
|
+
} from "./chunk-FYMZKPOL.mjs";
|
|
75
|
+
import "./chunk-LHERIF3L.mjs";
|
|
76
|
+
import "./chunk-HE22TZMF.mjs";
|
|
79
77
|
import "./chunk-PMWUKW3Z.mjs";
|
|
80
78
|
import "./chunk-YCG6SNAU.mjs";
|
|
81
79
|
import "./chunk-PIF5KJYI.mjs";
|
|
82
|
-
import "./chunk-
|
|
83
|
-
import "./chunk-
|
|
80
|
+
import "./chunk-RKTVJRK7.mjs";
|
|
81
|
+
import "./chunk-CYDWEPFL.mjs";
|
|
84
82
|
import {
|
|
85
83
|
shouldShowDevConsole
|
|
86
84
|
} from "./chunk-ICIK2BSB.mjs";
|
|
87
|
-
import
|
|
88
|
-
|
|
85
|
+
import {
|
|
86
|
+
SUGGESTION_RETRY_CONFIG
|
|
87
|
+
} from "./chunk-2IDV5OHF.mjs";
|
|
89
88
|
import "./chunk-YYN33GSG.mjs";
|
|
89
|
+
import "./chunk-PMAFHQ7P.mjs";
|
|
90
90
|
import "./chunk-6PUNP7CD.mjs";
|
|
91
91
|
import "./chunk-O7ARI5CV.mjs";
|
|
92
92
|
import "./chunk-QNUAXSDP.mjs";
|
|
@@ -128,13 +128,13 @@ export {
|
|
|
128
128
|
useCoAgent,
|
|
129
129
|
useCoAgentStateRender,
|
|
130
130
|
useCoAgentStateRenders,
|
|
131
|
-
useConfigureChatSuggestions,
|
|
132
131
|
useCopilotAction,
|
|
133
132
|
useCopilotAdditionalInstructions,
|
|
134
133
|
useCopilotAuthenticatedAction_c,
|
|
135
134
|
useCopilotChat,
|
|
136
135
|
useCopilotChatHeadless_c,
|
|
137
136
|
useCopilotChatInternal,
|
|
137
|
+
useCopilotChatSuggestions,
|
|
138
138
|
useCopilotContext,
|
|
139
139
|
useCopilotMessagesContext,
|
|
140
140
|
useCopilotReadable,
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CopilotTask
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-B5ELMVT7.mjs";
|
|
4
4
|
import "../chunk-4CEQJ2X6.mjs";
|
|
5
5
|
import "../chunk-JD7BAH7U.mjs";
|
|
6
6
|
import "../chunk-SPCZTZCY.mjs";
|
|
7
|
-
import "../chunk-
|
|
8
|
-
import "../chunk-
|
|
9
|
-
import "../chunk-
|
|
7
|
+
import "../chunk-FYMZKPOL.mjs";
|
|
8
|
+
import "../chunk-LHERIF3L.mjs";
|
|
9
|
+
import "../chunk-HE22TZMF.mjs";
|
|
10
10
|
import "../chunk-PMWUKW3Z.mjs";
|
|
11
11
|
import "../chunk-YCG6SNAU.mjs";
|
|
12
12
|
import "../chunk-PIF5KJYI.mjs";
|
|
13
|
-
import "../chunk-LHERIF3L.mjs";
|
|
14
|
-
import "../chunk-HE22TZMF.mjs";
|
|
15
|
-
import "../chunk-ICIK2BSB.mjs";
|
|
16
13
|
import "../chunk-RKTVJRK7.mjs";
|
|
17
|
-
import "../chunk-
|
|
14
|
+
import "../chunk-CYDWEPFL.mjs";
|
|
15
|
+
import "../chunk-ICIK2BSB.mjs";
|
|
16
|
+
import "../chunk-2IDV5OHF.mjs";
|
|
18
17
|
import "../chunk-YYN33GSG.mjs";
|
|
18
|
+
import "../chunk-PMAFHQ7P.mjs";
|
|
19
19
|
import "../chunk-6PUNP7CD.mjs";
|
|
20
20
|
import "../chunk-O7ARI5CV.mjs";
|
|
21
21
|
import "../chunk-QNUAXSDP.mjs";
|
package/dist/lib/index.mjs
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import "../chunk-LUGEI4YQ.mjs";
|
|
2
2
|
import {
|
|
3
3
|
CopilotTask
|
|
4
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-B5ELMVT7.mjs";
|
|
5
5
|
import "../chunk-4CEQJ2X6.mjs";
|
|
6
6
|
import "../chunk-JD7BAH7U.mjs";
|
|
7
7
|
import "../chunk-SPCZTZCY.mjs";
|
|
8
|
-
import "../chunk-
|
|
9
|
-
import "../chunk-
|
|
10
|
-
import "../chunk-
|
|
8
|
+
import "../chunk-FYMZKPOL.mjs";
|
|
9
|
+
import "../chunk-LHERIF3L.mjs";
|
|
10
|
+
import "../chunk-HE22TZMF.mjs";
|
|
11
11
|
import "../chunk-PMWUKW3Z.mjs";
|
|
12
12
|
import "../chunk-YCG6SNAU.mjs";
|
|
13
13
|
import "../chunk-PIF5KJYI.mjs";
|
|
14
|
-
import "../chunk-LHERIF3L.mjs";
|
|
15
|
-
import "../chunk-HE22TZMF.mjs";
|
|
16
|
-
import "../chunk-ICIK2BSB.mjs";
|
|
17
14
|
import "../chunk-RKTVJRK7.mjs";
|
|
18
|
-
import "../chunk-
|
|
15
|
+
import "../chunk-CYDWEPFL.mjs";
|
|
16
|
+
import "../chunk-ICIK2BSB.mjs";
|
|
17
|
+
import "../chunk-2IDV5OHF.mjs";
|
|
19
18
|
import "../chunk-YYN33GSG.mjs";
|
|
19
|
+
import "../chunk-PMAFHQ7P.mjs";
|
|
20
20
|
import "../chunk-6PUNP7CD.mjs";
|
|
21
21
|
import "../chunk-O7ARI5CV.mjs";
|
|
22
22
|
import "../chunk-QNUAXSDP.mjs";
|
package/dist/types/index.mjs
CHANGED
package/dist/utils/index.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import "../chunk-CYDWEPFL.mjs";
|
|
2
|
-
import {
|
|
3
|
-
SUGGESTION_RETRY_CONFIG
|
|
4
|
-
} from "../chunk-2IDV5OHF.mjs";
|
|
5
2
|
import {
|
|
6
3
|
shouldShowDevConsole
|
|
7
4
|
} from "../chunk-ICIK2BSB.mjs";
|
|
5
|
+
import {
|
|
6
|
+
SUGGESTION_RETRY_CONFIG
|
|
7
|
+
} from "../chunk-2IDV5OHF.mjs";
|
|
8
8
|
import "../chunk-SKC7AJIV.mjs";
|
|
9
9
|
export {
|
|
10
10
|
SUGGESTION_RETRY_CONFIG,
|
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"publishConfig": {
|
|
10
10
|
"access": "public"
|
|
11
11
|
},
|
|
12
|
-
"version": "1.50.0-beta.
|
|
12
|
+
"version": "1.50.0-beta.9",
|
|
13
13
|
"sideEffects": [
|
|
14
14
|
"**/*.css"
|
|
15
15
|
],
|
|
@@ -56,13 +56,13 @@
|
|
|
56
56
|
"tsconfig": "1.4.6"
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
|
-
"@copilotkitnext/core": "0.0.
|
|
60
|
-
"@copilotkitnext/react": "0.0.
|
|
59
|
+
"@copilotkitnext/core": "0.0.28",
|
|
60
|
+
"@copilotkitnext/react": "0.0.28",
|
|
61
61
|
"@scarf/scarf": "^1.3.0",
|
|
62
62
|
"react-markdown": "^8.0.7",
|
|
63
63
|
"untruncate-json": "^0.0.1",
|
|
64
|
-
"@copilotkit/runtime-client-gql": "1.50.0-beta.
|
|
65
|
-
"@copilotkit/shared": "1.50.0-beta.
|
|
64
|
+
"@copilotkit/runtime-client-gql": "1.50.0-beta.9",
|
|
65
|
+
"@copilotkit/shared": "1.50.0-beta.9"
|
|
66
66
|
},
|
|
67
67
|
"keywords": [
|
|
68
68
|
"copilotkit",
|
package/src/hooks/index.ts
CHANGED
|
@@ -24,6 +24,6 @@ export { useRenderToolCall } from "./use-render-tool-call";
|
|
|
24
24
|
export { useDefaultTool } from "./use-default-tool";
|
|
25
25
|
export { useLazyToolRenderer } from "./use-lazy-tool-renderer";
|
|
26
26
|
export {
|
|
27
|
-
|
|
27
|
+
useCopilotChatSuggestions,
|
|
28
28
|
type UseCopilotChatSuggestionsConfiguration,
|
|
29
|
-
} from "./use-
|
|
29
|
+
} from "./use-copilot-chat-suggestions";
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* <Callout type="warning">
|
|
3
|
+
* useCopilotChatSuggestions is experimental. The interface is not final and
|
|
4
|
+
* can change without notice.
|
|
5
|
+
* </Callout>
|
|
6
|
+
*
|
|
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.
|
|
10
|
+
*
|
|
11
|
+
* <br/>
|
|
12
|
+
* <img src="https://cdn.copilotkit.ai/docs/copilotkit/images/use-copilot-chat-suggestions/use-copilot-chat-suggestions.gif" width="500" />
|
|
13
|
+
*
|
|
14
|
+
* ## Usage
|
|
15
|
+
*
|
|
16
|
+
* ### Install Dependencies
|
|
17
|
+
*
|
|
18
|
+
* This component is part of the [@copilotkit/react-ui](https://npmjs.com/package/@copilotkit/react-ui) package.
|
|
19
|
+
*
|
|
20
|
+
* ```shell npm2yarn \"@copilotkit/react-ui"\
|
|
21
|
+
* npm install @copilotkit/react-core @copilotkit/react-ui
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* ### Simple Usage
|
|
25
|
+
*
|
|
26
|
+
* ```tsx
|
|
27
|
+
* import { useCopilotChatSuggestions } from "@copilotkit/react-ui";
|
|
28
|
+
*
|
|
29
|
+
* export function MyComponent() {
|
|
30
|
+
* const [employees, setEmployees] = useState([]);
|
|
31
|
+
*
|
|
32
|
+
* useCopilotChatSuggestions({
|
|
33
|
+
* instructions: `The following employees are on duty: ${JSON.stringify(employees)}`,
|
|
34
|
+
* });
|
|
35
|
+
* }
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* ### Dependency Management
|
|
39
|
+
*
|
|
40
|
+
* ```tsx
|
|
41
|
+
* import { useCopilotChatSuggestions } from "@copilotkit/react-ui";
|
|
42
|
+
*
|
|
43
|
+
* export function MyComponent() {
|
|
44
|
+
* useCopilotChatSuggestions(
|
|
45
|
+
* {
|
|
46
|
+
* instructions: "Suggest the most relevant next actions.",
|
|
47
|
+
* },
|
|
48
|
+
* [appState],
|
|
49
|
+
* );
|
|
50
|
+
* }
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* In the example above, the suggestions are generated based on the given instructions.
|
|
54
|
+
* The hook monitors `appState`, and updates suggestions accordingly whenever it changes.
|
|
55
|
+
*
|
|
56
|
+
* ### Behavior and Lifecycle
|
|
57
|
+
*
|
|
58
|
+
* The hook registers the configuration with the chat context upon component mount and
|
|
59
|
+
* removes it on unmount, ensuring a clean and efficient lifecycle management.
|
|
60
|
+
*/
|
|
61
|
+
import {
|
|
62
|
+
useConfigureSuggestions,
|
|
63
|
+
useCopilotChatConfiguration,
|
|
64
|
+
useCopilotKit,
|
|
65
|
+
useSuggestions,
|
|
66
|
+
} from "@copilotkitnext/react";
|
|
67
|
+
import { useEffect } from "react";
|
|
68
|
+
import { StaticSuggestionsConfig, Suggestion } from "@copilotkitnext/core";
|
|
69
|
+
|
|
70
|
+
type StaticSuggestionInput = Omit<Suggestion, "isLoading"> & Partial<Pick<Suggestion, "isLoading">>;
|
|
71
|
+
|
|
72
|
+
type StaticSuggestionsConfigInput = Omit<StaticSuggestionsConfig, "suggestions"> & {
|
|
73
|
+
suggestions: StaticSuggestionInput[];
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
type DynamicSuggestionsConfigInput = {
|
|
77
|
+
/**
|
|
78
|
+
* A prompt or instructions for the GPT to generate suggestions.
|
|
79
|
+
*/
|
|
80
|
+
instructions: string;
|
|
81
|
+
/**
|
|
82
|
+
* The minimum number of suggestions to generate. Defaults to `1`.
|
|
83
|
+
* @default 1
|
|
84
|
+
*/
|
|
85
|
+
minSuggestions?: number;
|
|
86
|
+
/**
|
|
87
|
+
* The maximum number of suggestions to generate. Defaults to `3`.
|
|
88
|
+
* @default 1
|
|
89
|
+
*/
|
|
90
|
+
maxSuggestions?: number;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Whether the suggestions are available. Defaults to `enabled`.
|
|
94
|
+
* @default enabled
|
|
95
|
+
*/
|
|
96
|
+
available?: "enabled" | "disabled" | "always" | "before-first-message" | "after-first-message";
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* An optional class name to apply to the suggestions.
|
|
100
|
+
*/
|
|
101
|
+
className?: string;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
export type UseCopilotChatSuggestionsConfiguration =
|
|
105
|
+
| DynamicSuggestionsConfigInput
|
|
106
|
+
| StaticSuggestionsConfigInput;
|
|
107
|
+
|
|
108
|
+
export function useCopilotChatSuggestions(
|
|
109
|
+
config: UseCopilotChatSuggestionsConfiguration,
|
|
110
|
+
dependencies: any[] = [],
|
|
111
|
+
) {
|
|
112
|
+
const existingConfig = useCopilotChatConfiguration();
|
|
113
|
+
const resolvedAgentId = existingConfig?.agentId ?? "default";
|
|
114
|
+
|
|
115
|
+
const available =
|
|
116
|
+
(config.available === "enabled" ? "always" : config.available) ?? "before-first-message";
|
|
117
|
+
|
|
118
|
+
const finalSuggestionConfig = {
|
|
119
|
+
...config,
|
|
120
|
+
available,
|
|
121
|
+
consumerAgentId: resolvedAgentId, // Use chatConfig.agentId here
|
|
122
|
+
};
|
|
123
|
+
useConfigureSuggestions(finalSuggestionConfig, dependencies);
|
|
124
|
+
}
|
|
@@ -14,10 +14,6 @@ import {
|
|
|
14
14
|
} from "@copilotkitnext/react";
|
|
15
15
|
import { Suggestion } from "@copilotkitnext/core";
|
|
16
16
|
import { useLazyToolRenderer } from "./use-lazy-tool-renderer";
|
|
17
|
-
import {
|
|
18
|
-
useConfigureChatSuggestions,
|
|
19
|
-
UseCopilotChatSuggestionsConfiguration,
|
|
20
|
-
} from "./use-configure-chat-suggestions";
|
|
21
17
|
import { AbstractAgent, AGUIConnectNotImplementedError } from "@ag-ui/client";
|
|
22
18
|
import {
|
|
23
19
|
CoAgentStateRenderBridge,
|
|
@@ -71,7 +67,23 @@ export interface UseCopilotChatOptions {
|
|
|
71
67
|
* Disables inclusion of CopilotKit’s default system message. When true, no system message is sent (this also suppresses any custom message from <code>makeSystemMessage</code>).
|
|
72
68
|
*/
|
|
73
69
|
disableSystemMessage?: boolean;
|
|
74
|
-
|
|
70
|
+
/**
|
|
71
|
+
* Controls the behavior of suggestions in the chat interface.
|
|
72
|
+
*
|
|
73
|
+
* `auto` (default) - Suggestions are generated automatically:
|
|
74
|
+
* - When the chat is first opened (empty state)
|
|
75
|
+
* - After each message exchange completes
|
|
76
|
+
* - Uses configuration from `useCopilotChatSuggestions` hooks
|
|
77
|
+
*
|
|
78
|
+
* `manual` - Suggestions are controlled programmatically:
|
|
79
|
+
* - Use `setSuggestions()` to set custom suggestions
|
|
80
|
+
* - Use `generateSuggestions()` to trigger AI generation
|
|
81
|
+
* - Access via `useCopilotChat` hook
|
|
82
|
+
*
|
|
83
|
+
* `SuggestionItem[]` - Static suggestions array:
|
|
84
|
+
* - Always shows the same suggestions
|
|
85
|
+
* - No AI generation involved
|
|
86
|
+
*/
|
|
75
87
|
suggestions?: ChatSuggestions;
|
|
76
88
|
}
|
|
77
89
|
|
|
@@ -258,27 +270,6 @@ export interface UseCopilotChatReturn {
|
|
|
258
270
|
threadId?: string;
|
|
259
271
|
}
|
|
260
272
|
|
|
261
|
-
function useConfigureSuggestions(suggestions?: UseCopilotChatOptions["suggestions"]) {
|
|
262
|
-
let suggestionsConfig: UseCopilotChatSuggestionsConfiguration;
|
|
263
|
-
|
|
264
|
-
if (Array.isArray(suggestions)) {
|
|
265
|
-
suggestionsConfig = {
|
|
266
|
-
suggestions,
|
|
267
|
-
available: "always",
|
|
268
|
-
};
|
|
269
|
-
} else if (suggestions === "auto") {
|
|
270
|
-
suggestionsConfig = {
|
|
271
|
-
available: suggestions === "auto" ? "always" : "disabled",
|
|
272
|
-
instructions:
|
|
273
|
-
"Suggest what the user could say next. Provide clear, highly relevant suggestions. Do not literally suggest function calls.",
|
|
274
|
-
};
|
|
275
|
-
} else {
|
|
276
|
-
suggestionsConfig = { available: "disabled" } as UseCopilotChatSuggestionsConfiguration;
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
useConfigureChatSuggestions(suggestionsConfig);
|
|
280
|
-
}
|
|
281
|
-
|
|
282
273
|
export function useCopilotChatInternal({
|
|
283
274
|
suggestions,
|
|
284
275
|
}: UseCopilotChatOptions = {}): UseCopilotChatReturn {
|
|
@@ -286,7 +277,6 @@ export function useCopilotChatInternal({
|
|
|
286
277
|
const { threadId, agentSession } = useCopilotContext();
|
|
287
278
|
const existingConfig = useCopilotChatConfiguration();
|
|
288
279
|
const [agentAvailable, setAgentAvailable] = useState(false);
|
|
289
|
-
useConfigureSuggestions(suggestions);
|
|
290
280
|
|
|
291
281
|
// Apply priority: props > existing config > defaults
|
|
292
282
|
const resolvedAgentId = existingConfig?.agentId ?? "default";
|
|
@@ -523,6 +513,16 @@ export function useCopilotChatInternal({
|
|
|
523
513
|
resolvedAgentId,
|
|
524
514
|
]);
|
|
525
515
|
|
|
516
|
+
const renderedSuggestions = useMemo(() => {
|
|
517
|
+
if (Array.isArray(suggestions)) {
|
|
518
|
+
return {
|
|
519
|
+
suggestions: suggestions.map((s) => ({ ...s, isLoading: false })),
|
|
520
|
+
isLoading: false,
|
|
521
|
+
};
|
|
522
|
+
}
|
|
523
|
+
return currentSuggestions;
|
|
524
|
+
}, [suggestions, currentSuggestions]);
|
|
525
|
+
|
|
526
526
|
// @ts-ignore
|
|
527
527
|
return {
|
|
528
528
|
messages: resolvedMessages,
|
|
@@ -537,12 +537,12 @@ export function useCopilotChatInternal({
|
|
|
537
537
|
isLoading: Boolean(agent?.isRunning),
|
|
538
538
|
// mcpServers,
|
|
539
539
|
// setMcpServers,
|
|
540
|
-
suggestions:
|
|
540
|
+
suggestions: renderedSuggestions.suggestions,
|
|
541
541
|
setSuggestions: (suggestions: Omit<Suggestion, "isLoading">[]) =>
|
|
542
542
|
copilotkit.addSuggestionsConfig({ suggestions }),
|
|
543
543
|
generateSuggestions: async () => copilotkit.reloadSuggestions(resolvedAgentId),
|
|
544
544
|
resetSuggestions: () => copilotkit.clearSuggestions(resolvedAgentId),
|
|
545
|
-
isLoadingSuggestions:
|
|
545
|
+
isLoadingSuggestions: renderedSuggestions.isLoading,
|
|
546
546
|
interrupt,
|
|
547
547
|
agent,
|
|
548
548
|
threadId,
|
|
@@ -61,9 +61,8 @@
|
|
|
61
61
|
* }
|
|
62
62
|
* ```
|
|
63
63
|
*/
|
|
64
|
+
import { useCopilotKit } from "@copilotkitnext/react";
|
|
64
65
|
import { useEffect, useRef } from "react";
|
|
65
|
-
import { useCopilotContext } from "../context/copilot-context";
|
|
66
|
-
import { useAgentContext } from "@copilotkitnext/react";
|
|
67
66
|
|
|
68
67
|
/**
|
|
69
68
|
* Options for the useCopilotReadable hook.
|
|
@@ -99,20 +98,38 @@ export interface UseCopilotReadableOptions {
|
|
|
99
98
|
convert?: (description: string, value: any) => string;
|
|
100
99
|
}
|
|
101
100
|
|
|
102
|
-
function convertToJSON(description: string, value: any): string {
|
|
103
|
-
return `${description}: ${typeof value === "string" ? value : JSON.stringify(value)}`;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
101
|
/**
|
|
107
102
|
* Adds the given information to the Copilot context to make it readable by Copilot.
|
|
108
103
|
*/
|
|
109
104
|
export function useCopilotReadable(
|
|
110
|
-
{ description, value }: UseCopilotReadableOptions,
|
|
105
|
+
{ description, value, convert, available }: UseCopilotReadableOptions,
|
|
111
106
|
dependencies?: any[],
|
|
112
|
-
): undefined {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
107
|
+
): string | undefined {
|
|
108
|
+
const { copilotkit } = useCopilotKit();
|
|
109
|
+
const ctxIdRef = useRef<string | undefined>(undefined);
|
|
110
|
+
useEffect(() => {
|
|
111
|
+
if (!copilotkit) return;
|
|
112
|
+
|
|
113
|
+
const found = Object.entries(copilotkit.context).find(([id, ctxItem]) => {
|
|
114
|
+
return JSON.stringify({ description, value }) == JSON.stringify(ctxItem);
|
|
115
|
+
});
|
|
116
|
+
if (found) {
|
|
117
|
+
ctxIdRef.current = found[0];
|
|
118
|
+
if (available === "disabled") copilotkit.removeContext(ctxIdRef.current);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
if (!found && available === "disabled") return;
|
|
122
|
+
|
|
123
|
+
ctxIdRef.current = copilotkit.addContext({
|
|
124
|
+
description,
|
|
125
|
+
value: (convert ?? JSON.stringify)(value),
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
return () => {
|
|
129
|
+
if (!ctxIdRef.current) return;
|
|
130
|
+
copilotkit.removeContext(ctxIdRef.current);
|
|
131
|
+
};
|
|
132
|
+
}, [description, value, convert]);
|
|
133
|
+
|
|
134
|
+
return ctxIdRef.current;
|
|
118
135
|
}
|
package/dist/chunk-2CYJN455.mjs
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
// src/hooks/use-copilot-readable.ts
|
|
2
|
-
import { useAgentContext } from "@copilotkitnext/react";
|
|
3
|
-
function useCopilotReadable({ description, value }, dependencies) {
|
|
4
|
-
useAgentContext({
|
|
5
|
-
description,
|
|
6
|
-
value
|
|
7
|
-
});
|
|
8
|
-
return;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export {
|
|
12
|
-
useCopilotReadable
|
|
13
|
-
};
|
|
14
|
-
//# sourceMappingURL=chunk-2CYJN455.mjs.map
|
|
@@ -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 { useEffect, useRef } from \"react\";\nimport { useCopilotContext } from \"../context/copilot-context\";\nimport { useAgentContext } from \"@copilotkitnext/react\";\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: any;\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?: (description: string, value: any) => string;\n}\n\nfunction convertToJSON(description: string, value: any): string {\n return `${description}: ${typeof value === \"string\" ? value : JSON.stringify(value)}`;\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 }: UseCopilotReadableOptions,\n dependencies?: any[],\n): undefined {\n useAgentContext({\n description,\n value,\n });\n return;\n}\n"],"mappings":";AAiEA,SAAS,uBAAuB;AA2CzB,SAAS,mBACd,EAAE,aAAa,MAAM,GACrB,cACW;AACX,kBAAgB;AAAA,IACd;AAAA,IACA;AAAA,EACF,CAAC;AACD;AACF;","names":[]}
|