dirac-lang 0.1.2
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/.env.example +8 -0
- package/COMMUNITY.md +465 -0
- package/LIBRARIES.md +172 -0
- package/NAMESPACES.md +366 -0
- package/PROMOTION.md +257 -0
- package/QUICKSTART-LIBRARY.md +93 -0
- package/README.md +257 -0
- package/config.yml +6 -0
- package/config.yml.openai +4 -0
- package/dirac-http/examples/demo.di +9 -0
- package/dirac-http/lib/index.di +12 -0
- package/dist/chunk-NDIRTD3D.js +217 -0
- package/dist/chunk-S625X7ME.js +1071 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +261 -0
- package/dist/index.d.ts +144 -0
- package/dist/index.js +22 -0
- package/dist/session-4QG7OERD.js +42 -0
- package/examples/add-demo.di +74 -0
- package/examples/add.bk +11 -0
- package/examples/advanced-math-demo.di +53 -0
- package/examples/calculator.di +32 -0
- package/examples/comprehensive.bk +29 -0
- package/examples/defvar-variable-demo.di +18 -0
- package/examples/direct-call.di +17 -0
- package/examples/disk-analysis.di +16 -0
- package/examples/executable-hello.di +7 -0
- package/examples/execute-demo.di +38 -0
- package/examples/file-manager.di +77 -0
- package/examples/file-stats.di +18 -0
- package/examples/hello.bk +1 -0
- package/examples/hello.di +5 -0
- package/examples/import-demo.di +31 -0
- package/examples/inline-test.bk +7 -0
- package/examples/lib/advanced-math.di +81 -0
- package/examples/lib/fileops.di +26 -0
- package/examples/lib/math.di +25 -0
- package/examples/lib/mongodb.di +96 -0
- package/examples/llm-agent.di +32 -0
- package/examples/llm-basic.di +12 -0
- package/examples/llm-command-no-exec.di +13 -0
- package/examples/llm-command.di +13 -0
- package/examples/llm-complex.di +141 -0
- package/examples/llm-recursive.di +31 -0
- package/examples/llm-reflection-test.di +19 -0
- package/examples/llm-subs.di +132 -0
- package/examples/llm-use-subs.di +6 -0
- package/examples/loop.di +12 -0
- package/examples/math-test.di +22 -0
- package/examples/mongodb-count-events.di +8 -0
- package/examples/mongodb-import-demo.di +25 -0
- package/examples/mongodb-simple-test.di +18 -0
- package/examples/nl-agent.di +47 -0
- package/examples/parameters-demo.di +68 -0
- package/examples/params-test.di +10 -0
- package/examples/recipe-chain.di +38 -0
- package/examples/recursive-llm.di +44 -0
- package/examples/sample-library/README.md +152 -0
- package/examples/sample-library/examples/demo.di +34 -0
- package/examples/sample-library/lib/index.di +65 -0
- package/examples/sample-library/package.json +31 -0
- package/examples/seamless.di +45 -0
- package/examples/shell-test.bk +10 -0
- package/examples/simple-import.di +13 -0
- package/examples/simple-recursive.di +26 -0
- package/examples/story-builder.di +45 -0
- package/examples/subroutine.di +23 -0
- package/examples/system-llm.di +21 -0
- package/examples/system-simple.di +3 -0
- package/examples/system-test.di +13 -0
- package/examples/task-assistant.di +27 -0
- package/examples/test-parameters.di +50 -0
- package/examples/two-styles.di +28 -0
- package/examples/var-debug.di +6 -0
- package/examples/var-inline.di +4 -0
- package/examples/var-test2.di +6 -0
- package/examples/variable-simple.di +16 -0
- package/examples/variable-test.di +22 -0
- package/filePath +1 -0
- package/greeting.txt +1 -0
- package/package.json +41 -0
- package/src/cli.ts +118 -0
- package/src/index.ts +33 -0
- package/src/llm/ollama.ts +58 -0
- package/src/runtime/braket-parser.ts +234 -0
- package/src/runtime/interpreter.ts +135 -0
- package/src/runtime/parser.ts +151 -0
- package/src/runtime/session.ts +228 -0
- package/src/tags/assign.ts +37 -0
- package/src/tags/call.ts +156 -0
- package/src/tags/defvar.ts +56 -0
- package/src/tags/eval.ts +68 -0
- package/src/tags/execute.ts +52 -0
- package/src/tags/expr.ts +128 -0
- package/src/tags/if.ts +58 -0
- package/src/tags/import.ts +66 -0
- package/src/tags/index.ts +37 -0
- package/src/tags/llm.ts +207 -0
- package/src/tags/loop.ts +43 -0
- package/src/tags/mongodb.ts +70 -0
- package/src/tags/output.ts +23 -0
- package/src/tags/parameters.ts +79 -0
- package/src/tags/require_module.ts +19 -0
- package/src/tags/subroutine.ts +52 -0
- package/src/tags/system.ts +70 -0
- package/src/tags/variable.ts +25 -0
- package/src/types/index.ts +101 -0
- package/src/utils/llm-adapter.ts +113 -0
- package/tools/create-library.sh +175 -0
- package/tsconfig.json +19 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#!/usr/bin/env dirac
|
|
2
|
+
<dirac>
|
|
3
|
+
<import src="./lib/math.di" />
|
|
4
|
+
|
|
5
|
+
<output>Direct Tag Call Test </output>
|
|
6
|
+
|
|
7
|
+
<defvar name="x" value="9" />
|
|
8
|
+
<output>Using <SQUARE />: </output>
|
|
9
|
+
<SQUARE />
|
|
10
|
+
<output> </output>
|
|
11
|
+
|
|
12
|
+
<defvar name="a" value="100" />
|
|
13
|
+
<defvar name="b" value="200" />
|
|
14
|
+
<output>Using <ADD />: </output>
|
|
15
|
+
<ADD />
|
|
16
|
+
<output> </output>
|
|
17
|
+
</dirac>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<dirac>
|
|
2
|
+
<!-- Get disk usage and ask LLM to summarize -->
|
|
3
|
+
<output>Analyzing disk usage...</output>
|
|
4
|
+
<output> </output>
|
|
5
|
+
|
|
6
|
+
<llm>
|
|
7
|
+
<system>du -sh . 2>/dev/null</system>
|
|
8
|
+
<system>df -h . | tail -1</system>
|
|
9
|
+
|
|
10
|
+
Above are two commands:
|
|
11
|
+
1. Total size of current directory
|
|
12
|
+
2. Disk space information for the filesystem
|
|
13
|
+
|
|
14
|
+
Please tell me in one sentence: How much space is this directory using and what percentage of the disk is free?
|
|
15
|
+
</llm>
|
|
16
|
+
</dirac>
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
<!-- Simple Execute Demo - LLM generates and executes code -->
|
|
2
|
+
<dirac>
|
|
3
|
+
<output>Demo: LLM-Generated Executable Code </output>
|
|
4
|
+
|
|
5
|
+
<!-- Simple calculation task -->
|
|
6
|
+
<output>Task: Calculate 15 * 23 + 7 </output>
|
|
7
|
+
<LLM output="mathCode" maxTokens="150">
|
|
8
|
+
Generate Dirac XML to calculate: 15 * 23 + 7
|
|
9
|
+
|
|
10
|
+
Format:
|
|
11
|
+
<dirac>
|
|
12
|
+
<eval name="result">return 15 * 23 + 7;</eval>
|
|
13
|
+
<output>Result: ${result}</output>
|
|
14
|
+
</dirac>
|
|
15
|
+
|
|
16
|
+
Return only XML, no markdown.
|
|
17
|
+
</LLM>
|
|
18
|
+
|
|
19
|
+
<execute source="mathCode" />
|
|
20
|
+
<output> </output>
|
|
21
|
+
|
|
22
|
+
<!-- File listing task -->
|
|
23
|
+
<output>Task: Count files in current directory </output>
|
|
24
|
+
<LLM output="fileCode" maxTokens="150">
|
|
25
|
+
Generate Dirac XML to count files in current directory.
|
|
26
|
+
|
|
27
|
+
Format:
|
|
28
|
+
<dirac>
|
|
29
|
+
<eval name="count">return fs.readdirSync('.').length;</eval>
|
|
30
|
+
<output>Files: ${count}</output>
|
|
31
|
+
</dirac>
|
|
32
|
+
|
|
33
|
+
Return only XML, no markdown.
|
|
34
|
+
</LLM>
|
|
35
|
+
|
|
36
|
+
<execute source="fileCode" />
|
|
37
|
+
<output> Done! </output>
|
|
38
|
+
</dirac>
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
<!-- File Manager Agent - Operational Example -->
|
|
2
|
+
<dirac>
|
|
3
|
+
<defvar name="targetDir" value="examples" />
|
|
4
|
+
|
|
5
|
+
<output>Analyzing directory: ${targetDir} </output>
|
|
6
|
+
|
|
7
|
+
<!-- Step 1: List files in directory -->
|
|
8
|
+
<output>Listing files... </output>
|
|
9
|
+
<eval name="fileList">
|
|
10
|
+
const files = fs.readdirSync(targetDir);
|
|
11
|
+
return files.join(', ');
|
|
12
|
+
</eval>
|
|
13
|
+
<output>Found: ${fileList} </output>
|
|
14
|
+
|
|
15
|
+
<!-- Step 2: Ask LLM to analyze what's missing -->
|
|
16
|
+
<output>Asking LLM to analyze... </output>
|
|
17
|
+
<LLM output="analysis" maxTokens="200">
|
|
18
|
+
I have a directory with these files: ${fileList}
|
|
19
|
+
|
|
20
|
+
These appear to be example files for a programming language.
|
|
21
|
+
Suggest ONE simple example file that would be useful to add.
|
|
22
|
+
|
|
23
|
+
Respond with ONLY:
|
|
24
|
+
1. Filename (must end in .di)
|
|
25
|
+
2. Brief description (one line)
|
|
26
|
+
|
|
27
|
+
Format:
|
|
28
|
+
FILENAME: name.di
|
|
29
|
+
DESCRIPTION: what it does
|
|
30
|
+
</LLM>
|
|
31
|
+
<output>${analysis} </output>
|
|
32
|
+
|
|
33
|
+
<!-- Step 3: Extract filename from LLM response -->
|
|
34
|
+
<eval name="newFilename">
|
|
35
|
+
const text = analysis;
|
|
36
|
+
const match = text.match(/FILENAME:\s*(\S+\.di)/i);
|
|
37
|
+
return match ? match[1] : 'new-example.di';
|
|
38
|
+
</eval>
|
|
39
|
+
|
|
40
|
+
<output>Creating file: ${newFilename} </output>
|
|
41
|
+
|
|
42
|
+
<!-- Step 4: Ask LLM to generate the file content -->
|
|
43
|
+
<LLM output="fileContent" maxTokens="300">
|
|
44
|
+
Create the content for ${newFilename} based on this description:
|
|
45
|
+
${analysis}
|
|
46
|
+
|
|
47
|
+
The file should use Dirac XML syntax with these tags:
|
|
48
|
+
- <dirac> (root)
|
|
49
|
+
- <defvar name="x" value="y" />
|
|
50
|
+
- <output>text</output>
|
|
51
|
+
- <LLM output="var">prompt</LLM>
|
|
52
|
+
|
|
53
|
+
Make it simple and functional. Include XML declaration and comment.
|
|
54
|
+
</LLM>
|
|
55
|
+
|
|
56
|
+
<!-- Step 5: Write the file -->
|
|
57
|
+
<eval name="writeResult">
|
|
58
|
+
const filePath = path.join(targetDir, newFilename);
|
|
59
|
+
const content = fileContent;
|
|
60
|
+
fs.writeFileSync(filePath, content, 'utf-8');
|
|
61
|
+
return 'File written successfully to ' + filePath;
|
|
62
|
+
</eval>
|
|
63
|
+
|
|
64
|
+
<output> Result: ${writeResult} </output>
|
|
65
|
+
|
|
66
|
+
<!-- Step 6: Verify the file was created -->
|
|
67
|
+
<eval name="verification">
|
|
68
|
+
const filePath = path.join(targetDir, newFilename);
|
|
69
|
+
if (fs.existsSync(filePath)) {
|
|
70
|
+
const stats = fs.statSync(filePath);
|
|
71
|
+
return 'Verified! File size: ' + stats.size + ' bytes';
|
|
72
|
+
}
|
|
73
|
+
return 'Error: File not found';
|
|
74
|
+
</eval>
|
|
75
|
+
|
|
76
|
+
<output>Verification: ${verification} </output>
|
|
77
|
+
</dirac>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#!/usr/bin/env dirac
|
|
2
|
+
<!-- Executable Dirac Script: Quick File Analysis -->
|
|
3
|
+
<dirac>
|
|
4
|
+
<eval name="fileCount">
|
|
5
|
+
return fs.readdirSync('.').length;
|
|
6
|
+
</eval>
|
|
7
|
+
|
|
8
|
+
<eval name="diracFiles">
|
|
9
|
+
return fs.readdirSync('.')
|
|
10
|
+
.filter(f => f.endsWith('.di'))
|
|
11
|
+
.length;
|
|
12
|
+
</eval>
|
|
13
|
+
|
|
14
|
+
<output>Current Directory Analysis </output>
|
|
15
|
+
<output>======================== </output>
|
|
16
|
+
<output>Total files: ${fileCount} </output>
|
|
17
|
+
<output>Dirac scripts: ${diracFiles} </output>
|
|
18
|
+
</dirac>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|output>Hello from bra-ket notation!
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
#!/usr/bin/env dirac
|
|
2
|
+
<!-- Demo: Using imported libraries -->
|
|
3
|
+
<dirac>
|
|
4
|
+
<output>Import Demo </output>
|
|
5
|
+
|
|
6
|
+
<!-- Import libraries -->
|
|
7
|
+
<import src="./lib/math.di" />
|
|
8
|
+
<import src="./lib/fileops.di" />
|
|
9
|
+
|
|
10
|
+
<output>Testing math library: </output>
|
|
11
|
+
<defvar name="x" value="5" />
|
|
12
|
+
<output>Square of ${x}: </output>
|
|
13
|
+
<call name="SQUARE" />
|
|
14
|
+
|
|
15
|
+
<defvar name="a" value="10" />
|
|
16
|
+
<defvar name="b" value="20" />
|
|
17
|
+
<output>Add ${a} + ${b}: </output>
|
|
18
|
+
<call name="ADD" />
|
|
19
|
+
|
|
20
|
+
<defvar name="num" value="5" />
|
|
21
|
+
<output>Factorial of ${num}: </output>
|
|
22
|
+
<call name="FACTORIAL" />
|
|
23
|
+
|
|
24
|
+
<output> Testing file ops library: </output>
|
|
25
|
+
<defvar name="dir" value="." />
|
|
26
|
+
<call name="LIST_FILES" />
|
|
27
|
+
<call name="COUNT_FILES" />
|
|
28
|
+
|
|
29
|
+
<defvar name="filepath" value="./package.json" />
|
|
30
|
+
<call name="FILE_EXISTS" />
|
|
31
|
+
</dirac>
|
|
@@ -0,0 +1,81 @@
|
|
|
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>
|
|
@@ -0,0 +1,26 @@
|
|
|
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>
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
<!-- Math utility library -->
|
|
2
|
+
<dirac>
|
|
3
|
+
<!-- Square a number -->
|
|
4
|
+
<subroutine name="SQUARE">
|
|
5
|
+
<eval name="result">return x * x;</eval>
|
|
6
|
+
<output>${result}</output>
|
|
7
|
+
</subroutine>
|
|
8
|
+
|
|
9
|
+
<!-- Add two numbers -->
|
|
10
|
+
<subroutine name="ADD">
|
|
11
|
+
<eval name="result">return a + b;</eval>
|
|
12
|
+
<output>${result}</output>
|
|
13
|
+
</subroutine>
|
|
14
|
+
|
|
15
|
+
<!-- Calculate factorial -->
|
|
16
|
+
<subroutine name="FACTORIAL">
|
|
17
|
+
<eval name="result">
|
|
18
|
+
const n = parseInt(num);
|
|
19
|
+
let fact = 1;
|
|
20
|
+
for (let i = 2; i <= n; i++) fact *= i;
|
|
21
|
+
return fact;
|
|
22
|
+
</eval>
|
|
23
|
+
<output>${result}</output>
|
|
24
|
+
</subroutine>
|
|
25
|
+
</dirac>
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
<!-- MongoDB operations library for Dirac -->
|
|
2
|
+
<dirac>
|
|
3
|
+
<!-- General MongoDB subroutine: supports find, aggregate, insert, count -->
|
|
4
|
+
<subroutine name="MONGODB">
|
|
5
|
+
<parameters select="@database" />
|
|
6
|
+
<parameters select="@collection" />
|
|
7
|
+
<parameters select="@action" />
|
|
8
|
+
<defvar name="body"><parameters select="*"/></defvar>
|
|
9
|
+
|
|
10
|
+
<require_module name="mongodb" var="mongo" />
|
|
11
|
+
|
|
12
|
+
<!-- mongo is: <variable name="mongo" />
|
|
13
|
+
and the dollar sign expression : ${mongo} -->
|
|
14
|
+
<!-- the body is ${body} -->
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
<eval name="result">
|
|
19
|
+
{ let output = body;
|
|
20
|
+
const uri = process.env.MONGODB_URI || 'mongodb://localhost:27017';
|
|
21
|
+
console.log("action is:", action)
|
|
22
|
+
console.log('DEBUG: body content before JSON.parse:', body);
|
|
23
|
+
const query = body ? JSON.parse(body) : {};
|
|
24
|
+
const client = new mongo.MongoClient(uri);
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
try {
|
|
28
|
+
await client.connect();
|
|
29
|
+
const db = database ? client.db(database) : undefined;
|
|
30
|
+
const col = db && collection ? db.collection(collection) : undefined;
|
|
31
|
+
|
|
32
|
+
switch (action) {
|
|
33
|
+
case 'find':
|
|
34
|
+
output = await col.find(query).toArray();
|
|
35
|
+
break;
|
|
36
|
+
case 'count':
|
|
37
|
+
output = await col.countDocuments(query);
|
|
38
|
+
break;
|
|
39
|
+
case 'aggregate':
|
|
40
|
+
output = await col.aggregate(query).toArray();
|
|
41
|
+
break;
|
|
42
|
+
case 'insert':
|
|
43
|
+
output = await col.insertOne(query);
|
|
44
|
+
break;
|
|
45
|
+
default:
|
|
46
|
+
throw new Error('unknown action for MONGODB: ' + action);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
} finally {
|
|
52
|
+
await client.close();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return JSON.stringify(output, null, 2);
|
|
56
|
+
}
|
|
57
|
+
</eval>
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
<!--
|
|
62
|
+
<eval name="result">
|
|
63
|
+
const uri = process.env.MONGODB_URI || 'mongodb://localhost:27017';
|
|
64
|
+
// database, collection, action, and body are available as variables
|
|
65
|
+
console.log('DEBUG: body content before JSON.parse:', body);
|
|
66
|
+
const query = body ? JSON.parse(body) : {};
|
|
67
|
+
const client = new mongo.MongoClient(uri);
|
|
68
|
+
let output;
|
|
69
|
+
try {
|
|
70
|
+
await client.connect();
|
|
71
|
+
const db = database ? client.db(database) : undefined;
|
|
72
|
+
const col = db && collection ? db.collection(collection) : undefined;
|
|
73
|
+
switch (action || 'find') {
|
|
74
|
+
case 'find':
|
|
75
|
+
output = await col.find(query).toArray();
|
|
76
|
+
break;
|
|
77
|
+
case 'aggregate':
|
|
78
|
+
output = await col.aggregate(query).toArray();
|
|
79
|
+
break;
|
|
80
|
+
case 'insert':
|
|
81
|
+
output = await col.insertOne(query);
|
|
82
|
+
break;
|
|
83
|
+
case 'count':
|
|
84
|
+
output = await col.countDocuments(query);
|
|
85
|
+
break;
|
|
86
|
+
default:
|
|
87
|
+
throw new Error('Unknown action for MONGODB: ' + action);
|
|
88
|
+
}
|
|
89
|
+
} finally {
|
|
90
|
+
await client.close();
|
|
91
|
+
}
|
|
92
|
+
return JSON.stringify(output, null, 2);
|
|
93
|
+
</eval> -->
|
|
94
|
+
<output>${result}\n</output>
|
|
95
|
+
</subroutine>
|
|
96
|
+
</dirac>
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
<!-- Agent with LLM-generated operations -->
|
|
2
|
+
<dirac>
|
|
3
|
+
<defvar name="task" value="create a hello world file named greeting.txt" />
|
|
4
|
+
|
|
5
|
+
<output>Task: ${task} </output>
|
|
6
|
+
|
|
7
|
+
<!-- Ask LLM to generate Dirac code to accomplish the task -->
|
|
8
|
+
<output>Asking LLM to generate executable code... </output>
|
|
9
|
+
<LLM output="generatedCode" maxTokens="400">
|
|
10
|
+
You are a Dirac code generator. Generate valid Dirac XML to accomplish this task:
|
|
11
|
+
"${task}"
|
|
12
|
+
|
|
13
|
+
Available tags:
|
|
14
|
+
- <dirac> (root element)
|
|
15
|
+
- <defvar name="x" value="y" /> (define variable)
|
|
16
|
+
- <output>text</output> (print output)
|
|
17
|
+
- <eval name="result">JavaScript code</eval> (run JS, has fs and path modules)
|
|
18
|
+
|
|
19
|
+
The eval tag can use fs.writeFileSync(filename, content) to write files.
|
|
20
|
+
Variables are accessed as plain JavaScript variables (not with ${}).
|
|
21
|
+
|
|
22
|
+
Return ONLY valid Dirac XML starting with <dirac> tag. No explanations.
|
|
23
|
+
</LLM>
|
|
24
|
+
|
|
25
|
+
<output> Generated code: ${generatedCode} </output>
|
|
26
|
+
|
|
27
|
+
<!-- Execute the LLM-generated code -->
|
|
28
|
+
<output>Executing generated code... </output>
|
|
29
|
+
<execute source="generatedCode" />
|
|
30
|
+
|
|
31
|
+
<output> Task completed! </output>
|
|
32
|
+
</dirac>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<!-- LLM integration example - THE INNOVATION -->
|
|
2
|
+
<dirac>
|
|
3
|
+
<defvar name="topic" value="quantum computing" />
|
|
4
|
+
|
|
5
|
+
<output>Asking LLM about ${topic}... </output>
|
|
6
|
+
|
|
7
|
+
<LLM output="response" maxTokens="200">
|
|
8
|
+
Explain ${topic} in one sentence.
|
|
9
|
+
</LLM>
|
|
10
|
+
|
|
11
|
+
<output>Response: ${response} </output>
|
|
12
|
+
</dirac>
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<dirac>
|
|
2
|
+
|
|
3
|
+
<subroutine name="background" description="set the background color." param-color="string:required:color name" >
|
|
4
|
+
<parameters select="@color"/>
|
|
5
|
+
<output>
|
|
6
|
+
this is my color: <variable name="color" />
|
|
7
|
+
</output>
|
|
8
|
+
</subroutine>
|
|
9
|
+
|
|
10
|
+
<llm >set the background color to red</llm>
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
</dirac>
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<dirac>
|
|
2
|
+
|
|
3
|
+
<subroutine name="background" description="set the background color." param-color="string:required:color name" >
|
|
4
|
+
<parameters select="@color"/>
|
|
5
|
+
<output>
|
|
6
|
+
this is my color: <variable name="color" />
|
|
7
|
+
</output>
|
|
8
|
+
</subroutine>
|
|
9
|
+
|
|
10
|
+
<llm execute="true">set the background color to red</llm>
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
</dirac>
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
<dirac>
|
|
2
|
+
<!-- UI Control Services -->
|
|
3
|
+
<!-- These subroutines are exposed as natural language endpoints -->
|
|
4
|
+
|
|
5
|
+
<subroutine name="background"
|
|
6
|
+
description="Change the background color, do not generate other tags like <changeBackground /> use precise tag"
|
|
7
|
+
param-color="string:required:Background color:red|blue|green|yellow|orange|purple|pink|white|black">
|
|
8
|
+
<parameters select="@color"/>
|
|
9
|
+
|
|
10
|
+
<eval>
|
|
11
|
+
console.log('Changing background color to: ' + color);
|
|
12
|
+
</eval>
|
|
13
|
+
</subroutine>
|
|
14
|
+
|
|
15
|
+
<subroutine name="set-text-size"
|
|
16
|
+
description="Adjust the text size"
|
|
17
|
+
param-size="string:required:Font size:12px|14px|16px|18px|20px|24px">
|
|
18
|
+
<parameters select="@size" />
|
|
19
|
+
<eval>
|
|
20
|
+
console.log("change text size to "+size );
|
|
21
|
+
document.body.style.fontSize = '${size}';
|
|
22
|
+
</eval>
|
|
23
|
+
</subroutine>
|
|
24
|
+
|
|
25
|
+
<subroutine name="reset-styles"
|
|
26
|
+
description="Reset all styles to default">
|
|
27
|
+
<eval>
|
|
28
|
+
console.log("reset all styles back");
|
|
29
|
+
document.body.style.backgroundColor = 'white';
|
|
30
|
+
document.body.style.fontSize = '16px';
|
|
31
|
+
</eval>
|
|
32
|
+
</subroutine>
|
|
33
|
+
|
|
34
|
+
<subroutine name="text-color"
|
|
35
|
+
description="Change the text color"
|
|
36
|
+
param-color="string:required:Text color:black|white|red|blue|green">
|
|
37
|
+
<parameters select="@color" />
|
|
38
|
+
<eval>
|
|
39
|
+
console.log("change color of text to "+color);
|
|
40
|
+
document.body.style.color = '${color}';
|
|
41
|
+
</eval>
|
|
42
|
+
</subroutine>
|
|
43
|
+
|
|
44
|
+
<!-- Event Generation Examples -->
|
|
45
|
+
|
|
46
|
+
<subroutine name="click-button"
|
|
47
|
+
description="Simulate clicking a button"
|
|
48
|
+
param-selector="string:optional:CSS selector (default: #submit-button)">
|
|
49
|
+
<eval>
|
|
50
|
+
const selector = '${selector}' || '#submit-button';
|
|
51
|
+
const element = document.querySelector(selector);
|
|
52
|
+
if (element) {
|
|
53
|
+
const clickEvent = new MouseEvent('click', {
|
|
54
|
+
bubbles: true,
|
|
55
|
+
cancelable: true,
|
|
56
|
+
view: window
|
|
57
|
+
});
|
|
58
|
+
element.dispatchEvent(clickEvent);
|
|
59
|
+
} else {
|
|
60
|
+
throw new Error('Element not found: ' + selector);
|
|
61
|
+
}
|
|
62
|
+
</eval>
|
|
63
|
+
</subroutine>
|
|
64
|
+
|
|
65
|
+
<subroutine name="type-text"
|
|
66
|
+
description="Type text into an input field"
|
|
67
|
+
param-text="string:required:Text to type"
|
|
68
|
+
param-field="string:optional:Which field:name|email">
|
|
69
|
+
<parameters select="@text" />
|
|
70
|
+
<parameters select="@field" />
|
|
71
|
+
<eval>
|
|
72
|
+
const _field = typeof field !== 'undefined' && field ? field : 'name';
|
|
73
|
+
const selector = _field === 'email' ? '#email-input' : '#name-input';
|
|
74
|
+
const input = document.querySelector(selector);
|
|
75
|
+
if (input) {
|
|
76
|
+
input.value = text;
|
|
77
|
+
input.dispatchEvent(new Event('input', { bubbles: true }));
|
|
78
|
+
input.dispatchEvent(new Event('change', { bubbles: true }));
|
|
79
|
+
} else {
|
|
80
|
+
throw new Error('Input not found: ' + selector);
|
|
81
|
+
}
|
|
82
|
+
</eval>
|
|
83
|
+
</subroutine>
|
|
84
|
+
|
|
85
|
+
<subroutine name="check-terms"
|
|
86
|
+
description="Check or uncheck the terms checkbox"
|
|
87
|
+
param-checked="string:optional:Check state:true|false">
|
|
88
|
+
<eval>
|
|
89
|
+
const shouldCheck = '${checked}' !== 'false';
|
|
90
|
+
const checkbox = document.querySelector('#terms-checkbox');
|
|
91
|
+
if (checkbox) {
|
|
92
|
+
checkbox.checked = shouldCheck;
|
|
93
|
+
checkbox.dispatchEvent(new Event('change', { bubbles: true }));
|
|
94
|
+
} else {
|
|
95
|
+
throw new Error('Checkbox not found');
|
|
96
|
+
}
|
|
97
|
+
</eval>
|
|
98
|
+
</subroutine>
|
|
99
|
+
|
|
100
|
+
<subroutine name="clear-input"
|
|
101
|
+
description="Clear an input field"
|
|
102
|
+
param-field="string:optional:Which field:name|email">
|
|
103
|
+
<eval>
|
|
104
|
+
const field = '${field}' || 'name';
|
|
105
|
+
const selector = field === 'email' ? '#email-input' : '#name-input';
|
|
106
|
+
const input = document.querySelector(selector);
|
|
107
|
+
if (input) {
|
|
108
|
+
input.value = '';
|
|
109
|
+
input.dispatchEvent(new Event('input', { bubbles: true }));
|
|
110
|
+
input.dispatchEvent(new Event('change', { bubbles: true }));
|
|
111
|
+
} else {
|
|
112
|
+
throw new Error('Input not found: ' + selector);
|
|
113
|
+
}
|
|
114
|
+
</eval>
|
|
115
|
+
</subroutine>
|
|
116
|
+
|
|
117
|
+
<!--
|
|
118
|
+
<subroutine name="modify-file"
|
|
119
|
+
description="modify a file based on pattern and replacement field "
|
|
120
|
+
param-filename="string|required"
|
|
121
|
+
param-pattern="string|required"
|
|
122
|
+
param-replace="string|required"
|
|
123
|
+
>
|
|
124
|
+
<parameters select="@filename" />
|
|
125
|
+
<parameters select="@pattern" />
|
|
126
|
+
<parameters select="@replace" />
|
|
127
|
+
<system>
|
|
128
|
+
sed -e 's/${pattern}/${replace}/g' ${filename}
|
|
129
|
+
</system>
|
|
130
|
+
</subroutine>
|
|
131
|
+
-->
|
|
132
|
+
|
|
133
|
+
<llm noextra="true" execute="false">
|
|
134
|
+
<system>
|
|
135
|
+
ls -tl
|
|
136
|
+
</system>
|
|
137
|
+
find me the file with name hello.di and modify the pattern of World with Zhi
|
|
138
|
+
use the command <modify-file I listed to do this.
|
|
139
|
+
</llm>
|
|
140
|
+
|
|
141
|
+
</dirac>
|