agency-lang 0.0.8 → 0.0.9
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/lib/templates/backends/graphGenerator/imports.d.ts +1 -1
- package/dist/lib/templates/backends/graphGenerator/imports.js +16 -8
- package/dist/lib/templates/backends/typescriptGenerator/imports.d.ts +1 -1
- package/dist/lib/templates/backends/typescriptGenerator/imports.js +7 -1
- package/dist/lib/templates/backends/typescriptGenerator/promptFunction.d.ts +1 -1
- package/dist/lib/templates/backends/typescriptGenerator/promptFunction.js +5 -2
- package/dist/scripts/regenerate-fixtures.d.ts +2 -0
- package/dist/scripts/regenerate-fixtures.js +36 -0
- package/dist/scripts/regenerate-graph-fixtures.d.ts +2 -0
- package/dist/scripts/regenerate-graph-fixtures.js +36 -0
- package/package.json +8 -7
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const template = "import OpenAI from \"openai\";\nimport { zodResponseFormat } from \"openai/helpers/zod\";\nimport { z } from \"zod\";\nimport * as readline from \"readline\";\nimport fs from \"fs\";\nimport {
|
|
1
|
+
export declare const template = "import OpenAI from \"openai\";\nimport { zodResponseFormat } from \"openai/helpers/zod\";\nimport { 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\nconst client = getClient({\n openAiApiKey: process.env.OPENAI_API_KEY || \"\",\n googleApiKey: process.env.GEMINI_API_KEY || \"\",\n model,\n logLevel: \"warn\",\n});\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
|
};
|
|
@@ -7,19 +7,28 @@ import { zodResponseFormat } from "openai/helpers/zod";
|
|
|
7
7
|
import { z } from "zod";
|
|
8
8
|
import * as readline from "readline";
|
|
9
9
|
import fs from "fs";
|
|
10
|
-
import {
|
|
10
|
+
import { PieMachine, goToNode } from "piemachine";
|
|
11
11
|
import { StatelogClient } from "statelog-client";
|
|
12
12
|
import { nanoid } from "nanoid";
|
|
13
|
-
import { assistantMessage, getClient,
|
|
13
|
+
import { assistantMessage, getClient, userMessage } from "smoltalk";
|
|
14
14
|
|
|
15
|
-
const statelogHost = "
|
|
15
|
+
const statelogHost = "https://statelog.adit.io";
|
|
16
16
|
const traceId = nanoid();
|
|
17
|
-
const
|
|
17
|
+
const statelogConfig = {
|
|
18
|
+
host: statelogHost,
|
|
19
|
+
traceId: traceId,
|
|
20
|
+
apiKey: process.env.STATELOG_API_KEY || "",
|
|
21
|
+
projectId: "agency-lang",
|
|
22
|
+
debugMode: false,
|
|
23
|
+
};
|
|
24
|
+
const statelogClient = new StatelogClient(statelogConfig);
|
|
18
25
|
const model = "gpt-4o-mini";
|
|
19
26
|
|
|
20
27
|
const client = getClient({
|
|
21
|
-
|
|
28
|
+
openAiApiKey: process.env.OPENAI_API_KEY || "",
|
|
29
|
+
googleApiKey: process.env.GEMINI_API_KEY || "",
|
|
22
30
|
model,
|
|
31
|
+
logLevel: "warn",
|
|
23
32
|
});
|
|
24
33
|
|
|
25
34
|
type State = {
|
|
@@ -33,8 +42,7 @@ const graphConfig = {
|
|
|
33
42
|
log: true,
|
|
34
43
|
logData: true,
|
|
35
44
|
},
|
|
36
|
-
|
|
37
|
-
traceId
|
|
45
|
+
statelog: statelogConfig,
|
|
38
46
|
};
|
|
39
47
|
|
|
40
48
|
// Define the names of the nodes in the graph
|
|
@@ -42,7 +50,7 @@ const graphConfig = {
|
|
|
42
50
|
const nodes = {{{nodes:string}}} as const;
|
|
43
51
|
type Node = (typeof nodes)[number];
|
|
44
52
|
|
|
45
|
-
const graph = new
|
|
53
|
+
const graph = new PieMachine<State, Node>(nodes, graphConfig);`;
|
|
46
54
|
const render = (args) => {
|
|
47
55
|
return apply(template, args);
|
|
48
56
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const template = "import OpenAI from \"openai\";\nimport { zodResponseFormat } from \"openai/helpers/zod\";\nimport { z } from \"zod\";\nimport * as readline from \"readline\";\nimport fs from \"fs\";\nimport { StatelogClient } from \"statelog-client\";\nimport { nanoid } from \"nanoid\";\n\nconst statelogHost = \"http://localhost:1065\";\nconst traceId = nanoid();\nconst statelogClient = new StatelogClient({host: statelogHost
|
|
1
|
+
export declare const template = "import OpenAI from \"openai\";\nimport { zodResponseFormat } from \"openai/helpers/zod\";\nimport { z } from \"zod\";\nimport * as readline from \"readline\";\nimport fs from \"fs\";\nimport { StatelogClient } from \"statelog-client\";\nimport { nanoid } from \"nanoid\";\n\nconst statelogHost = \"http://localhost:1065\";\nconst traceId = nanoid();\nconst statelogClient = new StatelogClient({\n host: statelogHost,\n traceId: traceId,\n apiKey: process.env.STATELOG_API_KEY || \"\",\n projectId: \"agency-lang\",\n debugMode: true,\n });\n\nconst model = \"gpt-5-nano-2025-08-07\";\n\nconst openai = new OpenAI({\n apiKey: process.env.OPENAI_API_KEY,\n});";
|
|
2
2
|
export type TemplateType = {};
|
|
3
3
|
declare const render: (args: TemplateType) => string;
|
|
4
4
|
export default render;
|
|
@@ -12,7 +12,13 @@ import { nanoid } from "nanoid";
|
|
|
12
12
|
|
|
13
13
|
const statelogHost = "http://localhost:1065";
|
|
14
14
|
const traceId = nanoid();
|
|
15
|
-
const statelogClient = new StatelogClient({
|
|
15
|
+
const statelogClient = new StatelogClient({
|
|
16
|
+
host: statelogHost,
|
|
17
|
+
traceId: traceId,
|
|
18
|
+
apiKey: process.env.STATELOG_API_KEY || "",
|
|
19
|
+
projectId: "agency-lang",
|
|
20
|
+
debugMode: true,
|
|
21
|
+
});
|
|
16
22
|
|
|
17
23
|
const model = "gpt-5-nano-2025-08-07";
|
|
18
24
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const template = "\nasync function _{{{variableName:string}}}({{{argsStr:string}}}): Promise<{{{typeString:string}}}> {\n const prompt = {{{promptCode:string}}};\n const startTime = performance.now();\n const messages: Message[] = [userMessage(prompt)];\n const tools = {{{tools}}};\n\n const responseFormat = {{{zodSchema:string}}};\n\n let completion = await client.text({\n messages,\n tools,\n responseFormat,\n });\n\n const endTime = performance.now();\n statelogClient.promptCompletion({\n messages,\n completion,\n model,\n timeTaken: endTime - startTime,\n });\n\n if (!completion.success) {\n throw new Error(\n `Error getting response from ${model}: ${completion.error}`\n );\n }\n\n let responseMessage = completion.value;\n\n // Handle function calls\n while (responseMessage.toolCalls.length > 0) {\n // Add assistant's response with tool calls to message history\n messages.push(assistantMessage(responseMessage.output));\n let toolCallStartTime, toolCallEndTime;\n\n // Process each tool call\n for (const toolCall of responseMessage.toolCalls) {\n {{{functionCalls:string}}}\n }\n\n const nextStartTime = performance.now();\n let completion = await client.text({\n messages,\n tools,\n responseFormat,\n });\n\n const nextEndTime = performance.now();\n\n statelogClient.promptCompletion({\n messages,\n completion,\n model,\n timeTaken: nextEndTime - nextStartTime,\n });\n\n if (!completion.success) {\n throw new Error(\n `Error getting response from ${model}: ${completion.error}`\n );\n }\n responseMessage = completion.value;\n }\n\n // Add final assistant response to history\n messages.push(assistantMessage(responseMessage.output));\n\n try {\n const result = JSON.parse(responseMessage.output || \"\");\n return result.
|
|
1
|
+
export declare const template = "\nasync function _{{{variableName:string}}}({{{argsStr:string}}}): Promise<{{{typeString:string}}}> {\n const prompt = {{{promptCode:string}}};\n const startTime = performance.now();\n const messages: Message[] = [userMessage(prompt)];\n const tools = {{{tools}}};\n\n // Need to make sure this is always an object\n const responseFormat = z.object({\n response: {{{zodSchema:string}}}\n });\n\n let completion = await client.text({\n messages,\n tools,\n responseFormat,\n });\n\n const endTime = performance.now();\n statelogClient.promptCompletion({\n messages,\n completion,\n model,\n timeTaken: endTime - startTime,\n });\n\n if (!completion.success) {\n throw new Error(\n `Error getting response from ${model}: ${completion.error}`\n );\n }\n\n let responseMessage = completion.value;\n\n // Handle function calls\n while (responseMessage.toolCalls.length > 0) {\n // Add assistant's response with tool calls to message history\n messages.push(assistantMessage(responseMessage.output));\n let toolCallStartTime, toolCallEndTime;\n\n // Process each tool call\n for (const toolCall of responseMessage.toolCalls) {\n {{{functionCalls:string}}}\n }\n\n const nextStartTime = performance.now();\n let completion = await client.text({\n messages,\n tools,\n responseFormat,\n });\n\n const nextEndTime = performance.now();\n\n statelogClient.promptCompletion({\n messages,\n completion,\n model,\n timeTaken: nextEndTime - nextStartTime,\n });\n\n if (!completion.success) {\n throw new Error(\n `Error getting response from ${model}: ${completion.error}`\n );\n }\n responseMessage = completion.value;\n }\n\n // Add final assistant response to history\n messages.push(assistantMessage(responseMessage.output));\n\n try {\n const result = JSON.parse(responseMessage.output || \"\");\n return result.response;\n } catch (e) {\n return responseMessage.output;\n // console.error(\"Error parsing response for variable '{{{variableName:string}}}':\", e);\n // console.error(\"Full completion response:\", JSON.stringify(completion, null, 2));\n // throw e;\n }\n}\n";
|
|
2
2
|
export type TemplateType = {
|
|
3
3
|
variableName: string;
|
|
4
4
|
argsStr: string;
|
|
@@ -9,7 +9,10 @@ async function _{{{variableName:string}}}({{{argsStr:string}}}): Promise<{{{type
|
|
|
9
9
|
const messages: Message[] = [userMessage(prompt)];
|
|
10
10
|
const tools = {{{tools}}};
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
// Need to make sure this is always an object
|
|
13
|
+
const responseFormat = z.object({
|
|
14
|
+
response: {{{zodSchema:string}}}
|
|
15
|
+
});
|
|
13
16
|
|
|
14
17
|
let completion = await client.text({
|
|
15
18
|
messages,
|
|
@@ -73,7 +76,7 @@ async function _{{{variableName:string}}}({{{argsStr:string}}}): Promise<{{{type
|
|
|
73
76
|
|
|
74
77
|
try {
|
|
75
78
|
const result = JSON.parse(responseMessage.output || "");
|
|
76
|
-
return result.
|
|
79
|
+
return result.response;
|
|
77
80
|
} catch (e) {
|
|
78
81
|
return responseMessage.output;
|
|
79
82
|
// console.error("Error parsing response for variable '{{{variableName:string}}}':", e);
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import path, { dirname } from "path";
|
|
3
|
+
import fs from "fs";
|
|
4
|
+
import { generateTypeScript } from "../lib/backends/typescriptGenerator.js";
|
|
5
|
+
import { parseAgency } from "../lib/parser.js";
|
|
6
|
+
import { fileURLToPath } from "url";
|
|
7
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
8
|
+
const __dirname = dirname(__filename);
|
|
9
|
+
const fixturesDir = path.join(__dirname, "../../tests/typescriptGenerator");
|
|
10
|
+
function regenerateFixtures(dir, relativePath = "") {
|
|
11
|
+
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
12
|
+
for (const entry of entries) {
|
|
13
|
+
const fullPath = path.join(dir, entry.name);
|
|
14
|
+
if (entry.isDirectory()) {
|
|
15
|
+
regenerateFixtures(fullPath, path.join(relativePath, entry.name));
|
|
16
|
+
}
|
|
17
|
+
else if (entry.isFile() && entry.name.endsWith(".agency")) {
|
|
18
|
+
const baseName = entry.name.replace(".agency", "");
|
|
19
|
+
const mtsPath = path.join(dir, `${baseName}.mts`);
|
|
20
|
+
const agencyContent = fs.readFileSync(fullPath, "utf-8");
|
|
21
|
+
const parseResult = parseAgency(agencyContent);
|
|
22
|
+
if (parseResult.success) {
|
|
23
|
+
const tsCode = generateTypeScript(parseResult.result);
|
|
24
|
+
fs.writeFileSync(mtsPath, tsCode, "utf-8");
|
|
25
|
+
const fixtureRelPath = path.join(relativePath, baseName) || baseName;
|
|
26
|
+
console.log(`✓ Updated ${fixtureRelPath}.mts`);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
console.error(`✗ Failed to parse ${fullPath}: ${parseResult.message}`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
console.log("Regenerating fixture files...\n");
|
|
35
|
+
regenerateFixtures(fixturesDir);
|
|
36
|
+
console.log("\nDone!");
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import path, { dirname } from "path";
|
|
3
|
+
import fs from "fs";
|
|
4
|
+
import { generateGraph } from "../lib/backends/graphGenerator.js";
|
|
5
|
+
import { parseAgency } from "../lib/parser.js";
|
|
6
|
+
import { fileURLToPath } from "url";
|
|
7
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
8
|
+
const __dirname = dirname(__filename);
|
|
9
|
+
const fixturesDir = path.join(__dirname, "../../tests/graphGenerator");
|
|
10
|
+
function regenerateFixtures(dir, relativePath = "") {
|
|
11
|
+
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
12
|
+
for (const entry of entries) {
|
|
13
|
+
const fullPath = path.join(dir, entry.name);
|
|
14
|
+
if (entry.isDirectory()) {
|
|
15
|
+
regenerateFixtures(fullPath, path.join(relativePath, entry.name));
|
|
16
|
+
}
|
|
17
|
+
else if (entry.isFile() && entry.name.endsWith(".agency")) {
|
|
18
|
+
const baseName = entry.name.replace(".agency", "");
|
|
19
|
+
const mtsPath = path.join(dir, `${baseName}.mts`);
|
|
20
|
+
const agencyContent = fs.readFileSync(fullPath, "utf-8");
|
|
21
|
+
const parseResult = parseAgency(agencyContent);
|
|
22
|
+
if (parseResult.success) {
|
|
23
|
+
const graphCode = generateGraph(parseResult.result);
|
|
24
|
+
fs.writeFileSync(mtsPath, graphCode, "utf-8");
|
|
25
|
+
const fixtureRelPath = path.join(relativePath, baseName) || baseName;
|
|
26
|
+
console.log(`✓ Updated ${fixtureRelPath}.mts`);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
console.error(`✗ Failed to parse ${fullPath}: ${parseResult.message}`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
console.log("Regenerating graph generator fixture files...\n");
|
|
35
|
+
regenerateFixtures(fixturesDir);
|
|
36
|
+
console.log("\nDone!");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agency-lang",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"description": "The Agency language",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
"start": "node dist/lib/index.js",
|
|
11
11
|
"templates": "typestache ./lib/templates",
|
|
12
12
|
"typecheck": "tsc --noEmit",
|
|
13
|
-
"agency": "node ./dist/scripts/agency.js"
|
|
13
|
+
"agency": "node ./dist/scripts/agency.js",
|
|
14
|
+
"compile": "node ./dist/scripts/agency.js compile"
|
|
14
15
|
},
|
|
15
16
|
"bin": {
|
|
16
17
|
"agency": "./dist/scripts/agency.js"
|
|
@@ -24,9 +25,9 @@
|
|
|
24
25
|
],
|
|
25
26
|
"exports": {
|
|
26
27
|
".": {
|
|
28
|
+
"types": "./dist/lib/index.d.ts",
|
|
27
29
|
"import": "./dist/lib/index.js",
|
|
28
|
-
"require": "./dist/lib/index.js"
|
|
29
|
-
"types": "./dist/lib/index.d.ts"
|
|
30
|
+
"require": "./dist/lib/index.js"
|
|
30
31
|
}
|
|
31
32
|
},
|
|
32
33
|
"type": "module",
|
|
@@ -42,9 +43,9 @@
|
|
|
42
43
|
"egonlog": "^0.0.2",
|
|
43
44
|
"nanoid": "^5.1.6",
|
|
44
45
|
"openai": "^6.15.0",
|
|
45
|
-
"
|
|
46
|
-
"smoltalk": "^0.0.
|
|
47
|
-
"statelog-client": "^0.0.
|
|
46
|
+
"piemachine": "^0.0.2",
|
|
47
|
+
"smoltalk": "^0.0.8",
|
|
48
|
+
"statelog-client": "^0.0.31",
|
|
48
49
|
"tarsec": "^0.1.1",
|
|
49
50
|
"typestache": "^0.4.4",
|
|
50
51
|
"zod": "^4.2.1"
|