@copilotkit/react-core 1.50.1-next.0 → 1.50.1-next.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.
- package/CHANGELOG.md +16 -0
- package/dist/{chunk-BTZ3TJVX.mjs → chunk-4RRMC7L2.mjs} +4 -4
- package/dist/{chunk-JZN7YOPM.mjs → chunk-4YZA2BZC.mjs} +13 -13
- package/dist/{chunk-ZE4JVTEP.mjs → chunk-53K6WNJG.mjs} +2 -2
- package/dist/{chunk-U2ZRVVKT.mjs → chunk-BUSWSDYO.mjs} +2 -2
- package/dist/{chunk-T2VBHAAP.mjs → chunk-CDUIA2WM.mjs} +11 -3
- package/dist/chunk-CDUIA2WM.mjs.map +1 -0
- package/dist/{chunk-4HRUQH6U.mjs → chunk-E7SE25ZU.mjs} +2 -2
- package/dist/{chunk-5J7RRLRO.mjs → chunk-FQFXYAV7.mjs} +2 -2
- package/dist/{chunk-EG56H77V.mjs → chunk-GPEJNVE5.mjs} +2 -2
- package/dist/{chunk-7HI6VLJJ.mjs → chunk-HE22TZMF.mjs} +4 -4
- package/dist/{chunk-FESRCHUE.mjs → chunk-LCZZ7YGZ.mjs} +2 -2
- package/dist/{chunk-SNON4QA6.mjs → chunk-LHERIF3L.mjs} +4 -4
- package/dist/{chunk-LDEWO5XH.mjs → chunk-LSHFN2Y5.mjs} +28 -7
- package/dist/chunk-LSHFN2Y5.mjs.map +1 -0
- package/dist/{chunk-IUNU4CUG.mjs → chunk-YTQHRJUA.mjs} +4 -4
- package/dist/components/copilot-provider/copilot-messages.mjs +2 -2
- package/dist/components/copilot-provider/copilotkit.mjs +7 -7
- package/dist/components/copilot-provider/index.mjs +7 -7
- package/dist/components/error-boundary/error-boundary.mjs +2 -2
- package/dist/components/index.mjs +7 -7
- package/dist/context/index.mjs +5 -5
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/index.js +36 -7
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +14 -14
- package/dist/hooks/use-coagent-state-render-bridge.mjs +1 -1
- package/dist/hooks/use-coagent-state-render.mjs +2 -2
- package/dist/hooks/use-copilot-action.js +9 -1
- package/dist/hooks/use-copilot-action.js.map +1 -1
- package/dist/hooks/use-copilot-action.mjs +2 -2
- package/dist/hooks/use-copilot-authenticated-action.js +9 -1
- package/dist/hooks/use-copilot-authenticated-action.js.map +1 -1
- package/dist/hooks/use-copilot-authenticated-action.mjs +3 -3
- package/dist/hooks/use-copilot-chat-headless_c.js +27 -6
- package/dist/hooks/use-copilot-chat-headless_c.js.map +1 -1
- package/dist/hooks/use-copilot-chat-headless_c.mjs +5 -5
- package/dist/hooks/use-copilot-chat.js +27 -6
- package/dist/hooks/use-copilot-chat.js.map +1 -1
- package/dist/hooks/use-copilot-chat.mjs +5 -5
- package/dist/hooks/use-copilot-chat_internal.d.ts +24 -2
- package/dist/hooks/use-copilot-chat_internal.js +27 -6
- package/dist/hooks/use-copilot-chat_internal.js.map +1 -1
- package/dist/hooks/use-copilot-chat_internal.mjs +4 -4
- package/dist/hooks/use-default-tool.js +9 -1
- package/dist/hooks/use-default-tool.js.map +1 -1
- package/dist/hooks/use-default-tool.mjs +3 -3
- package/dist/hooks/use-frontend-tool.js +9 -1
- package/dist/hooks/use-frontend-tool.js.map +1 -1
- package/dist/hooks/use-frontend-tool.mjs +1 -1
- package/dist/hooks/use-langgraph-interrupt-render.mjs +1 -1
- package/dist/hooks/use-langgraph-interrupt.mjs +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +36 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +39 -39
- package/dist/lib/copilot-task.mjs +8 -8
- package/dist/lib/index.mjs +8 -8
- package/package.json +3 -3
- package/src/hooks/index.ts +6 -1
- package/src/hooks/use-copilot-chat_internal.ts +59 -3
- package/src/hooks/use-frontend-tool.ts +13 -2
- package/dist/chunk-LDEWO5XH.mjs.map +0 -1
- package/dist/chunk-T2VBHAAP.mjs.map +0 -1
- /package/dist/{chunk-BTZ3TJVX.mjs.map → chunk-4RRMC7L2.mjs.map} +0 -0
- /package/dist/{chunk-JZN7YOPM.mjs.map → chunk-4YZA2BZC.mjs.map} +0 -0
- /package/dist/{chunk-ZE4JVTEP.mjs.map → chunk-53K6WNJG.mjs.map} +0 -0
- /package/dist/{chunk-U2ZRVVKT.mjs.map → chunk-BUSWSDYO.mjs.map} +0 -0
- /package/dist/{chunk-4HRUQH6U.mjs.map → chunk-E7SE25ZU.mjs.map} +0 -0
- /package/dist/{chunk-5J7RRLRO.mjs.map → chunk-FQFXYAV7.mjs.map} +0 -0
- /package/dist/{chunk-EG56H77V.mjs.map → chunk-GPEJNVE5.mjs.map} +0 -0
- /package/dist/{chunk-7HI6VLJJ.mjs.map → chunk-HE22TZMF.mjs.map} +0 -0
- /package/dist/{chunk-FESRCHUE.mjs.map → chunk-LCZZ7YGZ.mjs.map} +0 -0
- /package/dist/{chunk-SNON4QA6.mjs.map → chunk-LHERIF3L.mjs.map} +0 -0
- /package/dist/{chunk-IUNU4CUG.mjs.map → chunk-YTQHRJUA.mjs.map} +0 -0
package/dist/index.mjs
CHANGED
|
@@ -5,34 +5,15 @@ import "./chunk-36KQV2NA.mjs";
|
|
|
5
5
|
import "./chunk-LUGEI4YQ.mjs";
|
|
6
6
|
import {
|
|
7
7
|
CopilotTask
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-LCZZ7YGZ.mjs";
|
|
9
9
|
import "./chunk-4CEQJ2X6.mjs";
|
|
10
|
-
import "./chunk-JD7BAH7U.mjs";
|
|
11
|
-
import "./chunk-SPCZTZCY.mjs";
|
|
12
|
-
import {
|
|
13
|
-
CopilotKit,
|
|
14
|
-
defaultCopilotContextCategories
|
|
15
|
-
} from "./chunk-JZN7YOPM.mjs";
|
|
16
|
-
import "./chunk-SNON4QA6.mjs";
|
|
17
|
-
import "./chunk-7HI6VLJJ.mjs";
|
|
18
|
-
import "./chunk-CYDWEPFL.mjs";
|
|
19
|
-
import {
|
|
20
|
-
SUGGESTION_RETRY_CONFIG
|
|
21
|
-
} from "./chunk-2IDV5OHF.mjs";
|
|
22
|
-
import {
|
|
23
|
-
shouldShowDevConsole
|
|
24
|
-
} from "./chunk-ICIK2BSB.mjs";
|
|
25
|
-
import "./chunk-RKTVJRK7.mjs";
|
|
26
|
-
import "./chunk-PMAFHQ7P.mjs";
|
|
27
|
-
import "./chunk-YYN33GSG.mjs";
|
|
28
|
-
import "./chunk-6ZLPNY7X.mjs";
|
|
29
10
|
import "./chunk-A6NKSGH3.mjs";
|
|
30
11
|
import {
|
|
31
12
|
useDefaultTool
|
|
32
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-BUSWSDYO.mjs";
|
|
33
14
|
import {
|
|
34
15
|
useLangGraphInterrupt
|
|
35
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-4RRMC7L2.mjs";
|
|
36
17
|
import {
|
|
37
18
|
useMakeCopilotDocumentReadable
|
|
38
19
|
} from "./chunk-7IBF6RBW.mjs";
|
|
@@ -41,19 +22,19 @@ import {
|
|
|
41
22
|
} from "./chunk-ABWT4DRT.mjs";
|
|
42
23
|
import {
|
|
43
24
|
useCopilotAuthenticatedAction_c
|
|
44
|
-
} from "./chunk-
|
|
25
|
+
} from "./chunk-E7SE25ZU.mjs";
|
|
45
26
|
import {
|
|
46
27
|
useCopilotChatHeadless_c
|
|
47
|
-
} from "./chunk-
|
|
28
|
+
} from "./chunk-FQFXYAV7.mjs";
|
|
48
29
|
import {
|
|
49
30
|
useCopilotChatSuggestions
|
|
50
31
|
} from "./chunk-XDFVCQD3.mjs";
|
|
51
32
|
import {
|
|
52
33
|
useCopilotChat
|
|
53
|
-
} from "./chunk-
|
|
34
|
+
} from "./chunk-53K6WNJG.mjs";
|
|
54
35
|
import {
|
|
55
36
|
useCopilotChatInternal
|
|
56
|
-
} from "./chunk-
|
|
37
|
+
} from "./chunk-LSHFN2Y5.mjs";
|
|
57
38
|
import {
|
|
58
39
|
useLangGraphInterruptRender
|
|
59
40
|
} from "./chunk-VV56AVPB.mjs";
|
|
@@ -66,29 +47,55 @@ import {
|
|
|
66
47
|
import {
|
|
67
48
|
useCopilotRuntimeClient
|
|
68
49
|
} from "./chunk-6ESSSQ7Q.mjs";
|
|
69
|
-
import "./chunk-6PUNP7CD.mjs";
|
|
70
|
-
import "./chunk-O7ARI5CV.mjs";
|
|
71
|
-
import "./chunk-QNUAXSDP.mjs";
|
|
72
50
|
import {
|
|
73
51
|
useCoAgentStateRender
|
|
74
|
-
} from "./chunk-
|
|
52
|
+
} from "./chunk-YTQHRJUA.mjs";
|
|
75
53
|
import {
|
|
76
54
|
useCoAgent
|
|
77
55
|
} from "./chunk-ZYTXB6HH.mjs";
|
|
78
56
|
import "./chunk-I76HKHPJ.mjs";
|
|
79
57
|
import {
|
|
80
58
|
useCopilotAction
|
|
81
|
-
} from "./chunk-
|
|
59
|
+
} from "./chunk-GPEJNVE5.mjs";
|
|
82
60
|
import {
|
|
83
61
|
useRenderToolCall
|
|
84
62
|
} from "./chunk-NBK4KBLX.mjs";
|
|
85
63
|
import {
|
|
86
64
|
useFrontendTool
|
|
87
|
-
} from "./chunk-
|
|
65
|
+
} from "./chunk-CDUIA2WM.mjs";
|
|
88
66
|
import {
|
|
89
67
|
useHumanInTheLoop
|
|
90
68
|
} from "./chunk-7DTB7S5V.mjs";
|
|
69
|
+
import "./chunk-JD7BAH7U.mjs";
|
|
70
|
+
import "./chunk-SPCZTZCY.mjs";
|
|
71
|
+
import {
|
|
72
|
+
CopilotKit,
|
|
73
|
+
defaultCopilotContextCategories
|
|
74
|
+
} from "./chunk-4YZA2BZC.mjs";
|
|
75
|
+
import "./chunk-LHERIF3L.mjs";
|
|
76
|
+
import "./chunk-HE22TZMF.mjs";
|
|
77
|
+
import "./chunk-CYDWEPFL.mjs";
|
|
78
|
+
import {
|
|
79
|
+
SUGGESTION_RETRY_CONFIG
|
|
80
|
+
} from "./chunk-2IDV5OHF.mjs";
|
|
81
|
+
import {
|
|
82
|
+
shouldShowDevConsole
|
|
83
|
+
} from "./chunk-ICIK2BSB.mjs";
|
|
84
|
+
import "./chunk-RKTVJRK7.mjs";
|
|
85
|
+
import "./chunk-PMAFHQ7P.mjs";
|
|
86
|
+
import "./chunk-YYN33GSG.mjs";
|
|
87
|
+
import "./chunk-6PUNP7CD.mjs";
|
|
88
|
+
import "./chunk-O7ARI5CV.mjs";
|
|
89
|
+
import "./chunk-QNUAXSDP.mjs";
|
|
91
90
|
import "./chunk-NB2FKV2V.mjs";
|
|
91
|
+
import {
|
|
92
|
+
ThreadsContext,
|
|
93
|
+
ThreadsProvider,
|
|
94
|
+
useThreads
|
|
95
|
+
} from "./chunk-F555TVE4.mjs";
|
|
96
|
+
import "./chunk-WF65O6HX.mjs";
|
|
97
|
+
import "./chunk-EFL5OBKN.mjs";
|
|
98
|
+
import "./chunk-6ZLPNY7X.mjs";
|
|
92
99
|
import {
|
|
93
100
|
CoAgentStateRendersContext,
|
|
94
101
|
CoAgentStateRendersProvider,
|
|
@@ -102,13 +109,6 @@ import {
|
|
|
102
109
|
CopilotMessagesContext,
|
|
103
110
|
useCopilotMessagesContext
|
|
104
111
|
} from "./chunk-DMLQZG75.mjs";
|
|
105
|
-
import {
|
|
106
|
-
ThreadsContext,
|
|
107
|
-
ThreadsProvider,
|
|
108
|
-
useThreads
|
|
109
|
-
} from "./chunk-F555TVE4.mjs";
|
|
110
|
-
import "./chunk-WF65O6HX.mjs";
|
|
111
|
-
import "./chunk-EFL5OBKN.mjs";
|
|
112
112
|
import "./chunk-SKC7AJIV.mjs";
|
|
113
113
|
export {
|
|
114
114
|
CoAgentStateRendersContext,
|
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CopilotTask
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-LCZZ7YGZ.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-4YZA2BZC.mjs";
|
|
8
|
+
import "../chunk-LHERIF3L.mjs";
|
|
9
|
+
import "../chunk-HE22TZMF.mjs";
|
|
10
10
|
import "../chunk-CYDWEPFL.mjs";
|
|
11
11
|
import "../chunk-2IDV5OHF.mjs";
|
|
12
12
|
import "../chunk-ICIK2BSB.mjs";
|
|
13
13
|
import "../chunk-RKTVJRK7.mjs";
|
|
14
14
|
import "../chunk-PMAFHQ7P.mjs";
|
|
15
15
|
import "../chunk-YYN33GSG.mjs";
|
|
16
|
-
import "../chunk-6ZLPNY7X.mjs";
|
|
17
16
|
import "../chunk-6PUNP7CD.mjs";
|
|
18
17
|
import "../chunk-O7ARI5CV.mjs";
|
|
19
18
|
import "../chunk-QNUAXSDP.mjs";
|
|
20
19
|
import "../chunk-NB2FKV2V.mjs";
|
|
21
|
-
import "../chunk-FDOMAPJY.mjs";
|
|
22
|
-
import "../chunk-AFNWX62Q.mjs";
|
|
23
|
-
import "../chunk-DMLQZG75.mjs";
|
|
24
20
|
import "../chunk-F555TVE4.mjs";
|
|
25
21
|
import "../chunk-WF65O6HX.mjs";
|
|
26
22
|
import "../chunk-EFL5OBKN.mjs";
|
|
23
|
+
import "../chunk-6ZLPNY7X.mjs";
|
|
24
|
+
import "../chunk-FDOMAPJY.mjs";
|
|
25
|
+
import "../chunk-AFNWX62Q.mjs";
|
|
26
|
+
import "../chunk-DMLQZG75.mjs";
|
|
27
27
|
import "../chunk-SKC7AJIV.mjs";
|
|
28
28
|
export {
|
|
29
29
|
CopilotTask
|
package/dist/lib/index.mjs
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
import "../chunk-LUGEI4YQ.mjs";
|
|
2
2
|
import {
|
|
3
3
|
CopilotTask
|
|
4
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-LCZZ7YGZ.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-4YZA2BZC.mjs";
|
|
9
|
+
import "../chunk-LHERIF3L.mjs";
|
|
10
|
+
import "../chunk-HE22TZMF.mjs";
|
|
11
11
|
import "../chunk-CYDWEPFL.mjs";
|
|
12
12
|
import "../chunk-2IDV5OHF.mjs";
|
|
13
13
|
import "../chunk-ICIK2BSB.mjs";
|
|
14
14
|
import "../chunk-RKTVJRK7.mjs";
|
|
15
15
|
import "../chunk-PMAFHQ7P.mjs";
|
|
16
16
|
import "../chunk-YYN33GSG.mjs";
|
|
17
|
-
import "../chunk-6ZLPNY7X.mjs";
|
|
18
17
|
import "../chunk-6PUNP7CD.mjs";
|
|
19
18
|
import "../chunk-O7ARI5CV.mjs";
|
|
20
19
|
import "../chunk-QNUAXSDP.mjs";
|
|
21
20
|
import "../chunk-NB2FKV2V.mjs";
|
|
22
|
-
import "../chunk-FDOMAPJY.mjs";
|
|
23
|
-
import "../chunk-AFNWX62Q.mjs";
|
|
24
|
-
import "../chunk-DMLQZG75.mjs";
|
|
25
21
|
import "../chunk-F555TVE4.mjs";
|
|
26
22
|
import "../chunk-WF65O6HX.mjs";
|
|
27
23
|
import "../chunk-EFL5OBKN.mjs";
|
|
24
|
+
import "../chunk-6ZLPNY7X.mjs";
|
|
25
|
+
import "../chunk-FDOMAPJY.mjs";
|
|
26
|
+
import "../chunk-AFNWX62Q.mjs";
|
|
27
|
+
import "../chunk-DMLQZG75.mjs";
|
|
28
28
|
import "../chunk-SKC7AJIV.mjs";
|
|
29
29
|
export {
|
|
30
30
|
CopilotTask
|
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"publishConfig": {
|
|
10
10
|
"access": "public"
|
|
11
11
|
},
|
|
12
|
-
"version": "1.50.1-next.
|
|
12
|
+
"version": "1.50.1-next.2",
|
|
13
13
|
"sideEffects": [
|
|
14
14
|
"**/*.css"
|
|
15
15
|
],
|
|
@@ -61,8 +61,8 @@
|
|
|
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.1-next.
|
|
65
|
-
"@copilotkit/shared": "1.50.1-next.
|
|
64
|
+
"@copilotkit/runtime-client-gql": "1.50.1-next.2",
|
|
65
|
+
"@copilotkit/shared": "1.50.1-next.2"
|
|
66
66
|
},
|
|
67
67
|
"keywords": [
|
|
68
68
|
"copilotkit",
|
package/src/hooks/index.ts
CHANGED
|
@@ -6,7 +6,12 @@ export {
|
|
|
6
6
|
type UseCopilotChatOptions_c,
|
|
7
7
|
useCopilotChatHeadless_c,
|
|
8
8
|
} from "./use-copilot-chat-headless_c";
|
|
9
|
-
export {
|
|
9
|
+
export {
|
|
10
|
+
useCopilotChatInternal,
|
|
11
|
+
type ChatSuggestions,
|
|
12
|
+
type OnReloadMessages,
|
|
13
|
+
type OnStopGeneration,
|
|
14
|
+
} from "./use-copilot-chat_internal";
|
|
10
15
|
export { useCopilotAction } from "./use-copilot-action";
|
|
11
16
|
export { useCoAgentStateRender } from "./use-coagent-state-render";
|
|
12
17
|
export { useMakeCopilotDocumentReadable } from "./use-make-copilot-document-readable";
|
|
@@ -40,6 +40,29 @@ export interface AppendMessageOptions {
|
|
|
40
40
|
clearSuggestions?: boolean;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
+
export interface OnStopGenerationArguments {
|
|
44
|
+
/**
|
|
45
|
+
* The name of the currently executing agent.
|
|
46
|
+
*/
|
|
47
|
+
currentAgentName: string | undefined;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The messages in the chat.
|
|
51
|
+
*/
|
|
52
|
+
messages: Message[];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export type OnReloadMessagesArguments = OnStopGenerationArguments & {
|
|
56
|
+
/**
|
|
57
|
+
* The message on which "regenerate" was pressed
|
|
58
|
+
*/
|
|
59
|
+
messageId: string;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export type OnStopGeneration = (args: OnStopGenerationArguments) => void;
|
|
63
|
+
|
|
64
|
+
export type OnReloadMessages = (args: OnReloadMessagesArguments) => void;
|
|
65
|
+
|
|
43
66
|
export interface UseCopilotChatOptions {
|
|
44
67
|
/**
|
|
45
68
|
* A unique identifier for the chat. If not provided, a random one will be
|
|
@@ -85,6 +108,11 @@ export interface UseCopilotChatOptions {
|
|
|
85
108
|
* - No AI generation involved
|
|
86
109
|
*/
|
|
87
110
|
suggestions?: ChatSuggestions;
|
|
111
|
+
|
|
112
|
+
onInProgress?: (isLoading: boolean) => void;
|
|
113
|
+
onSubmitMessage?: (messageContent: string) => Promise<void> | void;
|
|
114
|
+
onStopGeneration?: OnStopGeneration;
|
|
115
|
+
onReloadMessages?: OnReloadMessages;
|
|
88
116
|
}
|
|
89
117
|
|
|
90
118
|
export interface MCPServerConfig {
|
|
@@ -272,6 +300,10 @@ export interface UseCopilotChatReturn {
|
|
|
272
300
|
|
|
273
301
|
export function useCopilotChatInternal({
|
|
274
302
|
suggestions,
|
|
303
|
+
onInProgress,
|
|
304
|
+
onSubmitMessage,
|
|
305
|
+
onStopGeneration,
|
|
306
|
+
onReloadMessages,
|
|
275
307
|
}: UseCopilotChatOptions = {}): UseCopilotChatReturn {
|
|
276
308
|
const { copilotkit } = useCopilotKit();
|
|
277
309
|
const { threadId, agentSession } = useCopilotContext();
|
|
@@ -303,6 +335,10 @@ export function useCopilotChatInternal({
|
|
|
303
335
|
return () => {};
|
|
304
336
|
}, [existingConfig?.threadId, agent, copilotkit, resolvedAgentId]);
|
|
305
337
|
|
|
338
|
+
useEffect(() => {
|
|
339
|
+
onInProgress?.(Boolean(agent?.isRunning));
|
|
340
|
+
}, [agent?.isRunning, onInProgress]);
|
|
341
|
+
|
|
306
342
|
const interrupt = useLangGraphInterruptRender(agent);
|
|
307
343
|
|
|
308
344
|
const reset = () => {
|
|
@@ -398,8 +434,19 @@ export function useCopilotChatInternal({
|
|
|
398
434
|
console.error("CopilotChat: runAgent failed", error);
|
|
399
435
|
}
|
|
400
436
|
}
|
|
437
|
+
if (onSubmitMessage) {
|
|
438
|
+
const content =
|
|
439
|
+
typeof message.content === "string"
|
|
440
|
+
? message.content
|
|
441
|
+
: message.content && "text" in message.content
|
|
442
|
+
? message.content.text
|
|
443
|
+
: message.content && "filename" in message.content
|
|
444
|
+
? message.content.filename
|
|
445
|
+
: "";
|
|
446
|
+
onSubmitMessage(content);
|
|
447
|
+
}
|
|
401
448
|
},
|
|
402
|
-
[agent, copilotkit, resolvedAgentId],
|
|
449
|
+
[agent, copilotkit, resolvedAgentId, onSubmitMessage],
|
|
403
450
|
);
|
|
404
451
|
|
|
405
452
|
const latestAppendFunc = useAsyncCallback(
|
|
@@ -422,14 +469,23 @@ export function useCopilotChatInternal({
|
|
|
422
469
|
const latestReload = useUpdatedRef(reload);
|
|
423
470
|
const latestReloadFunc = useAsyncCallback(
|
|
424
471
|
async (messageId: string) => {
|
|
472
|
+
onReloadMessages?.({
|
|
473
|
+
messageId,
|
|
474
|
+
currentAgentName: agent?.agentId,
|
|
475
|
+
messages: agent?.messages ?? [],
|
|
476
|
+
});
|
|
425
477
|
return await latestReload.current(messageId);
|
|
426
478
|
},
|
|
427
|
-
[latestReload],
|
|
479
|
+
[latestReload, agent, onReloadMessages],
|
|
428
480
|
);
|
|
429
481
|
|
|
430
482
|
const latestStopFunc = useCallback(() => {
|
|
483
|
+
onStopGeneration?.({
|
|
484
|
+
currentAgentName: agent?.agentId,
|
|
485
|
+
messages: agent?.messages ?? [],
|
|
486
|
+
});
|
|
431
487
|
return agent?.abortRun?.();
|
|
432
|
-
}, [agent
|
|
488
|
+
}, [onStopGeneration, agent]);
|
|
433
489
|
|
|
434
490
|
const latestReset = useUpdatedRef(reset);
|
|
435
491
|
const latestResetFunc = useCallback(() => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React from "react";
|
|
1
|
+
import React, { useEffect, useRef } from "react";
|
|
2
2
|
import { ActionRenderProps, FrontendAction } from "../types/frontend-action";
|
|
3
3
|
import { Parameter, getZodParameters, MappedParameterTypes } from "@copilotkit/shared";
|
|
4
4
|
import { parseJson } from "@copilotkit/shared";
|
|
@@ -74,11 +74,22 @@ export function useFrontendTool<const T extends Parameter[] = []>(
|
|
|
74
74
|
}) as FrontendToolOptions<T>["render"];
|
|
75
75
|
})();
|
|
76
76
|
|
|
77
|
+
// Handler ref to avoid stale closures
|
|
78
|
+
const handlerRef = useRef<typeof tool.handler>(tool.handler);
|
|
79
|
+
|
|
80
|
+
useEffect(() => {
|
|
81
|
+
handlerRef.current = tool.handler;
|
|
82
|
+
}, [tool.handler, ...(dependencies ?? [])]);
|
|
83
|
+
|
|
84
|
+
const normalizedHandler = tool.handler
|
|
85
|
+
? (args: MappedParameterTypes<T>) => handlerRef.current?.(args)
|
|
86
|
+
: undefined;
|
|
87
|
+
|
|
77
88
|
useFrontendToolVNext<MappedParameterTypes<T>>({
|
|
78
89
|
name,
|
|
79
90
|
description,
|
|
80
91
|
parameters: zodParameters,
|
|
81
|
-
handler:
|
|
92
|
+
handler: normalizedHandler,
|
|
82
93
|
followUp,
|
|
83
94
|
render: normalizedRender,
|
|
84
95
|
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/hooks/use-copilot-chat_internal.ts"],"sourcesContent":["import { useRef, useEffect, useCallback, useMemo, useState, createElement } from \"react\";\nimport { useCopilotContext } from \"../context/copilot-context\";\nimport { SystemMessageFunction } from \"../types\";\nimport { useAsyncCallback } from \"../components/error-boundary/error-utils\";\nimport { Message } from \"@copilotkit/shared\";\nimport { gqlToAGUI, Message as DeprecatedGqlMessage } from \"@copilotkit/runtime-client-gql\";\nimport { useLangGraphInterruptRender } from \"./use-langgraph-interrupt-render\";\nimport {\n useAgent,\n useCopilotChatConfiguration,\n useCopilotKit,\n useRenderCustomMessages,\n useSuggestions,\n} from \"@copilotkitnext/react\";\nimport { Suggestion } from \"@copilotkitnext/core\";\nimport { useLazyToolRenderer } from \"./use-lazy-tool-renderer\";\nimport { AbstractAgent, AGUIConnectNotImplementedError } from \"@ag-ui/client\";\nimport {\n CoAgentStateRenderBridge,\n type CoAgentStateRenderBridgeProps,\n} from \"./use-coagent-state-render-bridge\";\n\n/**\n * The type of suggestions to use in the chat.\n *\n * `auto` - Suggestions are generated automatically.\n * `manual` - Suggestions are controlled programmatically.\n * `SuggestionItem[]` - Static suggestions array.\n */\nexport type ChatSuggestions = \"auto\" | \"manual\" | Omit<Suggestion, \"isLoading\">[];\n\nexport interface AppendMessageOptions {\n /**\n * Whether to run the chat completion after appending the message. Defaults to `true`.\n */\n followUp?: boolean;\n /**\n * Whether to clear the suggestions after appending the message. Defaults to `true`.\n */\n clearSuggestions?: boolean;\n}\n\nexport interface UseCopilotChatOptions {\n /**\n * A unique identifier for the chat. If not provided, a random one will be\n * generated. When provided, the `useChat` hook with the same `id` will\n * have shared states across components.\n */\n id?: string;\n\n /**\n * HTTP headers to be sent with the API request.\n */\n headers?: Record<string, string> | Headers;\n\n /**\n * Initial messages to populate the chat with.\n */\n initialMessages?: Message[];\n\n /**\n * A function to generate the system message. Defaults to `defaultSystemMessage`.\n */\n makeSystemMessage?: SystemMessageFunction;\n\n /**\n * 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>).\n */\n disableSystemMessage?: boolean;\n /**\n * Controls the behavior of suggestions in the chat interface.\n *\n * `auto` (default) - Suggestions are generated automatically:\n * - When the chat is first opened (empty state)\n * - After each message exchange completes\n * - Uses configuration from `useCopilotChatSuggestions` hooks\n *\n * `manual` - Suggestions are controlled programmatically:\n * - Use `setSuggestions()` to set custom suggestions\n * - Use `generateSuggestions()` to trigger AI generation\n * - Access via `useCopilotChat` hook\n *\n * `SuggestionItem[]` - Static suggestions array:\n * - Always shows the same suggestions\n * - No AI generation involved\n */\n suggestions?: ChatSuggestions;\n}\n\nexport interface MCPServerConfig {\n endpoint: string;\n apiKey?: string;\n}\n\n// Old suggestion item interface, for returning from useCopilotChatInternal\ninterface SuggestionItem {\n title: string;\n message: string;\n partial?: boolean;\n className?: string;\n}\n\nexport interface UseCopilotChatReturn {\n /**\n * @deprecated use `messages` instead, this is an old non ag-ui version of the messages\n * Array of messages currently visible in the chat interface\n *\n * This is the visible messages, not the raw messages from the runtime client.\n */\n visibleMessages: DeprecatedGqlMessage[];\n\n /**\n * The messages that are currently in the chat in AG-UI format.\n */\n messages: Message[];\n\n /** @deprecated use `sendMessage` in `useCopilotChatHeadless_c` instead. This will be removed in a future major version. */\n appendMessage: (message: DeprecatedGqlMessage, options?: AppendMessageOptions) => Promise<void>;\n\n /**\n * Send a new message to the chat\n *\n * ```tsx\n * await sendMessage({\n * id: \"123\",\n * role: \"user\",\n * content: \"Hello, process this request\",\n * });\n * ```\n */\n sendMessage: (message: Message, options?: AppendMessageOptions) => Promise<void>;\n\n /**\n * Replace all messages in the chat\n *\n * ```tsx\n * setMessages([\n * { id: \"123\", role: \"user\", content: \"Hello, process this request\" },\n * { id: \"456\", role: \"assistant\", content: \"Hello, I'm the assistant\" },\n * ]);\n * ```\n *\n * **Deprecated** non-ag-ui version:\n *\n * ```tsx\n * setMessages([\n * new TextMessage({\n * content: \"Hello, process this request\",\n * role: gqlRole.User,\n * }),\n * new TextMessage({\n * content: \"Hello, I'm the assistant\",\n * role: gqlRole.Assistant,\n * ]);\n * ```\n *\n */\n setMessages: (messages: Message[] | DeprecatedGqlMessage[]) => void;\n\n /**\n * Remove a specific message by ID\n *\n * ```tsx\n * deleteMessage(\"123\");\n * ```\n */\n deleteMessage: (messageId: string) => void;\n\n /**\n * Regenerate the response for a specific message\n *\n * ```tsx\n * reloadMessages(\"123\");\n * ```\n */\n reloadMessages: (messageId: string) => Promise<void>;\n\n /**\n * Stop the current message generation\n *\n * ```tsx\n * if (isLoading) {\n * stopGeneration();\n * }\n * ```\n */\n stopGeneration: () => void;\n\n /**\n * Clear all messages and reset chat state\n *\n * ```tsx\n * reset();\n * console.log(messages); // []\n * ```\n */\n reset: () => void;\n\n /**\n * Whether the chat is currently generating a response\n *\n * ```tsx\n * if (isLoading) {\n * console.log(\"Loading...\");\n * } else {\n * console.log(\"Not loading\");\n * }\n */\n isLoading: boolean;\n\n /**\n * Whether the chat agent is available to generate responses\n *\n * ```tsx\n * if (isAvailable) {\n * console.log(\"Loading...\");\n * } else {\n * console.log(\"Not loading\");\n * }\n */\n isAvailable: boolean;\n\n /** Manually trigger chat completion (advanced usage) */\n runChatCompletion: () => Promise<Message[]>;\n\n /** MCP (Model Context Protocol) server configurations */\n mcpServers: MCPServerConfig[];\n\n /** Update MCP server configurations */\n setMcpServers: (mcpServers: MCPServerConfig[]) => void;\n\n /**\n * Current suggestions array\n * Use this to read the current suggestions or in conjunction with setSuggestions for manual control\n */\n suggestions: Suggestion[];\n\n /**\n * Manually set suggestions\n * Useful for manual mode or custom suggestion workflows\n */\n setSuggestions: (suggestions: Omit<Suggestion, \"isLoading\">[]) => void;\n\n /**\n * Trigger AI-powered suggestion generation\n * Uses configurations from useCopilotChatSuggestions hooks\n * Respects global debouncing - only one generation can run at a time\n *\n * ```tsx\n * generateSuggestions();\n * console.log(suggestions); // [suggestion1, suggestion2, suggestion3]\n * ```\n */\n generateSuggestions: () => Promise<void>;\n\n /**\n * Clear all current suggestions\n * Also resets suggestion generation state\n */\n resetSuggestions: () => void;\n\n /** Whether suggestions are currently being generated */\n isLoadingSuggestions: boolean;\n\n /** Interrupt content for human-in-the-loop workflows */\n interrupt: string | React.ReactElement | null;\n\n agent?: ReturnType<typeof useAgent>[\"agent\"];\n\n threadId?: string;\n}\n\nexport function useCopilotChatInternal({\n suggestions,\n}: UseCopilotChatOptions = {}): UseCopilotChatReturn {\n const { copilotkit } = useCopilotKit();\n const { threadId, agentSession } = useCopilotContext();\n const existingConfig = useCopilotChatConfiguration();\n const [agentAvailable, setAgentAvailable] = useState(false);\n\n // Apply priority: props > existing config > defaults\n const resolvedAgentId = existingConfig?.agentId ?? \"default\";\n const { agent } = useAgent({ agentId: resolvedAgentId });\n\n useEffect(() => {\n const connect = async (agent: AbstractAgent) => {\n setAgentAvailable(false);\n try {\n await copilotkit.connectAgent({ agent });\n setAgentAvailable(true);\n } catch (error) {\n if (error instanceof AGUIConnectNotImplementedError) {\n // connect not implemented, ignore\n } else {\n throw error;\n }\n }\n };\n if (agent && existingConfig?.threadId && agent.threadId !== existingConfig.threadId) {\n agent.threadId = existingConfig.threadId;\n connect(agent);\n }\n return () => {};\n }, [existingConfig?.threadId, agent, copilotkit, resolvedAgentId]);\n\n const interrupt = useLangGraphInterruptRender(agent);\n\n const reset = () => {\n agent?.setMessages([]);\n agent?.setState(null);\n };\n\n const deleteMessage = useCallback(\n (messageId: string) => {\n const filteredMessages = (agent?.messages ?? []).filter(\n (message) => message.id !== messageId,\n );\n agent?.setMessages(filteredMessages);\n },\n [agent?.setMessages, agent?.messages],\n );\n\n const latestDelete = useUpdatedRef(deleteMessage);\n const latestDeleteFunc = useCallback(\n (messageId: string) => {\n return latestDelete.current(messageId);\n },\n [latestDelete],\n );\n\n const currentSuggestions = useSuggestions({ agentId: resolvedAgentId });\n\n const reload = useAsyncCallback(\n async (reloadMessageId: string): Promise<void> => {\n const messages = agent?.messages ?? [];\n // TODO: get isLoading\n const isLoading = false;\n if (isLoading || messages.length === 0) {\n return;\n }\n\n const reloadMessageIndex = messages.findIndex((msg) => msg.id === reloadMessageId);\n if (reloadMessageIndex === -1) {\n console.warn(`Message with id ${reloadMessageId} not found`);\n return;\n }\n\n const reloadMessageRole = messages[reloadMessageIndex].role;\n if (reloadMessageRole !== \"assistant\") {\n console.warn(`Regenerate cannot be performed on ${reloadMessageRole} role`);\n return;\n }\n let historyCutoff: Message[] = [messages[0]];\n\n if (messages.length > 2 && reloadMessageIndex !== 0) {\n // message to regenerate from is now first.\n // Work backwards to find the first the closest user message\n const lastUserMessageBeforeRegenerate = messages\n .slice(0, reloadMessageIndex)\n .reverse()\n .find((msg) => msg.role === \"user\");\n\n if (!lastUserMessageBeforeRegenerate) {\n historyCutoff = [messages[0]];\n } else {\n const indexOfLastUserMessageBeforeRegenerate = messages.findIndex(\n (msg) => msg.id === lastUserMessageBeforeRegenerate.id,\n );\n // Include the user message, remove everything after it\n historyCutoff = messages.slice(0, indexOfLastUserMessageBeforeRegenerate + 1);\n }\n } else if (messages.length > 2 && reloadMessageIndex === 0) {\n historyCutoff = [messages[0], messages[1]];\n }\n\n agent?.setMessages(historyCutoff);\n\n if (agent) {\n copilotkit.runAgent({ agent });\n }\n return;\n },\n [agent?.setMessages, copilotkit?.runAgent],\n );\n\n const latestSendMessageFunc = useAsyncCallback(\n async (message: Message, options?: AppendMessageOptions) => {\n if (!agent) return;\n const followUp = options?.followUp ?? true;\n if (options?.clearSuggestions) {\n copilotkit.clearSuggestions(resolvedAgentId);\n }\n agent?.addMessage(message);\n if (followUp) {\n try {\n await copilotkit.runAgent({ agent });\n } catch (error) {\n console.error(\"CopilotChat: runAgent failed\", error);\n }\n }\n },\n [agent, copilotkit, resolvedAgentId],\n );\n\n const latestAppendFunc = useAsyncCallback(\n async (message: DeprecatedGqlMessage, options?: AppendMessageOptions) => {\n return latestSendMessageFunc(gqlToAGUI([message])[0], options);\n },\n [latestSendMessageFunc],\n );\n\n const latestSetMessagesFunc = useCallback(\n (messages: Message[] | DeprecatedGqlMessage[]) => {\n if (messages.every((message) => message instanceof DeprecatedGqlMessage)) {\n return agent?.setMessages?.(gqlToAGUI(messages));\n }\n return agent?.setMessages?.(messages);\n },\n [agent?.setMessages, agent],\n );\n\n const latestReload = useUpdatedRef(reload);\n const latestReloadFunc = useAsyncCallback(\n async (messageId: string) => {\n return await latestReload.current(messageId);\n },\n [latestReload],\n );\n\n const latestStopFunc = useCallback(() => {\n return agent?.abortRun?.();\n }, [agent?.abortRun]);\n\n const latestReset = useUpdatedRef(reset);\n const latestResetFunc = useCallback(() => {\n return latestReset.current();\n }, [latestReset]);\n\n const lazyToolRendered = useLazyToolRenderer();\n const renderCustomMessage = useRenderCustomMessages();\n const legacyCustomMessageRenderer = useLegacyCoagentRenderer({\n copilotkit,\n agent,\n agentId: resolvedAgentId,\n threadId: existingConfig?.threadId ?? threadId,\n });\n const allMessages = agent?.messages ?? [];\n const resolvedMessages = useMemo(() => {\n let processedMessages = allMessages.map((message) => {\n if (message.role !== \"assistant\") {\n return message;\n }\n\n const lazyRendered = lazyToolRendered(message, allMessages);\n if (lazyRendered) {\n const renderedGenUi = lazyRendered();\n if (renderedGenUi) {\n return { ...message, generativeUI: () => renderedGenUi };\n }\n }\n\n const bridgeRenderer =\n legacyCustomMessageRenderer || renderCustomMessage\n ? () => {\n const customRender = renderCustomMessage?.({\n message,\n position: \"before\",\n });\n if (customRender) {\n return customRender;\n }\n return legacyCustomMessageRenderer?.({ message, position: \"before\" });\n }\n : null;\n\n if (bridgeRenderer) {\n return { ...message, generativeUI: bridgeRenderer };\n }\n return message;\n });\n\n const hasAssistantMessages = processedMessages.some((msg) => msg.role === \"assistant\");\n\n // TODO: what is this?\n // if (legacyCustomMessageRenderer && !hasAssistantMessages) {\n // const placeholderId = `coagent-state-render-${resolvedAgentId}`;\n // const placeholderMessage: Message = {\n // id: placeholderId,\n // role: \"assistant\",\n // content: \"\",\n // name: \"coagent-state-render\",\n // };\n // processedMessages = [\n // ...processedMessages,\n // {\n // ...placeholderMessage,\n // generativeUI: () =>\n // legacyCustomMessageRenderer({\n // message: placeholderMessage,\n // position: \"before\",\n // }),\n // } as Message,\n // ];\n // }\n\n return processedMessages;\n }, [\n agent?.messages,\n lazyToolRendered,\n allMessages,\n renderCustomMessage,\n // legacyCustomMessageRenderer,\n resolvedAgentId,\n ]);\n\n const renderedSuggestions = useMemo(() => {\n if (Array.isArray(suggestions)) {\n return {\n suggestions: suggestions.map((s) => ({ ...s, isLoading: false })),\n isLoading: false,\n };\n }\n return currentSuggestions;\n }, [suggestions, currentSuggestions]);\n\n // @ts-ignore\n return {\n messages: resolvedMessages,\n sendMessage: latestSendMessageFunc,\n appendMessage: latestAppendFunc,\n setMessages: latestSetMessagesFunc,\n reloadMessages: latestReloadFunc,\n stopGeneration: latestStopFunc,\n reset: latestResetFunc,\n deleteMessage: latestDeleteFunc,\n isAvailable: agentAvailable,\n isLoading: Boolean(agent?.isRunning),\n // mcpServers,\n // setMcpServers,\n suggestions: renderedSuggestions.suggestions,\n setSuggestions: (suggestions: Omit<Suggestion, \"isLoading\">[]) =>\n copilotkit.addSuggestionsConfig({ suggestions }),\n generateSuggestions: async () => copilotkit.reloadSuggestions(resolvedAgentId),\n resetSuggestions: () => copilotkit.clearSuggestions(resolvedAgentId),\n isLoadingSuggestions: renderedSuggestions.isLoading,\n interrupt,\n agent,\n threadId,\n };\n}\n\n// store `value` in a ref and update\n// it whenever it changes.\nfunction useUpdatedRef<T>(value: T) {\n const ref = useRef(value);\n\n useEffect(() => {\n ref.current = value;\n }, [value]);\n\n return ref;\n}\n\ntype LegacyRenderParams = {\n message: Message;\n position: \"before\" | \"after\";\n};\n\ntype LegacyRenderer = ((args: LegacyRenderParams) => any) | null;\n\nfunction useLegacyCoagentRenderer({\n copilotkit,\n agent,\n agentId,\n threadId,\n}: {\n copilotkit: ReturnType<typeof useCopilotKit>[\"copilotkit\"];\n agent?: AbstractAgent;\n agentId: string;\n threadId?: string;\n}): LegacyRenderer {\n return useMemo(() => {\n if (!copilotkit || !agent) {\n return null;\n }\n\n return ({ message, position }: LegacyRenderParams) => {\n const effectiveThreadId = threadId ?? agent.threadId ?? \"default\";\n const existingRunId = copilotkit.getRunIdForMessage(agentId, effectiveThreadId, message.id);\n const runId = existingRunId || `pending:${message.id}`;\n const messageIndex = Math.max(\n agent.messages.findIndex((msg) => msg.id === message.id),\n 0,\n );\n\n const bridgeProps: CoAgentStateRenderBridgeProps = {\n message: message as any,\n position,\n runId,\n messageIndex,\n messageIndexInRun: 0,\n numberOfMessagesInRun: 1,\n agentId,\n stateSnapshot: (message as any).state,\n };\n\n return createElement(CoAgentStateRenderBridge, bridgeProps) as any;\n };\n }, [agent, agentId, copilotkit, threadId]);\n}\n\nexport function defaultSystemMessage(\n contextString: string,\n additionalInstructions?: string,\n): string {\n return (\n `\nPlease act as an efficient, competent, conscientious, and industrious professional assistant.\n\nHelp the user achieve their goals, and you do so in a way that is as efficient as possible, without unnecessary fluff, but also without sacrificing professionalism.\nAlways be polite and respectful, and prefer brevity over verbosity.\n\nThe user has provided you with the following context:\n\\`\\`\\`\n${contextString}\n\\`\\`\\`\n\nThey have also provided you with functions you can call to initiate actions on their behalf, or functions you can call to receive more information.\n\nPlease assist them as best you can.\n\nYou can ask them for clarifying questions if needed, but don't be annoying about it. If you can reasonably 'fill in the blanks' yourself, do so.\n\nIf you would like to call a function, call it without saying anything else.\nIn case of a function error:\n- If this error stems from incorrect function parameters or syntax, you may retry with corrected arguments.\n- If the error's source is unclear or seems unrelated to your input, do not attempt further retries.\n` + (additionalInstructions ? `\\n\\n${additionalInstructions}` : \"\")\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,QAAQ,WAAW,aAAa,SAAS,UAAU,qBAAqB;AAKjF,SAAS,WAAW,WAAW,4BAA4B;AAE3D;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAGP,SAAwB,sCAAsC;AAgQvD,SAAS,uBAAuB;AAAA,EACrC;AACF,IAA2B,CAAC,GAAyB;AAlRrD;AAmRE,QAAM,EAAE,WAAW,IAAI,cAAc;AACrC,QAAM,EAAE,UAAU,aAAa,IAAI,kBAAkB;AACrD,QAAM,iBAAiB,4BAA4B;AACnD,QAAM,CAAC,gBAAgB,iBAAiB,IAAI,SAAS,KAAK;AAG1D,QAA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,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA,mBAAmB;AAAA,QACnB,uBAAuB;AAAA,QACvB;AAAA,QACA,eAAgB,QAAgB;AAAA,MAClC;AAEA,aAAO,cAAc,0BAA0B,WAAW;AAAA,IAC5D;AAAA,EACF,GAAG,CAAC,OAAO,SAAS,YAAY,QAAQ,CAAC;AAC3C;AAEO,SAAS,qBACd,eACA,wBACQ;AACR,SACE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,KAaG,yBAAyB;AAAA;AAAA,EAAO,2BAA2B;AAEhE;","names":["agent","_a","_b","suggestions"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/hooks/use-frontend-tool.ts"],"sourcesContent":["import React from \"react\";\nimport { ActionRenderProps, FrontendAction } from \"../types/frontend-action\";\nimport { Parameter, getZodParameters, MappedParameterTypes } from \"@copilotkit/shared\";\nimport { parseJson } from \"@copilotkit/shared\";\nimport { ToolCallStatus } from \"@copilotkitnext/core\";\nimport {\n type ReactFrontendTool,\n useFrontendTool as useFrontendToolVNext,\n} from \"@copilotkitnext/react\";\n\ntype FrontendToolOptions<T extends Parameter[] | []> = ReactFrontendTool<MappedParameterTypes<T>>;\ntype FrontendToolRenderArgs<T extends Parameter[] | []> =\n | {\n name: string;\n args: Partial<MappedParameterTypes<T>>;\n status: ToolCallStatus.InProgress;\n result: undefined;\n }\n | {\n name: string;\n args: MappedParameterTypes<T>;\n status: ToolCallStatus.Executing;\n result: undefined;\n }\n | {\n name: string;\n args: MappedParameterTypes<T>;\n status: ToolCallStatus.Complete;\n result: string;\n };\n\nexport type UseFrontendToolArgs<T extends Parameter[] | [] = []> = {\n available?: \"disabled\" | \"enabled\";\n} & Pick<\n FrontendAction<T>,\n \"name\" | \"description\" | \"parameters\" | \"handler\" | \"followUp\" | \"render\"\n>;\n\nexport function useFrontendTool<const T extends Parameter[] = []>(\n tool: UseFrontendToolArgs<T>,\n dependencies?: any[],\n) {\n const { name, description, parameters, render, followUp } = tool;\n const zodParameters = getZodParameters(parameters);\n\n const normalizedRender: FrontendToolOptions<T>[\"render\"] | undefined = (() => {\n if (typeof render === \"undefined\") {\n return undefined;\n }\n\n if (typeof render === \"string\") {\n const staticRender = render;\n return (() =>\n React.createElement(\n React.Fragment,\n null,\n staticRender,\n )) as FrontendToolOptions<T>[\"render\"];\n }\n\n return ((args: FrontendToolRenderArgs<T>) => {\n const renderArgs = {\n ...args,\n result: typeof args.result === \"string\" ? parseJson(args.result, args.result) : args.result,\n } as ActionRenderProps<T>;\n\n const rendered = render(renderArgs);\n\n if (typeof rendered === \"string\") {\n return React.createElement(React.Fragment, null, rendered);\n }\n\n return rendered ?? null;\n }) as FrontendToolOptions<T>[\"render\"];\n })();\n\n useFrontendToolVNext<MappedParameterTypes<T>>({\n name,\n description,\n parameters: zodParameters,\n handler: tool.handler,\n followUp,\n render: normalizedRender,\n });\n}\n"],"mappings":";;;;;;AAAA,OAAO,WAAW;AAElB,SAAoB,wBAA8C;AAClE,SAAS,iBAAiB;AAE1B;AAAA,EAEE,mBAAmB;AAAA,OACd;AA8BA,SAAS,gBACd,MACA,cACA;AACA,QAAM,EAAE,MAAM,aAAa,YAAY,QAAQ,SAAS,IAAI;AAC5D,QAAM,gBAAgB,iBAAiB,UAAU;AAEjD,QAAM,oBAAkE,MAAM;AAC5E,QAAI,OAAO,WAAW,aAAa;AACjC,aAAO;AAAA,IACT;AAEA,QAAI,OAAO,WAAW,UAAU;AAC9B,YAAM,eAAe;AACrB,aAAQ,MACN,MAAM;AAAA,QACJ,MAAM;AAAA,QACN;AAAA,QACA;AAAA,MACF;AAAA,IACJ;AAEA,WAAQ,CAAC,SAAoC;AAC3C,YAAM,aAAa,iCACd,OADc;AAAA,QAEjB,QAAQ,OAAO,KAAK,WAAW,WAAW,UAAU,KAAK,QAAQ,KAAK,MAAM,IAAI,KAAK;AAAA,MACvF;AAEA,YAAM,WAAW,OAAO,UAAU;AAElC,UAAI,OAAO,aAAa,UAAU;AAChC,eAAO,MAAM,cAAc,MAAM,UAAU,MAAM,QAAQ;AAAA,MAC3D;AAEA,aAAO,8BAAY;AAAA,IACrB;AAAA,EACF,GAAG;AAEH,uBAA8C;AAAA,IAC5C;AAAA,IACA;AAAA,IACA,YAAY;AAAA,IACZ,SAAS,KAAK;AAAA,IACd;AAAA,IACA,QAAQ;AAAA,EACV,CAAC;AACH;","names":[]}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|