@copilotkit/react-core 1.4.0-pre.16 → 1.4.1-pre.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 CHANGED
@@ -1,213 +1,106 @@
1
1
  # ui
2
2
 
3
- ## 1.4.0-pre.16
4
-
5
- ### Minor Changes
6
-
7
- - lgc and lgjs alpha
8
-
9
- ### Patch Changes
10
-
11
- - Updated dependencies
12
- - @copilotkit/runtime-client-gql@1.4.0-pre.16
13
- - @copilotkit/shared@1.4.0-pre.16
14
-
15
- ## 1.4.0-pre.15
16
-
17
- ### Patch Changes
18
-
19
- - No changes
20
- - Updated dependencies
21
- - @copilotkit/runtime-client-gql@1.4.0-pre.15
22
- - @copilotkit/shared@1.4.0-pre.15
23
-
24
- ## 1.4.0-pre-1-4-0.14
25
-
26
- ### Minor Changes
27
-
28
- - lgc & lgjs alpha release
3
+ ## 1.4.1-pre.0
29
4
 
30
5
  ### Patch Changes
31
6
 
32
- - a5efccd: Revert rxjs changes
33
- - Updated dependencies [a5efccd]
7
+ - lower case copilotkit property
34
8
  - Updated dependencies
35
- - @copilotkit/runtime-client-gql@1.4.0-pre-1-4-0.14
36
- - @copilotkit/shared@1.4.0-pre-1-4-0.14
9
+ - @copilotkit/runtime-client-gql@1.4.1-pre.0
10
+ - @copilotkit/shared@1.4.1-pre.0
37
11
 
38
- ## 1.4.0-pre-1-4-0.13
12
+ ## 1.4.0
39
13
 
40
14
  ### Minor Changes
41
15
 
42
- - lgc & lgjs alpha
16
+ CopilotKit Core:
43
17
 
44
- ### Patch Changes
18
+ - Improved error messages and overall logs
19
+ - `useCopilotAction.renderAndAwait` renamed to `.renderAndAwaitForResponse` (backwards compatible, will be deprecated in the future)
20
+ - Improved scrolling behavior. It is now possible to scroll up during LLM response generation
21
+ - Added Azure OpenAI integration
22
+ - Updated interfaces for better developer ergonomics
45
23
 
46
- - Updated dependencies
47
- - @copilotkit/runtime-client-gql@1.4.0-pre-1-4-0.13
48
- - @copilotkit/shared@1.4.0-pre-1-4-0.13
24
+ CoAgents:
49
25
 
50
- ## 1.4.0-pre-1-4-0.12
26
+ - Renamed `remoteActions` to `remoteEndpoints` (backwards compatible, will be deprecated in the future)
27
+ - Support for LangGraph Platform in Remote Endpoints
28
+ - LangGraph JS Support for CoAgents (locally via `langgraph dev`, `langgraph up` or deployed to LangGraph Platform)
29
+ - Improved LangSmith integration - requests made through CoAgents will now surface in LangSmith
30
+ - Enhanced state management and message handling
51
31
 
52
- ### Minor Changes
32
+ CopilotKid Back-end SDK:
53
33
 
54
- - c6b489d: LangGraph Platform and LangGraph JS support
55
- - 7cc6cc8: LangGraph Cloud and LangGraphJS alpha release
56
- - prerelease lgc and lgjs
57
- - Add LangGraph Platform and LangGraph JS support
58
- - b318b18: Add LangGraph Cloud support
34
+ - Released a whole-new `@copilotkit/sdk-js` for building agents with LangGraph JS Support
59
35
 
60
36
  ### Patch Changes
61
37
 
62
- - 9ea9db1: update tsup config
63
- - d52c1f9: update entry
64
- - e71d469: export langchain module
38
+ - f6fab28: update tsup config
39
+ - f6fab28: update entry
40
+ - f6fab28: export langchain module
65
41
  - 8a77944: Improve LangSmith support
66
- - 3caa5d5: Ensure intermediate state config is sent as snake case
67
- - cf3a787: update entry in tsup config
42
+ - f6fab28: Ensure intermediate state config is sent as snake case
43
+ - f6fab28: update entry in tsup config
68
44
  - 8a77944: Ensure the last message is sent to LangSmith
69
- - 264a693: update entry
70
- - dd99f00: Update exports
71
- - a28fb90: Update exports
45
+ - a5efccd: Revert rxjs changes
46
+ - f6fab28: update entry
47
+ - f6fab28: Update exports
48
+ - f6fab28: Update exports
72
49
  - 332d744: Add support for Azure OpenAI
73
- - 1f8032e: Export LangGraph functions
74
- - c3576f6: Update lockfile
75
- - Updated dependencies [9ea9db1]
76
- - Updated dependencies [d52c1f9]
77
- - Updated dependencies [c6b489d]
78
- - Updated dependencies [7cc6cc8]
79
- - Updated dependencies [e71d469]
80
- - Updated dependencies [8a77944]
81
- - Updated dependencies [3caa5d5]
82
- - Updated dependencies [cf3a787]
83
- - Updated dependencies
50
+ - f6fab28: Export LangGraph functions
51
+ - f6fab28: Update lockfile
52
+ - Updated dependencies [f6fab28]
53
+ - Updated dependencies [f6fab28]
84
54
  - Updated dependencies
55
+ - Updated dependencies [f6fab28]
85
56
  - Updated dependencies [8a77944]
86
- - Updated dependencies [264a693]
87
- - Updated dependencies [dd99f00]
88
- - Updated dependencies [a28fb90]
57
+ - Updated dependencies [f6fab28]
58
+ - Updated dependencies [f6fab28]
59
+ - Updated dependencies [8a77944]
60
+ - Updated dependencies [a5efccd]
61
+ - Updated dependencies [f6fab28]
62
+ - Updated dependencies [f6fab28]
63
+ - Updated dependencies [f6fab28]
89
64
  - Updated dependencies [332d744]
90
- - Updated dependencies [b318b18]
91
- - Updated dependencies [1f8032e]
92
- - Updated dependencies [c3576f6]
93
- - @copilotkit/runtime-client-gql@1.4.0-pre-1-4-0.12
94
- - @copilotkit/shared@1.4.0-pre-1-4-0.12
95
-
96
- ## 1.4.0-pre-1-4-0.11
97
-
98
- ### Minor Changes
99
-
100
- - LangGraph Platform and LangGraph JS support
101
-
102
- ### Patch Changes
103
-
104
- - Updated dependencies
105
- - @copilotkit/runtime-client-gql@1.4.0-pre-1-4-0.11
106
- - @copilotkit/shared@1.4.0-pre-1-4-0.11
107
-
108
- ## 1.4.0-pre-1-4-0.10
109
-
110
- ### Minor Changes
111
-
112
- - LangGraph Cloud and LangGraphJS alpha release
113
- - b318b18: Add LangGraph Cloud support
114
-
115
- ### Patch Changes
116
-
117
- - Updated dependencies
118
- - Updated dependencies [b318b18]
119
- - @copilotkit/runtime-client-gql@1.4.0-pre-1-4-0.10
120
- - @copilotkit/shared@1.4.0-pre-1-4-0.10
121
-
122
- ## 1.3.16-mme-lgc-langgraph-package.9
123
-
124
- ### Patch Changes
125
-
126
- - update entry
127
- - Updated dependencies
128
- - @copilotkit/runtime-client-gql@1.3.16-mme-lgc-langgraph-package.9
129
- - @copilotkit/shared@1.3.16-mme-lgc-langgraph-package.9
65
+ - Updated dependencies [f6fab28]
66
+ - Updated dependencies [f6fab28]
67
+ - @copilotkit/runtime-client-gql@1.4.0
68
+ - @copilotkit/shared@1.4.0
130
69
 
131
- ## 1.3.16-mme-lgc-langgraph-package.8
70
+ ## 1.3.16-mme-revert-rxjs-changes.10
132
71
 
133
72
  ### Patch Changes
134
73
 
135
- - update entry
136
- - Updated dependencies
137
- - @copilotkit/runtime-client-gql@1.3.16-mme-lgc-langgraph-package.8
138
- - @copilotkit/shared@1.3.16-mme-lgc-langgraph-package.8
139
-
140
- ## 1.3.16-mme-lgc-langgraph-package.7
141
-
142
- ### Patch Changes
143
-
144
- - update entry in tsup config
145
- - Updated dependencies
146
- - @copilotkit/runtime-client-gql@1.3.16-mme-lgc-langgraph-package.7
147
- - @copilotkit/shared@1.3.16-mme-lgc-langgraph-package.7
148
-
149
- ## 1.3.16-mme-lgc-langgraph-package.6
150
-
151
- ### Patch Changes
152
-
153
- - Update exports
154
- - Updated dependencies
155
- - @copilotkit/runtime-client-gql@1.3.16-mme-lgc-langgraph-package.6
156
- - @copilotkit/shared@1.3.16-mme-lgc-langgraph-package.6
157
-
158
- ## 1.3.16-mme-lgc-langgraph-package.5
159
-
160
- ### Patch Changes
161
-
162
- - update tsup config
163
- - Updated dependencies
164
- - @copilotkit/runtime-client-gql@1.3.16-mme-lgc-langgraph-package.5
165
- - @copilotkit/shared@1.3.16-mme-lgc-langgraph-package.5
166
-
167
- ## 1.3.16-mme-lgc-langgraph-package.4
168
-
169
- ### Patch Changes
170
-
171
- - Update exports
172
- - Updated dependencies
173
- - @copilotkit/runtime-client-gql@1.3.16-mme-lgc-langgraph-package.4
174
- - @copilotkit/shared@1.3.16-mme-lgc-langgraph-package.4
175
-
176
- ## 1.3.16-mme-lgc-langgraph-package.3
177
-
178
- ### Patch Changes
179
-
180
- - export langchain module
181
- - Updated dependencies
182
- - @copilotkit/runtime-client-gql@1.3.16-mme-lgc-langgraph-package.3
183
- - @copilotkit/shared@1.3.16-mme-lgc-langgraph-package.3
184
-
185
- ## 1.3.16-mme-sdk-js.2
186
-
187
- ### Patch Changes
188
-
189
- - Ensure intermediate state config is sent as snake case
190
- - Updated dependencies
191
- - @copilotkit/runtime-client-gql@1.3.16-mme-sdk-js.2
192
- - @copilotkit/shared@1.3.16-mme-sdk-js.2
193
-
194
- ## 1.3.16-mme-sdk-js.1
195
-
196
- ### Patch Changes
197
-
198
- - Update lockfile
199
- - Updated dependencies
200
- - @copilotkit/runtime-client-gql@1.3.16-mme-sdk-js.1
201
- - @copilotkit/shared@1.3.16-mme-sdk-js.1
202
-
203
- ## 1.3.16-mme-sdk-js.0
204
-
205
- ### Patch Changes
206
-
207
- - Export LangGraph functions
74
+ - f6fab28: update tsup config
75
+ - f6fab28: update entry
76
+ - f6fab28: export langchain module
77
+ - 8a77944: Improve LangSmith support
78
+ - f6fab28: Ensure intermediate state config is sent as snake case
79
+ - f6fab28: update entry in tsup config
80
+ - 8a77944: Ensure the last message is sent to LangSmith
81
+ - Revert rxjs changes
82
+ - f6fab28: update entry
83
+ - f6fab28: Update exports
84
+ - f6fab28: Update exports
85
+ - 332d744: Add support for Azure OpenAI
86
+ - f6fab28: Export LangGraph functions
87
+ - f6fab28: Update lockfile
88
+ - Updated dependencies [f6fab28]
89
+ - Updated dependencies [f6fab28]
90
+ - Updated dependencies [f6fab28]
91
+ - Updated dependencies [8a77944]
92
+ - Updated dependencies [f6fab28]
93
+ - Updated dependencies [f6fab28]
94
+ - Updated dependencies [8a77944]
208
95
  - Updated dependencies
209
- - @copilotkit/runtime-client-gql@1.3.16-mme-sdk-js.0
210
- - @copilotkit/shared@1.3.16-mme-sdk-js.0
96
+ - Updated dependencies [f6fab28]
97
+ - Updated dependencies [f6fab28]
98
+ - Updated dependencies [f6fab28]
99
+ - Updated dependencies [332d744]
100
+ - Updated dependencies [f6fab28]
101
+ - Updated dependencies [f6fab28]
102
+ - @copilotkit/runtime-client-gql@1.3.16-mme-revert-rxjs-changes.10
103
+ - @copilotkit/shared@1.3.16-mme-revert-rxjs-changes.10
211
104
 
212
105
  ## 1.3.15
213
106
 
@@ -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
- return renderAndWait(waitProps);
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-RYDEG77L.mjs.map
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,EAA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;AAAA,IAEhC,OAAO,OAAO,WAAW,WAAW,OAAO,SAAS;AAAA;AAAA,IAEpD,GAAI,gBAAgB,CAAC;AAAA,EACvB,CAAC;AACH;","names":[]}
@@ -123,4 +123,4 @@ function runAgent(name, context, appendMessage, hint) {
123
123
  export {
124
124
  useCoAgent
125
125
  };
126
- //# sourceMappingURL=chunk-XACBOJF5.mjs.map
126
+ //# sourceMappingURL=chunk-K4HZL7SA.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/hooks/use-coagent.ts"],"sourcesContent":["/**\n * <Callout type=\"info\">\n * Usage of this hook assumes some additional setup in your application, for more information\n * on that see the CoAgents <span className=\"text-blue-500\">[getting started guide](/coagents/quickstart)</span>.\n * </Callout>\n * <Frame className=\"my-12\">\n * <img\n * src=\"/images/coagents/SharedStateCoAgents.gif\"\n * alt=\"CoAgents demonstration\"\n * className=\"w-auto\"\n * />\n * </Frame>\n *\n * This hook is used to integrate an agent into your application. With its use, you can\n * render and update the state of an agent, allowing for a dynamic and interactive experience.\n * We call these shared state experiences agentic copilots, or CoAgents for short.\n *\n * ## Usage\n *\n * ### Simple Usage\n *\n * ```tsx\n * import { useCoAgent } from \"@copilotkit/react-core\";\n *\n * type AgentState = {\n * count: number;\n * }\n *\n * const agent = useCoAgent<AgentState>({\n * name: \"my-agent\",\n * initialState: {\n * count: 0,\n * },\n * });\n *\n * ```\n *\n * `useCoAgent` returns an object with the following properties:\n *\n * ```tsx\n * const {\n * name, // The name of the agent currently being used.\n * nodeName, // The name of the current LangGraph node.\n * state, // The current state of the agent.\n * setState, // A function to update the state of the agent.\n * running, // A boolean indicating if the agent is currently running.\n * start, // A function to start the agent.\n * stop, // A function to stop the agent.\n * run, // A function to re-run the agent. Takes a HintFunction to inform the agent why it is being re-run.\n * } = agent;\n * ```\n *\n * Finally we can leverage these properties to create reactive experiences with the agent!\n *\n * ```tsx\n * const { state, setState } = useCoAgent<AgentState>({\n * name: \"my-agent\",\n * initialState: {\n * count: 0,\n * },\n * });\n *\n * return (\n * <div>\n * <p>Count: {state.count}</p>\n * <button onClick={() => setState({ count: state.count + 1 })}>Increment</button>\n * </div>\n * );\n * ```\n *\n * This reactivity is bidirectional, meaning that changes to the state from the agent will be reflected in the UI and vice versa.\n *\n * ## Parameters\n * <PropertyReference name=\"options\" type=\"UseCoagentOptions<T>\" required>\n * The options to use when creating the coagent.\n * <PropertyReference name=\"name\" type=\"string\" required>\n * The name of the agent to use.\n * </PropertyReference>\n * <PropertyReference name=\"initialState\" type=\"T | any\">\n * The initial state of the agent.\n * </PropertyReference>\n * <PropertyReference name=\"state\" type=\"T | any\">\n * State to manage externally if you are using this hook with external state management.\n * </PropertyReference>\n * <PropertyReference name=\"setState\" type=\"(newState: T | ((prevState: T | undefined) => T)) => void\">\n * A function to update the state of the agent if you are using this hook with external state management.\n * </PropertyReference>\n * </PropertyReference>\n */\n\nimport { useEffect } from \"react\";\nimport {\n CopilotContextParams,\n CopilotMessagesContextParams,\n useCopilotContext,\n useCopilotMessagesContext,\n} from \"../context\";\nimport { CoagentState } from \"../types/coagent-state\";\nimport { useCopilotChat } from \"./use-copilot-chat\";\nimport { AgentStateMessage, Message, Role, TextMessage } from \"@copilotkit/runtime-client-gql\";\n\ninterface WithInternalStateManagementAndInitial<T> {\n /**\n * The name of the agent being used.\n */\n name: string;\n /**\n * The initial state of the agent.\n */\n initialState: T;\n}\n\ninterface WithInternalStateManagement {\n /**\n * The name of the agent being used.\n */\n name: string;\n /**\n * Optional initialState with default type any\n */\n initialState?: any;\n}\n\ninterface WithExternalStateManagement<T> {\n /**\n * The name of the agent being used.\n */\n name: string;\n /**\n * The current state of the agent.\n */\n state: T;\n /**\n * A function to update the state of the agent.\n */\n setState: (newState: T | ((prevState: T | undefined) => T)) => void;\n}\n\ntype UseCoagentOptions<T> =\n | WithInternalStateManagementAndInitial<T>\n | WithInternalStateManagement\n | WithExternalStateManagement<T>;\n\nexport interface UseCoagentReturnType<T> {\n /**\n * The name of the agent being used.\n */\n name: string;\n /**\n * The name of the current LangGraph node.\n */\n nodeName?: string;\n /**\n * The ID of the thread the agent is running in.\n */\n threadId?: string;\n /**\n * A boolean indicating if the agent is currently running.\n */\n running: boolean;\n /**\n * The current state of the agent.\n */\n state: T;\n /**\n * A function to update the state of the agent.\n */\n setState: (newState: T | ((prevState: T | undefined) => T)) => void;\n /**\n * A function to start the agent.\n */\n start: () => void;\n /**\n * A function to stop the agent.\n */\n stop: () => void;\n /**\n * A function to re-run the agent. The hint function can be used to provide a hint to the agent\n * about why it is being re-run again.\n */\n run: (hint?: HintFunction) => Promise<void>;\n}\n\nexport interface HintFunctionParams {\n /**\n * The previous state of the agent.\n */\n previousState: any;\n /**\n * The current state of the agent.\n */\n currentState: any;\n}\n\nexport type HintFunction = (params: HintFunctionParams) => Message | undefined;\n\n/**\n * This hook is used to integrate an agent into your application. With its use, you can\n * render and update the state of the agent, allowing for a dynamic and interactive experience.\n * We call these shared state experiences \"agentic copilots\". To get started using agentic copilots, which\n * we refer to as CoAgents, checkout the documentation at https://docs.copilotkit.ai/coagents/quickstart.\n */\nexport function useCoAgent<T = any>(options: UseCoagentOptions<T>): UseCoagentReturnType<T> {\n const isExternalStateManagement = (\n options: UseCoagentOptions<T>,\n ): options is WithExternalStateManagement<T> => {\n return \"state\" in options && \"setState\" in options;\n };\n\n const { name } = options;\n\n const isInternalStateManagementWithInitial = (\n options: UseCoagentOptions<T>,\n ): options is WithInternalStateManagementAndInitial<T> => {\n return \"initialState\" in options;\n };\n\n const generalContext = useCopilotContext();\n const messagesContext = useCopilotMessagesContext();\n const context = { ...generalContext, ...messagesContext };\n const { coagentStates, setCoagentStates } = context;\n const { appendMessage } = useCopilotChat();\n\n const getCoagentState = (coagentStates: Record<string, CoagentState>, name: string) => {\n if (coagentStates[name]) {\n return coagentStates[name];\n } else {\n return {\n name,\n state: isInternalStateManagementWithInitial(options) ? options.initialState : {},\n running: false,\n active: false,\n threadId: undefined,\n nodeName: undefined,\n runId: undefined,\n };\n }\n };\n\n // if we manage state internally, we need to provide a function to set the state\n const setState = (newState: T | ((prevState: T | undefined) => T)) => {\n setCoagentStates((prevAgentStates) => {\n let coagentState: CoagentState = getCoagentState(prevAgentStates, name);\n\n const updatedState =\n typeof newState === \"function\" ? (newState as Function)(coagentState.state) : newState;\n\n return {\n ...prevAgentStates,\n [name]: {\n ...coagentState,\n state: updatedState,\n },\n };\n });\n };\n\n const coagentState = getCoagentState(coagentStates, name);\n\n const state = isExternalStateManagement(options) ? options.state : coagentState.state;\n\n // Sync internal state with external state if state management is external\n useEffect(() => {\n if (isExternalStateManagement(options)) {\n setState(options.state);\n } else if (coagentStates[name] === undefined) {\n setState(options.initialState === undefined ? {} : options.initialState);\n }\n }, [isExternalStateManagement(options) ? JSON.stringify(options.state) : undefined]);\n\n // Return the state and setState function\n return {\n name,\n nodeName: coagentState.nodeName,\n state,\n setState,\n running: coagentState.running,\n start: () => {\n startAgent(name, context);\n },\n stop: () => {\n stopAgent(name, context);\n },\n run: (hint?: HintFunction) => {\n return runAgent(name, context, appendMessage, hint);\n },\n };\n}\n\nfunction startAgent(name: string, context: CopilotContextParams) {\n const { setAgentSession } = context;\n setAgentSession({\n agentName: name,\n });\n}\n\nfunction stopAgent(name: string, context: CopilotContextParams) {\n const { agentSession, setAgentSession } = context;\n if (agentSession && agentSession.agentName === name) {\n setAgentSession(null);\n } else {\n console.warn(`No agent session found for ${name}`);\n }\n}\n\nasync function runAgent(\n name: string,\n context: CopilotContextParams & CopilotMessagesContextParams,\n appendMessage: (message: Message) => Promise<void>,\n hint?: HintFunction,\n) {\n const { agentSession, setAgentSession } = context;\n if (!agentSession || agentSession.agentName !== name) {\n setAgentSession({\n agentName: name,\n });\n }\n\n let previousState: any = null;\n for (let i = context.messages.length - 1; i >= 0; i--) {\n const message = context.messages[i];\n if (message.isAgentStateMessage() && message.agentName === name) {\n previousState = message.state;\n }\n }\n\n let state = context.coagentStates?.[name]?.state || {};\n\n if (hint) {\n const hintMessage = hint({ previousState, curr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,QAAQ,cAAc,MAAM;AAC/D,wBAAgB,QAAQ;AAAA,MAC1B;AAAA,IACF;AAEA,QAAI,UAAQ,mBAAQ,kBAAR,mBAAwB,UAAxB,mBAA+B,UAAS,CAAC;AAErD,QAAI,MAAM;AACR,YAAM,cAAc,KAAK,EAAE,eAAe,cAAc,MAAM,CAAC;AAC/D,UAAI,aAAa;AACf,cAAM,cAAc,WAAW;AAAA,MACjC;AAAA,IACF;AAAA,EACF;AAAA;","names":["options","coagentStates","name","coagentState"]}
@@ -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';
@@ -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
- return renderAndWait(waitProps);
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) {