agency-lang 0.0.11 → 0.0.13

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 { 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);";
1
+ export declare const template = "// @ts-nocheck\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: ModelName = \"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: __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,7 +2,8 @@
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 { z } from "zod";
5
+ export const template = `// @ts-nocheck
6
+ import { z } from "zod";
6
7
  import * as readline from "readline";
7
8
  import fs from "fs";
8
9
  import { PieMachine, goToNode } from "piemachine";
@@ -20,21 +21,21 @@ const statelogConfig = {
20
21
  debugMode: false,
21
22
  };
22
23
  const statelogClient = new StatelogClient(statelogConfig);
23
- const model = "gpt-4o-mini";
24
+ const __model: ModelName = "gpt-4o-mini";
24
25
 
25
26
 
26
27
  const getClientWithConfig = (config = {}) => {
27
28
  const defaultConfig = {
28
29
  openAiApiKey: process.env.OPENAI_API_KEY || "",
29
30
  googleApiKey: process.env.GEMINI_API_KEY || "",
30
- model,
31
+ model: __model,
31
32
  logLevel: "warn",
32
33
  };
33
34
 
34
35
  return getClient({ ...defaultConfig, ...config });
35
36
  };
36
37
 
37
- let client = getClientWithConfig();
38
+ let __client = getClientWithConfig();
38
39
 
39
40
  type State = {
40
41
  messages: string[];
@@ -52,10 +53,10 @@ const graphConfig = {
52
53
 
53
54
  // Define the names of the nodes in the graph
54
55
  // Useful for type safety
55
- const nodes = {{{nodes:string}}} as const;
56
- type Node = (typeof nodes)[number];
56
+ const __nodes = {{{nodes:string}}} as const;
57
+ type Node = (typeof __nodes)[number];
57
58
 
58
- const graph = new PieMachine<State, Node>(nodes, graphConfig);`;
59
+ const graph = new PieMachine<State, Node>(__nodes, graphConfig);`;
59
60
  const render = (args) => {
60
61
  return apply(template, args);
61
62
  };
@@ -1,4 +1,4 @@
1
- export declare const template = "export async function {{{nodeName:string}}}(data) {\n const result = await graph.run(\"{{{nodeName:string}}}\", { messages: [], data });\n return result.data;\n}\n";
1
+ export declare const template = "export async function {{{nodeName:string}}}(data:any): Promise<any> {\n const result = await graph.run(\"{{{nodeName:string}}}\", { messages: [], data });\n return result.data;\n}\n";
2
2
  export type TemplateType = {
3
3
  nodeName: string;
4
4
  };
@@ -2,7 +2,7 @@
2
2
  // Source: lib/templates/backends/graphGenerator/runNodeFunction.mustache
3
3
  // Any manual changes will be lost.
4
4
  import { apply } from "typestache";
5
- export const template = `export async function {{{nodeName:string}}}(data) {
5
+ export const template = `export async function {{{nodeName:string}}}(data:any): Promise<any> {
6
6
  const result = await graph.run("{{{nodeName:string}}}", { messages: [], data });
7
7
  return result.data;
8
8
  }
@@ -1,4 +1,4 @@
1
- export declare const template = "client = getClientWithConfig({ {{{name}}}: {{{value}}} });";
1
+ export declare const template = "__client = getClientWithConfig({ {{{name}}}: {{{value}}} });";
2
2
  export type TemplateType = {
3
3
  name: string | boolean | number;
4
4
  value: string | boolean | number;
@@ -2,7 +2,7 @@
2
2
  // Source: lib/templates/backends/graphGenerator/specialVar.mustache
3
3
  // Any manual changes will be lost.
4
4
  import { apply } from "typestache";
5
- export const template = `client = getClientWithConfig({ {{{name}}}: {{{value}}} });`;
5
+ export const template = `__client = getClientWithConfig({ {{{name}}}: {{{value}}} });`;
6
6
  const render = (args) => {
7
7
  return apply(template, args);
8
8
  };
@@ -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 {{#hasResponseFormat}}\n // Need to make sure this is always an object\n const responseFormat = z.object({\n response: {{{zodSchema:string}}}\n });\n {{/hasResponseFormat}}\n {{^hasResponseFormat}}\n const responseFormat = undefined;\n {{/hasResponseFormat}}\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: client.getModel(),\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: client.getModel(),\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 {{#hasResponseFormat}}\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 {{/hasResponseFormat}}\n\n {{^hasResponseFormat}}\n return responseMessage.output;\n {{/hasResponseFormat}}\n}\n";
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 {{#hasResponseFormat}}\n // Need to make sure this is always an object\n const __responseFormat = z.object({\n response: {{{zodSchema:string}}}\n });\n {{/hasResponseFormat}}\n {{^hasResponseFormat}}\n const __responseFormat = undefined;\n {{/hasResponseFormat}}\n\n let __completion = await __client.text({\n messages: __messages,\n tools: __tools,\n responseFormat: __responseFormat,\n });\n\n const endTime = performance.now();\n statelogClient.promptCompletion({\n messages: __messages,\n completion: __completion,\n model: __client.getModel(),\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: __messages,\n tools: __tools,\n responseFormat: __responseFormat,\n });\n\n const nextEndTime = performance.now();\n\n statelogClient.promptCompletion({\n messages: __messages,\n completion: __completion,\n model: __client.getModel(),\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 {{#hasResponseFormat}}\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 {{/hasResponseFormat}}\n\n {{^hasResponseFormat}}\n return responseMessage.output;\n {{/hasResponseFormat}}\n}\n";
2
2
  export type TemplateType = {
3
3
  variableName: string;
4
4
  argsStr: string;
@@ -4,81 +4,80 @@
4
4
  import { apply } from "typestache";
5
5
  export const template = `
6
6
  async function _{{{variableName:string}}}({{{argsStr:string}}}): Promise<{{{typeString:string}}}> {
7
- const prompt = {{{promptCode:string}}};
7
+ const __prompt = {{{promptCode:string}}};
8
8
  const startTime = performance.now();
9
- const messages: Message[] = [userMessage(prompt)];
10
- const tools = {{{tools}}};
9
+ const __messages: Message[] = [userMessage(__prompt)];
10
+ const __tools = {{{tools}}};
11
11
 
12
12
  {{#hasResponseFormat}}
13
13
  // Need to make sure this is always an object
14
- const responseFormat = z.object({
14
+ const __responseFormat = z.object({
15
15
  response: {{{zodSchema:string}}}
16
16
  });
17
17
  {{/hasResponseFormat}}
18
18
  {{^hasResponseFormat}}
19
- const responseFormat = undefined;
19
+ const __responseFormat = undefined;
20
20
  {{/hasResponseFormat}}
21
21
 
22
- let completion = await client.text({
23
- messages,
24
- tools,
25
- responseFormat,
22
+ let __completion = await __client.text({
23
+ messages: __messages,
24
+ tools: __tools,
25
+ responseFormat: __responseFormat,
26
26
  });
27
27
 
28
28
  const endTime = performance.now();
29
29
  statelogClient.promptCompletion({
30
- messages,
31
- completion,
32
- model: client.getModel(),
30
+ messages: __messages,
31
+ completion: __completion,
32
+ model: __client.getModel(),
33
33
  timeTaken: endTime - startTime,
34
34
  });
35
35
 
36
- if (!completion.success) {
36
+ if (!__completion.success) {
37
37
  throw new Error(
38
- \`Error getting response from $\{model\}: $\{completion.error\}\`
38
+ \`Error getting response from $\{__model\}: $\{__completion.error\}\`
39
39
  );
40
40
  }
41
41
 
42
- let responseMessage = completion.value;
42
+ let responseMessage = __completion.value;
43
43
 
44
44
  // Handle function calls
45
45
  while (responseMessage.toolCalls.length > 0) {
46
46
  // Add assistant's response with tool calls to message history
47
- messages.push(assistantMessage(responseMessage.output));
47
+ __messages.push(assistantMessage(responseMessage.output));
48
48
  let toolCallStartTime, toolCallEndTime;
49
49
 
50
50
  // Process each tool call
51
51
  for (const toolCall of responseMessage.toolCalls) {
52
52
  {{{functionCalls:string}}}
53
53
  }
54
-
54
+
55
55
  const nextStartTime = performance.now();
56
- let completion = await client.text({
57
- messages,
58
- tools,
59
- responseFormat,
56
+ let __completion = await __client.text({
57
+ messages: __messages,
58
+ tools: __tools,
59
+ responseFormat: __responseFormat,
60
60
  });
61
61
 
62
62
  const nextEndTime = performance.now();
63
63
 
64
64
  statelogClient.promptCompletion({
65
- messages,
66
- completion,
67
- model: client.getModel(),
65
+ messages: __messages,
66
+ completion: __completion,
67
+ model: __client.getModel(),
68
68
  timeTaken: nextEndTime - nextStartTime,
69
69
  });
70
70
 
71
- if (!completion.success) {
71
+ if (!__completion.success) {
72
72
  throw new Error(
73
- \`Error getting response from $\{model\}: $\{completion.error\}\`
73
+ \`Error getting response from $\{__model\}: $\{__completion.error\}\`
74
74
  );
75
75
  }
76
- responseMessage = completion.value;
76
+ responseMessage = __completion.value;
77
77
  }
78
78
 
79
79
  // Add final assistant response to history
80
- messages.push(assistantMessage(responseMessage.output));
81
-
80
+ __messages.push(assistantMessage(responseMessage.output));
82
81
  {{#hasResponseFormat}}
83
82
  try {
84
83
  const result = JSON.parse(responseMessage.output || "");
@@ -86,7 +85,7 @@ async function _{{{variableName:string}}}({{{argsStr:string}}}): Promise<{{{type
86
85
  } catch (e) {
87
86
  return responseMessage.output;
88
87
  // console.error("Error parsing response for variable '{{{variableName:string}}}':", e);
89
- // console.error("Full completion response:", JSON.stringify(completion, null, 2));
88
+ // console.error("Full completion response:", JSON.stringify(__completion, null, 2));
90
89
  // throw e;
91
90
  }
92
91
  {{/hasResponseFormat}}
@@ -1,4 +1,4 @@
1
- export declare const template = "if (toolCall.type === \"function\" &&\n toolCall.function.name === \"{{{name:string}}}\"\n) {\n const args = JSON.parse(toolCall.function.arguments);\n\n toolCallStartTime = performance.now();\n const result = await {{{name}}}(args);\n toolCallEndTime = performance.now();\n\n console.log(\"Tool '{{{name:string}}}' called with arguments:\", args);\n console.log(\"Tool '{{{name:string}}}' returned result:\", result);\n\nstatelogClient.toolCall({\n toolName: \"{{{name:string}}}\",\n args,\n output: result,\n model,\n timeTaken: toolCallEndTime - toolCallStartTime,\n });\n\n // Add function result to messages\n messages.push({\n role: \"tool\",\n tool_call_id: toolCall.id,\n content: JSON.stringify(result),\n });\n}";
1
+ export declare const template = "if (toolCall.type === \"function\" &&\n toolCall.function.name === \"{{{name:string}}}\"\n) {\n const args = JSON.parse(toolCall.function.arguments);\n\n toolCallStartTime = performance.now();\n const result = await {{{name}}}(args);\n toolCallEndTime = performance.now();\n\n console.log(\"Tool '{{{name:string}}}' called with arguments:\", args);\n console.log(\"Tool '{{{name:string}}}' returned result:\", result);\n\nstatelogClient.toolCall({\n toolName: \"{{{name:string}}}\",\n args,\n output: result,\n model: __client.getModel(),\n timeTaken: toolCallEndTime - toolCallStartTime,\n });\n\n // Add function result to messages\n __messages.push({\n role: \"tool\",\n tool_call_id: toolCall.id,\n content: JSON.stringify(result),\n });\n}";
2
2
  export type TemplateType = {
3
3
  name: string;
4
4
  };
@@ -18,12 +18,12 @@ statelogClient.toolCall({
18
18
  toolName: "{{{name:string}}}",
19
19
  args,
20
20
  output: result,
21
- model,
21
+ model: __client.getModel(),
22
22
  timeTaken: toolCallEndTime - toolCallStartTime,
23
23
  });
24
24
 
25
25
  // Add function result to messages
26
- messages.push({
26
+ __messages.push({
27
27
  role: "tool",
28
28
  tool_call_id: toolCall.id,
29
29
  content: JSON.stringify(result),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agency-lang",
3
- "version": "0.0.11",
3
+ "version": "0.0.13",
4
4
  "description": "The Agency language",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -41,18 +41,18 @@
41
41
  "homepage": "https://github.com/egonSchiele/agency-lang#readme",
42
42
  "dependencies": {
43
43
  "egonlog": "^0.0.2",
44
- "nanoid": "^5.1.6",
45
- "piemachine": "^0.0.2",
46
- "smoltalk": "^0.0.11",
47
- "statelog-client": "^0.0.31",
44
+ "tarsec": "^0.1.1",
45
+ "typestache": "^0.4.4",
48
46
  "zod": "^4.3.5"
49
47
  },
50
48
  "devDependencies": {
51
49
  "@types/node": "^25.0.3",
52
- "tarsec": "^0.1.1",
50
+ "nanoid": "^5.1.6",
51
+ "piemachine": "^0.0.2",
52
+ "smoltalk": "^0.0.11",
53
+ "statelog-client": "^0.0.31",
53
54
  "tsc-alias": "^1.8.16",
54
55
  "typescript": "^5.9.3",
55
- "typestache": "^0.4.4",
56
56
  "vitest": "^4.0.16"
57
57
  }
58
58
  }