sunpeak 0.16.4 → 0.16.7
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/README.md +0 -2
- package/bin/commands/build.mjs +19 -16
- package/bin/commands/dev.mjs +7 -6
- package/bin/commands/new.mjs +69 -40
- package/dist/mcp/index.cjs +52 -30
- package/dist/mcp/index.cjs.map +1 -1
- package/dist/mcp/index.js +52 -30
- package/dist/mcp/index.js.map +1 -1
- package/package.json +3 -2
- package/template/src/resources/review/review.tsx +4 -4
package/dist/mcp/index.js
CHANGED
|
@@ -15518,27 +15518,30 @@ function createAppServer(config, simulations, viteMode) {
|
|
|
15518
15518
|
},
|
|
15519
15519
|
{ capabilities: { resources: {}, tools: {} } }
|
|
15520
15520
|
);
|
|
15521
|
-
const
|
|
15521
|
+
const registeredUriSet = /* @__PURE__ */ new Set();
|
|
15522
|
+
const resourceHandles = /* @__PURE__ */ new Map();
|
|
15523
|
+
const toolHandles = [];
|
|
15522
15524
|
for (const simulation of simulations) {
|
|
15523
15525
|
const resource = simulation.resource;
|
|
15524
15526
|
const tool = simulation.tool;
|
|
15525
15527
|
const toolResult = simulation.toolResult ?? { structuredContent: null };
|
|
15526
15528
|
const uri2 = resource.uri ?? `ui://${resource.name}`;
|
|
15529
|
+
const resourceName = resource.name;
|
|
15527
15530
|
const resourceMeta = resource._meta ?? {};
|
|
15528
15531
|
const toolMeta = tool._meta ?? {};
|
|
15529
|
-
if (!
|
|
15530
|
-
|
|
15532
|
+
if (!registeredUriSet.has(uri2)) {
|
|
15533
|
+
registeredUriSet.add(uri2);
|
|
15531
15534
|
const listMeta = viteMode ? injectViteCSP(resourceMeta) : resourceMeta;
|
|
15532
15535
|
console.log(`[MCP] RegisterResource: ${uri2}`);
|
|
15533
|
-
|
|
15534
|
-
|
|
15535
|
-
resource.name,
|
|
15536
|
+
const handle = mcpServer.registerResource(
|
|
15537
|
+
resourceName,
|
|
15536
15538
|
uri2,
|
|
15537
15539
|
{
|
|
15540
|
+
mimeType: EI,
|
|
15538
15541
|
description: resource.description,
|
|
15539
15542
|
_meta: listMeta
|
|
15540
15543
|
},
|
|
15541
|
-
async (
|
|
15544
|
+
async (readUri, extra) => {
|
|
15542
15545
|
const prodBuild = needsProdBuild(
|
|
15543
15546
|
extra?.requestInfo?.headers ?? {}
|
|
15544
15547
|
);
|
|
@@ -15547,17 +15550,18 @@ function createAppServer(config, simulations, viteMode) {
|
|
|
15547
15550
|
try {
|
|
15548
15551
|
content = getResourceHtml(simulation, viteMode, prodBuild);
|
|
15549
15552
|
} catch (error) {
|
|
15550
|
-
console.error(`[MCP] ReadResource error for ${
|
|
15553
|
+
console.error(`[MCP] ReadResource error for ${readUri.href}:`, error);
|
|
15551
15554
|
throw error;
|
|
15552
15555
|
}
|
|
15553
15556
|
const sizeKB = (content.length / 1024).toFixed(1);
|
|
15554
15557
|
console.log(
|
|
15555
|
-
`[MCP] ReadResource: ${
|
|
15558
|
+
`[MCP] ReadResource: ${readUri.href} → ${sizeKB}KB${prodBuild ? " (prod build)" : " (vite)"}`
|
|
15556
15559
|
);
|
|
15557
15560
|
return {
|
|
15558
15561
|
contents: [
|
|
15559
15562
|
{
|
|
15560
|
-
|
|
15563
|
+
// Use readUri (not closure variable) so the response URI matches after updates
|
|
15564
|
+
uri: readUri.href,
|
|
15561
15565
|
mimeType: EI,
|
|
15562
15566
|
text: content,
|
|
15563
15567
|
_meta: readMeta
|
|
@@ -15566,20 +15570,22 @@ function createAppServer(config, simulations, viteMode) {
|
|
|
15566
15570
|
};
|
|
15567
15571
|
}
|
|
15568
15572
|
);
|
|
15573
|
+
resourceHandles.set(resourceName, handle);
|
|
15569
15574
|
}
|
|
15570
|
-
|
|
15575
|
+
const fullToolMeta = {
|
|
15576
|
+
...toolMeta,
|
|
15577
|
+
ui: {
|
|
15578
|
+
resourceUri: uri2,
|
|
15579
|
+
// Preserve tool visibility from simulation metadata if declared
|
|
15580
|
+
...toolMeta.ui?.visibility ? { visibility: toolMeta.ui.visibility } : {}
|
|
15581
|
+
}
|
|
15582
|
+
};
|
|
15583
|
+
const toolHandle = hk(
|
|
15571
15584
|
mcpServer,
|
|
15572
15585
|
tool.name,
|
|
15573
15586
|
{
|
|
15574
15587
|
description: tool.description,
|
|
15575
|
-
_meta:
|
|
15576
|
-
...toolMeta,
|
|
15577
|
-
ui: {
|
|
15578
|
-
resourceUri: uri2,
|
|
15579
|
-
// Preserve tool visibility from simulation metadata if declared
|
|
15580
|
-
...toolMeta.ui?.visibility ? { visibility: toolMeta.ui.visibility } : {}
|
|
15581
|
-
}
|
|
15582
|
-
}
|
|
15588
|
+
_meta: fullToolMeta
|
|
15583
15589
|
},
|
|
15584
15590
|
async (extra) => {
|
|
15585
15591
|
const args = extra.request?.params?.arguments ?? {};
|
|
@@ -15600,12 +15606,13 @@ function createAppServer(config, simulations, viteMode) {
|
|
|
15600
15606
|
};
|
|
15601
15607
|
}
|
|
15602
15608
|
);
|
|
15609
|
+
toolHandles.push({ handle: toolHandle, resourceName, toolMeta: fullToolMeta });
|
|
15603
15610
|
}
|
|
15604
|
-
const registeredUris = Array.from(
|
|
15611
|
+
const registeredUris = Array.from(registeredUriSet).join(", ");
|
|
15605
15612
|
console.log(
|
|
15606
15613
|
`[MCP] Registered ${simulations.length} tool(s) and resource(s)${viteMode ? " (vite mode)" : ""}: ${registeredUris}`
|
|
15607
15614
|
);
|
|
15608
|
-
return mcpServer;
|
|
15615
|
+
return { server: mcpServer, resourceHandles, toolHandles };
|
|
15609
15616
|
}
|
|
15610
15617
|
const SESSION_IDLE_TIMEOUT_MS$1 = 5 * 60 * 1e3;
|
|
15611
15618
|
function isLocalConnection(req) {
|
|
@@ -15672,11 +15679,18 @@ async function handleMcpRequest(req, res, config, simulations, viteMode) {
|
|
|
15672
15679
|
}
|
|
15673
15680
|
if (req.method === "POST") {
|
|
15674
15681
|
const isLocal = isLocalConnection(req);
|
|
15675
|
-
const server = createAppServer(config, simulations, viteMode);
|
|
15682
|
+
const { server, resourceHandles, toolHandles } = createAppServer(config, simulations, viteMode);
|
|
15676
15683
|
const transport = new StreamableHTTPServerTransport({
|
|
15677
15684
|
sessionIdGenerator: () => randomUUID(),
|
|
15678
15685
|
onsessioninitialized: (id2) => {
|
|
15679
|
-
sessions.set(id2, {
|
|
15686
|
+
sessions.set(id2, {
|
|
15687
|
+
server,
|
|
15688
|
+
transport,
|
|
15689
|
+
isLocal,
|
|
15690
|
+
lastActivity: Date.now(),
|
|
15691
|
+
resourceHandles,
|
|
15692
|
+
toolHandles
|
|
15693
|
+
});
|
|
15680
15694
|
const origin = isLocal ? "local" : "tunnel";
|
|
15681
15695
|
console.log(
|
|
15682
15696
|
`[MCP] Session started: ${id2.substring(0, 8)}... (${origin}, ${sessions.size} active)`
|
|
@@ -15791,16 +15805,24 @@ function runMCPServer(config) {
|
|
|
15791
15805
|
process.on("SIGINT", () => void shutdown());
|
|
15792
15806
|
return {
|
|
15793
15807
|
invalidateResources() {
|
|
15794
|
-
|
|
15808
|
+
if (sessions.size === 0) return;
|
|
15809
|
+
const timestamp = Date.now();
|
|
15795
15810
|
for (const [, session] of sessions) {
|
|
15796
|
-
|
|
15797
|
-
|
|
15798
|
-
|
|
15811
|
+
for (const [name, handle] of session.resourceHandles) {
|
|
15812
|
+
handle.update({ uri: `ui://${name}-${timestamp}` });
|
|
15813
|
+
}
|
|
15814
|
+
for (const { handle, resourceName, toolMeta } of session.toolHandles) {
|
|
15815
|
+
const newUri = `ui://${resourceName}-${timestamp}`;
|
|
15816
|
+
handle.update({
|
|
15817
|
+
_meta: {
|
|
15818
|
+
...toolMeta,
|
|
15819
|
+
ui: { ...toolMeta.ui, resourceUri: newUri },
|
|
15820
|
+
"ui/resourceUri": newUri
|
|
15821
|
+
}
|
|
15822
|
+
});
|
|
15799
15823
|
}
|
|
15800
15824
|
}
|
|
15801
|
-
|
|
15802
|
-
console.log(`[MCP] Notified ${notified} session(s) of resource changes`);
|
|
15803
|
-
}
|
|
15825
|
+
console.log(`[MCP] Cache-busted ${sessions.size} session(s) with timestamp ${timestamp}`);
|
|
15804
15826
|
}
|
|
15805
15827
|
};
|
|
15806
15828
|
}
|