@vulcan-energy/mcp-helper 0.1.8 → 0.2.3
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 +45 -3
- package/dist/bin/vulcan-mcp-helper.js +53 -2810
- package/dist/hem-target-runtime/browser-adapter.mjs +260 -0
- package/dist/hem-target-runtime/host.mjs +7364 -0
- package/dist/hem-target-runtime/python-worker.mjs +1005 -0
- package/dist/hem-target-runtime/release-manifests.mjs +50 -0
- package/dist/hem-target-runtime/rust-worker.mjs +460 -0
- package/dist/server.js +52 -2771
- package/package.json +4 -3
- package/wasm/wasm_version.json +13 -5
- package/wasm/wasm_wrapper.js +163 -56
- package/wasm/wasm_wrapper_bg.wasm +0 -0
|
@@ -0,0 +1,1005 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
9
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
28
|
+
|
|
29
|
+
// ../node_modules/papaparse/papaparse.min.js
|
|
30
|
+
var require_papaparse_min = __commonJS({
|
|
31
|
+
"../node_modules/papaparse/papaparse.min.js"(exports, module) {
|
|
32
|
+
((e, t) => {
|
|
33
|
+
"function" == typeof define && define.amd ? define([], t) : "object" == typeof module && "undefined" != typeof exports ? module.exports = t() : e.Papa = t();
|
|
34
|
+
})(exports, function r() {
|
|
35
|
+
var n = "undefined" != typeof self ? self : "undefined" != typeof window ? window : void 0 !== n ? n : {};
|
|
36
|
+
var d, s = !n.document && !!n.postMessage, a = n.IS_PAPA_WORKER || false, o = {}, h = 0, v = {};
|
|
37
|
+
function u(e) {
|
|
38
|
+
this._handle = null, this._finished = false, this._completed = false, this._halted = false, this._input = null, this._baseIndex = 0, this._partialLine = "", this._rowCount = 0, this._start = 0, this._nextChunk = null, this.isFirstChunk = true, this._completeResults = { data: [], errors: [], meta: {} }, function(e2) {
|
|
39
|
+
var t = b(e2);
|
|
40
|
+
t.chunkSize = parseInt(t.chunkSize), e2.step || e2.chunk || (t.chunkSize = null);
|
|
41
|
+
this._handle = new i(t), (this._handle.streamer = this)._config = t;
|
|
42
|
+
}.call(this, e), this.parseChunk = function(t, e2) {
|
|
43
|
+
var i2 = parseInt(this._config.skipFirstNLines) || 0;
|
|
44
|
+
if (this.isFirstChunk && 0 < i2) {
|
|
45
|
+
let e3 = this._config.newline;
|
|
46
|
+
e3 || (r2 = this._config.quoteChar || '"', e3 = this._handle.guessLineEndings(t, r2)), t = [...t.split(e3).slice(i2)].join(e3);
|
|
47
|
+
}
|
|
48
|
+
this.isFirstChunk && U(this._config.beforeFirstChunk) && void 0 !== (r2 = this._config.beforeFirstChunk(t)) && (t = r2), this.isFirstChunk = false, this._halted = false;
|
|
49
|
+
var i2 = this._partialLine + t, r2 = (this._partialLine = "", this._handle.parse(i2, this._baseIndex, !this._finished));
|
|
50
|
+
if (!this._handle.paused() && !this._handle.aborted()) {
|
|
51
|
+
t = r2.meta.cursor, i2 = (this._finished || (this._partialLine = i2.substring(t - this._baseIndex), this._baseIndex = t), r2 && r2.data && (this._rowCount += r2.data.length), this._finished || this._config.preview && this._rowCount >= this._config.preview);
|
|
52
|
+
if (a) n.postMessage({ results: r2, workerId: v.WORKER_ID, finished: i2 });
|
|
53
|
+
else if (U(this._config.chunk) && !e2) {
|
|
54
|
+
if (this._config.chunk(r2, this._handle), this._handle.paused() || this._handle.aborted()) return void (this._halted = true);
|
|
55
|
+
this._completeResults = r2 = void 0;
|
|
56
|
+
}
|
|
57
|
+
return this._config.step || this._config.chunk || (this._completeResults.data = this._completeResults.data.concat(r2.data), this._completeResults.errors = this._completeResults.errors.concat(r2.errors), this._completeResults.meta = r2.meta), this._completed || !i2 || !U(this._config.complete) || r2 && r2.meta.aborted || (this._config.complete(this._completeResults, this._input), this._completed = true), i2 || r2 && r2.meta.paused || this._nextChunk(), r2;
|
|
58
|
+
}
|
|
59
|
+
this._halted = true;
|
|
60
|
+
}, this._sendError = function(e2) {
|
|
61
|
+
U(this._config.error) ? this._config.error(e2) : a && this._config.error && n.postMessage({ workerId: v.WORKER_ID, error: e2, finished: false });
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
function f(e) {
|
|
65
|
+
var r2;
|
|
66
|
+
(e = e || {}).chunkSize || (e.chunkSize = v.RemoteChunkSize), u.call(this, e), this._nextChunk = s ? function() {
|
|
67
|
+
this._readChunk(), this._chunkLoaded();
|
|
68
|
+
} : function() {
|
|
69
|
+
this._readChunk();
|
|
70
|
+
}, this.stream = function(e2) {
|
|
71
|
+
this._input = e2, this._nextChunk();
|
|
72
|
+
}, this._readChunk = function() {
|
|
73
|
+
if (this._finished) this._chunkLoaded();
|
|
74
|
+
else {
|
|
75
|
+
if (r2 = new XMLHttpRequest(), this._config.withCredentials && (r2.withCredentials = this._config.withCredentials), s || (r2.onload = y(this._chunkLoaded, this), r2.onerror = y(this._chunkError, this)), r2.open(this._config.downloadRequestBody ? "POST" : "GET", this._input, !s), this._config.downloadRequestHeaders) {
|
|
76
|
+
var e2, t = this._config.downloadRequestHeaders;
|
|
77
|
+
for (e2 in t) r2.setRequestHeader(e2, t[e2]);
|
|
78
|
+
}
|
|
79
|
+
var i2;
|
|
80
|
+
this._config.chunkSize && (i2 = this._start + this._config.chunkSize - 1, r2.setRequestHeader("Range", "bytes=" + this._start + "-" + i2));
|
|
81
|
+
try {
|
|
82
|
+
r2.send(this._config.downloadRequestBody);
|
|
83
|
+
} catch (e3) {
|
|
84
|
+
this._chunkError(e3.message);
|
|
85
|
+
}
|
|
86
|
+
s && 0 === r2.status && this._chunkError();
|
|
87
|
+
}
|
|
88
|
+
}, this._chunkLoaded = function() {
|
|
89
|
+
4 === r2.readyState && (r2.status < 200 || 400 <= r2.status ? this._chunkError() : (this._start += this._config.chunkSize || r2.responseText.length, this._finished = !this._config.chunkSize || this._start >= ((e2) => null !== (e2 = e2.getResponseHeader("Content-Range")) ? parseInt(e2.substring(e2.lastIndexOf("/") + 1)) : -1)(r2), this.parseChunk(r2.responseText)));
|
|
90
|
+
}, this._chunkError = function(e2) {
|
|
91
|
+
e2 = r2.statusText || e2;
|
|
92
|
+
this._sendError(new Error(e2));
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
function l(e) {
|
|
96
|
+
(e = e || {}).chunkSize || (e.chunkSize = v.LocalChunkSize), u.call(this, e);
|
|
97
|
+
var i2, r2, n2 = "undefined" != typeof FileReader;
|
|
98
|
+
this.stream = function(e2) {
|
|
99
|
+
this._input = e2, r2 = e2.slice || e2.webkitSlice || e2.mozSlice, n2 ? ((i2 = new FileReader()).onload = y(this._chunkLoaded, this), i2.onerror = y(this._chunkError, this)) : i2 = new FileReaderSync(), this._nextChunk();
|
|
100
|
+
}, this._nextChunk = function() {
|
|
101
|
+
this._finished || this._config.preview && !(this._rowCount < this._config.preview) || this._readChunk();
|
|
102
|
+
}, this._readChunk = function() {
|
|
103
|
+
var e2 = this._input, t = (this._config.chunkSize && (t = Math.min(this._start + this._config.chunkSize, this._input.size), e2 = r2.call(e2, this._start, t)), i2.readAsText(e2, this._config.encoding));
|
|
104
|
+
n2 || this._chunkLoaded({ target: { result: t } });
|
|
105
|
+
}, this._chunkLoaded = function(e2) {
|
|
106
|
+
this._start += this._config.chunkSize, this._finished = !this._config.chunkSize || this._start >= this._input.size, this.parseChunk(e2.target.result);
|
|
107
|
+
}, this._chunkError = function() {
|
|
108
|
+
this._sendError(i2.error);
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
function c(e) {
|
|
112
|
+
var i2;
|
|
113
|
+
u.call(this, e = e || {}), this.stream = function(e2) {
|
|
114
|
+
return i2 = e2, this._nextChunk();
|
|
115
|
+
}, this._nextChunk = function() {
|
|
116
|
+
var e2, t;
|
|
117
|
+
if (!this._finished) return e2 = this._config.chunkSize, i2 = e2 ? (t = i2.substring(0, e2), i2.substring(e2)) : (t = i2, ""), this._finished = !i2, this.parseChunk(t);
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
function p(e) {
|
|
121
|
+
u.call(this, e = e || {});
|
|
122
|
+
var t = [], i2 = true, r2 = false;
|
|
123
|
+
this.pause = function() {
|
|
124
|
+
u.prototype.pause.apply(this, arguments), this._input.pause();
|
|
125
|
+
}, this.resume = function() {
|
|
126
|
+
u.prototype.resume.apply(this, arguments), this._input.resume();
|
|
127
|
+
}, this.stream = function(e2) {
|
|
128
|
+
this._input = e2, this._input.on("data", this._streamData), this._input.on("end", this._streamEnd), this._input.on("error", this._streamError);
|
|
129
|
+
}, this._checkIsFinished = function() {
|
|
130
|
+
r2 && 1 === t.length && (this._finished = true);
|
|
131
|
+
}, this._nextChunk = function() {
|
|
132
|
+
this._checkIsFinished(), t.length ? this.parseChunk(t.shift()) : i2 = true;
|
|
133
|
+
}, this._streamData = y(function(e2) {
|
|
134
|
+
try {
|
|
135
|
+
t.push("string" == typeof e2 ? e2 : e2.toString(this._config.encoding)), i2 && (i2 = false, this._checkIsFinished(), this.parseChunk(t.shift()));
|
|
136
|
+
} catch (e3) {
|
|
137
|
+
this._streamError(e3);
|
|
138
|
+
}
|
|
139
|
+
}, this), this._streamError = y(function(e2) {
|
|
140
|
+
this._streamCleanUp(), this._sendError(e2);
|
|
141
|
+
}, this), this._streamEnd = y(function() {
|
|
142
|
+
this._streamCleanUp(), r2 = true, this._streamData("");
|
|
143
|
+
}, this), this._streamCleanUp = y(function() {
|
|
144
|
+
this._input.removeListener("data", this._streamData), this._input.removeListener("end", this._streamEnd), this._input.removeListener("error", this._streamError);
|
|
145
|
+
}, this);
|
|
146
|
+
}
|
|
147
|
+
function i(m2) {
|
|
148
|
+
var n2, s2, a2, t, o2 = Math.pow(2, 53), h2 = -o2, u2 = /^\s*-?(\d+\.?|\.\d+|\d+\.\d+)([eE][-+]?\d+)?\s*$/, d2 = /^((\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z)))$/, i2 = this, r2 = 0, f2 = 0, l2 = false, e = false, c2 = [], p2 = { data: [], errors: [], meta: {} };
|
|
149
|
+
function y2(e2) {
|
|
150
|
+
return "greedy" === m2.skipEmptyLines ? "" === e2.join("").trim() : 1 === e2.length && 0 === e2[0].length;
|
|
151
|
+
}
|
|
152
|
+
function g2() {
|
|
153
|
+
if (p2 && a2 && (k("Delimiter", "UndetectableDelimiter", "Unable to auto-detect delimiting character; defaulted to '" + v.DefaultDelimiter + "'"), a2 = false), m2.skipEmptyLines && (p2.data = p2.data.filter(function(e3) {
|
|
154
|
+
return !y2(e3);
|
|
155
|
+
})), _2()) {
|
|
156
|
+
let t3 = function(e3, t4) {
|
|
157
|
+
U(m2.transformHeader) && (e3 = m2.transformHeader(e3, t4)), c2.push(e3);
|
|
158
|
+
};
|
|
159
|
+
var t2 = t3;
|
|
160
|
+
if (p2) if (Array.isArray(p2.data[0])) {
|
|
161
|
+
for (var e2 = 0; _2() && e2 < p2.data.length; e2++) p2.data[e2].forEach(t3);
|
|
162
|
+
p2.data.splice(0, 1);
|
|
163
|
+
} else p2.data.forEach(t3);
|
|
164
|
+
}
|
|
165
|
+
function i3(e3, t3) {
|
|
166
|
+
for (var i4 = m2.header ? {} : [], r4 = 0; r4 < e3.length; r4++) {
|
|
167
|
+
var n3 = r4, s3 = e3[r4], s3 = ((e4, t4) => ((e5) => (m2.dynamicTypingFunction && void 0 === m2.dynamicTyping[e5] && (m2.dynamicTyping[e5] = m2.dynamicTypingFunction(e5)), true === (m2.dynamicTyping[e5] || m2.dynamicTyping)))(e4) ? "true" === t4 || "TRUE" === t4 || "false" !== t4 && "FALSE" !== t4 && (((e5) => {
|
|
168
|
+
if (u2.test(e5)) {
|
|
169
|
+
e5 = parseFloat(e5);
|
|
170
|
+
if (h2 < e5 && e5 < o2) return 1;
|
|
171
|
+
}
|
|
172
|
+
})(t4) ? parseFloat(t4) : d2.test(t4) ? new Date(t4) : "" === t4 ? null : t4) : t4)(n3 = m2.header ? r4 >= c2.length ? "__parsed_extra" : c2[r4] : n3, s3 = m2.transform ? m2.transform(s3, n3) : s3);
|
|
173
|
+
"__parsed_extra" === n3 ? (i4[n3] = i4[n3] || [], i4[n3].push(s3)) : i4[n3] = s3;
|
|
174
|
+
}
|
|
175
|
+
return m2.header && (r4 > c2.length ? k("FieldMismatch", "TooManyFields", "Too many fields: expected " + c2.length + " fields but parsed " + r4, f2 + t3) : r4 < c2.length && k("FieldMismatch", "TooFewFields", "Too few fields: expected " + c2.length + " fields but parsed " + r4, f2 + t3)), i4;
|
|
176
|
+
}
|
|
177
|
+
var r3;
|
|
178
|
+
p2 && (m2.header || m2.dynamicTyping || m2.transform) && (r3 = 1, !p2.data.length || Array.isArray(p2.data[0]) ? (p2.data = p2.data.map(i3), r3 = p2.data.length) : p2.data = i3(p2.data, 0), m2.header && p2.meta && (p2.meta.fields = c2), f2 += r3);
|
|
179
|
+
}
|
|
180
|
+
function _2() {
|
|
181
|
+
return m2.header && 0 === c2.length;
|
|
182
|
+
}
|
|
183
|
+
function k(e2, t2, i3, r3) {
|
|
184
|
+
e2 = { type: e2, code: t2, message: i3 };
|
|
185
|
+
void 0 !== r3 && (e2.row = r3), p2.errors.push(e2);
|
|
186
|
+
}
|
|
187
|
+
U(m2.step) && (t = m2.step, m2.step = function(e2) {
|
|
188
|
+
p2 = e2, _2() ? g2() : (g2(), 0 !== p2.data.length && (r2 += e2.data.length, m2.preview && r2 > m2.preview ? s2.abort() : (p2.data = p2.data[0], t(p2, i2))));
|
|
189
|
+
}), this.parse = function(e2, t2, i3) {
|
|
190
|
+
var r3 = m2.quoteChar || '"', r3 = (m2.newline || (m2.newline = this.guessLineEndings(e2, r3)), a2 = false, m2.delimiter ? U(m2.delimiter) && (m2.delimiter = m2.delimiter(e2), p2.meta.delimiter = m2.delimiter) : ((r3 = ((e3, t3, i4, r4, n3) => {
|
|
191
|
+
var s3, a3, o3, h3;
|
|
192
|
+
n3 = n3 || [",", " ", "|", ";", v.RECORD_SEP, v.UNIT_SEP];
|
|
193
|
+
for (var u3 = 0; u3 < n3.length; u3++) {
|
|
194
|
+
for (var d3, f3 = n3[u3], l3 = 0, c3 = 0, p3 = 0, g3 = (o3 = void 0, new E({ comments: r4, delimiter: f3, newline: t3, preview: 10 }).parse(e3)), _3 = 0; _3 < g3.data.length; _3++) i4 && y2(g3.data[_3]) ? p3++ : (d3 = g3.data[_3].length, c3 += d3, void 0 === o3 ? o3 = d3 : 0 < d3 && (l3 += Math.abs(d3 - o3), o3 = d3));
|
|
195
|
+
0 < g3.data.length && (c3 /= g3.data.length - p3), (void 0 === a3 || l3 <= a3) && (void 0 === h3 || h3 < c3) && 1.99 < c3 && (a3 = l3, s3 = f3, h3 = c3);
|
|
196
|
+
}
|
|
197
|
+
return { successful: !!(m2.delimiter = s3), bestDelimiter: s3 };
|
|
198
|
+
})(e2, m2.newline, m2.skipEmptyLines, m2.comments, m2.delimitersToGuess)).successful ? m2.delimiter = r3.bestDelimiter : (a2 = true, m2.delimiter = v.DefaultDelimiter), p2.meta.delimiter = m2.delimiter), b(m2));
|
|
199
|
+
return m2.preview && m2.header && r3.preview++, n2 = e2, s2 = new E(r3), p2 = s2.parse(n2, t2, i3), g2(), l2 ? { meta: { paused: true } } : p2 || { meta: { paused: false } };
|
|
200
|
+
}, this.paused = function() {
|
|
201
|
+
return l2;
|
|
202
|
+
}, this.pause = function() {
|
|
203
|
+
l2 = true, s2.abort(), n2 = U(m2.chunk) ? "" : n2.substring(s2.getCharIndex());
|
|
204
|
+
}, this.resume = function() {
|
|
205
|
+
i2.streamer._halted ? (l2 = false, i2.streamer.parseChunk(n2, true)) : setTimeout(i2.resume, 3);
|
|
206
|
+
}, this.aborted = function() {
|
|
207
|
+
return e;
|
|
208
|
+
}, this.abort = function() {
|
|
209
|
+
e = true, s2.abort(), p2.meta.aborted = true, U(m2.complete) && m2.complete(p2), n2 = "";
|
|
210
|
+
}, this.guessLineEndings = function(e2, t2) {
|
|
211
|
+
e2 = e2.substring(0, 1048576);
|
|
212
|
+
var t2 = new RegExp(P(t2) + "([^]*?)" + P(t2), "gm"), i3 = (e2 = e2.replace(t2, "")).split("\r"), t2 = e2.split("\n"), e2 = 1 < t2.length && t2[0].length < i3[0].length;
|
|
213
|
+
if (1 === i3.length || e2) return "\n";
|
|
214
|
+
for (var r3 = 0, n3 = 0; n3 < i3.length; n3++) "\n" === i3[n3][0] && r3++;
|
|
215
|
+
return r3 >= i3.length / 2 ? "\r\n" : "\r";
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
function P(e) {
|
|
219
|
+
return e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
220
|
+
}
|
|
221
|
+
function E(C) {
|
|
222
|
+
var S = (C = C || {}).delimiter, O = C.newline, x = C.comments, I = C.step, A = C.preview, T = C.fastMode, D = null, L = false, F = null == C.quoteChar ? '"' : C.quoteChar, j = F;
|
|
223
|
+
if (void 0 !== C.escapeChar && (j = C.escapeChar), ("string" != typeof S || -1 < v.BAD_DELIMITERS.indexOf(S)) && (S = ","), x === S) throw new Error("Comment character same as delimiter");
|
|
224
|
+
true === x ? x = "#" : ("string" != typeof x || -1 < v.BAD_DELIMITERS.indexOf(x)) && (x = false), "\n" !== O && "\r" !== O && "\r\n" !== O && (O = "\n");
|
|
225
|
+
var z = 0, M = false;
|
|
226
|
+
this.parse = function(i2, t, r2) {
|
|
227
|
+
if ("string" != typeof i2) throw new Error("Input must be a string");
|
|
228
|
+
var n2 = i2.length, e = S.length, s2 = O.length, a2 = x.length, o2 = U(I), h2 = [], u2 = [], d2 = [], f2 = z = 0;
|
|
229
|
+
if (!i2) return w();
|
|
230
|
+
if (T || false !== T && -1 === i2.indexOf(F)) {
|
|
231
|
+
for (var l2 = i2.split(O), c2 = 0; c2 < l2.length; c2++) {
|
|
232
|
+
if (d2 = l2[c2], z += d2.length, c2 !== l2.length - 1) z += O.length;
|
|
233
|
+
else if (r2) return w();
|
|
234
|
+
if (!x || d2.substring(0, a2) !== x) {
|
|
235
|
+
if (o2) {
|
|
236
|
+
if (h2 = [], k(d2.split(S)), R(), M) return w();
|
|
237
|
+
} else k(d2.split(S));
|
|
238
|
+
if (A && A <= c2) return h2 = h2.slice(0, A), w(true);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
return w();
|
|
242
|
+
}
|
|
243
|
+
for (var p2 = i2.indexOf(S, z), g2 = i2.indexOf(O, z), _2 = new RegExp(P(j) + P(F), "g"), m2 = i2.indexOf(F, z); ; ) if (i2[z] === F) for (m2 = z, z++; ; ) {
|
|
244
|
+
if (-1 === (m2 = i2.indexOf(F, m2 + 1))) return r2 || u2.push({ type: "Quotes", code: "MissingQuotes", message: "Quoted field unterminated", row: h2.length, index: z }), E2();
|
|
245
|
+
if (m2 === n2 - 1) return E2(i2.substring(z, m2).replace(_2, F));
|
|
246
|
+
if (F === j && i2[m2 + 1] === j) m2++;
|
|
247
|
+
else if (F === j || 0 === m2 || i2[m2 - 1] !== j) {
|
|
248
|
+
-1 !== p2 && p2 < m2 + 1 && (p2 = i2.indexOf(S, m2 + 1));
|
|
249
|
+
var y2 = v2(-1 === (g2 = -1 !== g2 && g2 < m2 + 1 ? i2.indexOf(O, m2 + 1) : g2) ? p2 : Math.min(p2, g2));
|
|
250
|
+
if (i2.substr(m2 + 1 + y2, e) === S) {
|
|
251
|
+
d2.push(i2.substring(z, m2).replace(_2, F)), i2[z = m2 + 1 + y2 + e] !== F && (m2 = i2.indexOf(F, z)), p2 = i2.indexOf(S, z), g2 = i2.indexOf(O, z);
|
|
252
|
+
break;
|
|
253
|
+
}
|
|
254
|
+
y2 = v2(g2);
|
|
255
|
+
if (i2.substring(m2 + 1 + y2, m2 + 1 + y2 + s2) === O) {
|
|
256
|
+
if (d2.push(i2.substring(z, m2).replace(_2, F)), b2(m2 + 1 + y2 + s2), p2 = i2.indexOf(S, z), m2 = i2.indexOf(F, z), o2 && (R(), M)) return w();
|
|
257
|
+
if (A && h2.length >= A) return w(true);
|
|
258
|
+
break;
|
|
259
|
+
}
|
|
260
|
+
u2.push({ type: "Quotes", code: "InvalidQuotes", message: "Trailing quote on quoted field is malformed", row: h2.length, index: z }), m2++;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
else if (x && 0 === d2.length && i2.substring(z, z + a2) === x) {
|
|
264
|
+
if (-1 === g2) return w();
|
|
265
|
+
z = g2 + s2, g2 = i2.indexOf(O, z), p2 = i2.indexOf(S, z);
|
|
266
|
+
} else if (-1 !== p2 && (p2 < g2 || -1 === g2)) d2.push(i2.substring(z, p2)), z = p2 + e, p2 = i2.indexOf(S, z);
|
|
267
|
+
else {
|
|
268
|
+
if (-1 === g2) break;
|
|
269
|
+
if (d2.push(i2.substring(z, g2)), b2(g2 + s2), o2 && (R(), M)) return w();
|
|
270
|
+
if (A && h2.length >= A) return w(true);
|
|
271
|
+
}
|
|
272
|
+
return E2();
|
|
273
|
+
function k(e2) {
|
|
274
|
+
h2.push(e2), f2 = z;
|
|
275
|
+
}
|
|
276
|
+
function v2(e2) {
|
|
277
|
+
var t2 = 0;
|
|
278
|
+
return t2 = -1 !== e2 && (e2 = i2.substring(m2 + 1, e2)) && "" === e2.trim() ? e2.length : t2;
|
|
279
|
+
}
|
|
280
|
+
function E2(e2) {
|
|
281
|
+
return r2 || (void 0 === e2 && (e2 = i2.substring(z)), d2.push(e2), z = n2, k(d2), o2 && R()), w();
|
|
282
|
+
}
|
|
283
|
+
function b2(e2) {
|
|
284
|
+
z = e2, k(d2), d2 = [], g2 = i2.indexOf(O, z);
|
|
285
|
+
}
|
|
286
|
+
function w(e2) {
|
|
287
|
+
if (C.header && !t && h2.length && !L) {
|
|
288
|
+
var s3 = h2[0], a3 = /* @__PURE__ */ Object.create(null), o3 = new Set(s3);
|
|
289
|
+
let n3 = false;
|
|
290
|
+
for (let r3 = 0; r3 < s3.length; r3++) {
|
|
291
|
+
let i3 = s3[r3];
|
|
292
|
+
if (a3[i3 = U(C.transformHeader) ? C.transformHeader(i3, r3) : i3]) {
|
|
293
|
+
let e3, t2 = a3[i3];
|
|
294
|
+
for (; e3 = i3 + "_" + t2, t2++, o3.has(e3); ) ;
|
|
295
|
+
o3.add(e3), s3[r3] = e3, a3[i3]++, n3 = true, (D = null === D ? {} : D)[e3] = i3;
|
|
296
|
+
} else a3[i3] = 1, s3[r3] = i3;
|
|
297
|
+
o3.add(i3);
|
|
298
|
+
}
|
|
299
|
+
n3 && console.warn("Duplicate headers found and renamed."), L = true;
|
|
300
|
+
}
|
|
301
|
+
return { data: h2, errors: u2, meta: { delimiter: S, linebreak: O, aborted: M, truncated: !!e2, cursor: f2 + (t || 0), renamedHeaders: D } };
|
|
302
|
+
}
|
|
303
|
+
function R() {
|
|
304
|
+
I(w()), h2 = [], u2 = [];
|
|
305
|
+
}
|
|
306
|
+
}, this.abort = function() {
|
|
307
|
+
M = true;
|
|
308
|
+
}, this.getCharIndex = function() {
|
|
309
|
+
return z;
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
function g(e) {
|
|
313
|
+
var t = e.data, i2 = o[t.workerId], r2 = false;
|
|
314
|
+
if (t.error) i2.userError(t.error, t.file);
|
|
315
|
+
else if (t.results && t.results.data) {
|
|
316
|
+
var n2 = { abort: function() {
|
|
317
|
+
r2 = true, _(t.workerId, { data: [], errors: [], meta: { aborted: true } });
|
|
318
|
+
}, pause: m, resume: m };
|
|
319
|
+
if (U(i2.userStep)) {
|
|
320
|
+
for (var s2 = 0; s2 < t.results.data.length && (i2.userStep({ data: t.results.data[s2], errors: t.results.errors, meta: t.results.meta }, n2), !r2); s2++) ;
|
|
321
|
+
delete t.results;
|
|
322
|
+
} else U(i2.userChunk) && (i2.userChunk(t.results, n2, t.file), delete t.results);
|
|
323
|
+
}
|
|
324
|
+
t.finished && !r2 && _(t.workerId, t.results);
|
|
325
|
+
}
|
|
326
|
+
function _(e, t) {
|
|
327
|
+
var i2 = o[e];
|
|
328
|
+
U(i2.userComplete) && i2.userComplete(t), i2.terminate(), delete o[e];
|
|
329
|
+
}
|
|
330
|
+
function m() {
|
|
331
|
+
throw new Error("Not implemented.");
|
|
332
|
+
}
|
|
333
|
+
function b(e) {
|
|
334
|
+
if ("object" != typeof e || null === e) return e;
|
|
335
|
+
var t, i2 = Array.isArray(e) ? [] : {};
|
|
336
|
+
for (t in e) i2[t] = b(e[t]);
|
|
337
|
+
return i2;
|
|
338
|
+
}
|
|
339
|
+
function y(e, t) {
|
|
340
|
+
return function() {
|
|
341
|
+
e.apply(t, arguments);
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
function U(e) {
|
|
345
|
+
return "function" == typeof e;
|
|
346
|
+
}
|
|
347
|
+
return v.parse = function(e, t) {
|
|
348
|
+
var i2 = (t = t || {}).dynamicTyping || false;
|
|
349
|
+
U(i2) && (t.dynamicTypingFunction = i2, i2 = {});
|
|
350
|
+
if (t.dynamicTyping = i2, t.transform = !!U(t.transform) && t.transform, !t.worker || !v.WORKERS_SUPPORTED) return i2 = null, v.NODE_STREAM_INPUT, "string" == typeof e ? (e = ((e2) => 65279 !== e2.charCodeAt(0) ? e2 : e2.slice(1))(e), i2 = new (t.download ? f : c)(t)) : true === e.readable && U(e.read) && U(e.on) ? i2 = new p(t) : (n.File && e instanceof File || e instanceof Object) && (i2 = new l(t)), i2.stream(e);
|
|
351
|
+
(i2 = (() => {
|
|
352
|
+
var e2;
|
|
353
|
+
return !!v.WORKERS_SUPPORTED && (e2 = (() => {
|
|
354
|
+
var e3 = n.URL || n.webkitURL || null, t2 = r.toString();
|
|
355
|
+
return v.BLOB_URL || (v.BLOB_URL = e3.createObjectURL(new Blob(["var global = (function() { if (typeof self !== 'undefined') { return self; } if (typeof window !== 'undefined') { return window; } if (typeof global !== 'undefined') { return global; } return {}; })(); global.IS_PAPA_WORKER=true; ", "(", t2, ")();"], { type: "text/javascript" })));
|
|
356
|
+
})(), (e2 = new n.Worker(e2)).onmessage = g, e2.id = h++, o[e2.id] = e2);
|
|
357
|
+
})()).userStep = t.step, i2.userChunk = t.chunk, i2.userComplete = t.complete, i2.userError = t.error, t.step = U(t.step), t.chunk = U(t.chunk), t.complete = U(t.complete), t.error = U(t.error), delete t.worker, i2.postMessage({ input: e, config: t, workerId: i2.id });
|
|
358
|
+
}, v.unparse = function(e, t) {
|
|
359
|
+
var n2 = false, _2 = true, m2 = ",", y2 = "\r\n", s2 = '"', a2 = s2 + s2, i2 = false, r2 = null, o2 = false, h2 = ((() => {
|
|
360
|
+
if ("object" == typeof t) {
|
|
361
|
+
if ("string" != typeof t.delimiter || v.BAD_DELIMITERS.filter(function(e2) {
|
|
362
|
+
return -1 !== t.delimiter.indexOf(e2);
|
|
363
|
+
}).length || (m2 = t.delimiter), "boolean" != typeof t.quotes && "function" != typeof t.quotes && !Array.isArray(t.quotes) || (n2 = t.quotes), "boolean" != typeof t.skipEmptyLines && "string" != typeof t.skipEmptyLines || (i2 = t.skipEmptyLines), "string" == typeof t.newline && (y2 = t.newline), "string" == typeof t.quoteChar && (s2 = t.quoteChar), "boolean" == typeof t.header && (_2 = t.header), Array.isArray(t.columns)) {
|
|
364
|
+
if (0 === t.columns.length) throw new Error("Option columns is empty");
|
|
365
|
+
r2 = t.columns;
|
|
366
|
+
}
|
|
367
|
+
void 0 !== t.escapeChar && (a2 = t.escapeChar + s2), t.escapeFormulae instanceof RegExp ? o2 = t.escapeFormulae : "boolean" == typeof t.escapeFormulae && t.escapeFormulae && (o2 = /^[=+\-@\t\r].*$/);
|
|
368
|
+
}
|
|
369
|
+
})(), new RegExp(P(s2), "g"));
|
|
370
|
+
"string" == typeof e && (e = JSON.parse(e));
|
|
371
|
+
if (Array.isArray(e)) {
|
|
372
|
+
if (!e.length || Array.isArray(e[0])) return u2(null, e, i2);
|
|
373
|
+
if ("object" == typeof e[0]) return u2(r2 || Object.keys(e[0]), e, i2);
|
|
374
|
+
} else if ("object" == typeof e) return "string" == typeof e.data && (e.data = JSON.parse(e.data)), Array.isArray(e.data) && (e.fields || (e.fields = e.meta && e.meta.fields || r2), e.fields || (e.fields = Array.isArray(e.data[0]) ? e.fields : "object" == typeof e.data[0] ? Object.keys(e.data[0]) : []), Array.isArray(e.data[0]) || "object" == typeof e.data[0] || (e.data = [e.data])), u2(e.fields || [], e.data || [], i2);
|
|
375
|
+
throw new Error("Unable to serialize unrecognized input");
|
|
376
|
+
function u2(e2, t2, i3) {
|
|
377
|
+
var r3 = "", n3 = ("string" == typeof e2 && (e2 = JSON.parse(e2)), "string" == typeof t2 && (t2 = JSON.parse(t2)), Array.isArray(e2) && 0 < e2.length), s3 = !Array.isArray(t2[0]);
|
|
378
|
+
if (n3 && _2) {
|
|
379
|
+
for (var a3 = 0; a3 < e2.length; a3++) 0 < a3 && (r3 += m2), r3 += k(e2[a3], a3);
|
|
380
|
+
0 < t2.length && (r3 += y2);
|
|
381
|
+
}
|
|
382
|
+
for (var o3 = 0; o3 < t2.length; o3++) {
|
|
383
|
+
var h3 = (n3 ? e2 : t2[o3]).length, u3 = false, d2 = n3 ? 0 === Object.keys(t2[o3]).length : 0 === t2[o3].length;
|
|
384
|
+
if (i3 && !n3 && (u3 = "greedy" === i3 ? "" === t2[o3].join("").trim() : 1 === t2[o3].length && 0 === t2[o3][0].length), "greedy" === i3 && n3) {
|
|
385
|
+
for (var f2 = [], l2 = 0; l2 < h3; l2++) {
|
|
386
|
+
var c2 = s3 ? e2[l2] : l2;
|
|
387
|
+
f2.push(t2[o3][c2]);
|
|
388
|
+
}
|
|
389
|
+
u3 = "" === f2.join("").trim();
|
|
390
|
+
}
|
|
391
|
+
if (!u3) {
|
|
392
|
+
for (var p2 = 0; p2 < h3; p2++) {
|
|
393
|
+
0 < p2 && !d2 && (r3 += m2);
|
|
394
|
+
var g2 = n3 && s3 ? e2[p2] : p2;
|
|
395
|
+
r3 += k(t2[o3][g2], p2);
|
|
396
|
+
}
|
|
397
|
+
o3 < t2.length - 1 && (!i3 || 0 < h3 && !d2) && (r3 += y2);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
return r3;
|
|
401
|
+
}
|
|
402
|
+
function k(e2, t2) {
|
|
403
|
+
var i3, r3;
|
|
404
|
+
return null == e2 ? "" : e2.constructor === Date ? JSON.stringify(e2).slice(1, 25) : (r3 = false, o2 && "string" == typeof e2 && o2.test(e2) && (e2 = "'" + e2, r3 = true), i3 = e2.toString().replace(h2, a2), (r3 = r3 || true === n2 || "function" == typeof n2 && n2(e2, t2) || Array.isArray(n2) && n2[t2] || ((e3, t3) => {
|
|
405
|
+
for (var i4 = 0; i4 < t3.length; i4++) if (-1 < e3.indexOf(t3[i4])) return true;
|
|
406
|
+
return false;
|
|
407
|
+
})(i3, v.BAD_DELIMITERS) || -1 < i3.indexOf(m2) || " " === i3.charAt(0) || " " === i3.charAt(i3.length - 1)) ? s2 + i3 + s2 : i3);
|
|
408
|
+
}
|
|
409
|
+
}, v.RECORD_SEP = String.fromCharCode(30), v.UNIT_SEP = String.fromCharCode(31), v.BYTE_ORDER_MARK = "\uFEFF", v.BAD_DELIMITERS = ["\r", "\n", '"', v.BYTE_ORDER_MARK], v.WORKERS_SUPPORTED = !s && !!n.Worker, v.NODE_STREAM_INPUT = 1, v.LocalChunkSize = 10485760, v.RemoteChunkSize = 5242880, v.DefaultDelimiter = ",", v.Parser = E, v.ParserHandle = i, v.NetworkStreamer = f, v.FileStreamer = l, v.StringStreamer = c, v.ReadableStreamStreamer = p, n.jQuery && ((d = n.jQuery).fn.parse = function(o2) {
|
|
410
|
+
var i2 = o2.config || {}, h2 = [];
|
|
411
|
+
return this.each(function(e2) {
|
|
412
|
+
if (!("INPUT" === d(this).prop("tagName").toUpperCase() && "file" === d(this).attr("type").toLowerCase() && n.FileReader) || !this.files || 0 === this.files.length) return true;
|
|
413
|
+
for (var t = 0; t < this.files.length; t++) h2.push({ file: this.files[t], inputElem: this, instanceConfig: d.extend({}, i2) });
|
|
414
|
+
}), e(), this;
|
|
415
|
+
function e() {
|
|
416
|
+
if (0 === h2.length) U(o2.complete) && o2.complete();
|
|
417
|
+
else {
|
|
418
|
+
var e2, t, i3, r2, n2 = h2[0];
|
|
419
|
+
if (U(o2.before)) {
|
|
420
|
+
var s2 = o2.before(n2.file, n2.inputElem);
|
|
421
|
+
if ("object" == typeof s2) {
|
|
422
|
+
if ("abort" === s2.action) return e2 = "AbortError", t = n2.file, i3 = n2.inputElem, r2 = s2.reason, void (U(o2.error) && o2.error({ name: e2 }, t, i3, r2));
|
|
423
|
+
if ("skip" === s2.action) return void u2();
|
|
424
|
+
"object" == typeof s2.config && (n2.instanceConfig = d.extend(n2.instanceConfig, s2.config));
|
|
425
|
+
} else if ("skip" === s2) return void u2();
|
|
426
|
+
}
|
|
427
|
+
var a2 = n2.instanceConfig.complete;
|
|
428
|
+
n2.instanceConfig.complete = function(e3) {
|
|
429
|
+
U(a2) && a2(e3, n2.file, n2.inputElem), u2();
|
|
430
|
+
}, v.parse(n2.file, n2.instanceConfig);
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
function u2() {
|
|
434
|
+
h2.splice(0, 1), e();
|
|
435
|
+
}
|
|
436
|
+
}), a && (n.onmessage = function(e) {
|
|
437
|
+
e = e.data;
|
|
438
|
+
void 0 === v.WORKER_ID && e && (v.WORKER_ID = e.workerId);
|
|
439
|
+
"string" == typeof e.input ? n.postMessage({ workerId: v.WORKER_ID, results: v.parse(e.input, e.config), finished: true }) : (n.File && e.input instanceof File || e.input instanceof Object) && (e = v.parse(e.input, e.config)) && n.postMessage({ workerId: v.WORKER_ID, results: e, finished: true });
|
|
440
|
+
}), (f.prototype = Object.create(u.prototype)).constructor = f, (l.prototype = Object.create(u.prototype)).constructor = l, (c.prototype = Object.create(c.prototype)).constructor = c, (p.prototype = Object.create(u.prototype)).constructor = p, v;
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
});
|
|
444
|
+
|
|
445
|
+
// ../hem-target-runtime/src/hem/pythonFhsArguments.ts
|
|
446
|
+
function pythonFhsArguments(inputPath, modes, weatherPath) {
|
|
447
|
+
const cliModes = {
|
|
448
|
+
actual: "actual",
|
|
449
|
+
"actual-fee": "actual-FEE",
|
|
450
|
+
notional: "notional",
|
|
451
|
+
"notional-fee": "notional-FEE"
|
|
452
|
+
};
|
|
453
|
+
return [inputPath, ...weatherPath ? ["--epw-file", weatherPath] : [], ...modes.flatMap((mode) => {
|
|
454
|
+
if (!Object.prototype.hasOwnProperty.call(cliModes, mode)) throw new Error(`Unsupported Python FHS mode ${mode}`);
|
|
455
|
+
return ["--mode", cliModes[mode]];
|
|
456
|
+
})];
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
// ../hem-target-runtime/src/hem/pythonFhsCompliance.ts
|
|
460
|
+
var import_papaparse = __toESM(require_papaparse_min(), 1);
|
|
461
|
+
function buildPythonFhsComplianceReport(files, modes) {
|
|
462
|
+
if (!["actual", "actual-fee", "notional", "notional-fee"].every((mode) => modes.includes(mode))) return void 0;
|
|
463
|
+
const rows = (path) => {
|
|
464
|
+
if (!Object.prototype.hasOwnProperty.call(files, path)) throw new Error(`Python compliance summary is missing ${path}`);
|
|
465
|
+
const parsed = import_papaparse.default.parse(files[path], { delimiter: ",", skipEmptyLines: "greedy" });
|
|
466
|
+
if (parsed.errors.length) throw new Error(`Invalid Python compliance CSV ${path}: ${parsed.errors[0].message}`);
|
|
467
|
+
return parsed.data;
|
|
468
|
+
};
|
|
469
|
+
const rate = (records, name, unit, path) => {
|
|
470
|
+
const matching = records.filter((row) => row[0] === name);
|
|
471
|
+
if (matching.length !== 1 || matching[0].length !== 3 || matching[0][1] !== unit) throw new Error(`Python compliance summary requires one ${name} row in ${unit} from ${path}`);
|
|
472
|
+
const text = matching[0][2].trim();
|
|
473
|
+
const value = Number(text);
|
|
474
|
+
if (!/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?$/.test(text) || !Number.isFinite(value)) throw new Error(`Invalid ${name} rate in Python compliance output ${path}`);
|
|
475
|
+
return value;
|
|
476
|
+
};
|
|
477
|
+
const actualPath = "model__FHS__postproc_summary.csv";
|
|
478
|
+
const notionalPath = "model__FHS_notional__postproc_summary.csv";
|
|
479
|
+
const feePath = "model__FHS_FEE__postproc.csv";
|
|
480
|
+
const notionalFeePath = "model__FHS_FEE_notional__postproc.csv";
|
|
481
|
+
const actual = rows(actualPath);
|
|
482
|
+
const notional = rows(notionalPath);
|
|
483
|
+
const dwelling_emission_rate = rate(actual, "DER", "kgCO2/m2", actualPath);
|
|
484
|
+
const target_emission_rate = rate(notional, "TER", "kgCO2/m2", notionalPath);
|
|
485
|
+
const dwelling_primary_energy_rate = rate(actual, "DPER", "kWh/m2", actualPath);
|
|
486
|
+
const target_primary_energy_rate = rate(notional, "TPER", "kWh/m2", notionalPath);
|
|
487
|
+
const dwelling_fabric_energy_efficiency = rate(rows(feePath), "Fabric Energy Efficiency", "kWh / m2.yr", feePath);
|
|
488
|
+
const target_fabric_energy_efficiency = rate(rows(notionalFeePath), "Fabric Energy Efficiency", "kWh / m2.yr", notionalFeePath);
|
|
489
|
+
return {
|
|
490
|
+
dwelling_emission_rate,
|
|
491
|
+
target_emission_rate,
|
|
492
|
+
emission_rate_compliant: dwelling_emission_rate <= target_emission_rate,
|
|
493
|
+
dwelling_primary_energy_rate,
|
|
494
|
+
target_primary_energy_rate,
|
|
495
|
+
primary_energy_rate_compliant: dwelling_primary_energy_rate <= target_primary_energy_rate,
|
|
496
|
+
dwelling_fabric_energy_efficiency,
|
|
497
|
+
target_fabric_energy_efficiency,
|
|
498
|
+
fabric_energy_efficiency_compliant: dwelling_fabric_energy_efficiency <= target_fabric_energy_efficiency
|
|
499
|
+
};
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
// ../hem-target-runtime/src/hem/targets.ts
|
|
503
|
+
var WRAPPERS = {
|
|
504
|
+
fhs: {
|
|
505
|
+
profile: "fhs",
|
|
506
|
+
modes: ["actual", "actual-fee", "notional", "notional-fee"],
|
|
507
|
+
scenarioModes: {
|
|
508
|
+
fhs_assumptions: ["actual"],
|
|
509
|
+
fhs_compliance: ["actual", "actual-fee", "notional", "notional-fee"]
|
|
510
|
+
},
|
|
511
|
+
pythonModule: "bin.fhs",
|
|
512
|
+
coreDistribution: "hem-core",
|
|
513
|
+
wrapperDistribution: "hem-fhs-wrapper"
|
|
514
|
+
}
|
|
515
|
+
};
|
|
516
|
+
function targetWrapper(target) {
|
|
517
|
+
const wrapper = WRAPPERS[target.wrapper];
|
|
518
|
+
if (!wrapper) throw new Error(`Unsupported HEM wrapper: ${target.wrapper}`);
|
|
519
|
+
return wrapper;
|
|
520
|
+
}
|
|
521
|
+
var HEM_TARGETS = [
|
|
522
|
+
{
|
|
523
|
+
id: "rust-fhs-a7-62d3df70-c5ba2673-v1",
|
|
524
|
+
label: "Rust HEM:FHS 1.0.0a7",
|
|
525
|
+
runtime: "rust",
|
|
526
|
+
version: "1.0.0a7",
|
|
527
|
+
engineVersion: "1.0.0a7",
|
|
528
|
+
wrapperVersion: "1.0.0a7",
|
|
529
|
+
wrapper: "fhs",
|
|
530
|
+
engineCommit: "62d3df705690f33b3fc3e905c9971d4f3743bf2e",
|
|
531
|
+
wrapperCommit: "c5ba2673fbd886cfe4fb528f61b376bdf406ebbd",
|
|
532
|
+
conversionProfile: "current_rust_fhs"
|
|
533
|
+
},
|
|
534
|
+
{
|
|
535
|
+
id: "python-fhs-a9-918addad-b9b90138-v1",
|
|
536
|
+
label: "Python HEM:FHS 1.0.0a9",
|
|
537
|
+
runtime: "python",
|
|
538
|
+
version: "1.0.0a9",
|
|
539
|
+
engineVersion: "1.0.0a9",
|
|
540
|
+
wrapperVersion: "1.0.0a9",
|
|
541
|
+
wrapper: "fhs",
|
|
542
|
+
engineCommit: "918addad2f9ffbcd9c7a4ed73497d047210be2d2",
|
|
543
|
+
wrapperCommit: "b9b901382feb0e5d27f969532842250147fb4068",
|
|
544
|
+
conversionProfile: "python_fhs_a9"
|
|
545
|
+
},
|
|
546
|
+
{
|
|
547
|
+
id: "python-fhs-a8-f2ab6cf7-8ca182b0-v1",
|
|
548
|
+
label: "Python HEM:FHS 1.0.0a8",
|
|
549
|
+
runtime: "python",
|
|
550
|
+
version: "1.0.0a8",
|
|
551
|
+
engineVersion: "1.0.0a8",
|
|
552
|
+
wrapperVersion: "1.0.0a8",
|
|
553
|
+
wrapper: "fhs",
|
|
554
|
+
engineCommit: "f2ab6cf78860c36d260cb21396b747cc372f2c9d",
|
|
555
|
+
wrapperCommit: "8ca182b0171a3a928059a9c0ec0145ecefe3f4e9",
|
|
556
|
+
conversionProfile: "python_fhs_a8"
|
|
557
|
+
}
|
|
558
|
+
];
|
|
559
|
+
var RECOMMENDED_HEM_TARGET = HEM_TARGETS[0].id;
|
|
560
|
+
function resolveHemTarget(id) {
|
|
561
|
+
const target = HEM_TARGETS.find((target2) => target2.id === id);
|
|
562
|
+
if (!target) throw new Error(`HEM target '${id}' is unavailable. Select a supported target explicitly; saved runs are never upgraded automatically.`);
|
|
563
|
+
return target;
|
|
564
|
+
}
|
|
565
|
+
function modelArtifacts(manifest2) {
|
|
566
|
+
return manifest2.artifacts.filter((artifact) => !artifact.path.startsWith("source/") && !artifact.path.startsWith("notices/"));
|
|
567
|
+
}
|
|
568
|
+
function validateTargetManifest(manifest2, target) {
|
|
569
|
+
if (manifest2.bundleId !== target.id || manifest2.protocol !== 1 || manifest2.engineCommit !== target.engineCommit || manifest2.wrapperCommit !== target.wrapperCommit || manifest2.conversionProfile !== target.conversionProfile) {
|
|
570
|
+
throw new Error(`Target manifest identity mismatch for ${target.id}`);
|
|
571
|
+
}
|
|
572
|
+
const paths = /* @__PURE__ */ new Set();
|
|
573
|
+
const sizesByHash = /* @__PURE__ */ new Map();
|
|
574
|
+
const isRelativePath = (path) => typeof path === "string" && /^[a-zA-Z0-9_./+-]+$/.test(path) && path.split("/").every((segment) => segment !== "" && segment !== "." && segment !== "..");
|
|
575
|
+
for (const artifact of manifest2.artifacts) {
|
|
576
|
+
if (!isRelativePath(artifact.path) || !/^[a-f0-9]{64}$/.test(artifact.sha256) || !Number.isSafeInteger(artifact.bytes) || artifact.bytes <= 0 || paths.has(artifact.path)) {
|
|
577
|
+
throw new Error(`Invalid artifact in ${target.id}: ${artifact.path}`);
|
|
578
|
+
}
|
|
579
|
+
const priorSize = sizesByHash.get(artifact.sha256);
|
|
580
|
+
if (priorSize !== void 0 && priorSize !== artifact.bytes) throw new Error(`Conflicting sizes for pinned artifact hash ${artifact.sha256}`);
|
|
581
|
+
sizesByHash.set(artifact.sha256, artifact.bytes);
|
|
582
|
+
paths.add(artifact.path);
|
|
583
|
+
}
|
|
584
|
+
for (const path of [...Object.values(manifest2.preparation), manifest2.runtime.javascript, ...manifest2.runtime.wasm ? [manifest2.runtime.wasm] : [], ...manifest2.runtime.wheels ?? []]) {
|
|
585
|
+
if (path.startsWith("source/") || path.startsWith("notices/")) throw new Error(`Runtime/preparation cannot reference reserved source/notice material: ${path}`);
|
|
586
|
+
if (!paths.has(path)) throw new Error(`Target manifest is missing required artifact ${path}`);
|
|
587
|
+
}
|
|
588
|
+
if (!manifest2.modes.length || new Set(manifest2.modes).size !== manifest2.modes.length || manifest2.modes.some((mode) => !targetWrapper(target).modes.includes(mode))) throw new Error("Unsupported or duplicate FHS calculation modes");
|
|
589
|
+
if (target.runtime === "rust") {
|
|
590
|
+
if (!manifest2.runtime.wasm) throw new Error("Rust target manifest is missing its runtime WASM artifact");
|
|
591
|
+
if (manifest2.modes.some((mode) => mode !== "actual") && manifest2.modes.length !== targetWrapper(target).modes.length) throw new Error("Rust target modes require actual alone or the complete compliance set");
|
|
592
|
+
} else {
|
|
593
|
+
const { index, wheels, requiredVersions } = manifest2.runtime;
|
|
594
|
+
if (index?.startsWith("source/") || index?.startsWith("notices/")) throw new Error("Python runtime cannot use the reserved source/notice directory");
|
|
595
|
+
if (!index?.endsWith("/") || !isRelativePath(index.slice(0, -1))) throw new Error("Python runtime index must be a relative directory ending in /");
|
|
596
|
+
if (!wheels?.length || new Set(wheels).size !== wheels.length) throw new Error("Python runtime requires its exact wheel artifacts");
|
|
597
|
+
for (const file of ["pyodide.asm.js", "pyodide.asm.wasm", "pyodide-lock.json", "python_stdlib.zip"]) {
|
|
598
|
+
if (!paths.has(`${index}${file}`)) throw new Error(`Python runtime is missing pinned artifact ${index}${file}`);
|
|
599
|
+
}
|
|
600
|
+
if (requiredVersions?.[targetWrapper(target).coreDistribution] !== target.engineVersion || requiredVersions?.[targetWrapper(target).wrapperDistribution] !== target.wrapperVersion) {
|
|
601
|
+
throw new Error(`Python runtime must pin matching engine ${target.engineVersion} and wrapper ${target.wrapperVersion} distributions`);
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
// ../hem-target-runtime/src/hem/targetAssets.ts
|
|
607
|
+
var CACHE = "vulcan-hem-artifacts-v1";
|
|
608
|
+
async function sha256(bytes) {
|
|
609
|
+
return Array.from(new Uint8Array(await crypto.subtle.digest("SHA-256", bytes)), (b) => b.toString(16).padStart(2, "0")).join("");
|
|
610
|
+
}
|
|
611
|
+
var keyFor = (artifact) => new URL(`/__hem_content/${artifact.sha256}`, globalThis.location.origin).href;
|
|
612
|
+
async function verified(response, artifact, preserveBody = true) {
|
|
613
|
+
const bytes = new Uint8Array(await (preserveBody ? response.clone() : response).arrayBuffer());
|
|
614
|
+
return bytes.byteLength === artifact.bytes && await sha256(bytes) === artifact.sha256;
|
|
615
|
+
}
|
|
616
|
+
var TargetAssets = class _TargetAssets {
|
|
617
|
+
constructor(cache, fetcher = (...args) => globalThis.fetch(...args)) {
|
|
618
|
+
this.cache = cache;
|
|
619
|
+
this.fetcher = fetcher;
|
|
620
|
+
}
|
|
621
|
+
static async open() {
|
|
622
|
+
return new _TargetAssets(await caches.open(CACHE));
|
|
623
|
+
}
|
|
624
|
+
async inspect(manifest2, signal) {
|
|
625
|
+
signal?.throwIfAborted();
|
|
626
|
+
const unique = [...new Map(modelArtifacts(manifest2).map((artifact) => [artifact.sha256, artifact])).values()];
|
|
627
|
+
const missing = [];
|
|
628
|
+
for (let offset = 0; offset < unique.length; offset += 4) {
|
|
629
|
+
signal?.throwIfAborted();
|
|
630
|
+
const results = await Promise.all(unique.slice(offset, offset + 4).map(async (artifact) => {
|
|
631
|
+
signal?.throwIfAborted();
|
|
632
|
+
const key = keyFor(artifact);
|
|
633
|
+
const response = await this.cache.match(key);
|
|
634
|
+
signal?.throwIfAborted();
|
|
635
|
+
const valid = response && await verified(response, artifact, false);
|
|
636
|
+
signal?.throwIfAborted();
|
|
637
|
+
if (valid) return void 0;
|
|
638
|
+
if (response) await this.cache.delete(key);
|
|
639
|
+
return artifact;
|
|
640
|
+
}));
|
|
641
|
+
missing.push(...results.filter((artifact) => artifact !== void 0));
|
|
642
|
+
}
|
|
643
|
+
signal?.throwIfAborted();
|
|
644
|
+
return { missing, missingBytes: missing.reduce((bytes, artifact) => bytes + artifact.bytes, 0) };
|
|
645
|
+
}
|
|
646
|
+
async download(manifest2, progress, signal) {
|
|
647
|
+
const { missing, missingBytes } = await this.inspect(manifest2, signal);
|
|
648
|
+
signal?.throwIfAborted();
|
|
649
|
+
let downloaded = 0;
|
|
650
|
+
let next = 0;
|
|
651
|
+
let failure;
|
|
652
|
+
const controller = new AbortController();
|
|
653
|
+
const abort = () => controller.abort(signal?.reason);
|
|
654
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
655
|
+
const activeSignal = controller.signal;
|
|
656
|
+
const acquire = async (artifact) => {
|
|
657
|
+
activeSignal.throwIfAborted();
|
|
658
|
+
const response = await this.fetcher(`/hem-targets/${manifest2.bundleId}/${artifact.path}`, { signal: activeSignal, cache: "no-store" });
|
|
659
|
+
activeSignal.throwIfAborted();
|
|
660
|
+
if (!response.ok) throw new Error(`Missing or corrupt HEM artifact: ${artifact.path}. Retry the download.`);
|
|
661
|
+
const bytes = new Uint8Array(artifact.bytes);
|
|
662
|
+
let received = 0;
|
|
663
|
+
const append = (chunk) => {
|
|
664
|
+
activeSignal.throwIfAborted();
|
|
665
|
+
if (received + chunk.byteLength > artifact.bytes) throw new Error(`Missing or corrupt HEM artifact size: ${artifact.path}. Retry the download.`);
|
|
666
|
+
bytes.set(chunk, received);
|
|
667
|
+
received += chunk.byteLength;
|
|
668
|
+
downloaded += chunk.byteLength;
|
|
669
|
+
progress(downloaded, missingBytes);
|
|
670
|
+
};
|
|
671
|
+
if (response.body) {
|
|
672
|
+
const reader = response.body.getReader();
|
|
673
|
+
const cancelReader = () => {
|
|
674
|
+
void reader.cancel(activeSignal.reason).catch(() => {
|
|
675
|
+
});
|
|
676
|
+
};
|
|
677
|
+
activeSignal.addEventListener("abort", cancelReader, { once: true });
|
|
678
|
+
try {
|
|
679
|
+
while (true) {
|
|
680
|
+
activeSignal.throwIfAborted();
|
|
681
|
+
const { done, value } = await reader.read();
|
|
682
|
+
activeSignal.throwIfAborted();
|
|
683
|
+
if (done) break;
|
|
684
|
+
append(value);
|
|
685
|
+
}
|
|
686
|
+
} catch (error) {
|
|
687
|
+
await reader.cancel(error).catch(() => {
|
|
688
|
+
});
|
|
689
|
+
throw error;
|
|
690
|
+
} finally {
|
|
691
|
+
activeSignal.removeEventListener("abort", cancelReader);
|
|
692
|
+
reader.releaseLock();
|
|
693
|
+
}
|
|
694
|
+
} else {
|
|
695
|
+
append(new Uint8Array(await response.arrayBuffer()));
|
|
696
|
+
}
|
|
697
|
+
if (received !== artifact.bytes || await sha256(bytes) !== artifact.sha256) throw new Error(`Missing or corrupt HEM artifact: ${artifact.path}. Retry the download.`);
|
|
698
|
+
activeSignal.throwIfAborted();
|
|
699
|
+
await this.cache.put(keyFor(artifact), new Response(bytes, { headers: response.headers }));
|
|
700
|
+
activeSignal.throwIfAborted();
|
|
701
|
+
};
|
|
702
|
+
const worker = async () => {
|
|
703
|
+
try {
|
|
704
|
+
while (next < missing.length) {
|
|
705
|
+
activeSignal.throwIfAborted();
|
|
706
|
+
const artifact = missing[next++];
|
|
707
|
+
await acquire(artifact);
|
|
708
|
+
}
|
|
709
|
+
} catch (error) {
|
|
710
|
+
failure ?? (failure = error);
|
|
711
|
+
controller.abort(error);
|
|
712
|
+
}
|
|
713
|
+
};
|
|
714
|
+
try {
|
|
715
|
+
signal?.throwIfAborted();
|
|
716
|
+
progress(0, missingBytes);
|
|
717
|
+
await Promise.all(Array.from({ length: Math.min(4, missing.length) }, worker));
|
|
718
|
+
if (failure !== void 0) throw failure;
|
|
719
|
+
activeSignal.throwIfAborted();
|
|
720
|
+
} finally {
|
|
721
|
+
signal?.removeEventListener("abort", abort);
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
/** Load only the editor schema; selecting a version must not fetch its runtime. */
|
|
725
|
+
async ensureBytes(bundleId, artifact) {
|
|
726
|
+
let response = await this.cache.match(keyFor(artifact));
|
|
727
|
+
if (!response || !await verified(response, artifact)) {
|
|
728
|
+
response = await this.fetcher(`/hem-targets/${bundleId}/${artifact.path}`, { cache: "no-store" });
|
|
729
|
+
if (!response.ok || !await verified(response, artifact)) {
|
|
730
|
+
throw new Error(`Missing or corrupt HEM artifact: ${artifact.path}. Retry the download.`);
|
|
731
|
+
}
|
|
732
|
+
await this.cache.put(keyFor(artifact), response.clone());
|
|
733
|
+
}
|
|
734
|
+
return new Uint8Array(await response.arrayBuffer());
|
|
735
|
+
}
|
|
736
|
+
async bytes(artifact) {
|
|
737
|
+
const response = await this.cache.match(keyFor(artifact));
|
|
738
|
+
if (!response || !await verified(response, artifact)) throw new Error(`Exact HEM artifact unavailable: ${artifact.path}. Download this target again.`);
|
|
739
|
+
return new Uint8Array(await response.arrayBuffer());
|
|
740
|
+
}
|
|
741
|
+
};
|
|
742
|
+
|
|
743
|
+
// ../hem-target-runtime/src/workers/workerProtocol.ts
|
|
744
|
+
var FS_REQUEST_TYPE = "file_system";
|
|
745
|
+
var FS_RESPONSE_TYPE = "file_system_response";
|
|
746
|
+
|
|
747
|
+
// ../hem-target-runtime/src/workers/batchWorkerFileSystemBridge.ts
|
|
748
|
+
var DEFAULT_ACKNOWLEDGEMENT_TIMEOUT_MS = 3e4;
|
|
749
|
+
var BatchWorkerFileSystemAcknowledgements = class {
|
|
750
|
+
constructor(timeoutMs = DEFAULT_ACKNOWLEDGEMENT_TIMEOUT_MS) {
|
|
751
|
+
this.timeoutMs = timeoutMs;
|
|
752
|
+
__publicField(this, "pending", /* @__PURE__ */ new Map());
|
|
753
|
+
if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) {
|
|
754
|
+
throw new Error("Batch worker filesystem acknowledgement timeout must be positive");
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
get pendingCount() {
|
|
758
|
+
return this.pending.size;
|
|
759
|
+
}
|
|
760
|
+
register(request) {
|
|
761
|
+
if (request.operation !== "write_file" && request.operation !== "delete_file") {
|
|
762
|
+
throw new Error(`Cannot acknowledge unsupported filesystem operation '${request.operation}'`);
|
|
763
|
+
}
|
|
764
|
+
if (this.pending.has(request.messageId)) {
|
|
765
|
+
throw new Error(`Duplicate filesystem acknowledgement id '${request.messageId}'`);
|
|
766
|
+
}
|
|
767
|
+
let resolve;
|
|
768
|
+
let reject;
|
|
769
|
+
const promise = new Promise((promiseResolve, promiseReject) => {
|
|
770
|
+
resolve = promiseResolve;
|
|
771
|
+
reject = promiseReject;
|
|
772
|
+
});
|
|
773
|
+
void promise.catch(() => void 0);
|
|
774
|
+
const entry = {
|
|
775
|
+
operation: request.operation,
|
|
776
|
+
path: request.path,
|
|
777
|
+
promise,
|
|
778
|
+
resolve,
|
|
779
|
+
reject,
|
|
780
|
+
settled: false
|
|
781
|
+
};
|
|
782
|
+
entry.timer = setTimeout(() => {
|
|
783
|
+
this.settleFailure(
|
|
784
|
+
request.messageId,
|
|
785
|
+
`Timed out after ${this.timeoutMs}ms waiting for ${request.operation} acknowledgement for '${request.path}'`
|
|
786
|
+
);
|
|
787
|
+
}, this.timeoutMs);
|
|
788
|
+
this.pending.set(request.messageId, entry);
|
|
789
|
+
}
|
|
790
|
+
acknowledge(messageId, error) {
|
|
791
|
+
const entry = this.pending.get(messageId);
|
|
792
|
+
if (!entry) return false;
|
|
793
|
+
if (error) {
|
|
794
|
+
this.settleFailure(
|
|
795
|
+
messageId,
|
|
796
|
+
`Physical ${entry.operation} failed for '${entry.path}': ${error}`
|
|
797
|
+
);
|
|
798
|
+
} else {
|
|
799
|
+
this.settleSuccess(entry);
|
|
800
|
+
}
|
|
801
|
+
return true;
|
|
802
|
+
}
|
|
803
|
+
async waitForPending() {
|
|
804
|
+
const failures = [];
|
|
805
|
+
while (this.pending.size > 0) {
|
|
806
|
+
const snapshot = Array.from(this.pending.entries());
|
|
807
|
+
const results = await Promise.allSettled(snapshot.map(([, entry]) => entry.promise));
|
|
808
|
+
results.forEach((result) => {
|
|
809
|
+
if (result.status === "rejected") {
|
|
810
|
+
failures.push(
|
|
811
|
+
result.reason instanceof Error ? result.reason : new Error(String(result.reason))
|
|
812
|
+
);
|
|
813
|
+
}
|
|
814
|
+
});
|
|
815
|
+
snapshot.forEach(([messageId, entry]) => {
|
|
816
|
+
if (this.pending.get(messageId) === entry) {
|
|
817
|
+
if (entry.timer) clearTimeout(entry.timer);
|
|
818
|
+
this.pending.delete(messageId);
|
|
819
|
+
}
|
|
820
|
+
});
|
|
821
|
+
}
|
|
822
|
+
if (failures.length === 1) throw failures[0];
|
|
823
|
+
if (failures.length > 1) {
|
|
824
|
+
throw new Error(
|
|
825
|
+
`Multiple batch worker filesystem operations failed: ${failures.map((failure) => failure.message).join("; ")}`
|
|
826
|
+
);
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
settleSuccess(entry) {
|
|
830
|
+
if (entry.settled) return;
|
|
831
|
+
entry.settled = true;
|
|
832
|
+
if (entry.timer) clearTimeout(entry.timer);
|
|
833
|
+
entry.resolve();
|
|
834
|
+
}
|
|
835
|
+
settleFailure(messageId, message) {
|
|
836
|
+
const entry = this.pending.get(messageId);
|
|
837
|
+
if (!entry || entry.settled) return;
|
|
838
|
+
entry.settled = true;
|
|
839
|
+
if (entry.timer) clearTimeout(entry.timer);
|
|
840
|
+
entry.reject(new Error(message));
|
|
841
|
+
}
|
|
842
|
+
};
|
|
843
|
+
|
|
844
|
+
// ../hem-target-runtime/src/hem/preparedRun.ts
|
|
845
|
+
async function executePreparedJobs(manifest2, bundleId, jobId, jobs, execute, write2, progress) {
|
|
846
|
+
if (manifest2.bundleId !== bundleId) throw new Error("Worker target identity mismatch");
|
|
847
|
+
if (!jobs.length) throw new Error("Batch has no prepared jobs");
|
|
848
|
+
const allowedModes = new Set(manifest2.modes);
|
|
849
|
+
const reservedNames = /* @__PURE__ */ new Set(["model.json", "source.csv", "weather.epw", "target-run.json"]);
|
|
850
|
+
for (const [index, job] of jobs.entries()) {
|
|
851
|
+
if (!/^[a-zA-Z0-9_./ -]+$/.test(job.outputDirectory) || job.outputDirectory.split("/").some((segment) => segment === "..") || !job.outputDirectory.startsWith("output/")) throw new Error("Invalid run output path");
|
|
852
|
+
if (!job.modes.length || job.modes.some((mode) => !allowedModes.has(mode))) throw new Error("Unsupported calculation mode for selected target");
|
|
853
|
+
if (job.archiveDirectory && (!job.archiveDirectory.startsWith(`${job.outputDirectory}/`) || job.archiveDirectory.split("/").some((segment) => segment === ".."))) throw new Error("Invalid archive path");
|
|
854
|
+
const archive = job.archiveDirectory ?? job.outputDirectory;
|
|
855
|
+
const inputSha256 = await sha256(new TextEncoder().encode(job.input));
|
|
856
|
+
if (job.weather && (!job.weather.epw.trim() || await sha256(new TextEncoder().encode(job.weather.epw)) !== job.weather.sha256)) throw new Error("Prepared weather hash mismatch or empty EPW");
|
|
857
|
+
const provenance = { ...job.weather ? { weather: { path: job.weather.path, sha256: job.weather.sha256 } } : {}, target: manifest2, inputSha256, modes: job.modes, jobId, name: job.name, ...job.warnings?.length ? { warnings: job.warnings } : {} };
|
|
858
|
+
try {
|
|
859
|
+
await write2(`${archive}/target-run.json`, JSON.stringify({ ...provenance, status: "running" }));
|
|
860
|
+
if (archive !== job.outputDirectory) await write2(`${job.outputDirectory}/target-run.json`, JSON.stringify({ ...provenance, status: "running", archive }));
|
|
861
|
+
await write2(`${archive}/model.json`, job.input);
|
|
862
|
+
if (job.sourceCsv) await write2(`${archive}/source.csv`, job.sourceCsv);
|
|
863
|
+
if (job.weather) await write2(`${archive}/weather.epw`, job.weather.epw);
|
|
864
|
+
progress(index, jobs.length);
|
|
865
|
+
const files = await execute(job.input, job.modes, job.weather);
|
|
866
|
+
const names = Object.keys(files);
|
|
867
|
+
if (!names.length) throw new Error("Calculation produced no result files");
|
|
868
|
+
for (const [name, content] of Object.entries(files)) {
|
|
869
|
+
if (reservedNames.has(name) || !name || name === "." || name === ".." || /[\\/]/.test(name)) throw new Error("Unexpected result path");
|
|
870
|
+
await write2(`${archive}/${name}`, content);
|
|
871
|
+
}
|
|
872
|
+
if (archive !== job.outputDirectory) {
|
|
873
|
+
for (const [name, content] of Object.entries(files)) await write2(`${job.outputDirectory}/${name}`, content);
|
|
874
|
+
await write2(`${job.outputDirectory}/target-run.json`, JSON.stringify({ ...provenance, status: "complete", files: names, archive }));
|
|
875
|
+
}
|
|
876
|
+
await write2(`${archive}/target-run.json`, JSON.stringify({ ...provenance, status: "complete", files: names }));
|
|
877
|
+
} catch (error) {
|
|
878
|
+
await write2(`${archive}/target-run.json`, JSON.stringify({ ...provenance, status: "failed", error: String(error) }));
|
|
879
|
+
if (archive !== job.outputDirectory) await write2(`${job.outputDirectory}/target-run.json`, JSON.stringify({ ...provenance, status: "failed", error: String(error), archive }));
|
|
880
|
+
throw error;
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
// ../hem-target-runtime/src/hem/pythonFhsWorker.ts
|
|
886
|
+
var runtime;
|
|
887
|
+
var manifest;
|
|
888
|
+
var busy = false;
|
|
889
|
+
var acknowledgements = new BatchWorkerFileSystemAcknowledgements();
|
|
890
|
+
var send = (message) => self.postMessage(message);
|
|
891
|
+
async function write(path, content) {
|
|
892
|
+
const request = { type: FS_REQUEST_TYPE, operation: "write_file", path, content, messageId: crypto.randomUUID() };
|
|
893
|
+
acknowledgements.register(request);
|
|
894
|
+
send(request);
|
|
895
|
+
await acknowledgements.waitForPending();
|
|
896
|
+
}
|
|
897
|
+
async function initialize(bundle) {
|
|
898
|
+
const target = resolveHemTarget(bundle.bundleId);
|
|
899
|
+
validateTargetManifest(bundle, target);
|
|
900
|
+
if (target.runtime !== "python" || target.wrapper !== "fhs") throw new Error("Python worker requires a Python FHS target");
|
|
901
|
+
const assets = await TargetAssets.open();
|
|
902
|
+
const responses = /* @__PURE__ */ new Map();
|
|
903
|
+
await Promise.all(modelArtifacts(bundle).map(async (artifact) => {
|
|
904
|
+
const bytes = await assets.bytes(artifact);
|
|
905
|
+
const url = new URL(`/hem-targets/${bundle.bundleId}/${artifact.path}`, self.location.origin).href;
|
|
906
|
+
responses.set(url, new Response(bytes, { headers: { "Content-Type": artifact.path.endsWith(".wasm") ? "application/wasm" : "application/octet-stream" } }));
|
|
907
|
+
}));
|
|
908
|
+
self.fetch = async (input) => {
|
|
909
|
+
const url = new URL(typeof input === "string" ? input : input instanceof URL ? input.href : input.url, self.location.origin).href;
|
|
910
|
+
const response = responses.get(url);
|
|
911
|
+
if (!response) throw new Error(`Python attempted to load an artifact outside its pinned bundle: ${url}`);
|
|
912
|
+
return response.clone();
|
|
913
|
+
};
|
|
914
|
+
const importAsset = async (path) => {
|
|
915
|
+
const response = responses.get(new URL(`/hem-targets/${bundle.bundleId}/${path}`, self.location.origin).href);
|
|
916
|
+
if (!response) throw new Error(`Missing executable artifact ${path}`);
|
|
917
|
+
const url = URL.createObjectURL(new Blob([await response.arrayBuffer()], { type: "text/javascript" }));
|
|
918
|
+
try {
|
|
919
|
+
return await import(
|
|
920
|
+
/* @vite-ignore */
|
|
921
|
+
url
|
|
922
|
+
);
|
|
923
|
+
} finally {
|
|
924
|
+
URL.revokeObjectURL(url);
|
|
925
|
+
}
|
|
926
|
+
};
|
|
927
|
+
const index = bundle.runtime.index;
|
|
928
|
+
if (!index || !bundle.runtime.wheels?.length || !bundle.runtime.requiredVersions) throw new Error("Incomplete Python runtime manifest");
|
|
929
|
+
await importAsset(`${index}pyodide.asm.js`);
|
|
930
|
+
const { loadPyodide } = await importAsset(bundle.runtime.javascript);
|
|
931
|
+
runtime = await loadPyodide({
|
|
932
|
+
indexURL: new URL(`/hem-targets/${bundle.bundleId}/${index}`, self.location.origin).href,
|
|
933
|
+
stdout: (message) => send({ type: "worker_log", message }),
|
|
934
|
+
stderr: (message) => send({ type: "worker_log", message })
|
|
935
|
+
});
|
|
936
|
+
const py = runtime;
|
|
937
|
+
await py.loadPackage("micropip");
|
|
938
|
+
const install = (paths) => py.runPythonAsync(`import micropip
|
|
939
|
+
await micropip.install(${JSON.stringify(paths.map((path) => new URL(`/hem-targets/${bundle.bundleId}/${path}`, self.location.origin).href))}, index_urls=[])`);
|
|
940
|
+
await install(bundle.runtime.wheels.filter((path) => path.split("/").pop().startsWith("numpy-")));
|
|
941
|
+
await py.loadPackage(bundle.runtime.packages ?? []);
|
|
942
|
+
await install(bundle.runtime.wheels.filter((path) => !path.split("/").pop().startsWith("numpy-")));
|
|
943
|
+
py.runPython(`import os
|
|
944
|
+
os.environ['MPLBACKEND']='Agg'
|
|
945
|
+
from ${targetWrapper(target).pythonModule} import main`);
|
|
946
|
+
const versions = JSON.parse(py.runPython("import importlib.metadata as m,json\njson.dumps({d.metadata['Name'].lower().replace('_','-'):d.version for d in m.distributions()})"));
|
|
947
|
+
for (const [name, version] of Object.entries(bundle.runtime.requiredVersions)) {
|
|
948
|
+
if (versions[name.toLowerCase().replace(/_/g, "-")] !== version) throw new Error(`Python runtime identity mismatch for ${name}`);
|
|
949
|
+
}
|
|
950
|
+
manifest = bundle;
|
|
951
|
+
send({ type: "worker_ready", targetBundleId: bundle.bundleId });
|
|
952
|
+
}
|
|
953
|
+
async function run(jobId, bundleId, jobs) {
|
|
954
|
+
if (!runtime || !manifest) throw new Error("Python worker is not initialized");
|
|
955
|
+
await executePreparedJobs(manifest, bundleId, jobId, jobs, async (input, modes, weather) => {
|
|
956
|
+
const py = runtime;
|
|
957
|
+
const folder = `/runs/${crypto.randomUUID()}`;
|
|
958
|
+
py.FS.mkdirTree(folder);
|
|
959
|
+
py.FS.writeFile(`${folder}/model.json`, input);
|
|
960
|
+
try {
|
|
961
|
+
if (weather) py.FS.writeFile(`${folder}/weather.epw`, weather.epw);
|
|
962
|
+
const args = pythonFhsArguments(`${folder}/model.json`, modes, weather ? `${folder}/weather.epw` : void 0);
|
|
963
|
+
await py.runPythonAsync(`main(${JSON.stringify(args)}, standalone_mode=False)`);
|
|
964
|
+
const output = `${folder}/model__results`;
|
|
965
|
+
const files = Object.fromEntries(py.FS.readdir(output).flatMap((name) => name !== "." && name !== ".." ? [[name, py.FS.readFile(`${output}/${name}`, { encoding: "utf8" })]] : []));
|
|
966
|
+
const compliance = buildPythonFhsComplianceReport(files, modes);
|
|
967
|
+
if (compliance) files["fhs_compliance_report.json"] = JSON.stringify(compliance);
|
|
968
|
+
return files;
|
|
969
|
+
} finally {
|
|
970
|
+
await py.runPythonAsync(`import shutil
|
|
971
|
+
shutil.rmtree(${JSON.stringify(folder)})`);
|
|
972
|
+
}
|
|
973
|
+
}, write, (completed, total) => send({ type: "progress", jobId, progress: { completed, total, status: "Calculating" } }));
|
|
974
|
+
send({ type: "complete", jobId, targetBundleId: bundleId, result: { status: "success", targetBundleId: bundleId } });
|
|
975
|
+
}
|
|
976
|
+
self.onmessage = async ({ data }) => {
|
|
977
|
+
if (data.type === FS_RESPONSE_TYPE) {
|
|
978
|
+
acknowledgements.acknowledge(data.messageId, data.error ?? null);
|
|
979
|
+
return;
|
|
980
|
+
}
|
|
981
|
+
if (busy) {
|
|
982
|
+
send({ type: "error", jobId: data.jobId, error: "A calculation worker is already active" });
|
|
983
|
+
return;
|
|
984
|
+
}
|
|
985
|
+
busy = true;
|
|
986
|
+
try {
|
|
987
|
+
if (data.type === "initialize") await initialize(data.manifest);
|
|
988
|
+
else if (data.type === "run_prepared_batch") await run(data.jobId, data.targetBundleId, data.jobs);
|
|
989
|
+
else throw new Error(`Unsupported Python worker message ${data.type}`);
|
|
990
|
+
} catch (error) {
|
|
991
|
+
send({ type: data.type === "initialize" ? "init_error" : "error", jobId: data.jobId, error: String(error) });
|
|
992
|
+
} finally {
|
|
993
|
+
busy = false;
|
|
994
|
+
}
|
|
995
|
+
};
|
|
996
|
+
/*! Bundled license information:
|
|
997
|
+
|
|
998
|
+
papaparse/papaparse.min.js:
|
|
999
|
+
(* @license
|
|
1000
|
+
Papa Parse
|
|
1001
|
+
v5.5.3
|
|
1002
|
+
https://github.com/mholt/PapaParse
|
|
1003
|
+
License: MIT
|
|
1004
|
+
*)
|
|
1005
|
+
*/
|