agentlang 0.0.2
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/LICENSE +83 -0
- package/README.md +120 -0
- package/bin/cli.js +4 -0
- package/out/api/http.d.ts +3 -0
- package/out/api/http.d.ts.map +1 -0
- package/out/api/http.js +290 -0
- package/out/api/http.js.map +1 -0
- package/out/cli/cli-util.d.ts +7 -0
- package/out/cli/cli-util.d.ts.map +1 -0
- package/out/cli/cli-util.js +9 -0
- package/out/cli/cli-util.js.map +1 -0
- package/out/cli/docs.d.ts +2 -0
- package/out/cli/docs.d.ts.map +1 -0
- package/out/cli/docs.js +236 -0
- package/out/cli/docs.js.map +1 -0
- package/out/cli/main.d.ts +288 -0
- package/out/cli/main.d.ts.map +1 -0
- package/out/cli/main.js +119 -0
- package/out/cli/main.js.map +1 -0
- package/out/cli/openapi-docs.yml +695 -0
- package/out/extension/main.cjs +18093 -0
- package/out/extension/main.cjs.map +7 -0
- package/out/extension/main.d.ts +4 -0
- package/out/extension/main.d.ts.map +1 -0
- package/out/extension/main.js +42 -0
- package/out/extension/main.js.map +1 -0
- package/out/language/agentlang-module.d.ts +42 -0
- package/out/language/agentlang-module.d.ts.map +1 -0
- package/out/language/agentlang-module.js +42 -0
- package/out/language/agentlang-module.js.map +1 -0
- package/out/language/agentlang-validator.d.ts +15 -0
- package/out/language/agentlang-validator.d.ts.map +1 -0
- package/out/language/agentlang-validator.js +50 -0
- package/out/language/agentlang-validator.js.map +1 -0
- package/out/language/generated/ast.d.ts +491 -0
- package/out/language/generated/ast.d.ts.map +1 -0
- package/out/language/generated/ast.js +934 -0
- package/out/language/generated/ast.js.map +1 -0
- package/out/language/generated/grammar.d.ts +7 -0
- package/out/language/generated/grammar.d.ts.map +1 -0
- package/out/language/generated/grammar.js +4475 -0
- package/out/language/generated/grammar.js.map +1 -0
- package/out/language/generated/module.d.ts +14 -0
- package/out/language/generated/module.d.ts.map +1 -0
- package/out/language/generated/module.js +21 -0
- package/out/language/generated/module.js.map +1 -0
- package/out/language/main-browser.d.ts +2 -0
- package/out/language/main-browser.d.ts.map +1 -0
- package/out/language/main-browser.js +10 -0
- package/out/language/main-browser.js.map +1 -0
- package/out/language/main.cjs +36229 -0
- package/out/language/main.cjs.map +7 -0
- package/out/language/main.d.ts +2 -0
- package/out/language/main.d.ts.map +1 -0
- package/out/language/main.js +11 -0
- package/out/language/main.js.map +1 -0
- package/out/language/parser.d.ts +9 -0
- package/out/language/parser.d.ts.map +1 -0
- package/out/language/parser.js +273 -0
- package/out/language/parser.js.map +1 -0
- package/out/language/syntax.d.ts +155 -0
- package/out/language/syntax.d.ts.map +1 -0
- package/out/language/syntax.js +527 -0
- package/out/language/syntax.js.map +1 -0
- package/out/runtime/agents/common.d.ts +2 -0
- package/out/runtime/agents/common.d.ts.map +1 -0
- package/out/runtime/agents/common.js +178 -0
- package/out/runtime/agents/common.js.map +1 -0
- package/out/runtime/agents/impl/openai.d.ts +8 -0
- package/out/runtime/agents/impl/openai.d.ts.map +1 -0
- package/out/runtime/agents/impl/openai.js +15 -0
- package/out/runtime/agents/impl/openai.js.map +1 -0
- package/out/runtime/agents/provider.d.ts +21 -0
- package/out/runtime/agents/provider.d.ts.map +1 -0
- package/out/runtime/agents/provider.js +32 -0
- package/out/runtime/agents/provider.js.map +1 -0
- package/out/runtime/agents/registry.d.ts +2 -0
- package/out/runtime/agents/registry.d.ts.map +1 -0
- package/out/runtime/agents/registry.js +10 -0
- package/out/runtime/agents/registry.js.map +1 -0
- package/out/runtime/auth/cognito.d.ts +16 -0
- package/out/runtime/auth/cognito.d.ts.map +1 -0
- package/out/runtime/auth/cognito.js +186 -0
- package/out/runtime/auth/cognito.js.map +1 -0
- package/out/runtime/auth/defs.d.ts +11 -0
- package/out/runtime/auth/defs.d.ts.map +1 -0
- package/out/runtime/auth/defs.js +24 -0
- package/out/runtime/auth/defs.js.map +1 -0
- package/out/runtime/auth/interface.d.ts +22 -0
- package/out/runtime/auth/interface.d.ts.map +1 -0
- package/out/runtime/auth/interface.js +2 -0
- package/out/runtime/auth/interface.js.map +1 -0
- package/out/runtime/defs.js +24 -0
- package/out/runtime/defs.js.map +1 -0
- package/out/runtime/interpreter.d.ts +69 -0
- package/out/runtime/interpreter.d.ts.map +1 -0
- package/out/runtime/interpreter.js +1163 -0
- package/out/runtime/interpreter.js.map +1 -0
- package/out/runtime/loader.d.ts +25 -0
- package/out/runtime/loader.d.ts.map +1 -0
- package/out/runtime/loader.js +346 -0
- package/out/runtime/loader.js.map +1 -0
- package/out/runtime/logger.d.ts +2 -0
- package/out/runtime/logger.d.ts.map +1 -0
- package/out/runtime/logger.js +44 -0
- package/out/runtime/logger.js.map +1 -0
- package/out/runtime/module.d.ts +273 -0
- package/out/runtime/module.d.ts.map +1 -0
- package/out/runtime/module.js +1786 -0
- package/out/runtime/module.js.map +1 -0
- package/out/runtime/modules/ai.d.ts +26 -0
- package/out/runtime/modules/ai.d.ts.map +1 -0
- package/out/runtime/modules/ai.js +211 -0
- package/out/runtime/modules/ai.js.map +1 -0
- package/out/runtime/modules/auth.d.ts +39 -0
- package/out/runtime/modules/auth.d.ts.map +1 -0
- package/out/runtime/modules/auth.js +359 -0
- package/out/runtime/modules/auth.js.map +1 -0
- package/out/runtime/modules/core.d.ts +2 -0
- package/out/runtime/modules/core.d.ts.map +1 -0
- package/out/runtime/modules/core.js +67 -0
- package/out/runtime/modules/core.js.map +1 -0
- package/out/runtime/relgraph.d.ts +21 -0
- package/out/runtime/relgraph.d.ts.map +1 -0
- package/out/runtime/relgraph.js +156 -0
- package/out/runtime/relgraph.js.map +1 -0
- package/out/runtime/resolvers/interface.d.ts +59 -0
- package/out/runtime/resolvers/interface.d.ts.map +1 -0
- package/out/runtime/resolvers/interface.js +111 -0
- package/out/runtime/resolvers/interface.js.map +1 -0
- package/out/runtime/resolvers/registry.d.ts +8 -0
- package/out/runtime/resolvers/registry.d.ts.map +1 -0
- package/out/runtime/resolvers/registry.js +26 -0
- package/out/runtime/resolvers/registry.js.map +1 -0
- package/out/runtime/resolvers/sqldb/database.d.ts +50 -0
- package/out/runtime/resolvers/sqldb/database.d.ts.map +1 -0
- package/out/runtime/resolvers/sqldb/database.js +618 -0
- package/out/runtime/resolvers/sqldb/database.js.map +1 -0
- package/out/runtime/resolvers/sqldb/dbutil.d.ts +18 -0
- package/out/runtime/resolvers/sqldb/dbutil.d.ts.map +1 -0
- package/out/runtime/resolvers/sqldb/dbutil.js +221 -0
- package/out/runtime/resolvers/sqldb/dbutil.js.map +1 -0
- package/out/runtime/resolvers/sqldb/impl.d.ts +26 -0
- package/out/runtime/resolvers/sqldb/impl.d.ts.map +1 -0
- package/out/runtime/resolvers/sqldb/impl.js +300 -0
- package/out/runtime/resolvers/sqldb/impl.js.map +1 -0
- package/out/runtime/state.js +83 -0
- package/out/runtime/state.js.map +1 -0
- package/out/runtime/util.d.ts +43 -0
- package/out/runtime/util.d.ts.map +1 -0
- package/out/runtime/util.js +447 -0
- package/out/runtime/util.js.map +1 -0
- package/out/setupClassic.d.ts +98 -0
- package/out/setupClassic.d.ts.map +1 -0
- package/out/setupClassic.js +38 -0
- package/out/setupClassic.js.map +1 -0
- package/out/setupCommon.d.ts +2 -0
- package/out/setupCommon.d.ts.map +1 -0
- package/out/setupCommon.js +33 -0
- package/out/setupCommon.js.map +1 -0
- package/out/setupExtended.d.ts +40 -0
- package/out/setupExtended.d.ts.map +1 -0
- package/out/setupExtended.js +67 -0
- package/out/setupExtended.js.map +1 -0
- package/out/syntaxes/agentlang.monarch.d.ts +77 -0
- package/out/syntaxes/agentlang.monarch.d.ts.map +1 -0
- package/out/syntaxes/agentlang.monarch.js +31 -0
- package/out/syntaxes/agentlang.monarch.js.map +1 -0
- package/out/utils/fs/index.d.ts +14 -0
- package/out/utils/fs/index.d.ts.map +1 -0
- package/out/utils/fs/index.js +26 -0
- package/out/utils/fs/index.js.map +1 -0
- package/out/utils/fs/interfaces.d.ts +105 -0
- package/out/utils/fs/interfaces.d.ts.map +1 -0
- package/out/utils/fs/interfaces.js +5 -0
- package/out/utils/fs/interfaces.js.map +1 -0
- package/out/utils/fs/lightning-fs.d.ts +116 -0
- package/out/utils/fs/lightning-fs.d.ts.map +1 -0
- package/out/utils/fs/lightning-fs.js +243 -0
- package/out/utils/fs/lightning-fs.js.map +1 -0
- package/out/utils/fs/node-fs.d.ts +93 -0
- package/out/utils/fs/node-fs.d.ts.map +1 -0
- package/out/utils/fs/node-fs.js +169 -0
- package/out/utils/fs/node-fs.js.map +1 -0
- package/out/utils/fs-utils.d.ts +153 -0
- package/out/utils/fs-utils.d.ts.map +1 -0
- package/out/utils/fs-utils.js +271 -0
- package/out/utils/fs-utils.js.map +1 -0
- package/out/utils/runtime.d.ts +36 -0
- package/out/utils/runtime.d.ts.map +1 -0
- package/out/utils/runtime.js +39 -0
- package/out/utils/runtime.js.map +1 -0
- package/package.json +155 -0
- package/src/api/http.ts +361 -0
- package/src/cli/cli-util.ts +18 -0
- package/src/cli/main.ts +146 -0
- package/src/extension/main.ts +51 -0
- package/src/language/agentlang-module.ts +75 -0
- package/src/language/agentlang-validator.ts +60 -0
- package/src/language/agentlang.langium +178 -0
- package/src/language/generated/ast.ts +1698 -0
- package/src/language/generated/grammar.ts +4477 -0
- package/src/language/generated/module.ts +25 -0
- package/src/language/main-browser.ts +19 -0
- package/src/language/main.ts +13 -0
- package/src/language/parser.ts +329 -0
- package/src/language/syntax.ts +646 -0
- package/src/runtime/agents/common.ts +177 -0
- package/src/runtime/agents/impl/openai.ts +19 -0
- package/src/runtime/agents/provider.ts +58 -0
- package/src/runtime/agents/registry.ts +9 -0
- package/src/runtime/auth/cognito.ts +225 -0
- package/src/runtime/auth/defs.ts +33 -0
- package/src/runtime/auth/interface.ts +31 -0
- package/src/runtime/defs.ts +33 -0
- package/src/runtime/interpreter.ts +1352 -0
- package/src/runtime/loader.ts +450 -0
- package/src/runtime/logger.ts +51 -0
- package/src/runtime/module.ts +2188 -0
- package/src/runtime/modules/ai.ts +257 -0
- package/src/runtime/modules/auth.ts +489 -0
- package/src/runtime/modules/core.ts +95 -0
- package/src/runtime/relgraph.ts +195 -0
- package/src/runtime/resolvers/interface.ts +160 -0
- package/src/runtime/resolvers/registry.ts +30 -0
- package/src/runtime/resolvers/sqldb/database.ts +823 -0
- package/src/runtime/resolvers/sqldb/dbutil.ts +257 -0
- package/src/runtime/resolvers/sqldb/impl.ts +471 -0
- package/src/runtime/state.ts +87 -0
- package/src/runtime/util.ts +513 -0
- package/src/setupClassic.ts +43 -0
- package/src/setupCommon.ts +33 -0
- package/src/setupExtended.ts +79 -0
- package/src/syntaxes/agentlang.monarch.ts +31 -0
- package/src/utils/fs/index.ts +28 -0
- package/src/utils/fs/interfaces.ts +118 -0
- package/src/utils/fs/lightning-fs.ts +284 -0
- package/src/utils/fs/node-fs.ts +185 -0
- package/src/utils/fs-utils.ts +304 -0
- package/src/utils/runtime.ts +43 -0
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
export const PlannerInstructions = `Agentlang is a very-high-level declarative language that makes it easy to define business applications as 'models'.
|
|
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,
|
|
4
|
+
|
|
5
|
+
module Erp
|
|
6
|
+
|
|
7
|
+
entity Employee {
|
|
8
|
+
employeeId UUID @id @default(uuid()),
|
|
9
|
+
firstName String,
|
|
10
|
+
lastName String,
|
|
11
|
+
salary Number,
|
|
12
|
+
email Email @indexed
|
|
13
|
+
}
|
|
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).
|
|
18
|
+
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:
|
|
19
|
+
|
|
20
|
+
workflow CreateEmployee {
|
|
21
|
+
{Erp/Employee {firstName CreateEmployee.firstName,
|
|
22
|
+
lastName CreateEmployee.lastName,
|
|
23
|
+
salary CreateEmployee.salary,
|
|
24
|
+
email CreateEmployee.email}}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
The attribute-values of the new Employee are derived from the "event" that triggers the workflow. In this example the event is called "CreateEmployee".
|
|
28
|
+
An event need not have an explicit schema, because its attributes can always be inferred from the workflow definition. But a model may also contain
|
|
29
|
+
explicit definitions of events, as follows,
|
|
30
|
+
|
|
31
|
+
event CreateEmployee {
|
|
32
|
+
firstName String,
|
|
33
|
+
lastName String,
|
|
34
|
+
salary Number,
|
|
35
|
+
email Email
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
A workflow attached to an event is invoked by creating an instance of the event, e.g:
|
|
39
|
+
|
|
40
|
+
{Erp/CreateEmployee {firstName "Sam", lastName "K", salary 1400, email "samk@acme.com"}}
|
|
41
|
+
|
|
42
|
+
This means a workflow can be invoked from another workflow, simply by adding the event-creation as a pattern.
|
|
43
|
+
|
|
44
|
+
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:
|
|
45
|
+
1. Query - e.g: '{Erp/Employee {employeeId? "56392e13-0d9a-42f7-b556-0d7cd9468a24"}}'. The attributes by which the query happens must end with a '?' character.
|
|
46
|
+
To lookup all instances of an entity, use the syntax: '{EntityName?: {}}'.
|
|
47
|
+
2. Update - e.g: '{Erp/Employee {employeeId? "56392e13-0d9a-42f7-b556-0d7cd9468a24", firstName "Joe"}}'. This pattern updates the firstName of the employee
|
|
48
|
+
with the given employeeId.
|
|
49
|
+
3. Upsert - e.g: upsert '{Erp/Employee {employeeId "56392e13-0d9a-42f7-b556-0d7cd9468a24", firstName "Joe"}}'. The 'upsert' pattern will create a new
|
|
50
|
+
instance, if the instance does not already exist.
|
|
51
|
+
4. Delete - e.g: delete '{Erp/Employee {employeeId? "56392e13-0d9a-42f7-b556-0d7cd9468a24"}}'
|
|
52
|
+
|
|
53
|
+
The default query operator is '=' (equals). So an expression like 'employeeId? "56392e13-0d9a-42f7-b556-0d7cd9468a24"' means,
|
|
54
|
+
'where employeeId equals "56392e13-0d9a-42f7-b556-0d7cd9468a24"'. Other comparison operators has to be specified explicitly, as in
|
|
55
|
+
'{age?< 50}' - which means 'where age less-than 50'. The comparison operators supported by a query pattern are:
|
|
56
|
+
|
|
57
|
+
= - equals
|
|
58
|
+
<> - not-equals
|
|
59
|
+
< - less-than
|
|
60
|
+
<= - less-than or equals
|
|
61
|
+
> - greater-than
|
|
62
|
+
>= - greater-than or equals
|
|
63
|
+
in - membership check (argument must be an array)
|
|
64
|
+
like - string-ends-with?
|
|
65
|
+
between - between given values (argument must be an array)
|
|
66
|
+
|
|
67
|
+
Two comparison expressions can be combined together by the logical operators 'or' and 'and'. The comparison and logical expressions produce a boolean
|
|
68
|
+
result, represented by 'true' or 'false'. A boolean value can be inversed by using the 'not' expression, e.g: 'not(some-value)'
|
|
69
|
+
|
|
70
|
+
In addition to the basic CRUD patterns, you can execute conditional-logic with the help of the 'if' pattern. An example follows,
|
|
71
|
+
|
|
72
|
+
workflow IncrementSalary {
|
|
73
|
+
if (IncrementSalary.percentage > 10) {
|
|
74
|
+
{Erp/Employee {employeeId IncrementSalary.employeeId, salary salary + salary * IncrementSalary.percentage}}
|
|
75
|
+
} else {
|
|
76
|
+
{Erp/Employee {employeeId IncrementSalary.employeeId, salary salary + 1500}}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
Note the value passed to the 'salary' attribute - it's an arithmetic expression. All normal arithmetic expressions are supported by workflow patterns.
|
|
81
|
+
|
|
82
|
+
A successful query pattern will return an array of instances. The 'for' pattern can be used to iterate over an array. An example follows:
|
|
83
|
+
|
|
84
|
+
workflow NotifyEmployees {
|
|
85
|
+
{Erp/Employee {salary?> 1000}} as employees;
|
|
86
|
+
for emp in employees {
|
|
87
|
+
{Erp/SendMail {email emp.email, body "You are selected for an increment!"}}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
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
|
|
92
|
+
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,
|
|
93
|
+
via the dot(.) notation. Aliases can also be used to destructure a query result - here's an example:
|
|
94
|
+
|
|
95
|
+
workflow FindFirstTwoEmployees {
|
|
96
|
+
{Erp/Employee {salary?> 1000}} as [emp1, emp2];
|
|
97
|
+
[emp1, emp2]
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
This alias will bind the first two instances to 'a' and 'b' and the rest of the instances to an array named 'xs':
|
|
101
|
+
|
|
102
|
+
{SomeEntity {id?> 1}} as [a, b, _, xs]
|
|
103
|
+
|
|
104
|
+
Examples of binding aliases to 'if' and 'for':
|
|
105
|
+
|
|
106
|
+
if (IncrementSalary.percentage > 10) {
|
|
107
|
+
{Erp/Employee {employeeId IncrementSalary.employeeId, salary salary + salary * IncrementSalary.percentage}}
|
|
108
|
+
} else {
|
|
109
|
+
{Erp/Employee {employeeId IncrementSalary.employeeId, salary salary + 1500}}
|
|
110
|
+
} as emp
|
|
111
|
+
|
|
112
|
+
for emp in employees {
|
|
113
|
+
{Erp/SendMail {email emp.email, body "You are selected for an increment!"}}
|
|
114
|
+
} as emails
|
|
115
|
+
|
|
116
|
+
Entities in a module can be connected together in relationships. There are two types of relationships - 'contains' and 'between'.
|
|
117
|
+
'Contains' relationship is for hierarchical data, as in a Library entity containing Books. 'Between' relationship is for graph-like data,
|
|
118
|
+
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),
|
|
119
|
+
'one_many' (one-to-many) and 'many_many' (many-to-many), which is the default.
|
|
120
|
+
|
|
121
|
+
The 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:
|
|
122
|
+
|
|
123
|
+
entity Profile {
|
|
124
|
+
id UUID @id @default(uuid()),
|
|
125
|
+
address String @optional,
|
|
126
|
+
photo URL @optional,
|
|
127
|
+
dateOfBirth DateTime @optional
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
relationship EmployeeProfile between (Erp/Employee, Erp/Profile) @one_one
|
|
131
|
+
|
|
132
|
+
The '@one_one' annotation means exactly one Employee and Profile can be related to each other via 'EmployeeProfile'.
|
|
133
|
+
|
|
134
|
+
Here's the 'CreateEmployee' workflow updated to create the Employee with the his/her Profile attached:
|
|
135
|
+
|
|
136
|
+
workflow CreateEmployee {
|
|
137
|
+
{Erp/Employee {firstName CreateEmployee.firstName,
|
|
138
|
+
lastName CreateEmployee.lastName,
|
|
139
|
+
salary CreateEmployee.salary,
|
|
140
|
+
email CreateEmployee.email},
|
|
141
|
+
Erp/EmployeeProfile {Erp/Profile {address CreateEmployee.address,
|
|
142
|
+
photo CreateEmployee.photo,
|
|
143
|
+
dateOfBirth CreateEmployee.dateOfBirth}}}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
The following pattern can be user to query an Employee along with his Profile:
|
|
147
|
+
|
|
148
|
+
{Erp/Employee {employeeId? "56392e13-0d9a-42f7-b556-0d7cd9468a24"},
|
|
149
|
+
Erp/EmployeeProfile {Erp/Profile? {}}}
|
|
150
|
+
|
|
151
|
+
As an example of 'contains' relaionships, consider modelling task-assignments for an Employee as folllows:
|
|
152
|
+
|
|
153
|
+
entity TaskAssignment {
|
|
154
|
+
id UUID @id @default(uuid()),
|
|
155
|
+
description String,
|
|
156
|
+
assignmentDate DateTime @default(now())
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
relationship EmployeeTaskAssignment contains (Erp/Employee, Erp/TaskAssignment)
|
|
160
|
+
|
|
161
|
+
The following workflow shows how to assign a new task to an Employee:
|
|
162
|
+
|
|
163
|
+
workflow AssignNewTask {
|
|
164
|
+
{Erp/Employee {employeeId? AssignNewTask.employeeId},
|
|
165
|
+
Erp/EmployeeTaskAssignment {Erp/TaskAssignment {description AssignNewTask.description}}}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
The following workflow queries an Employee along with all his tasks:
|
|
169
|
+
|
|
170
|
+
workflow GetEmployeeTaskAssignments {
|
|
171
|
+
{Erp/Employee {employeeId? GetEmployeeTaskAssignments.employeeId},
|
|
172
|
+
Erp/EmployeeTaskAssignment {Erp/TaskAssignment? {}}}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
Now consider the following module definition and generate appropriate patterns in response to the user instructions. You must return only valid patterns or workflows,
|
|
176
|
+
no other descriptive text or comments are needed.
|
|
177
|
+
`;
|
|
178
|
+
//# sourceMappingURL=common.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../../src/runtime/agents/common.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,mBAAmB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgLlC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { AgentServiceProvider, AIResponse } from '../provider.js';
|
|
2
|
+
import { BaseMessage } from '@langchain/core/messages';
|
|
3
|
+
export declare class OpenAIProvider implements AgentServiceProvider {
|
|
4
|
+
private model;
|
|
5
|
+
constructor(config?: Map<string, any>);
|
|
6
|
+
invoke(messages: BaseMessage[]): Promise<AIResponse>;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=openai.d.ts.map
|
|
@@ -0,0 +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,CAAC;AAChF,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD,qBAAa,cAAe,YAAW,oBAAoB;IACzD,OAAO,CAAC,KAAK,CAAa;gBAEd,MAAM,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC;IAQ/B,MAAM,CAAC,QAAQ,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC,UAAU,CAAC;CAG3D"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ChatOpenAI } from '@langchain/openai';
|
|
2
|
+
import { asAIResponse } from '../provider.js';
|
|
3
|
+
export class OpenAIProvider {
|
|
4
|
+
constructor(config) {
|
|
5
|
+
let modelName = 'gpt-4';
|
|
6
|
+
if (config) {
|
|
7
|
+
modelName = config.get('model') || modelName;
|
|
8
|
+
}
|
|
9
|
+
this.model = new ChatOpenAI({ model: modelName });
|
|
10
|
+
}
|
|
11
|
+
async invoke(messages) {
|
|
12
|
+
return asAIResponse(await this.model.invoke(messages));
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=openai.js.map
|
|
@@ -0,0 +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,OAAO,CAAC;QACxB,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"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { AIMessage, BaseMessage, HumanMessage, SystemMessage } from '@langchain/core/messages';
|
|
2
|
+
import { ChatPromptTemplate } from '@langchain/core/prompts';
|
|
3
|
+
export interface AgentServiceProvider {
|
|
4
|
+
invoke(messages: BaseMessage[]): any;
|
|
5
|
+
}
|
|
6
|
+
export declare function systemMessage(msg: string): SystemMessage;
|
|
7
|
+
export declare function humanMessage(msg: string): HumanMessage;
|
|
8
|
+
export declare function assistantMessage(msg: string): AIMessage;
|
|
9
|
+
export type AIResponse = {
|
|
10
|
+
content: string;
|
|
11
|
+
sysMsg: AIMessage;
|
|
12
|
+
};
|
|
13
|
+
export declare function asAIResponse(aiMsg: AIMessage): AIResponse;
|
|
14
|
+
export type MessageRole = 'system' | 'user' | 'assistant' | 'tool';
|
|
15
|
+
export type PromptTemplateEntry = {
|
|
16
|
+
role: MessageRole;
|
|
17
|
+
text: string;
|
|
18
|
+
};
|
|
19
|
+
export declare function makePromptTemplate(msgs: PromptTemplateEntry[]): ChatPromptTemplate;
|
|
20
|
+
export declare function realizePromptTemplate(template: ChatPromptTemplate, values: any): Promise<BaseMessage[]>;
|
|
21
|
+
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../../src/runtime/agents/provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAE/F,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAE7D,MAAM,WAAW,oBAAoB;IACnC,MAAM,CAAC,QAAQ,EAAE,WAAW,EAAE,GAAG,GAAG,CAAC;CACtC;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,aAAa,CAExD;AAED,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY,CAEtD;AAED,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAEvD;AAMD,MAAM,MAAM,UAAU,GAAG;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,SAAS,CAAC;CACnB,CAAC;AAEF,wBAAgB,YAAY,CAAC,KAAK,EAAE,SAAS,GAAG,UAAU,CAKzD;AAED,MAAM,MAAM,WAAW,GAAG,QAAQ,GAAG,MAAM,GAAG,WAAW,GAAG,MAAM,CAAC;AACnE,MAAM,MAAM,mBAAmB,GAAG;IAChC,IAAI,EAAE,WAAW,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAMF,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,mBAAmB,EAAE,GAAG,kBAAkB,CAGlF;AAED,wBAAsB,qBAAqB,CACzC,QAAQ,EAAE,kBAAkB,EAC5B,MAAM,EAAE,GAAG,GACV,OAAO,CAAC,WAAW,EAAE,CAAC,CAGxB"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { AIMessage, HumanMessage, SystemMessage } from '@langchain/core/messages';
|
|
2
|
+
import { ChatPromptTemplate } from '@langchain/core/prompts';
|
|
3
|
+
export function systemMessage(msg) {
|
|
4
|
+
return new SystemMessage(msg);
|
|
5
|
+
}
|
|
6
|
+
export function humanMessage(msg) {
|
|
7
|
+
return new HumanMessage(msg);
|
|
8
|
+
}
|
|
9
|
+
export function assistantMessage(msg) {
|
|
10
|
+
return new AIMessage(msg);
|
|
11
|
+
}
|
|
12
|
+
function getContent(aiMsg) {
|
|
13
|
+
return aiMsg.content.toString();
|
|
14
|
+
}
|
|
15
|
+
export function asAIResponse(aiMsg) {
|
|
16
|
+
return {
|
|
17
|
+
content: getContent(aiMsg),
|
|
18
|
+
sysMsg: aiMsg,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function normalizeTemplateEntry(entry) {
|
|
22
|
+
return [entry.role, entry.text];
|
|
23
|
+
}
|
|
24
|
+
export function makePromptTemplate(msgs) {
|
|
25
|
+
const input = msgs.map(normalizeTemplateEntry);
|
|
26
|
+
return ChatPromptTemplate.fromMessages(input);
|
|
27
|
+
}
|
|
28
|
+
export async function realizePromptTemplate(template, values) {
|
|
29
|
+
const pvals = await template.invoke(values);
|
|
30
|
+
return pvals.toChatMessages();
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../../../src/runtime/agents/provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAe,YAAY,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAE/F,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAM7D,MAAM,UAAU,aAAa,CAAC,GAAW;IACvC,OAAO,IAAI,aAAa,CAAC,GAAG,CAAC,CAAC;AAChC,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,GAAW;IACtC,OAAO,IAAI,YAAY,CAAC,GAAG,CAAC,CAAC;AAC/B,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,GAAW;IAC1C,OAAO,IAAI,SAAS,CAAC,GAAG,CAAC,CAAC;AAC5B,CAAC;AAED,SAAS,UAAU,CAAC,KAAgB;IAClC,OAAO,KAAK,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;AAClC,CAAC;AAOD,MAAM,UAAU,YAAY,CAAC,KAAgB;IAC3C,OAAO;QACL,OAAO,EAAE,UAAU,CAAC,KAAK,CAAC;QAC1B,MAAM,EAAE,KAAK;KACd,CAAC;AACJ,CAAC;AAQD,SAAS,sBAAsB,CAAC,KAA0B;IACxD,OAAO,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;AAClC,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,IAA2B;IAC5D,MAAM,KAAK,GAAQ,IAAI,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC;IACpD,OAAO,kBAAkB,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;AAChD,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,QAA4B,EAC5B,MAAW;IAEX,MAAM,KAAK,GAA6B,MAAM,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IACtE,OAAO,KAAK,CAAC,cAAc,EAAE,CAAC;AAChC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../../src/runtime/agents/registry.ts"],"names":[],"mappings":"AAIA,wBAAgB,QAAQ,CAAC,OAAO,EAAE,MAAM,OAIvC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { OpenAIProvider } from './impl/openai.js';
|
|
2
|
+
const Providers = new Map().set('openai', OpenAIProvider);
|
|
3
|
+
export function provider(service) {
|
|
4
|
+
const p = Providers.get(service.toLowerCase());
|
|
5
|
+
if (p)
|
|
6
|
+
return p;
|
|
7
|
+
else
|
|
8
|
+
throw new Error(`No provider found for ${service}`);
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { AgentlangAuth, LoginCallback, LogoutCallback, SessionInfo, SignUpCallback } from './interface.js';
|
|
2
|
+
import { Environment } from '../interpreter.js';
|
|
3
|
+
export declare class CognitoAuth implements AgentlangAuth {
|
|
4
|
+
config: Map<string, string | undefined>;
|
|
5
|
+
userPool: any;
|
|
6
|
+
constructor(config?: Map<string, string>);
|
|
7
|
+
fetchUserPoolId(): string;
|
|
8
|
+
fetchClientId(): string;
|
|
9
|
+
private fetchConfig;
|
|
10
|
+
signUp(username: string, password: string, userData: Map<string, string> | undefined, env: Environment, cb: SignUpCallback): Promise<void>;
|
|
11
|
+
login(username: string, password: string, env: Environment, cb: LoginCallback): Promise<void>;
|
|
12
|
+
logout(sessionInfo: SessionInfo, env: Environment, cb?: LogoutCallback): Promise<void>;
|
|
13
|
+
private fetchUserPool;
|
|
14
|
+
verifyToken(token: string): Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=cognito.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cognito.d.ts","sourceRoot":"","sources":["../../../src/runtime/auth/cognito.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,aAAa,EACb,cAAc,EACd,WAAW,EACX,cAAc,EAEf,MAAM,gBAAgB,CAAC;AAaxB,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AA8BhD,qBAAa,WAAY,YAAW,aAAa;IAC/C,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;IACxC,QAAQ,EAAE,GAAG,CAAC;gBACF,MAAM,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC;IAUxC,eAAe,IAAI,MAAM;IAIzB,aAAa,IAAI,MAAM;IAIvB,OAAO,CAAC,WAAW;IAQb,MAAM,CACV,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,EACzC,GAAG,EAAE,WAAW,EAChB,EAAE,EAAE,cAAc,GACjB,OAAO,CAAC,IAAI,CAAC;IA0CV,KAAK,CACT,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,GAAG,EAAE,WAAW,EAChB,EAAE,EAAE,aAAa,GAChB,OAAO,CAAC,IAAI,CAAC;IA0CV,MAAM,CAAC,WAAW,EAAE,WAAW,EAAE,GAAG,EAAE,WAAW,EAAE,EAAE,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAwB5F,OAAO,CAAC,aAAa;IAOf,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAchD"}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { ensureUser, ensureUserSession, findUser, findUserByEmail, findUserSession, removeSession, } from '../modules/auth.js';
|
|
2
|
+
import { logger } from '../logger.js';
|
|
3
|
+
import { sleepMilliseconds } from '../util.js';
|
|
4
|
+
import { CognitoJwtVerifier } from 'aws-jwt-verify';
|
|
5
|
+
import { isNodeEnv } from '../../utils/runtime.js';
|
|
6
|
+
import { UnauthorisedError } from '../defs.js';
|
|
7
|
+
let fromEnv = undefined;
|
|
8
|
+
let CognitoIdentityProviderClient = undefined;
|
|
9
|
+
let SignUpCommand = undefined;
|
|
10
|
+
let AuthenticationDetails = undefined;
|
|
11
|
+
let CognitoUser = undefined;
|
|
12
|
+
let CognitoUserPool = undefined;
|
|
13
|
+
if (isNodeEnv) {
|
|
14
|
+
const cp = await import('@aws-sdk/credential-providers');
|
|
15
|
+
fromEnv = cp.fromEnv;
|
|
16
|
+
const cip = await import('@aws-sdk/client-cognito-identity-provider');
|
|
17
|
+
CognitoIdentityProviderClient = cip.CognitoIdentityProviderClient;
|
|
18
|
+
SignUpCommand = cip.SignUpCommand;
|
|
19
|
+
const ci = await import('amazon-cognito-identity-js');
|
|
20
|
+
AuthenticationDetails = ci.AuthenticationDetails;
|
|
21
|
+
CognitoUser = ci.CognitoUser;
|
|
22
|
+
CognitoUserPool = ci.CognitoUserPool;
|
|
23
|
+
}
|
|
24
|
+
const defaultConfig = isNodeEnv
|
|
25
|
+
? new Map()
|
|
26
|
+
.set('UserPoolId', process.env.COGNITO_USER_POOL_ID)
|
|
27
|
+
.set('ClientId', process.env.COGNITO_CLIENT_ID)
|
|
28
|
+
: new Map();
|
|
29
|
+
export class CognitoAuth {
|
|
30
|
+
constructor(config) {
|
|
31
|
+
this.config = config ? config : defaultConfig;
|
|
32
|
+
const upid = this.config.get('UserPoolId');
|
|
33
|
+
if (upid)
|
|
34
|
+
this.userPool = new CognitoUserPool({
|
|
35
|
+
UserPoolId: upid,
|
|
36
|
+
ClientId: this.fetchClientId(),
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
fetchUserPoolId() {
|
|
40
|
+
return this.fetchConfig('UserPoolId');
|
|
41
|
+
}
|
|
42
|
+
fetchClientId() {
|
|
43
|
+
return this.fetchConfig('ClientId');
|
|
44
|
+
}
|
|
45
|
+
fetchConfig(k) {
|
|
46
|
+
const id = this.config.get(k);
|
|
47
|
+
if (id) {
|
|
48
|
+
return id;
|
|
49
|
+
}
|
|
50
|
+
throw new Error(`${k} is not set`);
|
|
51
|
+
}
|
|
52
|
+
async signUp(username, password, userData, env, cb) {
|
|
53
|
+
const client = new CognitoIdentityProviderClient({
|
|
54
|
+
region: process.env.AWS_REGION || 'us-west-2',
|
|
55
|
+
credentials: fromEnv(),
|
|
56
|
+
});
|
|
57
|
+
const userAttrs = [
|
|
58
|
+
{
|
|
59
|
+
Name: 'email',
|
|
60
|
+
Value: username,
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
Name: 'name',
|
|
64
|
+
Value: username,
|
|
65
|
+
},
|
|
66
|
+
];
|
|
67
|
+
if (userData) {
|
|
68
|
+
userData.forEach((v, k) => {
|
|
69
|
+
userAttrs.push({ Name: k, Value: v });
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
const input = {
|
|
73
|
+
ClientId: this.config.get('ClientId'),
|
|
74
|
+
Username: username,
|
|
75
|
+
Password: password,
|
|
76
|
+
UserAttributes: userAttrs,
|
|
77
|
+
ValidationData: userAttrs,
|
|
78
|
+
};
|
|
79
|
+
const command = new SignUpCommand(input);
|
|
80
|
+
const response = await client.send(command);
|
|
81
|
+
if (response.$metadata.httpStatusCode == 200) {
|
|
82
|
+
const user = await ensureUser(username, '', '', env);
|
|
83
|
+
const userInfo = {
|
|
84
|
+
username: username,
|
|
85
|
+
id: user.id,
|
|
86
|
+
systemUserInfo: response.UserSub,
|
|
87
|
+
};
|
|
88
|
+
cb(userInfo);
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
throw new Error(`Signup failed with status ${response.$metadata.httpStatusCode}`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
async login(username, password, env, cb) {
|
|
95
|
+
let localUser = await findUserByEmail(username, env);
|
|
96
|
+
if (!localUser) {
|
|
97
|
+
logger.warn(`User ${username} not found in local store`);
|
|
98
|
+
localUser = await ensureUser(username, '', '', env);
|
|
99
|
+
}
|
|
100
|
+
const user = new CognitoUser({
|
|
101
|
+
Username: username,
|
|
102
|
+
Pool: this.fetchUserPool(),
|
|
103
|
+
});
|
|
104
|
+
const authDetails = new AuthenticationDetails({
|
|
105
|
+
Username: username,
|
|
106
|
+
Password: password,
|
|
107
|
+
});
|
|
108
|
+
let result;
|
|
109
|
+
let errMsg;
|
|
110
|
+
user.authenticateUser(authDetails, {
|
|
111
|
+
onSuccess: (session) => {
|
|
112
|
+
result = session;
|
|
113
|
+
},
|
|
114
|
+
onFailure: (err) => {
|
|
115
|
+
errMsg = `Authentication failed for ${username} - ${err}`;
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
while (result == undefined && errMsg == undefined) {
|
|
119
|
+
await sleepMilliseconds(100);
|
|
120
|
+
}
|
|
121
|
+
if (errMsg) {
|
|
122
|
+
throw new UnauthorisedError(errMsg);
|
|
123
|
+
}
|
|
124
|
+
if (result) {
|
|
125
|
+
const userid = localUser.lookup('id');
|
|
126
|
+
const token = result.getIdToken().getJwtToken();
|
|
127
|
+
const localSess = await ensureUserSession(userid, token, env);
|
|
128
|
+
const sessInfo = {
|
|
129
|
+
sessionId: localSess.lookup('id'),
|
|
130
|
+
userId: userid,
|
|
131
|
+
authToken: token,
|
|
132
|
+
systemSesionInfo: result,
|
|
133
|
+
};
|
|
134
|
+
cb(sessInfo);
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
console.log(`Login failed for ${username}`);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
async logout(sessionInfo, env, cb) {
|
|
141
|
+
const localUser = await findUser(sessionInfo.userId, env);
|
|
142
|
+
if (!localUser) {
|
|
143
|
+
if (cb)
|
|
144
|
+
cb(true);
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
const user = new CognitoUser({
|
|
148
|
+
Username: localUser.email,
|
|
149
|
+
Pool: this.fetchUserPool(),
|
|
150
|
+
});
|
|
151
|
+
let done = false;
|
|
152
|
+
user.signOut(() => {
|
|
153
|
+
done = true;
|
|
154
|
+
});
|
|
155
|
+
while (!done) {
|
|
156
|
+
await sleepMilliseconds(100);
|
|
157
|
+
}
|
|
158
|
+
const sess = await findUserSession(localUser.id, env);
|
|
159
|
+
if (sess) {
|
|
160
|
+
await removeSession(sess.id, env);
|
|
161
|
+
}
|
|
162
|
+
if (cb)
|
|
163
|
+
cb(true);
|
|
164
|
+
}
|
|
165
|
+
fetchUserPool() {
|
|
166
|
+
if (this.userPool) {
|
|
167
|
+
return this.userPool;
|
|
168
|
+
}
|
|
169
|
+
throw new Error('UserPool not initialized');
|
|
170
|
+
}
|
|
171
|
+
async verifyToken(token) {
|
|
172
|
+
try {
|
|
173
|
+
const verifier = CognitoJwtVerifier.create({
|
|
174
|
+
userPoolId: this.fetchUserPoolId(),
|
|
175
|
+
tokenUse: 'id',
|
|
176
|
+
clientId: this.fetchClientId(),
|
|
177
|
+
});
|
|
178
|
+
const payload = await verifier.verify(token);
|
|
179
|
+
logger.debug(`Decoded JWT for ${payload.email}`);
|
|
180
|
+
}
|
|
181
|
+
catch (err) {
|
|
182
|
+
throw new Error(`Failed to verify token - ${err}`);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
//# sourceMappingURL=cognito.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cognito.js","sourceRoot":"","sources":["../../../src/runtime/auth/cognito.ts"],"names":[],"mappings":"AAQA,OAAO,EACL,UAAU,EACV,iBAAiB,EACjB,QAAQ,EACR,eAAe,EACf,eAAe,EACf,aAAa,GACd,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAE/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAEpD,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAE/C,IAAI,OAAO,GAAQ,SAAS,CAAC;AAC7B,IAAI,6BAA6B,GAAQ,SAAS,CAAC;AACnD,IAAI,aAAa,GAAQ,SAAS,CAAC;AACnC,IAAI,qBAAqB,GAAQ,SAAS,CAAC;AAC3C,IAAI,WAAW,GAAQ,SAAS,CAAC;AACjC,IAAI,eAAe,GAAQ,SAAS,CAAC;AAErC,IAAI,SAAS,EAAE,CAAC;IACd,MAAM,EAAE,GAA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}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const AdminUserId = "00000000-0000-0000-0000-000000000000";
|
|
2
|
+
export declare const AuthEnabled = true;
|
|
3
|
+
export type ActiveSessionInfo = {
|
|
4
|
+
sessionId: string;
|
|
5
|
+
userId: string;
|
|
6
|
+
};
|
|
7
|
+
export declare const AdminSession: ActiveSessionInfo;
|
|
8
|
+
export declare const BypassSession: ActiveSessionInfo;
|
|
9
|
+
export declare const NoSession: ActiveSessionInfo;
|
|
10
|
+
export declare function isNoSession(sess: ActiveSessionInfo): boolean;
|
|
11
|
+
//# sourceMappingURL=defs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defs.d.ts","sourceRoot":"","sources":["../../../src/runtime/auth/defs.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,WAAW,yCAAyC,CAAC;AAElE,eAAO,MAAM,WAAW,OAAO,CAAC;AAEhC,MAAM,MAAM,iBAAiB,GAAG;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,eAAO,MAAM,YAAY,EAAE,iBAG1B,CAAC;AAEF,eAAO,MAAM,aAAa,mBAAe,CAAC;AAE1C,eAAO,MAAM,SAAS,EAAE,iBAGvB,CAAC;AAEF,wBAAgB,WAAW,CAAC,IAAI,EAAE,iBAAiB,GAAG,OAAO,CAE5D"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { AppConfig } from '../state.js';
|
|
2
|
+
// TODO: AdminUserId must be dynamically set based on auth-service-config and a valid admin-login
|
|
3
|
+
export const AdminUserId = '00000000-0000-0000-0000-000000000000';
|
|
4
|
+
export function isAuthEnabled() {
|
|
5
|
+
if (AppConfig && AppConfig.rbacEnabled == true) {
|
|
6
|
+
return true;
|
|
7
|
+
}
|
|
8
|
+
else {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export const AdminSession = {
|
|
13
|
+
sessionId: crypto.randomUUID(),
|
|
14
|
+
userId: AdminUserId,
|
|
15
|
+
};
|
|
16
|
+
export const BypassSession = AdminSession;
|
|
17
|
+
export const NoSession = {
|
|
18
|
+
sessionId: 'nil',
|
|
19
|
+
userId: 'nil',
|
|
20
|
+
};
|
|
21
|
+
export function isNoSession(sess) {
|
|
22
|
+
return sess == NoSession;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=defs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defs.js","sourceRoot":"","sources":["../../../src/runtime/auth/defs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,iGAAiG;AACjG,MAAM,CAAC,MAAM,WAAW,GAAG,sCAAsC,CAAC;AAElE,MAAM,UAAU,aAAa;IAC3B,IAAI,SAAS,IAAI,SAAS,CAAC,WAAW,IAAI,IAAI,EAAE,CAAC;QAC/C,OAAO,IAAI,CAAC;IACd,CAAC;SAAM,CAAC;QACN,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAOD,MAAM,CAAC,MAAM,YAAY,GAAsB;IAC7C,SAAS,EAAE,MAAM,CAAC,UAAU,EAAE;IAC9B,MAAM,EAAE,WAAW;CACpB,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAG,YAAY,CAAC;AAE1C,MAAM,CAAC,MAAM,SAAS,GAAsB;IAC1C,SAAS,EAAE,KAAK;IAChB,MAAM,EAAE,KAAK;CACd,CAAC;AAEF,MAAM,UAAU,WAAW,CAAC,IAAuB;IACjD,OAAO,IAAI,IAAI,SAAS,CAAC;AAC3B,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Environment } from '../interpreter.js';
|
|
2
|
+
export type UserInfo = {
|
|
3
|
+
id: string;
|
|
4
|
+
username: string;
|
|
5
|
+
systemUserInfo?: any;
|
|
6
|
+
};
|
|
7
|
+
export type SessionInfo = {
|
|
8
|
+
sessionId: string;
|
|
9
|
+
userId: string;
|
|
10
|
+
authToken: string;
|
|
11
|
+
systemSesionInfo?: any;
|
|
12
|
+
};
|
|
13
|
+
export type SignUpCallback = (userInfo: UserInfo) => void;
|
|
14
|
+
export type LoginCallback = (sessionInfo: SessionInfo) => void;
|
|
15
|
+
export type LogoutCallback = (status: boolean) => void;
|
|
16
|
+
export interface AgentlangAuth {
|
|
17
|
+
signUp(username: string, password: string, userData: Map<string, any> | undefined, env: Environment, cb: SignUpCallback): any;
|
|
18
|
+
login(username: string, password: string, env: Environment, cb: LoginCallback): any;
|
|
19
|
+
logout(sessionInfo: SessionInfo, env: Environment, cb?: LogoutCallback): any;
|
|
20
|
+
verifyToken(token: string, env: Environment): any;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=interface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../../../src/runtime/auth/interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,MAAM,MAAM,QAAQ,GAAG;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,CAAC,EAAE,GAAG,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB,CAAC,EAAE,GAAG,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG,CAAC,QAAQ,EAAE,QAAQ,KAAK,IAAI,CAAC;AAC1D,MAAM,MAAM,aAAa,GAAG,CAAC,WAAW,EAAE,WAAW,KAAK,IAAI,CAAC;AAC/D,MAAM,MAAM,cAAc,GAAG,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,CAAC;AAEvD,MAAM,WAAW,aAAa;IAC5B,MAAM,CACJ,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,SAAS,EACtC,GAAG,EAAE,WAAW,EAChB,EAAE,EAAE,cAAc,GACjB,GAAG,CAAC;IACP,KAAK,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,WAAW,EAAE,EAAE,EAAE,aAAa,GAAG,GAAG,CAAC;IACpF,MAAM,CAAC,WAAW,EAAE,WAAW,EAAE,GAAG,EAAE,WAAW,EAAE,EAAE,CAAC,EAAE,cAAc,GAAG,GAAG,CAAC;IAC7E,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,WAAW,GAAG,GAAG,CAAC;CACnD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interface.js","sourceRoot":"","sources":["../../../src/runtime/auth/interface.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export const DefaultIdAttributeName = '__id__';
|
|
2
|
+
export const PathAttributeName = '__path__';
|
|
3
|
+
export const PathAttributeNameQuery = '__path__?';
|
|
4
|
+
export const ParentAttributeName = '__parent__';
|
|
5
|
+
export const DeletedFlagAttributeName = '__is_deleted__';
|
|
6
|
+
function asUnauthMessage(obj) {
|
|
7
|
+
if (typeof obj == 'string') {
|
|
8
|
+
return obj;
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
return `User not authorised to perform '${obj.opr}' on ${obj.entity}`;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export class UnauthorisedError extends Error {
|
|
15
|
+
constructor(message, options) {
|
|
16
|
+
super(message ? asUnauthMessage(message) : 'User not authorised to perform this operation', options);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export class BadRequestError extends Error {
|
|
20
|
+
constructor(message, options) {
|
|
21
|
+
super(message ? asUnauthMessage(message) : 'BadRequest', options);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=defs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defs.js","sourceRoot":"","sources":["../../src/runtime/defs.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,sBAAsB,GAAW,QAAQ,CAAC;AACvD,MAAM,CAAC,MAAM,iBAAiB,GAAW,UAAU,CAAC;AACpD,MAAM,CAAC,MAAM,sBAAsB,GAAW,WAAW,CAAC;AAC1D,MAAM,CAAC,MAAM,mBAAmB,GAAW,YAAY,CAAC;AACxD,MAAM,CAAC,MAAM,wBAAwB,GAAW,gBAAgB,CAAC;AAOjE,SAAS,eAAe,CAAC,GAAuB;IAC9C,IAAI,OAAO,GAAG,IAAI,QAAQ,EAAE,CAAC;QAC3B,OAAO,GAAG,CAAC;IACb,CAAC;SAAM,CAAC;QACN,OAAO,mCAAmC,GAAG,CAAC,GAAG,QAAQ,GAAG,CAAC,MAAM,EAAE,CAAC;IACxE,CAAC;AACH,CAAC;AAED,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IAC1C,YAAY,OAA4B,EAAE,OAAsB;QAC9D,KAAK,CACH,OAAO,CAAC,CAAC,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,+CAA+C,EACpF,OAAO,CACR,CAAC;IACJ,CAAC;CACF;AAED,MAAM,OAAO,eAAgB,SAAQ,KAAK;IACxC,YAAY,OAAgB,EAAE,OAAsB;QAClD,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;IACpE,CAAC;CACF"}
|