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

Function writeFile

apps/webuiapps/src/lib/localFileApi.ts:82–127  ·  view source on GitHub ↗
(
    path: string,
    content: unknown,
    options?: WriteFileOptions,
  )

Source from the content-addressed store, hash-verified

80 };
81
82 const writeFile = async (
83 path: string,
84 content: unknown,
85 options?: WriteFileOptions,
86 ): Promise<void> => {
87 const normalizedPath = normalizePath(path);
88 const existingNode = findNodeByPath(normalizedPath);
89
90 if (existingNode) {
91 if (!options?.overwrite) {
92 throw new Error(`File already exists: ${path}`);
93 }
94 existingNode.content = content;
95 existingNode.metadata = {
96 ...existingNode.metadata,
97 ...options?.metadata,
98 updatedAt: Date.now(),
99 };
100 return;
101 }
102
103 const parentPath = getParentPath(normalizedPath);
104 const parentNode = findNodeByPath(parentPath);
105
106 if (!parentNode) {
107 throw new Error(`Parent directory not found: ${parentPath}`);
108 }
109
110 const nodeId = generateId();
111 const newNode: FileNode = {
112 id: nodeId,
113 name: getFileName(normalizedPath),
114 path: normalizedPath,
115 type: 'file',
116 parentId: parentNode.id,
117 content,
118 metadata: {
119 createdAt: Date.now(),
120 updatedAt: Date.now(),
121 ...options?.metadata,
122 },
123 };
124
125 store.set(nodeId, newNode);
126 parentNode.children = [...(parentNode.children || []), nodeId];
127 };
128
129 const deleteFile = async (path: string): Promise<void> => {
130 const normalizedPath = normalizePath(path);

Callers

nothing calls this directly

Calls 5

normalizePathFunction · 0.90
getParentPathFunction · 0.90
generateIdFunction · 0.90
getFileNameFunction · 0.90
findNodeByPathFunction · 0.85

Tested by

no test coverage detected