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.
Files changed (240) hide show
  1. package/LICENSE +83 -0
  2. package/README.md +120 -0
  3. package/bin/cli.js +4 -0
  4. package/out/api/http.d.ts +3 -0
  5. package/out/api/http.d.ts.map +1 -0
  6. package/out/api/http.js +290 -0
  7. package/out/api/http.js.map +1 -0
  8. package/out/cli/cli-util.d.ts +7 -0
  9. package/out/cli/cli-util.d.ts.map +1 -0
  10. package/out/cli/cli-util.js +9 -0
  11. package/out/cli/cli-util.js.map +1 -0
  12. package/out/cli/docs.d.ts +2 -0
  13. package/out/cli/docs.d.ts.map +1 -0
  14. package/out/cli/docs.js +236 -0
  15. package/out/cli/docs.js.map +1 -0
  16. package/out/cli/main.d.ts +288 -0
  17. package/out/cli/main.d.ts.map +1 -0
  18. package/out/cli/main.js +119 -0
  19. package/out/cli/main.js.map +1 -0
  20. package/out/cli/openapi-docs.yml +695 -0
  21. package/out/extension/main.cjs +18093 -0
  22. package/out/extension/main.cjs.map +7 -0
  23. package/out/extension/main.d.ts +4 -0
  24. package/out/extension/main.d.ts.map +1 -0
  25. package/out/extension/main.js +42 -0
  26. package/out/extension/main.js.map +1 -0
  27. package/out/language/agentlang-module.d.ts +42 -0
  28. package/out/language/agentlang-module.d.ts.map +1 -0
  29. package/out/language/agentlang-module.js +42 -0
  30. package/out/language/agentlang-module.js.map +1 -0
  31. package/out/language/agentlang-validator.d.ts +15 -0
  32. package/out/language/agentlang-validator.d.ts.map +1 -0
  33. package/out/language/agentlang-validator.js +50 -0
  34. package/out/language/agentlang-validator.js.map +1 -0
  35. package/out/language/generated/ast.d.ts +491 -0
  36. package/out/language/generated/ast.d.ts.map +1 -0
  37. package/out/language/generated/ast.js +934 -0
  38. package/out/language/generated/ast.js.map +1 -0
  39. package/out/language/generated/grammar.d.ts +7 -0
  40. package/out/language/generated/grammar.d.ts.map +1 -0
  41. package/out/language/generated/grammar.js +4475 -0
  42. package/out/language/generated/grammar.js.map +1 -0
  43. package/out/language/generated/module.d.ts +14 -0
  44. package/out/language/generated/module.d.ts.map +1 -0
  45. package/out/language/generated/module.js +21 -0
  46. package/out/language/generated/module.js.map +1 -0
  47. package/out/language/main-browser.d.ts +2 -0
  48. package/out/language/main-browser.d.ts.map +1 -0
  49. package/out/language/main-browser.js +10 -0
  50. package/out/language/main-browser.js.map +1 -0
  51. package/out/language/main.cjs +36229 -0
  52. package/out/language/main.cjs.map +7 -0
  53. package/out/language/main.d.ts +2 -0
  54. package/out/language/main.d.ts.map +1 -0
  55. package/out/language/main.js +11 -0
  56. package/out/language/main.js.map +1 -0
  57. package/out/language/parser.d.ts +9 -0
  58. package/out/language/parser.d.ts.map +1 -0
  59. package/out/language/parser.js +273 -0
  60. package/out/language/parser.js.map +1 -0
  61. package/out/language/syntax.d.ts +155 -0
  62. package/out/language/syntax.d.ts.map +1 -0
  63. package/out/language/syntax.js +527 -0
  64. package/out/language/syntax.js.map +1 -0
  65. package/out/runtime/agents/common.d.ts +2 -0
  66. package/out/runtime/agents/common.d.ts.map +1 -0
  67. package/out/runtime/agents/common.js +178 -0
  68. package/out/runtime/agents/common.js.map +1 -0
  69. package/out/runtime/agents/impl/openai.d.ts +8 -0
  70. package/out/runtime/agents/impl/openai.d.ts.map +1 -0
  71. package/out/runtime/agents/impl/openai.js +15 -0
  72. package/out/runtime/agents/impl/openai.js.map +1 -0
  73. package/out/runtime/agents/provider.d.ts +21 -0
  74. package/out/runtime/agents/provider.d.ts.map +1 -0
  75. package/out/runtime/agents/provider.js +32 -0
  76. package/out/runtime/agents/provider.js.map +1 -0
  77. package/out/runtime/agents/registry.d.ts +2 -0
  78. package/out/runtime/agents/registry.d.ts.map +1 -0
  79. package/out/runtime/agents/registry.js +10 -0
  80. package/out/runtime/agents/registry.js.map +1 -0
  81. package/out/runtime/auth/cognito.d.ts +16 -0
  82. package/out/runtime/auth/cognito.d.ts.map +1 -0
  83. package/out/runtime/auth/cognito.js +186 -0
  84. package/out/runtime/auth/cognito.js.map +1 -0
  85. package/out/runtime/auth/defs.d.ts +11 -0
  86. package/out/runtime/auth/defs.d.ts.map +1 -0
  87. package/out/runtime/auth/defs.js +24 -0
  88. package/out/runtime/auth/defs.js.map +1 -0
  89. package/out/runtime/auth/interface.d.ts +22 -0
  90. package/out/runtime/auth/interface.d.ts.map +1 -0
  91. package/out/runtime/auth/interface.js +2 -0
  92. package/out/runtime/auth/interface.js.map +1 -0
  93. package/out/runtime/defs.js +24 -0
  94. package/out/runtime/defs.js.map +1 -0
  95. package/out/runtime/interpreter.d.ts +69 -0
  96. package/out/runtime/interpreter.d.ts.map +1 -0
  97. package/out/runtime/interpreter.js +1163 -0
  98. package/out/runtime/interpreter.js.map +1 -0
  99. package/out/runtime/loader.d.ts +25 -0
  100. package/out/runtime/loader.d.ts.map +1 -0
  101. package/out/runtime/loader.js +346 -0
  102. package/out/runtime/loader.js.map +1 -0
  103. package/out/runtime/logger.d.ts +2 -0
  104. package/out/runtime/logger.d.ts.map +1 -0
  105. package/out/runtime/logger.js +44 -0
  106. package/out/runtime/logger.js.map +1 -0
  107. package/out/runtime/module.d.ts +273 -0
  108. package/out/runtime/module.d.ts.map +1 -0
  109. package/out/runtime/module.js +1786 -0
  110. package/out/runtime/module.js.map +1 -0
  111. package/out/runtime/modules/ai.d.ts +26 -0
  112. package/out/runtime/modules/ai.d.ts.map +1 -0
  113. package/out/runtime/modules/ai.js +211 -0
  114. package/out/runtime/modules/ai.js.map +1 -0
  115. package/out/runtime/modules/auth.d.ts +39 -0
  116. package/out/runtime/modules/auth.d.ts.map +1 -0
  117. package/out/runtime/modules/auth.js +359 -0
  118. package/out/runtime/modules/auth.js.map +1 -0
  119. package/out/runtime/modules/core.d.ts +2 -0
  120. package/out/runtime/modules/core.d.ts.map +1 -0
  121. package/out/runtime/modules/core.js +67 -0
  122. package/out/runtime/modules/core.js.map +1 -0
  123. package/out/runtime/relgraph.d.ts +21 -0
  124. package/out/runtime/relgraph.d.ts.map +1 -0
  125. package/out/runtime/relgraph.js +156 -0
  126. package/out/runtime/relgraph.js.map +1 -0
  127. package/out/runtime/resolvers/interface.d.ts +59 -0
  128. package/out/runtime/resolvers/interface.d.ts.map +1 -0
  129. package/out/runtime/resolvers/interface.js +111 -0
  130. package/out/runtime/resolvers/interface.js.map +1 -0
  131. package/out/runtime/resolvers/registry.d.ts +8 -0
  132. package/out/runtime/resolvers/registry.d.ts.map +1 -0
  133. package/out/runtime/resolvers/registry.js +26 -0
  134. package/out/runtime/resolvers/registry.js.map +1 -0
  135. package/out/runtime/resolvers/sqldb/database.d.ts +50 -0
  136. package/out/runtime/resolvers/sqldb/database.d.ts.map +1 -0
  137. package/out/runtime/resolvers/sqldb/database.js +618 -0
  138. package/out/runtime/resolvers/sqldb/database.js.map +1 -0
  139. package/out/runtime/resolvers/sqldb/dbutil.d.ts +18 -0
  140. package/out/runtime/resolvers/sqldb/dbutil.d.ts.map +1 -0
  141. package/out/runtime/resolvers/sqldb/dbutil.js +221 -0
  142. package/out/runtime/resolvers/sqldb/dbutil.js.map +1 -0
  143. package/out/runtime/resolvers/sqldb/impl.d.ts +26 -0
  144. package/out/runtime/resolvers/sqldb/impl.d.ts.map +1 -0
  145. package/out/runtime/resolvers/sqldb/impl.js +300 -0
  146. package/out/runtime/resolvers/sqldb/impl.js.map +1 -0
  147. package/out/runtime/state.js +83 -0
  148. package/out/runtime/state.js.map +1 -0
  149. package/out/runtime/util.d.ts +43 -0
  150. package/out/runtime/util.d.ts.map +1 -0
  151. package/out/runtime/util.js +447 -0
  152. package/out/runtime/util.js.map +1 -0
  153. package/out/setupClassic.d.ts +98 -0
  154. package/out/setupClassic.d.ts.map +1 -0
  155. package/out/setupClassic.js +38 -0
  156. package/out/setupClassic.js.map +1 -0
  157. package/out/setupCommon.d.ts +2 -0
  158. package/out/setupCommon.d.ts.map +1 -0
  159. package/out/setupCommon.js +33 -0
  160. package/out/setupCommon.js.map +1 -0
  161. package/out/setupExtended.d.ts +40 -0
  162. package/out/setupExtended.d.ts.map +1 -0
  163. package/out/setupExtended.js +67 -0
  164. package/out/setupExtended.js.map +1 -0
  165. package/out/syntaxes/agentlang.monarch.d.ts +77 -0
  166. package/out/syntaxes/agentlang.monarch.d.ts.map +1 -0
  167. package/out/syntaxes/agentlang.monarch.js +31 -0
  168. package/out/syntaxes/agentlang.monarch.js.map +1 -0
  169. package/out/utils/fs/index.d.ts +14 -0
  170. package/out/utils/fs/index.d.ts.map +1 -0
  171. package/out/utils/fs/index.js +26 -0
  172. package/out/utils/fs/index.js.map +1 -0
  173. package/out/utils/fs/interfaces.d.ts +105 -0
  174. package/out/utils/fs/interfaces.d.ts.map +1 -0
  175. package/out/utils/fs/interfaces.js +5 -0
  176. package/out/utils/fs/interfaces.js.map +1 -0
  177. package/out/utils/fs/lightning-fs.d.ts +116 -0
  178. package/out/utils/fs/lightning-fs.d.ts.map +1 -0
  179. package/out/utils/fs/lightning-fs.js +243 -0
  180. package/out/utils/fs/lightning-fs.js.map +1 -0
  181. package/out/utils/fs/node-fs.d.ts +93 -0
  182. package/out/utils/fs/node-fs.d.ts.map +1 -0
  183. package/out/utils/fs/node-fs.js +169 -0
  184. package/out/utils/fs/node-fs.js.map +1 -0
  185. package/out/utils/fs-utils.d.ts +153 -0
  186. package/out/utils/fs-utils.d.ts.map +1 -0
  187. package/out/utils/fs-utils.js +271 -0
  188. package/out/utils/fs-utils.js.map +1 -0
  189. package/out/utils/runtime.d.ts +36 -0
  190. package/out/utils/runtime.d.ts.map +1 -0
  191. package/out/utils/runtime.js +39 -0
  192. package/out/utils/runtime.js.map +1 -0
  193. package/package.json +155 -0
  194. package/src/api/http.ts +361 -0
  195. package/src/cli/cli-util.ts +18 -0
  196. package/src/cli/main.ts +146 -0
  197. package/src/extension/main.ts +51 -0
  198. package/src/language/agentlang-module.ts +75 -0
  199. package/src/language/agentlang-validator.ts +60 -0
  200. package/src/language/agentlang.langium +178 -0
  201. package/src/language/generated/ast.ts +1698 -0
  202. package/src/language/generated/grammar.ts +4477 -0
  203. package/src/language/generated/module.ts +25 -0
  204. package/src/language/main-browser.ts +19 -0
  205. package/src/language/main.ts +13 -0
  206. package/src/language/parser.ts +329 -0
  207. package/src/language/syntax.ts +646 -0
  208. package/src/runtime/agents/common.ts +177 -0
  209. package/src/runtime/agents/impl/openai.ts +19 -0
  210. package/src/runtime/agents/provider.ts +58 -0
  211. package/src/runtime/agents/registry.ts +9 -0
  212. package/src/runtime/auth/cognito.ts +225 -0
  213. package/src/runtime/auth/defs.ts +33 -0
  214. package/src/runtime/auth/interface.ts +31 -0
  215. package/src/runtime/defs.ts +33 -0
  216. package/src/runtime/interpreter.ts +1352 -0
  217. package/src/runtime/loader.ts +450 -0
  218. package/src/runtime/logger.ts +51 -0
  219. package/src/runtime/module.ts +2188 -0
  220. package/src/runtime/modules/ai.ts +257 -0
  221. package/src/runtime/modules/auth.ts +489 -0
  222. package/src/runtime/modules/core.ts +95 -0
  223. package/src/runtime/relgraph.ts +195 -0
  224. package/src/runtime/resolvers/interface.ts +160 -0
  225. package/src/runtime/resolvers/registry.ts +30 -0
  226. package/src/runtime/resolvers/sqldb/database.ts +823 -0
  227. package/src/runtime/resolvers/sqldb/dbutil.ts +257 -0
  228. package/src/runtime/resolvers/sqldb/impl.ts +471 -0
  229. package/src/runtime/state.ts +87 -0
  230. package/src/runtime/util.ts +513 -0
  231. package/src/setupClassic.ts +43 -0
  232. package/src/setupCommon.ts +33 -0
  233. package/src/setupExtended.ts +79 -0
  234. package/src/syntaxes/agentlang.monarch.ts +31 -0
  235. package/src/utils/fs/index.ts +28 -0
  236. package/src/utils/fs/interfaces.ts +118 -0
  237. package/src/utils/fs/lightning-fs.ts +284 -0
  238. package/src/utils/fs/node-fs.ts +185 -0
  239. package/src/utils/fs-utils.ts +304 -0
  240. package/src/utils/runtime.ts +43 -0
@@ -0,0 +1,513 @@
1
+ import { isNodeEnv } from '../utils/runtime.js';
2
+ import {
3
+ AliasSpec,
4
+ CatchSpec,
5
+ ExtendsClause,
6
+ MetaDefinition,
7
+ PrePostTriggerDefinition,
8
+ RbacSpecDefinition,
9
+ RecordExtraDefinition,
10
+ RecordSchemaDefinition,
11
+ Statement,
12
+ } from '../language/generated/ast.js';
13
+ import { readFile } from '../utils/fs-utils.js';
14
+ import { logger } from './logger.js';
15
+
16
+ export const QuerySuffix = '?';
17
+
18
+ // Conditionally import Node.js specific modules
19
+ let exec: any = undefined;
20
+ let promisify: any = undefined;
21
+ if (isNodeEnv) {
22
+ // Dynamic import for node:child_process to avoid browser compatibility issues
23
+ const childProcess = await import('node:child_process');
24
+ exec = childProcess.exec;
25
+
26
+ const nu = await import('node:util');
27
+ promisify = nu.promisify;
28
+ }
29
+
30
+ const importedModules = new Map<string, any>();
31
+
32
+ // Usage: importModule("./mymodels/acme.js")
33
+ export async function importModule(path: string, name: string) {
34
+ const m = await import(/* @vite-ignore */ path);
35
+ importedModules.set(name, m);
36
+ // e.g of dynamic fn-call:
37
+ //// let f = eval("(a, b) => m.add(a, b)");
38
+ //// console.log(f(10, 20))
39
+ return m;
40
+ }
41
+
42
+ export function moduleImported(moduleName: string): boolean {
43
+ return importedModules.has(moduleName);
44
+ }
45
+
46
+ function maybeEvalFunction(fnName: string): Function | undefined {
47
+ try {
48
+ return eval(fnName);
49
+ } catch (reason: any) {
50
+ logger.debug(reason);
51
+ return undefined;
52
+ }
53
+ }
54
+
55
+ export async function invokeModuleFn(
56
+ fqFnName: string,
57
+ args: Array<any> | null,
58
+ isAsync: boolean = false
59
+ ): Promise<any> {
60
+ try {
61
+ const refs: string[] = splitRefs(fqFnName);
62
+ const m = importedModules.get(refs[0]);
63
+ if (m != undefined) {
64
+ const f = m[refs[1]];
65
+ if (f != undefined) {
66
+ if (args == null)
67
+ if (isAsync) {
68
+ return await f();
69
+ } else return f();
70
+ else if (isAsync) {
71
+ return await f(...args);
72
+ } else return f(...args);
73
+ } else throw new Error(`Function not found - ${fqFnName}`);
74
+ } else throw new Error(`JavaScript module ${refs[0]} not found`);
75
+ } catch (reason: any) {
76
+ const pf: Function | undefined = maybeEvalFunction(fqFnName);
77
+ if (pf instanceof Function) {
78
+ if (args == null) {
79
+ if (isAsync) return await pf();
80
+ else return pf();
81
+ } else {
82
+ if (isAsync) return await pf(...args.slice(0, args.length - 1));
83
+ else return pf(...args.slice(0, args.length - 1));
84
+ }
85
+ } else {
86
+ throw new Error(reason);
87
+ }
88
+ }
89
+ }
90
+
91
+ export function isNumber(x: any): boolean {
92
+ return typeof x === 'number';
93
+ }
94
+
95
+ export function isMinusZero(value: number): boolean {
96
+ return 1 / value === -Infinity;
97
+ }
98
+
99
+ export function isBoolean(x: any): boolean {
100
+ return typeof x === 'boolean';
101
+ }
102
+
103
+ type MaybeString = string | undefined;
104
+
105
+ export function isString(s: MaybeString): boolean {
106
+ return s != undefined && typeof s === 'string';
107
+ }
108
+
109
+ function asString(s: MaybeString): string {
110
+ if (s == undefined) return '';
111
+ else return s;
112
+ }
113
+
114
+ export class Path {
115
+ private moduleName: MaybeString;
116
+ private entryName: MaybeString;
117
+
118
+ constructor(moduleName: MaybeString, entryName: MaybeString) {
119
+ this.moduleName = moduleName;
120
+ this.entryName = entryName;
121
+ }
122
+
123
+ hasModule(): boolean {
124
+ return isString(this.moduleName);
125
+ }
126
+
127
+ hasEntry(): boolean {
128
+ return isString(this.entryName);
129
+ }
130
+
131
+ setModuleName(n: string): Path {
132
+ this.moduleName = n;
133
+ return this;
134
+ }
135
+
136
+ getModuleName(): string {
137
+ return asString(this.moduleName);
138
+ }
139
+
140
+ setEntryname(n: string): Path {
141
+ this.entryName = n;
142
+ return this;
143
+ }
144
+
145
+ getEntryName(): string {
146
+ return asString(this.entryName);
147
+ }
148
+
149
+ asFqName(): string {
150
+ return makeFqName(this.moduleName || '?', this.entryName || '?');
151
+ }
152
+
153
+ equals(p: Path): boolean {
154
+ return this.moduleName == p.moduleName && this.entryName == p.entryName;
155
+ }
156
+ }
157
+
158
+ export function newPath(): Path {
159
+ return new Path(undefined, undefined);
160
+ }
161
+
162
+ export function makeFqName(moduleName: string, entryName: string): string {
163
+ return moduleName + '/' + entryName;
164
+ }
165
+
166
+ export function forceAsFqName(entryName: string, moduleName: string): string {
167
+ if (entryName.indexOf('$') > 0) {
168
+ return restoreFqName(entryName);
169
+ }
170
+ if (isFqName(entryName)) {
171
+ return entryName;
172
+ }
173
+ return makeFqName(moduleName, entryName);
174
+ }
175
+
176
+ export function forceAsEscapedName(entryName: string, moduleName: string): string {
177
+ if (entryName.indexOf('$') > 0) {
178
+ return entryName;
179
+ }
180
+ if (isFqName(entryName)) {
181
+ return escapeFqName(entryName);
182
+ }
183
+ return `${moduleName}$${entryName}`;
184
+ }
185
+
186
+ export function isFqName(s: string): boolean {
187
+ return s.indexOf('/') > 0;
188
+ }
189
+
190
+ export function splitFqName(s: string): Path {
191
+ if (s.indexOf('/') > 0) {
192
+ const parts: string[] = s.split('/');
193
+ return new Path(parts[0], parts[1]);
194
+ }
195
+ return new Path(undefined, s);
196
+ }
197
+
198
+ export function splitRefs(s: string): string[] {
199
+ if (s.indexOf('.') > 0) {
200
+ return s.split('.');
201
+ } else {
202
+ return [s];
203
+ }
204
+ }
205
+
206
+ export function runShellCommand(cmd: string, options?: any, continuation?: Function) {
207
+ if (!isNodeEnv) {
208
+ console.warn('Shell commands cannot be executed in non-Node.js environments');
209
+ // Call continuation to allow the program flow to continue
210
+ if (continuation) continuation();
211
+ return;
212
+ }
213
+
214
+ if (!exec) {
215
+ console.error('Node.js child_process not available');
216
+ if (continuation) continuation();
217
+ return;
218
+ }
219
+
220
+ exec(cmd, options, (err: any, stdout: string, stderr: string) => {
221
+ if (err) {
222
+ throw new Error(`Failed to execute ${cmd} - ${err.message}`);
223
+ }
224
+ if (stdout.length > 0) {
225
+ console.log(stdout);
226
+ if (continuation) continuation();
227
+ }
228
+ if (stderr.length > 0) console.log(stderr);
229
+ });
230
+ }
231
+
232
+ export function escapeFqName(n: string, moduleName?: string): string {
233
+ if (moduleName) {
234
+ if (n.indexOf('/') < 0) {
235
+ return `${moduleName}$${n}`;
236
+ }
237
+ }
238
+ return n.replace('/', '$');
239
+ }
240
+
241
+ export function restoreFqName(n: string): string {
242
+ return n.replace('$', '/');
243
+ }
244
+
245
+ export function arrayEquals(a: Array<any>, b: Array<any>) {
246
+ if (a.length !== b.length) return false;
247
+ else {
248
+ // Comparing each element of your array
249
+ for (let i = 0; i < a.length; i++) {
250
+ if (a[i] !== b[i]) {
251
+ return false;
252
+ }
253
+ }
254
+ return true;
255
+ }
256
+ }
257
+
258
+ export const DefaultModuleName = 'agentlang';
259
+
260
+ export function makeCoreModuleName(n: string): string {
261
+ return DefaultModuleName + '_' + n;
262
+ }
263
+
264
+ const InitFunctions: Function[] = [];
265
+
266
+ export function registerInitFunction(f: Function) {
267
+ InitFunctions.push(f);
268
+ }
269
+
270
+ export async function runInitFunctions() {
271
+ for (let i = 0; i < InitFunctions.length; ++i) {
272
+ await InitFunctions[i]();
273
+ }
274
+ InitFunctions.splice(0, InitFunctions.length);
275
+ }
276
+
277
+ export function maybeExtends(ext: ExtendsClause | undefined): string | undefined {
278
+ return ext ? ext.parentName : undefined;
279
+ }
280
+
281
+ export function escapeQueryName(s: string): string {
282
+ if (s.endsWith('?')) {
283
+ return s.substring(0, s.length - 1);
284
+ } else {
285
+ return s;
286
+ }
287
+ }
288
+
289
+ export function joinStatements(stmts: string[]): string {
290
+ return stmts
291
+ .filter((s: string) => {
292
+ return s.trim().length > 0;
293
+ })
294
+ .join(';\n');
295
+ }
296
+
297
+ export const sleepMilliseconds = isNodeEnv
298
+ ? promisify(setTimeout)
299
+ : (m: any) => new Promise(r => setTimeout(r, m));
300
+
301
+ export function now(): string {
302
+ return new Date().toISOString();
303
+ }
304
+
305
+ export async function slurpJsonFile(fileName: string): Promise<any> {
306
+ const s = await readFile(fileName);
307
+ return JSON.parse(s);
308
+ }
309
+
310
+ const enum ExtraType {
311
+ META,
312
+ RBAC,
313
+ PRE_POST_TRIGGER,
314
+ }
315
+
316
+ function findExtraSchema(
317
+ type: ExtraType,
318
+ scm: RecordSchemaDefinition | undefined
319
+ ): RecordExtraDefinition | undefined {
320
+ if (scm && scm.extras) {
321
+ return scm.extras.find((ex: RecordExtraDefinition) => {
322
+ switch (type) {
323
+ case ExtraType.META:
324
+ return ex.meta ? true : false;
325
+ case ExtraType.RBAC:
326
+ return ex.rbacSpec ? true : false;
327
+ case ExtraType.PRE_POST_TRIGGER:
328
+ return ex.prePost ? true : false;
329
+ }
330
+ });
331
+ } else {
332
+ return undefined;
333
+ }
334
+ }
335
+
336
+ export function findMetaSchema(
337
+ scm: RecordSchemaDefinition | undefined
338
+ ): MetaDefinition | undefined {
339
+ const ex = findExtraSchema(ExtraType.META, scm);
340
+ if (ex) {
341
+ return ex.meta;
342
+ }
343
+ return undefined;
344
+ }
345
+
346
+ export function findRbacSchema(
347
+ scm: RecordSchemaDefinition | undefined
348
+ ): RbacSpecDefinition | undefined {
349
+ const ex = findExtraSchema(ExtraType.RBAC, scm);
350
+ if (ex) {
351
+ return ex.rbacSpec;
352
+ }
353
+ return undefined;
354
+ }
355
+
356
+ export function findUqCompositeAttributes(
357
+ scm: RecordSchemaDefinition | undefined
358
+ ): Array<string> | undefined {
359
+ if (scm && scm.extras) {
360
+ const uqs = scm.extras.filter((ex: RecordExtraDefinition) => {
361
+ return ex.uq ? true : false;
362
+ });
363
+ if (uqs && uqs.length > 0) {
364
+ if (uqs.length == 1 && uqs[0].uq) {
365
+ return uqs[0].uq.attrs;
366
+ } else {
367
+ let attrs = new Array<string>();
368
+ uqs.forEach((uq: RecordExtraDefinition) => {
369
+ if (uq.uq) {
370
+ attrs = attrs.concat(uq.uq.attrs);
371
+ }
372
+ });
373
+ return attrs;
374
+ }
375
+ }
376
+ }
377
+ return undefined;
378
+ }
379
+
380
+ export function findAllPrePostTriggerSchema(
381
+ scm: RecordSchemaDefinition | undefined
382
+ ): PrePostTriggerDefinition[] | undefined {
383
+ if (scm && scm.extras) {
384
+ let result: PrePostTriggerDefinition[] | undefined;
385
+ for (let i = 0; i < scm.extras.length; ++i) {
386
+ const rex: RecordExtraDefinition = scm.extras[i];
387
+ if (rex.prePost) {
388
+ if (result == undefined) {
389
+ result = new Array<PrePostTriggerDefinition>();
390
+ }
391
+ result.push(rex.prePost);
392
+ }
393
+ }
394
+ return result;
395
+ }
396
+ return undefined;
397
+ }
398
+
399
+ export enum CrudType {
400
+ CREATE,
401
+ UPDATE,
402
+ DELETE,
403
+ READ,
404
+ UPSERT,
405
+ }
406
+
407
+ export function asCrudType(s: string): CrudType {
408
+ const r: CrudType | undefined = CrudType[s.toUpperCase() as keyof typeof CrudType];
409
+ if (r == undefined) {
410
+ throw new Error(`${s} does not represent a valid CrudType`);
411
+ }
412
+ return r;
413
+ }
414
+
415
+ export function isPath(obj: any, ref?: string): boolean {
416
+ if (isString(obj)) {
417
+ const s = obj as string;
418
+ const r = s.indexOf('/') > 0;
419
+ if (r && ref) {
420
+ return s.indexOf(ref) >= 0;
421
+ }
422
+ return r;
423
+ } else {
424
+ return false;
425
+ }
426
+ }
427
+
428
+ export function fqNameFromPath(path: string): string | undefined {
429
+ const parts = path.split('/');
430
+ const len = parts.length;
431
+ if (len > 1) {
432
+ const n = restoreFqName(parts[len - 2]);
433
+ if (n.indexOf('/') > 0) {
434
+ return n;
435
+ }
436
+ }
437
+ return undefined;
438
+ }
439
+
440
+ export function firstAliasSpec(stmt: Statement): AliasSpec | undefined {
441
+ if (stmt.hints) {
442
+ for (let i = 0; i < stmt.hints.length; ++i) {
443
+ const rh = stmt.hints[i];
444
+ if (rh.aliasSpec) {
445
+ return rh.aliasSpec;
446
+ }
447
+ }
448
+ }
449
+ return undefined;
450
+ }
451
+
452
+ export function firstCatchSpec(stmt: Statement): CatchSpec | undefined {
453
+ if (stmt.hints) {
454
+ for (let i = 0; i < stmt.hints.length; ++i) {
455
+ const rh = stmt.hints[i];
456
+ if (rh.catchSpec) {
457
+ return rh.catchSpec;
458
+ }
459
+ }
460
+ }
461
+ return undefined;
462
+ }
463
+
464
+ function maybeExtractEntryName(n: string): string {
465
+ const i = n.indexOf('$');
466
+ if (i > 0) {
467
+ return n.substring(i + 1);
468
+ }
469
+ return n;
470
+ }
471
+
472
+ function maybeExtractModuleName(n: string, moduleName?: string | undefined): string {
473
+ const i = n.indexOf('$');
474
+ if (i > 0) {
475
+ return n.substring(0, i);
476
+ }
477
+ if (moduleName == undefined) {
478
+ throw new Error(`Failed to extract module-name from ${n}`);
479
+ }
480
+ return moduleName;
481
+ }
482
+
483
+ export function walkDownInstancePath(path: string): [string, string, string | undefined, string[]] {
484
+ const parts = path.split('/').filter((n: string) => {
485
+ return n.length > 0;
486
+ });
487
+ const nameParts = parts[0].split('$');
488
+ const hasParts = nameParts.length == 2;
489
+ let moduleName = hasParts ? nameParts[0] : parts[0];
490
+ let entryName = hasParts ? nameParts[1] : parts[1];
491
+ if (!hasParts && parts.length == 2) {
492
+ return [moduleName, entryName, undefined, parts];
493
+ }
494
+ if (parts.length > 1) {
495
+ let id: string | undefined = parts[1];
496
+ if (parts.length > 2) {
497
+ for (let i = 2; i < parts.length; ++i) {
498
+ const relName = parts[i];
499
+ moduleName = maybeExtractModuleName(relName, moduleName);
500
+ entryName = parts[++i];
501
+ moduleName = maybeExtractModuleName(entryName, moduleName);
502
+ entryName = maybeExtractEntryName(entryName);
503
+ if (i < parts.length) {
504
+ id = parts[++i];
505
+ } else {
506
+ id = undefined;
507
+ }
508
+ }
509
+ }
510
+ return [moduleName, entryName, id, parts];
511
+ }
512
+ return [moduleName, entryName, undefined, parts];
513
+ }
@@ -0,0 +1,43 @@
1
+ import { MonacoEditorLanguageClientWrapper, type WrapperConfig } from 'monaco-editor-wrapper';
2
+ import monarchSyntax from './syntaxes/agentlang.monarch.js';
3
+
4
+ export const setupConfigClassic = () => {
5
+ return {
6
+ $type: 'classic',
7
+ editorAppConfig: {
8
+ codeResources: {
9
+ modified: {
10
+ uri: '/workspace/example.al',
11
+ text: `// Agentlang is running in the web!`,
12
+ },
13
+ },
14
+ useDiffEditor: false,
15
+ languageDef: {
16
+ languageExtensionConfig: { id: 'agentlang' },
17
+ monarchLanguage: monarchSyntax,
18
+ },
19
+ editorOptions: {
20
+ 'semanticHighlighting.enabled': true,
21
+ theme: 'vs-dark',
22
+ },
23
+ },
24
+ };
25
+ };
26
+
27
+ export const executeClassic = async (htmlElement: HTMLElement) => {
28
+ try {
29
+ const config = setupConfigClassic();
30
+ const wrapper = new MonacoEditorLanguageClientWrapper();
31
+
32
+ // Add the HTML container to the config
33
+ const wrapperConfig = {
34
+ ...config,
35
+ htmlContainer: htmlElement,
36
+ } as WrapperConfig;
37
+
38
+ // Initialize and start the wrapper
39
+ await wrapper.initAndStart(wrapperConfig);
40
+ } catch (error) {
41
+ console.error('Error initializing monaco editor:', error);
42
+ }
43
+ };
@@ -0,0 +1,33 @@
1
+ // This file is kept for reference but is not used directly anymore
2
+ // The monaco-editor-wrapper API has changed significantly in v6+
3
+
4
+ // These functions are kept for reference but not used directly anymore
5
+
6
+ /*
7
+ export const defineUserServices = () => {
8
+ return {
9
+ userServices: {
10
+ // This API has changed in the latest version
11
+ },
12
+ debugLogging: true,
13
+ };
14
+ };
15
+
16
+ export const configureMonacoWorkers = () => {
17
+ // This function is kept for compatibility, but implementation has changed
18
+ // Use configureDefaultWorkerFactory from monaco-editor-wrapper/workers/workerLoaders in newer code
19
+ };
20
+
21
+ export const configureWorker = () => {
22
+ // vite does not extract the worker properly if it is URL is a variable
23
+ const lsWorker = new Worker(new URL('./language/main-browser', import.meta.url), {
24
+ type: 'module',
25
+ name: 'Agentlang Language Server',
26
+ });
27
+
28
+ return {
29
+ type: 'WorkerDirect',
30
+ worker: lsWorker,
31
+ };
32
+ };
33
+ */
@@ -0,0 +1,79 @@
1
+ import { MonacoEditorLanguageClientWrapper, type WrapperConfig } from 'monaco-editor-wrapper';
2
+
3
+ export const setupConfigExtended = () => {
4
+ const extensionFilesOrContents = new Map();
5
+ extensionFilesOrContents.set(
6
+ '/language-configuration.json',
7
+ new URL('../language-configuration.json', import.meta.url)
8
+ );
9
+ extensionFilesOrContents.set(
10
+ '/agentlang-grammar.json',
11
+ new URL('../syntaxes/agentlang.tmLanguage.json', import.meta.url)
12
+ );
13
+
14
+ return {
15
+ $type: 'extended',
16
+ editorAppConfig: {
17
+ codeResources: {
18
+ modified: {
19
+ uri: '/workspace/example.al',
20
+ text: `// Agentlang is running in the web!`,
21
+ },
22
+ },
23
+ useDiffEditor: false,
24
+ extensions: [
25
+ {
26
+ config: {
27
+ name: 'agentlang-web',
28
+ publisher: 'generator-langium',
29
+ version: '1.0.0',
30
+ engines: {
31
+ vscode: '*',
32
+ },
33
+ contributes: {
34
+ languages: [
35
+ {
36
+ id: 'agentlang',
37
+ extensions: ['.agentlang'],
38
+ configuration: './language-configuration.json',
39
+ },
40
+ ],
41
+ grammars: [
42
+ {
43
+ language: 'agentlang',
44
+ scopeName: 'source.agentlang',
45
+ path: './agentlang-grammar.json',
46
+ },
47
+ ],
48
+ },
49
+ },
50
+ filesOrContents: extensionFilesOrContents,
51
+ },
52
+ ],
53
+ userConfiguration: {
54
+ json: JSON.stringify({
55
+ 'workbench.colorTheme': 'Default Dark Modern',
56
+ 'editor.semanticHighlighting.enabled': true,
57
+ }),
58
+ },
59
+ },
60
+ };
61
+ };
62
+
63
+ export const executeExtended = async (htmlElement: HTMLElement) => {
64
+ try {
65
+ const config = setupConfigExtended();
66
+ const wrapper = new MonacoEditorLanguageClientWrapper();
67
+
68
+ // Add the HTML container to the config
69
+ const wrapperConfig = {
70
+ ...config,
71
+ htmlContainer: htmlElement,
72
+ } as WrapperConfig;
73
+
74
+ // Initialize and start the wrapper
75
+ await wrapper.initAndStart(wrapperConfig);
76
+ } catch (error) {
77
+ console.error('Error initializing monaco editor:', error);
78
+ }
79
+ };
@@ -0,0 +1,31 @@
1
+ // Monarch syntax highlighting for the agentlang language.
2
+ export default {
3
+ keywords: [
4
+ '@after','@async','@before','@enum','@expr','@meta','@oneof','@rbac','@ref','@with_unique','allow','and','as','await','between','catch','contains','create','delete','else','entity','error','event','extends','false','for','if','import','in','into','like','module','not','not_found','or','purge','read','record','relationship','roles','true','update','upsert','where','workflow'
5
+ ],
6
+ operators: [
7
+ '*','+',',','-','.','/',':',';','<','<=','<>','=','>','>=','?','@'
8
+ ],
9
+ symbols: /\(|\)|\*|\+|,|-|\.|\/|:|;|<|<=|<>|=|>|>=|\?|@|\[|\]|\{|\}/,
10
+
11
+ tokenizer: {
12
+ initial: [
13
+ { regex: /(([_a-zA-Z][\w_]*)(\/([_a-zA-Z][\w_]*))?)/, action: { cases: { '@keywords': {"token":"keyword"}, '@default': {"token":"string"} }} },
14
+ { regex: /[_a-zA-Z][\w_]*/, action: { cases: { '@keywords': {"token":"keyword"}, '@default': {"token":"string"} }} },
15
+ { regex: /(["'])((\\{2})*|(.*?[^\\](\\{2})*))\1/, action: {"token":"string"} },
16
+ { regex: /-?[0-9]+/, action: {"token":"number"} },
17
+ { include: '@whitespace' },
18
+ { regex: /@symbols/, action: { cases: { '@operators': {"token":"operator"}, '@default': {"token":""} }} },
19
+ ],
20
+ whitespace: [
21
+ { regex: /\s+/, action: {"token":"white"} },
22
+ { regex: /\/\*/, action: {"token":"comment","next":"@comment"} },
23
+ { regex: /\/\/[^\n\r]*/, action: {"token":"comment"} },
24
+ ],
25
+ comment: [
26
+ { regex: /[^/\*]+/, action: {"token":"comment"} },
27
+ { regex: /\*\//, action: {"token":"comment","next":"@pop"} },
28
+ { regex: /[/\*]/, action: {"token":"comment"} },
29
+ ],
30
+ }
31
+ };