agentlang 0.3.5 → 0.3.7
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/README.md +82 -29
- package/out/api/http.js +2 -2
- package/out/api/http.js.map +1 -1
- package/out/extension/main.cjs +250 -250
- package/out/extension/main.cjs.map +2 -2
- package/out/language/generated/ast.js +0 -1
- package/out/language/generated/ast.js.map +1 -1
- package/out/language/main.cjs +502 -502
- package/out/language/main.cjs.map +3 -3
- package/out/language/syntax.js +8 -8
- package/out/language/syntax.js.map +1 -1
- package/out/runtime/auth/cognito.js +2 -2
- package/out/runtime/auth/cognito.js.map +1 -1
- package/out/runtime/exec-graph.d.ts.map +1 -1
- package/out/runtime/exec-graph.js +6 -5
- package/out/runtime/exec-graph.js.map +1 -1
- package/out/runtime/interpreter.js +49 -49
- package/out/runtime/interpreter.js.map +1 -1
- package/out/runtime/jsmodules.js +6 -6
- package/out/runtime/jsmodules.js.map +1 -1
- package/out/runtime/loader.js +6 -6
- package/out/runtime/loader.js.map +1 -1
- package/out/runtime/module.d.ts.map +1 -1
- package/out/runtime/module.js +72 -66
- package/out/runtime/module.js.map +1 -1
- package/out/runtime/modules/ai.js +5 -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 -18
- package/out/runtime/modules/auth.js.map +1 -1
- package/out/runtime/modules/core.js +1 -1
- package/out/runtime/modules/core.js.map +1 -1
- package/out/runtime/openapi.js +2 -2
- package/out/runtime/openapi.js.map +1 -1
- package/out/runtime/relgraph.js +1 -1
- package/out/runtime/relgraph.js.map +1 -1
- package/out/runtime/resolvers/authinfo.js +2 -2
- package/out/runtime/resolvers/authinfo.js.map +1 -1
- package/out/runtime/resolvers/interface.js +1 -1
- package/out/runtime/resolvers/interface.js.map +1 -1
- package/out/runtime/resolvers/registry.js +1 -1
- package/out/runtime/resolvers/registry.js.map +1 -1
- package/out/runtime/resolvers/sqldb/database.js +11 -11
- package/out/runtime/resolvers/sqldb/database.js.map +1 -1
- package/out/runtime/resolvers/sqldb/impl.js +4 -4
- package/out/runtime/resolvers/sqldb/impl.js.map +1 -1
- package/out/runtime/util.js +5 -5
- package/out/runtime/util.js.map +1 -1
- package/out/utils/runtime.d.ts.map +1 -1
- package/out/utils/runtime.js +4 -2
- package/out/utils/runtime.js.map +1 -1
- package/package.json +184 -182
- package/src/api/http.ts +2 -2
- package/src/language/generated/ast.ts +1 -1
- package/src/language/syntax.ts +8 -8
- package/src/runtime/auth/cognito.ts +107 -2
- package/src/runtime/auth/interface.ts +1 -0
- package/src/runtime/exec-graph.ts +6 -5
- package/src/runtime/interpreter.ts +49 -49
- package/src/runtime/jsmodules.ts +6 -6
- package/src/runtime/loader.ts +6 -6
- package/src/runtime/module.ts +71 -66
- package/src/runtime/modules/ai.ts +5 -5
- package/src/runtime/modules/auth.ts +54 -20
- package/src/runtime/modules/core.ts +1 -1
- package/src/runtime/openapi.ts +2 -2
- package/src/runtime/relgraph.ts +1 -1
- package/src/runtime/resolvers/authinfo.ts +2 -2
- package/src/runtime/resolvers/interface.ts +1 -1
- package/src/runtime/resolvers/registry.ts +1 -1
- package/src/runtime/resolvers/sqldb/database.ts +11 -11
- package/src/runtime/resolvers/sqldb/impl.ts +4 -4
- package/src/runtime/util.ts +5 -5
- package/src/utils/runtime.ts +3 -3
package/package.json
CHANGED
|
@@ -1,183 +1,185 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
}
|
|
2
|
+
"name": "agentlang",
|
|
3
|
+
"description": "The easiest way to build the most reliable AI agents - enterprise-grade teams of AI agents that collaborate with each other and humans",
|
|
4
|
+
"version": "0.3.7",
|
|
5
|
+
"license": "Sustainable Use License",
|
|
6
|
+
"author": "agentlang-ai",
|
|
7
|
+
"homepage": "https://github.com/agentlang-ai/agentlang#readme",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/agentlang-ai/agentlang.git"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/agentlang-ai/agentlang/issues"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"agentlang",
|
|
17
|
+
"agents-generation",
|
|
18
|
+
"ai-agents",
|
|
19
|
+
"enterprise",
|
|
20
|
+
"multi-agent",
|
|
21
|
+
"no-code",
|
|
22
|
+
"agent-teams",
|
|
23
|
+
"production-ready"
|
|
24
|
+
],
|
|
25
|
+
"files": [
|
|
26
|
+
"bin",
|
|
27
|
+
"out",
|
|
28
|
+
"src",
|
|
29
|
+
"LICENSE"
|
|
30
|
+
],
|
|
31
|
+
"type": "module",
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"access": "public",
|
|
34
|
+
"registry": "https://registry.npmjs.org/"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "tsc -b tsconfig.src.json && tsc -b tsconfig.declarations.json && node esbuild.mjs",
|
|
38
|
+
"build:ts": "tsc -b tsconfig.src.json",
|
|
39
|
+
"watch": "concurrently -n tsc,esbuild -c blue,yellow \"tsc -b tsconfig.src.json --watch\" \"node esbuild.mjs --watch\"",
|
|
40
|
+
"lint": "eslint . --ext .ts",
|
|
41
|
+
"lint:fix": "eslint . --ext .ts --fix",
|
|
42
|
+
"format": "prettier --write \"src/**/*.{js,ts,tsx,json,md}\"",
|
|
43
|
+
"format:check": "prettier --check \"src/**/*.{js,ts,tsx,json,md}\"",
|
|
44
|
+
"langium:generate": "langium generate",
|
|
45
|
+
"langium:generate:production": "langium generate --mode=production",
|
|
46
|
+
"langium:watch": "langium generate --watch",
|
|
47
|
+
"vscode:prepublish": "npm run build && npm run lint",
|
|
48
|
+
"dev": "vite",
|
|
49
|
+
"test": "vitest run",
|
|
50
|
+
"test:verbose": "VITEST_VERBOSE=true vitest run"
|
|
51
|
+
},
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"@aws-sdk/client-cognito-identity": "^3.828.0",
|
|
54
|
+
"@aws-sdk/client-cognito-identity-provider": "^3.828.0",
|
|
55
|
+
"@aws-sdk/credential-providers": "^3.828.0",
|
|
56
|
+
"@isomorphic-git/lightning-fs": "^4.6.1",
|
|
57
|
+
"@langchain/anthropic": "^0.3.32",
|
|
58
|
+
"@langchain/core": "^0.3.78",
|
|
59
|
+
"@langchain/openai": "^0.6.16",
|
|
60
|
+
"@types/jsonwebtoken": "^9.0.10",
|
|
61
|
+
"amazon-cognito-identity-js": "^6.3.15",
|
|
62
|
+
"aws-jwt-verify": "^5.1.0",
|
|
63
|
+
"bcryptjs": "^3.0.2",
|
|
64
|
+
"buffer": "^6.0.3",
|
|
65
|
+
"chalk": "~5.3.0",
|
|
66
|
+
"commander": "~11.0.0",
|
|
67
|
+
"express": "^5.1.0",
|
|
68
|
+
"handlebars": "^4.7.8",
|
|
69
|
+
"jsonwebtoken": "^9.0.2",
|
|
70
|
+
"langchain": "^0.3.36",
|
|
71
|
+
"langium": "^3.5.0",
|
|
72
|
+
"openapi-client-axios": "^7.6.0",
|
|
73
|
+
"pg": "^8.16.1",
|
|
74
|
+
"pgvector": "^0.2.1",
|
|
75
|
+
"sql.js": "^1.13.0",
|
|
76
|
+
"sqlite3": "^5.1.7",
|
|
77
|
+
"typeorm": "^0.3.25",
|
|
78
|
+
"vscode-languageserver": "^9.0.1",
|
|
79
|
+
"winston": "^3.17.0",
|
|
80
|
+
"winston-daily-rotate-file": "^5.0.0",
|
|
81
|
+
"zod": "^3.25.55"
|
|
82
|
+
},
|
|
83
|
+
"overrides": {
|
|
84
|
+
"semver": "^7.5.3",
|
|
85
|
+
"trim-newlines": ">=3.0.1"
|
|
86
|
+
},
|
|
87
|
+
"devDependencies": {
|
|
88
|
+
"@codingame/esbuild-import-meta-url-plugin": "~1.0.2",
|
|
89
|
+
"@eslint/js": "^9.26.0",
|
|
90
|
+
"@types/cookie-parser": "^1.4.9",
|
|
91
|
+
"@types/express": "^5.0.1",
|
|
92
|
+
"@types/node": "^18.19.110",
|
|
93
|
+
"@types/sql.js": "^1.4.9",
|
|
94
|
+
"@types/vscode": "^1.100.0",
|
|
95
|
+
"@typescript-eslint/eslint-plugin": "~8.32.1",
|
|
96
|
+
"@typescript-eslint/parser": "~8.32.1",
|
|
97
|
+
"brace-expansion": ">=2.0.2",
|
|
98
|
+
"concurrently": "~8.2.1",
|
|
99
|
+
"esbuild": "^0.25.4",
|
|
100
|
+
"eslint": "~9.26.0",
|
|
101
|
+
"generator-langium": "^3.0.0",
|
|
102
|
+
"http-server": "~14.1.1",
|
|
103
|
+
"langium-cli": "^3.5.0",
|
|
104
|
+
"nodemon": "^3.1.10",
|
|
105
|
+
"prettier": "^3.5.3",
|
|
106
|
+
"typescript": "^5.8.3",
|
|
107
|
+
"typescript-eslint": "^8.32.1",
|
|
108
|
+
"vite": "^6.3.5",
|
|
109
|
+
"vite-plugin-node-polyfills": "^0.24.0",
|
|
110
|
+
"vitest": "^3.1.3",
|
|
111
|
+
"vscode-languageclient": "^9.0.1",
|
|
112
|
+
"vscode-uri": "^3.1.0"
|
|
113
|
+
},
|
|
114
|
+
"volta": {
|
|
115
|
+
"node": ">=20.0.0",
|
|
116
|
+
"npm": ">=10.8.2"
|
|
117
|
+
},
|
|
118
|
+
"displayName": "agentlang",
|
|
119
|
+
"engines": {
|
|
120
|
+
"vscode": "^1.67.0",
|
|
121
|
+
"node": ">=20.0.0"
|
|
122
|
+
},
|
|
123
|
+
"categories": [
|
|
124
|
+
"Programming Languages"
|
|
125
|
+
],
|
|
126
|
+
"contributes": {
|
|
127
|
+
"languages": [
|
|
128
|
+
{
|
|
129
|
+
"id": "agentlang",
|
|
130
|
+
"aliases": [
|
|
131
|
+
"Agentlang",
|
|
132
|
+
"agentlang"
|
|
133
|
+
],
|
|
134
|
+
"extensions": [
|
|
135
|
+
".al"
|
|
136
|
+
],
|
|
137
|
+
"configuration": "./language-configuration.json"
|
|
138
|
+
}
|
|
139
|
+
],
|
|
140
|
+
"grammars": [
|
|
141
|
+
{
|
|
142
|
+
"language": "agentlang",
|
|
143
|
+
"scopeName": "source.agentlang",
|
|
144
|
+
"path": "syntaxes/agentlang.tmLanguage.json"
|
|
145
|
+
}
|
|
146
|
+
]
|
|
147
|
+
},
|
|
148
|
+
"activationEvents": [
|
|
149
|
+
"onLanguage:agentlang"
|
|
150
|
+
],
|
|
151
|
+
"main": "./out/extension/main.cjs",
|
|
152
|
+
"types": "./out/index.d.ts",
|
|
153
|
+
"exports": {
|
|
154
|
+
".": {
|
|
155
|
+
"types": "./out/index.d.ts",
|
|
156
|
+
"import": "./out/extension/main.cjs",
|
|
157
|
+
"require": "./out/extension/main.cjs"
|
|
158
|
+
},
|
|
159
|
+
"./browser": {
|
|
160
|
+
"types": "./out/browser.d.ts",
|
|
161
|
+
"import": "./out/browser.js",
|
|
162
|
+
"default": "./out/browser.js"
|
|
163
|
+
},
|
|
164
|
+
"./src/*": {
|
|
165
|
+
"types": "./out/*.d.ts",
|
|
166
|
+
"import": "./out/*.js",
|
|
167
|
+
"require": "./out/*.js",
|
|
168
|
+
"default": "./out/*.js"
|
|
169
|
+
},
|
|
170
|
+
"./out/*": "./out/*"
|
|
171
|
+
},
|
|
172
|
+
"bin": {
|
|
173
|
+
"agentlang-cli": "./bin/cli.js"
|
|
174
|
+
},
|
|
175
|
+
"lint-staged": {
|
|
176
|
+
"*.{js,ts,tsx}": [
|
|
177
|
+
"eslint --fix --cache",
|
|
178
|
+
"prettier --write"
|
|
179
|
+
],
|
|
180
|
+
"*.{json,md,yml,yaml}": [
|
|
181
|
+
"prettier --write"
|
|
182
|
+
]
|
|
183
|
+
},
|
|
184
|
+
"packageManager": "pnpm@10.13.1+sha512.37ebf1a5c7a30d5fabe0c5df44ee8da4c965ca0c5af3dbab28c3a1681b70a256218d05c81c9c0dcf767ef6b8551eb5b960042b9ed4300c59242336377e01cfad"
|
|
185
|
+
}
|
package/src/api/http.ts
CHANGED
|
@@ -287,7 +287,7 @@ function queryPatternFromPath(path: string, req: Request): string {
|
|
|
287
287
|
let entityName = r[1];
|
|
288
288
|
const id = r[2];
|
|
289
289
|
const parts = r[3];
|
|
290
|
-
if (parts.length == 2 && id
|
|
290
|
+
if (parts.length == 2 && id === undefined) {
|
|
291
291
|
if (req.query && Object.keys(req.query).length > 0) {
|
|
292
292
|
const pat = objectAsAttributesPattern(req.query);
|
|
293
293
|
return `{${moduleName}/${entityName} ${pat}}`;
|
|
@@ -306,7 +306,7 @@ function queryPatternFromPath(path: string, req: Request): string {
|
|
|
306
306
|
return `{${pm}/${pe} {${PathAttributeNameQuery} "${p}"}, ${relName} {${moduleName}/${entityName}? {}}}`;
|
|
307
307
|
}
|
|
308
308
|
entityName = restoreFqName(entityName);
|
|
309
|
-
if (id
|
|
309
|
+
if (id === undefined) {
|
|
310
310
|
return `{${moduleName}/${entityName} {${PathAttributeNameQuery}like "${path}%"}}`;
|
|
311
311
|
} else {
|
|
312
312
|
return `{${moduleName}/${entityName} {${PathAttributeNameQuery} "${path}"}}`;
|
package/src/language/syntax.ts
CHANGED
|
@@ -20,7 +20,7 @@ export class BasePattern {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
addAlias(alias: string) {
|
|
23
|
-
if (this.aliases
|
|
23
|
+
if (this.aliases === undefined) {
|
|
24
24
|
this.aliases = [];
|
|
25
25
|
}
|
|
26
26
|
this.aliases.push(alias);
|
|
@@ -31,7 +31,7 @@ export class BasePattern {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
addHandler(k: 'not_found' | 'error', handler: BasePattern) {
|
|
34
|
-
if (this.handlers
|
|
34
|
+
if (this.handlers === undefined) {
|
|
35
35
|
this.handlers = new Map();
|
|
36
36
|
}
|
|
37
37
|
this.handlers.set(k, handler);
|
|
@@ -150,12 +150,12 @@ export class LiteralPattern extends BasePattern {
|
|
|
150
150
|
const arr = new Array<string>();
|
|
151
151
|
m.forEach((v: BasePattern, key: any) => {
|
|
152
152
|
let k: any = key.str;
|
|
153
|
-
if (k
|
|
153
|
+
if (k === undefined) {
|
|
154
154
|
k = key.num;
|
|
155
155
|
} else {
|
|
156
156
|
k = `"${k}"`;
|
|
157
157
|
}
|
|
158
|
-
if (k
|
|
158
|
+
if (k === undefined) {
|
|
159
159
|
k = key.bool;
|
|
160
160
|
}
|
|
161
161
|
arr.push(`${k}: ${v.toString()}`);
|
|
@@ -407,7 +407,7 @@ export class CrudPattern extends BasePattern {
|
|
|
407
407
|
}
|
|
408
408
|
|
|
409
409
|
addInto(alias: string, attr: string): CrudPattern {
|
|
410
|
-
if (this.into
|
|
410
|
+
if (this.into === undefined) {
|
|
411
411
|
this.into = new Map();
|
|
412
412
|
}
|
|
413
413
|
this.into.set(alias, attr);
|
|
@@ -459,7 +459,7 @@ export class CrudPattern extends BasePattern {
|
|
|
459
459
|
}
|
|
460
460
|
|
|
461
461
|
addRelationship(n: string, p: CrudPattern[] | CrudPattern) {
|
|
462
|
-
if (this.relationships
|
|
462
|
+
if (this.relationships === undefined) {
|
|
463
463
|
this.relationships = new Map();
|
|
464
464
|
}
|
|
465
465
|
this.relationships.set(n, p);
|
|
@@ -483,7 +483,7 @@ export class CrudPattern extends BasePattern {
|
|
|
483
483
|
}
|
|
484
484
|
|
|
485
485
|
private relationshipsAsString(): string | undefined {
|
|
486
|
-
if (this.relationships
|
|
486
|
+
if (this.relationships !== undefined) {
|
|
487
487
|
const result: Array<string> = [];
|
|
488
488
|
this.relationships.forEach((p: CrudPattern | CrudPattern[], n: string) => {
|
|
489
489
|
const ps = p instanceof Array ? `[${patternsToString(p, ',')}]` : p.toString();
|
|
@@ -587,7 +587,7 @@ export class ForEachPattern extends BasePattern {
|
|
|
587
587
|
}
|
|
588
588
|
|
|
589
589
|
override toString(): string {
|
|
590
|
-
if (this.source
|
|
590
|
+
if (this.source === undefined || this.variable === undefined) {
|
|
591
591
|
throw new Error('`for` requires variable and source-pattern');
|
|
592
592
|
}
|
|
593
593
|
let s = `for ${this.variable} in ${this.source.toString()}`;
|
|
@@ -531,7 +531,7 @@ export class CognitoAuth implements AgentlangAuth {
|
|
|
531
531
|
);
|
|
532
532
|
},
|
|
533
533
|
});
|
|
534
|
-
while (result
|
|
534
|
+
while (result === undefined && authError === undefined) {
|
|
535
535
|
await sleepMilliseconds(100);
|
|
536
536
|
}
|
|
537
537
|
if (authError) {
|
|
@@ -624,7 +624,7 @@ export class CognitoAuth implements AgentlangAuth {
|
|
|
624
624
|
);
|
|
625
625
|
},
|
|
626
626
|
});
|
|
627
|
-
while (result
|
|
627
|
+
while (result === undefined && authError === undefined) {
|
|
628
628
|
await sleepMilliseconds(100);
|
|
629
629
|
}
|
|
630
630
|
if (authError) {
|
|
@@ -1165,4 +1165,109 @@ export class CognitoAuth implements AgentlangAuth {
|
|
|
1165
1165
|
handleCognitoError(err, 'acceptInvitation');
|
|
1166
1166
|
}
|
|
1167
1167
|
}
|
|
1168
|
+
|
|
1169
|
+
async callback(code: string, env: Environment, cb: LoginCallback): Promise<void> {
|
|
1170
|
+
try {
|
|
1171
|
+
if (!isNodeEnv) {
|
|
1172
|
+
throw new Error('Callback authentication is only supported in Node.js environment');
|
|
1173
|
+
}
|
|
1174
|
+
|
|
1175
|
+
const clientId = this.fetchConfig('ClientId');
|
|
1176
|
+
const region = process.env.AWS_REGION || 'us-east-1';
|
|
1177
|
+
const redirectUri = process.env.COGNITO_REDIRECT_URI || 'http://localhost:3000/auth/callback';
|
|
1178
|
+
const hostedDomain = process.env.COGNITO_HOSTED_DOMAIN;
|
|
1179
|
+
const tokenEndpoint = `https://${hostedDomain}.auth.${region}.amazoncognito.com/oauth2/token`;
|
|
1180
|
+
|
|
1181
|
+
const tokenRequestBody = new URLSearchParams({
|
|
1182
|
+
grant_type: 'authorization_code',
|
|
1183
|
+
client_id: clientId,
|
|
1184
|
+
code: code,
|
|
1185
|
+
redirect_uri: redirectUri,
|
|
1186
|
+
});
|
|
1187
|
+
|
|
1188
|
+
logger.debug(`Exchanging authorization code for tokens via OAuth2 endpoint`);
|
|
1189
|
+
|
|
1190
|
+
console.log('te', tokenEndpoint, tokenRequestBody.toString());
|
|
1191
|
+
const response = await fetch(tokenEndpoint, {
|
|
1192
|
+
method: 'POST',
|
|
1193
|
+
headers: {
|
|
1194
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
1195
|
+
},
|
|
1196
|
+
body: tokenRequestBody.toString(),
|
|
1197
|
+
});
|
|
1198
|
+
|
|
1199
|
+
if (!response.ok) {
|
|
1200
|
+
const errorText = await response.text();
|
|
1201
|
+
throw new Error(`Token exchange failed: ${response.status} ${errorText}`);
|
|
1202
|
+
}
|
|
1203
|
+
|
|
1204
|
+
const tokenData = await response.json();
|
|
1205
|
+
|
|
1206
|
+
if (!tokenData.access_token || !tokenData.id_token || !tokenData.refresh_token) {
|
|
1207
|
+
throw new Error('Missing required tokens in response');
|
|
1208
|
+
}
|
|
1209
|
+
|
|
1210
|
+
const {
|
|
1211
|
+
access_token: AccessToken,
|
|
1212
|
+
id_token: IdToken,
|
|
1213
|
+
refresh_token: RefreshToken,
|
|
1214
|
+
} = tokenData;
|
|
1215
|
+
|
|
1216
|
+
const idTokenPayload = this.decodeJwtPayload(IdToken);
|
|
1217
|
+
const userEmail = idTokenPayload.email;
|
|
1218
|
+
const firstName = idTokenPayload['given_name'] || idTokenPayload['name'] || '';
|
|
1219
|
+
const lastName = idTokenPayload['family_name'] || '';
|
|
1220
|
+
const userGroups = idTokenPayload['cognito:groups'];
|
|
1221
|
+
|
|
1222
|
+
if (!userEmail) {
|
|
1223
|
+
throw new Error('Email not found in ID attributes');
|
|
1224
|
+
}
|
|
1225
|
+
|
|
1226
|
+
let localUser = await findUserByEmail(userEmail, env);
|
|
1227
|
+
if (!localUser) {
|
|
1228
|
+
localUser = await ensureUser(userEmail, firstName, lastName, env);
|
|
1229
|
+
}
|
|
1230
|
+
const userId = localUser.lookup('id');
|
|
1231
|
+
|
|
1232
|
+
if (userGroups) {
|
|
1233
|
+
await ensureUserRoles(userId, userGroups, env);
|
|
1234
|
+
}
|
|
1235
|
+
|
|
1236
|
+
const localSession = await ensureUserSession(userId, IdToken, AccessToken, RefreshToken, env);
|
|
1237
|
+
|
|
1238
|
+
const sessionInfo: SessionInfo = {
|
|
1239
|
+
sessionId: localSession.lookup('id'),
|
|
1240
|
+
userId: userId,
|
|
1241
|
+
authToken: IdToken,
|
|
1242
|
+
idToken: IdToken,
|
|
1243
|
+
accessToken: AccessToken,
|
|
1244
|
+
refreshToken: RefreshToken,
|
|
1245
|
+
systemSesionInfo: tokenData,
|
|
1246
|
+
};
|
|
1247
|
+
|
|
1248
|
+
logger.info(`Auth callback successful for user ${userEmail}`);
|
|
1249
|
+
cb(sessionInfo);
|
|
1250
|
+
} catch (err: any) {
|
|
1251
|
+
console.log(err);
|
|
1252
|
+
logger.error(`Auth callback failed: ${sanitizeErrorMessage(err.message)}`);
|
|
1253
|
+
handleCognitoError(err, 'callback');
|
|
1254
|
+
}
|
|
1255
|
+
}
|
|
1256
|
+
|
|
1257
|
+
private decodeJwtPayload(token: string): any {
|
|
1258
|
+
try {
|
|
1259
|
+
const base64Url = token.split('.')[1];
|
|
1260
|
+
const base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');
|
|
1261
|
+
const jsonPayload = decodeURIComponent(
|
|
1262
|
+
atob(base64)
|
|
1263
|
+
.split('')
|
|
1264
|
+
.map(c => '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2))
|
|
1265
|
+
.join('')
|
|
1266
|
+
);
|
|
1267
|
+
return JSON.parse(jsonPayload);
|
|
1268
|
+
} catch (err) {
|
|
1269
|
+
logger.error(`Failed to decode JWT payload: ${err}`);
|
|
1270
|
+
throw new Error('Invalid JWT token');
|
|
1271
|
+
}
|
|
1272
|
+
}
|
|
1168
1273
|
}
|