dirac-lang 0.1.26 → 0.1.27
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/dist/cli.js +3 -9
- package/package.json +3 -9
- package/lib/advanced-math.di +0 -81
- package/lib/fileops.di +0 -26
- package/lib/index.di +0 -9
- package/lib/math.di +0 -25
- package/lib/mongodb.di +0 -72
package/dist/cli.js
CHANGED
|
@@ -13,7 +13,7 @@ import "dotenv/config";
|
|
|
13
13
|
// package.json
|
|
14
14
|
var package_default = {
|
|
15
15
|
name: "dirac-lang",
|
|
16
|
-
version: "0.1.
|
|
16
|
+
version: "0.1.27",
|
|
17
17
|
description: "LLM-Augmented Declarative Execution",
|
|
18
18
|
type: "module",
|
|
19
19
|
main: "dist/index.js",
|
|
@@ -22,16 +22,10 @@ var package_default = {
|
|
|
22
22
|
dirac: "dist/cli.js"
|
|
23
23
|
},
|
|
24
24
|
exports: {
|
|
25
|
-
".": "./dist/index.js"
|
|
26
|
-
"./lib": "./lib/index.di",
|
|
27
|
-
"./lib/math": "./lib/math.di",
|
|
28
|
-
"./lib/advanced-math": "./lib/advanced-math.di",
|
|
29
|
-
"./lib/fileops": "./lib/fileops.di",
|
|
30
|
-
"./lib/mongodb": "./lib/mongodb.di"
|
|
25
|
+
".": "./dist/index.js"
|
|
31
26
|
},
|
|
32
27
|
files: [
|
|
33
|
-
"dist/"
|
|
34
|
-
"lib/"
|
|
28
|
+
"dist/"
|
|
35
29
|
],
|
|
36
30
|
scripts: {
|
|
37
31
|
dev: "tsx src/cli.ts",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dirac-lang",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.27",
|
|
4
4
|
"description": "LLM-Augmented Declarative Execution",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -9,16 +9,10 @@
|
|
|
9
9
|
"dirac": "dist/cli.js"
|
|
10
10
|
},
|
|
11
11
|
"exports": {
|
|
12
|
-
".": "./dist/index.js"
|
|
13
|
-
"./lib": "./lib/index.di",
|
|
14
|
-
"./lib/math": "./lib/math.di",
|
|
15
|
-
"./lib/advanced-math": "./lib/advanced-math.di",
|
|
16
|
-
"./lib/fileops": "./lib/fileops.di",
|
|
17
|
-
"./lib/mongodb": "./lib/mongodb.di"
|
|
12
|
+
".": "./dist/index.js"
|
|
18
13
|
},
|
|
19
14
|
"files": [
|
|
20
|
-
"dist/"
|
|
21
|
-
"lib/"
|
|
15
|
+
"dist/"
|
|
22
16
|
],
|
|
23
17
|
"scripts": {
|
|
24
18
|
"dev": "tsx src/cli.ts",
|
package/lib/advanced-math.di
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
<dirac>
|
|
2
|
-
|
|
3
|
-
<subroutine name="MATH_SQRT">
|
|
4
|
-
<eval>
|
|
5
|
-
const caller = getParams();
|
|
6
|
-
const n = parseFloat(caller.attributes.n || 0);
|
|
7
|
-
if (n < 0) {
|
|
8
|
-
console.log('NaN');
|
|
9
|
-
return;
|
|
10
|
-
}
|
|
11
|
-
let x = n;
|
|
12
|
-
let prev;
|
|
13
|
-
do {
|
|
14
|
-
prev = x;
|
|
15
|
-
x = (x + n / x) / 2;
|
|
16
|
-
} while (Math.abs(x - prev) < 1e-10);
|
|
17
|
-
console.log(x);
|
|
18
|
-
</eval>
|
|
19
|
-
</subroutine>
|
|
20
|
-
|
|
21
|
-
<subroutine name="MATH_STATS">
|
|
22
|
-
<eval>
|
|
23
|
-
const caller = getParams();
|
|
24
|
-
const dataStr = caller.attributes.data || '[]';
|
|
25
|
-
const data = JSON.parse(dataStr);
|
|
26
|
-
if (data.length === 0) { console.log('{}'); return; }
|
|
27
|
-
const sum = data.reduce((a, b) => a + b, 0);
|
|
28
|
-
const mean = sum / data.length;
|
|
29
|
-
const variance = data.reduce((acc, x) => acc + Math.pow(x - mean, 2), 0) / data.length;
|
|
30
|
-
const stddev = Math.sqrt(variance);
|
|
31
|
-
const sorted = [...data].sort((a, b) => a - b);
|
|
32
|
-
const median = data.length % 2 === 0 ? (sorted[data.length/2 - 1] + sorted[data.length/2]) / 2 : sorted[Math.floor(data.length/2)];
|
|
33
|
-
const stats = { count: data.length, sum: sum, mean: mean, median: median, stddev: stddev, min: sorted[0], max: sorted[sorted.length - 1] };
|
|
34
|
-
console.log(JSON.stringify(stats, null, 2));
|
|
35
|
-
</eval>
|
|
36
|
-
</subroutine>
|
|
37
|
-
|
|
38
|
-
<subroutine name="MATH_RANDOM">
|
|
39
|
-
<eval>
|
|
40
|
-
const caller = getParams();
|
|
41
|
-
const min = parseFloat(caller.attributes.min || 0);
|
|
42
|
-
const max = parseFloat(caller.attributes.max || 1);
|
|
43
|
-
const random = Math.random() * (max - min) + min;
|
|
44
|
-
console.log(random);
|
|
45
|
-
</eval>
|
|
46
|
-
</subroutine>
|
|
47
|
-
|
|
48
|
-
<subroutine name="MATH_FACTORIAL">
|
|
49
|
-
<eval>
|
|
50
|
-
const caller = getParams();
|
|
51
|
-
const n = parseInt(caller.attributes.n || 0);
|
|
52
|
-
function factorial(x) { if (x <= 1) return 1; return x * factorial(x - 1); }
|
|
53
|
-
console.log(factorial(n));
|
|
54
|
-
</eval>
|
|
55
|
-
</subroutine>
|
|
56
|
-
|
|
57
|
-
<subroutine name="MATH_GCD">
|
|
58
|
-
<eval>
|
|
59
|
-
const caller = getParams();
|
|
60
|
-
const a = parseInt(caller.attributes.a || 0);
|
|
61
|
-
const b = parseInt(caller.attributes.b || 0);
|
|
62
|
-
function gcd(x, y) { return y === 0 ? x : gcd(y, x % y); }
|
|
63
|
-
console.log(gcd(Math.abs(a), Math.abs(b)));
|
|
64
|
-
</eval>
|
|
65
|
-
</subroutine>
|
|
66
|
-
|
|
67
|
-
<subroutine name="MATH_PRIME">
|
|
68
|
-
<eval>
|
|
69
|
-
const caller = getParams();
|
|
70
|
-
const n = parseInt(caller.attributes.n || 0);
|
|
71
|
-
if (n <= 1) { console.log(0); return; }
|
|
72
|
-
if (n <= 3) { console.log(1); return; }
|
|
73
|
-
if (n % 2 === 0 || n % 3 === 0) { console.log(0); return; }
|
|
74
|
-
for (let i = 5; i * i <= n; i += 6) {
|
|
75
|
-
if (n % i === 0 || n % (i + 2) === 0) { console.log(0); return; }
|
|
76
|
-
}
|
|
77
|
-
console.log(1);
|
|
78
|
-
</eval>
|
|
79
|
-
</subroutine>
|
|
80
|
-
|
|
81
|
-
</dirac>
|
package/lib/fileops.di
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
<!-- File operations library -->
|
|
2
|
-
<dirac>
|
|
3
|
-
<!-- List files in directory -->
|
|
4
|
-
<subroutine name="LIST_FILES">
|
|
5
|
-
<eval name="files">
|
|
6
|
-
return fs.readdirSync(dir || '.').join(', ');
|
|
7
|
-
</eval>
|
|
8
|
-
<output>Files: ${files} </output>
|
|
9
|
-
</subroutine>
|
|
10
|
-
|
|
11
|
-
<!-- Count files in directory -->
|
|
12
|
-
<subroutine name="COUNT_FILES">
|
|
13
|
-
<eval name="count">
|
|
14
|
-
return fs.readdirSync(dir || '.').length;
|
|
15
|
-
</eval>
|
|
16
|
-
<output>Count: ${count} </output>
|
|
17
|
-
</subroutine>
|
|
18
|
-
|
|
19
|
-
<!-- Check if file exists -->
|
|
20
|
-
<subroutine name="FILE_EXISTS">
|
|
21
|
-
<eval name="exists">
|
|
22
|
-
return fs.existsSync(filepath) ? 'yes' : 'no';
|
|
23
|
-
</eval>
|
|
24
|
-
<output>Exists: ${exists} </output>
|
|
25
|
-
</subroutine>
|
|
26
|
-
</dirac>
|
package/lib/index.di
DELETED
package/lib/math.di
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
<!-- Math utility library -->
|
|
2
|
-
<dirac>
|
|
3
|
-
<!-- Square a number -->
|
|
4
|
-
<subroutine name="SQUARE" param-x="number">
|
|
5
|
-
<eval name="result">return Number(x) * Number(x);</eval>
|
|
6
|
-
<output><variable name="result" /></output>
|
|
7
|
-
</subroutine>
|
|
8
|
-
|
|
9
|
-
<!-- Add two numbers -->
|
|
10
|
-
<subroutine name="ADD" param-a="number" param-b="number">
|
|
11
|
-
<eval name="result">return Number(a) + Number(b);</eval>
|
|
12
|
-
<output><variable name="result" /></output>
|
|
13
|
-
</subroutine>
|
|
14
|
-
|
|
15
|
-
<!-- Calculate factorial -->
|
|
16
|
-
<subroutine name="FACTORIAL" param-num="number">
|
|
17
|
-
<eval name="result">
|
|
18
|
-
const n = parseInt(num, 10);
|
|
19
|
-
let fact = 1;
|
|
20
|
-
for (let i = 2; i <= n; i++) fact *= i;
|
|
21
|
-
return fact;
|
|
22
|
-
</eval>
|
|
23
|
-
<output><variable name="result" /></output>
|
|
24
|
-
</subroutine>
|
|
25
|
-
</dirac>
|
package/lib/mongodb.di
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
<!-- MongoDB operations library for Dirac -->
|
|
2
|
-
<dirac>
|
|
3
|
-
<!-- General MongoDB subroutine: supports find, aggregate, insert, count -->
|
|
4
|
-
<subroutine name="MONGODB"
|
|
5
|
-
description="a tag to access mongodb"
|
|
6
|
-
param-database="string:required:the database name::betting"
|
|
7
|
-
param-collection="string:required:the collection name::events"
|
|
8
|
-
param-action="string:required:the action need to take:find|aggregate|insert|count:find"
|
|
9
|
-
meta-body="string:optional:the JSON query or document body for the action, required for find/aggregate/insert: {"status":"active"}"
|
|
10
|
-
param-limit="number:optional:limit the number of records returned::10"
|
|
11
|
-
>
|
|
12
|
-
<!--
|
|
13
|
-
<parameters select="@database" />
|
|
14
|
-
<parameters select="@collection" />
|
|
15
|
-
<parameters select="@action" />
|
|
16
|
-
-->
|
|
17
|
-
<defvar name="body"><parameters select="*"/></defvar>
|
|
18
|
-
|
|
19
|
-
<require_module name="mongodb" var="mongo" />
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
<eval name="result">
|
|
26
|
-
{ let output = body;
|
|
27
|
-
const uri = process.env.MONGODB_URI || 'mongodb://localhost:27017';
|
|
28
|
-
|
|
29
|
-
const query = body ? JSON.parse(body) : {};
|
|
30
|
-
const client = new mongo.MongoClient(uri);
|
|
31
|
-
const limitVal = typeof limit !== 'undefined' && limit !== '' ? parseInt(limit, 10) : undefined;
|
|
32
|
-
|
|
33
|
-
try {
|
|
34
|
-
await client.connect();
|
|
35
|
-
const db = database ? client.db(database) : undefined;
|
|
36
|
-
const col = db && collection ? db.collection(collection) : undefined;
|
|
37
|
-
|
|
38
|
-
switch (action) {
|
|
39
|
-
case 'find':
|
|
40
|
-
let cursor = col.find(query);
|
|
41
|
-
if (limitVal) cursor = cursor.limit(limitVal);
|
|
42
|
-
output = await cursor.toArray();
|
|
43
|
-
break;
|
|
44
|
-
case 'count':
|
|
45
|
-
output = await col.countDocuments(query);
|
|
46
|
-
break;
|
|
47
|
-
case 'aggregate':
|
|
48
|
-
let aggCursor = col.aggregate(query);
|
|
49
|
-
if (limitVal) aggCursor = aggCursor.limit(limitVal);
|
|
50
|
-
output = await aggCursor.toArray();
|
|
51
|
-
break;
|
|
52
|
-
case 'insert':
|
|
53
|
-
output = await col.insertOne(query);
|
|
54
|
-
break;
|
|
55
|
-
default:
|
|
56
|
-
throw new Error('unknown action for MONGODB: ' + action);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
} finally {
|
|
60
|
-
await client.close();
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return JSON.stringify(output, null, 2);
|
|
64
|
-
}
|
|
65
|
-
</eval>
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
<output>${result}</output>
|
|
71
|
-
</subroutine>
|
|
72
|
-
</dirac>
|