@copilotkit/react-core 0.0.0-feat-dynamic-copilotcloud-qa-20250117190454

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 (293) hide show
  1. package/CHANGELOG.md +2001 -0
  2. package/README.md +48 -0
  3. package/dist/chunk-22XKTBPF.mjs +61 -0
  4. package/dist/chunk-22XKTBPF.mjs.map +1 -0
  5. package/dist/chunk-2KT73RVG.mjs +482 -0
  6. package/dist/chunk-2KT73RVG.mjs.map +1 -0
  7. package/dist/chunk-4TDYSNUD.mjs +215 -0
  8. package/dist/chunk-4TDYSNUD.mjs.map +1 -0
  9. package/dist/chunk-5FHSUKQL.mjs +70 -0
  10. package/dist/chunk-5FHSUKQL.mjs.map +1 -0
  11. package/dist/chunk-6BQVZFNO.mjs +35 -0
  12. package/dist/chunk-6BQVZFNO.mjs.map +1 -0
  13. package/dist/chunk-6U3UH3KO.mjs +140 -0
  14. package/dist/chunk-6U3UH3KO.mjs.map +1 -0
  15. package/dist/chunk-DCTJZ742.mjs +22 -0
  16. package/dist/chunk-DCTJZ742.mjs.map +1 -0
  17. package/dist/chunk-EFZPSZWO.mjs +1 -0
  18. package/dist/chunk-EFZPSZWO.mjs.map +1 -0
  19. package/dist/chunk-EWKJMQOF.mjs +107 -0
  20. package/dist/chunk-EWKJMQOF.mjs.map +1 -0
  21. package/dist/chunk-FQ53HQYZ.mjs +28 -0
  22. package/dist/chunk-FQ53HQYZ.mjs.map +1 -0
  23. package/dist/chunk-HIUT2NLX.mjs +23 -0
  24. package/dist/chunk-HIUT2NLX.mjs.map +1 -0
  25. package/dist/chunk-KSPLXKSX.mjs +160 -0
  26. package/dist/chunk-KSPLXKSX.mjs.map +1 -0
  27. package/dist/chunk-LHKIIAUQ.mjs +59 -0
  28. package/dist/chunk-LHKIIAUQ.mjs.map +1 -0
  29. package/dist/chunk-LNI2Z45S.mjs +242 -0
  30. package/dist/chunk-LNI2Z45S.mjs.map +1 -0
  31. package/dist/chunk-LUGEI4YQ.mjs +1 -0
  32. package/dist/chunk-LUGEI4YQ.mjs.map +1 -0
  33. package/dist/chunk-MLAS4QUR.mjs +18 -0
  34. package/dist/chunk-MLAS4QUR.mjs.map +1 -0
  35. package/dist/chunk-NR2BTA6Z.mjs +1 -0
  36. package/dist/chunk-NR2BTA6Z.mjs.map +1 -0
  37. package/dist/chunk-O7ARI5CV.mjs +31 -0
  38. package/dist/chunk-O7ARI5CV.mjs.map +1 -0
  39. package/dist/chunk-SKC7AJIV.mjs +61 -0
  40. package/dist/chunk-SKC7AJIV.mjs.map +1 -0
  41. package/dist/chunk-U6JICUGO.mjs +405 -0
  42. package/dist/chunk-U6JICUGO.mjs.map +1 -0
  43. package/dist/chunk-VNTDIJSG.mjs +37 -0
  44. package/dist/chunk-VNTDIJSG.mjs.map +1 -0
  45. package/dist/chunk-WXREY7UP.mjs +87 -0
  46. package/dist/chunk-WXREY7UP.mjs.map +1 -0
  47. package/dist/chunk-XERJQUHA.mjs +31 -0
  48. package/dist/chunk-XERJQUHA.mjs.map +1 -0
  49. package/dist/chunk-XOQMISG3.mjs +120 -0
  50. package/dist/chunk-XOQMISG3.mjs.map +1 -0
  51. package/dist/chunk-XXR4QFAQ.mjs +29 -0
  52. package/dist/chunk-XXR4QFAQ.mjs.map +1 -0
  53. package/dist/chunk-YPSGKPDA.mjs +1 -0
  54. package/dist/chunk-YPSGKPDA.mjs.map +1 -0
  55. package/dist/components/copilot-provider/copilot-messages.d.ts +16 -0
  56. package/dist/components/copilot-provider/copilot-messages.js +80 -0
  57. package/dist/components/copilot-provider/copilot-messages.js.map +1 -0
  58. package/dist/components/copilot-provider/copilot-messages.mjs +9 -0
  59. package/dist/components/copilot-provider/copilot-messages.mjs.map +1 -0
  60. package/dist/components/copilot-provider/copilotkit-props.d.ts +93 -0
  61. package/dist/components/copilot-provider/copilotkit-props.js +19 -0
  62. package/dist/components/copilot-provider/copilotkit-props.js.map +1 -0
  63. package/dist/components/copilot-provider/copilotkit-props.mjs +1 -0
  64. package/dist/components/copilot-provider/copilotkit-props.mjs.map +1 -0
  65. package/dist/components/copilot-provider/copilotkit.d.ts +18 -0
  66. package/dist/components/copilot-provider/copilotkit.js +990 -0
  67. package/dist/components/copilot-provider/copilotkit.js.map +1 -0
  68. package/dist/components/copilot-provider/copilotkit.mjs +22 -0
  69. package/dist/components/copilot-provider/copilotkit.mjs.map +1 -0
  70. package/dist/components/copilot-provider/index.d.ts +13 -0
  71. package/dist/components/copilot-provider/index.js +990 -0
  72. package/dist/components/copilot-provider/index.js.map +1 -0
  73. package/dist/components/copilot-provider/index.mjs +20 -0
  74. package/dist/components/copilot-provider/index.mjs.map +1 -0
  75. package/dist/components/error-boundary/error-boundary.d.ts +22 -0
  76. package/dist/components/error-boundary/error-boundary.js +183 -0
  77. package/dist/components/error-boundary/error-boundary.js.map +1 -0
  78. package/dist/components/error-boundary/error-boundary.mjs +12 -0
  79. package/dist/components/error-boundary/error-boundary.mjs.map +1 -0
  80. package/dist/components/error-boundary/error-utils.d.ts +11 -0
  81. package/dist/components/error-boundary/error-utils.js +177 -0
  82. package/dist/components/error-boundary/error-utils.js.map +1 -0
  83. package/dist/components/error-boundary/error-utils.mjs +13 -0
  84. package/dist/components/error-boundary/error-utils.mjs.map +1 -0
  85. package/dist/components/index.d.ts +13 -0
  86. package/dist/components/index.js +990 -0
  87. package/dist/components/index.js.map +1 -0
  88. package/dist/components/index.mjs +20 -0
  89. package/dist/components/index.mjs.map +1 -0
  90. package/dist/components/toast/exclamation-mark-icon.d.ts +9 -0
  91. package/dist/components/toast/exclamation-mark-icon.js +55 -0
  92. package/dist/components/toast/exclamation-mark-icon.js.map +1 -0
  93. package/dist/components/toast/exclamation-mark-icon.mjs +8 -0
  94. package/dist/components/toast/exclamation-mark-icon.mjs.map +1 -0
  95. package/dist/components/toast/toast-provider.d.ts +30 -0
  96. package/dist/components/toast/toast-provider.js +269 -0
  97. package/dist/components/toast/toast-provider.js.map +1 -0
  98. package/dist/components/toast/toast-provider.mjs +11 -0
  99. package/dist/components/toast/toast-provider.mjs.map +1 -0
  100. package/dist/context/copilot-context.d.ts +142 -0
  101. package/dist/context/copilot-context.js +138 -0
  102. package/dist/context/copilot-context.js.map +1 -0
  103. package/dist/context/copilot-context.mjs +10 -0
  104. package/dist/context/copilot-context.mjs.map +1 -0
  105. package/dist/context/copilot-messages-context.d.ts +15 -0
  106. package/dist/context/copilot-messages-context.js +57 -0
  107. package/dist/context/copilot-messages-context.js.map +1 -0
  108. package/dist/context/copilot-messages-context.mjs +10 -0
  109. package/dist/context/copilot-messages-context.mjs.map +1 -0
  110. package/dist/context/index.d.ts +11 -0
  111. package/dist/context/index.js +161 -0
  112. package/dist/context/index.js.map +1 -0
  113. package/dist/context/index.mjs +17 -0
  114. package/dist/context/index.mjs.map +1 -0
  115. package/dist/hooks/index.d.ts +21 -0
  116. package/dist/hooks/index.js +1307 -0
  117. package/dist/hooks/index.js.map +1 -0
  118. package/dist/hooks/index.mjs +56 -0
  119. package/dist/hooks/index.mjs.map +1 -0
  120. package/dist/hooks/use-chat.d.ts +130 -0
  121. package/dist/hooks/use-chat.js +612 -0
  122. package/dist/hooks/use-chat.js.map +1 -0
  123. package/dist/hooks/use-chat.mjs +12 -0
  124. package/dist/hooks/use-chat.mjs.map +1 -0
  125. package/dist/hooks/use-coagent-state-render.d.ts +60 -0
  126. package/dist/hooks/use-coagent-state-render.js +195 -0
  127. package/dist/hooks/use-coagent-state-render.js.map +1 -0
  128. package/dist/hooks/use-coagent-state-render.mjs +11 -0
  129. package/dist/hooks/use-coagent-state-render.mjs.map +1 -0
  130. package/dist/hooks/use-coagent.d.ts +199 -0
  131. package/dist/hooks/use-coagent.js +1068 -0
  132. package/dist/hooks/use-coagent.js.map +1 -0
  133. package/dist/hooks/use-coagent.mjs +29 -0
  134. package/dist/hooks/use-coagent.mjs.map +1 -0
  135. package/dist/hooks/use-copilot-action.d.ts +140 -0
  136. package/dist/hooks/use-copilot-action.js +369 -0
  137. package/dist/hooks/use-copilot-action.js.map +1 -0
  138. package/dist/hooks/use-copilot-action.mjs +11 -0
  139. package/dist/hooks/use-copilot-action.mjs.map +1 -0
  140. package/dist/hooks/use-copilot-authenticated-action.d.ts +8 -0
  141. package/dist/hooks/use-copilot-authenticated-action.js +418 -0
  142. package/dist/hooks/use-copilot-authenticated-action.js.map +1 -0
  143. package/dist/hooks/use-copilot-authenticated-action.mjs +12 -0
  144. package/dist/hooks/use-copilot-authenticated-action.mjs.map +1 -0
  145. package/dist/hooks/use-copilot-chat.d.ts +48 -0
  146. package/dist/hooks/use-copilot-chat.js +932 -0
  147. package/dist/hooks/use-copilot-chat.js.map +1 -0
  148. package/dist/hooks/use-copilot-chat.mjs +24 -0
  149. package/dist/hooks/use-copilot-chat.mjs.map +1 -0
  150. package/dist/hooks/use-copilot-readable.d.ts +33 -0
  151. package/dist/hooks/use-copilot-readable.js +158 -0
  152. package/dist/hooks/use-copilot-readable.js.map +1 -0
  153. package/dist/hooks/use-copilot-readable.mjs +9 -0
  154. package/dist/hooks/use-copilot-readable.mjs.map +1 -0
  155. package/dist/hooks/use-copilot-runtime-client.d.ts +5 -0
  156. package/dist/hooks/use-copilot-runtime-client.js +182 -0
  157. package/dist/hooks/use-copilot-runtime-client.js.map +1 -0
  158. package/dist/hooks/use-copilot-runtime-client.mjs +10 -0
  159. package/dist/hooks/use-copilot-runtime-client.mjs.map +1 -0
  160. package/dist/hooks/use-flat-category-store.d.ts +9 -0
  161. package/dist/hooks/use-flat-category-store.js +90 -0
  162. package/dist/hooks/use-flat-category-store.js.map +1 -0
  163. package/dist/hooks/use-flat-category-store.mjs +8 -0
  164. package/dist/hooks/use-flat-category-store.mjs.map +1 -0
  165. package/dist/hooks/use-make-copilot-document-readable.d.ts +12 -0
  166. package/dist/hooks/use-make-copilot-document-readable.js +153 -0
  167. package/dist/hooks/use-make-copilot-document-readable.js.map +1 -0
  168. package/dist/hooks/use-make-copilot-document-readable.mjs +9 -0
  169. package/dist/hooks/use-make-copilot-document-readable.mjs.map +1 -0
  170. package/dist/hooks/use-tree.d.ts +18 -0
  171. package/dist/hooks/use-tree.js +172 -0
  172. package/dist/hooks/use-tree.js.map +1 -0
  173. package/dist/hooks/use-tree.mjs +8 -0
  174. package/dist/hooks/use-tree.mjs.map +1 -0
  175. package/dist/index.d.ts +27 -0
  176. package/dist/index.js +2228 -0
  177. package/dist/index.js.map +1 -0
  178. package/dist/index.mjs +83 -0
  179. package/dist/index.mjs.map +1 -0
  180. package/dist/lib/copilot-task.d.ts +97 -0
  181. package/dist/lib/copilot-task.js +195 -0
  182. package/dist/lib/copilot-task.js.map +1 -0
  183. package/dist/lib/copilot-task.mjs +20 -0
  184. package/dist/lib/copilot-task.mjs.map +1 -0
  185. package/dist/lib/index.d.ts +11 -0
  186. package/dist/lib/index.js +197 -0
  187. package/dist/lib/index.js.map +1 -0
  188. package/dist/lib/index.mjs +21 -0
  189. package/dist/lib/index.mjs.map +1 -0
  190. package/dist/types/chat-suggestion-configuration.d.ts +22 -0
  191. package/dist/types/chat-suggestion-configuration.js +19 -0
  192. package/dist/types/chat-suggestion-configuration.js.map +1 -0
  193. package/dist/types/chat-suggestion-configuration.mjs +1 -0
  194. package/dist/types/chat-suggestion-configuration.mjs.map +1 -0
  195. package/dist/types/coagent-action.d.ts +29 -0
  196. package/dist/types/coagent-action.js +19 -0
  197. package/dist/types/coagent-action.js.map +1 -0
  198. package/dist/types/coagent-action.mjs +1 -0
  199. package/dist/types/coagent-action.mjs.map +1 -0
  200. package/dist/types/coagent-state.d.ts +11 -0
  201. package/dist/types/coagent-state.js +19 -0
  202. package/dist/types/coagent-state.js.map +1 -0
  203. package/dist/types/coagent-state.mjs +1 -0
  204. package/dist/types/coagent-state.mjs.map +1 -0
  205. package/dist/types/document-pointer.d.ts +9 -0
  206. package/dist/types/document-pointer.js +19 -0
  207. package/dist/types/document-pointer.js.map +1 -0
  208. package/dist/types/document-pointer.mjs +1 -0
  209. package/dist/types/document-pointer.mjs.map +1 -0
  210. package/dist/types/frontend-action.d.ts +126 -0
  211. package/dist/types/frontend-action.js +53 -0
  212. package/dist/types/frontend-action.js.map +1 -0
  213. package/dist/types/frontend-action.mjs +8 -0
  214. package/dist/types/frontend-action.mjs.map +1 -0
  215. package/dist/types/index.d.ts +7 -0
  216. package/dist/types/index.js +19 -0
  217. package/dist/types/index.js.map +1 -0
  218. package/dist/types/index.mjs +2 -0
  219. package/dist/types/index.mjs.map +1 -0
  220. package/dist/types/system-message.d.ts +3 -0
  221. package/dist/types/system-message.js +19 -0
  222. package/dist/types/system-message.js.map +1 -0
  223. package/dist/types/system-message.mjs +1 -0
  224. package/dist/types/system-message.mjs.map +1 -0
  225. package/dist/utils/dev-console.d.ts +3 -0
  226. package/dist/utils/dev-console.js +42 -0
  227. package/dist/utils/dev-console.js.map +1 -0
  228. package/dist/utils/dev-console.mjs +8 -0
  229. package/dist/utils/dev-console.mjs.map +1 -0
  230. package/dist/utils/extract.d.ts +43 -0
  231. package/dist/utils/extract.js +208 -0
  232. package/dist/utils/extract.js.map +1 -0
  233. package/dist/utils/extract.mjs +18 -0
  234. package/dist/utils/extract.mjs.map +1 -0
  235. package/dist/utils/index.d.ts +13 -0
  236. package/dist/utils/index.js +226 -0
  237. package/dist/utils/index.js.map +1 -0
  238. package/dist/utils/index.mjs +21 -0
  239. package/dist/utils/index.mjs.map +1 -0
  240. package/dist/utils/utils.d.ts +2 -0
  241. package/dist/utils/utils.js +19 -0
  242. package/dist/utils/utils.js.map +1 -0
  243. package/dist/utils/utils.mjs +1 -0
  244. package/dist/utils/utils.mjs.map +1 -0
  245. package/dist/utils/utils.test.d.ts +2 -0
  246. package/dist/utils/utils.test.js +9 -0
  247. package/dist/utils/utils.test.js.map +1 -0
  248. package/dist/utils/utils.test.mjs +7 -0
  249. package/dist/utils/utils.test.mjs.map +1 -0
  250. package/jest.config.js +5 -0
  251. package/package.json +69 -0
  252. package/src/components/copilot-provider/copilot-messages.tsx +23 -0
  253. package/src/components/copilot-provider/copilotkit-props.tsx +97 -0
  254. package/src/components/copilot-provider/copilotkit.tsx +401 -0
  255. package/src/components/copilot-provider/index.ts +3 -0
  256. package/src/components/error-boundary/error-boundary.tsx +42 -0
  257. package/src/components/error-boundary/error-utils.tsx +95 -0
  258. package/src/components/index.ts +1 -0
  259. package/src/components/toast/exclamation-mark-icon.tsx +27 -0
  260. package/src/components/toast/toast-provider.tsx +170 -0
  261. package/src/context/copilot-context.tsx +271 -0
  262. package/src/context/copilot-messages-context.tsx +29 -0
  263. package/src/context/index.ts +8 -0
  264. package/src/hooks/index.ts +12 -0
  265. package/src/hooks/use-chat.ts +649 -0
  266. package/src/hooks/use-coagent-state-render.ts +118 -0
  267. package/src/hooks/use-coagent.ts +368 -0
  268. package/src/hooks/use-copilot-action.ts +289 -0
  269. package/src/hooks/use-copilot-authenticated-action.ts +60 -0
  270. package/src/hooks/use-copilot-chat.ts +304 -0
  271. package/src/hooks/use-copilot-readable.ts +123 -0
  272. package/src/hooks/use-copilot-runtime-client.ts +28 -0
  273. package/src/hooks/use-flat-category-store.ts +104 -0
  274. package/src/hooks/use-make-copilot-document-readable.ts +30 -0
  275. package/src/hooks/use-tree.ts +202 -0
  276. package/src/index.tsx +7 -0
  277. package/src/lib/copilot-task.ts +201 -0
  278. package/src/lib/index.ts +1 -0
  279. package/src/types/chat-suggestion-configuration.ts +23 -0
  280. package/src/types/coagent-action.ts +31 -0
  281. package/src/types/coagent-state.ts +9 -0
  282. package/src/types/document-pointer.ts +7 -0
  283. package/src/types/frontend-action.ts +199 -0
  284. package/src/types/index.ts +8 -0
  285. package/src/types/system-message.ts +4 -0
  286. package/src/utils/dev-console.ts +18 -0
  287. package/src/utils/extract.ts +215 -0
  288. package/src/utils/index.ts +2 -0
  289. package/src/utils/utils.test.ts +7 -0
  290. package/src/utils/utils.ts +1 -0
  291. package/tsconfig.json +12 -0
  292. package/tsup.config.ts +16 -0
  293. package/typedoc.json +4 -0
@@ -0,0 +1,23 @@
1
+ export interface CopilotChatSuggestionConfiguration {
2
+ /**
3
+ * A prompt or instructions for the GPT to generate suggestions.
4
+ */
5
+ instructions: string;
6
+
7
+ /**
8
+ * The minimum number of suggestions to generate. Defaults to `1`.
9
+ * @default 1
10
+ */
11
+ minSuggestions?: number;
12
+
13
+ /**
14
+ * The maximum number of suggestions to generate. Defaults to `3`.
15
+ * @default 1
16
+ */
17
+ maxSuggestions?: number;
18
+
19
+ /**
20
+ * An optional class name to apply to the suggestions.
21
+ */
22
+ className?: string;
23
+ }
@@ -0,0 +1,31 @@
1
+ export type CoAgentStateRenderProps<T> = {
2
+ state: T;
3
+ nodeName: string;
4
+ status: "inProgress" | "complete";
5
+ };
6
+
7
+ export type CoAgentStateRenderHandlerArguments<T> = {
8
+ nodeName: string;
9
+ state: T;
10
+ };
11
+
12
+ export interface CoAgentStateRender<T = any> {
13
+ /**
14
+ * The name of the coagent.
15
+ */
16
+ name: string;
17
+ /**
18
+ * The node name of the coagent.
19
+ */
20
+ nodeName?: string;
21
+ /**
22
+ * The handler function to handle the state of the agent.
23
+ */
24
+ handler?: (props: CoAgentStateRenderHandlerArguments<T>) => void | Promise<void>;
25
+ /**
26
+ * The render function to handle the state of the agent.
27
+ */
28
+ render?:
29
+ | ((props: CoAgentStateRenderProps<T>) => string | React.ReactElement | undefined | null)
30
+ | string;
31
+ }
@@ -0,0 +1,9 @@
1
+ export interface CoagentState {
2
+ name: string;
3
+ state: any;
4
+ running: boolean;
5
+ active: boolean;
6
+ threadId?: string;
7
+ nodeName?: string;
8
+ runId?: string;
9
+ }
@@ -0,0 +1,7 @@
1
+ export interface DocumentPointer {
2
+ id: string;
3
+ name: string;
4
+ sourceApplication: string;
5
+ iconImageUri: string;
6
+ getContents: () => string;
7
+ }
@@ -0,0 +1,199 @@
1
+ import { ActionInputAvailability } from "@copilotkit/runtime-client-gql";
2
+ import {
3
+ Action,
4
+ Parameter,
5
+ MappedParameterTypes,
6
+ actionParametersToJsonSchema,
7
+ } from "@copilotkit/shared";
8
+ import React from "react";
9
+
10
+ interface InProgressState<T extends Parameter[] | [] = []> {
11
+ status: "inProgress";
12
+ args: Partial<MappedParameterTypes<T>>;
13
+ result: undefined;
14
+ }
15
+
16
+ interface ExecutingState<T extends Parameter[] | [] = []> {
17
+ status: "executing";
18
+ args: MappedParameterTypes<T>;
19
+ result: undefined;
20
+ }
21
+
22
+ interface CompleteState<T extends Parameter[] | [] = []> {
23
+ status: "complete";
24
+ args: MappedParameterTypes<T>;
25
+ result: any;
26
+ }
27
+
28
+ interface InProgressStateNoArgs<T extends Parameter[] | [] = []> {
29
+ status: "inProgress";
30
+ args: Partial<MappedParameterTypes<T>>;
31
+ result: undefined;
32
+ }
33
+
34
+ interface ExecutingStateNoArgs<T extends Parameter[] | [] = []> {
35
+ status: "executing";
36
+ args: MappedParameterTypes<T>;
37
+ result: undefined;
38
+ }
39
+
40
+ interface CompleteStateNoArgs<T extends Parameter[] | [] = []> {
41
+ status: "complete";
42
+ args: MappedParameterTypes<T>;
43
+ result: any;
44
+ }
45
+
46
+ interface InProgressStateWait<T extends Parameter[] | [] = []> {
47
+ status: "inProgress";
48
+ args: Partial<MappedParameterTypes<T>>;
49
+ /** @deprecated use respond instead */
50
+ handler: undefined;
51
+ respond: undefined;
52
+ result: undefined;
53
+ }
54
+
55
+ interface ExecutingStateWait<T extends Parameter[] | [] = []> {
56
+ status: "executing";
57
+ args: MappedParameterTypes<T>;
58
+ /** @deprecated use respond instead */
59
+ handler: (result: any) => void;
60
+ respond: (result: any) => void;
61
+ result: undefined;
62
+ }
63
+
64
+ interface CompleteStateWait<T extends Parameter[] | [] = []> {
65
+ status: "complete";
66
+ args: MappedParameterTypes<T>;
67
+ /** @deprecated use respond instead */
68
+ handler: undefined;
69
+ respond: undefined;
70
+ result: any;
71
+ }
72
+
73
+ interface InProgressStateNoArgsWait<T extends Parameter[] | [] = []> {
74
+ status: "inProgress";
75
+ args: Partial<MappedParameterTypes<T>>;
76
+ /** @deprecated use respond instead */
77
+ handler: undefined;
78
+ respond: undefined;
79
+ result: undefined;
80
+ }
81
+
82
+ interface ExecutingStateNoArgsWait<T extends Parameter[] | [] = []> {
83
+ status: "executing";
84
+ args: MappedParameterTypes<T>;
85
+ /** @deprecated use respond instead */
86
+ handler: (result: any) => void;
87
+ respond: (result: any) => void;
88
+ result: undefined;
89
+ }
90
+
91
+ interface CompleteStateNoArgsWait<T extends Parameter[] | [] = []> {
92
+ status: "complete";
93
+ args: MappedParameterTypes<T>;
94
+ /** @deprecated use respond instead */
95
+ handler: undefined;
96
+ respond: undefined;
97
+ }
98
+
99
+ export type ActionRenderProps<T extends Parameter[] | [] = []> =
100
+ | CompleteState<T>
101
+ | ExecutingState<T>
102
+ | InProgressState<T>;
103
+
104
+ export type ActionRenderPropsNoArgs<T extends Parameter[] | [] = []> =
105
+ | CompleteStateNoArgs<T>
106
+ | ExecutingStateNoArgs<T>
107
+ | InProgressStateNoArgs<T>;
108
+
109
+ export type ActionRenderPropsWait<T extends Parameter[] | [] = []> =
110
+ | CompleteStateWait<T>
111
+ | ExecutingStateWait<T>
112
+ | InProgressStateWait<T>;
113
+
114
+ export type ActionRenderPropsNoArgsWait<T extends Parameter[] | [] = []> =
115
+ | CompleteStateNoArgsWait<T>
116
+ | ExecutingStateNoArgsWait<T>
117
+ | InProgressStateNoArgsWait<T>;
118
+
119
+ export type CatchAllActionRenderProps<T extends Parameter[] | [] = []> =
120
+ | (CompleteState<T> & {
121
+ name: string;
122
+ })
123
+ | (ExecutingState<T> & {
124
+ name: string;
125
+ })
126
+ | (InProgressState<T> & {
127
+ name: string;
128
+ });
129
+
130
+ export type FrontendActionAvailability = "disabled" | "enabled" | "remote";
131
+
132
+ export type FrontendAction<
133
+ T extends Parameter[] | [] = [],
134
+ N extends string = string,
135
+ > = Action<T> & {
136
+ name: Exclude<N, "*">;
137
+ /**
138
+ * @deprecated Use `available` instead.
139
+ */
140
+ disabled?: boolean;
141
+ available?: FrontendActionAvailability;
142
+ followUp?: boolean;
143
+ } & (
144
+ | {
145
+ render?:
146
+ | string
147
+ | (T extends []
148
+ ? (props: ActionRenderPropsNoArgs<T>) => string | React.ReactElement
149
+ : (props: ActionRenderProps<T>) => string | React.ReactElement);
150
+ /** @deprecated use renderAndWaitForResponse instead */
151
+ renderAndWait?: never;
152
+ renderAndWaitForResponse?: never;
153
+ }
154
+ | {
155
+ render?: never;
156
+ /** @deprecated use renderAndWaitForResponse instead */
157
+ renderAndWait?: T extends []
158
+ ? (props: ActionRenderPropsNoArgsWait<T>) => React.ReactElement
159
+ : (props: ActionRenderPropsWait<T>) => React.ReactElement;
160
+ renderAndWaitForResponse?: T extends []
161
+ ? (props: ActionRenderPropsNoArgsWait<T>) => React.ReactElement
162
+ : (props: ActionRenderPropsWait<T>) => React.ReactElement;
163
+ handler?: never;
164
+ }
165
+ );
166
+
167
+ export type CatchAllFrontendAction = {
168
+ name: "*";
169
+ render: (props: CatchAllActionRenderProps<any>) => React.ReactElement;
170
+ };
171
+
172
+ export type RenderFunctionStatus = ActionRenderProps<any>["status"];
173
+
174
+ export function processActionsForRuntimeRequest(actions: FrontendAction<any>[]) {
175
+ const filteredActions = actions
176
+ .filter(
177
+ (action) =>
178
+ action.available !== ActionInputAvailability.Disabled &&
179
+ action.disabled !== true &&
180
+ action.name !== "*",
181
+ )
182
+ .map((action) => {
183
+ let available: ActionInputAvailability | undefined = ActionInputAvailability.Enabled;
184
+ if (action.disabled) {
185
+ available = ActionInputAvailability.Disabled;
186
+ } else if (action.available === "disabled") {
187
+ available = ActionInputAvailability.Disabled;
188
+ } else if (action.available === "remote") {
189
+ available = ActionInputAvailability.Remote;
190
+ }
191
+ return {
192
+ name: action.name,
193
+ description: action.description || "",
194
+ jsonSchema: JSON.stringify(actionParametersToJsonSchema(action.parameters || [])),
195
+ available,
196
+ };
197
+ });
198
+ return filteredActions;
199
+ }
@@ -0,0 +1,8 @@
1
+ export type { DocumentPointer } from "./document-pointer";
2
+ export type { SystemMessageFunction } from "./system-message";
3
+ export type {
4
+ ActionRenderProps,
5
+ RenderFunctionStatus,
6
+ CatchAllActionRenderProps,
7
+ } from "./frontend-action";
8
+ export type { CopilotChatSuggestionConfiguration } from "./chat-suggestion-configuration";
@@ -0,0 +1,4 @@
1
+ export type SystemMessageFunction = (
2
+ contextString: string,
3
+ additionalInstructions?: string,
4
+ ) => string;
@@ -0,0 +1,18 @@
1
+ export function shouldShowDevConsole(showDevConsole: boolean | "auto"): boolean {
2
+ if (typeof showDevConsole === "boolean") {
3
+ return showDevConsole;
4
+ }
5
+ return (
6
+ getHostname() === "localhost" ||
7
+ getHostname() === "127.0.0.1" ||
8
+ getHostname() === "0.0.0.0" ||
9
+ getHostname() === "::1"
10
+ );
11
+ }
12
+
13
+ function getHostname(): string {
14
+ if (typeof window !== "undefined" && window.location) {
15
+ return window.location.hostname;
16
+ }
17
+ return "";
18
+ }
@@ -0,0 +1,215 @@
1
+ import {
2
+ Action,
3
+ COPILOT_CLOUD_PUBLIC_API_KEY_HEADER,
4
+ MappedParameterTypes,
5
+ Parameter,
6
+ actionParametersToJsonSchema,
7
+ } from "@copilotkit/shared";
8
+ import {
9
+ ActionExecutionMessage,
10
+ Message,
11
+ Role,
12
+ TextMessage,
13
+ convertGqlOutputToMessages,
14
+ CopilotRequestType,
15
+ ForwardedParametersInput,
16
+ } from "@copilotkit/runtime-client-gql";
17
+ import { CopilotContextParams, CopilotMessagesContextParams } from "../context";
18
+ import { defaultCopilotContextCategories } from "../components";
19
+ import { CopilotRuntimeClient } from "@copilotkit/runtime-client-gql";
20
+ import {
21
+ convertMessagesToGqlInput,
22
+ filterAgentStateMessages,
23
+ } from "@copilotkit/runtime-client-gql";
24
+
25
+ interface InitialState<T extends Parameter[] | [] = []> {
26
+ status: "initial";
27
+ args: Partial<MappedParameterTypes<T>>;
28
+ }
29
+
30
+ interface InProgressState<T extends Parameter[] | [] = []> {
31
+ status: "inProgress";
32
+ args: Partial<MappedParameterTypes<T>>;
33
+ }
34
+
35
+ interface CompleteState<T extends Parameter[] | [] = []> {
36
+ status: "complete";
37
+ args: MappedParameterTypes<T>;
38
+ }
39
+
40
+ type StreamHandlerArgs<T extends Parameter[] | [] = []> =
41
+ | InitialState<T>
42
+ | InProgressState<T>
43
+ | CompleteState<T>;
44
+
45
+ interface ExtractOptions<T extends Parameter[]> {
46
+ context: CopilotContextParams & CopilotMessagesContextParams;
47
+ instructions: string;
48
+ parameters: T;
49
+ include?: IncludeOptions;
50
+ data?: any;
51
+ abortSignal?: AbortSignal;
52
+ stream?: (args: StreamHandlerArgs<T>) => void;
53
+ requestType?: CopilotRequestType;
54
+ forwardedParameters?: ForwardedParametersInput;
55
+ }
56
+
57
+ interface IncludeOptions {
58
+ readable?: boolean;
59
+ messages?: boolean;
60
+ }
61
+
62
+ export async function extract<const T extends Parameter[]>({
63
+ context,
64
+ instructions,
65
+ parameters,
66
+ include,
67
+ data,
68
+ abortSignal,
69
+ stream,
70
+ requestType = CopilotRequestType.Task,
71
+ forwardedParameters,
72
+ }: ExtractOptions<T>): Promise<MappedParameterTypes<T>> {
73
+ const { messages } = context;
74
+
75
+ const action: Action<any> = {
76
+ name: "extract",
77
+ description: instructions,
78
+ parameters,
79
+ handler: (args: any) => {},
80
+ };
81
+
82
+ const includeReadable = include?.readable ?? false;
83
+ const includeMessages = include?.messages ?? false;
84
+
85
+ let contextString = "";
86
+
87
+ if (data) {
88
+ contextString = (typeof data === "string" ? data : JSON.stringify(data)) + "\n\n";
89
+ }
90
+
91
+ if (includeReadable) {
92
+ contextString += context.getContextString([], defaultCopilotContextCategories);
93
+ }
94
+
95
+ const systemMessage: Message = new TextMessage({
96
+ content: makeSystemMessage(contextString, instructions),
97
+ role: Role.System,
98
+ });
99
+
100
+ const instructionsMessage: Message = new TextMessage({
101
+ content: makeInstructionsMessage(instructions),
102
+ role: Role.User,
103
+ });
104
+
105
+ const response = context.runtimeClient.asStream(
106
+ context.runtimeClient.generateCopilotResponse({
107
+ data: {
108
+ frontend: {
109
+ actions: [
110
+ {
111
+ name: action.name,
112
+ description: action.description || "",
113
+ jsonSchema: JSON.stringify(actionParametersToJsonSchema(action.parameters || [])),
114
+ },
115
+ ],
116
+ url: window.location.href,
117
+ },
118
+
119
+ messages: convertMessagesToGqlInput(
120
+ includeMessages
121
+ ? [systemMessage, instructionsMessage, ...filterAgentStateMessages(messages)]
122
+ : [systemMessage, instructionsMessage],
123
+ ),
124
+ metadata: {
125
+ requestType: requestType,
126
+ },
127
+ forwardedParameters: {
128
+ ...(forwardedParameters ?? {}),
129
+ toolChoice: "function",
130
+ toolChoiceFunctionName: action.name,
131
+ },
132
+ },
133
+ properties: context.copilotApiConfig.properties,
134
+ signal: abortSignal,
135
+ }),
136
+ );
137
+
138
+ const reader = response.getReader();
139
+
140
+ let isInitial = true;
141
+
142
+ let actionExecutionMessage: ActionExecutionMessage | undefined = undefined;
143
+
144
+ while (true) {
145
+ const { done, value } = await reader.read();
146
+
147
+ if (done) {
148
+ break;
149
+ }
150
+
151
+ if (abortSignal?.aborted) {
152
+ throw new Error("Aborted");
153
+ }
154
+
155
+ actionExecutionMessage = convertGqlOutputToMessages(
156
+ value.generateCopilotResponse.messages,
157
+ ).find((msg) => msg.isActionExecutionMessage()) as ActionExecutionMessage | undefined;
158
+
159
+ if (!actionExecutionMessage) {
160
+ continue;
161
+ }
162
+
163
+ stream?.({
164
+ status: isInitial ? "initial" : "inProgress",
165
+ args: actionExecutionMessage.arguments as Partial<MappedParameterTypes<T>>,
166
+ });
167
+
168
+ isInitial = false;
169
+ }
170
+
171
+ if (!actionExecutionMessage) {
172
+ throw new Error("extract() failed: No function call occurred");
173
+ }
174
+
175
+ stream?.({
176
+ status: "complete",
177
+ args: actionExecutionMessage.arguments as MappedParameterTypes<T>,
178
+ });
179
+
180
+ return actionExecutionMessage.arguments as MappedParameterTypes<T>;
181
+ }
182
+
183
+ // We need to put this in a user message since some LLMs need
184
+ // at least one user message to function
185
+ function makeInstructionsMessage(instructions: string): string {
186
+ return `
187
+ The user has given you the following task to complete:
188
+
189
+ \`\`\`
190
+ ${instructions}
191
+ \`\`\`
192
+
193
+ Any additional messages provided are for providing context only and should not be used to ask questions or engage in conversation.
194
+ `;
195
+ }
196
+
197
+ function makeSystemMessage(contextString: string, instructions: string): string {
198
+ return `
199
+ Please act as an efficient, competent, conscientious, and industrious professional assistant.
200
+
201
+ 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.
202
+ Always be polite and respectful, and prefer brevity over verbosity.
203
+
204
+ The user has provided you with the following context:
205
+ \`\`\`
206
+ ${contextString}
207
+ \`\`\`
208
+
209
+ They have also provided you with a function called extract you MUST call to initiate actions on their behalf.
210
+
211
+ Please assist them as best you can.
212
+
213
+ This is not a conversation, so please do not ask questions. Just call the function without saying anything else.
214
+ `;
215
+ }
@@ -0,0 +1,2 @@
1
+ export { extract } from "./extract";
2
+ export * from "./dev-console";
@@ -0,0 +1,7 @@
1
+ import * as utils from "./utils";
2
+
3
+ describe("emptyTest", () => {
4
+ it("should be truthy", () => {
5
+ expect(true).toBeTruthy();
6
+ });
7
+ });
@@ -0,0 +1 @@
1
+ export {};
package/tsconfig.json ADDED
@@ -0,0 +1,12 @@
1
+ {
2
+ "extends": "../../utilities/tsconfig/react-library.json",
3
+ "include": ["."],
4
+ "exclude": [
5
+ "dist",
6
+ "build",
7
+ "node_modules",
8
+ "**/*.test.ts",
9
+ "**/*.test.tsx",
10
+ "**/__tests__/*"
11
+ ]
12
+ }
package/tsup.config.ts ADDED
@@ -0,0 +1,16 @@
1
+ import { defineConfig, Options } from "tsup";
2
+
3
+ export default defineConfig((options: Options) => ({
4
+ entry: ["src/**/*.{ts,tsx}"],
5
+ format: ["esm", "cjs"],
6
+ dts: true,
7
+ minify: false,
8
+ external: ["react"],
9
+ sourcemap: true,
10
+ exclude: [
11
+ "**/*.test.ts", // Exclude TypeScript test files
12
+ "**/*.test.tsx", // Exclude TypeScript React test files
13
+ "**/__tests__/*", // Exclude any files inside a __tests__ directory
14
+ ],
15
+ ...options,
16
+ }));
package/typedoc.json ADDED
@@ -0,0 +1,4 @@
1
+ {
2
+ "extends": ["../../typedoc.base.json"],
3
+ "entryPoints": ["src/index.tsx"]
4
+ }