agentlang 0.4.8 → 0.4.9

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 (66) hide show
  1. package/out/api/http.d.ts +2 -1
  2. package/out/api/http.d.ts.map +1 -1
  3. package/out/api/http.js +246 -2
  4. package/out/api/http.js.map +1 -1
  5. package/out/cli/main.js +1 -1
  6. package/out/cli/main.js.map +1 -1
  7. package/out/language/generated/ast.js +0 -1
  8. package/out/language/generated/ast.js.map +1 -1
  9. package/out/language/main.cjs.map +1 -1
  10. package/out/language/parser.d.ts.map +1 -1
  11. package/out/language/parser.js +25 -6
  12. package/out/language/parser.js.map +1 -1
  13. package/out/language/syntax.d.ts +12 -0
  14. package/out/language/syntax.d.ts.map +1 -1
  15. package/out/language/syntax.js +21 -0
  16. package/out/language/syntax.js.map +1 -1
  17. package/out/runtime/auth/cognito.d.ts +2 -1
  18. package/out/runtime/auth/cognito.d.ts.map +1 -1
  19. package/out/runtime/auth/cognito.js +52 -2
  20. package/out/runtime/auth/cognito.js.map +1 -1
  21. package/out/runtime/auth/interface.d.ts +2 -1
  22. package/out/runtime/auth/interface.d.ts.map +1 -1
  23. package/out/runtime/modules/auth.d.ts +2 -1
  24. package/out/runtime/modules/auth.d.ts.map +1 -1
  25. package/out/runtime/modules/auth.js +56 -4
  26. package/out/runtime/modules/auth.js.map +1 -1
  27. package/out/runtime/modules/core.d.ts.map +1 -1
  28. package/out/runtime/modules/core.js +2 -1
  29. package/out/runtime/modules/core.js.map +1 -1
  30. package/out/runtime/modules/files.d.ts +18 -0
  31. package/out/runtime/modules/files.d.ts.map +1 -0
  32. package/out/runtime/modules/files.js +115 -0
  33. package/out/runtime/modules/files.js.map +1 -0
  34. package/out/runtime/state.d.ts +5 -0
  35. package/out/runtime/state.d.ts.map +1 -1
  36. package/out/runtime/state.js +2 -0
  37. package/out/runtime/state.js.map +1 -1
  38. package/out/runtime/util.d.ts +1 -0
  39. package/out/runtime/util.d.ts.map +1 -1
  40. package/out/runtime/util.js +1 -0
  41. package/out/runtime/util.js.map +1 -1
  42. package/out/setupClassic.d.ts +98 -0
  43. package/out/setupClassic.d.ts.map +1 -0
  44. package/out/setupClassic.js +38 -0
  45. package/out/setupClassic.js.map +1 -0
  46. package/out/setupCommon.d.ts +2 -0
  47. package/out/setupCommon.d.ts.map +1 -0
  48. package/out/setupCommon.js +33 -0
  49. package/out/setupCommon.js.map +1 -0
  50. package/out/setupExtended.d.ts +40 -0
  51. package/out/setupExtended.d.ts.map +1 -0
  52. package/out/setupExtended.js +67 -0
  53. package/out/setupExtended.js.map +1 -0
  54. package/package.json +186 -183
  55. package/src/api/http.ts +321 -2
  56. package/src/cli/main.ts +1 -1
  57. package/src/language/generated/ast.ts +1 -1
  58. package/src/language/parser.ts +34 -5
  59. package/src/language/syntax.ts +31 -0
  60. package/src/runtime/auth/cognito.ts +59 -1
  61. package/src/runtime/auth/interface.ts +2 -0
  62. package/src/runtime/modules/auth.ts +65 -5
  63. package/src/runtime/modules/core.ts +2 -1
  64. package/src/runtime/modules/files.ts +183 -0
  65. package/src/runtime/state.ts +2 -0
  66. package/src/runtime/util.ts +1 -0
@@ -380,16 +380,44 @@ entity Session {
380
380
  await Auth.getUserInfoByEmail(getUserByEmail.email)
381
381
  }
382
382
 
383
+ @public workflow getUsersDetail {
384
+ {User? {},
385
+ UserRole {Role? {}},
386
+ @into {
387
+ id User.id,
388
+ email User.email,
389
+ firstName User.firstName,
390
+ lastName User.lastName,
391
+ lastLoginTime User.lastLoginTime,
392
+ status User.status,
393
+ role Role.name}
394
+ }
395
+ }
396
+
383
397
  @public workflow inviteUser {
384
- await Auth.inviteUser(inviteUser.email, inviteUser.firstName, inviteUser.lastName, inviteUser.userData)
398
+ await Auth.inviteUser(inviteUser.email, inviteUser.firstName, inviteUser.lastName, inviteUser.userData, inviteUser.role)
385
399
  }
386
400
 
387
401
  @public workflow inviteUsers {
388
402
  for u in inviteUsers.users {
389
- {inviteUser {email u.email, firstName u.firstName, lastName u.lastName, userData u.userData}}
403
+ {inviteUser {email u.email, firstName u.firstName, lastName u.lastName, userData u.userData, role u.role}}
390
404
  }
391
405
  }
392
406
 
407
+ record ResendInvitationResult {
408
+ message String
409
+ }
410
+
411
+ @public workflow resendInvitation {
412
+ {User {email? resendInvitation.email}} @as [u]
413
+ if (u and u.status == "Invited") {
414
+ await Auth.resendInvitationUser(u.email)
415
+ } else if (u) {
416
+ {ResendInvitationResult {message "User is not invited"}}
417
+ } else {
418
+ {ResendInvitationResult {message "User not found"}}
419
+ }
420
+ }
393
421
 
394
422
  @public workflow acceptInvitation {
395
423
  await Auth.acceptInvitationUser(acceptInvitation.email, acceptInvitation.tempPassword, acceptInvitation.newPassword)
@@ -1336,6 +1364,7 @@ export async function inviteUser(
1336
1364
  firstName: string,
1337
1365
  lastName: string,
1338
1366
  userData: Map<string, any> | undefined,
1367
+ role: string | undefined,
1339
1368
  env: Environment
1340
1369
  ): Promise<object> {
1341
1370
  const needCommit = env ? false : true;
@@ -1343,9 +1372,17 @@ export async function inviteUser(
1343
1372
  const f = async () => {
1344
1373
  try {
1345
1374
  let invitationInfo: any;
1346
- await fetchAuthImpl().inviteUser(email, firstName, lastName, userData, env, (info: any) => {
1347
- invitationInfo = info;
1348
- });
1375
+ await fetchAuthImpl().inviteUser(
1376
+ email,
1377
+ firstName,
1378
+ lastName,
1379
+ userData,
1380
+ role,
1381
+ env,
1382
+ (info: any) => {
1383
+ invitationInfo = info;
1384
+ }
1385
+ );
1349
1386
 
1350
1387
  return {
1351
1388
  email: invitationInfo.email,
@@ -1366,6 +1403,28 @@ export async function inviteUser(
1366
1403
  }
1367
1404
  }
1368
1405
 
1406
+ export async function resendInvitationUser(email: string, env: Environment): Promise<object> {
1407
+ const needCommit = env ? false : true;
1408
+ env = env ? env : new Environment();
1409
+ const f = async () => {
1410
+ try {
1411
+ await fetchAuthImpl().resendInvitation(email, env);
1412
+ return {
1413
+ email: email,
1414
+ message: 'Invitation resent successfully',
1415
+ };
1416
+ } catch (err: any) {
1417
+ logger.error(`Invitation resend failed: ${err.message}`);
1418
+ throw err;
1419
+ }
1420
+ };
1421
+ if (needCommit) {
1422
+ return await env.callInTransaction(f);
1423
+ } else {
1424
+ return await f();
1425
+ }
1426
+ }
1427
+
1369
1428
  export async function acceptInvitationUser(
1370
1429
  email: string,
1371
1430
  tempPassword: string,
@@ -1413,6 +1472,7 @@ export function requireAuth(moduleName: string, eventName: string): boolean {
1413
1472
  eventName == 'confirmForgotPassword' ||
1414
1473
  eventName == 'refreshToken' ||
1415
1474
  eventName == 'acceptInvitation' ||
1475
+ eventName == 'resendInvitation' ||
1416
1476
  eventName == 'callback');
1417
1477
  return !f;
1418
1478
  } else {
@@ -1,5 +1,6 @@
1
1
  import { default as ai } from './ai.js';
2
2
  import { default as auth } from './auth.js';
3
+ import { default as files } from './files.js';
3
4
  import { DefaultModuleName, DefaultModules, escapeSpecialChars } from '../util.js';
4
5
  import { Instance, isInstanceOfType, makeInstance, newInstanceAttributes } from '../module.js';
5
6
  import {
@@ -87,7 +88,7 @@ export const CoreModules: string[] = [];
87
88
  export function registerCoreModules() {
88
89
  DefaultModules.add(DefaultModuleName);
89
90
  CoreModules.push(CoreModuleDefinition);
90
- [auth, ai].forEach((mdef: string) => {
91
+ [auth, ai, files].forEach((mdef: string) => {
91
92
  CoreModules.push(mdef);
92
93
  DefaultModules.add(mdef);
93
94
  });
@@ -0,0 +1,183 @@
1
+ import { Result, Environment, evaluate } from '../interpreter.js';
2
+ import { makeCoreModuleName } from '../util.js';
3
+ import { Instance, makeInstance, objectAsInstanceAttributes } from '../module.js';
4
+ import crypto from 'crypto';
5
+ import { ActiveSessionInfo } from '../auth/defs.js';
6
+
7
+ export const CoreFilesModuleName = makeCoreModuleName('files');
8
+
9
+ export default `module ${CoreFilesModuleName}
10
+
11
+ entity File {
12
+ id String @id,
13
+ filename String @unique @indexed,
14
+ originalName String @optional,
15
+ mimetype String @default("application/octet-stream"),
16
+ size Int @optional,
17
+ uploadedBy String @optional,
18
+ uploadedAt DateTime @default(now()),
19
+ path String @optional,
20
+ @rbac [(allow: [create, read, update, delete], where: auth.user = this.uploadedBy)]
21
+ }
22
+
23
+ @public workflow CreateFile {
24
+ {File {id CreateFile.id,
25
+ filename CreateFile.filename,
26
+ originalName CreateFile.originalName,
27
+ mimetype CreateFile.mimetype,
28
+ size CreateFile.size,
29
+ uploadedBy CreateFile.uploadedBy,
30
+ uploadedAt CreateFile.uploadedAt,
31
+ path CreateFile.path},
32
+ @upsert}
33
+ }
34
+
35
+ @public workflow FindFile {
36
+ {File {id? FindFile.id}} @as [file];
37
+ file
38
+ }
39
+
40
+ @public workflow FindFileByFilename {
41
+ {File {filename? FindFileByFilename.filename}} @as [file];
42
+ file
43
+ }
44
+
45
+ @public workflow ListFiles {
46
+ {File? {}}
47
+ }
48
+
49
+ @public workflow ListUserFiles {
50
+ {File {uploadedBy? ListUserFiles.userId}}
51
+ }
52
+
53
+ @public workflow DeleteFile {
54
+ delete {File {id? DeleteFile.id}}
55
+ }
56
+
57
+ @public workflow DeleteFileByFilename {
58
+ delete {File {filename? DeleteFileByFilename.filename}}
59
+ }
60
+
61
+ @public workflow UpdateFile {
62
+ {File {id? UpdateFile.id,
63
+ originalName UpdateFile.originalName,
64
+ mimetype UpdateFile.mimetype,
65
+ size UpdateFile.size}}
66
+ }
67
+ `;
68
+
69
+ export async function createFileRecord(
70
+ fileInfo: {
71
+ filename: string;
72
+ originalName: string;
73
+ mimetype: string;
74
+ size: number;
75
+ path: string;
76
+ uploadedBy?: string;
77
+ },
78
+ sessionInfo?: ActiveSessionInfo,
79
+ callback?: (result: Result) => void,
80
+ env?: Environment
81
+ ): Promise<Result> {
82
+ let inst: Instance = makeInstance(
83
+ CoreFilesModuleName,
84
+ 'CreateFile',
85
+ objectAsInstanceAttributes({
86
+ id: crypto.randomUUID(),
87
+ filename: fileInfo.filename,
88
+ originalName: fileInfo.originalName,
89
+ mimetype: fileInfo.mimetype,
90
+ size: fileInfo.size,
91
+ path: fileInfo.path,
92
+ uploadedBy: fileInfo.uploadedBy || '',
93
+ uploadedAt: new Date().toISOString(),
94
+ })
95
+ );
96
+
97
+ if (sessionInfo) {
98
+ inst = inst.setAuthContext(sessionInfo);
99
+ }
100
+
101
+ return await evaluate(inst, callback, env);
102
+ }
103
+
104
+ export async function findFileByFilename(
105
+ filename: string,
106
+ sessionInfo?: ActiveSessionInfo,
107
+ callback?: (result: Result) => void,
108
+ env?: Environment
109
+ ): Promise<Result> {
110
+ let inst: Instance = makeInstance(
111
+ CoreFilesModuleName,
112
+ 'FindFileByFilename',
113
+ objectAsInstanceAttributes({
114
+ filename: filename,
115
+ })
116
+ );
117
+
118
+ if (sessionInfo) {
119
+ inst = inst.setAuthContext(sessionInfo);
120
+ }
121
+
122
+ return await evaluate(inst, callback, env);
123
+ }
124
+
125
+ export async function deleteFileRecord(
126
+ filename: string,
127
+ sessionInfo?: ActiveSessionInfo,
128
+ callback?: (result: Result) => void,
129
+ env?: Environment
130
+ ): Promise<Result> {
131
+ let inst: Instance = makeInstance(
132
+ CoreFilesModuleName,
133
+ 'DeleteFileByFilename',
134
+ objectAsInstanceAttributes({
135
+ filename: filename,
136
+ })
137
+ );
138
+
139
+ if (sessionInfo) {
140
+ inst = inst.setAuthContext(sessionInfo);
141
+ }
142
+
143
+ return await evaluate(inst, callback, env);
144
+ }
145
+
146
+ export async function listAllFiles(
147
+ sessionInfo?: ActiveSessionInfo,
148
+ callback?: (result: Result) => void,
149
+ env?: Environment
150
+ ): Promise<Result> {
151
+ let inst: Instance = makeInstance(
152
+ CoreFilesModuleName,
153
+ 'ListFiles',
154
+ objectAsInstanceAttributes({})
155
+ );
156
+
157
+ if (sessionInfo) {
158
+ inst = inst.setAuthContext(sessionInfo);
159
+ }
160
+
161
+ return await evaluate(inst, callback, env);
162
+ }
163
+
164
+ export async function listUserFiles(
165
+ userId: string,
166
+ sessionInfo?: ActiveSessionInfo,
167
+ callback?: (result: Result) => void,
168
+ env?: Environment
169
+ ): Promise<Result> {
170
+ let inst: Instance = makeInstance(
171
+ CoreFilesModuleName,
172
+ 'ListUserFiles',
173
+ objectAsInstanceAttributes({
174
+ userId: userId,
175
+ })
176
+ );
177
+
178
+ if (sessionInfo) {
179
+ inst = inst.setAuthContext(sessionInfo);
180
+ }
181
+
182
+ return await evaluate(inst, callback, env);
183
+ }
@@ -6,10 +6,12 @@ export const ConfigSchema = z.object({
6
6
  .object({
7
7
  port: z.number(),
8
8
  host: z.string().optional(),
9
+ httpFileHandling: z.boolean().default(false),
9
10
  })
10
11
  .default({
11
12
  port: 8080,
12
13
  host: 'localhost',
14
+ httpFileHandling: false,
13
15
  }),
14
16
  store: z
15
17
  .discriminatedUnion('type', [
@@ -222,6 +222,7 @@ export function arrayEquals(a: Array<any>, b: Array<any>) {
222
222
 
223
223
  export const DefaultModuleName = 'agentlang';
224
224
  export const DefaultModules = new Set();
225
+ export const DefaultFileHandlingDirectory = 'fs';
225
226
 
226
227
  export function makeCoreModuleName(n: string): string {
227
228
  return DefaultModuleName + '.' + n;