File tree Expand file tree Collapse file tree 1 file changed +41
-1
lines changed
assets/components/modai/js/mgr Expand file tree Collapse file tree 1 file changed +41
-1
lines changed Original file line number Diff line number Diff line change 75
75
} ;
76
76
}
77
77
} ,
78
+ claude : {
79
+ content : ( newData , currentData = undefined ) => {
80
+ const currentContent = currentData ?. content ?? '' ;
81
+
82
+ const content = newData . delta ?. text || '' ;
83
+
84
+ return {
85
+ content : `${ currentContent } ${ content } `
86
+ } ;
87
+ }
88
+ } ,
78
89
gemini : {
79
90
content : ( newData , currentData = undefined ) => {
80
91
const currentContent = currentData ?. content ?? '' ;
144
155
145
156
try {
146
157
const parsedData = JSON . parse ( data ) ;
147
- console . log ( parsedData ) ;
158
+ currentData = services . stream [ service ] [ parser ] ( parsedData , currentData ) ;
159
+ if ( onChunkStream ) {
160
+ onChunkStream ( currentData ) ;
161
+ }
162
+ } catch { }
163
+ }
164
+ }
165
+
166
+ buffer = buffer . slice ( lastNewlineIndex ) ;
167
+ }
168
+
169
+ if ( service === 'claude' ) {
170
+ buffer += chunk ;
171
+
172
+ let lastNewlineIndex = 0 ;
173
+ let newlineIndex ;
174
+
175
+ while ( ( newlineIndex = buffer . indexOf ( '\n' , lastNewlineIndex ) ) !== - 1 ) {
176
+ const line = buffer . slice ( lastNewlineIndex , newlineIndex ) . trim ( ) ;
177
+ lastNewlineIndex = newlineIndex + 1 ;
178
+
179
+ if ( line . startsWith ( 'data: ' ) ) {
180
+ const data = line . slice ( 6 ) ;
181
+
182
+ try {
183
+ const parsedData = JSON . parse ( data ) ;
184
+ if ( parsedData . type !== 'content_block_delta' ) {
185
+ continue ;
186
+ }
187
+
148
188
currentData = services . stream [ service ] [ parser ] ( parsedData , currentData ) ;
149
189
if ( onChunkStream ) {
150
190
onChunkStream ( currentData ) ;
You can’t perform that action at this time.
0 commit comments