@runtypelabs/persona 3.35.0 → 3.36.0

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@runtypelabs/persona",
3
- "version": "3.35.0",
3
+ "version": "3.36.0",
4
4
  "description": "Themeable, pluggable streaming agent widget for websites, in plain JS with support for voice input and reasoning / tool output.",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -2,6 +2,7 @@ import { describe, it, expect, beforeEach, vi } from 'vitest';
2
2
  import { AgentWidgetClient, preferFinalStructuredContent } from './client';
3
3
  import { AgentWidgetEvent, AgentWidgetMessage } from './types';
4
4
  import { createJsonStreamParser } from './utils/formatting';
5
+ import { VERSION } from './version';
5
6
 
6
7
  describe('AgentWidgetClient - Empty Message Filtering', () => {
7
8
  let client: AgentWidgetClient;
@@ -4176,3 +4177,46 @@ describe('AgentWidgetClient - Feedback request builder', () => {
4176
4177
  expect(feedbackBodies[0].rating).toBe(5);
4177
4178
  });
4178
4179
  });
4180
+
4181
+ describe('AgentWidgetClient - version header', () => {
4182
+ function captureHeaders() {
4183
+ const headers: Array<Record<string, string>> = [];
4184
+ global.fetch = vi.fn().mockImplementation(async (_url: string, options: { headers: Record<string, string> }) => {
4185
+ headers.push(options.headers);
4186
+ const encoder = new TextEncoder();
4187
+ const stream = new ReadableStream({
4188
+ start(c) {
4189
+ c.enqueue(encoder.encode('data: {"type":"flow_complete","success":true}\n\n'));
4190
+ c.close();
4191
+ },
4192
+ });
4193
+ return { ok: true, body: stream };
4194
+ });
4195
+ return headers;
4196
+ }
4197
+
4198
+ const msg = () => ({
4199
+ messages: [{ id: 'u1', role: 'user' as const, content: 'hi', createdAt: '2025-01-01T00:00:00.000Z' }],
4200
+ });
4201
+
4202
+ it('broadcasts X-Persona-Version on the dispatch request', async () => {
4203
+ const headers = captureHeaders();
4204
+ const client = new AgentWidgetClient({ apiUrl: 'http://localhost:8000' });
4205
+
4206
+ await client.dispatch(msg(), () => undefined);
4207
+
4208
+ expect(headers[0]['X-Persona-Version']).toBe(VERSION);
4209
+ });
4210
+
4211
+ it('lets an explicit config header override the version', async () => {
4212
+ const headers = captureHeaders();
4213
+ const client = new AgentWidgetClient({
4214
+ apiUrl: 'http://localhost:8000',
4215
+ headers: { 'X-Persona-Version': 'override' },
4216
+ });
4217
+
4218
+ await client.dispatch(msg(), () => undefined);
4219
+
4220
+ expect(headers[0]['X-Persona-Version']).toBe('override');
4221
+ });
4222
+ });
package/src/client.ts CHANGED
@@ -33,6 +33,7 @@ import {
33
33
  createXmlParser
34
34
  } from "./utils/formatting";
35
35
  import { SequenceReorderBuffer } from "./utils/sequence-buffer";
36
+ import { VERSION } from "./version";
36
37
  // artifactsSidebarEnabled is used in ui.ts to gate the sidebar pane rendering;
37
38
  // artifact events are always processed here regardless of config.
38
39
 
@@ -188,6 +189,7 @@ export class AgentWidgetClient {
188
189
  this.apiUrl = config.apiUrl ?? DEFAULT_ENDPOINT;
189
190
  this.headers = {
190
191
  "Content-Type": "application/json",
192
+ "X-Persona-Version": VERSION,
191
193
  ...config.headers
192
194
  };
193
195
  this.debug = Boolean(config.debug);
@@ -355,6 +357,7 @@ export class AgentWidgetClient {
355
357
  method: 'POST',
356
358
  headers: {
357
359
  'Content-Type': 'application/json',
360
+ 'X-Persona-Version': VERSION,
358
361
  },
359
362
  body: JSON.stringify(requestBody),
360
363
  });
@@ -495,6 +498,7 @@ export class AgentWidgetClient {
495
498
  method: 'POST',
496
499
  headers: {
497
500
  'Content-Type': 'application/json',
501
+ 'X-Persona-Version': VERSION,
498
502
  },
499
503
  body: JSON.stringify(requestBody),
500
504
  });
@@ -682,6 +686,7 @@ export class AgentWidgetClient {
682
686
  method: 'POST',
683
687
  headers: {
684
688
  'Content-Type': 'application/json',
689
+ 'X-Persona-Version': VERSION,
685
690
  },
686
691
  body: JSON.stringify(chatRequest),
687
692
  signal: controller.signal,