@creature-ai/sdk 0.1.21 → 0.1.22

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.
@@ -357,6 +357,8 @@ declare class ChatGptAppHostClient extends Subscribable implements HostClient {
357
357
  private connected;
358
358
  private hasProcessedInitialData;
359
359
  private globalsHandler;
360
+ private lastToolOutputJson;
361
+ private lastWidgetStateJson;
360
362
  constructor(config: HostClientConfig);
361
363
  /**
362
364
  * Get the current client state.
@@ -372,7 +374,7 @@ declare class ChatGptAppHostClient extends Subscribable implements HostClient {
372
374
  /**
373
375
  * Disconnect from the host.
374
376
  *
375
- * Removes the globals event listener.
377
+ * Removes the globals event listener and cleanup.
376
378
  */
377
379
  disconnect(): void;
378
380
  /**
@@ -421,7 +423,8 @@ declare class ChatGptAppHostClient extends Subscribable implements HostClient {
421
423
  * Set up listener for `openai:set_globals` events.
422
424
  *
423
425
  * ChatGPT dispatches this event when tool output or widget state
424
- * changes after initial load.
426
+ * changes after initial load. Uses JSON comparison to prevent
427
+ * infinite loops from unchanged data.
425
428
  */
426
429
  private setupGlobalsListener;
427
430
  /**
@@ -9301,10 +9301,8 @@ var Subscribable = class {
9301
9301
  this.eventHandlers.set(event, handlers);
9302
9302
  }
9303
9303
  handlers.add(handler);
9304
- console.log(`[Subscribable] on "${String(event)}" registered, total handlers: ${handlers.size}`);
9305
9304
  return () => {
9306
9305
  handlers.delete(handler);
9307
- console.log(`[Subscribable] on "${String(event)}" unregistered, remaining: ${handlers.size}`);
9308
9306
  };
9309
9307
  }
9310
9308
  notifyStateChange(state, prevState) {
@@ -9312,7 +9310,6 @@ var Subscribable = class {
9312
9310
  }
9313
9311
  emit(event, ...args) {
9314
9312
  const handlers = this.eventHandlers.get(event);
9315
- console.log(`[Subscribable] emit "${String(event)}", handlers: ${handlers?.size ?? 0}`);
9316
9313
  if (handlers) {
9317
9314
  handlers.forEach((handler) => {
9318
9315
  handler(...args);
@@ -9611,6 +9608,8 @@ var ChatGptAppHostClient = class extends Subscribable {
9611
9608
  connected = false;
9612
9609
  hasProcessedInitialData = false;
9613
9610
  globalsHandler = null;
9611
+ lastToolOutputJson = null;
9612
+ lastWidgetStateJson = null;
9614
9613
  // ============================================================================
9615
9614
  // Constructor
9616
9615
  // ============================================================================
@@ -9642,7 +9641,7 @@ var ChatGptAppHostClient = class extends Subscribable {
9642
9641
  /**
9643
9642
  * Disconnect from the host.
9644
9643
  *
9645
- * Removes the globals event listener.
9644
+ * Removes the globals event listener and cleanup.
9646
9645
  */
9647
9646
  disconnect() {
9648
9647
  if (!this.connected) return;
@@ -9748,19 +9747,28 @@ var ChatGptAppHostClient = class extends Subscribable {
9748
9747
  * Set up listener for `openai:set_globals` events.
9749
9748
  *
9750
9749
  * ChatGPT dispatches this event when tool output or widget state
9751
- * changes after initial load.
9750
+ * changes after initial load. Uses JSON comparison to prevent
9751
+ * infinite loops from unchanged data.
9752
9752
  */
9753
9753
  setupGlobalsListener() {
9754
9754
  this.globalsHandler = (event) => {
9755
9755
  const customEvent = event;
9756
9756
  const globals = customEvent.detail?.globals;
9757
9757
  if (globals?.toolOutput) {
9758
- this.emit("tool-input", globals.toolOutput);
9759
- this.emit("tool-result", { structuredContent: globals.toolOutput });
9758
+ const toolOutputJson = JSON.stringify(globals.toolOutput);
9759
+ if (toolOutputJson !== this.lastToolOutputJson) {
9760
+ this.lastToolOutputJson = toolOutputJson;
9761
+ this.emit("tool-input", globals.toolOutput);
9762
+ this.emit("tool-result", { structuredContent: globals.toolOutput });
9763
+ }
9760
9764
  }
9761
9765
  if (globals?.widgetState !== void 0) {
9762
- this.setState({ widgetState: globals.widgetState });
9763
- this.emit("widget-state-change", globals.widgetState);
9766
+ const widgetStateJson = JSON.stringify(globals.widgetState);
9767
+ if (widgetStateJson !== this.lastWidgetStateJson) {
9768
+ this.lastWidgetStateJson = widgetStateJson;
9769
+ this.setState({ widgetState: globals.widgetState });
9770
+ this.emit("widget-state-change", globals.widgetState);
9771
+ }
9764
9772
  }
9765
9773
  };
9766
9774
  window.addEventListener("openai:set_globals", this.globalsHandler, { passive: true });