nitrostack 1.0.52 → 1.0.53

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nitrostack",
3
- "version": "1.0.52",
3
+ "version": "1.0.53",
4
4
  "description": "NitroStack - Build powerful MCP servers with TypeScript",
5
5
  "type": "module",
6
6
  "main": "dist/core/index.js",
@@ -108,4 +108,4 @@
108
108
  "url": "https://github.com/abhishekpanditofficial/nitrostack/issues"
109
109
  },
110
110
  "homepage": "https://nitrostack.vercel.app"
111
- }
111
+ }
@@ -11,7 +11,7 @@ interface WidgetRendererProps {
11
11
 
12
12
  export function WidgetRenderer({ uri, data, className = '' }: WidgetRendererProps) {
13
13
  const iframeRef = useRef<HTMLIFrameElement>(null);
14
-
14
+
15
15
  // Check if we're in dev mode (localhost)
16
16
  const isDevMode =
17
17
  typeof window !== 'undefined' &&
@@ -22,13 +22,33 @@ export function WidgetRenderer({ uri, data, className = '' }: WidgetRendererProp
22
22
 
23
23
  if (isDevMode) {
24
24
  // Dev mode: load from widget dev server (port 3001)
25
- // Widget URIs are like "/calculator-result" or "calculator-result"
26
- // Remove leading slash if present
27
- const widgetPath = uri.startsWith('/') ? uri.substring(1) : uri;
25
+ // Parse the widget path from various URI formats:
26
+ // - "ui://widget/calculator-result.html" -> "calculator-result"
27
+ // - "/calculator-result" -> "calculator-result"
28
+ // - "calculator-result" -> "calculator-result"
29
+ // - "/widgets/calculator-result" -> "calculator-result"
30
+
31
+ let widgetPath = uri;
32
+
33
+ // Handle ui://widget/ URIs
34
+ if (widgetPath.startsWith('ui://widget/')) {
35
+ widgetPath = widgetPath.replace('ui://widget/', '');
36
+ // Remove .html extension if present
37
+ widgetPath = widgetPath.replace(/\.html$/, '');
38
+ }
39
+ // Handle /widgets/ prefix (legacy)
40
+ else if (widgetPath.startsWith('/widgets/')) {
41
+ widgetPath = widgetPath.replace('/widgets/', '');
42
+ }
43
+ // Handle leading slash
44
+ else if (widgetPath.startsWith('/')) {
45
+ widgetPath = widgetPath.substring(1);
46
+ }
47
+
28
48
  const widgetUrl = `http://localhost:3001/${widgetPath}`;
29
-
49
+
30
50
  console.log('Loading widget in dev mode:', { uri, widgetPath, widgetUrl, data });
31
-
51
+
32
52
  // Set up onload handler BEFORE setting src
33
53
  iframeRef.current.onload = () => {
34
54
  console.log('Widget iframe loaded, posting data...');
@@ -48,7 +68,7 @@ export function WidgetRenderer({ uri, data, className = '' }: WidgetRendererProp
48
68
  }
49
69
  }, 300);
50
70
  };
51
-
71
+
52
72
  // Set src AFTER onload handler is set
53
73
  iframeRef.current.src = widgetUrl;
54
74
  } else {
@@ -63,9 +83,9 @@ export function WidgetRenderer({ uri, data, className = '' }: WidgetRendererProp
63
83
  const widgetPath = uri.startsWith('/') ? uri.substring(1) : uri;
64
84
  resourceUri = `widget://${widgetPath}`;
65
85
  }
66
-
86
+
67
87
  console.log('Loading widget in production mode:', { originalUri: uri, resourceUri, data });
68
-
88
+
69
89
  const response = await fetch(`/api/resources/${encodeURIComponent(resourceUri)}`);
70
90
  const result = await response.json();
71
91
 
@@ -88,9 +108,9 @@ export function WidgetRenderer({ uri, data, className = '' }: WidgetRendererProp
88
108
  console.warn('⚠️ Widget resource found but no content:', { resourceUri, result });
89
109
  }
90
110
  } catch (error) {
91
- console.error('❌ Failed to load widget:', {
92
- originalUri: uri,
93
- resourceUri,
111
+ console.error('❌ Failed to load widget:', {
112
+ originalUri: uri,
113
+ resourceUri,
94
114
  error: error instanceof Error ? error.message : String(error),
95
115
  stack: error instanceof Error ? error.stack : undefined
96
116
  });
@@ -102,7 +122,7 @@ export function WidgetRenderer({ uri, data, className = '' }: WidgetRendererProp
102
122
  }, [uri, data, isDevMode]);
103
123
 
104
124
  const isInChat = className?.includes('widget-in-chat');
105
-
125
+
106
126
  return (
107
127
  <iframe
108
128
  ref={iframeRef}