@copilotkit/react-core 0.17.0-alpha.1 → 0.17.0-alpha.2
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.
- package/.turbo/turbo-build.log +78 -78
- package/CHANGELOG.md +6 -0
- package/dist/{chunk-TDH7XE4X.mjs → chunk-WMXA2TIX.mjs} +2 -4
- package/dist/chunk-WMXA2TIX.mjs.map +1 -0
- package/dist/{chunk-SM3XH2NJ.mjs → chunk-XSS45JC5.mjs} +2 -2
- package/dist/hooks/index.mjs +2 -2
- package/dist/hooks/use-chat.mjs +1 -1
- package/dist/hooks/use-copilot-chat.mjs +2 -2
- package/dist/index.mjs +3 -3
- package/package.json +1 -1
- package/src/hooks/use-chat.ts +1 -3
- package/dist/chunk-TDH7XE4X.mjs.map +0 -1
- /package/dist/{chunk-SM3XH2NJ.mjs.map → chunk-XSS45JC5.mjs.map} +0 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
|
|
2
|
-
> @copilotkit/react-core@0.17.0-alpha.
|
|
2
|
+
> @copilotkit/react-core@0.17.0-alpha.1 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
|
|
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/utils/utils.test.ts, src/utils/utils.ts, src/types/annotated-function.ts, src/types/base.ts, src/types/document-pointer.ts, src/types/index.ts, src/types/message.ts, src/openai-assistants/index.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
6
|
CLI Using tsconfig: tsconfig.json
|
|
7
7
|
CLI tsup v6.7.0
|
|
8
8
|
CLI Using tsup config: /Users/ataibarkai/LocalGit/Recursively.ai/CopilotKit/CopilotKit/packages/react-core/tsup.config.ts
|
|
@@ -17,139 +17,139 @@ Module level directives cause errors when bundled, "use client" in "dist/hooks/u
|
|
|
17
17
|
Module level directives cause errors when bundled, "use client" in "dist/hooks/use-make-copilot-readable.mjs" was ignored.
|
|
18
18
|
Module level directives cause errors when bundled, "use client" in "dist/context/copilot-context.mjs" was ignored.
|
|
19
19
|
Generated an empty chunk: "copilot-provider-props".
|
|
20
|
+
Generated an empty chunk: "utils".
|
|
20
21
|
Generated an empty chunk: "annotated-function".
|
|
21
22
|
Generated an empty chunk: "base".
|
|
22
23
|
Generated an empty chunk: "document-pointer".
|
|
23
24
|
Generated an empty chunk: "message".
|
|
24
|
-
Generated an empty chunk: "utils".
|
|
25
|
-
Generated an empty chunk: "chunk-PUFR5OAI".
|
|
26
25
|
Generated an empty chunk: "chunk-EFZPSZWO".
|
|
27
26
|
Generated an empty chunk: "chunk-7GFKOIO7".
|
|
28
27
|
Generated an empty chunk: "chunk-BABVSMJR".
|
|
29
28
|
Generated an empty chunk: "chunk-FRAKUJWH".
|
|
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
34
|
ESM dist/chunk-EFZPSZWO.mjs 76.00 B
|
|
35
|
-
ESM dist/hooks/use-make-copilot-actionable.mjs 218.00 B
|
|
36
35
|
ESM dist/types/index.mjs 98.00 B
|
|
37
|
-
ESM dist/openai/index.mjs 224.00 B
|
|
38
|
-
ESM dist/chunk-PUFR5OAI.mjs 76.00 B
|
|
39
36
|
ESM dist/openai-assistants/index.mjs 570.00 B
|
|
40
|
-
ESM dist/
|
|
37
|
+
ESM dist/hooks/use-make-copilot-actionable.mjs 218.00 B
|
|
38
|
+
ESM dist/openai/chat-completion-client.mjs 209.00 B
|
|
39
|
+
ESM dist/context/copilot-context.mjs 164.00 B
|
|
40
|
+
ESM dist/chunk-7GFKOIO7.mjs 76.00 B
|
|
41
|
+
ESM dist/chunk-PUFR5OAI.mjs 76.00 B
|
|
42
|
+
ESM dist/chunk-VNRDQJXW.mjs 76.00 B
|
|
43
|
+
ESM dist/chunk-5UGLWBZJ.mjs 76.00 B
|
|
41
44
|
ESM dist/chunk-JD7BAH7U.mjs 76.00 B
|
|
42
45
|
ESM dist/chunk-F2JIAPZQ.mjs 435.00 B
|
|
43
|
-
ESM dist/chunk-7GFKOIO7.mjs 76.00 B
|
|
44
46
|
ESM dist/chunk-MRXNTQOX.mjs 1.92 KB
|
|
45
47
|
ESM dist/chunk-SPCZTZCY.mjs 76.00 B
|
|
46
|
-
ESM dist/
|
|
47
|
-
ESM dist/chunk-
|
|
48
|
+
ESM dist/hooks/use-make-copilot-document-readable.mjs 231.00 B
|
|
49
|
+
ESM dist/chunk-BABVSMJR.mjs 76.00 B
|
|
48
50
|
ESM dist/hooks/use-tree.mjs 170.00 B
|
|
49
|
-
ESM dist/hooks/use-make-copilot-readable.mjs 214.00 B
|
|
50
|
-
ESM dist/openai/chat-completion-client.mjs 209.00 B
|
|
51
|
-
ESM dist/openai/chat-completion-transport.mjs 183.00 B
|
|
52
|
-
ESM dist/openai/chat-completion-stream.mjs 209.00 B
|
|
53
51
|
ESM dist/index.mjs 1.11 KB
|
|
54
|
-
ESM dist/
|
|
55
|
-
ESM dist/
|
|
52
|
+
ESM dist/openai/index.mjs 224.00 B
|
|
53
|
+
ESM dist/hooks/use-make-copilot-readable.mjs 214.00 B
|
|
56
54
|
ESM dist/components/index.mjs 380.00 B
|
|
55
|
+
ESM dist/chunk-6SOQYBNX.mjs 1.24 KB
|
|
56
|
+
ESM dist/context/index.mjs 186.00 B
|
|
57
57
|
ESM dist/chunk-TU4DNDO7.mjs 4.33 KB
|
|
58
|
-
ESM dist/chunk-
|
|
58
|
+
ESM dist/chunk-FRAKUJWH.mjs 76.00 B
|
|
59
59
|
ESM dist/hooks/index.mjs 708.00 B
|
|
60
|
-
ESM dist/chunk-
|
|
61
|
-
ESM dist/
|
|
62
|
-
ESM dist/chunk-SM3XH2NJ.mjs 2.71 KB
|
|
63
|
-
ESM dist/hooks/use-copilot-chat.mjs 507.00 B
|
|
60
|
+
ESM dist/chunk-FP4EXCGS.mjs 954.00 B
|
|
61
|
+
ESM dist/openai/chat-completion-transport.mjs 183.00 B
|
|
64
62
|
ESM dist/chunk-HW5IH6PV.mjs 626.00 B
|
|
65
|
-
ESM dist/chunk-
|
|
66
|
-
ESM dist/chunk-FRAKUJWH.mjs 76.00 B
|
|
63
|
+
ESM dist/chunk-MZ5UN3BY.mjs 830.00 B
|
|
67
64
|
ESM dist/chunk-VUY2K2DI.mjs 3.89 KB
|
|
68
|
-
ESM dist/chunk-TKXPMMND.mjs 5.33 KB
|
|
69
|
-
ESM dist/chunk-VK25FIML.mjs 4.48 KB
|
|
70
|
-
ESM dist/chunk-TDH7XE4X.mjs 3.28 KB
|
|
71
65
|
ESM dist/chunk-QTET3FBV.mjs 5.18 KB
|
|
66
|
+
ESM dist/chunk-WMXA2TIX.mjs 3.25 KB
|
|
67
|
+
ESM dist/chunk-6A4PCNMZ.mjs 1.30 KB
|
|
68
|
+
ESM dist/chunk-VK25FIML.mjs 4.48 KB
|
|
69
|
+
ESM dist/hooks/use-chat.mjs 214.00 B
|
|
72
70
|
ESM dist/hooks/use-flat-category-store.mjs 200.00 B
|
|
73
|
-
ESM dist/
|
|
74
|
-
ESM dist/hooks/use-make-copilot-document-readable.mjs 231.00 B
|
|
71
|
+
ESM dist/hooks/use-copilot-chat.mjs 507.00 B
|
|
75
72
|
ESM dist/chunk-YULKJPY3.mjs 1.87 KB
|
|
76
|
-
ESM dist/
|
|
73
|
+
ESM dist/chunk-XSS45JC5.mjs 2.71 KB
|
|
74
|
+
ESM dist/chunk-TKXPMMND.mjs 5.33 KB
|
|
75
|
+
ESM dist/chunk-7P4OYNP3.mjs 677.00 B
|
|
76
|
+
ESM dist/openai/chat-completion-stream.mjs 209.00 B
|
|
77
77
|
ESM dist/components/copilot-provider/copilot-provider-props.mjs 84.00 B
|
|
78
|
-
ESM dist/openai-assistants/utils/process-message-stream.mjs 183.00 B
|
|
79
78
|
ESM dist/utils/utils.test.mjs 202.00 B
|
|
79
|
+
ESM dist/openai-assistants/utils/process-message-stream.mjs 183.00 B
|
|
80
80
|
ESM dist/openai-assistants/hooks/index.mjs 547.00 B
|
|
81
|
-
ESM dist/types/message.mjs 69.00 B
|
|
82
|
-
ESM dist/utils/utils.mjs 67.00 B
|
|
83
|
-
ESM dist/types/base.mjs 66.00 B
|
|
84
81
|
ESM dist/types/annotated-function.mjs 80.00 B
|
|
85
|
-
ESM dist/types/
|
|
82
|
+
ESM dist/types/base.mjs 66.00 B
|
|
83
|
+
ESM dist/types/message.mjs 69.00 B
|
|
86
84
|
ESM dist/components/copilot-provider/index.mjs 369.00 B
|
|
87
|
-
ESM dist/openai-assistants/utils/index.mjs 201.00 B
|
|
88
|
-
ESM dist/components/copilot-provider/copilot-provider.mjs 345.00 B
|
|
89
85
|
ESM dist/openai-assistants/hooks/use-assistants.mjs 2.55 KB
|
|
90
|
-
ESM dist/components/copilot-provider/
|
|
86
|
+
ESM dist/components/copilot-provider/copilot-provider.mjs 345.00 B
|
|
87
|
+
ESM dist/openai-assistants/utils/index.mjs 201.00 B
|
|
91
88
|
ESM dist/openai-assistants/hooks/use-copilot-chat-v2.mjs 548.00 B
|
|
89
|
+
ESM dist/components/copilot-provider/standard-copilot-api-config.mjs 192.00 B
|
|
90
|
+
ESM dist/utils/utils.mjs 67.00 B
|
|
91
|
+
ESM dist/types/document-pointer.mjs 78.00 B
|
|
92
92
|
ESM dist/chunk-EFZPSZWO.mjs.map 51.00 B
|
|
93
|
-
ESM dist/hooks/use-make-copilot-actionable.mjs.map 51.00 B
|
|
94
93
|
ESM dist/types/index.mjs.map 51.00 B
|
|
95
|
-
ESM dist/openai/index.mjs.map
|
|
94
|
+
ESM dist/openai-assistants/index.mjs.map 51.00 B
|
|
95
|
+
ESM dist/hooks/use-make-copilot-actionable.mjs.map 51.00 B
|
|
96
|
+
ESM dist/chunk-7GFKOIO7.mjs.map 51.00 B
|
|
96
97
|
ESM dist/chunk-PUFR5OAI.mjs.map 51.00 B
|
|
97
|
-
ESM dist/chunk-
|
|
98
|
-
ESM dist/chunk-MRXNTQOX.mjs.map 71.00 B
|
|
98
|
+
ESM dist/chunk-5UGLWBZJ.mjs.map 51.00 B
|
|
99
99
|
ESM dist/chunk-F2JIAPZQ.mjs.map 1.12 KB
|
|
100
|
-
ESM dist/
|
|
100
|
+
ESM dist/context/copilot-context.mjs.map 51.00 B
|
|
101
|
+
ESM dist/chunk-VNRDQJXW.mjs.map 51.00 B
|
|
102
|
+
ESM dist/chunk-MRXNTQOX.mjs.map 71.00 B
|
|
101
103
|
ESM dist/chunk-JD7BAH7U.mjs.map 51.00 B
|
|
102
|
-
ESM dist/chunk-5UGLWBZJ.mjs.map 51.00 B
|
|
103
|
-
ESM dist/chunk-SPCZTZCY.mjs.map 51.00 B
|
|
104
104
|
ESM dist/openai/chat-completion-client.mjs.map 51.00 B
|
|
105
|
-
ESM dist/
|
|
106
|
-
ESM dist/
|
|
107
|
-
ESM dist/hooks/use-make-copilot-readable.mjs.map 51.00 B
|
|
108
|
-
ESM dist/chunk-VNRDQJXW.mjs.map 51.00 B
|
|
105
|
+
ESM dist/hooks/use-make-copilot-document-readable.mjs.map 51.00 B
|
|
106
|
+
ESM dist/chunk-BABVSMJR.mjs.map 51.00 B
|
|
109
107
|
ESM dist/hooks/use-tree.mjs.map 51.00 B
|
|
110
|
-
ESM dist/chunk-6SOQYBNX.mjs.map 2.07 KB
|
|
111
108
|
ESM dist/index.mjs.map 51.00 B
|
|
109
|
+
ESM dist/hooks/use-make-copilot-readable.mjs.map 51.00 B
|
|
110
|
+
ESM dist/chunk-SPCZTZCY.mjs.map 51.00 B
|
|
111
|
+
ESM dist/chunk-6SOQYBNX.mjs.map 2.07 KB
|
|
112
|
+
ESM dist/openai/index.mjs.map 51.00 B
|
|
113
|
+
ESM dist/chunk-FRAKUJWH.mjs.map 51.00 B
|
|
114
|
+
ESM dist/openai/chat-completion-transport.mjs.map 51.00 B
|
|
115
|
+
ESM dist/chunk-TU4DNDO7.mjs.map 7.90 KB
|
|
112
116
|
ESM dist/chunk-MZ5UN3BY.mjs.map 1.26 KB
|
|
113
|
-
ESM dist/chunk-
|
|
114
|
-
ESM dist/
|
|
117
|
+
ESM dist/chunk-WMXA2TIX.mjs.map 7.79 KB
|
|
118
|
+
ESM dist/context/index.mjs.map 51.00 B
|
|
119
|
+
ESM dist/components/index.mjs.map 51.00 B
|
|
115
120
|
ESM dist/hooks/index.mjs.map 51.00 B
|
|
116
|
-
ESM dist/hooks/use-chat.mjs.map 51.00 B
|
|
117
|
-
ESM dist/chunk-TU4DNDO7.mjs.map 7.90 KB
|
|
118
|
-
ESM dist/chunk-HW5IH6PV.mjs.map 1.47 KB
|
|
119
121
|
ESM dist/chunk-FP4EXCGS.mjs.map 1.67 KB
|
|
120
|
-
ESM dist/
|
|
122
|
+
ESM dist/hooks/use-flat-category-store.mjs.map 51.00 B
|
|
121
123
|
ESM dist/chunk-6A4PCNMZ.mjs.map 4.26 KB
|
|
122
|
-
ESM dist/hooks/use-copilot-chat.mjs.map 51.00 B
|
|
123
|
-
ESM dist/chunk-FRAKUJWH.mjs.map 51.00 B
|
|
124
|
-
ESM dist/components/index.mjs.map 51.00 B
|
|
125
|
-
ESM dist/chunk-TKXPMMND.mjs.map 9.93 KB
|
|
126
|
-
ESM dist/chunk-VUY2K2DI.mjs.map 8.27 KB
|
|
127
124
|
ESM dist/chunk-VK25FIML.mjs.map 7.84 KB
|
|
128
|
-
ESM dist/
|
|
125
|
+
ESM dist/hooks/use-chat.mjs.map 51.00 B
|
|
126
|
+
ESM dist/chunk-VUY2K2DI.mjs.map 8.27 KB
|
|
127
|
+
ESM dist/hooks/use-copilot-chat.mjs.map 51.00 B
|
|
129
128
|
ESM dist/chunk-QTET3FBV.mjs.map 11.03 KB
|
|
130
|
-
ESM dist/context/copilot-context.mjs.map 51.00 B
|
|
131
129
|
ESM dist/chunk-YULKJPY3.mjs.map 4.21 KB
|
|
132
|
-
ESM dist/
|
|
133
|
-
ESM dist/
|
|
134
|
-
ESM dist/
|
|
130
|
+
ESM dist/chunk-XSS45JC5.mjs.map 4.37 KB
|
|
131
|
+
ESM dist/chunk-TKXPMMND.mjs.map 9.93 KB
|
|
132
|
+
ESM dist/chunk-HW5IH6PV.mjs.map 1.47 KB
|
|
133
|
+
ESM dist/chunk-7P4OYNP3.mjs.map 1.42 KB
|
|
134
|
+
ESM dist/openai/chat-completion-stream.mjs.map 51.00 B
|
|
135
135
|
ESM dist/components/copilot-provider/copilot-provider-props.mjs.map 51.00 B
|
|
136
|
-
ESM dist/openai-assistants/utils/process-message-stream.mjs.map 51.00 B
|
|
137
136
|
ESM dist/utils/utils.test.mjs.map 351.00 B
|
|
137
|
+
ESM dist/openai-assistants/utils/process-message-stream.mjs.map 51.00 B
|
|
138
138
|
ESM dist/openai-assistants/hooks/index.mjs.map 51.00 B
|
|
139
|
-
ESM dist/types/message.mjs.map 51.00 B
|
|
140
|
-
ESM dist/utils/utils.mjs.map 51.00 B
|
|
141
|
-
ESM dist/types/annotated-function.mjs.map 51.00 B
|
|
142
|
-
ESM dist/types/base.mjs.map 51.00 B
|
|
143
|
-
ESM dist/openai-assistants/utils/index.mjs.map 51.00 B
|
|
144
139
|
ESM dist/components/copilot-provider/index.mjs.map 51.00 B
|
|
145
|
-
ESM dist/types/
|
|
140
|
+
ESM dist/types/annotated-function.mjs.map 51.00 B
|
|
146
141
|
ESM dist/openai-assistants/hooks/use-assistants.mjs.map 4.67 KB
|
|
142
|
+
ESM dist/types/base.mjs.map 51.00 B
|
|
143
|
+
ESM dist/types/message.mjs.map 51.00 B
|
|
147
144
|
ESM dist/components/copilot-provider/copilot-provider.mjs.map 51.00 B
|
|
148
145
|
ESM dist/components/copilot-provider/standard-copilot-api-config.mjs.map 51.00 B
|
|
146
|
+
ESM dist/openai-assistants/utils/index.mjs.map 51.00 B
|
|
147
|
+
ESM dist/types/document-pointer.mjs.map 51.00 B
|
|
149
148
|
ESM dist/openai-assistants/hooks/use-copilot-chat-v2.mjs.map 51.00 B
|
|
150
|
-
ESM
|
|
149
|
+
ESM dist/utils/utils.mjs.map 51.00 B
|
|
150
|
+
ESM ⚡️ Build success in 168ms
|
|
151
151
|
DTS Build start
|
|
152
|
-
DTS ⚡️ Build success in
|
|
152
|
+
DTS ⚡️ Build success in 2842ms
|
|
153
153
|
DTS dist/index.d.ts 1.61 KB
|
|
154
154
|
DTS dist/components/copilot-provider/copilot-provider.d.ts 1.55 KB
|
|
155
155
|
DTS dist/components/copilot-provider/copilot-provider-props.d.ts 1.52 KB
|
|
@@ -171,13 +171,13 @@ DTS dist/components/index.d.ts 482.00 B
|
|
|
171
171
|
DTS dist/context/index.d.ts 281.00 B
|
|
172
172
|
DTS dist/hooks/index.d.ts 608.00 B
|
|
173
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
174
|
DTS dist/openai/chat-completion-client.d.ts 1.44 KB
|
|
176
175
|
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
176
|
DTS dist/utils/utils.test.d.ts 12.00 B
|
|
180
177
|
DTS dist/utils/utils.d.ts 12.00 B
|
|
178
|
+
DTS dist/types/index.d.ts 233.00 B
|
|
179
|
+
DTS dist/types/message.d.ts 12.00 B
|
|
180
|
+
DTS dist/openai-assistants/index.d.ts 262.00 B
|
|
181
181
|
DTS dist/components/copilot-provider/index.d.ts 463.00 B
|
|
182
182
|
DTS dist/components/copilot-provider/standard-copilot-api-config.d.ts 911.00 B
|
|
183
183
|
DTS dist/openai-assistants/hooks/index.d.ts 182.00 B
|
package/CHANGELOG.md
CHANGED
|
@@ -18,9 +18,7 @@ function useChat(options) {
|
|
|
18
18
|
};
|
|
19
19
|
setMessages([...messages2, __spreadValues({}, assistantMessage)]);
|
|
20
20
|
const messagesWithContext = [...options.initialMessages || [], ...messages2];
|
|
21
|
-
const client = new ChatCompletionClient({
|
|
22
|
-
url: options.api
|
|
23
|
-
});
|
|
21
|
+
const client = new ChatCompletionClient({});
|
|
24
22
|
const cleanup = () => {
|
|
25
23
|
client.off("content");
|
|
26
24
|
client.off("end");
|
|
@@ -101,4 +99,4 @@ function useChat(options) {
|
|
|
101
99
|
|
|
102
100
|
export { useChat };
|
|
103
101
|
//# sourceMappingURL=out.js.map
|
|
104
|
-
//# sourceMappingURL=chunk-
|
|
102
|
+
//# sourceMappingURL=chunk-WMXA2TIX.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/hooks/use-chat.ts"],"names":["messages"],"mappings":"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","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"]}
|
|
@@ -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-
|
|
3
|
+
import { useChat } from './chunk-WMXA2TIX.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-
|
|
77
|
+
//# sourceMappingURL=chunk-XSS45JC5.mjs.map
|
package/dist/hooks/index.mjs
CHANGED
|
@@ -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-
|
|
5
|
+
export { useCopilotChat } from '../chunk-XSS45JC5.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-
|
|
12
|
+
import '../chunk-WMXA2TIX.mjs';
|
|
13
13
|
import '../chunk-TKXPMMND.mjs';
|
|
14
14
|
import '../chunk-VK25FIML.mjs';
|
|
15
15
|
import '../chunk-YULKJPY3.mjs';
|
package/dist/hooks/use-chat.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export { defaultSystemMessage, useCopilotChat } from '../chunk-
|
|
1
|
+
export { defaultSystemMessage, useCopilotChat } from '../chunk-XSS45JC5.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-
|
|
8
|
+
import '../chunk-WMXA2TIX.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
1
|
import './chunk-EFZPSZWO.mjs';
|
|
3
2
|
import './chunk-7GFKOIO7.mjs';
|
|
4
3
|
import './chunk-BABVSMJR.mjs';
|
|
5
4
|
export { useCopilotChatV2 } from './chunk-TU4DNDO7.mjs';
|
|
6
5
|
import './chunk-FRAKUJWH.mjs';
|
|
7
6
|
export { processMessageStream } from './chunk-MZ5UN3BY.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-
|
|
14
|
+
export { useCopilotChat } from './chunk-XSS45JC5.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-
|
|
21
|
+
import './chunk-WMXA2TIX.mjs';
|
|
22
22
|
import './chunk-TKXPMMND.mjs';
|
|
23
23
|
import './chunk-VK25FIML.mjs';
|
|
24
24
|
import './chunk-YULKJPY3.mjs';
|
package/package.json
CHANGED
package/src/hooks/use-chat.ts
CHANGED
|
@@ -101,9 +101,7 @@ export function useChat(options: UseChatOptionsWithCopilotConfig): UseChatHelper
|
|
|
101
101
|
|
|
102
102
|
const messagesWithContext = [...(options.initialMessages || []), ...messages];
|
|
103
103
|
|
|
104
|
-
const client = new ChatCompletionClient({
|
|
105
|
-
url: options.api,
|
|
106
|
-
});
|
|
104
|
+
const client = new ChatCompletionClient({});
|
|
107
105
|
|
|
108
106
|
const cleanup = () => {
|
|
109
107
|
client.off("content");
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/hooks/use-chat.ts"],"names":["messages"],"mappings":"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","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 url: options.api,\n });\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"]}
|
|
File without changes
|