@fias/plugin-dev-harness 1.5.12 → 1.5.13

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,37 +375,21 @@
375
375
  return;
376
376
  }
377
377
 
378
- // Live mode: call the developer API SSE endpoint directly from the
379
- // browser, matching the production PluginBridgeHost architecture.
380
- // This avoids localhost Express SSE buffering issues.
381
- fetch('/api/live-stream-config')
382
- .then(function (r) {
383
- if (!r.ok) throw new Error('Failed to get live stream config');
384
- return r.json();
385
- })
386
- .then(function (config) {
387
- return fetch(config.apiUrl + '/developer/bridge', {
388
- method: 'POST',
389
- headers: {
390
- 'Content-Type': 'application/json',
391
- Authorization: 'Bearer ' + config.authToken,
392
- 'X-Plugin-Permissions': config.permissions.join(','),
393
- },
394
- body: JSON.stringify({
395
- type: data.type,
396
- payload: Object.assign({}, data.payload, { stream: true }),
397
- }),
398
- });
399
- })
378
+ // Live mode: proxy through local Express SSE endpoint
379
+ fetch('/api/bridge/stream', {
380
+ method: 'POST',
381
+ headers: { 'Content-Type': 'application/json' },
382
+ body: JSON.stringify({ type: data.type, payload: data.payload }),
383
+ })
400
384
  .then(function (response) {
401
385
  if (!response.ok) {
402
386
  return response.json().then(function (err) {
403
- throw new Error((err.error && err.error.message) || err.error || 'Bridge streaming call failed');
387
+ throw new Error(err.error || 'Bridge streaming call failed');
404
388
  });
405
389
  }
406
390
 
407
391
  var contentType = response.headers.get('content-type') || '';
408
- logMessage('info', 'Live SSE response content-type: ' + contentType);
392
+ logMessage('info', 'SSE response content-type: ' + contentType);
409
393
  if (contentType.indexOf('text/event-stream') === -1) {
410
394
  logMessage('warn', 'Not SSE — falling back to JSON');
411
395
  return response.json().then(function (result) {
@@ -413,45 +397,42 @@
413
397
  });
414
398
  }
415
399
 
416
- // Consume SSE stream directly — same pattern as production PluginBridgeHost
417
400
  var reader = response.body.getReader();
418
401
  var decoder = new TextDecoder();
419
402
  var buffer = '';
420
- var fullOutput = '';
403
+ var finalPayload = null;
421
404
  var tokenCount = 0;
405
+ var chunkCount = 0;
422
406
 
423
407
  function pump() {
424
408
  return reader.read().then(function (chunk) {
425
409
  if (chunk.done) {
426
- logMessage('info', 'Stream complete — ' + tokenCount + ' tokens sent');
427
- sendToPlugin({
428
- type: 'response',
429
- messageId: data.messageId,
430
- payload: { output: fullOutput },
431
- });
410
+ logMessage('info', 'Stream complete — ' + tokenCount + ' tokens in ' + chunkCount + ' chunks');
411
+ if (finalPayload) {
412
+ sendToPlugin({ type: 'response', messageId: data.messageId, payload: finalPayload });
413
+ }
432
414
  return;
433
415
  }
434
416
 
417
+ chunkCount++;
435
418
  buffer += decoder.decode(chunk.value, { stream: true });
436
419
  var lines = buffer.split('\n');
437
420
  buffer = lines.pop() || '';
421
+ var tokensThisChunk = 0;
438
422
 
439
423
  for (var i = 0; i < lines.length; i++) {
440
424
  var line = lines[i];
441
425
  if (line.indexOf('data: ') !== 0) continue;
442
- var lineData = line.slice(6);
443
- if (lineData === '[DONE]') continue;
444
426
  try {
445
- var parsed = JSON.parse(lineData);
427
+ var parsed = JSON.parse(line.slice(6));
446
428
  if (parsed.error) throw new Error(parsed.error);
447
429
  if (parsed.text) {
448
- fullOutput += parsed.text;
449
430
  tokenCount++;
431
+ tokensThisChunk++;
450
432
  sendToPlugin({ type: 'stream_token', messageId: data.messageId, text: parsed.text });
451
- if (tokenCount <= 3) logMessage('info', 'stream_token #' + tokenCount + ': "' + parsed.text.substring(0, 20) + '"');
452
433
  }
453
434
  if (parsed.done) {
454
- if (parsed.output) fullOutput = parsed.output;
435
+ finalPayload = { output: parsed.output, metadata: parsed.metadata };
455
436
  if (parsed.metadata && parsed.metadata.cost > 0) {
456
437
  logMessage('cost', 'Credits used: ' + parsed.metadata.cost.toFixed(4));
457
438
  fetchCredits();
@@ -463,6 +444,10 @@
463
444
  }
464
445
  }
465
446
 
447
+ if (tokensThisChunk > 0) {
448
+ logMessage('info', 'chunk #' + chunkCount + ': ' + tokensThisChunk + ' tokens');
449
+ }
450
+
466
451
  return pump();
467
452
  });
468
453
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fias/plugin-dev-harness",
3
- "version": "1.5.12",
3
+ "version": "1.5.13",
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",