@runtypelabs/persona 1.36.1 → 1.37.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/README.md CHANGED
@@ -137,6 +137,97 @@ const chat = initAgentWidget({
137
137
  chat.clearChat()
138
138
  ```
139
139
 
140
+ #### Message Injection
141
+
142
+ Inject messages programmatically from external sources like tool call responses, system events, or third-party integrations. This is useful when local tools need to push results back into the conversation.
143
+
144
+ ```ts
145
+ const chat = initAgentWidget({
146
+ target: '#launcher-root',
147
+ config: { /* ... */ }
148
+ })
149
+
150
+ // Simple message injection
151
+ chat.injectAssistantMessage({
152
+ content: 'Here are your search results...'
153
+ });
154
+
155
+ // User message injection
156
+ chat.injectUserMessage({
157
+ content: 'Add to cart'
158
+ });
159
+
160
+ // System context injection
161
+ chat.injectSystemMessage({
162
+ content: '[Context updated]',
163
+ llmContent: 'User is viewing product page for iPhone 15 Pro'
164
+ });
165
+ ```
166
+
167
+ **Dual-Content Messages (llmContent)**
168
+
169
+ Use `llmContent` to show different content to the user versus what gets sent to the LLM. This is useful for:
170
+ - **Token efficiency**: Show rich content to users while sending concise summaries to the LLM
171
+ - **Sensitive data redaction**: Display PII to users while hiding it from the LLM
172
+ - **Context injection**: Provide detailed LLM context with minimal UI footprint
173
+
174
+ ```ts
175
+ // Example: Tool callback that injects search results
176
+ async function handleProductSearch(query: string) {
177
+ const results = await searchProducts(query);
178
+
179
+ // User sees full product details with images and prices
180
+ // LLM receives a concise summary to save tokens
181
+ chat.injectAssistantMessage({
182
+ content: `**Found ${results.length} products:**
183
+ ${results.map(p => `- ${p.name} - $${p.price} (SKU: ${p.sku})`).join('\n')}`,
184
+
185
+ llmContent: `[Search results: ${results.length} products found, price range $${results.minPrice}-$${results.maxPrice}]`
186
+ });
187
+ }
188
+
189
+ // Example: Redacting sensitive information
190
+ chat.injectAssistantMessage({
191
+ // User sees their order confirmation with details
192
+ content: `Your order #12345 has been placed!
193
+ - Card ending in 4242
194
+ - Shipping to: 123 Main St, Anytown, USA`,
195
+
196
+ // LLM only knows an order was placed (no PII)
197
+ llmContent: '[Order confirmation displayed to user]'
198
+ });
199
+ ```
200
+
201
+ **Content Priority**
202
+
203
+ When messages are sent to the API, content is resolved in this priority order:
204
+ 1. `contentParts` - Multi-modal content (images, files)
205
+ 2. `llmContent` - Explicit LLM-specific content
206
+ 3. `content` - Display content as fallback
207
+
208
+ **Streaming Updates**
209
+
210
+ For long-running operations, use the same message ID to update content:
211
+
212
+ ```ts
213
+ const messageId = 'search-123';
214
+
215
+ // Show loading state
216
+ chat.injectAssistantMessage({
217
+ id: messageId,
218
+ content: 'Searching...',
219
+ streaming: true
220
+ });
221
+
222
+ // Update with results
223
+ chat.injectAssistantMessage({
224
+ id: messageId,
225
+ content: 'Found 5 results...',
226
+ llmContent: '[5 search results]',
227
+ streaming: false
228
+ });
229
+ ```
230
+
140
231
  #### Accessing from window
141
232
 
142
233
  To access the controller globally (e.g., from browser console or external scripts), use the `windowKey` option:
@@ -305,17 +396,17 @@ type AgentWidgetMessageActionsConfig = {
305
396
  - **Copy button**: Shows a checkmark briefly after successful copy
306
397
  - **Vote buttons**: Toggle active state and are mutually exclusive (upvoting clears downvote and vice versa)
307
398
 
308
- ### Travrse adapter
399
+ ### Runtype adapter
309
400
 
310
- This package ships with a Travrse adapter by default. The proxy handles all flow configuration, keeping the client lightweight and flexible.
401
+ This package ships with a Runtype adapter by default. The proxy handles all flow configuration, keeping the client lightweight and flexible.
311
402
 
312
403
  **Flow configuration happens server-side** - you have three options:
313
404
 
314
405
  1. **Use default flow** - The proxy includes a basic streaming chat flow out of the box
315
- 2. **Reference a Travrse flow ID** - Configure flows in your Travrse dashboard and reference them by ID
406
+ 2. **Reference a Runtype flow ID** - Configure flows in your Runtype dashboard and reference them by ID
316
407
  3. **Define custom flows** - Build flow configurations directly in the proxy
317
408
 
318
- The client simply sends messages to the proxy, which constructs the full Travrse payload. This architecture allows you to:
409
+ The client simply sends messages to the proxy, which constructs the full Runtype payload. This architecture allows you to:
319
410
  - Change models/prompts without redeploying the widget
320
411
  - A/B test different flows server-side
321
412
  - Enforce security and cost controls centrally
@@ -777,8 +868,8 @@ This ensures all configuration values are set to sensible defaults while allowin
777
868
 
778
869
  | Option | Type | Description |
779
870
  | --- | --- | --- |
780
- | `apiUrl` | `string` | Proxy endpoint for your chat backend (defaults to Travrse's cloud API). |
781
- | `flowId` | `string` | Optional Travrse flow ID. If provided, the client sends it to the proxy which can use it to select a specific flow. |
871
+ | `apiUrl` | `string` | Proxy endpoint for your chat backend (defaults to Runtype's cloud API). |
872
+ | `flowId` | `string` | Optional Runtype flow ID. If provided, the client sends it to the proxy which can use it to select a specific flow. |
782
873
  | `headers` | `Record<string, string>` | Extra headers forwarded to your proxy. |
783
874
  | `copy` | `{ welcomeTitle?, welcomeSubtitle?, inputPlaceholder?, sendButtonLabel? }` | Customize user-facing text. |
784
875
  | `theme` | `{ primary?, secondary?, surface?, muted?, accent?, radiusSm?, radiusMd?, radiusLg?, radiusFull? }` | Override CSS variables for the widget. Colors: `primary` (text/UI), `secondary` (unused), `surface` (backgrounds), `muted` (secondary text), `accent` (buttons/links). Border radius: `radiusSm` (0.75rem, inputs), `radiusMd` (1rem, cards), `radiusLg` (1.5rem, panels/bubbles), `radiusFull` (9999px, pills/buttons). |
@@ -1000,7 +1091,7 @@ The parser's `processChunk` method is called for each chunk. If the content matc
1000
1091
 
1001
1092
  ### Optional proxy server
1002
1093
 
1003
- The proxy server handles flow configuration and forwards requests to Travrse. You can configure it in three ways:
1094
+ The proxy server handles flow configuration and forwards requests to Runtype. You can configure it in three ways:
1004
1095
 
1005
1096
  **Option 1: Use default flow (recommended for getting started)**
1006
1097
 
@@ -1014,7 +1105,7 @@ export default createChatProxyApp({
1014
1105
  });
1015
1106
  ```
1016
1107
 
1017
- **Option 2: Reference a Travrse flow ID**
1108
+ **Option 2: Reference a Runtype flow ID**
1018
1109
 
1019
1110
  ```ts
1020
1111
  import { createChatProxyApp } from '@runtypelabs/persona-proxy';
@@ -1022,7 +1113,7 @@ import { createChatProxyApp } from '@runtypelabs/persona-proxy';
1022
1113
  export default createChatProxyApp({
1023
1114
  path: '/api/chat/dispatch',
1024
1115
  allowedOrigins: ['https://www.example.com'],
1025
- flowId: 'flow_abc123' // Flow created in Travrse dashboard or API
1116
+ flowId: 'flow_abc123' // Flow created in Runtype dashboard or API
1026
1117
  });
1027
1118
  ```
1028
1119
 
@@ -1070,7 +1161,7 @@ export default createVercelHandler({
1070
1161
 
1071
1162
  **Environment setup:**
1072
1163
 
1073
- Add `TRAVRSE_API_KEY` to your environment. The proxy constructs the Travrse payload (including flow configuration) and streams the response back to the client.
1164
+ Add `RUNTYPE_API_KEY` to your environment. The proxy constructs the Runtype payload (including flow configuration) and streams the response back to the client.
1074
1165
 
1075
1166
  ### Development notes
1076
1167