openaxies 0.5.2 → 0.5.4
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/package.json +1 -1
- package/src/App.js +28 -22
- package/src/providers/index.js +1 -0
- package/src/providers/streaming.js +37 -1
package/package.json
CHANGED
package/src/App.js
CHANGED
|
@@ -180,23 +180,21 @@ function AppRoot() {
|
|
|
180
180
|
}
|
|
181
181
|
if (event.type === 'thinking' || event.type === 'token') {
|
|
182
182
|
const content = typeof event.content === 'string' ? event.content : '';
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
setThinkingElapsed(0);
|
|
197
|
-
}
|
|
198
|
-
await new Promise(function (r) { setTimeout(r, 0); });
|
|
183
|
+
accumulated = accumulated + content;
|
|
184
|
+
const inside = checkThink(accumulated);
|
|
185
|
+
setStreamText(accumulated);
|
|
186
|
+
setIsThinking(inside);
|
|
187
|
+
if (inside === true && thinkStarted === false) {
|
|
188
|
+
thinkStarted = true;
|
|
189
|
+
thinkStartRef.current = Date.now();
|
|
190
|
+
setThinkingElapsed(0);
|
|
191
|
+
}
|
|
192
|
+
if (inside === false && thinkStarted === true) {
|
|
193
|
+
thinkStarted = false;
|
|
194
|
+
thinkStartRef.current = null;
|
|
195
|
+
setThinkingElapsed(0);
|
|
199
196
|
}
|
|
197
|
+
await new Promise(function (r) { setTimeout(r, 0); });
|
|
200
198
|
}
|
|
201
199
|
if (event.type === 'done') break;
|
|
202
200
|
if (event.type === 'timeout') {
|
|
@@ -210,10 +208,9 @@ function AppRoot() {
|
|
|
210
208
|
thinkStartRef.current = null;
|
|
211
209
|
setThinkingElapsed(0);
|
|
212
210
|
setStreamingActive(false);
|
|
213
|
-
const finalText = streamText;
|
|
214
211
|
setStreamText('');
|
|
215
|
-
if (
|
|
216
|
-
setMessages(function (p) { return p.concat([{ role: 'assistant', content:
|
|
212
|
+
if (accumulated.length > 0) {
|
|
213
|
+
setMessages(function (p) { return p.concat([{ role: 'assistant', content: accumulated, id: 'a-' + Date.now() }]); });
|
|
217
214
|
}
|
|
218
215
|
} catch (err) {
|
|
219
216
|
if (connRef.current !== null) clearInterval(connRef.current), connRef.current = null;
|
|
@@ -279,7 +276,7 @@ function AppRoot() {
|
|
|
279
276
|
h(Text, { key: 'l' + r, color: LOGO_COLORS[r % LOGO_COLORS.length], bold: true }, LOGO[r])
|
|
280
277
|
);
|
|
281
278
|
}
|
|
282
|
-
const logo = h(Box, { flexDirection: 'column', width: '100%', flexShrink: 0, paddingLeft:
|
|
279
|
+
const logo = h(Box, { flexDirection: 'column', width: '100%', flexShrink: 0, paddingLeft: 0 }, ...logoEls);
|
|
283
280
|
|
|
284
281
|
const viewLines = [];
|
|
285
282
|
for (let i = 0; i < messages.length; i++) {
|
|
@@ -310,7 +307,10 @@ function AppRoot() {
|
|
|
310
307
|
}
|
|
311
308
|
|
|
312
309
|
if (viewLines.length === 0) {
|
|
313
|
-
viewLines.push({ t: 'idle', text: ' \u25B8 type a message to begin
|
|
310
|
+
viewLines.push({ t: 'idle', text: ' \u25B8 type a message to begin | /model to switch models | /help for commands' });
|
|
311
|
+
viewLines.push({ t: 'idle', text: '' });
|
|
312
|
+
viewLines.push({ t: 'idle-sm', text: ' Models: OpenAxies Llama | OpenAxies GPT | OpenAxies DeepSeek' });
|
|
313
|
+
viewLines.push({ t: 'idle-sm', text: ' Current: ' + activeLabel });
|
|
314
314
|
}
|
|
315
315
|
|
|
316
316
|
const visible = Math.max(1, availLines - 1);
|
|
@@ -352,7 +352,13 @@ function AppRoot() {
|
|
|
352
352
|
} else if (l.t === 'idle') {
|
|
353
353
|
viewEls.push(
|
|
354
354
|
h(Box, { key: 'i-' + i, height: 1, paddingLeft: 1 },
|
|
355
|
-
h(Text, { color: '#
|
|
355
|
+
h(Text, { color: '#555577' }, l.text)
|
|
356
|
+
)
|
|
357
|
+
);
|
|
358
|
+
} else if (l.t === 'idle-sm') {
|
|
359
|
+
viewEls.push(
|
|
360
|
+
h(Box, { key: 'is-' + i, height: 1, paddingLeft: 1 },
|
|
361
|
+
h(Text, { color: '#333355' }, l.text)
|
|
356
362
|
)
|
|
357
363
|
);
|
|
358
364
|
}
|
package/src/providers/index.js
CHANGED
|
@@ -78,7 +78,7 @@ export async function* streamResponse(endpoint, body, signal) {
|
|
|
78
78
|
}, READ_TIMEOUT);
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
|
|
81
|
+
let firstChunk = true;
|
|
82
82
|
|
|
83
83
|
try {
|
|
84
84
|
while (true) {
|
|
@@ -86,12 +86,48 @@ export async function* streamResponse(endpoint, body, signal) {
|
|
|
86
86
|
resetReadTimeout();
|
|
87
87
|
|
|
88
88
|
if (result.done === true) {
|
|
89
|
+
if (buffer.trim().length > 0 && firstChunk === false) {
|
|
90
|
+
try {
|
|
91
|
+
const parsed = JSON.parse(buffer);
|
|
92
|
+
const choice = parsed.choices && parsed.choices[0];
|
|
93
|
+
if (choice !== null && choice !== undefined) {
|
|
94
|
+
const msg = choice.message || choice.delta;
|
|
95
|
+
if (msg !== null && msg !== undefined) {
|
|
96
|
+
if (typeof msg.content === 'string' && msg.content.length > 0) {
|
|
97
|
+
yield { type: 'token', content: msg.content };
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
} catch (_) {
|
|
102
|
+
}
|
|
103
|
+
}
|
|
89
104
|
yield { type: 'done' };
|
|
90
105
|
return;
|
|
91
106
|
}
|
|
92
107
|
|
|
93
108
|
const chunk = decoder.decode(result.value, { stream: true });
|
|
94
109
|
buffer = buffer + chunk;
|
|
110
|
+
|
|
111
|
+
if (firstChunk === true && buffer.includes('data: ') === false && buffer.trim().startsWith('{') === true) {
|
|
112
|
+
try {
|
|
113
|
+
const parsed = JSON.parse(buffer);
|
|
114
|
+
const choice = parsed.choices && parsed.choices[0];
|
|
115
|
+
if (choice !== null && choice !== undefined) {
|
|
116
|
+
const msg = choice.message || choice.delta;
|
|
117
|
+
if (msg !== null && msg !== undefined) {
|
|
118
|
+
if (typeof msg.content === 'string' && msg.content.length > 0) {
|
|
119
|
+
yield { type: 'token', content: msg.content };
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
yield { type: 'done' };
|
|
124
|
+
return;
|
|
125
|
+
} catch (_) {
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
firstChunk = false;
|
|
130
|
+
|
|
95
131
|
const lines = buffer.split('\n');
|
|
96
132
|
buffer = lines.pop() || '';
|
|
97
133
|
|