agentlang 0.10.2 → 0.10.3

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 (145) hide show
  1. package/README.md +7 -14
  2. package/out/api/http.d.ts +4 -0
  3. package/out/api/http.d.ts.map +1 -1
  4. package/out/api/http.js +171 -26
  5. package/out/api/http.js.map +1 -1
  6. package/out/cli/main.d.ts.map +1 -1
  7. package/out/cli/main.js +3 -0
  8. package/out/cli/main.js.map +1 -1
  9. package/out/extension/main.cjs +250 -250
  10. package/out/extension/main.cjs.map +2 -2
  11. package/out/language/agentlang-validator.d.ts.map +1 -1
  12. package/out/language/agentlang-validator.js +4 -0
  13. package/out/language/agentlang-validator.js.map +1 -1
  14. package/out/language/error-reporter.d.ts +53 -0
  15. package/out/language/error-reporter.d.ts.map +1 -0
  16. package/out/language/error-reporter.js +879 -0
  17. package/out/language/error-reporter.js.map +1 -0
  18. package/out/language/generated/ast.d.ts +51 -1
  19. package/out/language/generated/ast.d.ts.map +1 -1
  20. package/out/language/generated/ast.js +40 -0
  21. package/out/language/generated/ast.js.map +1 -1
  22. package/out/language/generated/grammar.d.ts.map +1 -1
  23. package/out/language/generated/grammar.js +286 -190
  24. package/out/language/generated/grammar.js.map +1 -1
  25. package/out/language/main.cjs +828 -694
  26. package/out/language/main.cjs.map +3 -3
  27. package/out/language/parser.d.ts +4 -2
  28. package/out/language/parser.d.ts.map +1 -1
  29. package/out/language/parser.js +30 -97
  30. package/out/language/parser.js.map +1 -1
  31. package/out/language/syntax.d.ts +2 -0
  32. package/out/language/syntax.d.ts.map +1 -1
  33. package/out/language/syntax.js +6 -0
  34. package/out/language/syntax.js.map +1 -1
  35. package/out/runtime/api.d.ts.map +1 -1
  36. package/out/runtime/api.js +22 -0
  37. package/out/runtime/api.js.map +1 -1
  38. package/out/runtime/defs.d.ts +1 -0
  39. package/out/runtime/defs.d.ts.map +1 -1
  40. package/out/runtime/defs.js +2 -1
  41. package/out/runtime/defs.js.map +1 -1
  42. package/out/runtime/document-retriever.d.ts +24 -0
  43. package/out/runtime/document-retriever.d.ts.map +1 -0
  44. package/out/runtime/document-retriever.js +258 -0
  45. package/out/runtime/document-retriever.js.map +1 -0
  46. package/out/runtime/embeddings/chunker.d.ts +18 -0
  47. package/out/runtime/embeddings/chunker.d.ts.map +1 -1
  48. package/out/runtime/embeddings/chunker.js +47 -15
  49. package/out/runtime/embeddings/chunker.js.map +1 -1
  50. package/out/runtime/embeddings/openai.d.ts.map +1 -1
  51. package/out/runtime/embeddings/openai.js +22 -9
  52. package/out/runtime/embeddings/openai.js.map +1 -1
  53. package/out/runtime/embeddings/provider.d.ts +1 -0
  54. package/out/runtime/embeddings/provider.d.ts.map +1 -1
  55. package/out/runtime/embeddings/provider.js +20 -1
  56. package/out/runtime/embeddings/provider.js.map +1 -1
  57. package/out/runtime/integration-client.d.ts +21 -0
  58. package/out/runtime/integration-client.d.ts.map +1 -0
  59. package/out/runtime/integration-client.js +112 -0
  60. package/out/runtime/integration-client.js.map +1 -0
  61. package/out/runtime/integrations.d.ts.map +1 -1
  62. package/out/runtime/integrations.js +20 -9
  63. package/out/runtime/integrations.js.map +1 -1
  64. package/out/runtime/interpreter.d.ts +1 -0
  65. package/out/runtime/interpreter.d.ts.map +1 -1
  66. package/out/runtime/interpreter.js +152 -17
  67. package/out/runtime/interpreter.js.map +1 -1
  68. package/out/runtime/loader.d.ts.map +1 -1
  69. package/out/runtime/loader.js +70 -7
  70. package/out/runtime/loader.js.map +1 -1
  71. package/out/runtime/logger.d.ts.map +1 -1
  72. package/out/runtime/logger.js +8 -1
  73. package/out/runtime/logger.js.map +1 -1
  74. package/out/runtime/module.d.ts +10 -0
  75. package/out/runtime/module.d.ts.map +1 -1
  76. package/out/runtime/module.js +68 -3
  77. package/out/runtime/module.js.map +1 -1
  78. package/out/runtime/modules/ai.d.ts +9 -2
  79. package/out/runtime/modules/ai.d.ts.map +1 -1
  80. package/out/runtime/modules/ai.js +219 -67
  81. package/out/runtime/modules/ai.js.map +1 -1
  82. package/out/runtime/resolvers/interface.d.ts +4 -0
  83. package/out/runtime/resolvers/interface.d.ts.map +1 -1
  84. package/out/runtime/resolvers/interface.js +14 -1
  85. package/out/runtime/resolvers/interface.js.map +1 -1
  86. package/out/runtime/resolvers/sqldb/database.d.ts +2 -0
  87. package/out/runtime/resolvers/sqldb/database.d.ts.map +1 -1
  88. package/out/runtime/resolvers/sqldb/database.js +142 -126
  89. package/out/runtime/resolvers/sqldb/database.js.map +1 -1
  90. package/out/runtime/resolvers/sqldb/dbutil.d.ts.map +1 -1
  91. package/out/runtime/resolvers/sqldb/dbutil.js +8 -0
  92. package/out/runtime/resolvers/sqldb/dbutil.js.map +1 -1
  93. package/out/runtime/resolvers/sqldb/impl.d.ts +1 -0
  94. package/out/runtime/resolvers/sqldb/impl.d.ts.map +1 -1
  95. package/out/runtime/resolvers/sqldb/impl.js +7 -0
  96. package/out/runtime/resolvers/sqldb/impl.js.map +1 -1
  97. package/out/runtime/resolvers/vector/lancedb-store.d.ts +16 -0
  98. package/out/runtime/resolvers/vector/lancedb-store.d.ts.map +1 -0
  99. package/out/runtime/resolvers/vector/lancedb-store.js +159 -0
  100. package/out/runtime/resolvers/vector/lancedb-store.js.map +1 -0
  101. package/out/runtime/resolvers/vector/types.d.ts +32 -0
  102. package/out/runtime/resolvers/vector/types.d.ts.map +1 -0
  103. package/out/runtime/resolvers/vector/types.js +2 -0
  104. package/out/runtime/resolvers/vector/types.js.map +1 -0
  105. package/out/runtime/services/documentFetcher.d.ts.map +1 -1
  106. package/out/runtime/services/documentFetcher.js +21 -6
  107. package/out/runtime/services/documentFetcher.js.map +1 -1
  108. package/out/runtime/state.d.ts +19 -1
  109. package/out/runtime/state.d.ts.map +1 -1
  110. package/out/runtime/state.js +36 -1
  111. package/out/runtime/state.js.map +1 -1
  112. package/out/syntaxes/agentlang.monarch.js +1 -1
  113. package/out/syntaxes/agentlang.monarch.js.map +1 -1
  114. package/package.json +19 -19
  115. package/src/api/http.ts +197 -37
  116. package/src/cli/main.ts +3 -0
  117. package/src/language/agentlang-validator.ts +3 -0
  118. package/src/language/agentlang.langium +3 -1
  119. package/src/language/error-reporter.ts +1028 -0
  120. package/src/language/generated/ast.ts +62 -0
  121. package/src/language/generated/grammar.ts +286 -190
  122. package/src/language/parser.ts +31 -100
  123. package/src/language/syntax.ts +8 -0
  124. package/src/runtime/api.ts +31 -0
  125. package/src/runtime/defs.ts +2 -1
  126. package/src/runtime/document-retriever.ts +311 -0
  127. package/src/runtime/embeddings/chunker.ts +52 -14
  128. package/src/runtime/embeddings/openai.ts +27 -9
  129. package/src/runtime/embeddings/provider.ts +22 -1
  130. package/src/runtime/integration-client.ts +158 -0
  131. package/src/runtime/integrations.ts +20 -11
  132. package/src/runtime/interpreter.ts +142 -12
  133. package/src/runtime/loader.ts +83 -5
  134. package/src/runtime/logger.ts +12 -1
  135. package/src/runtime/module.ts +78 -3
  136. package/src/runtime/modules/ai.ts +263 -76
  137. package/src/runtime/resolvers/interface.ts +19 -1
  138. package/src/runtime/resolvers/sqldb/database.ts +158 -130
  139. package/src/runtime/resolvers/sqldb/dbutil.ts +8 -0
  140. package/src/runtime/resolvers/sqldb/impl.ts +8 -0
  141. package/src/runtime/resolvers/vector/lancedb-store.ts +187 -0
  142. package/src/runtime/resolvers/vector/types.ts +39 -0
  143. package/src/runtime/services/documentFetcher.ts +21 -6
  144. package/src/runtime/state.ts +40 -1
  145. package/src/syntaxes/agentlang.monarch.ts +1 -1
@@ -0,0 +1,39 @@
1
+ export interface VectorRecord {
2
+ id: string;
3
+ embedding: number[];
4
+ tenantId?: string;
5
+ agentId?: string;
6
+ documentId?: string;
7
+ metadata?: Record<string, any>;
8
+ }
9
+
10
+ export interface SearchResult {
11
+ id: string;
12
+ distance: number;
13
+ tenantId?: string;
14
+ agentId?: string;
15
+ documentId?: string;
16
+ metadata?: Record<string, any>;
17
+ }
18
+
19
+ export interface VectorStore {
20
+ init(): Promise<void>;
21
+ addEmbedding(record: VectorRecord): Promise<void>;
22
+ addEmbeddings(records: VectorRecord[]): Promise<void>;
23
+ search(
24
+ embedding: number[],
25
+ tenantId?: string,
26
+ agentId?: string,
27
+ limit?: number
28
+ ): Promise<SearchResult[]>;
29
+ delete(id: string): Promise<void>;
30
+ exists(id: string): Promise<boolean>;
31
+ close(): Promise<void>;
32
+ }
33
+
34
+ export interface VectorStoreConfig {
35
+ dbname?: string;
36
+ moduleName: string;
37
+ vectorDimension: number;
38
+ inMemory?: boolean;
39
+ }
@@ -68,6 +68,7 @@ class DocumentFetcherService {
68
68
 
69
69
  async fetchDocument(config: DocumentConfig): Promise<FetchedDocument | null> {
70
70
  this.ensureNodeEnv();
71
+ logger.info(`[DOC-FETCH] Starting fetch for: ${config.title}`);
71
72
  const cacheKey = `${config.title}:${config.url || config.documentServiceId}`;
72
73
  const cached = this.documentCache.get(cacheKey);
73
74
 
@@ -79,6 +80,7 @@ class DocumentFetcherService {
79
80
  try {
80
81
  let content: string;
81
82
  let sourceUrl: string;
83
+ logger.info(`[DOC-FETCH] Fetching from URL: ${config.url}`);
82
84
 
83
85
  if (config.url?.startsWith('document-service://')) {
84
86
  if (!config.retrievalConfig || config.retrievalConfig.provider !== 'document-service') {
@@ -144,8 +146,10 @@ class DocumentFetcherService {
144
146
  content = await this.fetchFromUrl(config.url);
145
147
  sourceUrl = config.url;
146
148
  } else if (config.url) {
149
+ logger.info(`[DOC-FETCH] Fetching from local file: ${config.url}`);
147
150
  content = await this.fetchFromLocal(config.url);
148
151
  sourceUrl = config.url;
152
+ logger.info(`[DOC-FETCH] Local file fetched successfully: ${content.length} chars`);
149
153
  } else {
150
154
  if (this.documentServiceConfig) {
151
155
  const docId = await this.lookupDocumentByTitle(config.title);
@@ -171,7 +175,9 @@ class DocumentFetcherService {
171
175
 
172
176
  this.documentCache.set(cacheKey, document);
173
177
 
178
+ logger.info(`[DOC-FETCH] Creating Document entity for: ${config.title}`);
174
179
  await this.createDocumentEntity(document);
180
+ logger.info(`[DOC-FETCH] Document entity created successfully for: ${config.title}`);
175
181
 
176
182
  return document;
177
183
  } catch (error) {
@@ -443,11 +449,14 @@ class DocumentFetcherService {
443
449
 
444
450
  private async fetchFromLocal(filePath: string): Promise<string> {
445
451
  try {
452
+ logger.info(`[DOC-FETCH] Reading local file: ${filePath}`);
446
453
  const content = await readFile(filePath);
454
+ logger.info(`[DOC-FETCH] File read successfully: ${content.length} chars`);
447
455
  const lowerPath = filePath.toLowerCase();
448
456
  const isMarkdown = lowerPath.endsWith('.md') || lowerPath.endsWith('.markdown');
449
457
 
450
458
  if (isMarkdown) {
459
+ logger.info(`[DOC-FETCH] Parsing markdown...`);
451
460
  return this.parseMarkdownText(content);
452
461
  }
453
462
 
@@ -547,10 +556,11 @@ class DocumentFetcherService {
547
556
  // Lazy load PDF parser
548
557
  if (!this.pdfParser) {
549
558
  try {
550
- const pdfParse = await import('pdf-parse');
551
- // Handle both ESM and CSM module formats
552
- const parser = (pdfParse as any).default || pdfParse;
553
- this.pdfParser = parser;
559
+ const { PDFParse } = await import('pdf-parse');
560
+ if (!PDFParse) {
561
+ throw new Error('pdf-parse does not export PDFParse');
562
+ }
563
+ this.pdfParser = PDFParse;
554
564
  } catch (error) {
555
565
  logger.error('Failed to load PDF parser', { error });
556
566
  throw new Error(
@@ -560,11 +570,16 @@ class DocumentFetcherService {
560
570
  }
561
571
 
562
572
  try {
563
- const result = await this.pdfParser(buffer);
573
+ const parser = new this.pdfParser({ data: buffer });
574
+ const result = await parser.getText();
575
+ if (typeof parser.destroy === 'function') {
576
+ await parser.destroy();
577
+ }
564
578
  return result.text || '';
565
579
  } catch (error) {
566
580
  logger.error('PDF parsing failed', { error });
567
- throw new Error(`Failed to parse PDF: ${error}`);
581
+ const message = error instanceof Error ? error.message : String(error);
582
+ throw new Error(`Failed to parse PDF: ${message}`);
568
583
  }
569
584
  }
570
585
 
@@ -35,6 +35,21 @@ export const ConfigSchema = z.object({
35
35
  type: z.literal('sqlite'),
36
36
  dbname: z.string().optional(),
37
37
  }),
38
+ z.object({
39
+ type: z.literal('lancedb'),
40
+ path: z.string().optional(),
41
+ }),
42
+ ])
43
+ .optional(),
44
+ vectorStore: z
45
+ .discriminatedUnion('type', [
46
+ z.object({
47
+ type: z.literal('pgvector'),
48
+ }),
49
+ z.object({
50
+ type: z.literal('lancedb'),
51
+ dbname: z.string().optional(),
52
+ }),
38
53
  ])
39
54
  .optional(),
40
55
  integrations: z
@@ -42,7 +57,17 @@ export const ConfigSchema = z.object({
42
57
  host: z.string(),
43
58
  username: z.string().optional(),
44
59
  password: z.string().optional(),
45
- connections: z.record(z.string(), z.string()),
60
+ connections: z.record(
61
+ z.string(),
62
+ z.union([
63
+ z.string(),
64
+ z.object({
65
+ config: z.string(),
66
+ resolvers: z.array(z.string()),
67
+ }),
68
+ ])
69
+ ),
70
+ oauth: z.boolean().default(false),
46
71
  })
47
72
  .optional(),
48
73
  graphql: z
@@ -71,6 +96,11 @@ export const ConfigSchema = z.object({
71
96
  enabled: z.boolean().default(false),
72
97
  })
73
98
  .optional(),
99
+ knowledgeGraph: z
100
+ .object({
101
+ serviceUrl: z.string().default('#js process.env.KNOWLEDGE_SERVICE_URL || ""'),
102
+ })
103
+ .optional(),
74
104
  authentication: z
75
105
  .discriminatedUnion('service', [
76
106
  z.object({
@@ -155,6 +185,15 @@ export function isMonitoringEnabled(): boolean {
155
185
  return internalMonitoringEnabled || AppConfig?.monitoring?.enabled === true;
156
186
  }
157
187
 
188
+ export function isKnowledgeGraphEnabled(): boolean {
189
+ const url = AppConfig?.knowledgeGraph?.serviceUrl?.trim();
190
+ return !!(url && url.length > 0) || !!process.env.KNOWLEDGE_SERVICE_URL;
191
+ }
192
+
193
+ export function getKnowledgeGraphConfig(): Config['knowledgeGraph'] | undefined {
194
+ return AppConfig?.knowledgeGraph;
195
+ }
196
+
158
197
  type TtlCacheEntry<T> = {
159
198
  value: T;
160
199
  expireTime: number;
@@ -1,7 +1,7 @@
1
1
  // Monarch syntax highlighting for the agentlang language.
2
2
  export default {
3
3
  keywords: [
4
- '@actions','@after','@as','@asc','@async','@before','@catch','@desc','@distinct','@empty','@enum','@expr','@from','@full_join','@groupBy','@inner_join','@into','@join','@left_join','@meta','@oneof','@orderBy','@public','@rbac','@ref','@right_join','@then','@upsert','@where','@withRole','@with_unique','agent','agentlang/retry','allow','and','attempts','await','backoff','between','case','commitTransaction','contains','create','decision','delete','directive','else','entity','error','eval','event','extends','false','flow','for','glossaryEntry','if','import','in','like','module','not','not_found','onSubscription','or','purge','query','read','record','relationship','resolver','return','roles','rollbackTransaction','scenario','startTransaction','subscribe','throw','true','update','upsert','where','workflow'
4
+ '@actions','@after','@as','@asc','@async','@before','@catch','@desc','@distinct','@empty','@enum','@expr','@from','@full_join','@groupBy','@inner_join','@into','@join','@left_join','@limit','@meta','@offset','@oneof','@orderBy','@public','@rbac','@ref','@right_join','@then','@upsert','@where','@withRole','@with_unique','agent','agentlang/retry','allow','and','attempts','await','backoff','between','case','commitTransaction','contains','create','decision','delete','directive','else','entity','error','eval','event','extends','false','flow','for','glossaryEntry','if','import','in','like','module','not','not_found','onSubscription','or','purge','query','read','record','relationship','resolver','return','roles','rollbackTransaction','scenario','startTransaction','subscribe','throw','true','update','upsert','where','workflow'
5
5
  ],
6
6
  operators: [
7
7
  '!=','*','+',',','-','-->','.','/',':',';','<','<=','<>','=','==','>','>=','?','@'