@copilotkit/react-core 1.4.0-pre-1-4-0.14 → 1.4.0
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 +70 -165
- package/dist/{chunk-RYDEG77L.mjs → chunk-7LKXEJXM.mjs} +19 -6
- package/dist/chunk-7LKXEJXM.mjs.map +1 -0
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/index.js +18 -5
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +11 -11
- package/dist/hooks/use-coagent.mjs +1 -1
- package/dist/hooks/use-copilot-action.d.ts +124 -1
- package/dist/hooks/use-copilot-action.js +18 -5
- package/dist/hooks/use-copilot-action.js.map +1 -1
- package/dist/hooks/use-copilot-action.mjs +1 -1
- package/dist/hooks/use-copilot-chat.mjs +1 -1
- package/dist/index.js +18 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +11 -11
- package/dist/types/frontend-action.d.ts +15 -2
- package/dist/types/frontend-action.js.map +1 -1
- package/package.json +5 -5
- package/src/hooks/use-copilot-action.ts +114 -43
- package/src/types/frontend-action.ts +17 -2
- package/dist/chunk-RYDEG77L.mjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,192 +1,97 @@
|
|
|
1
1
|
# ui
|
|
2
2
|
|
|
3
|
-
## 1.4.0
|
|
3
|
+
## 1.4.0
|
|
4
4
|
|
|
5
5
|
### Minor Changes
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
CopilotKit Core:
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
- Updated
|
|
14
|
-
- @copilotkit/runtime-client-gql@1.4.0-pre-1-4-0.14
|
|
15
|
-
- @copilotkit/shared@1.4.0-pre-1-4-0.14
|
|
16
|
-
|
|
17
|
-
## 1.4.0-pre-1-4-0.13
|
|
18
|
-
|
|
19
|
-
### Minor Changes
|
|
20
|
-
|
|
21
|
-
- lgc & lgjs alpha
|
|
22
|
-
|
|
23
|
-
### Patch Changes
|
|
9
|
+
- Improved error messages and overall logs
|
|
10
|
+
- `useCopilotAction.renderAndAwait` renamed to `.renderAndAwaitForResponse` (backwards compatible, will be deprecated in the future)
|
|
11
|
+
- Improved scrolling behavior. It is now possible to scroll up during LLM response generation
|
|
12
|
+
- Added Azure OpenAI integration
|
|
13
|
+
- Updated interfaces for better developer ergonomics
|
|
24
14
|
|
|
25
|
-
|
|
26
|
-
- @copilotkit/runtime-client-gql@1.4.0-pre-1-4-0.13
|
|
27
|
-
- @copilotkit/shared@1.4.0-pre-1-4-0.13
|
|
15
|
+
CoAgents:
|
|
28
16
|
|
|
29
|
-
|
|
17
|
+
- Renamed `remoteActions` to `remoteEndpoints` (backwards compatible, will be deprecated in the future)
|
|
18
|
+
- Support for LangGraph Platform in Remote Endpoints
|
|
19
|
+
- LangGraph JS Support for CoAgents (locally via `langgraph dev`, `langgraph up` or deployed to LangGraph Platform)
|
|
20
|
+
- Improved LangSmith integration - requests made through CoAgents will now surface in LangSmith
|
|
21
|
+
- Enhanced state management and message handling
|
|
30
22
|
|
|
31
|
-
|
|
23
|
+
CopilotKid Back-end SDK:
|
|
32
24
|
|
|
33
|
-
-
|
|
34
|
-
- 7cc6cc8: LangGraph Cloud and LangGraphJS alpha release
|
|
35
|
-
- prerelease lgc and lgjs
|
|
36
|
-
- Add LangGraph Platform and LangGraph JS support
|
|
37
|
-
- b318b18: Add LangGraph Cloud support
|
|
25
|
+
- Released a whole-new `@copilotkit/sdk-js` for building agents with LangGraph JS Support
|
|
38
26
|
|
|
39
27
|
### Patch Changes
|
|
40
28
|
|
|
41
|
-
-
|
|
42
|
-
-
|
|
43
|
-
-
|
|
29
|
+
- f6fab28: update tsup config
|
|
30
|
+
- f6fab28: update entry
|
|
31
|
+
- f6fab28: export langchain module
|
|
44
32
|
- 8a77944: Improve LangSmith support
|
|
45
|
-
-
|
|
46
|
-
-
|
|
33
|
+
- f6fab28: Ensure intermediate state config is sent as snake case
|
|
34
|
+
- f6fab28: update entry in tsup config
|
|
47
35
|
- 8a77944: Ensure the last message is sent to LangSmith
|
|
48
|
-
-
|
|
49
|
-
-
|
|
50
|
-
-
|
|
36
|
+
- a5efccd: Revert rxjs changes
|
|
37
|
+
- f6fab28: update entry
|
|
38
|
+
- f6fab28: Update exports
|
|
39
|
+
- f6fab28: Update exports
|
|
51
40
|
- 332d744: Add support for Azure OpenAI
|
|
52
|
-
-
|
|
53
|
-
-
|
|
54
|
-
- Updated dependencies [
|
|
55
|
-
- Updated dependencies [
|
|
56
|
-
- Updated dependencies [c6b489d]
|
|
57
|
-
- Updated dependencies [7cc6cc8]
|
|
58
|
-
- Updated dependencies [e71d469]
|
|
59
|
-
- Updated dependencies [8a77944]
|
|
60
|
-
- Updated dependencies [3caa5d5]
|
|
61
|
-
- Updated dependencies [cf3a787]
|
|
62
|
-
- Updated dependencies
|
|
41
|
+
- f6fab28: Export LangGraph functions
|
|
42
|
+
- f6fab28: Update lockfile
|
|
43
|
+
- Updated dependencies [f6fab28]
|
|
44
|
+
- Updated dependencies [f6fab28]
|
|
63
45
|
- Updated dependencies
|
|
46
|
+
- Updated dependencies [f6fab28]
|
|
47
|
+
- Updated dependencies [8a77944]
|
|
48
|
+
- Updated dependencies [f6fab28]
|
|
49
|
+
- Updated dependencies [f6fab28]
|
|
64
50
|
- Updated dependencies [8a77944]
|
|
65
|
-
- Updated dependencies [
|
|
66
|
-
- Updated dependencies [
|
|
67
|
-
- Updated dependencies [
|
|
51
|
+
- Updated dependencies [a5efccd]
|
|
52
|
+
- Updated dependencies [f6fab28]
|
|
53
|
+
- Updated dependencies [f6fab28]
|
|
54
|
+
- Updated dependencies [f6fab28]
|
|
68
55
|
- Updated dependencies [332d744]
|
|
69
|
-
- Updated dependencies [
|
|
70
|
-
- Updated dependencies [
|
|
71
|
-
-
|
|
72
|
-
- @copilotkit/
|
|
73
|
-
- @copilotkit/shared@1.4.0-pre-1-4-0.12
|
|
74
|
-
|
|
75
|
-
## 1.4.0-pre-1-4-0.11
|
|
56
|
+
- Updated dependencies [f6fab28]
|
|
57
|
+
- Updated dependencies [f6fab28]
|
|
58
|
+
- @copilotkit/runtime-client-gql@1.4.0
|
|
59
|
+
- @copilotkit/shared@1.4.0
|
|
76
60
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
- LangGraph Platform and LangGraph JS support
|
|
61
|
+
## 1.3.16-mme-revert-rxjs-changes.10
|
|
80
62
|
|
|
81
63
|
### Patch Changes
|
|
82
64
|
|
|
65
|
+
- f6fab28: update tsup config
|
|
66
|
+
- f6fab28: update entry
|
|
67
|
+
- f6fab28: export langchain module
|
|
68
|
+
- 8a77944: Improve LangSmith support
|
|
69
|
+
- f6fab28: Ensure intermediate state config is sent as snake case
|
|
70
|
+
- f6fab28: update entry in tsup config
|
|
71
|
+
- 8a77944: Ensure the last message is sent to LangSmith
|
|
72
|
+
- Revert rxjs changes
|
|
73
|
+
- f6fab28: update entry
|
|
74
|
+
- f6fab28: Update exports
|
|
75
|
+
- f6fab28: Update exports
|
|
76
|
+
- 332d744: Add support for Azure OpenAI
|
|
77
|
+
- f6fab28: Export LangGraph functions
|
|
78
|
+
- f6fab28: Update lockfile
|
|
79
|
+
- Updated dependencies [f6fab28]
|
|
80
|
+
- Updated dependencies [f6fab28]
|
|
81
|
+
- Updated dependencies [f6fab28]
|
|
82
|
+
- Updated dependencies [8a77944]
|
|
83
|
+
- Updated dependencies [f6fab28]
|
|
84
|
+
- Updated dependencies [f6fab28]
|
|
85
|
+
- Updated dependencies [8a77944]
|
|
83
86
|
- Updated dependencies
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
-
|
|
92
|
-
- b318b18: Add LangGraph Cloud support
|
|
93
|
-
|
|
94
|
-
### Patch Changes
|
|
95
|
-
|
|
96
|
-
- Updated dependencies
|
|
97
|
-
- Updated dependencies [b318b18]
|
|
98
|
-
- @copilotkit/runtime-client-gql@1.4.0-pre-1-4-0.10
|
|
99
|
-
- @copilotkit/shared@1.4.0-pre-1-4-0.10
|
|
100
|
-
|
|
101
|
-
## 1.3.16-mme-lgc-langgraph-package.9
|
|
102
|
-
|
|
103
|
-
### Patch Changes
|
|
104
|
-
|
|
105
|
-
- update entry
|
|
106
|
-
- Updated dependencies
|
|
107
|
-
- @copilotkit/runtime-client-gql@1.3.16-mme-lgc-langgraph-package.9
|
|
108
|
-
- @copilotkit/shared@1.3.16-mme-lgc-langgraph-package.9
|
|
109
|
-
|
|
110
|
-
## 1.3.16-mme-lgc-langgraph-package.8
|
|
111
|
-
|
|
112
|
-
### Patch Changes
|
|
113
|
-
|
|
114
|
-
- update entry
|
|
115
|
-
- Updated dependencies
|
|
116
|
-
- @copilotkit/runtime-client-gql@1.3.16-mme-lgc-langgraph-package.8
|
|
117
|
-
- @copilotkit/shared@1.3.16-mme-lgc-langgraph-package.8
|
|
118
|
-
|
|
119
|
-
## 1.3.16-mme-lgc-langgraph-package.7
|
|
120
|
-
|
|
121
|
-
### Patch Changes
|
|
122
|
-
|
|
123
|
-
- update entry in tsup config
|
|
124
|
-
- Updated dependencies
|
|
125
|
-
- @copilotkit/runtime-client-gql@1.3.16-mme-lgc-langgraph-package.7
|
|
126
|
-
- @copilotkit/shared@1.3.16-mme-lgc-langgraph-package.7
|
|
127
|
-
|
|
128
|
-
## 1.3.16-mme-lgc-langgraph-package.6
|
|
129
|
-
|
|
130
|
-
### Patch Changes
|
|
131
|
-
|
|
132
|
-
- Update exports
|
|
133
|
-
- Updated dependencies
|
|
134
|
-
- @copilotkit/runtime-client-gql@1.3.16-mme-lgc-langgraph-package.6
|
|
135
|
-
- @copilotkit/shared@1.3.16-mme-lgc-langgraph-package.6
|
|
136
|
-
|
|
137
|
-
## 1.3.16-mme-lgc-langgraph-package.5
|
|
138
|
-
|
|
139
|
-
### Patch Changes
|
|
140
|
-
|
|
141
|
-
- update tsup config
|
|
142
|
-
- Updated dependencies
|
|
143
|
-
- @copilotkit/runtime-client-gql@1.3.16-mme-lgc-langgraph-package.5
|
|
144
|
-
- @copilotkit/shared@1.3.16-mme-lgc-langgraph-package.5
|
|
145
|
-
|
|
146
|
-
## 1.3.16-mme-lgc-langgraph-package.4
|
|
147
|
-
|
|
148
|
-
### Patch Changes
|
|
149
|
-
|
|
150
|
-
- Update exports
|
|
151
|
-
- Updated dependencies
|
|
152
|
-
- @copilotkit/runtime-client-gql@1.3.16-mme-lgc-langgraph-package.4
|
|
153
|
-
- @copilotkit/shared@1.3.16-mme-lgc-langgraph-package.4
|
|
154
|
-
|
|
155
|
-
## 1.3.16-mme-lgc-langgraph-package.3
|
|
156
|
-
|
|
157
|
-
### Patch Changes
|
|
158
|
-
|
|
159
|
-
- export langchain module
|
|
160
|
-
- Updated dependencies
|
|
161
|
-
- @copilotkit/runtime-client-gql@1.3.16-mme-lgc-langgraph-package.3
|
|
162
|
-
- @copilotkit/shared@1.3.16-mme-lgc-langgraph-package.3
|
|
163
|
-
|
|
164
|
-
## 1.3.16-mme-sdk-js.2
|
|
165
|
-
|
|
166
|
-
### Patch Changes
|
|
167
|
-
|
|
168
|
-
- Ensure intermediate state config is sent as snake case
|
|
169
|
-
- Updated dependencies
|
|
170
|
-
- @copilotkit/runtime-client-gql@1.3.16-mme-sdk-js.2
|
|
171
|
-
- @copilotkit/shared@1.3.16-mme-sdk-js.2
|
|
172
|
-
|
|
173
|
-
## 1.3.16-mme-sdk-js.1
|
|
174
|
-
|
|
175
|
-
### Patch Changes
|
|
176
|
-
|
|
177
|
-
- Update lockfile
|
|
178
|
-
- Updated dependencies
|
|
179
|
-
- @copilotkit/runtime-client-gql@1.3.16-mme-sdk-js.1
|
|
180
|
-
- @copilotkit/shared@1.3.16-mme-sdk-js.1
|
|
181
|
-
|
|
182
|
-
## 1.3.16-mme-sdk-js.0
|
|
183
|
-
|
|
184
|
-
### Patch Changes
|
|
185
|
-
|
|
186
|
-
- Export LangGraph functions
|
|
187
|
-
- Updated dependencies
|
|
188
|
-
- @copilotkit/runtime-client-gql@1.3.16-mme-sdk-js.0
|
|
189
|
-
- @copilotkit/shared@1.3.16-mme-sdk-js.0
|
|
87
|
+
- Updated dependencies [f6fab28]
|
|
88
|
+
- Updated dependencies [f6fab28]
|
|
89
|
+
- Updated dependencies [f6fab28]
|
|
90
|
+
- Updated dependencies [332d744]
|
|
91
|
+
- Updated dependencies [f6fab28]
|
|
92
|
+
- Updated dependencies [f6fab28]
|
|
93
|
+
- @copilotkit/runtime-client-gql@1.3.16-mme-revert-rxjs-changes.10
|
|
94
|
+
- @copilotkit/shared@1.3.16-mme-revert-rxjs-changes.10
|
|
190
95
|
|
|
191
96
|
## 1.3.15
|
|
192
97
|
|
|
@@ -7,16 +7,17 @@ import {
|
|
|
7
7
|
} from "./chunk-SKC7AJIV.mjs";
|
|
8
8
|
|
|
9
9
|
// src/hooks/use-copilot-action.ts
|
|
10
|
-
import { useRef, useEffect } from "react";
|
|
11
10
|
import { randomId } from "@copilotkit/shared";
|
|
11
|
+
import { createElement, Fragment, useEffect, useRef } from "react";
|
|
12
12
|
function useCopilotAction(action, dependencies) {
|
|
13
13
|
const { setAction, removeAction, actions, chatComponentsCache } = useCopilotContext();
|
|
14
14
|
const idRef = useRef(randomId());
|
|
15
15
|
const renderAndWaitRef = useRef(null);
|
|
16
16
|
action = __spreadValues({}, action);
|
|
17
|
-
if (action.renderAndWait) {
|
|
18
|
-
const renderAndWait = action.renderAndWait;
|
|
17
|
+
if (action.renderAndWait || action.renderAndWaitForResponse) {
|
|
18
|
+
const renderAndWait = action.renderAndWait || action.renderAndWaitForResponse;
|
|
19
19
|
action.renderAndWait = void 0;
|
|
20
|
+
action.renderAndWaitForResponse = void 0;
|
|
20
21
|
action.handler = () => __async(this, null, function* () {
|
|
21
22
|
let resolve;
|
|
22
23
|
let reject;
|
|
@@ -32,9 +33,21 @@ function useCopilotAction(action, dependencies) {
|
|
|
32
33
|
status: props.status,
|
|
33
34
|
args: props.args,
|
|
34
35
|
result: props.result,
|
|
35
|
-
handler: props.status === "executing" ? renderAndWaitRef.current.resolve : void 0
|
|
36
|
+
handler: props.status === "executing" ? renderAndWaitRef.current.resolve : void 0,
|
|
37
|
+
respond: props.status === "executing" ? renderAndWaitRef.current.resolve : void 0
|
|
36
38
|
};
|
|
37
|
-
|
|
39
|
+
const isNoArgsRenderWait = (_fn) => {
|
|
40
|
+
var _a;
|
|
41
|
+
return ((_a = action.parameters) == null ? void 0 : _a.length) === 0;
|
|
42
|
+
};
|
|
43
|
+
if (renderAndWait) {
|
|
44
|
+
if (isNoArgsRenderWait(renderAndWait)) {
|
|
45
|
+
return renderAndWait(waitProps);
|
|
46
|
+
} else {
|
|
47
|
+
return renderAndWait(waitProps);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return createElement(Fragment);
|
|
38
51
|
};
|
|
39
52
|
}
|
|
40
53
|
if (dependencies === void 0) {
|
|
@@ -74,4 +87,4 @@ function useCopilotAction(action, dependencies) {
|
|
|
74
87
|
export {
|
|
75
88
|
useCopilotAction
|
|
76
89
|
};
|
|
77
|
-
//# sourceMappingURL=chunk-
|
|
90
|
+
//# sourceMappingURL=chunk-7LKXEJXM.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/hooks/use-copilot-action.ts"],"sourcesContent":["/**\n * Example usage of useCopilotAction with complex parameters:\n *\n * @example\n * useCopilotAction({\n * name: \"myAction\",\n * parameters: [\n * { name: \"arg1\", type: \"string\", enum: [\"option1\", \"option2\", \"option3\"], required: false },\n * { name: \"arg2\", type: \"number\" },\n * {\n * name: \"arg3\",\n * type: \"object\",\n * attributes: [\n * { name: \"nestedArg1\", type: \"boolean\" },\n * { name: \"xyz\", required: false },\n * ],\n * },\n * { name: \"arg4\", type: \"number[]\" },\n * ],\n * handler: ({ arg1, arg2, arg3, arg4 }) => {\n * const x = arg3.nestedArg1;\n * const z = arg3.xyz;\n * console.log(arg1, arg2, arg3);\n * },\n * });\n *\n * @example\n * // Simple action without parameters\n * useCopilotAction({\n * name: \"myAction\",\n * handler: () => {\n * console.log(\"No parameters provided.\");\n * },\n * });\n *\n * @example\n * // Interactive action with UI rendering and response handling\n * useCopilotAction({\n * name: \"handleMeeting\",\n * description: \"Handle a meeting by booking or canceling\",\n * parameters: [\n * {\n * name: \"meeting\",\n * type: \"string\",\n * description: \"The meeting to handle\",\n * required: true,\n * },\n * {\n * name: \"date\",\n * type: \"string\",\n * description: \"The date of the meeting\",\n * required: true,\n * },\n * {\n * name: \"title\",\n * type: \"string\",\n * description: \"The title of the meeting\",\n * required: true,\n * },\n * ],\n * renderAndWaitForResponse: ({ args, respond, status }) => {\n * const { meeting, date, title } = args;\n * return (\n * <MeetingConfirmationDialog\n * meeting={meeting}\n * date={date}\n * title={title}\n * onConfirm={() => respond('meeting confirmed')}\n * onCancel={() => respond('meeting canceled')}\n * />\n * );\n * },\n * });\n */\n\n/**\n * <img src=\"/images/use-copilot-action/useCopilotAction.gif\" width=\"500\" />\n * `useCopilotAction` is a React hook that you can use in your application to provide\n * custom actions that can be called by the AI. Essentially, it allows the Copilot to\n * execute these actions contextually during a chat, based on the user's interactions\n * and needs.\n *\n * Here's how it works:\n *\n * Use `useCopilotAction` to set up actions that the Copilot can call. To provide\n * more context to the Copilot, you can provide it with a `description` (for example to explain\n * what the action does, under which conditions it can be called, etc.).\n *\n * Then you define the parameters of the action, which can be simple, e.g. primitives like strings or numbers,\n * or complex, e.g. objects or arrays.\n *\n * Finally, you provide a `handler` function that receives the parameters and returns a result.\n * CopilotKit takes care of automatically inferring the parameter types, so you get type safety\n * and autocompletion for free.\n *\n * To render a custom UI for the action, you can provide a `render()` function. This function\n * lets you render a custom component or return a string to display.\n *\n * ## Usage\n *\n * ### Simple Usage\n *\n * ```tsx\n * useCopilotAction({\n * name: \"sayHello\",\n * description: \"Say hello to someone.\",\n * parameters: [\n * {\n * name: \"name\",\n * type: \"string\",\n * description: \"name of the person to say greet\",\n * },\n * ],\n * handler: async ({ name }) => {\n * alert(`Hello, ${name}!`);\n * },\n * });\n * ```\n *\n * ## Generative UI\n *\n * This hooks enables you to dynamically generate UI elements and render them in the copilot chat. For more information, check out the [Generative UI](/concepts/generative-ui) page.\n */\nimport { Parameter, randomId } from \"@copilotkit/shared\";\nimport { createElement, Fragment, useEffect, useRef } from \"react\";\nimport { useCopilotContext } from \"../context/copilot-context\";\nimport {\n ActionRenderProps,\n ActionRenderPropsNoArgsWait,\n ActionRenderPropsWait,\n FrontendAction,\n} from \"../types/frontend-action\";\n\n// We implement useCopilotAction dependency handling so that\n// the developer has the option to not provide any dependencies.\n// In this case, we assume they want to update the handler on each rerender.\n// To avoid getting stuck in an infinite loop, we update the handler directly,\n// skipping React state updates.\n// This is ok in this case, because the handler is not part of any UI that\n// needs to be updated.\n// useCallback, useMemo or other memoization techniques are not suitable here,\n// because they will cause a infinite rerender loop.\nexport function useCopilotAction<const T extends Parameter[] | [] = []>(\n action: FrontendAction<T>,\n dependencies?: any[],\n): void {\n const { setAction, removeAction, actions, chatComponentsCache } = useCopilotContext();\n const idRef = useRef<string>(randomId());\n const renderAndWaitRef = useRef<RenderAndWaitForResponse | null>(null);\n\n // clone the action to avoid mutating the original object\n action = { ...action };\n\n // If the developer provides a renderAndWait function, we transform the action\n // to use a promise internally, so that we can treat it like a normal action.\n if (action.renderAndWait || action.renderAndWaitForResponse) {\n const renderAndWait = action.renderAndWait || action.renderAndWaitForResponse;\n // remove the renderAndWait function from the action\n action.renderAndWait = undefined;\n action.renderAndWaitForResponse = undefined;\n // add a handler that will be called when the action is executed\n action.handler = (async () => {\n // we create a new promise when the handler is called\n let resolve: (result: any) => void;\n let reject: (error: any) => void;\n const promise = new Promise<any>((resolvePromise, rejectPromise) => {\n resolve = resolvePromise;\n reject = rejectPromise;\n });\n renderAndWaitRef.current = { promise, resolve: resolve!, reject: reject! };\n // then we await the promise (it will be resolved in the original renderAndWait function)\n return await promise;\n }) as any;\n\n // add a render function that will be called when the action is rendered\n action.render = ((props: ActionRenderProps<T>): React.ReactElement => {\n // Create type safe waitProps based on whether T extends empty array or not\n const waitProps = {\n status: props.status,\n args: props.args,\n result: props.result,\n handler: props.status === \"executing\" ? renderAndWaitRef.current!.resolve : undefined,\n respond: props.status === \"executing\" ? renderAndWaitRef.current!.resolve : undefined,\n } as T extends [] ? ActionRenderPropsNoArgsWait<T> : ActionRenderPropsWait<T>;\n\n // Type guard to check if renderAndWait is for no args case\n const isNoArgsRenderWait = (\n _fn:\n | ((props: ActionRenderPropsNoArgsWait<T>) => React.ReactElement)\n | ((props: ActionRenderPropsWait<T>) => React.ReactElement),\n ): _fn is (props: ActionRenderPropsNoArgsWait<T>) => React.ReactElement => {\n return action.parameters?.length === 0;\n };\n\n // Safely call renderAndWait with correct props type\n if (renderAndWait) {\n if (isNoArgsRenderWait(renderAndWait)) {\n return renderAndWait(waitProps as ActionRenderPropsNoArgsWait<T>);\n } else {\n return renderAndWait(waitProps as ActionRenderPropsWait<T>);\n }\n }\n\n // Return empty Fragment instead of null\n return createElement(Fragment);\n }) as any;\n }\n\n // If the developer doesn't provide dependencies, we assume they want to\n // update handler and render function when the action object changes.\n // This ensures that any captured variables in the handler are up to date.\n if (dependencies === undefined) {\n if (actions[idRef.current]) {\n actions[idRef.current].handler = action.handler as any;\n if (typeof action.render === \"function\") {\n if (chatComponentsCache.current !== null) {\n chatComponentsCache.current.actions[action.name] = action.render;\n }\n }\n }\n }\n\n useEffect(() => {\n setAction(idRef.current, action as any);\n if (chatComponentsCache.current !== null && action.render !== undefined) {\n chatComponentsCache.current.actions[action.name] = action.render;\n }\n return () => {\n // NOTE: For now, we don't remove the chatComponentsCache entry when the action is removed.\n // This is because we currently don't have access to the messages array in CopilotContext.\n removeAction(idRef.current);\n };\n }, [\n setAction,\n removeAction,\n action.description,\n action.name,\n action.disabled,\n // This should be faster than deep equality checking\n // In addition, all major JS engines guarantee the order of object keys\n JSON.stringify(action.parameters),\n // include render only if it's a string\n typeof action.render === \"string\" ? action.render : undefined,\n // dependencies set by the developer\n ...(dependencies || []),\n ]);\n}\n\ninterface RenderAndWaitForResponse {\n promise: Promise<any>;\n resolve: (result: any) => void;\n reject: (error: any) => void;\n}\n"],"mappings":";;;;;;;;;AA2HA,SAAoB,gBAAgB;AACpC,SAAS,eAAe,UAAU,WAAW,cAAc;AAkBpD,SAAS,iBACd,QACA,cACM;AACN,QAAM,EAAE,WAAW,cAAc,SAAS,oBAAoB,IAAI,kBAAkB;AACpF,QAAM,QAAQ,OAAe,SAAS,CAAC;AACvC,QAAM,mBAAmB,OAAwC,IAAI;AAGrE,WAAS,mBAAK;AAId,MAAI,OAAO,iBAAiB,OAAO,0BAA0B;AAC3D,UAAM,gBAAgB,OAAO,iBAAiB,OAAO;AAErD,WAAO,gBAAgB;AACvB,WAAO,2BAA2B;AAElC,WAAO,UAAW,MAAY;AAE5B,UAAI;AACJ,UAAI;AACJ,YAAM,UAAU,IAAI,QAAa,CAAC,gBAAgB,kBAAkB;AAClE,kBAAU;AACV,iBAAS;AAAA,MACX,CAAC;AACD,uBAAiB,UAAU,EAAE,SAAS,SAAmB,OAAgB;AAEzE,aAAO,MAAM;AAAA,IACf;AAGA,WAAO,SAAU,CAAC,UAAoD;AAEpE,YAAM,YAAY;AAAA,QAChB,QAAQ,MAAM;AAAA,QACd,MAAM,MAAM;AAAA,QACZ,QAAQ,MAAM;AAAA,QACd,SAAS,MAAM,WAAW,cAAc,iBAAiB,QAAS,UAAU;AAAA,QAC5E,SAAS,MAAM,WAAW,cAAc,iBAAiB,QAAS,UAAU;AAAA,MAC9E;AAGA,YAAM,qBAAqB,CACzB,QAGyE;AA9LjF;AA+LQ,iBAAO,YAAO,eAAP,mBAAmB,YAAW;AAAA,MACvC;AAGA,UAAI,eAAe;AACjB,YAAI,mBAAmB,aAAa,GAAG;AACrC,iBAAO,cAAc,SAA2C;AAAA,QAClE,OAAO;AACL,iBAAO,cAAc,SAAqC;AAAA,QAC5D;AAAA,MACF;AAGA,aAAO,cAAc,QAAQ;AAAA,IAC/B;AAAA,EACF;AAKA,MAAI,iBAAiB,QAAW;AAC9B,QAAI,QAAQ,MAAM,OAAO,GAAG;AAC1B,cAAQ,MAAM,OAAO,EAAE,UAAU,OAAO;AACxC,UAAI,OAAO,OAAO,WAAW,YAAY;AACvC,YAAI,oBAAoB,YAAY,MAAM;AACxC,8BAAoB,QAAQ,QAAQ,OAAO,IAAI,IAAI,OAAO;AAAA,QAC5D;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,YAAU,MAAM;AACd,cAAU,MAAM,SAAS,MAAa;AACtC,QAAI,oBAAoB,YAAY,QAAQ,OAAO,WAAW,QAAW;AACvE,0BAAoB,QAAQ,QAAQ,OAAO,IAAI,IAAI,OAAO;AAAA,IAC5D;AACA,WAAO,MAAM;AAGX,mBAAa,MAAM,OAAO;AAAA,IAC5B;AAAA,EACF,GAAG;AAAA,IACD;AAAA,IACA;AAAA,IACA,OAAO;AAAA,IACP,OAAO;AAAA,IACP,OAAO;AAAA;AAAA;AAAA,IAGP,KAAK,UAAU,OAAO,UAAU;AAAA;AAAA,IAEhC,OAAO,OAAO,WAAW,WAAW,OAAO,SAAS;AAAA;AAAA,IAEpD,GAAI,gBAAgB,CAAC;AAAA,EACvB,CAAC;AACH;","names":[]}
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -7,8 +7,8 @@ export { useCopilotReadable } from './use-copilot-readable.js';
|
|
|
7
7
|
export { useCoAgent } from './use-coagent.js';
|
|
8
8
|
import '@copilotkit/runtime-client-gql';
|
|
9
9
|
import '../types/system-message.js';
|
|
10
|
-
import '../types/frontend-action.js';
|
|
11
10
|
import '@copilotkit/shared';
|
|
11
|
+
import '../types/frontend-action.js';
|
|
12
12
|
import 'react';
|
|
13
13
|
import '../types/coagent-action.js';
|
|
14
14
|
import '../types/document-pointer.js';
|
package/dist/hooks/index.js
CHANGED
|
@@ -570,16 +570,17 @@ ${additionalInstructions}` : "");
|
|
|
570
570
|
}
|
|
571
571
|
|
|
572
572
|
// src/hooks/use-copilot-action.ts
|
|
573
|
-
var import_react6 = require("react");
|
|
574
573
|
var import_shared3 = require("@copilotkit/shared");
|
|
574
|
+
var import_react6 = require("react");
|
|
575
575
|
function useCopilotAction(action, dependencies) {
|
|
576
576
|
const { setAction, removeAction, actions, chatComponentsCache } = useCopilotContext();
|
|
577
577
|
const idRef = (0, import_react6.useRef)((0, import_shared3.randomId)());
|
|
578
578
|
const renderAndWaitRef = (0, import_react6.useRef)(null);
|
|
579
579
|
action = __spreadValues({}, action);
|
|
580
|
-
if (action.renderAndWait) {
|
|
581
|
-
const renderAndWait = action.renderAndWait;
|
|
580
|
+
if (action.renderAndWait || action.renderAndWaitForResponse) {
|
|
581
|
+
const renderAndWait = action.renderAndWait || action.renderAndWaitForResponse;
|
|
582
582
|
action.renderAndWait = void 0;
|
|
583
|
+
action.renderAndWaitForResponse = void 0;
|
|
583
584
|
action.handler = () => __async(this, null, function* () {
|
|
584
585
|
let resolve;
|
|
585
586
|
let reject;
|
|
@@ -595,9 +596,21 @@ function useCopilotAction(action, dependencies) {
|
|
|
595
596
|
status: props.status,
|
|
596
597
|
args: props.args,
|
|
597
598
|
result: props.result,
|
|
598
|
-
handler: props.status === "executing" ? renderAndWaitRef.current.resolve : void 0
|
|
599
|
+
handler: props.status === "executing" ? renderAndWaitRef.current.resolve : void 0,
|
|
600
|
+
respond: props.status === "executing" ? renderAndWaitRef.current.resolve : void 0
|
|
601
|
+
};
|
|
602
|
+
const isNoArgsRenderWait = (_fn) => {
|
|
603
|
+
var _a;
|
|
604
|
+
return ((_a = action.parameters) == null ? void 0 : _a.length) === 0;
|
|
599
605
|
};
|
|
600
|
-
|
|
606
|
+
if (renderAndWait) {
|
|
607
|
+
if (isNoArgsRenderWait(renderAndWait)) {
|
|
608
|
+
return renderAndWait(waitProps);
|
|
609
|
+
} else {
|
|
610
|
+
return renderAndWait(waitProps);
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
return (0, import_react6.createElement)(import_react6.Fragment);
|
|
601
614
|
};
|
|
602
615
|
}
|
|
603
616
|
if (dependencies === void 0) {
|