agentlang 0.9.9 → 0.9.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.
Files changed (61) hide show
  1. package/out/extension/main.cjs +38 -38
  2. package/out/extension/main.cjs.map +2 -2
  3. package/out/language/generated/ast.d.ts +1 -1
  4. package/out/language/generated/ast.js +1 -1
  5. package/out/language/generated/grammar.d.ts +1 -1
  6. package/out/language/generated/grammar.js +1 -1
  7. package/out/language/generated/module.d.ts +1 -1
  8. package/out/language/generated/module.js +1 -1
  9. package/out/language/main.cjs +850 -2388
  10. package/out/language/main.cjs.map +4 -4
  11. package/out/runtime/agents/common.d.ts +3 -1
  12. package/out/runtime/agents/common.d.ts.map +1 -1
  13. package/out/runtime/agents/common.js +35 -31
  14. package/out/runtime/agents/common.js.map +1 -1
  15. package/out/runtime/docs.d.ts +1 -0
  16. package/out/runtime/docs.d.ts.map +1 -1
  17. package/out/runtime/docs.js +16 -1
  18. package/out/runtime/docs.js.map +1 -1
  19. package/out/runtime/interpreter.d.ts +1 -0
  20. package/out/runtime/interpreter.d.ts.map +1 -1
  21. package/out/runtime/interpreter.js +60 -9
  22. package/out/runtime/interpreter.js.map +1 -1
  23. package/out/runtime/jsmodules.d.ts +2 -1
  24. package/out/runtime/jsmodules.d.ts.map +1 -1
  25. package/out/runtime/jsmodules.js +2 -1
  26. package/out/runtime/jsmodules.js.map +1 -1
  27. package/out/runtime/loader.d.ts.map +1 -1
  28. package/out/runtime/loader.js +3 -2
  29. package/out/runtime/loader.js.map +1 -1
  30. package/out/runtime/module.d.ts +1 -0
  31. package/out/runtime/module.d.ts.map +1 -1
  32. package/out/runtime/module.js +3 -0
  33. package/out/runtime/module.js.map +1 -1
  34. package/out/runtime/modules/ai.d.ts +12 -0
  35. package/out/runtime/modules/ai.d.ts.map +1 -1
  36. package/out/runtime/modules/ai.js +225 -28
  37. package/out/runtime/modules/ai.js.map +1 -1
  38. package/out/runtime/modules/core.d.ts.map +1 -1
  39. package/out/runtime/modules/core.js +7 -1
  40. package/out/runtime/modules/core.js.map +1 -1
  41. package/out/runtime/resolvers/sqldb/impl.d.ts.map +1 -1
  42. package/out/runtime/resolvers/sqldb/impl.js +37 -6
  43. package/out/runtime/resolvers/sqldb/impl.js.map +1 -1
  44. package/out/runtime/services/documentFetcher.d.ts +70 -0
  45. package/out/runtime/services/documentFetcher.d.ts.map +1 -0
  46. package/out/runtime/services/documentFetcher.js +582 -0
  47. package/out/runtime/services/documentFetcher.js.map +1 -0
  48. package/package.json +2 -1
  49. package/src/language/generated/ast.ts +1 -1
  50. package/src/language/generated/grammar.ts +1 -1
  51. package/src/language/generated/module.ts +1 -1
  52. package/src/runtime/agents/common.ts +37 -31
  53. package/src/runtime/docs.ts +17 -1
  54. package/src/runtime/interpreter.ts +64 -7
  55. package/src/runtime/jsmodules.ts +3 -1
  56. package/src/runtime/loader.ts +3 -2
  57. package/src/runtime/module.ts +4 -0
  58. package/src/runtime/modules/ai.ts +270 -33
  59. package/src/runtime/modules/core.ts +7 -1
  60. package/src/runtime/resolvers/sqldb/impl.ts +36 -6
  61. package/src/runtime/services/documentFetcher.ts +691 -0
@@ -1,4 +1,4 @@
1
- import { default as ai } from './ai.js';
1
+ import { default as ai, normalizeGeneratedCode } from './ai.js';
2
2
  import { default as auth } from './auth.js';
3
3
  import { default as files } from './files.js';
4
4
  import { default as mcp } from './mcp.js';
@@ -527,6 +527,12 @@ export function eventMonitorsData(
527
527
  export async function validateModule(moduleDef: any): Promise<Instance> {
528
528
  try {
529
529
  if (isString(moduleDef)) {
530
+ moduleDef = normalizeGeneratedCode(moduleDef);
531
+ if (!moduleDef.startsWith('module')) {
532
+ moduleDef = `module Temp
533
+ ${moduleDef}
534
+ `;
535
+ }
530
536
  await parseModule(moduleDef);
531
537
  return makeInstance(
532
538
  'agentlang',
@@ -241,10 +241,31 @@ export class SqlDbResolver extends Resolver {
241
241
  ) {
242
242
  const ftsAttrs = inst.record.getFullTextSearchAttributes() || ['*'];
243
243
  const textToEmbed = this.extractTextForEmbedding(rowObj, ftsAttrs);
244
- const embeddingConfig = inst.record.getEmbeddingConfig();
245
- const embeddingService = embeddingConfig
246
- ? new EmbeddingService(embeddingConfig)
247
- : this.embeddingService;
244
+ let embeddingConfig: any = undefined;
245
+ const instanceEmbeddingConfig = inst.get('embeddingConfig');
246
+ if (instanceEmbeddingConfig) {
247
+ try {
248
+ embeddingConfig =
249
+ typeof instanceEmbeddingConfig === 'string'
250
+ ? JSON.parse(instanceEmbeddingConfig)
251
+ : instanceEmbeddingConfig;
252
+ } catch {
253
+ // If parsing fails, will fall back to env vars
254
+ }
255
+ }
256
+ if (!embeddingConfig) {
257
+ embeddingConfig = {
258
+ provider: process.env.AGENTLANG_EMBEDDING_PROVIDER || 'openai',
259
+ model: process.env.AGENTLANG_EMBEDDING_MODEL || 'text-embedding-3-small',
260
+ chunkSize: process.env.AGENTLANG_EMBEDDING_CHUNKSIZE
261
+ ? parseInt(process.env.AGENTLANG_EMBEDDING_CHUNKSIZE, 10)
262
+ : 1000,
263
+ chunkOverlap: process.env.AGENTLANG_EMBEDDING_CHUNKOVERLAP
264
+ ? parseInt(process.env.AGENTLANG_EMBEDDING_CHUNKOVERLAP, 10)
265
+ : 200,
266
+ };
267
+ }
268
+ const embeddingService = new EmbeddingService(embeddingConfig);
248
269
  const res = await embeddingService.embedText(textToEmbed);
249
270
  await addRowForFullTextSearch(n, path, res, ctx);
250
271
  }
@@ -330,11 +351,20 @@ export class SqlDbResolver extends Resolver {
330
351
  const aggregates = SqlDbResolver.normalizedAggregates(inst, tableName);
331
352
 
332
353
  let vectorResult: Instance[] | undefined;
333
- const embeddingConfig = inst.record.getEmbeddingConfig();
354
+ // Use environment variable based embedding config for queries
355
+ const embeddingConfig = {
356
+ provider: process.env.AGENTLANG_EMBEDDING_PROVIDER || 'openai',
357
+ model: process.env.AGENTLANG_EMBEDDING_MODEL || 'text-embedding-3-small',
358
+ chunkSize: process.env.AGENTLANG_EMBEDDING_CHUNKSIZE
359
+ ? parseInt(process.env.AGENTLANG_EMBEDDING_CHUNKSIZE, 10)
360
+ : 1000,
361
+ chunkOverlap: process.env.AGENTLANG_EMBEDDING_CHUNKOVERLAP
362
+ ? parseInt(process.env.AGENTLANG_EMBEDDING_CHUNKOVERLAP, 10)
363
+ : 200,
364
+ };
334
365
  const ftsAttrs = inst.record.getFullTextSearchAttributes();
335
366
  if (
336
367
  (await isVectorStoreSupported()) &&
337
- embeddingConfig &&
338
368
  qattrs &&
339
369
  (ftsAttrs || Object.keys(qattrs).some(k => k.endsWith('?')))
340
370
  ) {