@copilotkit/react-core 0.20.1 → 0.21.0-mme-assistant-api.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 (36) hide show
  1. package/.turbo/turbo-build.log +84 -84
  2. package/CHANGELOG.md +11 -0
  3. package/dist/{chunk-JFUS5YVO.mjs → chunk-2YF2MC22.mjs} +21 -4
  4. package/dist/chunk-2YF2MC22.mjs.map +1 -0
  5. package/dist/{chunk-BQ5SSV4Z.mjs → chunk-3WKJ25L3.mjs} +25 -12
  6. package/dist/chunk-3WKJ25L3.mjs.map +1 -0
  7. package/dist/{chunk-EACH5HZU.mjs → chunk-KLGA2MES.mjs} +2 -2
  8. package/dist/{chunk-3TF6G3W5.mjs → chunk-UHTJLRI6.mjs} +2 -2
  9. package/dist/hooks/index.js +33 -6
  10. package/dist/hooks/index.js.map +1 -1
  11. package/dist/hooks/index.mjs +3 -3
  12. package/dist/hooks/use-chat.js +33 -6
  13. package/dist/hooks/use-chat.js.map +1 -1
  14. package/dist/hooks/use-chat.mjs +2 -2
  15. package/dist/hooks/use-copilot-chat.js +33 -6
  16. package/dist/hooks/use-copilot-chat.js.map +1 -1
  17. package/dist/hooks/use-copilot-chat.mjs +3 -3
  18. package/dist/index.js +40 -11
  19. package/dist/index.js.map +1 -1
  20. package/dist/index.mjs +4 -4
  21. package/dist/lib/copilot-task.js +17 -8
  22. package/dist/lib/copilot-task.js.map +1 -1
  23. package/dist/lib/copilot-task.mjs +2 -2
  24. package/dist/lib/index.js +17 -8
  25. package/dist/lib/index.js.map +1 -1
  26. package/dist/lib/index.mjs +2 -2
  27. package/dist/utils/fetch-chat-completion.js +24 -13
  28. package/dist/utils/fetch-chat-completion.js.map +1 -1
  29. package/dist/utils/fetch-chat-completion.mjs +1 -1
  30. package/package.json +4 -4
  31. package/src/hooks/use-chat.ts +20 -1
  32. package/src/utils/fetch-chat-completion.ts +25 -11
  33. package/dist/chunk-BQ5SSV4Z.mjs.map +0 -1
  34. package/dist/chunk-JFUS5YVO.mjs.map +0 -1
  35. /package/dist/{chunk-EACH5HZU.mjs.map → chunk-KLGA2MES.mjs.map} +0 -0
  36. /package/dist/{chunk-3TF6G3W5.mjs.map → chunk-UHTJLRI6.mjs.map} +0 -0
@@ -1,5 +1,5 @@
1
1
 
2
- > @copilotkit/react-core@0.20.1 build /home/runner/work/CopilotKit/CopilotKit/CopilotKit/packages/react-core
2
+ > @copilotkit/react-core@0.21.0-mme-assistant-api.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-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/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/components/copilot-provider/standard-copilot-api-config.tsx, 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,26 +10,25 @@
10
10
  CLI Cleaning output folder
11
11
  ESM Build start
12
12
  CJS Build start
13
- CJS dist/index.js 36.07 KB
14
- CJS dist/components/index.js 15.17 KB
15
- CJS dist/context/copilot-context.js 3.62 KB
16
- CJS dist/hooks/index.js 16.68 KB
17
- CJS dist/lib/copilot-task.js 7.43 KB
18
- CJS dist/openai-assistants/index.js 9.31 KB
13
+ CJS dist/lib/copilot-task.js 7.38 KB
19
14
  CJS dist/types/document-pointer.js 841.00 B
20
- CJS dist/utils/fetch-chat-completion.js 5.04 KB
15
+ CJS dist/utils/fetch-chat-completion.js 4.95 KB
21
16
  CJS dist/components/copilot-provider/copilotkit-props.js 878.00 B
22
- CJS dist/openai-assistants/hooks/index.js 9.21 KB
23
17
  CJS dist/openai-assistants/utils/index.js 2.30 KB
18
+ CJS dist/index.js 36.75 KB
19
+ CJS dist/components/index.js 15.17 KB
20
+ CJS dist/context/copilot-context.js 3.62 KB
24
21
  CJS dist/context/index.js 3.60 KB
25
- CJS dist/hooks/use-chat.js 9.29 KB
26
- CJS dist/hooks/use-copilot-chat.js 14.51 KB
22
+ CJS dist/hooks/index.js 17.41 KB
23
+ CJS dist/hooks/use-chat.js 10.01 KB
24
+ CJS dist/hooks/use-copilot-chat.js 15.24 KB
27
25
  CJS dist/hooks/use-flat-category-store.js 2.87 KB
28
26
  CJS dist/hooks/use-make-copilot-actionable.js 4.47 KB
29
27
  CJS dist/hooks/use-make-copilot-document-readable.js 4.22 KB
30
28
  CJS dist/hooks/use-make-copilot-readable.js 4.10 KB
31
29
  CJS dist/hooks/use-tree.js 5.53 KB
32
- CJS dist/lib/index.js 7.39 KB
30
+ CJS dist/lib/index.js 7.34 KB
31
+ CJS dist/openai-assistants/index.js 9.31 KB
33
32
  CJS dist/types/index.js 797.00 B
34
33
  CJS dist/types/system-message.js 833.00 B
35
34
  CJS dist/utils/utils.test.js 184.00 B
@@ -37,29 +36,29 @@
37
36
  CJS dist/components/copilot-provider/copilotkit.js 15.17 KB
38
37
  CJS dist/components/copilot-provider/index.js 15.21 KB
39
38
  CJS dist/components/copilot-provider/standard-copilot-api-config.js 1.48 KB
39
+ CJS dist/openai-assistants/hooks/index.js 9.21 KB
40
40
  CJS dist/openai-assistants/hooks/use-assistants.js 4.82 KB
41
41
  CJS dist/openai-assistants/hooks/use-copilot-chat-v2.js 9.30 KB
42
42
  CJS dist/openai-assistants/utils/process-message-stream.js 2.33 KB
43
- CJS dist/index.js.map 67.24 KB
44
- CJS dist/components/index.js.map 27.80 KB
45
- CJS dist/context/copilot-context.js.map 4.68 KB
46
- CJS dist/hooks/index.js.map 36.60 KB
47
- CJS dist/lib/copilot-task.js.map 16.84 KB
48
- CJS dist/openai-assistants/index.js.map 20.99 KB
43
+ CJS dist/lib/copilot-task.js.map 17.19 KB
49
44
  CJS dist/types/document-pointer.js.map 292.00 B
50
- CJS dist/utils/fetch-chat-completion.js.map 4.44 KB
45
+ CJS dist/utils/fetch-chat-completion.js.map 4.79 KB
51
46
  CJS dist/components/copilot-provider/copilotkit-props.js.map 1.12 KB
52
- CJS dist/openai-assistants/hooks/index.js.map 21.29 KB
53
47
  CJS dist/openai-assistants/utils/index.js.map 1.44 KB
48
+ CJS dist/index.js.map 68.63 KB
49
+ CJS dist/components/index.js.map 27.80 KB
50
+ CJS dist/context/copilot-context.js.map 4.68 KB
54
51
  CJS dist/context/index.js.map 4.91 KB
55
- CJS dist/hooks/use-chat.js.map 15.40 KB
56
- CJS dist/hooks/use-copilot-chat.js.map 31.69 KB
52
+ CJS dist/hooks/index.js.map 38.00 KB
53
+ CJS dist/hooks/use-chat.js.map 16.80 KB
54
+ CJS dist/hooks/use-copilot-chat.js.map 33.09 KB
57
55
  CJS dist/hooks/use-flat-category-store.js.map 4.25 KB
58
56
  CJS dist/hooks/use-make-copilot-actionable.js.map 6.22 KB
59
57
  CJS dist/hooks/use-make-copilot-document-readable.js.map 5.99 KB
60
58
  CJS dist/hooks/use-make-copilot-readable.js.map 6.04 KB
61
59
  CJS dist/hooks/use-tree.js.map 8.32 KB
62
- CJS dist/lib/index.js.map 16.91 KB
60
+ CJS dist/lib/index.js.map 17.26 KB
61
+ CJS dist/openai-assistants/index.js.map 20.99 KB
63
62
  CJS dist/types/index.js.map 253.00 B
64
63
  CJS dist/types/system-message.js.map 249.00 B
65
64
  CJS dist/utils/utils.test.js.map 354.00 B
@@ -67,121 +66,122 @@
67
66
  CJS dist/components/copilot-provider/copilotkit.js.map 27.74 KB
68
67
  CJS dist/components/copilot-provider/index.js.map 27.93 KB
69
68
  CJS dist/components/copilot-provider/standard-copilot-api-config.js.map 1.17 KB
69
+ CJS dist/openai-assistants/hooks/index.js.map 21.29 KB
70
70
  CJS dist/openai-assistants/hooks/use-assistants.js.map 5.92 KB
71
71
  CJS dist/openai-assistants/hooks/use-copilot-chat-v2.js.map 20.90 KB
72
72
  CJS dist/openai-assistants/utils/process-message-stream.js.map 1.33 KB
73
- CJS ⚡️ Build success in 164ms
74
- ESM dist/components/copilot-provider/standard-copilot-api-config.mjs 201.00 B
75
- ESM dist/openai-assistants/hooks/index.mjs 548.00 B
76
- ESM dist/openai-assistants/hooks/use-assistants.mjs 2.59 KB
77
- ESM dist/openai-assistants/hooks/use-copilot-chat-v2.mjs 575.00 B
78
- ESM dist/openai-assistants/utils/index.mjs 206.00 B
79
- ESM dist/openai-assistants/utils/process-message-stream.mjs 188.00 B
80
- ESM dist/types/index.mjs 66.00 B
81
- ESM dist/types/system-message.mjs 43.00 B
82
- ESM dist/utils/fetch-chat-completion.mjs 319.00 B
83
- ESM dist/utils/utils.test.mjs 170.00 B
84
- ESM dist/utils/utils.mjs 34.00 B
85
- ESM dist/components/copilot-provider/copilotkit-props.mjs 59.00 B
86
- ESM dist/components/copilot-provider/copilotkit.mjs 380.00 B
87
- ESM dist/components/copilot-provider/index.mjs 396.00 B
88
- ESM dist/hooks/use-make-copilot-actionable.mjs 241.00 B
89
- ESM dist/hooks/use-make-copilot-document-readable.mjs 260.00 B
90
- ESM dist/hooks/use-make-copilot-readable.mjs 235.00 B
91
- ESM dist/hooks/use-tree.mjs 171.00 B
92
- ESM dist/lib/copilot-task.mjs 410.00 B
93
- ESM dist/lib/index.mjs 435.00 B
94
- ESM dist/openai-assistants/index.mjs 597.00 B
95
- ESM dist/types/document-pointer.mjs 45.00 B
73
+ CJS ⚡️ Build success in 187ms
96
74
  ESM dist/index.mjs 1.52 KB
75
+ ESM dist/components/index.mjs 407.00 B
76
+ ESM dist/context/copilot-context.mjs 219.00 B
77
+ ESM dist/hooks/index.mjs 769.00 B
97
78
  ESM dist/chunk-EFZPSZWO.mjs 43.00 B
98
79
  ESM dist/chunk-LUGEI4YQ.mjs 43.00 B
99
- ESM dist/chunk-EACH5HZU.mjs 3.17 KB
80
+ ESM dist/chunk-KLGA2MES.mjs 3.17 KB
100
81
  ESM dist/chunk-7GFKOIO7.mjs 43.00 B
101
82
  ESM dist/chunk-BABVSMJR.mjs 43.00 B
102
83
  ESM dist/chunk-6WZFE6II.mjs 4.39 KB
103
84
  ESM dist/chunk-FRAKUJWH.mjs 43.00 B
104
85
  ESM dist/chunk-MZ5UN3BY.mjs 802.00 B
105
- ESM dist/components/index.mjs 407.00 B
106
- ESM dist/context/copilot-context.mjs 219.00 B
107
86
  ESM dist/context/index.mjs 227.00 B
108
87
  ESM dist/chunk-VNRDQJXW.mjs 43.00 B
109
- ESM dist/hooks/index.mjs 769.00 B
110
88
  ESM dist/chunk-5UGLWBZJ.mjs 43.00 B
111
89
  ESM dist/chunk-WH4L73VS.mjs 970.00 B
112
90
  ESM dist/chunk-JVCBCB2T.mjs 700.00 B
113
91
  ESM dist/chunk-2EP7VLPI.mjs 640.00 B
114
92
  ESM dist/hooks/use-chat.mjs 174.00 B
115
93
  ESM dist/hooks/use-copilot-chat.mjs 500.00 B
116
- ESM dist/chunk-3TF6G3W5.mjs 2.89 KB
94
+ ESM dist/chunk-UHTJLRI6.mjs 2.89 KB
117
95
  ESM dist/chunk-JD7BAH7U.mjs 43.00 B
118
96
  ESM dist/chunk-SPCZTZCY.mjs 43.00 B
119
97
  ESM dist/chunk-PHK2K7UB.mjs 4.60 KB
120
98
  ESM dist/chunk-F2JIAPZQ.mjs 405.00 B
121
99
  ESM dist/chunk-VUY2K2DI.mjs 3.89 KB
122
100
  ESM dist/chunk-S7ZVOTYK.mjs 1.42 KB
123
- ESM dist/chunk-JFUS5YVO.mjs 5.04 KB
124
- ESM dist/chunk-BQ5SSV4Z.mjs 2.64 KB
101
+ ESM dist/chunk-2YF2MC22.mjs 5.65 KB
102
+ ESM dist/chunk-3WKJ25L3.mjs 2.69 KB
125
103
  ESM dist/hooks/use-flat-category-store.mjs 216.00 B
126
104
  ESM dist/chunk-YULKJPY3.mjs 1.84 KB
127
105
  ESM dist/chunk-MRXNTQOX.mjs 1.89 KB
128
- ESM dist/components/copilot-provider/standard-copilot-api-config.mjs.map 71.00 B
129
- ESM dist/openai-assistants/hooks/index.mjs.map 71.00 B
130
- ESM dist/openai-assistants/hooks/use-assistants.mjs.map 4.67 KB
131
- ESM dist/openai-assistants/hooks/use-copilot-chat-v2.mjs.map 71.00 B
132
- ESM dist/openai-assistants/utils/index.mjs.map 71.00 B
133
- ESM dist/openai-assistants/utils/process-message-stream.mjs.map 71.00 B
134
- ESM dist/types/index.mjs.map 71.00 B
135
- ESM dist/types/system-message.mjs.map 71.00 B
136
- ESM dist/utils/fetch-chat-completion.mjs.map 71.00 B
137
- ESM dist/utils/utils.test.mjs.map 352.00 B
138
- ESM dist/utils/utils.mjs.map 71.00 B
139
- ESM dist/components/copilot-provider/copilotkit-props.mjs.map 71.00 B
140
- ESM dist/components/copilot-provider/copilotkit.mjs.map 71.00 B
141
- ESM dist/components/copilot-provider/index.mjs.map 71.00 B
142
- ESM dist/hooks/use-make-copilot-actionable.mjs.map 71.00 B
143
- ESM dist/hooks/use-make-copilot-document-readable.mjs.map 71.00 B
144
- ESM dist/hooks/use-make-copilot-readable.mjs.map 71.00 B
145
- ESM dist/hooks/use-tree.mjs.map 71.00 B
146
- ESM dist/lib/copilot-task.mjs.map 71.00 B
147
- ESM dist/lib/index.mjs.map 71.00 B
148
- ESM dist/openai-assistants/index.mjs.map 71.00 B
149
- ESM dist/types/document-pointer.mjs.map 71.00 B
106
+ ESM dist/openai-assistants/hooks/index.mjs 548.00 B
107
+ ESM dist/components/copilot-provider/standard-copilot-api-config.mjs 201.00 B
108
+ ESM dist/openai-assistants/hooks/use-assistants.mjs 2.59 KB
109
+ ESM dist/openai-assistants/hooks/use-copilot-chat-v2.mjs 575.00 B
110
+ ESM dist/openai-assistants/utils/index.mjs 206.00 B
111
+ ESM dist/openai-assistants/utils/process-message-stream.mjs 188.00 B
112
+ ESM dist/types/index.mjs 66.00 B
113
+ ESM dist/types/system-message.mjs 43.00 B
114
+ ESM dist/utils/fetch-chat-completion.mjs 319.00 B
115
+ ESM dist/utils/utils.test.mjs 170.00 B
116
+ ESM dist/utils/utils.mjs 34.00 B
117
+ ESM dist/components/copilot-provider/copilotkit-props.mjs 59.00 B
118
+ ESM dist/components/copilot-provider/copilotkit.mjs 380.00 B
119
+ ESM dist/components/copilot-provider/index.mjs 396.00 B
120
+ ESM dist/hooks/use-make-copilot-actionable.mjs 241.00 B
121
+ ESM dist/hooks/use-make-copilot-document-readable.mjs 260.00 B
122
+ ESM dist/hooks/use-make-copilot-readable.mjs 235.00 B
123
+ ESM dist/hooks/use-tree.mjs 171.00 B
124
+ ESM dist/lib/copilot-task.mjs 410.00 B
125
+ ESM dist/lib/index.mjs 435.00 B
126
+ ESM dist/openai-assistants/index.mjs 597.00 B
127
+ ESM dist/types/document-pointer.mjs 45.00 B
150
128
  ESM dist/index.mjs.map 71.00 B
129
+ ESM dist/components/index.mjs.map 71.00 B
130
+ ESM dist/context/copilot-context.mjs.map 71.00 B
131
+ ESM dist/hooks/index.mjs.map 71.00 B
151
132
  ESM dist/chunk-EFZPSZWO.mjs.map 71.00 B
152
133
  ESM dist/chunk-LUGEI4YQ.mjs.map 71.00 B
153
- ESM dist/chunk-EACH5HZU.mjs.map 5.55 KB
134
+ ESM dist/chunk-KLGA2MES.mjs.map 5.55 KB
154
135
  ESM dist/chunk-7GFKOIO7.mjs.map 71.00 B
155
136
  ESM dist/chunk-BABVSMJR.mjs.map 71.00 B
156
137
  ESM dist/chunk-6WZFE6II.mjs.map 7.90 KB
157
138
  ESM dist/chunk-FRAKUJWH.mjs.map 71.00 B
158
139
  ESM dist/chunk-MZ5UN3BY.mjs.map 1.26 KB
159
- ESM dist/components/index.mjs.map 71.00 B
160
- ESM dist/context/copilot-context.mjs.map 71.00 B
161
140
  ESM dist/context/index.mjs.map 71.00 B
162
141
  ESM dist/chunk-VNRDQJXW.mjs.map 71.00 B
163
- ESM dist/hooks/index.mjs.map 71.00 B
164
142
  ESM dist/chunk-5UGLWBZJ.mjs.map 71.00 B
165
143
  ESM dist/chunk-WH4L73VS.mjs.map 1.66 KB
166
144
  ESM dist/chunk-JVCBCB2T.mjs.map 1.42 KB
167
145
  ESM dist/chunk-2EP7VLPI.mjs.map 1.47 KB
168
146
  ESM dist/hooks/use-chat.mjs.map 71.00 B
169
147
  ESM dist/hooks/use-copilot-chat.mjs.map 71.00 B
170
- ESM dist/chunk-3TF6G3W5.mjs.map 4.59 KB
148
+ ESM dist/chunk-UHTJLRI6.mjs.map 4.59 KB
171
149
  ESM dist/chunk-JD7BAH7U.mjs.map 71.00 B
172
150
  ESM dist/chunk-SPCZTZCY.mjs.map 71.00 B
173
151
  ESM dist/chunk-PHK2K7UB.mjs.map 9.68 KB
174
152
  ESM dist/chunk-F2JIAPZQ.mjs.map 1.12 KB
175
153
  ESM dist/chunk-VUY2K2DI.mjs.map 8.27 KB
176
154
  ESM dist/chunk-S7ZVOTYK.mjs.map 4.59 KB
177
- ESM dist/chunk-JFUS5YVO.mjs.map 11.29 KB
178
- ESM dist/chunk-BQ5SSV4Z.mjs.map 4.40 KB
155
+ ESM dist/chunk-2YF2MC22.mjs.map 12.34 KB
156
+ ESM dist/chunk-3WKJ25L3.mjs.map 4.75 KB
179
157
  ESM dist/hooks/use-flat-category-store.mjs.map 71.00 B
180
158
  ESM dist/chunk-YULKJPY3.mjs.map 4.21 KB
181
159
  ESM dist/chunk-MRXNTQOX.mjs.map 71.00 B
182
- ESM ⚡️ Build success in 175ms
160
+ ESM dist/openai-assistants/hooks/index.mjs.map 71.00 B
161
+ ESM dist/components/copilot-provider/standard-copilot-api-config.mjs.map 71.00 B
162
+ ESM dist/openai-assistants/hooks/use-assistants.mjs.map 4.67 KB
163
+ ESM dist/openai-assistants/hooks/use-copilot-chat-v2.mjs.map 71.00 B
164
+ ESM dist/openai-assistants/utils/index.mjs.map 71.00 B
165
+ ESM dist/openai-assistants/utils/process-message-stream.mjs.map 71.00 B
166
+ ESM dist/types/index.mjs.map 71.00 B
167
+ ESM dist/types/system-message.mjs.map 71.00 B
168
+ ESM dist/utils/fetch-chat-completion.mjs.map 71.00 B
169
+ ESM dist/utils/utils.test.mjs.map 352.00 B
170
+ ESM dist/utils/utils.mjs.map 71.00 B
171
+ ESM dist/components/copilot-provider/copilotkit-props.mjs.map 71.00 B
172
+ ESM dist/components/copilot-provider/copilotkit.mjs.map 71.00 B
173
+ ESM dist/components/copilot-provider/index.mjs.map 71.00 B
174
+ ESM dist/hooks/use-make-copilot-actionable.mjs.map 71.00 B
175
+ ESM dist/hooks/use-make-copilot-document-readable.mjs.map 71.00 B
176
+ ESM dist/hooks/use-make-copilot-readable.mjs.map 71.00 B
177
+ ESM dist/hooks/use-tree.mjs.map 71.00 B
178
+ ESM dist/lib/copilot-task.mjs.map 71.00 B
179
+ ESM dist/lib/index.mjs.map 71.00 B
180
+ ESM dist/openai-assistants/index.mjs.map 71.00 B
181
+ ESM dist/types/document-pointer.mjs.map 71.00 B
182
+ ESM ⚡️ Build success in 192ms
183
183
  DTS Build start
184
- DTS ⚡️ Build success in 6031ms
184
+ DTS ⚡️ Build success in 5689ms
185
185
  DTS dist/index.d.ts 1.41 KB
186
186
  DTS dist/components/copilot-provider/copilotkit.d.ts 1.26 KB
187
187
  DTS dist/components/copilot-provider/copilotkit-props.d.ts 1007.00 B
package/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # ui
2
2
 
3
+ ## 0.21.0-mme-assistant-api.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Alpha
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies
12
+ - @copilotkit/shared@0.5.0-mme-assistant-api.0
13
+
3
14
  ## 0.20.1
4
15
 
5
16
  ### Patch Changes
@@ -1,8 +1,10 @@
1
1
  import {
2
2
  fetchAndDecodeChatCompletion
3
- } from "./chunk-BQ5SSV4Z.mjs";
3
+ } from "./chunk-3WKJ25L3.mjs";
4
4
  import {
5
- __async
5
+ __async,
6
+ __spreadProps,
7
+ __spreadValues
6
8
  } from "./chunk-MRXNTQOX.mjs";
7
9
 
8
10
  // src/hooks/use-chat.ts
@@ -14,6 +16,8 @@ function useChat(options) {
14
16
  const [input, setInput] = useState("");
15
17
  const [isLoading, setIsLoading] = useState(false);
16
18
  const abortControllerRef = useRef();
19
+ const threadIdRef = useRef(null);
20
+ const runIdRef = useRef(null);
17
21
  const runChatCompletion = (messages2) => __async(this, null, function* () {
18
22
  setIsLoading(true);
19
23
  const newMessages = [
@@ -27,14 +31,27 @@ function useChat(options) {
27
31
  const abortController = new AbortController();
28
32
  abortControllerRef.current = abortController;
29
33
  setMessages([...messages2, ...newMessages]);
34
+ const copilotConfigBody = options.copilotConfig.body || {};
35
+ if (threadIdRef.current) {
36
+ copilotConfigBody.threadId = threadIdRef.current;
37
+ }
38
+ if (runIdRef.current) {
39
+ copilotConfigBody.runId = runIdRef.current;
40
+ }
30
41
  const messagesWithContext = [...options.initialMessages || [], ...messages2];
31
42
  const response = yield fetchAndDecodeChatCompletion({
32
- copilotConfig: options.copilotConfig,
43
+ copilotConfig: __spreadProps(__spreadValues({}, options.copilotConfig), { body: copilotConfigBody }),
33
44
  messages: messagesWithContext,
34
45
  tools: options.tools,
35
46
  headers: options.headers,
36
47
  signal: abortController.signal
37
48
  });
49
+ if (response.headers.get("threadid")) {
50
+ threadIdRef.current = response.headers.get("threadid");
51
+ }
52
+ if (response.headers.get("runid")) {
53
+ runIdRef.current = response.headers.get("runid");
54
+ }
38
55
  if (!response.events) {
39
56
  throw new Error("Failed to fetch chat completion");
40
57
  }
@@ -155,4 +172,4 @@ function useChat(options) {
155
172
  export {
156
173
  useChat
157
174
  };
158
- //# sourceMappingURL=chunk-JFUS5YVO.mjs.map
175
+ //# sourceMappingURL=chunk-2YF2MC22.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/hooks/use-chat.ts"],"sourcesContent":["import { useRef, useState } from \"react\";\nimport { Message, ToolDefinition, FunctionCallHandler, encodeResult } from \"@copilotkit/shared\";\nimport { nanoid } from \"nanoid\";\nimport { fetchAndDecodeChatCompletion } from \"../utils/fetch-chat-completion\";\nimport { CopilotApiConfig } from \"../context\";\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 /** Current messages in the chat */\n messages: Message[];\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\nexport function useChat(options: UseChatOptionsWithCopilotConfig): UseChatHelpers {\n const [messages, setMessages] = useState<Message[]>([]);\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\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: options.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\") {\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 currentMessage.function_call = {\n name: value.name,\n arguments: JSON.stringify(value.arguments),\n scope: value.scope,\n };\n\n newMessages[newMessages.length - 1] = currentMessage;\n setMessages([...messages, ...newMessages]);\n\n // Execute the function call\n try {\n if (options.onFunctionCall && value.scope === \"client\") {\n const result = await options.onFunctionCall(messages, currentMessage.function_call);\n\n currentMessage = {\n id: nanoid(),\n role: \"function\",\n content: encodeResult(result),\n name: currentMessage.function_call!.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 // 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 messages,\n append,\n reload,\n stop,\n isLoading,\n input,\n setInput,\n };\n}\n"],"mappings":";;;;;;;;;;AAAA,SAAS,QAAQ,gBAAgB;AACjC,SAAuD,oBAAoB;AAC3E,SAAS,cAAc;AAgFhB,SAAS,QAAQ,SAA0D;AAChF,QAAM,CAAC,UAAU,WAAW,IAAI,SAAoB,CAAC,CAAC;AACtD,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;AAE3C,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,GAAG,WAAW,CAAC;AAGzC,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,sBAAsB,CAAC,GAAI,QAAQ,mBAAmB,CAAC,GAAI,GAAGA,SAAQ;AAC5E,UAAM,WAAW,M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,SAAS,CAAO,YAAoC;AACxD,QAAI,WAAW;AACb;AAAA,IACF;AACA,UAAM,cAAc,CAAC,GAAG,UAAU,OAAO;AACzC,gBAAY,WAAW;AACvB,WAAO,uCAAuC,WAAW;AAAA,EAC3D;AAEA,QAAM,SAAS,MAA2B;AACxC,QAAI,aAAa,SAAS,WAAW,GAAG;AACtC;AAAA,IACF;AACA,QAAI,cAAc,CAAC,GAAG,QAAQ;AAC9B,UAAM,cAAc,SAAS,SAAS,SAAS,CAAC;AAEhD,QAAI,YAAY,SAAS,aAAa;AACpC,oBAAc,YAAY,MAAM,GAAG,EAAE;AAAA,IACvC;AACA,gBAAY,WAAW;AAEvB,WAAO,uCAAuC,WAAW;AAAA,EAC3D;AAEA,QAAM,OAAO,MAAY;AA5Q3B;AA6QI,6BAAmB,YAAnB,mBAA4B;AAAA,EAC9B;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":["messages"]}
@@ -1,6 +1,5 @@
1
1
  import {
2
2
  __async,
3
- __spreadProps,
4
3
  __spreadValues
5
4
  } from "./chunk-MRXNTQOX.mjs";
6
5
 
@@ -22,7 +21,6 @@ function fetchChatCompletion(_0) {
22
21
  body,
23
22
  signal
24
23
  }) {
25
- var _a, _b;
26
24
  temperature || (temperature = 0.5);
27
25
  tools || (tools = []);
28
26
  const cleanedMessages = messages.map((message) => {
@@ -38,32 +36,47 @@ function fetchChatCompletion(_0) {
38
36
  model,
39
37
  messages: cleanedMessages,
40
38
  stream: true
41
- }, tools.length ? { tools } : {}), temperature ? { temperature } : {}), tools.length != 0 ? { tool_choice: "auto" } : {}), copilotConfig.body), copilotConfig.backendOnlyProps), Object.keys((_a = copilotConfig["body"]) != null ? _a : {}).length > 0 ? { [EXCLUDE_FROM_FORWARD_PROPS_KEYS]: Object.keys((_b = copilotConfig["body"]) != null ? _b : {}) } : {}), body ? __spreadValues({}, body) : {})),
39
+ }, tools.length ? { tools } : {}), temperature ? { temperature } : {}), tools.length != 0 ? { tool_choice: "auto" } : {}), copilotConfig.body), copilotConfig.backendOnlyProps), excludeBackendOnlyProps(copilotConfig)), body ? __spreadValues({}, body) : {})),
42
40
  signal
43
41
  });
44
42
  return response;
45
43
  });
46
44
  }
45
+ function excludeBackendOnlyProps(copilotConfig) {
46
+ var _a;
47
+ const backendOnlyProps = (_a = copilotConfig.backendOnlyProps) != null ? _a : {};
48
+ if (Object.keys(backendOnlyProps).length > 0) {
49
+ return {
50
+ [EXCLUDE_FROM_FORWARD_PROPS_KEYS]: Object.keys(backendOnlyProps)
51
+ };
52
+ } else {
53
+ return {};
54
+ }
55
+ }
47
56
  function fetchAndDecodeChatCompletion(params) {
48
57
  return __async(this, null, function* () {
49
58
  const response = yield fetchChatCompletion(params);
50
59
  if (!response.ok || !response.body) {
51
- return __spreadProps(__spreadValues({}, response), { events: null });
60
+ response.events = null;
61
+ } else {
62
+ const events = yield decodeChatCompletion(parseChatCompletion(response.body));
63
+ response.events = events;
52
64
  }
53
- const events = yield decodeChatCompletion(parseChatCompletion(response.body));
54
- return __spreadProps(__spreadValues({}, response), { events });
65
+ return response;
55
66
  });
56
67
  }
57
68
  function fetchAndDecodeChatCompletionAsText(params) {
58
69
  return __async(this, null, function* () {
59
70
  const response = yield fetchChatCompletion(params);
60
71
  if (!response.ok || !response.body) {
61
- return __spreadProps(__spreadValues({}, response), { events: null });
72
+ response.events = null;
73
+ } else {
74
+ const events = yield decodeChatCompletionAsText(
75
+ decodeChatCompletion(parseChatCompletion(response.body))
76
+ );
77
+ response.events = events;
62
78
  }
63
- const events = yield decodeChatCompletionAsText(
64
- decodeChatCompletion(parseChatCompletion(response.body))
65
- );
66
- return __spreadProps(__spreadValues({}, response), { events });
79
+ return response;
67
80
  });
68
81
  }
69
82
 
@@ -72,4 +85,4 @@ export {
72
85
  fetchAndDecodeChatCompletion,
73
86
  fetchAndDecodeChatCompletionAsText
74
87
  };
75
- //# sourceMappingURL=chunk-BQ5SSV4Z.mjs.map
88
+ //# sourceMappingURL=chunk-3WKJ25L3.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils/fetch-chat-completion.ts"],"sourcesContent":["import {\n Message,\n ToolDefinition,\n ChatCompletionEvent,\n decodeChatCompletion,\n parseChatCompletion,\n decodeChatCompletionAsText,\n EXCLUDE_FROM_FORWARD_PROPS_KEYS,\n} from \"@copilotkit/shared\";\nimport { CopilotApiConfig } from \"../context\";\n\nexport interface FetchChatCompletionParams {\n copilotConfig: CopilotApiConfig;\n model?: string;\n messages: Message[];\n tools?: ToolDefinition[];\n temperature?: number;\n maxTokens?: number;\n headers?: Record<string, string> | Headers;\n body?: object;\n signal?: AbortSignal;\n}\n\nexport async function fetchChatCompletion({\n copilotConfig,\n model,\n messages,\n tools,\n temperature,\n headers,\n body,\n signal,\n}: FetchChatCompletionParams): Promise<Response> {\n temperature ||= 0.5;\n tools ||= [];\n\n // clean up any extra properties from messages\n const cleanedMessages = messages.map((message) => {\n const { content, role, name, function_call } = message;\n return { content, role, name, function_call };\n });\n\n const response = await fetch(copilotConfig.chatApiEndpoint, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n ...copilotConfig.headers,\n ...(headers ? { ...headers } : {}),\n },\n body: JSON.stringify({\n model,\n messages: cleanedMessages,\n stream: true,\n ...(tools.length ? { tools } : {}),\n ...(temperature ? { temperature } : {}),\n ...(tools.length != 0 ? { tool_choice: \"auto\" } : {}),\n ...copilotConfig.body,\n ...copilotConfig.backendOnlyProps,\n ...excludeBackendOnlyProps(copilotConfig),\n ...(body ? { ...body } : {}),\n }),\n signal,\n });\n\n return response;\n}\n\nfunction excludeBackendOnlyProps(copilotConfig: any) {\n const backendOnlyProps = copilotConfig.backendOnlyProps ?? {};\n if (Object.keys(backendOnlyProps).length > 0) {\n return {\n [EXCLUDE_FROM_FORWARD_PROPS_KEYS]: Object.keys(backendOnlyProps),\n };\n } else {\n return {};\n }\n}\n\nexport interface DecodedChatCompletionResponse extends Response {\n events: ReadableStream<ChatCompletionEvent> | null;\n}\n\nexport async function fetchAndDecodeChatCompletion(\n params: FetchChatCompletionParams,\n): Promise<DecodedChatCompletionResponse> {\n const response = await fetchChatCompletion(params);\n if (!response.ok || !response.body) {\n (response as any).events = null;\n } else {\n const events = await decodeChatCompletion(parseChatCompletion(response.body));\n (response as any).events = events;\n }\n return response as any;\n}\n\nexport interface DecodedChatCompletionResponseAsText extends Response {\n events: ReadableStream<string> | null;\n}\n\nexport async function fetchAndDecodeChatCompletionAsText(\n params: FetchChatCompletionParams,\n): Promise<DecodedChatCompletionResponseAsText> {\n const response = await fetchChatCompletion(params);\n if (!response.ok || !response.body) {\n (response as any).events = null;\n } else {\n const events = await decodeChatCompletionAsText(\n decodeChatCompletion(parseChatCompletion(response.body)),\n );\n (response as any).events = events;\n }\n\n return response as any;\n}\n"],"mappings":";;;;;;AAAA;AAAA,EAIE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAeP,SAAsB,oBAAoB,IASO;AAAA,6CATP;AAAA,IACxC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAAiD;AAC/C,kCAAgB;AAChB,sBAAU,CAAC;AAGX,UAAM,kBAAkB,SAAS,IAAI,CAAC,YAAY;AAChD,YAAM,EAAE,SAAS,MAAM,MAAM,cAAc,IAAI;AAC/C,aAAO,EAAE,SAAS,MAAM,MAAM,cAAc;AAAA,IAC9C,CAAC;AAED,UAAM,WAAW,MAAM,MAAM,cAAc,iBAAiB;AAAA,MAC1D,QAAQ;AAAA,MACR,SAAS;AAAA,QACP,gBAAgB;AAAA,SACb,cAAc,UACb,UAAU,mBAAK,WAAY,CAAC;AAAA,MAElC,MAAM,KAAK,UAAU;AAAA,QACnB;AAAA,QACA,UAAU;AAAA,QACV,QAAQ;AAAA,SACJ,MAAM,SAAS,EAAE,MAAM,I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s";
6
+ } from "./chunk-3WKJ25L3.mjs";
7
7
  import {
8
8
  __async
9
9
  } from "./chunk-MRXNTQOX.mjs";
@@ -99,4 +99,4 @@ ${instructions}
99
99
  export {
100
100
  CopilotTask
101
101
  };
102
- //# sourceMappingURL=chunk-EACH5HZU.mjs.map
102
+ //# sourceMappingURL=chunk-KLGA2MES.mjs.map
@@ -6,7 +6,7 @@ import {
6
6
  } from "./chunk-S7ZVOTYK.mjs";
7
7
  import {
8
8
  useChat
9
- } from "./chunk-JFUS5YVO.mjs";
9
+ } from "./chunk-2YF2MC22.mjs";
10
10
  import {
11
11
  __objRest,
12
12
  __spreadProps,
@@ -91,4 +91,4 @@ export {
91
91
  useCopilotChat,
92
92
  defaultSystemMessage
93
93
  };
94
- //# sourceMappingURL=chunk-3TF6G3W5.mjs.map
94
+ //# sourceMappingURL=chunk-UHTJLRI6.mjs.map
@@ -147,7 +147,6 @@ function fetchChatCompletion(_0) {
147
147
  body,
148
148
  signal
149
149
  }) {
150
- var _a, _b;
151
150
  temperature || (temperature = 0.5);
152
151
  tools || (tools = []);
153
152
  const cleanedMessages = messages.map((message) => {
@@ -163,20 +162,33 @@ function fetchChatCompletion(_0) {
163
162
  model,
164
163
  messages: cleanedMessages,
165
164
  stream: true
166
- }, tools.length ? { tools } : {}), temperature ? { temperature } : {}), tools.length != 0 ? { tool_choice: "auto" } : {}), copilotConfig.body), copilotConfig.backendOnlyProps), Object.keys((_a = copilotConfig["body"]) != null ? _a : {}).length > 0 ? { [import_shared.EXCLUDE_FROM_FORWARD_PROPS_KEYS]: Object.keys((_b = copilotConfig["body"]) != null ? _b : {}) } : {}), body ? __spreadValues({}, body) : {})),
165
+ }, tools.length ? { tools } : {}), temperature ? { temperature } : {}), tools.length != 0 ? { tool_choice: "auto" } : {}), copilotConfig.body), copilotConfig.backendOnlyProps), excludeBackendOnlyProps(copilotConfig)), body ? __spreadValues({}, body) : {})),
167
166
  signal
168
167
  });
169
168
  return response;
170
169
  });
171
170
  }
171
+ function excludeBackendOnlyProps(copilotConfig) {
172
+ var _a;
173
+ const backendOnlyProps = (_a = copilotConfig.backendOnlyProps) != null ? _a : {};
174
+ if (Object.keys(backendOnlyProps).length > 0) {
175
+ return {
176
+ [import_shared.EXCLUDE_FROM_FORWARD_PROPS_KEYS]: Object.keys(backendOnlyProps)
177
+ };
178
+ } else {
179
+ return {};
180
+ }
181
+ }
172
182
  function fetchAndDecodeChatCompletion(params) {
173
183
  return __async(this, null, function* () {
174
184
  const response = yield fetchChatCompletion(params);
175
185
  if (!response.ok || !response.body) {
176
- return __spreadProps(__spreadValues({}, response), { events: null });
186
+ response.events = null;
187
+ } else {
188
+ const events = yield (0, import_shared.decodeChatCompletion)((0, import_shared.parseChatCompletion)(response.body));
189
+ response.events = events;
177
190
  }
178
- const events = yield (0, import_shared.decodeChatCompletion)((0, import_shared.parseChatCompletion)(response.body));
179
- return __spreadProps(__spreadValues({}, response), { events });
191
+ return response;
180
192
  });
181
193
  }
182
194
 
@@ -186,6 +198,8 @@ function useChat(options) {
186
198
  const [input, setInput] = (0, import_react2.useState)("");
187
199
  const [isLoading, setIsLoading] = (0, import_react2.useState)(false);
188
200
  const abortControllerRef = (0, import_react2.useRef)();
201
+ const threadIdRef = (0, import_react2.useRef)(null);
202
+ const runIdRef = (0, import_react2.useRef)(null);
189
203
  const runChatCompletion = (messages2) => __async(this, null, function* () {
190
204
  setIsLoading(true);
191
205
  const newMessages = [
@@ -199,14 +213,27 @@ function useChat(options) {
199
213
  const abortController = new AbortController();
200
214
  abortControllerRef.current = abortController;
201
215
  setMessages([...messages2, ...newMessages]);
216
+ const copilotConfigBody = options.copilotConfig.body || {};
217
+ if (threadIdRef.current) {
218
+ copilotConfigBody.threadId = threadIdRef.current;
219
+ }
220
+ if (runIdRef.current) {
221
+ copilotConfigBody.runId = runIdRef.current;
222
+ }
202
223
  const messagesWithContext = [...options.initialMessages || [], ...messages2];
203
224
  const response = yield fetchAndDecodeChatCompletion({
204
- copilotConfig: options.copilotConfig,
225
+ copilotConfig: __spreadProps(__spreadValues({}, options.copilotConfig), { body: copilotConfigBody }),
205
226
  messages: messagesWithContext,
206
227
  tools: options.tools,
207
228
  headers: options.headers,
208
229
  signal: abortController.signal
209
230
  });
231
+ if (response.headers.get("threadid")) {
232
+ threadIdRef.current = response.headers.get("threadid");
233
+ }
234
+ if (response.headers.get("runid")) {
235
+ runIdRef.current = response.headers.get("runid");
236
+ }
210
237
  if (!response.events) {
211
238
  throw new Error("Failed to fetch chat completion");
212
239
  }