cvm-server 0.9.2 → 0.11.0
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/main.cjs +641 -219
- package/package.json +1 -1
package/main.cjs
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
const mcp_js = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
3
3
|
const stdio_js = require("@modelcontextprotocol/sdk/server/stdio.js");
|
|
4
4
|
const zod = require("zod");
|
|
5
|
-
const i$
|
|
6
|
-
const
|
|
7
|
-
const
|
|
5
|
+
const i$2 = require("typescript");
|
|
6
|
+
const M$1 = require("fs");
|
|
7
|
+
const r = require("path");
|
|
8
8
|
const mongodb = require("mongodb");
|
|
9
9
|
const promises = require("fs/promises");
|
|
10
10
|
const dotenv = require("dotenv");
|
|
@@ -26,13 +26,13 @@ function _interopNamespaceDefault(e2) {
|
|
|
26
26
|
n2.default = e2;
|
|
27
27
|
return Object.freeze(n2);
|
|
28
28
|
}
|
|
29
|
-
const i__namespace = /* @__PURE__ */ _interopNamespaceDefault(i$
|
|
30
|
-
const
|
|
31
|
-
const
|
|
29
|
+
const i__namespace = /* @__PURE__ */ _interopNamespaceDefault(i$2);
|
|
30
|
+
const M__namespace = /* @__PURE__ */ _interopNamespaceDefault(M$1);
|
|
31
|
+
const r__namespace = /* @__PURE__ */ _interopNamespaceDefault(r);
|
|
32
32
|
const dotenv__namespace = /* @__PURE__ */ _interopNamespaceDefault(dotenv);
|
|
33
33
|
var f$1 = Object.defineProperty;
|
|
34
|
-
var p$
|
|
35
|
-
var T = (e2, t2, s2) => p$
|
|
34
|
+
var p$1 = (e2, t2, s2) => t2 in e2 ? f$1(e2, t2, { enumerable: true, configurable: true, writable: true, value: s2 }) : e2[t2] = s2;
|
|
35
|
+
var T$1 = (e2, t2, s2) => p$1(e2, typeof t2 != "symbol" ? t2 + "" : t2, s2);
|
|
36
36
|
var n$1 = /* @__PURE__ */ ((e2) => (e2.PUSH = "PUSH", e2.PUSH_UNDEFINED = "PUSH_UNDEFINED", e2.POP = "POP", e2.LOAD = "LOAD", e2.STORE = "STORE", e2.CONCAT = "CONCAT", e2.ARRAY_NEW = "ARRAY_NEW", e2.ARRAY_PUSH = "ARRAY_PUSH", e2.ARRAY_GET = "ARRAY_GET", e2.ARRAY_SET = "ARRAY_SET", e2.ARRAY_LEN = "ARRAY_LEN", e2.STRING_LEN = "STRING_LEN", e2.STRING_SUBSTRING = "STRING_SUBSTRING", e2.STRING_INDEXOF = "STRING_INDEXOF", e2.STRING_SPLIT = "STRING_SPLIT", e2.STRING_SLICE = "STRING_SLICE", e2.STRING_CHARAT = "STRING_CHARAT", e2.STRING_TOUPPERCASE = "STRING_TOUPPERCASE", e2.STRING_TOLOWERCASE = "STRING_TOLOWERCASE", e2.LENGTH = "LENGTH", e2.TO_STRING = "TO_STRING", e2.JSON_PARSE = "JSON_PARSE", e2.TYPEOF = "TYPEOF", e2.ADD = "ADD", e2.SUB = "SUB", e2.MUL = "MUL", e2.DIV = "DIV", e2.MOD = "MOD", e2.UNARY_MINUS = "UNARY_MINUS", e2.UNARY_PLUS = "UNARY_PLUS", e2.INC = "INC", e2.DEC = "DEC", e2.EQ = "EQ", e2.NEQ = "NEQ", e2.LT = "LT", e2.GT = "GT", e2.LTE = "LTE", e2.GTE = "GTE", e2.EQ_STRICT = "EQ_STRICT", e2.NEQ_STRICT = "NEQ_STRICT", e2.JUMP = "JUMP", e2.JUMP_IF = "JUMP_IF", e2.JUMP_IF_FALSE = "JUMP_IF_FALSE", e2.JUMP_IF_TRUE = "JUMP_IF_TRUE", e2.CALL = "CALL", e2.RETURN = "RETURN", e2.AND = "AND", e2.OR = "OR", e2.NOT = "NOT", e2.BREAK = "BREAK", e2.CONTINUE = "CONTINUE", e2.ITER_START = "ITER_START", e2.ITER_NEXT = "ITER_NEXT", e2.ITER_END = "ITER_END", e2.FS_LIST_FILES = "FS_LIST_FILES", e2.OBJECT_CREATE = "OBJECT_CREATE", e2.PROPERTY_GET = "PROPERTY_GET", e2.PROPERTY_SET = "PROPERTY_SET", e2.JSON_STRINGIFY = "JSON_STRINGIFY", e2.CC = "CC", e2.PRINT = "PRINT", e2.HALT = "HALT", e2))(n$1 || {});
|
|
37
37
|
function R(e2) {
|
|
38
38
|
const t2 = [], s2 = [];
|
|
@@ -43,14 +43,14 @@ function R(e2) {
|
|
|
43
43
|
i__namespace.ScriptTarget.Latest,
|
|
44
44
|
true
|
|
45
45
|
);
|
|
46
|
-
function
|
|
46
|
+
function S(c2) {
|
|
47
47
|
if (i__namespace.isFunctionDeclaration(c2) && c2.name && c2.name.text === "main" && (r2 = true, c2.parameters.length > 0 && t2.push("main() must not have parameters")), i__namespace.isCallExpression(c2) && i__namespace.isIdentifier(c2.expression)) {
|
|
48
48
|
const o2 = c2.expression.text;
|
|
49
49
|
["setTimeout", "fetch", "require", "import"].includes(o2) && t2.push(`Unsupported function: ${o2}`);
|
|
50
50
|
}
|
|
51
|
-
i__namespace.forEachChild(c2,
|
|
51
|
+
i__namespace.forEachChild(c2, S);
|
|
52
52
|
}
|
|
53
|
-
return
|
|
53
|
+
return S(a2), r2 || t2.push("Program must have a main() function"), t2.length === 0 && s2.push({ op: n$1.HALT }), {
|
|
54
54
|
bytecode: s2,
|
|
55
55
|
errors: t2,
|
|
56
56
|
hasMain: r2
|
|
@@ -58,8 +58,8 @@ function R(e2) {
|
|
|
58
58
|
}
|
|
59
59
|
let A$1 = class A {
|
|
60
60
|
constructor() {
|
|
61
|
-
T(this, "bytecode", []);
|
|
62
|
-
T(this, "contextStack", []);
|
|
61
|
+
T$1(this, "bytecode", []);
|
|
62
|
+
T$1(this, "contextStack", []);
|
|
63
63
|
}
|
|
64
64
|
/**
|
|
65
65
|
* Emit an instruction and return its index
|
|
@@ -136,13 +136,13 @@ let A$1 = class A {
|
|
|
136
136
|
};
|
|
137
137
|
const P$1 = (e2, t2, { compileExpression: s2, compileStatement: r2 }) => {
|
|
138
138
|
s2(e2.expression);
|
|
139
|
-
const a2 = t2.emit(n$1.JUMP_IF_FALSE, -1),
|
|
139
|
+
const a2 = t2.emit(n$1.JUMP_IF_FALSE, -1), S = {
|
|
140
140
|
type: "if",
|
|
141
141
|
endTargets: []
|
|
142
142
|
};
|
|
143
|
-
if (e2.elseStatement ?
|
|
143
|
+
if (e2.elseStatement ? S.elseTarget = a2 : S.endTargets.push(a2), t2.pushContext(S), r2(e2.thenStatement), e2.elseStatement) {
|
|
144
144
|
const o2 = t2.emit(n$1.JUMP, -1);
|
|
145
|
-
|
|
145
|
+
S.endTargets.push(o2);
|
|
146
146
|
const m2 = t2.currentAddress();
|
|
147
147
|
t2.patchJump(a2, m2), r2(e2.elseStatement);
|
|
148
148
|
}
|
|
@@ -168,7 +168,7 @@ const P$1 = (e2, t2, { compileExpression: s2, compileStatement: r2 }) => {
|
|
|
168
168
|
t2.patchJumps(o2.breakTargets || [], m2);
|
|
169
169
|
}
|
|
170
170
|
}, h$2 = (e2, t2, { compileExpression: s2, compileStatement: r2 }) => {
|
|
171
|
-
const a2 = e2.initializer,
|
|
171
|
+
const a2 = e2.initializer, S = e2.expression;
|
|
172
172
|
let c2;
|
|
173
173
|
if (i__namespace.isVariableDeclarationList(a2))
|
|
174
174
|
c2 = a2.declarations[0].name.getText();
|
|
@@ -176,7 +176,7 @@ const P$1 = (e2, t2, { compileExpression: s2, compileStatement: r2 }) => {
|
|
|
176
176
|
c2 = a2.text;
|
|
177
177
|
else
|
|
178
178
|
throw new Error("Unsupported for-of variable declaration");
|
|
179
|
-
s2(
|
|
179
|
+
s2(S), t2.emit(n$1.ITER_START);
|
|
180
180
|
const o2 = t2.currentAddress();
|
|
181
181
|
t2.emit(n$1.ITER_NEXT);
|
|
182
182
|
const m2 = t2.emit(n$1.JUMP_IF_FALSE, -1);
|
|
@@ -199,10 +199,10 @@ const P$1 = (e2, t2, { compileExpression: s2, compileStatement: r2 }) => {
|
|
|
199
199
|
e2.statements.forEach((r2) => {
|
|
200
200
|
s2(r2);
|
|
201
201
|
});
|
|
202
|
-
}, N
|
|
202
|
+
}, N = (e2, t2, { compileExpression: s2 }) => {
|
|
203
203
|
const r2 = e2.declarationList.declarations[0];
|
|
204
204
|
r2.initializer && (s2(r2.initializer), t2.emit(n$1.STORE, r2.name.getText()));
|
|
205
|
-
}, _ = (e2, t2, { compileExpression: s2 }) => {
|
|
205
|
+
}, _$1 = (e2, t2, { compileExpression: s2 }) => {
|
|
206
206
|
const r2 = e2.expression;
|
|
207
207
|
if (i__namespace.isBinaryExpression(r2)) {
|
|
208
208
|
const a2 = r2.operatorToken.kind;
|
|
@@ -233,11 +233,11 @@ const P$1 = (e2, t2, { compileExpression: s2, compileStatement: r2 }) => {
|
|
|
233
233
|
if (s2(r2.right), i__namespace.isIdentifier(r2.left))
|
|
234
234
|
t2.emit(n$1.STORE, r2.left.text);
|
|
235
235
|
else if (i__namespace.isElementAccessExpression(r2.left)) {
|
|
236
|
-
const
|
|
237
|
-
t2.emit(n$1.STORE,
|
|
236
|
+
const S = `__temp_${t2.getBytecode().length}`;
|
|
237
|
+
t2.emit(n$1.STORE, S), s2(r2.left.expression), s2(r2.left.argumentExpression), t2.emit(n$1.LOAD, S), t2.emit(n$1.ARRAY_SET), t2.emit(n$1.POP);
|
|
238
238
|
} else if (i__namespace.isPropertyAccessExpression(r2.left)) {
|
|
239
|
-
const
|
|
240
|
-
t2.emit(n$1.STORE,
|
|
239
|
+
const S = `__temp_${t2.getBytecode().length}`;
|
|
240
|
+
t2.emit(n$1.STORE, S), s2(r2.left.expression), t2.emit(n$1.PUSH, r2.left.name.text), t2.emit(n$1.LOAD, S), t2.emit(n$1.PROPERTY_SET), t2.emit(n$1.POP);
|
|
241
241
|
}
|
|
242
242
|
return;
|
|
243
243
|
}
|
|
@@ -267,8 +267,8 @@ const P$1 = (e2, t2, { compileExpression: s2, compileStatement: r2 }) => {
|
|
|
267
267
|
[i__namespace.SyntaxKind.WhileStatement]: I,
|
|
268
268
|
[i__namespace.SyntaxKind.ForOfStatement]: h$2,
|
|
269
269
|
[i__namespace.SyntaxKind.Block]: y$1,
|
|
270
|
-
[i__namespace.SyntaxKind.VariableStatement]: N
|
|
271
|
-
[i__namespace.SyntaxKind.ExpressionStatement]: _,
|
|
270
|
+
[i__namespace.SyntaxKind.VariableStatement]: N,
|
|
271
|
+
[i__namespace.SyntaxKind.ExpressionStatement]: _$1,
|
|
272
272
|
[i__namespace.SyntaxKind.ReturnStatement]: g$2,
|
|
273
273
|
[i__namespace.SyntaxKind.BreakStatement]: k,
|
|
274
274
|
[i__namespace.SyntaxKind.ContinueStatement]: U
|
|
@@ -276,11 +276,11 @@ const P$1 = (e2, t2, { compileExpression: s2, compileStatement: r2 }) => {
|
|
|
276
276
|
t2.emit(n$1.PUSH, e2.text);
|
|
277
277
|
}, d$1 = (e2, t2, s2) => {
|
|
278
278
|
t2.emit(n$1.PUSH, Number(e2.text));
|
|
279
|
-
}, b$
|
|
279
|
+
}, b$1 = (e2, t2, s2) => {
|
|
280
280
|
t2.emit(n$1.PUSH, true);
|
|
281
281
|
}, F$1 = (e2, t2, s2) => {
|
|
282
282
|
t2.emit(n$1.PUSH, false);
|
|
283
|
-
}, G = (e2, t2, s2) => {
|
|
283
|
+
}, G$1 = (e2, t2, s2) => {
|
|
284
284
|
t2.emit(n$1.PUSH, null);
|
|
285
285
|
}, D$1 = (e2, t2, s2) => {
|
|
286
286
|
e2.text === "undefined" ? t2.emit(n$1.PUSH_UNDEFINED) : t2.emit(n$1.LOAD, e2.text);
|
|
@@ -288,13 +288,13 @@ const P$1 = (e2, t2, { compileExpression: s2, compileStatement: r2 }) => {
|
|
|
288
288
|
t2.emit(n$1.ARRAY_NEW), e2.elements.forEach((r2) => {
|
|
289
289
|
s2(r2), t2.emit(n$1.ARRAY_PUSH);
|
|
290
290
|
});
|
|
291
|
-
}, M
|
|
291
|
+
}, M = (e2, t2, { compileExpression: s2 }) => {
|
|
292
292
|
s2(e2.expression);
|
|
293
293
|
}, J$1 = (e2, t2, { compileExpression: s2 }) => {
|
|
294
294
|
e2.name.text === "length" ? (s2(e2.expression), t2.emit(n$1.LENGTH)) : (s2(e2.expression), t2.emit(n$1.PUSH, e2.name.text), t2.emit(n$1.PROPERTY_GET));
|
|
295
295
|
}, Y$1 = (e2, t2, { compileExpression: s2, reportError: r2 }) => {
|
|
296
296
|
s2(e2.expression), e2.argumentExpression ? s2(e2.argumentExpression) : r2(e2, "Element access requires an index expression"), t2.emit(n$1.ARRAY_GET);
|
|
297
|
-
}, C = (e2, t2, { compileExpression: s2 }) => {
|
|
297
|
+
}, C$1 = (e2, t2, { compileExpression: s2 }) => {
|
|
298
298
|
switch (e2.operator) {
|
|
299
299
|
case i__namespace.SyntaxKind.ExclamationToken:
|
|
300
300
|
s2(e2.operand), t2.emit(n$1.NOT);
|
|
@@ -322,14 +322,14 @@ const P$1 = (e2, t2, { compileExpression: s2, compileStatement: r2 }) => {
|
|
|
322
322
|
break;
|
|
323
323
|
}
|
|
324
324
|
};
|
|
325
|
-
function x$
|
|
326
|
-
return !!(i__namespace.isStringLiteral(e2) || i__namespace.isStringLiteral(t2) || i__namespace.isBinaryExpression(e2) && e2.operatorToken.kind === i__namespace.SyntaxKind.PlusToken && x$
|
|
325
|
+
function x$2(e2, t2) {
|
|
326
|
+
return !!(i__namespace.isStringLiteral(e2) || i__namespace.isStringLiteral(t2) || i__namespace.isBinaryExpression(e2) && e2.operatorToken.kind === i__namespace.SyntaxKind.PlusToken && x$2(e2.left, e2.right) || i__namespace.isBinaryExpression(t2) && t2.operatorToken.kind === i__namespace.SyntaxKind.PlusToken && x$2(t2.left, t2.right));
|
|
327
327
|
}
|
|
328
328
|
const B$1 = (e2, t2, { compileExpression: s2 }) => {
|
|
329
329
|
const r2 = e2.operatorToken.kind;
|
|
330
330
|
switch (s2(e2.left), s2(e2.right), r2) {
|
|
331
331
|
case i__namespace.SyntaxKind.PlusToken:
|
|
332
|
-
x$
|
|
332
|
+
x$2(e2.left, e2.right) ? t2.emit(n$1.CONCAT) : t2.emit(n$1.ADD);
|
|
333
333
|
break;
|
|
334
334
|
case i__namespace.SyntaxKind.MinusToken:
|
|
335
335
|
t2.emit(n$1.SUB);
|
|
@@ -378,8 +378,8 @@ const B$1 = (e2, t2, { compileExpression: s2 }) => {
|
|
|
378
378
|
s2(e2.condition);
|
|
379
379
|
const r2 = t2.emit(n$1.JUMP_IF_FALSE, -1);
|
|
380
380
|
s2(e2.whenTrue);
|
|
381
|
-
const a2 = t2.emit(n$1.JUMP, -1),
|
|
382
|
-
t2.patchJump(r2,
|
|
381
|
+
const a2 = t2.emit(n$1.JUMP, -1), S = t2.currentAddress();
|
|
382
|
+
t2.patchJump(r2, S), s2(e2.whenFalse);
|
|
383
383
|
const c2 = t2.currentAddress();
|
|
384
384
|
t2.patchJump(a2, c2);
|
|
385
385
|
}, O = (e2, t2, { compileExpression: s2 }) => {
|
|
@@ -435,20 +435,20 @@ const B$1 = (e2, t2, { compileExpression: s2 }) => {
|
|
|
435
435
|
}, j$2 = {
|
|
436
436
|
[i__namespace.SyntaxKind.StringLiteral]: K,
|
|
437
437
|
[i__namespace.SyntaxKind.NumericLiteral]: d$1,
|
|
438
|
-
[i__namespace.SyntaxKind.TrueKeyword]: b$
|
|
438
|
+
[i__namespace.SyntaxKind.TrueKeyword]: b$1,
|
|
439
439
|
[i__namespace.SyntaxKind.FalseKeyword]: F$1,
|
|
440
|
-
[i__namespace.SyntaxKind.NullKeyword]: G,
|
|
440
|
+
[i__namespace.SyntaxKind.NullKeyword]: G$1,
|
|
441
441
|
[i__namespace.SyntaxKind.Identifier]: D$1,
|
|
442
442
|
[i__namespace.SyntaxKind.ArrayLiteralExpression]: H$1,
|
|
443
443
|
[i__namespace.SyntaxKind.BinaryExpression]: B$1,
|
|
444
|
-
[i__namespace.SyntaxKind.PrefixUnaryExpression]: C,
|
|
444
|
+
[i__namespace.SyntaxKind.PrefixUnaryExpression]: C$1,
|
|
445
445
|
[i__namespace.SyntaxKind.PostfixUnaryExpression]: w$1,
|
|
446
446
|
[i__namespace.SyntaxKind.CallExpression]: V$1,
|
|
447
447
|
[i__namespace.SyntaxKind.PropertyAccessExpression]: J$1,
|
|
448
448
|
[i__namespace.SyntaxKind.ElementAccessExpression]: Y$1,
|
|
449
449
|
[i__namespace.SyntaxKind.ConditionalExpression]: q$1,
|
|
450
450
|
[i__namespace.SyntaxKind.TypeOfExpression]: O,
|
|
451
|
-
[i__namespace.SyntaxKind.ParenthesizedExpression]: M
|
|
451
|
+
[i__namespace.SyntaxKind.ParenthesizedExpression]: M,
|
|
452
452
|
[i__namespace.SyntaxKind.ObjectLiteralExpression]: Q
|
|
453
453
|
};
|
|
454
454
|
function W$1(e2) {
|
|
@@ -460,13 +460,13 @@ function W$1(e2) {
|
|
|
460
460
|
errors: t2.errors
|
|
461
461
|
};
|
|
462
462
|
const s2 = new A$1(), r2 = i__namespace.createSourceFile("program.ts", e2, i__namespace.ScriptTarget.Latest, true), a2 = {
|
|
463
|
-
compileStatement:
|
|
463
|
+
compileStatement: S,
|
|
464
464
|
compileExpression: c2,
|
|
465
465
|
reportError: (o2, m2) => {
|
|
466
466
|
throw new Error(m2);
|
|
467
467
|
}
|
|
468
468
|
};
|
|
469
|
-
function
|
|
469
|
+
function S(o2) {
|
|
470
470
|
const m2 = L$1[o2.kind];
|
|
471
471
|
m2 && m2(o2, s2, a2);
|
|
472
472
|
}
|
|
@@ -477,7 +477,7 @@ function W$1(e2) {
|
|
|
477
477
|
return r2.forEachChild((o2) => {
|
|
478
478
|
var m2;
|
|
479
479
|
i__namespace.isFunctionDeclaration(o2) && ((m2 = o2.name) == null ? void 0 : m2.text) === "main" && o2.body && o2.body.statements.forEach((l2) => {
|
|
480
|
-
|
|
480
|
+
S(l2);
|
|
481
481
|
});
|
|
482
482
|
}), s2.emit(n$1.HALT), {
|
|
483
483
|
success: true,
|
|
@@ -491,7 +491,7 @@ function n(r2) {
|
|
|
491
491
|
function t(r2) {
|
|
492
492
|
return typeof r2 == "number";
|
|
493
493
|
}
|
|
494
|
-
function i(r2) {
|
|
494
|
+
function i$1(r2) {
|
|
495
495
|
return typeof r2 == "boolean";
|
|
496
496
|
}
|
|
497
497
|
function e(r2) {
|
|
@@ -503,21 +503,21 @@ function f(r2) {
|
|
|
503
503
|
function o(r2) {
|
|
504
504
|
return r2 !== null && typeof r2 == "object" && "type" in r2 && r2.type === "undefined";
|
|
505
505
|
}
|
|
506
|
-
function c
|
|
506
|
+
function c(r2) {
|
|
507
507
|
return r2 !== null && typeof r2 == "object" && "type" in r2 && r2.type === "object";
|
|
508
508
|
}
|
|
509
509
|
function y(r2) {
|
|
510
|
-
return n(r2) ? r2 : t(r2) || i(r2) ? r2.toString() : e(r2) ? "null" : o(r2) ? "undefined" : f(r2) ? `[array:${r2.elements.length}]` : c
|
|
510
|
+
return n(r2) ? r2 : t(r2) || i$1(r2) ? r2.toString() : e(r2) ? "null" : o(r2) ? "undefined" : f(r2) ? `[array:${r2.elements.length}]` : c(r2) ? "[object Object]" : String(r2);
|
|
511
511
|
}
|
|
512
|
-
function b
|
|
513
|
-
return i(r2) ? r2 : e(r2) || o(r2) ? false : t(r2) ? r2 !== 0 : n(r2) ? r2 !== "" : f(r2) || c
|
|
512
|
+
function b(r2) {
|
|
513
|
+
return i$1(r2) ? r2 : e(r2) || o(r2) ? false : t(r2) ? r2 !== 0 : n(r2) ? r2 !== "" : f(r2) || c(r2) ? true : !!r2;
|
|
514
514
|
}
|
|
515
|
-
function p
|
|
516
|
-
return n(r2) ? "string" : t(r2) ? "number" : i(r2) ? "boolean" : e(r2) ? "null" : o(r2) ? "undefined" : f(r2) ? "array" : c
|
|
515
|
+
function p(r2) {
|
|
516
|
+
return n(r2) ? "string" : t(r2) ? "number" : i$1(r2) ? "boolean" : e(r2) ? "null" : o(r2) ? "undefined" : f(r2) ? "array" : c(r2) ? "object" : "unknown";
|
|
517
517
|
}
|
|
518
518
|
function m(r2) {
|
|
519
519
|
if (t(r2)) return r2;
|
|
520
|
-
if (i(r2)) return r2 ? 1 : 0;
|
|
520
|
+
if (i$1(r2)) return r2 ? 1 : 0;
|
|
521
521
|
if (e(r2)) return 0;
|
|
522
522
|
if (o(r2)) return NaN;
|
|
523
523
|
if (n(r2)) {
|
|
@@ -529,25 +529,28 @@ function m(r2) {
|
|
|
529
529
|
function d(r2 = []) {
|
|
530
530
|
return { type: "array", elements: r2 };
|
|
531
531
|
}
|
|
532
|
-
function s
|
|
532
|
+
function s() {
|
|
533
533
|
return { type: "undefined" };
|
|
534
534
|
}
|
|
535
535
|
function j$1(r2 = {}) {
|
|
536
536
|
return { type: "object", properties: r2 };
|
|
537
537
|
}
|
|
538
538
|
var l = Object.defineProperty;
|
|
539
|
-
var u = (s2, t2,
|
|
540
|
-
var
|
|
539
|
+
var u$1 = (s2, t2, e2) => t2 in s2 ? l(s2, t2, { enumerable: true, configurable: true, writable: true, value: e2 }) : s2[t2] = e2;
|
|
540
|
+
var a = (s2, t2, e2) => u$1(s2, typeof t2 != "symbol" ? t2 + "" : t2, e2);
|
|
541
541
|
let h$1 = class h {
|
|
542
542
|
constructor(t2) {
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
this.dataDir = t2, this.programsDir =
|
|
543
|
+
a(this, "connected", false);
|
|
544
|
+
a(this, "programsDir");
|
|
545
|
+
a(this, "executionsDir");
|
|
546
|
+
a(this, "outputsDir");
|
|
547
|
+
this.dataDir = t2, this.programsDir = r__namespace.join(t2, "programs"), this.executionsDir = r__namespace.join(t2, "executions"), this.outputsDir = r__namespace.join(t2, "outputs");
|
|
548
|
+
}
|
|
549
|
+
get metadataFile() {
|
|
550
|
+
return r__namespace.join(this.dataDir, "metadata.json");
|
|
548
551
|
}
|
|
549
552
|
async connect() {
|
|
550
|
-
await
|
|
553
|
+
await M$1.promises.mkdir(this.dataDir, { recursive: true }), await M$1.promises.mkdir(this.programsDir, { recursive: true }), await M$1.promises.mkdir(this.executionsDir, { recursive: true }), await M$1.promises.mkdir(this.outputsDir, { recursive: true }), this.connected = true;
|
|
551
554
|
}
|
|
552
555
|
async disconnect() {
|
|
553
556
|
this.connected = false;
|
|
@@ -557,63 +560,124 @@ let h$1 = class h {
|
|
|
557
560
|
}
|
|
558
561
|
async saveProgram(t2) {
|
|
559
562
|
if (!this.connected) throw new Error("Not connected");
|
|
560
|
-
const
|
|
561
|
-
await
|
|
563
|
+
const e2 = r__namespace.join(this.programsDir, `${t2.id}.json`), n2 = JSON.stringify(t2, null, 2);
|
|
564
|
+
await M$1.promises.writeFile(e2, n2, "utf-8");
|
|
562
565
|
}
|
|
563
566
|
async getProgram(t2) {
|
|
564
567
|
if (!this.connected) throw new Error("Not connected");
|
|
565
|
-
const
|
|
568
|
+
const e2 = r__namespace.join(this.programsDir, `${t2}.json`);
|
|
566
569
|
try {
|
|
567
|
-
const
|
|
570
|
+
const n2 = await M$1.promises.readFile(e2, "utf-8"), o2 = JSON.parse(n2);
|
|
568
571
|
return o2.created = new Date(o2.created), o2.updated && (o2.updated = new Date(o2.updated)), o2;
|
|
569
|
-
} catch (
|
|
570
|
-
if (
|
|
572
|
+
} catch (n2) {
|
|
573
|
+
if (n2.code === "ENOENT")
|
|
571
574
|
return null;
|
|
572
|
-
throw
|
|
575
|
+
throw n2;
|
|
573
576
|
}
|
|
574
577
|
}
|
|
575
578
|
async saveExecution(t2) {
|
|
576
579
|
if (!this.connected) throw new Error("Not connected");
|
|
577
|
-
const
|
|
578
|
-
await
|
|
580
|
+
const e2 = r__namespace.join(this.executionsDir, `${t2.id}.json`), n2 = JSON.stringify(t2, null, 2);
|
|
581
|
+
await M$1.promises.writeFile(e2, n2, "utf-8");
|
|
579
582
|
}
|
|
580
583
|
async getExecution(t2) {
|
|
581
584
|
if (!this.connected) throw new Error("Not connected");
|
|
582
|
-
const
|
|
585
|
+
const e2 = r__namespace.join(this.executionsDir, `${t2}.json`);
|
|
583
586
|
try {
|
|
584
|
-
const
|
|
587
|
+
const n2 = await M$1.promises.readFile(e2, "utf-8"), o2 = JSON.parse(n2);
|
|
585
588
|
return o2.created = new Date(o2.created), o2.updated && (o2.updated = new Date(o2.updated)), o2;
|
|
586
|
-
} catch (
|
|
587
|
-
if (
|
|
589
|
+
} catch (n2) {
|
|
590
|
+
if (n2.code === "ENOENT")
|
|
588
591
|
return null;
|
|
589
|
-
throw
|
|
592
|
+
throw n2;
|
|
590
593
|
}
|
|
591
594
|
}
|
|
592
|
-
async appendOutput(t2,
|
|
595
|
+
async appendOutput(t2, e2) {
|
|
593
596
|
if (!this.connected) throw new Error("Not connected");
|
|
594
|
-
const
|
|
597
|
+
const n2 = r__namespace.join(this.outputsDir, `${t2}.output`), o2 = e2.join(`
|
|
595
598
|
`) + `
|
|
596
599
|
`;
|
|
597
|
-
await
|
|
600
|
+
await M$1.promises.appendFile(n2, o2, "utf-8");
|
|
598
601
|
}
|
|
599
602
|
async getOutput(t2) {
|
|
600
603
|
if (!this.connected) throw new Error("Not connected");
|
|
601
|
-
const
|
|
604
|
+
const e2 = r__namespace.join(this.outputsDir, `${t2}.output`);
|
|
602
605
|
try {
|
|
603
|
-
return (await
|
|
606
|
+
return (await M$1.promises.readFile(e2, "utf-8")).split(`
|
|
604
607
|
`).filter((o2) => o2.length > 0);
|
|
605
|
-
} catch (
|
|
606
|
-
if (
|
|
608
|
+
} catch (n2) {
|
|
609
|
+
if (n2.code === "ENOENT")
|
|
607
610
|
return [];
|
|
608
|
-
throw
|
|
611
|
+
throw n2;
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
async listExecutions() {
|
|
615
|
+
if (!this.connected) throw new Error("Not connected");
|
|
616
|
+
const t2 = await M$1.promises.readdir(this.executionsDir), e2 = [];
|
|
617
|
+
for (const n2 of t2)
|
|
618
|
+
if (n2.endsWith(".json")) {
|
|
619
|
+
const o2 = n2.slice(0, -5), c2 = await this.getExecution(o2);
|
|
620
|
+
c2 && e2.push(c2);
|
|
621
|
+
}
|
|
622
|
+
return e2;
|
|
623
|
+
}
|
|
624
|
+
async getCurrentExecutionId() {
|
|
625
|
+
if (!this.connected) throw new Error("Not connected");
|
|
626
|
+
try {
|
|
627
|
+
const t2 = await M$1.promises.readFile(this.metadataFile, "utf-8");
|
|
628
|
+
return JSON.parse(t2).currentExecutionId || null;
|
|
629
|
+
} catch (t2) {
|
|
630
|
+
if (t2.code === "ENOENT")
|
|
631
|
+
return null;
|
|
632
|
+
throw t2;
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
async setCurrentExecutionId(t2) {
|
|
636
|
+
if (!this.connected) throw new Error("Not connected");
|
|
637
|
+
const e2 = { currentExecutionId: t2 };
|
|
638
|
+
await M$1.promises.writeFile(this.metadataFile, JSON.stringify(e2, null, 2), "utf-8");
|
|
639
|
+
}
|
|
640
|
+
async deleteExecution(t2) {
|
|
641
|
+
if (!this.connected) throw new Error("Not connected");
|
|
642
|
+
const e2 = r__namespace.join(this.executionsDir, `${t2}.json`);
|
|
643
|
+
try {
|
|
644
|
+
await M$1.promises.unlink(e2);
|
|
645
|
+
} catch (c2) {
|
|
646
|
+
if (c2.code !== "ENOENT") throw c2;
|
|
647
|
+
}
|
|
648
|
+
const n2 = r__namespace.join(this.outputsDir, `${t2}.output`);
|
|
649
|
+
try {
|
|
650
|
+
await M$1.promises.unlink(n2);
|
|
651
|
+
} catch (c2) {
|
|
652
|
+
if (c2.code !== "ENOENT") throw c2;
|
|
653
|
+
}
|
|
654
|
+
await this.getCurrentExecutionId() === t2 && await this.setCurrentExecutionId(null);
|
|
655
|
+
}
|
|
656
|
+
async listPrograms() {
|
|
657
|
+
if (!this.connected) throw new Error("Not connected");
|
|
658
|
+
const t2 = await M$1.promises.readdir(this.programsDir), e2 = [];
|
|
659
|
+
for (const n2 of t2)
|
|
660
|
+
if (n2.endsWith(".json")) {
|
|
661
|
+
const o2 = n2.slice(0, -5), c2 = await this.getProgram(o2);
|
|
662
|
+
c2 && e2.push(c2);
|
|
663
|
+
}
|
|
664
|
+
return e2;
|
|
665
|
+
}
|
|
666
|
+
async deleteProgram(t2) {
|
|
667
|
+
if (!this.connected) throw new Error("Not connected");
|
|
668
|
+
const e2 = r__namespace.join(this.programsDir, `${t2}.json`);
|
|
669
|
+
try {
|
|
670
|
+
await M$1.promises.unlink(e2);
|
|
671
|
+
} catch (n2) {
|
|
672
|
+
if (n2.code !== "ENOENT") throw n2;
|
|
609
673
|
}
|
|
610
674
|
}
|
|
611
675
|
};
|
|
612
|
-
class
|
|
676
|
+
class w {
|
|
613
677
|
constructor(t2) {
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
678
|
+
a(this, "client");
|
|
679
|
+
a(this, "db", null);
|
|
680
|
+
a(this, "connected", false);
|
|
617
681
|
this.connectionString = t2, this.client = new mongodb.MongoClient(t2);
|
|
618
682
|
}
|
|
619
683
|
async connect() {
|
|
@@ -621,8 +685,8 @@ class p {
|
|
|
621
685
|
await this.client.connect();
|
|
622
686
|
const t2 = ((o2 = this.connectionString.split("/").pop()) == null ? void 0 : o2.split("?")[0]) || "cvm";
|
|
623
687
|
this.db = this.client.db(t2), this.connected = true;
|
|
624
|
-
const
|
|
625
|
-
|
|
688
|
+
const n2 = (await this.db.listCollections().toArray()).map((c2) => c2.name);
|
|
689
|
+
n2.includes("programs") || await this.db.createCollection("programs"), n2.includes("executions") || await this.db.createCollection("executions"), n2.includes("outputs") || await this.db.createCollection("outputs"), n2.includes("metadata") || await this.db.createCollection("metadata");
|
|
626
690
|
}
|
|
627
691
|
async disconnect() {
|
|
628
692
|
await this.client.close(), this.connected = false, this.db = null;
|
|
@@ -632,7 +696,7 @@ class p {
|
|
|
632
696
|
}
|
|
633
697
|
async getCollections() {
|
|
634
698
|
if (!this.db) throw new Error("Not connected to database");
|
|
635
|
-
return (await this.db.listCollections().toArray()).map((
|
|
699
|
+
return (await this.db.listCollections().toArray()).map((e2) => e2.name);
|
|
636
700
|
}
|
|
637
701
|
getCollection(t2) {
|
|
638
702
|
if (!this.db) throw new Error("Not connected to database");
|
|
@@ -658,39 +722,62 @@ class p {
|
|
|
658
722
|
async getExecution(t2) {
|
|
659
723
|
return await this.getCollection("executions").findOne({ id: t2 });
|
|
660
724
|
}
|
|
661
|
-
async appendOutput(t2,
|
|
662
|
-
const
|
|
663
|
-
await
|
|
725
|
+
async appendOutput(t2, e2) {
|
|
726
|
+
const n2 = this.getCollection("outputs");
|
|
727
|
+
await n2.findOne({ executionId: t2 }) ? await n2.updateOne(
|
|
664
728
|
{ executionId: t2 },
|
|
665
|
-
{ $push: { lines: { $each:
|
|
666
|
-
) : await
|
|
729
|
+
{ $push: { lines: { $each: e2 } } }
|
|
730
|
+
) : await n2.insertOne({ executionId: t2, lines: e2 });
|
|
667
731
|
}
|
|
668
732
|
async getOutput(t2) {
|
|
669
|
-
const
|
|
670
|
-
return (
|
|
733
|
+
const n2 = await this.getCollection("outputs").findOne({ executionId: t2 });
|
|
734
|
+
return (n2 == null ? void 0 : n2.lines) || [];
|
|
735
|
+
}
|
|
736
|
+
async listExecutions() {
|
|
737
|
+
return await this.getCollection("executions").find({}).toArray();
|
|
738
|
+
}
|
|
739
|
+
async getCurrentExecutionId() {
|
|
740
|
+
const e2 = await this.getCollection("metadata").findOne({ _id: "current" });
|
|
741
|
+
return (e2 == null ? void 0 : e2.currentExecutionId) || null;
|
|
742
|
+
}
|
|
743
|
+
async setCurrentExecutionId(t2) {
|
|
744
|
+
await this.getCollection("metadata").replaceOne(
|
|
745
|
+
{ _id: "current" },
|
|
746
|
+
{ _id: "current", currentExecutionId: t2 },
|
|
747
|
+
{ upsert: true }
|
|
748
|
+
);
|
|
749
|
+
}
|
|
750
|
+
async deleteExecution(t2) {
|
|
751
|
+
await this.getCollection("executions").deleteOne({ id: t2 }), await this.getCollection("outputs").deleteOne({ executionId: t2 }), await this.getCurrentExecutionId() === t2 && await this.setCurrentExecutionId(null);
|
|
752
|
+
}
|
|
753
|
+
async listPrograms() {
|
|
754
|
+
return await this.getCollection("programs").find({}).toArray();
|
|
755
|
+
}
|
|
756
|
+
async deleteProgram(t2) {
|
|
757
|
+
await this.getCollection("programs").deleteOne({ id: t2 });
|
|
671
758
|
}
|
|
672
759
|
}
|
|
673
760
|
let g$1 = class g {
|
|
674
761
|
static create(t2) {
|
|
675
|
-
const
|
|
676
|
-
switch (
|
|
762
|
+
const e2 = (t2 == null ? void 0 : t2.type) || process.env.CVM_STORAGE_TYPE || "file";
|
|
763
|
+
switch (e2) {
|
|
677
764
|
case "file": {
|
|
678
|
-
const
|
|
679
|
-
return new h$1(
|
|
765
|
+
const n2 = (t2 == null ? void 0 : t2.dataDir) || process.env.CVM_DATA_DIR || ".cvm";
|
|
766
|
+
return new h$1(n2);
|
|
680
767
|
}
|
|
681
768
|
case "mongodb": {
|
|
682
|
-
const
|
|
683
|
-
return new
|
|
769
|
+
const n2 = (t2 == null ? void 0 : t2.mongoUri) || process.env.MONGODB_URI || "mongodb://localhost:27017/cvm";
|
|
770
|
+
return new w(n2);
|
|
684
771
|
}
|
|
685
772
|
default:
|
|
686
|
-
throw new Error(`Unsupported storage type: ${
|
|
773
|
+
throw new Error(`Unsupported storage type: ${e2}`);
|
|
687
774
|
}
|
|
688
775
|
}
|
|
689
776
|
};
|
|
690
|
-
var
|
|
691
|
-
var
|
|
692
|
-
var h2 = (e2, r2, t2) =>
|
|
693
|
-
const
|
|
777
|
+
var A2 = Object.defineProperty;
|
|
778
|
+
var C = (e2, r2, t2) => r2 in e2 ? A2(e2, r2, { enumerable: true, configurable: true, writable: true, value: t2 }) : e2[r2] = t2;
|
|
779
|
+
var h2 = (e2, r2, t2) => C(e2, typeof r2 != "symbol" ? r2 + "" : r2, t2);
|
|
780
|
+
const G = {
|
|
694
781
|
[n$1.ADD]: {
|
|
695
782
|
stackIn: 2,
|
|
696
783
|
stackOut: 1,
|
|
@@ -754,7 +841,7 @@ const L = {
|
|
|
754
841
|
e2.stack.push(t2);
|
|
755
842
|
}
|
|
756
843
|
}
|
|
757
|
-
},
|
|
844
|
+
}, L = {
|
|
758
845
|
[n$1.PUSH]: {
|
|
759
846
|
stackIn: 0,
|
|
760
847
|
stackOut: 1,
|
|
@@ -766,7 +853,7 @@ const L = {
|
|
|
766
853
|
stackIn: 0,
|
|
767
854
|
stackOut: 1,
|
|
768
855
|
execute: (e2) => {
|
|
769
|
-
e2.stack.push(s
|
|
856
|
+
e2.stack.push(s());
|
|
770
857
|
}
|
|
771
858
|
},
|
|
772
859
|
[n$1.POP]: {
|
|
@@ -776,7 +863,7 @@ const L = {
|
|
|
776
863
|
e2.stack.pop();
|
|
777
864
|
}
|
|
778
865
|
}
|
|
779
|
-
},
|
|
866
|
+
}, V = {
|
|
780
867
|
[n$1.PRINT]: {
|
|
781
868
|
stackIn: 1,
|
|
782
869
|
stackOut: 0,
|
|
@@ -795,7 +882,7 @@ const L = {
|
|
|
795
882
|
e2.ccPrompt = y(t2), e2.status = "waiting_cc";
|
|
796
883
|
}
|
|
797
884
|
}
|
|
798
|
-
},
|
|
885
|
+
}, F = {
|
|
799
886
|
[n$1.HALT]: {
|
|
800
887
|
stackIn: 0,
|
|
801
888
|
stackOut: 0,
|
|
@@ -848,16 +935,75 @@ const L = {
|
|
|
848
935
|
pc: e2.pc,
|
|
849
936
|
opcode: r2.op
|
|
850
937
|
};
|
|
851
|
-
b
|
|
938
|
+
b(t2) ? e2.pc++ : e2.pc = s2;
|
|
939
|
+
}
|
|
940
|
+
},
|
|
941
|
+
[n$1.JUMP_IF]: {
|
|
942
|
+
stackIn: 1,
|
|
943
|
+
stackOut: 0,
|
|
944
|
+
controlsPC: true,
|
|
945
|
+
execute: (e2, r2) => {
|
|
946
|
+
const t2 = e2.stack.pop();
|
|
947
|
+
if (r2.arg === void 0)
|
|
948
|
+
return {
|
|
949
|
+
type: "RuntimeError",
|
|
950
|
+
message: "JUMP_IF requires a target address",
|
|
951
|
+
pc: e2.pc,
|
|
952
|
+
opcode: r2.op
|
|
953
|
+
};
|
|
954
|
+
const s2 = r2.arg;
|
|
955
|
+
if (s2 < 0)
|
|
956
|
+
return {
|
|
957
|
+
type: "RuntimeError",
|
|
958
|
+
message: `Invalid jump target: ${s2}`,
|
|
959
|
+
pc: e2.pc,
|
|
960
|
+
opcode: r2.op
|
|
961
|
+
};
|
|
962
|
+
b(t2) ? e2.pc = s2 : e2.pc++;
|
|
963
|
+
}
|
|
964
|
+
},
|
|
965
|
+
[n$1.JUMP_IF_TRUE]: {
|
|
966
|
+
stackIn: 1,
|
|
967
|
+
stackOut: 0,
|
|
968
|
+
controlsPC: true,
|
|
969
|
+
execute: (e2, r2) => {
|
|
970
|
+
const t2 = e2.stack.pop();
|
|
971
|
+
if (r2.arg === void 0)
|
|
972
|
+
return {
|
|
973
|
+
type: "RuntimeError",
|
|
974
|
+
message: "JUMP_IF_TRUE requires a target address",
|
|
975
|
+
pc: e2.pc,
|
|
976
|
+
opcode: r2.op
|
|
977
|
+
};
|
|
978
|
+
const s2 = r2.arg;
|
|
979
|
+
if (s2 < 0)
|
|
980
|
+
return {
|
|
981
|
+
type: "RuntimeError",
|
|
982
|
+
message: `Invalid jump target: ${s2}`,
|
|
983
|
+
pc: e2.pc,
|
|
984
|
+
opcode: r2.op
|
|
985
|
+
};
|
|
986
|
+
b(t2) ? e2.pc = s2 : e2.pc++;
|
|
852
987
|
}
|
|
988
|
+
},
|
|
989
|
+
[n$1.CALL]: {
|
|
990
|
+
stackIn: 1,
|
|
991
|
+
stackOut: 0,
|
|
992
|
+
controlsPC: false,
|
|
993
|
+
execute: (e2) => (e2.stack.pop(), {
|
|
994
|
+
type: "RuntimeError",
|
|
995
|
+
message: "Functions not implemented",
|
|
996
|
+
pc: e2.pc,
|
|
997
|
+
opcode: n$1.CALL
|
|
998
|
+
})
|
|
853
999
|
}
|
|
854
|
-
},
|
|
1000
|
+
}, j = {
|
|
855
1001
|
[n$1.LOAD]: {
|
|
856
1002
|
stackIn: 0,
|
|
857
1003
|
stackOut: 1,
|
|
858
1004
|
execute: (e2, r2) => {
|
|
859
1005
|
const t2 = r2.arg;
|
|
860
|
-
e2.variables.has(t2) ? e2.stack.push(e2.variables.get(t2)) : e2.stack.push(s
|
|
1006
|
+
e2.variables.has(t2) ? e2.stack.push(e2.variables.get(t2)) : e2.stack.push(s());
|
|
861
1007
|
}
|
|
862
1008
|
},
|
|
863
1009
|
[n$1.STORE]: {
|
|
@@ -915,7 +1061,7 @@ const L = {
|
|
|
915
1061
|
opcode: r2.op
|
|
916
1062
|
};
|
|
917
1063
|
const t2 = e2.iterators[e2.iterators.length - 1];
|
|
918
|
-
t2.index < t2.length ? (t2.index < t2.array.elements.length ? e2.stack.push(t2.array.elements[t2.index]) : e2.stack.push(s
|
|
1064
|
+
t2.index < t2.length ? (t2.index < t2.array.elements.length ? e2.stack.push(t2.array.elements[t2.index]) : e2.stack.push(s()), e2.stack.push(true), t2.index++) : (e2.stack.push(null), e2.stack.push(false));
|
|
919
1065
|
}
|
|
920
1066
|
},
|
|
921
1067
|
[n$1.ITER_END]: {
|
|
@@ -1008,12 +1154,12 @@ const q = {
|
|
|
1008
1154
|
stackOut: 1,
|
|
1009
1155
|
execute: (e2, r2) => g2(e2, r2, (t2, s2) => t2 !== s2)
|
|
1010
1156
|
}
|
|
1011
|
-
},
|
|
1157
|
+
}, $$1 = {
|
|
1012
1158
|
[n$1.AND]: {
|
|
1013
1159
|
stackIn: 2,
|
|
1014
1160
|
stackOut: 1,
|
|
1015
1161
|
execute: (e2, r2) => {
|
|
1016
|
-
const t2 = e2.stack.pop(), s2 = e2.stack.pop(), o2 = b
|
|
1162
|
+
const t2 = e2.stack.pop(), s2 = e2.stack.pop(), o2 = b(s2) ? t2 : s2;
|
|
1017
1163
|
e2.stack.push(o2);
|
|
1018
1164
|
}
|
|
1019
1165
|
},
|
|
@@ -1021,7 +1167,7 @@ const q = {
|
|
|
1021
1167
|
stackIn: 2,
|
|
1022
1168
|
stackOut: 1,
|
|
1023
1169
|
execute: (e2, r2) => {
|
|
1024
|
-
const t2 = e2.stack.pop(), s2 = e2.stack.pop(), o2 = b
|
|
1170
|
+
const t2 = e2.stack.pop(), s2 = e2.stack.pop(), o2 = b(s2) ? s2 : t2;
|
|
1025
1171
|
e2.stack.push(o2);
|
|
1026
1172
|
}
|
|
1027
1173
|
},
|
|
@@ -1029,11 +1175,11 @@ const q = {
|
|
|
1029
1175
|
stackIn: 1,
|
|
1030
1176
|
stackOut: 1,
|
|
1031
1177
|
execute: (e2, r2) => {
|
|
1032
|
-
const t2 = e2.stack.pop(), s2 = !b
|
|
1178
|
+
const t2 = e2.stack.pop(), s2 = !b(t2);
|
|
1033
1179
|
e2.stack.push(s2);
|
|
1034
1180
|
}
|
|
1035
1181
|
}
|
|
1036
|
-
},
|
|
1182
|
+
}, H = {
|
|
1037
1183
|
[n$1.ARRAY_NEW]: {
|
|
1038
1184
|
stackIn: 0,
|
|
1039
1185
|
stackOut: 1,
|
|
@@ -1073,7 +1219,7 @@ const q = {
|
|
|
1073
1219
|
e2.stack.push(o2);
|
|
1074
1220
|
return;
|
|
1075
1221
|
}
|
|
1076
|
-
if (c
|
|
1222
|
+
if (c(s2)) {
|
|
1077
1223
|
if (!n(t$1))
|
|
1078
1224
|
return {
|
|
1079
1225
|
type: "RuntimeError",
|
|
@@ -1117,7 +1263,7 @@ const q = {
|
|
|
1117
1263
|
o2.elements[n2] = t$1, e2.stack.push(o2);
|
|
1118
1264
|
return;
|
|
1119
1265
|
}
|
|
1120
|
-
if (c
|
|
1266
|
+
if (c(o2)) {
|
|
1121
1267
|
if (!n(s2))
|
|
1122
1268
|
return {
|
|
1123
1269
|
type: "RuntimeError",
|
|
@@ -1152,27 +1298,27 @@ const q = {
|
|
|
1152
1298
|
}
|
|
1153
1299
|
}
|
|
1154
1300
|
};
|
|
1155
|
-
function
|
|
1301
|
+
function T(e2) {
|
|
1156
1302
|
if (e2 === null) return null;
|
|
1157
1303
|
if (e2 !== void 0) {
|
|
1158
1304
|
if (typeof e2 == "string" || typeof e2 == "number" || typeof e2 == "boolean" || e2 && typeof e2 == "object" && e2.type === "array" && Array.isArray(e2.elements))
|
|
1159
1305
|
return e2;
|
|
1160
1306
|
if (Array.isArray(e2)) {
|
|
1161
1307
|
const r2 = d();
|
|
1162
|
-
return r2.elements = e2.map(
|
|
1308
|
+
return r2.elements = e2.map(T), r2;
|
|
1163
1309
|
}
|
|
1164
1310
|
if (e2 && typeof e2 == "object" && e2.type === "object" && e2.properties)
|
|
1165
1311
|
return e2;
|
|
1166
1312
|
if (typeof e2 == "object") {
|
|
1167
1313
|
const r2 = j$1();
|
|
1168
1314
|
for (const [t2, s2] of Object.entries(e2))
|
|
1169
|
-
r2.properties[t2] =
|
|
1315
|
+
r2.properties[t2] = T(s2);
|
|
1170
1316
|
return r2;
|
|
1171
1317
|
}
|
|
1172
1318
|
return null;
|
|
1173
1319
|
}
|
|
1174
1320
|
}
|
|
1175
|
-
const
|
|
1321
|
+
const J = {
|
|
1176
1322
|
[n$1.CONCAT]: {
|
|
1177
1323
|
stackIn: 2,
|
|
1178
1324
|
stackOut: 1,
|
|
@@ -1228,7 +1374,7 @@ const $ = {
|
|
|
1228
1374
|
};
|
|
1229
1375
|
try {
|
|
1230
1376
|
const s2 = JSON.parse(t2);
|
|
1231
|
-
e2.stack.push(
|
|
1377
|
+
e2.stack.push(T(s2));
|
|
1232
1378
|
} catch {
|
|
1233
1379
|
e2.stack.push(null);
|
|
1234
1380
|
}
|
|
@@ -1239,10 +1385,10 @@ const $ = {
|
|
|
1239
1385
|
stackOut: 1,
|
|
1240
1386
|
execute: (e2, r2) => {
|
|
1241
1387
|
const t2 = e2.stack.pop();
|
|
1242
|
-
e2.stack.push(p
|
|
1388
|
+
e2.stack.push(p(t2));
|
|
1243
1389
|
}
|
|
1244
1390
|
}
|
|
1245
|
-
},
|
|
1391
|
+
}, Y = {
|
|
1246
1392
|
[n$1.INC]: {
|
|
1247
1393
|
stackIn: 1,
|
|
1248
1394
|
stackOut: 1,
|
|
@@ -1279,7 +1425,7 @@ const $ = {
|
|
|
1279
1425
|
e2.stack.push(n2 ? m(s2) : o2);
|
|
1280
1426
|
}
|
|
1281
1427
|
}
|
|
1282
|
-
},
|
|
1428
|
+
}, B = {
|
|
1283
1429
|
[n$1.RETURN]: {
|
|
1284
1430
|
stackIn: 0,
|
|
1285
1431
|
stackOut: 0,
|
|
@@ -1396,8 +1542,8 @@ const $ = {
|
|
|
1396
1542
|
};
|
|
1397
1543
|
const u2 = s2.length;
|
|
1398
1544
|
o2 < 0 && (o2 = Math.max(0, u2 + o2)), n$12 !== void 0 && n$12 < 0 && (n$12 = Math.max(0, u2 + n$12));
|
|
1399
|
-
const
|
|
1400
|
-
e2.stack.push(
|
|
1545
|
+
const O2 = n$12 !== void 0 ? s2.substring(o2, n$12) : s2.substring(o2);
|
|
1546
|
+
e2.stack.push(O2);
|
|
1401
1547
|
}
|
|
1402
1548
|
},
|
|
1403
1549
|
[n$1.STRING_INDEXOF]: {
|
|
@@ -1534,13 +1680,13 @@ const $ = {
|
|
|
1534
1680
|
}
|
|
1535
1681
|
}
|
|
1536
1682
|
};
|
|
1537
|
-
function
|
|
1683
|
+
function _(e2) {
|
|
1538
1684
|
if (f(e2))
|
|
1539
|
-
return e2.elements.map(
|
|
1540
|
-
if (c
|
|
1685
|
+
return e2.elements.map(_);
|
|
1686
|
+
if (c(e2)) {
|
|
1541
1687
|
const r2 = {};
|
|
1542
1688
|
for (const [t2, s2] of Object.entries(e2.properties))
|
|
1543
|
-
r2[t2] =
|
|
1689
|
+
r2[t2] = _(s2);
|
|
1544
1690
|
return r2;
|
|
1545
1691
|
}
|
|
1546
1692
|
if (!o(e2))
|
|
@@ -1559,10 +1705,10 @@ const W = {
|
|
|
1559
1705
|
stackOut: 1,
|
|
1560
1706
|
execute: (e2, r2) => {
|
|
1561
1707
|
const t2 = e2.stack.pop(), s2 = e2.stack.pop(), o2 = e2.stack.pop();
|
|
1562
|
-
if (!c
|
|
1708
|
+
if (!c(o2))
|
|
1563
1709
|
return {
|
|
1564
1710
|
type: "RuntimeError",
|
|
1565
|
-
message: `Cannot set property '${s2}' on ${p
|
|
1711
|
+
message: `Cannot set property '${s2}' on ${p(o2)}`,
|
|
1566
1712
|
pc: e2.pc,
|
|
1567
1713
|
opcode: r2.op
|
|
1568
1714
|
};
|
|
@@ -1580,46 +1726,46 @@ const W = {
|
|
|
1580
1726
|
stackIn: 2,
|
|
1581
1727
|
stackOut: 1,
|
|
1582
1728
|
execute: (e$1, r2) => {
|
|
1583
|
-
const t2 = e$1.stack.pop(),
|
|
1584
|
-
if (e(
|
|
1729
|
+
const t2 = e$1.stack.pop(), s$1 = e$1.stack.pop();
|
|
1730
|
+
if (e(s$1) || o(s$1))
|
|
1585
1731
|
return {
|
|
1586
1732
|
type: "RuntimeError",
|
|
1587
|
-
message: `Cannot read property '${t2}' of ${p$1
|
|
1733
|
+
message: `Cannot read property '${t2}' of ${p(s$1)}`,
|
|
1588
1734
|
pc: e$1.pc,
|
|
1589
1735
|
opcode: r2.op
|
|
1590
1736
|
};
|
|
1591
|
-
if (!c$1
|
|
1592
|
-
e$1.stack.push(s
|
|
1737
|
+
if (!c(s$1)) {
|
|
1738
|
+
e$1.stack.push(s());
|
|
1593
1739
|
return;
|
|
1594
1740
|
}
|
|
1595
|
-
const o$1 =
|
|
1596
|
-
e$1.stack.push(o$1 ?? s
|
|
1741
|
+
const o$1 = s$1.properties[y(t2)];
|
|
1742
|
+
e$1.stack.push(o$1 ?? s());
|
|
1597
1743
|
}
|
|
1598
1744
|
},
|
|
1599
1745
|
[n$1.JSON_STRINGIFY]: {
|
|
1600
1746
|
stackIn: 1,
|
|
1601
1747
|
stackOut: 1,
|
|
1602
1748
|
execute: (e2) => {
|
|
1603
|
-
const r2 = e2.stack.pop(), t2 =
|
|
1749
|
+
const r2 = e2.stack.pop(), t2 = _(r2);
|
|
1604
1750
|
e2.stack.push(JSON.stringify(t2));
|
|
1605
1751
|
}
|
|
1606
1752
|
}
|
|
1607
1753
|
}, z = {
|
|
1754
|
+
...G,
|
|
1608
1755
|
...L,
|
|
1609
1756
|
...V,
|
|
1610
|
-
...M,
|
|
1611
|
-
...j,
|
|
1612
1757
|
...F,
|
|
1758
|
+
...j,
|
|
1613
1759
|
...D,
|
|
1614
1760
|
...q,
|
|
1761
|
+
...$$1,
|
|
1615
1762
|
...H,
|
|
1763
|
+
...J,
|
|
1616
1764
|
...Y,
|
|
1617
|
-
...$,
|
|
1618
1765
|
...B,
|
|
1619
|
-
...J,
|
|
1620
1766
|
...W
|
|
1621
1767
|
};
|
|
1622
|
-
class
|
|
1768
|
+
let x$1 = class x {
|
|
1623
1769
|
validateStack(r2, t2, s2) {
|
|
1624
1770
|
if (s2.stack.length < r2.stackIn)
|
|
1625
1771
|
return {
|
|
@@ -1647,9 +1793,9 @@ class N {
|
|
|
1647
1793
|
s2.status = "error", s2.error = a2.message;
|
|
1648
1794
|
break;
|
|
1649
1795
|
}
|
|
1650
|
-
if ((o2.op === n$1.JUMP || o2.op === n$1.JUMP_IF_FALSE || o2.op === n$1.BREAK || o2.op === n$1.CONTINUE) && o2.arg !== void 0 && o2.arg >= r2.length) {
|
|
1796
|
+
if ((o2.op === n$1.JUMP || o2.op === n$1.JUMP_IF_FALSE || o2.op === n$1.JUMP_IF || o2.op === n$1.JUMP_IF_TRUE || o2.op === n$1.BREAK || o2.op === n$1.CONTINUE) && o2.arg !== void 0 && o2.arg >= r2.length) {
|
|
1651
1797
|
s2.status = "error";
|
|
1652
|
-
const u2 = o2.op === n$1.JUMP || o2.op === n$1.JUMP_IF_FALSE ? "jump" : o2.op === n$1.BREAK ? "break" : "continue";
|
|
1798
|
+
const u2 = o2.op === n$1.JUMP || o2.op === n$1.JUMP_IF_FALSE || o2.op === n$1.JUMP_IF || o2.op === n$1.JUMP_IF_TRUE ? "jump" : o2.op === n$1.BREAK ? "break" : "continue";
|
|
1653
1799
|
s2.error = `Invalid ${u2} target: ${o2.arg}`;
|
|
1654
1800
|
break;
|
|
1655
1801
|
}
|
|
@@ -1690,15 +1836,15 @@ class N {
|
|
|
1690
1836
|
};
|
|
1691
1837
|
return this.execute(s2, o2);
|
|
1692
1838
|
}
|
|
1693
|
-
}
|
|
1694
|
-
class
|
|
1839
|
+
};
|
|
1840
|
+
class P {
|
|
1695
1841
|
constructor() {
|
|
1696
1842
|
h2(this, "sandboxPaths", []);
|
|
1697
1843
|
const r2 = process.env.CVM_SANDBOX_PATHS, t2 = process.env.CVM_SANDBOX_ROOT;
|
|
1698
|
-
r2 ? this.sandboxPaths = r2.split(",").map((s2) =>
|
|
1844
|
+
r2 ? this.sandboxPaths = r2.split(",").map((s2) => r__namespace.resolve(s2.trim())) : t2 && (this.sandboxPaths = [r__namespace.resolve(t2)]);
|
|
1699
1845
|
}
|
|
1700
1846
|
isPathAllowed(r2) {
|
|
1701
|
-
const t2 =
|
|
1847
|
+
const t2 = r__namespace.resolve(r2);
|
|
1702
1848
|
return t2.includes("..") || this.sandboxPaths.length === 0 ? false : this.sandboxPaths.some(
|
|
1703
1849
|
(s2) => t2.startsWith(s2)
|
|
1704
1850
|
);
|
|
@@ -1708,7 +1854,7 @@ class A2 {
|
|
|
1708
1854
|
if (!this.isPathAllowed(r2))
|
|
1709
1855
|
return s2;
|
|
1710
1856
|
try {
|
|
1711
|
-
const o2 =
|
|
1857
|
+
const o2 = r__namespace.resolve(r2);
|
|
1712
1858
|
this.listFilesRecursive(o2, o2, s2.elements, t2);
|
|
1713
1859
|
} catch {
|
|
1714
1860
|
}
|
|
@@ -1725,22 +1871,22 @@ class A2 {
|
|
|
1725
1871
|
}
|
|
1726
1872
|
listFilesRecursive(r2, t2, s2, o2, n2 = 0) {
|
|
1727
1873
|
try {
|
|
1728
|
-
const a2 =
|
|
1874
|
+
const a2 = M__namespace.readdirSync(t2, { withFileTypes: true });
|
|
1729
1875
|
for (const i2 of a2) {
|
|
1730
|
-
const u2 =
|
|
1731
|
-
i2.isSymbolicLink() || o2.filter && !this.matchesPattern(
|
|
1876
|
+
const u2 = r__namespace.join(t2, i2.name), O2 = r__namespace.relative(r2, u2);
|
|
1877
|
+
i2.isSymbolicLink() || o2.filter && !this.matchesPattern(O2, o2.filter) || (s2.push(u2), i2.isDirectory() && o2.recursive && this.listFilesRecursive(r2, u2, s2, o2, n2 + 1));
|
|
1732
1878
|
}
|
|
1733
1879
|
} catch {
|
|
1734
1880
|
}
|
|
1735
1881
|
}
|
|
1736
1882
|
}
|
|
1737
|
-
new
|
|
1883
|
+
new P();
|
|
1738
1884
|
class te {
|
|
1739
1885
|
constructor(r2, t2) {
|
|
1740
1886
|
h2(this, "vms", /* @__PURE__ */ new Map());
|
|
1741
1887
|
h2(this, "storage");
|
|
1742
1888
|
h2(this, "fileSystem");
|
|
1743
|
-
r2 ? this.storage = r2 : this.storage = g$1.create(), this.fileSystem = t2 || new
|
|
1889
|
+
r2 ? this.storage = r2 : this.storage = g$1.create(), this.fileSystem = t2 || new P();
|
|
1744
1890
|
}
|
|
1745
1891
|
/**
|
|
1746
1892
|
* Initialize the VMManager (connect to database)
|
|
@@ -1787,7 +1933,7 @@ class te {
|
|
|
1787
1933
|
created: /* @__PURE__ */ new Date()
|
|
1788
1934
|
};
|
|
1789
1935
|
await this.storage.saveExecution(o2);
|
|
1790
|
-
const n2 = new
|
|
1936
|
+
const n2 = new x$1();
|
|
1791
1937
|
this.vms.set(t2, n2);
|
|
1792
1938
|
}
|
|
1793
1939
|
/**
|
|
@@ -1803,7 +1949,7 @@ class te {
|
|
|
1803
1949
|
if (!s2)
|
|
1804
1950
|
throw new Error(`Program not found: ${t2.programId}`);
|
|
1805
1951
|
let o2 = this.vms.get(r2);
|
|
1806
|
-
o2 || (o2 = new
|
|
1952
|
+
o2 || (o2 = new x$1(), this.vms.set(r2, o2));
|
|
1807
1953
|
const n2 = {
|
|
1808
1954
|
pc: 0,
|
|
1809
1955
|
stack: [],
|
|
@@ -1870,7 +2016,7 @@ class te {
|
|
|
1870
2016
|
if (!o2)
|
|
1871
2017
|
throw new Error(`Program not found: ${s2.programId}`);
|
|
1872
2018
|
let n2 = this.vms.get(r2);
|
|
1873
|
-
n2 || (n2 = new
|
|
2019
|
+
n2 || (n2 = new x$1(), this.vms.set(r2, n2));
|
|
1874
2020
|
const a2 = {
|
|
1875
2021
|
pc: s2.pc,
|
|
1876
2022
|
stack: s2.stack,
|
|
@@ -1904,17 +2050,69 @@ class te {
|
|
|
1904
2050
|
async getExecutionOutput(r2) {
|
|
1905
2051
|
return await this.storage.getOutput(r2);
|
|
1906
2052
|
}
|
|
2053
|
+
/**
|
|
2054
|
+
* List all executions
|
|
2055
|
+
*/
|
|
2056
|
+
async listExecutions() {
|
|
2057
|
+
return await this.storage.listExecutions();
|
|
2058
|
+
}
|
|
2059
|
+
/**
|
|
2060
|
+
* Get current execution ID
|
|
2061
|
+
*/
|
|
2062
|
+
async getCurrentExecutionId() {
|
|
2063
|
+
return await this.storage.getCurrentExecutionId();
|
|
2064
|
+
}
|
|
2065
|
+
/**
|
|
2066
|
+
* Set current execution ID
|
|
2067
|
+
*/
|
|
2068
|
+
async setCurrentExecutionId(r2) {
|
|
2069
|
+
return await this.storage.setCurrentExecutionId(r2);
|
|
2070
|
+
}
|
|
2071
|
+
/**
|
|
2072
|
+
* Delete an execution
|
|
2073
|
+
*/
|
|
2074
|
+
async deleteExecution(r2) {
|
|
2075
|
+
return await this.storage.deleteExecution(r2);
|
|
2076
|
+
}
|
|
2077
|
+
/**
|
|
2078
|
+
* Get execution with attempt tracking
|
|
2079
|
+
*/
|
|
2080
|
+
async getExecutionWithAttempts(r2) {
|
|
2081
|
+
const t2 = await this.storage.getExecution(r2);
|
|
2082
|
+
if (!t2)
|
|
2083
|
+
throw new Error(`Execution not found: ${r2}`);
|
|
2084
|
+
return t2;
|
|
2085
|
+
}
|
|
2086
|
+
/**
|
|
2087
|
+
* List all programs
|
|
2088
|
+
*/
|
|
2089
|
+
async listPrograms() {
|
|
2090
|
+
return await this.storage.listPrograms();
|
|
2091
|
+
}
|
|
2092
|
+
/**
|
|
2093
|
+
* Delete a program
|
|
2094
|
+
*/
|
|
2095
|
+
async deleteProgram(r2) {
|
|
2096
|
+
return await this.storage.deleteProgram(r2);
|
|
2097
|
+
}
|
|
2098
|
+
/**
|
|
2099
|
+
* Restart a program (create new execution and set as current)
|
|
2100
|
+
*/
|
|
2101
|
+
async restartExecution(r2, t2) {
|
|
2102
|
+
const s2 = t2 || `${r2}-${Date.now()}`;
|
|
2103
|
+
return await this.startExecution(r2, s2), await this.setCurrentExecutionId(s2), s2;
|
|
2104
|
+
}
|
|
1907
2105
|
}
|
|
1908
|
-
var
|
|
1909
|
-
var
|
|
1910
|
-
var
|
|
1911
|
-
class
|
|
1912
|
-
constructor(
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
this.version =
|
|
2106
|
+
var u = Object.defineProperty;
|
|
2107
|
+
var x2 = (s2, e2, r2) => e2 in s2 ? u(s2, e2, { enumerable: true, configurable: true, writable: true, value: r2 }) : s2[e2] = r2;
|
|
2108
|
+
var i = (s2, e2, r2) => x2(s2, typeof e2 != "symbol" ? e2 + "" : e2, r2);
|
|
2109
|
+
class $ {
|
|
2110
|
+
constructor(e2 = "0.0.1") {
|
|
2111
|
+
i(this, "server");
|
|
2112
|
+
i(this, "transport", null);
|
|
2113
|
+
i(this, "vmManager");
|
|
2114
|
+
i(this, "version");
|
|
2115
|
+
this.version = e2, this.vmManager = new te(), this.server = new mcp_js.McpServer({
|
|
1918
2116
|
name: "cvm-server",
|
|
1919
2117
|
version: this.version
|
|
1920
2118
|
}), this.setupTools();
|
|
@@ -1932,14 +2130,14 @@ class w {
|
|
|
1932
2130
|
programId: zod.z.string(),
|
|
1933
2131
|
source: zod.z.string()
|
|
1934
2132
|
},
|
|
1935
|
-
async ({ programId:
|
|
2133
|
+
async ({ programId: e2, source: r2 }) => {
|
|
1936
2134
|
try {
|
|
1937
|
-
return await this.vmManager.loadProgram(
|
|
1938
|
-
content: [{ type: "text", text: `Program loaded successfully: ${
|
|
2135
|
+
return await this.vmManager.loadProgram(e2, r2), {
|
|
2136
|
+
content: [{ type: "text", text: `Program loaded successfully: ${e2}` }]
|
|
1939
2137
|
};
|
|
1940
|
-
} catch (
|
|
2138
|
+
} catch (t2) {
|
|
1941
2139
|
return {
|
|
1942
|
-
content: [{ type: "text", text: `Error: ${
|
|
2140
|
+
content: [{ type: "text", text: `Error: ${t2 instanceof Error ? t2.message : "Unknown error"}` }],
|
|
1943
2141
|
isError: true
|
|
1944
2142
|
};
|
|
1945
2143
|
}
|
|
@@ -1950,28 +2148,28 @@ class w {
|
|
|
1950
2148
|
programId: zod.z.string(),
|
|
1951
2149
|
filePath: zod.z.string()
|
|
1952
2150
|
},
|
|
1953
|
-
async ({ programId:
|
|
2151
|
+
async ({ programId: e2, filePath: r$1 }) => {
|
|
1954
2152
|
try {
|
|
1955
|
-
const
|
|
1956
|
-
return await this.vmManager.loadProgram(
|
|
1957
|
-
content: [{ type: "text", text: `Program loaded successfully from ${
|
|
2153
|
+
const t2 = r.resolve(r$1), n2 = await promises.readFile(t2, "utf-8");
|
|
2154
|
+
return await this.vmManager.loadProgram(e2, n2), {
|
|
2155
|
+
content: [{ type: "text", text: `Program loaded successfully from ${r$1}: ${e2}` }]
|
|
1958
2156
|
};
|
|
1959
|
-
} catch (
|
|
1960
|
-
if (
|
|
1961
|
-
const
|
|
1962
|
-
if (
|
|
2157
|
+
} catch (t2) {
|
|
2158
|
+
if (t2 instanceof Error) {
|
|
2159
|
+
const n2 = t2;
|
|
2160
|
+
if (n2.code === "ENOENT")
|
|
1963
2161
|
return {
|
|
1964
|
-
content: [{ type: "text", text: `Error: File not found: ${
|
|
2162
|
+
content: [{ type: "text", text: `Error: File not found: ${r$1}` }],
|
|
1965
2163
|
isError: true
|
|
1966
2164
|
};
|
|
1967
|
-
if (
|
|
2165
|
+
if (n2.code === "EACCES")
|
|
1968
2166
|
return {
|
|
1969
|
-
content: [{ type: "text", text: `Error: Permission denied: ${
|
|
2167
|
+
content: [{ type: "text", text: `Error: Permission denied: ${r$1}` }],
|
|
1970
2168
|
isError: true
|
|
1971
2169
|
};
|
|
1972
2170
|
}
|
|
1973
2171
|
return {
|
|
1974
|
-
content: [{ type: "text", text: `Error: ${
|
|
2172
|
+
content: [{ type: "text", text: `Error: ${t2 instanceof Error ? t2.message : "Unknown error"}` }],
|
|
1975
2173
|
isError: true
|
|
1976
2174
|
};
|
|
1977
2175
|
}
|
|
@@ -1980,16 +2178,17 @@ class w {
|
|
|
1980
2178
|
"start",
|
|
1981
2179
|
{
|
|
1982
2180
|
programId: zod.z.string(),
|
|
1983
|
-
executionId: zod.z.string()
|
|
2181
|
+
executionId: zod.z.string(),
|
|
2182
|
+
setCurrent: zod.z.boolean().optional()
|
|
1984
2183
|
},
|
|
1985
|
-
async ({ programId:
|
|
2184
|
+
async ({ programId: e2, executionId: r2, setCurrent: t2 = true }) => {
|
|
1986
2185
|
try {
|
|
1987
|
-
return await this.vmManager.startExecution(r2, t2), {
|
|
1988
|
-
content: [{ type: "text", text: `Execution started: ${t2}` }]
|
|
2186
|
+
return await this.vmManager.startExecution(e2, r2), t2 && await this.vmManager.setCurrentExecutionId(r2), {
|
|
2187
|
+
content: [{ type: "text", text: `Execution started: ${r2}${t2 ? " (set as current)" : ""}` }]
|
|
1989
2188
|
};
|
|
1990
|
-
} catch (
|
|
2189
|
+
} catch (n2) {
|
|
1991
2190
|
return {
|
|
1992
|
-
content: [{ type: "text", text: `Error: ${
|
|
2191
|
+
content: [{ type: "text", text: `Error: ${n2 instanceof Error ? n2.message : "Unknown error"}` }],
|
|
1993
2192
|
isError: true
|
|
1994
2193
|
};
|
|
1995
2194
|
}
|
|
@@ -1997,10 +2196,19 @@ class w {
|
|
|
1997
2196
|
), this.server.tool(
|
|
1998
2197
|
"getTask",
|
|
1999
2198
|
{
|
|
2000
|
-
executionId: zod.z.string()
|
|
2199
|
+
executionId: zod.z.string().optional()
|
|
2001
2200
|
},
|
|
2002
|
-
async ({ executionId:
|
|
2201
|
+
async ({ executionId: e2 }) => {
|
|
2003
2202
|
try {
|
|
2203
|
+
let r2 = e2;
|
|
2204
|
+
if (!r2) {
|
|
2205
|
+
const n2 = await this.vmManager.getCurrentExecutionId();
|
|
2206
|
+
if (!n2)
|
|
2207
|
+
return {
|
|
2208
|
+
content: [{ type: "text", text: "No current execution set. Use list_executions to see available executions." }]
|
|
2209
|
+
};
|
|
2210
|
+
r2 = n2;
|
|
2211
|
+
}
|
|
2004
2212
|
const t2 = await this.vmManager.getNext(r2);
|
|
2005
2213
|
return t2.type === "completed" ? {
|
|
2006
2214
|
content: [{ type: "text", text: t2.result !== void 0 ? `Execution completed with result: ${JSON.stringify(t2.result)}` : "Execution completed" }]
|
|
@@ -2013,9 +2221,9 @@ class w {
|
|
|
2013
2221
|
content: [{ type: "text", text: "Unexpected state" }],
|
|
2014
2222
|
isError: true
|
|
2015
2223
|
};
|
|
2016
|
-
} catch (
|
|
2224
|
+
} catch (r2) {
|
|
2017
2225
|
return {
|
|
2018
|
-
content: [{ type: "text", text: `Error: ${
|
|
2226
|
+
content: [{ type: "text", text: `Error: ${r2 instanceof Error ? r2.message : "Unknown error"}` }],
|
|
2019
2227
|
isError: true
|
|
2020
2228
|
};
|
|
2021
2229
|
}
|
|
@@ -2023,17 +2231,27 @@ class w {
|
|
|
2023
2231
|
), this.server.tool(
|
|
2024
2232
|
"submitTask",
|
|
2025
2233
|
{
|
|
2026
|
-
executionId: zod.z.string(),
|
|
2234
|
+
executionId: zod.z.string().optional(),
|
|
2027
2235
|
result: zod.z.string()
|
|
2028
2236
|
},
|
|
2029
|
-
async ({ executionId:
|
|
2237
|
+
async ({ executionId: e2, result: r2 }) => {
|
|
2030
2238
|
try {
|
|
2031
|
-
|
|
2239
|
+
let t2 = e2;
|
|
2240
|
+
if (!t2) {
|
|
2241
|
+
const n2 = await this.vmManager.getCurrentExecutionId();
|
|
2242
|
+
if (!n2)
|
|
2243
|
+
return {
|
|
2244
|
+
content: [{ type: "text", text: "Error: No current execution set" }],
|
|
2245
|
+
isError: true
|
|
2246
|
+
};
|
|
2247
|
+
t2 = n2;
|
|
2248
|
+
}
|
|
2249
|
+
return await this.vmManager.reportCCResult(t2, r2), {
|
|
2032
2250
|
content: [{ type: "text", text: "Execution resumed" }]
|
|
2033
2251
|
};
|
|
2034
|
-
} catch (
|
|
2252
|
+
} catch (t2) {
|
|
2035
2253
|
return {
|
|
2036
|
-
content: [{ type: "text", text: `Error: ${
|
|
2254
|
+
content: [{ type: "text", text: `Error: ${t2 instanceof Error ? t2.message : "Unknown error"}` }],
|
|
2037
2255
|
isError: true
|
|
2038
2256
|
};
|
|
2039
2257
|
}
|
|
@@ -2041,14 +2259,218 @@ class w {
|
|
|
2041
2259
|
), this.server.tool(
|
|
2042
2260
|
"status",
|
|
2043
2261
|
{
|
|
2044
|
-
executionId: zod.z.string()
|
|
2262
|
+
executionId: zod.z.string().optional()
|
|
2045
2263
|
},
|
|
2046
|
-
async ({ executionId:
|
|
2264
|
+
async ({ executionId: e2 }) => {
|
|
2047
2265
|
try {
|
|
2266
|
+
let r2 = e2;
|
|
2267
|
+
if (!r2) {
|
|
2268
|
+
const n2 = await this.vmManager.getCurrentExecutionId();
|
|
2269
|
+
if (!n2)
|
|
2270
|
+
return {
|
|
2271
|
+
content: [{ type: "text", text: "Error: No current execution set" }],
|
|
2272
|
+
isError: true
|
|
2273
|
+
};
|
|
2274
|
+
r2 = n2;
|
|
2275
|
+
}
|
|
2048
2276
|
const t2 = await this.vmManager.getExecutionStatus(r2);
|
|
2049
2277
|
return {
|
|
2050
2278
|
content: [{ type: "text", text: JSON.stringify(t2, null, 2) }]
|
|
2051
2279
|
};
|
|
2280
|
+
} catch (r2) {
|
|
2281
|
+
return {
|
|
2282
|
+
content: [{ type: "text", text: `Error: ${r2 instanceof Error ? r2.message : "Unknown error"}` }],
|
|
2283
|
+
isError: true
|
|
2284
|
+
};
|
|
2285
|
+
}
|
|
2286
|
+
}
|
|
2287
|
+
), this.server.tool(
|
|
2288
|
+
"list_executions",
|
|
2289
|
+
{},
|
|
2290
|
+
async () => {
|
|
2291
|
+
try {
|
|
2292
|
+
const e2 = await this.vmManager.listExecutions(), r2 = await this.vmManager.getCurrentExecutionId(), t2 = e2.map((n2) => ({
|
|
2293
|
+
executionId: n2.id,
|
|
2294
|
+
programId: n2.programId,
|
|
2295
|
+
state: n2.state,
|
|
2296
|
+
created: n2.created,
|
|
2297
|
+
isCurrent: n2.id === r2,
|
|
2298
|
+
summary: {
|
|
2299
|
+
currentPrompt: n2.state === "AWAITING_COGNITIVE_RESULT" ? n2.ccPrompt : void 0,
|
|
2300
|
+
tasksCompleted: 0
|
|
2301
|
+
// TODO: Track this in future
|
|
2302
|
+
}
|
|
2303
|
+
}));
|
|
2304
|
+
return {
|
|
2305
|
+
content: [{ type: "text", text: JSON.stringify(t2, null, 2) }]
|
|
2306
|
+
};
|
|
2307
|
+
} catch (e2) {
|
|
2308
|
+
return {
|
|
2309
|
+
content: [{ type: "text", text: `Error: ${e2 instanceof Error ? e2.message : "Unknown error"}` }],
|
|
2310
|
+
isError: true
|
|
2311
|
+
};
|
|
2312
|
+
}
|
|
2313
|
+
}
|
|
2314
|
+
), this.server.tool(
|
|
2315
|
+
"get_execution",
|
|
2316
|
+
{
|
|
2317
|
+
executionId: zod.z.string().optional()
|
|
2318
|
+
},
|
|
2319
|
+
async ({ executionId: e2 }) => {
|
|
2320
|
+
try {
|
|
2321
|
+
let r2 = e2;
|
|
2322
|
+
if (!r2) {
|
|
2323
|
+
const a2 = await this.vmManager.getCurrentExecutionId();
|
|
2324
|
+
if (!a2)
|
|
2325
|
+
return {
|
|
2326
|
+
content: [{ type: "text", text: "Error: No current execution set" }],
|
|
2327
|
+
isError: true
|
|
2328
|
+
};
|
|
2329
|
+
r2 = a2;
|
|
2330
|
+
}
|
|
2331
|
+
const t2 = await this.vmManager.getExecutionWithAttempts(r2), n2 = await this.vmManager.getCurrentExecutionId(), c2 = {
|
|
2332
|
+
executionId: t2.id,
|
|
2333
|
+
programId: t2.programId,
|
|
2334
|
+
state: t2.state,
|
|
2335
|
+
created: t2.created,
|
|
2336
|
+
isCurrent: t2.id === n2,
|
|
2337
|
+
currentTask: t2.state === "AWAITING_COGNITIVE_RESULT" ? {
|
|
2338
|
+
prompt: t2.ccPrompt,
|
|
2339
|
+
attempts: t2.attempts || 1,
|
|
2340
|
+
firstAttemptAt: t2.firstAttemptAt || t2.created,
|
|
2341
|
+
lastAttemptAt: t2.lastAttemptAt || t2.created
|
|
2342
|
+
} : void 0,
|
|
2343
|
+
variables: t2.variables,
|
|
2344
|
+
stats: {
|
|
2345
|
+
tasksCompleted: 0
|
|
2346
|
+
// TODO: Track this
|
|
2347
|
+
}
|
|
2348
|
+
};
|
|
2349
|
+
return {
|
|
2350
|
+
content: [{ type: "text", text: JSON.stringify(c2, null, 2) }]
|
|
2351
|
+
};
|
|
2352
|
+
} catch (r2) {
|
|
2353
|
+
return {
|
|
2354
|
+
content: [{ type: "text", text: `Error: ${r2 instanceof Error ? r2.message : "Unknown error"}` }],
|
|
2355
|
+
isError: true
|
|
2356
|
+
};
|
|
2357
|
+
}
|
|
2358
|
+
}
|
|
2359
|
+
), this.server.tool(
|
|
2360
|
+
"set_current",
|
|
2361
|
+
{
|
|
2362
|
+
executionId: zod.z.string()
|
|
2363
|
+
},
|
|
2364
|
+
async ({ executionId: e2 }) => {
|
|
2365
|
+
try {
|
|
2366
|
+
return await this.vmManager.setCurrentExecutionId(e2), {
|
|
2367
|
+
content: [{ type: "text", text: `Current execution set to: ${e2}` }]
|
|
2368
|
+
};
|
|
2369
|
+
} catch (r2) {
|
|
2370
|
+
return {
|
|
2371
|
+
content: [{ type: "text", text: `Error: ${r2 instanceof Error ? r2.message : "Unknown error"}` }],
|
|
2372
|
+
isError: true
|
|
2373
|
+
};
|
|
2374
|
+
}
|
|
2375
|
+
}
|
|
2376
|
+
), this.server.tool(
|
|
2377
|
+
"delete_execution",
|
|
2378
|
+
{
|
|
2379
|
+
executionId: zod.z.string(),
|
|
2380
|
+
confirmToken: zod.z.string().optional()
|
|
2381
|
+
},
|
|
2382
|
+
async ({ executionId: e2, confirmToken: r2 }) => {
|
|
2383
|
+
try {
|
|
2384
|
+
const t2 = `delete-${e2}-${Date.now()}`;
|
|
2385
|
+
return r2 ? r2 && r2.startsWith(`delete-${e2}-`) ? (await this.vmManager.deleteExecution(e2), {
|
|
2386
|
+
content: [{ type: "text", text: `Execution deleted: ${e2}` }]
|
|
2387
|
+
}) : {
|
|
2388
|
+
content: [{ type: "text", text: "Invalid confirmation token" }],
|
|
2389
|
+
isError: true
|
|
2390
|
+
} : {
|
|
2391
|
+
content: [{
|
|
2392
|
+
type: "text",
|
|
2393
|
+
text: JSON.stringify({
|
|
2394
|
+
confirmationRequired: true,
|
|
2395
|
+
message: `To delete execution '${e2}', call this tool again with the confirmation token`,
|
|
2396
|
+
token: t2
|
|
2397
|
+
}, null, 2)
|
|
2398
|
+
}]
|
|
2399
|
+
};
|
|
2400
|
+
} catch (t2) {
|
|
2401
|
+
return {
|
|
2402
|
+
content: [{ type: "text", text: `Error: ${t2 instanceof Error ? t2.message : "Unknown error"}` }],
|
|
2403
|
+
isError: true
|
|
2404
|
+
};
|
|
2405
|
+
}
|
|
2406
|
+
}
|
|
2407
|
+
), this.server.tool(
|
|
2408
|
+
"list_programs",
|
|
2409
|
+
{},
|
|
2410
|
+
async () => {
|
|
2411
|
+
try {
|
|
2412
|
+
const e2 = await this.vmManager.listPrograms();
|
|
2413
|
+
if (e2.length === 0)
|
|
2414
|
+
return {
|
|
2415
|
+
content: [{ type: "text", text: "No programs loaded" }]
|
|
2416
|
+
};
|
|
2417
|
+
const r2 = e2.map((t2) => ({
|
|
2418
|
+
programId: t2.id,
|
|
2419
|
+
name: t2.name,
|
|
2420
|
+
created: t2.created
|
|
2421
|
+
}));
|
|
2422
|
+
return {
|
|
2423
|
+
content: [{ type: "text", text: JSON.stringify(r2, null, 2) }]
|
|
2424
|
+
};
|
|
2425
|
+
} catch (e2) {
|
|
2426
|
+
return {
|
|
2427
|
+
content: [{ type: "text", text: `Error: ${e2 instanceof Error ? e2.message : "Unknown error"}` }],
|
|
2428
|
+
isError: true
|
|
2429
|
+
};
|
|
2430
|
+
}
|
|
2431
|
+
}
|
|
2432
|
+
), this.server.tool(
|
|
2433
|
+
"delete_program",
|
|
2434
|
+
{
|
|
2435
|
+
programId: zod.z.string(),
|
|
2436
|
+
confirmToken: zod.z.string().optional()
|
|
2437
|
+
},
|
|
2438
|
+
async ({ programId: e2, confirmToken: r2 }) => {
|
|
2439
|
+
try {
|
|
2440
|
+
const t2 = `delete-${e2}-${Date.now()}`;
|
|
2441
|
+
return r2 ? r2 && r2.startsWith(`delete-${e2}-`) ? (await this.vmManager.deleteProgram(e2), {
|
|
2442
|
+
content: [{ type: "text", text: `Program deleted: ${e2}` }]
|
|
2443
|
+
}) : {
|
|
2444
|
+
content: [{ type: "text", text: "Invalid confirmation token" }],
|
|
2445
|
+
isError: true
|
|
2446
|
+
} : {
|
|
2447
|
+
content: [{
|
|
2448
|
+
type: "text",
|
|
2449
|
+
text: JSON.stringify({
|
|
2450
|
+
confirmationRequired: true,
|
|
2451
|
+
message: `To delete program '${e2}', call this tool again with the confirmation token`,
|
|
2452
|
+
token: t2
|
|
2453
|
+
}, null, 2)
|
|
2454
|
+
}]
|
|
2455
|
+
};
|
|
2456
|
+
} catch (t2) {
|
|
2457
|
+
return {
|
|
2458
|
+
content: [{ type: "text", text: `Error: ${t2 instanceof Error ? t2.message : "Unknown error"}` }],
|
|
2459
|
+
isError: true
|
|
2460
|
+
};
|
|
2461
|
+
}
|
|
2462
|
+
}
|
|
2463
|
+
), this.server.tool(
|
|
2464
|
+
"restart",
|
|
2465
|
+
{
|
|
2466
|
+
programId: zod.z.string(),
|
|
2467
|
+
executionId: zod.z.string().optional()
|
|
2468
|
+
},
|
|
2469
|
+
async ({ programId: e2, executionId: r2 }) => {
|
|
2470
|
+
try {
|
|
2471
|
+
return {
|
|
2472
|
+
content: [{ type: "text", text: `Execution started: ${await this.vmManager.restartExecution(e2, r2)} (set as current)` }]
|
|
2473
|
+
};
|
|
2052
2474
|
} catch (t2) {
|
|
2053
2475
|
return {
|
|
2054
2476
|
content: [{ type: "text", text: `Error: ${t2 instanceof Error ? t2.message : "Unknown error"}` }],
|
|
@@ -2058,8 +2480,8 @@ class w {
|
|
|
2058
2480
|
}
|
|
2059
2481
|
);
|
|
2060
2482
|
}
|
|
2061
|
-
async start(
|
|
2062
|
-
await this.vmManager.initialize(), this.transport =
|
|
2483
|
+
async start(e2) {
|
|
2484
|
+
await this.vmManager.initialize(), this.transport = e2 || new stdio_js.StdioServerTransport(), await this.server.connect(this.transport);
|
|
2063
2485
|
}
|
|
2064
2486
|
async stop() {
|
|
2065
2487
|
this.transport && (await this.transport.close(), this.transport = null), await this.vmManager.dispose();
|
|
@@ -2069,7 +2491,7 @@ class w {
|
|
|
2069
2491
|
return this.vmManager;
|
|
2070
2492
|
}
|
|
2071
2493
|
}
|
|
2072
|
-
dotenv__namespace.config({ path:
|
|
2494
|
+
dotenv__namespace.config({ path: r.resolve(__dirname, "../../../.env") });
|
|
2073
2495
|
function loadConfig() {
|
|
2074
2496
|
const env = process.env.NODE_ENV || "development";
|
|
2075
2497
|
const storageType = process.env.CVM_STORAGE_TYPE || "file";
|
|
@@ -2150,7 +2572,7 @@ function getLogger() {
|
|
|
2150
2572
|
return logger;
|
|
2151
2573
|
}
|
|
2152
2574
|
const __filename$1 = url.fileURLToPath(typeof document === "undefined" ? require("url").pathToFileURL(__filename).href : _documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === "SCRIPT" && _documentCurrentScript.src || new URL("main.cjs", document.baseURI).href);
|
|
2153
|
-
const __dirname$1 =
|
|
2575
|
+
const __dirname$1 = r.dirname(__filename$1);
|
|
2154
2576
|
async function main() {
|
|
2155
2577
|
let cvmServer;
|
|
2156
2578
|
try {
|
|
@@ -2159,16 +2581,16 @@ async function main() {
|
|
|
2159
2581
|
const logger2 = getLogger();
|
|
2160
2582
|
let version = "0.4.3";
|
|
2161
2583
|
const possiblePaths = [
|
|
2162
|
-
|
|
2584
|
+
r.join(__dirname$1, "..", "package.json"),
|
|
2163
2585
|
// Development
|
|
2164
|
-
|
|
2586
|
+
r.join(__dirname$1, "package.json"),
|
|
2165
2587
|
// Bundled dist
|
|
2166
|
-
|
|
2588
|
+
r.join(process.cwd(), "package.json")
|
|
2167
2589
|
// Current directory
|
|
2168
2590
|
];
|
|
2169
2591
|
for (const packageJsonPath of possiblePaths) {
|
|
2170
2592
|
try {
|
|
2171
|
-
const packageJson = JSON.parse(
|
|
2593
|
+
const packageJson = JSON.parse(M$1.readFileSync(packageJsonPath, "utf-8"));
|
|
2172
2594
|
if (packageJson.name === "cvm-server" && packageJson.version) {
|
|
2173
2595
|
version = packageJson.version;
|
|
2174
2596
|
break;
|
|
@@ -2183,13 +2605,13 @@ async function main() {
|
|
|
2183
2605
|
});
|
|
2184
2606
|
if (config.storage.type === "file") {
|
|
2185
2607
|
const dataDir = config.storage.dataDir || ".cvm";
|
|
2186
|
-
const fullPath =
|
|
2608
|
+
const fullPath = r.resolve(process.cwd(), dataDir);
|
|
2187
2609
|
logger2.info(`[CVM] Initializing file storage in: ${fullPath}`);
|
|
2188
2610
|
logger2.warn(`[CVM] ⚠️ Remember to add '${dataDir}/' to your .gitignore file!`);
|
|
2189
2611
|
} else {
|
|
2190
2612
|
logger2.info("[CVM] Using MongoDB storage");
|
|
2191
2613
|
}
|
|
2192
|
-
cvmServer = new
|
|
2614
|
+
cvmServer = new $(version);
|
|
2193
2615
|
await cvmServer.start();
|
|
2194
2616
|
logger2.info("CVM Server is running and ready to accept MCP connections");
|
|
2195
2617
|
process.on("SIGINT", async () => {
|