sunpeak 0.9.12 → 0.10.1
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/bin/commands/build.mjs +56 -30
- package/bin/commands/deploy.mjs +17 -17
- package/bin/commands/push.mjs +115 -64
- package/bin/lib/patterns.mjs +40 -0
- package/bin/sunpeak.js +50 -106
- package/dist/index.cjs +149 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +165 -27
- package/dist/index.js.map +1 -1
- package/dist/lib/discovery.d.ts +76 -13
- package/dist/mcp/entry.cjs +24 -27
- package/dist/mcp/entry.cjs.map +1 -1
- package/dist/mcp/entry.js +25 -28
- package/dist/mcp/entry.js.map +1 -1
- package/package.json +1 -1
- package/template/.sunpeak/dev.tsx +5 -5
- package/template/README.md +54 -50
- package/template/dist/{albums.json → albums/albums.json} +1 -1
- package/template/dist/{carousel.json → carousel/carousel.json} +1 -1
- package/template/dist/{map.json → map/map.json} +1 -1
- package/template/dist/{review.json → review/review.json} +1 -1
- package/template/node_modules/.vite/deps/_metadata.json +19 -19
- package/template/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +1 -1
- package/template/src/resources/{albums-resource.test.tsx → albums/albums-resource.test.tsx} +1 -1
- package/template/src/resources/{albums-resource.tsx → albums/albums-resource.tsx} +1 -1
- package/template/src/resources/albums/albums-show-simulation.json +131 -0
- package/template/src/{components/album → resources/albums/components}/album-card.tsx +1 -1
- package/template/src/{components/album → resources/albums/components}/album-carousel.tsx +1 -1
- package/template/src/{components/album → resources/albums/components}/film-strip.tsx +1 -1
- package/template/src/{components/album → resources/albums/components}/fullscreen-viewer.tsx +1 -1
- package/template/src/resources/{carousel-resource.test.tsx → carousel/carousel-resource.test.tsx} +1 -1
- package/template/src/resources/{carousel-resource.tsx → carousel/carousel-resource.tsx} +1 -1
- package/template/src/resources/carousel/carousel-show-simulation.json +68 -0
- package/template/src/{components/carousel → resources/carousel/components}/card.tsx +1 -1
- package/template/src/{components/carousel → resources/carousel/components}/carousel.tsx +1 -1
- package/template/src/resources/index.ts +5 -5
- package/template/src/{components/map → resources/map/components}/map-view.tsx +1 -1
- package/template/src/{components/map → resources/map/components}/map.tsx +1 -1
- package/template/src/{components/map → resources/map/components}/place-card.tsx +1 -1
- package/template/src/{components/map → resources/map/components}/place-carousel.tsx +1 -1
- package/template/src/{components/map → resources/map/components}/place-inspector.tsx +1 -1
- package/template/src/{components/map → resources/map/components}/place-list.tsx +1 -1
- package/template/src/resources/{map-resource.test.tsx → map/map-resource.test.tsx} +1 -1
- package/template/src/resources/{map-resource.tsx → map/map-resource.tsx} +1 -1
- package/template/src/resources/map/map-show-simulation.json +123 -0
- package/template/src/resources/review/review-diff-simulation.json +80 -0
- package/template/src/resources/review/review-post-simulation.json +56 -0
- package/template/src/resources/review/review-purchase-simulation.json +88 -0
- package/dist/discovery-a4WId9PC.cjs +0 -125
- package/dist/discovery-a4WId9PC.cjs.map +0 -1
- package/dist/discovery-ft3cd2dW.js +0 -126
- package/dist/discovery-ft3cd2dW.js.map +0 -1
- package/template/src/components/index.ts +0 -3
- package/template/src/simulations/index.ts +0 -16
- /package/template/{src/simulations → dist/albums}/albums-show-simulation.json +0 -0
- /package/template/dist/{albums.js → albums/albums.js} +0 -0
- /package/template/{src/simulations → dist/carousel}/carousel-show-simulation.json +0 -0
- /package/template/dist/{carousel.js → carousel/carousel.js} +0 -0
- /package/template/{src/simulations → dist/map}/map-show-simulation.json +0 -0
- /package/template/dist/{map.js → map/map.js} +0 -0
- /package/template/{src/simulations → dist/review}/review-diff-simulation.json +0 -0
- /package/template/{src/simulations → dist/review}/review-post-simulation.json +0 -0
- /package/template/{src/simulations → dist/review}/review-purchase-simulation.json +0 -0
- /package/template/dist/{review.js → review/review.js} +0 -0
- /package/template/src/resources/{albums-resource.json → albums/albums-resource.json} +0 -0
- /package/template/src/{components/album → resources/albums/components}/album-card.test.tsx +0 -0
- /package/template/src/{components/album → resources/albums/components}/album-carousel.test.tsx +0 -0
- /package/template/src/{components/album → resources/albums/components}/albums.test.tsx +0 -0
- /package/template/src/{components/album → resources/albums/components}/albums.tsx +0 -0
- /package/template/src/{components/album → resources/albums/components}/film-strip.test.tsx +0 -0
- /package/template/src/{components/album → resources/albums/components}/fullscreen-viewer.test.tsx +0 -0
- /package/template/src/{components/album → resources/albums/components}/index.ts +0 -0
- /package/template/src/resources/{carousel-resource.json → carousel/carousel-resource.json} +0 -0
- /package/template/src/{components/carousel → resources/carousel/components}/card.test.tsx +0 -0
- /package/template/src/{components/carousel → resources/carousel/components}/carousel.test.tsx +0 -0
- /package/template/src/{components/carousel → resources/carousel/components}/index.ts +0 -0
- /package/template/src/{components/map → resources/map/components}/index.ts +0 -0
- /package/template/src/{components/map → resources/map/components}/map-view.test.tsx +0 -0
- /package/template/src/{components/map → resources/map/components}/place-card.test.tsx +0 -0
- /package/template/src/{components/map → resources/map/components}/place-carousel.test.tsx +0 -0
- /package/template/src/{components/map → resources/map/components}/place-inspector.test.tsx +0 -0
- /package/template/src/{components/map → resources/map/components}/place-list.test.tsx +0 -0
- /package/template/src/{components/map → resources/map/components}/types.ts +0 -0
- /package/template/src/resources/{map-resource.json → map/map-resource.json} +0 -0
- /package/template/src/resources/{review-resource.json → review/review-resource.json} +0 -0
- /package/template/src/resources/{review-resource.test.tsx → review/review-resource.test.tsx} +0 -0
- /package/template/src/resources/{review-resource.tsx → review/review-resource.tsx} +0 -0
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
{
|
|
2
|
+
"userMessage": "Find pizza near me",
|
|
3
|
+
"tool": {
|
|
4
|
+
"name": "show-map",
|
|
5
|
+
"description": "Show the map",
|
|
6
|
+
"inputSchema": { "type": "object", "properties": {}, "additionalProperties": false },
|
|
7
|
+
"title": "Show Map",
|
|
8
|
+
"annotations": { "readOnlyHint": true },
|
|
9
|
+
"_meta": {
|
|
10
|
+
"openai/toolInvocation/invoking": "Finding pizza places",
|
|
11
|
+
"openai/toolInvocation/invoked": "Found pizza places",
|
|
12
|
+
"openai/widgetAccessible": true,
|
|
13
|
+
"openai/resultCanProduceWidget": true
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"callToolResult": {
|
|
17
|
+
"structuredContent": {
|
|
18
|
+
"places": [
|
|
19
|
+
{
|
|
20
|
+
"id": "nova-slice-lab",
|
|
21
|
+
"name": "Nova Slice Lab",
|
|
22
|
+
"coords": [-122.4098, 37.8001],
|
|
23
|
+
"description": "Award-winning Neapolitan pies in North Beach.",
|
|
24
|
+
"city": "North Beach",
|
|
25
|
+
"rating": 4.8,
|
|
26
|
+
"price": "$$$",
|
|
27
|
+
"thumbnail": "https://persistent.oaistatic.com/pizzaz/pizzaz-1.png"
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"id": "midnight-marinara",
|
|
31
|
+
"name": "Midnight Marinara",
|
|
32
|
+
"coords": [-122.4093, 37.799],
|
|
33
|
+
"description": "Focaccia-style squares, late-night favorite.",
|
|
34
|
+
"city": "North Beach",
|
|
35
|
+
"rating": 4.6,
|
|
36
|
+
"price": "$",
|
|
37
|
+
"thumbnail": "https://persistent.oaistatic.com/pizzaz/pizzaz-2.png"
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"id": "cinder-oven-co",
|
|
41
|
+
"name": "Cinder Oven Co.",
|
|
42
|
+
"coords": [-122.4255, 37.7613],
|
|
43
|
+
"description": "Thin-crust classics on 18th Street.",
|
|
44
|
+
"city": "Mission",
|
|
45
|
+
"rating": 4.5,
|
|
46
|
+
"price": "$$",
|
|
47
|
+
"thumbnail": "https://persistent.oaistatic.com/pizzaz/pizzaz-3.png"
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
"id": "neon-crust-works",
|
|
51
|
+
"name": "Neon Crust Works",
|
|
52
|
+
"coords": [-122.4388, 37.7775],
|
|
53
|
+
"description": "Deep-dish and cornmeal crust favorites.",
|
|
54
|
+
"city": "Alamo Square",
|
|
55
|
+
"rating": 4.5,
|
|
56
|
+
"price": "$$",
|
|
57
|
+
"thumbnail": "https://persistent.oaistatic.com/pizzaz/pizzaz-6.png"
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"id": "luna-pie-collective",
|
|
61
|
+
"name": "Luna Pie Collective",
|
|
62
|
+
"coords": [-122.4077, 37.799],
|
|
63
|
+
"description": "Wood-fired pies and burrata in North Beach.",
|
|
64
|
+
"city": "North Beach",
|
|
65
|
+
"rating": 4.6,
|
|
66
|
+
"price": "$$",
|
|
67
|
+
"thumbnail": "https://persistent.oaistatic.com/pizzaz/pizzaz-4.png"
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
"id": "bricklight-deep-dish",
|
|
71
|
+
"name": "Bricklight Deep Dish",
|
|
72
|
+
"coords": [-122.4097, 37.7992],
|
|
73
|
+
"description": "Chicago-style pies from Tony Gemignani.",
|
|
74
|
+
"city": "North Beach",
|
|
75
|
+
"rating": 4.4,
|
|
76
|
+
"price": "$$$",
|
|
77
|
+
"thumbnail": "https://persistent.oaistatic.com/pizzaz/pizzaz-5.png"
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
"id": "garden-ember-pies",
|
|
81
|
+
"name": "Garden Ember Pies",
|
|
82
|
+
"coords": [-122.438, 37.7722],
|
|
83
|
+
"description": "Neighborhood spot with seasonal toppings.",
|
|
84
|
+
"city": "Lower Haight",
|
|
85
|
+
"rating": 4.4,
|
|
86
|
+
"price": "$$",
|
|
87
|
+
"thumbnail": "https://persistent.oaistatic.com/pizzaz/pizzaz-1.png"
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
"id": "atlas-fire-pizzeria",
|
|
91
|
+
"name": "Atlas Fire Pizzeria",
|
|
92
|
+
"coords": [-122.4123, 37.7899],
|
|
93
|
+
"description": "Sourdough, wood-fired pies near Nob Hill.",
|
|
94
|
+
"city": "Nob Hill",
|
|
95
|
+
"rating": 4.6,
|
|
96
|
+
"price": "$$$",
|
|
97
|
+
"thumbnail": "https://persistent.oaistatic.com/pizzaz/pizzaz-2.png"
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
"id": "circuit-slice-garage",
|
|
101
|
+
"name": "Circuit Slice Garage",
|
|
102
|
+
"coords": [-122.4135, 37.7805],
|
|
103
|
+
"description": "Crispy-edged Detroit-style in SoMa.",
|
|
104
|
+
"city": "SoMa",
|
|
105
|
+
"rating": 4.5,
|
|
106
|
+
"price": "$$",
|
|
107
|
+
"thumbnail": "https://persistent.oaistatic.com/pizzaz/pizzaz-3.png"
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
"id": "velvet-mozza-lounge",
|
|
111
|
+
"name": "Velvet Mozza Lounge",
|
|
112
|
+
"coords": [-122.4019, 37.7818],
|
|
113
|
+
"description": "Bianca pies and cocktails near Yerba Buena.",
|
|
114
|
+
"city": "Yerba Buena",
|
|
115
|
+
"rating": 4.3,
|
|
116
|
+
"price": "$$",
|
|
117
|
+
"thumbnail": "https://persistent.oaistatic.com/pizzaz/pizzaz-6.png"
|
|
118
|
+
}
|
|
119
|
+
]
|
|
120
|
+
},
|
|
121
|
+
"_meta": {}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
{
|
|
2
|
+
"userMessage": "I'd like to refactor the authentication module",
|
|
3
|
+
"tool": {
|
|
4
|
+
"name": "diff-review",
|
|
5
|
+
"description": "Show a review dialog for a proposed code diff",
|
|
6
|
+
"inputSchema": { "type": "object", "properties": {}, "additionalProperties": false },
|
|
7
|
+
"title": "Diff Review",
|
|
8
|
+
"annotations": { "readOnlyHint": false },
|
|
9
|
+
"_meta": {
|
|
10
|
+
"openai/toolInvocation/invoking": "Preparing changes",
|
|
11
|
+
"openai/toolInvocation/invoked": "Changes ready for review",
|
|
12
|
+
"openai/widgetAccessible": true,
|
|
13
|
+
"openai/resultCanProduceWidget": true
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"callToolResult": {
|
|
17
|
+
"structuredContent": {
|
|
18
|
+
"title": "Refactor Authentication Module",
|
|
19
|
+
"description": "The following changes will update the authentication system to use JWT tokens instead of session-based auth.",
|
|
20
|
+
"sections": [
|
|
21
|
+
{
|
|
22
|
+
"title": "File Changes",
|
|
23
|
+
"type": "changes",
|
|
24
|
+
"content": [
|
|
25
|
+
{
|
|
26
|
+
"id": "1",
|
|
27
|
+
"type": "create",
|
|
28
|
+
"path": "src/lib/jwt.ts",
|
|
29
|
+
"description": "Create JWT utility functions",
|
|
30
|
+
"details": "Token generation, verification, and refresh logic"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"id": "2",
|
|
34
|
+
"type": "modify",
|
|
35
|
+
"path": "src/middleware/auth.ts",
|
|
36
|
+
"description": "Update auth middleware to use JWT",
|
|
37
|
+
"details": "Replace session checks with JWT verification"
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"id": "3",
|
|
41
|
+
"type": "modify",
|
|
42
|
+
"path": "src/routes/login.ts",
|
|
43
|
+
"description": "Update login endpoint to return JWT tokens"
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
"id": "4",
|
|
47
|
+
"type": "delete",
|
|
48
|
+
"path": "src/lib/session.ts",
|
|
49
|
+
"description": "Remove deprecated session management",
|
|
50
|
+
"details": "No longer needed after JWT migration"
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
"id": "5",
|
|
54
|
+
"type": "action",
|
|
55
|
+
"description": "Run database migration for token storage",
|
|
56
|
+
"details": "Creates refresh_tokens table"
|
|
57
|
+
}
|
|
58
|
+
]
|
|
59
|
+
}
|
|
60
|
+
],
|
|
61
|
+
"acceptLabel": "Apply Changes",
|
|
62
|
+
"rejectLabel": "Cancel",
|
|
63
|
+
"acceptedMessage": "Changes applied",
|
|
64
|
+
"rejectedMessage": "Changes cancelled",
|
|
65
|
+
"reviewTool": {
|
|
66
|
+
"name": "apply_changes",
|
|
67
|
+
"arguments": {
|
|
68
|
+
"changesetId": "cs_789",
|
|
69
|
+
"files": [
|
|
70
|
+
"src/lib/jwt.ts",
|
|
71
|
+
"src/middleware/auth.ts",
|
|
72
|
+
"src/routes/login.ts",
|
|
73
|
+
"src/lib/session.ts"
|
|
74
|
+
]
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
"_meta": {}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"userMessage": "Post this to my social media",
|
|
3
|
+
"tool": {
|
|
4
|
+
"name": "review-post",
|
|
5
|
+
"description": "Review a social media post before publishing",
|
|
6
|
+
"inputSchema": { "type": "object", "properties": {}, "additionalProperties": false },
|
|
7
|
+
"title": "Review Post",
|
|
8
|
+
"annotations": { "readOnlyHint": false },
|
|
9
|
+
"_meta": {
|
|
10
|
+
"openai/toolInvocation/invoking": "Preparing post",
|
|
11
|
+
"openai/toolInvocation/invoked": "Post ready for review",
|
|
12
|
+
"openai/widgetAccessible": true,
|
|
13
|
+
"openai/resultCanProduceWidget": true
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"callToolResult": {
|
|
17
|
+
"structuredContent": {
|
|
18
|
+
"title": "Review Your Post",
|
|
19
|
+
"description": "This post will be published to your connected accounts.",
|
|
20
|
+
"sections": [
|
|
21
|
+
{
|
|
22
|
+
"title": "Content",
|
|
23
|
+
"type": "preview",
|
|
24
|
+
"content": "Just shipped a major update to our app! 🚀\n\nNew features include:\n• Dark mode support\n• Faster load times\n• Bug fixes and improvements\n\nThanks to everyone who provided feedback. You all are amazing! 💪\n\n#ProductUpdate #TechNews #Startup"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"title": "Post Details",
|
|
28
|
+
"type": "details",
|
|
29
|
+
"content": [
|
|
30
|
+
{ "label": "Platforms", "value": "X, LinkedIn" },
|
|
31
|
+
{ "label": "Schedule", "value": "Post immediately" },
|
|
32
|
+
{ "label": "Visibility", "value": "Public" }
|
|
33
|
+
]
|
|
34
|
+
}
|
|
35
|
+
],
|
|
36
|
+
"alerts": [
|
|
37
|
+
{
|
|
38
|
+
"type": "warning",
|
|
39
|
+
"message": "This post contains hashtags that may limit reach on some platforms."
|
|
40
|
+
}
|
|
41
|
+
],
|
|
42
|
+
"acceptLabel": "Publish",
|
|
43
|
+
"rejectLabel": "Cancel",
|
|
44
|
+
"acceptedMessage": "Post published!",
|
|
45
|
+
"rejectedMessage": "Post cancelled",
|
|
46
|
+
"reviewTool": {
|
|
47
|
+
"name": "publish_post",
|
|
48
|
+
"arguments": {
|
|
49
|
+
"postId": "draft_456",
|
|
50
|
+
"platforms": ["x", "linkedin"]
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
"_meta": {}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
{
|
|
2
|
+
"userMessage": "I want to buy these items",
|
|
3
|
+
"tool": {
|
|
4
|
+
"name": "review-purchase",
|
|
5
|
+
"description": "Review a purchase before completing the transaction",
|
|
6
|
+
"inputSchema": { "type": "object", "properties": {}, "additionalProperties": false },
|
|
7
|
+
"title": "Review Purchase",
|
|
8
|
+
"annotations": { "readOnlyHint": false },
|
|
9
|
+
"_meta": {
|
|
10
|
+
"openai/toolInvocation/invoking": "Preparing order",
|
|
11
|
+
"openai/toolInvocation/invoked": "Order ready for review",
|
|
12
|
+
"openai/widgetAccessible": true,
|
|
13
|
+
"openai/resultCanProduceWidget": true
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"callToolResult": {
|
|
17
|
+
"structuredContent": {
|
|
18
|
+
"title": "Confirm Your Order",
|
|
19
|
+
"description": "Please review your order before completing the purchase.",
|
|
20
|
+
"alerts": [
|
|
21
|
+
{
|
|
22
|
+
"type": "info",
|
|
23
|
+
"message": "Free shipping on orders over $50!"
|
|
24
|
+
}
|
|
25
|
+
],
|
|
26
|
+
"sections": [
|
|
27
|
+
{
|
|
28
|
+
"title": "Items",
|
|
29
|
+
"type": "items",
|
|
30
|
+
"content": [
|
|
31
|
+
{
|
|
32
|
+
"id": "1",
|
|
33
|
+
"title": "Wireless Headphones",
|
|
34
|
+
"subtitle": "Black, Over-ear",
|
|
35
|
+
"image": "https://images.unsplash.com/photo-1505740420928-5e560c06d30e?w=100&h=100&fit=crop",
|
|
36
|
+
"value": "$79.99"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"id": "2",
|
|
40
|
+
"title": "USB-C Charging Cable",
|
|
41
|
+
"subtitle": "2m, Braided",
|
|
42
|
+
"image": "https://images.unsplash.com/photo-1588872657578-7efd1f1555ed?w=100&h=100&fit=crop",
|
|
43
|
+
"value": "$12.99",
|
|
44
|
+
"badge": "Sale"
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"id": "3",
|
|
48
|
+
"title": "Phone Case",
|
|
49
|
+
"subtitle": "Clear, iPhone 15 Pro",
|
|
50
|
+
"image": "https://images.unsplash.com/photo-1601784551446-20c9e07cdbdb?w=100&h=100&fit=crop",
|
|
51
|
+
"value": "$24.99"
|
|
52
|
+
}
|
|
53
|
+
]
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
"title": "Shipping",
|
|
57
|
+
"type": "details",
|
|
58
|
+
"content": [
|
|
59
|
+
{ "label": "Method", "value": "Standard (5-7 days)" },
|
|
60
|
+
{ "label": "Address", "value": "123 Main St, Austin, TX", "sublabel": "John Doe" }
|
|
61
|
+
]
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
"type": "summary",
|
|
65
|
+
"content": [
|
|
66
|
+
{ "label": "Subtotal", "value": "$117.97" },
|
|
67
|
+
{ "label": "Shipping", "value": "FREE" },
|
|
68
|
+
{ "label": "Tax", "value": "$9.68" },
|
|
69
|
+
{ "label": "Total", "value": "$127.65", "emphasis": true }
|
|
70
|
+
]
|
|
71
|
+
}
|
|
72
|
+
],
|
|
73
|
+
"acceptLabel": "Place Order",
|
|
74
|
+
"rejectLabel": "Cancel",
|
|
75
|
+
"acceptedMessage": "Order placed!",
|
|
76
|
+
"rejectedMessage": "Order cancelled",
|
|
77
|
+
"reviewTool": {
|
|
78
|
+
"name": "complete_purchase",
|
|
79
|
+
"arguments": {
|
|
80
|
+
"orderId": "order_123",
|
|
81
|
+
"items": ["1", "2", "3"],
|
|
82
|
+
"total": 127.65
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
"_meta": {}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -1,125 +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 == null ? void 0 : match[1];
|
|
8
|
-
}
|
|
9
|
-
function extractSimulationKey(path) {
|
|
10
|
-
const match = path.match(/([^/]+)-simulation\.json$/);
|
|
11
|
-
return match == null ? void 0 : 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 createSimulationIndex(modules) {
|
|
40
|
-
return Object.fromEntries(
|
|
41
|
-
Object.entries(modules).map(([path, module2]) => {
|
|
42
|
-
const key = extractSimulationKey(path);
|
|
43
|
-
if (!key) return null;
|
|
44
|
-
return [key, module2.default];
|
|
45
|
-
}).filter((entry) => entry !== null)
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
function buildResourceMap(modules) {
|
|
49
|
-
const map = /* @__PURE__ */ new Map();
|
|
50
|
-
for (const [path, module2] of Object.entries(modules)) {
|
|
51
|
-
const key = extractResourceKey(path);
|
|
52
|
-
if (key) {
|
|
53
|
-
map.set(key, module2.default);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
return map;
|
|
57
|
-
}
|
|
58
|
-
function buildSimulations(options) {
|
|
59
|
-
const {
|
|
60
|
-
simulationModules,
|
|
61
|
-
resourcesMap,
|
|
62
|
-
resourceComponents,
|
|
63
|
-
createSimulation,
|
|
64
|
-
onMissingResource = (key, prefix) => console.warn(
|
|
65
|
-
`No matching resource found for simulation "${key}". Expected a resource file like src/resources/${prefix}-resource.json`
|
|
66
|
-
)
|
|
67
|
-
} = options;
|
|
68
|
-
const resourceKeys = Array.from(resourcesMap.keys());
|
|
69
|
-
const simulations = {};
|
|
70
|
-
for (const [path, module2] of Object.entries(simulationModules)) {
|
|
71
|
-
const simulationKey = extractSimulationKey(path);
|
|
72
|
-
if (!simulationKey) continue;
|
|
73
|
-
const simulationData = module2.default;
|
|
74
|
-
const resourceKey = findResourceKey(simulationKey, resourceKeys);
|
|
75
|
-
if (!resourceKey) {
|
|
76
|
-
onMissingResource(simulationKey, simulationKey.split("-")[0]);
|
|
77
|
-
continue;
|
|
78
|
-
}
|
|
79
|
-
const resource = resourcesMap.get(resourceKey);
|
|
80
|
-
const componentName = getComponentName(resourceKey);
|
|
81
|
-
const resourceComponent = resourceComponents[componentName];
|
|
82
|
-
if (!resourceComponent) {
|
|
83
|
-
console.warn(
|
|
84
|
-
`Resource component "${componentName}" not found for resource "${resourceKey}". Make sure src/resources/${resourceKey}-resource.tsx exists with a default export.`
|
|
85
|
-
);
|
|
86
|
-
continue;
|
|
87
|
-
}
|
|
88
|
-
simulations[simulationKey] = createSimulation(
|
|
89
|
-
simulationKey,
|
|
90
|
-
simulationData,
|
|
91
|
-
resource,
|
|
92
|
-
resourceComponent
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
return simulations;
|
|
96
|
-
}
|
|
97
|
-
function buildDevSimulations(options) {
|
|
98
|
-
const { simulationModules, resourceModules, resourceComponents } = options;
|
|
99
|
-
const resourcesMap = buildResourceMap(resourceModules);
|
|
100
|
-
return buildSimulations({
|
|
101
|
-
simulationModules,
|
|
102
|
-
resourcesMap,
|
|
103
|
-
resourceComponents,
|
|
104
|
-
createSimulation: (simulationKey, simulationData, resource, resourceComponent) => ({
|
|
105
|
-
...simulationData,
|
|
106
|
-
name: simulationKey,
|
|
107
|
-
resource: {
|
|
108
|
-
uri: `ui://${resource.name}`,
|
|
109
|
-
...resource
|
|
110
|
-
},
|
|
111
|
-
resourceComponent
|
|
112
|
-
})
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
exports.buildDevSimulations = buildDevSimulations;
|
|
116
|
-
exports.buildResourceMap = buildResourceMap;
|
|
117
|
-
exports.buildSimulations = buildSimulations;
|
|
118
|
-
exports.createResourceExports = createResourceExports;
|
|
119
|
-
exports.createSimulationIndex = createSimulationIndex;
|
|
120
|
-
exports.extractResourceKey = extractResourceKey;
|
|
121
|
-
exports.extractSimulationKey = extractSimulationKey;
|
|
122
|
-
exports.findResourceKey = findResourceKey;
|
|
123
|
-
exports.getComponentName = getComponentName;
|
|
124
|
-
exports.toPascalCase = toPascalCase;
|
|
125
|
-
//# sourceMappingURL=discovery-a4WId9PC.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"discovery-a4WId9PC.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\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.json') // '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 * Process simulation modules from import.meta.glob() result.\n * Builds a map of simulation key -> simulation data.\n *\n * @example\n * const modules = import.meta.glob('./*-simulation.json', { eager: true });\n * export const SIMULATIONS = createSimulationIndex(modules);\n */\nexport function createSimulationIndex(modules: GlobModules): Record<string, unknown> {\n return Object.fromEntries(\n Object.entries(modules)\n .map(([path, module]) => {\n const key = extractSimulationKey(path);\n if (!key) return null;\n return [key, (module as { default: unknown }).default];\n })\n .filter((entry): entry is [string, unknown] => entry !== null)\n );\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.json', { 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 { default: T }).default);\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}-resource.json`\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}-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.json 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.json', { 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/simulations/*-simulation.json', { eager: true }),\n * resourceModules: import.meta.glob('../src/resources/*-resource.json', { 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, resourceComponent) => ({\n ...(simulationData as Omit<Simulation, 'name' | 'resourceComponent' | 'resource'>),\n name: simulationKey,\n resource: {\n uri: `ui://${resource.name}`,\n ...resource,\n },\n resourceComponent,\n }),\n });\n}\n"],"names":["module"],"mappings":";AAiBO,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,+BAAQ;AACjB;AAMO,SAAS,qBAAqB,MAAkC;AACrE,QAAM,QAAQ,KAAK,MAAM,2BAA2B;AACpD,SAAO,+BAAQ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AQ,SAAS,IAAI;AAAA,QAC1B,GAAG;AAAA,MAAA;AAAA,MAEL;AAAA,IAAA;AAAA,EACF,CACD;AACH;;;;;;;;;;;"}
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
function toPascalCase(str) {
|
|
2
|
-
return str.split("-").map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("");
|
|
3
|
-
}
|
|
4
|
-
function extractResourceKey(path) {
|
|
5
|
-
const match = path.match(/([^/]+)-resource\.(tsx|json)$/);
|
|
6
|
-
return match == null ? void 0 : match[1];
|
|
7
|
-
}
|
|
8
|
-
function extractSimulationKey(path) {
|
|
9
|
-
const match = path.match(/([^/]+)-simulation\.json$/);
|
|
10
|
-
return match == null ? void 0 : match[1];
|
|
11
|
-
}
|
|
12
|
-
function findResourceKey(simulationKey, resourceKeys) {
|
|
13
|
-
const sorted = [...resourceKeys].sort((a, b) => b.length - a.length);
|
|
14
|
-
for (const resourceKey of sorted) {
|
|
15
|
-
if (simulationKey === resourceKey || simulationKey.startsWith(resourceKey + "-")) {
|
|
16
|
-
return resourceKey;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
return void 0;
|
|
20
|
-
}
|
|
21
|
-
function getComponentName(resourceKey) {
|
|
22
|
-
return `${toPascalCase(resourceKey)}Resource`;
|
|
23
|
-
}
|
|
24
|
-
function createResourceExports(modules) {
|
|
25
|
-
const resources = {};
|
|
26
|
-
for (const [path, module] of Object.entries(modules)) {
|
|
27
|
-
const key = extractResourceKey(path);
|
|
28
|
-
if (!key) continue;
|
|
29
|
-
const exportName = getComponentName(key);
|
|
30
|
-
const mod = module;
|
|
31
|
-
const component = mod.default ?? mod[exportName];
|
|
32
|
-
if (component && (typeof component === "function" || typeof component === "object")) {
|
|
33
|
-
resources[exportName] = component;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return resources;
|
|
37
|
-
}
|
|
38
|
-
function createSimulationIndex(modules) {
|
|
39
|
-
return Object.fromEntries(
|
|
40
|
-
Object.entries(modules).map(([path, module]) => {
|
|
41
|
-
const key = extractSimulationKey(path);
|
|
42
|
-
if (!key) return null;
|
|
43
|
-
return [key, module.default];
|
|
44
|
-
}).filter((entry) => entry !== null)
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
function buildResourceMap(modules) {
|
|
48
|
-
const map = /* @__PURE__ */ new Map();
|
|
49
|
-
for (const [path, module] of Object.entries(modules)) {
|
|
50
|
-
const key = extractResourceKey(path);
|
|
51
|
-
if (key) {
|
|
52
|
-
map.set(key, module.default);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return map;
|
|
56
|
-
}
|
|
57
|
-
function buildSimulations(options) {
|
|
58
|
-
const {
|
|
59
|
-
simulationModules,
|
|
60
|
-
resourcesMap,
|
|
61
|
-
resourceComponents,
|
|
62
|
-
createSimulation,
|
|
63
|
-
onMissingResource = (key, prefix) => console.warn(
|
|
64
|
-
`No matching resource found for simulation "${key}". Expected a resource file like src/resources/${prefix}-resource.json`
|
|
65
|
-
)
|
|
66
|
-
} = options;
|
|
67
|
-
const resourceKeys = Array.from(resourcesMap.keys());
|
|
68
|
-
const simulations = {};
|
|
69
|
-
for (const [path, module] of Object.entries(simulationModules)) {
|
|
70
|
-
const simulationKey = extractSimulationKey(path);
|
|
71
|
-
if (!simulationKey) continue;
|
|
72
|
-
const simulationData = module.default;
|
|
73
|
-
const resourceKey = findResourceKey(simulationKey, resourceKeys);
|
|
74
|
-
if (!resourceKey) {
|
|
75
|
-
onMissingResource(simulationKey, simulationKey.split("-")[0]);
|
|
76
|
-
continue;
|
|
77
|
-
}
|
|
78
|
-
const resource = resourcesMap.get(resourceKey);
|
|
79
|
-
const componentName = getComponentName(resourceKey);
|
|
80
|
-
const resourceComponent = resourceComponents[componentName];
|
|
81
|
-
if (!resourceComponent) {
|
|
82
|
-
console.warn(
|
|
83
|
-
`Resource component "${componentName}" not found for resource "${resourceKey}". Make sure src/resources/${resourceKey}-resource.tsx exists with a default export.`
|
|
84
|
-
);
|
|
85
|
-
continue;
|
|
86
|
-
}
|
|
87
|
-
simulations[simulationKey] = createSimulation(
|
|
88
|
-
simulationKey,
|
|
89
|
-
simulationData,
|
|
90
|
-
resource,
|
|
91
|
-
resourceComponent
|
|
92
|
-
);
|
|
93
|
-
}
|
|
94
|
-
return simulations;
|
|
95
|
-
}
|
|
96
|
-
function buildDevSimulations(options) {
|
|
97
|
-
const { simulationModules, resourceModules, resourceComponents } = options;
|
|
98
|
-
const resourcesMap = buildResourceMap(resourceModules);
|
|
99
|
-
return buildSimulations({
|
|
100
|
-
simulationModules,
|
|
101
|
-
resourcesMap,
|
|
102
|
-
resourceComponents,
|
|
103
|
-
createSimulation: (simulationKey, simulationData, resource, resourceComponent) => ({
|
|
104
|
-
...simulationData,
|
|
105
|
-
name: simulationKey,
|
|
106
|
-
resource: {
|
|
107
|
-
uri: `ui://${resource.name}`,
|
|
108
|
-
...resource
|
|
109
|
-
},
|
|
110
|
-
resourceComponent
|
|
111
|
-
})
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
export {
|
|
115
|
-
extractSimulationKey as a,
|
|
116
|
-
createSimulationIndex as b,
|
|
117
|
-
createResourceExports as c,
|
|
118
|
-
buildResourceMap as d,
|
|
119
|
-
extractResourceKey as e,
|
|
120
|
-
findResourceKey as f,
|
|
121
|
-
getComponentName as g,
|
|
122
|
-
buildSimulations as h,
|
|
123
|
-
buildDevSimulations as i,
|
|
124
|
-
toPascalCase as t
|
|
125
|
-
};
|
|
126
|
-
//# sourceMappingURL=discovery-ft3cd2dW.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"discovery-ft3cd2dW.js","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\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.json') // '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 * Process simulation modules from import.meta.glob() result.\n * Builds a map of simulation key -> simulation data.\n *\n * @example\n * const modules = import.meta.glob('./*-simulation.json', { eager: true });\n * export const SIMULATIONS = createSimulationIndex(modules);\n */\nexport function createSimulationIndex(modules: GlobModules): Record<string, unknown> {\n return Object.fromEntries(\n Object.entries(modules)\n .map(([path, module]) => {\n const key = extractSimulationKey(path);\n if (!key) return null;\n return [key, (module as { default: unknown }).default];\n })\n .filter((entry): entry is [string, unknown] => entry !== null)\n );\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.json', { 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 { default: T }).default);\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}-resource.json`\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}-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.json 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.json', { 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/simulations/*-simulation.json', { eager: true }),\n * resourceModules: import.meta.glob('../src/resources/*-resource.json', { 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, resourceComponent) => ({\n ...(simulationData as Omit<Simulation, 'name' | 'resourceComponent' | 'resource'>),\n name: simulationKey,\n resource: {\n uri: `ui://${resource.name}`,\n ...resource,\n },\n resourceComponent,\n }),\n });\n}\n"],"names":[],"mappings":"AAiBO,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,+BAAQ;AACjB;AAMO,SAAS,qBAAqB,MAAkC;AACrE,QAAM,QAAQ,KAAK,MAAM,2BAA2B;AACpD,SAAO,+BAAQ;AACjB;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,W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