sunpeak 0.15.4 → 0.16.2

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 (105) hide show
  1. package/README.md +53 -49
  2. package/bin/commands/build.mjs +119 -6
  3. package/bin/commands/dev.mjs +168 -27
  4. package/bin/commands/new.mjs +13 -3
  5. package/bin/commands/start.mjs +215 -0
  6. package/bin/lib/extract-resource.mjs +1 -1
  7. package/bin/lib/extract-tool.mjs +78 -0
  8. package/bin/lib/patterns.mjs +2 -26
  9. package/bin/sunpeak.js +11 -1
  10. package/dist/chatgpt/index.cjs +3 -6
  11. package/dist/chatgpt/index.cjs.map +1 -1
  12. package/dist/chatgpt/index.d.ts +1 -1
  13. package/dist/chatgpt/index.js +6 -9
  14. package/dist/claude/index.cjs +1 -1
  15. package/dist/claude/index.js +1 -1
  16. package/dist/discovery-CH80W5l9.js +217 -0
  17. package/dist/discovery-CH80W5l9.js.map +1 -0
  18. package/dist/discovery-DmB8_4QL.cjs +216 -0
  19. package/dist/discovery-DmB8_4QL.cjs.map +1 -0
  20. package/dist/{index-Cngntkp2.cjs → index-Bll1bszc.cjs} +3 -6
  21. package/dist/{index-Cngntkp2.cjs.map → index-Bll1bszc.cjs.map} +1 -1
  22. package/dist/{index-Ce_5ZIdJ.js → index-CACtnwu2.js} +3 -6
  23. package/dist/{index-Ce_5ZIdJ.js.map → index-CACtnwu2.js.map} +1 -1
  24. package/dist/{index-CutQgPzR.js → index-CLcr8IyR.js} +3 -6
  25. package/dist/index-CLcr8IyR.js.map +1 -0
  26. package/dist/{index-B0dxRJvS.cjs → index-CaQmwZJc.cjs} +3 -6
  27. package/dist/index-CaQmwZJc.cjs.map +1 -0
  28. package/dist/index.cjs +49 -6
  29. package/dist/index.cjs.map +1 -1
  30. package/dist/index.d.ts +3 -0
  31. package/dist/index.js +3405 -3362
  32. package/dist/index.js.map +1 -1
  33. package/dist/lib/discovery-cli.cjs +58 -5
  34. package/dist/lib/discovery-cli.cjs.map +1 -1
  35. package/dist/lib/discovery-cli.d.ts +3 -2
  36. package/dist/lib/discovery-cli.js +61 -8
  37. package/dist/lib/discovery-cli.js.map +1 -1
  38. package/dist/lib/discovery.d.ts +42 -43
  39. package/dist/lib/extract-tool.d.ts +12 -0
  40. package/dist/mcp/favicon.d.ts +1 -1
  41. package/dist/mcp/index.cjs +1582 -5
  42. package/dist/mcp/index.cjs.map +1 -1
  43. package/dist/mcp/index.d.ts +3 -1
  44. package/dist/mcp/index.js +1583 -6
  45. package/dist/mcp/index.js.map +1 -1
  46. package/dist/mcp/production-server.d.ts +156 -0
  47. package/dist/mcp/types.d.ts +24 -1
  48. package/dist/platform/chatgpt/index.cjs +1 -1
  49. package/dist/platform/chatgpt/index.js +1 -1
  50. package/dist/{protocol-DFbsCx7E.js → protocol-BD5jDQEx.js} +8 -1
  51. package/dist/{protocol-DFbsCx7E.js.map → protocol-BD5jDQEx.js.map} +1 -1
  52. package/dist/{protocol-CL4_Npj5.cjs → protocol-BOjXuK6l.cjs} +8 -1
  53. package/dist/{protocol-CL4_Npj5.cjs.map → protocol-BOjXuK6l.cjs.map} +1 -1
  54. package/dist/simulator/index.cjs +2 -5
  55. package/dist/simulator/index.cjs.map +1 -1
  56. package/dist/simulator/index.d.ts +1 -1
  57. package/dist/simulator/index.js +5 -8
  58. package/dist/simulator/simulator-url.d.ts +9 -9
  59. package/dist/{simulator-CxrtnguM.js → simulator-B7rw83zP.js} +9 -3
  60. package/dist/{simulator-CxrtnguM.js.map → simulator-B7rw83zP.js.map} +1 -1
  61. package/dist/{simulator-DcfQBRXE.cjs → simulator-DjZNa1MI.cjs} +9 -3
  62. package/dist/{simulator-DcfQBRXE.cjs.map → simulator-DjZNa1MI.cjs.map} +1 -1
  63. package/dist/simulator-url-CuLqtnSS.js.map +1 -1
  64. package/dist/simulator-url-rgg_KYOg.cjs.map +1 -1
  65. package/dist/types/resource-config.d.ts +7 -5
  66. package/dist/{use-app-BnoSPiUT.cjs → use-app-BpAJqzdE.cjs} +50 -21
  67. package/dist/{use-app-BnoSPiUT.cjs.map → use-app-BpAJqzdE.cjs.map} +1 -1
  68. package/dist/{use-app-D_TeaMFG.js → use-app-WOUdh1PR.js} +52 -23
  69. package/dist/{use-app-D_TeaMFG.js.map → use-app-WOUdh1PR.js.map} +1 -1
  70. package/package.json +1 -1
  71. package/template/.sunpeak/dev.tsx +8 -4
  72. package/template/.sunpeak/resource-loader.tsx +2 -1
  73. package/template/README.md +27 -22
  74. package/template/package.json +3 -1
  75. package/template/src/resources/albums/{albums-resource.test.tsx → albums.test.tsx} +1 -1
  76. package/template/src/resources/albums/{albums-resource.tsx → albums.tsx} +0 -1
  77. package/template/src/resources/carousel/{carousel-resource.test.tsx → carousel.test.tsx} +1 -1
  78. package/template/src/resources/carousel/{carousel-resource.tsx → carousel.tsx} +0 -1
  79. package/template/src/resources/index.ts +4 -4
  80. package/template/src/resources/map/{map-resource.test.tsx → map.test.tsx} +1 -1
  81. package/template/src/resources/map/{map-resource.tsx → map.tsx} +0 -1
  82. package/template/src/resources/review/{review-resource.test.tsx → review.test.tsx} +1 -1
  83. package/template/src/resources/review/{review-resource.tsx → review.tsx} +1 -2
  84. package/template/src/server.ts +17 -0
  85. package/template/src/tools/review-diff.ts +24 -0
  86. package/template/src/tools/review-post.ts +26 -0
  87. package/template/src/tools/review-purchase.ts +31 -0
  88. package/template/src/tools/show-albums.ts +22 -0
  89. package/template/src/tools/show-carousel.ts +25 -0
  90. package/template/src/tools/show-map.ts +29 -0
  91. package/template/tests/e2e/albums.spec.ts +6 -6
  92. package/template/tests/e2e/carousel.spec.ts +6 -6
  93. package/template/tests/e2e/map.spec.ts +11 -11
  94. package/template/tests/simulations/{review/review-diff-simulation.json → review-diff.json} +1 -31
  95. package/template/tests/simulations/{review/review-post-simulation.json → review-post.json} +1 -37
  96. package/template/tests/simulations/{review/review-purchase-simulation.json → review-purchase.json} +1 -38
  97. package/template/tests/simulations/{albums/albums-show-simulation.json → show-albums.json} +1 -24
  98. package/template/tests/simulations/{carousel/carousel-show-simulation.json → show-carousel.json} +1 -24
  99. package/template/tests/simulations/{map/map-show-simulation.json → show-map.json} +1 -35
  100. package/dist/discovery-CRR3SlyI.cjs +0 -156
  101. package/dist/discovery-CRR3SlyI.cjs.map +0 -1
  102. package/dist/discovery-DzV3HLXs.js +0 -157
  103. package/dist/discovery-DzV3HLXs.js.map +0 -1
  104. package/dist/index-B0dxRJvS.cjs.map +0 -1
  105. package/dist/index-CutQgPzR.js.map +0 -1
@@ -7,7 +7,7 @@ for (const host of hosts) {
7
7
  test.describe(`Map Resource [${host}]`, () => {
8
8
  test.describe('Light Mode', () => {
9
9
  test('should render map container with correct styles', async ({ page }) => {
10
- await page.goto(createSimulatorUrl({ simulation: 'map-show', theme: 'light', host }));
10
+ await page.goto(createSimulatorUrl({ simulation: 'show-map', theme: 'light', host }));
11
11
 
12
12
  const iframe = page.frameLocator('iframe');
13
13
  const mapContainer = iframe.locator('.antialiased.w-full.overflow-hidden').first();
@@ -26,7 +26,7 @@ for (const host of hosts) {
26
26
  test('should have rounded border in inline mode', async ({ page }) => {
27
27
  await page.goto(
28
28
  createSimulatorUrl({
29
- simulation: 'map-show',
29
+ simulation: 'show-map',
30
30
  theme: 'light',
31
31
  displayMode: 'inline',
32
32
  host,
@@ -52,7 +52,7 @@ for (const host of hosts) {
52
52
  test('should have fullscreen expand button in inline mode', async ({ page }) => {
53
53
  await page.goto(
54
54
  createSimulatorUrl({
55
- simulation: 'map-show',
55
+ simulation: 'show-map',
56
56
  theme: 'light',
57
57
  displayMode: 'inline',
58
58
  host,
@@ -83,7 +83,7 @@ for (const host of hosts) {
83
83
  }
84
84
  });
85
85
 
86
- await page.goto(createSimulatorUrl({ simulation: 'map-show', theme: 'light', host }));
86
+ await page.goto(createSimulatorUrl({ simulation: 'show-map', theme: 'light', host }));
87
87
 
88
88
  const iframe = page.frameLocator('iframe');
89
89
  const mapContainer = iframe.locator('.antialiased.w-full.overflow-hidden').first();
@@ -103,7 +103,7 @@ for (const host of hosts) {
103
103
 
104
104
  test.describe('Dark Mode', () => {
105
105
  test('should render map container with correct styles', async ({ page }) => {
106
- await page.goto(createSimulatorUrl({ simulation: 'map-show', theme: 'dark', host }));
106
+ await page.goto(createSimulatorUrl({ simulation: 'show-map', theme: 'dark', host }));
107
107
 
108
108
  const iframe = page.frameLocator('iframe');
109
109
  const mapContainer = iframe.locator('.antialiased.w-full.overflow-hidden').first();
@@ -113,7 +113,7 @@ for (const host of hosts) {
113
113
  test('should have appropriate border color for dark mode', async ({ page }) => {
114
114
  await page.goto(
115
115
  createSimulatorUrl({
116
- simulation: 'map-show',
116
+ simulation: 'show-map',
117
117
  theme: 'dark',
118
118
  displayMode: 'inline',
119
119
  host,
@@ -143,7 +143,7 @@ for (const host of hosts) {
143
143
  }
144
144
  });
145
145
 
146
- await page.goto(createSimulatorUrl({ simulation: 'map-show', theme: 'dark', host }));
146
+ await page.goto(createSimulatorUrl({ simulation: 'show-map', theme: 'dark', host }));
147
147
 
148
148
  const iframe = page.frameLocator('iframe');
149
149
  const mapContainer = iframe.locator('.antialiased.w-full.overflow-hidden').first();
@@ -165,7 +165,7 @@ for (const host of hosts) {
165
165
  test('should not have rounded border in fullscreen mode', async ({ page }) => {
166
166
  await page.goto(
167
167
  createSimulatorUrl({
168
- simulation: 'map-show',
168
+ simulation: 'show-map',
169
169
  theme: 'light',
170
170
  displayMode: 'fullscreen',
171
171
  host,
@@ -189,7 +189,7 @@ for (const host of hosts) {
189
189
  test('should not show fullscreen button when already in fullscreen', async ({ page }) => {
190
190
  await page.goto(
191
191
  createSimulatorUrl({
192
- simulation: 'map-show',
192
+ simulation: 'show-map',
193
193
  theme: 'light',
194
194
  displayMode: 'fullscreen',
195
195
  host,
@@ -208,7 +208,7 @@ for (const host of hosts) {
208
208
  test('should show place list sidebar in fullscreen', async ({ page }) => {
209
209
  await page.goto(
210
210
  createSimulatorUrl({
211
- simulation: 'map-show',
211
+ simulation: 'show-map',
212
212
  theme: 'dark',
213
213
  displayMode: 'fullscreen',
214
214
  host,
@@ -225,7 +225,7 @@ for (const host of hosts) {
225
225
  await page.setViewportSize({ width: 1024, height: 768 });
226
226
  await page.goto(
227
227
  createSimulatorUrl({
228
- simulation: 'map-show',
228
+ simulation: 'show-map',
229
229
  theme: 'light',
230
230
  displayMode: 'fullscreen',
231
231
  host,
@@ -1,36 +1,6 @@
1
1
  {
2
+ "tool": "review-diff",
2
3
  "userMessage": "Refactor the authentication module to use JWT tokens instead of sessions.",
3
- "tool": {
4
- "name": "review-diff",
5
- "description": "Show a review dialog for a proposed code diff",
6
- "inputSchema": {
7
- "type": "object",
8
- "properties": {
9
- "changesetId": { "type": "string", "description": "Unique identifier for the changeset" },
10
- "title": { "type": "string", "description": "Title describing the changes" },
11
- "description": {
12
- "type": "string",
13
- "description": "Detailed description of what the changes accomplish"
14
- },
15
- "files": {
16
- "type": "array",
17
- "items": { "type": "string" },
18
- "description": "List of file paths affected by this change"
19
- },
20
- "runMigrations": {
21
- "type": "boolean",
22
- "description": "Whether to run database migrations as part of the change"
23
- }
24
- },
25
- "required": ["changesetId", "title"],
26
- "additionalProperties": false
27
- },
28
- "title": "Diff Review",
29
- "annotations": { "readOnlyHint": false },
30
- "_meta": {
31
- "ui": { "visibility": ["model", "app"] }
32
- }
33
- },
34
4
  "toolInput": {
35
5
  "changesetId": "cs_789",
36
6
  "title": "Refactor Authentication Module",
@@ -1,42 +1,6 @@
1
1
  {
2
+ "tool": "review-post",
2
3
  "userMessage": "Write a launch announcement for X and LinkedIn.",
3
- "tool": {
4
- "name": "review-post",
5
- "description": "Review a social media post before publishing",
6
- "inputSchema": {
7
- "type": "object",
8
- "properties": {
9
- "content": { "type": "string", "description": "The text content of the post" },
10
- "platforms": {
11
- "type": "array",
12
- "items": { "type": "string", "enum": ["x", "linkedin", "facebook", "instagram"] },
13
- "description": "Social media platforms to post to"
14
- },
15
- "schedule": {
16
- "type": "string",
17
- "enum": ["now", "scheduled"],
18
- "description": "When to publish the post"
19
- },
20
- "scheduledTime": {
21
- "type": "string",
22
- "format": "date-time",
23
- "description": "ISO 8601 timestamp for scheduled posts"
24
- },
25
- "visibility": {
26
- "type": "string",
27
- "enum": ["public", "connections", "private"],
28
- "description": "Post visibility setting"
29
- }
30
- },
31
- "required": ["content", "platforms"],
32
- "additionalProperties": false
33
- },
34
- "title": "Review Post",
35
- "annotations": { "readOnlyHint": false },
36
- "_meta": {
37
- "ui": { "visibility": ["model", "app"] }
38
- }
39
- },
40
4
  "toolInput": {
41
5
  "content": "Just shipped a major update to our app! \ud83d\ude80\n\nNew features include:\n\u2022 Dark mode support\n\u2022 Faster load times\n\u2022 Bug fixes and improvements\n\nThanks to everyone who provided feedback. You all are amazing! \ud83d\udcaa\n\n#ProductUpdate #TechNews #Startup",
42
6
  "platforms": ["x", "linkedin"],
@@ -1,43 +1,6 @@
1
1
  {
2
+ "tool": "review-purchase",
2
3
  "userMessage": "Buy some wireless headphones, a USB-C cable, and a clear iPhone case.",
3
- "tool": {
4
- "name": "review-purchase",
5
- "description": "Review a purchase before completing the transaction",
6
- "inputSchema": {
7
- "type": "object",
8
- "properties": {
9
- "cartId": { "type": "string", "description": "Shopping cart identifier" },
10
- "items": {
11
- "type": "array",
12
- "items": {
13
- "type": "object",
14
- "properties": {
15
- "productId": { "type": "string" },
16
- "quantity": { "type": "number" }
17
- }
18
- },
19
- "description": "List of items to purchase"
20
- },
21
- "shippingAddressId": {
22
- "type": "string",
23
- "description": "ID of the saved shipping address"
24
- },
25
- "shippingMethod": {
26
- "type": "string",
27
- "enum": ["standard", "express", "overnight"],
28
- "description": "Shipping speed"
29
- },
30
- "paymentMethodId": { "type": "string", "description": "ID of the saved payment method" }
31
- },
32
- "required": ["items"],
33
- "additionalProperties": false
34
- },
35
- "title": "Review Purchase",
36
- "annotations": { "readOnlyHint": false },
37
- "_meta": {
38
- "ui": { "visibility": ["model", "app"] }
39
- }
40
- },
41
4
  "toolInput": {
42
5
  "cartId": "cart_abc123",
43
6
  "items": [
@@ -1,29 +1,6 @@
1
1
  {
2
+ "tool": "show-albums",
2
3
  "userMessage": "Show me photos from my Austin pizza tour.",
3
- "tool": {
4
- "name": "show-albums",
5
- "description": "Show photo albums",
6
- "inputSchema": {
7
- "type": "object",
8
- "properties": {
9
- "category": {
10
- "type": "string",
11
- "description": "Filter albums by category (e.g., travel, food, family)"
12
- },
13
- "search": {
14
- "type": "string",
15
- "description": "Search term to filter albums by title or description"
16
- },
17
- "limit": { "type": "number", "description": "Maximum number of albums to return" }
18
- },
19
- "additionalProperties": false
20
- },
21
- "title": "Show Albums",
22
- "annotations": { "readOnlyHint": true },
23
- "_meta": {
24
- "ui": { "visibility": ["model", "app"] }
25
- }
26
- },
27
4
  "toolInput": {
28
5
  "category": "food",
29
6
  "search": "Austin pizza tour",
@@ -1,29 +1,6 @@
1
1
  {
2
+ "tool": "show-carousel",
2
3
  "userMessage": "Show me popular places to visit in Austin Texas.",
3
- "tool": {
4
- "name": "show-carousel",
5
- "description": "Show popular places to visit",
6
- "inputSchema": {
7
- "type": "object",
8
- "properties": {
9
- "city": { "type": "string", "description": "City name to search for places" },
10
- "state": { "type": "string", "description": "State or region" },
11
- "categories": {
12
- "type": "array",
13
- "items": { "type": "string" },
14
- "description": "Filter by categories (e.g., parks, restaurants, landmarks)"
15
- },
16
- "limit": { "type": "number", "description": "Maximum number of places to return" }
17
- },
18
- "required": ["city"],
19
- "additionalProperties": false
20
- },
21
- "title": "Show Carousel",
22
- "annotations": { "readOnlyHint": true },
23
- "_meta": {
24
- "ui": { "visibility": ["model", "app"] }
25
- }
26
- },
27
4
  "toolInput": {
28
5
  "city": "Austin",
29
6
  "state": "Texas",
@@ -1,40 +1,6 @@
1
1
  {
2
+ "tool": "show-map",
2
3
  "userMessage": "Where's the best pizza in San Francisco?",
3
- "tool": {
4
- "name": "show-map",
5
- "description": "Show the map",
6
- "inputSchema": {
7
- "type": "object",
8
- "properties": {
9
- "query": {
10
- "type": "string",
11
- "description": "Search query for places (e.g., pizza, coffee, restaurants)"
12
- },
13
- "location": {
14
- "type": "object",
15
- "properties": {
16
- "lat": { "type": "number" },
17
- "lng": { "type": "number" }
18
- },
19
- "description": "Center location for the search"
20
- },
21
- "radius": { "type": "number", "description": "Search radius in miles" },
22
- "minRating": { "type": "number", "description": "Minimum rating filter (1-5)" },
23
- "priceRange": {
24
- "type": "array",
25
- "items": { "type": "string", "enum": ["$", "$$", "$$$", "$$$$"] },
26
- "description": "Price range filter"
27
- }
28
- },
29
- "required": ["query"],
30
- "additionalProperties": false
31
- },
32
- "title": "Show Map",
33
- "annotations": { "readOnlyHint": true },
34
- "_meta": {
35
- "ui": { "visibility": ["model", "app"] }
36
- }
37
- },
38
4
  "toolInput": {
39
5
  "query": "pizza",
40
6
  "location": { "lat": 37.7749, "lng": -122.4194 },
@@ -1,156 +0,0 @@
1
- "use strict";
2
- function toPascalCase(str) {
3
- return str.split("-").map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("");
4
- }
5
- function extractResourceKey(path) {
6
- const match = path.match(/([^/]+)-resource\.(tsx|json)$/);
7
- return match?.[1];
8
- }
9
- function extractSimulationKey(path) {
10
- const match = path.match(/([^/]+)-simulation\.json$/);
11
- return match?.[1];
12
- }
13
- function findResourceKey(simulationKey, resourceKeys) {
14
- const sorted = [...resourceKeys].sort((a, b) => b.length - a.length);
15
- for (const resourceKey of sorted) {
16
- if (simulationKey === resourceKey || simulationKey.startsWith(resourceKey + "-")) {
17
- return resourceKey;
18
- }
19
- }
20
- return void 0;
21
- }
22
- function getComponentName(resourceKey) {
23
- return `${toPascalCase(resourceKey)}Resource`;
24
- }
25
- function createResourceExports(modules) {
26
- const resources = {};
27
- for (const [path, module2] of Object.entries(modules)) {
28
- const key = extractResourceKey(path);
29
- if (!key) continue;
30
- const exportName = getComponentName(key);
31
- const mod = module2;
32
- const component = mod.default ?? mod[exportName];
33
- if (component && (typeof component === "function" || typeof component === "object")) {
34
- resources[exportName] = component;
35
- }
36
- }
37
- return resources;
38
- }
39
- function buildResourceMap(modules) {
40
- const map = /* @__PURE__ */ new Map();
41
- for (const [path, module2] of Object.entries(modules)) {
42
- const key = extractResourceKey(path);
43
- if (key) {
44
- map.set(key, module2.resource);
45
- }
46
- }
47
- return map;
48
- }
49
- function buildSimulations(options) {
50
- const {
51
- simulationModules,
52
- resourcesMap,
53
- resourceComponents,
54
- createSimulation,
55
- onMissingResource = (key, prefix) => console.warn(
56
- `No matching resource found for simulation "${key}". Expected a resource file like src/resources/${prefix}/${prefix}-resource.tsx`
57
- )
58
- } = options;
59
- const resourceKeys = Array.from(resourcesMap.keys());
60
- const simulations = {};
61
- for (const [path, module2] of Object.entries(simulationModules)) {
62
- const simulationKey = extractSimulationKey(path);
63
- if (!simulationKey) continue;
64
- const simulationData = module2.default;
65
- const resourceKey = findResourceKey(simulationKey, resourceKeys);
66
- if (!resourceKey) {
67
- onMissingResource(simulationKey, simulationKey.split("-")[0]);
68
- continue;
69
- }
70
- const resource = resourcesMap.get(resourceKey);
71
- const componentName = getComponentName(resourceKey);
72
- const resourceComponent = resourceComponents[componentName];
73
- if (!resourceComponent) {
74
- console.warn(
75
- `Resource component "${componentName}" not found for resource "${resourceKey}". Make sure src/resources/${resourceKey}/${resourceKey}-resource.tsx exists with a default export.`
76
- );
77
- continue;
78
- }
79
- simulations[simulationKey] = createSimulation(
80
- simulationKey,
81
- simulationData,
82
- resource,
83
- resourceComponent
84
- );
85
- }
86
- return simulations;
87
- }
88
- function buildDevSimulations(options) {
89
- const { simulationModules, resourceModules, resourceComponents } = options;
90
- const resourcesMap = buildResourceMap(resourceModules);
91
- return buildSimulations({
92
- simulationModules,
93
- resourcesMap,
94
- resourceComponents,
95
- createSimulation: (simulationKey, simulationData, resource) => {
96
- const resourceKey = findResourceKey(simulationKey, Array.from(resourcesMap.keys()));
97
- const componentName = resourceKey ? getComponentName(resourceKey) : "";
98
- return {
99
- ...simulationData,
100
- name: simulationKey,
101
- resource: {
102
- uri: `ui://${resource.name}`,
103
- ...resource
104
- },
105
- // Generate URL to the resource loader with component name as query param
106
- resourceUrl: `/.sunpeak/resource-loader.html?component=${componentName}`
107
- };
108
- }
109
- });
110
- }
111
- function findResourceDirs(baseDir, filePattern, fs) {
112
- if (!fs.existsSync(baseDir)) {
113
- return [];
114
- }
115
- const entries = fs.readdirSync(baseDir, { withFileTypes: true });
116
- return entries.filter((entry) => entry.isDirectory()).map((entry) => {
117
- const key = entry.name;
118
- const dir = `${baseDir}/${key}`;
119
- const resourcePath = `${dir}/${filePattern(key)}`;
120
- if (!fs.existsSync(resourcePath)) {
121
- return null;
122
- }
123
- return { key, dir, resourcePath };
124
- }).filter((info) => info !== null);
125
- }
126
- function isSimulationFile(filename, resourceKey) {
127
- return filename.startsWith(`${resourceKey}-`) && filename.endsWith("-simulation.json");
128
- }
129
- function extractSimulationName(filename, resourceKey) {
130
- return filename.replace(`${resourceKey}-`, "").replace("-simulation.json", "");
131
- }
132
- function findSimulationFiles(resourceDir, resourceKey, fs) {
133
- if (!fs.existsSync(resourceDir)) {
134
- return [];
135
- }
136
- const entries = fs.readdirSync(resourceDir, { withFileTypes: true });
137
- return entries.filter((entry) => !entry.isDirectory() && isSimulationFile(entry.name, resourceKey)).map((entry) => ({
138
- filename: entry.name,
139
- name: extractSimulationName(entry.name, resourceKey),
140
- path: `${resourceDir}/${entry.name}`
141
- }));
142
- }
143
- exports.buildDevSimulations = buildDevSimulations;
144
- exports.buildResourceMap = buildResourceMap;
145
- exports.buildSimulations = buildSimulations;
146
- exports.createResourceExports = createResourceExports;
147
- exports.extractResourceKey = extractResourceKey;
148
- exports.extractSimulationKey = extractSimulationKey;
149
- exports.extractSimulationName = extractSimulationName;
150
- exports.findResourceDirs = findResourceDirs;
151
- exports.findResourceKey = findResourceKey;
152
- exports.findSimulationFiles = findSimulationFiles;
153
- exports.getComponentName = getComponentName;
154
- exports.isSimulationFile = isSimulationFile;
155
- exports.toPascalCase = toPascalCase;
156
- //# sourceMappingURL=discovery-CRR3SlyI.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"discovery-CRR3SlyI.cjs","sources":["../src/lib/discovery.ts"],"sourcesContent":["/**\n * Discovery utilities for auto-discovering resources and simulations\n *\n * These helpers process the results of import.meta.glob() calls to extract\n * keys, build component maps, and connect simulations to resources.\n *\n * The glob calls themselves must remain in the template (Vite compile-time),\n * but all the processing logic lives here for easy updates across templates.\n *\n * Node.js utilities (findResourceDirs, isSimulationFile, etc.) can be used\n * by CLI commands for build-time and runtime discovery.\n */\n\nimport type { Simulation } from '../types/simulation.js';\n\n/**\n * Convert a kebab-case string to PascalCase\n * @example toPascalCase('review') // 'Review'\n * @example toPascalCase('album-art') // 'AlbumArt'\n */\nexport function toPascalCase(str: string): string {\n return str\n .split('-')\n .map((part) => part.charAt(0).toUpperCase() + part.slice(1))\n .join('');\n}\n\n/**\n * Extract the resource key from a resource file path\n * @example extractResourceKey('./review-resource.tsx') // 'review'\n * @example extractResourceKey('../src/resources/albums-resource.tsx') // 'albums'\n */\nexport function extractResourceKey(path: string): string | undefined {\n const match = path.match(/([^/]+)-resource\\.(tsx|json)$/);\n return match?.[1];\n}\n\n/**\n * Extract the simulation key from a simulation file path\n * @example extractSimulationKey('./albums-show-simulation.json') // 'albums-show'\n */\nexport function extractSimulationKey(path: string): string | undefined {\n const match = path.match(/([^/]+)-simulation\\.json$/);\n return match?.[1];\n}\n\n/**\n * Find the best matching resource key for a simulation key.\n * Matches the longest resource name that is a prefix of the simulation key.\n * @example findResourceKey('albums-show', ['albums', 'album']) // 'albums'\n * @example findResourceKey('review-diff', ['review', 'carousel']) // 'review'\n */\nexport function findResourceKey(simulationKey: string, resourceKeys: string[]): string | undefined {\n // Sort by length descending to find longest match first\n const sorted = [...resourceKeys].sort((a, b) => b.length - a.length);\n for (const resourceKey of sorted) {\n if (simulationKey === resourceKey || simulationKey.startsWith(resourceKey + '-')) {\n return resourceKey;\n }\n }\n return undefined;\n}\n\n/**\n * Get the expected component export name for a resource\n * @example getComponentName('review') // 'ReviewResource'\n * @example getComponentName('album-art') // 'AlbumArtResource'\n */\nexport function getComponentName(resourceKey: string): string {\n return `${toPascalCase(resourceKey)}Resource`;\n}\n\n// --- Glob processing helpers ---\n\ntype GlobModules = Record<string, unknown>;\n\n/**\n * Process resource component modules from import.meta.glob() result.\n * Extracts components and exports them with PascalCase names.\n *\n * @example\n * const modules = import.meta.glob('./**\\/*-resource.tsx', { eager: true });\n * export default createResourceExports(modules);\n */\nexport function createResourceExports(modules: GlobModules): Record<string, React.ComponentType> {\n const resources: Record<string, React.ComponentType> = {};\n\n for (const [path, module] of Object.entries(modules)) {\n const key = extractResourceKey(path);\n if (!key) continue;\n\n const exportName = getComponentName(key);\n const mod = module as Record<string, unknown>;\n\n // Try default export first, then named export matching the expected name\n const component = mod.default ?? mod[exportName];\n\n // Accept functions (regular components) or objects (forwardRef/memo components)\n if (component && (typeof component === 'function' || typeof component === 'object')) {\n resources[exportName] = component as React.ComponentType;\n }\n }\n\n return resources;\n}\n\n/**\n * Build a resource metadata map from import.meta.glob() result.\n * Used for connecting simulations to their resource definitions.\n *\n * @example\n * const modules = import.meta.glob('../src/resources/**\\/*-resource.tsx', { eager: true });\n * const resourcesMap = buildResourceMap(modules);\n */\nexport function buildResourceMap<T>(modules: GlobModules): Map<string, T> {\n const map = new Map<string, T>();\n\n for (const [path, module] of Object.entries(modules)) {\n const key = extractResourceKey(path);\n if (key) {\n map.set(key, (module as { resource: T }).resource);\n }\n }\n\n return map;\n}\n\n/**\n * Options for building simulations from discovered modules\n */\nexport interface BuildSimulationsOptions<TResource, TSimulation> {\n /** Glob result of simulation JSON files */\n simulationModules: GlobModules;\n /** Map of resource key -> resource metadata */\n resourcesMap: Map<string, TResource>;\n /** Map of component name -> React component */\n resourceComponents: Record<string, React.ComponentType>;\n /** Create the final simulation object */\n createSimulation: (\n simulationKey: string,\n simulationData: unknown,\n resource: TResource,\n resourceComponent: React.ComponentType\n ) => TSimulation;\n /** Optional warning handler for missing resources */\n onMissingResource?: (simulationKey: string, expectedPrefix: string) => void;\n}\n\n/**\n * Build simulations by connecting simulation data with resources and components.\n * This is the main orchestration function for dev server bootstrap.\n */\nexport function buildSimulations<TResource, TSimulation>(\n options: BuildSimulationsOptions<TResource, TSimulation>\n): Record<string, TSimulation> {\n const {\n simulationModules,\n resourcesMap,\n resourceComponents,\n createSimulation,\n onMissingResource = (key, prefix) =>\n console.warn(\n `No matching resource found for simulation \"${key}\". ` +\n `Expected a resource file like src/resources/${prefix}/${prefix}-resource.tsx`\n ),\n } = options;\n\n const resourceKeys = Array.from(resourcesMap.keys());\n const simulations: Record<string, TSimulation> = {};\n\n for (const [path, module] of Object.entries(simulationModules)) {\n const simulationKey = extractSimulationKey(path);\n if (!simulationKey) continue;\n\n const simulationData = (module as { default: unknown }).default;\n\n // Find matching resource\n const resourceKey = findResourceKey(simulationKey, resourceKeys);\n if (!resourceKey) {\n onMissingResource(simulationKey, simulationKey.split('-')[0]);\n continue;\n }\n\n const resource = resourcesMap.get(resourceKey)!;\n\n // Get component\n const componentName = getComponentName(resourceKey);\n const resourceComponent = resourceComponents[componentName];\n\n if (!resourceComponent) {\n console.warn(\n `Resource component \"${componentName}\" not found for resource \"${resourceKey}\". ` +\n `Make sure src/resources/${resourceKey}/${resourceKey}-resource.tsx exists with a default export.`\n );\n continue;\n }\n\n simulations[simulationKey] = createSimulation(\n simulationKey,\n simulationData,\n resource,\n resourceComponent\n );\n }\n\n return simulations;\n}\n\n// --- Dev server helpers ---\n\n/**\n * Resource metadata from *-resource.tsx files\n */\nexport interface ResourceMetadata {\n name: string;\n [key: string]: unknown;\n}\n\n/**\n * Options for building dev simulations\n */\nexport interface BuildDevSimulationsOptions {\n /** Glob result of simulation JSON files: import.meta.glob('*-simulation.json', { eager: true }) */\n simulationModules: GlobModules;\n /** Glob result of resource JSON files: import.meta.glob('*-resource.tsx', { eager: true }) */\n resourceModules: GlobModules;\n /** Resource components map from src/resources/index.ts */\n resourceComponents: Record<string, React.ComponentType>;\n}\n\n/**\n * Build simulations for the dev server from glob results.\n * This is the main entry point for dev.tsx bootstrap.\n *\n * @example\n * const simulations = buildDevSimulations({\n * simulationModules: import.meta.glob('../src/resources/**\\/*-simulation.json', { eager: true }),\n * resourceModules: import.meta.glob('../src/resources/**\\/*-resource.tsx', { eager: true }),\n * resourceComponents: resourceComponents,\n * });\n */\nexport function buildDevSimulations(\n options: BuildDevSimulationsOptions\n): Record<string, Simulation> {\n const { simulationModules, resourceModules, resourceComponents } = options;\n\n // Build resource metadata map\n const resourcesMap = buildResourceMap<ResourceMetadata>(resourceModules);\n\n // Build simulations with the standard dev server format\n return buildSimulations<ResourceMetadata, Simulation>({\n simulationModules,\n resourcesMap,\n resourceComponents,\n createSimulation: (simulationKey, simulationData, resource) => {\n // Get the component name for the resource URL\n const resourceKey = findResourceKey(simulationKey, Array.from(resourcesMap.keys()));\n const componentName = resourceKey ? getComponentName(resourceKey) : '';\n\n return {\n ...(simulationData as Omit<Simulation, 'name' | 'resourceUrl' | 'resource'>),\n name: simulationKey,\n resource: {\n uri: `ui://${resource.name}`,\n ...resource,\n },\n // Generate URL to the resource loader with component name as query param\n resourceUrl: `/.sunpeak/resource-loader.html?component=${componentName}`,\n } as Simulation;\n },\n });\n}\n\n// --- Node.js utilities for CLI commands ---\n// These utilities use standard Node.js APIs and can be imported by build/push/mcp commands.\n\n/**\n * Information about a discovered resource directory\n */\nexport interface ResourceDirInfo {\n /** Resource key (directory name), e.g., 'albums', 'carousel' */\n key: string;\n /** Full path to the resource directory */\n dir: string;\n /** Full path to the main resource file (tsx or json depending on context) */\n resourcePath: string;\n}\n\n/**\n * File system operations interface for dependency injection in tests\n */\nexport interface FsOps {\n readdirSync: (\n path: string,\n options: { withFileTypes: true }\n ) => Array<{ name: string; isDirectory: () => boolean }>;\n existsSync: (path: string) => boolean;\n}\n\n/**\n * Find all resource directories in a base directory.\n * Each valid resource directory contains a file matching the expected pattern.\n *\n * @param baseDir - Base directory to scan (e.g., 'src/resources' or 'dist')\n * @param filePattern - Function to generate expected filename from resource key\n * @param fs - File system operations (for testing)\n *\n * @example\n * // Find source resources (tsx files)\n * const resources = findResourceDirs('src/resources', key => `${key}-resource.tsx`);\n *\n * @example\n * // Find built resources (js files)\n * const resources = findResourceDirs('dist', key => `${key}.js`);\n */\nexport function findResourceDirs(\n baseDir: string,\n filePattern: (key: string) => string,\n fs: FsOps\n): ResourceDirInfo[] {\n if (!fs.existsSync(baseDir)) {\n return [];\n }\n\n const entries = fs.readdirSync(baseDir, { withFileTypes: true });\n\n return entries\n .filter((entry) => entry.isDirectory())\n .map((entry) => {\n const key = entry.name;\n const dir = `${baseDir}/${key}`;\n const resourcePath = `${dir}/${filePattern(key)}`;\n\n if (!fs.existsSync(resourcePath)) {\n return null;\n }\n\n return { key, dir, resourcePath };\n })\n .filter((info): info is ResourceDirInfo => info !== null);\n}\n\n/**\n * Check if a filename is a simulation file for a given resource.\n * Matches pattern: {resourceKey}-*-simulation.json\n *\n * @example\n * isSimulationFile('albums-show-simulation.json', 'albums') // true\n * isSimulationFile('albums-show-simulation.json', 'carousel') // false\n * isSimulationFile('albums-resource.tsx', 'albums') // false\n */\nexport function isSimulationFile(filename: string, resourceKey: string): boolean {\n return filename.startsWith(`${resourceKey}-`) && filename.endsWith('-simulation.json');\n}\n\n/**\n * Extract the simulation name from a simulation filename.\n * Given \"{resourceKey}-{name}-simulation.json\", returns \"{name}\".\n *\n * @example\n * extractSimulationName('albums-show-simulation.json', 'albums') // 'show'\n * extractSimulationName('carousel-hero-simulation.json', 'carousel') // 'hero'\n */\nexport function extractSimulationName(filename: string, resourceKey: string): string {\n return filename.replace(`${resourceKey}-`, '').replace('-simulation.json', '');\n}\n\n/**\n * Find all simulation files in a resource directory.\n *\n * @param resourceDir - Path to the resource directory\n * @param resourceKey - Resource key (e.g., 'albums')\n * @param fs - File system operations (for testing)\n * @returns Array of { filename, name } objects\n */\nexport function findSimulationFiles(\n resourceDir: string,\n resourceKey: string,\n fs: Pick<FsOps, 'readdirSync' | 'existsSync'>\n): Array<{ filename: string; name: string; path: string }> {\n if (!fs.existsSync(resourceDir)) {\n return [];\n }\n\n const entries = fs.readdirSync(resourceDir, { withFileTypes: true });\n\n return entries\n .filter((entry) => !entry.isDirectory() && isSimulationFile(entry.name, resourceKey))\n .map((entry) => ({\n filename: entry.name,\n name: extractSimulationName(entry.name, resourceKey),\n path: `${resourceDir}/${entry.name}`,\n }));\n}\n"],"names":["module"],"mappings":";AAoBO,SAAS,aAAa,KAAqB;AAChD,SAAO,IACJ,MAAM,GAAG,EACT,IAAI,CAAC,SAAS,KAAK,OAAO,CAAC,EAAE,YAAA,IAAgB,KAAK,MAAM,CAAC,CAAC,EAC1D,KAAK,EAAE;AACZ;AAOO,SAAS,mBAAmB,MAAkC;AACnE,QAAM,QAAQ,KAAK,MAAM,+BAA+B;AACxD,SAAO,QAAQ,CAAC;AAClB;AAMO,SAAS,qBAAqB,MAAkC;AACrE,QAAM,QAAQ,KAAK,MAAM,2BAA2B;AACpD,SAAO,QAAQ,CAAC;AAClB;AAQO,SAAS,gBAAgB,eAAuB,cAA4C;AAEjG,QAAM,SAAS,CAAC,GAAG,YAAY,EAAE,KAAK,CAAC,GAAG,MAAM,EAAE,SAAS,EAAE,MAAM;AACnE,aAAW,eAAe,QAAQ;AAChC,QAAI,kBAAkB,eAAe,cAAc,WAAW,cAAc,GAAG,GAAG;AAChF,aAAO;AAAA,IACT;AAAA,EACF;AACA,SAAO;AACT;AAOO,SAAS,iBAAiB,aAA6B;AAC5D,SAAO,GAAG,aAAa,WAAW,CAAC;AACrC;AAcO,SAAS,sBAAsB,SAA2D;AAC/F,QAAM,YAAiD,CAAA;AAEvD,aAAW,CAAC,MAAMA,OAAM,KAAK,OAAO,QAAQ,OAAO,GAAG;AACpD,UAAM,MAAM,mBAAmB,IAAI;AACnC,QAAI,CAAC,IAAK;AAEV,UAAM,aAAa,iBAAiB,GAAG;AACvC,UAAM,MAAMA;AAGZ,UAAM,YAAY,IAAI,WAAW,I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