cvm-server 0.1.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/LICENSE +202 -0
- package/README.md +83 -0
- package/apps/cvm-server/src/config.d.ts +18 -0
- package/apps/cvm-server/src/config.d.ts.map +1 -0
- package/apps/cvm-server/src/config.js +73 -0
- package/apps/cvm-server/src/logger.d.ts +13 -0
- package/apps/cvm-server/src/logger.d.ts.map +1 -0
- package/apps/cvm-server/src/logger.js +77 -0
- package/apps/cvm-server/src/main.d.ts +2 -0
- package/apps/cvm-server/src/main.d.ts.map +1 -0
- package/apps/cvm-server/src/main.js +57 -0
- package/bin/cvm-server.js +17 -0
- package/main.js +44 -0
- package/package.json +94 -0
- package/packages/mcp-server/src/index.js +28 -0
- package/packages/mcp-server/src/lib/mcp-server.js +233 -0
- package/packages/mongodb/src/index.js +28 -0
- package/packages/mongodb/src/lib/mongodb.js +94 -0
- package/packages/mongodb/src/lib/types.js +16 -0
- package/packages/parser/src/index.js +26 -0
- package/packages/parser/src/lib/bytecode.js +42 -0
- package/packages/parser/src/lib/compiler.js +104 -0
- package/packages/parser/src/lib/parser.js +91 -0
- package/packages/storage/src/index.js +28 -0
- package/packages/storage/src/lib/file-adapter.js +113 -0
- package/packages/storage/src/lib/mongodb-adapter.js +94 -0
- package/packages/storage/src/lib/storage-factory.js +58 -0
- package/packages/storage/src/lib/storage.js +16 -0
- package/packages/types/src/index.js +22 -0
- package/packages/types/src/lib/types.js +16 -0
- package/packages/vm/src/index.js +24 -0
- package/packages/vm/src/lib/vm-manager.js +231 -0
- package/packages/vm/src/lib/vm.js +97 -0
package/package.json
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "cvm-server",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Cognitive Virtual Machine (CVM) - A deterministic bytecode VM with AI cognitive operations",
|
|
5
|
+
"keywords": ["mcp", "ai", "vm", "cognitive", "bytecode", "virtual-machine", "claude"],
|
|
6
|
+
"author": "Ladislav Sopko",
|
|
7
|
+
"license": "Apache-2.0",
|
|
8
|
+
"homepage": "https://github.com/LadislavSopko/cvm#readme",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/LadislavSopko/cvm.git"
|
|
12
|
+
},
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/LadislavSopko/cvm/issues"
|
|
15
|
+
},
|
|
16
|
+
"bin": {
|
|
17
|
+
"cvm-server": "./bin/cvm-server.js"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"bin",
|
|
21
|
+
"main.js",
|
|
22
|
+
"apps",
|
|
23
|
+
"packages",
|
|
24
|
+
"README.md",
|
|
25
|
+
"LICENSE"
|
|
26
|
+
],
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": ">=18.0.0"
|
|
29
|
+
},
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"access": "public"
|
|
32
|
+
},
|
|
33
|
+
"nx": {
|
|
34
|
+
"targets": {
|
|
35
|
+
"build": {
|
|
36
|
+
"executor": "@nx/esbuild:esbuild",
|
|
37
|
+
"outputs": [
|
|
38
|
+
"{options.outputPath}"
|
|
39
|
+
],
|
|
40
|
+
"defaultConfiguration": "production",
|
|
41
|
+
"options": {
|
|
42
|
+
"platform": "node",
|
|
43
|
+
"outputPath": "apps/cvm-server/dist",
|
|
44
|
+
"format": [
|
|
45
|
+
"cjs"
|
|
46
|
+
],
|
|
47
|
+
"bundle": false,
|
|
48
|
+
"main": "apps/cvm-server/src/main.ts",
|
|
49
|
+
"tsConfig": "apps/cvm-server/tsconfig.app.json",
|
|
50
|
+
"assets": [
|
|
51
|
+
"apps/cvm-server/src/assets"
|
|
52
|
+
],
|
|
53
|
+
"esbuildOptions": {
|
|
54
|
+
"sourcemap": true,
|
|
55
|
+
"outExtension": {
|
|
56
|
+
".js": ".js"
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
"configurations": {
|
|
61
|
+
"development": {},
|
|
62
|
+
"production": {
|
|
63
|
+
"esbuildOptions": {
|
|
64
|
+
"sourcemap": false,
|
|
65
|
+
"outExtension": {
|
|
66
|
+
".js": ".js"
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
"serve": {
|
|
73
|
+
"continuous": true,
|
|
74
|
+
"executor": "@nx/js:node",
|
|
75
|
+
"defaultConfiguration": "development",
|
|
76
|
+
"dependsOn": [
|
|
77
|
+
"build"
|
|
78
|
+
],
|
|
79
|
+
"options": {
|
|
80
|
+
"buildTarget": "@cvm/cvm-server:build",
|
|
81
|
+
"runBuildTargetDependencies": false
|
|
82
|
+
},
|
|
83
|
+
"configurations": {
|
|
84
|
+
"development": {
|
|
85
|
+
"buildTarget": "@cvm/cvm-server:build:development"
|
|
86
|
+
},
|
|
87
|
+
"production": {
|
|
88
|
+
"buildTarget": "@cvm/cvm-server:build:production"
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
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 src_exports = {};
|
|
20
|
+
__export(src_exports, {
|
|
21
|
+
CVMMcpServer: () => import_mcp_server.CVMMcpServer
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(src_exports);
|
|
24
|
+
var import_mcp_server = require("./lib/mcp-server.js");
|
|
25
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
26
|
+
0 && (module.exports = {
|
|
27
|
+
CVMMcpServer
|
|
28
|
+
});
|
|
@@ -0,0 +1,233 @@
|
|
|
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 mcp_server_exports = {};
|
|
20
|
+
__export(mcp_server_exports, {
|
|
21
|
+
CVMMcpServer: () => CVMMcpServer
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(mcp_server_exports);
|
|
24
|
+
var import_mcp = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
25
|
+
var import_stdio = require("@modelcontextprotocol/sdk/server/stdio.js");
|
|
26
|
+
var import_zod = require("zod");
|
|
27
|
+
var import_vm = require("@cvm/vm");
|
|
28
|
+
class CVMMcpServer {
|
|
29
|
+
server;
|
|
30
|
+
transport = null;
|
|
31
|
+
vmManager;
|
|
32
|
+
constructor() {
|
|
33
|
+
this.vmManager = new import_vm.VMManager();
|
|
34
|
+
this.server = new import_mcp.McpServer({
|
|
35
|
+
name: "cvm-server",
|
|
36
|
+
version: "1.0.0"
|
|
37
|
+
});
|
|
38
|
+
this.setupTools();
|
|
39
|
+
}
|
|
40
|
+
getName() {
|
|
41
|
+
return "cvm-server";
|
|
42
|
+
}
|
|
43
|
+
getVersion() {
|
|
44
|
+
return "1.0.0";
|
|
45
|
+
}
|
|
46
|
+
setupTools() {
|
|
47
|
+
this.server.tool(
|
|
48
|
+
"loadProgram",
|
|
49
|
+
{
|
|
50
|
+
programId: import_zod.z.string(),
|
|
51
|
+
source: import_zod.z.string()
|
|
52
|
+
},
|
|
53
|
+
async ({ programId, source }) => {
|
|
54
|
+
try {
|
|
55
|
+
await this.vmManager.loadProgram(programId, source);
|
|
56
|
+
return {
|
|
57
|
+
content: [{ type: "text", text: `Program loaded successfully: ${programId}` }]
|
|
58
|
+
};
|
|
59
|
+
} catch (error) {
|
|
60
|
+
return {
|
|
61
|
+
content: [{ type: "text", text: `Error: ${error instanceof Error ? error.message : "Unknown error"}` }],
|
|
62
|
+
isError: true
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
);
|
|
67
|
+
this.server.tool(
|
|
68
|
+
"startExecution",
|
|
69
|
+
{
|
|
70
|
+
programId: import_zod.z.string(),
|
|
71
|
+
executionId: import_zod.z.string()
|
|
72
|
+
},
|
|
73
|
+
async ({ programId, executionId }) => {
|
|
74
|
+
try {
|
|
75
|
+
await this.vmManager.startExecution(programId, executionId);
|
|
76
|
+
return {
|
|
77
|
+
content: [{ type: "text", text: `Execution started: ${executionId}` }]
|
|
78
|
+
};
|
|
79
|
+
} catch (error) {
|
|
80
|
+
return {
|
|
81
|
+
content: [{ type: "text", text: `Error: ${error instanceof Error ? error.message : "Unknown error"}` }],
|
|
82
|
+
isError: true
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
);
|
|
87
|
+
this.server.tool(
|
|
88
|
+
"getNext",
|
|
89
|
+
{
|
|
90
|
+
executionId: import_zod.z.string()
|
|
91
|
+
},
|
|
92
|
+
async ({ executionId }) => {
|
|
93
|
+
try {
|
|
94
|
+
const result = await this.vmManager.getNext(executionId);
|
|
95
|
+
if (result.type === "completed") {
|
|
96
|
+
return {
|
|
97
|
+
content: [{ type: "text", text: "Execution completed" }]
|
|
98
|
+
};
|
|
99
|
+
} else if (result.type === "waiting") {
|
|
100
|
+
return {
|
|
101
|
+
content: [{ type: "text", text: result.message || "Waiting for input" }]
|
|
102
|
+
};
|
|
103
|
+
} else if (result.type === "error") {
|
|
104
|
+
return {
|
|
105
|
+
content: [{ type: "text", text: `Error: ${result.error}` }],
|
|
106
|
+
isError: true
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
content: [{ type: "text", text: "Unexpected state" }],
|
|
111
|
+
isError: true
|
|
112
|
+
};
|
|
113
|
+
} catch (error) {
|
|
114
|
+
return {
|
|
115
|
+
content: [{ type: "text", text: `Error: ${error instanceof Error ? error.message : "Unknown error"}` }],
|
|
116
|
+
isError: true
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
);
|
|
121
|
+
this.server.tool(
|
|
122
|
+
"reportCCResult",
|
|
123
|
+
{
|
|
124
|
+
executionId: import_zod.z.string(),
|
|
125
|
+
result: import_zod.z.string()
|
|
126
|
+
},
|
|
127
|
+
async ({ executionId, result }) => {
|
|
128
|
+
try {
|
|
129
|
+
await this.vmManager.reportCCResult(executionId, result);
|
|
130
|
+
return {
|
|
131
|
+
content: [{ type: "text", text: "Execution resumed" }]
|
|
132
|
+
};
|
|
133
|
+
} catch (error) {
|
|
134
|
+
return {
|
|
135
|
+
content: [{ type: "text", text: `Error: ${error instanceof Error ? error.message : "Unknown error"}` }],
|
|
136
|
+
isError: true
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
);
|
|
141
|
+
this.server.tool(
|
|
142
|
+
"getExecutionState",
|
|
143
|
+
{
|
|
144
|
+
executionId: import_zod.z.string()
|
|
145
|
+
},
|
|
146
|
+
async ({ executionId }) => {
|
|
147
|
+
try {
|
|
148
|
+
const status = await this.vmManager.getExecutionStatus(executionId);
|
|
149
|
+
return {
|
|
150
|
+
content: [{ type: "text", text: JSON.stringify(status, null, 2) }]
|
|
151
|
+
};
|
|
152
|
+
} catch (error) {
|
|
153
|
+
return {
|
|
154
|
+
content: [{ type: "text", text: `Error: ${error instanceof Error ? error.message : "Unknown error"}` }],
|
|
155
|
+
isError: true
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
async start() {
|
|
162
|
+
await this.vmManager.initialize();
|
|
163
|
+
this.transport = new import_stdio.StdioServerTransport();
|
|
164
|
+
await this.server.connect(this.transport);
|
|
165
|
+
}
|
|
166
|
+
async stop() {
|
|
167
|
+
if (this.transport) {
|
|
168
|
+
await this.transport.close();
|
|
169
|
+
this.transport = null;
|
|
170
|
+
}
|
|
171
|
+
await this.vmManager.dispose();
|
|
172
|
+
}
|
|
173
|
+
// For testing - direct tool invocation
|
|
174
|
+
async handleTool(toolName, args) {
|
|
175
|
+
const handlers = {
|
|
176
|
+
loadProgram: async ({ programId, source }) => {
|
|
177
|
+
try {
|
|
178
|
+
await this.vmManager.loadProgram(programId, source);
|
|
179
|
+
return { content: [{ type: "text", text: `Program loaded successfully: ${programId}` }] };
|
|
180
|
+
} catch (error) {
|
|
181
|
+
return { content: [{ type: "text", text: error instanceof Error ? error.message : "Unknown error" }], isError: true };
|
|
182
|
+
}
|
|
183
|
+
},
|
|
184
|
+
startExecution: async ({ programId, executionId }) => {
|
|
185
|
+
try {
|
|
186
|
+
await this.vmManager.startExecution(programId, executionId);
|
|
187
|
+
return { content: [{ type: "text", text: `Execution started: ${executionId}` }] };
|
|
188
|
+
} catch (error) {
|
|
189
|
+
return { content: [{ type: "text", text: error instanceof Error ? error.message : "Unknown error" }], isError: true };
|
|
190
|
+
}
|
|
191
|
+
},
|
|
192
|
+
getNext: async ({ executionId }) => {
|
|
193
|
+
try {
|
|
194
|
+
const result = await this.vmManager.getNext(executionId);
|
|
195
|
+
if (result.type === "completed") {
|
|
196
|
+
return { content: [{ type: "text", text: "Execution completed" }] };
|
|
197
|
+
} else if (result.type === "waiting") {
|
|
198
|
+
return { content: [{ type: "text", text: result.message || "Waiting for input" }] };
|
|
199
|
+
} else {
|
|
200
|
+
return { content: [{ type: "text", text: `Error: ${result.error}` }], isError: true };
|
|
201
|
+
}
|
|
202
|
+
} catch (error) {
|
|
203
|
+
return { content: [{ type: "text", text: error instanceof Error ? error.message : "Unknown error" }], isError: true };
|
|
204
|
+
}
|
|
205
|
+
},
|
|
206
|
+
reportCCResult: async ({ executionId, result }) => {
|
|
207
|
+
try {
|
|
208
|
+
await this.vmManager.reportCCResult(executionId, result);
|
|
209
|
+
return { content: [{ type: "text", text: "Execution resumed" }] };
|
|
210
|
+
} catch (error) {
|
|
211
|
+
return { content: [{ type: "text", text: error instanceof Error ? error.message : "Unknown error" }], isError: true };
|
|
212
|
+
}
|
|
213
|
+
},
|
|
214
|
+
getExecutionState: async ({ executionId }) => {
|
|
215
|
+
try {
|
|
216
|
+
const status = await this.vmManager.getExecutionStatus(executionId);
|
|
217
|
+
return { content: [{ type: "text", text: JSON.stringify(status, null, 2) }] };
|
|
218
|
+
} catch (error) {
|
|
219
|
+
return { content: [{ type: "text", text: error instanceof Error ? error.message : "Unknown error" }], isError: true };
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
const handler = handlers[toolName];
|
|
224
|
+
if (!handler) {
|
|
225
|
+
throw new Error(`Tool not found: ${toolName}`);
|
|
226
|
+
}
|
|
227
|
+
return await handler(args);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
231
|
+
0 && (module.exports = {
|
|
232
|
+
CVMMcpServer
|
|
233
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
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 src_exports = {};
|
|
20
|
+
__export(src_exports, {
|
|
21
|
+
MongoDBAdapter: () => import_mongodb.MongoDBAdapter
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(src_exports);
|
|
24
|
+
var import_mongodb = require("./lib/mongodb.js");
|
|
25
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
26
|
+
0 && (module.exports = {
|
|
27
|
+
MongoDBAdapter
|
|
28
|
+
});
|
|
@@ -0,0 +1,94 @@
|
|
|
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_exports = {};
|
|
20
|
+
__export(mongodb_exports, {
|
|
21
|
+
MongoDBAdapter: () => MongoDBAdapter
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(mongodb_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
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
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);
|
|
@@ -0,0 +1,26 @@
|
|
|
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/parser.js"), module.exports);
|
|
19
|
+
__reExport(src_exports, require("./lib/bytecode.js"), module.exports);
|
|
20
|
+
__reExport(src_exports, require("./lib/compiler.js"), module.exports);
|
|
21
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
22
|
+
0 && (module.exports = {
|
|
23
|
+
...require("./lib/parser.js"),
|
|
24
|
+
...require("./lib/bytecode.js"),
|
|
25
|
+
...require("./lib/compiler.js")
|
|
26
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
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 bytecode_exports = {};
|
|
20
|
+
__export(bytecode_exports, {
|
|
21
|
+
OpCode: () => OpCode
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(bytecode_exports);
|
|
24
|
+
var OpCode = /* @__PURE__ */ ((OpCode2) => {
|
|
25
|
+
OpCode2["PUSH"] = "PUSH";
|
|
26
|
+
OpCode2["POP"] = "POP";
|
|
27
|
+
OpCode2["LOAD"] = "LOAD";
|
|
28
|
+
OpCode2["STORE"] = "STORE";
|
|
29
|
+
OpCode2["CONCAT"] = "CONCAT";
|
|
30
|
+
OpCode2["JUMP"] = "JUMP";
|
|
31
|
+
OpCode2["JUMP_IF"] = "JUMP_IF";
|
|
32
|
+
OpCode2["CALL"] = "CALL";
|
|
33
|
+
OpCode2["RETURN"] = "RETURN";
|
|
34
|
+
OpCode2["CC"] = "CC";
|
|
35
|
+
OpCode2["PRINT"] = "PRINT";
|
|
36
|
+
OpCode2["HALT"] = "HALT";
|
|
37
|
+
return OpCode2;
|
|
38
|
+
})(OpCode || {});
|
|
39
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
40
|
+
0 && (module.exports = {
|
|
41
|
+
OpCode
|
|
42
|
+
});
|
|
@@ -0,0 +1,104 @@
|
|
|
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 compiler_exports = {};
|
|
30
|
+
__export(compiler_exports, {
|
|
31
|
+
compile: () => compile
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(compiler_exports);
|
|
34
|
+
var ts = __toESM(require("typescript"), 1);
|
|
35
|
+
var import_bytecode = require("./bytecode.js");
|
|
36
|
+
var import_parser = require("./parser.js");
|
|
37
|
+
function compile(source) {
|
|
38
|
+
const parseResult = (0, import_parser.parseProgram)(source);
|
|
39
|
+
if (parseResult.errors.length > 0) {
|
|
40
|
+
return {
|
|
41
|
+
success: false,
|
|
42
|
+
bytecode: [],
|
|
43
|
+
errors: parseResult.errors
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
const bytecode = [];
|
|
47
|
+
const sourceFile = ts.createSourceFile("program.ts", source, ts.ScriptTarget.Latest, true);
|
|
48
|
+
function compileStatement(node) {
|
|
49
|
+
if (ts.isExpressionStatement(node)) {
|
|
50
|
+
const expr = node.expression;
|
|
51
|
+
if (ts.isCallExpression(expr) && ts.isPropertyAccessExpression(expr.expression) && expr.expression.expression.getText() === "console" && expr.expression.name.getText() === "log") {
|
|
52
|
+
expr.arguments.forEach((arg) => {
|
|
53
|
+
compileExpression(arg);
|
|
54
|
+
});
|
|
55
|
+
bytecode.push({ op: import_bytecode.OpCode.PRINT });
|
|
56
|
+
} else if (ts.isCallExpression(expr) && ts.isIdentifier(expr.expression) && expr.expression.text === "CC") {
|
|
57
|
+
if (expr.arguments.length > 0) {
|
|
58
|
+
compileExpression(expr.arguments[0]);
|
|
59
|
+
}
|
|
60
|
+
bytecode.push({ op: import_bytecode.OpCode.CC });
|
|
61
|
+
bytecode.push({ op: import_bytecode.OpCode.POP });
|
|
62
|
+
}
|
|
63
|
+
} else if (ts.isVariableStatement(node)) {
|
|
64
|
+
const decl = node.declarationList.declarations[0];
|
|
65
|
+
if (decl.initializer) {
|
|
66
|
+
compileExpression(decl.initializer);
|
|
67
|
+
bytecode.push({ op: import_bytecode.OpCode.STORE, arg: decl.name.getText() });
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
function compileExpression(node) {
|
|
72
|
+
if (ts.isStringLiteral(node)) {
|
|
73
|
+
bytecode.push({ op: import_bytecode.OpCode.PUSH, arg: node.text });
|
|
74
|
+
} else if (ts.isIdentifier(node)) {
|
|
75
|
+
bytecode.push({ op: import_bytecode.OpCode.LOAD, arg: node.text });
|
|
76
|
+
} else if (ts.isCallExpression(node) && ts.isIdentifier(node.expression) && node.expression.text === "CC") {
|
|
77
|
+
if (node.arguments.length > 0) {
|
|
78
|
+
compileExpression(node.arguments[0]);
|
|
79
|
+
}
|
|
80
|
+
bytecode.push({ op: import_bytecode.OpCode.CC });
|
|
81
|
+
} else if (ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.PlusToken) {
|
|
82
|
+
compileExpression(node.left);
|
|
83
|
+
compileExpression(node.right);
|
|
84
|
+
bytecode.push({ op: import_bytecode.OpCode.CONCAT });
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
sourceFile.forEachChild((node) => {
|
|
88
|
+
if (ts.isFunctionDeclaration(node) && node.name?.text === "main" && node.body) {
|
|
89
|
+
node.body.statements.forEach((stmt) => {
|
|
90
|
+
compileStatement(stmt);
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
bytecode.push({ op: import_bytecode.OpCode.HALT });
|
|
95
|
+
return {
|
|
96
|
+
success: true,
|
|
97
|
+
bytecode,
|
|
98
|
+
errors: []
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
102
|
+
0 && (module.exports = {
|
|
103
|
+
compile
|
|
104
|
+
});
|