veryfront 0.1.932 → 0.1.933
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/esm/deno.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rag-store.d.ts","sourceRoot":"","sources":["../../../../src/src/embedding/veryfront-cloud/rag-store.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAIV,QAAQ,EACR,cAAc,EACf,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"rag-store.d.ts","sourceRoot":"","sources":["../../../../src/src/embedding/veryfront-cloud/rag-store.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAIV,QAAQ,EACR,cAAc,EACf,MAAM,aAAa,CAAC;AA4ErB,KAAK,2BAA2B,GAAG,cAAc,GAAG;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AA6gBtE,wBAAgB,4BAA4B,CAAC,MAAM,EAAE,2BAA2B,GAAG,QAAQ,CA6H1F"}
|
|
@@ -102,6 +102,7 @@ async function requestJson(context, path, init, options) {
|
|
|
102
102
|
}
|
|
103
103
|
function getCloudStoreContext(config) {
|
|
104
104
|
const bootstrap = requireVeryfrontCloudBootstrap();
|
|
105
|
+
const requestContext = getCurrentRequestContext();
|
|
105
106
|
if (!bootstrap.projectSlug) {
|
|
106
107
|
throw INVALID_ARGUMENT.create({
|
|
107
108
|
detail: "VERYFRONT_PROJECT_SLUG not set. Set the environment variable or runtime projectSlug before using the veryfront-cloud RAG store.",
|
|
@@ -111,7 +112,10 @@ function getCloudStoreContext(config) {
|
|
|
111
112
|
apiBaseUrl: bootstrap.apiBaseUrl,
|
|
112
113
|
fetch: createVeryfrontCloudFetch(bootstrap.apiToken),
|
|
113
114
|
projectSlug: bootstrap.projectSlug,
|
|
114
|
-
branch: config.branch ??
|
|
115
|
+
branch: config.branch ?? requestContext?.branch ?? "main",
|
|
116
|
+
environmentName: requestContext?.environmentName ?? null,
|
|
117
|
+
hasRequestContext: requestContext !== null,
|
|
118
|
+
releaseId: requestContext?.releaseId ?? null,
|
|
115
119
|
};
|
|
116
120
|
}
|
|
117
121
|
function getFileChunksPath(context, filePath) {
|
|
@@ -258,7 +262,7 @@ async function listContentFiles(contentDir, contentExtensions) {
|
|
|
258
262
|
files.push(...(await listContentFiles(fullPath, contentExtensions)));
|
|
259
263
|
}
|
|
260
264
|
else if (entry.isFile && contentExtensions.has(extname(entry.name))) {
|
|
261
|
-
files.push(fullPath);
|
|
265
|
+
files.push({ path: fullPath });
|
|
262
266
|
}
|
|
263
267
|
}
|
|
264
268
|
}
|
|
@@ -267,6 +271,67 @@ async function listContentFiles(contentDir, contentExtensions) {
|
|
|
267
271
|
}
|
|
268
272
|
return files;
|
|
269
273
|
}
|
|
274
|
+
function buildContentDirPattern(contentDir) {
|
|
275
|
+
return `${contentDir.replace(/\/+$/, "")}/**`;
|
|
276
|
+
}
|
|
277
|
+
function buildContentFilesQuery(context, contentDir, cursor) {
|
|
278
|
+
const params = new URLSearchParams({
|
|
279
|
+
include_server_functions: "true",
|
|
280
|
+
limit: "100",
|
|
281
|
+
pattern: buildContentDirPattern(contentDir),
|
|
282
|
+
});
|
|
283
|
+
if (!context.releaseId && !context.environmentName) {
|
|
284
|
+
params.set("branch", context.branch);
|
|
285
|
+
}
|
|
286
|
+
if (cursor) {
|
|
287
|
+
params.set("cursor", cursor);
|
|
288
|
+
}
|
|
289
|
+
return params.toString();
|
|
290
|
+
}
|
|
291
|
+
function getPublishedFileListPath(context, contentDir, cursor) {
|
|
292
|
+
const query = buildContentFilesQuery(context, contentDir, cursor);
|
|
293
|
+
const projectRef = encodeURIComponent(context.projectSlug);
|
|
294
|
+
if (context.releaseId) {
|
|
295
|
+
return `/projects/${projectRef}/releases/${encodeURIComponent(context.releaseId)}/files?${query}`;
|
|
296
|
+
}
|
|
297
|
+
if (context.environmentName) {
|
|
298
|
+
return `/projects/${projectRef}/environments/${encodeURIComponent(context.environmentName)}/files?${query}`;
|
|
299
|
+
}
|
|
300
|
+
return `/projects/${projectRef}/files?${query}`;
|
|
301
|
+
}
|
|
302
|
+
function getPublishedFileDetailPath(context, path) {
|
|
303
|
+
const query = new URLSearchParams({ include_server_functions: "true" });
|
|
304
|
+
const projectRef = encodeURIComponent(context.projectSlug);
|
|
305
|
+
const encodedPath = encodeURIComponent(path);
|
|
306
|
+
if (context.releaseId) {
|
|
307
|
+
return `/projects/${projectRef}/releases/${encodeURIComponent(context.releaseId)}/files/${encodedPath}?${query}`;
|
|
308
|
+
}
|
|
309
|
+
if (context.environmentName) {
|
|
310
|
+
return `/projects/${projectRef}/environments/${encodeURIComponent(context.environmentName)}/files/${encodedPath}?${query}`;
|
|
311
|
+
}
|
|
312
|
+
query.set("branch", context.branch);
|
|
313
|
+
return `/projects/${projectRef}/files/${encodedPath}?${query}`;
|
|
314
|
+
}
|
|
315
|
+
async function listPublishedContentFiles(context, contentDir, contentExtensions) {
|
|
316
|
+
const files = [];
|
|
317
|
+
let cursor;
|
|
318
|
+
do {
|
|
319
|
+
const response = await requestJson(context, getPublishedFileListPath(context, contentDir, cursor));
|
|
320
|
+
files.push(...(response?.data ?? [])
|
|
321
|
+
.filter((file) => contentExtensions.has(extname(file.path)))
|
|
322
|
+
.map((file) => ({ path: file.path, content: file.content })));
|
|
323
|
+
cursor = response?.page_info?.next ?? null;
|
|
324
|
+
} while (cursor);
|
|
325
|
+
return files;
|
|
326
|
+
}
|
|
327
|
+
async function readContentFile(context, file) {
|
|
328
|
+
if (file.content !== undefined)
|
|
329
|
+
return file.content;
|
|
330
|
+
if (!context.hasRequestContext)
|
|
331
|
+
return readTextFile(file.path);
|
|
332
|
+
const response = await requestJson(context, getPublishedFileDetailPath(context, file.path));
|
|
333
|
+
return response?.content ?? "";
|
|
334
|
+
}
|
|
270
335
|
export function createVeryfrontCloudRagStore(config) {
|
|
271
336
|
const contentDir = config.contentDir;
|
|
272
337
|
const contentExtensions = new Set(config.contentExtensions ?? [".md", ".mdx", ".txt"]);
|
|
@@ -341,22 +406,24 @@ export function createVeryfrontCloudRagStore(config) {
|
|
|
341
406
|
const context = getCloudStoreContext(config);
|
|
342
407
|
const existingDocuments = await listRagDocuments(context);
|
|
343
408
|
const indexedSources = new Set(existingDocuments.map((doc) => doc.source));
|
|
344
|
-
const files =
|
|
345
|
-
|
|
409
|
+
const files = context.hasRequestContext
|
|
410
|
+
? await listPublishedContentFiles(context, contentDir, contentExtensions)
|
|
411
|
+
: await listContentFiles(contentDir, contentExtensions);
|
|
412
|
+
const newFiles = files.filter((file) => !indexedSources.has(file.path));
|
|
346
413
|
for (const file of newFiles) {
|
|
347
|
-
const content = await
|
|
414
|
+
const content = await readContentFile(context, file);
|
|
348
415
|
if (!content?.trim())
|
|
349
416
|
continue;
|
|
350
417
|
if (content.length > MAX_TEXT_LENGTH) {
|
|
351
|
-
serverLogger.warn(`[rag-store/cloud] Skipping ${file}: exceeds ${MAX_TEXT_LENGTH / 1024 / 1024} MB text limit`);
|
|
418
|
+
serverLogger.warn(`[rag-store/cloud] Skipping ${file.path}: exceeds ${MAX_TEXT_LENGTH / 1024 / 1024} MB text limit`);
|
|
352
419
|
continue;
|
|
353
420
|
}
|
|
354
|
-
const title = file.startsWith(contentDir + "/")
|
|
355
|
-
? file.slice(contentDir.length + 1).replace(/\.[^.]+$/, "")
|
|
356
|
-
: file.replace(/\.[^.]+$/, "");
|
|
357
|
-
const type = extname(file).slice(1);
|
|
421
|
+
const title = file.path.startsWith(contentDir + "/")
|
|
422
|
+
? file.path.slice(contentDir.length + 1).replace(/\.[^.]+$/, "")
|
|
423
|
+
: file.path.replace(/\.[^.]+$/, "");
|
|
424
|
+
const type = extname(file.path).slice(1);
|
|
358
425
|
await ingestDocument(context, config, title, content, {
|
|
359
|
-
source: file,
|
|
426
|
+
source: file.path,
|
|
360
427
|
type,
|
|
361
428
|
});
|
|
362
429
|
}
|