agentlang 0.0.8 → 0.0.11
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/out/api/http.js +1 -1
- package/out/api/http.js.map +1 -1
- package/out/language/generated/ast.d.ts +11 -2
- package/out/language/generated/ast.d.ts.map +1 -1
- package/out/language/generated/ast.js +15 -2
- package/out/language/generated/ast.js.map +1 -1
- package/out/language/generated/grammar.d.ts.map +1 -1
- package/out/language/generated/grammar.js +162 -119
- package/out/language/generated/grammar.js.map +1 -1
- package/out/language/main.cjs +174 -121
- package/out/language/main.cjs.map +2 -2
- package/out/language/parser.d.ts +1 -0
- package/out/language/parser.d.ts.map +1 -1
- package/out/language/parser.js +4 -0
- package/out/language/parser.js.map +1 -1
- package/out/language/syntax.js +2 -2
- package/out/language/syntax.js.map +1 -1
- package/out/runtime/agents/common.d.ts +1 -1
- package/out/runtime/agents/common.d.ts.map +1 -1
- package/out/runtime/agents/common.js +10 -10
- package/out/runtime/interpreter.d.ts +20 -1
- package/out/runtime/interpreter.d.ts.map +1 -1
- package/out/runtime/interpreter.js +160 -13
- package/out/runtime/interpreter.js.map +1 -1
- package/out/runtime/jsmodules.d.ts +2 -2
- package/out/runtime/jsmodules.d.ts.map +1 -1
- package/out/runtime/jsmodules.js +12 -4
- package/out/runtime/jsmodules.js.map +1 -1
- package/out/runtime/loader.d.ts +1 -1
- package/out/runtime/loader.d.ts.map +1 -1
- package/out/runtime/loader.js +10 -7
- package/out/runtime/loader.js.map +1 -1
- package/out/runtime/module.d.ts +4 -1
- package/out/runtime/module.d.ts.map +1 -1
- package/out/runtime/module.js +56 -11
- package/out/runtime/module.js.map +1 -1
- package/out/runtime/modules/ai.d.ts +1 -0
- package/out/runtime/modules/ai.d.ts.map +1 -1
- package/out/runtime/modules/ai.js +17 -5
- package/out/runtime/modules/ai.js.map +1 -1
- package/out/runtime/modules/auth.d.ts.map +1 -1
- package/out/runtime/modules/auth.js +21 -16
- package/out/runtime/modules/auth.js.map +1 -1
- package/out/runtime/modules/core.d.ts +9 -0
- package/out/runtime/modules/core.d.ts.map +1 -1
- package/out/runtime/modules/core.js +107 -2
- package/out/runtime/modules/core.js.map +1 -1
- package/out/runtime/resolvers/interface.d.ts +4 -3
- package/out/runtime/resolvers/interface.d.ts.map +1 -1
- package/out/runtime/resolvers/interface.js +4 -4
- package/out/runtime/resolvers/interface.js.map +1 -1
- package/out/runtime/resolvers/sqldb/impl.js +2 -2
- package/out/runtime/resolvers/sqldb/impl.js.map +1 -1
- package/out/runtime/util.d.ts.map +1 -1
- package/out/runtime/util.js +3 -2
- package/out/runtime/util.js.map +1 -1
- package/out/syntaxes/agentlang.monarch.js +1 -1
- package/out/syntaxes/agentlang.monarch.js.map +1 -1
- package/package.json +1 -1
- package/src/api/http.ts +1 -1
- package/src/language/agentlang.langium +7 -5
- package/src/language/generated/ast.ts +29 -5
- package/src/language/generated/grammar.ts +162 -119
- package/src/language/parser.ts +5 -0
- package/src/language/syntax.ts +2 -2
- package/src/runtime/agents/common.ts +10 -10
- package/src/runtime/interpreter.ts +177 -13
- package/src/runtime/jsmodules.ts +12 -4
- package/src/runtime/loader.ts +12 -6
- package/src/runtime/module.ts +61 -11
- package/src/runtime/modules/ai.ts +16 -5
- package/src/runtime/modules/auth.ts +21 -17
- package/src/runtime/modules/core.ts +144 -2
- package/src/runtime/resolvers/interface.ts +6 -6
- package/src/runtime/resolvers/sqldb/impl.ts +2 -2
- package/src/runtime/util.ts +4 -2
- package/src/syntaxes/agentlang.monarch.ts +1 -1
|
@@ -29,7 +29,7 @@ export const CoreAuthModuleName = makeCoreModuleName('auth');
|
|
|
29
29
|
|
|
30
30
|
export default `module ${CoreAuthModuleName}
|
|
31
31
|
|
|
32
|
-
import "./modules/auth.js" as Auth
|
|
32
|
+
import "./modules/auth.js" @as Auth
|
|
33
33
|
|
|
34
34
|
entity User {
|
|
35
35
|
id UUID @id @default(uuid()),
|
|
@@ -52,12 +52,12 @@ workflow CreateUser {
|
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
workflow FindUser {
|
|
55
|
-
{User {id? FindUser.id}} as [user];
|
|
55
|
+
{User {id? FindUser.id}} @as [user];
|
|
56
56
|
user
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
workflow FindUserByEmail {
|
|
60
|
-
{User {email? FindUserByEmail.email}} as [user];
|
|
60
|
+
{User {email? FindUserByEmail.email}} @as [user];
|
|
61
61
|
user
|
|
62
62
|
}
|
|
63
63
|
|
|
@@ -83,19 +83,19 @@ workflow CreateRole {
|
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
workflow FindRole {
|
|
86
|
-
{Role {name? FindRole.name}} as [role];
|
|
86
|
+
{Role {name? FindRole.name}} @as [role];
|
|
87
87
|
role
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
workflow AssignUserToRole {
|
|
91
|
-
{User {id? AssignUserToRole.userId}} as [user];
|
|
92
|
-
{Role {name? AssignUserToRole.roleName}} as [role];
|
|
91
|
+
{User {id? AssignUserToRole.userId}} @as [user];
|
|
92
|
+
{Role {name? AssignUserToRole.roleName}} @as [role];
|
|
93
93
|
{UserRole {User user, Role role}, @upsert}
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
workflow AssignUserToRoleByEmail {
|
|
97
|
-
{User {email? AssignUserToRoleByEmail.email}} as [user];
|
|
98
|
-
{Role {name? AssignUserToRoleByEmail.roleName}} as [role];
|
|
97
|
+
{User {email? AssignUserToRoleByEmail.email}} @as [user];
|
|
98
|
+
{Role {name? AssignUserToRoleByEmail.roleName}} @as [role];
|
|
99
99
|
{UserRole {User user, Role role}, @upsert}
|
|
100
100
|
}
|
|
101
101
|
|
|
@@ -116,8 +116,8 @@ workflow CreatePermission {
|
|
|
116
116
|
}
|
|
117
117
|
|
|
118
118
|
workflow AddPermissionToRole {
|
|
119
|
-
{Role {name? AddPermissionToRole.roleName}} as role;
|
|
120
|
-
{Permission {id? AddPermissionToRole.permissionId}} as perm;
|
|
119
|
+
{Role {name? AddPermissionToRole.roleName}} @as role;
|
|
120
|
+
{Permission {id? AddPermissionToRole.permissionId}} @as perm;
|
|
121
121
|
{RolePermission {Role role, Permission perm}, @upsert}
|
|
122
122
|
}
|
|
123
123
|
|
|
@@ -154,12 +154,12 @@ workflow UpdateSession {
|
|
|
154
154
|
}
|
|
155
155
|
|
|
156
156
|
workflow FindSession {
|
|
157
|
-
{Session {id? FindSession.id}} as [session];
|
|
157
|
+
{Session {id? FindSession.id}} @as [session];
|
|
158
158
|
session
|
|
159
159
|
}
|
|
160
160
|
|
|
161
161
|
workflow FindUserSession {
|
|
162
|
-
{Session {userId? FindUserSession.userId}} as [session];
|
|
162
|
+
{Session {userId? FindUserSession.userId}} @as [session];
|
|
163
163
|
session
|
|
164
164
|
}
|
|
165
165
|
|
|
@@ -168,7 +168,7 @@ workflow RemoveSession {
|
|
|
168
168
|
}
|
|
169
169
|
|
|
170
170
|
workflow RemoveUserSession {
|
|
171
|
-
{Session {userId? RemoveUserSession.id}} as [session];
|
|
171
|
+
{Session {userId? RemoveUserSession.id}} @as [session];
|
|
172
172
|
purge {Session {id? session.id}}
|
|
173
173
|
}
|
|
174
174
|
|
|
@@ -837,10 +837,14 @@ export async function refreshUserToken(refreshToken: string, env: Environment):
|
|
|
837
837
|
}
|
|
838
838
|
|
|
839
839
|
export function requireAuth(moduleName: string, eventName: string): boolean {
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
840
|
+
if (isAuthEnabled()) {
|
|
841
|
+
const f =
|
|
842
|
+
moduleName == CoreAuthModuleName &&
|
|
843
|
+
(eventName == 'login' || eventName == 'signup' || eventName == 'refreshToken');
|
|
844
|
+
return !f;
|
|
845
|
+
} else {
|
|
846
|
+
return false;
|
|
847
|
+
}
|
|
844
848
|
}
|
|
845
849
|
|
|
846
850
|
// Export getHttpStatusForError for use in HTTP handlers
|
|
@@ -1,11 +1,23 @@
|
|
|
1
1
|
import { default as ai } from './ai.js';
|
|
2
2
|
import { default as auth } from './auth.js';
|
|
3
3
|
import { DefaultModuleName, DefaultModules } from '../util.js';
|
|
4
|
-
import { Instance, isInstanceOfType } from '../module.js';
|
|
5
|
-
import {
|
|
4
|
+
import { Instance, isInstanceOfType, makeInstance, newInstanceAttributes } from '../module.js';
|
|
5
|
+
import {
|
|
6
|
+
Environment,
|
|
7
|
+
evaluate,
|
|
8
|
+
evaluateStatements,
|
|
9
|
+
parseAndEvaluateStatement,
|
|
10
|
+
} from '../interpreter.js';
|
|
6
11
|
import { logger } from '../logger.js';
|
|
12
|
+
import { Statement } from '../../language/generated/ast.js';
|
|
13
|
+
import { parseStatements } from '../../language/parser.js';
|
|
14
|
+
import { Resolver } from '../resolvers/interface.js';
|
|
15
|
+
import { PathAttributeName } from '../defs.js';
|
|
7
16
|
|
|
8
17
|
const CoreModuleDefinition = `module ${DefaultModuleName}
|
|
18
|
+
|
|
19
|
+
import "./modules/core.js" @as Core
|
|
20
|
+
|
|
9
21
|
entity timer {
|
|
10
22
|
name String @id,
|
|
11
23
|
duration Int,
|
|
@@ -23,6 +35,34 @@ entity auditlog {
|
|
|
23
35
|
user String,
|
|
24
36
|
token String @optional
|
|
25
37
|
}
|
|
38
|
+
|
|
39
|
+
entity suspension {
|
|
40
|
+
id UUID @id,
|
|
41
|
+
continuation String[], // rest of the patterns to execute
|
|
42
|
+
env Any, // serialized environment-object
|
|
43
|
+
createdOn DateTime @default(now()),
|
|
44
|
+
createdBy String
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
entity activeSuspension {
|
|
48
|
+
id UUID @id
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
resolver servicenow ["${DefaultModuleName}/activeSuspension"] {
|
|
52
|
+
query Core.lookupActiveSuspension
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
workflow createSuspension {
|
|
56
|
+
{suspension
|
|
57
|
+
{id createSuspension.id
|
|
58
|
+
continuation createSuspension.continuation,
|
|
59
|
+
env createSuspension.env,
|
|
60
|
+
createdBy createSuspension.createdBy}}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
workflow restartSuspension {
|
|
64
|
+
await Core.restartSuspension(restartSuspension.id, restartSuspension.data)
|
|
65
|
+
}
|
|
26
66
|
`;
|
|
27
67
|
export const CoreModules: string[] = [];
|
|
28
68
|
|
|
@@ -95,3 +135,105 @@ export async function addUpdateAudit(
|
|
|
95
135
|
) {
|
|
96
136
|
await addAudit(env, 'u', resource, previous_value);
|
|
97
137
|
}
|
|
138
|
+
|
|
139
|
+
export async function createSuspension(
|
|
140
|
+
suspId: string,
|
|
141
|
+
continuation: string[],
|
|
142
|
+
env: Environment
|
|
143
|
+
): Promise<string | undefined> {
|
|
144
|
+
const user = env.getActiveUser();
|
|
145
|
+
const newEnv = new Environment('susp', env).setInKernelMode(true);
|
|
146
|
+
const envObj = env.asSerializableObject();
|
|
147
|
+
const inst = makeInstance(
|
|
148
|
+
'agentlang',
|
|
149
|
+
'createSuspension',
|
|
150
|
+
newInstanceAttributes()
|
|
151
|
+
.set('id', suspId)
|
|
152
|
+
.set('continuation', continuation)
|
|
153
|
+
.set('env', envObj)
|
|
154
|
+
.set('createdBy', user)
|
|
155
|
+
);
|
|
156
|
+
const r: any = await evaluate(inst, undefined, newEnv);
|
|
157
|
+
if (!isInstanceOfType(r, 'agentlang/suspension')) {
|
|
158
|
+
logger.warn(`Failed to create suspension for user ${user}`);
|
|
159
|
+
return undefined;
|
|
160
|
+
}
|
|
161
|
+
return (r as Instance).lookup('id');
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export type Suspension = {
|
|
165
|
+
continuation: Statement[];
|
|
166
|
+
env: Environment;
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
async function loadSuspension(suspId: string, env?: Environment): Promise<Suspension | undefined> {
|
|
170
|
+
const newEnv = new Environment('auditlog', env).setInKernelMode(true);
|
|
171
|
+
const r: any = await parseAndEvaluateStatement(
|
|
172
|
+
`{agentlang/suspension {id? "${suspId}"}}`,
|
|
173
|
+
undefined,
|
|
174
|
+
newEnv
|
|
175
|
+
);
|
|
176
|
+
if (r instanceof Array && r.length > 0) {
|
|
177
|
+
const inst: Instance = r[0];
|
|
178
|
+
const cont = inst.lookup('continuation');
|
|
179
|
+
const stmts: Statement[] = await parseStatements(cont);
|
|
180
|
+
const envStr = inst.lookup('env');
|
|
181
|
+
const suspEnv: Environment = Environment.FromSerializableObject(JSON.parse(envStr));
|
|
182
|
+
return {
|
|
183
|
+
continuation: stmts,
|
|
184
|
+
env: suspEnv,
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
return undefined;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
async function deleteSuspension(suspId: string, env?: Environment): Promise<any> {
|
|
191
|
+
try {
|
|
192
|
+
await parseAndEvaluateStatement(
|
|
193
|
+
`purge {agentlang/suspension {id? "${suspId}"}}`,
|
|
194
|
+
undefined,
|
|
195
|
+
env
|
|
196
|
+
);
|
|
197
|
+
return suspId;
|
|
198
|
+
} catch (err: any) {
|
|
199
|
+
logger.warn(`Failed to delete suspension ${suspId} - ${err}`);
|
|
200
|
+
return undefined;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export async function restartSuspension(
|
|
205
|
+
suspId: string,
|
|
206
|
+
userData: string,
|
|
207
|
+
env?: Environment
|
|
208
|
+
): Promise<any> {
|
|
209
|
+
const susp = await loadSuspension(suspId, env);
|
|
210
|
+
if (susp) {
|
|
211
|
+
susp.env.bindSuspensionUserData(userData);
|
|
212
|
+
await evaluateStatements(susp.continuation, susp.env);
|
|
213
|
+
await deleteSuspension(suspId, env);
|
|
214
|
+
return susp.env.getLastResult();
|
|
215
|
+
} else {
|
|
216
|
+
logger.warn(`Suspension ${suspId} not found`);
|
|
217
|
+
return undefined;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
export async function lookupActiveSuspension(
|
|
222
|
+
resolver: Resolver,
|
|
223
|
+
inst: Instance,
|
|
224
|
+
queryAll: boolean
|
|
225
|
+
) {
|
|
226
|
+
if (!queryAll) {
|
|
227
|
+
const data = inst.lookupQueryVal(PathAttributeName).split('/')[1];
|
|
228
|
+
if (data) {
|
|
229
|
+
const parts = data.split(':');
|
|
230
|
+
const id = parts[0];
|
|
231
|
+
const userData = parts[1];
|
|
232
|
+
return await restartSuspension(id, userData, resolver.getEnvironment());
|
|
233
|
+
} else {
|
|
234
|
+
return [];
|
|
235
|
+
}
|
|
236
|
+
} else {
|
|
237
|
+
return [];
|
|
238
|
+
}
|
|
239
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { evaluate } from '../interpreter.js';
|
|
1
|
+
import { Environment, evaluate } from '../interpreter.js';
|
|
2
2
|
import { logger } from '../logger.js';
|
|
3
3
|
import {
|
|
4
4
|
Instance,
|
|
@@ -45,7 +45,7 @@ export function getSubscriptionEvent(resolverName: string): string | undefined {
|
|
|
45
45
|
|
|
46
46
|
export class Resolver {
|
|
47
47
|
protected authInfo: ResolverAuthInfo = DefaultAuthInfo;
|
|
48
|
-
protected
|
|
48
|
+
protected env: Environment | undefined;
|
|
49
49
|
protected name: string = 'default';
|
|
50
50
|
|
|
51
51
|
static Default = new Resolver();
|
|
@@ -59,13 +59,13 @@ export class Resolver {
|
|
|
59
59
|
return this;
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
public
|
|
63
|
-
this.
|
|
62
|
+
public setEnvironment(env: Environment): Resolver {
|
|
63
|
+
this.env = env;
|
|
64
64
|
return this;
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
public
|
|
68
|
-
return this.
|
|
67
|
+
public getEnvironment(): Environment | undefined {
|
|
68
|
+
return this.env;
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
public getName(): string {
|
|
@@ -65,7 +65,7 @@ export class SqlDbResolver extends Resolver {
|
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
private getDbContext(resourceFqName: string): DbContext {
|
|
68
|
-
const activeEnv: Environment = this.
|
|
68
|
+
const activeEnv: Environment = this.getEnvironment() as Environment;
|
|
69
69
|
if (!activeEnv) {
|
|
70
70
|
throw new Error('Active environment context is required by SqlDbResolver');
|
|
71
71
|
}
|
|
@@ -104,7 +104,7 @@ export class SqlDbResolver extends Resolver {
|
|
|
104
104
|
attrs.set(PathAttributeName, p);
|
|
105
105
|
}
|
|
106
106
|
const n: string = asTableName(inst.moduleName, inst.name);
|
|
107
|
-
const rowObj: object = inst.
|
|
107
|
+
const rowObj: object = inst.attributesWithStringifiedObjects();
|
|
108
108
|
const ctx = this.getDbContext(inst.getFqName());
|
|
109
109
|
await insertRow(n, rowObj, ctx, orUpdate);
|
|
110
110
|
if (inst.record.getFullTextSearchAttributes()) {
|
package/src/runtime/util.ts
CHANGED
|
@@ -49,12 +49,14 @@ function asString(s: MaybeString): string {
|
|
|
49
49
|
else return s;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
+
const QuoteCharacter = '"';
|
|
53
|
+
|
|
52
54
|
export function restoreSpecialChars(s: string) {
|
|
53
|
-
return s.replaceAll(
|
|
55
|
+
return s.replaceAll(QuoteCharacter, '"');
|
|
54
56
|
}
|
|
55
57
|
|
|
56
58
|
export function escapeSpecialChars(s: string) {
|
|
57
|
-
return s.replaceAll('"',
|
|
59
|
+
return s.replaceAll('"', QuoteCharacter);
|
|
58
60
|
}
|
|
59
61
|
|
|
60
62
|
export class Path {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Monarch syntax highlighting for the agentlang language.
|
|
2
2
|
export default {
|
|
3
3
|
keywords: [
|
|
4
|
-
'@actions','@after','@async','@before','@enum','@expr','@from','@meta','@oneof','@rbac','@ref','@upsert','@with_unique','agent','allow','and','
|
|
4
|
+
'@actions','@after','@as','@async','@before','@catch','@enum','@expr','@from','@meta','@oneof','@rbac','@ref','@upsert','@with_unique','agent','allow','and','await','between','contains','create','delete','else','entity','error','event','extends','false','for','if','import','in','into','like','module','not','not_found','onSubscription','or','purge','query','read','record','relationship','resolver','return','roles','subscribe','true','update','upsert','where','workflow'
|
|
5
5
|
],
|
|
6
6
|
operators: [
|
|
7
7
|
'*','+',',','-','.','/',':',';','<','<=','<>','=','>','>=','?','@'
|