open-mcp-app 0.0.11 → 0.0.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.
@@ -116,6 +116,12 @@ var ChatGptWebHostClient = class _ChatGptWebHostClient extends Subscribable {
116
116
  globalsHandler = null;
117
117
  lastToolOutputJson = null;
118
118
  lastWidgetStateJson = null;
119
+ hostContext = {
120
+ theme: "light",
121
+ displayMode: "inline",
122
+ availableDisplayModes: ["inline", "pip", "fullscreen"],
123
+ platform: "web"
124
+ };
119
125
  constructor(config) {
120
126
  super();
121
127
  this.config = config;
@@ -143,10 +149,10 @@ var ChatGptWebHostClient = class _ChatGptWebHostClient extends Subscribable {
143
149
  return this.state;
144
150
  }
145
151
  /**
146
- * Get host context - returns null for ChatGPT as it doesn't use MCP Apps protocol.
152
+ * Get host context synthesized from window.openai properties.
147
153
  */
148
154
  getHostContext() {
149
- return null;
155
+ return this.hostContext;
150
156
  }
151
157
  subscribe(listener) {
152
158
  return this.subscribeToState(listener);
@@ -189,21 +195,34 @@ var ChatGptWebHostClient = class _ChatGptWebHostClient extends Subscribable {
189
195
  type: c2.type,
190
196
  text: c2.text || ""
191
197
  })),
192
- source: "ui"
198
+ source: "ui",
199
+ toolName
193
200
  };
194
201
  this.emit("tool-result", result);
195
202
  return result;
196
203
  }
197
204
  /**
198
205
  * Request a display mode change from the ChatGPT host.
206
+ * Updates internal host context and triggers re-render on success.
207
+ *
208
+ * Note: ChatGPT requires this to be called from a synchronous user event
209
+ * (e.g. click handler). Calling it programmatically on mount will warn
210
+ * and may return undefined.
199
211
  */
200
212
  async requestDisplayMode(params) {
201
213
  const openai = window.openai;
214
+ let grantedMode = params.mode;
202
215
  if (openai?.requestDisplayMode) {
203
- const result = await openai.requestDisplayMode({ mode: params.mode });
204
- return { mode: result.mode };
216
+ try {
217
+ const result = await openai.requestDisplayMode({ mode: params.mode });
218
+ if (result?.mode) {
219
+ grantedMode = result.mode;
220
+ }
221
+ } catch {
222
+ }
205
223
  }
206
- return { mode: params.mode };
224
+ this.updateHostContext({ displayMode: grantedMode });
225
+ return { mode: grantedMode };
207
226
  }
208
227
  /**
209
228
  * Log a message to the console.
@@ -305,6 +324,14 @@ var ChatGptWebHostClient = class _ChatGptWebHostClient extends Subscribable {
305
324
  this.state = { ...this.state, ...partial };
306
325
  this.notifyStateChange(this.state, prev);
307
326
  }
327
+ /**
328
+ * Merge new values into the tracked host context and trigger a re-render
329
+ * so React components see the updated displayMode / theme.
330
+ */
331
+ updateHostContext(patch) {
332
+ this.hostContext = { ...this.hostContext, ...patch };
333
+ this.setState({});
334
+ }
308
335
  /**
309
336
  * Process initial data from `window.openai`.
310
337
  */
@@ -316,10 +343,21 @@ var ChatGptWebHostClient = class _ChatGptWebHostClient extends Subscribable {
316
343
  return;
317
344
  }
318
345
  this.hasProcessedInitialData = true;
346
+ const contextPatch = {};
347
+ if (openai.displayMode) {
348
+ contextPatch.displayMode = openai.displayMode;
349
+ }
350
+ if (openai.theme) {
351
+ contextPatch.theme = openai.theme;
352
+ }
353
+ if (Object.keys(contextPatch).length > 0) {
354
+ this.hostContext = { ...this.hostContext, ...contextPatch };
355
+ }
319
356
  this.setState({ isReady: true });
320
357
  if (openai.toolOutput) {
321
358
  this.emit("tool-input", openai.toolOutput);
322
- this.emit("tool-result", { structuredContent: openai.toolOutput });
359
+ const toolName = openai.toolOutput?._toolName;
360
+ this.emit("tool-result", { structuredContent: openai.toolOutput, ...toolName && { toolName } });
323
361
  }
324
362
  if (openai.widgetState) {
325
363
  this.setState({ widgetState: openai.widgetState });
@@ -338,7 +376,8 @@ var ChatGptWebHostClient = class _ChatGptWebHostClient extends Subscribable {
338
376
  if (toolOutputJson !== this.lastToolOutputJson) {
339
377
  this.lastToolOutputJson = toolOutputJson;
340
378
  this.emit("tool-input", globals.toolOutput);
341
- this.emit("tool-result", { structuredContent: globals.toolOutput });
379
+ const toolName = globals.toolOutput?._toolName;
380
+ this.emit("tool-result", { structuredContent: globals.toolOutput, ...toolName && { toolName } });
342
381
  }
343
382
  }
344
383
  if (globals?.widgetState !== void 0) {
@@ -349,6 +388,16 @@ var ChatGptWebHostClient = class _ChatGptWebHostClient extends Subscribable {
349
388
  this.emit("widget-state-change", globals.widgetState);
350
389
  }
351
390
  }
391
+ const contextPatch = {};
392
+ if (globals?.displayMode && globals.displayMode !== this.hostContext.displayMode) {
393
+ contextPatch.displayMode = globals.displayMode;
394
+ }
395
+ if (globals?.theme && globals.theme !== this.hostContext.theme) {
396
+ contextPatch.theme = globals.theme;
397
+ }
398
+ if (Object.keys(contextPatch).length > 0) {
399
+ this.updateHostContext(contextPatch);
400
+ }
352
401
  };
353
402
  window.addEventListener("openai:set_globals", this.globalsHandler, { passive: true });
354
403
  }
@@ -9749,7 +9798,8 @@ var CreatureDesktopHostClient = class _CreatureDesktopHostClient extends Subscri
9749
9798
  content: this.extractTextContent(sdkResult.content),
9750
9799
  structuredContent: sdkResult.structuredContent,
9751
9800
  isError: sdkResult.isError,
9752
- source: "ui"
9801
+ source: "ui",
9802
+ toolName
9753
9803
  };
9754
9804
  if (sdkResult.structuredContent && typeof sdkResult.structuredContent === "object") {
9755
9805
  const sc = sdkResult.structuredContent;
@@ -10132,7 +10182,8 @@ var ClaudeDesktopHostClient = class _ClaudeDesktopHostClient extends Subscribabl
10132
10182
  content: this.extractTextContent(sdkResult.content),
10133
10183
  structuredContent: sdkResult.structuredContent,
10134
10184
  isError: sdkResult.isError,
10135
- source: "ui"
10185
+ source: "ui",
10186
+ toolName
10136
10187
  };
10137
10188
  this.emit("tool-result", result);
10138
10189
  return result;