sunpeak 0.18.7 → 0.18.12

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.
Files changed (76) hide show
  1. package/README.md +12 -0
  2. package/bin/commands/dev.mjs +3 -3
  3. package/bin/commands/inspect.mjs +4 -1
  4. package/bin/lib/sandbox-server.mjs +31 -1
  5. package/dist/chatgpt/index.cjs +1 -2
  6. package/dist/chatgpt/index.js +1 -2
  7. package/dist/claude/index.cjs +1 -2
  8. package/dist/claude/index.js +1 -2
  9. package/dist/host/chatgpt/index.cjs +1 -2
  10. package/dist/host/chatgpt/index.cjs.map +1 -1
  11. package/dist/host/chatgpt/index.js +1 -2
  12. package/dist/host/chatgpt/index.js.map +1 -1
  13. package/dist/index.cjs +93 -93
  14. package/dist/index.cjs.map +1 -1
  15. package/dist/index.js +54 -54
  16. package/dist/index.js.map +1 -1
  17. package/dist/inspector/hosts.d.ts +12 -0
  18. package/dist/inspector/index.cjs +1 -2
  19. package/dist/inspector/index.js +1 -2
  20. package/dist/{inspector-CKc58UuI.cjs → inspector-8nPV2A-z.cjs} +104 -54
  21. package/dist/inspector-8nPV2A-z.cjs.map +1 -0
  22. package/dist/{inspector-DZrN0kej.js → inspector-Cdo5BK2D.js} +103 -53
  23. package/dist/inspector-Cdo5BK2D.js.map +1 -0
  24. package/dist/mcp/index.cjs +85 -71
  25. package/dist/mcp/index.cjs.map +1 -1
  26. package/dist/mcp/index.js +79 -65
  27. package/dist/mcp/index.js.map +1 -1
  28. package/dist/{protocol-DJmRaBzO.js → protocol-BfAACnv0.js} +14 -9
  29. package/dist/{protocol-DJmRaBzO.js.map → protocol-BfAACnv0.js.map} +1 -1
  30. package/dist/{protocol-jbxhzcnS.cjs → protocol-C7kTcBr_.cjs} +14 -9
  31. package/dist/{protocol-jbxhzcnS.cjs.map → protocol-C7kTcBr_.cjs.map} +1 -1
  32. package/dist/style.css +36 -1
  33. package/dist/{use-app-BNbz1uzj.js → use-app-CfP9VypY.js} +107 -56
  34. package/dist/use-app-CfP9VypY.js.map +1 -0
  35. package/dist/{use-app-Dqh20JPP.cjs → use-app-CzcYw1Kz.cjs} +165 -114
  36. package/dist/use-app-CzcYw1Kz.cjs.map +1 -0
  37. package/package.json +7 -7
  38. package/template/README.md +12 -0
  39. package/template/dist/albums/albums.html +16 -15
  40. package/template/dist/albums/albums.json +1 -1
  41. package/template/dist/carousel/carousel.html +20 -19
  42. package/template/dist/carousel/carousel.json +1 -1
  43. package/template/dist/map/map.html +7 -6
  44. package/template/dist/map/map.json +1 -1
  45. package/template/dist/review/review.html +6 -5
  46. package/template/dist/review/review.json +1 -1
  47. package/template/node_modules/.bin/vite +2 -2
  48. package/template/node_modules/.bin/vitest +2 -2
  49. package/template/node_modules/.vite/deps/_metadata.json +4 -4
  50. package/template/node_modules/.vite-mcp/deps/@modelcontextprotocol_ext-apps.js +49 -49
  51. package/template/node_modules/.vite-mcp/deps/@modelcontextprotocol_ext-apps.js.map +1 -1
  52. package/template/node_modules/.vite-mcp/deps/@modelcontextprotocol_ext-apps_app-bridge.js +49 -49
  53. package/template/node_modules/.vite-mcp/deps/@modelcontextprotocol_ext-apps_app-bridge.js.map +1 -1
  54. package/template/node_modules/.vite-mcp/deps/@modelcontextprotocol_ext-apps_react.js +89 -89
  55. package/template/node_modules/.vite-mcp/deps/@modelcontextprotocol_ext-apps_react.js.map +1 -1
  56. package/template/node_modules/.vite-mcp/deps/@testing-library_react.js +9 -6
  57. package/template/node_modules/.vite-mcp/deps/@testing-library_react.js.map +1 -1
  58. package/template/node_modules/.vite-mcp/deps/_metadata.json +26 -26
  59. package/template/node_modules/.vite-mcp/deps/{protocol-CTflwIfG.js → protocol-B_qKkui_.js} +14 -9
  60. package/template/node_modules/.vite-mcp/deps/protocol-B_qKkui_.js.map +1 -0
  61. package/template/node_modules/.vite-mcp/deps/vitest.js +366 -128
  62. package/template/node_modules/.vite-mcp/deps/vitest.js.map +1 -1
  63. package/template/package.json +2 -2
  64. package/template/src/resources/carousel/carousel.test.tsx +16 -2
  65. package/template/src/resources/carousel/carousel.tsx +42 -14
  66. package/template/src/resources/carousel/components/carousel.tsx +20 -0
  67. package/template/src/resources/carousel/components/index.ts +1 -0
  68. package/template/src/resources/carousel/components/place-detail.tsx +153 -0
  69. package/template/tests/e2e/carousel.spec.ts +125 -0
  70. package/template/tests/live/carousel.spec.ts +2 -2
  71. package/template/tests/simulations/show-carousel.json +54 -5
  72. package/dist/inspector-CKc58UuI.cjs.map +0 -1
  73. package/dist/inspector-DZrN0kej.js.map +0 -1
  74. package/dist/use-app-BNbz1uzj.js.map +0 -1
  75. package/dist/use-app-Dqh20JPP.cjs.map +0 -1
  76. package/template/node_modules/.vite-mcp/deps/protocol-CTflwIfG.js.map +0 -1
@@ -1,9 +1,9 @@
1
1
  require("./chunk-9hOWP6kD.cjs");
2
- const require_protocol = require("./protocol-jbxhzcnS.cjs");
2
+ const require_protocol = require("./protocol-C7kTcBr_.cjs");
3
3
  let react = require("react");
4
4
  let react_jsx_runtime = require("react/jsx-runtime");
5
- //#region ../../node_modules/.pnpm/@modelcontextprotocol+ext-apps@1.3.1_@modelcontextprotocol+sdk@1.27.1_zod@4.3.6__react-_cd1fb28fd87e0bddd0a29eba0721855d/node_modules/@modelcontextprotocol/ext-apps/dist/src/app.js
6
- var W = "2026-01-26", d = "ui/open-link", h = "ui/download-file", m = "ui/message", r = "ui/notifications/size-changed", p = "ui/notifications/tool-input", z = "ui/notifications/tool-input-partial", c = "ui/notifications/tool-result", n = "ui/notifications/tool-cancelled", a = "ui/notifications/host-context-changed", o = "ui/notifications/request-teardown", s = "ui/resource-teardown", t = "ui/initialize", e = "ui/notifications/initialized", QQ = "ui/request-display-mode";
5
+ //#region ../../node_modules/.pnpm/@modelcontextprotocol+ext-apps@1.3.2_@modelcontextprotocol+sdk@1.29.0_zod@4.3.6__react-_38e5f6c50a4ca9cf3f1dffc73a60c951/node_modules/@modelcontextprotocol/ext-apps/dist/src/app.js
6
+ var E = "2026-01-26", y = "ui/open-link", u = "ui/download-file", f = "ui/message", m = "ui/notifications/size-changed", i = "ui/notifications/tool-input", z = "ui/notifications/tool-input-partial", l = "ui/notifications/tool-result", r = "ui/notifications/tool-cancelled", c = "ui/notifications/host-context-changed", p = "ui/notifications/request-teardown", n = "ui/resource-teardown", a = "ui/initialize", o = "ui/notifications/initialized", s = "ui/request-display-mode";
7
7
  var K = class {
8
8
  eventTarget;
9
9
  eventSource;
@@ -37,11 +37,11 @@ var K = class {
37
37
  onmessage;
38
38
  sessionId;
39
39
  setProtocolVersion;
40
- }, b = require_protocol.union([require_protocol.literal("light"), require_protocol.literal("dark")]).describe("Color theme preference for the host environment."), J = require_protocol.union([
40
+ }, v = require_protocol.union([require_protocol.literal("light"), require_protocol.literal("dark")]).describe("Color theme preference for the host environment."), D = require_protocol.union([
41
41
  require_protocol.literal("inline"),
42
42
  require_protocol.literal("fullscreen"),
43
43
  require_protocol.literal("pip")
44
- ]).describe("Display mode for UI presentation."), KQ = require_protocol.union([
44
+ ]).describe("Display mode for UI presentation."), $Q = require_protocol.union([
45
45
  require_protocol.literal("--color-background-primary"),
46
46
  require_protocol.literal("--color-background-secondary"),
47
47
  require_protocol.literal("--color-background-tertiary"),
@@ -118,7 +118,7 @@ var K = class {
118
118
  require_protocol.literal("--shadow-sm"),
119
119
  require_protocol.literal("--shadow-md"),
120
120
  require_protocol.literal("--shadow-lg")
121
- ]).describe("CSS variable keys available to MCP apps for theming."), GQ = require_protocol.record(KQ.describe(`Style variables for theming MCP apps.
121
+ ]).describe("CSS variable keys available to MCP apps for theming."), DQ = require_protocol.record($Q.describe(`Style variables for theming MCP apps.
122
122
 
123
123
  Individual style keys are optional - hosts may provide any subset of these values.
124
124
  Values are strings containing CSS values (colors, sizes, font stacks, etc.).
@@ -136,7 +136,7 @@ Individual style keys are optional - hosts may provide any subset of these value
136
136
  Values are strings containing CSS values (colors, sizes, font stacks, etc.).
137
137
 
138
138
  Note: This type uses \`Record<K, string | undefined>\` rather than \`Partial<Record<K, string>>\`
139
- for compatibility with Zod schema generation. Both are functionally equivalent for validation.`), VQ = require_protocol.object({
139
+ for compatibility with Zod schema generation. Both are functionally equivalent for validation.`), JQ = require_protocol.object({
140
140
  method: require_protocol.literal("ui/open-link"),
141
141
  params: require_protocol.object({ url: require_protocol.string().describe("URL to open in the host's browser") })
142
142
  }), B = require_protocol.object({ isError: require_protocol.boolean().optional().describe("True if the host failed to open the URL (e.g., due to security policy).") }).passthrough(), _ = require_protocol.object({ isError: require_protocol.boolean().optional().describe("True if the download failed (e.g., user cancelled or host denied).") }).passthrough(), O = require_protocol.object({ isError: require_protocol.boolean().optional().describe("True if the host rejected or failed to deliver the message.") }).passthrough();
@@ -157,7 +157,7 @@ var G = require_protocol.object({
157
157
  microphone: require_protocol.object({}).optional().describe("Request microphone access.\n\nMaps to Permission Policy `microphone` feature."),
158
158
  geolocation: require_protocol.object({}).optional().describe("Request geolocation access.\n\nMaps to Permission Policy `geolocation` feature."),
159
159
  clipboardWrite: require_protocol.object({}).optional().describe("Request clipboard write access.\n\nMaps to Permission Policy `clipboard-write` feature.")
160
- }), jQ = require_protocol.object({
160
+ }), GQ = require_protocol.object({
161
161
  method: require_protocol.literal("ui/notifications/size-changed"),
162
162
  params: require_protocol.object({
163
163
  width: require_protocol.number().optional().describe("New width in pixels."),
@@ -172,13 +172,13 @@ var G = require_protocol.object({
172
172
  }), A = require_protocol.object({
173
173
  method: require_protocol.literal("ui/notifications/tool-cancelled"),
174
174
  params: require_protocol.object({ reason: require_protocol.string().optional().describe("Optional reason for the cancellation (e.g., \"user action\", \"timeout\").") })
175
- }), k = require_protocol.object({ fonts: require_protocol.string().optional() }), C = require_protocol.object({
176
- variables: GQ.optional().describe("CSS variables for theming the app."),
177
- css: k.optional().describe("CSS blocks that apps can inject.")
175
+ }), b = require_protocol.object({ fonts: require_protocol.string().optional() }), k = require_protocol.object({
176
+ variables: DQ.optional().describe("CSS variables for theming the app."),
177
+ css: b.optional().describe("CSS blocks that apps can inject.")
178
178
  }), F = require_protocol.object({
179
179
  method: require_protocol.literal("ui/resource-teardown"),
180
180
  params: require_protocol.object({})
181
- }), EQ = require_protocol.record(require_protocol.string(), require_protocol.unknown()), L = require_protocol.object({
181
+ }), VQ = require_protocol.record(require_protocol.string(), require_protocol.unknown()), L = require_protocol.object({
182
182
  text: require_protocol.object({}).optional().describe("Host supports text content blocks."),
183
183
  image: require_protocol.object({}).optional().describe("Host supports image content blocks."),
184
184
  audio: require_protocol.object({}).optional().describe("Host supports audio content blocks."),
@@ -188,7 +188,7 @@ var G = require_protocol.object({
188
188
  }), WQ = require_protocol.object({
189
189
  method: require_protocol.literal("ui/notifications/request-teardown"),
190
190
  params: require_protocol.object({}).optional()
191
- }), x = require_protocol.object({
191
+ }), C = require_protocol.object({
192
192
  experimental: require_protocol.object({}).optional().describe("Experimental features (structure TBD)."),
193
193
  openLinks: require_protocol.object({}).optional().describe("Host supports opening external URLs."),
194
194
  downloadFile: require_protocol.object({}).optional().describe("Host supports file downloads via ui/download-file."),
@@ -201,14 +201,14 @@ var G = require_protocol.object({
201
201
  }).optional().describe("Sandbox configuration applied by the host."),
202
202
  updateModelContext: L.optional().describe("Host accepts context updates (ui/update-model-context) to be included in the model's context for future turns."),
203
203
  message: L.optional().describe("Host supports receiving content messages (ui/message) from the view.")
204
- }), g = require_protocol.object({
204
+ }), x = require_protocol.object({
205
205
  experimental: require_protocol.object({}).optional().describe("Experimental features (structure TBD)."),
206
206
  tools: require_protocol.object({ listChanged: require_protocol.boolean().optional().describe("App supports tools/list_changed notifications.") }).optional().describe("App exposes MCP-style tools that the host can call."),
207
- availableDisplayModes: require_protocol.array(J).optional().describe("Display modes the app supports.")
208
- }), zQ = require_protocol.object({
207
+ availableDisplayModes: require_protocol.array(D).optional().describe("Display modes the app supports.")
208
+ }), NQ = require_protocol.object({
209
209
  method: require_protocol.literal("ui/notifications/initialized"),
210
210
  params: require_protocol.object({}).optional()
211
- }), LQ = require_protocol.object({
211
+ }), jQ = require_protocol.object({
212
212
  csp: G.optional().describe("Content Security Policy configuration for UI resources."),
213
213
  permissions: V.optional().describe("Sandbox permissions requested by the UI resource."),
214
214
  domain: require_protocol.string().optional().describe(`Dedicated origin for view sandbox.
@@ -227,20 +227,20 @@ Boolean requesting whether a visible border and background is provided by the ho
227
227
  - \`true\`: request visible border + background
228
228
  - \`false\`: request no visible border + background
229
229
  - omitted: host decides border`)
230
- }), BQ = require_protocol.object({
230
+ }), EQ = require_protocol.object({
231
231
  method: require_protocol.literal("ui/request-display-mode"),
232
- params: require_protocol.object({ mode: J.describe("The display mode being requested.") })
233
- }), P = require_protocol.object({ mode: J.describe("The display mode that was actually set. May differ from requested if not supported.") }).passthrough(), S = require_protocol.union([require_protocol.literal("model"), require_protocol.literal("app")]).describe("Tool visibility scope - who can access the tool."), _Q = require_protocol.object({
232
+ params: require_protocol.object({ mode: D.describe("The display mode being requested.") })
233
+ }), P = require_protocol.object({ mode: D.describe("The display mode that was actually set. May differ from requested if not supported.") }).passthrough(), g = require_protocol.union([require_protocol.literal("model"), require_protocol.literal("app")]).describe("Tool visibility scope - who can access the tool."), zQ = require_protocol.object({
234
234
  resourceUri: require_protocol.string().optional(),
235
- visibility: require_protocol.array(S).optional().describe(`Who can access this tool. Default: ["model", "app"]
235
+ visibility: require_protocol.array(g).optional().describe(`Who can access this tool. Default: ["model", "app"]
236
236
  - "model": Tool visible to and callable by the agent
237
237
  - "app": Tool callable by the app from this server only`)
238
238
  });
239
239
  require_protocol.object({ mimeTypes: require_protocol.array(require_protocol.string()).optional().describe("Array of supported MIME types for UI resources.\nMust include `\"text/html;profile=mcp-app\"` for MCP Apps support.") });
240
- var OQ = require_protocol.object({
240
+ var LQ = require_protocol.object({
241
241
  method: require_protocol.literal("ui/download-file"),
242
242
  params: require_protocol.object({ contents: require_protocol.array(require_protocol.union([require_protocol.EmbeddedResourceSchema, require_protocol.ResourceLinkSchema])).describe("Resource contents to download — embedded (inline data) or linked (host fetches). Uses standard MCP resource types.") })
243
- }), IQ = require_protocol.object({
243
+ }), BQ = require_protocol.object({
244
244
  method: require_protocol.literal("ui/message"),
245
245
  params: require_protocol.object({
246
246
  role: require_protocol.literal("user").describe("Message role, currently only \"user\" is supported."),
@@ -264,10 +264,10 @@ var q = require_protocol.object({
264
264
  id: require_protocol.RequestIdSchema.optional().describe("JSON-RPC id of the tools/call request."),
265
265
  tool: require_protocol.ToolSchema.describe("Tool definition including name, inputSchema, etc.")
266
266
  }).optional().describe("Metadata of the tool call that instantiated this App."),
267
- theme: b.optional().describe("Current color theme preference."),
268
- styles: C.optional().describe("Style configuration for theming the app."),
269
- displayMode: J.optional().describe("How the UI is currently displayed."),
270
- availableDisplayModes: require_protocol.array(J).optional().describe("Display modes the host supports."),
267
+ theme: v.optional().describe("Current color theme preference."),
268
+ styles: k.optional().describe("Style configuration for theming the app."),
269
+ displayMode: D.optional().describe("How the UI is currently displayed."),
270
+ availableDisplayModes: require_protocol.array(D).optional().describe("Display modes the host supports."),
271
271
  containerDimensions: require_protocol.union([require_protocol.object({ height: require_protocol.number().describe("Fixed container height in pixels.") }), require_protocol.object({ maxHeight: require_protocol.union([require_protocol.number(), require_protocol._undefined()]).optional().describe("Maximum container height in pixels.") })]).and(require_protocol.union([require_protocol.object({ width: require_protocol.number().describe("Fixed container width in pixels.") }), require_protocol.object({ maxWidth: require_protocol.union([require_protocol.number(), require_protocol._undefined()]).optional().describe("Maximum container width in pixels.") })])).optional().describe(`Container dimensions. Represents the dimensions of the iframe or other
272
272
  container holding the app. Specify either width or maxWidth, and either height or maxHeight.`),
273
273
  locale: require_protocol.string().optional().describe("User's language and region preference in BCP 47 format."),
@@ -291,44 +291,44 @@ container holding the app. Specify either width or maxWidth, and either height o
291
291
  }).passthrough(), R = require_protocol.object({
292
292
  method: require_protocol.literal("ui/notifications/host-context-changed"),
293
293
  params: T.describe("Partial context update containing only changed fields.")
294
- }), AQ = require_protocol.object({
294
+ }), OQ = require_protocol.object({
295
295
  method: require_protocol.literal("ui/update-model-context"),
296
296
  params: require_protocol.object({
297
297
  content: require_protocol.array(require_protocol.ContentBlockSchema).optional().describe("Context content blocks (text, image, etc.)."),
298
298
  structuredContent: require_protocol.record(require_protocol.string(), require_protocol.unknown().describe("Structured content for machine-readable context data.")).optional().describe("Structured content for machine-readable context data.")
299
299
  })
300
- }), FQ = require_protocol.object({
300
+ }), IQ = require_protocol.object({
301
301
  method: require_protocol.literal("ui/initialize"),
302
302
  params: require_protocol.object({
303
303
  appInfo: require_protocol.ImplementationSchema.describe("App identification (name and version)."),
304
- appCapabilities: g.describe("Features and capabilities this app provides."),
304
+ appCapabilities: x.describe("Features and capabilities this app provides."),
305
305
  protocolVersion: require_protocol.string().describe("Protocol version this app supports.")
306
306
  })
307
307
  }), U = require_protocol.object({
308
308
  protocolVersion: require_protocol.string().describe("Negotiated protocol version string (e.g., \"2025-11-21\")."),
309
309
  hostInfo: require_protocol.ImplementationSchema.describe("Host application identification and version."),
310
- hostCapabilities: x.describe("Features and capabilities provided by the host."),
310
+ hostCapabilities: C.describe("Features and capabilities provided by the host."),
311
311
  hostContext: T.describe("Rich context about the host environment.")
312
312
  }).passthrough();
313
- function PQ() {
313
+ function wQ() {
314
314
  let X = document.documentElement.getAttribute("data-theme");
315
315
  if (X === "dark" || X === "light") return X;
316
316
  return document.documentElement.classList.contains("dark") ? "dark" : "light";
317
317
  }
318
- function qQ(X) {
318
+ function AQ(X) {
319
319
  let Y = document.documentElement;
320
320
  Y.setAttribute("data-theme", X), Y.style.colorScheme = X;
321
321
  }
322
- function TQ(X, Y = document.documentElement) {
322
+ function FQ(X, Y = document.documentElement) {
323
323
  for (let [Z, $] of Object.entries(X)) if ($ !== void 0) Y.style.setProperty(Z, $);
324
324
  }
325
- function RQ(X) {
325
+ function PQ(X) {
326
326
  if (document.getElementById("__mcp-host-fonts")) return;
327
327
  let Z = document.createElement("style");
328
328
  Z.id = "__mcp-host-fonts", Z.textContent = X, document.head.appendChild(Z);
329
329
  }
330
- var MX = "ui/resourceUri", vX = "text/html;profile=mcp-app";
331
- var gQ = class extends require_protocol.Protocol {
330
+ var RX = "ui/resourceUri", UX = "text/html;profile=mcp-app";
331
+ var kQ = class extends require_protocol.Protocol {
332
332
  _appInfo;
333
333
  _capabilities;
334
334
  options;
@@ -474,20 +474,20 @@ var gQ = class extends require_protocol.Protocol {
474
474
  if (X) return;
475
475
  X = !0, requestAnimationFrame(() => {
476
476
  X = !1;
477
- let D = document.documentElement, y = D.style.width, u = D.style.height;
478
- D.style.width = "fit-content", D.style.height = "max-content";
479
- let H = D.getBoundingClientRect();
480
- D.style.width = y, D.style.height = u;
481
- let f = window.innerWidth - D.clientWidth, j = Math.ceil(H.width + f), E = Math.ceil(H.height);
482
- if (j !== Y || E !== Z) Y = j, Z = E, this.sendSizeChanged({
477
+ let J = document.documentElement, S = J.style.height;
478
+ J.style.height = "max-content";
479
+ let N = Math.ceil(J.getBoundingClientRect().height);
480
+ J.style.height = S;
481
+ let j = Math.ceil(window.innerWidth);
482
+ if (j !== Y || N !== Z) Y = j, Z = N, this.sendSizeChanged({
483
483
  width: j,
484
- height: E
484
+ height: N
485
485
  });
486
486
  });
487
487
  };
488
488
  $();
489
- let N = new ResizeObserver($);
490
- return N.observe(document.documentElement), N.observe(document.body), () => N.disconnect();
489
+ let W = new ResizeObserver($);
490
+ return W.observe(document.documentElement), W.observe(document.body), () => W.disconnect();
491
491
  }
492
492
  async connect(X = new K(window.parent, window.parent), Y) {
493
493
  if (this.transport) throw Error("App is already connected. Call close() before connecting again.");
@@ -498,7 +498,7 @@ var gQ = class extends require_protocol.Protocol {
498
498
  params: {
499
499
  appCapabilities: this._capabilities,
500
500
  appInfo: this._appInfo,
501
- protocolVersion: W
501
+ protocolVersion: E
502
502
  }
503
503
  }, U, Y);
504
504
  if (Z === void 0) throw Error(`Server sent invalid initialize result: ${Z}`);
@@ -519,6 +519,11 @@ var gQ = class extends require_protocol.Protocol {
519
519
  *
520
520
  * The provider preserves the App instance across React Fast Refresh (HMR)
521
521
  * by storing it at module scope, matching the previous useApp() behavior.
522
+ *
523
+ * Connection resilience: if the initial PostMessage handshake doesn't complete
524
+ * within a timeout, the provider automatically retries with exponential backoff.
525
+ * This handles race conditions where the host iframe bridge isn't ready when the
526
+ * app first mounts (common on first load in ChatGPT and Claude).
522
527
  */
523
528
  var defaultState = {
524
529
  app: null,
@@ -528,6 +533,58 @@ var defaultState = {
528
533
  var AppContext = (0, react.createContext)(defaultState);
529
534
  var _app = null;
530
535
  var _connecting = null;
536
+ /** Timeout for a single connection attempt (ms). */
537
+ var CONNECT_TIMEOUT_MS = 5e3;
538
+ /** Maximum number of retry attempts before giving up. */
539
+ var MAX_RETRIES = 3;
540
+ /** Base delay for exponential backoff between retries (ms). */
541
+ var RETRY_BASE_DELAY_MS = 500;
542
+ /**
543
+ * Race a promise against a timeout. Rejects with a TimeoutError if the
544
+ * promise doesn't settle within `ms` milliseconds.
545
+ */
546
+ function withTimeout(promise, ms) {
547
+ return new Promise((resolve, reject) => {
548
+ const timer = setTimeout(() => reject(/* @__PURE__ */ new Error("Connection timed out")), ms);
549
+ promise.then((v) => {
550
+ clearTimeout(timer);
551
+ resolve(v);
552
+ }, (e) => {
553
+ clearTimeout(timer);
554
+ reject(e);
555
+ });
556
+ });
557
+ }
558
+ /**
559
+ * Attempt to connect to the host with timeout and retries.
560
+ * Each attempt creates a fresh transport + App instance so stale PostMessage
561
+ * listeners from a previous failed attempt don't interfere.
562
+ */
563
+ async function connectWithRetry(appInfo, capabilities, onAppCreated) {
564
+ let lastError = null;
565
+ for (let attempt = 0; attempt <= MAX_RETRIES; attempt++) {
566
+ if (attempt > 0) {
567
+ const delay = RETRY_BASE_DELAY_MS * 2 ** (attempt - 1);
568
+ await new Promise((r) => setTimeout(r, delay));
569
+ }
570
+ let transport = null;
571
+ try {
572
+ transport = new K(window.parent, window.parent);
573
+ const newApp = new kQ(appInfo, capabilities);
574
+ onAppCreated?.(newApp);
575
+ await withTimeout(newApp.connect(transport), CONNECT_TIMEOUT_MS);
576
+ return newApp;
577
+ } catch (err) {
578
+ if (transport) try {
579
+ await transport.close();
580
+ } catch {}
581
+ lastError = err instanceof Error ? err : /* @__PURE__ */ new Error("Connection failed");
582
+ if (attempt < MAX_RETRIES) console.warn(`[sunpeak] Connection attempt ${attempt + 1}/${MAX_RETRIES + 1} failed, retrying...`, lastError.message);
583
+ }
584
+ }
585
+ console.error("[sunpeak] All connection attempts failed. Try refreshing the page or opening a new chat.\nTroubleshooting: https://sunpeak.ai/docs/guides/troubleshooting");
586
+ throw lastError ?? /* @__PURE__ */ new Error("Failed to connect");
587
+ }
531
588
  function AppProvider({ appInfo, capabilities, onAppCreated, children }) {
532
589
  const [state, setState] = (0, react.useState)(() => _app ? {
533
590
  app: _app,
@@ -546,15 +603,9 @@ function AppProvider({ appInfo, capabilities, onAppCreated, children }) {
546
603
  cancelled = true;
547
604
  };
548
605
  }
549
- if (!_connecting) _connecting = (async () => {
550
- const transport = new K(window.parent, window.parent);
551
- const newApp = new gQ(appInfo, capabilities ?? {});
552
- onAppCreated?.(newApp);
553
- await newApp.connect(transport);
554
- _app = newApp;
555
- return newApp;
556
- })();
606
+ if (!_connecting) _connecting = connectWithRetry(appInfo, capabilities ?? {}, onAppCreated);
557
607
  _connecting.then((connectedApp) => {
608
+ _app = connectedApp;
558
609
  if (!cancelled) setState({
559
610
  app: connectedApp,
560
611
  isConnected: true,
@@ -639,6 +690,18 @@ Object.defineProperty(exports, "C", {
639
690
  return C;
640
691
  }
641
692
  });
693
+ Object.defineProperty(exports, "D", {
694
+ enumerable: true,
695
+ get: function() {
696
+ return D;
697
+ }
698
+ });
699
+ Object.defineProperty(exports, "E", {
700
+ enumerable: true,
701
+ get: function() {
702
+ return E;
703
+ }
704
+ });
642
705
  Object.defineProperty(exports, "EQ", {
643
706
  enumerable: true,
644
707
  get: function() {
@@ -663,6 +726,12 @@ Object.defineProperty(exports, "G", {
663
726
  return G;
664
727
  }
665
728
  });
729
+ Object.defineProperty(exports, "GQ", {
730
+ enumerable: true,
731
+ get: function() {
732
+ return GQ;
733
+ }
734
+ });
666
735
  Object.defineProperty(exports, "I", {
667
736
  enumerable: true,
668
737
  get: function() {
@@ -675,10 +744,10 @@ Object.defineProperty(exports, "IQ", {
675
744
  return IQ;
676
745
  }
677
746
  });
678
- Object.defineProperty(exports, "J", {
747
+ Object.defineProperty(exports, "JQ", {
679
748
  enumerable: true,
680
749
  get: function() {
681
- return J;
750
+ return JQ;
682
751
  }
683
752
  });
684
753
  Object.defineProperty(exports, "K", {
@@ -699,10 +768,10 @@ Object.defineProperty(exports, "LQ", {
699
768
  return LQ;
700
769
  }
701
770
  });
702
- Object.defineProperty(exports, "MX", {
771
+ Object.defineProperty(exports, "NQ", {
703
772
  enumerable: true,
704
773
  get: function() {
705
- return MX;
774
+ return NQ;
706
775
  }
707
776
  });
708
777
  Object.defineProperty(exports, "O", {
@@ -729,28 +798,16 @@ Object.defineProperty(exports, "PQ", {
729
798
  return PQ;
730
799
  }
731
800
  });
732
- Object.defineProperty(exports, "QQ", {
733
- enumerable: true,
734
- get: function() {
735
- return QQ;
736
- }
737
- });
738
801
  Object.defineProperty(exports, "R", {
739
802
  enumerable: true,
740
803
  get: function() {
741
804
  return R;
742
805
  }
743
806
  });
744
- Object.defineProperty(exports, "RQ", {
807
+ Object.defineProperty(exports, "RX", {
745
808
  enumerable: true,
746
809
  get: function() {
747
- return RQ;
748
- }
749
- });
750
- Object.defineProperty(exports, "S", {
751
- enumerable: true,
752
- get: function() {
753
- return S;
810
+ return RX;
754
811
  }
755
812
  });
756
813
  Object.defineProperty(exports, "T", {
@@ -759,16 +816,16 @@ Object.defineProperty(exports, "T", {
759
816
  return T;
760
817
  }
761
818
  });
762
- Object.defineProperty(exports, "TQ", {
819
+ Object.defineProperty(exports, "U", {
763
820
  enumerable: true,
764
821
  get: function() {
765
- return TQ;
822
+ return U;
766
823
  }
767
824
  });
768
- Object.defineProperty(exports, "U", {
825
+ Object.defineProperty(exports, "UX", {
769
826
  enumerable: true,
770
827
  get: function() {
771
- return U;
828
+ return UX;
772
829
  }
773
830
  });
774
831
  Object.defineProperty(exports, "V", {
@@ -783,12 +840,6 @@ Object.defineProperty(exports, "VQ", {
783
840
  return VQ;
784
841
  }
785
842
  });
786
- Object.defineProperty(exports, "W", {
787
- enumerable: true,
788
- get: function() {
789
- return W;
790
- }
791
- });
792
843
  Object.defineProperty(exports, "WQ", {
793
844
  enumerable: true,
794
845
  get: function() {
@@ -801,12 +852,6 @@ Object.defineProperty(exports, "_", {
801
852
  return _;
802
853
  }
803
854
  });
804
- Object.defineProperty(exports, "_Q", {
805
- enumerable: true,
806
- get: function() {
807
- return _Q;
808
- }
809
- });
810
855
  Object.defineProperty(exports, "a", {
811
856
  enumerable: true,
812
857
  get: function() {
@@ -825,46 +870,46 @@ Object.defineProperty(exports, "c", {
825
870
  return c;
826
871
  }
827
872
  });
828
- Object.defineProperty(exports, "d", {
873
+ Object.defineProperty(exports, "f", {
829
874
  enumerable: true,
830
875
  get: function() {
831
- return d;
876
+ return f;
832
877
  }
833
878
  });
834
- Object.defineProperty(exports, "e", {
879
+ Object.defineProperty(exports, "g", {
835
880
  enumerable: true,
836
881
  get: function() {
837
- return e;
882
+ return g;
838
883
  }
839
884
  });
840
- Object.defineProperty(exports, "g", {
885
+ Object.defineProperty(exports, "i", {
841
886
  enumerable: true,
842
887
  get: function() {
843
- return g;
888
+ return i;
844
889
  }
845
890
  });
846
- Object.defineProperty(exports, "gQ", {
891
+ Object.defineProperty(exports, "jQ", {
847
892
  enumerable: true,
848
893
  get: function() {
849
- return gQ;
894
+ return jQ;
850
895
  }
851
896
  });
852
- Object.defineProperty(exports, "h", {
897
+ Object.defineProperty(exports, "k", {
853
898
  enumerable: true,
854
899
  get: function() {
855
- return h;
900
+ return k;
856
901
  }
857
902
  });
858
- Object.defineProperty(exports, "jQ", {
903
+ Object.defineProperty(exports, "kQ", {
859
904
  enumerable: true,
860
905
  get: function() {
861
- return jQ;
906
+ return kQ;
862
907
  }
863
908
  });
864
- Object.defineProperty(exports, "k", {
909
+ Object.defineProperty(exports, "l", {
865
910
  enumerable: true,
866
911
  get: function() {
867
- return k;
912
+ return l;
868
913
  }
869
914
  });
870
915
  Object.defineProperty(exports, "m", {
@@ -897,12 +942,6 @@ Object.defineProperty(exports, "q", {
897
942
  return q;
898
943
  }
899
944
  });
900
- Object.defineProperty(exports, "qQ", {
901
- enumerable: true,
902
- get: function() {
903
- return qQ;
904
- }
905
- });
906
945
  Object.defineProperty(exports, "r", {
907
946
  enumerable: true,
908
947
  get: function() {
@@ -915,10 +954,10 @@ Object.defineProperty(exports, "s", {
915
954
  return s;
916
955
  }
917
956
  });
918
- Object.defineProperty(exports, "t", {
957
+ Object.defineProperty(exports, "u", {
919
958
  enumerable: true,
920
959
  get: function() {
921
- return t;
960
+ return u;
922
961
  }
923
962
  });
924
963
  Object.defineProperty(exports, "useApp", {
@@ -927,10 +966,10 @@ Object.defineProperty(exports, "useApp", {
927
966
  return useApp;
928
967
  }
929
968
  });
930
- Object.defineProperty(exports, "vX", {
969
+ Object.defineProperty(exports, "v", {
931
970
  enumerable: true,
932
971
  get: function() {
933
- return vX;
972
+ return v;
934
973
  }
935
974
  });
936
975
  Object.defineProperty(exports, "w", {
@@ -939,12 +978,24 @@ Object.defineProperty(exports, "w", {
939
978
  return w;
940
979
  }
941
980
  });
981
+ Object.defineProperty(exports, "wQ", {
982
+ enumerable: true,
983
+ get: function() {
984
+ return wQ;
985
+ }
986
+ });
942
987
  Object.defineProperty(exports, "x", {
943
988
  enumerable: true,
944
989
  get: function() {
945
990
  return x;
946
991
  }
947
992
  });
993
+ Object.defineProperty(exports, "y", {
994
+ enumerable: true,
995
+ get: function() {
996
+ return y;
997
+ }
998
+ });
948
999
  Object.defineProperty(exports, "z", {
949
1000
  enumerable: true,
950
1001
  get: function() {
@@ -958,4 +1009,4 @@ Object.defineProperty(exports, "zQ", {
958
1009
  }
959
1010
  });
960
1011
 
961
- //# sourceMappingURL=use-app-Dqh20JPP.cjs.map
1012
+ //# sourceMappingURL=use-app-CzcYw1Kz.cjs.map