@copilotkit/react-core 1.5.9 → 1.5.10-next.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.
Files changed (249) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/chunk-22XKTBPF.mjs +61 -0
  3. package/dist/chunk-22XKTBPF.mjs.map +1 -0
  4. package/dist/chunk-2KT73RVG.mjs +482 -0
  5. package/dist/chunk-2KT73RVG.mjs.map +1 -0
  6. package/dist/chunk-3GQPEN4M.mjs +160 -0
  7. package/dist/chunk-3GQPEN4M.mjs.map +1 -0
  8. package/dist/chunk-5FHSUKQL.mjs +70 -0
  9. package/dist/chunk-5FHSUKQL.mjs.map +1 -0
  10. package/dist/chunk-6BQVZFNO.mjs +35 -0
  11. package/dist/chunk-6BQVZFNO.mjs.map +1 -0
  12. package/dist/chunk-6U3UH3KO.mjs +140 -0
  13. package/dist/chunk-6U3UH3KO.mjs.map +1 -0
  14. package/dist/chunk-DCTJZ742.mjs +22 -0
  15. package/dist/chunk-DCTJZ742.mjs.map +1 -0
  16. package/dist/chunk-EFZPSZWO.mjs +1 -0
  17. package/dist/chunk-EFZPSZWO.mjs.map +1 -0
  18. package/dist/chunk-EWKJMQOF.mjs +107 -0
  19. package/dist/chunk-EWKJMQOF.mjs.map +1 -0
  20. package/dist/chunk-FQ53HQYZ.mjs +28 -0
  21. package/dist/chunk-FQ53HQYZ.mjs.map +1 -0
  22. package/dist/chunk-HIUT2NLX.mjs +23 -0
  23. package/dist/chunk-HIUT2NLX.mjs.map +1 -0
  24. package/dist/chunk-LHKIIAUQ.mjs +59 -0
  25. package/dist/chunk-LHKIIAUQ.mjs.map +1 -0
  26. package/dist/chunk-LNI2Z45S.mjs +242 -0
  27. package/dist/chunk-LNI2Z45S.mjs.map +1 -0
  28. package/dist/chunk-LUGEI4YQ.mjs +1 -0
  29. package/dist/chunk-LUGEI4YQ.mjs.map +1 -0
  30. package/dist/chunk-MLAS4QUR.mjs +18 -0
  31. package/dist/chunk-MLAS4QUR.mjs.map +1 -0
  32. package/dist/chunk-NR2BTA6Z.mjs +1 -0
  33. package/dist/chunk-NR2BTA6Z.mjs.map +1 -0
  34. package/dist/chunk-O7ARI5CV.mjs +31 -0
  35. package/dist/chunk-O7ARI5CV.mjs.map +1 -0
  36. package/dist/chunk-SKC7AJIV.mjs +61 -0
  37. package/dist/chunk-SKC7AJIV.mjs.map +1 -0
  38. package/dist/chunk-VGOFRULA.mjs +401 -0
  39. package/dist/chunk-VGOFRULA.mjs.map +1 -0
  40. package/dist/chunk-VNTDIJSG.mjs +37 -0
  41. package/dist/chunk-VNTDIJSG.mjs.map +1 -0
  42. package/dist/chunk-WXREY7UP.mjs +87 -0
  43. package/dist/chunk-WXREY7UP.mjs.map +1 -0
  44. package/dist/chunk-X36DNILG.mjs +215 -0
  45. package/dist/chunk-X36DNILG.mjs.map +1 -0
  46. package/dist/chunk-XERJQUHA.mjs +31 -0
  47. package/dist/chunk-XERJQUHA.mjs.map +1 -0
  48. package/dist/chunk-XOQMISG3.mjs +120 -0
  49. package/dist/chunk-XOQMISG3.mjs.map +1 -0
  50. package/dist/chunk-XXR4QFAQ.mjs +29 -0
  51. package/dist/chunk-XXR4QFAQ.mjs.map +1 -0
  52. package/dist/chunk-YPSGKPDA.mjs +1 -0
  53. package/dist/chunk-YPSGKPDA.mjs.map +1 -0
  54. package/dist/components/copilot-provider/copilot-messages.d.ts +16 -0
  55. package/dist/components/copilot-provider/copilot-messages.js +80 -0
  56. package/dist/components/copilot-provider/copilot-messages.js.map +1 -0
  57. package/dist/components/copilot-provider/copilot-messages.mjs +9 -0
  58. package/dist/components/copilot-provider/copilot-messages.mjs.map +1 -0
  59. package/dist/components/copilot-provider/copilotkit-props.d.ts +93 -0
  60. package/dist/components/copilot-provider/copilotkit-props.js +19 -0
  61. package/dist/components/copilot-provider/copilotkit-props.js.map +1 -0
  62. package/dist/components/copilot-provider/copilotkit-props.mjs +1 -0
  63. package/dist/components/copilot-provider/copilotkit-props.mjs.map +1 -0
  64. package/dist/components/copilot-provider/copilotkit.d.ts +18 -0
  65. package/dist/components/copilot-provider/copilotkit.js +990 -0
  66. package/dist/components/copilot-provider/copilotkit.js.map +1 -0
  67. package/dist/components/copilot-provider/copilotkit.mjs +22 -0
  68. package/dist/components/copilot-provider/copilotkit.mjs.map +1 -0
  69. package/dist/components/copilot-provider/index.d.ts +13 -0
  70. package/dist/components/copilot-provider/index.js +990 -0
  71. package/dist/components/copilot-provider/index.js.map +1 -0
  72. package/dist/components/copilot-provider/index.mjs +20 -0
  73. package/dist/components/copilot-provider/index.mjs.map +1 -0
  74. package/dist/components/error-boundary/error-boundary.d.ts +22 -0
  75. package/dist/components/error-boundary/error-boundary.js +183 -0
  76. package/dist/components/error-boundary/error-boundary.js.map +1 -0
  77. package/dist/components/error-boundary/error-boundary.mjs +12 -0
  78. package/dist/components/error-boundary/error-boundary.mjs.map +1 -0
  79. package/dist/components/error-boundary/error-utils.d.ts +11 -0
  80. package/dist/components/error-boundary/error-utils.js +177 -0
  81. package/dist/components/error-boundary/error-utils.js.map +1 -0
  82. package/dist/components/error-boundary/error-utils.mjs +13 -0
  83. package/dist/components/error-boundary/error-utils.mjs.map +1 -0
  84. package/dist/components/index.d.ts +13 -0
  85. package/dist/components/index.js +990 -0
  86. package/dist/components/index.js.map +1 -0
  87. package/dist/components/index.mjs +20 -0
  88. package/dist/components/index.mjs.map +1 -0
  89. package/dist/components/toast/exclamation-mark-icon.d.ts +9 -0
  90. package/dist/components/toast/exclamation-mark-icon.js +55 -0
  91. package/dist/components/toast/exclamation-mark-icon.js.map +1 -0
  92. package/dist/components/toast/exclamation-mark-icon.mjs +8 -0
  93. package/dist/components/toast/exclamation-mark-icon.mjs.map +1 -0
  94. package/dist/components/toast/toast-provider.d.ts +30 -0
  95. package/dist/components/toast/toast-provider.js +269 -0
  96. package/dist/components/toast/toast-provider.js.map +1 -0
  97. package/dist/components/toast/toast-provider.mjs +11 -0
  98. package/dist/components/toast/toast-provider.mjs.map +1 -0
  99. package/dist/context/copilot-context.d.ts +142 -0
  100. package/dist/context/copilot-context.js +138 -0
  101. package/dist/context/copilot-context.js.map +1 -0
  102. package/dist/context/copilot-context.mjs +10 -0
  103. package/dist/context/copilot-context.mjs.map +1 -0
  104. package/dist/context/copilot-messages-context.d.ts +15 -0
  105. package/dist/context/copilot-messages-context.js +57 -0
  106. package/dist/context/copilot-messages-context.js.map +1 -0
  107. package/dist/context/copilot-messages-context.mjs +10 -0
  108. package/dist/context/copilot-messages-context.mjs.map +1 -0
  109. package/dist/context/index.d.ts +11 -0
  110. package/dist/context/index.js +161 -0
  111. package/dist/context/index.js.map +1 -0
  112. package/dist/context/index.mjs +17 -0
  113. package/dist/context/index.mjs.map +1 -0
  114. package/dist/hooks/index.d.ts +21 -0
  115. package/dist/hooks/index.js +1303 -0
  116. package/dist/hooks/index.js.map +1 -0
  117. package/dist/hooks/index.mjs +56 -0
  118. package/dist/hooks/index.mjs.map +1 -0
  119. package/dist/hooks/use-chat.d.ts +124 -0
  120. package/dist/hooks/use-chat.js +608 -0
  121. package/dist/hooks/use-chat.js.map +1 -0
  122. package/dist/hooks/use-chat.mjs +12 -0
  123. package/dist/hooks/use-chat.mjs.map +1 -0
  124. package/dist/hooks/use-coagent-state-render.d.ts +60 -0
  125. package/dist/hooks/use-coagent-state-render.js +195 -0
  126. package/dist/hooks/use-coagent-state-render.js.map +1 -0
  127. package/dist/hooks/use-coagent-state-render.mjs +11 -0
  128. package/dist/hooks/use-coagent-state-render.mjs.map +1 -0
  129. package/dist/hooks/use-coagent.d.ts +199 -0
  130. package/dist/hooks/use-coagent.js +1064 -0
  131. package/dist/hooks/use-coagent.js.map +1 -0
  132. package/dist/hooks/use-coagent.mjs +29 -0
  133. package/dist/hooks/use-coagent.mjs.map +1 -0
  134. package/dist/hooks/use-copilot-action.d.ts +140 -0
  135. package/dist/hooks/use-copilot-action.js +369 -0
  136. package/dist/hooks/use-copilot-action.js.map +1 -0
  137. package/dist/hooks/use-copilot-action.mjs +11 -0
  138. package/dist/hooks/use-copilot-action.mjs.map +1 -0
  139. package/dist/hooks/use-copilot-authenticated-action.d.ts +8 -0
  140. package/dist/hooks/use-copilot-authenticated-action.js +418 -0
  141. package/dist/hooks/use-copilot-authenticated-action.js.map +1 -0
  142. package/dist/hooks/use-copilot-authenticated-action.mjs +12 -0
  143. package/dist/hooks/use-copilot-authenticated-action.mjs.map +1 -0
  144. package/dist/hooks/use-copilot-chat.d.ts +38 -0
  145. package/dist/hooks/use-copilot-chat.js +928 -0
  146. package/dist/hooks/use-copilot-chat.js.map +1 -0
  147. package/dist/hooks/use-copilot-chat.mjs +24 -0
  148. package/dist/hooks/use-copilot-chat.mjs.map +1 -0
  149. package/dist/hooks/use-copilot-readable.d.ts +33 -0
  150. package/dist/hooks/use-copilot-readable.js +158 -0
  151. package/dist/hooks/use-copilot-readable.js.map +1 -0
  152. package/dist/hooks/use-copilot-readable.mjs +9 -0
  153. package/dist/hooks/use-copilot-readable.mjs.map +1 -0
  154. package/dist/hooks/use-copilot-runtime-client.d.ts +5 -0
  155. package/dist/hooks/use-copilot-runtime-client.js +182 -0
  156. package/dist/hooks/use-copilot-runtime-client.js.map +1 -0
  157. package/dist/hooks/use-copilot-runtime-client.mjs +10 -0
  158. package/dist/hooks/use-copilot-runtime-client.mjs.map +1 -0
  159. package/dist/hooks/use-flat-category-store.d.ts +9 -0
  160. package/dist/hooks/use-flat-category-store.js +90 -0
  161. package/dist/hooks/use-flat-category-store.js.map +1 -0
  162. package/dist/hooks/use-flat-category-store.mjs +8 -0
  163. package/dist/hooks/use-flat-category-store.mjs.map +1 -0
  164. package/dist/hooks/use-make-copilot-document-readable.d.ts +12 -0
  165. package/dist/hooks/use-make-copilot-document-readable.js +153 -0
  166. package/dist/hooks/use-make-copilot-document-readable.js.map +1 -0
  167. package/dist/hooks/use-make-copilot-document-readable.mjs +9 -0
  168. package/dist/hooks/use-make-copilot-document-readable.mjs.map +1 -0
  169. package/dist/hooks/use-tree.d.ts +18 -0
  170. package/dist/hooks/use-tree.js +172 -0
  171. package/dist/hooks/use-tree.js.map +1 -0
  172. package/dist/hooks/use-tree.mjs +8 -0
  173. package/dist/hooks/use-tree.mjs.map +1 -0
  174. package/dist/index.d.ts +27 -0
  175. package/dist/index.js +2224 -0
  176. package/dist/index.js.map +1 -0
  177. package/dist/index.mjs +83 -0
  178. package/dist/index.mjs.map +1 -0
  179. package/dist/lib/copilot-task.d.ts +97 -0
  180. package/dist/lib/copilot-task.js +195 -0
  181. package/dist/lib/copilot-task.js.map +1 -0
  182. package/dist/lib/copilot-task.mjs +20 -0
  183. package/dist/lib/copilot-task.mjs.map +1 -0
  184. package/dist/lib/index.d.ts +11 -0
  185. package/dist/lib/index.js +197 -0
  186. package/dist/lib/index.js.map +1 -0
  187. package/dist/lib/index.mjs +21 -0
  188. package/dist/lib/index.mjs.map +1 -0
  189. package/dist/types/chat-suggestion-configuration.d.ts +22 -0
  190. package/dist/types/chat-suggestion-configuration.js +19 -0
  191. package/dist/types/chat-suggestion-configuration.js.map +1 -0
  192. package/dist/types/chat-suggestion-configuration.mjs +1 -0
  193. package/dist/types/chat-suggestion-configuration.mjs.map +1 -0
  194. package/dist/types/coagent-action.d.ts +29 -0
  195. package/dist/types/coagent-action.js +19 -0
  196. package/dist/types/coagent-action.js.map +1 -0
  197. package/dist/types/coagent-action.mjs +1 -0
  198. package/dist/types/coagent-action.mjs.map +1 -0
  199. package/dist/types/coagent-state.d.ts +11 -0
  200. package/dist/types/coagent-state.js +19 -0
  201. package/dist/types/coagent-state.js.map +1 -0
  202. package/dist/types/coagent-state.mjs +1 -0
  203. package/dist/types/coagent-state.mjs.map +1 -0
  204. package/dist/types/document-pointer.d.ts +9 -0
  205. package/dist/types/document-pointer.js +19 -0
  206. package/dist/types/document-pointer.js.map +1 -0
  207. package/dist/types/document-pointer.mjs +1 -0
  208. package/dist/types/document-pointer.mjs.map +1 -0
  209. package/dist/types/frontend-action.d.ts +126 -0
  210. package/dist/types/frontend-action.js +53 -0
  211. package/dist/types/frontend-action.js.map +1 -0
  212. package/dist/types/frontend-action.mjs +8 -0
  213. package/dist/types/frontend-action.mjs.map +1 -0
  214. package/dist/types/index.d.ts +7 -0
  215. package/dist/types/index.js +19 -0
  216. package/dist/types/index.js.map +1 -0
  217. package/dist/types/index.mjs +2 -0
  218. package/dist/types/index.mjs.map +1 -0
  219. package/dist/types/system-message.d.ts +3 -0
  220. package/dist/types/system-message.js +19 -0
  221. package/dist/types/system-message.js.map +1 -0
  222. package/dist/types/system-message.mjs +1 -0
  223. package/dist/types/system-message.mjs.map +1 -0
  224. package/dist/utils/dev-console.d.ts +3 -0
  225. package/dist/utils/dev-console.js +42 -0
  226. package/dist/utils/dev-console.js.map +1 -0
  227. package/dist/utils/dev-console.mjs +8 -0
  228. package/dist/utils/dev-console.mjs.map +1 -0
  229. package/dist/utils/extract.d.ts +43 -0
  230. package/dist/utils/extract.js +208 -0
  231. package/dist/utils/extract.js.map +1 -0
  232. package/dist/utils/extract.mjs +18 -0
  233. package/dist/utils/extract.mjs.map +1 -0
  234. package/dist/utils/index.d.ts +13 -0
  235. package/dist/utils/index.js +226 -0
  236. package/dist/utils/index.js.map +1 -0
  237. package/dist/utils/index.mjs +21 -0
  238. package/dist/utils/index.mjs.map +1 -0
  239. package/dist/utils/utils.d.ts +2 -0
  240. package/dist/utils/utils.js +19 -0
  241. package/dist/utils/utils.js.map +1 -0
  242. package/dist/utils/utils.mjs +1 -0
  243. package/dist/utils/utils.mjs.map +1 -0
  244. package/dist/utils/utils.test.d.ts +2 -0
  245. package/dist/utils/utils.test.js +9 -0
  246. package/dist/utils/utils.test.js.map +1 -0
  247. package/dist/utils/utils.test.mjs +7 -0
  248. package/dist/utils/utils.test.mjs.map +1 -0
  249. package/package.json +3 -3
@@ -0,0 +1,215 @@
1
+ import {
2
+ defaultCopilotContextCategories
3
+ } from "./chunk-2KT73RVG.mjs";
4
+ import {
5
+ useCopilotMessagesContext
6
+ } from "./chunk-DCTJZ742.mjs";
7
+ import {
8
+ useChat
9
+ } from "./chunk-VGOFRULA.mjs";
10
+ import {
11
+ useCopilotContext
12
+ } from "./chunk-WXREY7UP.mjs";
13
+ import {
14
+ useAsyncCallback
15
+ } from "./chunk-LNI2Z45S.mjs";
16
+ import {
17
+ __async,
18
+ __objRest,
19
+ __spreadProps,
20
+ __spreadValues
21
+ } from "./chunk-SKC7AJIV.mjs";
22
+
23
+ // src/hooks/use-copilot-chat.ts
24
+ import { useRef, useEffect, useCallback } from "react";
25
+ import { Role, TextMessage } from "@copilotkit/runtime-client-gql";
26
+ function useCopilotChat(_a = {}) {
27
+ var _b = _a, {
28
+ makeSystemMessage
29
+ } = _b, options = __objRest(_b, [
30
+ "makeSystemMessage"
31
+ ]);
32
+ const {
33
+ getContextString,
34
+ getFunctionCallHandler,
35
+ copilotApiConfig,
36
+ isLoading,
37
+ setIsLoading,
38
+ chatInstructions,
39
+ actions,
40
+ coagentStatesRef,
41
+ setCoagentStatesWithRef,
42
+ coAgentStateRenders,
43
+ agentSession,
44
+ setAgentSession,
45
+ forwardedParameters,
46
+ agentLock,
47
+ threadId,
48
+ setThreadId,
49
+ runId,
50
+ setRunId,
51
+ chatAbortControllerRef
52
+ } = useCopilotContext();
53
+ const { messages, setMessages } = useCopilotMessagesContext();
54
+ const latestGetContextString = useUpdatedRef(getContextString);
55
+ const deleteMessage = useCallback(
56
+ (messageId) => {
57
+ setMessages((prev) => prev.filter((message) => message.id !== messageId));
58
+ },
59
+ [setMessages]
60
+ );
61
+ const makeSystemMessageCallback = useCallback(() => {
62
+ const systemMessageMaker = makeSystemMessage || defaultSystemMessage;
63
+ const contextString = latestGetContextString.current([], defaultCopilotContextCategories);
64
+ return new TextMessage({
65
+ content: systemMessageMaker(contextString, chatInstructions),
66
+ role: Role.System
67
+ });
68
+ }, [getContextString, makeSystemMessage, chatInstructions]);
69
+ const onCoAgentStateRender = useAsyncCallback(
70
+ (args) => __async(this, null, function* () {
71
+ var _a2;
72
+ const { name, nodeName, state } = args;
73
+ let action = Object.values(coAgentStateRenders).find(
74
+ (action2) => action2.name === name && action2.nodeName === nodeName
75
+ );
76
+ if (!action) {
77
+ action = Object.values(coAgentStateRenders).find(
78
+ (action2) => action2.name === name && !action2.nodeName
79
+ );
80
+ }
81
+ if (action) {
82
+ yield (_a2 = action.handler) == null ? void 0 : _a2.call(action, { state, nodeName });
83
+ }
84
+ }),
85
+ [coAgentStateRenders]
86
+ );
87
+ const { append, reload, stop, runChatCompletion } = useChat(__spreadProps(__spreadValues({}, options), {
88
+ actions: Object.values(actions),
89
+ copilotConfig: copilotApiConfig,
90
+ initialMessages: options.initialMessages || [],
91
+ onFunctionCall: getFunctionCallHandler(),
92
+ onCoAgentStateRender,
93
+ messages,
94
+ setMessages,
95
+ makeSystemMessageCallback,
96
+ isLoading,
97
+ setIsLoading,
98
+ coagentStatesRef,
99
+ setCoagentStatesWithRef,
100
+ agentSession,
101
+ setAgentSession,
102
+ forwardedParameters,
103
+ threadId,
104
+ setThreadId,
105
+ runId,
106
+ setRunId,
107
+ chatAbortControllerRef,
108
+ agentLock
109
+ }));
110
+ const latestAppend = useUpdatedRef(append);
111
+ const latestAppendFunc = useAsyncCallback(
112
+ (message) => __async(this, null, function* () {
113
+ return yield latestAppend.current(message);
114
+ }),
115
+ [latestAppend]
116
+ );
117
+ const latestReload = useUpdatedRef(reload);
118
+ const latestReloadFunc = useAsyncCallback(() => __async(this, null, function* () {
119
+ return yield latestReload.current();
120
+ }), [latestReload]);
121
+ const latestStop = useUpdatedRef(stop);
122
+ const latestStopFunc = useCallback(() => {
123
+ return latestStop.current();
124
+ }, [latestStop]);
125
+ const latestDelete = useUpdatedRef(deleteMessage);
126
+ const latestDeleteFunc = useCallback(
127
+ (messageId) => {
128
+ return latestDelete.current(messageId);
129
+ },
130
+ [latestDelete]
131
+ );
132
+ const latestSetMessages = useUpdatedRef(setMessages);
133
+ const latestSetMessagesFunc = useCallback(
134
+ (messages2) => {
135
+ return latestSetMessages.current(messages2);
136
+ },
137
+ [latestSetMessages]
138
+ );
139
+ const latestRunChatCompletion = useUpdatedRef(runChatCompletion);
140
+ const latestRunChatCompletionFunc = useAsyncCallback(() => __async(this, null, function* () {
141
+ return yield latestRunChatCompletion.current();
142
+ }), [latestRunChatCompletion]);
143
+ const reset = useCallback(() => {
144
+ latestStopFunc();
145
+ setMessages([]);
146
+ setThreadId(null);
147
+ setRunId(null);
148
+ setCoagentStatesWithRef({});
149
+ let initialAgentSession = null;
150
+ if (agentLock) {
151
+ initialAgentSession = {
152
+ agentName: agentLock
153
+ };
154
+ }
155
+ setAgentSession(initialAgentSession);
156
+ }, [
157
+ latestStopFunc,
158
+ setMessages,
159
+ setThreadId,
160
+ setCoagentStatesWithRef,
161
+ setAgentSession,
162
+ agentLock
163
+ ]);
164
+ const latestReset = useUpdatedRef(reset);
165
+ const latestResetFunc = useCallback(() => {
166
+ return latestReset.current();
167
+ }, [latestReset]);
168
+ return {
169
+ visibleMessages: messages,
170
+ appendMessage: latestAppendFunc,
171
+ setMessages: latestSetMessagesFunc,
172
+ reloadMessages: latestReloadFunc,
173
+ stopGeneration: latestStopFunc,
174
+ reset: latestResetFunc,
175
+ deleteMessage: latestDeleteFunc,
176
+ runChatCompletion: latestRunChatCompletionFunc,
177
+ isLoading
178
+ };
179
+ }
180
+ function useUpdatedRef(value) {
181
+ const ref = useRef(value);
182
+ useEffect(() => {
183
+ ref.current = value;
184
+ }, [value]);
185
+ return ref;
186
+ }
187
+ function defaultSystemMessage(contextString, additionalInstructions) {
188
+ return `
189
+ Please act as an efficient, competent, conscientious, and industrious professional assistant.
190
+
191
+ 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.
192
+ Always be polite and respectful, and prefer brevity over verbosity.
193
+
194
+ The user has provided you with the following context:
195
+ \`\`\`
196
+ ${contextString}
197
+ \`\`\`
198
+
199
+ 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.
200
+
201
+ Please assist them as best you can.
202
+
203
+ 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.
204
+
205
+ If you would like to call a function, call it without saying anything else.
206
+ ` + (additionalInstructions ? `
207
+
208
+ ${additionalInstructions}` : "");
209
+ }
210
+
211
+ export {
212
+ useCopilotChat,
213
+ defaultSystemMessage
214
+ };
215
+ //# sourceMappingURL=chunk-X36DNILG.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/hooks/use-copilot-chat.ts"],"sourcesContent":["/**\n * `useCopilotChat` is a React hook that lets you directly interact with the\n * Copilot instance. Use to implement a fully custom UI (headless UI) or to\n * programmatically interact with the Copilot instance managed by the default\n * UI.\n *\n * ## Usage\n *\n * ### Simple Usage\n *\n * ```tsx\n * import { useCopilotChat } from \"@copilotkit/react-core\";\n * import { Role, TextMessage } from \"@copilotkit/runtime-client-gql\";\n *\n * export function YourComponent() {\n * const { appendMessage } = useCopilotChat();\n *\n * appendMessage(\n * new TextMessage({\n * content: \"Hello World\",\n * role: Role.User,\n * }),\n * );\n * }\n * ```\n *\n * `useCopilotChat` returns an object with the following properties:\n *\n * ```tsx\n * const {\n * visibleMessages, // An array of messages that are currently visible in the chat.\n * appendMessage, // A function to append a message to the chat.\n * setMessages, // A function to set the messages in the chat.\n * deleteMessage, // A function to delete a message from the chat.\n * reloadMessages, // A function to reload the messages from the API.\n * stopGeneration, // A function to stop the generation of the next message.\n * isLoading, // A boolean indicating if the chat is loading.\n * } = useCopilotChat();\n * ```\n */\nimport { useRef, useEffect, useCallback } from \"react\";\nimport { AgentSession, useCopilotContext } from \"../context/copilot-context\";\nimport { Message, Role, TextMessage } from \"@copilotkit/runtime-client-gql\";\nimport { SystemMessageFunction } from \"../types\";\nimport { useChat } from \"./use-chat\";\nimport { defaultCopilotContextCategories } from \"../components\";\nimport { MessageStatusCode } from \"@copilotkit/runtime-client-gql\";\nimport { CoAgentStateRenderHandlerArguments } from \"@copilotkit/shared\";\nimport { useCopilotMessagesContext } from \"../context\";\nimport { useAsyncCallback } from \"../components/error-boundary/error-utils\";\n\nexport interface UseCopilotChatOptions {\n /**\n * A unique identifier for the chat. If not provided, a random one will be\n * generated. When provided, the `useChat` hook with the same `id` will\n * have shared states across components.\n */\n id?: string;\n\n /**\n * HTTP headers to be sent with the API request.\n */\n headers?: Record<string, string> | Headers;\n /**\n * System messages of the chat. Defaults to an empty array.\n */\n initialMessages?: Message[];\n\n /**\n * A function to generate the system message. Defaults to `defaultSystemMessage`.\n */\n makeSystemMessage?: SystemMessageFunction;\n}\n\nexport interface UseCopilotChatReturn {\n visibleMessages: Message[];\n appendMessage: (message: Message) => Promise<void>;\n setMessages: (messages: Message[]) => void;\n deleteMessage: (messageId: string) => void;\n reloadMessages: () => Promise<void>;\n stopGeneration: () => void;\n reset: () => void;\n isLoading: boolean;\n runChatCompletion: () => Promise<Message[]>;\n}\n\nexport function useCopilotChat({\n makeSystemMessage,\n ...options\n}: UseCopilotChatOptions = {}): UseCopilotChatReturn {\n const {\n getContextString,\n getFunctionCallHandler,\n copilotApiConfig,\n isLoading,\n setIsLoading,\n chatInstructions,\n actions,\n coagentStatesRef,\n setCoagentStatesWithRef,\n coAgentStateRenders,\n agentSession,\n setAgentSession,\n forwardedParameters,\n agentLock,\n threadId,\n setThreadId,\n runId,\n setRunId,\n chatAbortControllerRef,\n } = useCopilotContext();\n const { messages, setMessages } = useCopilotMessagesContext();\n\n // We need to ensure that makeSystemMessageCallback always uses the latest\n // useCopilotReadable data.\n const latestGetContextString = useUpdatedRef(getContextString);\n const deleteMessage = useCallback(\n (messageId: string) => {\n setMessages((prev) => prev.filter((message) => message.id !== messageId));\n },\n [setMessages],\n );\n\n const makeSystemMessageCallback = useCallback(() => {\n const systemMessageMaker = makeSystemMessage || defaultSystemMessage;\n // this always gets the latest context string\n const contextString = latestGetContextString.current([], defaultCopilotContextCategories); // TODO: make the context categories configurable\n\n return new TextMessage({\n content: systemMessageMaker(contextString, chatInstructions),\n role: Role.System,\n });\n }, [getContextString, makeSystemMessage, chatInstructions]);\n\n const onCoAgentStateRender = useAsyncCallback(\n async (args: CoAgentStateRenderHandlerArguments) => {\n const { name, nodeName, state } = args;\n let action = Object.values(coAgentStateRenders).find(\n (action) => action.name === name && action.nodeName === nodeName,\n );\n if (!action) {\n action = Object.values(coAgentStateRenders).find(\n (action) => action.name === name && !action.nodeName,\n );\n }\n if (action) {\n await action.handler?.({ state, nodeName });\n }\n },\n [coAgentStateRenders],\n );\n\n const { append, reload, stop, runChatCompletion } = useChat({\n ...options,\n actions: Object.values(actions),\n copilotConfig: copilotApiConfig,\n initialMessages: options.initialMessages || [],\n onFunctionCall: getFunctionCallHandler(),\n onCoAgentStateRender,\n messages,\n setMessages,\n makeSystemMessageCallback,\n isLoading,\n setIsLoading,\n coagentStatesRef,\n setCoagentStatesWithRef,\n agentSession,\n setAgentSession,\n forwardedParameters,\n threadId,\n setThreadId,\n runId,\n setRunId,\n chatAbortControllerRef,\n agentLock,\n });\n\n // this is a workaround born out of a bug that Athena incessantly ran into.\n // We could not find the origin of the bug, however, it was clear that an outdated version of the append function was being used somehow --\n // it referenced the old state of the messages array, and not the latest one.\n //\n // We want to make copilotkit as abuse-proof as possible, so we are adding this workaround to ensure that the latest version of the append function is always used.\n //\n // How does this work?\n // we store the relevant function in a ref that is always up-to-date, and then we use that ref in the callback.\n const latestAppend = useUpdatedRef(append);\n const latestAppendFunc = useAsyncCallback(\n async (message: Message) => {\n return await latestAppend.current(message);\n },\n [latestAppend],\n );\n\n const latestReload = useUpdatedRef(reload);\n const latestReloadFunc = useAsyncCallback(async () => {\n return await latestReload.current();\n }, [latestReload]);\n\n const latestStop = useUpdatedRef(stop);\n const latestStopFunc = useCallback(() => {\n return latestStop.current();\n }, [latestStop]);\n\n const latestDelete = useUpdatedRef(deleteMessage);\n const latestDeleteFunc = useCallback(\n (messageId: string) => {\n return latestDelete.current(messageId);\n },\n [latestDelete],\n );\n\n const latestSetMessages = useUpdatedRef(setMessages);\n const latestSetMessagesFunc = useCallback(\n (messages: Message[]) => {\n return latestSetMessages.current(messages);\n },\n [latestSetMessages],\n );\n\n const latestRunChatCompletion = useUpdatedRef(runChatCompletion);\n const latestRunChatCompletionFunc = useAsyncCallback(async () => {\n return await latestRunChatCompletion.current!();\n }, [latestRunChatCompletion]);\n\n const reset = useCallback(() => {\n latestStopFunc();\n setMessages([]);\n setThreadId(null);\n setRunId(null);\n setCoagentStatesWithRef({});\n let initialAgentSession: AgentSession | null = null;\n if (agentLock) {\n initialAgentSession = {\n agentName: agentLock,\n };\n }\n setAgentSession(initialAgentSession);\n }, [\n latestStopFunc,\n setMessages,\n setThreadId,\n setCoagentStatesWithRef,\n setAgentSession,\n agentLock,\n ]);\n\n const latestReset = useUpdatedRef(reset);\n const latestResetFunc = useCallback(() => {\n return latestReset.current();\n }, [latestReset]);\n\n return {\n visibleMessages: messages,\n appendMessage: latestAppendFunc,\n setMessages: latestSetMessagesFunc,\n reloadMessages: latestReloadFunc,\n stopGeneration: latestStopFunc,\n reset: latestResetFunc,\n deleteMessage: latestDeleteFunc,\n runChatCompletion: latestRunChatCompletionFunc,\n isLoading,\n };\n}\n\n// store `value` in a ref and update\n// it whenever it changes.\nfunction useUpdatedRef<T>(value: T) {\n const ref = useRef(value);\n\n useEffect(() => {\n ref.current = value;\n }, [value]);\n\n return ref;\n}\n\nexport function defaultSystemMessage(\n contextString: string,\n additionalInstructions?: string,\n): string {\n return (\n `\nPlease act as an efficient, competent, conscientious, and industrious professional assistant.\n\nHelp the user achieve their goals, and you do so in a way that is as efficient as possible, without unnecessary fluff, but also without sacrificing professionalism.\nAlways be polite and respectful, and prefer brevity over verbosity.\n\nThe user has provided you with the following context:\n\\`\\`\\`\n${contextString}\n\\`\\`\\`\n\nThey have also provided you with functions you can call to initiate actions on their behalf, or functions you can call to receive more information.\n\nPlease assist them as best you can.\n\nYou can ask them for clarifying questions if needed, but don't be annoying about it. If you can reasonably 'fill in the blanks' yourself, do so.\n\nIf you would like to call a function, call it without saying anything else.\n` + (additionalInstructions ? `\\n\\n${additionalInstructions}` : \"\")\n );\n}\n"],"mappings":"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","names":["_a","action","messages"]}
@@ -0,0 +1,31 @@
1
+ // src/types/frontend-action.ts
2
+ import { ActionInputAvailability } from "@copilotkit/runtime-client-gql";
3
+ import {
4
+ actionParametersToJsonSchema
5
+ } from "@copilotkit/shared";
6
+ function processActionsForRuntimeRequest(actions) {
7
+ const filteredActions = actions.filter(
8
+ (action) => action.available !== ActionInputAvailability.Disabled && action.disabled !== true && action.name !== "*"
9
+ ).map((action) => {
10
+ let available = ActionInputAvailability.Enabled;
11
+ if (action.disabled) {
12
+ available = ActionInputAvailability.Disabled;
13
+ } else if (action.available === "disabled") {
14
+ available = ActionInputAvailability.Disabled;
15
+ } else if (action.available === "remote") {
16
+ available = ActionInputAvailability.Remote;
17
+ }
18
+ return {
19
+ name: action.name,
20
+ description: action.description || "",
21
+ jsonSchema: JSON.stringify(actionParametersToJsonSchema(action.parameters || [])),
22
+ available
23
+ };
24
+ });
25
+ return filteredActions;
26
+ }
27
+
28
+ export {
29
+ processActionsForRuntimeRequest
30
+ };
31
+ //# sourceMappingURL=chunk-XERJQUHA.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/types/frontend-action.ts"],"sourcesContent":["import { ActionInputAvailability } from \"@copilotkit/runtime-client-gql\";\nimport {\n Action,\n Parameter,\n MappedParameterTypes,\n actionParametersToJsonSchema,\n} from \"@copilotkit/shared\";\nimport React from \"react\";\n\ninterface InProgressState<T extends Parameter[] | [] = []> {\n status: \"inProgress\";\n args: Partial<MappedParameterTypes<T>>;\n result: undefined;\n}\n\ninterface ExecutingState<T extends Parameter[] | [] = []> {\n status: \"executing\";\n args: MappedParameterTypes<T>;\n result: undefined;\n}\n\ninterface CompleteState<T extends Parameter[] | [] = []> {\n status: \"complete\";\n args: MappedParameterTypes<T>;\n result: any;\n}\n\ninterface InProgressStateNoArgs<T extends Parameter[] | [] = []> {\n status: \"inProgress\";\n args: Partial<MappedParameterTypes<T>>;\n result: undefined;\n}\n\ninterface ExecutingStateNoArgs<T extends Parameter[] | [] = []> {\n status: \"executing\";\n args: MappedParameterTypes<T>;\n result: undefined;\n}\n\ninterface CompleteStateNoArgs<T extends Parameter[] | [] = []> {\n status: \"complete\";\n args: MappedParameterTypes<T>;\n result: any;\n}\n\ninterface InProgressStateWait<T extends Parameter[] | [] = []> {\n status: \"inProgress\";\n args: Partial<MappedParameterTypes<T>>;\n /** @deprecated use respond instead */\n handler: undefined;\n respond: undefined;\n result: undefined;\n}\n\ninterface ExecutingStateWait<T extends Parameter[] | [] = []> {\n status: \"executing\";\n args: MappedParameterTypes<T>;\n /** @deprecated use respond instead */\n handler: (result: any) => void;\n respond: (result: any) => void;\n result: undefined;\n}\n\ninterface CompleteStateWait<T extends Parameter[] | [] = []> {\n status: \"complete\";\n args: MappedParameterTypes<T>;\n /** @deprecated use respond instead */\n handler: undefined;\n respond: undefined;\n result: any;\n}\n\ninterface InProgressStateNoArgsWait<T extends Parameter[] | [] = []> {\n status: \"inProgress\";\n args: Partial<MappedParameterTypes<T>>;\n /** @deprecated use respond instead */\n handler: undefined;\n respond: undefined;\n result: undefined;\n}\n\ninterface ExecutingStateNoArgsWait<T extends Parameter[] | [] = []> {\n status: \"executing\";\n args: MappedParameterTypes<T>;\n /** @deprecated use respond instead */\n handler: (result: any) => void;\n respond: (result: any) => void;\n result: undefined;\n}\n\ninterface CompleteStateNoArgsWait<T extends Parameter[] | [] = []> {\n status: \"complete\";\n args: MappedParameterTypes<T>;\n /** @deprecated use respond instead */\n handler: undefined;\n respond: undefined;\n}\n\nexport type ActionRenderProps<T extends Parameter[] | [] = []> =\n | CompleteState<T>\n | ExecutingState<T>\n | InProgressState<T>;\n\nexport type ActionRenderPropsNoArgs<T extends Parameter[] | [] = []> =\n | CompleteStateNoArgs<T>\n | ExecutingStateNoArgs<T>\n | InProgressStateNoArgs<T>;\n\nexport type ActionRenderPropsWait<T extends Parameter[] | [] = []> =\n | CompleteStateWait<T>\n | ExecutingStateWait<T>\n | InProgressStateWait<T>;\n\nexport type ActionRenderPropsNoArgsWait<T extends Parameter[] | [] = []> =\n | CompleteStateNoArgsWait<T>\n | ExecutingStateNoArgsWait<T>\n | InProgressStateNoArgsWait<T>;\n\nexport type CatchAllActionRenderProps<T extends Parameter[] | [] = []> =\n | (CompleteState<T> & {\n name: string;\n })\n | (ExecutingState<T> & {\n name: string;\n })\n | (InProgressState<T> & {\n name: string;\n });\n\nexport type FrontendActionAvailability = \"disabled\" | \"enabled\" | \"remote\";\n\nexport type FrontendAction<\n T extends Parameter[] | [] = [],\n N extends string = string,\n> = Action<T> & {\n name: Exclude<N, \"*\">;\n /**\n * @deprecated Use `available` instead.\n */\n disabled?: boolean;\n available?: FrontendActionAvailability;\n followUp?: boolean;\n} & (\n | {\n render?:\n | string\n | (T extends []\n ? (props: ActionRenderPropsNoArgs<T>) => string | React.ReactElement\n : (props: ActionRenderProps<T>) => string | React.ReactElement);\n /** @deprecated use renderAndWaitForResponse instead */\n renderAndWait?: never;\n renderAndWaitForResponse?: never;\n }\n | {\n render?: never;\n /** @deprecated use renderAndWaitForResponse instead */\n renderAndWait?: T extends []\n ? (props: ActionRenderPropsNoArgsWait<T>) => React.ReactElement\n : (props: ActionRenderPropsWait<T>) => React.ReactElement;\n renderAndWaitForResponse?: T extends []\n ? (props: ActionRenderPropsNoArgsWait<T>) => React.ReactElement\n : (props: ActionRenderPropsWait<T>) => React.ReactElement;\n handler?: never;\n }\n );\n\nexport type CatchAllFrontendAction = {\n name: \"*\";\n render: (props: CatchAllActionRenderProps<any>) => React.ReactElement;\n};\n\nexport type RenderFunctionStatus = ActionRenderProps<any>[\"status\"];\n\nexport function processActionsForRuntimeRequest(actions: FrontendAction<any>[]) {\n const filteredActions = actions\n .filter(\n (action) =>\n action.available !== ActionInputAvailability.Disabled &&\n action.disabled !== true &&\n action.name !== \"*\",\n )\n .map((action) => {\n let available: ActionInputAvailability | undefined = ActionInputAvailability.Enabled;\n if (action.disabled) {\n available = ActionInputAvailability.Disabled;\n } else if (action.available === \"disabled\") {\n available = ActionInputAvailability.Disabled;\n } else if (action.available === \"remote\") {\n available = ActionInputAvailability.Remote;\n }\n return {\n name: action.name,\n description: action.description || \"\",\n jsonSchema: JSON.stringify(actionParametersToJsonSchema(action.parameters || [])),\n available,\n };\n });\n return filteredActions;\n}\n"],"mappings":";AAAA,SAAS,+BAA+B;AACxC;AAAA,EAIE;AAAA,OACK;AAuKA,SAAS,gCAAgC,SAAgC;AAC9E,QAAM,kBAAkB,QACrB;AAAA,IACC,CAAC,WACC,OAAO,cAAc,wBAAwB,YAC7C,OAAO,aAAa,QACpB,OAAO,SAAS;AAAA,EACpB,EACC,IAAI,CAAC,WAAW;AACf,QAAI,YAAiD,wBAAwB;AAC7E,QAAI,OAAO,UAAU;AACnB,kBAAY,wBAAwB;AAAA,IACtC,WAAW,OAAO,cAAc,YAAY;AAC1C,kBAAY,wBAAwB;AAAA,IACtC,WAAW,OAAO,cAAc,UAAU;AACxC,kBAAY,wBAAwB;AAAA,IACtC;AACA,WAAO;AAAA,MACL,MAAM,OAAO;AAAA,MACb,aAAa,OAAO,eAAe;AAAA,MACnC,YAAY,KAAK,UAAU,6BAA6B,OAAO,cAAc,CAAC,CAAC,CAAC;AAAA,MAChF;AAAA,IACF;AAAA,EACF,CAAC;AACH,SAAO;AACT;","names":[]}
@@ -0,0 +1,120 @@
1
+ import {
2
+ defaultCopilotContextCategories
3
+ } from "./chunk-2KT73RVG.mjs";
4
+ import {
5
+ processActionsForRuntimeRequest
6
+ } from "./chunk-XERJQUHA.mjs";
7
+ import {
8
+ __async,
9
+ __spreadProps,
10
+ __spreadValues
11
+ } from "./chunk-SKC7AJIV.mjs";
12
+
13
+ // src/lib/copilot-task.ts
14
+ import {
15
+ CopilotRuntimeClient,
16
+ Role,
17
+ TextMessage,
18
+ convertGqlOutputToMessages,
19
+ convertMessagesToGqlInput,
20
+ filterAgentStateMessages,
21
+ CopilotRequestType
22
+ } from "@copilotkit/runtime-client-gql";
23
+ var CopilotTask = class {
24
+ constructor(config) {
25
+ this.instructions = config.instructions;
26
+ this.actions = config.actions || [];
27
+ this.includeCopilotReadable = config.includeCopilotReadable !== false;
28
+ this.includeCopilotActions = config.includeCopilotActions !== false;
29
+ this.forwardedParameters = config.forwardedParameters;
30
+ }
31
+ /**
32
+ * Run the task.
33
+ * @param context The CopilotContext to use for the task. Use `useCopilotContext` to obtain the current context.
34
+ * @param data The data to use for the task.
35
+ */
36
+ run(context, data) {
37
+ return __async(this, null, function* () {
38
+ var _a, _b, _c;
39
+ const actions = this.includeCopilotActions ? Object.assign({}, context.actions) : {};
40
+ for (const fn of this.actions) {
41
+ actions[fn.name] = fn;
42
+ }
43
+ let contextString = "";
44
+ if (data) {
45
+ contextString = (typeof data === "string" ? data : JSON.stringify(data)) + "\n\n";
46
+ }
47
+ if (this.includeCopilotReadable) {
48
+ contextString += context.getContextString([], defaultCopilotContextCategories);
49
+ }
50
+ const systemMessage = new TextMessage({
51
+ content: taskSystemMessage(contextString, this.instructions),
52
+ role: Role.System
53
+ });
54
+ const messages = [systemMessage];
55
+ const runtimeClient = new CopilotRuntimeClient({
56
+ url: context.copilotApiConfig.chatApiEndpoint,
57
+ publicApiKey: context.copilotApiConfig.publicApiKey,
58
+ headers: context.copilotApiConfig.headers,
59
+ credentials: context.copilotApiConfig.credentials
60
+ });
61
+ const response = yield runtimeClient.generateCopilotResponse({
62
+ data: {
63
+ frontend: {
64
+ actions: processActionsForRuntimeRequest(Object.values(actions)),
65
+ url: window.location.href
66
+ },
67
+ messages: convertMessagesToGqlInput(filterAgentStateMessages(messages)),
68
+ metadata: {
69
+ requestType: CopilotRequestType.Task
70
+ },
71
+ forwardedParameters: __spreadProps(__spreadValues({}, (_a = this.forwardedParameters) != null ? _a : {}), {
72
+ toolChoice: "required"
73
+ })
74
+ },
75
+ properties: context.copilotApiConfig.properties
76
+ }).toPromise();
77
+ const functionCallHandler = context.getFunctionCallHandler(actions);
78
+ const functionCalls = convertGqlOutputToMessages(
79
+ ((_c = (_b = response.data) == null ? void 0 : _b.generateCopilotResponse) == null ? void 0 : _c.messages) || []
80
+ ).filter((m) => m.isActionExecutionMessage());
81
+ for (const functionCall of functionCalls) {
82
+ yield functionCallHandler({
83
+ messages,
84
+ name: functionCall.name,
85
+ args: functionCall.arguments
86
+ });
87
+ }
88
+ });
89
+ }
90
+ };
91
+ function taskSystemMessage(contextString, instructions) {
92
+ return `
93
+ Please act as an efficient, competent, conscientious, and industrious professional assistant.
94
+
95
+ 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.
96
+ Always be polite and respectful, and prefer brevity over verbosity.
97
+
98
+ The user has provided you with the following context:
99
+ \`\`\`
100
+ ${contextString}
101
+ \`\`\`
102
+
103
+ They have also provided you with functions you can call to initiate actions on their behalf.
104
+
105
+ Please assist them as best you can.
106
+
107
+ This is not a conversation, so please do not ask questions. Just call a function without saying anything else.
108
+
109
+ The user has given you the following task to complete:
110
+
111
+ \`\`\`
112
+ ${instructions}
113
+ \`\`\`
114
+ `;
115
+ }
116
+
117
+ export {
118
+ CopilotTask
119
+ };
120
+ //# sourceMappingURL=chunk-XOQMISG3.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/lib/copilot-task.ts"],"sourcesContent":["/**\n * This class is used to execute one-off tasks, for example on button press. It can use the context available via [useCopilotReadable](/reference/hooks/useCopilotReadable) and the actions provided by [useCopilotAction](/reference/hooks/useCopilotAction), or you can provide your own context and actions.\n *\n * ## Example\n * In the simplest case, use CopilotTask in the context of your app by giving it instructions on what to do.\n *\n * ```tsx\n * import { CopilotTask, useCopilotContext } from \"@copilotkit/react-core\";\n *\n * export function MyComponent() {\n * const context = useCopilotContext();\n *\n * const task = new CopilotTask({\n * instructions: \"Set a random message\",\n * actions: [\n * {\n * name: \"setMessage\",\n * description: \"Set the message.\",\n * argumentAnnotations: [\n * {\n * name: \"message\",\n * type: \"string\",\n * description:\n * \"A message to display.\",\n * required: true,\n * },\n * ],\n * }\n * ]\n * });\n *\n * const executeTask = async () => {\n * await task.run(context, action);\n * }\n *\n * return (\n * <>\n * <button onClick={executeTask}>\n * Execute task\n * </button>\n * </>\n * )\n * }\n * ```\n *\n * Have a look at the [Presentation Example App](https://github.com/CopilotKit/CopilotKit/blob/main/CopilotKit/examples/next-openai/src/app/presentation/page.tsx) for a more complete example.\n */\n\nimport {\n ActionExecutionMessage,\n CopilotRuntimeClient,\n Message,\n Role,\n TextMessage,\n convertGqlOutputToMessages,\n convertMessagesToGqlInput,\n filterAgentStateMessages,\n CopilotRequestType,\n ForwardedParametersInput,\n} from \"@copilotkit/runtime-client-gql\";\nimport { FrontendAction, processActionsForRuntimeRequest } from \"../types/frontend-action\";\nimport { CopilotContextParams } from \"../context\";\nimport { defaultCopilotContextCategories } from \"../components\";\n\nexport interface CopilotTaskConfig {\n /**\n * The instructions to be given to the assistant.\n */\n instructions: string;\n /**\n * An array of action definitions that can be called.\n */\n actions?: FrontendAction<any>[];\n /**\n * Whether to include the copilot readable context in the task.\n */\n includeCopilotReadable?: boolean;\n\n /**\n * Whether to include actions defined via useCopilotAction in the task.\n */\n includeCopilotActions?: boolean;\n\n /**\n * The forwarded parameters to use for the task.\n */\n forwardedParameters?: ForwardedParametersInput;\n}\n\nexport class CopilotTask<T = any> {\n private instructions: string;\n private actions: FrontendAction<any>[];\n private includeCopilotReadable: boolean;\n private includeCopilotActions: boolean;\n private forwardedParameters?: ForwardedParametersInput;\n constructor(config: CopilotTaskConfig) {\n this.instructions = config.instructions;\n this.actions = config.actions || [];\n this.includeCopilotReadable = config.includeCopilotReadable !== false;\n this.includeCopilotActions = config.includeCopilotActions !== false;\n this.forwardedParameters = config.forwardedParameters;\n }\n\n /**\n * Run the task.\n * @param context The CopilotContext to use for the task. Use `useCopilotContext` to obtain the current context.\n * @param data The data to use for the task.\n */\n async run(context: CopilotContextParams, data?: T): Promise<void> {\n const actions = this.includeCopilotActions ? Object.assign({}, context.actions) : {};\n\n // merge functions into entry points\n for (const fn of this.actions) {\n actions[fn.name] = fn;\n }\n\n let contextString = \"\";\n\n if (data) {\n contextString = (typeof data === \"string\" ? data : JSON.stringify(data)) + \"\\n\\n\";\n }\n\n if (this.includeCopilotReadable) {\n contextString += context.getContextString([], defaultCopilotContextCategories);\n }\n\n const systemMessage = new TextMessage({\n content: taskSystemMessage(contextString, this.instructions),\n role: Role.System,\n });\n\n const messages: Message[] = [systemMessage];\n\n const runtimeClient = new CopilotRuntimeClient({\n url: context.copilotApiConfig.chatApiEndpoint,\n publicApiKey: context.copilotApiConfig.publicApiKey,\n headers: context.copilotApiConfig.headers,\n credentials: context.copilotApiConfig.credentials,\n });\n\n const response = await runtimeClient\n .generateCopilotResponse({\n data: {\n frontend: {\n actions: processActionsForRuntimeRequest(Object.values(actions)),\n url: window.location.href,\n },\n messages: convertMessagesToGqlInput(filterAgentStateMessages(messages)),\n metadata: {\n requestType: CopilotRequestType.Task,\n },\n forwardedParameters: {\n // if forwardedParameters is provided, use it\n ...(this.forwardedParameters ?? {}),\n toolChoice: \"required\",\n },\n },\n properties: context.copilotApiConfig.properties,\n })\n .toPromise();\n\n const functionCallHandler = context.getFunctionCallHandler(actions);\n const functionCalls = convertGqlOutputToMessages(\n response.data?.generateCopilotResponse?.messages || [],\n ).filter((m): m is ActionExecutionMessage => m.isActionExecutionMessage());\n\n for (const functionCall of functionCalls) {\n await functionCallHandler({\n messages,\n name: functionCall.name,\n args: functionCall.arguments,\n });\n }\n }\n}\n\nfunction taskSystemMessage(contextString: string, instructions: string): string {\n return `\nPlease act as an efficient, competent, conscientious, and industrious professional assistant.\n\nHelp the user achieve their goals, and you do so in a way that is as efficient as possible, without unnecessary fluff, but also without sacrificing professionalism.\nAlways be polite and respectful, and prefer brevity over verbosity.\n\nThe user has provided you with the following context:\n\\`\\`\\`\n${contextString}\n\\`\\`\\`\n\nThey have also provided you with functions you can call to initiate actions on their behalf.\n\nPlease assist them as best you can.\n\nThis is not a conversation, so please do not ask questions. Just call a function without saying anything else.\n\nThe user has given you the following task to complete:\n\n\\`\\`\\`\n${instructions}\n\\`\\`\\`\n`;\n}\n"],"mappings":";;;;;;;;;;;;;AAgDA;AAAA,EAEE;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AA8BA,IAAM,cAAN,MAA2B;AAAA,EAMhC,YAAY,QAA2B;AACrC,SAAK,eAAe,OAAO;AAC3B,SAAK,UAAU,OAAO,WAAW,CAAC;AAClC,SAAK,yBAAyB,OAAO,2BAA2B;AAChE,SAAK,wBAAwB,OAAO,0BAA0B;AAC9D,SAAK,sBAAsB,OAAO;AAAA,EACpC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOM,IAAI,SAA+B,MAAyB;AAAA;AA5GpE;AA6GI,YAAM,UAAU,KAAK,wBAAwB,OAAO,OAAO,CAAC,GAAG,QAAQ,OAAO,IAAI,CAAC;AAGnF,iBAAW,MAAM,KAAK,SAAS;AAC7B,gBAAQ,GAAG,IAAI,IAAI;AAAA,MACrB;AAEA,UAAI,gBAAgB;AAEpB,UAAI,MAAM;AACR,yBAAiB,OAAO,SAAS,WAAW,OAAO,KAAK,UAAU,IAAI,KAAK;AAAA,MAC7E;AAEA,UAAI,KAAK,wBAAwB;AAC/B,yBAAiB,QAAQ,iBAAiB,CAAC,GAAG,+BAA+B;AAAA,MAC/E;AAEA,YAAM,gBAAgB,IAAI,YAAY;AAAA,QACpC,SAAS,kBAAkB,eAAe,KAAK,YAAY;AAAA,QAC3D,MAAM,KAAK;AAAA,MACb,CAAC;AAED,YAAM,WAAsB,CAAC,aAAa;AAE1C,YAAM,gBAAgB,IAAI,qBAAqB;AAAA,QAC7C,KAAK,QAAQ,iBAAiB;AAAA,QAC9B,cAAc,QAAQ,iBAAiB;AAAA,QACvC,SAAS,QAAQ,iBAAiB;AAAA,QAClC,aAAa,QAAQ,iBAAiB;AAAA,MACxC,CAAC;AAED,YAAM,WAAW,MAAM,cACpB,wBAAwB;AAAA,QACvB,MAAM;AAAA,UACJ,UAAU;AAAA,YACR,SAAS,gCAAgC,OAAO,OAAO,OAAO,CAAC;AAAA,YAC/D,KAAK,OAAO,SAAS;AAAA,UACvB;AAAA,UACA,UAAU,0BAA0B,yBAAyB,QAAQ,CAAC;AAAA,UACtE,UAAU;AAAA,YACR,aAAa,mBAAmB;AAAA,UAClC;AAAA,UACA,qBAAqB,kCAEf,UAAK,wBAAL,YAA4B,CAAC,IAFd;AAAA,YAGnB,YAAY;AAAA,UACd;AAAA,QACF;AAAA,QACA,YAAY,QAAQ,iBAAiB;AAAA,MACvC,CAAC,EACA,UAAU;AAEb,YAAM,sBAAsB,QAAQ,uBAAuB,OAAO;AAClE,YAAM,gBAAgB;AAAA,UACpB,oBAAS,SAAT,mBAAe,4BAAf,mBAAwC,aAAY,CAAC;AAAA,MACvD,EAAE,OAAO,CAAC,MAAmC,EAAE,yBAAyB,CAAC;AAEzE,iBAAW,gBAAgB,eAAe;AACxC,cAAM,oBAAoB;AAAA,UACxB;AAAA,UACA,MAAM,aAAa;AAAA,UACnB,MAAM,aAAa;AAAA,QACrB,CAAC;AAAA,MACH;AAAA,IACF;AAAA;AACF;AAEA,SAAS,kBAAkB,eAAuB,cAA8B;AAC9E,SAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQP;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYA;AAAA;AAAA;AAGF;","names":[]}
@@ -0,0 +1,29 @@
1
+ import {
2
+ CopilotMessagesContext
3
+ } from "./chunk-DCTJZ742.mjs";
4
+ import {
5
+ __objRest
6
+ } from "./chunk-SKC7AJIV.mjs";
7
+
8
+ // src/components/copilot-provider/copilot-messages.tsx
9
+ import { useState } from "react";
10
+ import { jsx } from "react/jsx-runtime";
11
+ function CopilotMessages(_a) {
12
+ var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
13
+ const [messages, setMessages] = useState([]);
14
+ return /* @__PURE__ */ jsx(
15
+ CopilotMessagesContext.Provider,
16
+ {
17
+ value: {
18
+ messages,
19
+ setMessages
20
+ },
21
+ children
22
+ }
23
+ );
24
+ }
25
+
26
+ export {
27
+ CopilotMessages
28
+ };
29
+ //# sourceMappingURL=chunk-XXR4QFAQ.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/components/copilot-provider/copilot-messages.tsx"],"sourcesContent":["/**\n * An internal context to separate the messages state (which is constantly changing) from the rest of CopilotKit context\n */\n\nimport { useState } from \"react\";\nimport { CopilotMessagesContext } from \"../../context/copilot-messages-context\";\nimport { Message } from \"@copilotkit/runtime-client-gql\";\nimport { CopilotKitProps } from \"./copilotkit-props\";\n\nexport function CopilotMessages({ children, ...props }: CopilotKitProps) {\n const [messages, setMessages] = useState<Message[]>([]);\n\n return (\n <CopilotMessagesContext.Provider\n value={{\n messages,\n setMessages,\n }}\n >\n {children}\n </CopilotMessagesContext.Provider>\n );\n}\n"],"mappings":";;;;;;;;AAIA,SAAS,gBAAgB;AASrB;AAJG,SAAS,gBAAgB,IAAyC;AAAzC,eAAE,WATlC,IASgC,IAAe,kBAAf,IAAe,CAAb;AAChC,QAAM,CAAC,UAAU,WAAW,IAAI,SAAoB,CAAC,CAAC;AAEtD,SACE;AAAA,IAAC,uBAAuB;AAAA,IAAvB;AAAA,MACC,OAAO;AAAA,QACL;AAAA,QACA;AAAA,MACF;AAAA,MAEC;AAAA;AAAA,EACH;AAEJ;","names":[]}
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=chunk-YPSGKPDA.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,16 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { CopilotKitProps } from './copilotkit-props.js';
3
+ import '@copilotkit/runtime-client-gql';
4
+ import 'react';
5
+ import '../../context/copilot-context.js';
6
+ import '@copilotkit/shared';
7
+ import '../../types/frontend-action.js';
8
+ import '../../hooks/use-tree.js';
9
+ import '../../types/document-pointer.js';
10
+ import '../../types/chat-suggestion-configuration.js';
11
+ import '../../types/coagent-action.js';
12
+ import '../../types/coagent-state.js';
13
+
14
+ declare function CopilotMessages({ children, ...props }: CopilotKitProps): react_jsx_runtime.JSX.Element;
15
+
16
+ export { CopilotMessages };
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
10
+ var __objRest = (source, exclude) => {
11
+ var target = {};
12
+ for (var prop in source)
13
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
14
+ target[prop] = source[prop];
15
+ if (source != null && __getOwnPropSymbols)
16
+ for (var prop of __getOwnPropSymbols(source)) {
17
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
18
+ target[prop] = source[prop];
19
+ }
20
+ return target;
21
+ };
22
+ var __export = (target, all) => {
23
+ for (var name in all)
24
+ __defProp(target, name, { get: all[name], enumerable: true });
25
+ };
26
+ var __copyProps = (to, from, except, desc) => {
27
+ if (from && typeof from === "object" || typeof from === "function") {
28
+ for (let key of __getOwnPropNames(from))
29
+ if (!__hasOwnProp.call(to, key) && key !== except)
30
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
31
+ }
32
+ return to;
33
+ };
34
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
35
+ // If the importer is in node compatibility mode or this is not an ESM
36
+ // file that has been converted to a CommonJS file using a Babel-
37
+ // compatible transform (i.e. "__esModule" has not been set), then set
38
+ // "default" to the CommonJS "module.exports" for node compatibility.
39
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
40
+ mod
41
+ ));
42
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
43
+
44
+ // src/components/copilot-provider/copilot-messages.tsx
45
+ var copilot_messages_exports = {};
46
+ __export(copilot_messages_exports, {
47
+ CopilotMessages: () => CopilotMessages
48
+ });
49
+ module.exports = __toCommonJS(copilot_messages_exports);
50
+ var import_react2 = require("react");
51
+
52
+ // src/context/copilot-messages-context.tsx
53
+ var import_react = __toESM(require("react"));
54
+ var emptyCopilotContext = {
55
+ messages: [],
56
+ setMessages: () => []
57
+ };
58
+ var CopilotMessagesContext = import_react.default.createContext(emptyCopilotContext);
59
+
60
+ // src/components/copilot-provider/copilot-messages.tsx
61
+ var import_jsx_runtime = require("react/jsx-runtime");
62
+ function CopilotMessages(_a) {
63
+ var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
64
+ const [messages, setMessages] = (0, import_react2.useState)([]);
65
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
66
+ CopilotMessagesContext.Provider,
67
+ {
68
+ value: {
69
+ messages,
70
+ setMessages
71
+ },
72
+ children
73
+ }
74
+ );
75
+ }
76
+ // Annotate the CommonJS export names for ESM import in node:
77
+ 0 && (module.exports = {
78
+ CopilotMessages
79
+ });
80
+ //# sourceMappingURL=copilot-messages.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/components/copilot-provider/copilot-messages.tsx","../../../src/context/copilot-messages-context.tsx"],"sourcesContent":["/**\n * An internal context to separate the messages state (which is constantly changing) from the rest of CopilotKit context\n */\n\nimport { useState } from \"react\";\nimport { CopilotMessagesContext } from \"../../context/copilot-messages-context\";\nimport { Message } from \"@copilotkit/runtime-client-gql\";\nimport { CopilotKitProps } from \"./copilotkit-props\";\n\nexport function CopilotMessages({ children, ...props }: CopilotKitProps) {\n const [messages, setMessages] = useState<Message[]>([]);\n\n return (\n <CopilotMessagesContext.Provider\n value={{\n messages,\n setMessages,\n }}\n >\n {children}\n </CopilotMessagesContext.Provider>\n );\n}\n","/**\n * An internal context to separate the messages state (which is constantly changing) from the rest of CopilotKit context\n */\n\nimport { Message } from \"@copilotkit/runtime-client-gql\";\nimport React from \"react\";\n\nexport interface CopilotMessagesContextParams {\n messages: Message[];\n setMessages: React.Dispatch<React.SetStateAction<Message[]>>;\n}\n\nconst emptyCopilotContext: CopilotMessagesContextParams = {\n messages: [],\n setMessages: () => [],\n};\n\nexport const CopilotMessagesContext =\n React.createContext<CopilotMessagesContextParams>(emptyCopilotContext);\n\nexport function useCopilotMessagesContext(): CopilotMessagesContextParams {\n const context = React.useContext(CopilotMessagesContext);\n if (context === emptyCopilotContext) {\n throw new Error(\n \"A messages consuming component was not wrapped with `<CopilotMessages> {...} </CopilotMessages>`\",\n );\n }\n return context;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,IAAAA,gBAAyB;;;ACCzB,mBAAkB;AAOlB,IAAM,sBAAoD;AAAA,EACxD,UAAU,CAAC;AAAA,EACX,aAAa,MAAM,CAAC;AACtB;AAEO,IAAM,yBACX,aAAAC,QAAM,cAA4C,mBAAmB;;;ADLnE;AAJG,SAAS,gBAAgB,IAAyC;AAAzC,eAAE,WATlC,IASgC,IAAe,kBAAf,IAAe,CAAb;AAChC,QAAM,CAAC,UAAU,WAAW,QAAI,wBAAoB,CAAC,CAAC;AAEtD,SACE;AAAA,IAAC,uBAAuB;AAAA,IAAvB;AAAA,MACC,OAAO;AAAA,QACL;AAAA,QACA;AAAA,MACF;AAAA,MAEC;AAAA;AAAA,EACH;AAEJ;","names":["import_react","React"]}
@@ -0,0 +1,9 @@
1
+ import {
2
+ CopilotMessages
3
+ } from "../../chunk-XXR4QFAQ.mjs";
4
+ import "../../chunk-DCTJZ742.mjs";
5
+ import "../../chunk-SKC7AJIV.mjs";
6
+ export {
7
+ CopilotMessages
8
+ };
9
+ //# sourceMappingURL=copilot-messages.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}