|
1 | 1 | import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js' |
2 | 2 | import { forkSceneGraph, type SceneGraph } from '@pascal-app/core/clone-scene-graph' |
3 | | -import { type AnyNode, AnyNode as AnyNodeSchema } from '@pascal-app/core/schema' |
| 3 | +import { AnyNode as AnyNodeSchema } from '@pascal-app/core/schema' |
4 | 4 | import { z } from 'zod' |
5 | 5 | import type { SceneOperations } from '../../operations' |
6 | 6 | import { ErrorCode, throwMcpError } from '../errors' |
@@ -43,43 +43,6 @@ export const generateVariantsOutput = { |
43 | 43 | ), |
44 | 44 | } |
45 | 45 |
|
46 | | -/** |
47 | | - * `forkSceneGraph` normalises `SiteNode.children` to string IDs, but the |
48 | | - * `SiteNode` schema declares that field as an array of full `BuildingNode` / |
49 | | - * `ItemNode` objects (see CROSS_CUTTING §2). To keep variants validating |
50 | | - * against `AnyNode`, re-embed the site children from the flat dict. |
51 | | - * |
52 | | - * Pure: returns a new graph without mutating the input. |
53 | | - */ |
54 | | -function rehydrateSiteChildren(graph: SceneGraph): SceneGraph { |
55 | | - const out: SceneGraph = { |
56 | | - nodes: { ...graph.nodes }, |
57 | | - rootNodeIds: [...graph.rootNodeIds], |
58 | | - ...(graph.collections ? { collections: graph.collections } : {}), |
59 | | - } |
60 | | - for (const [id, node] of Object.entries(out.nodes)) { |
61 | | - if (node.type !== 'site') continue |
62 | | - const childrenField = (node as { children?: unknown[] }).children |
63 | | - if (!Array.isArray(childrenField)) continue |
64 | | - const rehydrated: AnyNode[] = [] |
65 | | - for (const child of childrenField) { |
66 | | - if (typeof child === 'string') { |
67 | | - const target = out.nodes[child as keyof typeof out.nodes] |
68 | | - if (target && (target.type === 'building' || target.type === 'item')) { |
69 | | - rehydrated.push(target) |
70 | | - } |
71 | | - } else if (child && typeof child === 'object' && 'id' in (child as Record<string, unknown>)) { |
72 | | - rehydrated.push(child as AnyNode) |
73 | | - } |
74 | | - } |
75 | | - out.nodes[id as keyof typeof out.nodes] = { |
76 | | - ...(node as AnyNode), |
77 | | - children: rehydrated, |
78 | | - } as AnyNode |
79 | | - } |
80 | | - return out |
81 | | -} |
82 | | - |
83 | 46 | /** |
84 | 47 | * Count how many nodes in a graph fail `AnyNode` validation. Used to keep the |
85 | 48 | * tool from returning silently corrupt variants. |
@@ -140,8 +103,6 @@ export function registerGenerateVariants(server: McpServer, bridge: SceneOperati |
140 | 103 | for (const kind of mutations) { |
141 | 104 | forked = applyMutation(forked, rng, kind) |
142 | 105 | } |
143 | | - // Re-embed site children so variants match the SiteNode schema. |
144 | | - forked = rehydrateSiteChildren(forked) |
145 | 106 |
|
146 | 107 | const invalidCount = countInvalidNodes(forked) |
147 | 108 | if (invalidCount > 0) { |
|
0 commit comments