@skedulo/memory-hub-mcp 0.2.38 → 0.2.39

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.
@@ -0,0 +1,393 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const worker_threads_1 = require("worker_threads");
7
+ const quickjs_emscripten_core_1 = require("quickjs-emscripten-core");
8
+ const quickjs_singlefile_cjs_release_sync_1 = __importDefault(require("@jitl/quickjs-singlefile-cjs-release-sync"));
9
+ const SCRIPT_FILE = 'eval.js';
10
+ const SCRIPT_FRAME = /[\s(]eval\.js:(\d+):/;
11
+ const PRELUDE_FILE = 'prelude.js';
12
+ const JOB_BATCH = 100;
13
+ const DROPPED_POST_MS = 100;
14
+ const TIME = { kind: 'limit', limit: 'time' };
15
+ const MEMORY = { kind: 'limit', limit: 'memory' };
16
+ const WASM_PAGE = 65_536;
17
+ // The module's memory import declares 256 pages; fewer fail to link.
18
+ const INITIAL_PAGES = 256;
19
+ // Static data and stack take the first 5.2 MB, before QuickJS's heap starts.
20
+ const MODULE_HEADROOM_BYTES = 8 * 1024 * 1024;
21
+ // The glue retries a refused heap growth with two smaller sizes before malloc fails.
22
+ const REFUSALS_PER_FAILED_GROWTH = 3;
23
+ // QuickJS refuses an allocation over its own limit before malloc, out of the grow latch's sight, so its limit sits at the glue's 2 GiB ceiling.
24
+ const QUICKJS_LIMIT_BYTES = 2 ** 31;
25
+ // V8's overflow of the worker's smaller stack unwinds QuickJS uncaught, so QuickJS's own, catchable check is only a backstop inside its 5 MiB stack.
26
+ const QUICKJS_STACK_BYTES = 4 * 1024 * 1024;
27
+ const LIMIT_BY_MESSAGE = new Map([
28
+ ['interrupted', 'time'],
29
+ ['out of memory', 'memory'],
30
+ ['stack overflow', 'stack'],
31
+ ]);
32
+ const PRELUDE = `(function (call, log, unknownMember, namesJson) {
33
+ const { parse, stringify } = JSON
34
+ const BaseError = Error
35
+ const toText = String
36
+ const create = Object.create
37
+ const read = (get) => {
38
+ try {
39
+ return get()
40
+ } catch (error) {
41
+ return undefined
42
+ }
43
+ }
44
+ const text = (value) => {
45
+ if (typeof value === 'string') return value
46
+ const json = read(() => stringify(value))
47
+ if (json !== undefined) return json
48
+ try {
49
+ return toText(value)
50
+ } catch (error) {
51
+ return '[unloggable]'
52
+ }
53
+ }
54
+ const typed = (get, type) => {
55
+ const value = read(get)
56
+ return typeof value === type ? value : undefined
57
+ }
58
+ const functions = create(null)
59
+ for (const name of parse(namesJson)) {
60
+ functions[name] = async (input) => {
61
+ const json = stringify(input)
62
+ return call(name, json, json === undefined ? 0 : json.length)
63
+ }
64
+ }
65
+ globalThis.hub = new Proxy(create(null), {
66
+ get(target, name) {
67
+ if (typeof name === 'symbol' || name === 'then') return undefined
68
+ if (name in functions) return functions[name]
69
+ throw new BaseError(unknownMember(name))
70
+ },
71
+ })
72
+ globalThis.console = {
73
+ log: (...values) => {
74
+ let line = ''
75
+ for (let i = 0; i < values.length; i++) line += (i === 0 ? '' : ' ') + text(values[i])
76
+ log(line, line.length)
77
+ },
78
+ }
79
+ const toJson = (value) => stringify(value) ?? 'null'
80
+ const describe = (error) => {
81
+ const description = create(null)
82
+ if (read(() => error instanceof BaseError)) {
83
+ description.name = text(read(() => error.name))
84
+ description.message = text(read(() => error.message))
85
+ description.fileName = typed(() => error.fileName, 'string')
86
+ description.lineNumber = typed(() => error.lineNumber, 'number')
87
+ description.stack = typed(() => error.stack, 'string')
88
+ } else {
89
+ description.text = text(error)
90
+ }
91
+ return stringify(description)
92
+ }
93
+ return [toJson, describe, parse]
94
+ })`;
95
+ function messageOf(error) {
96
+ return error instanceof Error ? error.message : String(error);
97
+ }
98
+ function errorText(description) {
99
+ if (description.text !== undefined)
100
+ return description.text;
101
+ const name = description.name ?? 'Error';
102
+ if (!description.message)
103
+ return name;
104
+ return name === 'Error' ? description.message : `${name}: ${description.message}`;
105
+ }
106
+ function wrapperLine(description) {
107
+ if (description.name === 'SyntaxError' && description.fileName === SCRIPT_FILE && description.lineNumber !== undefined) {
108
+ return description.lineNumber;
109
+ }
110
+ const frame = description.stack === undefined ? null : SCRIPT_FRAME.exec(description.stack);
111
+ return frame ? Number(frame[1]) : undefined;
112
+ }
113
+ function scriptResult(description, scriptLines) {
114
+ const limit = description.name === 'InternalError' ? LIMIT_BY_MESSAGE.get(description.message ?? '') : undefined;
115
+ if (limit)
116
+ return { kind: 'limit', limit };
117
+ const message = errorText(description);
118
+ const line = wrapperLine(description);
119
+ if (line === undefined)
120
+ return { kind: 'error', message };
121
+ return { kind: 'error', message, line: Math.min(Math.max(line - 1, 1), scriptLines) };
122
+ }
123
+ function cutLine(line, room) {
124
+ const last = line.charCodeAt(room - 1);
125
+ return line.slice(0, last >= 0xd800 && last <= 0xdbff ? room - 1 : room);
126
+ }
127
+ function isHostStackOverflow(error) {
128
+ return error instanceof RangeError && error.message.includes('call stack');
129
+ }
130
+ function hostFailure(error) {
131
+ if (isHostStackOverflow(error))
132
+ return { kind: 'limit', limit: 'stack' };
133
+ return { kind: 'error', message: `The sandbox failed: ${messageOf(error)}` };
134
+ }
135
+ function unconvertible(reason) {
136
+ return { kind: 'error', message: `The script's return value could not be turned into JSON (${reason}).` };
137
+ }
138
+ // QuickJS cannot see allocation sizes in this build (no malloc_usable_size), so the WASM memory itself is the limit.
139
+ async function loadCapped(memoryBytes, onExhausted) {
140
+ const maximum = Math.max(INITIAL_PAGES, Math.ceil((memoryBytes + MODULE_HEADROOM_BYTES) / WASM_PAGE));
141
+ const memory = new WebAssembly.Memory({ initial: INITIAL_PAGES, maximum });
142
+ const grow = memory.grow.bind(memory);
143
+ let refusals = 0;
144
+ memory.grow = (delta) => {
145
+ try {
146
+ const previous = grow(delta);
147
+ refusals = 0;
148
+ return previous;
149
+ }
150
+ catch (error) {
151
+ if (++refusals >= REFUSALS_PER_FAILED_GROWTH)
152
+ onExhausted();
153
+ throw error;
154
+ }
155
+ };
156
+ let loaded;
157
+ const hooks = {
158
+ postRun: [
159
+ (module) => {
160
+ loaded = module;
161
+ },
162
+ ],
163
+ };
164
+ const QuickJS = await (0, quickjs_emscripten_core_1.newQuickJSWASMModuleFromVariant)((0, quickjs_emscripten_core_1.newVariant)(quickjs_singlefile_cjs_release_sync_1.default, { wasmMemory: memory, emscriptenModule: hooks }));
165
+ if (!loaded || loaded.HEAPU8.buffer !== memory.buffer)
166
+ throw new Error('its WASM memory could not be capped.');
167
+ const malloc = loaded._malloc;
168
+ // The core library writes through whatever pointer malloc returns, even 0.
169
+ loaded._malloc = (size) => {
170
+ const pointer = malloc(size);
171
+ if (pointer === 0 && size > 0) {
172
+ onExhausted();
173
+ throw new Error('out of memory');
174
+ }
175
+ return pointer;
176
+ };
177
+ return QuickJS;
178
+ }
179
+ async function run(port, input) {
180
+ const { script, names, unknownMember, deadline, maxLogChars, maxPendingCallChars } = input;
181
+ const scriptLines = script.split('\n').length;
182
+ const pending = new Map();
183
+ const outbox = [];
184
+ let nextId = 0;
185
+ let settled = false;
186
+ let interrupted = false;
187
+ let outOfMemory = false;
188
+ let forwardedChars = 0;
189
+ let droppedChars = 0;
190
+ let postedDropped = 0;
191
+ let nextDroppedPost = 0;
192
+ let pendingCallChars = 0;
193
+ const post = (message) => {
194
+ if (!settled)
195
+ port.postMessage(message);
196
+ };
197
+ // QuickJS turns its interrupt and out-of-memory errors into catchable rejections, so once either fires it decides the outcome.
198
+ const finish = (result) => {
199
+ if (settled)
200
+ return;
201
+ settled = true;
202
+ const done = { type: 'done', result: interrupted ? TIME : outOfMemory ? MEMORY : result, droppedChars };
203
+ try {
204
+ port.postMessage(done);
205
+ }
206
+ catch (error) {
207
+ // Posting copies the value, and the worker's stack runs out on one nested a few thousand levels deep.
208
+ const unsent = { type: 'done', result: unconvertible(messageOf(error)), droppedChars };
209
+ port.postMessage(unsent);
210
+ }
211
+ };
212
+ const postDropped = () => {
213
+ if (droppedChars === postedDropped)
214
+ return;
215
+ postedDropped = droppedChars;
216
+ nextDroppedPost = Date.now() + DROPPED_POST_MS;
217
+ post({ type: 'dropped', chars: droppedChars });
218
+ };
219
+ // A synchronous loop never ends its step, so drops are also posted every DROPPED_POST_MS; the host may terminate the worker at any point.
220
+ const drop = (chars) => {
221
+ droppedChars += chars;
222
+ if (Date.now() >= nextDroppedPost)
223
+ postDropped();
224
+ };
225
+ // Every line is charged one extra character for its line break, so empty lines use up the cap too.
226
+ const forward = (line) => {
227
+ const room = maxLogChars - forwardedChars - 1;
228
+ if (line.length <= room) {
229
+ forwardedChars += line.length + 1;
230
+ post({ type: 'log', line });
231
+ return;
232
+ }
233
+ forwardedChars = maxLogChars;
234
+ const sent = room > 0 ? cutLine(line, room) : '';
235
+ if (sent)
236
+ post({ type: 'log', line: sent });
237
+ drop(sent ? line.length - sent.length : line.length + 1);
238
+ };
239
+ try {
240
+ const QuickJS = await loadCapped(input.memoryBytes, () => {
241
+ outOfMemory = true;
242
+ });
243
+ const runtime = QuickJS.newRuntime();
244
+ runtime.setMemoryLimit(QUICKJS_LIMIT_BYTES);
245
+ runtime.setMaxStackSize(QUICKJS_STACK_BYTES);
246
+ runtime.setInterruptHandler(() => {
247
+ if (outOfMemory)
248
+ return true;
249
+ if (Date.now() < deadline)
250
+ return false;
251
+ interrupted = true;
252
+ return true;
253
+ });
254
+ const vm = runtime.newContext();
255
+ const args = [
256
+ // Payloads waiting for an answer live outside QuickJS's memory limit, and V8 may keep them off its heap too.
257
+ vm.newFunction('call', (nameHandle, inputHandle, lengthHandle) => {
258
+ if (settled)
259
+ throw new Error('The run has ended.');
260
+ const chars = vm.getNumber(lengthHandle);
261
+ if (pendingCallChars + chars > maxPendingCallChars) {
262
+ finish(MEMORY);
263
+ throw new Error('Pending hub calls hold more data than the run allows.');
264
+ }
265
+ pendingCallChars += chars;
266
+ const id = nextId++;
267
+ const deferred = vm.newPromise();
268
+ pending.set(id, { deferred, chars });
269
+ const json = vm.typeof(inputHandle) === 'string' ? vm.getString(inputHandle) : undefined;
270
+ outbox.push({ type: 'call', id, name: vm.getString(nameHandle), json });
271
+ return deferred.handle;
272
+ }),
273
+ vm.newFunction('log', (line, length) => {
274
+ if (vm.typeof(line) !== 'string')
275
+ return;
276
+ if (forwardedChars >= maxLogChars)
277
+ drop(vm.getNumber(length) + 1);
278
+ else
279
+ forward(vm.getString(line));
280
+ }),
281
+ vm.newFunction('unknownMember', (name) => vm.newString(unknownMember.split('{name}').join(vm.getString(name)))),
282
+ vm.newString(JSON.stringify(names)),
283
+ ];
284
+ const prelude = vm.unwrapResult(vm.evalCode(PRELUDE, PRELUDE_FILE, { type: 'global' }));
285
+ const helpers = prelude.consume((fn) => vm.unwrapResult(vm.callFunction(fn, vm.undefined, args)));
286
+ const toJson = vm.getProp(helpers, 0);
287
+ const describe = vm.getProp(helpers, 1);
288
+ const parse = vm.getProp(helpers, 2);
289
+ helpers.dispose();
290
+ for (const handle of args)
291
+ handle.dispose();
292
+ const explain = (error) => {
293
+ const described = vm.callFunction(describe, vm.undefined, error);
294
+ if (described.error) {
295
+ described.error.dispose();
296
+ return { kind: 'limit', limit: Date.now() >= deadline ? 'time' : 'memory' };
297
+ }
298
+ return scriptResult(JSON.parse(described.value.consume(vm.getString)), scriptLines);
299
+ };
300
+ const convert = (value) => {
301
+ const converted = vm.callFunction(toJson, vm.undefined, value);
302
+ if (converted.error) {
303
+ const result = converted.error.consume(explain);
304
+ if (result.kind !== 'error')
305
+ return result;
306
+ return { ...result, ...unconvertible(result.message) };
307
+ }
308
+ return { kind: 'ok', value: JSON.parse(converted.value.consume(vm.getString)) };
309
+ };
310
+ // Parsed here rather than in the prelude, so a failure ends the run instead of reaching the script's catch.
311
+ const deliver = (id, deferred, json) => {
312
+ const text = vm.newString(json);
313
+ if (vm.typeof(text) !== 'string') {
314
+ outOfMemory = true;
315
+ return;
316
+ }
317
+ const parsed = text.consume((handle) => vm.callFunction(parse, vm.undefined, handle));
318
+ if (parsed.error) {
319
+ const result = outOfMemory ? MEMORY : parsed.error.consume(explain);
320
+ return finish(result.kind === 'limit' ? result : MEMORY);
321
+ }
322
+ parsed.value.consume(deferred.resolve);
323
+ post({ type: 'delivered', id });
324
+ };
325
+ const evaluated = vm.evalCode(`(async () => {\n${script}\n})()`, SCRIPT_FILE, { type: 'global' });
326
+ if (evaluated.error)
327
+ return finish(evaluated.error.consume(explain));
328
+ const promise = evaluated.value;
329
+ // Bounded batches return to this loop, so a chain of jobs that never empties still meets the deadline.
330
+ const step = () => {
331
+ if (settled)
332
+ return;
333
+ for (;;) {
334
+ if (outOfMemory)
335
+ return finish(MEMORY);
336
+ const jobs = runtime.executePendingJobs(JOB_BATCH);
337
+ if (jobs.error)
338
+ return finish(outOfMemory ? MEMORY : jobs.error.consume(explain));
339
+ if (Date.now() >= deadline)
340
+ return finish(TIME);
341
+ if (jobs.value < JOB_BATCH)
342
+ break;
343
+ }
344
+ if (outOfMemory)
345
+ return finish(MEMORY);
346
+ const state = vm.getPromiseState(promise);
347
+ if (state.type === 'pending') {
348
+ for (const message of outbox.splice(0))
349
+ post(message);
350
+ postDropped();
351
+ return;
352
+ }
353
+ if (state.type === 'rejected')
354
+ return finish(state.error.consume(explain));
355
+ try {
356
+ finish(state.notAPromise ? convert(state.value) : state.value.consume(convert));
357
+ }
358
+ catch (error) {
359
+ // JSON.stringify runs out of V8 stack on a value nested a few thousand levels deep.
360
+ finish(isHostStackOverflow(error) ? unconvertible(messageOf(error)) : hostFailure(error));
361
+ }
362
+ };
363
+ port.on('message', (answer) => {
364
+ const call = pending.get(answer.id);
365
+ if (settled || !call)
366
+ return;
367
+ pending.delete(answer.id);
368
+ pendingCallChars -= call.chars;
369
+ const { deferred } = call;
370
+ try {
371
+ if (answer.ok)
372
+ deliver(answer.id, deferred, answer.json);
373
+ else
374
+ vm.newError(answer.message).consume(deferred.reject);
375
+ if (outOfMemory)
376
+ finish(MEMORY);
377
+ if (settled)
378
+ return;
379
+ deferred.dispose();
380
+ step();
381
+ }
382
+ catch (error) {
383
+ finish(hostFailure(error));
384
+ }
385
+ });
386
+ step();
387
+ }
388
+ catch (error) {
389
+ finish(hostFailure(error));
390
+ }
391
+ }
392
+ if (worker_threads_1.parentPort)
393
+ void run(worker_threads_1.parentPort, worker_threads_1.workerData);
@@ -0,0 +1,139 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runSandboxed = void 0;
4
+ const fs_1 = require("fs");
5
+ const path_1 = require("path");
6
+ const worker_threads_1 = require("worker_threads");
7
+ // A worker with a smaller stack fails to start, and one far smaller takes the whole process down.
8
+ const MIN_WORKER_STACK_BYTES = 512 * 1024;
9
+ const WORKER_OLD_GENERATION_MB = 256;
10
+ const WORKER_YOUNG_GENERATION_MB = 32;
11
+ let sourceWorker;
12
+ function messageOf(error) {
13
+ return error instanceof Error ? error.message : String(error);
14
+ }
15
+ function memberText(template, name) {
16
+ return template.split('{name}').join(name);
17
+ }
18
+ // ts-jest runs this file from src/, where only sandbox-worker.ts exists; a build runs dist/sandbox-worker.js.
19
+ function transpiledWorker() {
20
+ if (!sourceWorker) {
21
+ const file = (0, path_1.join)(__dirname, 'sandbox-worker.ts');
22
+ const ts = require('typescript');
23
+ const { outputText } = ts.transpileModule((0, fs_1.readFileSync)(file, 'utf8'), {
24
+ compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2022, esModuleInterop: true },
25
+ });
26
+ const scope = `exports, require('module').createRequire(${JSON.stringify(file)}), module, ${JSON.stringify(file)}, ${JSON.stringify((0, path_1.dirname)(file))}`;
27
+ sourceWorker = `(function (exports, require, module, __filename, __dirname) {\n${outputText}\n})(${scope})`;
28
+ }
29
+ return sourceWorker;
30
+ }
31
+ function workerEntry() {
32
+ const compiled = (0, path_1.join)(__dirname, 'sandbox-worker.js');
33
+ return (0, fs_1.existsSync)(compiled) ? { source: compiled, eval: false } : { source: transpiledWorker(), eval: true };
34
+ }
35
+ function failure(error) {
36
+ return { kind: 'error', message: `The sandbox failed: ${messageOf(error)}` };
37
+ }
38
+ function unconvertible(error) {
39
+ return { kind: 'error', message: `The script's return value could not be turned into JSON (${messageOf(error)}).` };
40
+ }
41
+ function runSandboxed(request) {
42
+ const { script, functions, unknownMember, limits, onLog, onLogDropped, onDelivered } = request;
43
+ let worker;
44
+ try {
45
+ const entry = workerEntry();
46
+ const workerData = {
47
+ script,
48
+ names: Object.keys(functions),
49
+ unknownMember,
50
+ deadline: Date.now() + limits.deadlineMs,
51
+ memoryBytes: limits.memoryBytes,
52
+ maxLogChars: limits.maxLogChars,
53
+ maxPendingCallChars: limits.maxPendingCallChars,
54
+ };
55
+ const resourceLimits = {
56
+ stackSizeMb: Math.max(limits.maxStackBytes, MIN_WORKER_STACK_BYTES) / 2 ** 20,
57
+ maxOldGenerationSizeMb: WORKER_OLD_GENERATION_MB,
58
+ maxYoungGenerationSizeMb: WORKER_YOUNG_GENERATION_MB,
59
+ };
60
+ worker = new worker_threads_1.Worker(entry.source, { eval: entry.eval, workerData, resourceLimits });
61
+ }
62
+ catch (error) {
63
+ return Promise.resolve({ kind: 'error', message: `The sandbox could not start: ${messageOf(error)}` });
64
+ }
65
+ return new Promise((resolve) => {
66
+ const waiting = [];
67
+ let active = 0;
68
+ let settled = false;
69
+ let droppedChars = 0;
70
+ const finish = (result) => {
71
+ if (settled)
72
+ return;
73
+ settled = true;
74
+ clearTimeout(timer);
75
+ void worker.terminate();
76
+ if (droppedChars > 0 && onLogDropped) {
77
+ try {
78
+ onLogDropped(droppedChars);
79
+ }
80
+ catch (error) {
81
+ result = failure(error);
82
+ }
83
+ }
84
+ resolve(result);
85
+ };
86
+ const fail = (error) => finish(failure(error));
87
+ const timer = setTimeout(() => finish({ kind: 'limit', limit: 'time' }), limits.deadlineMs);
88
+ const callHost = async (id, name, json) => {
89
+ active++;
90
+ let answer;
91
+ try {
92
+ if (!Object.hasOwn(functions, name))
93
+ throw new Error(memberText(unknownMember, name));
94
+ const value = await functions[name](json === undefined ? undefined : JSON.parse(json), id);
95
+ answer = { type: 'answer', id, ok: true, json: JSON.stringify(value) ?? 'null' };
96
+ }
97
+ catch (error) {
98
+ answer = { type: 'answer', id, ok: false, message: messageOf(error) };
99
+ }
100
+ active--;
101
+ if (settled)
102
+ return;
103
+ worker.postMessage(answer);
104
+ waiting.shift()?.();
105
+ };
106
+ worker.on('message', (message) => {
107
+ if (settled)
108
+ return;
109
+ try {
110
+ if (message.type === 'log')
111
+ onLog(message.line);
112
+ else if (message.type === 'delivered')
113
+ onDelivered?.(message.id);
114
+ else if (message.type === 'dropped')
115
+ droppedChars = message.chars;
116
+ else if (message.type === 'done') {
117
+ droppedChars = message.droppedChars;
118
+ finish(message.result);
119
+ }
120
+ else {
121
+ const start = () => void callHost(message.id, message.name, message.json).catch(fail);
122
+ if (active < limits.maxInFlight)
123
+ start();
124
+ else
125
+ waiting.push(start);
126
+ }
127
+ }
128
+ catch (error) {
129
+ fail(error);
130
+ }
131
+ });
132
+ // Only the done message carries a script value; V8 runs out of stack deserializing one nested a few thousand levels deep.
133
+ worker.on('messageerror', (error) => finish(unconvertible(error)));
134
+ worker.on('error', (error) => finish(error.code === 'ERR_WORKER_OUT_OF_MEMORY' ? { kind: 'limit', limit: 'memory' } : failure(error)));
135
+ worker.on('exit', (code) => finish({ kind: 'error', message: `The sandbox stopped unexpectedly (exit code ${code}).` }));
136
+ worker.unref();
137
+ });
138
+ }
139
+ exports.runSandboxed = runSandboxed;
package/dist/soft.js CHANGED
@@ -3,13 +3,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.soft = exports.STALENESS_TIMEOUT_MS = void 0;
4
4
  // Annotation is a bonus on top of a result already in hand, so it gets less time than a fetch.
5
5
  exports.STALENESS_TIMEOUT_MS = 2000;
6
- function soft(p, fallback, ms) {
6
+ function soft(p, fallback, ms, onTimeout) {
7
7
  // Attached before the race, not after: a rejection arriving once the timeout has
8
8
  // already won would otherwise surface as an unhandled rejection and kill the process.
9
9
  const handled = p.catch(() => fallback);
10
10
  let timer;
11
11
  const capped = new Promise((resolve) => {
12
- timer = setTimeout(() => resolve(fallback), ms);
12
+ timer = setTimeout(() => {
13
+ onTimeout?.();
14
+ resolve(fallback);
15
+ }, ms);
13
16
  });
14
17
  return Promise.race([handled, capped]).finally(() => clearTimeout(timer));
15
18
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skedulo/memory-hub-mcp",
3
- "version": "0.2.38",
3
+ "version": "0.2.39",
4
4
  "description": "MCP server for the Memory Hub: recall and save developer memory from Claude Code and Claude Desktop.",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {
@@ -28,12 +28,15 @@
28
28
  "build": "tsc && ./scripts/source-hash.sh > dist/.source-hash",
29
29
  "start": "node dist/index.js",
30
30
  "test": "jest",
31
- "prepack": "./scripts/copy-assets.sh"
31
+ "prepack": "./scripts/copy-assets.sh",
32
+ "smoke:run": "./scripts/smoke-run.sh"
32
33
  },
33
34
  "dependencies": {
34
35
  "@huggingface/transformers": "3.8.1",
36
+ "@jitl/quickjs-singlefile-cjs-release-sync": "0.32.0",
35
37
  "@modelcontextprotocol/sdk": "^1.30.0",
36
38
  "axios": "^1.7.0",
39
+ "quickjs-emscripten-core": "0.32.0",
37
40
  "zod": "^3.25.0"
38
41
  },
39
42
  "devDependencies": {