agentlang 0.0.16 → 0.0.17

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 (56) hide show
  1. package/out/cli/docs.d.ts +2 -0
  2. package/out/cli/docs.d.ts.map +1 -0
  3. package/out/cli/docs.js +236 -0
  4. package/out/cli/docs.js.map +1 -0
  5. package/out/cli/openapi-docs.yml +695 -0
  6. package/out/extension/main.cjs +250 -250
  7. package/out/extension/main.cjs.map +2 -2
  8. package/out/index.d.ts +19 -0
  9. package/out/index.d.ts.map +1 -0
  10. package/out/index.js +25 -0
  11. package/out/index.js.map +1 -0
  12. package/out/language/generated/ast.d.ts +3 -3
  13. package/out/language/generated/ast.d.ts.map +1 -1
  14. package/out/language/generated/ast.js +0 -1
  15. package/out/language/generated/ast.js.map +1 -1
  16. package/out/language/generated/grammar.d.ts.map +1 -1
  17. package/out/language/generated/grammar.js +8 -0
  18. package/out/language/generated/grammar.js.map +1 -1
  19. package/out/language/main.cjs +510 -502
  20. package/out/language/main.cjs.map +3 -3
  21. package/out/runtime/agents/common.d.ts +1 -1
  22. package/out/runtime/agents/common.d.ts.map +1 -1
  23. package/out/runtime/agents/common.js +16 -2
  24. package/out/runtime/agents/common.js.map +1 -1
  25. package/out/runtime/auth/cognito.d.ts +2 -1
  26. package/out/runtime/auth/cognito.d.ts.map +1 -1
  27. package/out/runtime/auth/cognito.js +29 -1
  28. package/out/runtime/auth/cognito.js.map +1 -1
  29. package/out/runtime/auth/interface.d.ts +2 -1
  30. package/out/runtime/auth/interface.d.ts.map +1 -1
  31. package/out/runtime/interpreter.js +24 -5
  32. package/out/runtime/interpreter.js.map +1 -1
  33. package/out/runtime/jsmodules.js +1 -1
  34. package/out/runtime/jsmodules.js.map +1 -1
  35. package/out/runtime/module.d.ts +2 -0
  36. package/out/runtime/module.d.ts.map +1 -1
  37. package/out/runtime/module.js +14 -1
  38. package/out/runtime/module.js.map +1 -1
  39. package/out/runtime/modules/auth.d.ts +2 -1
  40. package/out/runtime/modules/auth.d.ts.map +1 -1
  41. package/out/runtime/modules/auth.js +25 -4
  42. package/out/runtime/modules/auth.js.map +1 -1
  43. package/out/syntaxes/agentlang.monarch.js +2 -2
  44. package/out/syntaxes/agentlang.monarch.js.map +1 -1
  45. package/package.json +6 -3
  46. package/src/language/agentlang.langium +2 -2
  47. package/src/language/generated/ast.ts +4 -3
  48. package/src/language/generated/grammar.ts +8 -0
  49. package/src/runtime/agents/common.ts +16 -2
  50. package/src/runtime/auth/cognito.ts +30 -0
  51. package/src/runtime/auth/interface.ts +3 -0
  52. package/src/runtime/interpreter.ts +22 -5
  53. package/src/runtime/jsmodules.ts +1 -1
  54. package/src/runtime/module.ts +15 -1
  55. package/src/runtime/modules/auth.ts +32 -2
  56. package/src/syntaxes/agentlang.monarch.ts +2 -2
@@ -154,7 +154,7 @@ Delete: 'delete' pattern=Pattern;
154
154
 
155
155
  Purge: 'purge' pattern=Pattern;
156
156
 
157
- SetAttribute: name=QueryId op=('='|'<>'|'<'|'<='|'>'|'>='|'in'|'like'|'between')? value=AttributeValueExpression;
157
+ SetAttribute: name=QueryId op=('='|'<>' | '!=' |'<'|'<='|'>'|'>='|'in'|'like'|'between')? value=AttributeValueExpression;
158
158
 
159
159
  AttributeValueExpression: Expr;
160
160
 
@@ -170,7 +170,7 @@ Logical infers Expr:
170
170
  Comparison ({infer BinExpr.e1=current} op=('or'|'and') e2=Comparison)*;
171
171
 
172
172
  Comparison infers Expr:
173
- PrimExpr ({infer BinExpr.e1=current} op=('='|'<>'|'<'|'<='|'>'|'>='|'in'|'like') e2=PrimExpr)*;
173
+ PrimExpr ({infer BinExpr.e1=current} op=('=' | '!=' | '<>'|'<'|'<='|'>'|'>='|'in'|'like') e2=PrimExpr)*;
174
174
 
175
175
  PrimExpr: Literal | Group | NegExpr | NotExpr;
176
176
 
@@ -3,7 +3,7 @@
3
3
  * DO NOT EDIT MANUALLY!
4
4
  ******************************************************************************/
5
5
 
6
- /* eslint-disable */
6
+
7
7
  import * as langium from 'langium';
8
8
 
9
9
  export const AgentlangTerminals = {
@@ -18,6 +18,7 @@ export const AgentlangTerminals = {
18
18
  export type AgentlangTerminalNames = keyof typeof AgentlangTerminals;
19
19
 
20
20
  export type AgentlangKeywordNames =
21
+ | "!="
21
22
  | "("
22
23
  | ")"
23
24
  | "*"
@@ -311,7 +312,7 @@ export interface BinExpr extends langium.AstNode {
311
312
  readonly $type: 'BinExpr';
312
313
  e1: Expr | PrimExpr;
313
314
  e2: Expr | PrimExpr;
314
- op: '*' | '+' | '-' | '/' | '<' | '<=' | '<>' | '=' | '>' | '>=' | 'and' | 'in' | 'like' | 'or';
315
+ op: '!=' | '*' | '+' | '-' | '/' | '<' | '<=' | '<>' | '=' | '>' | '>=' | 'and' | 'in' | 'like' | 'or';
315
316
  }
316
317
 
317
318
  export const BinExpr = 'BinExpr';
@@ -1061,7 +1062,7 @@ export interface SetAttribute extends langium.AstNode {
1061
1062
  readonly $container: CrudMapBody;
1062
1063
  readonly $type: 'SetAttribute';
1063
1064
  name: QueryId;
1064
- op?: '<' | '<=' | '<>' | '=' | '>' | '>=' | 'between' | 'in' | 'like';
1065
+ op?: '!=' | '<' | '<=' | '<>' | '=' | '>' | '>=' | 'between' | 'in' | 'like';
1065
1066
  value: AttributeValueExpression;
1066
1067
  }
1067
1068
 
@@ -4423,6 +4423,10 @@ export const AgentlangGrammar = (): Grammar => loadedAgentlangGrammar ?? (loaded
4423
4423
  "$type": "Keyword",
4424
4424
  "value": "<>"
4425
4425
  },
4426
+ {
4427
+ "$type": "Keyword",
4428
+ "value": "!="
4429
+ },
4426
4430
  {
4427
4431
  "$type": "Keyword",
4428
4432
  "value": "<"
@@ -4763,6 +4767,10 @@ export const AgentlangGrammar = (): Grammar => loadedAgentlangGrammar ?? (loaded
4763
4767
  "$type": "Keyword",
4764
4768
  "value": "="
4765
4769
  },
4770
+ {
4771
+ "$type": "Keyword",
4772
+ "value": "!="
4773
+ },
4766
4774
  {
4767
4775
  "$type": "Keyword",
4768
4776
  "value": "<>"
@@ -67,7 +67,7 @@ The default query operator is '=' (equals). So an expression like 'employeeId? "
67
67
  '{age?< 50}' - which means 'where age less-than 50'. The comparison operators supported by a query pattern are:
68
68
 
69
69
  = - equals
70
- <> - not-equals
70
+ != - not-equals
71
71
  < - less-than
72
72
  <= - less-than or equals
73
73
  > - greater-than
@@ -148,6 +148,20 @@ A fix for the reference-error is shown below:
148
148
  {Employee {id? 101}} @as employee;
149
149
  {SendEmail {to employee.email, body "hello"}}
150
150
 
151
+ Keep in mind that the only valid syntax for the 'if' condition is:
152
+
153
+ if (<expr>) {
154
+ <patterns>
155
+ } else if (<expr>) {
156
+ <patterns>
157
+ } else {
158
+ <patterns>
159
+ }
160
+
161
+ The following usage is NOT valid:
162
+
163
+ <pattern> if (<expr>)
164
+
151
165
  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
166
 
153
167
  {sendChatMessage {to "amy", "text" "hello"}} @as response @then {
@@ -241,7 +255,7 @@ As an example, if the user request is "send an email to employee 101 with this m
241
255
  [{employee {id? 101}} @as emp;
242
256
  {email {to emp.email, body "please call me as soon as possible"}}]
243
257
 
244
- Note that each pattern in the array is separated by a ; and not a comma(,).
258
+ You MUST separate each pattern in the array with a semi-colon (;) and never use a comma (,) for this purpose.
245
259
 
246
260
  Now consider the following module definition and generate appropriate patterns in response to the user instructions. You must return only valid patterns or workflows,
247
261
  no other descriptive text or comments are needed.
@@ -34,6 +34,7 @@ import {
34
34
  let fromEnv: any = undefined;
35
35
  let CognitoIdentityProviderClient: any = undefined;
36
36
  let SignUpCommand: any = undefined;
37
+ let ConfirmSignUp: any = undefined;
37
38
  let AdminGetUserCommand: any = undefined;
38
39
  let InitiateAuthCommand: any = undefined;
39
40
  let AuthenticationDetails: any = undefined;
@@ -51,6 +52,7 @@ if (isNodeEnv) {
51
52
  const cip = await import('@aws-sdk/client-cognito-identity-provider');
52
53
  CognitoIdentityProviderClient = cip.CognitoIdentityProviderClient;
53
54
  SignUpCommand = cip.SignUpCommand;
55
+ ConfirmSignUp = cip.ConfirmSignUpCommand;
54
56
  AdminGetUserCommand = cip.AdminGetUserCommand;
55
57
  InitiateAuthCommand = cip.InitiateAuthCommand;
56
58
 
@@ -321,6 +323,8 @@ export class CognitoAuth implements AgentlangAuth {
321
323
  }
322
324
 
323
325
  async signUp(
326
+ firstName: string,
327
+ lastName: string,
324
328
  username: string,
325
329
  password: string,
326
330
  userData: Map<string, string> | undefined,
@@ -340,6 +344,14 @@ export class CognitoAuth implements AgentlangAuth {
340
344
  Name: 'name',
341
345
  Value: username,
342
346
  },
347
+ {
348
+ Name: 'given_name',
349
+ Value: firstName,
350
+ },
351
+ {
352
+ Name: 'family_name',
353
+ Value: lastName,
354
+ },
343
355
  ];
344
356
  if (userData) {
345
357
  userData.forEach((v: string, k: string) => {
@@ -384,6 +396,24 @@ export class CognitoAuth implements AgentlangAuth {
384
396
  }
385
397
  }
386
398
 
399
+ async confirmSignup(username: string, confirmationCode: string, env: Environment): Promise<void> {
400
+ try {
401
+ const client = new CognitoIdentityProviderClient({
402
+ region: process.env.AWS_REGION || 'us-west-2',
403
+ credentials: fromEnv(),
404
+ });
405
+ const command = new ConfirmSignUp({
406
+ ClientId: this.config.get('ClientId'),
407
+ Username: username,
408
+ ConfirmationCode: confirmationCode,
409
+ });
410
+ await client.send(command);
411
+ } catch (error: any) {
412
+ logger.error(`Failed to confirm signup: ${error.message}`);
413
+ throw error;
414
+ }
415
+ }
416
+
387
417
  async login(
388
418
  username: string,
389
419
  password: string,
@@ -22,12 +22,15 @@ export type LogoutCallback = (status: boolean) => void;
22
22
 
23
23
  export interface AgentlangAuth {
24
24
  signUp(
25
+ firstName: string,
26
+ lastName: string,
25
27
  username: string,
26
28
  password: string,
27
29
  userData: Map<string, any> | undefined,
28
30
  env: Environment,
29
31
  cb: SignUpCallback
30
32
  ): any;
33
+ confirmSignup(username: string, confirmationCode: string, env: Environment): Promise<void>;
31
34
  login(username: string, password: string, env: Environment, cb: LoginCallback): any;
32
35
  logout(sessionInfo: SessionInfo, env: Environment, cb?: LogoutCallback): any;
33
36
  verifyToken(token: string, env?: Environment): any;
@@ -1127,8 +1127,15 @@ async function evaluateCrudMap(crud: CrudMap, env: Environment): Promise<void> {
1127
1127
  for (let j = 0; j < lastRes.length; ++j) {
1128
1128
  const newEnv: Environment = Environment.from(env);
1129
1129
  if (isContainsRelationship(rel.name, moduleName)) {
1130
- const ppath = lastRes[j].attributes.get(PathAttributeName);
1131
- newEnv.setParentPath(ppath + '/' + escapeFqName(relEntry.getFqName()));
1130
+ const currInst: Instance = lastRes[j];
1131
+ let ppath = '';
1132
+ if (relEntry.isParent(currInst)) {
1133
+ ppath = currInst.lookup(PathAttributeName);
1134
+ newEnv.setParentPath(ppath + '/' + escapeFqName(relEntry.getFqName()));
1135
+ } else {
1136
+ ppath = currInst.lookup(ParentAttributeName);
1137
+ newEnv.setParentPath(ppath);
1138
+ }
1132
1139
  newEnv.setNormalizedParentPath(ppath);
1133
1140
  await evaluatePattern(rel.pattern, newEnv);
1134
1141
  lastRes[j].attachRelatedInstances(rel.name, newEnv.getLastResult());
@@ -1303,11 +1310,17 @@ async function handleAgentInvocation(agentEventInst: Instance, env: Environment)
1303
1310
  logger.debug(`Agent ${agent.name} generated pattern: ${result}`);
1304
1311
  try {
1305
1312
  let rs = result.trim();
1306
- if (rs.startsWith('[')) {
1313
+ let isWf = rs.startsWith('workflow');
1314
+ const isGrp = rs.startsWith('[');
1315
+ if (!isWf && !isGrp && rs.indexOf(';') > 0) {
1316
+ rs = `workflow T {${rs}}`;
1317
+ isWf = true;
1318
+ } else if (!isWf && isGrp) {
1307
1319
  const stmts = rs.substring(1, rs.length - 1);
1308
1320
  rs = `workflow T {${stmts}}`;
1321
+ isWf = true;
1309
1322
  }
1310
- if (rs.startsWith('workflow')) {
1323
+ if (isWf) {
1311
1324
  const wf = await parseWorkflow(rs);
1312
1325
  if (agent.runWorkflows) {
1313
1326
  await evaluateStatements(wf.statements, env);
@@ -1334,7 +1347,10 @@ function cleanupAgentResponse(response: string | undefined): string | undefined
1334
1347
  }
1335
1348
  const parts = resp.split('\n');
1336
1349
  const validated = parts.filter((s: string) => {
1337
- const stmt = s.trim();
1350
+ let stmt = s.trim();
1351
+ if (stmt.endsWith(',')) {
1352
+ stmt = `${stmt.substring(0, stmt.length - 1)};`;
1353
+ }
1338
1354
  const r =
1339
1355
  stmt.startsWith('{') ||
1340
1356
  stmt.startsWith('}') ||
@@ -1479,6 +1495,7 @@ async function evaluateExpression(expr: Expr, env: Environment): Promise<void> {
1479
1495
  result = v1 >= v2;
1480
1496
  break;
1481
1497
  case '<>':
1498
+ case '!=':
1482
1499
  result = v1 != v2;
1483
1500
  break;
1484
1501
  case 'like':
@@ -36,7 +36,7 @@ export async function importModule(path: string, name: string, moduleFileName?:
36
36
  }
37
37
  path = `${s}${sep}${path}`;
38
38
  }
39
- if (!(path.startsWith(sep) || path.startsWith('.'))) {
39
+ if ((path.startsWith(sep) || path.startsWith('.')) && moduleFileName) {
40
40
  path = process.cwd() + sep + path;
41
41
  }
42
42
  const m = await import(/* @vite-ignore */ path);
@@ -139,6 +139,8 @@ function attributePropertyValueToString(
139
139
  if (isTextualType(attrType) && propValue != 'now()' && propValue != 'uuid()') {
140
140
  return `"${propValue}"`;
141
141
  }
142
+ } else if (propName == 'comment') {
143
+ return `"${propValue}"`;
142
144
  }
143
145
  return `${propValue}`;
144
146
  }
@@ -171,7 +173,7 @@ function normalizeMetaValue(metaValue: any): any {
171
173
  return normalizeMetaValue(value.pattern.expr);
172
174
  });
173
175
  } else if (v.bool != undefined) {
174
- return v.bool;
176
+ return v.bool == 'true' ? true : false;
175
177
  } else if (v.id) {
176
178
  return v.id;
177
179
  } else if (v.map) {
@@ -884,6 +886,11 @@ export class Entity extends Record {
884
886
  getRbacSpecifications(): RbacSpecification[] | undefined {
885
887
  return this.rbac;
886
888
  }
889
+
890
+ isConfigEntity(): boolean {
891
+ const v = this.getMeta('configEntity');
892
+ return v == true;
893
+ }
887
894
  }
888
895
 
889
896
  export class Event extends Record {
@@ -1286,6 +1293,12 @@ export class Module {
1286
1293
  return entry;
1287
1294
  }
1288
1295
 
1296
+ getConfigEntity(): Entity | undefined {
1297
+ return this.getEntityEntries().find((e: Entity) => {
1298
+ return e.isConfigEntity();
1299
+ });
1300
+ }
1301
+
1289
1302
  addAgent(agentEntry: Agent): Agent {
1290
1303
  return this.addEntry(agentEntry) as Agent;
1291
1304
  }
@@ -1590,6 +1603,7 @@ export const propertyNames = new Set([
1590
1603
  '@readonly',
1591
1604
  '@enum',
1592
1605
  '@oneof',
1606
+ '@comment',
1593
1607
  ]);
1594
1608
 
1595
1609
  const TextualTypes = new Set(['String', 'Email', 'UUID', 'DateTime', 'Date', 'Time', 'Path']);
@@ -173,7 +173,11 @@ workflow RemoveUserSession {
173
173
  }
174
174
 
175
175
  workflow signup {
176
- await Auth.signUpUser(signup.email, signup.password, signup.userData)
176
+ await Auth.signUpUser(signup.firstName, signup.lastName, signup.email, signup.password, signup.userData)
177
+ }
178
+
179
+ workflow confirmSignup {
180
+ await Auth.confirmSignupUser(confirmSignup.email, confirmSignup.confirmationCode)
177
181
  }
178
182
 
179
183
  workflow login {
@@ -573,7 +577,10 @@ function fetchAuthImpl(): AgentlangAuth {
573
577
  throw new Error('Auth not initialized');
574
578
  }
575
579
  }
580
+
576
581
  export async function signUpUser(
582
+ firstName: string,
583
+ lastName: string,
577
584
  username: string,
578
585
  password: string,
579
586
  userData: object,
@@ -582,6 +589,8 @@ export async function signUpUser(
582
589
  let result: any;
583
590
  try {
584
591
  await fetchAuthImpl().signUp(
592
+ firstName,
593
+ lastName,
585
594
  username,
586
595
  password,
587
596
  userData ? new Map(Object.entries(userData)) : undefined,
@@ -597,6 +606,24 @@ export async function signUpUser(
597
606
  }
598
607
  }
599
608
 
609
+ export async function confirmSignupUser(
610
+ username: string,
611
+ confirmationCode: string,
612
+ env: Environment
613
+ ): Promise<any> {
614
+ try {
615
+ console.log('confirmSignupUser', username, confirmationCode, env);
616
+ await fetchAuthImpl().confirmSignup(username, confirmationCode, env);
617
+ return {
618
+ status: 'ok',
619
+ message: 'User confirmed successfully',
620
+ };
621
+ } catch (err: any) {
622
+ logger.error(`Confirm signup failed for ${username}: ${err.message}`);
623
+ throw err; // Re-throw to preserve error type for HTTP status mapping
624
+ }
625
+ }
626
+
600
627
  export async function loginUser(
601
628
  username: string,
602
629
  password: string,
@@ -870,7 +897,10 @@ export function requireAuth(moduleName: string, eventName: string): boolean {
870
897
  if (isAuthEnabled()) {
871
898
  const f =
872
899
  moduleName == CoreAuthModuleName &&
873
- (eventName == 'login' || eventName == 'signup' || eventName == 'refreshToken');
900
+ (eventName == 'login' ||
901
+ eventName == 'signup' ||
902
+ eventName == 'confirmSignup' ||
903
+ eventName == 'refreshToken');
874
904
  return !f;
875
905
  } else {
876
906
  return false;
@@ -4,9 +4,9 @@ export default {
4
4
  '@actions','@after','@as','@async','@before','@catch','@distinct','@enum','@expr','@from','@into','@meta','@oneof','@rbac','@ref','@then','@upsert','@with_unique','agent','allow','and','await','between','contains','create','delete','else','entity','error','event','extends','false','for','if','import','in','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
+ '!=','*','+',',','-','.','/',':',';','<','<=','<>','=','>','>=','?','@'
8
8
  ],
9
- symbols: /\(|\)|\*|\+|,|-|\.|\/|:|;|<|<=|<>|=|>|>=|\?|@|\[|\]|\{|\}/,
9
+ symbols: /!=|\(|\)|\*|\+|,|-|\.|\/|:|;|<|<=|<>|=|>|>=|\?|@|\[|\]|\{|\}/,
10
10
 
11
11
  tokenizer: {
12
12
  initial: [