agentlang 0.0.12 → 0.0.14

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 (74) hide show
  1. package/README.md +2 -19
  2. package/out/cli/main.d.ts.map +1 -1
  3. package/out/cli/main.js +5 -0
  4. package/out/cli/main.js.map +1 -1
  5. package/out/extension/main.cjs +250 -250
  6. package/out/extension/main.cjs.map +2 -2
  7. package/out/language/generated/ast.d.ts +23 -12
  8. package/out/language/generated/ast.d.ts.map +1 -1
  9. package/out/language/generated/ast.js +18 -2
  10. package/out/language/generated/ast.js.map +1 -1
  11. package/out/language/generated/grammar.d.ts.map +1 -1
  12. package/out/language/generated/grammar.js +231 -122
  13. package/out/language/generated/grammar.js.map +1 -1
  14. package/out/language/main.cjs +747 -908
  15. package/out/language/main.cjs.map +4 -4
  16. package/out/runtime/agents/common.d.ts +1 -1
  17. package/out/runtime/agents/common.d.ts.map +1 -1
  18. package/out/runtime/agents/common.js +32 -9
  19. package/out/runtime/agents/common.js.map +1 -1
  20. package/out/runtime/agents/impl/anthropic.d.ts +26 -0
  21. package/out/runtime/agents/impl/anthropic.d.ts.map +1 -0
  22. package/out/runtime/agents/impl/anthropic.js +106 -0
  23. package/out/runtime/agents/impl/anthropic.js.map +1 -0
  24. package/out/runtime/agents/impl/openai.d.ts +22 -0
  25. package/out/runtime/agents/impl/openai.d.ts.map +1 -1
  26. package/out/runtime/agents/impl/openai.js +83 -4
  27. package/out/runtime/agents/impl/openai.js.map +1 -1
  28. package/out/runtime/agents/registry.d.ts.map +1 -1
  29. package/out/runtime/agents/registry.js +49 -5
  30. package/out/runtime/agents/registry.js.map +1 -1
  31. package/out/runtime/integrations.d.ts +3 -0
  32. package/out/runtime/integrations.d.ts.map +1 -0
  33. package/out/runtime/integrations.js +72 -0
  34. package/out/runtime/integrations.js.map +1 -0
  35. package/out/runtime/interpreter.d.ts.map +1 -1
  36. package/out/runtime/interpreter.js +73 -32
  37. package/out/runtime/interpreter.js.map +1 -1
  38. package/out/runtime/jsmodules.js +1 -1
  39. package/out/runtime/jsmodules.js.map +1 -1
  40. package/out/runtime/loader.js +2 -2
  41. package/out/runtime/loader.js.map +1 -1
  42. package/out/runtime/module.d.ts +2 -0
  43. package/out/runtime/module.d.ts.map +1 -1
  44. package/out/runtime/module.js +13 -2
  45. package/out/runtime/module.js.map +1 -1
  46. package/out/runtime/resolvers/sqldb/database.js +1 -1
  47. package/out/runtime/resolvers/sqldb/database.js.map +1 -1
  48. package/out/runtime/resolvers/sqldb/dbutil.d.ts.map +1 -1
  49. package/out/runtime/resolvers/sqldb/dbutil.js +3 -2
  50. package/out/runtime/resolvers/sqldb/dbutil.js.map +1 -1
  51. package/out/runtime/state.d.ts +28 -0
  52. package/out/runtime/state.d.ts.map +1 -1
  53. package/out/runtime/state.js +8 -0
  54. package/out/runtime/state.js.map +1 -1
  55. package/out/syntaxes/agentlang.monarch.js +1 -1
  56. package/out/syntaxes/agentlang.monarch.js.map +1 -1
  57. package/package.json +8 -10
  58. package/src/cli/main.ts +10 -0
  59. package/src/language/agentlang.langium +14 -10
  60. package/src/language/generated/ast.ts +43 -13
  61. package/src/language/generated/grammar.ts +231 -122
  62. package/src/runtime/agents/common.ts +32 -9
  63. package/src/runtime/agents/impl/anthropic.ts +166 -0
  64. package/src/runtime/agents/impl/openai.ts +124 -4
  65. package/src/runtime/agents/registry.ts +51 -4
  66. package/src/runtime/integrations.ts +92 -0
  67. package/src/runtime/interpreter.ts +97 -35
  68. package/src/runtime/jsmodules.ts +1 -1
  69. package/src/runtime/loader.ts +2 -2
  70. package/src/runtime/module.ts +15 -2
  71. package/src/runtime/resolvers/sqldb/database.ts +1 -1
  72. package/src/runtime/resolvers/sqldb/dbutil.ts +3 -2
  73. package/src/runtime/state.ts +8 -0
  74. package/src/syntaxes/agentlang.monarch.ts +1 -1
@@ -1,2 +1,2 @@
1
- export declare const PlannerInstructions = "Agentlang is a very-high-level declarative language that makes it easy to define business applications as 'models'.\nThe model of a business application consists of entity definitions and workflows defined in \"modules\". \nA module will be encoded in a syntax inspired by JavaScript and JSON. Example of a simple module definition is,\n\nmodule Erp\n\nentity Employee {\n employeeId UUID @id @default(uuid()),\n firstName String,\n lastName String,\n salary Number,\n email Email @indexed\n}\n\nThe Empoyee entity is part of the \"Erp\" module and it has four attributes: employeeId, firstName, lastName, salary and email. The employeeId uniquely identifies an\nEmployee and it's automatically filled-in by the system by calling the \"uuid()\" function. (In the place of the keyword 'entity', the keyword 'record' may also be used.\nThe difference between an entity and a record is that, instances of an entity is persisted to the database, instances of records are not).\n\nThis is an example of a record:\n\nrecord EmailMessage {\n to Email,\n from Email,\n subject String,\n body String\n}\n\nWorkflows contains JSON \"patterns\" that perform CRUD operations on entities. For example, here's is a workflow that creates a new instance of the Employee entity:\n\nworkflow CreateEmployee {\n {Erp/Employee {firstName CreateEmployee.firstName,\n lastName CreateEmployee.lastName,\n salary CreateEmployee.salary,\n email CreateEmployee.email}}\n}\n\nThe attribute-values of the new Employee are derived from the \"event\" that triggers the workflow. In this example the event is called \"CreateEmployee\".\nAn event need not have an explicit schema, because its attributes can always be inferred from the workflow definition. But a model may also contain\nexplicit definitions of events, as follows,\n\nevent CreateEmployee {\n firstName String,\n lastName String,\n salary Number,\n email Email\n}\n\nA workflow attached to an event is invoked by creating an instance of the event, e.g:\n\n{Erp/CreateEmployee {firstName \"Sam\", lastName \"K\", salary 1400, email \"samk@acme.com\"}}\n\nThis means a workflow can be invoked from another workflow, simply by adding the event-creation as a pattern.\n\nOther than the create-pattern for entities and events, some of the most useful patterns (related to entities) that can appear in a workflow are:\n1. Query - e.g: '{Erp/Employee {employeeId? \"56392e13-0d9a-42f7-b556-0d7cd9468a24\"}}'. The attributes by which the query happens must end with a '?' character.\n To lookup all instances of an entity, use the syntax: '{EntityName?: {}}'.\n2. Update - e.g: '{Erp/Employee {employeeId? \"56392e13-0d9a-42f7-b556-0d7cd9468a24\", firstName \"Joe\"}}'. This pattern updates the firstName of the employee\n with the given employeeId.\n3. Upsert - e.g: '{Erp/Employee {employeeId \"56392e13-0d9a-42f7-b556-0d7cd9468a24\", firstName \"Joe\"}, @upsert}'. The 'upsert' pattern will create a new\n instance, if the instance does not already exist.\n4. Delete - e.g: delete '{Erp/Employee {employeeId? \"56392e13-0d9a-42f7-b556-0d7cd9468a24\"}}'\n\nThe default query operator is '=' (equals). So an expression like 'employeeId? \"56392e13-0d9a-42f7-b556-0d7cd9468a24\"' means,\n'where employeeId equals \"56392e13-0d9a-42f7-b556-0d7cd9468a24\"'. Other comparison operators has to be specified explicitly, as in\n'{age?< 50}' - which means 'where age less-than 50'. The comparison operators supported by a query pattern are:\n\n= - equals\n<> - not-equals\n< - less-than\n<= - less-than or equals\n> - greater-than\n>= - greater-than or equals\nin - membership check (argument must be an array)\nlike - string-ends-with?\nbetween - between given values (argument must be an array)\n\nTwo comparison expressions can be combined together by the logical operators 'or' and 'and'. The comparison and logical expressions produce a boolean\nresult, represented by 'true' or 'false'. A boolean value can be inversed by using the 'not' expression, e.g: 'not(some-value)'\n\nIn addition to the basic CRUD patterns, you can execute conditional-logic with the help of the 'if' pattern. An example follows,\n\nworkflow IncrementSalary {\n if (IncrementSalary.percentage > 10) {\n {Erp/Employee {employeeId IncrementSalary.employeeId, salary salary + salary * IncrementSalary.percentage}}\n } else {\n {Erp/Employee {employeeId IncrementSalary.employeeId, salary salary + 1500}}\n }\n}\n\nNote the value passed to the 'salary' attribute - it's an arithmetic expression. All normal arithmetic expressions are supported by workflow patterns.\n\nA successful query pattern will return an array of instances. The 'for' pattern can be used to iterate over an array. An example follows:\n\nworkflow NotifyEmployees {\n {Erp/Employee {salary?> 1000}} @as employees;\n for emp in employees {\n {Erp/SendMail {email emp.email, body \"You are selected for an increment!\"}}\n }\n}\n\nAlso note the use of the '@as' keyword - this binds the result of a pattern to an 'alias'. Here the result of the query is bound to the\nalias named 'employees'. Any pattern can have an alias, including 'if' and 'for'. An alias can be used to refer to the attributes of the instance, \nvia the dot(.) notation. Aliases can also be used to destructure a query result - here's an example:\n\nworkflow FindFirstTwoEmployees {\n {Erp/Employee {salary?> 1000}} @as [emp1, emp2];\n [emp1, emp2]\n}\n\nThis alias will bind the first two instances to 'a' and 'b' and the rest of the instances to an array named 'xs':\n\n{SomeEntity {id?> 1}} @as [a, b, _, xs]\n\nExamples of binding aliases to 'if' and 'for':\n\nif (IncrementSalary.percentage > 10) {\n {Erp/Employee {employeeId IncrementSalary.employeeId, salary salary + salary * IncrementSalary.percentage}}\n} else {\n {Erp/Employee {employeeId IncrementSalary.employeeId, salary salary + 1500}}\n} @as emp\n\nfor emp in employees {\n {Erp/SendMail {email emp.email, body \"You are selected for an increment!\"}}\n} @as emails\n\nMake sure all references based on a preceding pattern is based either on an actual alias or the name of the workflow. For example, the following sequence of patterns\nare invalid, because the alias 'employee' is not defined:\n\n{Employee {id? 101}};\n{SendEmail {to employee.email, body \"hello\"}}\n\nA fix for the reference-error is shown below:\n\n{Employee {id? 101}} @as employee;\n{SendEmail {to employee.email, body \"hello\"}}\n\nEntities in a module can be connected together in relationships. There are two types of relationships - 'contains' and 'between'.\n'Contains' relationship is for hierarchical data, as in a Library entity containing Books. 'Between' relationship is for graph-like data,\nlike two Profiles in a social media app is connected as friends. A 'between' relationship can be one of the following three types - 'one_one' (one-to-one),\n'one_many' (one-to-many) and 'many_many' (many-to-many), which is the default.\n\nThe following example shows how additional profile data for an employee could be defined as a new entity and attached to the Employee entity as a between-relationship:\n\nentity Profile {\n id UUID @id @default(uuid()),\n address String @optional,\n photo URL @optional,\n dateOfBirth DateTime @optional\n}\n\nrelationship EmployeeProfile between (Erp/Employee, Erp/Profile) @one_one\n\nThe '@one_one' annotation means exactly one Employee and Profile can be related to each other via 'EmployeeProfile'.\n\nHere's the 'CreateEmployee' workflow updated to create the Employee with the his/her Profile attached:\n\nworkflow CreateEmployee {\n {Erp/Employee {firstName CreateEmployee.firstName,\n lastName CreateEmployee.lastName,\n salary CreateEmployee.salary,\n email CreateEmployee.email},\n Erp/EmployeeProfile {Erp/Profile {address CreateEmployee.address,\n photo CreateEmployee.photo,\n dateOfBirth CreateEmployee.dateOfBirth}}}\n}\n\nThe following pattern can be user to query an Employee along with his Profile:\n\n{Erp/Employee {employeeId? \"56392e13-0d9a-42f7-b556-0d7cd9468a24\"},\n Erp/EmployeeProfile {Erp/Profile? {}}}\n\nAs an example of 'contains' relaionships, consider modelling task-assignments for an Employee as folllows:\n\nentity TaskAssignment {\n id UUID @id @default(uuid()),\n description String,\n assignmentDate DateTime @default(now())\n}\n\nrelationship EmployeeTaskAssignment contains (Erp/Employee, Erp/TaskAssignment)\n\nThe following workflow shows how to assign a new task to an Employee:\n\nworkflow AssignNewTask {\n {Erp/Employee {employeeId? AssignNewTask.employeeId},\n Erp/EmployeeTaskAssignment {Erp/TaskAssignment {description AssignNewTask.description}}}\n}\n\nThe following workflow queries an Employee along with all his tasks:\n\nworkflow GetEmployeeTaskAssignments {\n {Erp/Employee {employeeId? GetEmployeeTaskAssignments.employeeId},\n Erp/EmployeeTaskAssignment {Erp/TaskAssignment? {}}}\n}\n\nA general rule regarding generating workflows - as much as possible, do not include references to the workflow event in the patterns. Try to\nfill-in values from the available context. For example, if your instruction is \"create a workflow to send an email to employee 101 with this message - \n'please call me as soon as possible'\", the best workflow to return is:\n\nworkflow sendEmail {\n {employee {id? 101}} @as emp;\n {email {to emp.email body \"please call me as soon as possible\"}}\n}\n\nbecause all the information needed is available in the context. If the instruction is \"create a workflow to send an email by employee-id with this message - \n'please call me as soon as possible'\", then you can return:\n\nworkflow sendEmail {\n {employee {id? sendEmail.employeeId}} @as emp;\n {email {to emp.email body \"please call me as soon as possible\"}}\n}\n\nThe point is use the immediate context to fill-in values in generated patterns, as much as possible.\n\nAlso generate a workflow only if required explicitly by the user or the contextual information is incomplete. Otherwise, just return an array of patterns.\nAs an example, if the user request is \"send an email to employee 101 with this message - 'please call me as soon as possible'\", you must return:\n\n[{employee {id? 101}} @as emp;\n {email {to emp.email, body \"please call me as soon as possible\"}}]\n\nNote that each pattern in the array is separated by a ; and not a comma(,).\n\nNow consider the following module definition and generate appropriate patterns in response to the user instructions. You must return only valid patterns or workflows,\nno other descriptive text or comments are needed.\n";
1
+ export declare const PlannerInstructions = "Agentlang is a very-high-level declarative language that makes it easy to define business applications as 'models'.\nThe model of a business application consists of entity definitions and workflows defined in \"modules\". \nA module is be encoded in a syntax inspired by JavaScript and JSON. Example of a simple module follows:\n\nmodule Erp\n\nentity Employee {\n employeeId UUID @id @default(uuid()),\n firstName String,\n lastName String,\n salary Number,\n email Email @indexed\n}\n\nThe Empoyee entity is part of the \"Erp\" module and it has four attributes: 'employeeId', 'firstName', 'lastName', 'salary' and 'email'. \nThe 'employeeId' attribute uniquely identifies an instance of the Employee entity and it's automatically filled-in by the system by calling the \"uuid()\" function. \nIn the place of the keyword 'entity', the keyword 'record' may also be used. The difference between an entity and a record is that, \ninstances of an entity is persisted to the database, instances of records are not.\n\nThis is an example of a record:\n\nrecord EmailMessage {\n to Email,\n from Email,\n subject String,\n body String\n}\n\nAnother major construct in Agentlang is the 'workflow'. Workflows contains JSON \"patterns\" that perform CRUD operations on entities. \nFor example, here's is a workflow that creates a new instance of the Employee entity:\n\nworkflow CreateEmployee {\n {Erp/Employee {firstName CreateEmployee.firstName,\n lastName CreateEmployee.lastName,\n salary CreateEmployee.salary,\n email CreateEmployee.email}}\n}\n\nThe attribute-values of the new Employee are derived from the \"event\" that triggers the workflow. In this example the event is called \"CreateEmployee\".\nAn event need not have an explicit schema, because its attributes can always be inferred from the workflow definition. But a model may also contain\nexplicit definitions of events, as follows,\n\nevent CreateEmployee {\n firstName String,\n lastName String,\n salary Number,\n email Email\n}\n\nA workflow attached to an event is invoked by creating an instance of the event, e.g:\n\n{Erp/CreateEmployee {firstName \"Sam\", lastName \"K\", salary 1400, email \"samk@acme.com\"}}\n\nThis means a workflow can be invoked from another workflow, simply by having the event-creation pattern.\n\nOther than the create-pattern for entities and events, some of the most useful patterns (related to entities) that can appear in a workflow are:\n1. Query - e.g: '{Erp/Employee {employeeId? \"56392e13-0d9a-42f7-b556-0d7cd9468a24\"}}'. The attributes by which the query happens must end with a '?' character.\n To lookup all instances of an entity, use the syntax: '{EntityName?: {}}'.\n2. Update - e.g: '{Erp/Employee {employeeId? \"56392e13-0d9a-42f7-b556-0d7cd9468a24\", firstName \"Joe\"}}'. This pattern updates the firstName of the employee\n with the given employeeId.\n3. Upsert - e.g: '{Erp/Employee {employeeId \"56392e13-0d9a-42f7-b556-0d7cd9468a24\", firstName \"Joe\"}, @upsert}'. The 'upsert' pattern will create a new\n instance, if the instance does not already exist.\n4. Delete - e.g: 'delete {Erp/Employee {employeeId? \"56392e13-0d9a-42f7-b556-0d7cd9468a24\"}}'\n\nThe default query operator is '=' (equals). So an expression like 'employeeId? \"56392e13-0d9a-42f7-b556-0d7cd9468a24\"' means,\n'where employeeId equals \"56392e13-0d9a-42f7-b556-0d7cd9468a24\"'. Other comparison operators has to be specified explicitly, as in\n'{age?< 50}' - which means 'where age less-than 50'. The comparison operators supported by a query pattern are:\n\n= - equals\n<> - not-equals\n< - less-than\n<= - less-than or equals\n> - greater-than\n>= - greater-than or equals\nin - membership check (argument must be an array)\nlike - string-ends-with?\nbetween - between given values (argument must be an array)\n\nTwo comparison expressions can be combined together by the logical operators 'or' and 'and'. The comparison and logical expressions produce a boolean\nresult, represented by 'true' or 'false'. A boolean value can be inversed by using the 'not' expression, e.g: 'not(some-value)'\n\nIn addition to the basic CRUD patterns, you can execute conditional-logic with the help of the 'if' pattern. An example follows,\n\nworkflow IncrementSalary {\n if (IncrementSalary.percentage > 10) {\n {Erp/Employee {employeeId IncrementSalary.employeeId, salary salary + salary * IncrementSalary.percentage}}\n } else {\n {Erp/Employee {employeeId IncrementSalary.employeeId, salary salary + 1500}}\n }\n}\n\nNote the value passed to the 'salary' attribute - it's an arithmetic expression. All normal arithmetic expressions are supported by workflow patterns.\n\nAnother example of the 'if' pattern:\n\nworkflow validateLicense {\n {checkLicenseNumber {number validateLicense.number}} @as response;\n if (response = \"ok\") {\n {license {number? validateLicense.number, status \"active\"}}\n } else {\n {license {number? validateLicense.number, status \"canceled\"}}\n }\n}\n\nAlso note the use of the '@as' keyword - this binds the result of a pattern to an 'alias'.\n\nA successful query pattern will return an array of instances. The 'for' pattern can be used to iterate over an array. An example follows:\n\nworkflow NotifyEmployees {\n {Erp/Employee {salary?> 1000}} @as employees;\n for emp in employees {\n {Erp/SendMail {email emp.email, body \"You are selected for an increment!\"}}\n }\n}\n\nHere the result of the query is bound to the alias named 'employees'. Any pattern can have an alias, including 'if' and 'for'. An alias can be used to refer to the attributes of the instance, \nvia the dot(.) notation. Aliases can also be used to destructure a query result - here's an example:\n\nworkflow FindFirstTwoEmployees {\n {Erp/Employee {salary?> 1000}} @as [emp1, emp2];\n [emp1, emp2]\n}\n\nThis alias will bind the first two instances to 'a' and 'b' and the rest of the instances to an array named 'xs':\n\n{SomeEntity {id?> 1}} @as [a, b, _, xs]\n\nExamples of binding aliases to 'if' and 'for':\n\nif (IncrementSalary.percentage > 10) {\n {Erp/Employee {employeeId IncrementSalary.employeeId, salary salary + salary * IncrementSalary.percentage}}\n} else {\n {Erp/Employee {employeeId IncrementSalary.employeeId, salary salary + 1500}}\n} @as emp\n\nfor emp in employees {\n {Erp/SendMail {email emp.email, body \"You are selected for an increment!\"}}\n} @as emails\n\nMake sure all references based on a preceding pattern is based either on an actual alias or the name of the workflow. For example, the following sequence of patterns\nare invalid, because the alias 'employee' is not defined:\n\n{Employee {id? 101}};\n{SendEmail {to employee.email, body \"hello\"}}\n\nA fix for the reference-error is shown below:\n\n{Employee {id? 101}} @as employee;\n{SendEmail {to employee.email, body \"hello\"}}\n\nA pattern may execute asynchronously and its eventual result can be handled by patterns provided in the '@then' clause. An example is shown below:\n\n{sendChatMessage {to \"amy\", \"text\" \"hello\"}} @as response @then {\n {saveResponse {from \"amy\", \"text\" response}}\n}\n\nIf you are instructed that a particular event will be called asynchronously, always provide the patterns that follows in its '@then' clause. You must add the \n'@then' clause only if an event's documentation or instruction explicitly requires to do so.\n\nEntities in a module can be connected together in relationships. There are two types of relationships - 'contains' and 'between'.\n'Contains' relationship is for hierarchical data, as in a Library entity containing Books. 'Between' relationship is for graph-like data,\nlike two Profiles in a social media app is connected as friends. A 'between' relationship can be one of the following three types - 'one_one' (one-to-one),\n'one_many' (one-to-many) and 'many_many' (many-to-many), which is the default.\n\nThe following example shows how additional profile data for an employee could be defined as a new entity and attached to the Employee entity as a between-relationship:\n\nentity Profile {\n id UUID @id @default(uuid()),\n address String @optional,\n photo URL @optional,\n dateOfBirth DateTime @optional\n}\n\nrelationship EmployeeProfile between (Erp/Employee, Erp/Profile) @one_one\n\nThe '@one_one' annotation means exactly one Employee and Profile can be related to each other via 'EmployeeProfile'.\n\nHere's the 'CreateEmployee' workflow updated to create the Employee with the his/her Profile attached:\n\nworkflow CreateEmployee {\n {Erp/Employee {firstName CreateEmployee.firstName,\n lastName CreateEmployee.lastName,\n salary CreateEmployee.salary,\n email CreateEmployee.email},\n Erp/EmployeeProfile {Erp/Profile {address CreateEmployee.address,\n photo CreateEmployee.photo,\n dateOfBirth CreateEmployee.dateOfBirth}}}\n}\n\nThe following pattern can be user to query an Employee along with his Profile:\n\n{Erp/Employee {employeeId? \"56392e13-0d9a-42f7-b556-0d7cd9468a24\"},\n Erp/EmployeeProfile {Erp/Profile? {}}}\n\nAs an example of 'contains' relaionships, consider modelling task-assignments for an Employee as folllows:\n\nentity TaskAssignment {\n id UUID @id @default(uuid()),\n description String,\n assignmentDate DateTime @default(now())\n}\n\nrelationship EmployeeTaskAssignment contains (Erp/Employee, Erp/TaskAssignment)\n\nThe following workflow shows how to assign a new task to an Employee:\n\nworkflow AssignNewTask {\n {Erp/Employee {employeeId? AssignNewTask.employeeId},\n Erp/EmployeeTaskAssignment {Erp/TaskAssignment {description AssignNewTask.description}}}\n}\n\nThe following workflow queries an Employee along with all his tasks:\n\nworkflow GetEmployeeTaskAssignments {\n {Erp/Employee {employeeId? GetEmployeeTaskAssignments.employeeId},\n Erp/EmployeeTaskAssignment {Erp/TaskAssignment? {}}}\n}\n\nA general rule regarding generating workflows - as much as possible, do not include references to the workflow event in the patterns. Try to\nfill-in values from the available context. For example, if your instruction is \"create a workflow to send an email to employee 101 with this message - \n'please call me as soon as possible'\", the best workflow to return is:\n\nworkflow sendEmail {\n {employee {id? 101}} @as emp;\n {email {to emp.email body \"please call me as soon as possible\"}}\n}\n\nbecause all the information needed is available in the context. If the instruction is \"create a workflow to send an email by employee-id with this message - \n'please call me as soon as possible'\", then you can return:\n\nworkflow sendEmail {\n {employee {id? sendEmail.employeeId}} @as emp;\n {email {to emp.email body \"please call me as soon as possible\"}}\n}\n\nThe point is use the immediate context to fill-in values in generated patterns, as much as possible.\n\nAlso generate a workflow only if required explicitly by the user or the contextual information is incomplete. Otherwise, just return an array of patterns.\nAs an example, if the user request is \"send an email to employee 101 with this message - 'please call me as soon as possible'\", you must return:\n\n[{employee {id? 101}} @as emp;\n {email {to emp.email, body \"please call me as soon as possible\"}}]\n\nNote that each pattern in the array is separated by a ; and not a comma(,).\n\nNow consider the following module definition and generate appropriate patterns in response to the user instructions. You must return only valid patterns or workflows,\nno other descriptive text or comments are needed.\n";
2
2
  //# sourceMappingURL=common.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../src/runtime/agents/common.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,mBAAmB,6rVAgO/B,CAAC"}
1
+ {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../src/runtime/agents/common.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,mBAAmB,yoXAuP/B,CAAC"}
@@ -1,6 +1,6 @@
1
1
  export const PlannerInstructions = `Agentlang is a very-high-level declarative language that makes it easy to define business applications as 'models'.
2
2
  The model of a business application consists of entity definitions and workflows defined in "modules".
3
- A module will be encoded in a syntax inspired by JavaScript and JSON. Example of a simple module definition is,
3
+ A module is be encoded in a syntax inspired by JavaScript and JSON. Example of a simple module follows:
4
4
 
5
5
  module Erp
6
6
 
@@ -12,9 +12,10 @@ entity Employee {
12
12
  email Email @indexed
13
13
  }
14
14
 
15
- The Empoyee entity is part of the "Erp" module and it has four attributes: employeeId, firstName, lastName, salary and email. The employeeId uniquely identifies an
16
- Employee and it's automatically filled-in by the system by calling the "uuid()" function. (In the place of the keyword 'entity', the keyword 'record' may also be used.
17
- The difference between an entity and a record is that, instances of an entity is persisted to the database, instances of records are not).
15
+ The Empoyee entity is part of the "Erp" module and it has four attributes: 'employeeId', 'firstName', 'lastName', 'salary' and 'email'.
16
+ The 'employeeId' attribute uniquely identifies an instance of the Employee entity and it's automatically filled-in by the system by calling the "uuid()" function.
17
+ In the place of the keyword 'entity', the keyword 'record' may also be used. The difference between an entity and a record is that,
18
+ instances of an entity is persisted to the database, instances of records are not.
18
19
 
19
20
  This is an example of a record:
20
21
 
@@ -25,7 +26,8 @@ record EmailMessage {
25
26
  body String
26
27
  }
27
28
 
28
- Workflows contains JSON "patterns" that perform CRUD operations on entities. For example, here's is a workflow that creates a new instance of the Employee entity:
29
+ Another major construct in Agentlang is the 'workflow'. Workflows contains JSON "patterns" that perform CRUD operations on entities.
30
+ For example, here's is a workflow that creates a new instance of the Employee entity:
29
31
 
30
32
  workflow CreateEmployee {
31
33
  {Erp/Employee {firstName CreateEmployee.firstName,
@@ -49,7 +51,7 @@ A workflow attached to an event is invoked by creating an instance of the event,
49
51
 
50
52
  {Erp/CreateEmployee {firstName "Sam", lastName "K", salary 1400, email "samk@acme.com"}}
51
53
 
52
- This means a workflow can be invoked from another workflow, simply by adding the event-creation as a pattern.
54
+ This means a workflow can be invoked from another workflow, simply by having the event-creation pattern.
53
55
 
54
56
  Other than the create-pattern for entities and events, some of the most useful patterns (related to entities) that can appear in a workflow are:
55
57
  1. Query - e.g: '{Erp/Employee {employeeId? "56392e13-0d9a-42f7-b556-0d7cd9468a24"}}'. The attributes by which the query happens must end with a '?' character.
@@ -58,7 +60,7 @@ Other than the create-pattern for entities and events, some of the most useful p
58
60
  with the given employeeId.
59
61
  3. Upsert - e.g: '{Erp/Employee {employeeId "56392e13-0d9a-42f7-b556-0d7cd9468a24", firstName "Joe"}, @upsert}'. The 'upsert' pattern will create a new
60
62
  instance, if the instance does not already exist.
61
- 4. Delete - e.g: delete '{Erp/Employee {employeeId? "56392e13-0d9a-42f7-b556-0d7cd9468a24"}}'
63
+ 4. Delete - e.g: 'delete {Erp/Employee {employeeId? "56392e13-0d9a-42f7-b556-0d7cd9468a24"}}'
62
64
 
63
65
  The default query operator is '=' (equals). So an expression like 'employeeId? "56392e13-0d9a-42f7-b556-0d7cd9468a24"' means,
64
66
  'where employeeId equals "56392e13-0d9a-42f7-b556-0d7cd9468a24"'. Other comparison operators has to be specified explicitly, as in
@@ -89,6 +91,19 @@ workflow IncrementSalary {
89
91
 
90
92
  Note the value passed to the 'salary' attribute - it's an arithmetic expression. All normal arithmetic expressions are supported by workflow patterns.
91
93
 
94
+ Another example of the 'if' pattern:
95
+
96
+ workflow validateLicense {
97
+ {checkLicenseNumber {number validateLicense.number}} @as response;
98
+ if (response = "ok") {
99
+ {license {number? validateLicense.number, status "active"}}
100
+ } else {
101
+ {license {number? validateLicense.number, status "canceled"}}
102
+ }
103
+ }
104
+
105
+ Also note the use of the '@as' keyword - this binds the result of a pattern to an 'alias'.
106
+
92
107
  A successful query pattern will return an array of instances. The 'for' pattern can be used to iterate over an array. An example follows:
93
108
 
94
109
  workflow NotifyEmployees {
@@ -98,8 +113,7 @@ workflow NotifyEmployees {
98
113
  }
99
114
  }
100
115
 
101
- Also note the use of the '@as' keyword - this binds the result of a pattern to an 'alias'. Here the result of the query is bound to the
102
- alias named 'employees'. Any pattern can have an alias, including 'if' and 'for'. An alias can be used to refer to the attributes of the instance,
116
+ Here the result of the query is bound to the alias named 'employees'. Any pattern can have an alias, including 'if' and 'for'. An alias can be used to refer to the attributes of the instance,
103
117
  via the dot(.) notation. Aliases can also be used to destructure a query result - here's an example:
104
118
 
105
119
  workflow FindFirstTwoEmployees {
@@ -134,6 +148,15 @@ A fix for the reference-error is shown below:
134
148
  {Employee {id? 101}} @as employee;
135
149
  {SendEmail {to employee.email, body "hello"}}
136
150
 
151
+ A pattern may execute asynchronously and its eventual result can be handled by patterns provided in the '@then' clause. An example is shown below:
152
+
153
+ {sendChatMessage {to "amy", "text" "hello"}} @as response @then {
154
+ {saveResponse {from "amy", "text" response}}
155
+ }
156
+
157
+ If you are instructed that a particular event will be called asynchronously, always provide the patterns that follows in its '@then' clause. You must add the
158
+ '@then' clause only if an event's documentation or instruction explicitly requires to do so.
159
+
137
160
  Entities in a module can be connected together in relationships. There are two types of relationships - 'contains' and 'between'.
138
161
  'Contains' relationship is for hierarchical data, as in a Library entity containing Books. 'Between' relationship is for graph-like data,
139
162
  like two Profiles in a social media app is connected as friends. A 'between' relationship can be one of the following three types - 'one_one' (one-to-one),
@@ -1 +1 @@
1
- {"version":3,"file":"common.js","sourceRoot":"","sources":["../../../src/runtime/agents/common.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,mBAAmB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgOlC,CAAC"}
1
+ {"version":3,"file":"common.js","sourceRoot":"","sources":["../../../src/runtime/agents/common.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,mBAAmB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuPlC,CAAC"}
@@ -0,0 +1,26 @@
1
+ import { AgentServiceProvider, AIResponse } from '../provider.js';
2
+ import { BaseMessage } from '@langchain/core/messages';
3
+ export interface AnthropicConfig {
4
+ model?: string;
5
+ temperature?: number;
6
+ maxTokens?: number;
7
+ maxRetries?: number;
8
+ apiKey?: string;
9
+ clientOptions?: {
10
+ defaultHeaders?: Record<string, string>;
11
+ [key: string]: any;
12
+ };
13
+ enablePromptCaching?: boolean;
14
+ cacheControl?: 'ephemeral';
15
+ }
16
+ export declare class AnthropicProvider implements AgentServiceProvider {
17
+ private model;
18
+ private config;
19
+ constructor(config?: Map<string, any>);
20
+ private parseConfig;
21
+ invoke(messages: BaseMessage[]): Promise<AIResponse>;
22
+ private applyCacheControl;
23
+ getConfig(): AnthropicConfig;
24
+ updateConfig(newConfig: Partial<AnthropicConfig>): void;
25
+ }
26
+ //# sourceMappingURL=anthropic.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anthropic.d.ts","sourceRoot":"","sources":["../../../../src/runtime/agents/impl/anthropic.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,UAAU,EAAgB,MAAM,gBAAgB,CAAC;AAChF,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD,MAAM,WAAW,eAAe;IAC9B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,aAAa,CAAC,EAAE;QACd,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACxC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;KACpB,CAAC;IACF,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,YAAY,CAAC,EAAE,WAAW,CAAC;CAC5B;AAED,qBAAa,iBAAkB,YAAW,oBAAoB;IAC5D,OAAO,CAAC,KAAK,CAAgB;IAC7B,OAAO,CAAC,MAAM,CAAkB;gBAEpB,MAAM,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC;IA+BrC,OAAO,CAAC,WAAW;IAmCb,MAAM,CAAC,QAAQ,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC,UAAU,CAAC;IAgB1D,OAAO,CAAC,iBAAiB;IA2BzB,SAAS,IAAI,eAAe;IAI5B,YAAY,CAAC,SAAS,EAAE,OAAO,CAAC,eAAe,CAAC,GAAG,IAAI;CA8BxD"}
@@ -0,0 +1,106 @@
1
+ import { ChatAnthropic } from '@langchain/anthropic';
2
+ import { asAIResponse } from '../provider.js';
3
+ export class AnthropicProvider {
4
+ constructor(config) {
5
+ var _a;
6
+ this.config = this.parseConfig(config);
7
+ const chatConfig = {
8
+ model: this.config.model,
9
+ temperature: this.config.temperature,
10
+ maxTokens: this.config.maxTokens,
11
+ maxRetries: this.config.maxRetries,
12
+ };
13
+ if (this.config.apiKey) {
14
+ chatConfig.apiKey = this.config.apiKey;
15
+ }
16
+ if (this.config.clientOptions) {
17
+ chatConfig.clientOptions = this.config.clientOptions;
18
+ }
19
+ if (this.config.enablePromptCaching) {
20
+ chatConfig.clientOptions = Object.assign(Object.assign({}, chatConfig.clientOptions), { defaultHeaders: Object.assign(Object.assign({}, (_a = chatConfig.clientOptions) === null || _a === void 0 ? void 0 : _a.defaultHeaders), { 'anthropic-beta': 'prompt-caching-2024-07-31' }) });
21
+ }
22
+ this.model = new ChatAnthropic(chatConfig);
23
+ }
24
+ parseConfig(config) {
25
+ var _a;
26
+ const defaultConfig = {
27
+ model: 'claude-sonnet-4-20250514',
28
+ temperature: 0.7,
29
+ maxTokens: 8192,
30
+ maxRetries: 2,
31
+ enablePromptCaching: false,
32
+ cacheControl: 'ephemeral',
33
+ };
34
+ if (!config) {
35
+ return Object.assign(Object.assign({}, defaultConfig), { apiKey: process.env.ANTHROPIC_API_KEY });
36
+ }
37
+ const apiKey = config.get('apiKey') || config.get('api_key') || process.env.ANTHROPIC_API_KEY;
38
+ return {
39
+ model: config.get('model') || defaultConfig.model,
40
+ temperature: (_a = config.get('temperature')) !== null && _a !== void 0 ? _a : defaultConfig.temperature,
41
+ maxTokens: config.get('maxTokens') || config.get('max_tokens') || defaultConfig.maxTokens,
42
+ maxRetries: config.get('maxRetries') || config.get('max_retries') || defaultConfig.maxRetries,
43
+ enablePromptCaching: config.get('enablePromptCaching') ||
44
+ config.get('enable_prompt_caching') ||
45
+ defaultConfig.enablePromptCaching,
46
+ cacheControl: config.get('cacheControl') || config.get('cache_control') || defaultConfig.cacheControl,
47
+ apiKey,
48
+ clientOptions: config.get('clientOptions') || config.get('client_options'),
49
+ };
50
+ }
51
+ async invoke(messages) {
52
+ if (!this.config.apiKey) {
53
+ throw new Error('Anthropic API key is required. Set ANTHROPIC_API_KEY environment variable or provide apiKey in config.');
54
+ }
55
+ let processedMessages = messages;
56
+ if (this.config.enablePromptCaching && messages.length > 0) {
57
+ processedMessages = this.applyCacheControl(messages);
58
+ }
59
+ return asAIResponse(await this.model.invoke(processedMessages));
60
+ }
61
+ applyCacheControl(messages) {
62
+ // Apply cache control to the last system message if present
63
+ // This follows Anthropic's recommendation to cache long context at the end of system messages
64
+ if (messages.length === 0)
65
+ return messages;
66
+ const processedMessages = [...messages];
67
+ // Find the last system message and apply cache control
68
+ for (let i = processedMessages.length - 1; i >= 0; i--) {
69
+ const message = processedMessages[i];
70
+ if (message._getType() === 'system') {
71
+ // Apply cache control to system message content
72
+ const content = message.content;
73
+ if (typeof content === 'string' && content.length > 1000) {
74
+ // Only cache if content is substantial (>1000 chars as a heuristic)
75
+ message.additional_kwargs = Object.assign(Object.assign({}, (message.additional_kwargs || {})), { cache_control: { type: 'ephemeral' } });
76
+ }
77
+ break;
78
+ }
79
+ }
80
+ return processedMessages;
81
+ }
82
+ getConfig() {
83
+ return Object.assign({}, this.config);
84
+ }
85
+ updateConfig(newConfig) {
86
+ var _a;
87
+ this.config = Object.assign(Object.assign({}, this.config), newConfig);
88
+ const chatConfig = {
89
+ model: this.config.model,
90
+ temperature: this.config.temperature,
91
+ maxTokens: this.config.maxTokens,
92
+ maxRetries: this.config.maxRetries,
93
+ };
94
+ if (this.config.apiKey) {
95
+ chatConfig.apiKey = this.config.apiKey;
96
+ }
97
+ if (this.config.clientOptions) {
98
+ chatConfig.clientOptions = this.config.clientOptions;
99
+ }
100
+ if (this.config.enablePromptCaching) {
101
+ chatConfig.clientOptions = Object.assign(Object.assign({}, chatConfig.clientOptions), { defaultHeaders: Object.assign(Object.assign({}, (_a = chatConfig.clientOptions) === null || _a === void 0 ? void 0 : _a.defaultHeaders), { 'anthropic-beta': 'prompt-caching-2024-07-31' }) });
102
+ }
103
+ this.model = new ChatAnthropic(chatConfig);
104
+ }
105
+ }
106
+ //# sourceMappingURL=anthropic.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anthropic.js","sourceRoot":"","sources":["../../../../src/runtime/agents/impl/anthropic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAoC,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAiBhF,MAAM,OAAO,iBAAiB;IAI5B,YAAY,MAAyB;;QACnC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QAEvC,MAAM,UAAU,GAAQ;YACtB,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,KAAK;YACxB,WAAW,EAAE,IAAI,CAAC,MAAM,CAAC,WAAW;YACpC,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,SAAS;YAChC,UAAU,EAAE,I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AAM,CAAC;QACzC,CAAC;QAED,IAAI,IAAI,CAAC,MAAM,CAAC,aAAa,EAAE,CAAC;YAC9B,UAAU,CAAC,aAAa,GAAG,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC;QACvD,CAAC;QAED,IAAI,IAAI,CAAC,MAAM,CAAC,mBAAmB,EAAE,CAAC;YACpC,UAAU,CAAC,aAAa,mCACnB,UAAU,CAAC,aAAa,KAC3B,cAAc,kCACT,MAAA,UAAU,CAAC,aAAa,0CAAE,cAAc,KAC3C,gBAAgB,EAAE,2BAA2B,MAEhD,CAAC;QACJ,CAAC;QAED,IAAI,CAAC,KAAK,GAAG,IAAI,aAAa,CAAC,UAAU,CAAC,CAAC;IAC7C,CAAC;CACF"}
@@ -1,8 +1,30 @@
1
1
  import { AgentServiceProvider, AIResponse } from '../provider.js';
2
2
  import { BaseMessage } from '@langchain/core/messages';
3
+ export interface OpenAIConfig {
4
+ model?: string;
5
+ temperature?: number;
6
+ maxTokens?: number;
7
+ topP?: number;
8
+ frequencyPenalty?: number;
9
+ presencePenalty?: number;
10
+ maxRetries?: number;
11
+ apiKey?: string;
12
+ configuration?: {
13
+ baseURL?: string;
14
+ defaultHeaders?: Record<string, string>;
15
+ [key: string]: any;
16
+ };
17
+ streamUsage?: boolean;
18
+ logprobs?: boolean;
19
+ topLogprobs?: number;
20
+ }
3
21
  export declare class OpenAIProvider implements AgentServiceProvider {
4
22
  private model;
23
+ private config;
5
24
  constructor(config?: Map<string, any>);
25
+ private parseConfig;
6
26
  invoke(messages: BaseMessage[]): Promise<AIResponse>;
27
+ getConfig(): OpenAIConfig;
28
+ updateConfig(newConfig: Partial<OpenAIConfig>): void;
7
29
  }
8
30
  //# sourceMappingURL=openai.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../../../../src/runtime/agents/impl/openai.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,UAAU,EAAgB,MAAM,gBAAgB,CA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AAC;IA2BrC,OAAO,CAAC,WAAW;IA6Cb,MAAM,CAAC,QAAQ,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC,UAAU,CAAC;IAS1D,SAAS,IAAI,YAAY;IAIzB,YAAY,CAAC,SAAS,EAAE,OAAO,CAAC,YAAY,CAAC,GAAG,IAAI;CA0BrD"}
@@ -2,14 +2,93 @@ import { ChatOpenAI } from '@langchain/openai';
2
2
  import { asAIResponse } from '../provider.js';
3
3
  export class OpenAIProvider {
4
4
  constructor(config) {
5
- let modelName = 'gpt-4.1-2025-04-14';
6
- if (config) {
7
- modelName = config.get('model') || modelName;
5
+ this.config = this.parseConfig(config);
6
+ const chatConfig = {
7
+ model: this.config.model,
8
+ temperature: this.config.temperature,
9
+ maxTokens: this.config.maxTokens,
10
+ topP: this.config.topP,
11
+ frequencyPenalty: this.config.frequencyPenalty,
12
+ presencePenalty: this.config.presencePenalty,
13
+ maxRetries: this.config.maxRetries,
14
+ streamUsage: this.config.streamUsage,
15
+ logprobs: this.config.logprobs,
16
+ topLogprobs: this.config.topLogprobs,
17
+ };
18
+ if (this.config.apiKey) {
19
+ chatConfig.apiKey = this.config.apiKey;
8
20
  }
9
- this.model = new ChatOpenAI({ model: modelName });
21
+ if (this.config.configuration) {
22
+ chatConfig.configuration = this.config.configuration;
23
+ }
24
+ this.model = new ChatOpenAI(chatConfig);
25
+ }
26
+ parseConfig(config) {
27
+ var _a, _b;
28
+ const defaultConfig = {
29
+ model: 'gpt-4o',
30
+ temperature: 0.7,
31
+ maxTokens: 4096,
32
+ topP: 1.0,
33
+ frequencyPenalty: 0,
34
+ presencePenalty: 0,
35
+ maxRetries: 2,
36
+ streamUsage: true,
37
+ logprobs: false,
38
+ };
39
+ if (!config) {
40
+ return Object.assign(Object.assign({}, defaultConfig), { apiKey: process.env.OPENAI_API_KEY });
41
+ }
42
+ const apiKey = config.get('apiKey') || config.get('api_key') || process.env.OPENAI_API_KEY;
43
+ return {
44
+ model: config.get('model') || defaultConfig.model,
45
+ temperature: (_a = config.get('temperature')) !== null && _a !== void 0 ? _a : defaultConfig.temperature,
46
+ maxTokens: config.get('maxTokens') || config.get('max_tokens') || defaultConfig.maxTokens,
47
+ topP: config.get('topP') || config.get('top_p') || defaultConfig.topP,
48
+ frequencyPenalty: config.get('frequencyPenalty') ||
49
+ config.get('frequency_penalty') ||
50
+ defaultConfig.frequencyPenalty,
51
+ presencePenalty: config.get('presencePenalty') ||
52
+ config.get('presence_penalty') ||
53
+ defaultConfig.presencePenalty,
54
+ maxRetries: config.get('maxRetries') || config.get('max_retries') || defaultConfig.maxRetries,
55
+ streamUsage: config.get('streamUsage') || config.get('stream_usage') || defaultConfig.streamUsage,
56
+ logprobs: (_b = config.get('logprobs')) !== null && _b !== void 0 ? _b : defaultConfig.logprobs,
57
+ topLogprobs: config.get('topLogprobs') || config.get('top_logprobs'),
58
+ apiKey,
59
+ configuration: config.get('configuration'),
60
+ };
10
61
  }
11
62
  async invoke(messages) {
63
+ if (!this.config.apiKey) {
64
+ throw new Error('OpenAI API key is required. Set OPENAI_API_KEY environment variable or provide apiKey in config.');
65
+ }
12
66
  return asAIResponse(await this.model.invoke(messages));
13
67
  }
68
+ getConfig() {
69
+ return Object.assign({}, this.config);
70
+ }
71
+ updateConfig(newConfig) {
72
+ this.config = Object.assign(Object.assign({}, this.config), newConfig);
73
+ const chatConfig = {
74
+ model: this.config.model,
75
+ temperature: this.config.temperature,
76
+ maxTokens: this.config.maxTokens,
77
+ topP: this.config.topP,
78
+ frequencyPenalty: this.config.frequencyPenalty,
79
+ presencePenalty: this.config.presencePenalty,
80
+ maxRetries: this.config.maxRetries,
81
+ streamUsage: this.config.streamUsage,
82
+ logprobs: this.config.logprobs,
83
+ topLogprobs: this.config.topLogprobs,
84
+ };
85
+ if (this.config.apiKey) {
86
+ chatConfig.apiKey = this.config.apiKey;
87
+ }
88
+ if (this.config.configuration) {
89
+ chatConfig.configuration = this.config.configuration;
90
+ }
91
+ this.model = new ChatOpenAI(chatConfig);
92
+ }
14
93
  }
15
94
  //# sourceMappingURL=openai.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"openai.js","sourceRoot":"","sources":["../../../../src/runtime/agents/impl/openai.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAoC,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAGhF,MAAM,OAAO,cAAc;IAGzB,YAAY,MAAyB;QACnC,IAAI,SAAS,GAAG,oBAAoB,CAAC;QACrC,IAAI,MAAM,EAAE,CAAC;YACX,SAAS,GAAG,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,SAAS,CAAC;QAC/C,CAAC;QACD,IAAI,CAAC,KAAK,GAAG,IAAI,UAAU,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;IACpD,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,QAAuB;QAClC,OAAO,YAAY,CAAC,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;IACzD,CAAC;CACF"}
1
+ {"version":3,"file":"openai.js","sourceRoot":"","sources":["../../../../src/runtime/agents/impl/openai.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAoC,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAsBhF,MAAM,OAAO,cAAc;IAIzB,YAAY,MAAyB;QACnC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QAEvC,MAAM,UAAU,GAAQ;YACtB,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,KAAK;YACxB,WAAW,EAAE,IAAI,CAAC,MAAM,CAAC,WAAW;YACpC,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,SAAS;YAChC,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI;YACtB,gBAAgB,EAAE,IA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":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../../src/runtime/agents/registry.ts"],"names":[],"mappings":"AAIA,wBAAgB,QAAQ,CAAC,OAAO,EAAE,MAAM,OAIvC"}
1
+ {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../../src/runtime/agents/registry.ts"],"names":[],"mappings":"AAKA,wBAAgB,QAAQ,CAAC,OAAO,EAAE,MAAM,OAsBvC"}
@@ -1,10 +1,54 @@
1
1
  import { OpenAIProvider } from './impl/openai.js';
2
- const Providers = new Map().set('openai', OpenAIProvider);
2
+ import { AnthropicProvider } from './impl/anthropic.js';
3
+ const Providers = new Map().set('openai', OpenAIProvider).set('anthropic', AnthropicProvider);
3
4
  export function provider(service) {
4
- const p = Providers.get(service.toLowerCase());
5
- if (p)
6
- return p;
7
- else
5
+ const requestedService = service.toLowerCase();
6
+ let p = Providers.get(requestedService);
7
+ if (p) {
8
+ // Check if the requested provider has its API key available
9
+ if (isProviderAvailable(requestedService)) {
10
+ return p;
11
+ }
12
+ else {
13
+ // Try to find an alternative available provider
14
+ const availableService = getAvailableProvider();
15
+ if (availableService && availableService !== requestedService) {
16
+ p = Providers.get(availableService);
17
+ if (p)
18
+ return p;
19
+ }
20
+ throw new Error(`${service} provider requested but ${service.toUpperCase()}_API_KEY not found. Available providers: ${getAvailableProviders().join(', ') || 'none'}`);
21
+ }
22
+ }
23
+ else {
8
24
  throw new Error(`No provider found for ${service}`);
25
+ }
26
+ }
27
+ function isProviderAvailable(service) {
28
+ switch (service) {
29
+ case 'openai':
30
+ return !!process.env.OPENAI_API_KEY;
31
+ case 'anthropic':
32
+ return !!process.env.ANTHROPIC_API_KEY;
33
+ default:
34
+ return false;
35
+ }
36
+ }
37
+ function getAvailableProvider() {
38
+ if (process.env.ANTHROPIC_API_KEY) {
39
+ return 'anthropic';
40
+ }
41
+ if (process.env.OPENAI_API_KEY) {
42
+ return 'openai';
43
+ }
44
+ return null;
45
+ }
46
+ function getAvailableProviders() {
47
+ const available = [];
48
+ if (process.env.ANTHROPIC_API_KEY)
49
+ available.push('anthropic');
50
+ if (process.env.OPENAI_API_KEY)
51
+ available.push('openai');
52
+ return available;
9
53
  }
10
54
  //# sourceMappingURL=registry.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"registry.js","sourceRoot":"","sources":["../../../src/runtime/agents/registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,MAAM,SAAS,GAAG,IAAI,GAAG,EAAE,CAAC,GAAG,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC;AAE1D,MAAM,UAAU,QAAQ,CAAC,OAAe;IACtC,MAAM,CAAC,GAAG,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC;IAC/C,IAAI,CAAC;QAAE,OAAO,CAAC,CAAC;;QACX,MAAM,IAAI,KAAK,CAAC,yBAAyB,OAAO,EAAE,CAAC,CAAC;AAC3D,CAAC"}
1
+ {"version":3,"file":"registry.js","sourceRoot":"","sources":["../../../src/runtime/agents/registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD,MAAM,SAAS,GAAG,IAAI,GAAG,EAAE,CAAC,GAAG,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC,GAAG,CAAC,WAAW,EAAE,iBAAiB,CAAC,CAAC;AAE9F,MAAM,UAAU,QAAQ,CAAC,OAAe;IACtC,MAAM,gBAAgB,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAC/C,IAAI,CAAC,GAAG,SAAS,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;IAExC,IAAI,CAAC,EAAE,CAAC;QACN,4DAA4D;QAC5D,IAAI,mBAAmB,CAAC,gBAAgB,CAAC,EAAE,CAAC;YAC1C,OAAO,CAAC,CAAC;QACX,CAAC;aAAM,CAAC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AAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACzD,OAAO,SAAS,CAAC;AACnB,CAAC"}
@@ -0,0 +1,3 @@
1
+ export declare function prepareIntegrations(integManagerHost: string, username: string | undefined, password: string | undefined, integConfigObj: object): Promise<void>;
2
+ export declare function getIntegrationConfig(name: string, configName: string): any;
3
+ //# sourceMappingURL=integrations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"integrations.d.ts","sourceRoot":"","sources":["../../src/runtime/integrations.ts"],"names":[],"mappings":"AAOA,wBAAsB,mBAAmB,CACvC,gBAAgB,EAAE,MAAM,EACxB,QAAQ,EAAE,MAAM,GAAG,SAAS,EAC5B,QAAQ,EAAE,MAAM,GAAG,SAAS,EAC5B,cAAc,EAAE,MAAM,iBAiCvB;AAwCD,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,GAAG,CAO1E"}
@@ -0,0 +1,72 @@
1
+ import { isString } from './util.js';
2
+ const Integrations = new Map();
3
+ const IntegManagerModel = 'integmanager.core';
4
+ export async function prepareIntegrations(integManagerHost, username, password, integConfigObj) {
5
+ const integConfig = new Map(Object.entries(integConfigObj));
6
+ const standardHeaders = await loginToIntegManager(integManagerHost, username, password);
7
+ const keys = [...integConfig.keys()];
8
+ for (let i = 0; i < keys.length; ++i) {
9
+ const configName = keys[i];
10
+ const configPath = integConfig.get(configName);
11
+ if (configPath) {
12
+ const apiUrl = mkApiUrl(integManagerHost, configPath);
13
+ const response = await fetch(apiUrl, {
14
+ method: 'GET',
15
+ headers: standardHeaders,
16
+ });
17
+ if (!response.ok) {
18
+ throw new Error(`Failed to fetch integration for ${configPath}, HTTP error! status: ${response.status} ${response.text} ${response.statusText}`);
19
+ }
20
+ const data = await response.json();
21
+ if (data.length > 0) {
22
+ const inst = data[0].config;
23
+ if (inst.type == 'custom' && isString(inst.parameter)) {
24
+ inst.parameter = new Map(Object.entries(JSON.parse(inst.parameter)));
25
+ }
26
+ Integrations.set(configName, inst);
27
+ }
28
+ else {
29
+ throw new Error(`Integration not found for ${configPath}`);
30
+ }
31
+ }
32
+ }
33
+ }
34
+ async function loginToIntegManager(host, username, password) {
35
+ const defaultHdr = { 'Content-Type': 'application/json' };
36
+ if (username && password && username.length > 0) {
37
+ const apiUrl = `${host}/agentlang_auth/login`;
38
+ const data = { email: username, password: password };
39
+ const response = await fetch(apiUrl, {
40
+ method: 'POST',
41
+ headers: defaultHdr,
42
+ body: JSON.stringify(data),
43
+ });
44
+ if (!response.ok) {
45
+ throw new Error(`Failed to login to integration-manager. HTTP error! status: ${response.status}`);
46
+ }
47
+ const responseData = await response.json();
48
+ return {
49
+ Authorization: `Bearer ${responseData.id_token}`,
50
+ 'Content-Type': 'application/json',
51
+ };
52
+ }
53
+ else {
54
+ return defaultHdr;
55
+ }
56
+ }
57
+ function mkApiUrl(integManagerHost, configPath) {
58
+ const parts = configPath.split('/');
59
+ const integId = parts[0];
60
+ const configId = parts[1];
61
+ return `${integManagerHost}/${IntegManagerModel}/integration/${integId}/integrationConfig/config/${configId}`;
62
+ }
63
+ export function getIntegrationConfig(name, configName) {
64
+ const config = Integrations.get(name);
65
+ if (config) {
66
+ return config.parameter.get(configName);
67
+ }
68
+ else {
69
+ return undefined;
70
+ }
71
+ }
72
+ //# sourceMappingURL=integrations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"integrations.js","sourceRoot":"","sources":["../../src/runtime/integrations.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAErC,MAAM,YAAY,GAAG,IAAI,GAAG,EAAoB,CAAC;AAEjD,MAAM,iBAAiB,GAAG,mBAAmB,CAAC;AAE9C,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,gBAAwB,EACxB,QAA4B,EAC5B,QAA4B,EAC5B,cAAsB;IAEtB,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,cAAc,C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