@copilotkit/react-core 0.37.0 → 0.38.0-mme-pre.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/.turbo/turbo-build.log +90 -90
  2. package/CHANGELOG.md +11 -0
  3. package/dist/{chunk-2EQGN5QK.mjs → chunk-36FKUOWM.mjs} +2 -2
  4. package/dist/{chunk-B2H3NC4E.mjs → chunk-3XVO5UEG.mjs} +5 -4
  5. package/dist/chunk-3XVO5UEG.mjs.map +1 -0
  6. package/dist/{chunk-LLU5URI5.mjs → chunk-AJSY6LS5.mjs} +1 -1
  7. package/dist/{chunk-LLU5URI5.mjs.map → chunk-AJSY6LS5.mjs.map} +1 -1
  8. package/dist/{chunk-HUKLBIUK.mjs → chunk-DY4YVUO3.mjs} +7 -5
  9. package/dist/{chunk-HUKLBIUK.mjs.map → chunk-DY4YVUO3.mjs.map} +1 -1
  10. package/dist/{chunk-Z5FB4WBL.mjs → chunk-NKIUZSGZ.mjs} +2 -2
  11. package/dist/{chunk-4OIVQMEM.mjs → chunk-ZHYCHXIO.mjs} +2 -2
  12. package/dist/components/copilot-provider/copilotkit.js.map +1 -1
  13. package/dist/components/copilot-provider/copilotkit.mjs +1 -1
  14. package/dist/components/copilot-provider/index.js.map +1 -1
  15. package/dist/components/copilot-provider/index.mjs +1 -1
  16. package/dist/components/index.js.map +1 -1
  17. package/dist/components/index.mjs +1 -1
  18. package/dist/hooks/index.js +8 -5
  19. package/dist/hooks/index.js.map +1 -1
  20. package/dist/hooks/index.mjs +3 -3
  21. package/dist/hooks/use-chat.d.ts +2 -2
  22. package/dist/hooks/use-chat.js +4 -3
  23. package/dist/hooks/use-chat.js.map +1 -1
  24. package/dist/hooks/use-chat.mjs +1 -1
  25. package/dist/hooks/use-copilot-chat.js +8 -5
  26. package/dist/hooks/use-copilot-chat.js.map +1 -1
  27. package/dist/hooks/use-copilot-chat.mjs +3 -3
  28. package/dist/index.js +8 -5
  29. package/dist/index.js.map +1 -1
  30. package/dist/index.mjs +6 -6
  31. package/dist/lib/copilot-task.js.map +1 -1
  32. package/dist/lib/copilot-task.mjs +2 -2
  33. package/dist/lib/index.js.map +1 -1
  34. package/dist/lib/index.mjs +2 -2
  35. package/dist/openai-assistants/hooks/index.js.map +1 -1
  36. package/dist/openai-assistants/hooks/index.mjs +2 -2
  37. package/dist/openai-assistants/hooks/use-copilot-chat-v2.js.map +1 -1
  38. package/dist/openai-assistants/hooks/use-copilot-chat-v2.mjs +2 -2
  39. package/dist/openai-assistants/index.js.map +1 -1
  40. package/dist/openai-assistants/index.mjs +2 -2
  41. package/dist/utils/extract.js.map +1 -1
  42. package/dist/utils/extract.mjs +2 -2
  43. package/dist/utils/index.js.map +1 -1
  44. package/dist/utils/index.mjs +2 -2
  45. package/package.json +4 -4
  46. package/src/components/copilot-provider/copilotkit.tsx +0 -1
  47. package/src/hooks/use-chat.ts +5 -5
  48. package/src/hooks/use-copilot-chat.ts +14 -4
  49. package/dist/chunk-B2H3NC4E.mjs.map +0 -1
  50. /package/dist/{chunk-2EQGN5QK.mjs.map → chunk-36FKUOWM.mjs.map} +0 -0
  51. /package/dist/{chunk-Z5FB4WBL.mjs.map → chunk-NKIUZSGZ.mjs.map} +0 -0
  52. /package/dist/{chunk-4OIVQMEM.mjs.map → chunk-ZHYCHXIO.mjs.map} +0 -0
@@ -1,5 +1,5 @@
1
1
 
2
- > @copilotkit/react-core@0.37.0 build /home/runner/work/CopilotKit/CopilotKit/CopilotKit/packages/react-core
2
+ > @copilotkit/react-core@0.38.0-mme-pre.0 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-copilot-readable.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/chat-suggestion-configuration.ts, src/types/document-pointer.ts, src/types/frontend-action.ts, src/types/index.ts, src/types/system-message.ts, src/utils/extract.ts, src/utils/fetch-chat-completion.ts, src/utils/index.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
@@ -10,6 +10,10 @@
10
10
  CLI Cleaning output folder
11
11
  ESM Build start
12
12
  CJS Build start
13
+ CJS dist/index.js 47.19 KB
14
+ CJS dist/components/index.js 17.23 KB
15
+ CJS dist/context/copilot-context.js 3.99 KB
16
+ CJS dist/hooks/index.js 22.31 KB
13
17
  CJS dist/lib/copilot-task.js 7.78 KB
14
18
  CJS dist/openai-assistants/index.js 9.69 KB
15
19
  CJS dist/types/chat-suggestion-configuration.js 893.00 B
@@ -17,14 +21,10 @@
17
21
  CJS dist/components/copilot-provider/copilotkit-props.js 864.00 B
18
22
  CJS dist/openai-assistants/hooks/index.js 9.59 KB
19
23
  CJS dist/openai-assistants/utils/index.js 2.30 KB
20
- CJS dist/index.js 47.02 KB
21
- CJS dist/components/index.js 17.23 KB
22
- CJS dist/context/copilot-context.js 3.99 KB
23
24
  CJS dist/context/index.js 3.98 KB
24
- CJS dist/hooks/index.js 22.14 KB
25
- CJS dist/hooks/use-chat.js 11.90 KB
25
+ CJS dist/hooks/use-chat.js 12.00 KB
26
26
  CJS dist/hooks/use-copilot-action.js 5.28 KB
27
- CJS dist/hooks/use-copilot-chat.js 17.53 KB
27
+ CJS dist/hooks/use-copilot-chat.js 17.70 KB
28
28
  CJS dist/hooks/use-copilot-readable.js 4.70 KB
29
29
  CJS dist/hooks/use-flat-category-store.js 2.87 KB
30
30
  CJS dist/hooks/use-make-copilot-actionable.js 4.96 KB
@@ -37,14 +37,18 @@
37
37
  CJS dist/types/index.js 797.00 B
38
38
  CJS dist/types/system-message.js 833.00 B
39
39
  CJS dist/utils/fetch-chat-completion.js 5.13 KB
40
- CJS dist/utils/index.js 9.53 KB
41
40
  CJS dist/utils/utils.test.js 184.00 B
41
+ CJS dist/utils/index.js 9.53 KB
42
42
  CJS dist/utils/utils.js 797.00 B
43
43
  CJS dist/components/copilot-provider/copilotkit.js 17.21 KB
44
44
  CJS dist/components/copilot-provider/index.js 17.27 KB
45
45
  CJS dist/openai-assistants/hooks/use-assistants.js 4.81 KB
46
46
  CJS dist/openai-assistants/hooks/use-copilot-chat-v2.js 9.68 KB
47
47
  CJS dist/openai-assistants/utils/process-message-stream.js 2.33 KB
48
+ CJS dist/index.js.map 97.16 KB
49
+ CJS dist/components/index.js.map 31.34 KB
50
+ CJS dist/context/copilot-context.js.map 6.81 KB
51
+ CJS dist/hooks/index.js.map 57.11 KB
48
52
  CJS dist/lib/copilot-task.js.map 21.93 KB
49
53
  CJS dist/openai-assistants/index.js.map 24.43 KB
50
54
  CJS dist/types/chat-suggestion-configuration.js.map 673.00 B
@@ -52,70 +56,31 @@
52
56
  CJS dist/components/copilot-provider/copilotkit-props.js.map 1.80 KB
53
57
  CJS dist/openai-assistants/hooks/index.js.map 24.73 KB
54
58
  CJS dist/openai-assistants/utils/index.js.map 1.44 KB
55
- CJS dist/index.js.map 96.64 KB
56
- CJS dist/components/index.js.map 31.34 KB
57
- CJS dist/context/copilot-context.js.map 6.81 KB
58
59
  CJS dist/context/index.js.map 7.04 KB
59
- CJS dist/hooks/index.js.map 56.58 KB
60
- CJS dist/hooks/use-chat.js.map 19.47 KB
60
+ CJS dist/hooks/use-chat.js.map 19.57 KB
61
61
  CJS dist/hooks/use-copilot-action.js.map 10.96 KB
62
- CJS dist/hooks/use-copilot-chat.js.map 42.38 KB
62
+ CJS dist/hooks/use-copilot-chat.js.map 42.91 KB
63
63
  CJS dist/hooks/use-copilot-readable.js.map 11.84 KB
64
64
  CJS dist/hooks/use-flat-category-store.js.map 4.25 KB
65
65
  CJS dist/hooks/use-make-copilot-actionable.js.map 8.56 KB
66
66
  CJS dist/hooks/use-make-copilot-document-readable.js.map 8.09 KB
67
67
  CJS dist/hooks/use-make-copilot-readable.js.map 7.78 KB
68
68
  CJS dist/hooks/use-tree.js.map 8.32 KB
69
- CJS dist/lib/index.js.map 22.00 KB
69
+ CJS dist/lib/index.js.map 21.99 KB
70
70
  CJS dist/types/document-pointer.js.map 292.00 B
71
71
  CJS dist/types/frontend-action.js.map 1.77 KB
72
72
  CJS dist/types/index.js.map 432.00 B
73
73
  CJS dist/types/system-message.js.map 249.00 B
74
74
  CJS dist/utils/fetch-chat-completion.js.map 5.11 KB
75
- CJS dist/utils/index.js.map 20.31 KB
76
75
  CJS dist/utils/utils.test.js.map 354.00 B
76
+ CJS dist/utils/index.js.map 20.31 KB
77
77
  CJS dist/utils/utils.js.map 137.00 B
78
78
  CJS dist/components/copilot-provider/copilotkit.js.map 31.28 KB
79
79
  CJS dist/components/copilot-provider/index.js.map 31.47 KB
80
80
  CJS dist/openai-assistants/hooks/use-assistants.js.map 5.90 KB
81
81
  CJS dist/openai-assistants/hooks/use-copilot-chat-v2.js.map 24.34 KB
82
82
  CJS dist/openai-assistants/utils/process-message-stream.js.map 1.33 KB
83
- CJS ⚡️ Build success in 213ms
84
- ESM dist/index.mjs 1.76 KB
85
- ESM dist/components/index.mjs 375.00 B
86
- ESM dist/context/copilot-context.mjs 205.00 B
87
- ESM dist/hooks/index.mjs 901.00 B
88
- ESM dist/chunk-CYDWEPFL.mjs 43.00 B
89
- ESM dist/chunk-7GFKOIO7.mjs 43.00 B
90
- ESM dist/chunk-BABVSMJR.mjs 43.00 B
91
- ESM dist/chunk-2EQGN5QK.mjs 4.39 KB
92
- ESM dist/chunk-FRAKUJWH.mjs 43.00 B
93
- ESM dist/chunk-ZFS5SQUT.mjs 802.00 B
94
- ESM dist/chunk-EFZPSZWO.mjs 43.00 B
95
- ESM dist/chunk-4OIVQMEM.mjs 3.79 KB
96
- ESM dist/chunk-LUGEI4YQ.mjs 43.00 B
97
- ESM dist/chunk-Z5FB4WBL.mjs 3.40 KB
98
- ESM dist/context/index.mjs 227.00 B
99
- ESM dist/chunk-VNRDQJXW.mjs 43.00 B
100
- ESM dist/chunk-EYKDJBDE.mjs 43.00 B
101
- ESM dist/chunk-MNZXQ6UH.mjs 909.00 B
102
- ESM dist/chunk-SR4RW4CU.mjs 1.06 KB
103
- ESM dist/chunk-S5LWO5V3.mjs 700.00 B
104
- ESM dist/chunk-B244LK6F.mjs 640.00 B
105
- ESM dist/hooks/use-chat.mjs 174.00 B
106
- ESM dist/hooks/use-copilot-action.mjs 202.00 B
107
- ESM dist/chunk-NSUYO6TP.mjs 1.46 KB
108
- ESM dist/hooks/use-copilot-chat.mjs 468.00 B
109
- ESM dist/chunk-HUKLBIUK.mjs 3.48 KB
110
- ESM dist/chunk-JD7BAH7U.mjs 43.00 B
111
- ESM dist/chunk-SPCZTZCY.mjs 43.00 B
112
- ESM dist/chunk-LLU5URI5.mjs 6.40 KB
113
- ESM dist/chunk-YULKJPY3.mjs 1.84 KB
114
- ESM dist/chunk-YWITCRBI.mjs 3.89 KB
115
- ESM dist/chunk-B2H3NC4E.mjs 6.78 KB
116
- ESM dist/chunk-MJKBCG4U.mjs 2.87 KB
117
- ESM dist/chunk-DY63PD22.mjs 1.80 KB
118
- ESM dist/chunk-SKC7AJIV.mjs 1.97 KB
83
+ CJS ⚡️ Build success in 231ms
119
84
  ESM dist/openai-assistants/hooks/use-copilot-chat-v2.mjs 540.00 B
120
85
  ESM dist/openai-assistants/utils/index.mjs 206.00 B
121
86
  ESM dist/openai-assistants/utils/process-message-stream.mjs 188.00 B
@@ -143,41 +108,41 @@
143
108
  ESM dist/hooks/use-tree.mjs 171.00 B
144
109
  ESM dist/lib/copilot-task.mjs 378.00 B
145
110
  ESM dist/lib/index.mjs 403.00 B
146
- ESM dist/index.mjs.map 71.00 B
147
- ESM dist/components/index.mjs.map 71.00 B
148
- ESM dist/context/copilot-context.mjs.map 71.00 B
149
- ESM dist/hooks/index.mjs.map 71.00 B
150
- ESM dist/chunk-CYDWEPFL.mjs.map 71.00 B
151
- ESM dist/chunk-7GFKOIO7.mjs.map 71.00 B
152
- ESM dist/chunk-BABVSMJR.mjs.map 71.00 B
153
- ESM dist/chunk-2EQGN5QK.mjs.map 7.90 KB
154
- ESM dist/chunk-FRAKUJWH.mjs.map 71.00 B
155
- ESM dist/chunk-ZFS5SQUT.mjs.map 1.26 KB
156
- ESM dist/chunk-EFZPSZWO.mjs.map 71.00 B
157
- ESM dist/chunk-4OIVQMEM.mjs.map 6.47 KB
158
- ESM dist/chunk-LUGEI4YQ.mjs.map 71.00 B
159
- ESM dist/chunk-Z5FB4WBL.mjs.map 8.65 KB
160
- ESM dist/context/index.mjs.map 71.00 B
161
- ESM dist/chunk-VNRDQJXW.mjs.map 71.00 B
162
- ESM dist/chunk-EYKDJBDE.mjs.map 71.00 B
163
- ESM dist/chunk-MNZXQ6UH.mjs.map 5.15 KB
164
- ESM dist/chunk-SR4RW4CU.mjs.map 1.87 KB
165
- ESM dist/chunk-S5LWO5V3.mjs.map 1.40 KB
166
- ESM dist/chunk-B244LK6F.mjs.map 1.08 KB
167
- ESM dist/hooks/use-chat.mjs.map 71.00 B
168
- ESM dist/hooks/use-copilot-action.mjs.map 71.00 B
169
- ESM dist/chunk-NSUYO6TP.mjs.map 4.27 KB
170
- ESM dist/hooks/use-copilot-chat.mjs.map 71.00 B
171
- ESM dist/chunk-HUKLBIUK.mjs.map 7.80 KB
172
- ESM dist/chunk-JD7BAH7U.mjs.map 71.00 B
173
- ESM dist/chunk-SPCZTZCY.mjs.map 71.00 B
174
- ESM dist/chunk-LLU5URI5.mjs.map 12.15 KB
175
- ESM dist/chunk-YULKJPY3.mjs.map 4.21 KB
176
- ESM dist/chunk-YWITCRBI.mjs.map 8.27 KB
177
- ESM dist/chunk-B2H3NC4E.mjs.map 14.66 KB
178
- ESM dist/chunk-MJKBCG4U.mjs.map 5.07 KB
179
- ESM dist/chunk-DY63PD22.mjs.map 6.71 KB
180
- ESM dist/chunk-SKC7AJIV.mjs.map 71.00 B
111
+ ESM dist/index.mjs 1.76 KB
112
+ ESM dist/chunk-CYDWEPFL.mjs 43.00 B
113
+ ESM dist/chunk-7GFKOIO7.mjs 43.00 B
114
+ ESM dist/chunk-BABVSMJR.mjs 43.00 B
115
+ ESM dist/chunk-36FKUOWM.mjs 4.39 KB
116
+ ESM dist/chunk-FRAKUJWH.mjs 43.00 B
117
+ ESM dist/chunk-ZFS5SQUT.mjs 802.00 B
118
+ ESM dist/chunk-EFZPSZWO.mjs 43.00 B
119
+ ESM dist/chunk-ZHYCHXIO.mjs 3.79 KB
120
+ ESM dist/chunk-LUGEI4YQ.mjs 43.00 B
121
+ ESM dist/chunk-NKIUZSGZ.mjs 3.40 KB
122
+ ESM dist/components/index.mjs 375.00 B
123
+ ESM dist/context/copilot-context.mjs 205.00 B
124
+ ESM dist/context/index.mjs 227.00 B
125
+ ESM dist/chunk-VNRDQJXW.mjs 43.00 B
126
+ ESM dist/hooks/index.mjs 901.00 B
127
+ ESM dist/chunk-EYKDJBDE.mjs 43.00 B
128
+ ESM dist/chunk-MNZXQ6UH.mjs 909.00 B
129
+ ESM dist/chunk-SR4RW4CU.mjs 1.06 KB
130
+ ESM dist/chunk-S5LWO5V3.mjs 700.00 B
131
+ ESM dist/chunk-B244LK6F.mjs 640.00 B
132
+ ESM dist/hooks/use-chat.mjs 174.00 B
133
+ ESM dist/hooks/use-copilot-action.mjs 202.00 B
134
+ ESM dist/chunk-NSUYO6TP.mjs 1.46 KB
135
+ ESM dist/hooks/use-copilot-chat.mjs 468.00 B
136
+ ESM dist/chunk-DY4YVUO3.mjs 3.55 KB
137
+ ESM dist/chunk-JD7BAH7U.mjs 43.00 B
138
+ ESM dist/chunk-SPCZTZCY.mjs 43.00 B
139
+ ESM dist/chunk-AJSY6LS5.mjs 6.40 KB
140
+ ESM dist/chunk-YULKJPY3.mjs 1.84 KB
141
+ ESM dist/chunk-YWITCRBI.mjs 3.89 KB
142
+ ESM dist/chunk-3XVO5UEG.mjs 6.88 KB
143
+ ESM dist/chunk-MJKBCG4U.mjs 2.87 KB
144
+ ESM dist/chunk-DY63PD22.mjs 1.80 KB
145
+ ESM dist/chunk-SKC7AJIV.mjs 1.97 KB
181
146
  ESM dist/openai-assistants/hooks/use-copilot-chat-v2.mjs.map 71.00 B
182
147
  ESM dist/openai-assistants/utils/index.mjs.map 71.00 B
183
148
  ESM dist/openai-assistants/utils/process-message-stream.mjs.map 71.00 B
@@ -205,9 +170,44 @@
205
170
  ESM dist/hooks/use-tree.mjs.map 71.00 B
206
171
  ESM dist/lib/copilot-task.mjs.map 71.00 B
207
172
  ESM dist/lib/index.mjs.map 71.00 B
208
- ESM ⚡️ Build success in 221ms
173
+ ESM dist/index.mjs.map 71.00 B
174
+ ESM dist/chunk-CYDWEPFL.mjs.map 71.00 B
175
+ ESM dist/chunk-7GFKOIO7.mjs.map 71.00 B
176
+ ESM dist/chunk-BABVSMJR.mjs.map 71.00 B
177
+ ESM dist/chunk-36FKUOWM.mjs.map 7.90 KB
178
+ ESM dist/chunk-FRAKUJWH.mjs.map 71.00 B
179
+ ESM dist/chunk-ZFS5SQUT.mjs.map 1.26 KB
180
+ ESM dist/chunk-EFZPSZWO.mjs.map 71.00 B
181
+ ESM dist/chunk-ZHYCHXIO.mjs.map 6.47 KB
182
+ ESM dist/chunk-LUGEI4YQ.mjs.map 71.00 B
183
+ ESM dist/chunk-NKIUZSGZ.mjs.map 8.65 KB
184
+ ESM dist/components/index.mjs.map 71.00 B
185
+ ESM dist/context/copilot-context.mjs.map 71.00 B
186
+ ESM dist/context/index.mjs.map 71.00 B
187
+ ESM dist/chunk-VNRDQJXW.mjs.map 71.00 B
188
+ ESM dist/hooks/index.mjs.map 71.00 B
189
+ ESM dist/chunk-EYKDJBDE.mjs.map 71.00 B
190
+ ESM dist/chunk-MNZXQ6UH.mjs.map 5.15 KB
191
+ ESM dist/chunk-SR4RW4CU.mjs.map 1.87 KB
192
+ ESM dist/chunk-S5LWO5V3.mjs.map 1.40 KB
193
+ ESM dist/chunk-B244LK6F.mjs.map 1.08 KB
194
+ ESM dist/hooks/use-chat.mjs.map 71.00 B
195
+ ESM dist/hooks/use-copilot-action.mjs.map 71.00 B
196
+ ESM dist/chunk-NSUYO6TP.mjs.map 4.27 KB
197
+ ESM dist/hooks/use-copilot-chat.mjs.map 71.00 B
198
+ ESM dist/chunk-DY4YVUO3.mjs.map 8.23 KB
199
+ ESM dist/chunk-JD7BAH7U.mjs.map 71.00 B
200
+ ESM dist/chunk-SPCZTZCY.mjs.map 71.00 B
201
+ ESM dist/chunk-AJSY6LS5.mjs.map 12.15 KB
202
+ ESM dist/chunk-YULKJPY3.mjs.map 4.21 KB
203
+ ESM dist/chunk-YWITCRBI.mjs.map 8.27 KB
204
+ ESM dist/chunk-3XVO5UEG.mjs.map 14.77 KB
205
+ ESM dist/chunk-MJKBCG4U.mjs.map 5.07 KB
206
+ ESM dist/chunk-DY63PD22.mjs.map 6.71 KB
207
+ ESM dist/chunk-SKC7AJIV.mjs.map 71.00 B
208
+ ESM ⚡️ Build success in 243ms
209
209
  DTS Build start
210
- DTS ⚡️ Build success in 8429ms
210
+ DTS ⚡️ Build success in 8825ms
211
211
  DTS dist/index.d.ts 1.76 KB
212
212
  DTS dist/components/copilot-provider/copilotkit.d.ts 271.00 B
213
213
  DTS dist/components/copilot-provider/copilotkit-props.d.ts 1.70 KB
@@ -217,7 +217,7 @@
217
217
  DTS dist/hooks/use-copilot-action.d.ts 286.00 B
218
218
  DTS dist/hooks/use-make-copilot-readable.d.ts 228.00 B
219
219
  DTS dist/hooks/use-make-copilot-document-readable.d.ts 516.00 B
220
- DTS dist/hooks/use-chat.d.ts 3.03 KB
220
+ DTS dist/hooks/use-chat.d.ts 3.08 KB
221
221
  DTS dist/hooks/use-copilot-readable.d.ts 1.10 KB
222
222
  DTS dist/types/document-pointer.d.ts 181.00 B
223
223
  DTS dist/types/system-message.d.ts 132.00 B
package/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # ui
2
2
 
3
+ ## 0.38.0-mme-pre.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Update actions in run loop
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies
12
+ - @copilotkit/shared@0.38.0-mme-pre.0
13
+
3
14
  ## 0.37.0
4
15
 
5
16
  ### Minor Changes
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-ZFS5SQUT.mjs";
4
4
  import {
5
5
  defaultCopilotContextCategories
6
- } from "./chunk-LLU5URI5.mjs";
6
+ } from "./chunk-AJSY6LS5.mjs";
7
7
  import {
8
8
  CopilotContext
9
9
  } from "./chunk-DY63PD22.mjs";
@@ -134,4 +134,4 @@ export {
134
134
  useCopilotChatV2,
135
135
  defaultSystemMessage
136
136
  };
137
- //# sourceMappingURL=chunk-2EQGN5QK.mjs.map
137
+ //# sourceMappingURL=chunk-36FKUOWM.mjs.map
@@ -23,6 +23,7 @@ function useChat(options) {
23
23
  const publicApiKey = options.copilotConfig.publicApiKey;
24
24
  const headers = __spreadValues(__spreadValues({}, options.headers || {}), publicApiKey ? { [COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey } : {});
25
25
  const runChatCompletion = (messages2) => __async(this, null, function* () {
26
+ var _a, _b;
26
27
  options.setIsLoading(true);
27
28
  const newMessages = [
28
29
  {
@@ -47,7 +48,7 @@ function useChat(options) {
47
48
  const response = yield fetchAndDecodeChatCompletion({
48
49
  copilotConfig: __spreadProps(__spreadValues({}, options.copilotConfig), { body: copilotConfigBody }),
49
50
  messages: messagesWithContext,
50
- tools: options.tools,
51
+ tools: (_a = options.tools) == null ? void 0 : _a.current,
51
52
  headers,
52
53
  signal: abortController.signal
53
54
  });
@@ -133,8 +134,8 @@ function useChat(options) {
133
134
  setMessages([...messages2, ...newMessages]);
134
135
  if (value.type === "function") {
135
136
  try {
136
- if (options.onFunctionCall && value.scope === "client") {
137
- const result = yield options.onFunctionCall(
137
+ if (((_b = options.onFunctionCall) == null ? void 0 : _b.current) && value.scope === "client") {
138
+ const result = yield options.onFunctionCall.current(
138
139
  messages2,
139
140
  currentMessage.function_call
140
141
  );
@@ -201,4 +202,4 @@ function useChat(options) {
201
202
  export {
202
203
  useChat
203
204
  };
204
- //# sourceMappingURL=chunk-B2H3NC4E.mjs.map
205
+ //# sourceMappingURL=chunk-3XVO5UEG.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/hooks/use-chat.ts"],"sourcesContent":["import { useRef, useState, useContext, useEffect } from \"react\";\nimport { CopilotContext } from \"../context/copilot-context\";\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?: React.MutableRefObject<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?: React.MutableRefObject<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};\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 /**\n * A callback to get the latest system message.\n */\n makeSystemMessageCallback: () => Message;\n\n /**\n * Whether the API request is in progress\n */\n isLoading: boolean;\n\n /**\n * setState-powered method to update the isChatLoading value\n */\n setIsLoading: React.Dispatch<React.SetStateAction<boolean>>;\n};\n\nexport function useChat(options: UseChatOptionsWithCopilotConfig): UseChatHelpers {\n const { messages, setMessages, makeSystemMessageCallback } = options;\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 options.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 // 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 systemMessage = makeSystemMessageCallback();\n\n const messagesWithContext = [systemMessage, ...(options.initialMessages || []), ...messages];\n const response = await fetchAndDecodeChatCompletion({\n copilotConfig: { ...options.copilotConfig, body: copilotConfigBody },\n messages: messagesWithContext,\n tools: options.tools?.current,\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 setMessages([\n ...messages,\n {\n id: nanoid(),\n createdAt: new Date(),\n content: response.statusText,\n role: \"assistant\",\n },\n ]);\n options.setIsLoading(false);\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?.current && value.scope === \"client\") {\n const result = await options.onFunctionCall.current(\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 // wait for next tick to make sure all the react state updates\n // TODO: This is a hack, is there a more robust way to do this?\n // - tried using react-dom's flushSync, but it did not work\n await new Promise((resolve) => setTimeout(resolve, 10));\n\n return await runChatCompletion([...messages, ...newMessages]);\n }\n // otherwise, return the new messages\n else {\n return newMessages.slice();\n }\n } finally {\n options.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 (options.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 (options.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 };\n}\n"],"mappings":";;;;;;;;;;AAAA,SAAS,cAA+C;AAExD;AAAA,EAIE;AAAA,EAEA;AAAA,OACK;AAEP,SAAS,cAAc;AAGvB,OAAO,oBAAoB;AA6FpB,SAAS,QAAQ,SAA0D;AAChF,QAAM,EAAE,UAAU,aAAa,0BAA0B,IAAI;AAC7D,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;AAtH/E;AAuHI,YAAQ,aAAa,IAAI;AAEzB,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,GAAG,WAAW,CAAC;AAEzC,UAAM,oBAAoB,QAAQ,cAAc,QAAQ,CAAC;AACzD,QAAI,YAAY,SAAS;AACvB,wBAAkB,WAAW,YAAY;AAAA,IAC3C;AACA,QAAI,SAAS,SAAS;AACpB,wBAAkB,QAAQ,SAAS;AAAA,IACrC;AAEA,UAAM,gBAAgB,0BAA0B;AAEhD,UA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AAzU3B;AA0UI,6BAAmB,YAAnB,mBAA4B;AAAA,EAC9B;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":["messages"]}
@@ -207,4 +207,4 @@ export {
207
207
  CopilotKit,
208
208
  defaultCopilotContextCategories
209
209
  };
210
- //# sourceMappingURL=chunk-LLU5URI5.mjs.map
210
+ //# sourceMappingURL=chunk-AJSY6LS5.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/components/copilot-provider/copilotkit.tsx"],"sourcesContent":["/**\n * Provides the Copilot context to its children.\n * \n * <img\n * referrerPolicy=\"no-referrer-when-downgrade\"\n * src=\"https://static.scarf.sh/a.png?x-pxid=a9b290bb-38f9-4518-ac3b-8f54fdbf43be\"\n * />\n * \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>\n * The backend can use OpenAI, or you can bring your own LLM. For examples of the\n * backend api implementation, see `examples/next-openai` or the [runtime\n * docs](https://docs.copilotkit.ai/getting-started/quickstart-runtime).\n * </Note>\n * \n * <RequestExample>\n * ```jsx CopilotKit Example\n * import { CopilotKit } from \"@copilotkit/react-core\";\n * \n * <CopilotKit \n * runtimeUrl=\"https://your.copilotkit.api\">\n * <YourApp/>\n * </CopilotKit>\n * ```\n * </RequestExample>\n * \n * ## Example usage\n * \n * ```jsx\n * <CopilotKit publicApiKey=\"the api key or self host (see below)\">\n * <App />\n * </CopilotKit>\n```\n */\nimport { 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 { CopilotChatSuggestionConfiguration, DocumentPointer } from \"../../types\";\n\nimport {\n COPILOT_CLOUD_CHAT_URL,\n CopilotCloudConfig,\n FunctionCallHandler,\n Message,\n actionToChatCompletionFunction,\n} from \"@copilotkit/shared\";\n\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\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.runtimeUrl && !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.runtimeUrl || 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 const [isLoading, setIsLoading] = useState(false);\n const [chatInstructions, setChatInstructions] = useState(\"\");\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 let cloud: CopilotCloudConfig | undefined = undefined;\n if (props.publicApiKey) {\n cloud = {\n guardrails: {\n input: {\n restrictToTopic: {\n enabled: props.cloudRestrictToTopic ? true : false,\n validTopics: props.cloudRestrictToTopic?.validTopics || [],\n invalidTopics: props.cloudRestrictToTopic?.invalidTopics || [],\n },\n },\n },\n };\n }\n\n // get the appropriate CopilotApiConfig from the props\n const copilotApiConfig: CopilotApiConfig = {\n publicApiKey: props.publicApiKey,\n ...(cloud ? { cloud } : {}),\n chatApiEndpoint: chatApiEndpoint,\n chatApiEndpointV2: `${props.url}/v2`,\n headers: props.headers || {},\n body: {\n ...props.body,\n ...props.backendOnlyProps,\n },\n transcribeAudioUrl: props.transcribeAudioUrl,\n textToSpeechUrl: props.textToSpeechUrl,\n credentials: props.credentials,\n };\n\n const [chatSuggestionConfiguration, setChatSuggestionConfiguration] = useState<{\n [key: string]: CopilotChatSuggestionConfiguration;\n }>({});\n\n const addChatSuggestionConfiguration = (\n id: string,\n suggestion: CopilotChatSuggestionConfiguration,\n ) => {\n setChatSuggestionConfiguration((prev) => ({ ...prev, [id]: suggestion }));\n };\n\n const removeChatSuggestionConfiguration = (id: string) => {\n setChatSuggestionConfiguration((prev) => {\n const { [id]: _, ...rest } = prev;\n return rest;\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 isLoading,\n setIsLoading,\n chatSuggestionConfiguration,\n addChatSuggestionConfiguration,\n removeChatSuggestionConfiguration,\n chatInstructions,\n setChatInstructions,\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":";;;;;;;;;;;;;;;;;;AAoCA,SAAc,aAAa,QAAQ,gBAAgB;AASnD;AAAA,EACE;AAAA,EAIA;AAAA,OACK;AA6KH;AAtKG,SAAS,WAAW,IAAyC;AAAzC,eAAE,WA1D7B,IA0D2B,IAAe,kBAAf,IAAe,CAAb;AA1D7B,MAAAA,KAAAC;AA8DE,MAAI,CAAC,MAAM,cAAc,CAAC,MAAM,OAAO,CAAC,MAA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qD;AAC7F,SAAO,CAAO,cAAc,iBAAiB;AAC3C,QAAI,wBAA6D,CAAC;AAClE,aAASE,WAAU,SAAS;AAC1B,4BAAsBA,QAAO,IAAI,IAAIA;AAAA,IACvC;AAEA,UAAM,SAAS,sBAAsB,aAAa,QAAQ,EAAE;AAC5D,QAAI,QAAQ;AACV,UAAI,wBAA+C,CAAC;AACpD,UAAI,aAAa,WAAW;AAC1B,gCAAwB,KAAK,MAAM,aAAa,SAAS;AAAA,MAC3D;AACA,aAAO,MAAM,OAAO,QAAQ,qBAAqB;AAAA,IACnD;AAAA,EACF;AACF;","names":["_a","_b","action"]}
1
+ {"version":3,"sources":["../src/components/copilot-provider/copilotkit.tsx"],"sourcesContent":["/**\n * Provides the Copilot context to its children.\n * \n * <img\n * referrerPolicy=\"no-referrer-when-downgrade\"\n * src=\"https://static.scarf.sh/a.png?x-pxid=a9b290bb-38f9-4518-ac3b-8f54fdbf43be\"\n * />\n * \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>\n * The backend can use OpenAI, or you can bring your own LLM. For examples of the\n * backend api implementation, see `examples/next-openai` or the [runtime\n * docs](https://docs.copilotkit.ai/getting-started/quickstart-runtime).\n * </Note>\n * \n * <RequestExample>\n * ```jsx CopilotKit Example\n * import { CopilotKit } from \"@copilotkit/react-core\";\n * \n * <CopilotKit \n * runtimeUrl=\"https://your.copilotkit.api\">\n * <YourApp/>\n * </CopilotKit>\n * ```\n * </RequestExample>\n * \n * ## Example usage\n * \n * ```jsx\n * <CopilotKit publicApiKey=\"the api key or self host (see below)\">\n * <App />\n * </CopilotKit>\n```\n */\nimport { 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 { CopilotChatSuggestionConfiguration, DocumentPointer } from \"../../types\";\n\nimport {\n COPILOT_CLOUD_CHAT_URL,\n CopilotCloudConfig,\n FunctionCallHandler,\n Message,\n actionToChatCompletionFunction,\n} from \"@copilotkit/shared\";\n\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\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.runtimeUrl && !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.runtimeUrl || 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 const [isLoading, setIsLoading] = useState(false);\n const [chatInstructions, setChatInstructions] = useState(\"\");\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 let cloud: CopilotCloudConfig | undefined = undefined;\n if (props.publicApiKey) {\n cloud = {\n guardrails: {\n input: {\n restrictToTopic: {\n enabled: props.cloudRestrictToTopic ? true : false,\n validTopics: props.cloudRestrictToTopic?.validTopics || [],\n invalidTopics: props.cloudRestrictToTopic?.invalidTopics || [],\n },\n },\n },\n };\n }\n\n // get the appropriate CopilotApiConfig from the props\n const copilotApiConfig: CopilotApiConfig = {\n publicApiKey: props.publicApiKey,\n ...(cloud ? { cloud } : {}),\n chatApiEndpoint: chatApiEndpoint,\n chatApiEndpointV2: `${props.url}/v2`,\n headers: props.headers || {},\n body: {\n ...props.body,\n ...props.backendOnlyProps,\n },\n transcribeAudioUrl: props.transcribeAudioUrl,\n textToSpeechUrl: props.textToSpeechUrl,\n credentials: props.credentials,\n };\n\n const [chatSuggestionConfiguration, setChatSuggestionConfiguration] = useState<{\n [key: string]: CopilotChatSuggestionConfiguration;\n }>({});\n\n const addChatSuggestionConfiguration = (\n id: string,\n suggestion: CopilotChatSuggestionConfiguration,\n ) => {\n setChatSuggestionConfiguration((prev) => ({ ...prev, [id]: suggestion }));\n };\n\n const removeChatSuggestionConfiguration = (id: string) => {\n setChatSuggestionConfiguration((prev) => {\n const { [id]: _, ...rest } = prev;\n return rest;\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 isLoading,\n setIsLoading,\n chatSuggestionConfiguration,\n addChatSuggestionConfiguration,\n removeChatSuggestionConfiguration,\n chatInstructions,\n setChatInstructions,\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 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":";;;;;;;;;;;;;;;;;;AAoCA,SAAc,aAAa,QAAQ,gBAAgB;AASnD;AAAA,EACE;AAAA,EAIA;AAAA,OACK;AA6KH;AAtKG,SAAS,WAAW,IAAyC;AAAzC,eAAE,WA1D7B,IA0D2B,IAAe,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,QAAQ;AAExD,SAAS,qCAAqC,SAAkD;AAC9F,SAAO,QAAQ,IAAI,8BAA8B;AACnD;AAEA,SAAS,iCAAiC,SAAqD;AAC7F,SAAO,CAAO,cAAc,iBAAiB;AAC3C,QAAI,wBAA6D,CAAC;AAClE,aAASE,WAAU,SAAS;AAC1B,4BAAsBA,QAAO,IAAI,IAAIA;AAAA,IACvC;AACA,UAAM,SAAS,sBAAsB,aAAa,QAAQ,EAAE;AAC5D,QAAI,QAAQ;AACV,UAAI,wBAA+C,CAAC;AACpD,UAAI,aAAa,WAAW;AAC1B,gCAAwB,KAAK,MAAM,aAAa,SAAS;AAAA,MAC3D;AACA,aAAO,MAAM,OAAO,QAAQ,qBAAqB;AAAA,IACnD;AAAA,EACF;AACF;","names":["_a","_b","action"]}
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  defaultCopilotContextCategories
3
- } from "./chunk-LLU5URI5.mjs";
3
+ } from "./chunk-AJSY6LS5.mjs";
4
4
  import {
5
5
  useChat
6
- } from "./chunk-B2H3NC4E.mjs";
6
+ } from "./chunk-3XVO5UEG.mjs";
7
7
  import {
8
8
  CopilotContext
9
9
  } from "./chunk-DY63PD22.mjs";
@@ -51,12 +51,14 @@ function useCopilotChat(_a = {}) {
51
51
  const functionDescriptions = useMemo(() => {
52
52
  return getChatCompletionFunctionDescriptions();
53
53
  }, [getChatCompletionFunctionDescriptions]);
54
+ const tools = useUpdatedRef(functionDescriptions);
55
+ const onFunctionCall = useUpdatedRef(getFunctionCallHandler());
54
56
  const { append, reload, stop } = useChat(__spreadProps(__spreadValues({}, options), {
55
57
  copilotConfig: copilotApiConfig,
56
58
  id: options.id,
57
59
  initialMessages: options.initialMessages || [],
58
- tools: functionDescriptions,
59
- onFunctionCall: getFunctionCallHandler(),
60
+ tools,
61
+ onFunctionCall,
60
62
  headers: __spreadValues({}, options.headers),
61
63
  body: __spreadValues({}, options.body),
62
64
  messages,
@@ -113,4 +115,4 @@ export {
113
115
  useCopilotChat,
114
116
  defaultSystemMessage
115
117
  };
116
- //# sourceMappingURL=chunk-HUKLBIUK.mjs.map
118
+ //# sourceMappingURL=chunk-DY4YVUO3.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/hooks/use-copilot-chat.ts"],"sourcesContent":["/**\n * A hook for accessing Copilot's chat API.\n *\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 * <RequestExample>\n * ```jsx useCopilotChat Example\n * import { useCopilotChat }\n * from \"@copilotkit/react-core\";\n *\n * const { appendMessage } = useCopilotChat();\n * appendMessage({ content: \"Hello, world!\", role: \"user\", id: \"1\" });\n * ```\n * </RequestExample>\n *\n * useCopilotChat returns an object with the following properties:\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 *\n */\nimport { useMemo, useContext, useRef, useEffect, useCallback } from \"react\";\nimport { CopilotContext } from \"../context/copilot-context\";\nimport { Message, ToolDefinition } from \"@copilotkit/shared\";\nimport { SystemMessageFunction } from \"../types\";\nimport { useChat } from \"./use-chat\";\nimport { defaultCopilotContextCategories } from \"../components\";\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 /**\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 * 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 isLoading: boolean;\n}\n\nexport function useCopilotChat({\n makeSystemMessage,\n ...options\n}: UseCopilotChatOptions = {}): UseCopilotChatReturn {\n const {\n getContextString,\n getChatCompletionFunctionDescriptions,\n getFunctionCallHandler,\n copilotApiConfig,\n messages,\n setMessages,\n isLoading,\n setIsLoading,\n chatInstructions,\n } = useContext(CopilotContext);\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 {\n id: \"system\",\n content: systemMessageMaker(contextString, chatInstructions),\n role: \"system\",\n } as Message;\n }, [getContextString, makeSystemMessage, chatInstructions]);\n\n const functionDescriptions: ToolDefinition[] = useMemo(() => {\n return getChatCompletionFunctionDescriptions();\n }, [getChatCompletionFunctionDescriptions]);\n\n const { append, reload, stop } = useChat({\n ...options,\n copilotConfig: copilotApiConfig,\n id: options.id,\n initialMessages: options.initialMessages || [],\n tools: functionDescriptions,\n onFunctionCall: getFunctionCallHandler(),\n headers: { ...options.headers },\n body: {\n ...options.body,\n },\n messages,\n setMessages,\n makeSystemMessageCallback,\n isLoading,\n setIsLoading,\n });\n\n const visibleMessages = messages.filter(\n (message) =>\n message.role === \"user\" || message.role === \"assistant\" || message.role === \"function\",\n );\n\n return {\n visibleMessages,\n appendMessage: append,\n setMessages,\n reloadMessages: reload,\n stopGeneration: stop,\n deleteMessage,\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":";;;;;;;;;;;;;;;;AA4BA,SAAS,SAAS,YAAY,QAAQ,WAAW,mBAAmB;AAsD7D,SAAS,eAAe,KAGJ,CAAC,GAAyB;AAHtB,eAC7B;AAAA;AAAA,EAnFF,IAkF+B,IAE1B,oBAF0B,IAE1B;AAAA,IADH;AAAA;AAGA,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI,WAAW,cAAc;AAI7B,QAAM,yBAAyB,cAAc,gBAAgB;AAC7D,QAAM,gBAAgB;AAAA,IACpB,CAAC,cAAsB;AACrB,kBAAY,CAAC,SAAS,KAAK,OAAO,CAAC,YAAY,QAAQ,OAAO,SAAS,CAAC;AAAA,IAC1E;AAAA,IACA,CAAC,WAAW;AAAA,EACd;AAEA,QAAM,4BAA4B,YA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B;AAAA;AAAA,EAAO,2BAA2B;AAEhE;","names":[]}
1
+ {"version":3,"sources":["../src/hooks/use-copilot-chat.ts"],"sourcesContent":["/**\n * A hook for accessing Copilot's chat API.\n *\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 * <RequestExample>\n * ```jsx useCopilotChat Example\n * import { useCopilotChat }\n * from \"@copilotkit/react-core\";\n *\n * const { appendMessage } = useCopilotChat();\n * appendMessage({ content: \"Hello, world!\", role: \"user\", id: \"1\" });\n * ```\n * </RequestExample>\n *\n * useCopilotChat returns an object with the following properties:\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 *\n */\nimport { useMemo, useContext, useRef, useEffect, useCallback } from \"react\";\nimport { CopilotContext } from \"../context/copilot-context\";\nimport { Message, ToolDefinition } from \"@copilotkit/shared\";\nimport { SystemMessageFunction } from \"../types\";\nimport { useChat } from \"./use-chat\";\nimport { defaultCopilotContextCategories } from \"../components\";\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 /**\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 * 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 isLoading: boolean;\n}\n\nexport function useCopilotChat({\n makeSystemMessage,\n ...options\n}: UseCopilotChatOptions = {}): UseCopilotChatReturn {\n const {\n getContextString,\n getChatCompletionFunctionDescriptions,\n getFunctionCallHandler,\n copilotApiConfig,\n messages,\n setMessages,\n isLoading,\n setIsLoading,\n chatInstructions,\n } = useContext(CopilotContext);\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 {\n id: \"system\",\n content: systemMessageMaker(contextString, chatInstructions),\n role: \"system\",\n } as Message;\n }, [getContextString, makeSystemMessage, chatInstructions]);\n\n const functionDescriptions: ToolDefinition[] = useMemo(() => {\n return getChatCompletionFunctionDescriptions();\n }, [getChatCompletionFunctionDescriptions]);\n\n const tools = useUpdatedRef(functionDescriptions);\n const onFunctionCall = useUpdatedRef(getFunctionCallHandler());\n\n const { append, reload, stop } = useChat({\n ...options,\n copilotConfig: copilotApiConfig,\n id: options.id,\n initialMessages: options.initialMessages || [],\n tools: tools,\n onFunctionCall: onFunctionCall,\n headers: { ...options.headers },\n body: {\n ...options.body,\n },\n messages,\n setMessages,\n makeSystemMessageCallback,\n isLoading,\n setIsLoading,\n });\n\n const visibleMessages = messages.filter(\n (message) =>\n message.role === \"user\" || message.role === \"assistant\" || message.role === \"function\",\n );\n\n return {\n visibleMessages,\n appendMessage: append,\n setMessages,\n reloadMessages: reload,\n stopGeneration: stop,\n deleteMessage,\n isLoading,\n };\n}\n\n/**\n * A lot of our functions get called in the same run loop. Hooks get called with state,\n * then process async long running loops. If the hook gets called with the new state,\n * we want ongoing runloops to use the latest state.\n *\n * For example, the first action updated the context, now the second action should\n * see the latest context.\n */\n\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":";;;;;;;;;;;;;;;;AA4BA,SAAS,SAAS,YAAY,QAAQ,WAAW,mBAAmB;AAsD7D,SAAS,eAAe,KAGJ,CAAC,GAAyB;AAHtB,eAC7B;AAAA;AAAA,EAnFF,IAkF+B,IAE1B,oBAF0B,IAE1B;AAAA,IADH;AAAA;AAGA,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI,WAAW,cAAc;AAI7B,QAAM,yBAAyB,cAAc,gBAAgB;AAC7D,QAAM,gBAAgB;AAAA,IACpB,CAAC,cAAsB;AACrB,kBAAY,CAAC,SAAS,KAAK,OAAO,CAAC,YAAY,QAAQ,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Q;AACR,SACE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,KAUG,yBAAyB;AAAA;AAAA,EAAO,2BAA2B;AAEhE;","names":[]}
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  defaultCopilotContextCategories
3
- } from "./chunk-LLU5URI5.mjs";
3
+ } from "./chunk-AJSY6LS5.mjs";
4
4
  import {
5
5
  fetchAndDecodeChatCompletion
6
6
  } from "./chunk-MJKBCG4U.mjs";
@@ -104,4 +104,4 @@ ${instructions}
104
104
  export {
105
105
  CopilotTask
106
106
  };
107
- //# sourceMappingURL=chunk-Z5FB4WBL.mjs.map
107
+ //# sourceMappingURL=chunk-NKIUZSGZ.mjs.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  defaultCopilotContextCategories
3
- } from "./chunk-LLU5URI5.mjs";
3
+ } from "./chunk-AJSY6LS5.mjs";
4
4
  import {
5
5
  fetchAndDecodeChatCompletion
6
6
  } from "./chunk-MJKBCG4U.mjs";
@@ -119,4 +119,4 @@ Any additional messages provided are for providing context only and should not b
119
119
  export {
120
120
  extract
121
121
  };
122
- //# sourceMappingURL=chunk-4OIVQMEM.mjs.map
122
+ //# sourceMappingURL=chunk-ZHYCHXIO.mjs.map