cvm-server 0.1.0 → 0.2.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/README.md +7 -0
- package/dist/LICENSE +202 -0
- package/dist/README.md +83 -0
- package/dist/bin/cvm-server.js +17 -0
- package/dist/main.js +725 -0
- package/dist/package-lock.json +1202 -0
- package/dist/package.json +91 -0
- package/package.json +27 -31
- package/apps/cvm-server/src/config.d.ts +0 -18
- package/apps/cvm-server/src/config.d.ts.map +0 -1
- package/apps/cvm-server/src/config.js +0 -73
- package/apps/cvm-server/src/logger.d.ts +0 -13
- package/apps/cvm-server/src/logger.d.ts.map +0 -1
- package/apps/cvm-server/src/logger.js +0 -77
- package/apps/cvm-server/src/main.d.ts +0 -2
- package/apps/cvm-server/src/main.d.ts.map +0 -1
- package/apps/cvm-server/src/main.js +0 -57
- package/main.js +0 -44
- package/packages/mcp-server/src/index.js +0 -28
- package/packages/mcp-server/src/lib/mcp-server.js +0 -233
- package/packages/mongodb/src/index.js +0 -28
- package/packages/mongodb/src/lib/mongodb.js +0 -94
- package/packages/mongodb/src/lib/types.js +0 -16
- package/packages/parser/src/index.js +0 -26
- package/packages/parser/src/lib/bytecode.js +0 -42
- package/packages/parser/src/lib/compiler.js +0 -104
- package/packages/parser/src/lib/parser.js +0 -91
- package/packages/storage/src/index.js +0 -28
- package/packages/storage/src/lib/file-adapter.js +0 -113
- package/packages/storage/src/lib/mongodb-adapter.js +0 -94
- package/packages/storage/src/lib/storage-factory.js +0 -58
- package/packages/storage/src/lib/storage.js +0 -16
- package/packages/types/src/index.js +0 -22
- package/packages/types/src/lib/types.js +0 -16
- package/packages/vm/src/index.js +0 -24
- package/packages/vm/src/lib/vm-manager.js +0 -231
- package/packages/vm/src/lib/vm.js +0 -97
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var file_adapter_exports = {};
|
|
30
|
-
__export(file_adapter_exports, {
|
|
31
|
-
FileStorageAdapter: () => FileStorageAdapter
|
|
32
|
-
});
|
|
33
|
-
module.exports = __toCommonJS(file_adapter_exports);
|
|
34
|
-
var import_fs = require("fs");
|
|
35
|
-
var path = __toESM(require("path"), 1);
|
|
36
|
-
class FileStorageAdapter {
|
|
37
|
-
constructor(dataDir) {
|
|
38
|
-
this.dataDir = dataDir;
|
|
39
|
-
this.programsDir = path.join(dataDir, "programs");
|
|
40
|
-
this.executionsDir = path.join(dataDir, "executions");
|
|
41
|
-
}
|
|
42
|
-
connected = false;
|
|
43
|
-
programsDir;
|
|
44
|
-
executionsDir;
|
|
45
|
-
async connect() {
|
|
46
|
-
await import_fs.promises.mkdir(this.dataDir, { recursive: true });
|
|
47
|
-
await import_fs.promises.mkdir(this.programsDir, { recursive: true });
|
|
48
|
-
await import_fs.promises.mkdir(this.executionsDir, { recursive: true });
|
|
49
|
-
this.connected = true;
|
|
50
|
-
}
|
|
51
|
-
async disconnect() {
|
|
52
|
-
this.connected = false;
|
|
53
|
-
}
|
|
54
|
-
isConnected() {
|
|
55
|
-
return this.connected;
|
|
56
|
-
}
|
|
57
|
-
async saveProgram(program) {
|
|
58
|
-
if (!this.connected)
|
|
59
|
-
throw new Error("Not connected");
|
|
60
|
-
const filePath = path.join(this.programsDir, `${program.id}.json`);
|
|
61
|
-
const data = JSON.stringify(program, null, 2);
|
|
62
|
-
await import_fs.promises.writeFile(filePath, data, "utf-8");
|
|
63
|
-
}
|
|
64
|
-
async getProgram(id) {
|
|
65
|
-
if (!this.connected)
|
|
66
|
-
throw new Error("Not connected");
|
|
67
|
-
const filePath = path.join(this.programsDir, `${id}.json`);
|
|
68
|
-
try {
|
|
69
|
-
const data = await import_fs.promises.readFile(filePath, "utf-8");
|
|
70
|
-
const program = JSON.parse(data);
|
|
71
|
-
program.created = new Date(program.created);
|
|
72
|
-
if (program.updated) {
|
|
73
|
-
program.updated = new Date(program.updated);
|
|
74
|
-
}
|
|
75
|
-
return program;
|
|
76
|
-
} catch (error) {
|
|
77
|
-
if (error.code === "ENOENT") {
|
|
78
|
-
return null;
|
|
79
|
-
}
|
|
80
|
-
throw error;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
async saveExecution(execution) {
|
|
84
|
-
if (!this.connected)
|
|
85
|
-
throw new Error("Not connected");
|
|
86
|
-
const filePath = path.join(this.executionsDir, `${execution.id}.json`);
|
|
87
|
-
const data = JSON.stringify(execution, null, 2);
|
|
88
|
-
await import_fs.promises.writeFile(filePath, data, "utf-8");
|
|
89
|
-
}
|
|
90
|
-
async getExecution(id) {
|
|
91
|
-
if (!this.connected)
|
|
92
|
-
throw new Error("Not connected");
|
|
93
|
-
const filePath = path.join(this.executionsDir, `${id}.json`);
|
|
94
|
-
try {
|
|
95
|
-
const data = await import_fs.promises.readFile(filePath, "utf-8");
|
|
96
|
-
const execution = JSON.parse(data);
|
|
97
|
-
execution.created = new Date(execution.created);
|
|
98
|
-
if (execution.updated) {
|
|
99
|
-
execution.updated = new Date(execution.updated);
|
|
100
|
-
}
|
|
101
|
-
return execution;
|
|
102
|
-
} catch (error) {
|
|
103
|
-
if (error.code === "ENOENT") {
|
|
104
|
-
return null;
|
|
105
|
-
}
|
|
106
|
-
throw error;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
111
|
-
0 && (module.exports = {
|
|
112
|
-
FileStorageAdapter
|
|
113
|
-
});
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var mongodb_adapter_exports = {};
|
|
20
|
-
__export(mongodb_adapter_exports, {
|
|
21
|
-
MongoDBAdapter: () => MongoDBAdapter
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(mongodb_adapter_exports);
|
|
24
|
-
var import_mongodb = require("mongodb");
|
|
25
|
-
class MongoDBAdapter {
|
|
26
|
-
constructor(connectionString) {
|
|
27
|
-
this.connectionString = connectionString;
|
|
28
|
-
this.client = new import_mongodb.MongoClient(connectionString);
|
|
29
|
-
}
|
|
30
|
-
client;
|
|
31
|
-
db = null;
|
|
32
|
-
connected = false;
|
|
33
|
-
async connect() {
|
|
34
|
-
await this.client.connect();
|
|
35
|
-
const dbName = this.connectionString.split("/").pop()?.split("?")[0] || "cvm";
|
|
36
|
-
this.db = this.client.db(dbName);
|
|
37
|
-
this.connected = true;
|
|
38
|
-
const collections = await this.db.listCollections().toArray();
|
|
39
|
-
const collectionNames = collections.map((c) => c.name);
|
|
40
|
-
if (!collectionNames.includes("programs")) {
|
|
41
|
-
await this.db.createCollection("programs");
|
|
42
|
-
}
|
|
43
|
-
if (!collectionNames.includes("executions")) {
|
|
44
|
-
await this.db.createCollection("executions");
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
async disconnect() {
|
|
48
|
-
await this.client.close();
|
|
49
|
-
this.connected = false;
|
|
50
|
-
this.db = null;
|
|
51
|
-
}
|
|
52
|
-
isConnected() {
|
|
53
|
-
return this.connected;
|
|
54
|
-
}
|
|
55
|
-
async getCollections() {
|
|
56
|
-
if (!this.db)
|
|
57
|
-
throw new Error("Not connected to database");
|
|
58
|
-
const collections = await this.db.listCollections().toArray();
|
|
59
|
-
return collections.map((c) => c.name);
|
|
60
|
-
}
|
|
61
|
-
getCollection(name) {
|
|
62
|
-
if (!this.db)
|
|
63
|
-
throw new Error("Not connected to database");
|
|
64
|
-
return this.db.collection(name);
|
|
65
|
-
}
|
|
66
|
-
async saveProgram(program) {
|
|
67
|
-
const collection = this.getCollection("programs");
|
|
68
|
-
await collection.replaceOne(
|
|
69
|
-
{ id: program.id },
|
|
70
|
-
program,
|
|
71
|
-
{ upsert: true }
|
|
72
|
-
);
|
|
73
|
-
}
|
|
74
|
-
async getProgram(id) {
|
|
75
|
-
const collection = this.getCollection("programs");
|
|
76
|
-
return await collection.findOne({ id });
|
|
77
|
-
}
|
|
78
|
-
async saveExecution(execution) {
|
|
79
|
-
const collection = this.getCollection("executions");
|
|
80
|
-
await collection.replaceOne(
|
|
81
|
-
{ id: execution.id },
|
|
82
|
-
execution,
|
|
83
|
-
{ upsert: true }
|
|
84
|
-
);
|
|
85
|
-
}
|
|
86
|
-
async getExecution(id) {
|
|
87
|
-
const collection = this.getCollection("executions");
|
|
88
|
-
return await collection.findOne({ id });
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
92
|
-
0 && (module.exports = {
|
|
93
|
-
MongoDBAdapter
|
|
94
|
-
});
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var storage_factory_exports = {};
|
|
30
|
-
__export(storage_factory_exports, {
|
|
31
|
-
StorageFactory: () => StorageFactory
|
|
32
|
-
});
|
|
33
|
-
module.exports = __toCommonJS(storage_factory_exports);
|
|
34
|
-
var import_file_adapter = require("./file-adapter.js");
|
|
35
|
-
var import_mongodb_adapter = require("./mongodb-adapter.js");
|
|
36
|
-
var os = __toESM(require("os"), 1);
|
|
37
|
-
var path = __toESM(require("path"), 1);
|
|
38
|
-
class StorageFactory {
|
|
39
|
-
static create(config) {
|
|
40
|
-
const type = config?.type || process.env.CVM_STORAGE_TYPE || "file";
|
|
41
|
-
switch (type) {
|
|
42
|
-
case "file": {
|
|
43
|
-
const dataDir = config?.dataDir || process.env.CVM_DATA_DIR || path.join(os.homedir(), ".cvm");
|
|
44
|
-
return new import_file_adapter.FileStorageAdapter(dataDir);
|
|
45
|
-
}
|
|
46
|
-
case "mongodb": {
|
|
47
|
-
const mongoUri = config?.mongoUri || process.env.MONGODB_URI || "mongodb://localhost:27017/cvm";
|
|
48
|
-
return new import_mongodb_adapter.MongoDBAdapter(mongoUri);
|
|
49
|
-
}
|
|
50
|
-
default:
|
|
51
|
-
throw new Error(`Unsupported storage type: ${type}`);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
56
|
-
0 && (module.exports = {
|
|
57
|
-
StorageFactory
|
|
58
|
-
});
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __copyProps = (to, from, except, desc) => {
|
|
7
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
-
for (let key of __getOwnPropNames(from))
|
|
9
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
-
}
|
|
12
|
-
return to;
|
|
13
|
-
};
|
|
14
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
-
var storage_exports = {};
|
|
16
|
-
module.exports = __toCommonJS(storage_exports);
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __copyProps = (to, from, except, desc) => {
|
|
7
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
-
for (let key of __getOwnPropNames(from))
|
|
9
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
-
}
|
|
12
|
-
return to;
|
|
13
|
-
};
|
|
14
|
-
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
-
var src_exports = {};
|
|
17
|
-
module.exports = __toCommonJS(src_exports);
|
|
18
|
-
__reExport(src_exports, require("./lib/types.js"), module.exports);
|
|
19
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
20
|
-
0 && (module.exports = {
|
|
21
|
-
...require("./lib/types.js")
|
|
22
|
-
});
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __copyProps = (to, from, except, desc) => {
|
|
7
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
-
for (let key of __getOwnPropNames(from))
|
|
9
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
-
}
|
|
12
|
-
return to;
|
|
13
|
-
};
|
|
14
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
-
var types_exports = {};
|
|
16
|
-
module.exports = __toCommonJS(types_exports);
|
package/packages/vm/src/index.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __copyProps = (to, from, except, desc) => {
|
|
7
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
-
for (let key of __getOwnPropNames(from))
|
|
9
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
-
}
|
|
12
|
-
return to;
|
|
13
|
-
};
|
|
14
|
-
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
-
var src_exports = {};
|
|
17
|
-
module.exports = __toCommonJS(src_exports);
|
|
18
|
-
__reExport(src_exports, require("./lib/vm.js"), module.exports);
|
|
19
|
-
__reExport(src_exports, require("./lib/vm-manager.js"), module.exports);
|
|
20
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
21
|
-
0 && (module.exports = {
|
|
22
|
-
...require("./lib/vm.js"),
|
|
23
|
-
...require("./lib/vm-manager.js")
|
|
24
|
-
});
|
|
@@ -1,231 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var vm_manager_exports = {};
|
|
20
|
-
__export(vm_manager_exports, {
|
|
21
|
-
VMManager: () => VMManager
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(vm_manager_exports);
|
|
24
|
-
var import_vm = require("./vm.js");
|
|
25
|
-
var import_parser = require("@cvm/parser");
|
|
26
|
-
var import_storage = require("@cvm/storage");
|
|
27
|
-
class VMManager {
|
|
28
|
-
vms = /* @__PURE__ */ new Map();
|
|
29
|
-
storage;
|
|
30
|
-
constructor(storageAdapter) {
|
|
31
|
-
if (storageAdapter) {
|
|
32
|
-
this.storage = storageAdapter;
|
|
33
|
-
} else {
|
|
34
|
-
this.storage = import_storage.StorageFactory.create();
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Initialize the VMManager (connect to database)
|
|
39
|
-
*/
|
|
40
|
-
async initialize() {
|
|
41
|
-
await this.storage.connect();
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Cleanup resources
|
|
45
|
-
*/
|
|
46
|
-
async dispose() {
|
|
47
|
-
await this.storage.disconnect();
|
|
48
|
-
this.vms.clear();
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Load and compile a program from source code
|
|
52
|
-
*/
|
|
53
|
-
async loadProgram(programId, source) {
|
|
54
|
-
const compileResult = (0, import_parser.compile)(source);
|
|
55
|
-
if (!compileResult.success) {
|
|
56
|
-
throw new Error(`Compilation failed: ${compileResult.errors.join(", ")}`);
|
|
57
|
-
}
|
|
58
|
-
const program = {
|
|
59
|
-
id: programId,
|
|
60
|
-
name: programId,
|
|
61
|
-
source,
|
|
62
|
-
bytecode: compileResult.bytecode,
|
|
63
|
-
// VM decides internal format
|
|
64
|
-
created: /* @__PURE__ */ new Date()
|
|
65
|
-
};
|
|
66
|
-
await this.storage.saveProgram(program);
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Start execution of a loaded program
|
|
70
|
-
*/
|
|
71
|
-
async startExecution(programId, executionId) {
|
|
72
|
-
const program = await this.storage.getProgram(programId);
|
|
73
|
-
if (!program) {
|
|
74
|
-
throw new Error(`Program not found: ${programId}`);
|
|
75
|
-
}
|
|
76
|
-
const execution = {
|
|
77
|
-
id: executionId,
|
|
78
|
-
programId,
|
|
79
|
-
state: "ready",
|
|
80
|
-
pc: 0,
|
|
81
|
-
stack: [],
|
|
82
|
-
variables: {},
|
|
83
|
-
output: [],
|
|
84
|
-
created: /* @__PURE__ */ new Date()
|
|
85
|
-
};
|
|
86
|
-
await this.storage.saveExecution(execution);
|
|
87
|
-
const vm = new import_vm.VM();
|
|
88
|
-
this.vms.set(executionId, vm);
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Get next action from execution (Claude polls this)
|
|
92
|
-
* This is READ-ONLY - just returns current state
|
|
93
|
-
*/
|
|
94
|
-
async getNext(executionId) {
|
|
95
|
-
const execution = await this.storage.getExecution(executionId);
|
|
96
|
-
if (!execution) {
|
|
97
|
-
throw new Error(`Execution not found: ${executionId}`);
|
|
98
|
-
}
|
|
99
|
-
if (execution.state === "ready") {
|
|
100
|
-
const program = await this.storage.getProgram(execution.programId);
|
|
101
|
-
if (!program) {
|
|
102
|
-
throw new Error(`Program not found: ${execution.programId}`);
|
|
103
|
-
}
|
|
104
|
-
let vm = this.vms.get(executionId);
|
|
105
|
-
if (!vm) {
|
|
106
|
-
vm = new import_vm.VM();
|
|
107
|
-
this.vms.set(executionId, vm);
|
|
108
|
-
}
|
|
109
|
-
const initialState = {
|
|
110
|
-
pc: 0,
|
|
111
|
-
stack: [],
|
|
112
|
-
variables: /* @__PURE__ */ new Map(),
|
|
113
|
-
output: []
|
|
114
|
-
};
|
|
115
|
-
const state = vm.execute(program.bytecode, initialState);
|
|
116
|
-
execution.pc = state.pc;
|
|
117
|
-
execution.stack = state.stack;
|
|
118
|
-
execution.variables = Object.fromEntries(state.variables);
|
|
119
|
-
execution.output = state.output;
|
|
120
|
-
if (state.status === "complete") {
|
|
121
|
-
execution.state = "completed";
|
|
122
|
-
await this.storage.saveExecution(execution);
|
|
123
|
-
this.vms.delete(executionId);
|
|
124
|
-
return {
|
|
125
|
-
type: "completed",
|
|
126
|
-
message: "Execution completed"
|
|
127
|
-
};
|
|
128
|
-
} else if (state.status === "waiting_cc") {
|
|
129
|
-
execution.state = "waiting_cc";
|
|
130
|
-
execution.ccPrompt = state.ccPrompt;
|
|
131
|
-
await this.storage.saveExecution(execution);
|
|
132
|
-
return {
|
|
133
|
-
type: "waiting",
|
|
134
|
-
message: state.ccPrompt || "Waiting for input"
|
|
135
|
-
};
|
|
136
|
-
} else if (state.status === "error") {
|
|
137
|
-
execution.state = "error";
|
|
138
|
-
execution.error = state.error;
|
|
139
|
-
await this.storage.saveExecution(execution);
|
|
140
|
-
this.vms.delete(executionId);
|
|
141
|
-
return {
|
|
142
|
-
type: "error",
|
|
143
|
-
error: state.error
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
if (execution.state === "completed") {
|
|
148
|
-
return {
|
|
149
|
-
type: "completed",
|
|
150
|
-
message: "Execution completed"
|
|
151
|
-
};
|
|
152
|
-
} else if (execution.state === "error") {
|
|
153
|
-
return {
|
|
154
|
-
type: "error",
|
|
155
|
-
error: execution.error || "Unknown error"
|
|
156
|
-
};
|
|
157
|
-
} else if (execution.state === "waiting_cc") {
|
|
158
|
-
return {
|
|
159
|
-
type: "waiting",
|
|
160
|
-
message: execution.ccPrompt || "Waiting for input"
|
|
161
|
-
};
|
|
162
|
-
}
|
|
163
|
-
throw new Error(`Unexpected execution state: ${execution.state}`);
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
* Report result from cognitive operation and continue execution
|
|
167
|
-
*/
|
|
168
|
-
async reportCCResult(executionId, result) {
|
|
169
|
-
const execution = await this.storage.getExecution(executionId);
|
|
170
|
-
if (!execution) {
|
|
171
|
-
throw new Error(`Execution not found: ${executionId}`);
|
|
172
|
-
}
|
|
173
|
-
const program = await this.storage.getProgram(execution.programId);
|
|
174
|
-
if (!program) {
|
|
175
|
-
throw new Error(`Program not found: ${execution.programId}`);
|
|
176
|
-
}
|
|
177
|
-
let vm = this.vms.get(executionId);
|
|
178
|
-
if (!vm) {
|
|
179
|
-
vm = new import_vm.VM();
|
|
180
|
-
this.vms.set(executionId, vm);
|
|
181
|
-
}
|
|
182
|
-
const currentState = {
|
|
183
|
-
pc: execution.pc,
|
|
184
|
-
stack: execution.stack,
|
|
185
|
-
variables: new Map(Object.entries(execution.variables)),
|
|
186
|
-
status: "waiting_cc",
|
|
187
|
-
output: execution.output,
|
|
188
|
-
ccPrompt: void 0
|
|
189
|
-
};
|
|
190
|
-
const newState = vm.resume(currentState, result, program.bytecode);
|
|
191
|
-
execution.pc = newState.pc;
|
|
192
|
-
execution.stack = newState.stack;
|
|
193
|
-
execution.variables = Object.fromEntries(newState.variables);
|
|
194
|
-
execution.output = newState.output;
|
|
195
|
-
if (newState.status === "complete") {
|
|
196
|
-
execution.state = "completed";
|
|
197
|
-
this.vms.delete(executionId);
|
|
198
|
-
} else if (newState.status === "error") {
|
|
199
|
-
execution.state = "error";
|
|
200
|
-
execution.error = newState.error;
|
|
201
|
-
this.vms.delete(executionId);
|
|
202
|
-
} else if (newState.status === "waiting_cc") {
|
|
203
|
-
execution.state = "waiting_cc";
|
|
204
|
-
execution.ccPrompt = newState.ccPrompt;
|
|
205
|
-
} else {
|
|
206
|
-
execution.state = "running";
|
|
207
|
-
}
|
|
208
|
-
await this.storage.saveExecution(execution);
|
|
209
|
-
}
|
|
210
|
-
/**
|
|
211
|
-
* Get current execution status
|
|
212
|
-
*/
|
|
213
|
-
async getExecutionStatus(executionId) {
|
|
214
|
-
const execution = await this.storage.getExecution(executionId);
|
|
215
|
-
if (!execution) {
|
|
216
|
-
throw new Error(`Execution not found: ${executionId}`);
|
|
217
|
-
}
|
|
218
|
-
return {
|
|
219
|
-
id: execution.id,
|
|
220
|
-
state: execution.state,
|
|
221
|
-
pc: execution.pc,
|
|
222
|
-
stack: execution.stack,
|
|
223
|
-
variables: execution.variables,
|
|
224
|
-
output: execution.output
|
|
225
|
-
};
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
229
|
-
0 && (module.exports = {
|
|
230
|
-
VMManager
|
|
231
|
-
});
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var vm_exports = {};
|
|
20
|
-
__export(vm_exports, {
|
|
21
|
-
VM: () => VM
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(vm_exports);
|
|
24
|
-
var import_parser = require("@cvm/parser");
|
|
25
|
-
class VM {
|
|
26
|
-
execute(bytecode, initialState) {
|
|
27
|
-
const state = {
|
|
28
|
-
pc: initialState?.pc ?? 0,
|
|
29
|
-
stack: initialState?.stack ?? [],
|
|
30
|
-
variables: initialState?.variables ?? /* @__PURE__ */ new Map(),
|
|
31
|
-
status: "running",
|
|
32
|
-
output: initialState?.output ?? [],
|
|
33
|
-
...initialState
|
|
34
|
-
};
|
|
35
|
-
while (state.status === "running" && state.pc < bytecode.length) {
|
|
36
|
-
const instruction = bytecode[state.pc];
|
|
37
|
-
switch (instruction.op) {
|
|
38
|
-
case import_parser.OpCode.HALT:
|
|
39
|
-
state.status = "complete";
|
|
40
|
-
break;
|
|
41
|
-
case import_parser.OpCode.PUSH:
|
|
42
|
-
state.stack.push(instruction.arg);
|
|
43
|
-
state.pc++;
|
|
44
|
-
break;
|
|
45
|
-
case import_parser.OpCode.POP:
|
|
46
|
-
state.stack.pop();
|
|
47
|
-
state.pc++;
|
|
48
|
-
break;
|
|
49
|
-
case import_parser.OpCode.LOAD:
|
|
50
|
-
state.stack.push(state.variables.get(instruction.arg) ?? "");
|
|
51
|
-
state.pc++;
|
|
52
|
-
break;
|
|
53
|
-
case import_parser.OpCode.STORE:
|
|
54
|
-
const value = state.stack.pop();
|
|
55
|
-
state.variables.set(instruction.arg, value);
|
|
56
|
-
state.pc++;
|
|
57
|
-
break;
|
|
58
|
-
case import_parser.OpCode.CONCAT:
|
|
59
|
-
const b = state.stack.pop();
|
|
60
|
-
const a = state.stack.pop();
|
|
61
|
-
state.stack.push(a + b);
|
|
62
|
-
state.pc++;
|
|
63
|
-
break;
|
|
64
|
-
case import_parser.OpCode.PRINT:
|
|
65
|
-
const printValue = state.stack.pop();
|
|
66
|
-
state.output.push(printValue);
|
|
67
|
-
state.pc++;
|
|
68
|
-
break;
|
|
69
|
-
case import_parser.OpCode.CC:
|
|
70
|
-
state.ccPrompt = state.stack.pop();
|
|
71
|
-
state.status = "waiting_cc";
|
|
72
|
-
break;
|
|
73
|
-
default:
|
|
74
|
-
state.status = "error";
|
|
75
|
-
state.error = `Unknown opcode: ${instruction.op}`;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
return state;
|
|
79
|
-
}
|
|
80
|
-
resume(state, ccResult, bytecode) {
|
|
81
|
-
if (state.status !== "waiting_cc") {
|
|
82
|
-
throw new Error("Cannot resume: VM not waiting for CC");
|
|
83
|
-
}
|
|
84
|
-
const newState = {
|
|
85
|
-
...state,
|
|
86
|
-
stack: [...state.stack, ccResult],
|
|
87
|
-
status: "running",
|
|
88
|
-
ccPrompt: void 0,
|
|
89
|
-
pc: state.pc + 1
|
|
90
|
-
};
|
|
91
|
-
return this.execute(bytecode, newState);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
95
|
-
0 && (module.exports = {
|
|
96
|
-
VM
|
|
97
|
-
});
|