agentlang 0.9.8 → 0.9.10
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/out/runtime/interpreter.d.ts.map +1 -1
- package/out/runtime/interpreter.js +19 -1
- package/out/runtime/interpreter.js.map +1 -1
- package/out/runtime/modules/ai.d.ts +2 -0
- package/out/runtime/modules/ai.d.ts.map +1 -1
- package/out/runtime/modules/ai.js +67 -18
- package/out/runtime/modules/ai.js.map +1 -1
- package/out/runtime/resolvers/sqldb/impl.d.ts.map +1 -1
- package/out/runtime/resolvers/sqldb/impl.js +37 -6
- package/out/runtime/resolvers/sqldb/impl.js.map +1 -1
- package/out/runtime/services/documentFetcher.d.ts +62 -0
- package/out/runtime/services/documentFetcher.d.ts.map +1 -0
- package/out/runtime/services/documentFetcher.js +387 -0
- package/out/runtime/services/documentFetcher.js.map +1 -0
- package/package.json +2 -1
- package/src/runtime/interpreter.ts +20 -1
- package/src/runtime/modules/ai.ts +81 -24
- package/src/runtime/resolvers/sqldb/impl.ts +36 -6
- package/src/runtime/services/documentFetcher.ts +468 -0
|
@@ -0,0 +1,387 @@
|
|
|
1
|
+
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
2
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
3
|
+
var m = o[Symbol.asyncIterator], i;
|
|
4
|
+
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
5
|
+
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
6
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
7
|
+
};
|
|
8
|
+
import { S3Client, GetObjectCommand } from '@aws-sdk/client-s3';
|
|
9
|
+
import { readFile } from 'node:fs/promises';
|
|
10
|
+
import path from 'node:path';
|
|
11
|
+
import { logger } from '../logger.js';
|
|
12
|
+
import { parseAndEvaluateStatement } from '../interpreter.js';
|
|
13
|
+
import { CoreAIModuleName } from '../modules/ai.js';
|
|
14
|
+
import { TtlCache } from '../state.js';
|
|
15
|
+
import { preprocessRawConfig } from '../util.js';
|
|
16
|
+
import { marked } from 'marked';
|
|
17
|
+
import { isNodeEnv } from '../../utils/runtime.js';
|
|
18
|
+
class DocumentFetcherService {
|
|
19
|
+
constructor() {
|
|
20
|
+
this.documentCache = new TtlCache(DocumentFetcherService.CACHE_TTL_MS);
|
|
21
|
+
this.s3Clients = new Map();
|
|
22
|
+
this.pdfParser = null;
|
|
23
|
+
}
|
|
24
|
+
async fetchDocument(config) {
|
|
25
|
+
this.ensureNodeEnv();
|
|
26
|
+
const cacheKey = `${config.title}:${config.url}`;
|
|
27
|
+
const cached = this.documentCache.get(cacheKey);
|
|
28
|
+
if (cached) {
|
|
29
|
+
logger.debug('Returning cached document', { title: config.title });
|
|
30
|
+
return cached;
|
|
31
|
+
}
|
|
32
|
+
try {
|
|
33
|
+
let content;
|
|
34
|
+
if (config.url.startsWith('s3://')) {
|
|
35
|
+
content = await this.fetchFromS3(config);
|
|
36
|
+
}
|
|
37
|
+
else if (config.url.startsWith('http://') || config.url.startsWith('https://')) {
|
|
38
|
+
content = await this.fetchFromUrl(config.url);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
// Local file path
|
|
42
|
+
content = await this.fetchFromLocal(config.url);
|
|
43
|
+
}
|
|
44
|
+
const document = {
|
|
45
|
+
title: config.title,
|
|
46
|
+
content,
|
|
47
|
+
url: config.url,
|
|
48
|
+
format: this.inferFormat(config.url),
|
|
49
|
+
fetchedAt: new Date(),
|
|
50
|
+
embeddingConfig: config.embeddingConfig,
|
|
51
|
+
};
|
|
52
|
+
this.documentCache.set(cacheKey, document);
|
|
53
|
+
// Auto-create Document entity from fetched content
|
|
54
|
+
await this.createDocumentEntity(document);
|
|
55
|
+
return document;
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
logger.error('Failed to fetch document', {
|
|
59
|
+
title: config.title,
|
|
60
|
+
url: config.url,
|
|
61
|
+
error: error instanceof Error ? error.message : String(error),
|
|
62
|
+
stack: error instanceof Error ? error.stack : undefined,
|
|
63
|
+
});
|
|
64
|
+
// Re-throw the error so the caller knows what happened
|
|
65
|
+
throw error;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
async fetchDocumentByTitle(title) {
|
|
69
|
+
this.ensureNodeEnv();
|
|
70
|
+
// First check if we have it in cache
|
|
71
|
+
// Note: TtlCache doesn't have a way to search by prefix, so we'll fetch directly
|
|
72
|
+
try {
|
|
73
|
+
// Try to find in loaded config
|
|
74
|
+
const doc = this.findDocumentInConfig(title);
|
|
75
|
+
if (doc) {
|
|
76
|
+
return this.fetchDocument(doc);
|
|
77
|
+
}
|
|
78
|
+
logger.warn('Document not found in config', { title });
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
logger.error('Failed to fetch document by title', { title, error });
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
findDocumentInConfig(title) {
|
|
87
|
+
// This method should be called during config loading
|
|
88
|
+
// The documents are stored when the config is parsed
|
|
89
|
+
const docs = getConfiguredDocuments();
|
|
90
|
+
return docs.find(d => d.title === title) || null;
|
|
91
|
+
}
|
|
92
|
+
async fetchFromS3(config) {
|
|
93
|
+
const s3Config = this.parseS3Url(config.url, config.retrievalConfig);
|
|
94
|
+
const client = await this.getOrCreateS3Client(s3Config);
|
|
95
|
+
try {
|
|
96
|
+
const response = await client.send(new GetObjectCommand({
|
|
97
|
+
Bucket: s3Config.bucket,
|
|
98
|
+
Key: s3Config.key,
|
|
99
|
+
}));
|
|
100
|
+
if (!response.Body) {
|
|
101
|
+
throw new Error('S3 object has no body');
|
|
102
|
+
}
|
|
103
|
+
const bodyBuffer = await this.readS3BodyToBuffer(response.Body);
|
|
104
|
+
const contentType = (response.ContentType || '').toLowerCase();
|
|
105
|
+
const lowerKey = s3Config.key.toLowerCase();
|
|
106
|
+
const isPdf = contentType.includes('application/pdf') || lowerKey.endsWith('.pdf');
|
|
107
|
+
const isMarkdown = contentType.includes('text/markdown') ||
|
|
108
|
+
lowerKey.endsWith('.md') ||
|
|
109
|
+
lowerKey.endsWith('.markdown') ||
|
|
110
|
+
lowerKey.endsWith('.mdown');
|
|
111
|
+
if (isPdf) {
|
|
112
|
+
return await this.parsePdfBuffer(bodyBuffer);
|
|
113
|
+
}
|
|
114
|
+
if (isMarkdown) {
|
|
115
|
+
return this.parseMarkdownText(bodyBuffer.toString('utf-8'));
|
|
116
|
+
}
|
|
117
|
+
return bodyBuffer.toString('utf-8');
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
121
|
+
const errorStack = error instanceof Error ? error.stack : undefined;
|
|
122
|
+
logger.error('S3 fetch failed', {
|
|
123
|
+
url: config.url,
|
|
124
|
+
bucket: s3Config.bucket,
|
|
125
|
+
key: s3Config.key,
|
|
126
|
+
region: s3Config.region,
|
|
127
|
+
hasAccessKey: !!s3Config.accessKeyId,
|
|
128
|
+
error: errorMessage,
|
|
129
|
+
stack: errorStack,
|
|
130
|
+
});
|
|
131
|
+
throw new Error(`Failed to fetch from S3 (bucket: ${s3Config.bucket}, key: ${s3Config.key}, region: ${s3Config.region}): ${errorMessage}`);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
async fetchFromUrl(url) {
|
|
135
|
+
try {
|
|
136
|
+
const response = await fetch(url, {
|
|
137
|
+
signal: AbortSignal.timeout(30000),
|
|
138
|
+
});
|
|
139
|
+
if (!response.ok) {
|
|
140
|
+
throw new Error(`HTTP ${response.status} ${response.statusText}`);
|
|
141
|
+
}
|
|
142
|
+
const body = await response.arrayBuffer();
|
|
143
|
+
const maxSize = 50 * 1024 * 1024;
|
|
144
|
+
if (body.byteLength > maxSize) {
|
|
145
|
+
throw new Error(`Response too large: ${body.byteLength} bytes`);
|
|
146
|
+
}
|
|
147
|
+
const contentType = (response.headers.get('content-type') || '').toLowerCase();
|
|
148
|
+
const lowerUrl = url.toLowerCase();
|
|
149
|
+
const isMarkdown = contentType.includes('text/markdown') ||
|
|
150
|
+
lowerUrl.endsWith('.md') ||
|
|
151
|
+
lowerUrl.endsWith('.markdown') ||
|
|
152
|
+
lowerUrl.endsWith('.mdown');
|
|
153
|
+
const text = Buffer.from(body).toString('utf-8');
|
|
154
|
+
return isMarkdown ? this.parseMarkdownText(text) : text;
|
|
155
|
+
}
|
|
156
|
+
catch (error) {
|
|
157
|
+
logger.error('URL fetch failed', { url, error });
|
|
158
|
+
throw new Error(`Failed to fetch from URL: ${error}`);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
async fetchFromLocal(filePath) {
|
|
162
|
+
try {
|
|
163
|
+
const resolvedPath = path.resolve(filePath);
|
|
164
|
+
const content = await readFile(resolvedPath, 'utf-8');
|
|
165
|
+
const lowerPath = resolvedPath.toLowerCase();
|
|
166
|
+
const isMarkdown = lowerPath.endsWith('.md') ||
|
|
167
|
+
lowerPath.endsWith('.markdown') ||
|
|
168
|
+
lowerPath.endsWith('.mdown');
|
|
169
|
+
return isMarkdown ? this.parseMarkdownText(content) : content;
|
|
170
|
+
}
|
|
171
|
+
catch (error) {
|
|
172
|
+
logger.error('Local file read failed', { path: filePath, error });
|
|
173
|
+
throw new Error(`Failed to read local file: ${error}`);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
parseS3Url(url, retrievalConfig) {
|
|
177
|
+
// Parse s3://bucket/key format
|
|
178
|
+
if (!url.startsWith('s3://')) {
|
|
179
|
+
throw new Error('Invalid S3 URL format. Expected: s3://bucket/key');
|
|
180
|
+
}
|
|
181
|
+
const withoutProtocol = url.slice(5);
|
|
182
|
+
const firstSlash = withoutProtocol.indexOf('/');
|
|
183
|
+
if (firstSlash === -1) {
|
|
184
|
+
throw new Error('Invalid S3 URL format. Expected: s3://bucket/key');
|
|
185
|
+
}
|
|
186
|
+
const bucket = withoutProtocol.slice(0, firstSlash);
|
|
187
|
+
const key = withoutProtocol.slice(firstSlash + 1);
|
|
188
|
+
const normalizedRetrievalConfig = this.normalizeRetrievalConfig(retrievalConfig);
|
|
189
|
+
// Get S3-specific config from retrievalConfig if provider is s3
|
|
190
|
+
let s3SpecificConfig = {};
|
|
191
|
+
if ((normalizedRetrievalConfig === null || normalizedRetrievalConfig === void 0 ? void 0 : normalizedRetrievalConfig.provider) === 's3' && normalizedRetrievalConfig.config) {
|
|
192
|
+
s3SpecificConfig = normalizedRetrievalConfig.config;
|
|
193
|
+
}
|
|
194
|
+
return {
|
|
195
|
+
bucket,
|
|
196
|
+
key,
|
|
197
|
+
region: s3SpecificConfig.region || process.env.AWS_REGION || 'us-east-1',
|
|
198
|
+
endpoint: s3SpecificConfig.endpoint,
|
|
199
|
+
accessKeyId: s3SpecificConfig.accessKeyId || process.env.AWS_ACCESS_KEY_ID,
|
|
200
|
+
secretAccessKey: s3SpecificConfig.secretAccessKey || process.env.AWS_SECRET_ACCESS_KEY,
|
|
201
|
+
forcePathStyle: s3SpecificConfig.forcePathStyle,
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
async getOrCreateS3Client(config) {
|
|
205
|
+
const clientKey = `${config.region}:${config.endpoint || 'default'}:${config.accessKeyId || 'default'}`;
|
|
206
|
+
if (!this.s3Clients.has(clientKey)) {
|
|
207
|
+
const client = new S3Client({
|
|
208
|
+
region: config.region,
|
|
209
|
+
endpoint: config.endpoint,
|
|
210
|
+
forcePathStyle: config.forcePathStyle,
|
|
211
|
+
credentials: config.accessKeyId && config.secretAccessKey
|
|
212
|
+
? {
|
|
213
|
+
accessKeyId: config.accessKeyId,
|
|
214
|
+
secretAccessKey: config.secretAccessKey,
|
|
215
|
+
}
|
|
216
|
+
: undefined,
|
|
217
|
+
});
|
|
218
|
+
this.s3Clients.set(clientKey, client);
|
|
219
|
+
}
|
|
220
|
+
return this.s3Clients.get(clientKey);
|
|
221
|
+
}
|
|
222
|
+
async createDocumentEntity(document) {
|
|
223
|
+
try {
|
|
224
|
+
// Build the Document entity attributes
|
|
225
|
+
let docAttrs = `{title "${document.title}", content "${this.escapeContent(document.content)}"`;
|
|
226
|
+
// Add embeddingConfig if present
|
|
227
|
+
if (document.embeddingConfig) {
|
|
228
|
+
const configStr = JSON.stringify(document.embeddingConfig).replace(/"/g, '\\"');
|
|
229
|
+
docAttrs += `, embeddingConfig "${configStr}"`;
|
|
230
|
+
}
|
|
231
|
+
docAttrs += '}';
|
|
232
|
+
// Upsert to database
|
|
233
|
+
await parseAndEvaluateStatement(`{${CoreAIModuleName}/Document ${docAttrs}, @upsert}`);
|
|
234
|
+
logger.debug('Created Document entity', {
|
|
235
|
+
title: document.title,
|
|
236
|
+
url: document.url,
|
|
237
|
+
hasEmbeddingConfig: !!document.embeddingConfig,
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
catch (error) {
|
|
241
|
+
logger.error('Failed to create Document entity', {
|
|
242
|
+
title: document.title,
|
|
243
|
+
error,
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
escapeContent(content) {
|
|
248
|
+
return content
|
|
249
|
+
.replace(/\\/g, '\\\\')
|
|
250
|
+
.replace(/"/g, '\\"')
|
|
251
|
+
.replace(/\n/g, '\\n')
|
|
252
|
+
.replace(/\r/g, '\\r')
|
|
253
|
+
.replace(/\t/g, '\\t');
|
|
254
|
+
}
|
|
255
|
+
inferFormat(url) {
|
|
256
|
+
const parts = url.split('.');
|
|
257
|
+
if (parts.length > 1) {
|
|
258
|
+
return parts[parts.length - 1].toLowerCase();
|
|
259
|
+
}
|
|
260
|
+
return 'txt';
|
|
261
|
+
}
|
|
262
|
+
clearCache(title) {
|
|
263
|
+
if (title) {
|
|
264
|
+
// Note: TtlCache doesn't expose keys, clear all for now
|
|
265
|
+
this.documentCache.clear();
|
|
266
|
+
}
|
|
267
|
+
else {
|
|
268
|
+
this.documentCache.clear();
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
normalizeConfigValue(value) {
|
|
272
|
+
if (value instanceof Map) {
|
|
273
|
+
const obj = {};
|
|
274
|
+
value.forEach((v, k) => {
|
|
275
|
+
obj[k] = this.normalizeConfigValue(v);
|
|
276
|
+
});
|
|
277
|
+
return obj;
|
|
278
|
+
}
|
|
279
|
+
if (Array.isArray(value)) {
|
|
280
|
+
return value.map(v => this.normalizeConfigValue(v));
|
|
281
|
+
}
|
|
282
|
+
if (value && typeof value === 'object') {
|
|
283
|
+
const obj = {};
|
|
284
|
+
Object.entries(value).forEach(([k, v]) => {
|
|
285
|
+
obj[k] = this.normalizeConfigValue(v);
|
|
286
|
+
});
|
|
287
|
+
return obj;
|
|
288
|
+
}
|
|
289
|
+
return value;
|
|
290
|
+
}
|
|
291
|
+
normalizeRetrievalConfig(retrievalConfig) {
|
|
292
|
+
if (!retrievalConfig)
|
|
293
|
+
return undefined;
|
|
294
|
+
const normalized = this.normalizeConfigValue(retrievalConfig);
|
|
295
|
+
if (normalized && typeof normalized === 'object') {
|
|
296
|
+
preprocessRawConfig(normalized);
|
|
297
|
+
}
|
|
298
|
+
return normalized;
|
|
299
|
+
}
|
|
300
|
+
ensureNodeEnv() {
|
|
301
|
+
if (!isNodeEnv) {
|
|
302
|
+
throw new Error('Document fetching is only available in Node.js environment');
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
async readS3BodyToBuffer(body) {
|
|
306
|
+
var _a, e_1, _b, _c;
|
|
307
|
+
if (body.transformToByteArray) {
|
|
308
|
+
const bytes = await body.transformToByteArray();
|
|
309
|
+
return Buffer.from(bytes);
|
|
310
|
+
}
|
|
311
|
+
if (body.transformToString) {
|
|
312
|
+
const text = await body.transformToString('utf-8');
|
|
313
|
+
return Buffer.from(text, 'utf-8');
|
|
314
|
+
}
|
|
315
|
+
const chunks = [];
|
|
316
|
+
try {
|
|
317
|
+
for (var _d = true, body_1 = __asyncValues(body), body_1_1; body_1_1 = await body_1.next(), _a = body_1_1.done, !_a; _d = true) {
|
|
318
|
+
_c = body_1_1.value;
|
|
319
|
+
_d = false;
|
|
320
|
+
const chunk = _c;
|
|
321
|
+
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
325
|
+
finally {
|
|
326
|
+
try {
|
|
327
|
+
if (!_d && !_a && (_b = body_1.return)) await _b.call(body_1);
|
|
328
|
+
}
|
|
329
|
+
finally { if (e_1) throw e_1.error; }
|
|
330
|
+
}
|
|
331
|
+
return Buffer.concat(chunks);
|
|
332
|
+
}
|
|
333
|
+
async getPdfParser() {
|
|
334
|
+
if (!this.pdfParser) {
|
|
335
|
+
const pdfModule = await import('pdf-parse');
|
|
336
|
+
this.pdfParser = pdfModule.PDFParse || pdfModule.default;
|
|
337
|
+
}
|
|
338
|
+
return this.pdfParser;
|
|
339
|
+
}
|
|
340
|
+
async parsePdfBuffer(buffer) {
|
|
341
|
+
try {
|
|
342
|
+
const PDFParseClass = await this.getPdfParser();
|
|
343
|
+
const parser = new PDFParseClass({
|
|
344
|
+
data: buffer,
|
|
345
|
+
verbosity: 0,
|
|
346
|
+
});
|
|
347
|
+
const data = await parser.getText();
|
|
348
|
+
return data.text;
|
|
349
|
+
}
|
|
350
|
+
catch (error) {
|
|
351
|
+
logger.error(`Failed to parse PDF: ${error.message}`);
|
|
352
|
+
throw new Error(`PDF parsing failed: ${error.message}`);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
parseMarkdownText(markdown) {
|
|
356
|
+
const html = marked.parse(markdown);
|
|
357
|
+
if (typeof html !== 'string') {
|
|
358
|
+
return markdown;
|
|
359
|
+
}
|
|
360
|
+
return html
|
|
361
|
+
.replace(/<\s*br\s*\/?>/gi, '\n')
|
|
362
|
+
.replace(/<\/(p|li|h[1-6]|blockquote|pre|tr|table)>/gi, '\n')
|
|
363
|
+
.replace(/<[^>]+>/g, '')
|
|
364
|
+
.replace(/\n{3,}/g, '\n\n')
|
|
365
|
+
.trim();
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
DocumentFetcherService.CACHE_TTL_MS = 5 * 60 * 1000; // 5 minutes
|
|
369
|
+
// Store configured documents from config.al
|
|
370
|
+
let configuredDocuments = [];
|
|
371
|
+
export function registerConfiguredDocument(doc) {
|
|
372
|
+
// Check if already registered
|
|
373
|
+
const existing = configuredDocuments.find(d => d.title === doc.title);
|
|
374
|
+
if (!existing) {
|
|
375
|
+
configuredDocuments.push(doc);
|
|
376
|
+
logger.debug('Registered configured document', { title: doc.title, url: doc.url });
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
export function getConfiguredDocuments() {
|
|
380
|
+
return [...configuredDocuments];
|
|
381
|
+
}
|
|
382
|
+
export function clearConfiguredDocuments() {
|
|
383
|
+
configuredDocuments = [];
|
|
384
|
+
}
|
|
385
|
+
export const documentFetcher = new DocumentFetcherService();
|
|
386
|
+
export default documentFetcher;
|
|
387
|
+
//# sourceMappingURL=documentFetcher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"documentFetcher.js","sourceRoot":"","sources":["../../../src/runtime/services/documentFetcher.ts"],"names":[],"mappings":";;;;;;;AAAA,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAChE,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,yBAAyB,EAAE,MAAM,mBAAmB,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,O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gC,EAAE,EAAE,KAAK,EAAE,GAAG,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC;IACrF,CAAC;AACH,CAAC;AAED,MAAM,UAAU,sBAAsB;IACpC,OAAO,CAAC,GAAG,mBAAmB,CAAC,CAAC;AAClC,CAAC;AAED,MAAM,UAAU,wBAAwB;IACtC,mBAAmB,GAAG,EAAE,CAAC;AAC3B,CAAC;AAED,MAAM,CAAC,MAAM,eAAe,GAAG,IAAI,sBAAsB,EAAE,CAAC;AAC5D,eAAe,eAAe,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agentlang",
|
|
3
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.9.
|
|
4
|
+
"version": "0.9.10",
|
|
5
5
|
"license": "Sustainable Use License",
|
|
6
6
|
"author": "agentlang-ai",
|
|
7
7
|
"homepage": "https://github.com/agentlang-ai/agentlang#readme",
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@aws-sdk/client-cognito-identity": "^3.975.0",
|
|
39
39
|
"@aws-sdk/client-cognito-identity-provider": "^3.975.0",
|
|
40
|
+
"@aws-sdk/client-s3": "^3.975.0",
|
|
40
41
|
"@aws-sdk/credential-providers": "^3.975.0",
|
|
41
42
|
"@isomorphic-git/lightning-fs": "^4.6.2",
|
|
42
43
|
"@langchain/anthropic": "^1.3.12",
|
|
@@ -111,6 +111,7 @@ import { isMonitoringEnabled } from './state.js';
|
|
|
111
111
|
import { Monitor, MonitorEntry } from './monitor.js';
|
|
112
112
|
import { detailedDiff } from 'deep-object-diff';
|
|
113
113
|
import { callMcpTool, mcpClientNameFromToolEvent } from './mcpclient.js';
|
|
114
|
+
import { isNodeEnv } from '../utils/runtime.js';
|
|
114
115
|
|
|
115
116
|
export type Result = any;
|
|
116
117
|
|
|
@@ -1752,7 +1753,25 @@ export function isMcpEventInstance(inst: Instance): boolean {
|
|
|
1752
1753
|
}
|
|
1753
1754
|
|
|
1754
1755
|
async function handleDocEvent(inst: Instance, env: Environment): Promise<void> {
|
|
1755
|
-
const
|
|
1756
|
+
const url = inst.lookup('url');
|
|
1757
|
+
if (typeof url === 'string' && url.startsWith('s3://')) {
|
|
1758
|
+
if (!isNodeEnv) {
|
|
1759
|
+
throw new Error('Document fetching is only available in Node.js environment');
|
|
1760
|
+
}
|
|
1761
|
+
const title = inst.lookup('title');
|
|
1762
|
+
const retrievalConfig = inst.lookup('retrievalConfig');
|
|
1763
|
+
const embeddingConfig = inst.lookup('embeddingConfig');
|
|
1764
|
+
const { documentFetcher } = await import('./services/documentFetcher.js');
|
|
1765
|
+
await documentFetcher.fetchDocument({
|
|
1766
|
+
title,
|
|
1767
|
+
url,
|
|
1768
|
+
retrievalConfig,
|
|
1769
|
+
embeddingConfig,
|
|
1770
|
+
});
|
|
1771
|
+
return;
|
|
1772
|
+
}
|
|
1773
|
+
|
|
1774
|
+
const s = await fetchDoc(url);
|
|
1756
1775
|
if (s) {
|
|
1757
1776
|
const title = inst.lookup('title');
|
|
1758
1777
|
const doc = makeInstance(
|
|
@@ -30,8 +30,8 @@ import {
|
|
|
30
30
|
makeInstance,
|
|
31
31
|
newInstanceAttributes,
|
|
32
32
|
Record,
|
|
33
|
-
Retry,
|
|
34
33
|
resolveDocumentAliases,
|
|
34
|
+
Retry,
|
|
35
35
|
} from '../module.js';
|
|
36
36
|
import { provider } from '../agents/registry.js';
|
|
37
37
|
import {
|
|
@@ -66,6 +66,7 @@ import { FlowStep } from '../agents/flows.js';
|
|
|
66
66
|
import Handlebars from 'handlebars';
|
|
67
67
|
import { Statement } from '../../language/generated/ast.js';
|
|
68
68
|
import { isMonitoringEnabled, TtlCache } from '../state.js';
|
|
69
|
+
import { isNodeEnv } from '../../utils/runtime.js';
|
|
69
70
|
|
|
70
71
|
export const CoreAIModuleName = makeCoreModuleName('ai');
|
|
71
72
|
export const AgentEntityName = 'Agent';
|
|
@@ -74,27 +75,6 @@ export const AgentLearnerType = 'learner';
|
|
|
74
75
|
|
|
75
76
|
const AgentEvalType = 'eval';
|
|
76
77
|
|
|
77
|
-
function buildEmbeddingConfig(): object {
|
|
78
|
-
const config: any = {
|
|
79
|
-
provider: process.env.AGENTLANG_EMBEDDING_PROVIDER || 'openai',
|
|
80
|
-
model: process.env.AGENTLANG_EMBEDDING_MODEL || 'text-embedding-3-small',
|
|
81
|
-
chunkSize: 1000,
|
|
82
|
-
chunkOverlap: 200,
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
if (process.env.AGENTLANG_EMBEDDING_CHUNKSIZE) {
|
|
86
|
-
config.chunkSize = parseInt(process.env.AGENTLANG_EMBEDDING_CHUNKSIZE, 1000);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
if (process.env.AGENTLANG_EMBEDDING_CHUNKOVERLAP) {
|
|
90
|
-
config.chunkOverlap = parseInt(process.env.AGENTLANG_EMBEDDING_CHUNKOVERLAP, 200);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
return config;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const embeddingConfig = JSON.stringify(buildEmbeddingConfig());
|
|
97
|
-
|
|
98
78
|
export default `module ${CoreAIModuleName}
|
|
99
79
|
|
|
100
80
|
import "./modules/ai.js" @as ai
|
|
@@ -110,6 +90,7 @@ entity ${AgentEntityName} {
|
|
|
110
90
|
moduleName String @default("${CoreAIModuleName}"),
|
|
111
91
|
type @enum("chat", "planner", "flow-exec", "${AgentEvalType}", "${AgentLearnerType}") @default("chat"),
|
|
112
92
|
runWorkflows Boolean @default(true),
|
|
93
|
+
stateless Boolean @default(false),
|
|
113
94
|
instruction String @optional,
|
|
114
95
|
tools String @optional, // comma-separated list of tool names
|
|
115
96
|
documents String @optional, // comma-separated list of document names
|
|
@@ -138,12 +119,24 @@ workflow saveAgentChatSession {
|
|
|
138
119
|
entity Document {
|
|
139
120
|
title String @id,
|
|
140
121
|
content String,
|
|
141
|
-
|
|
122
|
+
embeddingConfig Map @optional,
|
|
123
|
+
@meta {"fullTextSearch": "*"}
|
|
142
124
|
}
|
|
143
125
|
|
|
144
126
|
event doc {
|
|
145
127
|
title String,
|
|
146
|
-
url String
|
|
128
|
+
url String,
|
|
129
|
+
config Map @optional,
|
|
130
|
+
retrievalConfig Map @optional,
|
|
131
|
+
embeddingConfig Map @optional
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
workflow processDoc {
|
|
135
|
+
// Fetch document from URL and create Document entity
|
|
136
|
+
// Supports: local paths, http/https URLs, s3:// URLs
|
|
137
|
+
// S3 config can be provided via retrievalConfig or env vars
|
|
138
|
+
// Embedding config can customize chunking behavior
|
|
139
|
+
await ai.fetchAndCreateDocument(doc.title, doc.url, doc.retrievalConfig, doc.embeddingConfig)
|
|
147
140
|
}
|
|
148
141
|
|
|
149
142
|
entity Directive {
|
|
@@ -301,6 +294,7 @@ export class AgentInstance {
|
|
|
301
294
|
flows: string | undefined;
|
|
302
295
|
validate: string | undefined;
|
|
303
296
|
retry: string | undefined;
|
|
297
|
+
stateless: boolean = false;
|
|
304
298
|
private toolsArray: string[] | undefined = undefined;
|
|
305
299
|
private hasModuleTools = false;
|
|
306
300
|
private withSession = true;
|
|
@@ -794,6 +788,9 @@ Only return a pure JSON object with no extra text, annotations etc.`;
|
|
|
794
788
|
isplnr = false;
|
|
795
789
|
}
|
|
796
790
|
}
|
|
791
|
+
if (this.stateless) {
|
|
792
|
+
this.withSession = false;
|
|
793
|
+
}
|
|
797
794
|
const monitoringEnabled = isMonitoringEnabled();
|
|
798
795
|
const sess: Instance | null = this.withSession ? await findAgentChatSession(chatId, env) : null;
|
|
799
796
|
let msgs: BaseMessage[] | undefined;
|
|
@@ -1387,3 +1384,63 @@ export async function processAgentLearning(
|
|
|
1387
1384
|
await parseAndInternAgentLearning(moduleName, agentName, learning, env);
|
|
1388
1385
|
return { agentLearning: { result: learning } };
|
|
1389
1386
|
}
|
|
1387
|
+
|
|
1388
|
+
export async function fetchAndCreateDocument(
|
|
1389
|
+
title: string,
|
|
1390
|
+
url: string,
|
|
1391
|
+
retrievalConfig: Map<string, any> | undefined,
|
|
1392
|
+
embeddingConfig: Map<string, any> | undefined,
|
|
1393
|
+
_env: Environment
|
|
1394
|
+
): Promise<any> {
|
|
1395
|
+
if (!isNodeEnv) {
|
|
1396
|
+
throw new Error('Document fetching is only available in Node.js environment');
|
|
1397
|
+
}
|
|
1398
|
+
|
|
1399
|
+
const { documentFetcher } = await import('../services/documentFetcher.js');
|
|
1400
|
+
|
|
1401
|
+
const config: any = {
|
|
1402
|
+
title,
|
|
1403
|
+
url,
|
|
1404
|
+
};
|
|
1405
|
+
|
|
1406
|
+
if (retrievalConfig) {
|
|
1407
|
+
const provider = retrievalConfig.get('provider');
|
|
1408
|
+
const providerConfig = retrievalConfig.get('config');
|
|
1409
|
+
|
|
1410
|
+
config.retrievalConfig = {
|
|
1411
|
+
provider: provider || 's3',
|
|
1412
|
+
config: providerConfig
|
|
1413
|
+
? {
|
|
1414
|
+
region: providerConfig.get('region'),
|
|
1415
|
+
endpoint: providerConfig.get('endpoint'),
|
|
1416
|
+
accessKeyId: providerConfig.get('accessKeyId'),
|
|
1417
|
+
secretAccessKey: providerConfig.get('secretAccessKey'),
|
|
1418
|
+
forcePathStyle: providerConfig.get('forcePathStyle'),
|
|
1419
|
+
}
|
|
1420
|
+
: {},
|
|
1421
|
+
};
|
|
1422
|
+
}
|
|
1423
|
+
|
|
1424
|
+
if (embeddingConfig) {
|
|
1425
|
+
config.embeddingConfig = {
|
|
1426
|
+
provider: embeddingConfig.get('provider'),
|
|
1427
|
+
model: embeddingConfig.get('model'),
|
|
1428
|
+
chunkSize: embeddingConfig.get('chunkSize'),
|
|
1429
|
+
chunkOverlap: embeddingConfig.get('chunkOverlap'),
|
|
1430
|
+
};
|
|
1431
|
+
}
|
|
1432
|
+
|
|
1433
|
+
const document = await documentFetcher.fetchDocument(config);
|
|
1434
|
+
|
|
1435
|
+
if (document) {
|
|
1436
|
+
return {
|
|
1437
|
+
document: {
|
|
1438
|
+
title: document.title,
|
|
1439
|
+
url: document.url,
|
|
1440
|
+
format: document.format,
|
|
1441
|
+
},
|
|
1442
|
+
};
|
|
1443
|
+
} else {
|
|
1444
|
+
throw new Error(`Failed to fetch document: ${title} from ${url}`);
|
|
1445
|
+
}
|
|
1446
|
+
}
|