@frontmcp/uipack 1.2.1 → 1.4.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.
Files changed (44) hide show
  1. package/adapters/index.js +1046 -698
  2. package/adapters/template-renderer.d.ts +14 -0
  3. package/adapters/template-renderer.d.ts.map +1 -1
  4. package/bridge-runtime/iife-generator.d.ts.map +1 -1
  5. package/bridge-runtime/index.js +149 -0
  6. package/component/index.d.ts +1 -0
  7. package/component/index.d.ts.map +1 -1
  8. package/component/index.js +468 -145
  9. package/component/loader.d.ts +21 -2
  10. package/component/loader.d.ts.map +1 -1
  11. package/component/renderer.d.ts +2 -2
  12. package/component/renderer.d.ts.map +1 -1
  13. package/component/transpiler.d.ts +16 -1
  14. package/component/transpiler.d.ts.map +1 -1
  15. package/component/types.d.ts +19 -0
  16. package/component/types.d.ts.map +1 -1
  17. package/component/ui-availability.d.ts +27 -0
  18. package/component/ui-availability.d.ts.map +1 -0
  19. package/esm/adapters/index.mjs +1046 -698
  20. package/esm/bridge-runtime/index.mjs +149 -0
  21. package/esm/component/index.mjs +468 -145
  22. package/esm/index.mjs +444 -109
  23. package/esm/package.json +2 -2
  24. package/esm/shell/index.mjs +420 -171
  25. package/index.d.ts +1 -1
  26. package/index.d.ts.map +1 -1
  27. package/index.js +445 -109
  28. package/package.json +2 -2
  29. package/shell/builder.d.ts.map +1 -1
  30. package/shell/data-injector.d.ts +27 -1
  31. package/shell/data-injector.d.ts.map +1 -1
  32. package/shell/index.d.ts +3 -2
  33. package/shell/index.d.ts.map +1 -1
  34. package/shell/index.js +423 -171
  35. package/shell/sizing-css.d.ts +27 -0
  36. package/shell/sizing-css.d.ts.map +1 -0
  37. package/shell/types.d.ts +102 -0
  38. package/shell/types.d.ts.map +1 -1
  39. package/types/index.d.ts +1 -1
  40. package/types/index.d.ts.map +1 -1
  41. package/types/ui-config.d.ts +105 -11
  42. package/types/ui-config.d.ts.map +1 -1
  43. package/types/ui-runtime.d.ts +23 -2
  44. package/types/ui-runtime.d.ts.map +1 -1
@@ -6,6 +6,7 @@
6
6
  * @packageDocumentation
7
7
  */
8
8
  import type { ImportResolver } from '../resolver/types';
9
+ import type { WidgetSizing } from '../shell/types';
9
10
  /**
10
11
  * Options for rendering a tool template.
11
12
  */
@@ -22,6 +23,19 @@ export interface RenderToolTemplateOptions {
22
23
  platformType?: string;
23
24
  /** Optional import resolver with CDN overrides */
24
25
  resolver?: ImportResolver;
26
+ /**
27
+ * Resource loading mode. When `'inline'` and the template is a FileSource
28
+ * `.tsx`/`.jsx`, React is bundled into the output (no esm.sh import map)
29
+ * so the widget is fully self-contained — required for hosts that block
30
+ * external script execution like Claude (#454). Default `'cdn'`.
31
+ */
32
+ resourceMode?: 'cdn' | 'inline';
33
+ /**
34
+ * Widget sizing config (preferred/min/max height, aspect-ratio, auto-resize).
35
+ * Drives the static sizing CSS + `window.__mcpWidgetSizing` injection in the
36
+ * shell, and is mirrored onto the returned `meta` as `ui/preferredHeight` etc.
37
+ */
38
+ sizing?: WidgetSizing;
25
39
  }
26
40
  /**
27
41
  * Result of rendering a tool template.
@@ -1 +1 @@
1
- {"version":3,"file":"template-renderer.d.ts","sourceRoot":"","sources":["../../src/adapters/template-renderer.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AASH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAExD;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC,gBAAgB;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,iBAAiB;IACjB,KAAK,EAAE,OAAO,CAAC;IACf,kBAAkB;IAClB,MAAM,EAAE,OAAO,CAAC;IAChB,qDAAqD;IACrD,QAAQ,EAAE,OAAO,CAAC;IAClB,4CAA4C;IAC5C,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,kDAAkD;IAClD,QAAQ,CAAC,EAAE,cAAc,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,+BAA+B;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,2BAA2B;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,mBAAmB;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,oBAAoB;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,iCAAiC;IACjC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC/B;AAsBD;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,yBAAyB,GAAG,wBAAwB,CAgF/F"}
1
+ {"version":3,"file":"template-renderer.d.ts","sourceRoot":"","sources":["../../src/adapters/template-renderer.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAGxD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAKnD;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC,gBAAgB;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,iBAAiB;IACjB,KAAK,EAAE,OAAO,CAAC;IACf,kBAAkB;IAClB,MAAM,EAAE,OAAO,CAAC;IAChB,qDAAqD;IACrD,QAAQ,EAAE,OAAO,CAAC;IAClB,4CAA4C;IAC5C,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,kDAAkD;IAClD,QAAQ,CAAC,EAAE,cAAc,CAAC;IAC1B;;;;;OAKG;IACH,YAAY,CAAC,EAAE,KAAK,GAAG,QAAQ,CAAC;IAChC;;;;OAIG;IACH,MAAM,CAAC,EAAE,YAAY,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,+BAA+B;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,2BAA2B;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,mBAAmB;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,oBAAoB;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,iCAAiC;IACjC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC/B;AAsBD;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,yBAAyB,GAAG,wBAAwB,CAyG/F"}
@@ -1 +1 @@
1
- {"version":3,"file":"iife-generator.d.ts","sourceRoot":"","sources":["../../src/bridge-runtime/iife-generator.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,uDAAuD;IACvD,QAAQ,CAAC,EAAE,CAAC,QAAQ,GAAG,UAAU,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,CAAC,EAAE,CAAC;IACvE,2BAA2B;IAC3B,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,2CAA2C;IAC3C,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,wBAAwB;IACxB,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,GAAE,oBAAyB,GAAG,MAAM,CA0G7E;AAm+BD;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,SAAS,GAAG,QAAQ,GAAG,QAAQ,GAAG,WAAW,EACvD,OAAO,GAAE,IAAI,CAAC,oBAAoB,EAAE,UAAU,CAAM,GACnD,MAAM,CAYR;AAED;;;GAGG;AACH,eAAO,MAAM,uBAAuB,QAAuB,CAAC;AAE5D;;GAEG;AACH,eAAO,MAAM,kBAAkB;;;;;CAK9B,CAAC"}
1
+ {"version":3,"file":"iife-generator.d.ts","sourceRoot":"","sources":["../../src/bridge-runtime/iife-generator.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,uDAAuD;IACvD,QAAQ,CAAC,EAAE,CAAC,QAAQ,GAAG,UAAU,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,CAAC,EAAE,CAAC;IACvE,2BAA2B;IAC3B,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,2CAA2C;IAC3C,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,wBAAwB;IACxB,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,GAAE,oBAAyB,GAAG,MAAM,CA8G7E;AAooCD;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,SAAS,GAAG,QAAQ,GAAG,QAAQ,GAAG,WAAW,EACvD,OAAO,GAAE,IAAI,CAAC,oBAAoB,EAAE,UAAU,CAAM,GACnD,MAAM,CAYR;AAED;;;GAGG;AACH,eAAO,MAAM,uBAAuB,QAAuB,CAAC;AAE5D;;GAEG;AACH,eAAO,MAAM,kBAAkB;;;;;CAK9B,CAAC"}
@@ -81,6 +81,8 @@ function generateBridgeIIFE(options = {}) {
81
81
  parts.push("});");
82
82
  parts.push("");
83
83
  parts.push("window.FrontMcpBridge = bridge;");
84
+ parts.push("");
85
+ parts.push(generateAutoResize());
84
86
  parts.push("function __showLoading() {");
85
87
  parts.push(' var root = document.getElementById("root");');
86
88
  parts.push(" if (root && !root.hasChildNodes()) {");
@@ -101,6 +103,112 @@ function generateBridgeIIFE(options = {}) {
101
103
  }
102
104
  return code;
103
105
  }
106
+ function generateAutoResize() {
107
+ return `
108
+ function __applySizingCss(sizing) {
109
+ if (typeof document === 'undefined' || !document.documentElement) return;
110
+ function toLen(v) { return typeof v === 'number' ? v + 'px' : v; }
111
+ var de = document.documentElement;
112
+ var body = document.body;
113
+ var root = document.getElementById('root');
114
+ if (sizing.preferredHeight != null) {
115
+ var ph = toLen(sizing.preferredHeight);
116
+ de.style.height = ph;
117
+ if (body) body.style.height = ph;
118
+ if (root && !root.style.minHeight) root.style.minHeight = ph;
119
+ }
120
+ if (sizing.minHeight != null) {
121
+ var mh = toLen(sizing.minHeight);
122
+ de.style.minHeight = mh;
123
+ if (body) body.style.minHeight = mh;
124
+ if (root) root.style.minHeight = mh;
125
+ }
126
+ if (sizing.maxHeight != null) {
127
+ var mx = toLen(sizing.maxHeight);
128
+ de.style.maxHeight = mx;
129
+ if (body) body.style.maxHeight = mx;
130
+ if (root) root.style.maxHeight = mx;
131
+ }
132
+ if (sizing.aspectRatio != null && root) {
133
+ root.style.aspectRatio = String(sizing.aspectRatio);
134
+ }
135
+ }
136
+
137
+ function __initAutoResize() {
138
+ if (typeof window === 'undefined') return;
139
+ // Idempotent: a re-injected IIFE must not stack observers.
140
+ if (window.__mcpAutoResizeInit) return;
141
+ window.__mcpAutoResizeInit = true;
142
+ var sizing = window.__mcpWidgetSizing;
143
+ if (!sizing || typeof sizing !== 'object') return;
144
+
145
+ // Apply CSS as a runtime fallback (the static <style> may be absent on some
146
+ // render paths). Wait for the body if it isn't ready yet.
147
+ function apply() { try { __applySizingCss(sizing); } catch (e) {} }
148
+ if (typeof document !== 'undefined' && document.readyState === 'loading') {
149
+ document.addEventListener('DOMContentLoaded', apply);
150
+ } else {
151
+ apply();
152
+ }
153
+
154
+ // Auto-resize defaults ON; opt out with autoResize:false.
155
+ if (sizing.autoResize === false) return;
156
+ if (typeof ResizeObserver === 'undefined') return;
157
+
158
+ function startObserving() {
159
+ var target = document.getElementById('root') || document.body;
160
+ if (!target) return;
161
+
162
+ var rafId = null;
163
+ var lastReported = -1;
164
+ function report() {
165
+ rafId = null;
166
+ try {
167
+ var rect = target.getBoundingClientRect();
168
+ var height = Math.ceil(rect.height);
169
+ var width = Math.ceil(rect.width);
170
+ if (height === lastReported || height <= 0) return;
171
+ lastReported = height;
172
+ var payload = { height: height, width: width };
173
+ if (sizing.aspectRatio != null) payload.aspectRatio = sizing.aspectRatio;
174
+ if (window.FrontMcpBridge && typeof window.FrontMcpBridge.setSize === 'function') {
175
+ window.FrontMcpBridge.setSize(payload).catch(function() {});
176
+ }
177
+ window.dispatchEvent(new CustomEvent('widget:resize', { detail: payload }));
178
+ } catch (e) {}
179
+ }
180
+ function schedule() {
181
+ // Debounce via rAF; fall back to setTimeout if rAF is unavailable.
182
+ if (rafId != null) return;
183
+ if (typeof requestAnimationFrame === 'function') {
184
+ rafId = requestAnimationFrame(report);
185
+ } else {
186
+ rafId = setTimeout(report, 100);
187
+ }
188
+ }
189
+
190
+ try {
191
+ // Disconnect any prior observer before creating a new one (no leaks/dupes).
192
+ if (window.__mcpResizeObserver && typeof window.__mcpResizeObserver.disconnect === 'function') {
193
+ window.__mcpResizeObserver.disconnect();
194
+ }
195
+ var ro = new ResizeObserver(function() { schedule(); });
196
+ ro.observe(target);
197
+ window.__mcpResizeObserver = ro;
198
+ } catch (e) {}
199
+ // Report once on init so the host gets an initial measurement.
200
+ schedule();
201
+ }
202
+
203
+ if (typeof document !== 'undefined' && document.readyState === 'loading') {
204
+ document.addEventListener('DOMContentLoaded', startObserving);
205
+ } else {
206
+ startObserving();
207
+ }
208
+ }
209
+ __initAutoResize();
210
+ `.trim();
211
+ }
104
212
  function generateContextDetection() {
105
213
  return `
106
214
  function detectTheme() {
@@ -208,6 +316,19 @@ var OpenAIAdapter = {
208
316
  requestDisplayMode: function(context, mode) {
209
317
  return Promise.resolve();
210
318
  },
319
+ setSize: function(context, size) {
320
+ // OpenAI Apps SDK measures DOM height itself; if a sizing API surfaces on
321
+ // window.openai, forward to it, otherwise no-op (CSS drives layout).
322
+ try {
323
+ if (window.openai && typeof window.openai.requestDisplayMode === 'function' && size && size.displayMode) {
324
+ window.openai.requestDisplayMode(size.displayMode);
325
+ }
326
+ if (window.openai && typeof window.openai.setWidgetHeight === 'function' && size && typeof size.height === 'number') {
327
+ window.openai.setWidgetHeight(size.height);
328
+ }
329
+ } catch (e) {}
330
+ return Promise.resolve();
331
+ },
211
332
  requestClose: function(context) {
212
333
  return Promise.resolve();
213
334
  }
@@ -452,6 +573,15 @@ var ExtAppsAdapter = {
452
573
  requestDisplayMode: function(context, mode) {
453
574
  return this.sendRequest('ui/setDisplayMode', { mode: mode });
454
575
  },
576
+ setSize: function(context, size) {
577
+ // FrontMCP sizing channel \u2014 parallels ui/setDisplayMode. Reports the
578
+ // measured/desired widget dimensions to the host.
579
+ return this.sendRequest('ui/setSize', {
580
+ height: size && size.height,
581
+ width: size && size.width,
582
+ aspectRatio: size && size.aspectRatio
583
+ });
584
+ },
455
585
  requestClose: function(context) {
456
586
  return this.sendRequest('ui/close', {});
457
587
  },
@@ -540,6 +670,10 @@ var ClaudeAdapter = {
540
670
  requestDisplayMode: function() {
541
671
  return Promise.resolve();
542
672
  },
673
+ setSize: function() {
674
+ // Claude measures the rendered DOM height itself \u2014 CSS-only, no reporting.
675
+ return Promise.resolve();
676
+ },
543
677
  requestClose: function() {
544
678
  return Promise.resolve();
545
679
  }
@@ -591,6 +725,9 @@ var GeminiAdapter = {
591
725
  requestDisplayMode: function() {
592
726
  return Promise.resolve();
593
727
  },
728
+ setSize: function() {
729
+ return Promise.resolve();
730
+ },
594
731
  requestClose: function() {
595
732
  return Promise.resolve();
596
733
  }
@@ -626,6 +763,9 @@ var GenericAdapter = {
626
763
  requestDisplayMode: function() {
627
764
  return Promise.resolve();
628
765
  },
766
+ setSize: function() {
767
+ return Promise.resolve();
768
+ },
629
769
  requestClose: function() {
630
770
  return Promise.resolve();
631
771
  }
@@ -860,6 +1000,15 @@ FrontMcpBridge.prototype.requestDisplayMode = function(mode) {
860
1000
  });
861
1001
  };
862
1002
 
1003
+ // Report a desired widget size to the host. \`size\` is { height?, width?, aspectRatio? }.
1004
+ // Per-adapter behaviour: Claude/generic no-op (host measures the DOM),
1005
+ // ext-apps sends ui/setSize, OpenAI forwards to its SDK when available.
1006
+ FrontMcpBridge.prototype.setSize = function(size) {
1007
+ if (!this._adapter) return Promise.reject(new Error('Not initialized'));
1008
+ if (!this._adapter.setSize) return Promise.resolve();
1009
+ return this._adapter.setSize(this._context, size || {});
1010
+ };
1011
+
863
1012
  FrontMcpBridge.prototype.requestClose = function() {
864
1013
  if (!this._adapter) return Promise.reject(new Error('Not initialized'));
865
1014
  return this._adapter.requestClose(this._context);
@@ -10,5 +10,6 @@ export type { NpmSource, FileSource, ImportSource, FunctionSource, UISource, UIC
10
10
  export { isNpmSource, isFileSource, isImportSource, isFunctionSource, FRONTMCP_META_KEY } from './types';
11
11
  export { resolveUISource, generateMountScript } from './loader';
12
12
  export { transpileReactSource, bundleFileSource, extractDefaultExportName } from './transpiler';
13
+ export type { BundleFileSourceOptions } from './transpiler';
13
14
  export { renderComponent } from './renderer';
14
15
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/component/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,YAAY,EACV,SAAS,EACT,UAAU,EACV,YAAY,EACZ,cAAc,EACd,QAAQ,EACR,QAAQ,EACR,aAAa,EACb,iBAAiB,GAClB,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,cAAc,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAGzG,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAGhE,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AAGhG,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/component/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,YAAY,EACV,SAAS,EACT,UAAU,EACV,YAAY,EACZ,cAAc,EACd,QAAQ,EACR,QAAQ,EACR,aAAa,EACb,iBAAiB,GAClB,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,cAAc,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAGzG,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAGhE,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AAChG,YAAY,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAG5D,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC"}