this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: add widget support to JS client library

Add widget_update and widget_clear message handling to _handleMessage,
onWidgetUpdate/onWidgetClear callbacks to constructor options, and
sendWidgetEvent method for sending widget events to the worker.
Update TypeScript declarations with corresponding interfaces and types.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

+55
+24
client/ocaml-worker.d.ts
··· 126 126 mime_vals: MimeVal[]; 127 127 } 128 128 129 + export interface WidgetUpdateMessage { 130 + type: string; 131 + widget_id: string; 132 + view: any; 133 + } 134 + 135 + export interface WidgetClearMessage { 136 + type: string; 137 + widget_id: string; 138 + } 139 + 129 140 export interface OcamlWorkerOptions { 130 141 /** Timeout in milliseconds (default: 30000) */ 131 142 timeout?: number; 132 143 /** Callback for incremental output after each phrase */ 133 144 onOutputAt?: (output: OutputAt) => void; 145 + /** Callback for widget view updates */ 146 + onWidgetUpdate?: (msg: WidgetUpdateMessage) => void; 147 + /** Callback for widget clear events */ 148 + onWidgetClear?: (msg: WidgetClearMessage) => void; 134 149 } 135 150 136 151 export class OcamlWorker { ··· 193 208 * @param envId - Environment ID 194 209 */ 195 210 destroyEnv(envId: string): Promise<EnvResult>; 211 + 212 + /** 213 + * Send a widget event to the worker. 214 + * @param widgetId - Widget identifier 215 + * @param handlerId - Handler identifier within the widget 216 + * @param eventType - DOM event type (e.g., 'input', 'click') 217 + * @param value - Input value if applicable 218 + */ 219 + sendWidgetEvent(widgetId: string, handlerId: string, eventType: string, value?: string | null): void; 196 220 197 221 /** 198 222 * Terminate the worker.
+31
client/ocaml-worker.js
··· 145 145 this.worker = new Worker(blobUrl); 146 146 this.timeout = options.timeout || 30000; 147 147 this.onOutputAt = options.onOutputAt || null; 148 + this.onWidgetUpdate = options.onWidgetUpdate || null; 149 + this.onWidgetClear = options.onWidgetClear || null; 148 150 this.cellIdCounter = 0; 149 151 this.pendingRequests = new Map(); 150 152 this.readyPromise = null; ··· 218 220 case 'env_created': 219 221 case 'env_destroyed': 220 222 this._resolveRequest(msg.env_id, msg); 223 + break; 224 + 225 + case 'widget_update': 226 + if (this.onWidgetUpdate) { 227 + this.onWidgetUpdate(msg); 228 + } 229 + break; 230 + 231 + case 'widget_clear': 232 + if (this.onWidgetClear) { 233 + this.onWidgetClear(msg); 234 + } 221 235 break; 222 236 223 237 default: ··· 426 440 type: 'destroy_env', 427 441 env_id: envId, 428 442 }, envId); 443 + } 444 + 445 + /** 446 + * Send a widget event to the worker. 447 + * @param {string} widgetId - Widget identifier 448 + * @param {string} handlerId - Handler identifier within the widget 449 + * @param {string} eventType - DOM event type (e.g., 'input', 'click') 450 + * @param {string|null} [value=null] - Input value if applicable 451 + */ 452 + sendWidgetEvent(widgetId, handlerId, eventType, value = null) { 453 + this.worker.postMessage(JSON.stringify({ 454 + type: 'widget_event', 455 + widget_id: widgetId, 456 + handler_id: handlerId, 457 + event_type: eventType, 458 + value: value, 459 + })); 429 460 } 430 461 431 462 /**