agency-lang 0.0.10 → 0.0.11
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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const template = "import
|
|
1
|
+
export declare const template = "import { z } from \"zod\";\nimport * as readline from \"readline\";\nimport fs from \"fs\";\nimport { PieMachine, goToNode } from \"piemachine\";\nimport { StatelogClient } from \"statelog-client\";\nimport { nanoid } from \"nanoid\";\nimport { assistantMessage, getClient, userMessage } from \"smoltalk\";\n\nconst statelogHost = \"https://statelog.adit.io\";\nconst traceId = nanoid();\nconst statelogConfig = {\n host: statelogHost,\n traceId: traceId,\n apiKey: process.env.STATELOG_API_KEY || \"\",\n projectId: \"agency-lang\",\n debugMode: false,\n };\nconst statelogClient = new StatelogClient(statelogConfig);\nconst model = \"gpt-4o-mini\";\n\n\nconst getClientWithConfig = (config = {}) => {\n const defaultConfig = {\n openAiApiKey: process.env.OPENAI_API_KEY || \"\",\n googleApiKey: process.env.GEMINI_API_KEY || \"\",\n model,\n logLevel: \"warn\",\n };\n\n return getClient({ ...defaultConfig, ...config });\n};\n\nlet client = getClientWithConfig();\n\ntype State = {\n messages: string[];\n data: any;\n}\n\n// enable debug logging\nconst graphConfig = {\n debug: {\n log: true,\n logData: true,\n },\n statelog: statelogConfig,\n};\n\n// Define the names of the nodes in the graph\n// Useful for type safety\nconst nodes = {{{nodes:string}}} as const;\ntype Node = (typeof nodes)[number];\n\nconst graph = new PieMachine<State, Node>(nodes, graphConfig);";
|
|
2
2
|
export type TemplateType = {
|
|
3
3
|
nodes: string;
|
|
4
4
|
};
|
|
@@ -2,9 +2,7 @@
|
|
|
2
2
|
// Source: lib/templates/backends/graphGenerator/imports.mustache
|
|
3
3
|
// Any manual changes will be lost.
|
|
4
4
|
import { apply } from "typestache";
|
|
5
|
-
export const template = `import
|
|
6
|
-
import { zodResponseFormat } from "openai/helpers/zod";
|
|
7
|
-
import { z } from "zod";
|
|
5
|
+
export const template = `import { z } from "zod";
|
|
8
6
|
import * as readline from "readline";
|
|
9
7
|
import fs from "fs";
|
|
10
8
|
import { PieMachine, goToNode } from "piemachine";
|
package/dist/scripts/agency.js
CHANGED
|
@@ -11,15 +11,15 @@ Agency Language CLI
|
|
|
11
11
|
|
|
12
12
|
Usage:
|
|
13
13
|
agency help Show this help message
|
|
14
|
-
agency compile <input> [output] Compile .agency file to TypeScript
|
|
14
|
+
agency compile <input> [output] Compile .agency file or directory to TypeScript
|
|
15
15
|
agency run <input> [output] Compile and run .agency file
|
|
16
16
|
agency format [input] Format .agency file (reads from stdin if no input)
|
|
17
17
|
agency parse [input] Parse .agency file and show AST (reads from stdin if no input)
|
|
18
18
|
agency <input> Compile and run .agency file (shorthand)
|
|
19
19
|
|
|
20
20
|
Arguments:
|
|
21
|
-
input Path to .agency input file (or omit to read from stdin for format/parse)
|
|
22
|
-
output Path to output .ts file (optional)
|
|
21
|
+
input Path to .agency input file or directory (or omit to read from stdin for format/parse)
|
|
22
|
+
output Path to output .ts file (optional, ignored for directories)
|
|
23
23
|
Default: <input-name>.ts
|
|
24
24
|
|
|
25
25
|
Flags:
|
|
@@ -29,6 +29,7 @@ Examples:
|
|
|
29
29
|
agency help Show help
|
|
30
30
|
agency compile script.agency Compile to script.ts
|
|
31
31
|
agency compile script.agency out.ts Compile to out.ts
|
|
32
|
+
agency compile ./scripts Compile all .agency files in directory
|
|
32
33
|
agency run script.agency Compile and run script.agency
|
|
33
34
|
agency -v parse script.agency Parse with verbose logging
|
|
34
35
|
cat script.agency | agency format Format from stdin
|
|
@@ -81,7 +82,33 @@ function getImports(program) {
|
|
|
81
82
|
.map((node) => node.modulePath.trim().replace(/['"]/g, ""));
|
|
82
83
|
}
|
|
83
84
|
const compiledFiles = new Set();
|
|
85
|
+
const dirSearched = new Set();
|
|
84
86
|
function compile(inputFile, _outputFile, verbose = false) {
|
|
87
|
+
// Check if the input is a directory
|
|
88
|
+
const stats = fs.statSync(inputFile);
|
|
89
|
+
if (stats.isDirectory()) {
|
|
90
|
+
dirSearched.add(path.resolve(inputFile));
|
|
91
|
+
// Find all .agency files in the directory
|
|
92
|
+
const files = fs.readdirSync(inputFile);
|
|
93
|
+
const agencyFiles = files.filter((file) => file.endsWith(".agency"));
|
|
94
|
+
for (const file of agencyFiles) {
|
|
95
|
+
const fullPath = path.join(inputFile, file);
|
|
96
|
+
compile(fullPath, undefined, verbose);
|
|
97
|
+
}
|
|
98
|
+
// Find all subdirectories and compile their .agency files
|
|
99
|
+
const subdirs = files.filter((file) => {
|
|
100
|
+
const fullPath = path.join(inputFile, file);
|
|
101
|
+
return fs.statSync(fullPath).isDirectory();
|
|
102
|
+
});
|
|
103
|
+
for (const subdir of subdirs) {
|
|
104
|
+
const fullSubdirPath = path.join(inputFile, subdir);
|
|
105
|
+
const resolvedSubdirPath = path.resolve(fullSubdirPath);
|
|
106
|
+
if (!dirSearched.has(resolvedSubdirPath)) {
|
|
107
|
+
compile(fullSubdirPath, undefined, verbose);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
85
112
|
// Resolve the absolute path of the input file to avoid duplicates
|
|
86
113
|
const absoluteInputFile = path.resolve(inputFile);
|
|
87
114
|
const outputFile = _outputFile || inputFile.replace(".agency", ".ts");
|
|
@@ -112,6 +139,10 @@ function compile(inputFile, _outputFile, verbose = false) {
|
|
|
112
139
|
function run(inputFile, outputFile, verbose = false) {
|
|
113
140
|
// Compile the file
|
|
114
141
|
const output = compile(inputFile, outputFile, verbose);
|
|
142
|
+
if (output === null) {
|
|
143
|
+
console.error("Error: No output file generated.");
|
|
144
|
+
process.exit(1);
|
|
145
|
+
}
|
|
115
146
|
// Run the generated TypeScript file with Node.js
|
|
116
147
|
console.log(`Running ${output}...`);
|
|
117
148
|
console.log("---");
|
|
@@ -157,7 +188,7 @@ async function main() {
|
|
|
157
188
|
break;
|
|
158
189
|
case "compile":
|
|
159
190
|
if (filteredArgs.length < 2) {
|
|
160
|
-
console.error("Error: 'compile' command requires an input file");
|
|
191
|
+
console.error("Error: 'compile' command requires an input file or directory");
|
|
161
192
|
console.error("Usage: agency compile <input> [output]");
|
|
162
193
|
process.exit(1);
|
|
163
194
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agency-lang",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.11",
|
|
4
4
|
"description": "The Agency language",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -42,18 +42,17 @@
|
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"egonlog": "^0.0.2",
|
|
44
44
|
"nanoid": "^5.1.6",
|
|
45
|
-
"openai": "^6.15.0",
|
|
46
45
|
"piemachine": "^0.0.2",
|
|
47
46
|
"smoltalk": "^0.0.11",
|
|
48
47
|
"statelog-client": "^0.0.31",
|
|
49
|
-
"
|
|
50
|
-
"typestache": "^0.4.4",
|
|
51
|
-
"zod": "^4.2.1"
|
|
48
|
+
"zod": "^4.3.5"
|
|
52
49
|
},
|
|
53
50
|
"devDependencies": {
|
|
54
51
|
"@types/node": "^25.0.3",
|
|
52
|
+
"tarsec": "^0.1.1",
|
|
55
53
|
"tsc-alias": "^1.8.16",
|
|
56
54
|
"typescript": "^5.9.3",
|
|
55
|
+
"typestache": "^0.4.4",
|
|
57
56
|
"vitest": "^4.0.16"
|
|
58
57
|
}
|
|
59
58
|
}
|