@copilotkit/react-core 0.25.0-mme-cloud.0 → 0.25.0-mme-cloud.1

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 (76) hide show
  1. package/.turbo/turbo-build.log +56 -56
  2. package/CHANGELOG.md +11 -0
  3. package/dist/{chunk-KMTE4NLW.mjs → chunk-DFCYHW6B.mjs} +16 -7
  4. package/dist/chunk-DFCYHW6B.mjs.map +1 -0
  5. package/dist/{chunk-PYBBWHNC.mjs → chunk-GUQTL3VG.mjs} +3 -3
  6. package/dist/{chunk-SPLPX72P.mjs → chunk-ICZAFR7J.mjs} +4 -4
  7. package/dist/{chunk-O2GQ2XK7.mjs → chunk-MBLTLCOG.mjs} +2 -2
  8. package/dist/{chunk-APVNN5QF.mjs → chunk-MESZST5T.mjs} +6 -3
  9. package/dist/chunk-MESZST5T.mjs.map +1 -0
  10. package/dist/{chunk-M7JUS6OQ.mjs → chunk-Q6YXCGNM.mjs} +2 -2
  11. package/dist/{chunk-YKHUBROO.mjs → chunk-R3D5GIQT.mjs} +2 -2
  12. package/dist/{chunk-TEI34ZF5.mjs → chunk-WHODFSGA.mjs} +2 -2
  13. package/dist/{chunk-GH7QK2AZ.mjs → chunk-XUCMY57N.mjs} +1 -1
  14. package/dist/chunk-XUCMY57N.mjs.map +1 -0
  15. package/dist/{chunk-4E2RCCQB.mjs → chunk-YMX4OOEL.mjs} +2 -2
  16. package/dist/components/copilot-provider/copilotkit-props.d.ts +3 -3
  17. package/dist/components/copilot-provider/copilotkit-props.js.map +1 -1
  18. package/dist/components/copilot-provider/copilotkit.js +10 -4
  19. package/dist/components/copilot-provider/copilotkit.js.map +1 -1
  20. package/dist/components/copilot-provider/copilotkit.mjs +2 -2
  21. package/dist/components/copilot-provider/index.js +10 -4
  22. package/dist/components/copilot-provider/index.js.map +1 -1
  23. package/dist/components/copilot-provider/index.mjs +2 -2
  24. package/dist/components/index.js +10 -4
  25. package/dist/components/index.js.map +1 -1
  26. package/dist/components/index.mjs +2 -2
  27. package/dist/context/copilot-context.d.ts +4 -1
  28. package/dist/context/copilot-context.js.map +1 -1
  29. package/dist/context/copilot-context.mjs +1 -1
  30. package/dist/context/index.js.map +1 -1
  31. package/dist/context/index.mjs +1 -1
  32. package/dist/hooks/index.js +3 -1
  33. package/dist/hooks/index.js.map +1 -1
  34. package/dist/hooks/index.mjs +8 -8
  35. package/dist/hooks/use-chat.js +3 -1
  36. package/dist/hooks/use-chat.js.map +1 -1
  37. package/dist/hooks/use-chat.mjs +1 -1
  38. package/dist/hooks/use-copilot-action.js.map +1 -1
  39. package/dist/hooks/use-copilot-action.mjs +2 -2
  40. package/dist/hooks/use-copilot-chat.js +3 -1
  41. package/dist/hooks/use-copilot-chat.js.map +1 -1
  42. package/dist/hooks/use-copilot-chat.mjs +4 -4
  43. package/dist/hooks/use-make-copilot-actionable.js.map +1 -1
  44. package/dist/hooks/use-make-copilot-actionable.mjs +2 -2
  45. package/dist/hooks/use-make-copilot-document-readable.js.map +1 -1
  46. package/dist/hooks/use-make-copilot-document-readable.mjs +2 -2
  47. package/dist/hooks/use-make-copilot-readable.js.map +1 -1
  48. package/dist/hooks/use-make-copilot-readable.mjs +2 -2
  49. package/dist/index.js +13 -5
  50. package/dist/index.js.map +1 -1
  51. package/dist/index.mjs +10 -10
  52. package/dist/lib/copilot-task.js.map +1 -1
  53. package/dist/lib/copilot-task.mjs +3 -3
  54. package/dist/lib/index.js.map +1 -1
  55. package/dist/lib/index.mjs +3 -3
  56. package/dist/openai-assistants/hooks/index.js.map +1 -1
  57. package/dist/openai-assistants/hooks/index.mjs +3 -3
  58. package/dist/openai-assistants/hooks/use-copilot-chat-v2.js.map +1 -1
  59. package/dist/openai-assistants/hooks/use-copilot-chat-v2.mjs +3 -3
  60. package/dist/openai-assistants/index.js.map +1 -1
  61. package/dist/openai-assistants/index.mjs +3 -3
  62. package/package.json +4 -4
  63. package/src/components/copilot-provider/copilotkit-props.tsx +3 -3
  64. package/src/components/copilot-provider/copilotkit.tsx +17 -7
  65. package/src/context/copilot-context.tsx +5 -1
  66. package/src/hooks/use-chat.ts +7 -1
  67. package/dist/chunk-APVNN5QF.mjs.map +0 -1
  68. package/dist/chunk-GH7QK2AZ.mjs.map +0 -1
  69. package/dist/chunk-KMTE4NLW.mjs.map +0 -1
  70. /package/dist/{chunk-PYBBWHNC.mjs.map → chunk-GUQTL3VG.mjs.map} +0 -0
  71. /package/dist/{chunk-SPLPX72P.mjs.map → chunk-ICZAFR7J.mjs.map} +0 -0
  72. /package/dist/{chunk-O2GQ2XK7.mjs.map → chunk-MBLTLCOG.mjs.map} +0 -0
  73. /package/dist/{chunk-M7JUS6OQ.mjs.map → chunk-Q6YXCGNM.mjs.map} +0 -0
  74. /package/dist/{chunk-YKHUBROO.mjs.map → chunk-R3D5GIQT.mjs.map} +0 -0
  75. /package/dist/{chunk-TEI34ZF5.mjs.map → chunk-WHODFSGA.mjs.map} +0 -0
  76. /package/dist/{chunk-4E2RCCQB.mjs.map → chunk-YMX4OOEL.mjs.map} +0 -0
@@ -1,5 +1,5 @@
1
1
 
2
- > @copilotkit/react-core@0.25.0-mme-cloud.0 build /home/runner/work/CopilotKit/CopilotKit/CopilotKit/packages/react-core
2
+ > @copilotkit/react-core@0.25.0-mme-cloud.1 build /home/runner/work/CopilotKit/CopilotKit/CopilotKit/packages/react-core
3
3
  > tsup --clean
4
4
 
5
5
  CLI Building entry: src/index.tsx, src/components/index.ts, src/context/copilot-context.tsx, src/context/index.ts, src/hooks/index.ts, src/hooks/use-chat.ts, src/hooks/use-copilot-action.ts, src/hooks/use-copilot-chat.ts, src/hooks/use-flat-category-store.ts, src/hooks/use-make-copilot-actionable.ts, src/hooks/use-make-copilot-document-readable.ts, src/hooks/use-make-copilot-readable.ts, src/hooks/use-tree.ts, src/lib/copilot-task.ts, src/lib/index.ts, src/openai-assistants/index.ts, src/types/document-pointer.ts, src/types/frontend-action.ts, src/types/index.ts, src/types/system-message.ts, src/utils/fetch-chat-completion.ts, src/utils/utils.test.ts, src/utils/utils.ts, src/components/copilot-provider/copilotkit-props.tsx, src/components/copilot-provider/copilotkit.tsx, src/components/copilot-provider/index.ts, src/openai-assistants/hooks/index.ts, src/openai-assistants/hooks/use-assistants.ts, src/openai-assistants/hooks/use-copilot-chat-v2.ts, src/openai-assistants/utils/index.ts, src/openai-assistants/utils/process-message-stream.ts
@@ -17,14 +17,14 @@
17
17
  CJS dist/components/copilot-provider/copilotkit-props.js 864.00 B
18
18
  CJS dist/openai-assistants/hooks/index.js 9.31 KB
19
19
  CJS dist/openai-assistants/utils/index.js 2.30 KB
20
- CJS dist/index.js 39.22 KB
21
- CJS dist/components/index.js 15.24 KB
20
+ CJS dist/index.js 39.67 KB
21
+ CJS dist/components/index.js 15.48 KB
22
22
  CJS dist/context/copilot-context.js 3.71 KB
23
23
  CJS dist/context/index.js 3.70 KB
24
- CJS dist/hooks/index.js 19.90 KB
25
- CJS dist/hooks/use-chat.js 11.30 KB
24
+ CJS dist/hooks/index.js 20.11 KB
25
+ CJS dist/hooks/use-chat.js 11.51 KB
26
26
  CJS dist/hooks/use-copilot-action.js 5.00 KB
27
- CJS dist/hooks/use-copilot-chat.js 16.15 KB
27
+ CJS dist/hooks/use-copilot-chat.js 16.36 KB
28
28
  CJS dist/hooks/use-flat-category-store.js 2.87 KB
29
29
  CJS dist/hooks/use-make-copilot-actionable.js 4.68 KB
30
30
  CJS dist/hooks/use-make-copilot-document-readable.js 4.31 KB
@@ -36,75 +36,75 @@
36
36
  CJS dist/types/system-message.js 833.00 B
37
37
  CJS dist/utils/utils.test.js 184.00 B
38
38
  CJS dist/utils/utils.js 797.00 B
39
- CJS dist/components/copilot-provider/copilotkit.js 15.22 KB
40
- CJS dist/components/copilot-provider/index.js 15.28 KB
39
+ CJS dist/components/copilot-provider/copilotkit.js 15.46 KB
40
+ CJS dist/components/copilot-provider/index.js 15.52 KB
41
41
  CJS dist/openai-assistants/hooks/use-assistants.js 4.81 KB
42
42
  CJS dist/openai-assistants/hooks/use-copilot-chat-v2.js 9.40 KB
43
43
  CJS dist/openai-assistants/utils/process-message-stream.js 2.33 KB
44
- CJS dist/lib/copilot-task.js.map 16.62 KB
45
- CJS dist/openai-assistants/index.js.map 21.01 KB
44
+ CJS dist/lib/copilot-task.js.map 16.89 KB
45
+ CJS dist/openai-assistants/index.js.map 21.35 KB
46
46
  CJS dist/types/document-pointer.js.map 292.00 B
47
47
  CJS dist/utils/fetch-chat-completion.js.map 4.90 KB
48
- CJS dist/components/copilot-provider/copilotkit-props.js.map 1.35 KB
49
- CJS dist/openai-assistants/hooks/index.js.map 21.31 KB
48
+ CJS dist/components/copilot-provider/copilotkit-props.js.map 1.36 KB
49
+ CJS dist/openai-assistants/hooks/index.js.map 21.65 KB
50
50
  CJS dist/openai-assistants/utils/index.js.map 1.44 KB
51
- CJS dist/index.js.map 73.75 KB
52
- CJS dist/components/index.js.map 26.98 KB
53
- CJS dist/context/copilot-context.js.map 5.42 KB
54
- CJS dist/context/index.js.map 5.65 KB
55
- CJS dist/hooks/index.js.map 43.97 KB
56
- CJS dist/hooks/use-chat.js.map 18.10 KB
57
- CJS dist/hooks/use-copilot-action.js.map 9.57 KB
58
- CJS dist/hooks/use-copilot-chat.js.map 34.57 KB
51
+ CJS dist/index.js.map 74.52 KB
52
+ CJS dist/components/index.js.map 27.42 KB
53
+ CJS dist/context/copilot-context.js.map 5.48 KB
54
+ CJS dist/context/index.js.map 5.71 KB
55
+ CJS dist/hooks/index.js.map 44.64 KB
56
+ CJS dist/hooks/use-chat.js.map 18.43 KB
57
+ CJS dist/hooks/use-copilot-action.js.map 9.64 KB
58
+ CJS dist/hooks/use-copilot-chat.js.map 35.24 KB
59
59
  CJS dist/hooks/use-flat-category-store.js.map 4.25 KB
60
- CJS dist/hooks/use-make-copilot-actionable.js.map 7.17 KB
61
- CJS dist/hooks/use-make-copilot-document-readable.js.map 6.71 KB
62
- CJS dist/hooks/use-make-copilot-readable.js.map 6.76 KB
60
+ CJS dist/hooks/use-make-copilot-actionable.js.map 7.23 KB
61
+ CJS dist/hooks/use-make-copilot-document-readable.js.map 6.77 KB
62
+ CJS dist/hooks/use-make-copilot-readable.js.map 6.82 KB
63
63
  CJS dist/hooks/use-tree.js.map 8.32 KB
64
- CJS dist/lib/index.js.map 16.68 KB
64
+ CJS dist/lib/index.js.map 16.96 KB
65
65
  CJS dist/types/frontend-action.js.map 1.77 KB
66
66
  CJS dist/types/index.js.map 338.00 B
67
67
  CJS dist/types/system-message.js.map 249.00 B
68
68
  CJS dist/utils/utils.test.js.map 354.00 B
69
69
  CJS dist/utils/utils.js.map 137.00 B
70
- CJS dist/components/copilot-provider/copilotkit.js.map 26.92 KB
71
- CJS dist/components/copilot-provider/index.js.map 27.11 KB
70
+ CJS dist/components/copilot-provider/copilotkit.js.map 27.36 KB
71
+ CJS dist/components/copilot-provider/index.js.map 27.55 KB
72
72
  CJS dist/openai-assistants/hooks/use-assistants.js.map 5.90 KB
73
- CJS dist/openai-assistants/hooks/use-copilot-chat-v2.js.map 20.93 KB
73
+ CJS dist/openai-assistants/hooks/use-copilot-chat-v2.js.map 21.27 KB
74
74
  CJS dist/openai-assistants/utils/process-message-stream.js.map 1.33 KB
75
- CJS ⚡️ Build success in 225ms
75
+ CJS ⚡️ Build success in 226ms
76
76
  ESM dist/index.mjs 1.58 KB
77
77
  ESM dist/components/index.mjs 375.00 B
78
78
  ESM dist/context/copilot-context.mjs 205.00 B
79
79
  ESM dist/hooks/index.mjs 817.00 B
80
80
  ESM dist/chunk-EFZPSZWO.mjs 43.00 B
81
81
  ESM dist/chunk-LUGEI4YQ.mjs 43.00 B
82
- ESM dist/chunk-O2GQ2XK7.mjs 3.17 KB
82
+ ESM dist/chunk-MBLTLCOG.mjs 3.17 KB
83
83
  ESM dist/chunk-7GFKOIO7.mjs 43.00 B
84
84
  ESM dist/chunk-BABVSMJR.mjs 43.00 B
85
- ESM dist/chunk-PYBBWHNC.mjs 4.39 KB
85
+ ESM dist/chunk-GUQTL3VG.mjs 4.39 KB
86
86
  ESM dist/chunk-FRAKUJWH.mjs 43.00 B
87
87
  ESM dist/chunk-MZ5UN3BY.mjs 802.00 B
88
88
  ESM dist/context/index.mjs 227.00 B
89
89
  ESM dist/chunk-VNRDQJXW.mjs 43.00 B
90
90
  ESM dist/chunk-IOP6JX34.mjs 43.00 B
91
- ESM dist/chunk-4E2RCCQB.mjs 1.06 KB
92
- ESM dist/chunk-YKHUBROO.mjs 700.00 B
93
- ESM dist/chunk-M7JUS6OQ.mjs 640.00 B
91
+ ESM dist/chunk-YMX4OOEL.mjs 1.06 KB
92
+ ESM dist/chunk-R3D5GIQT.mjs 700.00 B
93
+ ESM dist/chunk-Q6YXCGNM.mjs 640.00 B
94
94
  ESM dist/hooks/use-chat.mjs 174.00 B
95
95
  ESM dist/hooks/use-copilot-action.mjs 202.00 B
96
- ESM dist/chunk-TEI34ZF5.mjs 1.46 KB
97
96
  ESM dist/hooks/use-copilot-chat.mjs 468.00 B
98
- ESM dist/chunk-SPLPX72P.mjs 3.00 KB
99
- ESM dist/chunk-JD7BAH7U.mjs 43.00 B
100
- ESM dist/chunk-SPCZTZCY.mjs 43.00 B
101
- ESM dist/chunk-KMTE4NLW.mjs 4.78 KB
97
+ ESM dist/chunk-WHODFSGA.mjs 1.46 KB
98
+ ESM dist/chunk-DFCYHW6B.mjs 5.03 KB
102
99
  ESM dist/chunk-YULKJPY3.mjs 1.84 KB
103
100
  ESM dist/chunk-VUY2K2DI.mjs 3.89 KB
104
- ESM dist/chunk-APVNN5QF.mjs 6.26 KB
101
+ ESM dist/chunk-MESZST5T.mjs 6.49 KB
105
102
  ESM dist/chunk-CGT3AVYT.mjs 2.77 KB
106
- ESM dist/chunk-GH7QK2AZ.mjs 1.52 KB
103
+ ESM dist/chunk-XUCMY57N.mjs 1.52 KB
107
104
  ESM dist/chunk-MRXNTQOX.mjs 1.89 KB
105
+ ESM dist/chunk-ICZAFR7J.mjs 3.00 KB
106
+ ESM dist/chunk-JD7BAH7U.mjs 43.00 B
107
+ ESM dist/chunk-SPCZTZCY.mjs 43.00 B
108
108
  ESM dist/components/copilot-provider/copilotkit.mjs 331.00 B
109
109
  ESM dist/components/copilot-provider/index.mjs 361.00 B
110
110
  ESM dist/openai-assistants/hooks/index.mjs 513.00 B
@@ -134,32 +134,32 @@
134
134
  ESM dist/hooks/index.mjs.map 71.00 B
135
135
  ESM dist/chunk-EFZPSZWO.mjs.map 71.00 B
136
136
  ESM dist/chunk-LUGEI4YQ.mjs.map 71.00 B
137
- ESM dist/chunk-O2GQ2XK7.mjs.map 5.57 KB
137
+ ESM dist/chunk-MBLTLCOG.mjs.map 5.57 KB
138
138
  ESM dist/chunk-7GFKOIO7.mjs.map 71.00 B
139
139
  ESM dist/chunk-BABVSMJR.mjs.map 71.00 B
140
- ESM dist/chunk-PYBBWHNC.mjs.map 7.90 KB
140
+ ESM dist/chunk-GUQTL3VG.mjs.map 7.90 KB
141
141
  ESM dist/chunk-FRAKUJWH.mjs.map 71.00 B
142
142
  ESM dist/chunk-MZ5UN3BY.mjs.map 1.26 KB
143
143
  ESM dist/context/index.mjs.map 71.00 B
144
144
  ESM dist/chunk-VNRDQJXW.mjs.map 71.00 B
145
145
  ESM dist/chunk-IOP6JX34.mjs.map 71.00 B
146
- ESM dist/chunk-4E2RCCQB.mjs.map 1.87 KB
147
- ESM dist/chunk-YKHUBROO.mjs.map 1.40 KB
148
- ESM dist/chunk-M7JUS6OQ.mjs.map 1.45 KB
146
+ ESM dist/chunk-YMX4OOEL.mjs.map 1.87 KB
147
+ ESM dist/chunk-R3D5GIQT.mjs.map 1.40 KB
148
+ ESM dist/chunk-Q6YXCGNM.mjs.map 1.45 KB
149
149
  ESM dist/hooks/use-chat.mjs.map 71.00 B
150
150
  ESM dist/hooks/use-copilot-action.mjs.map 71.00 B
151
- ESM dist/chunk-TEI34ZF5.mjs.map 4.27 KB
152
151
  ESM dist/hooks/use-copilot-chat.mjs.map 71.00 B
153
- ESM dist/chunk-SPLPX72P.mjs.map 4.77 KB
154
- ESM dist/chunk-JD7BAH7U.mjs.map 71.00 B
155
- ESM dist/chunk-SPCZTZCY.mjs.map 71.00 B
156
- ESM dist/chunk-KMTE4NLW.mjs.map 9.16 KB
152
+ ESM dist/chunk-WHODFSGA.mjs.map 4.27 KB
153
+ ESM dist/chunk-DFCYHW6B.mjs.map 9.56 KB
157
154
  ESM dist/chunk-YULKJPY3.mjs.map 4.21 KB
158
155
  ESM dist/chunk-VUY2K2DI.mjs.map 8.27 KB
159
- ESM dist/chunk-APVNN5QF.mjs.map 13.50 KB
156
+ ESM dist/chunk-MESZST5T.mjs.map 13.84 KB
160
157
  ESM dist/chunk-CGT3AVYT.mjs.map 4.86 KB
161
- ESM dist/chunk-GH7QK2AZ.mjs.map 5.33 KB
158
+ ESM dist/chunk-XUCMY57N.mjs.map 5.39 KB
162
159
  ESM dist/chunk-MRXNTQOX.mjs.map 71.00 B
160
+ ESM dist/chunk-ICZAFR7J.mjs.map 4.77 KB
161
+ ESM dist/chunk-JD7BAH7U.mjs.map 71.00 B
162
+ ESM dist/chunk-SPCZTZCY.mjs.map 71.00 B
163
163
  ESM dist/components/copilot-provider/copilotkit.mjs.map 71.00 B
164
164
  ESM dist/components/copilot-provider/index.mjs.map 71.00 B
165
165
  ESM dist/openai-assistants/hooks/index.mjs.map 71.00 B
@@ -183,13 +183,13 @@
183
183
  ESM dist/lib/copilot-task.mjs.map 71.00 B
184
184
  ESM dist/lib/index.mjs.map 71.00 B
185
185
  ESM dist/openai-assistants/index.mjs.map 71.00 B
186
- ESM ⚡️ Build success in 231ms
186
+ ESM ⚡️ Build success in 233ms
187
187
  DTS Build start
188
- DTS ⚡️ Build success in 5986ms
188
+ DTS ⚡️ Build success in 5996ms
189
189
  DTS dist/index.d.ts 1.56 KB
190
190
  DTS dist/components/copilot-provider/copilotkit.d.ts 1017.00 B
191
- DTS dist/components/copilot-provider/copilotkit-props.d.ts 1.25 KB
192
- DTS dist/context/copilot-context.d.ts 2.89 KB
191
+ DTS dist/components/copilot-provider/copilotkit-props.d.ts 1.26 KB
192
+ DTS dist/context/copilot-context.d.ts 2.96 KB
193
193
  DTS dist/hooks/use-copilot-chat.d.ts 1.05 KB
194
194
  DTS dist/hooks/use-make-copilot-actionable.d.ts 309.00 B
195
195
  DTS dist/hooks/use-copilot-action.d.ts 286.00 B
package/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # ui
2
2
 
3
+ ## 0.25.0-mme-cloud.1
4
+
5
+ ### Minor Changes
6
+
7
+ - Unify api key handling
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies
12
+ - @copilotkit/shared@0.9.0-mme-cloud.1
13
+
3
14
  ## 0.25.0-mme-cloud.0
4
15
 
5
16
  ### Minor Changes
@@ -6,7 +6,7 @@ import {
6
6
  } from "./chunk-VUY2K2DI.mjs";
7
7
  import {
8
8
  CopilotContext
9
- } from "./chunk-GH7QK2AZ.mjs";
9
+ } from "./chunk-XUCMY57N.mjs";
10
10
  import {
11
11
  __async,
12
12
  __objRest,
@@ -16,10 +16,17 @@ import {
16
16
 
17
17
  // src/components/copilot-provider/copilotkit.tsx
18
18
  import { useCallback, useRef, useState } from "react";
19
- import { actionToChatCompletionFunction } from "@copilotkit/shared";
19
+ import {
20
+ COPILOT_CLOUD_CHAT_URL,
21
+ actionToChatCompletionFunction
22
+ } from "@copilotkit/shared";
20
23
  import { jsx } from "react/jsx-runtime";
21
24
  function CopilotKit(_a) {
22
25
  var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
26
+ if (!props.url && !props.publicApiKey) {
27
+ throw new Error("Please provide either a url or a publicApiKey to the CopilotKit component.");
28
+ }
29
+ const chatApiEndpoint = props.url || COPILOT_CLOUD_CHAT_URL;
23
30
  const [entryPoints, setEntryPoints] = useState({});
24
31
  const chatComponentsCache = useRef({});
25
32
  const { addElement, removeElement, printTree } = use_tree_default();
@@ -98,15 +105,17 @@ ${nonDocumentStrings}`;
98
105
  },
99
106
  [removeDocument]
100
107
  );
101
- if (!props.apiKey) {
108
+ if (!props.publicApiKey) {
102
109
  if (props.cloudRestrictToTopic) {
103
110
  throw new Error(
104
- "To use the cloudRestrictToTopic feature, please sign up at https://copilotkit.ai and provide an apiKey."
111
+ "To use the cloudRestrictToTopic feature, please sign up at https://copilotkit.ai and provide a publicApiKey."
105
112
  );
106
113
  }
107
114
  }
108
- const copilotApiConfig = __spreadProps(__spreadValues({}, props.apiKey ? { cloud: { apiKey: props.apiKey, restrictToTopic: props.cloudRestrictToTopic } } : {}), {
109
- chatApiEndpoint: props.url,
115
+ const copilotApiConfig = __spreadProps(__spreadValues({
116
+ publicApiKey: props.publicApiKey
117
+ }, props.publicApiKey ? { cloud: { restrictToTopic: props.cloudRestrictToTopic } } : {}), {
118
+ chatApiEndpoint,
110
119
  chatApiEndpointV2: `${props.url}/v2`,
111
120
  headers: props.headers || {},
112
121
  body: __spreadValues(__spreadValues({}, props.body), props.backendOnlyProps)
@@ -160,4 +169,4 @@ export {
160
169
  CopilotKit,
161
170
  defaultCopilotContextCategories
162
171
  };
163
- //# sourceMappingURL=chunk-KMTE4NLW.mjs.map
172
+ //# sourceMappingURL=chunk-DFCYHW6B.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/components/copilot-provider/copilotkit.tsx"],"sourcesContent":["import { Ref, useCallback, useRef, useState } from \"react\";\nimport {\n CopilotContext,\n CopilotApiConfig,\n InChatRenderFunction,\n} from \"../../context/copilot-context\";\nimport useTree from \"../../hooks/use-tree\";\nimport { DocumentPointer } from \"../../types\";\nimport {\n COPILOT_CLOUD_CHAT_URL,\n FunctionCallHandler,\n Message,\n actionToChatCompletionFunction,\n} from \"@copilotkit/shared\";\nimport { FrontendAction } from \"../../types/frontend-action\";\nimport useFlatCategoryStore from \"../../hooks/use-flat-category-store\";\nimport { CopilotKitProps } from \"./copilotkit-props\";\nimport { ToolDefinition } from \"@copilotkit/shared\";\n\n/**\n * The CopilotKit component.\n * This component provides the Copilot context to its children.\n * It can be configured either with a chat API endpoint or a CopilotApiConfig.\n *\n * NOTE: The backend can use OpenAI, or you can bring your own LLM.\n * For examples of the backend api implementation, see `examples/next-openai` usage (under `src/api/copilotkit`),\n * or read the documentation at https://docs.copilotkit.ai\n * In particular, Getting-Started > Quickstart-Backend: https://docs.copilotkit.ai/getting-started/quickstart-backend\n *\n * Example usage:\n * ```\n * <CopilotKit url=\"https://your.copilotkit.api\">\n * <App />\n * </CopilotKit>\n * ```\n *\n * @param props - The props for the component.\n * @returns The CopilotKit component.\n */\nexport function CopilotKit({ children, ...props }: CopilotKitProps) {\n // Compute all the functions and properties that we need to pass\n // to the CopilotContext.\n\n if (!props.url && !props.publicApiKey) {\n throw new Error(\"Please provide either a url or a publicApiKey to the CopilotKit component.\");\n }\n\n const chatApiEndpoint = props.url || COPILOT_CLOUD_CHAT_URL;\n\n const [entryPoints, setEntryPoints] = useState<Record<string, FrontendAction<any>>>({});\n const chatComponentsCache = useRef<Record<string, InChatRenderFunction | string>>({});\n const { addElement, removeElement, printTree } = useTree();\n const [messages, setMessages] = useState<Message[]>([]);\n\n const {\n addElement: addDocument,\n removeElement: removeDocument,\n allElements: allDocuments,\n } = useFlatCategoryStore<DocumentPointer>();\n\n const setEntryPoint = useCallback((id: string, entryPoint: FrontendAction<any>) => {\n setEntryPoints((prevPoints) => {\n return {\n ...prevPoints,\n [id]: entryPoint,\n };\n });\n }, []);\n\n const removeEntryPoint = useCallback((id: string) => {\n setEntryPoints((prevPoints) => {\n const newPoints = { ...prevPoints };\n delete newPoints[id];\n return newPoints;\n });\n }, []);\n\n const getContextString = useCallback(\n (documents: DocumentPointer[], categories: string[]) => {\n const documentsString = documents\n .map((document) => {\n return `${document.name} (${document.sourceApplication}):\\n${document.getContents()}`;\n })\n .join(\"\\n\\n\");\n\n const nonDocumentStrings = printTree(categories);\n\n return `${documentsString}\\n\\n${nonDocumentStrings}`;\n },\n [printTree],\n );\n\n const addContext = useCallback(\n (\n context: string,\n parentId?: string,\n categories: string[] = defaultCopilotContextCategories,\n ) => {\n return addElement(context, categories, parentId);\n },\n [addElement],\n );\n\n const removeContext = useCallback(\n (id: string) => {\n removeElement(id);\n },\n [removeElement],\n );\n\n const getChatCompletionFunctionDescriptions = useCallback(\n (customEntryPoints?: Record<string, FrontendAction<any>>) => {\n return entryPointsToChatCompletionFunctions(Object.values(customEntryPoints || entryPoints));\n },\n [entryPoints],\n );\n\n const getFunctionCallHandler = useCallback(\n (customEntryPoints?: Record<string, FrontendAction<any>>) => {\n return entryPointsToFunctionCallHandler(Object.values(customEntryPoints || entryPoints));\n },\n [entryPoints],\n );\n\n const getDocumentsContext = useCallback(\n (categories: string[]) => {\n return allDocuments(categories);\n },\n [allDocuments],\n );\n\n const addDocumentContext = useCallback(\n (documentPointer: DocumentPointer, categories: string[] = defaultCopilotContextCategories) => {\n return addDocument(documentPointer, categories);\n },\n [addDocument],\n );\n\n const removeDocumentContext = useCallback(\n (documentId: string) => {\n removeDocument(documentId);\n },\n [removeDocument],\n );\n\n if (!props.publicApiKey) {\n if (props.cloudRestrictToTopic) {\n throw new Error(\n \"To use the cloudRestrictToTopic feature, please sign up at https://copilotkit.ai and provide a publicApiKey.\",\n );\n }\n }\n\n // get the appropriate CopilotApiConfig from the props\n const copilotApiConfig: CopilotApiConfig = {\n publicApiKey: props.publicApiKey,\n ...(props.publicApiKey ? { cloud: { restrictToTopic: props.cloudRestrictToTopic } } : {}),\n chatApiEndpoint: chatApiEndpoint,\n chatApiEndpointV2: `${props.url}/v2`,\n headers: props.headers || {},\n body: {\n ...props.body,\n ...props.backendOnlyProps,\n },\n };\n\n return (\n <CopilotContext.Provider\n value={{\n entryPoints,\n chatComponentsCache,\n getChatCompletionFunctionDescriptions,\n getFunctionCallHandler,\n setEntryPoint,\n removeEntryPoint,\n getContextString,\n addContext,\n removeContext,\n getDocumentsContext,\n addDocumentContext,\n removeDocumentContext,\n copilotApiConfig: copilotApiConfig,\n messages,\n setMessages,\n }}\n >\n {children}\n </CopilotContext.Provider>\n );\n}\n\nexport const defaultCopilotContextCategories = [\"global\"];\n\nfunction entryPointsToChatCompletionFunctions(actions: FrontendAction<any>[]): ToolDefinition[] {\n return actions.map(actionToChatCompletionFunction);\n}\n\nfunction entryPointsToFunctionCallHandler(actions: FrontendAction<any>[]): FunctionCallHandler {\n return async (chatMessages, functionCall) => {\n let actionsByFunctionName: Record<string, FrontendAction<any>> = {};\n for (let action of actions) {\n actionsByFunctionName[action.name] = action;\n }\n\n const action = actionsByFunctionName[functionCall.name || \"\"];\n if (action) {\n let functionCallArguments: Record<string, any>[] = [];\n if (functionCall.arguments) {\n functionCallArguments = JSON.parse(functionCall.arguments);\n }\n return await action.handler(functionCallArguments);\n }\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAAA,SAAc,aAAa,QAAQ,gBAAgB;AAQnD;AAAA,EACE;AAAA,EAGA;AAAA,OACK;AA0JH;AAhIG,SAAS,WAAW,IAAyC;AAAzC,eAAE,WAvC7B,IAuC2B,IAAe,kBAAf,IAAe,CAAb;AAI3B,MAAI,CAAC,MAAM,OAAO,CAAC,MAAM,cAAc;AACrC,UAAM,IAAI,MAAM,4EAA4E;AAAA,EAC9F;AAEA,QAAM,kBAAkB,MAAM,OAAO;AAErC,QAAM,CAAC,aAAa,cAAc,IAAI,SAA8C,CAAC,CAAC;AACtF,QAAM,sBAAsB,OAAsD,CAAC,CAAC;AACpF,QAAM,EAAE,YAAY,eAAe,UAAU,IAAI,iBAAQ;AACzD,QAAM,CAAC,UAAU,WAAW,IAAI,SAAoB,CAAC,CAAC;AAEtD,QAAM;AAAA,IACJ,YAAY;AAAA,IACZ,eAAe;AAAA,IACf,aAAa;AAAA,EACf,IAAI,gCAAsC;AAE1C,QAAM,gBAAgB,YAAY,CAAC,IAAY,eAAoC;AACjF,mBAAe,CAAC,eAAe;AAC7B,aAAO,iCACF,aADE;AAAA,QAEL,CAAC,EAAE,GAAG;AAAA,MACR;AAAA,IACF,CAAC;AAAA,EACH,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,gCAAwB,KAAK,MAAM,aAAa,SAAS;AAAA,MAC3D;AACA,aAAO,MAAM,OAAO,QAAQ,qBAAqB;AAAA,IACnD;AAAA,EACF;AACF;","names":["action"]}
@@ -3,10 +3,10 @@ import {
3
3
  } from "./chunk-MZ5UN3BY.mjs";
4
4
  import {
5
5
  defaultCopilotContextCategories
6
- } from "./chunk-KMTE4NLW.mjs";
6
+ } from "./chunk-DFCYHW6B.mjs";
7
7
  import {
8
8
  CopilotContext
9
- } from "./chunk-GH7QK2AZ.mjs";
9
+ } from "./chunk-XUCMY57N.mjs";
10
10
  import {
11
11
  __async,
12
12
  __spreadValues
@@ -134,4 +134,4 @@ export {
134
134
  useCopilotChatV2,
135
135
  defaultSystemMessage
136
136
  };
137
- //# sourceMappingURL=chunk-PYBBWHNC.mjs.map
137
+ //# sourceMappingURL=chunk-GUQTL3VG.mjs.map
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  defaultCopilotContextCategories
3
- } from "./chunk-KMTE4NLW.mjs";
3
+ } from "./chunk-DFCYHW6B.mjs";
4
4
  import {
5
5
  useChat
6
- } from "./chunk-APVNN5QF.mjs";
6
+ } from "./chunk-MESZST5T.mjs";
7
7
  import {
8
8
  CopilotContext
9
- } from "./chunk-GH7QK2AZ.mjs";
9
+ } from "./chunk-XUCMY57N.mjs";
10
10
  import {
11
11
  __objRest,
12
12
  __spreadProps,
@@ -95,4 +95,4 @@ export {
95
95
  useCopilotChat,
96
96
  defaultSystemMessage
97
97
  };
98
- //# sourceMappingURL=chunk-SPLPX72P.mjs.map
98
+ //# sourceMappingURL=chunk-ICZAFR7J.mjs.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  defaultCopilotContextCategories
3
- } from "./chunk-KMTE4NLW.mjs";
3
+ } from "./chunk-DFCYHW6B.mjs";
4
4
  import {
5
5
  fetchAndDecodeChatCompletion
6
6
  } from "./chunk-CGT3AVYT.mjs";
@@ -99,4 +99,4 @@ ${instructions}
99
99
  export {
100
100
  CopilotTask
101
101
  };
102
- //# sourceMappingURL=chunk-O2GQ2XK7.mjs.map
102
+ //# sourceMappingURL=chunk-MBLTLCOG.mjs.map
@@ -10,7 +10,8 @@ import {
10
10
  // src/hooks/use-chat.ts
11
11
  import { useRef, useState } from "react";
12
12
  import {
13
- encodeResult
13
+ encodeResult,
14
+ COPILOT_CLOUD_PUBLIC_API_KEY_HEADER
14
15
  } from "@copilotkit/shared";
15
16
  import { nanoid } from "nanoid";
16
17
  import untruncateJson from "untruncate-json";
@@ -21,6 +22,8 @@ function useChat(options) {
21
22
  const abortControllerRef = useRef();
22
23
  const threadIdRef = useRef(null);
23
24
  const runIdRef = useRef(null);
25
+ const publicApiKey = options.copilotConfig.publicApiKey;
26
+ const headers = __spreadValues(__spreadValues({}, options.headers || {}), publicApiKey ? { [COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey } : {});
24
27
  const runChatCompletion = (messages2) => __async(this, null, function* () {
25
28
  setIsLoading(true);
26
29
  const newMessages = [
@@ -46,7 +49,7 @@ function useChat(options) {
46
49
  copilotConfig: __spreadProps(__spreadValues({}, options.copilotConfig), { body: copilotConfigBody }),
47
50
  messages: messagesWithContext,
48
51
  tools: options.tools,
49
- headers: options.headers,
52
+ headers,
50
53
  signal: abortController.signal
51
54
  });
52
55
  if (response.headers.get("threadid")) {
@@ -191,4 +194,4 @@ function useChat(options) {
191
194
  export {
192
195
  useChat
193
196
  };
194
- //# sourceMappingURL=chunk-APVNN5QF.mjs.map
197
+ //# sourceMappingURL=chunk-MESZST5T.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/hooks/use-chat.ts"],"sourcesContent":["import { useRef, useState } from \"react\";\nimport {\n Message,\n ToolDefinition,\n FunctionCallHandler,\n encodeResult,\n FunctionCall,\n COPILOT_CLOUD_PUBLIC_API_KEY_HEADER,\n} from \"@copilotkit/shared\";\n\nimport { nanoid } from \"nanoid\";\nimport { fetchAndDecodeChatCompletion } from \"../utils/fetch-chat-completion\";\nimport { CopilotApiConfig } from \"../context\";\nimport untruncateJson from \"untruncate-json\";\n\nexport type UseChatOptions = {\n /**\n * The API endpoint that accepts a `{ messages: Message[] }` object and returns\n * a stream of tokens of the AI chat response. Defaults to `/api/chat`.\n */\n api?: string;\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 * System messages of the chat. Defaults to an empty array.\n */\n initialMessages?: Message[];\n /**\n * Callback function to be called when a function call is received.\n * If the function returns a `ChatRequest` object, the request will be sent\n * automatically to the API and will be used to update the chat.\n */\n onFunctionCall?: FunctionCallHandler;\n /**\n * HTTP headers to be sent with the API request.\n */\n headers?: Record<string, string> | Headers;\n /**\n * Extra body object to be sent with the API request.\n * @example\n * Send a `sessionId` to the API along with the messages.\n * ```js\n * useChat({\n * body: {\n * sessionId: '123',\n * }\n * })\n * ```\n */\n body?: object;\n /**\n * Function definitions to be sent to the API.\n */\n tools?: ToolDefinition[];\n};\n\nexport type UseChatHelpers = {\n /**\n * Append a user message to the chat list. This triggers the API call to fetch\n * the assistant's response.\n * @param message The message to append\n */\n append: (message: Message) => Promise<void>;\n /**\n * Reload the last AI chat response for the given chat history. If the last\n * message isn't from the assistant, it will request the API to generate a\n * new response.\n */\n reload: () => Promise<void>;\n /**\n * Abort the current request immediately, keep the generated tokens if any.\n */\n stop: () => void;\n /** The current value of the input */\n input: string;\n /** setState-powered method to update the input value */\n setInput: React.Dispatch<React.SetStateAction<string>>;\n /** Whether the API request is in progress */\n isLoading: boolean;\n};\n\nexport type UseChatOptionsWithCopilotConfig = UseChatOptions & {\n copilotConfig: CopilotApiConfig;\n /**\n * The current list of messages in the chat.\n */\n messages: Message[];\n /**\n * The setState-powered method to update the chat messages.\n */\n setMessages: React.Dispatch<React.SetStateAction<Message[]>>;\n};\n\nexport function useChat(options: UseChatOptionsWithCopilotConfig): UseChatHelpers {\n const { messages, setMessages } = options;\n const [input, setInput] = useState(\"\");\n const [isLoading, setIsLoading] = useState(false);\n const abortControllerRef = useRef<AbortController>();\n const threadIdRef = useRef<string | null>(null);\n const runIdRef = useRef<string | null>(null);\n const publicApiKey = options.copilotConfig.publicApiKey;\n const headers = {\n ...(options.headers || {}),\n ...(publicApiKey ? { [COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey } : {}),\n };\n\n const runChatCompletion = async (messages: Message[]): Promise<Message[]> => {\n setIsLoading(true);\n\n const newMessages: Message[] = [\n {\n id: nanoid(),\n createdAt: new Date(),\n content: \"\",\n role: \"assistant\",\n },\n ];\n const abortController = new AbortController();\n abortControllerRef.current = abortController;\n\n setMessages([...messages, ...newMessages]);\n\n // add threadId and runId to the body if it exists\n const copilotConfigBody = options.copilotConfig.body || {};\n if (threadIdRef.current) {\n copilotConfigBody.threadId = threadIdRef.current;\n }\n if (runIdRef.current) {\n copilotConfigBody.runId = runIdRef.current;\n }\n\n const messagesWithContext = [...(options.initialMessages || []), ...messages];\n const response = await fetchAndDecodeChatCompletion({\n copilotConfig: { ...options.copilotConfig, body: copilotConfigBody },\n messages: messagesWithContext,\n tools: options.tools,\n headers: headers,\n signal: abortController.signal,\n });\n\n if (response.headers.get(\"threadid\")) {\n threadIdRef.current = response.headers.get(\"threadid\");\n }\n\n if (response.headers.get(\"runid\")) {\n runIdRef.current = response.headers.get(\"runid\");\n }\n\n if (!response.events) {\n throw new Error(\"Failed to fetch chat completion\");\n }\n\n const reader = response.events.getReader();\n\n // Whether to feed back the new messages to GPT\n let feedback = false;\n\n try {\n while (true) {\n const { done, value } = await reader.read();\n\n if (done) {\n break;\n }\n\n let currentMessage = Object.assign({}, newMessages[newMessages.length - 1]);\n\n if (value.type === \"content\") {\n if (currentMessage.function_call || currentMessage.role === \"function\") {\n // Create a new message if the previous one is a function call or result\n currentMessage = {\n id: nanoid(),\n createdAt: new Date(),\n content: \"\",\n role: \"assistant\",\n };\n newMessages.push(currentMessage);\n }\n currentMessage.content += value.content;\n newMessages[newMessages.length - 1] = currentMessage;\n setMessages([...messages, ...newMessages]);\n } else if (value.type === \"result\") {\n // When we get a result message, it is already complete\n currentMessage = {\n id: nanoid(),\n role: \"function\",\n content: value.content,\n name: value.name,\n };\n newMessages.push(currentMessage);\n setMessages([...messages, ...newMessages]);\n\n // After receiving a result, feed back the new messages to GPT\n feedback = true;\n } else if (value.type === \"function\" || value.type === \"partial\") {\n // Create a new message if the previous one is not empty\n if (\n currentMessage.content != \"\" ||\n currentMessage.function_call ||\n currentMessage.role == \"function\"\n ) {\n currentMessage = {\n id: nanoid(),\n createdAt: new Date(),\n content: \"\",\n role: \"assistant\",\n };\n newMessages.push(currentMessage);\n }\n if (value.type === \"function\") {\n currentMessage.function_call = {\n name: value.name,\n arguments: JSON.stringify(value.arguments),\n scope: value.scope,\n };\n } else if (value.type === \"partial\") {\n let partialArguments: any = {};\n try {\n partialArguments = JSON.parse(untruncateJson(value.arguments));\n } catch (e) {}\n\n currentMessage.partialFunctionCall = {\n name: value.name,\n arguments: partialArguments,\n };\n }\n\n newMessages[newMessages.length - 1] = currentMessage;\n setMessages([...messages, ...newMessages]);\n\n if (value.type === \"function\") {\n // Execute the function call\n try {\n if (options.onFunctionCall && value.scope === \"client\") {\n const result = await options.onFunctionCall(\n messages,\n currentMessage.function_call as FunctionCall,\n );\n\n currentMessage = {\n id: nanoid(),\n role: \"function\",\n content: encodeResult(result),\n name: (currentMessage.function_call! as FunctionCall).name!,\n };\n newMessages.push(currentMessage);\n setMessages([...messages, ...newMessages]);\n\n // After a function call, feed back the new messages to GPT\n feedback = true;\n }\n } catch (error) {\n console.error(\"Failed to execute function call\", error);\n // TODO: Handle error\n // this should go to the message itself\n }\n }\n }\n }\n\n // If we want feedback, run the completion again and return the results\n if (feedback) {\n return await runChatCompletion([...messages, ...newMessages]);\n }\n // otherwise, return the new messages\n else {\n return newMessages.slice();\n }\n } finally {\n setIsLoading(false);\n }\n };\n\n const runChatCompletionAndHandleFunctionCall = async (messages: Message[]): Promise<void> => {\n await runChatCompletion(messages);\n };\n\n const append = async (message: Message): Promise<void> => {\n if (isLoading) {\n return;\n }\n const newMessages = [...messages, message];\n setMessages(newMessages);\n return runChatCompletionAndHandleFunctionCall(newMessages);\n };\n\n const reload = async (): Promise<void> => {\n if (isLoading || messages.length === 0) {\n return;\n }\n let newMessages = [...messages];\n const lastMessage = messages[messages.length - 1];\n\n if (lastMessage.role === \"assistant\") {\n newMessages = newMessages.slice(0, -1);\n }\n setMessages(newMessages);\n\n return runChatCompletionAndHandleFunctionCall(newMessages);\n };\n\n const stop = (): void => {\n abortControllerRef.current?.abort();\n };\n\n return {\n append,\n reload,\n stop,\n isLoading,\n input,\n setInput,\n };\n}\n"],"mappings":";;;;;;;;;;AAAA,SAAS,QAAQ,gBAAgB;AACjC;AAAA,EAIE;AAAA,EAEA;AAAA,OACK;AAEP,SAAS,cAAc;AAGvB,OAAO,oBAAoB;AAoFpB,SAAS,QAAQ,SAA0D;AAChF,QAAM,EAAE,UAAU,YAAY,IAAI;AAClC,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAS,EAAE;AACrC,QAAM,CAAC,WAAW,YAAY,IAAI,SAAS,KAAK;AAChD,QAAM,qBAAqB,OAAwB;AACnD,QAAM,cAAc,OAAsB,IAAI;AAC9C,QAAM,WAAW,OAAsB,IAAI;AAC3C,QAAM,eAAe,QAAQ,cAAc;AAC3C,QAAM,UAAU,kCACV,QAAQ,WAAW,CAAC,IACpB,eAAe,EAAE,CAAC,mCAAmC,GAAG,aAAa,IAAI,CAAC;AAGhF,QAAM,oBAAoB,CAAOA,cAA4C;AAC3E,iBAAa,IAAI;AAEjB,UAAM,cAAyB;AAAA,MAC7B;AAAA,QACE,IAAI,OAAO;AAAA,QACX,WAAW,oBAAI,KAAK;AAAA,QACpB,SAAS;AAAA,QACT,MAAM;AAAA,MACR;AAAA,IACF;AACA,UAAM,kBAAkB,IAAI,gBAAgB;AAC5C,uBAAmB,UAAU;AAE7B,gBAAY,CAAC,GAAGA,WAAU,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;AAAA,IACA;AAAA,EACF;AACF;","names":["messages"]}
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  CopilotContext
3
- } from "./chunk-GH7QK2AZ.mjs";
3
+ } from "./chunk-XUCMY57N.mjs";
4
4
 
5
5
  // src/hooks/use-make-copilot-readable.ts
6
6
  import { useContext, useEffect, useRef } from "react";
@@ -20,4 +20,4 @@ function useMakeCopilotReadable(information, parentId, categories) {
20
20
  export {
21
21
  useMakeCopilotReadable
22
22
  };
23
- //# sourceMappingURL=chunk-M7JUS6OQ.mjs.map
23
+ //# sourceMappingURL=chunk-Q6YXCGNM.mjs.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  CopilotContext
3
- } from "./chunk-GH7QK2AZ.mjs";
3
+ } from "./chunk-XUCMY57N.mjs";
4
4
 
5
5
  // src/hooks/use-make-copilot-document-readable.ts
6
6
  import { useContext, useEffect, useRef } from "react";
@@ -20,4 +20,4 @@ function useMakeCopilotDocumentReadable(document, categories, dependencies = [])
20
20
  export {
21
21
  useMakeCopilotDocumentReadable
22
22
  };
23
- //# sourceMappingURL=chunk-YKHUBROO.mjs.map
23
+ //# sourceMappingURL=chunk-R3D5GIQT.mjs.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  CopilotContext
3
- } from "./chunk-GH7QK2AZ.mjs";
3
+ } from "./chunk-XUCMY57N.mjs";
4
4
 
5
5
  // src/hooks/use-copilot-action.ts
6
6
  import { useRef, useContext, useEffect } from "react";
@@ -44,4 +44,4 @@ function useCopilotAction(action, dependencies) {
44
44
  export {
45
45
  useCopilotAction
46
46
  };
47
- //# sourceMappingURL=chunk-TEI34ZF5.mjs.map
47
+ //# sourceMappingURL=chunk-WHODFSGA.mjs.map
@@ -52,4 +52,4 @@ export {
52
52
  CopilotContext,
53
53
  useCopilotContext
54
54
  };
55
- //# sourceMappingURL=chunk-GH7QK2AZ.mjs.map
55
+ //# sourceMappingURL=chunk-XUCMY57N.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/context/copilot-context.tsx"],"sourcesContent":["import { FunctionCallHandler, Message, ToolDefinition } from \"@copilotkit/shared\";\nimport { ActionRenderProps, FrontendAction } from \"../types/frontend-action\";\nimport React, { Ref } from \"react\";\nimport { TreeNodeId } from \"../hooks/use-tree\";\nimport { DocumentPointer } from \"../types\";\n\nexport interface CopilotCloudConfig {\n restrictToTopic?: {\n validTopics: string[];\n invalidTopics?: string[];\n };\n}\n\n/**\n * Interface for the configuration of the Copilot API.\n */\nexport interface CopilotApiConfig {\n /**\n * The public API key for Copilot Cloud.\n */\n publicApiKey?: string;\n\n /**\n * The configuration for Copilot Cloud.\n */\n cloud?: CopilotCloudConfig;\n\n /**\n * The endpoint for the chat API.\n */\n chatApiEndpoint: string;\n\n /**\n * The endpoint for the chat API v2.\n */\n chatApiEndpointV2: string;\n\n /**\n * additional headers to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'Authorization': 'Bearer your_token_here'\n * }\n * ```\n */\n headers: Record<string, string>;\n\n /**\n * Additional body params to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'message': 'Hello, world!'\n * }\n * ```\n */\n body: Record<string, any>;\n\n /**\n * Backend only props that will be combined to body params to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'user_id': 'user_id'\n * }\n * ```\n */\n backendOnlyProps?: Record<string, any>;\n}\n\nexport type InChatRenderFunction = (props: ActionRenderProps<any>) => string | JSX.Element;\n\nexport interface CopilotContextParams {\n // function-calling\n entryPoints: Record<string, FrontendAction<any>>;\n setEntryPoint: (id: string, entryPoint: FrontendAction<any>) => void;\n removeEntryPoint: (id: string) => void;\n chatComponentsCache: React.RefObject<Record<string, InChatRenderFunction | string>>;\n getChatCompletionFunctionDescriptions: (\n customEntryPoints?: Record<string, FrontendAction<any>>,\n ) => ToolDefinition[];\n getFunctionCallHandler: (\n customEntryPoints?: Record<string, FrontendAction<any>>,\n ) => FunctionCallHandler;\n\n messages: Message[];\n setMessages: React.Dispatch<React.SetStateAction<Message[]>>;\n\n // text context\n addContext: (context: string, parentId?: string, categories?: string[]) => TreeNodeId;\n removeContext: (id: TreeNodeId) => void;\n getContextString: (documents: DocumentPointer[], categories: string[]) => string;\n\n // document context\n addDocumentContext: (documentPointer: DocumentPointer, categories?: string[]) => TreeNodeId;\n removeDocumentContext: (documentId: string) => void;\n getDocumentsContext: (categories: string[]) => DocumentPointer[];\n\n // api endpoints\n copilotApiConfig: CopilotApiConfig;\n}\n\nconst emptyCopilotContext: CopilotContextParams = {\n entryPoints: {},\n setEntryPoint: () => {},\n removeEntryPoint: () => {},\n getChatCompletionFunctionDescriptions: () => returnAndThrowInDebug([]),\n getFunctionCallHandler: () => returnAndThrowInDebug(async () => {}),\n chatComponentsCache: { current: {} },\n getContextString: (documents: DocumentPointer[], categories: string[]) =>\n returnAndThrowInDebug(\"\"),\n addContext: () => \"\",\n removeContext: () => {},\n messages: [],\n setMessages: () => returnAndThrowInDebug([]),\n\n getDocumentsContext: (categories: string[]) => returnAndThrowInDebug([]),\n addDocumentContext: () => returnAndThrowInDebug(\"\"),\n removeDocumentContext: () => {},\n\n copilotApiConfig: new (class implements CopilotApiConfig {\n get chatApiEndpoint(): string {\n throw new Error(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n }\n get chatApiEndpointV2(): string {\n throw new Error(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n }\n get headers(): Record<string, string> {\n return {};\n }\n get body(): Record<string, any> {\n return {};\n }\n })(),\n};\n\nexport const CopilotContext = React.createContext<CopilotContextParams>(emptyCopilotContext);\n\nexport function useCopilotContext(): CopilotContextParams {\n return React.useContext(CopilotContext);\n}\n\nfunction returnAndThrowInDebug<T>(value: T): T {\n throw new Error(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n return value;\n}\n"],"mappings":";;;;;AAEA,OAAO,WAAoB;AAwG3B,IAAM,sBAA4C;AAAA,EAChD,aAAa,CAAC;AAAA,EACd,eAAe,MAAM;AAAA,EAAC;AAAA,EACtB,kBAAkB,MAAM;AAAA,EAAC;AAAA,EACzB,uCAAuC,MAAM,sBAAsB,CAAC,CAAC;AAAA,EACrE,wBAAwB,MAAM,sBAAsB,MAAY;AAAA,EAAC,EAAC;AAAA,EAClE,qBAAqB,EAAE,SAAS,CAAC,EAAE;AAAA,EACnC,kBAAkB,CAAC,WAA8B,eAC/C,sBAAsB,EAAE;AAAA,EAC1B,YAAY,MAAM;AAAA,EAClB,eAAe,MAAM;AAAA,EAAC;AAAA,EACtB,UAAU,CAAC;AAAA,EACX,aAAa,MAAM,sBAAsB,CAAC,CAAC;AAAA,EAE3C,qBAAqB,CAAC,eAAyB,sBAAsB,CAAC,CAAC;AAAA,EACvE,oBAAoB,MAAM,sBAAsB,EAAE;AAAA,EAClD,uBAAuB,MAAM;AAAA,EAAC;AAAA,EAE9B,kBAAkB,IAAK,MAAkC;AAAA,IACvD,IAAI,kBAA0B;AAC5B,YAAM,IAAI,MAAM,uEAAuE;AAAA,IACzF;AAAA,IACA,IAAI,oBAA4B;AAC9B,YAAM,IAAI,MAAM,uEAAuE;AAAA,IACzF;AAAA,IACA,IAAI,UAAkC;AACpC,aAAO,CAAC;AAAA,IACV;AAAA,IACA,IAAI,OAA4B;AAC9B,aAAO,CAAC;AAAA,IACV;AAAA,EACF,EAAG;AACL;AAEO,IAAM,iBAAiB,MAAM,cAAoC,mBAAmB;AAEpF,SAAS,oBAA0C;AACxD,SAAO,MAAM,WAAW,cAAc;AACxC;AAEA,SAAS,sBAAyB,OAAa;AAC7C,QAAM,IAAI,MAAM,uEAAuE;AACvF,SAAO;AACT;","names":[]}
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  CopilotContext
3
- } from "./chunk-GH7QK2AZ.mjs";
3
+ } from "./chunk-XUCMY57N.mjs";
4
4
 
5
5
  // src/hooks/use-make-copilot-actionable.ts
6
6
  import { useRef, useContext, useEffect, useMemo } from "react";
@@ -30,4 +30,4 @@ function useMakeCopilotActionable(annotatedFunction, dependencies) {
30
30
  export {
31
31
  useMakeCopilotActionable
32
32
  };
33
- //# sourceMappingURL=chunk-4E2RCCQB.mjs.map
33
+ //# sourceMappingURL=chunk-YMX4OOEL.mjs.map
@@ -5,9 +5,9 @@ import { ReactNode } from 'react';
5
5
  */
6
6
  interface CopilotKitProps {
7
7
  /**
8
- * The api key for Copilot Cloud.
8
+ * The public API key for Copilot Cloud.
9
9
  */
10
- apiKey?: string;
10
+ publicApiKey?: string;
11
11
  /**
12
12
  * Cloud feature: Restrict to a specific topic.
13
13
  */
@@ -19,7 +19,7 @@ interface CopilotKitProps {
19
19
  /**
20
20
  * The endpoint for the chat API.
21
21
  */
22
- url: string;
22
+ url?: string;
23
23
  /**
24
24
  * additional headers to be sent with the request
25
25
  * @default {}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/copilot-provider/copilotkit-props.tsx"],"sourcesContent":["import { ReactNode } from \"react\";\n\n/**\n * Props for CopilotKit.\n */\n\nexport interface CopilotKitProps {\n /**\n * The api key for Copilot Cloud.\n */\n apiKey?: string;\n\n /**\n * Cloud feature: Restrict to a specific topic.\n */\n cloudRestrictToTopic?: {\n enabled?: boolean;\n validTopics: string[];\n invalidTopics?: string[];\n };\n\n /**\n * The endpoint for the chat API.\n */\n url: string;\n\n /**\n * additional headers to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'Authorization': 'Bearer your_token_here'\n * }\n * ```\n */\n headers?: Record<string, string>;\n\n /**\n * Additional body params to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'message': 'Hello, world!'\n * }\n * ```\n */\n body?: Record<string, any>;\n\n /**\n * The children to be rendered within the CopilotKit.\n */\n children: ReactNode;\n\n /**\n * Backend only props that will be combined to body params to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'user_id': 'users_id',\n * }\n * ```\n */\n backendOnlyProps?: Record<string, any>;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
1
+ {"version":3,"sources":["../../../src/components/copilot-provider/copilotkit-props.tsx"],"sourcesContent":["import { ReactNode } from \"react\";\n\n/**\n * Props for CopilotKit.\n */\n\nexport interface CopilotKitProps {\n /**\n * The public API key for Copilot Cloud.\n */\n publicApiKey?: string;\n\n /**\n * Cloud feature: Restrict to a specific topic.\n */\n cloudRestrictToTopic?: {\n enabled?: boolean;\n validTopics: string[];\n invalidTopics?: string[];\n };\n\n /**\n * The endpoint for the chat API.\n */\n url?: string;\n\n /**\n * additional headers to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'Authorization': 'Bearer your_token_here'\n * }\n * ```\n */\n headers?: Record<string, string>;\n\n /**\n * Additional body params to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'message': 'Hello, world!'\n * }\n * ```\n */\n body?: Record<string, any>;\n\n /**\n * The children to be rendered within the CopilotKit.\n */\n children: ReactNode;\n\n /**\n * Backend only props that will be combined to body params to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'user_id': 'users_id',\n * }\n * ```\n */\n backendOnlyProps?: Record<string, any>;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
@@ -332,6 +332,10 @@ function setsHaveIntersection2(setA, setB) {
332
332
  var import_jsx_runtime = require("react/jsx-runtime");
333
333
  function CopilotKit(_a) {
334
334
  var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
335
+ if (!props.url && !props.publicApiKey) {
336
+ throw new Error("Please provide either a url or a publicApiKey to the CopilotKit component.");
337
+ }
338
+ const chatApiEndpoint = props.url || import_shared.COPILOT_CLOUD_CHAT_URL;
335
339
  const [entryPoints, setEntryPoints] = (0, import_react4.useState)({});
336
340
  const chatComponentsCache = (0, import_react4.useRef)({});
337
341
  const { addElement, removeElement, printTree } = use_tree_default();
@@ -410,15 +414,17 @@ ${nonDocumentStrings}`;
410
414
  },
411
415
  [removeDocument]
412
416
  );
413
- if (!props.apiKey) {
417
+ if (!props.publicApiKey) {
414
418
  if (props.cloudRestrictToTopic) {
415
419
  throw new Error(
416
- "To use the cloudRestrictToTopic feature, please sign up at https://copilotkit.ai and provide an apiKey."
420
+ "To use the cloudRestrictToTopic feature, please sign up at https://copilotkit.ai and provide a publicApiKey."
417
421
  );
418
422
  }
419
423
  }
420
- const copilotApiConfig = __spreadProps(__spreadValues({}, props.apiKey ? { cloud: { apiKey: props.apiKey, restrictToTopic: props.cloudRestrictToTopic } } : {}), {
421
- chatApiEndpoint: props.url,
424
+ const copilotApiConfig = __spreadProps(__spreadValues({
425
+ publicApiKey: props.publicApiKey
426
+ }, props.publicApiKey ? { cloud: { restrictToTopic: props.cloudRestrictToTopic } } : {}), {
427
+ chatApiEndpoint,
422
428
  chatApiEndpointV2: `${props.url}/v2`,
423
429
  headers: props.headers || {},
424
430
  body: __spreadValues(__spreadValues({}, props.body), props.backendOnlyProps)