@copilotkit/react-core 0.17.0 → 0.17.1-alpha.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.
@@ -1,14 +1,14 @@
1
1
 
2
- > @copilotkit/react-core@0.17.0 build /home/runner/work/CopilotKit/CopilotKit/CopilotKit/packages/react-core
2
+ > @copilotkit/react-core@0.17.0 build /Users/ataibarkai/LocalGit/Recursively.ai/CopilotKit/CopilotKit/packages/react-core
3
3
  > tsup --treeshake
4
4
 
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/openai/chat-completion-client.ts, src/openai/chat-completion-stream.ts, src/openai/chat-completion-transport.ts, src/openai/index.tsx, src/openai-assistants/index.ts, src/types/annotated-function.ts, src/types/base.ts, src/types/document-pointer.ts, src/types/index.ts, src/types/message.ts, src/utils/utils.test.ts, src/utils/utils.ts, src/components/copilot-provider/copilot-provider-props.tsx, src/components/copilot-provider/copilot-provider.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
6
- CLI Using tsconfig: tsconfig.json
7
- CLI tsup v6.7.0
8
- CLI Using tsup config: /home/runner/work/CopilotKit/CopilotKit/CopilotKit/packages/react-core/tsup.config.ts
9
- CLI Target: es6
10
- CLI Cleaning output folder
11
- ESM Build start
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/openai-assistants/index.ts, src/openai/chat-completion-client.ts, src/openai/chat-completion-stream.ts, src/openai/chat-completion-transport.ts, src/openai/index.tsx, src/types/annotated-function.ts, src/types/base.ts, src/types/document-pointer.ts, src/types/index.ts, src/types/message.ts, src/utils/utils.test.ts, src/utils/utils.ts, src/components/copilot-provider/copilot-provider-props.tsx, src/components/copilot-provider/copilot-provider.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
6
+ CLI Using tsconfig: tsconfig.json
7
+ CLI tsup v6.7.0
8
+ CLI Using tsup config: /Users/ataibarkai/LocalGit/Recursively.ai/CopilotKit/CopilotKit/packages/react-core/tsup.config.ts
9
+ CLI Target: es6
10
+ CLI Cleaning output folder
11
+ ESM Build start
12
12
  Module level directives cause errors when bundled, "use client" in "dist/components/copilot-provider/copilot-provider-props.mjs" was ignored.
13
13
  Module level directives cause errors when bundled, "use client" in "dist/components/copilot-provider/copilot-provider.mjs" was ignored.
14
14
  Module level directives cause errors when bundled, "use client" in "dist/openai-assistants/hooks/use-assistants.mjs" was ignored.
@@ -22,164 +22,164 @@ Generated an empty chunk: "base".
22
22
  Generated an empty chunk: "document-pointer".
23
23
  Generated an empty chunk: "message".
24
24
  Generated an empty chunk: "utils".
25
+ Generated an empty chunk: "chunk-PUFR5OAI".
26
+ Generated an empty chunk: "chunk-EFZPSZWO".
25
27
  Generated an empty chunk: "chunk-7GFKOIO7".
26
28
  Generated an empty chunk: "chunk-BABVSMJR".
27
29
  Generated an empty chunk: "chunk-FRAKUJWH".
28
- Generated an empty chunk: "chunk-EFZPSZWO".
29
- Generated an empty chunk: "chunk-PUFR5OAI".
30
30
  Generated an empty chunk: "chunk-VNRDQJXW".
31
31
  Generated an empty chunk: "chunk-5UGLWBZJ".
32
32
  Generated an empty chunk: "chunk-JD7BAH7U".
33
33
  Generated an empty chunk: "chunk-SPCZTZCY".
34
- DTS Build start
35
- ESM dist/chunk-7GFKOIO7.mjs 76.00 B
36
- ESM dist/openai-assistants/index.mjs 570.00 B
37
- ESM dist/types/index.mjs 98.00 B
38
- ESM dist/hooks/use-make-copilot-actionable.mjs 218.00 B
39
- ESM dist/openai/chat-completion-client.mjs 209.00 B
40
- ESM dist/components/index.mjs 380.00 B
41
- ESM dist/context/copilot-context.mjs 164.00 B
42
- ESM dist/chunk-BABVSMJR.mjs 76.00 B
43
- ESM dist/chunk-FRAKUJWH.mjs 76.00 B
44
- ESM dist/chunk-EFZPSZWO.mjs 76.00 B
45
- ESM dist/chunk-PUFR5OAI.mjs 76.00 B
46
- ESM dist/chunk-VNRDQJXW.mjs 76.00 B
47
- ESM dist/chunk-5UGLWBZJ.mjs 76.00 B
48
- ESM dist/chunk-JD7BAH7U.mjs 76.00 B
49
- ESM dist/chunk-SPCZTZCY.mjs 76.00 B
50
- ESM dist/chunk-F2JIAPZQ.mjs 435.00 B
51
- ESM dist/chunk-MRXNTQOX.mjs 1.92 KB
52
- ESM dist/hooks/use-make-copilot-document-readable.mjs 231.00 B
53
- ESM dist/hooks/use-make-copilot-readable.mjs 214.00 B
54
- ESM dist/hooks/use-tree.mjs 170.00 B
55
- ESM dist/openai/chat-completion-stream.mjs 209.00 B
56
- ESM dist/openai/chat-completion-transport.mjs 183.00 B
57
- ESM dist/openai/index.mjs 224.00 B
58
- ESM dist/index.mjs 1.11 KB
59
- ESM dist/chunk-TU4DNDO7.mjs 4.33 KB
60
- ESM dist/chunk-MZ5UN3BY.mjs 830.00 B
61
- ESM dist/chunk-6SOQYBNX.mjs 1.24 KB
62
- ESM dist/context/index.mjs 186.00 B
63
- ESM dist/hooks/index.mjs 708.00 B
64
- ESM dist/chunk-FP4EXCGS.mjs 954.00 B
65
- ESM dist/chunk-7P4OYNP3.mjs 677.00 B
66
- ESM dist/chunk-HW5IH6PV.mjs 626.00 B
67
- ESM dist/hooks/use-chat.mjs 214.00 B
68
- ESM dist/hooks/use-copilot-chat.mjs 507.00 B
69
- ESM dist/chunk-XSS45JC5.mjs 2.71 KB
70
- ESM dist/chunk-QTET3FBV.mjs 5.18 KB
71
- ESM dist/chunk-VUY2K2DI.mjs 3.89 KB
72
- ESM dist/chunk-6A4PCNMZ.mjs 1.30 KB
73
- ESM dist/chunk-WMXA2TIX.mjs 3.25 KB
74
- ESM dist/chunk-TKXPMMND.mjs 5.33 KB
75
- ESM dist/chunk-VK25FIML.mjs 4.48 KB
76
- ESM dist/hooks/use-flat-category-store.mjs 200.00 B
77
- ESM dist/chunk-YULKJPY3.mjs 1.87 KB
78
- ESM dist/components/copilot-provider/copilot-provider-props.mjs 84.00 B
79
- ESM dist/utils/utils.test.mjs 202.00 B
80
- ESM dist/openai-assistants/utils/process-message-stream.mjs 183.00 B
81
- ESM dist/openai-assistants/hooks/index.mjs 547.00 B
82
- ESM dist/types/annotated-function.mjs 80.00 B
83
- ESM dist/types/base.mjs 66.00 B
84
- ESM dist/types/document-pointer.mjs 78.00 B
85
- ESM dist/types/message.mjs 69.00 B
86
- ESM dist/utils/utils.mjs 67.00 B
87
- ESM dist/components/copilot-provider/copilot-provider.mjs 345.00 B
88
- ESM dist/components/copilot-provider/index.mjs 369.00 B
89
- ESM dist/components/copilot-provider/standard-copilot-api-config.mjs 192.00 B
90
- ESM dist/openai-assistants/hooks/use-assistants.mjs 2.55 KB
91
- ESM dist/openai-assistants/hooks/use-copilot-chat-v2.mjs 548.00 B
92
- ESM dist/openai-assistants/utils/index.mjs 201.00 B
93
- ESM dist/chunk-7GFKOIO7.mjs.map 51.00 B
94
- ESM dist/openai-assistants/index.mjs.map 51.00 B
95
- ESM dist/types/index.mjs.map 51.00 B
96
- ESM dist/hooks/use-make-copilot-actionable.mjs.map 51.00 B
97
- ESM dist/openai/chat-completion-client.mjs.map 51.00 B
98
- ESM dist/components/index.mjs.map 51.00 B
99
- ESM dist/context/copilot-context.mjs.map 51.00 B
100
- ESM dist/chunk-BABVSMJR.mjs.map 51.00 B
101
- ESM dist/chunk-FRAKUJWH.mjs.map 51.00 B
102
- ESM dist/chunk-EFZPSZWO.mjs.map 51.00 B
103
- ESM dist/chunk-PUFR5OAI.mjs.map 51.00 B
104
- ESM dist/chunk-VNRDQJXW.mjs.map 51.00 B
105
- ESM dist/chunk-5UGLWBZJ.mjs.map 51.00 B
106
- ESM dist/chunk-JD7BAH7U.mjs.map 51.00 B
107
- ESM dist/chunk-SPCZTZCY.mjs.map 51.00 B
108
- ESM dist/chunk-F2JIAPZQ.mjs.map 1.12 KB
109
- ESM dist/chunk-MRXNTQOX.mjs.map 71.00 B
110
- ESM dist/hooks/use-make-copilot-document-readable.mjs.map 51.00 B
111
- ESM dist/hooks/use-make-copilot-readable.mjs.map 51.00 B
112
- ESM dist/hooks/use-tree.mjs.map 51.00 B
113
- ESM dist/openai/chat-completion-stream.mjs.map 51.00 B
114
- ESM dist/openai/chat-completion-transport.mjs.map 51.00 B
115
- ESM dist/openai/index.mjs.map 51.00 B
116
- ESM dist/index.mjs.map 51.00 B
117
- ESM dist/chunk-TU4DNDO7.mjs.map 7.90 KB
118
- ESM dist/chunk-MZ5UN3BY.mjs.map 1.26 KB
119
- ESM dist/chunk-6SOQYBNX.mjs.map 2.07 KB
120
- ESM dist/context/index.mjs.map 51.00 B
121
- ESM dist/hooks/index.mjs.map 51.00 B
122
- ESM dist/chunk-FP4EXCGS.mjs.map 1.67 KB
123
- ESM dist/chunk-7P4OYNP3.mjs.map 1.42 KB
124
- ESM dist/chunk-HW5IH6PV.mjs.map 1.47 KB
125
- ESM dist/hooks/use-chat.mjs.map 51.00 B
126
- ESM dist/hooks/use-copilot-chat.mjs.map 51.00 B
127
- ESM dist/chunk-XSS45JC5.mjs.map 4.37 KB
128
- ESM dist/chunk-QTET3FBV.mjs.map 11.03 KB
129
- ESM dist/chunk-VUY2K2DI.mjs.map 8.27 KB
130
- ESM dist/chunk-6A4PCNMZ.mjs.map 4.26 KB
131
- ESM dist/chunk-WMXA2TIX.mjs.map 7.79 KB
132
- ESM dist/chunk-TKXPMMND.mjs.map 9.93 KB
133
- ESM dist/chunk-VK25FIML.mjs.map 7.84 KB
134
- ESM dist/hooks/use-flat-category-store.mjs.map 51.00 B
135
- ESM dist/chunk-YULKJPY3.mjs.map 4.21 KB
136
- ESM dist/components/copilot-provider/copilot-provider-props.mjs.map 51.00 B
137
- ESM dist/utils/utils.test.mjs.map 351.00 B
138
- ESM dist/openai-assistants/utils/process-message-stream.mjs.map 51.00 B
139
- ESM dist/openai-assistants/hooks/index.mjs.map 51.00 B
140
- ESM dist/types/annotated-function.mjs.map 51.00 B
141
- ESM dist/types/base.mjs.map 51.00 B
142
- ESM dist/types/document-pointer.mjs.map 51.00 B
143
- ESM dist/types/message.mjs.map 51.00 B
144
- ESM dist/utils/utils.mjs.map 51.00 B
145
- ESM dist/components/copilot-provider/copilot-provider.mjs.map 51.00 B
146
- ESM dist/components/copilot-provider/index.mjs.map 51.00 B
147
- ESM dist/components/copilot-provider/standard-copilot-api-config.mjs.map 51.00 B
148
- ESM dist/openai-assistants/hooks/use-assistants.mjs.map 4.67 KB
149
- ESM dist/openai-assistants/hooks/use-copilot-chat-v2.mjs.map 51.00 B
150
- ESM dist/openai-assistants/utils/index.mjs.map 51.00 B
151
- ESM ⚡️ Build success in 489ms
152
- DTS ⚡️ Build success in 4844ms
153
- DTS dist/index.d.ts 1.61 KB
154
- DTS dist/components/copilot-provider/copilot-provider.d.ts 1.55 KB
155
- DTS dist/components/copilot-provider/copilot-provider-props.d.ts 1.52 KB
156
- DTS dist/context/copilot-context.d.ts 1.98 KB
157
- DTS dist/hooks/use-copilot-chat.d.ts 955.00 B
158
- DTS dist/hooks/use-make-copilot-actionable.d.ts 255.00 B
159
- DTS dist/hooks/use-make-copilot-readable.d.ts 598.00 B
160
- DTS dist/hooks/use-make-copilot-document-readable.d.ts 516.00 B
161
- DTS dist/hooks/use-chat.d.ts 2.75 KB
162
- DTS dist/types/annotated-function.d.ts 767.00 B
163
- DTS dist/types/document-pointer.d.ts 181.00 B
164
- DTS dist/types/base.d.ts 1.96 KB
165
- DTS dist/openai-assistants/hooks/use-copilot-chat-v2.d.ts 1.41 KB
166
- DTS dist/openai-assistants/utils/process-message-stream.d.ts 196.00 B
167
- DTS dist/openai/chat-completion-stream.d.ts 694.00 B
168
- DTS dist/openai/chat-completion-transport.d.ts 1.26 KB
169
- DTS dist/hooks/use-tree.d.ts 543.00 B
170
- DTS dist/components/index.d.ts 482.00 B
171
- DTS dist/context/index.d.ts 281.00 B
172
- DTS dist/hooks/index.d.ts 608.00 B
173
- DTS dist/hooks/use-flat-category-store.d.ts 424.00 B
174
- DTS dist/openai/chat-completion-client.d.ts 1.44 KB
175
- DTS dist/openai/index.d.ts 438.00 B
176
- DTS dist/openai-assistants/index.d.ts 262.00 B
177
- DTS dist/types/index.d.ts 233.00 B
178
- DTS dist/types/message.d.ts 12.00 B
179
- DTS dist/utils/utils.test.d.ts 12.00 B
180
- DTS dist/utils/utils.d.ts 12.00 B
181
- DTS dist/components/copilot-provider/index.d.ts 463.00 B
182
- DTS dist/components/copilot-provider/standard-copilot-api-config.d.ts 911.00 B
183
- DTS dist/openai-assistants/hooks/index.d.ts 182.00 B
184
- DTS dist/openai-assistants/hooks/use-assistants.d.ts 551.00 B
185
- DTS dist/openai-assistants/utils/index.d.ts 68.00 B
34
+ ESM dist/chunk-PUFR5OAI.mjs 76.00 B
35
+ ESM dist/types/index.mjs 98.00 B
36
+ ESM dist/openai/index.mjs 224.00 B
37
+ ESM dist/hooks/use-make-copilot-actionable.mjs 218.00 B
38
+ ESM dist/context/copilot-context.mjs 164.00 B
39
+ ESM dist/chunk-BABVSMJR.mjs 76.00 B
40
+ ESM dist/components/index.mjs 380.00 B
41
+ ESM dist/chunk-JD7BAH7U.mjs 76.00 B
42
+ ESM dist/chunk-SPCZTZCY.mjs 76.00 B
43
+ ESM dist/chunk-VNRDQJXW.mjs 76.00 B
44
+ ESM dist/chunk-7GFKOIO7.mjs 76.00 B
45
+ ESM dist/openai-assistants/index.mjs 570.00 B
46
+ ESM dist/chunk-MRXNTQOX.mjs 1.92 KB
47
+ ESM dist/chunk-EFZPSZWO.mjs 76.00 B
48
+ ESM dist/chunk-5UGLWBZJ.mjs 76.00 B
49
+ ESM dist/hooks/use-make-copilot-document-readable.mjs 231.00 B
50
+ ESM dist/openai/chat-completion-stream.mjs 209.00 B
51
+ ESM dist/openai/chat-completion-client.mjs 209.00 B
52
+ ESM dist/hooks/use-make-copilot-readable.mjs 214.00 B
53
+ ESM dist/openai/chat-completion-transport.mjs 183.00 B
54
+ ESM dist/index.mjs 1.11 KB
55
+ ESM dist/chunk-F2JIAPZQ.mjs 435.00 B
56
+ ESM dist/chunk-TU4DNDO7.mjs 4.33 KB
57
+ ESM dist/chunk-MZ5UN3BY.mjs 830.00 B
58
+ ESM dist/hooks/index.mjs 708.00 B
59
+ ESM dist/hooks/use-tree.mjs 170.00 B
60
+ ESM dist/chunk-FP4EXCGS.mjs 954.00 B
61
+ ESM dist/hooks/use-chat.mjs 214.00 B
62
+ ESM dist/chunk-HW5IH6PV.mjs 626.00 B
63
+ ESM dist/chunk-R75NEA76.mjs 2.71 KB
64
+ ESM dist/hooks/use-copilot-chat.mjs 507.00 B
65
+ ESM dist/chunk-6A4PCNMZ.mjs 1.30 KB
66
+ ESM dist/chunk-VUY2K2DI.mjs 3.89 KB
67
+ ESM dist/chunk-QTET3FBV.mjs 5.18 KB
68
+ ESM dist/chunk-TKXPMMND.mjs 5.33 KB
69
+ ESM dist/chunk-VK25FIML.mjs 4.48 KB
70
+ ESM dist/chunk-6SOQYBNX.mjs 1.24 KB
71
+ ESM dist/chunk-FRAKUJWH.mjs 76.00 B
72
+ ESM dist/chunk-7P4OYNP3.mjs 677.00 B
73
+ ESM dist/context/index.mjs 186.00 B
74
+ ESM dist/hooks/use-flat-category-store.mjs 200.00 B
75
+ ESM dist/chunk-YULKJPY3.mjs 1.87 KB
76
+ ESM dist/components/copilot-provider/copilot-provider-props.mjs 84.00 B
77
+ ESM dist/utils/utils.mjs 67.00 B
78
+ ESM dist/openai-assistants/utils/process-message-stream.mjs 183.00 B
79
+ ESM dist/chunk-R2WOR4SW.mjs 3.69 KB
80
+ ESM dist/openai-assistants/hooks/use-assistants.mjs 2.55 KB
81
+ ESM dist/types/annotated-function.mjs 80.00 B
82
+ ESM dist/types/base.mjs 66.00 B
83
+ ESM dist/utils/utils.test.mjs 202.00 B
84
+ ESM dist/components/copilot-provider/copilot-provider.mjs 345.00 B
85
+ ESM dist/openai-assistants/utils/index.mjs 201.00 B
86
+ ESM dist/types/document-pointer.mjs 78.00 B
87
+ ESM dist/components/copilot-provider/standard-copilot-api-config.mjs 192.00 B
88
+ ESM dist/types/message.mjs 69.00 B
89
+ ESM dist/openai-assistants/hooks/index.mjs 547.00 B
90
+ ESM dist/openai-assistants/hooks/use-copilot-chat-v2.mjs 548.00 B
91
+ ESM dist/components/copilot-provider/index.mjs 369.00 B
92
+ ESM dist/chunk-PUFR5OAI.mjs.map 51.00 B
93
+ ESM dist/types/index.mjs.map 51.00 B
94
+ ESM dist/openai/index.mjs.map 51.00 B
95
+ ESM dist/hooks/use-make-copilot-actionable.mjs.map 51.00 B
96
+ ESM dist/chunk-BABVSMJR.mjs.map 51.00 B
97
+ ESM dist/chunk-7GFKOIO7.mjs.map 51.00 B
98
+ ESM dist/chunk-VNRDQJXW.mjs.map 51.00 B
99
+ ESM dist/components/index.mjs.map 51.00 B
100
+ ESM dist/openai-assistants/index.mjs.map 51.00 B
101
+ ESM dist/chunk-MRXNTQOX.mjs.map 71.00 B
102
+ ESM dist/chunk-JD7BAH7U.mjs.map 51.00 B
103
+ ESM dist/chunk-EFZPSZWO.mjs.map 51.00 B
104
+ ESM dist/hooks/use-make-copilot-document-readable.mjs.map 51.00 B
105
+ ESM dist/index.mjs.map 51.00 B
106
+ ESM dist/openai/chat-completion-stream.mjs.map 51.00 B
107
+ ESM dist/context/copilot-context.mjs.map 51.00 B
108
+ ESM dist/chunk-SPCZTZCY.mjs.map 51.00 B
109
+ ESM dist/chunk-5UGLWBZJ.mjs.map 51.00 B
110
+ ESM dist/hooks/use-tree.mjs.map 51.00 B
111
+ ESM dist/chunk-MZ5UN3BY.mjs.map 1.26 KB
112
+ ESM dist/chunk-TU4DNDO7.mjs.map 7.90 KB
113
+ ESM dist/hooks/index.mjs.map 51.00 B
114
+ ESM dist/openai/chat-completion-client.mjs.map 51.00 B
115
+ ESM dist/hooks/use-make-copilot-readable.mjs.map 51.00 B
116
+ ESM dist/hooks/use-chat.mjs.map 51.00 B
117
+ ESM dist/chunk-FP4EXCGS.mjs.map 1.67 KB
118
+ ESM dist/hooks/use-copilot-chat.mjs.map 51.00 B
119
+ ESM dist/chunk-HW5IH6PV.mjs.map 1.47 KB
120
+ ESM dist/openai/chat-completion-transport.mjs.map 51.00 B
121
+ ESM dist/chunk-6A4PCNMZ.mjs.map 4.26 KB
122
+ ESM dist/chunk-F2JIAPZQ.mjs.map 1.12 KB
123
+ ESM dist/chunk-TKXPMMND.mjs.map 9.93 KB
124
+ ESM dist/chunk-7P4OYNP3.mjs.map 1.42 KB
125
+ ESM dist/chunk-QTET3FBV.mjs.map 11.03 KB
126
+ ESM dist/chunk-6SOQYBNX.mjs.map 2.07 KB
127
+ ESM dist/chunk-FRAKUJWH.mjs.map 51.00 B
128
+ ESM dist/chunk-VK25FIML.mjs.map 7.84 KB
129
+ ESM dist/chunk-VUY2K2DI.mjs.map 8.27 KB
130
+ ESM dist/chunk-R75NEA76.mjs.map 4.37 KB
131
+ ESM dist/context/index.mjs.map 51.00 B
132
+ ESM dist/hooks/use-flat-category-store.mjs.map 51.00 B
133
+ ESM dist/chunk-YULKJPY3.mjs.map 4.21 KB
134
+ ESM dist/utils/utils.mjs.map 51.00 B
135
+ ESM dist/components/copilot-provider/copilot-provider-props.mjs.map 51.00 B
136
+ ESM dist/chunk-R2WOR4SW.mjs.map 8.47 KB
137
+ ESM dist/openai-assistants/utils/process-message-stream.mjs.map 51.00 B
138
+ ESM dist/openai-assistants/hooks/use-assistants.mjs.map 4.67 KB
139
+ ESM dist/types/base.mjs.map 51.00 B
140
+ ESM dist/openai-assistants/utils/index.mjs.map 51.00 B
141
+ ESM dist/types/annotated-function.mjs.map 51.00 B
142
+ ESM dist/openai-assistants/hooks/index.mjs.map 51.00 B
143
+ ESM dist/components/copilot-provider/standard-copilot-api-config.mjs.map 51.00 B
144
+ ESM dist/components/copilot-provider/copilot-provider.mjs.map 51.00 B
145
+ ESM dist/components/copilot-provider/index.mjs.map 51.00 B
146
+ ESM dist/types/document-pointer.mjs.map 51.00 B
147
+ ESM dist/types/message.mjs.map 51.00 B
148
+ ESM dist/openai-assistants/hooks/use-copilot-chat-v2.mjs.map 51.00 B
149
+ ESM dist/utils/utils.test.mjs.map 351.00 B
150
+ ESM ⚡️ Build success in 135ms
151
+ DTS Build start
152
+ DTS ⚡️ Build success in 2216ms
153
+ DTS dist/index.d.ts 1.61 KB
154
+ DTS dist/components/copilot-provider/copilot-provider.d.ts 1.55 KB
155
+ DTS dist/components/copilot-provider/copilot-provider-props.d.ts 1.52 KB
156
+ DTS dist/context/copilot-context.d.ts 1.98 KB
157
+ DTS dist/hooks/use-copilot-chat.d.ts 955.00 B
158
+ DTS dist/hooks/use-make-copilot-actionable.d.ts 255.00 B
159
+ DTS dist/hooks/use-make-copilot-readable.d.ts 598.00 B
160
+ DTS dist/hooks/use-make-copilot-document-readable.d.ts 516.00 B
161
+ DTS dist/hooks/use-chat.d.ts 2.75 KB
162
+ DTS dist/types/annotated-function.d.ts 767.00 B
163
+ DTS dist/types/document-pointer.d.ts 181.00 B
164
+ DTS dist/types/base.d.ts 1.96 KB
165
+ DTS dist/openai-assistants/hooks/use-copilot-chat-v2.d.ts 1.41 KB
166
+ DTS dist/openai-assistants/utils/process-message-stream.d.ts 196.00 B
167
+ DTS dist/openai/chat-completion-stream.d.ts 694.00 B
168
+ DTS dist/openai/chat-completion-transport.d.ts 1.26 KB
169
+ DTS dist/hooks/use-tree.d.ts 543.00 B
170
+ DTS dist/components/index.d.ts 482.00 B
171
+ DTS dist/context/index.d.ts 281.00 B
172
+ DTS dist/hooks/index.d.ts 608.00 B
173
+ DTS dist/hooks/use-flat-category-store.d.ts 424.00 B
174
+ DTS dist/openai-assistants/index.d.ts 262.00 B
175
+ DTS dist/openai/chat-completion-client.d.ts 1.44 KB
176
+ DTS dist/openai/index.d.ts 438.00 B
177
+ DTS dist/types/index.d.ts 233.00 B
178
+ DTS dist/types/message.d.ts 12.00 B
179
+ DTS dist/utils/utils.test.d.ts 12.00 B
180
+ DTS dist/utils/utils.d.ts 12.00 B
181
+ DTS dist/components/copilot-provider/index.d.ts 463.00 B
182
+ DTS dist/components/copilot-provider/standard-copilot-api-config.d.ts 911.00 B
183
+ DTS dist/openai-assistants/hooks/index.d.ts 182.00 B
184
+ DTS dist/openai-assistants/hooks/use-assistants.d.ts 551.00 B
185
+ DTS dist/openai-assistants/utils/index.d.ts 68.00 B
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # ui
2
2
 
3
+ ## 0.17.1-alpha.0
4
+
5
+ ### Patch Changes
6
+
7
+ - fix stop generate
8
+ - Updated dependencies
9
+ - @copilotkit/shared@0.1.1-alpha.0
10
+
3
11
  ## 0.17.0
4
12
 
5
13
  ### Minor Changes
@@ -1,15 +1,18 @@
1
1
  import { ChatCompletionClient } from './chunk-TKXPMMND.mjs';
2
2
  import { __async, __spreadValues } from './chunk-MRXNTQOX.mjs';
3
- import { useState } from 'react';
3
+ import { useState, useRef } from 'react';
4
4
  import { nanoid } from 'nanoid';
5
5
 
6
6
  function useChat(options) {
7
7
  const [messages, setMessages] = useState([]);
8
8
  const [input, setInput] = useState("");
9
9
  const [isLoading, setIsLoading] = useState(false);
10
+ const abortControllerRef = useRef();
10
11
  const runChatCompletion = (messages2) => __async(this, null, function* () {
11
12
  return new Promise((resolve, reject) => {
12
13
  setIsLoading(true);
14
+ const abortController = new AbortController();
15
+ abortControllerRef.current = abortController;
13
16
  const assistantMessage = {
14
17
  id: nanoid(),
15
18
  createdAt: /* @__PURE__ */ new Date(),
@@ -24,7 +27,13 @@ function useChat(options) {
24
27
  client.off("end");
25
28
  client.off("error");
26
29
  client.off("function");
30
+ abortControllerRef.current = void 0;
27
31
  };
32
+ abortController.signal.addEventListener("abort", () => {
33
+ cleanup();
34
+ setIsLoading(false);
35
+ reject(new DOMException("Aborted", "AbortError"));
36
+ });
28
37
  client.on("content", (content) => {
29
38
  assistantMessage.content += content;
30
39
  setMessages([...messages2, __spreadValues({}, assistantMessage)]);
@@ -53,7 +62,8 @@ function useChat(options) {
53
62
  copilotConfig: options.copilotConfig,
54
63
  messages: messagesWithContext,
55
64
  functions: options.functions,
56
- headers: options.headers
65
+ headers: options.headers,
66
+ signal: abortController.signal
57
67
  });
58
68
  });
59
69
  });
@@ -84,7 +94,8 @@ function useChat(options) {
84
94
  return runChatCompletionAndHandleFunctionCall(newMessages);
85
95
  });
86
96
  const stop = () => {
87
- throw new Error("Not implemented");
97
+ var _a;
98
+ (_a = abortControllerRef.current) == null ? void 0 : _a.abort();
88
99
  };
89
100
  return {
90
101
  messages,
@@ -99,4 +110,4 @@ function useChat(options) {
99
110
 
100
111
  export { useChat };
101
112
  //# sourceMappingURL=out.js.map
102
- //# sourceMappingURL=chunk-WMXA2TIX.mjs.map
113
+ //# sourceMappingURL=chunk-R2WOR4SW.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/hooks/use-chat.ts"],"names":["messages"],"mappings":";;;;;;;;;AAAA,SAAS,QAAQ,gBAAgB;AAEjC,SAAS,cAAc;AAgFhB,SAAS,QAAQ,SAA0D;AAChF,QAAM,CAAC,UAAU,WAAW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A;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF","sourcesContent":["import { useRef, useState } from \"react\";\nimport { Message, Function, FunctionCallHandler } from \"../types\";\nimport { nanoid } from \"nanoid\";\nimport { ChatCompletionClient } from \"../openai/chat-completion-client\";\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 functions?: Function[];\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\n const runChatCompletion = async (messages: Message[]): Promise<Message> => {\n return new Promise<Message>((resolve, reject) => {\n setIsLoading(true);\n\n const abortController = new AbortController();\n abortControllerRef.current = abortController;\n\n const assistantMessage: Message = {\n id: nanoid(),\n createdAt: new Date(),\n content: \"\",\n role: \"assistant\",\n };\n\n // Assistant messages are always copied when using setState\n setMessages([...messages, { ...assistantMessage }]);\n\n const messagesWithContext = [...(options.initialMessages || []), ...messages];\n\n const client = new ChatCompletionClient({});\n\n const cleanup = () => {\n client.off(\"content\");\n client.off(\"end\");\n client.off(\"error\");\n client.off(\"function\");\n\n abortControllerRef.current = undefined;\n };\n\n abortController.signal.addEventListener(\"abort\", () => {\n cleanup();\n setIsLoading(false);\n reject(new DOMException(\"Aborted\", \"AbortError\"));\n });\n\n client.on(\"content\", (content) => {\n assistantMessage.content += content;\n setMessages([...messages, { ...assistantMessage }]);\n });\n\n client.on(\"end\", () => {\n setIsLoading(false);\n cleanup();\n resolve({ ...assistantMessage });\n });\n\n client.on(\"error\", (error) => {\n setIsLoading(false);\n cleanup();\n reject(error);\n });\n\n client.on(\"function\", async (functionCall) => {\n assistantMessage.function_call = {\n name: functionCall.name,\n arguments: JSON.stringify(functionCall.arguments),\n };\n setMessages([...messages, { ...assistantMessage }]);\n // quit early if we get a function call\n setIsLoading(false);\n cleanup();\n resolve({ ...assistantMessage });\n });\n\n client.fetch({\n copilotConfig: options.copilotConfig,\n messages: messagesWithContext,\n functions: options.functions,\n headers: options.headers,\n signal: abortController.signal,\n });\n });\n };\n\n const runChatCompletionAndHandleFunctionCall = async (messages: Message[]): Promise<void> => {\n const message = await runChatCompletion(messages);\n if (message.function_call && options.onFunctionCall) {\n await options.onFunctionCall(messages, message.function_call);\n }\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"]}
@@ -1,6 +1,6 @@
1
1
  import { defaultCopilotContextCategories } from './chunk-QTET3FBV.mjs';
2
2
  import { CopilotContext } from './chunk-6A4PCNMZ.mjs';
3
- import { useChat } from './chunk-WMXA2TIX.mjs';
3
+ import { useChat } from './chunk-R2WOR4SW.mjs';
4
4
  import { __objRest, __spreadProps, __spreadValues } from './chunk-MRXNTQOX.mjs';
5
5
  import { useContext, useMemo } from 'react';
6
6
 
@@ -74,4 +74,4 @@ If you would like to call a function, call it without saying anything else.
74
74
 
75
75
  export { defaultSystemMessage, useCopilotChat };
76
76
  //# sourceMappingURL=out.js.map
77
- //# sourceMappingURL=chunk-XSS45JC5.mjs.map
77
+ //# sourceMappingURL=chunk-R75NEA76.mjs.map
@@ -2,14 +2,14 @@ import '../chunk-5UGLWBZJ.mjs';
2
2
  export { useMakeCopilotActionable } from '../chunk-FP4EXCGS.mjs';
3
3
  export { useMakeCopilotDocumentReadable } from '../chunk-7P4OYNP3.mjs';
4
4
  export { useMakeCopilotReadable } from '../chunk-HW5IH6PV.mjs';
5
- export { useCopilotChat } from '../chunk-XSS45JC5.mjs';
5
+ export { useCopilotChat } from '../chunk-R75NEA76.mjs';
6
6
  import '../chunk-JD7BAH7U.mjs';
7
7
  import '../chunk-SPCZTZCY.mjs';
8
8
  import '../chunk-QTET3FBV.mjs';
9
9
  import '../chunk-F2JIAPZQ.mjs';
10
10
  import '../chunk-VUY2K2DI.mjs';
11
11
  import '../chunk-6A4PCNMZ.mjs';
12
- import '../chunk-WMXA2TIX.mjs';
12
+ import '../chunk-R2WOR4SW.mjs';
13
13
  import '../chunk-TKXPMMND.mjs';
14
14
  import '../chunk-VK25FIML.mjs';
15
15
  import '../chunk-YULKJPY3.mjs';
@@ -1,4 +1,4 @@
1
- export { useChat } from '../chunk-WMXA2TIX.mjs';
1
+ export { useChat } from '../chunk-R2WOR4SW.mjs';
2
2
  import '../chunk-TKXPMMND.mjs';
3
3
  import '../chunk-VK25FIML.mjs';
4
4
  import '../chunk-MRXNTQOX.mjs';
@@ -1,11 +1,11 @@
1
- export { defaultSystemMessage, useCopilotChat } from '../chunk-XSS45JC5.mjs';
1
+ export { defaultSystemMessage, useCopilotChat } from '../chunk-R75NEA76.mjs';
2
2
  import '../chunk-JD7BAH7U.mjs';
3
3
  import '../chunk-SPCZTZCY.mjs';
4
4
  import '../chunk-QTET3FBV.mjs';
5
5
  import '../chunk-F2JIAPZQ.mjs';
6
6
  import '../chunk-VUY2K2DI.mjs';
7
7
  import '../chunk-6A4PCNMZ.mjs';
8
- import '../chunk-WMXA2TIX.mjs';
8
+ import '../chunk-R2WOR4SW.mjs';
9
9
  import '../chunk-TKXPMMND.mjs';
10
10
  import '../chunk-VK25FIML.mjs';
11
11
  import '../chunk-YULKJPY3.mjs';
package/dist/index.mjs CHANGED
@@ -1,24 +1,24 @@
1
+ import './chunk-PUFR5OAI.mjs';
2
+ import './chunk-EFZPSZWO.mjs';
1
3
  import './chunk-7GFKOIO7.mjs';
2
4
  import './chunk-BABVSMJR.mjs';
3
5
  export { useCopilotChatV2 } from './chunk-TU4DNDO7.mjs';
4
6
  import './chunk-FRAKUJWH.mjs';
5
7
  export { processMessageStream } from './chunk-MZ5UN3BY.mjs';
6
- import './chunk-EFZPSZWO.mjs';
7
- import './chunk-PUFR5OAI.mjs';
8
8
  export { ChatCompletionStream } from './chunk-6SOQYBNX.mjs';
9
9
  import './chunk-VNRDQJXW.mjs';
10
10
  import './chunk-5UGLWBZJ.mjs';
11
11
  export { useMakeCopilotActionable } from './chunk-FP4EXCGS.mjs';
12
12
  export { useMakeCopilotDocumentReadable } from './chunk-7P4OYNP3.mjs';
13
13
  export { useMakeCopilotReadable } from './chunk-HW5IH6PV.mjs';
14
- export { useCopilotChat } from './chunk-XSS45JC5.mjs';
14
+ export { useCopilotChat } from './chunk-R75NEA76.mjs';
15
15
  import './chunk-JD7BAH7U.mjs';
16
16
  import './chunk-SPCZTZCY.mjs';
17
17
  export { CopilotProvider, defaultCopilotContextCategories } from './chunk-QTET3FBV.mjs';
18
18
  import './chunk-F2JIAPZQ.mjs';
19
19
  import './chunk-VUY2K2DI.mjs';
20
20
  export { CopilotContext } from './chunk-6A4PCNMZ.mjs';
21
- import './chunk-WMXA2TIX.mjs';
21
+ import './chunk-R2WOR4SW.mjs';
22
22
  import './chunk-TKXPMMND.mjs';
23
23
  import './chunk-VK25FIML.mjs';
24
24
  import './chunk-YULKJPY3.mjs';
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.17.0",
7
+ "version": "0.17.1-alpha.0",
8
8
  "sideEffects": false,
9
9
  "main": "./dist/index.js",
10
10
  "module": "./dist/index.mjs",
@@ -23,14 +23,14 @@
23
23
  "ts-jest": "^29.1.1",
24
24
  "tsup": "^6.7.0",
25
25
  "typescript": "^5.1.3",
26
- "eslint-config-custom": "0.2.0",
27
- "tsconfig": "0.6.0"
26
+ "tsconfig": "0.6.0",
27
+ "eslint-config-custom": "0.2.0"
28
28
  },
29
29
  "dependencies": {
30
30
  "eventemitter3": "^5.0.1",
31
31
  "nanoid": "^4.0.2",
32
32
  "openai": "^4.6.0",
33
- "@copilotkit/shared": "0.1.0"
33
+ "@copilotkit/shared": "0.1.1-alpha.0"
34
34
  },
35
35
  "scripts": {
36
36
  "build": "tsup --treeshake",
@@ -1,4 +1,4 @@
1
- import { useState } from "react";
1
+ import { useRef, useState } from "react";
2
2
  import { Message, Function, FunctionCallHandler } from "../types";
3
3
  import { nanoid } from "nanoid";
4
4
  import { ChatCompletionClient } from "../openai/chat-completion-client";
@@ -84,11 +84,15 @@ export function useChat(options: UseChatOptionsWithCopilotConfig): UseChatHelper
84
84
  const [messages, setMessages] = useState<Message[]>([]);
85
85
  const [input, setInput] = useState("");
86
86
  const [isLoading, setIsLoading] = useState(false);
87
+ const abortControllerRef = useRef<AbortController>();
87
88
 
88
89
  const runChatCompletion = async (messages: Message[]): Promise<Message> => {
89
90
  return new Promise<Message>((resolve, reject) => {
90
91
  setIsLoading(true);
91
92
 
93
+ const abortController = new AbortController();
94
+ abortControllerRef.current = abortController;
95
+
92
96
  const assistantMessage: Message = {
93
97
  id: nanoid(),
94
98
  createdAt: new Date(),
@@ -108,8 +112,16 @@ export function useChat(options: UseChatOptionsWithCopilotConfig): UseChatHelper
108
112
  client.off("end");
109
113
  client.off("error");
110
114
  client.off("function");
115
+
116
+ abortControllerRef.current = undefined;
111
117
  };
112
118
 
119
+ abortController.signal.addEventListener("abort", () => {
120
+ cleanup();
121
+ setIsLoading(false);
122
+ reject(new DOMException("Aborted", "AbortError"));
123
+ });
124
+
113
125
  client.on("content", (content) => {
114
126
  assistantMessage.content += content;
115
127
  setMessages([...messages, { ...assistantMessage }]);
@@ -144,6 +156,7 @@ export function useChat(options: UseChatOptionsWithCopilotConfig): UseChatHelper
144
156
  messages: messagesWithContext,
145
157
  functions: options.functions,
146
158
  headers: options.headers,
159
+ signal: abortController.signal,
147
160
  });
148
161
  });
149
162
  };
@@ -180,7 +193,7 @@ export function useChat(options: UseChatOptionsWithCopilotConfig): UseChatHelper
180
193
  };
181
194
 
182
195
  const stop = (): void => {
183
- throw new Error("Not implemented");
196
+ abortControllerRef.current?.abort();
184
197
  };
185
198
 
186
199
  return {
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/hooks/use-chat.ts"],"names":["messages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Aa,SAAS;AAAA,QAClD;AACA,oBAAY,CAAC,GAAGA,WAAU,mBAAK,iBAAkB,CAAC;AAElD,qBAAa,KAAK;AAClB,gBAAQ;AACR,gBAAQ,mBAAK,iBAAkB;AAAA,MACjC,EAAC;AAED,aAAO,MAAM;AAAA,QACX,eAAe,QAAQ;AAAA,QACvB,UAAU;AAAA,QACV,WAAW,QAAQ;AAAA,QACnB,SAAS,QAAQ;AAAA,MACnB,CAAC;AAAA,IACH,CAAC;AAAA,EACH;AAEA,QAAM,yCAAyC,CAAOA,cAAuC;AAC3F,UAAM,UAAU,MAAM,kBAAkBA,SAAQ;AAChD,QAAI,QAAQ,iBAAiB,QAAQ,gBAAgB;AACnD,YAAM,QAAQ,eAAeA,WAAU,QAAQ,aAAa;AAAA,IAC9D;AAAA,EACF;AAEA,QAAM,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;AACvB,UAAM,IAAI,MAAM,iBAAiB;AAAA,EACnC;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF","sourcesContent":["import { useState } from \"react\";\nimport { Message, Function, FunctionCallHandler } from \"../types\";\nimport { nanoid } from \"nanoid\";\nimport { ChatCompletionClient } from \"../openai/chat-completion-client\";\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 functions?: Function[];\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\n const runChatCompletion = async (messages: Message[]): Promise<Message> => {\n return new Promise<Message>((resolve, reject) => {\n setIsLoading(true);\n\n const assistantMessage: Message = {\n id: nanoid(),\n createdAt: new Date(),\n content: \"\",\n role: \"assistant\",\n };\n\n // Assistant messages are always copied when using setState\n setMessages([...messages, { ...assistantMessage }]);\n\n const messagesWithContext = [...(options.initialMessages || []), ...messages];\n\n const client = new ChatCompletionClient({});\n\n const cleanup = () => {\n client.off(\"content\");\n client.off(\"end\");\n client.off(\"error\");\n client.off(\"function\");\n };\n\n client.on(\"content\", (content) => {\n assistantMessage.content += content;\n setMessages([...messages, { ...assistantMessage }]);\n });\n\n client.on(\"end\", () => {\n setIsLoading(false);\n cleanup();\n resolve({ ...assistantMessage });\n });\n\n client.on(\"error\", (error) => {\n setIsLoading(false);\n cleanup();\n reject(error);\n });\n\n client.on(\"function\", async (functionCall) => {\n assistantMessage.function_call = {\n name: functionCall.name,\n arguments: JSON.stringify(functionCall.arguments),\n };\n setMessages([...messages, { ...assistantMessage }]);\n // quit early if we get a function call\n setIsLoading(false);\n cleanup();\n resolve({ ...assistantMessage });\n });\n\n client.fetch({\n copilotConfig: options.copilotConfig,\n messages: messagesWithContext,\n functions: options.functions,\n headers: options.headers,\n });\n });\n };\n\n const runChatCompletionAndHandleFunctionCall = async (messages: Message[]): Promise<void> => {\n const message = await runChatCompletion(messages);\n if (message.function_call && options.onFunctionCall) {\n await options.onFunctionCall(messages, message.function_call);\n }\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 throw new Error(\"Not implemented\");\n };\n\n return {\n messages,\n append,\n reload,\n stop,\n isLoading,\n input,\n setInput,\n };\n}\n"]}