nanobridge 0.2.1 → 0.2.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/package.json +1 -1
- package/src/chat/session.js +2 -12
- package/src/chrome/bridge.js +5 -6
- package/src/daemon/server.js +2 -12
package/package.json
CHANGED
package/src/chat/session.js
CHANGED
|
@@ -138,21 +138,11 @@ export class ChatSessionManager {
|
|
|
138
138
|
|
|
139
139
|
const stream = session.promptStreaming(${JSON.stringify(promptToSend)}, promptOpts);
|
|
140
140
|
let finalOutput = '';
|
|
141
|
-
let prev = '';
|
|
142
141
|
|
|
143
142
|
for await (const chunk of stream) {
|
|
144
|
-
|
|
145
|
-
if (chunk.startsWith(prev) && prev.length > 0) {
|
|
146
|
-
delta = chunk.slice(prev.length);
|
|
147
|
-
prev = chunk;
|
|
148
|
-
finalOutput = chunk;
|
|
149
|
-
} else {
|
|
150
|
-
delta = chunk;
|
|
151
|
-
prev = chunk;
|
|
143
|
+
if (chunk) {
|
|
152
144
|
finalOutput += chunk;
|
|
153
|
-
|
|
154
|
-
if (delta) {
|
|
155
|
-
console.debug('${prefix}' + JSON.stringify({ d: delta }));
|
|
145
|
+
console.debug('${prefix}' + JSON.stringify({ d: chunk }));
|
|
156
146
|
}
|
|
157
147
|
}
|
|
158
148
|
|
package/src/chrome/bridge.js
CHANGED
|
@@ -305,12 +305,11 @@ export class ChromeBridge {
|
|
|
305
305
|
const session = await window.LanguageModel.create(${createArgs});
|
|
306
306
|
const stream = session.promptStreaming(${escapedPrompt});
|
|
307
307
|
let finalResult = '';
|
|
308
|
-
let prev = '';
|
|
309
308
|
for await (const chunk of stream) {
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
309
|
+
if (chunk) {
|
|
310
|
+
finalResult += chunk;
|
|
311
|
+
console.debug('${prefix}' + JSON.stringify({ d: chunk }));
|
|
312
|
+
}
|
|
314
313
|
}
|
|
315
314
|
if (typeof session.destroy === 'function') {
|
|
316
315
|
session.destroy();
|
|
@@ -404,7 +403,7 @@ export class ChromeBridge {
|
|
|
404
403
|
console.debug('${prefix}' + JSON.stringify({ type: 'first_chunk' }));
|
|
405
404
|
}
|
|
406
405
|
chunkCount++;
|
|
407
|
-
finalOutput
|
|
406
|
+
finalOutput += chunk;
|
|
408
407
|
console.debug('${prefix}' + JSON.stringify({ type: 'chunk' }));
|
|
409
408
|
}
|
|
410
409
|
|
package/src/daemon/server.js
CHANGED
|
@@ -547,7 +547,6 @@ export class DaemonServer {
|
|
|
547
547
|
? session.promptStreaming(${escapedPrompt}, { responseConstraint: constraint })
|
|
548
548
|
: session.promptStreaming(${escapedPrompt});
|
|
549
549
|
let fullResult = '';
|
|
550
|
-
let prev = '';
|
|
551
550
|
|
|
552
551
|
for await (const chunk of stream) {
|
|
553
552
|
if (window.__nanobridge_abort_req === '${reqId}') {
|
|
@@ -556,18 +555,9 @@ export class DaemonServer {
|
|
|
556
555
|
}
|
|
557
556
|
return { success: false, error: 'Request cancelled' };
|
|
558
557
|
}
|
|
559
|
-
|
|
560
|
-
if (chunk.startsWith(prev) && prev.length > 0) {
|
|
561
|
-
delta = chunk.slice(prev.length);
|
|
562
|
-
prev = chunk;
|
|
563
|
-
fullResult = chunk;
|
|
564
|
-
} else {
|
|
565
|
-
delta = chunk;
|
|
566
|
-
prev = chunk;
|
|
558
|
+
if (chunk) {
|
|
567
559
|
fullResult += chunk;
|
|
568
|
-
|
|
569
|
-
if (delta) {
|
|
570
|
-
console.debug('${prefix}' + JSON.stringify({ d: delta }));
|
|
560
|
+
console.debug('${prefix}' + JSON.stringify({ d: chunk }));
|
|
571
561
|
}
|
|
572
562
|
}
|
|
573
563
|
|