@vulcan-energy/mcp-helper 0.1.7 → 0.1.8
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 +8 -4
- package/dist/bin/vulcan-mcp-helper.d.ts +0 -8
- package/dist/bin/vulcan-mcp-helper.js +2875 -42
- package/dist/{src/server.d.ts → server.d.ts} +3 -2
- package/dist/server.js +2844 -0
- package/package.json +4 -3
- package/wasm/wasm_version.json +2 -2
- package/wasm/wasm_wrapper.js +2 -2
- package/dist/bin/vulcan-mcp-helper.d.ts.map +0 -1
- package/dist/bin/vulcan-mcp-helper.js.map +0 -1
- package/dist/src/engine/filesystem.d.ts +0 -30
- package/dist/src/engine/filesystem.d.ts.map +0 -1
- package/dist/src/engine/filesystem.js +0 -61
- package/dist/src/engine/filesystem.js.map +0 -1
- package/dist/src/engine/licenseKeys.d.ts +0 -2
- package/dist/src/engine/licenseKeys.d.ts.map +0 -1
- package/dist/src/engine/licenseKeys.js +0 -9
- package/dist/src/engine/licenseKeys.js.map +0 -1
- package/dist/src/engine/wasm.d.ts +0 -23
- package/dist/src/engine/wasm.d.ts.map +0 -1
- package/dist/src/engine/wasm.js +0 -335
- package/dist/src/engine/wasm.js.map +0 -1
- package/dist/src/engine/workspace.d.ts +0 -23
- package/dist/src/engine/workspace.d.ts.map +0 -1
- package/dist/src/engine/workspace.js +0 -138
- package/dist/src/engine/workspace.js.map +0 -1
- package/dist/src/server.d.ts.map +0 -1
- package/dist/src/server.js +0 -172
- package/dist/src/server.js.map +0 -1
- package/dist/src/tools/autoThermalBridges.d.ts +0 -8
- package/dist/src/tools/autoThermalBridges.d.ts.map +0 -1
- package/dist/src/tools/autoThermalBridges.js +0 -12
- package/dist/src/tools/autoThermalBridges.js.map +0 -1
- package/dist/src/tools/calculateMetrics.d.ts +0 -7
- package/dist/src/tools/calculateMetrics.d.ts.map +0 -1
- package/dist/src/tools/calculateMetrics.js +0 -23
- package/dist/src/tools/calculateMetrics.js.map +0 -1
- package/dist/src/tools/createBatchConfig.d.ts +0 -7
- package/dist/src/tools/createBatchConfig.d.ts.map +0 -1
- package/dist/src/tools/createBatchConfig.js +0 -8
- package/dist/src/tools/createBatchConfig.js.map +0 -1
- package/dist/src/tools/geometryCsvConversion.d.ts +0 -3
- package/dist/src/tools/geometryCsvConversion.d.ts.map +0 -1
- package/dist/src/tools/geometryCsvConversion.js +0 -2
- package/dist/src/tools/geometryCsvConversion.js.map +0 -1
- package/dist/src/tools/getBatchStatus.d.ts +0 -7
- package/dist/src/tools/getBatchStatus.d.ts.map +0 -1
- package/dist/src/tools/getBatchStatus.js +0 -8
- package/dist/src/tools/getBatchStatus.js.map +0 -1
- package/dist/src/tools/index.d.ts +0 -100
- package/dist/src/tools/index.d.ts.map +0 -1
- package/dist/src/tools/index.js +0 -500
- package/dist/src/tools/index.js.map +0 -1
- package/dist/src/tools/listBatchModels.d.ts +0 -8
- package/dist/src/tools/listBatchModels.d.ts.map +0 -1
- package/dist/src/tools/listBatchModels.js +0 -8
- package/dist/src/tools/listBatchModels.js.map +0 -1
- package/dist/src/tools/listCsvColumns.d.ts +0 -8
- package/dist/src/tools/listCsvColumns.d.ts.map +0 -1
- package/dist/src/tools/listCsvColumns.js +0 -8
- package/dist/src/tools/listCsvColumns.js.map +0 -1
- package/dist/src/tools/listParameters.d.ts +0 -7
- package/dist/src/tools/listParameters.d.ts.map +0 -1
- package/dist/src/tools/listParameters.js +0 -8
- package/dist/src/tools/listParameters.js.map +0 -1
- package/dist/src/tools/mergeCsvToJson.d.ts +0 -21
- package/dist/src/tools/mergeCsvToJson.d.ts.map +0 -1
- package/dist/src/tools/mergeCsvToJson.js +0 -44
- package/dist/src/tools/mergeCsvToJson.js.map +0 -1
- package/dist/src/tools/runBatch.d.ts +0 -7
- package/dist/src/tools/runBatch.d.ts.map +0 -1
- package/dist/src/tools/runBatch.js +0 -41
- package/dist/src/tools/runBatch.js.map +0 -1
- package/dist/src/tools/saveParameter.d.ts +0 -7
- package/dist/src/tools/saveParameter.d.ts.map +0 -1
- package/dist/src/tools/saveParameter.js +0 -23
- package/dist/src/tools/saveParameter.js.map +0 -1
- package/dist/src/tools/validateGeometryCsv.d.ts +0 -8
- package/dist/src/tools/validateGeometryCsv.d.ts.map +0 -1
- package/dist/src/tools/validateGeometryCsv.js +0 -12
- package/dist/src/tools/validateGeometryCsv.js.map +0 -1
- package/dist/src/tools/validateThermalBridges.d.ts +0 -9
- package/dist/src/tools/validateThermalBridges.d.ts.map +0 -1
- package/dist/src/tools/validateThermalBridges.js +0 -13
- package/dist/src/tools/validateThermalBridges.js.map +0 -1
- package/dist/src/tools/viewParameter.d.ts +0 -7
- package/dist/src/tools/viewParameter.d.ts.map +0 -1
- package/dist/src/tools/viewParameter.js +0 -8
- package/dist/src/tools/viewParameter.js.map +0 -1
- package/dist/src/utils/batchConfig.d.ts +0 -32
- package/dist/src/utils/batchConfig.d.ts.map +0 -1
- package/dist/src/utils/batchConfig.js +0 -148
- package/dist/src/utils/batchConfig.js.map +0 -1
- package/dist/src/utils/defaultsPaths.d.ts +0 -10
- package/dist/src/utils/defaultsPaths.d.ts.map +0 -1
- package/dist/src/utils/defaultsPaths.js +0 -47
- package/dist/src/utils/defaultsPaths.js.map +0 -1
- package/dist/src/utils/fileLoader.d.ts +0 -40
- package/dist/src/utils/fileLoader.d.ts.map +0 -1
- package/dist/src/utils/fileLoader.js +0 -149
- package/dist/src/utils/fileLoader.js.map +0 -1
- package/dist/src/utils/schemaPaths.d.ts +0 -2
- package/dist/src/utils/schemaPaths.d.ts.map +0 -1
- package/dist/src/utils/schemaPaths.js +0 -12
- package/dist/src/utils/schemaPaths.js.map +0 -1
- package/dist/src/utils/tls.d.ts +0 -7
- package/dist/src/utils/tls.d.ts.map +0 -1
- package/dist/src/utils/tls.js +0 -183
- package/dist/src/utils/tls.js.map +0 -1
|
@@ -1,35 +1,2870 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
2
|
+
|
|
3
|
+
// src/server.ts
|
|
4
|
+
import express from "express";
|
|
5
|
+
import cors from "cors";
|
|
6
|
+
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
7
|
+
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
|
|
8
|
+
import {
|
|
9
|
+
ListToolsRequestSchema,
|
|
10
|
+
CallToolRequestSchema,
|
|
11
|
+
InitializeRequestSchema
|
|
12
|
+
} from "@modelcontextprotocol/sdk/types.js";
|
|
13
|
+
|
|
14
|
+
// src/engine/workspace.ts
|
|
15
|
+
import fs from "fs/promises";
|
|
16
|
+
import path from "path";
|
|
17
|
+
import { jwtVerify, importSPKI } from "jose";
|
|
18
|
+
|
|
19
|
+
// src/engine/licenseKeys.ts
|
|
20
|
+
var MCP_PUBLIC_KEYS = [
|
|
21
|
+
`-----BEGIN PUBLIC KEY-----
|
|
22
|
+
MCowBQYDK2VwAyEAOmr0DweQnQ2L747vGML7l/ieYywCQzrnd39idAZ2YK4=
|
|
23
|
+
-----END PUBLIC KEY-----`
|
|
24
|
+
];
|
|
25
|
+
|
|
26
|
+
// src/engine/workspace.ts
|
|
27
|
+
var WARNING_WINDOW_SECONDS = 3 * 24 * 60 * 60;
|
|
28
|
+
var CLOCK_SKEW_TOLERANCE_SECONDS = 300;
|
|
29
|
+
async function readConfig(configPath) {
|
|
30
|
+
let resolvedPath = configPath;
|
|
31
|
+
if (!resolvedPath) {
|
|
32
|
+
const workspace = process.env.VULCAN_WORKSPACE;
|
|
33
|
+
if (workspace) {
|
|
34
|
+
resolvedPath = path.join(workspace, "vulcan-mcp-config.json");
|
|
35
|
+
} else {
|
|
36
|
+
resolvedPath = path.join(process.cwd(), "vulcan-mcp-config.json");
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
resolvedPath = path.resolve(resolvedPath);
|
|
40
|
+
let configContent;
|
|
41
|
+
try {
|
|
42
|
+
configContent = await fs.readFile(resolvedPath, "utf-8");
|
|
43
|
+
} catch (error) {
|
|
44
|
+
const err = error;
|
|
45
|
+
throw new Error(`Config file not found: ${resolvedPath}. Please generate it from Vulcan \u2192 Integrations \u2192 MCP.`);
|
|
46
|
+
}
|
|
47
|
+
let config;
|
|
48
|
+
try {
|
|
49
|
+
config = JSON.parse(configContent);
|
|
50
|
+
} catch (error) {
|
|
51
|
+
const err = error;
|
|
52
|
+
throw new Error(`Invalid JSON in config file: ${err.message}`);
|
|
53
|
+
}
|
|
54
|
+
if (!config.workspace) {
|
|
55
|
+
throw new Error("Config file missing required field: workspace");
|
|
56
|
+
}
|
|
57
|
+
if (!config.license_token || typeof config.license_token !== "string") {
|
|
58
|
+
throw new Error('Your Vulcan MCP token is missing. Open Vulcan \u2192 Integrations \u2192 MCP and click "Generate config".');
|
|
59
|
+
}
|
|
60
|
+
const workspacePath = path.resolve(path.dirname(resolvedPath), config.workspace);
|
|
61
|
+
try {
|
|
62
|
+
await fs.access(workspacePath);
|
|
63
|
+
} catch (error) {
|
|
64
|
+
throw new Error(`Workspace directory not found: ${workspacePath}`);
|
|
65
|
+
}
|
|
66
|
+
const batchParamsDir = path.join(workspacePath, "input", "batch_parameters");
|
|
67
|
+
try {
|
|
68
|
+
await fs.access(batchParamsDir);
|
|
69
|
+
} catch (error) {
|
|
70
|
+
throw new Error(`Workspace missing required directory: ${batchParamsDir}. MCP only supports folder (FSA) workspaces backed by the real filesystem.`);
|
|
71
|
+
}
|
|
72
|
+
const { payload } = await verifyLicenseToken(config.license_token);
|
|
73
|
+
const nowSeconds = Math.floor(Date.now() / 1e3);
|
|
74
|
+
const exp = payload.exp;
|
|
75
|
+
if (exp - nowSeconds < WARNING_WINDOW_SECONDS) {
|
|
76
|
+
console.error(
|
|
77
|
+
'[MCP Helper] Warning: Your Vulcan MCP token will expire soon. Open Vulcan \u2192 Integrations \u2192 MCP and click "Refresh token" to avoid interruptions.'
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
workspace: workspacePath,
|
|
82
|
+
license_token: config.license_token,
|
|
83
|
+
configPath: resolvedPath
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
async function verifyLicenseToken(token) {
|
|
87
|
+
const nowSeconds = Math.floor(Date.now() / 1e3);
|
|
88
|
+
let lastError;
|
|
89
|
+
for (const pem of MCP_PUBLIC_KEYS) {
|
|
90
|
+
try {
|
|
91
|
+
const key = await importSPKI(pem, "EdDSA");
|
|
92
|
+
const { payload } = await jwtVerify(token, key, { algorithms: ["EdDSA"] });
|
|
93
|
+
const claims = payload;
|
|
94
|
+
if (!claims.token_id || !claims.user_id || !Array.isArray(claims.entitlements)) {
|
|
95
|
+
throw new Error("MCP license token missing required claims");
|
|
96
|
+
}
|
|
97
|
+
if (!claims.entitlements.includes("mcp")) {
|
|
98
|
+
throw new Error('MCP license token missing "mcp" entitlement');
|
|
99
|
+
}
|
|
100
|
+
const iat = claims.iat;
|
|
101
|
+
const exp = claims.exp;
|
|
102
|
+
if (typeof iat !== "number" || typeof exp !== "number") {
|
|
103
|
+
throw new Error("MCP license token missing iat/exp claims");
|
|
104
|
+
}
|
|
105
|
+
if (nowSeconds < iat - CLOCK_SKEW_TOLERANCE_SECONDS) {
|
|
106
|
+
console.error(
|
|
107
|
+
"[MCP Helper] System clock appears to be too far behind the token issue time."
|
|
108
|
+
);
|
|
109
|
+
throw new Error("clock skew too large");
|
|
110
|
+
}
|
|
111
|
+
if (nowSeconds > exp) {
|
|
112
|
+
console.error(
|
|
113
|
+
"[MCP Helper] MCP license token expired at",
|
|
114
|
+
new Date(exp * 1e3).toISOString()
|
|
115
|
+
);
|
|
116
|
+
throw new Error("token expired");
|
|
117
|
+
}
|
|
118
|
+
return { payload: claims };
|
|
119
|
+
} catch (err) {
|
|
120
|
+
lastError = err;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
const message = lastError instanceof Error && lastError.message.includes("expired") ? 'Your Vulcan MCP token has expired. Open Vulcan \u2192 Integrations \u2192 MCP and click "Refresh token" to continue.' : "Your Vulcan MCP token is invalid or was signed with an unknown key. Please refresh your token in Vulcan \u2192 Integrations \u2192 MCP.";
|
|
124
|
+
throw new Error(message);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// src/engine/requestAuth.ts
|
|
128
|
+
import { timingSafeEqual } from "crypto";
|
|
129
|
+
function extractBearerToken(header) {
|
|
130
|
+
if (typeof header !== "string") {
|
|
131
|
+
throw new Error("MCP request Bearer token is required");
|
|
132
|
+
}
|
|
133
|
+
const match = /^Bearer[\t ]+([^\t ]+)$/i.exec(header.trim());
|
|
134
|
+
if (!match?.[1]) {
|
|
135
|
+
throw new Error("MCP request Bearer token is required");
|
|
136
|
+
}
|
|
137
|
+
return match[1];
|
|
138
|
+
}
|
|
139
|
+
function tokensMatch(candidate, expected) {
|
|
140
|
+
const candidateBytes = Buffer.from(candidate);
|
|
141
|
+
const expectedBytes = Buffer.from(expected);
|
|
142
|
+
return candidateBytes.length === expectedBytes.length && timingSafeEqual(candidateBytes, expectedBytes);
|
|
143
|
+
}
|
|
144
|
+
async function authorizeMcpRequest(authorizationHeader, expectedToken, verify = verifyLicenseToken) {
|
|
145
|
+
const candidate = extractBearerToken(authorizationHeader);
|
|
146
|
+
if (!tokensMatch(candidate, expectedToken)) {
|
|
147
|
+
throw new Error("MCP request Bearer token is invalid");
|
|
148
|
+
}
|
|
149
|
+
await verify(candidate);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// src/engine/wasm.ts
|
|
153
|
+
import fs2 from "fs";
|
|
154
|
+
import path2 from "path";
|
|
155
|
+
import { fileURLToPath } from "url";
|
|
156
|
+
import { pathToFileURL } from "url";
|
|
157
|
+
var __filename = fileURLToPath(import.meta.url);
|
|
158
|
+
var __dirname = path2.dirname(__filename);
|
|
159
|
+
var consoleRedirected = false;
|
|
160
|
+
function redirectConsoleToStderr() {
|
|
161
|
+
if (consoleRedirected) {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
const originalConsole = globalThis.console || console;
|
|
165
|
+
if (!originalConsole) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
const errorLogger = typeof originalConsole.error === "function" ? originalConsole.error.bind(originalConsole) : (...args) => {
|
|
169
|
+
process.stderr.write(args.map(String).join(" ") + "\n");
|
|
170
|
+
};
|
|
171
|
+
const patchedConsole = originalConsole;
|
|
172
|
+
patchedConsole.log = (...args) => errorLogger(...args);
|
|
173
|
+
globalThis.console = patchedConsole;
|
|
174
|
+
consoleRedirected = true;
|
|
175
|
+
}
|
|
176
|
+
redirectConsoleToStderr();
|
|
177
|
+
function resolveWasmPaths() {
|
|
178
|
+
const roots = [];
|
|
179
|
+
let current = __dirname;
|
|
180
|
+
for (let depth = 0; depth < 6; depth += 1) {
|
|
181
|
+
roots.push(current);
|
|
182
|
+
const parent = path2.dirname(current);
|
|
183
|
+
if (parent === current) break;
|
|
184
|
+
current = parent;
|
|
185
|
+
}
|
|
186
|
+
roots.push(process.cwd());
|
|
187
|
+
const candidates = [];
|
|
188
|
+
for (const root of roots) {
|
|
189
|
+
candidates.push(
|
|
190
|
+
{ directory: path2.join(root, "wasm"), context: "helper-root" },
|
|
191
|
+
{ directory: path2.join(root, "vulcan-mcp-server", "wasm"), context: "helper-dist" },
|
|
192
|
+
{ directory: path2.join(root, "web", "dist", "wasm"), context: "rust-hem-runner" },
|
|
193
|
+
{ directory: path2.join(root, "web", "dist"), context: "rust-hem-runner" },
|
|
194
|
+
{ directory: path2.join(root, "web", "pkg"), context: "rust-hem-runner" },
|
|
195
|
+
{ directory: path2.join(root, "apps", "web", "public", "launch"), context: "vulcan-website" }
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
const tried = [];
|
|
199
|
+
const seen = /* @__PURE__ */ new Set();
|
|
200
|
+
for (const candidate of candidates) {
|
|
201
|
+
const jsPath = path2.join(candidate.directory, "wasm_wrapper.js");
|
|
202
|
+
if (seen.has(jsPath)) continue;
|
|
203
|
+
seen.add(jsPath);
|
|
204
|
+
tried.push(jsPath);
|
|
205
|
+
const wasmPath = path2.join(candidate.directory, "wasm_wrapper_bg.wasm");
|
|
206
|
+
if (fs2.existsSync(jsPath) && fs2.existsSync(wasmPath)) {
|
|
207
|
+
return { jsPath, wasmPath, context: candidate.context };
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
throw new Error(
|
|
211
|
+
`WASM files not found. Tried:
|
|
212
|
+
` + tried.map((candidate) => ` - ${candidate}`).join("\n") + `
|
|
213
|
+
Please ensure WASM is built (run: scripts/deploy-wasm.sh --update)`
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
var wasmModule = null;
|
|
217
|
+
var wasmInitialized = false;
|
|
218
|
+
var currentWorkspace = process.cwd();
|
|
219
|
+
async function initWasm() {
|
|
220
|
+
if (wasmInitialized && wasmModule) {
|
|
221
|
+
return wasmModule;
|
|
222
|
+
}
|
|
223
|
+
try {
|
|
224
|
+
const { jsPath, wasmPath, context } = resolveWasmPaths();
|
|
225
|
+
console.error(`[WASM] Loading from ${context}: ${jsPath}`);
|
|
226
|
+
const global = globalThis;
|
|
227
|
+
if (!global.self) {
|
|
228
|
+
global.self = globalThis;
|
|
229
|
+
}
|
|
230
|
+
if (!global.window) {
|
|
231
|
+
global.window = globalThis;
|
|
232
|
+
}
|
|
233
|
+
if (typeof global.addEventListener !== "function") {
|
|
234
|
+
global.addEventListener = () => {
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
if (typeof global.postMessage !== "function") {
|
|
238
|
+
global.postMessage = () => {
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
if (typeof global.self.addEventListener !== "function") {
|
|
242
|
+
global.self.addEventListener = () => {
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
if (typeof global.self.postMessage !== "function") {
|
|
246
|
+
global.self.postMessage = () => {
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
if (typeof global.Worker !== "function") {
|
|
250
|
+
global.Worker = class {
|
|
251
|
+
constructor() {
|
|
252
|
+
}
|
|
253
|
+
addEventListener() {
|
|
254
|
+
}
|
|
255
|
+
postMessage() {
|
|
256
|
+
}
|
|
257
|
+
terminate() {
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
globalThis.write_file = (p, content) => {
|
|
262
|
+
const abs = path2.isAbsolute(p) ? p : path2.resolve(currentWorkspace, p);
|
|
263
|
+
try {
|
|
264
|
+
fs2.mkdirSync(path2.dirname(abs), { recursive: true });
|
|
265
|
+
fs2.writeFileSync(abs, content);
|
|
266
|
+
return true;
|
|
267
|
+
} catch (error) {
|
|
268
|
+
const err = error;
|
|
269
|
+
console.error(`[FS Bridge] write_file failed for ${abs}:`, err.message);
|
|
270
|
+
return false;
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
globalThis.read_file = (p) => {
|
|
274
|
+
const abs = path2.isAbsolute(p) ? p : path2.resolve(currentWorkspace, p);
|
|
275
|
+
try {
|
|
276
|
+
return fs2.readFileSync(abs, "utf8");
|
|
277
|
+
} catch (error) {
|
|
278
|
+
const err = error;
|
|
279
|
+
console.error(`[FS Bridge] read_file failed for ${abs}:`, err.message);
|
|
280
|
+
throw error;
|
|
281
|
+
}
|
|
282
|
+
};
|
|
283
|
+
globalThis.file_exists = (p) => {
|
|
284
|
+
try {
|
|
285
|
+
const abs = path2.isAbsolute(p) ? p : path2.resolve(currentWorkspace, p);
|
|
286
|
+
return fs2.existsSync(abs);
|
|
287
|
+
} catch {
|
|
288
|
+
return false;
|
|
289
|
+
}
|
|
290
|
+
};
|
|
291
|
+
globalThis.create_dir_all = (p) => {
|
|
292
|
+
const abs = path2.isAbsolute(p) ? p : path2.resolve(currentWorkspace, p);
|
|
293
|
+
try {
|
|
294
|
+
fs2.mkdirSync(abs, { recursive: true });
|
|
295
|
+
return true;
|
|
296
|
+
} catch (error) {
|
|
297
|
+
const err = error;
|
|
298
|
+
console.error(`[FS Bridge] create_dir_all failed for ${abs}:`, err.message);
|
|
299
|
+
return false;
|
|
300
|
+
}
|
|
301
|
+
};
|
|
302
|
+
globalThis.list_dir = (p) => {
|
|
303
|
+
const abs = path2.isAbsolute(p) ? p : path2.resolve(currentWorkspace, p);
|
|
304
|
+
try {
|
|
305
|
+
return fs2.readdirSync(abs);
|
|
306
|
+
} catch (error) {
|
|
307
|
+
const err = error;
|
|
308
|
+
console.error(`[FS Bridge] list_dir failed for ${abs}:`, err.message);
|
|
309
|
+
return [];
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
const originalFetch = globalThis.fetch;
|
|
313
|
+
globalThis.fetch = async (url, options) => {
|
|
314
|
+
if (typeof url === "string" && url.startsWith("file://")) {
|
|
315
|
+
const filePath = fileURLToPath(url);
|
|
316
|
+
try {
|
|
317
|
+
const content = fs2.readFileSync(filePath);
|
|
318
|
+
if (typeof Response !== "undefined") {
|
|
319
|
+
return new Response(content, {
|
|
320
|
+
status: 200,
|
|
321
|
+
statusText: "OK",
|
|
322
|
+
headers: { "Content-Type": "application/javascript" }
|
|
323
|
+
});
|
|
324
|
+
} else {
|
|
325
|
+
return {
|
|
326
|
+
ok: true,
|
|
327
|
+
status: 200,
|
|
328
|
+
statusText: "OK",
|
|
329
|
+
async text() {
|
|
330
|
+
return content.toString();
|
|
331
|
+
},
|
|
332
|
+
async arrayBuffer() {
|
|
333
|
+
return content.buffer;
|
|
334
|
+
},
|
|
335
|
+
headers: /* @__PURE__ */ new Map([["Content-Type", "application/javascript"]])
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
} catch (error) {
|
|
339
|
+
if (typeof Response !== "undefined") {
|
|
340
|
+
return new Response(null, {
|
|
341
|
+
status: 404,
|
|
342
|
+
statusText: "Not Found"
|
|
343
|
+
});
|
|
344
|
+
} else {
|
|
345
|
+
return {
|
|
346
|
+
ok: false,
|
|
347
|
+
status: 404,
|
|
348
|
+
statusText: "Not Found",
|
|
349
|
+
async text() {
|
|
350
|
+
return "";
|
|
351
|
+
},
|
|
352
|
+
async arrayBuffer() {
|
|
353
|
+
return new ArrayBuffer(0);
|
|
354
|
+
},
|
|
355
|
+
headers: /* @__PURE__ */ new Map()
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
if (originalFetch) {
|
|
361
|
+
return originalFetch(url, options);
|
|
362
|
+
}
|
|
363
|
+
throw new Error("fetch not available for non-file URLs");
|
|
364
|
+
};
|
|
365
|
+
const wasmModuleUrl = pathToFileURL(jsPath).href;
|
|
366
|
+
wasmModule = await import(wasmModuleUrl);
|
|
367
|
+
if (wasmModule.initSync) {
|
|
368
|
+
const wasmBytes = fs2.readFileSync(wasmPath);
|
|
369
|
+
wasmModule.initSync({ module: wasmBytes });
|
|
370
|
+
} else {
|
|
371
|
+
throw new Error("WASM module does not have initSync - this should not happen with wasm-pack build");
|
|
372
|
+
}
|
|
373
|
+
if (wasmModule.setup_panic_hook) {
|
|
374
|
+
wasmModule.setup_panic_hook();
|
|
375
|
+
}
|
|
376
|
+
wasmInitialized = true;
|
|
377
|
+
console.error(`[WASM] Initialized successfully from ${context}`);
|
|
378
|
+
return wasmModule;
|
|
379
|
+
} catch (error) {
|
|
380
|
+
console.error("[WASM] Initialization failed:", error);
|
|
381
|
+
wasmModule = null;
|
|
382
|
+
wasmInitialized = false;
|
|
383
|
+
const err = error;
|
|
384
|
+
throw new Error(`WASM initialization failed: ${err.message}`);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
function getWasmModule() {
|
|
388
|
+
if (!wasmModule || !wasmInitialized) {
|
|
389
|
+
throw new Error("WASM module not initialized. Call initWasm() first.");
|
|
390
|
+
}
|
|
391
|
+
return wasmModule;
|
|
392
|
+
}
|
|
393
|
+
function setWorkspace(workspace) {
|
|
394
|
+
currentWorkspace = workspace;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
// src/tools/index.ts
|
|
398
|
+
import { z } from "zod";
|
|
399
|
+
|
|
400
|
+
// ../packages/workspace-tools/src/batchConfig.ts
|
|
401
|
+
import fs3 from "fs/promises";
|
|
402
|
+
import path3 from "path";
|
|
403
|
+
function validateBatchConfigStructure(config) {
|
|
404
|
+
const errors = [];
|
|
405
|
+
const warnings = [];
|
|
406
|
+
if (!config || typeof config !== "object") {
|
|
407
|
+
return { valid: false, errors: ["Config must be an object"], warnings: [] };
|
|
408
|
+
}
|
|
409
|
+
const scenarios = Object.keys(config);
|
|
410
|
+
if (scenarios.length === 0) {
|
|
411
|
+
errors.push("Config must have at least one scenario");
|
|
412
|
+
}
|
|
413
|
+
for (const [scenarioName, scenarioValue] of Object.entries(config)) {
|
|
414
|
+
if (!scenarioValue || typeof scenarioValue !== "object") {
|
|
415
|
+
errors.push(`Scenario '${scenarioName}' must be an object`);
|
|
416
|
+
continue;
|
|
417
|
+
}
|
|
418
|
+
const scenario = scenarioValue;
|
|
419
|
+
if (!Array.isArray(scenario.base_json)) {
|
|
420
|
+
errors.push(`Scenario '${scenarioName}' is missing required 'base_json' field (must be array)`);
|
|
421
|
+
} else if (scenario.base_json.length !== 1) {
|
|
422
|
+
errors.push(`Scenario '${scenarioName}' must have exactly one base_json (found ${scenario.base_json.length})`);
|
|
423
|
+
}
|
|
424
|
+
const hasWeatherFiles = Boolean(scenario.weather_file || scenario.weather_files);
|
|
425
|
+
const hasExternalConditions = Boolean(scenario.external_conditions);
|
|
426
|
+
if (hasWeatherFiles) {
|
|
427
|
+
const weatherField = scenario.weather_file || scenario.weather_files;
|
|
428
|
+
if (Array.isArray(weatherField)) {
|
|
429
|
+
if (weatherField.length > 1) {
|
|
430
|
+
errors.push(`Scenario '${scenarioName}' must have at most one weather_file (found ${weatherField.length})`);
|
|
431
|
+
}
|
|
432
|
+
} else {
|
|
433
|
+
errors.push(`Scenario '${scenarioName}' weather_file/weather_files must be an array`);
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
if (hasExternalConditions && !Array.isArray(scenario.external_conditions)) {
|
|
437
|
+
errors.push(`Scenario '${scenarioName}' external_conditions must be an array`);
|
|
438
|
+
}
|
|
439
|
+
if (!hasWeatherFiles && !hasExternalConditions) {
|
|
440
|
+
errors.push(`Scenario '${scenarioName}' must have either 'weather_files' or 'external_conditions'`);
|
|
441
|
+
}
|
|
442
|
+
if (hasWeatherFiles && hasExternalConditions) {
|
|
443
|
+
warnings.push(`Scenario '${scenarioName}' has both 'weather_files' and 'external_conditions' - weather_files will take precedence`);
|
|
444
|
+
}
|
|
445
|
+
for (const [category, values] of Object.entries(scenario)) {
|
|
446
|
+
if (!Array.isArray(values)) {
|
|
447
|
+
errors.push(`Scenario '${scenarioName}': '${category}' must be an array`);
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
return {
|
|
452
|
+
valid: errors.length === 0,
|
|
453
|
+
errors,
|
|
454
|
+
warnings
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
function calculatePermutations(config) {
|
|
458
|
+
try {
|
|
459
|
+
if (!config || typeof config !== "object") return null;
|
|
460
|
+
let totalPermutations = 0;
|
|
461
|
+
for (const scenarioValue of Object.values(config)) {
|
|
462
|
+
if (!scenarioValue || typeof scenarioValue !== "object") continue;
|
|
463
|
+
const scenario = scenarioValue;
|
|
464
|
+
let scenarioPermutations = 1;
|
|
465
|
+
for (const values of Object.values(scenario)) {
|
|
466
|
+
if (Array.isArray(values)) {
|
|
467
|
+
scenarioPermutations *= values.length;
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
totalPermutations += scenarioPermutations;
|
|
471
|
+
}
|
|
472
|
+
return totalPermutations;
|
|
473
|
+
} catch {
|
|
474
|
+
return null;
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
async function validateParameterFilesExist(workspace, config) {
|
|
478
|
+
const errors = [];
|
|
479
|
+
const missingFiles = [];
|
|
480
|
+
if (!config || typeof config !== "object") {
|
|
481
|
+
return {
|
|
482
|
+
valid: false,
|
|
483
|
+
errors: ["Config must be an object"],
|
|
484
|
+
missingFiles
|
|
485
|
+
};
|
|
486
|
+
}
|
|
487
|
+
for (const [scenarioName, scenarioValue] of Object.entries(config)) {
|
|
488
|
+
if (!scenarioValue || typeof scenarioValue !== "object") continue;
|
|
489
|
+
const scenario = scenarioValue;
|
|
490
|
+
for (const [category, values] of Object.entries(scenario)) {
|
|
491
|
+
if (!Array.isArray(values)) continue;
|
|
492
|
+
if (category === "weather_file" || category === "weather_files") continue;
|
|
493
|
+
for (const paramId of values) {
|
|
494
|
+
const paramPath = path3.join(
|
|
495
|
+
workspace,
|
|
496
|
+
"input",
|
|
497
|
+
"batch_parameters",
|
|
498
|
+
category,
|
|
499
|
+
`${String(paramId)}.json`
|
|
500
|
+
);
|
|
501
|
+
try {
|
|
502
|
+
await fs3.access(paramPath);
|
|
503
|
+
} catch {
|
|
504
|
+
missingFiles.push({
|
|
505
|
+
scenario: scenarioName,
|
|
506
|
+
category,
|
|
507
|
+
parameter: String(paramId),
|
|
508
|
+
path: paramPath
|
|
509
|
+
});
|
|
510
|
+
errors.push(`Scenario '${scenarioName}': Parameter '${String(paramId)}' in category '${category}' not found at ${paramPath}`);
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
return {
|
|
516
|
+
valid: errors.length === 0,
|
|
517
|
+
errors,
|
|
518
|
+
missingFiles
|
|
519
|
+
};
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
// ../packages/workspace-tools/src/batches.ts
|
|
523
|
+
import { randomUUID } from "crypto";
|
|
524
|
+
import fs4 from "fs/promises";
|
|
525
|
+
import path4 from "path";
|
|
526
|
+
async function createBatchConfig(workspace, args) {
|
|
527
|
+
const { config_name, base_model, weather_file, wrapper, parameters } = args;
|
|
528
|
+
if (!config_name) {
|
|
529
|
+
throw new Error("config_name is required");
|
|
530
|
+
}
|
|
531
|
+
if (!base_model) {
|
|
532
|
+
throw new Error("base_model is required");
|
|
533
|
+
}
|
|
534
|
+
if (!weather_file) {
|
|
535
|
+
throw new Error("weather_file is required");
|
|
536
|
+
}
|
|
537
|
+
if (!parameters || typeof parameters !== "object" || Array.isArray(parameters)) {
|
|
538
|
+
throw new Error("parameters is required and must be an object mapping category to parameter IDs array");
|
|
539
|
+
}
|
|
540
|
+
const normalizedParameters = normalizeParameterSelections(parameters);
|
|
541
|
+
const batchConfig = {
|
|
542
|
+
scenario_1: {
|
|
543
|
+
base_json: [base_model],
|
|
544
|
+
weather_files: [weather_file],
|
|
545
|
+
...wrapper ? { model_wrappers: [wrapper] } : {},
|
|
546
|
+
...normalizedParameters
|
|
547
|
+
}
|
|
548
|
+
};
|
|
549
|
+
const structureValidation = validateBatchConfigStructure(batchConfig);
|
|
550
|
+
if (!structureValidation.valid) {
|
|
551
|
+
return {
|
|
552
|
+
success: false,
|
|
553
|
+
valid: false,
|
|
554
|
+
errors: structureValidation.errors,
|
|
555
|
+
warnings: structureValidation.warnings,
|
|
556
|
+
message: `Config validation failed: ${structureValidation.errors.join("; ")}`
|
|
557
|
+
};
|
|
558
|
+
}
|
|
559
|
+
const permutations = calculatePermutations(batchConfig);
|
|
560
|
+
if (permutations === null) {
|
|
561
|
+
return {
|
|
562
|
+
success: false,
|
|
563
|
+
valid: false,
|
|
564
|
+
errors: ["Failed to calculate permutations"],
|
|
565
|
+
message: "Failed to calculate permutations for batch config"
|
|
566
|
+
};
|
|
567
|
+
}
|
|
568
|
+
if (permutations > 500) {
|
|
569
|
+
return {
|
|
570
|
+
success: false,
|
|
571
|
+
valid: false,
|
|
572
|
+
errors: [`Total permutations (${permutations}) exceeds maximum of 500`],
|
|
573
|
+
message: `Config would generate ${permutations} permutations, which exceeds the limit of 500`
|
|
574
|
+
};
|
|
575
|
+
}
|
|
576
|
+
const fileValidation = await validateParameterFilesExist(workspace, batchConfig);
|
|
577
|
+
if (!fileValidation.valid) {
|
|
578
|
+
return {
|
|
579
|
+
success: false,
|
|
580
|
+
valid: false,
|
|
581
|
+
errors: fileValidation.errors,
|
|
582
|
+
missingFiles: fileValidation.missingFiles,
|
|
583
|
+
message: `Some parameter files are missing: ${fileValidation.errors.slice(0, 3).join("; ")}${fileValidation.errors.length > 3 ? "..." : ""}`
|
|
584
|
+
};
|
|
585
|
+
}
|
|
586
|
+
const baseModelPath = path4.join(
|
|
587
|
+
workspace,
|
|
588
|
+
"input",
|
|
589
|
+
"batch_parameters",
|
|
590
|
+
"base_json",
|
|
591
|
+
`${base_model}.json`
|
|
592
|
+
);
|
|
593
|
+
try {
|
|
594
|
+
await fs4.access(baseModelPath);
|
|
595
|
+
} catch {
|
|
596
|
+
return {
|
|
597
|
+
success: false,
|
|
598
|
+
valid: false,
|
|
599
|
+
errors: [`Base model '${base_model}' not found at ${baseModelPath}`],
|
|
600
|
+
message: `Base model file not found: ${base_model}`
|
|
601
|
+
};
|
|
602
|
+
}
|
|
603
|
+
const weatherFilePath = path4.join(
|
|
604
|
+
workspace,
|
|
605
|
+
"input",
|
|
606
|
+
"batch_parameters",
|
|
607
|
+
"weather_files",
|
|
608
|
+
weather_file.endsWith(".epw") ? weather_file : `${weather_file}.epw`
|
|
609
|
+
);
|
|
610
|
+
try {
|
|
611
|
+
await fs4.access(weatherFilePath);
|
|
612
|
+
} catch {
|
|
613
|
+
return {
|
|
614
|
+
success: false,
|
|
615
|
+
valid: false,
|
|
616
|
+
errors: [`Weather file '${weather_file}' not found at ${weatherFilePath}`],
|
|
617
|
+
message: `Weather file not found: ${weather_file}`
|
|
618
|
+
};
|
|
619
|
+
}
|
|
620
|
+
const configDir = path4.join(workspace, "input", "batch_configs");
|
|
621
|
+
await fs4.mkdir(configDir, { recursive: true });
|
|
622
|
+
const configFileName = config_name.endsWith(".json") ? config_name : `${config_name}.json`;
|
|
623
|
+
const configPath = path4.join(configDir, configFileName);
|
|
624
|
+
try {
|
|
625
|
+
await fs4.access(configPath);
|
|
626
|
+
return {
|
|
627
|
+
success: false,
|
|
628
|
+
valid: false,
|
|
629
|
+
errors: [`Config file '${configFileName}' already exists`],
|
|
630
|
+
message: "Config file already exists. Use a different name or delete the existing file first."
|
|
631
|
+
};
|
|
632
|
+
} catch {
|
|
633
|
+
}
|
|
634
|
+
await fs4.writeFile(configPath, JSON.stringify(batchConfig, null, 2), "utf8");
|
|
635
|
+
return {
|
|
636
|
+
success: true,
|
|
637
|
+
valid: true,
|
|
638
|
+
message: `Batch config '${config_name}' created successfully`,
|
|
639
|
+
config_path: configPath,
|
|
640
|
+
permutations,
|
|
641
|
+
structure: batchConfig
|
|
642
|
+
};
|
|
643
|
+
}
|
|
644
|
+
async function runBatch(workspace, args, deps) {
|
|
645
|
+
const { config_name, job_id } = args;
|
|
646
|
+
if (!config_name) {
|
|
647
|
+
throw new Error("config_name is required");
|
|
648
|
+
}
|
|
649
|
+
const finalJobId = job_id || deps.generateJobId?.() || `mcp_${randomUUID()}`;
|
|
650
|
+
const configFileName = config_name.endsWith(".json") ? config_name : `${config_name}.json`;
|
|
651
|
+
const configPath = path4.join(workspace, "input", "batch_configs", configFileName);
|
|
652
|
+
let configContent;
|
|
653
|
+
try {
|
|
654
|
+
configContent = await fs4.readFile(configPath, "utf8");
|
|
655
|
+
} catch (error) {
|
|
656
|
+
const err = error;
|
|
657
|
+
if (err.code === "ENOENT") {
|
|
658
|
+
throw new Error(`Batch config '${config_name}' not found at ${configPath}`);
|
|
659
|
+
}
|
|
660
|
+
throw new Error(`Failed to read config file: ${err.message}`);
|
|
661
|
+
}
|
|
662
|
+
const outputDir = path4.join(workspace, "output");
|
|
663
|
+
await fs4.mkdir(outputDir, { recursive: true });
|
|
664
|
+
try {
|
|
665
|
+
const resultJson = deps.processBatchConfig(
|
|
666
|
+
configContent,
|
|
667
|
+
workspace,
|
|
668
|
+
outputDir,
|
|
669
|
+
config_name.replace(/\.json$/, ""),
|
|
670
|
+
finalJobId
|
|
671
|
+
);
|
|
672
|
+
const result = JSON.parse(resultJson);
|
|
673
|
+
if (result.error) {
|
|
674
|
+
return {
|
|
675
|
+
job_id: finalJobId,
|
|
676
|
+
status: "error",
|
|
677
|
+
message: `Batch execution failed: ${result.error}`,
|
|
678
|
+
error: result.error
|
|
679
|
+
};
|
|
680
|
+
}
|
|
681
|
+
return {
|
|
682
|
+
job_id: finalJobId,
|
|
683
|
+
status: "started",
|
|
684
|
+
message: "Batch execution started successfully",
|
|
685
|
+
config_name,
|
|
686
|
+
output_dir: outputDir
|
|
687
|
+
};
|
|
688
|
+
} catch (error) {
|
|
689
|
+
const err = error;
|
|
690
|
+
return {
|
|
691
|
+
job_id: finalJobId,
|
|
692
|
+
status: "error",
|
|
693
|
+
message: `Failed to start batch execution: ${err.message}`,
|
|
694
|
+
error: err.message
|
|
695
|
+
};
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
async function getBatchStatus(workspace, args = {}) {
|
|
699
|
+
let { job_id, config_name } = args;
|
|
700
|
+
if (config_name && !job_id) {
|
|
701
|
+
const outputDir2 = path4.join(workspace, "output");
|
|
702
|
+
const cleanConfigName = config_name.replace(/\.json$/, "");
|
|
703
|
+
try {
|
|
704
|
+
const files = await fs4.readdir(outputDir2);
|
|
705
|
+
const progressFiles = files.filter((file) => file.startsWith("progress_") && file.endsWith(".json")).map((file) => ({
|
|
706
|
+
name: file,
|
|
707
|
+
jobId: file.replace("progress_", "").replace(".json", ""),
|
|
708
|
+
path: path4.join(outputDir2, file),
|
|
709
|
+
isMcp: file.startsWith("progress_mcp_")
|
|
710
|
+
}));
|
|
711
|
+
const filesWithStats = await Promise.all(
|
|
712
|
+
progressFiles.map(async (file) => {
|
|
713
|
+
try {
|
|
714
|
+
const stat = await fs4.stat(file.path);
|
|
715
|
+
return { ...file, mtime: stat.mtime };
|
|
716
|
+
} catch {
|
|
717
|
+
return { ...file, mtime: /* @__PURE__ */ new Date(0) };
|
|
718
|
+
}
|
|
719
|
+
})
|
|
720
|
+
);
|
|
721
|
+
filesWithStats.sort((a, b) => {
|
|
722
|
+
if (a.isMcp && !b.isMcp) return -1;
|
|
723
|
+
if (!a.isMcp && b.isMcp) return 1;
|
|
724
|
+
return b.mtime.getTime() - a.mtime.getTime();
|
|
725
|
+
});
|
|
726
|
+
if (filesWithStats[0]) {
|
|
727
|
+
job_id = filesWithStats[0].jobId;
|
|
728
|
+
}
|
|
729
|
+
} catch (error2) {
|
|
730
|
+
console.warn(`Failed to find job_id for config_name '${config_name}': ${error2.message}`);
|
|
731
|
+
}
|
|
732
|
+
if (!job_id) {
|
|
733
|
+
return {
|
|
734
|
+
config_name: cleanConfigName,
|
|
735
|
+
status: "queued",
|
|
736
|
+
progress: 0,
|
|
737
|
+
passes: 0,
|
|
738
|
+
failures: 0,
|
|
739
|
+
output_dir: path4.join(workspace, "output"),
|
|
740
|
+
error: null,
|
|
741
|
+
batch_progress: void 0,
|
|
742
|
+
sim_progress: void 0
|
|
743
|
+
};
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
if (!job_id) {
|
|
747
|
+
throw new Error("Either job_id or config_name is required");
|
|
748
|
+
}
|
|
749
|
+
const outputDir = path4.join(workspace, "output");
|
|
750
|
+
const progressPath = path4.join(outputDir, `progress_${job_id}.json`);
|
|
751
|
+
const simProgressPath = path4.join(outputDir, `sim_progress_${job_id}.json`);
|
|
752
|
+
let batchProgress = null;
|
|
753
|
+
let simProgress = null;
|
|
754
|
+
try {
|
|
755
|
+
batchProgress = JSON.parse(await fs4.readFile(progressPath, "utf8"));
|
|
756
|
+
} catch (error2) {
|
|
757
|
+
const err = error2;
|
|
758
|
+
if (err.code !== "ENOENT") {
|
|
759
|
+
console.warn(`Failed to read batch progress: ${err.message}`);
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
try {
|
|
763
|
+
simProgress = JSON.parse(await fs4.readFile(simProgressPath, "utf8"));
|
|
764
|
+
} catch (error2) {
|
|
765
|
+
const err = error2;
|
|
766
|
+
if (err.code !== "ENOENT") {
|
|
767
|
+
console.warn(`Failed to read simulation progress: ${err.message}`);
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
let status = "queued";
|
|
771
|
+
let progress = 0;
|
|
772
|
+
let passes = 0;
|
|
773
|
+
let failures = 0;
|
|
774
|
+
let error = null;
|
|
775
|
+
if (batchProgress) {
|
|
776
|
+
if (isBatchStatus(batchProgress.status)) {
|
|
777
|
+
status = batchProgress.status;
|
|
778
|
+
} else if (typeof batchProgress.percentage === "number") {
|
|
779
|
+
progress = batchProgress.percentage;
|
|
780
|
+
status = progress >= 100 ? "completed" : "running";
|
|
781
|
+
} else if (typeof batchProgress.current_combination === "number" && typeof batchProgress.total_combinations === "number") {
|
|
782
|
+
progress = Math.round(
|
|
783
|
+
batchProgress.current_combination / batchProgress.total_combinations * 100
|
|
784
|
+
);
|
|
785
|
+
status = progress >= 100 ? "completed" : "running";
|
|
786
|
+
}
|
|
787
|
+
if (typeof batchProgress.error === "string") {
|
|
788
|
+
error = batchProgress.error;
|
|
789
|
+
status = "error";
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
if (simProgress) {
|
|
793
|
+
if (isBatchStatus(simProgress.status)) {
|
|
794
|
+
status = simProgress.status;
|
|
795
|
+
}
|
|
796
|
+
if (typeof simProgress.passes === "number") {
|
|
797
|
+
passes = simProgress.passes;
|
|
798
|
+
}
|
|
799
|
+
if (typeof simProgress.failures === "number") {
|
|
800
|
+
failures = simProgress.failures;
|
|
801
|
+
}
|
|
802
|
+
if (typeof simProgress.error === "string") {
|
|
803
|
+
error = simProgress.error;
|
|
804
|
+
status = "error";
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
if (!batchProgress && !simProgress) {
|
|
808
|
+
const jobOutputDir = path4.join(outputDir, job_id);
|
|
809
|
+
try {
|
|
810
|
+
const entries = await fs4.readdir(jobOutputDir);
|
|
811
|
+
status = entries.length > 0 ? "completed" : "queued";
|
|
812
|
+
progress = entries.length > 0 ? 100 : 0;
|
|
813
|
+
} catch {
|
|
814
|
+
status = "queued";
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
return {
|
|
818
|
+
job_id,
|
|
819
|
+
...config_name ? { config_name: config_name.replace(/\.json$/, "") } : {},
|
|
820
|
+
status,
|
|
821
|
+
progress,
|
|
822
|
+
passes,
|
|
823
|
+
failures,
|
|
824
|
+
output_dir: outputDir,
|
|
825
|
+
error,
|
|
826
|
+
batch_progress: batchProgress,
|
|
827
|
+
sim_progress: simProgress
|
|
828
|
+
};
|
|
829
|
+
}
|
|
830
|
+
function normalizeParameterSelections(parameters) {
|
|
831
|
+
return Object.fromEntries(
|
|
832
|
+
Object.entries(parameters).map(([category, values]) => [
|
|
833
|
+
category,
|
|
834
|
+
Array.isArray(values) ? values.map(String) : [String(values)]
|
|
835
|
+
])
|
|
836
|
+
);
|
|
837
|
+
}
|
|
838
|
+
function isBatchStatus(value) {
|
|
839
|
+
return value === "queued" || value === "running" || value === "completed" || value === "error";
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
// ../packages/workspace-tools/src/defaults.ts
|
|
843
|
+
import fs5 from "fs/promises";
|
|
844
|
+
import path5 from "path";
|
|
845
|
+
var DEFAULT_DEFAULTS_PATH = "input/defaults/defaults_template.json";
|
|
846
|
+
var LEGACY_DEFAULT_DEFAULTS_PATH = "input/batch_parameters/base_json/defaults_template.json";
|
|
847
|
+
var LEGACY_SUFFIX = "batch_parameters/base_json/defaults_template.json";
|
|
848
|
+
var CANONICAL_SUFFIX = "defaults/defaults_template.json";
|
|
849
|
+
function parseCsvDefaultsPath(csvContent) {
|
|
850
|
+
const head = csvContent.split("\n").slice(0, 50);
|
|
851
|
+
const metaLine = head.find((line) => /^DefaultsPath,/i.test(line.trim()));
|
|
852
|
+
if (!metaLine) return null;
|
|
853
|
+
const parts = parseCsvLine(metaLine);
|
|
854
|
+
const parsed = (parts[1] || "").trim();
|
|
855
|
+
return parsed || null;
|
|
856
|
+
}
|
|
857
|
+
function isLegacyDefaultsTemplatePath(value) {
|
|
858
|
+
const normalized = value.trim().replace(/\\/g, "/");
|
|
859
|
+
return normalized === LEGACY_DEFAULT_DEFAULTS_PATH || normalized.endsWith("/batch_parameters/base_json/defaults_template.json");
|
|
860
|
+
}
|
|
861
|
+
function defaultsReadPathAttempts(workspaceRelativePath) {
|
|
862
|
+
const trimmed = workspaceRelativePath.trim();
|
|
863
|
+
if (!trimmed) return [];
|
|
864
|
+
if (!isLegacyDefaultsTemplatePath(trimmed)) return [trimmed];
|
|
865
|
+
const normalized = trimmed.replace(/\\/g, "/");
|
|
866
|
+
const suffixIndex = normalized.lastIndexOf(LEGACY_SUFFIX);
|
|
867
|
+
const canonical = suffixIndex >= 0 ? `${normalized.slice(0, suffixIndex)}${CANONICAL_SUFFIX}` : DEFAULT_DEFAULTS_PATH;
|
|
868
|
+
return [canonical, trimmed];
|
|
869
|
+
}
|
|
870
|
+
async function loadDefaultsForCsv(args) {
|
|
871
|
+
const explicitDefaultsPath = (args.explicitDefaultsPath ?? "").trim();
|
|
872
|
+
const declaredDefaultsPath = explicitDefaultsPath || parseCsvDefaultsPath(args.csvContent);
|
|
873
|
+
if (declaredDefaultsPath) {
|
|
874
|
+
const attempts = defaultsReadPathAttempts(declaredDefaultsPath);
|
|
875
|
+
let lastError;
|
|
876
|
+
for (const relativePath of attempts) {
|
|
877
|
+
const absolutePath = path5.isAbsolute(relativePath) ? relativePath : path5.join(args.workspace, relativePath);
|
|
878
|
+
try {
|
|
879
|
+
return {
|
|
880
|
+
defaultsJson: await fs5.readFile(absolutePath, "utf8"),
|
|
881
|
+
source: explicitDefaultsPath ? `custom: ${relativePath}` : `CSV metadata: ${relativePath}`,
|
|
882
|
+
path: absolutePath
|
|
883
|
+
};
|
|
884
|
+
} catch (error) {
|
|
885
|
+
lastError = error;
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
const message = lastError instanceof Error ? lastError.message : String(lastError);
|
|
889
|
+
throw new Error(
|
|
890
|
+
`Could not read defaults file "${declaredDefaultsPath}". Conversion was aborted instead of silently substituting the standard defaults template. ${message}`
|
|
891
|
+
);
|
|
892
|
+
}
|
|
893
|
+
for (const relativePath of [
|
|
894
|
+
DEFAULT_DEFAULTS_PATH,
|
|
895
|
+
LEGACY_DEFAULT_DEFAULTS_PATH,
|
|
896
|
+
"defaults_template.json"
|
|
897
|
+
]) {
|
|
898
|
+
const absolutePath = path5.join(args.workspace, relativePath);
|
|
899
|
+
try {
|
|
900
|
+
return {
|
|
901
|
+
defaultsJson: await fs5.readFile(absolutePath, "utf8"),
|
|
902
|
+
source: "legacy fallback: standard defaults template",
|
|
903
|
+
path: absolutePath
|
|
904
|
+
};
|
|
905
|
+
} catch {
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
throw new Error(
|
|
909
|
+
`Defaults file not found. Tried ${DEFAULT_DEFAULTS_PATH}, ${LEGACY_DEFAULT_DEFAULTS_PATH}, defaults_template.json`
|
|
910
|
+
);
|
|
911
|
+
}
|
|
912
|
+
function parseCsvLine(line) {
|
|
913
|
+
const result = [];
|
|
914
|
+
let current = "";
|
|
915
|
+
let inQuotes = false;
|
|
916
|
+
for (let i = 0; i < line.length; i += 1) {
|
|
917
|
+
const ch = line[i];
|
|
918
|
+
if (inQuotes) {
|
|
919
|
+
if (ch === '"') {
|
|
920
|
+
if (line[i + 1] === '"') {
|
|
921
|
+
current += '"';
|
|
922
|
+
i += 1;
|
|
923
|
+
} else {
|
|
924
|
+
inQuotes = false;
|
|
925
|
+
}
|
|
926
|
+
} else {
|
|
927
|
+
current += ch;
|
|
928
|
+
}
|
|
929
|
+
} else if (ch === '"') {
|
|
930
|
+
inQuotes = true;
|
|
931
|
+
} else if (ch === ",") {
|
|
932
|
+
result.push(current);
|
|
933
|
+
current = "";
|
|
934
|
+
} else {
|
|
935
|
+
current += ch;
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
result.push(current);
|
|
939
|
+
return result;
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
// ../packages/workspace-tools/src/geometryCsv.ts
|
|
943
|
+
import crypto from "crypto";
|
|
944
|
+
import fs8 from "fs/promises";
|
|
945
|
+
import path8 from "path";
|
|
946
|
+
|
|
947
|
+
// ../packages/workspace-tools/src/repo.ts
|
|
948
|
+
import fs6 from "fs";
|
|
949
|
+
import path6 from "path";
|
|
950
|
+
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
951
|
+
function findRepoRoot(start = process.cwd()) {
|
|
952
|
+
let current = path6.resolve(start);
|
|
953
|
+
if (fs6.existsSync(current) && fs6.statSync(current).isFile()) {
|
|
954
|
+
current = path6.dirname(current);
|
|
955
|
+
}
|
|
956
|
+
while (true) {
|
|
957
|
+
if (fs6.existsSync(path6.join(current, "package.json")) && fs6.existsSync(path6.join(current, "hem-batch-core")) && fs6.existsSync(path6.join(current, "web"))) {
|
|
958
|
+
return current;
|
|
959
|
+
}
|
|
960
|
+
const parent = path6.dirname(current);
|
|
961
|
+
if (parent === current) {
|
|
962
|
+
break;
|
|
963
|
+
}
|
|
964
|
+
current = parent;
|
|
965
|
+
}
|
|
966
|
+
const moduleDir = path6.dirname(fileURLToPath2(import.meta.url));
|
|
967
|
+
return path6.resolve(moduleDir, "..", "..", "..");
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
// ../packages/workspace-tools/src/schema.ts
|
|
971
|
+
import fs7 from "fs/promises";
|
|
972
|
+
import path7 from "path";
|
|
973
|
+
function parseSchemaModeFromCsv(csvContent) {
|
|
974
|
+
let complianceValidationEnabled = false;
|
|
975
|
+
let metadataSchemaMode = null;
|
|
976
|
+
for (const rawLine of csvContent.split("\n").slice(0, 80)) {
|
|
977
|
+
const line = rawLine.trim();
|
|
978
|
+
if (/^ComplianceValidationEnabled,/i.test(line)) {
|
|
979
|
+
const value = parseCsvLine2(line)[1]?.trim().toUpperCase();
|
|
980
|
+
complianceValidationEnabled = value === "TRUE";
|
|
981
|
+
continue;
|
|
982
|
+
}
|
|
983
|
+
if (/^SchemaProfile,/i.test(line)) {
|
|
984
|
+
const value = parseCsvLine2(line)[1]?.trim().toLowerCase();
|
|
985
|
+
if (value === "ecaas_input_fhs") metadataSchemaMode = "ecaas_input_fhs";
|
|
986
|
+
if (value === "input_fhs") metadataSchemaMode = "input_fhs";
|
|
987
|
+
if (value === "input_core") metadataSchemaMode = "input_core";
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
if (metadataSchemaMode) return metadataSchemaMode;
|
|
991
|
+
return complianceValidationEnabled ? "input_fhs" : "input_core";
|
|
992
|
+
}
|
|
993
|
+
async function loadSchemaForCsv(args) {
|
|
994
|
+
const mode = parseSchemaModeFromCsv(args.csvContent);
|
|
995
|
+
if (args.explicitSchemaPath) {
|
|
996
|
+
const schemaPath = path7.isAbsolute(args.explicitSchemaPath) ? args.explicitSchemaPath : path7.resolve(args.workspace ?? process.cwd(), args.explicitSchemaPath);
|
|
997
|
+
return {
|
|
998
|
+
mode,
|
|
999
|
+
source: schemaPath,
|
|
1000
|
+
schemaJson: await fs7.readFile(schemaPath, "utf8")
|
|
1001
|
+
};
|
|
1002
|
+
}
|
|
1003
|
+
const candidates = schemaCandidatePaths({
|
|
1004
|
+
mode,
|
|
1005
|
+
repoRoot: args.repoRoot,
|
|
1006
|
+
workspace: args.workspace
|
|
1007
|
+
});
|
|
1008
|
+
const tried = [];
|
|
1009
|
+
for (const schemaPath of candidates) {
|
|
1010
|
+
tried.push(schemaPath);
|
|
1011
|
+
try {
|
|
1012
|
+
return {
|
|
1013
|
+
mode,
|
|
1014
|
+
source: schemaPath,
|
|
1015
|
+
schemaJson: await fs7.readFile(schemaPath, "utf8")
|
|
1016
|
+
};
|
|
1017
|
+
} catch {
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
throw new Error(`Schema file not found for ${mode}. Tried: ${tried.join(", ")}`);
|
|
1021
|
+
}
|
|
1022
|
+
function schemaCandidatePaths(args) {
|
|
1023
|
+
const candidates = [];
|
|
1024
|
+
if (args.repoRoot) {
|
|
1025
|
+
candidates.push(path7.join(args.repoRoot, ...repoSchemaPathSegments(args.mode)));
|
|
1026
|
+
}
|
|
1027
|
+
if (args.workspace) {
|
|
1028
|
+
const workspaceSegments = workspaceSchemaCandidateSegments(args.mode);
|
|
1029
|
+
candidates.push(...workspaceSegments.map((segments) => path7.join(args.workspace, ...segments)));
|
|
1030
|
+
}
|
|
1031
|
+
return [...new Set(candidates)];
|
|
1032
|
+
}
|
|
1033
|
+
function repoSchemaPathSegments(mode) {
|
|
1034
|
+
switch (mode) {
|
|
1035
|
+
case "input_core":
|
|
1036
|
+
return ["hem_engine_upstream", "schemas", "core-input.schema.json"];
|
|
1037
|
+
case "input_fhs":
|
|
1038
|
+
return ["hem_fhs_upstream", "schema", "input_fhs.schema.json"];
|
|
1039
|
+
case "ecaas_input_fhs":
|
|
1040
|
+
return ["schemas", "ecaas_input_fhs.schema.json"];
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
function workspaceSchemaCandidateSegments(mode) {
|
|
1044
|
+
switch (mode) {
|
|
1045
|
+
case "input_core":
|
|
1046
|
+
return [
|
|
1047
|
+
["input_core.schema.json"],
|
|
1048
|
+
["hem_engine_upstream", "schemas", "core-input.schema.json"],
|
|
1049
|
+
["core-input.schema.json"],
|
|
1050
|
+
["schemas", "core-input.schema.json"],
|
|
1051
|
+
["input.schema.json"]
|
|
1052
|
+
];
|
|
1053
|
+
case "input_fhs":
|
|
1054
|
+
return [
|
|
1055
|
+
["input_fhs.schema.json"],
|
|
1056
|
+
["hem_fhs_upstream", "schema", "input_fhs.schema.json"],
|
|
1057
|
+
["schema", "input_fhs.schema.json"],
|
|
1058
|
+
["schemas", "input_fhs.schema.json"]
|
|
1059
|
+
];
|
|
1060
|
+
case "ecaas_input_fhs":
|
|
1061
|
+
return [
|
|
1062
|
+
["ecaas_input_fhs.schema.json"],
|
|
1063
|
+
["schemas", "ecaas_input_fhs.schema.json"]
|
|
1064
|
+
];
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
function parseCsvLine2(line) {
|
|
1068
|
+
const result = [];
|
|
1069
|
+
let current = "";
|
|
1070
|
+
let inQuotes = false;
|
|
1071
|
+
for (let i = 0; i < line.length; i += 1) {
|
|
1072
|
+
const ch = line[i];
|
|
1073
|
+
if (inQuotes) {
|
|
1074
|
+
if (ch === '"') {
|
|
1075
|
+
if (line[i + 1] === '"') {
|
|
1076
|
+
current += '"';
|
|
1077
|
+
i += 1;
|
|
1078
|
+
} else {
|
|
1079
|
+
inQuotes = false;
|
|
1080
|
+
}
|
|
1081
|
+
} else {
|
|
1082
|
+
current += ch;
|
|
1083
|
+
}
|
|
1084
|
+
} else if (ch === '"') {
|
|
1085
|
+
inQuotes = true;
|
|
1086
|
+
} else if (ch === ",") {
|
|
1087
|
+
result.push(current);
|
|
1088
|
+
current = "";
|
|
1089
|
+
} else {
|
|
1090
|
+
current += ch;
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
result.push(current);
|
|
1094
|
+
return result;
|
|
1095
|
+
}
|
|
1096
|
+
|
|
1097
|
+
// ../packages/workspace-tools/src/geometryCsv.ts
|
|
1098
|
+
async function convertGeometryCsvWithPolicy(args) {
|
|
1099
|
+
const { workspace, csvContent, schemaJson, defaultsPath, deps } = args;
|
|
1100
|
+
const defaults = await loadDefaultsForCsv({
|
|
1101
|
+
workspace,
|
|
1102
|
+
csvContent,
|
|
1103
|
+
explicitDefaultsPath: defaultsPath
|
|
1104
|
+
});
|
|
1105
|
+
let resultJson;
|
|
1106
|
+
try {
|
|
1107
|
+
resultJson = deps.convertGeometryCsvToJson(
|
|
1108
|
+
csvContent,
|
|
1109
|
+
schemaJson,
|
|
1110
|
+
defaults.defaultsJson
|
|
1111
|
+
);
|
|
1112
|
+
} catch (error) {
|
|
1113
|
+
const err = error;
|
|
1114
|
+
return {
|
|
1115
|
+
ok: false,
|
|
1116
|
+
error: `WASM conversion failed: ${err.message}`,
|
|
1117
|
+
defaults_source: defaults.source,
|
|
1118
|
+
defaults_path: defaults.path
|
|
1119
|
+
};
|
|
1120
|
+
}
|
|
1121
|
+
if (!resultJson || typeof resultJson !== "string") {
|
|
1122
|
+
return {
|
|
1123
|
+
ok: false,
|
|
1124
|
+
error: "WASM returned empty or invalid result",
|
|
1125
|
+
defaults_source: defaults.source,
|
|
1126
|
+
defaults_path: defaults.path
|
|
1127
|
+
};
|
|
1128
|
+
}
|
|
1129
|
+
const result = parseConversionEnvelope(resultJson);
|
|
1130
|
+
if (!result.ok || result.json === void 0 || result.json === null) {
|
|
1131
|
+
return {
|
|
1132
|
+
ok: false,
|
|
1133
|
+
validation: result.validation,
|
|
1134
|
+
error: result.error || "WASM conversion returned invalid result",
|
|
1135
|
+
defaults_source: defaults.source,
|
|
1136
|
+
defaults_path: defaults.path
|
|
1137
|
+
};
|
|
1138
|
+
}
|
|
1139
|
+
return {
|
|
1140
|
+
ok: true,
|
|
1141
|
+
json: result.json,
|
|
1142
|
+
validation: result.validation,
|
|
1143
|
+
defaults_source: defaults.source,
|
|
1144
|
+
defaults_path: defaults.path
|
|
1145
|
+
};
|
|
1146
|
+
}
|
|
1147
|
+
async function mergeGeometryCsvToJson(options) {
|
|
1148
|
+
const { workspace, csvPath, outputPath, schemaPath, defaultsPath, repoRoot, deps } = options;
|
|
1149
|
+
const csvAbsPath = path8.isAbsolute(csvPath) ? csvPath : path8.join(workspace, csvPath);
|
|
1150
|
+
let csvContent;
|
|
1151
|
+
try {
|
|
1152
|
+
csvContent = await fs8.readFile(csvAbsPath, "utf8");
|
|
1153
|
+
} catch (error) {
|
|
1154
|
+
const err = error;
|
|
1155
|
+
if (err.code === "ENOENT") {
|
|
1156
|
+
throw new Error(`CSV file not found at ${csvAbsPath}`);
|
|
1157
|
+
}
|
|
1158
|
+
throw new Error(`Failed to read CSV file: ${err.message}`);
|
|
1159
|
+
}
|
|
1160
|
+
const schema = await loadSchemaForCsv({
|
|
1161
|
+
repoRoot: repoRoot ?? findRepoRoot(workspace),
|
|
1162
|
+
workspace,
|
|
1163
|
+
csvContent,
|
|
1164
|
+
explicitSchemaPath: schemaPath
|
|
1165
|
+
});
|
|
1166
|
+
const conversion = await convertGeometryCsvWithPolicy({
|
|
1167
|
+
workspace,
|
|
1168
|
+
csvContent,
|
|
1169
|
+
schemaJson: schema.schemaJson,
|
|
1170
|
+
defaultsPath,
|
|
1171
|
+
deps
|
|
1172
|
+
});
|
|
1173
|
+
if (!conversion.ok || conversion.json === void 0 || conversion.json === null) {
|
|
1174
|
+
return {
|
|
1175
|
+
ok: false,
|
|
1176
|
+
validation: conversion.validation,
|
|
1177
|
+
error: conversion.error || "WASM conversion returned invalid result",
|
|
1178
|
+
defaults_source: conversion.defaults_source,
|
|
1179
|
+
schema_source: schema.source
|
|
1180
|
+
};
|
|
1181
|
+
}
|
|
1182
|
+
const outputAbsPath = outputPath ? path8.isAbsolute(outputPath) ? outputPath : path8.join(workspace, outputPath) : defaultJsonOutputPath(workspace, csvAbsPath);
|
|
1183
|
+
await fs8.mkdir(path8.dirname(outputAbsPath), { recursive: true });
|
|
1184
|
+
try {
|
|
1185
|
+
await fs8.writeFile(outputAbsPath, JSON.stringify(conversion.json, null, 2), "utf8");
|
|
1186
|
+
} catch (error) {
|
|
1187
|
+
const err = error;
|
|
1188
|
+
return {
|
|
1189
|
+
ok: false,
|
|
1190
|
+
validation: conversion.validation,
|
|
1191
|
+
error: `Failed to write JSON file: ${err.message}`,
|
|
1192
|
+
defaults_source: conversion.defaults_source,
|
|
1193
|
+
schema_source: schema.source
|
|
1194
|
+
};
|
|
1195
|
+
}
|
|
1196
|
+
return {
|
|
1197
|
+
ok: true,
|
|
1198
|
+
json_path: path8.relative(workspace, outputAbsPath),
|
|
1199
|
+
validation: conversion.validation,
|
|
1200
|
+
defaults_source: conversion.defaults_source,
|
|
1201
|
+
schema_source: schema.source
|
|
1202
|
+
};
|
|
1203
|
+
}
|
|
1204
|
+
function parseConversionEnvelope(resultJson) {
|
|
1205
|
+
try {
|
|
1206
|
+
return JSON.parse(resultJson);
|
|
1207
|
+
} catch (error) {
|
|
1208
|
+
const err = error;
|
|
1209
|
+
return {
|
|
1210
|
+
ok: false,
|
|
1211
|
+
error: `WASM returned invalid JSON: ${err.message}`
|
|
1212
|
+
};
|
|
1213
|
+
}
|
|
1214
|
+
}
|
|
1215
|
+
function defaultJsonOutputPath(workspace, csvAbsPath) {
|
|
1216
|
+
const csvBasename = path8.basename(csvAbsPath, path8.extname(csvAbsPath));
|
|
1217
|
+
return path8.join(
|
|
1218
|
+
workspace,
|
|
1219
|
+
"input",
|
|
1220
|
+
"batch_parameters",
|
|
1221
|
+
"base_json",
|
|
1222
|
+
`${csvBasename}.json`
|
|
1223
|
+
);
|
|
1224
|
+
}
|
|
1225
|
+
|
|
1226
|
+
// ../packages/workspace-tools/src/parameters.ts
|
|
1227
|
+
import fs9 from "fs/promises";
|
|
1228
|
+
import path9 from "path";
|
|
1229
|
+
async function listParameters(workspace, args = {}) {
|
|
1230
|
+
const { category: filterCategory } = args;
|
|
1231
|
+
const batchParamsDir = path9.join(workspace, "input", "batch_parameters");
|
|
1232
|
+
const entries = await fs9.readdir(batchParamsDir, { withFileTypes: true });
|
|
1233
|
+
const catalog = {};
|
|
1234
|
+
for (const entry of entries) {
|
|
1235
|
+
if (!entry.isDirectory()) continue;
|
|
1236
|
+
const categoryName = entry.name;
|
|
1237
|
+
if (filterCategory && categoryName !== filterCategory) continue;
|
|
1238
|
+
const categoryPath = path9.join(batchParamsDir, categoryName);
|
|
1239
|
+
const categoryFiles = await fs9.readdir(categoryPath);
|
|
1240
|
+
const parameters = [];
|
|
1241
|
+
for (const file of categoryFiles) {
|
|
1242
|
+
if (!file.endsWith(".json")) continue;
|
|
1243
|
+
const parameterId = file.replace(/\.json$/, "");
|
|
1244
|
+
const filePath = path9.join(categoryPath, file);
|
|
1245
|
+
try {
|
|
1246
|
+
const content = await fs9.readFile(filePath, "utf8");
|
|
1247
|
+
const json = JSON.parse(content);
|
|
1248
|
+
parameters.push({
|
|
1249
|
+
id: parameterId,
|
|
1250
|
+
name: typeof json.name === "string" ? json.name : parameterId,
|
|
1251
|
+
description: typeof json.description === "string" ? json.description : "",
|
|
1252
|
+
category: categoryName
|
|
1253
|
+
});
|
|
1254
|
+
} catch (error) {
|
|
1255
|
+
const err = error;
|
|
1256
|
+
console.error(`Failed to parse ${filePath}: ${err.message}`);
|
|
1257
|
+
}
|
|
1258
|
+
}
|
|
1259
|
+
if (parameters.length > 0) {
|
|
1260
|
+
catalog[categoryName] = {
|
|
1261
|
+
category: categoryName,
|
|
1262
|
+
parameters: parameters.sort((a, b) => a.name.localeCompare(b.name))
|
|
1263
|
+
};
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
1266
|
+
return {
|
|
1267
|
+
catalog,
|
|
1268
|
+
total_categories: Object.keys(catalog).length,
|
|
1269
|
+
total_parameters: Object.values(catalog).reduce(
|
|
1270
|
+
(sum, category) => sum + category.parameters.length,
|
|
1271
|
+
0
|
|
1272
|
+
)
|
|
1273
|
+
};
|
|
1274
|
+
}
|
|
1275
|
+
async function viewParameter(workspace, args) {
|
|
1276
|
+
const { category, parameter_id } = args;
|
|
1277
|
+
if (!category) {
|
|
1278
|
+
throw new Error("category is required");
|
|
1279
|
+
}
|
|
1280
|
+
if (!parameter_id) {
|
|
1281
|
+
throw new Error("parameter_id is required");
|
|
1282
|
+
}
|
|
1283
|
+
const paramDir = path9.join(workspace, "input", "batch_parameters", category);
|
|
1284
|
+
const jsonPath = path9.join(paramDir, `${parameter_id}.json`);
|
|
1285
|
+
const markdownPath = path9.join(paramDir, `${parameter_id}.md`);
|
|
1286
|
+
let jsonContent;
|
|
1287
|
+
try {
|
|
1288
|
+
const content = await fs9.readFile(jsonPath, "utf8");
|
|
1289
|
+
jsonContent = JSON.parse(content);
|
|
1290
|
+
} catch (error) {
|
|
1291
|
+
const err = error;
|
|
1292
|
+
if (err.code === "ENOENT") {
|
|
1293
|
+
throw new Error(`Parameter '${parameter_id}' not found in category '${category}'`);
|
|
1294
|
+
}
|
|
1295
|
+
throw new Error(`Failed to read parameter JSON: ${err.message}`);
|
|
1296
|
+
}
|
|
1297
|
+
let markdownContent = null;
|
|
1298
|
+
try {
|
|
1299
|
+
markdownContent = await fs9.readFile(markdownPath, "utf8");
|
|
1300
|
+
} catch (error) {
|
|
1301
|
+
const err = error;
|
|
1302
|
+
if (err.code !== "ENOENT") {
|
|
1303
|
+
console.warn(`Failed to read markdown file: ${err.message}`);
|
|
1304
|
+
}
|
|
1305
|
+
}
|
|
1306
|
+
return {
|
|
1307
|
+
category,
|
|
1308
|
+
parameter_id,
|
|
1309
|
+
json: jsonContent,
|
|
1310
|
+
markdown: markdownContent,
|
|
1311
|
+
has_markdown: markdownContent !== null
|
|
1312
|
+
};
|
|
1313
|
+
}
|
|
1314
|
+
async function saveParameter(workspace, args, deps) {
|
|
1315
|
+
const { category, parameter_id, content, markdown_content } = args;
|
|
1316
|
+
if (!category) {
|
|
1317
|
+
throw new Error("category is required");
|
|
1318
|
+
}
|
|
1319
|
+
if (!parameter_id) {
|
|
1320
|
+
throw new Error("parameter_id is required");
|
|
1321
|
+
}
|
|
1322
|
+
if (content === void 0 || content === null || content === "") {
|
|
1323
|
+
throw new Error("content is required");
|
|
1324
|
+
}
|
|
1325
|
+
const jsonContent = parseContent(content);
|
|
1326
|
+
const [schema, baseline, simplifiedExample] = await Promise.all([
|
|
1327
|
+
loadSnippetSchema(workspace),
|
|
1328
|
+
loadBaseline(workspace),
|
|
1329
|
+
loadSimplifiedExample(workspace, category)
|
|
1330
|
+
]);
|
|
1331
|
+
const validationResult = deps.validateSnippetJs(
|
|
1332
|
+
category,
|
|
1333
|
+
JSON.stringify(jsonContent),
|
|
1334
|
+
JSON.stringify(schema),
|
|
1335
|
+
JSON.stringify(baseline),
|
|
1336
|
+
simplifiedExample ? JSON.stringify(simplifiedExample) : null
|
|
1337
|
+
);
|
|
1338
|
+
const validation = JSON.parse(validationResult);
|
|
1339
|
+
if (!validation.ok) {
|
|
1340
|
+
const errors = (validation.errors ?? []).map(
|
|
1341
|
+
(error) => typeof error === "string" ? error : error.message || String(error)
|
|
1342
|
+
);
|
|
1343
|
+
return {
|
|
1344
|
+
success: false,
|
|
1345
|
+
valid: false,
|
|
1346
|
+
errors,
|
|
1347
|
+
message: `Validation failed: ${errors.join("; ")}`
|
|
1348
|
+
};
|
|
1349
|
+
}
|
|
1350
|
+
const paramDir = path9.join(workspace, "input", "batch_parameters", category);
|
|
1351
|
+
await fs9.mkdir(paramDir, { recursive: true });
|
|
1352
|
+
const jsonPath = path9.join(paramDir, `${parameter_id}.json`);
|
|
1353
|
+
await fs9.writeFile(jsonPath, JSON.stringify(jsonContent, null, 2), "utf8");
|
|
1354
|
+
let markdownPath = null;
|
|
1355
|
+
if (markdown_content) {
|
|
1356
|
+
markdownPath = path9.join(paramDir, `${parameter_id}.md`);
|
|
1357
|
+
await fs9.writeFile(markdownPath, markdown_content, "utf8");
|
|
1358
|
+
}
|
|
1359
|
+
return {
|
|
1360
|
+
success: true,
|
|
1361
|
+
valid: true,
|
|
1362
|
+
errors: [],
|
|
1363
|
+
message: `Parameter '${parameter_id}' saved successfully in category '${category}'`,
|
|
1364
|
+
paths: {
|
|
1365
|
+
json: jsonPath,
|
|
1366
|
+
markdown: markdownPath
|
|
1367
|
+
}
|
|
1368
|
+
};
|
|
1369
|
+
}
|
|
1370
|
+
function parseContent(content) {
|
|
1371
|
+
if (typeof content !== "string") {
|
|
1372
|
+
return content;
|
|
1373
|
+
}
|
|
1374
|
+
try {
|
|
1375
|
+
return JSON.parse(content);
|
|
1376
|
+
} catch (error) {
|
|
1377
|
+
throw new Error(`Invalid JSON syntax: ${error.message}`);
|
|
1378
|
+
}
|
|
1379
|
+
}
|
|
1380
|
+
async function loadSnippetSchema(workspace) {
|
|
1381
|
+
const schemaPaths = [
|
|
1382
|
+
path9.join(workspace, "input_core.schema.json"),
|
|
1383
|
+
path9.join(workspace, "hem_engine_upstream", "schemas", "core-input.schema.json"),
|
|
1384
|
+
path9.join(workspace, "core-input.schema.json"),
|
|
1385
|
+
path9.join(workspace, "schemas", "core-input.schema.json"),
|
|
1386
|
+
path9.join(workspace, "input.schema.json")
|
|
1387
|
+
];
|
|
1388
|
+
for (const schemaPath of schemaPaths) {
|
|
1389
|
+
try {
|
|
1390
|
+
return JSON.parse(await fs9.readFile(schemaPath, "utf8"));
|
|
1391
|
+
} catch {
|
|
1392
|
+
}
|
|
1393
|
+
}
|
|
1394
|
+
throw new Error(`Schema file not found. Tried: ${schemaPaths.join(", ")}`);
|
|
1395
|
+
}
|
|
1396
|
+
async function loadBaseline(workspace) {
|
|
1397
|
+
const baselinePath = path9.join(
|
|
1398
|
+
workspace,
|
|
1399
|
+
"input",
|
|
1400
|
+
"batch_parameters",
|
|
1401
|
+
"base_json",
|
|
1402
|
+
"demo_hp_annual.json"
|
|
1403
|
+
);
|
|
1404
|
+
try {
|
|
1405
|
+
return JSON.parse(await fs9.readFile(baselinePath, "utf8"));
|
|
1406
|
+
} catch (error) {
|
|
1407
|
+
const err = error;
|
|
1408
|
+
throw new Error(`Baseline model not found at ${baselinePath}: ${err.message}`);
|
|
1409
|
+
}
|
|
1410
|
+
}
|
|
1411
|
+
async function loadSimplifiedExample(workspace, category) {
|
|
1412
|
+
if (category !== "simplified_fabric") {
|
|
1413
|
+
return null;
|
|
1414
|
+
}
|
|
1415
|
+
const examplePaths = [
|
|
1416
|
+
path9.join(
|
|
1417
|
+
workspace,
|
|
1418
|
+
"input",
|
|
1419
|
+
"batch_parameters",
|
|
1420
|
+
"simplified_fabric",
|
|
1421
|
+
"good_insulation_compliance.json"
|
|
1422
|
+
),
|
|
1423
|
+
path9.join(
|
|
1424
|
+
workspace,
|
|
1425
|
+
"input",
|
|
1426
|
+
"batch_parameters",
|
|
1427
|
+
"simplified_fabric",
|
|
1428
|
+
"compliance_example.json"
|
|
1429
|
+
)
|
|
1430
|
+
];
|
|
1431
|
+
for (const examplePath of examplePaths) {
|
|
1432
|
+
try {
|
|
1433
|
+
return JSON.parse(await fs9.readFile(examplePath, "utf8"));
|
|
1434
|
+
} catch {
|
|
1435
|
+
}
|
|
1436
|
+
}
|
|
1437
|
+
return null;
|
|
1438
|
+
}
|
|
1439
|
+
|
|
1440
|
+
// ../packages/workspace-tools/src/metrics.ts
|
|
1441
|
+
import fs10 from "fs/promises";
|
|
1442
|
+
import path10 from "path";
|
|
1443
|
+
var CONDITIONAL_FUNCS = /* @__PURE__ */ new Set(["sumif", "averageif", "countif"]);
|
|
1444
|
+
var VALID_COMPARATORS = /* @__PURE__ */ new Set([">=", "<=", ">", "<", "="]);
|
|
1445
|
+
async function calculateMetrics(workspace, args, deps) {
|
|
1446
|
+
const {
|
|
1447
|
+
config_name,
|
|
1448
|
+
model_names,
|
|
1449
|
+
metric_definitions,
|
|
1450
|
+
time_range,
|
|
1451
|
+
tariff_file_path,
|
|
1452
|
+
tariff_column_index
|
|
1453
|
+
} = args;
|
|
1454
|
+
if (!config_name) {
|
|
1455
|
+
throw new Error("config_name is required");
|
|
1456
|
+
}
|
|
1457
|
+
if (!model_names || !Array.isArray(model_names) || model_names.length === 0) {
|
|
1458
|
+
throw new Error("model_names is required and must be a non-empty array");
|
|
1459
|
+
}
|
|
1460
|
+
if (!metric_definitions || !Array.isArray(metric_definitions) || metric_definitions.length === 0) {
|
|
1461
|
+
throw new Error("metric_definitions is required and must be a non-empty array");
|
|
1462
|
+
}
|
|
1463
|
+
const outputDir = path10.join(workspace, "output");
|
|
1464
|
+
const cleanConfigName = config_name.replace(/\.json$/, "");
|
|
1465
|
+
const { encodedMetrics, metadata: metricMetadata } = formatMetricDefinitions(metric_definitions);
|
|
1466
|
+
const hasCostMetric = metricMetadata.some(
|
|
1467
|
+
(metric) => metric.function.toLowerCase() === "cost"
|
|
1468
|
+
);
|
|
1469
|
+
if (hasCostMetric && (!tariff_file_path || tariff_column_index === void 0)) {
|
|
1470
|
+
throw new Error("Cost metrics require both tariff_file_path and tariff_column_index parameters");
|
|
1471
|
+
}
|
|
1472
|
+
let tariffJson;
|
|
1473
|
+
if (tariff_file_path && tariff_column_index !== void 0) {
|
|
1474
|
+
const tariffRates = await loadTariffData(tariff_file_path, tariff_column_index, workspace);
|
|
1475
|
+
tariffJson = JSON.stringify(tariffRates);
|
|
1476
|
+
}
|
|
1477
|
+
const allResults = [];
|
|
1478
|
+
for (const modelName of model_names) {
|
|
1479
|
+
const { csvPath, csvContent } = await readModelCsv({
|
|
1480
|
+
outputDir,
|
|
1481
|
+
cleanConfigName,
|
|
1482
|
+
modelName
|
|
1483
|
+
});
|
|
1484
|
+
try {
|
|
1485
|
+
const coreResultsData = parseCoreResults(csvContent, modelName, config_name);
|
|
1486
|
+
if (coreResultsData.timestamps.length === 0) {
|
|
1487
|
+
throw new Error(`No timestamps found in CSV for model ${modelName}`);
|
|
1488
|
+
}
|
|
1489
|
+
if (Object.keys(coreResultsData.columns).length === 0) {
|
|
1490
|
+
throw new Error(`No columns found in CSV for model ${modelName}`);
|
|
1491
|
+
}
|
|
1492
|
+
const missingColumns = missingMetricColumns(coreResultsData, encodedMetrics, metricMetadata);
|
|
1493
|
+
if (missingColumns.length > 0) {
|
|
1494
|
+
const availableColumns = Object.keys(coreResultsData.columns).slice(0, 10);
|
|
1495
|
+
throw new Error(
|
|
1496
|
+
`Columns not found in CSV: ${missingColumns.join(", ")}. Available columns: ${availableColumns.join(", ")}...`
|
|
1497
|
+
);
|
|
1498
|
+
}
|
|
1499
|
+
const resultJson = deps.calculateMetricsFromParsedData(
|
|
1500
|
+
JSON.stringify(coreResultsData),
|
|
1501
|
+
JSON.stringify(encodedMetrics),
|
|
1502
|
+
time_range ? JSON.stringify(time_range) : void 0,
|
|
1503
|
+
tariffJson
|
|
1504
|
+
);
|
|
1505
|
+
if (!resultJson || typeof resultJson !== "string") {
|
|
1506
|
+
throw new Error(`WASM returned invalid result: ${typeof resultJson}`);
|
|
1507
|
+
}
|
|
1508
|
+
const results = JSON.parse(resultJson);
|
|
1509
|
+
if (!Array.isArray(results)) {
|
|
1510
|
+
throw new Error(`WASM returned non-array result: ${typeof results}`);
|
|
1511
|
+
}
|
|
1512
|
+
results.forEach((result, index) => {
|
|
1513
|
+
const meta = metricMetadata[index];
|
|
1514
|
+
const [resultColumn = result.name, resultFunction = "sum"] = result.name.split("|");
|
|
1515
|
+
allResults.push({
|
|
1516
|
+
id: meta?.id || result.name,
|
|
1517
|
+
name: meta?.name || result.name,
|
|
1518
|
+
column: meta?.column || resultColumn,
|
|
1519
|
+
function: meta?.function || resultFunction,
|
|
1520
|
+
comparator: meta?.comparator,
|
|
1521
|
+
threshold: meta?.threshold,
|
|
1522
|
+
value: result.value,
|
|
1523
|
+
model_name: modelName
|
|
1524
|
+
});
|
|
1525
|
+
});
|
|
1526
|
+
} catch (error) {
|
|
1527
|
+
const err = error;
|
|
1528
|
+
if (err.code === "ENOENT") {
|
|
1529
|
+
console.warn(`CSV file not found for model ${modelName}: ${csvPath}`);
|
|
1530
|
+
continue;
|
|
1531
|
+
}
|
|
1532
|
+
throw new Error(`Failed to process model ${modelName}: ${err.message}`);
|
|
1533
|
+
}
|
|
1534
|
+
}
|
|
1535
|
+
return {
|
|
1536
|
+
metrics: allResults,
|
|
1537
|
+
total_models: model_names.length,
|
|
1538
|
+
total_metrics: allResults.length
|
|
1539
|
+
};
|
|
1540
|
+
}
|
|
1541
|
+
function parseCoreResults(csvContent, modelName, configName) {
|
|
1542
|
+
const lines = csvContent.split("\n").filter((line) => line.trim());
|
|
1543
|
+
if (lines.length < 2) {
|
|
1544
|
+
throw new Error("CSV must have at least headers and units rows");
|
|
1545
|
+
}
|
|
1546
|
+
const headers = (lines[0] ?? "").split(",").map((header) => header.trim());
|
|
1547
|
+
const units = (lines[1] ?? "").split(",").map((unit) => unit.trim());
|
|
1548
|
+
const timestamps = [];
|
|
1549
|
+
const columnsMap = {};
|
|
1550
|
+
const columnOrder = [];
|
|
1551
|
+
const columnUnits = [];
|
|
1552
|
+
for (let i = 1; i < headers.length; i += 1) {
|
|
1553
|
+
const header = headers[i];
|
|
1554
|
+
if (!header) continue;
|
|
1555
|
+
columnsMap[header] = [];
|
|
1556
|
+
columnOrder.push(header);
|
|
1557
|
+
columnUnits.push(i < units.length ? units[i] || "" : "");
|
|
1558
|
+
}
|
|
1559
|
+
for (let rowIndex = 2; rowIndex < lines.length; rowIndex += 1) {
|
|
1560
|
+
const row = (lines[rowIndex] ?? "").split(",").map((value) => value.trim());
|
|
1561
|
+
if (row.length === 0 || row.length === 1 && !row[0]) continue;
|
|
1562
|
+
const tsValue = row[0];
|
|
1563
|
+
if (!tsValue) continue;
|
|
1564
|
+
const timestep = Number.parseInt(tsValue, 10);
|
|
1565
|
+
if (Number.isNaN(timestep) || timestep < 0) continue;
|
|
1566
|
+
timestamps.push(timestep);
|
|
1567
|
+
for (let colIndex = 1; colIndex < headers.length && colIndex < row.length; colIndex += 1) {
|
|
1568
|
+
const header = headers[colIndex];
|
|
1569
|
+
if (!header || !columnsMap[header]) continue;
|
|
1570
|
+
const rowValue = row[colIndex];
|
|
1571
|
+
if (rowValue === void 0) continue;
|
|
1572
|
+
const value = Number.parseFloat(rowValue);
|
|
1573
|
+
columnsMap[header].push(Number.isNaN(value) ? 0 : value);
|
|
1574
|
+
}
|
|
1575
|
+
}
|
|
1576
|
+
return {
|
|
1577
|
+
timestamps,
|
|
1578
|
+
columns: columnsMap,
|
|
1579
|
+
column_order: columnOrder,
|
|
1580
|
+
column_units: columnUnits,
|
|
1581
|
+
metadata: {
|
|
1582
|
+
model_name: modelName,
|
|
1583
|
+
config_name: configName.replace(/\.json$/, ""),
|
|
1584
|
+
total_points: timestamps.length,
|
|
1585
|
+
sample_rate: 1800
|
|
1586
|
+
},
|
|
1587
|
+
dwelling_emission_rate: null,
|
|
1588
|
+
dwelling_primary_energy_rate: null,
|
|
1589
|
+
dwelling_fabric_energy_efficiency: null
|
|
1590
|
+
};
|
|
1591
|
+
}
|
|
1592
|
+
function buildFunctionSegment(definition) {
|
|
1593
|
+
const rawFunction = (definition.function || definition.type || "sum").toString();
|
|
1594
|
+
const normalized = rawFunction.toLowerCase();
|
|
1595
|
+
if (normalized === "cost") {
|
|
1596
|
+
return "cost";
|
|
1597
|
+
}
|
|
1598
|
+
if (!CONDITIONAL_FUNCS.has(normalized)) {
|
|
1599
|
+
return normalized;
|
|
1600
|
+
}
|
|
1601
|
+
const comparator = definition.comparator || ">=";
|
|
1602
|
+
if (!VALID_COMPARATORS.has(comparator)) {
|
|
1603
|
+
throw new Error(
|
|
1604
|
+
`Invalid comparator "${comparator}" for ${rawFunction}. Use one of ${Array.from(VALID_COMPARATORS).join(", ")}`
|
|
1605
|
+
);
|
|
1606
|
+
}
|
|
1607
|
+
if (definition.threshold === void 0 || definition.threshold === null || Number.isNaN(Number(definition.threshold))) {
|
|
1608
|
+
throw new Error(`threshold is required for ${rawFunction} metrics`);
|
|
1609
|
+
}
|
|
1610
|
+
return `${normalized}${comparator}${definition.threshold}`;
|
|
1611
|
+
}
|
|
1612
|
+
function formatMetricDefinitions(metricDefinitions) {
|
|
1613
|
+
const encodedMetrics = [];
|
|
1614
|
+
const metadata = [];
|
|
1615
|
+
metricDefinitions.forEach((definition, index) => {
|
|
1616
|
+
if (typeof definition === "string") {
|
|
1617
|
+
const encoded2 = definition.includes("|") ? definition : `${definition}|sum`;
|
|
1618
|
+
const [column2 = definition, fn = "sum"] = encoded2.split("|");
|
|
1619
|
+
encodedMetrics.push({ name: encoded2 });
|
|
1620
|
+
metadata.push({
|
|
1621
|
+
id: definition,
|
|
1622
|
+
name: definition,
|
|
1623
|
+
column: column2,
|
|
1624
|
+
function: fn,
|
|
1625
|
+
isCompliance: fn.toLowerCase() === "compliance"
|
|
1626
|
+
});
|
|
1627
|
+
return;
|
|
1628
|
+
}
|
|
1629
|
+
const column = definition.column || (definition.name?.includes("|") ? definition.name.split("|")[0] : definition.name);
|
|
1630
|
+
if (!column) {
|
|
1631
|
+
throw new Error(`Metric definition at index ${index} missing column or name. Got: ${JSON.stringify(definition)}`);
|
|
1632
|
+
}
|
|
1633
|
+
const functionSegment = definition.name?.includes("|") && !definition.function ? definition.name.split("|")[1] || "sum" : buildFunctionSegment(definition);
|
|
1634
|
+
const encoded = `${column}|${functionSegment}`;
|
|
1635
|
+
encodedMetrics.push({ name: encoded });
|
|
1636
|
+
metadata.push({
|
|
1637
|
+
id: definition.id || definition.metric_id || `${column}_${functionSegment}`,
|
|
1638
|
+
name: definition.name || definition.id || column,
|
|
1639
|
+
column,
|
|
1640
|
+
function: functionSegment,
|
|
1641
|
+
comparator: definition.comparator,
|
|
1642
|
+
threshold: definition.threshold,
|
|
1643
|
+
isCompliance: functionSegment.toLowerCase() === "compliance"
|
|
1644
|
+
});
|
|
1645
|
+
});
|
|
1646
|
+
return { encodedMetrics, metadata };
|
|
1647
|
+
}
|
|
1648
|
+
async function loadTariffData(tariffFilePath, columnIndex, workspacePath) {
|
|
1649
|
+
const resolvedPath = path10.isAbsolute(tariffFilePath) ? tariffFilePath : path10.resolve(workspacePath, tariffFilePath);
|
|
1650
|
+
const csvContent = await fs10.readFile(resolvedPath, "utf8").catch((error) => {
|
|
1651
|
+
throw new Error(`Failed to read tariff file: ${resolvedPath}. Error: ${error.message}`);
|
|
1652
|
+
});
|
|
1653
|
+
const lines = csvContent.split("\n").filter((line) => line.trim());
|
|
1654
|
+
if (lines.length === 0) {
|
|
1655
|
+
throw new Error(`Tariff file is empty: ${resolvedPath}`);
|
|
1656
|
+
}
|
|
1657
|
+
const rates = [];
|
|
1658
|
+
for (let i = 1; i < lines.length; i += 1) {
|
|
1659
|
+
const columns = (lines[i] ?? "").split(",").map((column) => column.trim().replace(/"/g, ""));
|
|
1660
|
+
if (columnIndex >= columns.length) {
|
|
1661
|
+
throw new Error(`Column index ${columnIndex} not found in record ${i} with ${columns.length} columns`);
|
|
1662
|
+
}
|
|
1663
|
+
const raw = columns[columnIndex];
|
|
1664
|
+
if (raw === void 0) {
|
|
1665
|
+
throw new Error(`Column index ${columnIndex} is undefined in record ${i}`);
|
|
1666
|
+
}
|
|
1667
|
+
const parsed = Number.parseFloat(raw);
|
|
1668
|
+
if (Number.isNaN(parsed)) {
|
|
1669
|
+
throw new Error(`Could not parse '${raw}' as number in row ${i + 1}, column ${columnIndex + 1}`);
|
|
1670
|
+
}
|
|
1671
|
+
rates.push(parsed);
|
|
1672
|
+
}
|
|
1673
|
+
if (rates.length !== 17520) {
|
|
1674
|
+
throw new Error(`Tariff must contain 17,520 rows (found ${rates.length})`);
|
|
1675
|
+
}
|
|
1676
|
+
return rates;
|
|
1677
|
+
}
|
|
1678
|
+
async function readModelCsv(args) {
|
|
1679
|
+
const { outputDir, cleanConfigName, modelName } = args;
|
|
1680
|
+
const candidates = [
|
|
1681
|
+
path10.join(outputDir, cleanConfigName, `${modelName}__core__results.csv`),
|
|
1682
|
+
path10.join(outputDir, cleanConfigName, `${modelName}__results.csv`)
|
|
1683
|
+
];
|
|
1684
|
+
try {
|
|
1685
|
+
const files = await fs10.readdir(outputDir);
|
|
1686
|
+
const resultDirs = files.filter((file) => file.startsWith(`result_${cleanConfigName}_`));
|
|
1687
|
+
for (const resultDir of resultDirs) {
|
|
1688
|
+
candidates.push(path10.join(outputDir, resultDir, `${modelName}__core__results.csv`));
|
|
1689
|
+
candidates.push(path10.join(outputDir, resultDir, `${modelName}__results.csv`));
|
|
1690
|
+
}
|
|
1691
|
+
} catch {
|
|
1692
|
+
}
|
|
1693
|
+
for (const csvPath of candidates) {
|
|
1694
|
+
try {
|
|
1695
|
+
return {
|
|
1696
|
+
csvPath,
|
|
1697
|
+
csvContent: await fs10.readFile(csvPath, "utf8")
|
|
1698
|
+
};
|
|
1699
|
+
} catch {
|
|
1700
|
+
}
|
|
1701
|
+
}
|
|
1702
|
+
throw new Error(`CSV file not found for model ${modelName}. Tried: ${candidates.join(", ")}`);
|
|
1703
|
+
}
|
|
1704
|
+
function missingMetricColumns(coreResultsData, encodedMetrics, metricMetadata) {
|
|
1705
|
+
const missingColumns = [];
|
|
1706
|
+
encodedMetrics.forEach((metric, index) => {
|
|
1707
|
+
const columnName = metric.name.split("|")[0];
|
|
1708
|
+
if (!columnName) {
|
|
1709
|
+
throw new Error(`Invalid metric name format: ${metric.name}`);
|
|
1710
|
+
}
|
|
1711
|
+
if (metricMetadata[index]?.isCompliance) {
|
|
1712
|
+
return;
|
|
1713
|
+
}
|
|
1714
|
+
if (!coreResultsData.columns[columnName]) {
|
|
1715
|
+
missingColumns.push(columnName);
|
|
1716
|
+
}
|
|
1717
|
+
});
|
|
1718
|
+
return missingColumns;
|
|
1719
|
+
}
|
|
1720
|
+
|
|
1721
|
+
// ../packages/workspace-tools/src/results.ts
|
|
1722
|
+
import fs11 from "fs/promises";
|
|
1723
|
+
import path11 from "path";
|
|
1724
|
+
async function listBatchModels(workspace, args) {
|
|
1725
|
+
const outputDir = path11.join(workspace, "output");
|
|
1726
|
+
const cleanConfigName = cleanConfigStem(args.config_name);
|
|
1727
|
+
const models = [];
|
|
1728
|
+
const modelNamesSet = /* @__PURE__ */ new Set();
|
|
1729
|
+
try {
|
|
1730
|
+
const configOutputDir = path11.join(outputDir, cleanConfigName);
|
|
1731
|
+
if (await pathExists(configOutputDir)) {
|
|
1732
|
+
await collectModelResultFiles(configOutputDir, models, modelNamesSet);
|
|
1733
|
+
}
|
|
1734
|
+
const filesInOutputDir = await fs11.readdir(outputDir);
|
|
1735
|
+
const resultDirs = filesInOutputDir.filter(
|
|
1736
|
+
(file) => file.startsWith(`result_${cleanConfigName}_`)
|
|
1737
|
+
);
|
|
1738
|
+
for (const resultDir of resultDirs) {
|
|
1739
|
+
const resultDirPath = path11.join(outputDir, resultDir);
|
|
1740
|
+
try {
|
|
1741
|
+
await collectModelResultFiles(resultDirPath, models, modelNamesSet);
|
|
1742
|
+
} catch (error) {
|
|
1743
|
+
console.warn(
|
|
1744
|
+
`Failed to read result directory ${resultDir}: ${error.message}`
|
|
1745
|
+
);
|
|
1746
|
+
}
|
|
1747
|
+
}
|
|
1748
|
+
models.sort((a, b) => a.name.localeCompare(b.name));
|
|
1749
|
+
return {
|
|
1750
|
+
config_name: cleanConfigName,
|
|
1751
|
+
models,
|
|
1752
|
+
total_models: models.length,
|
|
1753
|
+
output_dir: outputDir
|
|
1754
|
+
};
|
|
1755
|
+
} catch (error) {
|
|
1756
|
+
return {
|
|
1757
|
+
config_name: cleanConfigName,
|
|
1758
|
+
models: [],
|
|
1759
|
+
total_models: 0,
|
|
1760
|
+
output_dir: outputDir,
|
|
1761
|
+
error: `Failed to list models: ${error.message}`
|
|
1762
|
+
};
|
|
1763
|
+
}
|
|
1764
|
+
}
|
|
1765
|
+
async function listCsvColumns(workspace, args) {
|
|
1766
|
+
const outputDir = path11.join(workspace, "output");
|
|
1767
|
+
const cleanConfigName = cleanConfigStem(args.config_name);
|
|
1768
|
+
const potentialCsvPaths = [
|
|
1769
|
+
path11.join(outputDir, cleanConfigName, `${args.model_name}__core__results.csv`),
|
|
1770
|
+
path11.join(outputDir, cleanConfigName, `${args.model_name}__results.csv`)
|
|
1771
|
+
];
|
|
1772
|
+
try {
|
|
1773
|
+
const filesInOutputDir = await fs11.readdir(outputDir);
|
|
1774
|
+
const resultDirs = filesInOutputDir.filter(
|
|
1775
|
+
(file) => file.startsWith(`result_${cleanConfigName}_`)
|
|
1776
|
+
);
|
|
1777
|
+
for (const resultDir of resultDirs) {
|
|
1778
|
+
potentialCsvPaths.push(
|
|
1779
|
+
path11.join(outputDir, resultDir, `${args.model_name}__core__results.csv`)
|
|
1780
|
+
);
|
|
1781
|
+
potentialCsvPaths.push(
|
|
1782
|
+
path11.join(outputDir, resultDir, `${args.model_name}__results.csv`)
|
|
1783
|
+
);
|
|
1784
|
+
}
|
|
1785
|
+
} catch {
|
|
1786
|
+
}
|
|
1787
|
+
let csvPath;
|
|
1788
|
+
let csvContent;
|
|
1789
|
+
for (const candidatePath of potentialCsvPaths) {
|
|
1790
|
+
if (!await pathExists(candidatePath)) continue;
|
|
1791
|
+
csvPath = candidatePath;
|
|
1792
|
+
try {
|
|
1793
|
+
csvContent = await fs11.readFile(csvPath, "utf8");
|
|
1794
|
+
break;
|
|
1795
|
+
} catch (error) {
|
|
1796
|
+
console.warn(`Failed to read CSV from ${candidatePath}: ${error.message}`);
|
|
1797
|
+
}
|
|
1798
|
+
}
|
|
1799
|
+
if (!csvContent || !csvPath) {
|
|
1800
|
+
return {
|
|
1801
|
+
config_name: cleanConfigName,
|
|
1802
|
+
model_name: args.model_name,
|
|
1803
|
+
columns: [],
|
|
1804
|
+
total_columns: 0,
|
|
1805
|
+
error: `CSV file not found for model ${args.model_name}. Tried: ${potentialCsvPaths.join(", ")}`
|
|
1806
|
+
};
|
|
1807
|
+
}
|
|
1808
|
+
const lines = csvContent.split("\n").filter((line) => line.trim());
|
|
1809
|
+
if (lines.length < 2) {
|
|
1810
|
+
return {
|
|
1811
|
+
config_name: cleanConfigName,
|
|
1812
|
+
model_name: args.model_name,
|
|
1813
|
+
columns: [],
|
|
1814
|
+
total_columns: 0,
|
|
1815
|
+
csv_path: csvPath,
|
|
1816
|
+
error: "CSV must have at least headers and units rows"
|
|
1817
|
+
};
|
|
1818
|
+
}
|
|
1819
|
+
const headers = parseCsvLine3(lines[0] ?? "").map((header) => header.trim());
|
|
1820
|
+
const units = parseCsvLine3(lines[1] ?? "").map((unit) => unit.trim());
|
|
1821
|
+
const columns = [];
|
|
1822
|
+
for (let i = 1; i < headers.length; i += 1) {
|
|
1823
|
+
const header = headers[i];
|
|
1824
|
+
const unit = i < units.length ? units[i] : "";
|
|
1825
|
+
if (!header) continue;
|
|
1826
|
+
columns.push({
|
|
1827
|
+
name: header,
|
|
1828
|
+
unit: unit || "",
|
|
1829
|
+
index: i - 1
|
|
1830
|
+
});
|
|
1831
|
+
}
|
|
1832
|
+
return {
|
|
1833
|
+
config_name: cleanConfigName,
|
|
1834
|
+
model_name: args.model_name,
|
|
1835
|
+
columns,
|
|
1836
|
+
total_columns: columns.length,
|
|
1837
|
+
csv_path: csvPath
|
|
1838
|
+
};
|
|
1839
|
+
}
|
|
1840
|
+
async function collectModelResultFiles(resultDirPath, models, modelNamesSet) {
|
|
1841
|
+
const files = await fs11.readdir(resultDirPath);
|
|
1842
|
+
for (const file of files) {
|
|
1843
|
+
const match = file.match(/^(.+?)__(?:core__)?results\.csv$/);
|
|
1844
|
+
if (!match?.[1]) continue;
|
|
1845
|
+
const modelName = match[1];
|
|
1846
|
+
if (modelNamesSet.has(modelName)) continue;
|
|
1847
|
+
modelNamesSet.add(modelName);
|
|
1848
|
+
models.push({
|
|
1849
|
+
name: modelName,
|
|
1850
|
+
csv_path: path11.join(resultDirPath, file),
|
|
1851
|
+
has_results: true
|
|
1852
|
+
});
|
|
1853
|
+
}
|
|
1854
|
+
}
|
|
1855
|
+
function cleanConfigStem(configName) {
|
|
1856
|
+
return configName.replace(/\.json$/, "");
|
|
1857
|
+
}
|
|
1858
|
+
async function pathExists(filePath) {
|
|
1859
|
+
try {
|
|
1860
|
+
await fs11.access(filePath);
|
|
1861
|
+
return true;
|
|
1862
|
+
} catch {
|
|
1863
|
+
return false;
|
|
1864
|
+
}
|
|
1865
|
+
}
|
|
1866
|
+
function parseCsvLine3(line) {
|
|
1867
|
+
const result = [];
|
|
1868
|
+
let current = "";
|
|
1869
|
+
let inQuotes = false;
|
|
1870
|
+
for (let i = 0; i < line.length; i += 1) {
|
|
1871
|
+
const ch = line[i];
|
|
1872
|
+
if (inQuotes) {
|
|
1873
|
+
if (ch === '"') {
|
|
1874
|
+
if (line[i + 1] === '"') {
|
|
1875
|
+
current += '"';
|
|
1876
|
+
i += 1;
|
|
1877
|
+
} else {
|
|
1878
|
+
inQuotes = false;
|
|
1879
|
+
}
|
|
1880
|
+
} else {
|
|
1881
|
+
current += ch;
|
|
1882
|
+
}
|
|
1883
|
+
} else if (ch === '"') {
|
|
1884
|
+
inQuotes = true;
|
|
1885
|
+
} else if (ch === ",") {
|
|
1886
|
+
result.push(current);
|
|
1887
|
+
current = "";
|
|
1888
|
+
} else {
|
|
1889
|
+
current += ch;
|
|
1890
|
+
}
|
|
1891
|
+
}
|
|
1892
|
+
result.push(current);
|
|
1893
|
+
return result;
|
|
1894
|
+
}
|
|
1895
|
+
|
|
1896
|
+
// ../packages/workspace-tools/src/validation.ts
|
|
1897
|
+
import { spawn } from "child_process";
|
|
1898
|
+
import path12 from "path";
|
|
1899
|
+
async function validateGeometryCsv(args) {
|
|
1900
|
+
const repoRoot = resolveRepoRoot(args);
|
|
1901
|
+
const failOn = args.failOn ?? "critical";
|
|
1902
|
+
const csvPath = path12.resolve(args.csvPath);
|
|
1903
|
+
const run = await runCommand(args, "npm", [
|
|
1904
|
+
"run",
|
|
1905
|
+
"--silent",
|
|
1906
|
+
"validate:geometry-csv",
|
|
1907
|
+
"--",
|
|
1908
|
+
csvPath,
|
|
1909
|
+
"--json",
|
|
1910
|
+
`--fail-on=${failOn}`
|
|
1911
|
+
]);
|
|
1912
|
+
const parsed = parseJsonStdout(run);
|
|
1913
|
+
const parsedRecord = isRecord(parsed) ? parsed : void 0;
|
|
1914
|
+
return {
|
|
1915
|
+
ok: run.exitCode === 0 && parsedRecord !== void 0,
|
|
1916
|
+
command: "geometry validate",
|
|
1917
|
+
csv_path: csvPath,
|
|
1918
|
+
repo_root: repoRoot,
|
|
1919
|
+
fail_on: failOn,
|
|
1920
|
+
exit_code: run.exitCode,
|
|
1921
|
+
signal: run.signal,
|
|
1922
|
+
stdout: run.stdout,
|
|
1923
|
+
stderr: run.stderr,
|
|
1924
|
+
parsed: parsedRecord,
|
|
1925
|
+
counts: isRecord(parsedRecord?.counts) ? parsedRecord.counts : void 0,
|
|
1926
|
+
critical_issues: Array.isArray(parsedRecord?.criticalIssues) ? parsedRecord.criticalIssues : void 0,
|
|
1927
|
+
warnings: Array.isArray(parsedRecord?.warnings) ? parsedRecord.warnings : void 0,
|
|
1928
|
+
missing_elements: Array.isArray(parsedRecord?.missingElements) ? parsedRecord.missingElements : void 0,
|
|
1929
|
+
error: parsedRecord === void 0 ? jsonParseError(run) : void 0
|
|
1930
|
+
};
|
|
1931
|
+
}
|
|
1932
|
+
async function generateAutoThermalBridges(args) {
|
|
1933
|
+
const repoRoot = resolveRepoRoot(args);
|
|
1934
|
+
const mode = args.mode ?? "summary";
|
|
1935
|
+
const csvPath = path12.resolve(args.csvPath);
|
|
1936
|
+
const run = await runCommand(args, "npx", [
|
|
1937
|
+
"vite-node",
|
|
1938
|
+
"scripts/auto-tb-cli.ts",
|
|
1939
|
+
csvPath,
|
|
1940
|
+
modeFlag(mode)
|
|
1941
|
+
]);
|
|
1942
|
+
const parsed = mode === "json" ? parseJsonStdout(run) : void 0;
|
|
1943
|
+
return {
|
|
1944
|
+
ok: run.exitCode === 0 && (mode !== "json" || parsed !== void 0),
|
|
1945
|
+
command: "thermal-bridges auto",
|
|
1946
|
+
csv_path: csvPath,
|
|
1947
|
+
repo_root: repoRoot,
|
|
1948
|
+
mode,
|
|
1949
|
+
exit_code: run.exitCode,
|
|
1950
|
+
signal: run.signal,
|
|
1951
|
+
stdout: run.stdout,
|
|
1952
|
+
stderr: run.stderr,
|
|
1953
|
+
parsed,
|
|
1954
|
+
proposal_count: Array.isArray(parsed) ? parsed.length : void 0,
|
|
1955
|
+
error: mode === "json" && parsed === void 0 ? jsonParseError(run) : void 0
|
|
1956
|
+
};
|
|
1957
|
+
}
|
|
1958
|
+
async function validateThermalBridges(args) {
|
|
1959
|
+
const repoRoot = resolveRepoRoot(args);
|
|
1960
|
+
const mode = args.mode ?? "summary";
|
|
1961
|
+
const includeAuto = args.includeAuto === true;
|
|
1962
|
+
const csvPath = path12.resolve(args.csvPath);
|
|
1963
|
+
const scriptArgs = [
|
|
1964
|
+
"vite-node",
|
|
1965
|
+
"scripts/validate-tb-cli.ts",
|
|
1966
|
+
csvPath,
|
|
1967
|
+
...includeAuto ? ["--with-auto"] : [],
|
|
1968
|
+
modeFlag(mode)
|
|
1969
|
+
];
|
|
1970
|
+
const run = await runCommand(args, "npx", scriptArgs);
|
|
1971
|
+
const parsed = mode === "json" ? parseJsonStdout(run) : void 0;
|
|
1972
|
+
const parsedRecord = isRecord(parsed) ? parsed : void 0;
|
|
1973
|
+
return {
|
|
1974
|
+
ok: run.exitCode === 0 && (mode !== "json" || parsedRecord !== void 0),
|
|
1975
|
+
command: "thermal-bridges validate",
|
|
1976
|
+
csv_path: csvPath,
|
|
1977
|
+
repo_root: repoRoot,
|
|
1978
|
+
include_auto: includeAuto,
|
|
1979
|
+
mode,
|
|
1980
|
+
exit_code: run.exitCode,
|
|
1981
|
+
signal: run.signal,
|
|
1982
|
+
stdout: run.stdout,
|
|
1983
|
+
stderr: run.stderr,
|
|
1984
|
+
parsed: parsedRecord,
|
|
1985
|
+
issue_count: typeof parsedRecord?.issueCount === "number" ? parsedRecord.issueCount : void 0,
|
|
1986
|
+
thermal_bridge_linear_rows: typeof parsedRecord?.thermalBridgeLinearRows === "number" ? parsedRecord.thermalBridgeLinearRows : void 0,
|
|
1987
|
+
error: mode === "json" && parsedRecord === void 0 ? jsonParseError(run) : void 0
|
|
1988
|
+
};
|
|
1989
|
+
}
|
|
1990
|
+
function resolveRepoRoot(args) {
|
|
1991
|
+
return path12.resolve(args.repoRoot ?? findRepoRoot(args.csvPath));
|
|
1992
|
+
}
|
|
1993
|
+
async function runCommand(args, command, commandArgs) {
|
|
1994
|
+
const repoRoot = resolveRepoRoot(args);
|
|
1995
|
+
const runner = args.runner ?? defaultCommandRunner;
|
|
1996
|
+
return runner(command, commandArgs, { cwd: repoRoot });
|
|
1997
|
+
}
|
|
1998
|
+
function modeFlag(mode) {
|
|
1999
|
+
return `--${mode}`;
|
|
2000
|
+
}
|
|
2001
|
+
function parseJsonStdout(run) {
|
|
2002
|
+
try {
|
|
2003
|
+
return JSON.parse(run.stdout);
|
|
2004
|
+
} catch {
|
|
2005
|
+
return void 0;
|
|
2006
|
+
}
|
|
2007
|
+
}
|
|
2008
|
+
function jsonParseError(run) {
|
|
2009
|
+
const suffix = run.stderr.trim() ? ` stderr: ${run.stderr.trim()}` : "";
|
|
2010
|
+
return `Expected JSON output from validation CLI.${suffix}`;
|
|
2011
|
+
}
|
|
2012
|
+
function isRecord(value) {
|
|
2013
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2014
|
+
}
|
|
2015
|
+
var defaultCommandRunner = (command, args, options) => new Promise((resolve, reject) => {
|
|
2016
|
+
const child = spawn(command, [...args], {
|
|
2017
|
+
cwd: options.cwd,
|
|
2018
|
+
shell: false,
|
|
2019
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
2020
|
+
});
|
|
2021
|
+
let stdout = "";
|
|
2022
|
+
let stderr = "";
|
|
2023
|
+
child.stdout.setEncoding("utf8");
|
|
2024
|
+
child.stderr.setEncoding("utf8");
|
|
2025
|
+
child.stdout.on("data", (chunk) => {
|
|
2026
|
+
stdout += chunk;
|
|
2027
|
+
});
|
|
2028
|
+
child.stderr.on("data", (chunk) => {
|
|
2029
|
+
stderr += chunk;
|
|
2030
|
+
});
|
|
2031
|
+
child.on("error", reject);
|
|
2032
|
+
child.on("close", (exitCode, signal) => {
|
|
2033
|
+
resolve({ exitCode, signal, stdout, stderr });
|
|
2034
|
+
});
|
|
2035
|
+
});
|
|
2036
|
+
|
|
2037
|
+
// src/tools/listParameters.ts
|
|
2038
|
+
async function listParameters2(config, args = {}) {
|
|
2039
|
+
return listParameters(config.workspace, args);
|
|
2040
|
+
}
|
|
2041
|
+
|
|
2042
|
+
// src/tools/viewParameter.ts
|
|
2043
|
+
async function viewParameter2(config, args) {
|
|
2044
|
+
return viewParameter(config.workspace, args);
|
|
2045
|
+
}
|
|
2046
|
+
|
|
2047
|
+
// src/tools/saveParameter.ts
|
|
2048
|
+
async function saveParameter2(config, args) {
|
|
2049
|
+
let wasm;
|
|
2050
|
+
try {
|
|
2051
|
+
await initWasm();
|
|
2052
|
+
wasm = getWasmModule();
|
|
2053
|
+
} catch (error) {
|
|
2054
|
+
const err = error;
|
|
2055
|
+
throw new Error(`WASM initialization failed: ${err.message}`);
|
|
2056
|
+
}
|
|
2057
|
+
if (!wasm.validate_snippet_js) {
|
|
2058
|
+
throw new Error("WASM validate_snippet_js function not available");
|
|
2059
|
+
}
|
|
2060
|
+
return saveParameter(config.workspace, args, {
|
|
2061
|
+
validateSnippetJs: wasm.validate_snippet_js.bind(wasm)
|
|
2062
|
+
});
|
|
2063
|
+
}
|
|
2064
|
+
|
|
2065
|
+
// src/tools/createBatchConfig.ts
|
|
2066
|
+
async function createBatchConfig2(config, args) {
|
|
2067
|
+
return createBatchConfig(config.workspace, args);
|
|
2068
|
+
}
|
|
2069
|
+
|
|
2070
|
+
// src/tools/runBatch.ts
|
|
2071
|
+
import { randomUUID as randomUUID2 } from "crypto";
|
|
2072
|
+
async function runBatch2(config, args) {
|
|
2073
|
+
const { workspace } = config;
|
|
2074
|
+
const { config_name } = args;
|
|
2075
|
+
if (!config_name) {
|
|
2076
|
+
throw new Error("config_name is required");
|
|
2077
|
+
}
|
|
2078
|
+
const finalJobId = args.job_id || `mcp_${randomUUID2()}`;
|
|
2079
|
+
let wasm;
|
|
2080
|
+
try {
|
|
2081
|
+
await initWasm();
|
|
2082
|
+
wasm = getWasmModule();
|
|
2083
|
+
} catch (error) {
|
|
2084
|
+
const err = error;
|
|
2085
|
+
return {
|
|
2086
|
+
job_id: finalJobId,
|
|
2087
|
+
status: "error",
|
|
2088
|
+
message: `WASM initialization failed: ${err.message}`,
|
|
2089
|
+
error: err.message
|
|
2090
|
+
};
|
|
2091
|
+
}
|
|
2092
|
+
if (!wasm.process_batch_config) {
|
|
2093
|
+
return {
|
|
2094
|
+
job_id: finalJobId,
|
|
2095
|
+
status: "error",
|
|
2096
|
+
message: "WASM process_batch_config function not available",
|
|
2097
|
+
error: "WASM function missing"
|
|
2098
|
+
};
|
|
2099
|
+
}
|
|
2100
|
+
setWorkspace(workspace);
|
|
2101
|
+
return runBatch(workspace, { ...args, job_id: finalJobId }, {
|
|
2102
|
+
processBatchConfig: wasm.process_batch_config.bind(wasm)
|
|
2103
|
+
});
|
|
2104
|
+
}
|
|
2105
|
+
|
|
2106
|
+
// src/tools/getBatchStatus.ts
|
|
2107
|
+
async function getBatchStatus2(config, args = {}) {
|
|
2108
|
+
return getBatchStatus(config.workspace, args);
|
|
2109
|
+
}
|
|
2110
|
+
|
|
2111
|
+
// src/tools/calculateMetrics.ts
|
|
2112
|
+
async function calculateMetrics2(config, args) {
|
|
2113
|
+
let wasm;
|
|
2114
|
+
try {
|
|
2115
|
+
await initWasm();
|
|
2116
|
+
wasm = getWasmModule();
|
|
2117
|
+
} catch (error) {
|
|
2118
|
+
const err = error;
|
|
2119
|
+
throw new Error(`WASM initialization failed: ${err.message}`);
|
|
2120
|
+
}
|
|
2121
|
+
if (!wasm.calculate_metrics_from_parsed_data) {
|
|
2122
|
+
throw new Error("WASM calculate_metrics_from_parsed_data function not available");
|
|
2123
|
+
}
|
|
2124
|
+
return calculateMetrics(config.workspace, args, {
|
|
2125
|
+
calculateMetricsFromParsedData: wasm.calculate_metrics_from_parsed_data.bind(wasm)
|
|
2126
|
+
});
|
|
2127
|
+
}
|
|
2128
|
+
|
|
2129
|
+
// src/tools/listCsvColumns.ts
|
|
2130
|
+
async function listCsvColumns2(config, args) {
|
|
2131
|
+
return listCsvColumns(config.workspace, args);
|
|
2132
|
+
}
|
|
2133
|
+
|
|
2134
|
+
// src/tools/listBatchModels.ts
|
|
2135
|
+
async function listBatchModels2(config, args) {
|
|
2136
|
+
return listBatchModels(config.workspace, args);
|
|
2137
|
+
}
|
|
2138
|
+
|
|
2139
|
+
// src/tools/mergeCsvToJson.ts
|
|
2140
|
+
async function mergeCsvToJson(config, args) {
|
|
2141
|
+
const { workspace } = config;
|
|
2142
|
+
const { csv_path, output_path, schema_path, defaults_path } = args;
|
|
2143
|
+
if (!csv_path) {
|
|
2144
|
+
throw new Error("csv_path is required");
|
|
2145
|
+
}
|
|
2146
|
+
let wasm;
|
|
2147
|
+
try {
|
|
2148
|
+
await initWasm();
|
|
2149
|
+
wasm = getWasmModule();
|
|
2150
|
+
} catch (error) {
|
|
2151
|
+
const err = error;
|
|
2152
|
+
return {
|
|
2153
|
+
ok: false,
|
|
2154
|
+
error: `WASM initialization failed: ${err.message}`
|
|
2155
|
+
};
|
|
2156
|
+
}
|
|
2157
|
+
if (!wasm.convert_geometry_csv_to_json) {
|
|
2158
|
+
return {
|
|
2159
|
+
ok: false,
|
|
2160
|
+
error: "WASM convert_geometry_csv_to_json function not available"
|
|
2161
|
+
};
|
|
2162
|
+
}
|
|
2163
|
+
setWorkspace(workspace);
|
|
2164
|
+
return mergeGeometryCsvToJson({
|
|
2165
|
+
workspace,
|
|
2166
|
+
csvPath: csv_path,
|
|
2167
|
+
outputPath: output_path,
|
|
2168
|
+
schemaPath: schema_path,
|
|
2169
|
+
defaultsPath: defaults_path,
|
|
2170
|
+
deps: {
|
|
2171
|
+
convertGeometryCsvToJson: wasm.convert_geometry_csv_to_json.bind(wasm)
|
|
2172
|
+
}
|
|
2173
|
+
});
|
|
2174
|
+
}
|
|
2175
|
+
|
|
2176
|
+
// src/tools/validateGeometryCsv.ts
|
|
2177
|
+
import path13 from "path";
|
|
2178
|
+
async function validateGeometryCsv2(config, args) {
|
|
2179
|
+
return validateGeometryCsv({
|
|
2180
|
+
csvPath: path13.isAbsolute(args.csv_path) ? args.csv_path : path13.join(config.workspace, args.csv_path),
|
|
2181
|
+
failOn: args.fail_on,
|
|
2182
|
+
repoRoot: process.cwd()
|
|
2183
|
+
});
|
|
2184
|
+
}
|
|
2185
|
+
|
|
2186
|
+
// src/tools/autoThermalBridges.ts
|
|
2187
|
+
import path14 from "path";
|
|
2188
|
+
async function generateAutoThermalBridges2(config, args) {
|
|
2189
|
+
return generateAutoThermalBridges({
|
|
2190
|
+
csvPath: path14.isAbsolute(args.csv_path) ? args.csv_path : path14.join(config.workspace, args.csv_path),
|
|
2191
|
+
mode: args.mode,
|
|
2192
|
+
repoRoot: process.cwd()
|
|
2193
|
+
});
|
|
2194
|
+
}
|
|
2195
|
+
|
|
2196
|
+
// src/tools/validateThermalBridges.ts
|
|
2197
|
+
import path15 from "path";
|
|
2198
|
+
async function validateThermalBridges2(config, args) {
|
|
2199
|
+
return validateThermalBridges({
|
|
2200
|
+
csvPath: path15.isAbsolute(args.csv_path) ? args.csv_path : path15.join(config.workspace, args.csv_path),
|
|
2201
|
+
includeAuto: args.include_auto,
|
|
2202
|
+
mode: args.mode,
|
|
2203
|
+
repoRoot: process.cwd()
|
|
2204
|
+
});
|
|
2205
|
+
}
|
|
2206
|
+
|
|
2207
|
+
// src/tools/index.ts
|
|
2208
|
+
var toolSchemas = {
|
|
2209
|
+
vulcan_list_parameters: z.object({
|
|
2210
|
+
category: z.string().optional().describe('Optional: filter by category name (e.g., "base_json", "heat_source_wet", "controls")')
|
|
2211
|
+
}),
|
|
2212
|
+
vulcan_view_parameter: z.object({
|
|
2213
|
+
category: z.string().describe('Parameter category (e.g., "heat_source_wet", "controls", "base_json")'),
|
|
2214
|
+
parameter_id: z.string().describe("Parameter ID (filename without .json extension)")
|
|
2215
|
+
}),
|
|
2216
|
+
vulcan_save_parameter: z.object({
|
|
2217
|
+
category: z.string().describe('Parameter category (e.g., "heat_source_wet", "controls")'),
|
|
2218
|
+
parameter_id: z.string().describe("Parameter ID (filename without .json extension)"),
|
|
2219
|
+
content: z.record(z.string(), z.any()).describe("Parameter JSON content (must be valid JSON object)"),
|
|
2220
|
+
markdown_content: z.string().optional().describe("Optional markdown documentation for the parameter")
|
|
2221
|
+
}),
|
|
2222
|
+
vulcan_create_batch_config: z.object({
|
|
2223
|
+
config_name: z.string().describe("Configuration name (will be saved as {config_name}.json)"),
|
|
2224
|
+
base_model: z.string().describe("Base model filename (without .json extension)"),
|
|
2225
|
+
weather_file: z.string().describe("Weather file name (with or without .epw extension)"),
|
|
2226
|
+
wrapper: z.string().optional().describe('Optional model wrapper (e.g., "fhs_compliance", "passthrough")'),
|
|
2227
|
+
parameters: z.preprocess((params) => {
|
|
2228
|
+
if (!params || typeof params !== "object" || Array.isArray(params)) {
|
|
2229
|
+
return params;
|
|
2230
|
+
}
|
|
2231
|
+
return Object.fromEntries(
|
|
2232
|
+
Object.entries(params).map(([key, value]) => {
|
|
2233
|
+
if (typeof value === "string") {
|
|
2234
|
+
try {
|
|
2235
|
+
const parsed = JSON.parse(value);
|
|
2236
|
+
return [key, Array.isArray(parsed) ? parsed : [parsed]];
|
|
2237
|
+
} catch {
|
|
2238
|
+
return [key, [value]];
|
|
27
2239
|
}
|
|
28
|
-
|
|
29
|
-
|
|
2240
|
+
}
|
|
2241
|
+
return [key, Array.isArray(value) ? value : [value]];
|
|
2242
|
+
})
|
|
2243
|
+
);
|
|
2244
|
+
}, z.record(z.string(), z.array(z.string()))).describe("Object mapping category to array of parameter IDs")
|
|
2245
|
+
}),
|
|
2246
|
+
vulcan_run_batch: z.object({
|
|
2247
|
+
config_name: z.string().describe("Configuration name (with or without .json extension)"),
|
|
2248
|
+
job_id: z.string().optional().describe("Optional custom job ID (defaults to mcp_{uuid})")
|
|
2249
|
+
}),
|
|
2250
|
+
vulcan_get_batch_status: z.object({
|
|
2251
|
+
job_id: z.string().optional().describe("Job ID returned from vulcan_run_batch"),
|
|
2252
|
+
config_name: z.string().optional().describe("Configuration name (alternative to job_id, since config names are unique)")
|
|
2253
|
+
}).refine((data) => data.job_id || data.config_name, {
|
|
2254
|
+
message: "Either job_id or config_name must be provided"
|
|
2255
|
+
}),
|
|
2256
|
+
vulcan_calculate_metrics: z.object({
|
|
2257
|
+
config_name: z.string().describe("Configuration name (with or without .json extension)"),
|
|
2258
|
+
model_names: z.array(z.string()).describe("Array of model names to calculate metrics for"),
|
|
2259
|
+
metric_definitions: z.array(z.object({
|
|
2260
|
+
id: z.string().optional(),
|
|
2261
|
+
name: z.string().optional(),
|
|
2262
|
+
column: z.string().optional(),
|
|
2263
|
+
function: z.enum(["sum", "average", "peak", "min", "cost", "sumIf", "averageIf", "countIf"]).optional(),
|
|
2264
|
+
comparator: z.string().optional(),
|
|
2265
|
+
threshold: z.number().optional()
|
|
2266
|
+
})).describe("Array of metric definitions"),
|
|
2267
|
+
time_range: z.object({
|
|
2268
|
+
start: z.number().optional(),
|
|
2269
|
+
end: z.number().optional()
|
|
2270
|
+
}).optional().describe("Optional time range filter"),
|
|
2271
|
+
tariff_file_path: z.string().optional().describe("Path to tariff CSV file (relative to workspace or absolute). Required for cost metrics."),
|
|
2272
|
+
tariff_column_index: z.number().optional().describe("Zero-based index of tariff column in CSV. Required for cost metrics.")
|
|
2273
|
+
}),
|
|
2274
|
+
vulcan_list_csv_columns: z.object({
|
|
2275
|
+
config_name: z.string().describe("Configuration name (with or without .json extension)"),
|
|
2276
|
+
model_name: z.string().describe('Model name (e.g., "scenario_1_0")')
|
|
2277
|
+
}),
|
|
2278
|
+
vulcan_list_batch_models: z.object({
|
|
2279
|
+
config_name: z.string().describe("Configuration name (with or without .json extension)")
|
|
2280
|
+
}),
|
|
2281
|
+
vulcan_merge_csv_to_json: z.object({
|
|
2282
|
+
csv_path: z.string().describe("Path to CSV file (relative to workspace or absolute)"),
|
|
2283
|
+
output_path: z.string().optional().describe("Optional: output JSON path (defaults to input/batch_parameters/base_json/{csv_filename}.json)"),
|
|
2284
|
+
schema_path: z.string().optional().describe("Optional: custom schema path (defaults to the core schema with workspace fallbacks)"),
|
|
2285
|
+
defaults_path: z.string().optional().describe("Optional: custom defaults path. Declared paths must load; standard defaults are used only for legacy CSVs without DefaultsPath.")
|
|
2286
|
+
}),
|
|
2287
|
+
vulcan_validate_geometry_csv: z.object({
|
|
2288
|
+
csv_path: z.string().describe("Path to geometry CSV file (relative to workspace or absolute)"),
|
|
2289
|
+
fail_on: z.enum(["none", "critical", "warning"]).optional().describe("Validation exit policy for the wrapped CLI. Defaults to critical.")
|
|
2290
|
+
}),
|
|
2291
|
+
vulcan_auto_thermal_bridges: z.object({
|
|
2292
|
+
csv_path: z.string().describe("Path to geometry CSV file (relative to workspace or absolute)"),
|
|
2293
|
+
mode: z.enum(["summary", "json", "csv-section"]).optional().describe("Wrapped auto-TB CLI output mode. Defaults to summary.")
|
|
2294
|
+
}),
|
|
2295
|
+
vulcan_validate_thermal_bridges: z.object({
|
|
2296
|
+
csv_path: z.string().describe("Path to geometry CSV file (relative to workspace or absolute)"),
|
|
2297
|
+
include_auto: z.boolean().optional().describe("Also synthesize auto-TB proposals before validation."),
|
|
2298
|
+
mode: z.enum(["summary", "json"]).optional().describe("Wrapped TB validation CLI output mode. Defaults to summary.")
|
|
2299
|
+
})
|
|
2300
|
+
};
|
|
2301
|
+
var toolDefinitions = [
|
|
2302
|
+
{
|
|
2303
|
+
name: "vulcan_list_parameters",
|
|
2304
|
+
description: `List available parameter categories and their JSON snippets.
|
|
2305
|
+
|
|
2306
|
+
Use this to discover what parameters are available before creating batch configurations.
|
|
2307
|
+
Returns a catalog of all categories (e.g., base_json, heat_source_wet, controls) and their parameters.
|
|
2308
|
+
|
|
2309
|
+
Example: Call with category='base_json' to see all base models available.
|
|
2310
|
+
See also: vulcan_view_parameter to see details of a specific parameter.`,
|
|
2311
|
+
inputSchema: {
|
|
2312
|
+
type: "object",
|
|
2313
|
+
properties: {
|
|
2314
|
+
category: {
|
|
2315
|
+
type: "string",
|
|
2316
|
+
description: 'Optional: filter by category name (e.g., "base_json", "heat_source_wet", "controls")'
|
|
2317
|
+
}
|
|
2318
|
+
}
|
|
2319
|
+
}
|
|
2320
|
+
},
|
|
2321
|
+
{
|
|
2322
|
+
name: "vulcan_view_parameter",
|
|
2323
|
+
description: `View a specific parameter JSON snippet and its markdown documentation.
|
|
2324
|
+
|
|
2325
|
+
Use this to see the full content of a parameter after discovering it with vulcan_list_parameters.
|
|
2326
|
+
Returns both the JSON content and optional markdown documentation if available.
|
|
2327
|
+
|
|
2328
|
+
Example: View the "hp" parameter in "heat_source_wet" category to see heat pump configuration.
|
|
2329
|
+
See also: vulcan_list_parameters to discover available parameters.`,
|
|
2330
|
+
inputSchema: {
|
|
2331
|
+
type: "object",
|
|
2332
|
+
required: ["category", "parameter_id"],
|
|
2333
|
+
properties: {
|
|
2334
|
+
category: { type: "string" },
|
|
2335
|
+
parameter_id: { type: "string" }
|
|
2336
|
+
}
|
|
2337
|
+
}
|
|
2338
|
+
},
|
|
2339
|
+
{
|
|
2340
|
+
name: "vulcan_save_parameter",
|
|
2341
|
+
description: `Create or edit a parameter JSON snippet with validation.
|
|
2342
|
+
|
|
2343
|
+
Use this to create new parameters or modify existing ones. The parameter will be validated
|
|
2344
|
+
against the schema and baseline model before saving. Validation ensures the parameter is
|
|
2345
|
+
compatible with the HEM engine.
|
|
2346
|
+
|
|
2347
|
+
Example: Create a new heat pump configuration or modify an existing control schedule.
|
|
2348
|
+
See also: vulcan_view_parameter to view existing parameters before editing.`,
|
|
2349
|
+
inputSchema: {
|
|
2350
|
+
type: "object",
|
|
2351
|
+
required: ["category", "parameter_id", "content"],
|
|
2352
|
+
properties: {
|
|
2353
|
+
category: { type: "string" },
|
|
2354
|
+
parameter_id: { type: "string" },
|
|
2355
|
+
content: { type: "object" },
|
|
2356
|
+
markdown_content: { type: "string" }
|
|
2357
|
+
}
|
|
2358
|
+
}
|
|
2359
|
+
},
|
|
2360
|
+
{
|
|
2361
|
+
name: "vulcan_create_batch_config",
|
|
2362
|
+
description: `Create a batch configuration with base model, weather file, wrapper, and parameters.
|
|
2363
|
+
|
|
2364
|
+
Use this to create a batch simulation configuration that can be executed with vulcan_run_batch.
|
|
2365
|
+
The config defines which parameters to combine in a batch run. All parameter files must exist.
|
|
2366
|
+
|
|
2367
|
+
Example: Create a config comparing different insulation levels with a heat pump system.
|
|
2368
|
+
See also: vulcan_list_parameters to discover available parameters, vulcan_run_batch to execute.`,
|
|
2369
|
+
inputSchema: {
|
|
2370
|
+
type: "object",
|
|
2371
|
+
required: ["config_name", "base_model", "weather_file", "parameters"],
|
|
2372
|
+
properties: {
|
|
2373
|
+
config_name: { type: "string" },
|
|
2374
|
+
base_model: { type: "string" },
|
|
2375
|
+
weather_file: { type: "string" },
|
|
2376
|
+
wrapper: { type: "string" },
|
|
2377
|
+
parameters: {
|
|
2378
|
+
type: "object",
|
|
2379
|
+
additionalProperties: {
|
|
2380
|
+
oneOf: [
|
|
2381
|
+
{ type: "array", items: { type: "string" } },
|
|
2382
|
+
{ type: "string" }
|
|
2383
|
+
// Allow strings that will be parsed to arrays
|
|
2384
|
+
]
|
|
2385
|
+
}
|
|
2386
|
+
}
|
|
2387
|
+
}
|
|
2388
|
+
}
|
|
2389
|
+
},
|
|
2390
|
+
{
|
|
2391
|
+
name: "vulcan_run_batch",
|
|
2392
|
+
description: `Run a batch simulation configuration asynchronously.
|
|
2393
|
+
|
|
2394
|
+
Use this to execute a batch configuration created with vulcan_create_batch_config.
|
|
2395
|
+
The simulation runs in the background and progress can be checked with vulcan_get_batch_status.
|
|
2396
|
+
|
|
2397
|
+
Example: Run a batch config named "insulation_test" to execute all parameter combinations.
|
|
2398
|
+
See also: vulcan_get_batch_status to check progress, vulcan_create_batch_config to create configs.`,
|
|
2399
|
+
inputSchema: {
|
|
2400
|
+
type: "object",
|
|
2401
|
+
required: ["config_name"],
|
|
2402
|
+
properties: {
|
|
2403
|
+
config_name: { type: "string" },
|
|
2404
|
+
job_id: { type: "string" }
|
|
2405
|
+
}
|
|
2406
|
+
}
|
|
2407
|
+
},
|
|
2408
|
+
{
|
|
2409
|
+
name: "vulcan_get_batch_status",
|
|
2410
|
+
description: `Get the status, progress, and results summary of a batch run.
|
|
2411
|
+
|
|
2412
|
+
Use this to check the progress of a batch simulation started with vulcan_run_batch.
|
|
2413
|
+
Returns current status (queued/running/completed/error), progress percentage, and pass/fail counts.
|
|
2414
|
+
|
|
2415
|
+
You can provide either job_id (returned from vulcan_run_batch) or config_name (since config names are unique).
|
|
2416
|
+
|
|
2417
|
+
Example: Check status using config_name "my_batch_config" or job_id "mcp_abc123".
|
|
2418
|
+
See also: vulcan_run_batch to start a batch, vulcan_calculate_metrics to analyze results.`,
|
|
2419
|
+
inputSchema: {
|
|
2420
|
+
type: "object",
|
|
2421
|
+
properties: {
|
|
2422
|
+
job_id: { type: "string", description: "Job ID returned from vulcan_run_batch" },
|
|
2423
|
+
config_name: { type: "string", description: "Configuration name (alternative to job_id)" }
|
|
2424
|
+
}
|
|
2425
|
+
}
|
|
2426
|
+
},
|
|
2427
|
+
{
|
|
2428
|
+
name: "vulcan_calculate_metrics",
|
|
2429
|
+
description: `Calculate metrics by aggregating columns from simulation results.
|
|
2430
|
+
|
|
2431
|
+
Use this to compute metrics (sum, average, peak, min, cost) from CSV result files after a batch run.
|
|
2432
|
+
Supports time range filtering and conditional metrics (sumIf, averageIf).
|
|
2433
|
+
|
|
2434
|
+
For cost metrics, provide tariff_file_path and tariff_column_index to use time-of-use tariff rates.
|
|
2435
|
+
Tariff file must be CSV with 17,520 rows (half-hourly for a full year).
|
|
2436
|
+
|
|
2437
|
+
Example: Calculate total electricity consumption and peak demand for all models in a batch.
|
|
2438
|
+
Example with tariff: Calculate cost using Octopus Agile rates from input/tariff_data_structured/Octopus.csv, column index 2.
|
|
2439
|
+
See also: vulcan_get_batch_status to check if batch is complete, vulcan_run_batch to start batch.`,
|
|
2440
|
+
inputSchema: {
|
|
2441
|
+
type: "object",
|
|
2442
|
+
required: ["config_name", "model_names", "metric_definitions"],
|
|
2443
|
+
properties: {
|
|
2444
|
+
config_name: { type: "string" },
|
|
2445
|
+
model_names: { type: "array", items: { type: "string" } },
|
|
2446
|
+
metric_definitions: { type: "array" },
|
|
2447
|
+
time_range: {
|
|
2448
|
+
type: "object",
|
|
2449
|
+
description: "Optional time range filter (start and end timesteps)",
|
|
2450
|
+
properties: {
|
|
2451
|
+
start: { type: "number" },
|
|
2452
|
+
end: { type: "number" }
|
|
2453
|
+
}
|
|
2454
|
+
},
|
|
2455
|
+
tariff_file_path: {
|
|
2456
|
+
type: "string",
|
|
2457
|
+
description: "Path to tariff CSV file (relative to workspace or absolute). Required for cost metrics."
|
|
2458
|
+
},
|
|
2459
|
+
tariff_column_index: {
|
|
2460
|
+
type: "number",
|
|
2461
|
+
description: "Zero-based index of tariff column in CSV. Required for cost metrics."
|
|
30
2462
|
}
|
|
31
|
-
|
|
32
|
-
|
|
2463
|
+
}
|
|
2464
|
+
}
|
|
2465
|
+
},
|
|
2466
|
+
{
|
|
2467
|
+
name: "vulcan_list_csv_columns",
|
|
2468
|
+
description: `List available columns from a CSV result file.
|
|
2469
|
+
|
|
2470
|
+
Use this to discover what columns are available in a model's results before calculating metrics.
|
|
2471
|
+
Returns column names, units, and their indices.
|
|
2472
|
+
|
|
2473
|
+
Example: List columns for model "scenario_1_0" in config "my_batch" to see available data columns.
|
|
2474
|
+
See also: vulcan_list_batch_models to get model names, vulcan_calculate_metrics to compute metrics.`,
|
|
2475
|
+
inputSchema: {
|
|
2476
|
+
type: "object",
|
|
2477
|
+
required: ["config_name", "model_name"],
|
|
2478
|
+
properties: {
|
|
2479
|
+
config_name: { type: "string" },
|
|
2480
|
+
model_name: { type: "string" }
|
|
2481
|
+
}
|
|
2482
|
+
}
|
|
2483
|
+
},
|
|
2484
|
+
{
|
|
2485
|
+
name: "vulcan_list_batch_models",
|
|
2486
|
+
description: `List all model names from a completed batch run.
|
|
2487
|
+
|
|
2488
|
+
Use this to discover which models were generated by a batch run, so you can use them in vulcan_calculate_metrics.
|
|
2489
|
+
Returns all model names that have result CSV files.
|
|
2490
|
+
|
|
2491
|
+
Example: List models from config "my_batch" to get ["scenario_1_0", "scenario_1_1", ...].
|
|
2492
|
+
See also: vulcan_get_batch_status to check if batch is complete, vulcan_calculate_metrics to analyze results.`,
|
|
2493
|
+
inputSchema: {
|
|
2494
|
+
type: "object",
|
|
2495
|
+
required: ["config_name"],
|
|
2496
|
+
properties: {
|
|
2497
|
+
config_name: { type: "string" }
|
|
2498
|
+
}
|
|
2499
|
+
}
|
|
2500
|
+
},
|
|
2501
|
+
{
|
|
2502
|
+
name: "vulcan_merge_csv_to_json",
|
|
2503
|
+
description: `Convert a geometry CSV file to JSON format using WASM conversion.
|
|
2504
|
+
|
|
2505
|
+
This tool performs the same conversion as the geometry canvas save operation:
|
|
2506
|
+
- Parses CSV geometry data
|
|
2507
|
+
- Merges with the declared defaults template (supports CSV metadata DefaultsPath)
|
|
2508
|
+
- Validates against schema
|
|
2509
|
+
- Saves JSON to workspace
|
|
2510
|
+
|
|
2511
|
+
The tool supports CSV metadata DefaultsPath (same as geometry canvas), which allows
|
|
2512
|
+
the CSV file to specify its own defaults template path in the metadata section.
|
|
2513
|
+
If a CSV declares DefaultsPath, that file must load; the standard defaults template
|
|
2514
|
+
is used only for legacy CSVs with no DefaultsPath row.
|
|
2515
|
+
|
|
2516
|
+
Example: Convert input/base_models/my_model.csv to JSON.
|
|
2517
|
+
See also: vulcan_list_parameters to see available base models.`,
|
|
2518
|
+
inputSchema: {
|
|
2519
|
+
type: "object",
|
|
2520
|
+
required: ["csv_path"],
|
|
2521
|
+
properties: {
|
|
2522
|
+
csv_path: { type: "string" },
|
|
2523
|
+
output_path: { type: "string" },
|
|
2524
|
+
schema_path: { type: "string" },
|
|
2525
|
+
defaults_path: { type: "string" }
|
|
2526
|
+
}
|
|
2527
|
+
}
|
|
2528
|
+
},
|
|
2529
|
+
{
|
|
2530
|
+
name: "vulcan_validate_geometry_csv",
|
|
2531
|
+
description: `Validate a geometry CSV through the existing Vulcan geometry validator CLI.
|
|
2532
|
+
|
|
2533
|
+
This wraps npm run validate:geometry-csv and reuses the same pure web validators used by
|
|
2534
|
+
Build Geometry. It reports element, zone, global, missing-element, and Part F findings
|
|
2535
|
+
without reimplementing validation logic in MCP.
|
|
2536
|
+
|
|
2537
|
+
Example: Validate input/base_models/H283_target.csv before merging or running batches.`,
|
|
2538
|
+
inputSchema: {
|
|
2539
|
+
type: "object",
|
|
2540
|
+
required: ["csv_path"],
|
|
2541
|
+
properties: {
|
|
2542
|
+
csv_path: { type: "string" },
|
|
2543
|
+
fail_on: { type: "string", enum: ["none", "critical", "warning"] }
|
|
2544
|
+
}
|
|
2545
|
+
}
|
|
2546
|
+
},
|
|
2547
|
+
{
|
|
2548
|
+
name: "vulcan_auto_thermal_bridges",
|
|
2549
|
+
description: `Generate auto thermal-bridge proposals through the existing Vulcan auto-TB CLI.
|
|
2550
|
+
|
|
2551
|
+
This wraps scripts/auto-tb-cli.ts and reuses the web app's per-junction thermal-bridge
|
|
2552
|
+
proposal pipeline. Use mode=json for structured proposals, summary for a compact table,
|
|
2553
|
+
or csv-section for a pasteable Thermal Bridging Elements CSV section.`,
|
|
2554
|
+
inputSchema: {
|
|
2555
|
+
type: "object",
|
|
2556
|
+
required: ["csv_path"],
|
|
2557
|
+
properties: {
|
|
2558
|
+
csv_path: { type: "string" },
|
|
2559
|
+
mode: { type: "string", enum: ["summary", "json", "csv-section"] }
|
|
2560
|
+
}
|
|
2561
|
+
}
|
|
2562
|
+
},
|
|
2563
|
+
{
|
|
2564
|
+
name: "vulcan_validate_thermal_bridges",
|
|
2565
|
+
description: `Validate ThermalBridgeLinear rows through the existing Vulcan TB validation CLI.
|
|
2566
|
+
|
|
2567
|
+
This wraps scripts/validate-tb-cli.ts and reuses findLinearThermalBridgeIssues plus
|
|
2568
|
+
validateElementCore. Set include_auto=true to validate existing CSV rows plus synthesized
|
|
2569
|
+
auto-TB proposals without mutating the CSV.`,
|
|
2570
|
+
inputSchema: {
|
|
2571
|
+
type: "object",
|
|
2572
|
+
required: ["csv_path"],
|
|
2573
|
+
properties: {
|
|
2574
|
+
csv_path: { type: "string" },
|
|
2575
|
+
include_auto: { type: "boolean" },
|
|
2576
|
+
mode: { type: "string", enum: ["summary", "json"] }
|
|
2577
|
+
}
|
|
2578
|
+
}
|
|
2579
|
+
}
|
|
2580
|
+
];
|
|
2581
|
+
async function handleToolCall(name, args, config) {
|
|
2582
|
+
switch (name) {
|
|
2583
|
+
case "vulcan_list_parameters": {
|
|
2584
|
+
const params = toolSchemas.vulcan_list_parameters.parse(args);
|
|
2585
|
+
return await listParameters2(config, params);
|
|
2586
|
+
}
|
|
2587
|
+
case "vulcan_view_parameter": {
|
|
2588
|
+
const params = toolSchemas.vulcan_view_parameter.parse(args);
|
|
2589
|
+
return await viewParameter2(config, params);
|
|
2590
|
+
}
|
|
2591
|
+
case "vulcan_save_parameter": {
|
|
2592
|
+
const { category, parameter_id, content, markdown_content } = args || {};
|
|
2593
|
+
if (!category || typeof category !== "string") {
|
|
2594
|
+
throw new Error("category is required and must be a string");
|
|
2595
|
+
}
|
|
2596
|
+
if (!parameter_id || typeof parameter_id !== "string") {
|
|
2597
|
+
throw new Error("parameter_id is required and must be a string");
|
|
2598
|
+
}
|
|
2599
|
+
if (!content || typeof content !== "object" || Array.isArray(content)) {
|
|
2600
|
+
throw new Error("content is required and must be a JSON object");
|
|
2601
|
+
}
|
|
2602
|
+
const saveParams = {
|
|
2603
|
+
category,
|
|
2604
|
+
parameter_id,
|
|
2605
|
+
content,
|
|
2606
|
+
...markdown_content ? { markdown_content } : {}
|
|
2607
|
+
};
|
|
2608
|
+
return await saveParameter2(config, saveParams);
|
|
2609
|
+
}
|
|
2610
|
+
case "vulcan_create_batch_config": {
|
|
2611
|
+
const { config_name, base_model, weather_file, wrapper, parameters } = args || {};
|
|
2612
|
+
if (!config_name || typeof config_name !== "string") {
|
|
2613
|
+
throw new Error("config_name is required and must be a string");
|
|
2614
|
+
}
|
|
2615
|
+
if (!base_model || typeof base_model !== "string") {
|
|
2616
|
+
throw new Error("base_model is required and must be a string");
|
|
2617
|
+
}
|
|
2618
|
+
if (!weather_file || typeof weather_file !== "string") {
|
|
2619
|
+
throw new Error("weather_file is required and must be a string");
|
|
2620
|
+
}
|
|
2621
|
+
let parsedParameters = {};
|
|
2622
|
+
if (parameters) {
|
|
2623
|
+
if (typeof parameters !== "object" || Array.isArray(parameters)) {
|
|
2624
|
+
throw new Error("parameters must be an object mapping category to array of parameter IDs");
|
|
2625
|
+
}
|
|
2626
|
+
parsedParameters = Object.fromEntries(
|
|
2627
|
+
Object.entries(parameters).map(([key, value]) => {
|
|
2628
|
+
if (typeof value === "string") {
|
|
2629
|
+
try {
|
|
2630
|
+
const parsed = JSON.parse(value);
|
|
2631
|
+
return [key, Array.isArray(parsed) ? parsed : [parsed]];
|
|
2632
|
+
} catch {
|
|
2633
|
+
return [key, [value]];
|
|
2634
|
+
}
|
|
2635
|
+
}
|
|
2636
|
+
return [key, Array.isArray(value) ? value : [value]];
|
|
2637
|
+
})
|
|
2638
|
+
);
|
|
2639
|
+
}
|
|
2640
|
+
const createParams = {
|
|
2641
|
+
config_name,
|
|
2642
|
+
base_model,
|
|
2643
|
+
weather_file,
|
|
2644
|
+
...wrapper ? { wrapper } : {},
|
|
2645
|
+
parameters: parsedParameters
|
|
2646
|
+
};
|
|
2647
|
+
return await createBatchConfig2(config, createParams);
|
|
2648
|
+
}
|
|
2649
|
+
case "vulcan_run_batch": {
|
|
2650
|
+
const params = toolSchemas.vulcan_run_batch.parse(args);
|
|
2651
|
+
return await runBatch2(config, params);
|
|
2652
|
+
}
|
|
2653
|
+
case "vulcan_get_batch_status": {
|
|
2654
|
+
const params = toolSchemas.vulcan_get_batch_status.parse(args);
|
|
2655
|
+
return await getBatchStatus2(config, params);
|
|
2656
|
+
}
|
|
2657
|
+
case "vulcan_calculate_metrics": {
|
|
2658
|
+
const params = toolSchemas.vulcan_calculate_metrics.parse(args);
|
|
2659
|
+
return await calculateMetrics2(config, params);
|
|
2660
|
+
}
|
|
2661
|
+
case "vulcan_list_csv_columns": {
|
|
2662
|
+
const params = toolSchemas.vulcan_list_csv_columns.parse(args);
|
|
2663
|
+
return await listCsvColumns2(config, params);
|
|
2664
|
+
}
|
|
2665
|
+
case "vulcan_list_batch_models": {
|
|
2666
|
+
const params = toolSchemas.vulcan_list_batch_models.parse(args);
|
|
2667
|
+
return await listBatchModels2(config, params);
|
|
2668
|
+
}
|
|
2669
|
+
case "vulcan_merge_csv_to_json": {
|
|
2670
|
+
const params = toolSchemas.vulcan_merge_csv_to_json.parse(args);
|
|
2671
|
+
return await mergeCsvToJson(config, params);
|
|
2672
|
+
}
|
|
2673
|
+
case "vulcan_validate_geometry_csv": {
|
|
2674
|
+
const params = toolSchemas.vulcan_validate_geometry_csv.parse(args);
|
|
2675
|
+
return await validateGeometryCsv2(config, params);
|
|
2676
|
+
}
|
|
2677
|
+
case "vulcan_auto_thermal_bridges": {
|
|
2678
|
+
const params = toolSchemas.vulcan_auto_thermal_bridges.parse(args);
|
|
2679
|
+
return await generateAutoThermalBridges2(config, params);
|
|
2680
|
+
}
|
|
2681
|
+
case "vulcan_validate_thermal_bridges": {
|
|
2682
|
+
const params = toolSchemas.vulcan_validate_thermal_bridges.parse(args);
|
|
2683
|
+
return await validateThermalBridges2(config, params);
|
|
2684
|
+
}
|
|
2685
|
+
default:
|
|
2686
|
+
throw new Error(`Unknown tool: ${name}`);
|
|
2687
|
+
}
|
|
2688
|
+
}
|
|
2689
|
+
|
|
2690
|
+
// src/server.ts
|
|
2691
|
+
async function startServer(configPath, port) {
|
|
2692
|
+
const httpPort = port || parseInt(process.env.HELPER_PORT || "5000", 10);
|
|
2693
|
+
let config;
|
|
2694
|
+
try {
|
|
2695
|
+
config = await readConfig(configPath);
|
|
2696
|
+
console.error(`[MCP Helper] Config loaded from: ${config.configPath}`);
|
|
2697
|
+
console.error(`[MCP Helper] Workspace: ${config.workspace}`);
|
|
2698
|
+
} catch (error) {
|
|
2699
|
+
const err = error;
|
|
2700
|
+
console.error(`[MCP Helper] Failed to load config: ${err.message}`);
|
|
2701
|
+
process.exit(1);
|
|
2702
|
+
}
|
|
2703
|
+
try {
|
|
2704
|
+
await initWasm();
|
|
2705
|
+
console.error("[MCP Helper] WASM initialized");
|
|
2706
|
+
} catch (error) {
|
|
2707
|
+
const err = error;
|
|
2708
|
+
console.error(`[MCP Helper] WASM initialization failed: ${err.message}`);
|
|
2709
|
+
process.exit(1);
|
|
2710
|
+
}
|
|
2711
|
+
const app = express();
|
|
2712
|
+
const corsOptions = {
|
|
2713
|
+
origin: true,
|
|
2714
|
+
// Allow all origins (localhost, 127.0.0.1, etc.)
|
|
2715
|
+
methods: ["GET", "OPTIONS"],
|
|
2716
|
+
credentials: false
|
|
2717
|
+
};
|
|
2718
|
+
const mcpServer = new Server(
|
|
2719
|
+
{
|
|
2720
|
+
name: "vulcan-mcp-helper",
|
|
2721
|
+
version: "0.1.0"
|
|
2722
|
+
},
|
|
2723
|
+
{
|
|
2724
|
+
capabilities: {
|
|
2725
|
+
tools: {}
|
|
2726
|
+
}
|
|
2727
|
+
}
|
|
2728
|
+
);
|
|
2729
|
+
const originalOnInitialize = mcpServer._oninitialize?.bind(mcpServer);
|
|
2730
|
+
if (originalOnInitialize) {
|
|
2731
|
+
mcpServer.removeRequestHandler("initialize");
|
|
2732
|
+
const LegacyInitializeSchema = InitializeRequestSchema.extend({
|
|
2733
|
+
params: InitializeRequestSchema.shape.params.partial().transform((params = {}) => ({
|
|
2734
|
+
protocolVersion: params.protocolVersion || "2024-11-05",
|
|
2735
|
+
capabilities: params.capabilities || {},
|
|
2736
|
+
clientInfo: params.clientInfo || { name: "unknown-client", version: "0.0.0" }
|
|
2737
|
+
}))
|
|
2738
|
+
});
|
|
2739
|
+
mcpServer.setRequestHandler(LegacyInitializeSchema, (request) => originalOnInitialize(request));
|
|
2740
|
+
}
|
|
2741
|
+
mcpServer.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
2742
|
+
return { tools: toolDefinitions };
|
|
2743
|
+
});
|
|
2744
|
+
mcpServer.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
2745
|
+
const { name, arguments: toolArgs } = request.params;
|
|
2746
|
+
console.error(`[MCP Helper] Tool call: ${name}`);
|
|
2747
|
+
try {
|
|
2748
|
+
const result = await handleToolCall(name, toolArgs, config);
|
|
2749
|
+
return {
|
|
2750
|
+
content: [
|
|
2751
|
+
{
|
|
2752
|
+
type: "text",
|
|
2753
|
+
text: JSON.stringify(result, null, 2)
|
|
2754
|
+
}
|
|
2755
|
+
]
|
|
2756
|
+
};
|
|
2757
|
+
} catch (error) {
|
|
2758
|
+
const err = error;
|
|
2759
|
+
console.error(`[MCP Helper] Tool call failed: ${err.message}`);
|
|
2760
|
+
throw err;
|
|
2761
|
+
}
|
|
2762
|
+
});
|
|
2763
|
+
app.post("/mcp", express.raw({ type: "application/json", limit: "10mb" }), async (req, res) => {
|
|
2764
|
+
try {
|
|
2765
|
+
await authorizeMcpRequest(req.headers.authorization, config.license_token);
|
|
2766
|
+
} catch {
|
|
2767
|
+
console.error("[MCP Helper] Rejected unauthorized MCP request");
|
|
2768
|
+
res.set("WWW-Authenticate", 'Bearer realm="vulcan-mcp"').status(401).json({
|
|
2769
|
+
jsonrpc: "2.0",
|
|
2770
|
+
error: {
|
|
2771
|
+
code: -32001,
|
|
2772
|
+
message: "Unauthorized"
|
|
2773
|
+
},
|
|
2774
|
+
id: null
|
|
2775
|
+
});
|
|
2776
|
+
return;
|
|
2777
|
+
}
|
|
2778
|
+
let requestBody;
|
|
2779
|
+
try {
|
|
2780
|
+
const bodyText = req.body.toString("utf-8");
|
|
2781
|
+
requestBody = JSON.parse(bodyText);
|
|
2782
|
+
} catch (error) {
|
|
2783
|
+
const err = error;
|
|
2784
|
+
res.status(400).json({
|
|
2785
|
+
jsonrpc: "2.0",
|
|
2786
|
+
error: {
|
|
2787
|
+
code: -32700,
|
|
2788
|
+
message: "Parse error",
|
|
2789
|
+
data: err.message
|
|
2790
|
+
},
|
|
2791
|
+
id: null
|
|
2792
|
+
});
|
|
2793
|
+
return;
|
|
2794
|
+
}
|
|
2795
|
+
const transport = new StreamableHTTPServerTransport({
|
|
2796
|
+
sessionIdGenerator: void 0,
|
|
2797
|
+
enableJsonResponse: true
|
|
2798
|
+
});
|
|
2799
|
+
res.on("close", () => {
|
|
2800
|
+
transport.close();
|
|
2801
|
+
});
|
|
2802
|
+
try {
|
|
2803
|
+
await mcpServer.connect(transport);
|
|
2804
|
+
await transport.handleRequest(req, res, requestBody);
|
|
2805
|
+
} catch (error) {
|
|
2806
|
+
const err = error;
|
|
2807
|
+
console.error(`[MCP Helper] MCP request failed: ${err.message}`);
|
|
2808
|
+
if (!res.headersSent) {
|
|
2809
|
+
res.status(500).json({
|
|
2810
|
+
jsonrpc: "2.0",
|
|
2811
|
+
error: {
|
|
2812
|
+
code: -32603,
|
|
2813
|
+
message: "Internal server error",
|
|
2814
|
+
data: err.message
|
|
2815
|
+
},
|
|
2816
|
+
id: requestBody?.id || null
|
|
2817
|
+
});
|
|
2818
|
+
}
|
|
2819
|
+
}
|
|
2820
|
+
});
|
|
2821
|
+
app.get("/health", cors(corsOptions), (req, res) => {
|
|
2822
|
+
res.json({
|
|
2823
|
+
status: "running",
|
|
2824
|
+
port: httpPort,
|
|
2825
|
+
version: "0.1.0",
|
|
2826
|
+
name: "vulcan-mcp-helper"
|
|
2827
|
+
});
|
|
2828
|
+
});
|
|
2829
|
+
app.get("/helper/status", cors(corsOptions), (req, res) => {
|
|
2830
|
+
res.json({
|
|
2831
|
+
running: true,
|
|
2832
|
+
port: httpPort,
|
|
2833
|
+
version: "0.1.0",
|
|
2834
|
+
mcpReady: true
|
|
2835
|
+
});
|
|
2836
|
+
});
|
|
2837
|
+
app.listen(httpPort, "127.0.0.1", () => {
|
|
2838
|
+
console.error(`[MCP Helper] Server running on http://127.0.0.1:${httpPort}`);
|
|
2839
|
+
console.error(`[MCP Helper] MCP endpoint: http://127.0.0.1:${httpPort}/mcp`);
|
|
2840
|
+
console.error(`[MCP Helper] Health check: http://127.0.0.1:${httpPort}/health`);
|
|
2841
|
+
console.error(`[MCP Helper] Status API: http://127.0.0.1:${httpPort}/helper/status`);
|
|
2842
|
+
});
|
|
2843
|
+
}
|
|
2844
|
+
|
|
2845
|
+
// bin/vulcan-mcp-helper.ts
|
|
2846
|
+
function parseArgs() {
|
|
2847
|
+
const args = process.argv.slice(2);
|
|
2848
|
+
const result = {};
|
|
2849
|
+
for (let i = 0; i < args.length; i++) {
|
|
2850
|
+
if (args[i] === "--config" && i + 1 < args.length) {
|
|
2851
|
+
result.configPath = args[i + 1];
|
|
2852
|
+
i++;
|
|
2853
|
+
} else if (args[i] === "--port" && i + 1 < args.length) {
|
|
2854
|
+
const portArg = args[i + 1];
|
|
2855
|
+
if (!portArg) {
|
|
2856
|
+
console.error("Port argument is missing");
|
|
2857
|
+
process.exit(1);
|
|
2858
|
+
}
|
|
2859
|
+
const port = parseInt(portArg, 10);
|
|
2860
|
+
if (isNaN(port) || port < 1 || port > 65535) {
|
|
2861
|
+
console.error(`Invalid port: ${portArg}`);
|
|
2862
|
+
process.exit(1);
|
|
2863
|
+
}
|
|
2864
|
+
result.port = port;
|
|
2865
|
+
i++;
|
|
2866
|
+
} else if (args[i] === "--help" || args[i] === "-h") {
|
|
2867
|
+
console.log(`
|
|
33
2868
|
Usage: vulcan-mcp-helper [--config <path>] [--port <port>]
|
|
34
2869
|
|
|
35
2870
|
Options:
|
|
@@ -43,21 +2878,19 @@ Examples:
|
|
|
43
2878
|
vulcan-mcp-helper --port 5000
|
|
44
2879
|
vulcan-mcp-helper --config ./config.json --port 5000
|
|
45
2880
|
`);
|
|
46
|
-
|
|
47
|
-
}
|
|
2881
|
+
process.exit(0);
|
|
48
2882
|
}
|
|
49
|
-
|
|
2883
|
+
}
|
|
2884
|
+
return result;
|
|
50
2885
|
}
|
|
51
2886
|
async function main() {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
2887
|
+
try {
|
|
2888
|
+
const { configPath, port } = parseArgs();
|
|
2889
|
+
await startServer(configPath, port);
|
|
2890
|
+
} catch (error) {
|
|
2891
|
+
const err = error;
|
|
2892
|
+
console.error(`Error: ${err.message}`);
|
|
2893
|
+
process.exit(1);
|
|
2894
|
+
}
|
|
61
2895
|
}
|
|
62
2896
|
main();
|
|
63
|
-
//# sourceMappingURL=vulcan-mcp-helper.js.map
|