agency-lang 0.0.20 → 0.0.22

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.
Files changed (82) hide show
  1. package/dist/lib/backends/agencyGenerator.d.ts +10 -2
  2. package/dist/lib/backends/agencyGenerator.js +86 -19
  3. package/dist/lib/backends/agencyGenerator.test.js +0 -48
  4. package/dist/lib/backends/baseGenerator.d.ts +11 -4
  5. package/dist/lib/backends/baseGenerator.js +35 -11
  6. package/dist/lib/backends/graphGenerator.js +19 -186
  7. package/dist/lib/backends/typescriptGenerator/builtins.js +6 -0
  8. package/dist/lib/backends/typescriptGenerator.d.ts +11 -3
  9. package/dist/lib/backends/typescriptGenerator.js +98 -26
  10. package/dist/lib/backends/utils.d.ts +1 -1
  11. package/dist/lib/parser.js +5 -5
  12. package/dist/lib/parser.test.js +15 -38
  13. package/dist/lib/parsers/access.test.js +14 -3
  14. package/dist/lib/parsers/assignment.test.js +159 -4
  15. package/dist/lib/parsers/await.d.ts +3 -0
  16. package/dist/lib/parsers/await.js +18 -0
  17. package/dist/lib/parsers/body.test.js +10 -1
  18. package/dist/lib/parsers/dataStructures.js +2 -2
  19. package/dist/lib/parsers/dataStructures.test.js +11 -11
  20. package/dist/lib/parsers/function.d.ts +8 -3
  21. package/dist/lib/parsers/function.js +64 -12
  22. package/dist/lib/parsers/function.test.js +284 -52
  23. package/dist/lib/parsers/functionCall.test.js +6 -6
  24. package/dist/lib/parsers/ifElse.test.d.ts +1 -0
  25. package/dist/lib/parsers/ifElse.test.js +376 -0
  26. package/dist/lib/parsers/importStatement.js +2 -2
  27. package/dist/lib/parsers/literals.d.ts +1 -0
  28. package/dist/lib/parsers/literals.js +6 -2
  29. package/dist/lib/parsers/literals.test.js +110 -21
  30. package/dist/lib/parsers/matchBlock.js +7 -4
  31. package/dist/lib/parsers/matchBlock.test.js +16 -16
  32. package/dist/lib/parsers/newline.d.ts +3 -0
  33. package/dist/lib/parsers/newline.js +2 -0
  34. package/dist/lib/parsers/parserUtils.d.ts +3 -1
  35. package/dist/lib/parsers/parserUtils.js +4 -1
  36. package/dist/lib/parsers/returnStatement.js +2 -1
  37. package/dist/lib/parsers/returnStatement.test.js +2 -2
  38. package/dist/lib/parsers/specialVar.test.js +7 -7
  39. package/dist/lib/parsers/typeHints.d.ts +1 -1
  40. package/dist/lib/parsers/typeHints.js +6 -6
  41. package/dist/lib/parsers/typeHints.test.js +0 -8
  42. package/dist/lib/parsers/utils.d.ts +1 -0
  43. package/dist/lib/parsers/utils.js +2 -1
  44. package/dist/lib/parsers/whileLoop.test.js +46 -1
  45. package/dist/lib/templates/backends/graphGenerator/goToNode.d.ts +2 -1
  46. package/dist/lib/templates/backends/graphGenerator/goToNode.js +11 -1
  47. package/dist/lib/templates/backends/graphGenerator/graphNode.d.ts +2 -2
  48. package/dist/lib/templates/backends/graphGenerator/graphNode.js +2 -1
  49. package/dist/lib/templates/backends/graphGenerator/imports.d.ts +1 -1
  50. package/dist/lib/templates/backends/graphGenerator/imports.js +14 -1
  51. package/dist/lib/templates/backends/typescriptGenerator/builtinFunctions/sleep.d.ts +4 -0
  52. package/dist/lib/templates/backends/typescriptGenerator/builtinFunctions/sleep.js +13 -0
  53. package/dist/lib/templates/backends/typescriptGenerator/builtinFunctions/time.d.ts +7 -0
  54. package/dist/lib/templates/backends/typescriptGenerator/builtinFunctions/time.js +12 -0
  55. package/dist/lib/templates/backends/typescriptGenerator/functionDefinition.d.ts +1 -1
  56. package/dist/lib/templates/backends/typescriptGenerator/functionDefinition.js +1 -0
  57. package/dist/lib/templates/backends/typescriptGenerator/promptFunction.d.ts +1 -1
  58. package/dist/lib/templates/backends/typescriptGenerator/promptFunction.js +3 -2
  59. package/dist/lib/templates/backends/typescriptGenerator/tool.d.ts +1 -1
  60. package/dist/lib/templates/backends/typescriptGenerator/tool.js +1 -1
  61. package/dist/lib/templates/backends/typescriptGenerator/toolCall.d.ts +1 -1
  62. package/dist/lib/templates/backends/typescriptGenerator/toolCall.js +2 -2
  63. package/dist/lib/types/await.d.ts +7 -0
  64. package/dist/lib/types/await.js +1 -0
  65. package/dist/lib/types/graphNode.d.ts +2 -1
  66. package/dist/lib/types/ifElse.d.ts +7 -0
  67. package/dist/lib/types/ifElse.js +1 -0
  68. package/dist/lib/types/literals.d.ts +1 -1
  69. package/dist/lib/types/returnStatement.d.ts +2 -1
  70. package/dist/lib/types/timeBlock.d.ts +5 -0
  71. package/dist/lib/types/timeBlock.js +1 -0
  72. package/dist/lib/types.d.ts +16 -8
  73. package/dist/lib/types.js +1 -0
  74. package/dist/lib/utils.d.ts +1 -0
  75. package/dist/lib/utils.js +3 -0
  76. package/package.json +3 -2
  77. package/dist/lib/parsers/assignment.d.ts +0 -3
  78. package/dist/lib/parsers/assignment.js +0 -8
  79. package/dist/lib/templates/backends/graphGenerator/node.d.ts +0 -7
  80. package/dist/lib/templates/backends/graphGenerator/node.js +0 -18
  81. package/dist/lib/templates/backends/graphGenerator/promptNode.d.ts +0 -8
  82. package/dist/lib/templates/backends/graphGenerator/promptNode.js +0 -16
@@ -1,4 +1,4 @@
1
- export declare const template = "const {{{name:string}}}Tool = {\n name: \"{{{name:string}}}\",\n description: \"{{{description:string}}}\",\n schema: z.object({{{schema:string}}})\n};\n";
1
+ export declare const template = "const {{{name:string}}}Tool = {\n name: \"{{{name:string}}}\",\n description: `{{{description:string}}}`,\n schema: z.object({{{schema:string}}})\n};\n";
2
2
  export type TemplateType = {
3
3
  name: string;
4
4
  description: string;
@@ -4,7 +4,7 @@
4
4
  import { apply } from "typestache";
5
5
  export const template = `const {{{name:string}}}Tool = {
6
6
  name: "{{{name:string}}}",
7
- description: "{{{description:string}}}",
7
+ description: \`{{{description:string}}}\`,
8
8
  schema: z.object({{{schema:string}}})
9
9
  };
10
10
  `;
@@ -1,4 +1,4 @@
1
- export declare const template = "if (\n toolCall.name === \"{{{name:string}}}\"\n) {\n const args = toolCall.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(toolMessage(result, {\n tool_call_id: toolCall.id,\n name: toolCall.name,\n }));\n}";
1
+ export declare const template = "if (\n toolCall.name === \"{{{name:string}}}\"\n) {\n const args = toolCall.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(toolMessage(result, {\n tool_call_id: toolCall.id,\n name: toolCall.name,\n }));\n}";
2
2
  export type TemplateType = {
3
3
  name: string;
4
4
  };
@@ -11,8 +11,8 @@ export const template = `if (
11
11
  const result = await {{{name}}}(args);
12
12
  toolCallEndTime = performance.now();
13
13
 
14
- console.log("Tool '{{{name:string}}}' called with arguments:", args);
15
- console.log("Tool '{{{name:string}}}' returned result:", result);
14
+ // console.log("Tool '{{{name:string}}}' called with arguments:", args);
15
+ // console.log("Tool '{{{name:string}}}' returned result:", result);
16
16
 
17
17
  statelogClient.toolCall({
18
18
  toolName: "{{{name:string}}}",
@@ -0,0 +1,7 @@
1
+ import { AccessExpression } from "./access.js";
2
+ import { FunctionCall } from "./function.js";
3
+ import { Literal } from "./literals.js";
4
+ export type AwaitStatement = {
5
+ type: "awaitStatement";
6
+ expression: AccessExpression | Literal | FunctionCall;
7
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -1,10 +1,11 @@
1
1
  import { AgencyNode, FunctionCall, VariableType } from "../types.js";
2
2
  import { AccessExpression } from "./access.js";
3
+ import { FunctionParameter } from "./function.js";
3
4
  import { Literal } from "./literals.js";
4
5
  export type GraphNodeDefinition = {
5
6
  type: "graphNode";
6
7
  nodeName: string;
7
- parameters: string[];
8
+ parameters: FunctionParameter[];
8
9
  body: AgencyNode[];
9
10
  returnType?: VariableType | null;
10
11
  };
@@ -0,0 +1,7 @@
1
+ import { AccessExpression, AgencyNode, FunctionCall, IndexAccess, Literal } from "../types.js";
2
+ export type IfElse = {
3
+ type: "ifElse";
4
+ condition: IndexAccess | FunctionCall | AccessExpression | Literal;
5
+ thenBody: AgencyNode[];
6
+ elseBody?: AgencyNode[];
7
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -5,7 +5,7 @@ export type NumberLiteral = {
5
5
  };
6
6
  export type StringLiteral = {
7
7
  type: "string";
8
- value: string;
8
+ segments: PromptSegment[];
9
9
  };
10
10
  export type MultiLineStringLiteral = {
11
11
  type: "multiLineString";
@@ -1,6 +1,7 @@
1
1
  import { AccessExpression, FunctionCall, IndexAccess, Literal } from "../types.js";
2
+ import { AwaitStatement } from "./await.js";
2
3
  import { AgencyArray, AgencyObject } from "./dataStructures.js";
3
4
  export type ReturnStatement = {
4
5
  type: "returnStatement";
5
- value: AccessExpression | FunctionCall | Literal | AgencyObject | AgencyArray | IndexAccess;
6
+ value: AccessExpression | FunctionCall | Literal | AgencyObject | AgencyArray | IndexAccess | AwaitStatement;
6
7
  };
@@ -0,0 +1,5 @@
1
+ import { AgencyNode } from "../types.js";
2
+ export type TimeBlock = {
3
+ type: "timeBlock";
4
+ body: AgencyNode[];
5
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -1,19 +1,23 @@
1
- import { Literal } from "./types/literals.js";
2
- import { TypeAlias, TypeHint, VariableType } from "./types/typeHints.js";
3
- import { MatchBlock } from "./types/matchBlock.js";
4
1
  import { AccessExpression, DotProperty, IndexAccess } from "./types/access.js";
5
- import { FunctionCall, FunctionDefinition } from "./types/function.js";
2
+ import { AwaitStatement } from "./types/await.js";
6
3
  import { AgencyArray, AgencyObject } from "./types/dataStructures.js";
4
+ import { FunctionCall, FunctionDefinition } from "./types/function.js";
7
5
  import { GraphNodeDefinition } from "./types/graphNode.js";
6
+ import { ImportStatement } from "./types/importStatement.js";
7
+ import { Literal } from "./types/literals.js";
8
+ import { MatchBlock } from "./types/matchBlock.js";
8
9
  import { ReturnStatement } from "./types/returnStatement.js";
10
+ import { SpecialVar } from "./types/specialVar.js";
11
+ import { TimeBlock } from "./types/timeBlock.js";
9
12
  import { UsesTool } from "./types/tools.js";
10
- import { ImportStatement } from "./types/importStatement.js";
13
+ import { TypeAlias, TypeHint, VariableType } from "./types/typeHints.js";
11
14
  import { WhileLoop } from "./types/whileLoop.js";
12
- import { SpecialVar } from "./types/specialVar.js";
15
+ import { IfElse } from "./types/ifElse.js";
13
16
  export * from "./types/access.js";
14
17
  export * from "./types/dataStructures.js";
15
18
  export * from "./types/function.js";
16
19
  export * from "./types/graphNode.js";
20
+ export * from "./types/ifElse.js";
17
21
  export * from "./types/importStatement.js";
18
22
  export * from "./types/literals.js";
19
23
  export * from "./types/matchBlock.js";
@@ -24,13 +28,17 @@ export * from "./types/whileLoop.js";
24
28
  export type Assignment = {
25
29
  type: "assignment";
26
30
  variableName: string;
27
- value: AccessExpression | Literal | FunctionCall | AgencyObject | AgencyArray | IndexAccess;
31
+ typeHint?: VariableType;
32
+ value: AccessExpression | Literal | FunctionCall | AgencyObject | AgencyArray | IndexAccess | TimeBlock | AwaitStatement;
28
33
  };
29
34
  export type AgencyComment = {
30
35
  type: "comment";
31
36
  content: string;
32
37
  };
33
- export type AgencyNode = TypeHint | TypeAlias | UsesTool | GraphNodeDefinition | FunctionDefinition | Assignment | Literal | FunctionCall | MatchBlock | ReturnStatement | AccessExpression | AgencyComment | AgencyObject | AgencyArray | ImportStatement | WhileLoop | SpecialVar | IndexAccess | DotProperty;
38
+ export type NewLine = {
39
+ type: "newLine";
40
+ };
41
+ export type AgencyNode = TypeHint | TypeAlias | UsesTool | GraphNodeDefinition | FunctionDefinition | Assignment | Literal | FunctionCall | MatchBlock | ReturnStatement | AccessExpression | AgencyComment | AgencyObject | AgencyArray | ImportStatement | WhileLoop | IfElse | SpecialVar | IndexAccess | DotProperty | TimeBlock | AwaitStatement | NewLine;
34
42
  export type AgencyProgram = {
35
43
  type: "agencyProgram";
36
44
  nodes: AgencyNode[];
package/dist/lib/types.js CHANGED
@@ -2,6 +2,7 @@ export * from "./types/access.js";
2
2
  export * from "./types/dataStructures.js";
3
3
  export * from "./types/function.js";
4
4
  export * from "./types/graphNode.js";
5
+ export * from "./types/ifElse.js";
5
6
  export * from "./types/importStatement.js";
6
7
  export * from "./types/literals.js";
7
8
  export * from "./types/matchBlock.js";
@@ -1,3 +1,4 @@
1
1
  export declare function escape(str: string): string;
2
2
  export declare function deepCopy<T>(obj: T): T;
3
3
  export declare function zip<T, U>(arr1: T[], arr2: U[]): Array<[T, U]>;
4
+ export declare function uniq<T>(arr: T[]): T[];
package/dist/lib/utils.js CHANGED
@@ -16,3 +16,6 @@ export function zip(arr1, arr2) {
16
16
  }
17
17
  return result;
18
18
  }
19
+ export function uniq(arr) {
20
+ return Array.from(new Set(arr));
21
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agency-lang",
3
- "version": "0.0.20",
3
+ "version": "0.0.22",
4
4
  "description": "The Agency language",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -48,6 +48,7 @@
48
48
  },
49
49
  "devDependencies": {
50
50
  "@types/node": "^25.0.3",
51
+ "cli-highlight": "^2.1.11",
51
52
  "nanoid": "^5.1.6",
52
53
  "piemachine": "^0.0.3",
53
54
  "statelog-client": "^0.0.31",
@@ -55,4 +56,4 @@
55
56
  "typescript": "^5.9.3",
56
57
  "vitest": "^4.0.16"
57
58
  }
58
- }
59
+ }
@@ -1,3 +0,0 @@
1
- import { Assignment } from "../types.js";
2
- import { Parser } from "tarsec";
3
- export declare const assignmentParser: Parser<Assignment>;
@@ -1,8 +0,0 @@
1
- import { capture, char, many1WithJoin, or, seqC, set, trace, } from "tarsec";
2
- import { accessExpressionParser, indexAccessParser } from "./access.js";
3
- import { agencyArrayParser, agencyObjectParser } from "./dataStructures.js";
4
- import { functionCallParser } from "./functionCall.js";
5
- import { literalParser } from "./literals.js";
6
- import { optionalSemicolon } from "./parserUtils.js";
7
- import { optionalSpaces, varNameChar } from "./utils.js";
8
- export const assignmentParser = trace("assignmentParser", seqC(set("type", "assignment"), optionalSpaces, capture(many1WithJoin(varNameChar), "variableName"), optionalSpaces, char("="), optionalSpaces, capture(or(functionCallParser, indexAccessParser, accessExpressionParser, agencyArrayParser, agencyObjectParser, literalParser), "value"), optionalSemicolon));
@@ -1,7 +0,0 @@
1
- export declare const template = "let {{{name:string}}}:any;\n\ngraph.node(\"{{{name}}}\", async (state) => {\n const innerFunc = async () => {\n {{{body}}}\n };\n {{{name}}} = await innerFunc();\n return {{{name}}};\n});\n";
2
- export type TemplateType = {
3
- name: string;
4
- body: string | boolean | number;
5
- };
6
- declare const render: (args: TemplateType) => string;
7
- export default render;
@@ -1,18 +0,0 @@
1
- // THIS FILE WAS AUTO-GENERATED
2
- // Source: lib/templates/backends/graphGenerator/node.mustache
3
- // Any manual changes will be lost.
4
- import { apply } from "typestache";
5
- export const template = `let {{{name:string}}}:any;
6
-
7
- graph.node("{{{name}}}", async (state) => {
8
- const innerFunc = async () => {
9
- {{{body}}}
10
- };
11
- {{{name}}} = await innerFunc();
12
- return {{{name}}};
13
- });
14
- `;
15
- const render = (args) => {
16
- return apply(template, args);
17
- };
18
- export default render;
@@ -1,8 +0,0 @@
1
- export declare const template = "let {{{name:string}}}:any;\n\ngraph.node(\"{{{name}}}\", async (state) => {\n const innerFunc = {{{promptFunction:string}}};\n {{{name}}} = await innerFunc({{{argsStr:string}}});\n return {{{name}}};\n});\n";
2
- export type TemplateType = {
3
- name: string;
4
- promptFunction: string;
5
- argsStr: string;
6
- };
7
- declare const render: (args: TemplateType) => string;
8
- export default render;
@@ -1,16 +0,0 @@
1
- // THIS FILE WAS AUTO-GENERATED
2
- // Source: lib/templates/backends/graphGenerator/promptNode.mustache
3
- // Any manual changes will be lost.
4
- import { apply } from "typestache";
5
- export const template = `let {{{name:string}}}:any;
6
-
7
- graph.node("{{{name}}}", async (state) => {
8
- const innerFunc = {{{promptFunction:string}}};
9
- {{{name}}} = await innerFunc({{{argsStr:string}}});
10
- return {{{name}}};
11
- });
12
- `;
13
- const render = (args) => {
14
- return apply(template, args);
15
- };
16
- export default render;