MCPcopy Create free account
hub / github.com/MiniMax-AI/OpenRoom / addNode

Method addNode

apps/webuiapps/src/lib/FileSystemStore.ts:184–226  ·  view source on GitHub ↗

* Add a node

(params: CreateFileNodeParams)

Source from the content-addressed store, hash-verified

182 * Add a node
183 */
184 addNode(params: CreateFileNodeParams): FileNode {
185 const normalizedPath = normalizePath(params.path);
186
187 // Check if already exists
188 if (this.pathIndex.has(normalizedPath)) {
189 throw new Error(`Path already exists: ${normalizedPath}`);
190 }
191
192 // Get parent node
193 const parentPath = getParentPath(normalizedPath);
194 const parent = this.getByPath(parentPath);
195 if (!parent) {
196 throw new Error(`Parent not found: ${parentPath}`);
197 }
198
199 const nodeId = params.id || generateId();
200 const now = Date.now();
201
202 const node: FileNode = {
203 id: nodeId,
204 name: params.name || getFileName(normalizedPath),
205 path: normalizedPath,
206 type: params.type,
207 parentId: parent.id,
208 children: params.type === 'folder' ? [] : undefined,
209 content: params.content,
210 metadata: {
211 createdAt: now,
212 updatedAt: now,
213 ...params.metadata,
214 },
215 };
216
217 // Add to store
218 this.nodes.set(nodeId, node);
219 this.pathIndex.set(normalizedPath, nodeId);
220
221 // Update parent's children
222 parent.children = [...(parent.children || []), nodeId];
223
224 this.emit('node_added', nodeId, normalizedPath);
225 return node;
226 }
227
228 /**
229 * Update a node

Callers 2

loadFromNodesMethod · 0.95
useFileSystemFunction · 0.80

Calls 6

getByPathMethod · 0.95
emitMethod · 0.95
normalizePathFunction · 0.90
getParentPathFunction · 0.90
getFileNameFunction · 0.90
generateIdFunction · 0.70

Tested by

no test coverage detected