@copilotkit/react-core 1.5.1-next.3 → 1.5.1-next.4

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.
Files changed (228) hide show
  1. package/CHANGELOG.md +11 -2
  2. package/package.json +5 -5
  3. package/dist/chunk-2KCEHGSI.mjs +0 -192
  4. package/dist/chunk-2KCEHGSI.mjs.map +0 -1
  5. package/dist/chunk-5FHSUKQL.mjs +0 -70
  6. package/dist/chunk-5FHSUKQL.mjs.map +0 -1
  7. package/dist/chunk-6OR25P32.mjs +0 -426
  8. package/dist/chunk-6OR25P32.mjs.map +0 -1
  9. package/dist/chunk-6U3UH3KO.mjs +0 -140
  10. package/dist/chunk-6U3UH3KO.mjs.map +0 -1
  11. package/dist/chunk-DCTJZ742.mjs +0 -22
  12. package/dist/chunk-DCTJZ742.mjs.map +0 -1
  13. package/dist/chunk-DDVXFNYA.mjs +0 -126
  14. package/dist/chunk-DDVXFNYA.mjs.map +0 -1
  15. package/dist/chunk-EFZPSZWO.mjs +0 -1
  16. package/dist/chunk-EFZPSZWO.mjs.map +0 -1
  17. package/dist/chunk-FXHKK52V.mjs +0 -119
  18. package/dist/chunk-FXHKK52V.mjs.map +0 -1
  19. package/dist/chunk-H4VZMKR6.mjs +0 -23
  20. package/dist/chunk-H4VZMKR6.mjs.map +0 -1
  21. package/dist/chunk-H7LSKIDK.mjs +0 -167
  22. package/dist/chunk-H7LSKIDK.mjs.map +0 -1
  23. package/dist/chunk-JDQCJCAQ.mjs +0 -295
  24. package/dist/chunk-JDQCJCAQ.mjs.map +0 -1
  25. package/dist/chunk-L34MHAXR.mjs +0 -1
  26. package/dist/chunk-L34MHAXR.mjs.map +0 -1
  27. package/dist/chunk-LODRWFMB.mjs +0 -75
  28. package/dist/chunk-LODRWFMB.mjs.map +0 -1
  29. package/dist/chunk-LUGEI4YQ.mjs +0 -1
  30. package/dist/chunk-LUGEI4YQ.mjs.map +0 -1
  31. package/dist/chunk-MLAS4QUR.mjs +0 -18
  32. package/dist/chunk-MLAS4QUR.mjs.map +0 -1
  33. package/dist/chunk-MWZO6TUR.mjs +0 -91
  34. package/dist/chunk-MWZO6TUR.mjs.map +0 -1
  35. package/dist/chunk-O7ARI5CV.mjs +0 -31
  36. package/dist/chunk-O7ARI5CV.mjs.map +0 -1
  37. package/dist/chunk-ODN4H66E.mjs +0 -31
  38. package/dist/chunk-ODN4H66E.mjs.map +0 -1
  39. package/dist/chunk-QDGDXRRJ.mjs +0 -28
  40. package/dist/chunk-QDGDXRRJ.mjs.map +0 -1
  41. package/dist/chunk-SKC7AJIV.mjs +0 -61
  42. package/dist/chunk-SKC7AJIV.mjs.map +0 -1
  43. package/dist/chunk-XINZBP3J.mjs +0 -49
  44. package/dist/chunk-XINZBP3J.mjs.map +0 -1
  45. package/dist/chunk-XXR4QFAQ.mjs +0 -29
  46. package/dist/chunk-XXR4QFAQ.mjs.map +0 -1
  47. package/dist/chunk-YPSGKPDA.mjs +0 -1
  48. package/dist/chunk-YPSGKPDA.mjs.map +0 -1
  49. package/dist/components/copilot-provider/copilot-messages.d.ts +0 -7
  50. package/dist/components/copilot-provider/copilot-messages.js +0 -80
  51. package/dist/components/copilot-provider/copilot-messages.js.map +0 -1
  52. package/dist/components/copilot-provider/copilot-messages.mjs +0 -9
  53. package/dist/components/copilot-provider/copilot-messages.mjs.map +0 -1
  54. package/dist/components/copilot-provider/copilotkit-props.d.ts +0 -72
  55. package/dist/components/copilot-provider/copilotkit-props.js +0 -19
  56. package/dist/components/copilot-provider/copilotkit-props.js.map +0 -1
  57. package/dist/components/copilot-provider/copilotkit-props.mjs +0 -1
  58. package/dist/components/copilot-provider/copilotkit-props.mjs.map +0 -1
  59. package/dist/components/copilot-provider/copilotkit.d.ts +0 -9
  60. package/dist/components/copilot-provider/copilotkit.js +0 -861
  61. package/dist/components/copilot-provider/copilotkit.js.map +0 -1
  62. package/dist/components/copilot-provider/copilotkit.mjs +0 -21
  63. package/dist/components/copilot-provider/copilotkit.mjs.map +0 -1
  64. package/dist/components/copilot-provider/index.d.ts +0 -4
  65. package/dist/components/copilot-provider/index.js +0 -861
  66. package/dist/components/copilot-provider/index.js.map +0 -1
  67. package/dist/components/copilot-provider/index.mjs +0 -19
  68. package/dist/components/copilot-provider/index.mjs.map +0 -1
  69. package/dist/components/index.d.ts +0 -4
  70. package/dist/components/index.js +0 -861
  71. package/dist/components/index.js.map +0 -1
  72. package/dist/components/index.mjs +0 -19
  73. package/dist/components/index.mjs.map +0 -1
  74. package/dist/components/toast/exclamation-mark-icon.d.ts +0 -9
  75. package/dist/components/toast/exclamation-mark-icon.js +0 -55
  76. package/dist/components/toast/exclamation-mark-icon.js.map +0 -1
  77. package/dist/components/toast/exclamation-mark-icon.mjs +0 -8
  78. package/dist/components/toast/exclamation-mark-icon.mjs.map +0 -1
  79. package/dist/components/toast/toast-provider.d.ts +0 -29
  80. package/dist/components/toast/toast-provider.js +0 -255
  81. package/dist/components/toast/toast-provider.js.map +0 -1
  82. package/dist/components/toast/toast-provider.mjs +0 -11
  83. package/dist/components/toast/toast-provider.mjs.map +0 -1
  84. package/dist/context/copilot-context.d.ts +0 -109
  85. package/dist/context/copilot-context.js +0 -126
  86. package/dist/context/copilot-context.js.map +0 -1
  87. package/dist/context/copilot-context.mjs +0 -10
  88. package/dist/context/copilot-context.mjs.map +0 -1
  89. package/dist/context/copilot-messages-context.d.ts +0 -15
  90. package/dist/context/copilot-messages-context.js +0 -57
  91. package/dist/context/copilot-messages-context.js.map +0 -1
  92. package/dist/context/copilot-messages-context.mjs +0 -10
  93. package/dist/context/copilot-messages-context.mjs.map +0 -1
  94. package/dist/context/index.d.ts +0 -11
  95. package/dist/context/index.js +0 -149
  96. package/dist/context/index.js.map +0 -1
  97. package/dist/context/index.mjs +0 -17
  98. package/dist/context/index.mjs.map +0 -1
  99. package/dist/hooks/index.d.ts +0 -19
  100. package/dist/hooks/index.js +0 -897
  101. package/dist/hooks/index.js.map +0 -1
  102. package/dist/hooks/index.mjs +0 -44
  103. package/dist/hooks/index.mjs.map +0 -1
  104. package/dist/hooks/use-chat.d.ts +0 -92
  105. package/dist/hooks/use-chat.js +0 -360
  106. package/dist/hooks/use-chat.js.map +0 -1
  107. package/dist/hooks/use-chat.mjs +0 -11
  108. package/dist/hooks/use-chat.mjs.map +0 -1
  109. package/dist/hooks/use-coagent-state-render.d.ts +0 -60
  110. package/dist/hooks/use-coagent-state-render.js +0 -160
  111. package/dist/hooks/use-coagent-state-render.js.map +0 -1
  112. package/dist/hooks/use-coagent-state-render.mjs +0 -9
  113. package/dist/hooks/use-coagent-state-render.mjs.map +0 -1
  114. package/dist/hooks/use-coagent.d.ts +0 -186
  115. package/dist/hooks/use-coagent.js +0 -726
  116. package/dist/hooks/use-coagent.js.map +0 -1
  117. package/dist/hooks/use-coagent.mjs +0 -21
  118. package/dist/hooks/use-coagent.mjs.map +0 -1
  119. package/dist/hooks/use-copilot-action.d.ts +0 -130
  120. package/dist/hooks/use-copilot-action.js +0 -219
  121. package/dist/hooks/use-copilot-action.js.map +0 -1
  122. package/dist/hooks/use-copilot-action.mjs +0 -9
  123. package/dist/hooks/use-copilot-action.mjs.map +0 -1
  124. package/dist/hooks/use-copilot-chat.d.ts +0 -36
  125. package/dist/hooks/use-copilot-chat.js +0 -623
  126. package/dist/hooks/use-copilot-chat.js.map +0 -1
  127. package/dist/hooks/use-copilot-chat.mjs +0 -22
  128. package/dist/hooks/use-copilot-chat.mjs.map +0 -1
  129. package/dist/hooks/use-copilot-readable.d.ts +0 -33
  130. package/dist/hooks/use-copilot-readable.js +0 -146
  131. package/dist/hooks/use-copilot-readable.js.map +0 -1
  132. package/dist/hooks/use-copilot-readable.mjs +0 -9
  133. package/dist/hooks/use-copilot-readable.mjs.map +0 -1
  134. package/dist/hooks/use-copilot-runtime-client.d.ts +0 -5
  135. package/dist/hooks/use-copilot-runtime-client.js +0 -76
  136. package/dist/hooks/use-copilot-runtime-client.js.map +0 -1
  137. package/dist/hooks/use-copilot-runtime-client.mjs +0 -10
  138. package/dist/hooks/use-copilot-runtime-client.mjs.map +0 -1
  139. package/dist/hooks/use-flat-category-store.d.ts +0 -9
  140. package/dist/hooks/use-flat-category-store.js +0 -90
  141. package/dist/hooks/use-flat-category-store.js.map +0 -1
  142. package/dist/hooks/use-flat-category-store.mjs +0 -8
  143. package/dist/hooks/use-flat-category-store.mjs.map +0 -1
  144. package/dist/hooks/use-make-copilot-document-readable.d.ts +0 -12
  145. package/dist/hooks/use-make-copilot-document-readable.js +0 -141
  146. package/dist/hooks/use-make-copilot-document-readable.js.map +0 -1
  147. package/dist/hooks/use-make-copilot-document-readable.mjs +0 -9
  148. package/dist/hooks/use-make-copilot-document-readable.mjs.map +0 -1
  149. package/dist/hooks/use-tree.d.ts +0 -18
  150. package/dist/hooks/use-tree.js +0 -172
  151. package/dist/hooks/use-tree.js.map +0 -1
  152. package/dist/hooks/use-tree.mjs +0 -8
  153. package/dist/hooks/use-tree.mjs.map +0 -1
  154. package/dist/index.d.ts +0 -26
  155. package/dist/index.js +0 -1810
  156. package/dist/index.js.map +0 -1
  157. package/dist/index.mjs +0 -71
  158. package/dist/index.mjs.map +0 -1
  159. package/dist/lib/copilot-task.d.ts +0 -92
  160. package/dist/lib/copilot-task.js +0 -157
  161. package/dist/lib/copilot-task.js.map +0 -1
  162. package/dist/lib/copilot-task.mjs +0 -18
  163. package/dist/lib/copilot-task.mjs.map +0 -1
  164. package/dist/lib/index.d.ts +0 -11
  165. package/dist/lib/index.js +0 -159
  166. package/dist/lib/index.js.map +0 -1
  167. package/dist/lib/index.mjs +0 -19
  168. package/dist/lib/index.mjs.map +0 -1
  169. package/dist/types/chat-suggestion-configuration.d.ts +0 -22
  170. package/dist/types/chat-suggestion-configuration.js +0 -19
  171. package/dist/types/chat-suggestion-configuration.js.map +0 -1
  172. package/dist/types/chat-suggestion-configuration.mjs +0 -1
  173. package/dist/types/chat-suggestion-configuration.mjs.map +0 -1
  174. package/dist/types/coagent-action.d.ts +0 -29
  175. package/dist/types/coagent-action.js +0 -19
  176. package/dist/types/coagent-action.js.map +0 -1
  177. package/dist/types/coagent-action.mjs +0 -1
  178. package/dist/types/coagent-action.mjs.map +0 -1
  179. package/dist/types/coagent-state.d.ts +0 -11
  180. package/dist/types/coagent-state.js +0 -19
  181. package/dist/types/coagent-state.js.map +0 -1
  182. package/dist/types/coagent-state.mjs +0 -1
  183. package/dist/types/coagent-state.mjs.map +0 -1
  184. package/dist/types/document-pointer.d.ts +0 -9
  185. package/dist/types/document-pointer.js +0 -19
  186. package/dist/types/document-pointer.js.map +0 -1
  187. package/dist/types/document-pointer.mjs +0 -1
  188. package/dist/types/document-pointer.mjs.map +0 -1
  189. package/dist/types/frontend-action.d.ts +0 -107
  190. package/dist/types/frontend-action.js +0 -19
  191. package/dist/types/frontend-action.js.map +0 -1
  192. package/dist/types/frontend-action.mjs +0 -1
  193. package/dist/types/frontend-action.mjs.map +0 -1
  194. package/dist/types/index.d.ts +0 -6
  195. package/dist/types/index.js +0 -19
  196. package/dist/types/index.js.map +0 -1
  197. package/dist/types/index.mjs +0 -2
  198. package/dist/types/index.mjs.map +0 -1
  199. package/dist/types/system-message.d.ts +0 -3
  200. package/dist/types/system-message.js +0 -19
  201. package/dist/types/system-message.js.map +0 -1
  202. package/dist/types/system-message.mjs +0 -1
  203. package/dist/types/system-message.mjs.map +0 -1
  204. package/dist/utils/dev-console.d.ts +0 -3
  205. package/dist/utils/dev-console.js +0 -42
  206. package/dist/utils/dev-console.js.map +0 -1
  207. package/dist/utils/dev-console.mjs +0 -8
  208. package/dist/utils/dev-console.mjs.map +0 -1
  209. package/dist/utils/extract.d.ts +0 -42
  210. package/dist/utils/extract.js +0 -190
  211. package/dist/utils/extract.js.map +0 -1
  212. package/dist/utils/extract.mjs +0 -17
  213. package/dist/utils/extract.mjs.map +0 -1
  214. package/dist/utils/index.d.ts +0 -13
  215. package/dist/utils/index.js +0 -208
  216. package/dist/utils/index.js.map +0 -1
  217. package/dist/utils/index.mjs +0 -20
  218. package/dist/utils/index.mjs.map +0 -1
  219. package/dist/utils/utils.d.ts +0 -2
  220. package/dist/utils/utils.js +0 -19
  221. package/dist/utils/utils.js.map +0 -1
  222. package/dist/utils/utils.mjs +0 -1
  223. package/dist/utils/utils.mjs.map +0 -1
  224. package/dist/utils/utils.test.d.ts +0 -2
  225. package/dist/utils/utils.test.js +0 -9
  226. package/dist/utils/utils.test.js.map +0 -1
  227. package/dist/utils/utils.test.mjs +0 -7
  228. package/dist/utils/utils.test.mjs.map +0 -1
@@ -1,897 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __defProps = Object.defineProperties;
5
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
7
- var __getOwnPropNames = Object.getOwnPropertyNames;
8
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
9
- var __getProtoOf = Object.getPrototypeOf;
10
- var __hasOwnProp = Object.prototype.hasOwnProperty;
11
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
12
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
13
- var __spreadValues = (a, b) => {
14
- for (var prop in b || (b = {}))
15
- if (__hasOwnProp.call(b, prop))
16
- __defNormalProp(a, prop, b[prop]);
17
- if (__getOwnPropSymbols)
18
- for (var prop of __getOwnPropSymbols(b)) {
19
- if (__propIsEnum.call(b, prop))
20
- __defNormalProp(a, prop, b[prop]);
21
- }
22
- return a;
23
- };
24
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
25
- var __objRest = (source, exclude) => {
26
- var target = {};
27
- for (var prop in source)
28
- if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
29
- target[prop] = source[prop];
30
- if (source != null && __getOwnPropSymbols)
31
- for (var prop of __getOwnPropSymbols(source)) {
32
- if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
33
- target[prop] = source[prop];
34
- }
35
- return target;
36
- };
37
- var __export = (target, all) => {
38
- for (var name in all)
39
- __defProp(target, name, { get: all[name], enumerable: true });
40
- };
41
- var __copyProps = (to, from, except, desc) => {
42
- if (from && typeof from === "object" || typeof from === "function") {
43
- for (let key of __getOwnPropNames(from))
44
- if (!__hasOwnProp.call(to, key) && key !== except)
45
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
46
- }
47
- return to;
48
- };
49
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
50
- // If the importer is in node compatibility mode or this is not an ESM
51
- // file that has been converted to a CommonJS file using a Babel-
52
- // compatible transform (i.e. "__esModule" has not been set), then set
53
- // "default" to the CommonJS "module.exports" for node compatibility.
54
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
55
- mod
56
- ));
57
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
58
- var __async = (__this, __arguments, generator) => {
59
- return new Promise((resolve, reject) => {
60
- var fulfilled = (value) => {
61
- try {
62
- step(generator.next(value));
63
- } catch (e) {
64
- reject(e);
65
- }
66
- };
67
- var rejected = (value) => {
68
- try {
69
- step(generator.throw(value));
70
- } catch (e) {
71
- reject(e);
72
- }
73
- };
74
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
75
- step((generator = generator.apply(__this, __arguments)).next());
76
- });
77
- };
78
-
79
- // src/hooks/index.ts
80
- var hooks_exports = {};
81
- __export(hooks_exports, {
82
- useCoAgent: () => useCoAgent,
83
- useCoAgentStateRender: () => useCoAgentStateRender,
84
- useCopilotAction: () => useCopilotAction,
85
- useCopilotChat: () => useCopilotChat,
86
- useCopilotReadable: () => useCopilotReadable,
87
- useCopilotRuntimeClient: () => useCopilotRuntimeClient,
88
- useMakeCopilotDocumentReadable: () => useMakeCopilotDocumentReadable
89
- });
90
- module.exports = __toCommonJS(hooks_exports);
91
-
92
- // src/hooks/use-copilot-chat.ts
93
- var import_react7 = require("react");
94
-
95
- // src/context/copilot-context.tsx
96
- var import_react = __toESM(require("react"));
97
- var emptyCopilotContext = {
98
- actions: {},
99
- setAction: () => {
100
- },
101
- removeAction: () => {
102
- },
103
- coAgentStateRenders: {},
104
- setCoAgentStateRender: () => {
105
- },
106
- removeCoAgentStateRender: () => {
107
- },
108
- chatComponentsCache: { current: { actions: {}, coAgentStateRenders: {} } },
109
- getContextString: (documents, categories) => returnAndThrowInDebug(""),
110
- addContext: () => "",
111
- removeContext: () => {
112
- },
113
- getFunctionCallHandler: () => returnAndThrowInDebug(() => __async(void 0, null, function* () {
114
- })),
115
- isLoading: false,
116
- setIsLoading: () => returnAndThrowInDebug(false),
117
- chatInstructions: "",
118
- setChatInstructions: () => returnAndThrowInDebug(""),
119
- getDocumentsContext: (categories) => returnAndThrowInDebug([]),
120
- addDocumentContext: () => returnAndThrowInDebug(""),
121
- removeDocumentContext: () => {
122
- },
123
- runtimeClient: {},
124
- copilotApiConfig: new class {
125
- get chatApiEndpoint() {
126
- throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
127
- }
128
- get headers() {
129
- return {};
130
- }
131
- get body() {
132
- return {};
133
- }
134
- }(),
135
- chatSuggestionConfiguration: {},
136
- addChatSuggestionConfiguration: () => {
137
- },
138
- removeChatSuggestionConfiguration: () => {
139
- },
140
- showDevConsole: "auto",
141
- coagentStates: {},
142
- setCoagentStates: () => {
143
- },
144
- agentSession: null,
145
- setAgentSession: () => {
146
- }
147
- };
148
- var CopilotContext = import_react.default.createContext(emptyCopilotContext);
149
- function useCopilotContext() {
150
- const context = import_react.default.useContext(CopilotContext);
151
- if (context === emptyCopilotContext) {
152
- throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
153
- }
154
- return context;
155
- }
156
- function returnAndThrowInDebug(value) {
157
- throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
158
- return value;
159
- }
160
-
161
- // src/hooks/use-copilot-chat.ts
162
- var import_runtime_client_gql3 = require("@copilotkit/runtime-client-gql");
163
-
164
- // src/hooks/use-chat.ts
165
- var import_react4 = require("react");
166
- var import_shared = require("@copilotkit/shared");
167
- var import_runtime_client_gql2 = require("@copilotkit/runtime-client-gql");
168
-
169
- // src/components/toast/toast-provider.tsx
170
- var import_react2 = require("react");
171
- var import_jsx_runtime = require("react/jsx-runtime");
172
- var ToastContext = (0, import_react2.createContext)(void 0);
173
- function useToast() {
174
- const context = (0, import_react2.useContext)(ToastContext);
175
- if (!context) {
176
- throw new Error("useToast must be used within a ToastProvider");
177
- }
178
- return context;
179
- }
180
-
181
- // src/hooks/use-copilot-runtime-client.ts
182
- var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
183
- var import_react3 = require("react");
184
- var useCopilotRuntimeClient = (options) => {
185
- const { addGraphQLErrorsToast } = useToast();
186
- const runtimeClient = (0, import_react3.useMemo)(() => {
187
- return new import_runtime_client_gql.CopilotRuntimeClient(__spreadProps(__spreadValues({}, options), {
188
- handleGQLErrors: (error) => {
189
- if (error.graphQLErrors.length) {
190
- addGraphQLErrorsToast(error.graphQLErrors);
191
- }
192
- }
193
- }));
194
- }, [options, addGraphQLErrorsToast]);
195
- return runtimeClient;
196
- };
197
-
198
- // src/hooks/use-chat.ts
199
- function useChat(options) {
200
- const {
201
- messages,
202
- setMessages,
203
- makeSystemMessageCallback,
204
- copilotConfig,
205
- setIsLoading,
206
- initialMessages,
207
- isLoading,
208
- actions,
209
- onFunctionCall,
210
- onCoAgentStateRender,
211
- setCoagentStates,
212
- coagentStates,
213
- agentSession,
214
- setAgentSession
215
- } = options;
216
- const abortControllerRef = (0, import_react4.useRef)();
217
- const threadIdRef = (0, import_react4.useRef)(null);
218
- const runIdRef = (0, import_react4.useRef)(null);
219
- const { addGraphQLErrorsToast } = useToast();
220
- const runChatCompletionRef = (0, import_react4.useRef)();
221
- const coagentStatesRef = (0, import_react4.useRef)(coagentStates);
222
- coagentStatesRef.current = coagentStates;
223
- const agentSessionRef = (0, import_react4.useRef)(agentSession);
224
- agentSessionRef.current = agentSession;
225
- const publicApiKey = copilotConfig.publicApiKey;
226
- const headers = __spreadValues(__spreadValues({}, copilotConfig.headers || {}), publicApiKey ? { [import_shared.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey } : {});
227
- const runtimeClient = useCopilotRuntimeClient({
228
- url: copilotConfig.chatApiEndpoint,
229
- publicApiKey: copilotConfig.publicApiKey,
230
- headers,
231
- credentials: copilotConfig.credentials
232
- });
233
- const runChatCompletion = (previousMessages) => __async(this, null, function* () {
234
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
235
- setIsLoading(true);
236
- let newMessages = [
237
- new import_runtime_client_gql2.TextMessage({
238
- content: "",
239
- role: import_runtime_client_gql2.Role.Assistant
240
- })
241
- ];
242
- const abortController = new AbortController();
243
- abortControllerRef.current = abortController;
244
- setMessages([...previousMessages, ...newMessages]);
245
- const systemMessage = makeSystemMessageCallback();
246
- const messagesWithContext = [systemMessage, ...initialMessages || [], ...previousMessages];
247
- const stream = runtimeClient.asStream(
248
- runtimeClient.generateCopilotResponse({
249
- data: __spreadProps(__spreadValues(__spreadProps(__spreadValues({
250
- frontend: {
251
- actions: actions.filter(
252
- (action) => action.available !== import_runtime_client_gql2.ActionInputAvailability.Disabled || !action.disabled
253
- ).map((action) => {
254
- let available = import_runtime_client_gql2.ActionInputAvailability.Enabled;
255
- if (action.disabled) {
256
- available = import_runtime_client_gql2.ActionInputAvailability.Disabled;
257
- } else if (action.available === "disabled") {
258
- available = import_runtime_client_gql2.ActionInputAvailability.Disabled;
259
- } else if (action.available === "remote") {
260
- available = import_runtime_client_gql2.ActionInputAvailability.Remote;
261
- }
262
- return {
263
- name: action.name,
264
- description: action.description || "",
265
- jsonSchema: JSON.stringify((0, import_shared.actionParametersToJsonSchema)(action.parameters || [])),
266
- available
267
- };
268
- }),
269
- url: window.location.href
270
- },
271
- threadId: threadIdRef.current,
272
- runId: runIdRef.current,
273
- messages: (0, import_runtime_client_gql2.convertMessagesToGqlInput)((0, import_runtime_client_gql2.filterAgentStateMessages)(messagesWithContext))
274
- }, copilotConfig.cloud ? {
275
- cloud: __spreadValues({}, ((_c = (_b = (_a = copilotConfig.cloud.guardrails) == null ? void 0 : _a.input) == null ? void 0 : _b.restrictToTopic) == null ? void 0 : _c.enabled) ? {
276
- guardrails: {
277
- inputValidationRules: {
278
- allowList: copilotConfig.cloud.guardrails.input.restrictToTopic.validTopics,
279
- denyList: copilotConfig.cloud.guardrails.input.restrictToTopic.invalidTopics
280
- }
281
- }
282
- } : {})
283
- } : {}), {
284
- metadata: {
285
- requestType: import_runtime_client_gql2.CopilotRequestType.Chat
286
- }
287
- }), agentSessionRef.current ? {
288
- agentSession: agentSessionRef.current
289
- } : {}), {
290
- agentStates: Object.values(coagentStatesRef.current).map((state) => ({
291
- agentName: state.name,
292
- state: JSON.stringify(state.state)
293
- }))
294
- }),
295
- properties: copilotConfig.properties,
296
- signal: (_d = abortControllerRef.current) == null ? void 0 : _d.signal
297
- })
298
- );
299
- const guardrailsEnabled = ((_g = (_f = (_e = copilotConfig.cloud) == null ? void 0 : _e.guardrails) == null ? void 0 : _f.input) == null ? void 0 : _g.restrictToTopic.enabled) || false;
300
- const reader = stream.getReader();
301
- let actionResults = {};
302
- let executedCoAgentStateRenders = [];
303
- let followUp = void 0;
304
- try {
305
- while (true) {
306
- let done, value;
307
- try {
308
- const readResult = yield reader.read();
309
- done = readResult.done;
310
- value = readResult.value;
311
- } catch (readError) {
312
- break;
313
- }
314
- if (done) {
315
- break;
316
- }
317
- if (!(value == null ? void 0 : value.generateCopilotResponse)) {
318
- continue;
319
- }
320
- threadIdRef.current = value.generateCopilotResponse.threadId || null;
321
- runIdRef.current = value.generateCopilotResponse.runId || null;
322
- const messages2 = (0, import_runtime_client_gql2.convertGqlOutputToMessages)(
323
- (0, import_runtime_client_gql2.filterAdjacentAgentStateMessages)(value.generateCopilotResponse.messages)
324
- );
325
- if (messages2.length === 0) {
326
- continue;
327
- }
328
- newMessages = [];
329
- if (((_h = value.generateCopilotResponse.status) == null ? void 0 : _h.__typename) === "FailedResponseStatus" && value.generateCopilotResponse.status.reason === "GUARDRAILS_VALIDATION_FAILED") {
330
- newMessages = [
331
- new import_runtime_client_gql2.TextMessage({
332
- role: import_runtime_client_gql2.MessageRole.Assistant,
333
- content: ((_i = value.generateCopilotResponse.status.details) == null ? void 0 : _i.guardrailsReason) || ""
334
- })
335
- ];
336
- } else {
337
- for (const message of messages2) {
338
- newMessages.push(message);
339
- if (message.isActionExecutionMessage() && message.status.code !== import_runtime_client_gql2.MessageStatusCode.Pending && message.scope === "client" && onFunctionCall) {
340
- if (!(message.id in actionResults)) {
341
- if (guardrailsEnabled && value.generateCopilotResponse.status === void 0) {
342
- break;
343
- }
344
- try {
345
- setMessages([...previousMessages, ...newMessages]);
346
- const action = actions.find((action2) => action2.name === message.name);
347
- if (action) {
348
- followUp = action.followUp;
349
- }
350
- const result = yield onFunctionCall({
351
- messages: previousMessages,
352
- name: message.name,
353
- args: message.arguments
354
- });
355
- actionResults[message.id] = result;
356
- } catch (e) {
357
- actionResults[message.id] = `Failed to execute action ${message.name}`;
358
- console.error(`Failed to execute action ${message.name}: ${e}`);
359
- }
360
- }
361
- newMessages.push(
362
- new import_runtime_client_gql2.ResultMessage({
363
- result: import_runtime_client_gql2.ResultMessage.encodeResult(actionResults[message.id]),
364
- actionExecutionId: message.id,
365
- actionName: message.name
366
- })
367
- );
368
- }
369
- if (message.isAgentStateMessage() && !message.active && !executedCoAgentStateRenders.includes(message.id) && onCoAgentStateRender) {
370
- if (guardrailsEnabled && value.generateCopilotResponse.status === void 0) {
371
- break;
372
- }
373
- yield onCoAgentStateRender({
374
- name: message.agentName,
375
- nodeName: message.nodeName,
376
- state: message.state
377
- });
378
- executedCoAgentStateRenders.push(message.id);
379
- }
380
- }
381
- const lastAgentStateMessage = [...messages2].reverse().find((message) => message.isAgentStateMessage());
382
- if (lastAgentStateMessage) {
383
- setCoagentStates((prevAgentStates) => __spreadProps(__spreadValues({}, prevAgentStates), {
384
- [lastAgentStateMessage.agentName]: {
385
- name: lastAgentStateMessage.agentName,
386
- state: lastAgentStateMessage.state,
387
- running: lastAgentStateMessage.running,
388
- active: lastAgentStateMessage.active,
389
- threadId: lastAgentStateMessage.threadId,
390
- nodeName: lastAgentStateMessage.nodeName,
391
- runId: lastAgentStateMessage.runId
392
- }
393
- }));
394
- if (lastAgentStateMessage.running) {
395
- setAgentSession({
396
- threadId: lastAgentStateMessage.threadId,
397
- agentName: lastAgentStateMessage.agentName,
398
- nodeName: lastAgentStateMessage.nodeName
399
- });
400
- } else {
401
- setAgentSession(null);
402
- }
403
- }
404
- }
405
- if (newMessages.length > 0) {
406
- setMessages([...previousMessages, ...newMessages]);
407
- }
408
- }
409
- if (
410
- // if followUp is not explicitly false
411
- followUp !== false && // if we have client side results
412
- (Object.values(actionResults).length || // or the last message we received is a result
413
- newMessages.length && newMessages[newMessages.length - 1].isResultMessage())
414
- ) {
415
- yield new Promise((resolve) => setTimeout(resolve, 10));
416
- return yield runChatCompletionRef.current([...previousMessages, ...newMessages]);
417
- } else {
418
- return newMessages.slice();
419
- }
420
- } finally {
421
- setIsLoading(false);
422
- }
423
- });
424
- runChatCompletionRef.current = runChatCompletion;
425
- const runChatCompletionAndHandleFunctionCall = (messages2) => __async(this, null, function* () {
426
- yield runChatCompletionRef.current(messages2);
427
- });
428
- const append = (message) => __async(this, null, function* () {
429
- if (isLoading) {
430
- return;
431
- }
432
- const newMessages = [...messages, message];
433
- setMessages(newMessages);
434
- return runChatCompletionAndHandleFunctionCall(newMessages);
435
- });
436
- const reload = () => __async(this, null, function* () {
437
- if (isLoading || messages.length === 0) {
438
- return;
439
- }
440
- let newMessages = [...messages];
441
- const lastMessage = messages[messages.length - 1];
442
- if (lastMessage.isTextMessage() && lastMessage.role === "assistant") {
443
- newMessages = newMessages.slice(0, -1);
444
- }
445
- setMessages(newMessages);
446
- return runChatCompletionAndHandleFunctionCall(newMessages);
447
- });
448
- const stop = () => {
449
- var _a;
450
- (_a = abortControllerRef.current) == null ? void 0 : _a.abort();
451
- };
452
- return {
453
- append,
454
- reload,
455
- stop
456
- };
457
- }
458
-
459
- // src/components/copilot-provider/copilotkit.tsx
460
- var import_react6 = require("react");
461
- var import_react_dom = require("react-dom");
462
- var import_shared2 = require("@copilotkit/shared");
463
-
464
- // src/context/copilot-messages-context.tsx
465
- var import_react5 = __toESM(require("react"));
466
- var emptyCopilotContext2 = {
467
- messages: [],
468
- setMessages: () => []
469
- };
470
- var CopilotMessagesContext = import_react5.default.createContext(emptyCopilotContext2);
471
- function useCopilotMessagesContext() {
472
- const context = import_react5.default.useContext(CopilotMessagesContext);
473
- if (context === emptyCopilotContext2) {
474
- throw new Error(
475
- "A messages consuming component was not wrapped with `<CopilotMessages> {...} </CopilotMessages>`"
476
- );
477
- }
478
- return context;
479
- }
480
-
481
- // src/components/copilot-provider/copilotkit.tsx
482
- var import_jsx_runtime2 = require("react/jsx-runtime");
483
- var defaultCopilotContextCategories = ["global"];
484
-
485
- // src/hooks/use-copilot-chat.ts
486
- function useCopilotChat(_a = {}) {
487
- var _b = _a, {
488
- makeSystemMessage
489
- } = _b, options = __objRest(_b, [
490
- "makeSystemMessage"
491
- ]);
492
- const {
493
- getContextString,
494
- getFunctionCallHandler,
495
- copilotApiConfig,
496
- isLoading,
497
- setIsLoading,
498
- chatInstructions,
499
- actions,
500
- coagentStates,
501
- setCoagentStates,
502
- coAgentStateRenders,
503
- agentSession,
504
- setAgentSession
505
- } = useCopilotContext();
506
- const { messages, setMessages } = useCopilotMessagesContext();
507
- const latestGetContextString = useUpdatedRef(getContextString);
508
- const deleteMessage = (0, import_react7.useCallback)(
509
- (messageId) => {
510
- setMessages((prev) => prev.filter((message) => message.id !== messageId));
511
- },
512
- [setMessages]
513
- );
514
- const makeSystemMessageCallback = (0, import_react7.useCallback)(() => {
515
- const systemMessageMaker = makeSystemMessage || defaultSystemMessage;
516
- const contextString = latestGetContextString.current([], defaultCopilotContextCategories);
517
- return new import_runtime_client_gql3.TextMessage({
518
- content: systemMessageMaker(contextString, chatInstructions),
519
- role: import_runtime_client_gql3.Role.System
520
- });
521
- }, [getContextString, makeSystemMessage, chatInstructions]);
522
- const onCoAgentStateRender = (0, import_react7.useCallback)(
523
- (args) => __async(this, null, function* () {
524
- var _a2;
525
- const { name, nodeName, state } = args;
526
- let action = Object.values(coAgentStateRenders).find(
527
- (action2) => action2.name === name && action2.nodeName === nodeName
528
- );
529
- if (!action) {
530
- action = Object.values(coAgentStateRenders).find(
531
- (action2) => action2.name === name && !action2.nodeName
532
- );
533
- }
534
- if (action) {
535
- yield (_a2 = action.handler) == null ? void 0 : _a2.call(action, { state, nodeName });
536
- }
537
- }),
538
- [coAgentStateRenders]
539
- );
540
- const { append, reload, stop } = useChat(__spreadProps(__spreadValues({}, options), {
541
- actions: Object.values(actions),
542
- copilotConfig: copilotApiConfig,
543
- initialMessages: options.initialMessages || [],
544
- onFunctionCall: getFunctionCallHandler(),
545
- onCoAgentStateRender,
546
- messages,
547
- setMessages,
548
- makeSystemMessageCallback,
549
- isLoading,
550
- setIsLoading,
551
- coagentStates,
552
- setCoagentStates,
553
- agentSession,
554
- setAgentSession
555
- }));
556
- const latestAppend = useUpdatedRef(append);
557
- const latestAppendFunc = (0, import_react7.useCallback)(
558
- (message) => {
559
- return latestAppend.current(message);
560
- },
561
- [latestAppend]
562
- );
563
- const latestReload = useUpdatedRef(reload);
564
- const latestReloadFunc = (0, import_react7.useCallback)(() => {
565
- return latestReload.current();
566
- }, [latestReload]);
567
- const latestStop = useUpdatedRef(stop);
568
- const latestStopFunc = (0, import_react7.useCallback)(() => {
569
- return latestStop.current();
570
- }, [latestStop]);
571
- const latestDelete = useUpdatedRef(deleteMessage);
572
- const latestDeleteFunc = (0, import_react7.useCallback)(
573
- (messageId) => {
574
- return latestDelete.current(messageId);
575
- },
576
- [latestDelete]
577
- );
578
- const latestSetMessages = useUpdatedRef(setMessages);
579
- const latestSetMessagesFunc = (0, import_react7.useCallback)(
580
- (messages2) => {
581
- return latestSetMessages.current(messages2);
582
- },
583
- [latestSetMessages]
584
- );
585
- return {
586
- visibleMessages: messages,
587
- appendMessage: latestAppendFunc,
588
- setMessages: latestSetMessagesFunc,
589
- reloadMessages: latestReloadFunc,
590
- stopGeneration: latestStopFunc,
591
- deleteMessage: latestDeleteFunc,
592
- isLoading
593
- };
594
- }
595
- function useUpdatedRef(value) {
596
- const ref = (0, import_react7.useRef)(value);
597
- (0, import_react7.useEffect)(() => {
598
- ref.current = value;
599
- }, [value]);
600
- return ref;
601
- }
602
- function defaultSystemMessage(contextString, additionalInstructions) {
603
- return `
604
- Please act as an efficient, competent, conscientious, and industrious professional assistant.
605
-
606
- Help 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.
607
- Always be polite and respectful, and prefer brevity over verbosity.
608
-
609
- The user has provided you with the following context:
610
- \`\`\`
611
- ${contextString}
612
- \`\`\`
613
-
614
- They have also provided you with functions you can call to initiate actions on their behalf, or functions you can call to receive more information.
615
-
616
- Please assist them as best you can.
617
-
618
- You 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.
619
-
620
- If you would like to call a function, call it without saying anything else.
621
- ` + (additionalInstructions ? `
622
-
623
- ${additionalInstructions}` : "");
624
- }
625
-
626
- // src/hooks/use-copilot-action.ts
627
- var import_shared3 = require("@copilotkit/shared");
628
- var import_react8 = require("react");
629
- function useCopilotAction(action, dependencies) {
630
- const { setAction, removeAction, actions, chatComponentsCache } = useCopilotContext();
631
- const idRef = (0, import_react8.useRef)((0, import_shared3.randomId)());
632
- const renderAndWaitRef = (0, import_react8.useRef)(null);
633
- action = __spreadValues({}, action);
634
- if (action.renderAndWait || action.renderAndWaitForResponse) {
635
- const renderAndWait = action.renderAndWait || action.renderAndWaitForResponse;
636
- action.renderAndWait = void 0;
637
- action.renderAndWaitForResponse = void 0;
638
- action.handler = () => __async(this, null, function* () {
639
- let resolve;
640
- let reject;
641
- const promise = new Promise((resolvePromise, rejectPromise) => {
642
- resolve = resolvePromise;
643
- reject = rejectPromise;
644
- });
645
- renderAndWaitRef.current = { promise, resolve, reject };
646
- return yield promise;
647
- });
648
- action.render = (props) => {
649
- const waitProps = {
650
- status: props.status,
651
- args: props.args,
652
- result: props.result,
653
- handler: props.status === "executing" ? renderAndWaitRef.current.resolve : void 0,
654
- respond: props.status === "executing" ? renderAndWaitRef.current.resolve : void 0
655
- };
656
- const isNoArgsRenderWait = (_fn) => {
657
- var _a;
658
- return ((_a = action.parameters) == null ? void 0 : _a.length) === 0;
659
- };
660
- if (renderAndWait) {
661
- if (isNoArgsRenderWait(renderAndWait)) {
662
- return renderAndWait(waitProps);
663
- } else {
664
- return renderAndWait(waitProps);
665
- }
666
- }
667
- return (0, import_react8.createElement)(import_react8.Fragment);
668
- };
669
- }
670
- if (dependencies === void 0) {
671
- if (actions[idRef.current]) {
672
- actions[idRef.current].handler = action.handler;
673
- if (typeof action.render === "function") {
674
- if (chatComponentsCache.current !== null) {
675
- chatComponentsCache.current.actions[action.name] = action.render;
676
- }
677
- }
678
- }
679
- }
680
- (0, import_react8.useEffect)(() => {
681
- setAction(idRef.current, action);
682
- if (chatComponentsCache.current !== null && action.render !== void 0) {
683
- chatComponentsCache.current.actions[action.name] = action.render;
684
- }
685
- return () => {
686
- removeAction(idRef.current);
687
- };
688
- }, [
689
- setAction,
690
- removeAction,
691
- action.description,
692
- action.name,
693
- action.disabled,
694
- action.available,
695
- // This should be faster than deep equality checking
696
- // In addition, all major JS engines guarantee the order of object keys
697
- JSON.stringify(action.parameters),
698
- // include render only if it's a string
699
- typeof action.render === "string" ? action.render : void 0,
700
- // dependencies set by the developer
701
- ...dependencies || []
702
- ]);
703
- }
704
-
705
- // src/hooks/use-coagent-state-render.ts
706
- var import_react9 = require("react");
707
- var import_shared4 = require("@copilotkit/shared");
708
- function useCoAgentStateRender(action, dependencies) {
709
- const {
710
- setCoAgentStateRender,
711
- removeCoAgentStateRender,
712
- coAgentStateRenders,
713
- chatComponentsCache
714
- } = (0, import_react9.useContext)(CopilotContext);
715
- const idRef = (0, import_react9.useRef)((0, import_shared4.randomId)());
716
- const key = `${action.name}-${action.nodeName || "global"}`;
717
- if (dependencies === void 0) {
718
- if (coAgentStateRenders[idRef.current]) {
719
- coAgentStateRenders[idRef.current].handler = action.handler;
720
- if (typeof action.render === "function") {
721
- if (chatComponentsCache.current !== null) {
722
- chatComponentsCache.current.coAgentStateRenders[key] = action.render;
723
- }
724
- }
725
- }
726
- }
727
- (0, import_react9.useEffect)(() => {
728
- setCoAgentStateRender(idRef.current, action);
729
- if (chatComponentsCache.current !== null && action.render !== void 0) {
730
- chatComponentsCache.current.coAgentStateRenders[key] = action.render;
731
- }
732
- return () => {
733
- removeCoAgentStateRender(idRef.current);
734
- };
735
- }, [
736
- setCoAgentStateRender,
737
- removeCoAgentStateRender,
738
- action.name,
739
- // include render only if it's a string
740
- typeof action.render === "string" ? action.render : void 0,
741
- // dependencies set by the developer
742
- ...dependencies || []
743
- ]);
744
- }
745
-
746
- // src/hooks/use-make-copilot-document-readable.ts
747
- var import_react10 = require("react");
748
- function useMakeCopilotDocumentReadable(document, categories, dependencies = []) {
749
- const { addDocumentContext, removeDocumentContext } = useCopilotContext();
750
- const idRef = (0, import_react10.useRef)();
751
- (0, import_react10.useEffect)(() => {
752
- const id = addDocumentContext(document, categories);
753
- idRef.current = id;
754
- return () => {
755
- removeDocumentContext(id);
756
- };
757
- }, [addDocumentContext, removeDocumentContext, ...dependencies]);
758
- return idRef.current;
759
- }
760
-
761
- // src/hooks/use-copilot-readable.ts
762
- var import_react11 = require("react");
763
- function convertToJSON(description, value) {
764
- return `${description}: ${typeof value === "string" ? value : JSON.stringify(value)}`;
765
- }
766
- function useCopilotReadable({ description, value, parentId, categories, convert }, dependencies) {
767
- const { addContext, removeContext } = useCopilotContext();
768
- const idRef = (0, import_react11.useRef)();
769
- convert = convert || convertToJSON;
770
- const information = convert(description, value);
771
- (0, import_react11.useEffect)(() => {
772
- const id = addContext(information, parentId, categories);
773
- idRef.current = id;
774
- return () => {
775
- removeContext(id);
776
- };
777
- }, [information, parentId, addContext, removeContext, ...dependencies || []]);
778
- return idRef.current;
779
- }
780
-
781
- // src/hooks/use-coagent.ts
782
- var import_react12 = require("react");
783
- function useCoAgent(options) {
784
- const isExternalStateManagement = (options2) => {
785
- return "state" in options2 && "setState" in options2;
786
- };
787
- const { name } = options;
788
- const isInternalStateManagementWithInitial = (options2) => {
789
- return "initialState" in options2;
790
- };
791
- const generalContext = useCopilotContext();
792
- const messagesContext = useCopilotMessagesContext();
793
- const context = __spreadValues(__spreadValues({}, generalContext), messagesContext);
794
- const { coagentStates, setCoagentStates } = context;
795
- const { appendMessage } = useCopilotChat();
796
- const getCoagentState = (coagentStates2, name2) => {
797
- if (coagentStates2[name2]) {
798
- return coagentStates2[name2];
799
- } else {
800
- return {
801
- name: name2,
802
- state: isInternalStateManagementWithInitial(options) ? options.initialState : {},
803
- running: false,
804
- active: false,
805
- threadId: void 0,
806
- nodeName: void 0,
807
- runId: void 0
808
- };
809
- }
810
- };
811
- const setState = (newState) => {
812
- setCoagentStates((prevAgentStates) => {
813
- let coagentState2 = getCoagentState(prevAgentStates, name);
814
- const updatedState = typeof newState === "function" ? newState(coagentState2.state) : newState;
815
- return __spreadProps(__spreadValues({}, prevAgentStates), {
816
- [name]: __spreadProps(__spreadValues({}, coagentState2), {
817
- state: updatedState
818
- })
819
- });
820
- });
821
- };
822
- const coagentState = getCoagentState(coagentStates, name);
823
- const state = isExternalStateManagement(options) ? options.state : coagentState.state;
824
- (0, import_react12.useEffect)(() => {
825
- if (isExternalStateManagement(options)) {
826
- setState(options.state);
827
- } else if (coagentStates[name] === void 0) {
828
- setState(options.initialState === void 0 ? {} : options.initialState);
829
- }
830
- }, [isExternalStateManagement(options) ? JSON.stringify(options.state) : void 0]);
831
- return {
832
- name,
833
- nodeName: coagentState.nodeName,
834
- state,
835
- setState,
836
- running: coagentState.running,
837
- start: () => {
838
- startAgent(name, context);
839
- },
840
- stop: () => {
841
- stopAgent(name, context);
842
- },
843
- run: (hint) => {
844
- return runAgent(name, context, appendMessage, hint);
845
- }
846
- };
847
- }
848
- function startAgent(name, context) {
849
- const { setAgentSession } = context;
850
- setAgentSession({
851
- agentName: name
852
- });
853
- }
854
- function stopAgent(name, context) {
855
- const { agentSession, setAgentSession } = context;
856
- if (agentSession && agentSession.agentName === name) {
857
- setAgentSession(null);
858
- } else {
859
- console.warn(`No agent session found for ${name}`);
860
- }
861
- }
862
- function runAgent(name, context, appendMessage, hint) {
863
- return __async(this, null, function* () {
864
- var _a, _b;
865
- const { agentSession, setAgentSession } = context;
866
- if (!agentSession || agentSession.agentName !== name) {
867
- setAgentSession({
868
- agentName: name
869
- });
870
- }
871
- let previousState = null;
872
- for (let i = context.messages.length - 1; i >= 0; i--) {
873
- const message = context.messages[i];
874
- if (message.isAgentStateMessage() && message.agentName === name) {
875
- previousState = message.state;
876
- }
877
- }
878
- let state = ((_b = (_a = context.coagentStates) == null ? void 0 : _a[name]) == null ? void 0 : _b.state) || {};
879
- if (hint) {
880
- const hintMessage = hint({ previousState, currentState: state });
881
- if (hintMessage) {
882
- yield appendMessage(hintMessage);
883
- }
884
- }
885
- });
886
- }
887
- // Annotate the CommonJS export names for ESM import in node:
888
- 0 && (module.exports = {
889
- useCoAgent,
890
- useCoAgentStateRender,
891
- useCopilotAction,
892
- useCopilotChat,
893
- useCopilotReadable,
894
- useCopilotRuntimeClient,
895
- useMakeCopilotDocumentReadable
896
- });
897
- //# sourceMappingURL=index.js.map