@fias/plugin-dev-harness 1.5.13 → 1.5.14

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.
@@ -375,8 +375,11 @@
375
375
  return;
376
376
  }
377
377
 
378
- // Live mode: proxy through local Express SSE endpoint
379
- fetch('/api/bridge/stream', {
378
+ // Live mode: get the full response via non-streaming endpoint, then
379
+ // simulate streaming in the browser. The Express SSE proxy batches all
380
+ // tokens into a single chunk due to Node.js TCP buffering on localhost,
381
+ // so browser-side simulation is the only reliable approach.
382
+ fetch('/api/bridge', {
380
383
  method: 'POST',
381
384
  headers: { 'Content-Type': 'application/json' },
382
385
  body: JSON.stringify({ type: data.type, payload: data.payload }),
@@ -384,75 +387,17 @@
384
387
  .then(function (response) {
385
388
  if (!response.ok) {
386
389
  return response.json().then(function (err) {
387
- throw new Error(err.error || 'Bridge streaming call failed');
388
- });
389
- }
390
-
391
- var contentType = response.headers.get('content-type') || '';
392
- logMessage('info', 'SSE response content-type: ' + contentType);
393
- if (contentType.indexOf('text/event-stream') === -1) {
394
- logMessage('warn', 'Not SSE — falling back to JSON');
395
- return response.json().then(function (result) {
396
- sendToPlugin({ type: 'response', messageId: data.messageId, payload: result });
390
+ throw new Error(err.error || 'Bridge call failed');
397
391
  });
398
392
  }
399
-
400
- var reader = response.body.getReader();
401
- var decoder = new TextDecoder();
402
- var buffer = '';
403
- var finalPayload = null;
404
- var tokenCount = 0;
405
- var chunkCount = 0;
406
-
407
- function pump() {
408
- return reader.read().then(function (chunk) {
409
- if (chunk.done) {
410
- logMessage('info', 'Stream complete — ' + tokenCount + ' tokens in ' + chunkCount + ' chunks');
411
- if (finalPayload) {
412
- sendToPlugin({ type: 'response', messageId: data.messageId, payload: finalPayload });
413
- }
414
- return;
415
- }
416
-
417
- chunkCount++;
418
- buffer += decoder.decode(chunk.value, { stream: true });
419
- var lines = buffer.split('\n');
420
- buffer = lines.pop() || '';
421
- var tokensThisChunk = 0;
422
-
423
- for (var i = 0; i < lines.length; i++) {
424
- var line = lines[i];
425
- if (line.indexOf('data: ') !== 0) continue;
426
- try {
427
- var parsed = JSON.parse(line.slice(6));
428
- if (parsed.error) throw new Error(parsed.error);
429
- if (parsed.text) {
430
- tokenCount++;
431
- tokensThisChunk++;
432
- sendToPlugin({ type: 'stream_token', messageId: data.messageId, text: parsed.text });
433
- }
434
- if (parsed.done) {
435
- finalPayload = { output: parsed.output, metadata: parsed.metadata };
436
- if (parsed.metadata && parsed.metadata.cost > 0) {
437
- logMessage('cost', 'Credits used: ' + parsed.metadata.cost.toFixed(4));
438
- fetchCredits();
439
- }
440
- }
441
- } catch (e) {
442
- if (e instanceof SyntaxError) continue;
443
- throw e;
444
- }
445
- }
446
-
447
- if (tokensThisChunk > 0) {
448
- logMessage('info', 'chunk #' + chunkCount + ': ' + tokensThisChunk + ' tokens');
449
- }
450
-
451
- return pump();
452
- });
393
+ return response.json();
394
+ })
395
+ .then(function (result) {
396
+ if (result.metadata && result.metadata.cost > 0) {
397
+ logMessage('cost', 'Credits used: ' + result.metadata.cost.toFixed(4));
398
+ fetchCredits();
453
399
  }
454
-
455
- return pump();
400
+ simulateStreamInBrowser(data.messageId, result.output, result.metadata);
456
401
  })
457
402
  .catch(function (err) {
458
403
  logMessage('error', err.message);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fias/plugin-dev-harness",
3
- "version": "1.5.13",
3
+ "version": "1.5.14",
4
4
  "description": "Development harness for building and testing FIAS plugin arches locally",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",