@absolutejs/absolute 0.19.0-beta.498 → 0.19.0-beta.499
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/dist/ai/client/index.js +7 -3
- package/dist/ai/client/index.js.map +3 -3
- package/dist/ai/index.js +330 -61
- package/dist/ai/index.js.map +6 -6
- package/dist/ai-client/angular/ai/index.js +10 -6
- package/dist/ai-client/react/ai/index.js +6 -2
- package/dist/ai-client/vue/ai/index.js +6 -2
- package/dist/angular/ai/index.js +11 -7
- package/dist/angular/ai/index.js.map +4 -4
- package/dist/react/ai/index.js +7 -3
- package/dist/react/ai/index.js.map +3 -3
- package/dist/src/ai/client/ragClient.d.ts +3 -3
- package/dist/src/ai/index.d.ts +2 -2
- package/dist/src/ai/rag/index.d.ts +2 -2
- package/dist/src/ai/rag/sync.d.ts +6 -1
- package/dist/src/ai/rag/types.d.ts +1 -1
- package/dist/src/angular/ai/rag-client.service.d.ts +3 -3
- package/dist/src/react/ai/useRAG.d.ts +8 -0
- package/dist/src/react/ai/useRAGIndexAdmin.d.ts +8 -0
- package/dist/src/svelte/ai/createRAG.d.ts +8 -0
- package/dist/src/svelte/ai/createRAGIndexAdmin.d.ts +8 -0
- package/dist/src/vue/ai/useRAG.d.ts +46 -0
- package/dist/src/vue/ai/useRAGIndexAdmin.d.ts +36 -0
- package/dist/src/vue/ai/useRAGOps.d.ts +10 -0
- package/dist/svelte/ai/index.js +7 -3
- package/dist/svelte/ai/index.js.map +3 -3
- package/dist/types/ai.d.ts +44 -2
- package/dist/vue/ai/index.js +7 -3
- package/dist/vue/ai/index.js.map +3 -3
- package/package.json +1 -1
package/dist/ai/index.js
CHANGED
|
@@ -4846,6 +4846,12 @@ var normalizeStringArray2 = (value) => {
|
|
|
4846
4846
|
};
|
|
4847
4847
|
var normalizeChunkingOptions = (value) => isMetadataMap(value) ? value : undefined;
|
|
4848
4848
|
var getNumericStatus = (status) => typeof status === "number" ? status : HTTP_STATUS_OK;
|
|
4849
|
+
var getBooleanProperty = (value, key) => {
|
|
4850
|
+
if (!isObjectRecord(value)) {
|
|
4851
|
+
return;
|
|
4852
|
+
}
|
|
4853
|
+
return typeof value[key] === "boolean" ? value[key] : undefined;
|
|
4854
|
+
};
|
|
4849
4855
|
var isRAGDocumentChunk = (value) => isObjectRecord(value) && typeof value.chunkId === "string" && typeof value.text === "string";
|
|
4850
4856
|
var isRAGDocument = (value) => isObjectRecord(value) && typeof value.text === "string";
|
|
4851
4857
|
var isRAGDocumentUrl = (value) => isObjectRecord(value) && typeof value.url === "string" && value.url.trim().length > 0;
|
|
@@ -5836,7 +5842,7 @@ var ragChat = (config) => {
|
|
|
5836
5842
|
sources: await indexManager.listSyncSources()
|
|
5837
5843
|
};
|
|
5838
5844
|
};
|
|
5839
|
-
const handleSyncAllSources = async () => {
|
|
5845
|
+
const handleSyncAllSources = async (options) => {
|
|
5840
5846
|
if (!indexManager?.syncAllSources) {
|
|
5841
5847
|
return {
|
|
5842
5848
|
error: "RAG source sync is not configured",
|
|
@@ -5844,14 +5850,28 @@ var ragChat = (config) => {
|
|
|
5844
5850
|
};
|
|
5845
5851
|
}
|
|
5846
5852
|
const job = createAdminJob("sync_all_sources", undefined, syncJobs);
|
|
5853
|
+
const action = createAdminAction("sync_all_sources");
|
|
5847
5854
|
try {
|
|
5848
|
-
const result = await indexManager.syncAllSources();
|
|
5849
|
-
const action = createAdminAction("sync_all_sources");
|
|
5850
|
-
completeAdminJob(job);
|
|
5851
|
-
completeAdminAction(action);
|
|
5855
|
+
const result = await indexManager.syncAllSources(options);
|
|
5852
5856
|
if (result && "ok" in result) {
|
|
5857
|
+
if (!result.ok) {
|
|
5858
|
+
failAdminJob(job, result.error);
|
|
5859
|
+
failAdminAction(action, result.error);
|
|
5860
|
+
return result;
|
|
5861
|
+
}
|
|
5862
|
+
if (result.partial) {
|
|
5863
|
+
const failedSourceIds = "sources" in result ? result.failedSourceIds : undefined;
|
|
5864
|
+
const message = failedSourceIds?.length ? `Partial source sync failure: ${failedSourceIds.join(", ")}` : "Partial source sync failure";
|
|
5865
|
+
failAdminJob(job, message);
|
|
5866
|
+
failAdminAction(action, message);
|
|
5867
|
+
return result;
|
|
5868
|
+
}
|
|
5869
|
+
completeAdminJob(job);
|
|
5870
|
+
completeAdminAction(action);
|
|
5853
5871
|
return result;
|
|
5854
5872
|
}
|
|
5873
|
+
completeAdminJob(job);
|
|
5874
|
+
completeAdminAction(action);
|
|
5855
5875
|
return {
|
|
5856
5876
|
ok: true,
|
|
5857
5877
|
sources: await buildSyncSources()
|
|
@@ -5859,12 +5879,11 @@ var ragChat = (config) => {
|
|
|
5859
5879
|
} catch (caught) {
|
|
5860
5880
|
const message = caught instanceof Error ? caught.message : String(caught);
|
|
5861
5881
|
failAdminJob(job, message);
|
|
5862
|
-
const action = createAdminAction("sync_all_sources");
|
|
5863
5882
|
failAdminAction(action, message);
|
|
5864
5883
|
throw caught;
|
|
5865
5884
|
}
|
|
5866
5885
|
};
|
|
5867
|
-
const handleSyncSource = async (id) => {
|
|
5886
|
+
const handleSyncSource = async (id, options) => {
|
|
5868
5887
|
if (!indexManager?.syncSource) {
|
|
5869
5888
|
return {
|
|
5870
5889
|
error: "RAG source sync is not configured",
|
|
@@ -5878,14 +5897,21 @@ var ragChat = (config) => {
|
|
|
5878
5897
|
};
|
|
5879
5898
|
}
|
|
5880
5899
|
const job = createAdminJob("sync_source", id, syncJobs);
|
|
5900
|
+
const action = createAdminAction("sync_source", undefined, id);
|
|
5881
5901
|
try {
|
|
5882
|
-
const result = await indexManager.syncSource(id);
|
|
5883
|
-
const action = createAdminAction("sync_source", undefined, id);
|
|
5884
|
-
completeAdminJob(job);
|
|
5885
|
-
completeAdminAction(action);
|
|
5902
|
+
const result = await indexManager.syncSource(id, options);
|
|
5886
5903
|
if (result && "ok" in result) {
|
|
5904
|
+
if (!result.ok) {
|
|
5905
|
+
failAdminJob(job, result.error);
|
|
5906
|
+
failAdminAction(action, result.error);
|
|
5907
|
+
return result;
|
|
5908
|
+
}
|
|
5909
|
+
completeAdminJob(job);
|
|
5910
|
+
completeAdminAction(action);
|
|
5887
5911
|
return result;
|
|
5888
5912
|
}
|
|
5913
|
+
completeAdminJob(job);
|
|
5914
|
+
completeAdminAction(action);
|
|
5889
5915
|
const source = (await buildSyncSources()).find((record) => record.id === id);
|
|
5890
5916
|
return source ? { ok: true, source } : {
|
|
5891
5917
|
error: "sync source not found",
|
|
@@ -5894,7 +5920,6 @@ var ragChat = (config) => {
|
|
|
5894
5920
|
} catch (caught) {
|
|
5895
5921
|
const message = caught instanceof Error ? caught.message : String(caught);
|
|
5896
5922
|
failAdminJob(job, message);
|
|
5897
|
-
const action = createAdminAction("sync_source", undefined, id);
|
|
5898
5923
|
failAdminAction(action, message);
|
|
5899
5924
|
throw caught;
|
|
5900
5925
|
}
|
|
@@ -6150,30 +6175,32 @@ var ragChat = (config) => {
|
|
|
6150
6175
|
}));
|
|
6151
6176
|
}
|
|
6152
6177
|
return result;
|
|
6153
|
-
}).post(`${path}/sync`, async ({ request, set }) => {
|
|
6154
|
-
const
|
|
6178
|
+
}).post(`${path}/sync`, async ({ body, request, set }) => {
|
|
6179
|
+
const background = getBooleanProperty(body, "background");
|
|
6180
|
+
const result = await handleSyncAllSources({ background });
|
|
6155
6181
|
if (!result.ok) {
|
|
6156
6182
|
set.status = HTTP_STATUS_NOT_FOUND;
|
|
6157
6183
|
}
|
|
6158
6184
|
if (config.htmx && isHTMXRequest(request)) {
|
|
6159
6185
|
const html = result.ok ? workflowRenderers.mutationResult({
|
|
6160
6186
|
ok: true,
|
|
6161
|
-
status: "source sync started and completed successfully"
|
|
6187
|
+
status: background === true ? "source sync queued in the background" : "source sync started and completed successfully"
|
|
6162
6188
|
}) : workflowRenderers.error(result.error ?? "Failed to sync sources");
|
|
6163
6189
|
return toHTMXResponse(html, getNumericStatus(set.status), {
|
|
6164
6190
|
"HX-Trigger": "rag:mutated"
|
|
6165
6191
|
});
|
|
6166
6192
|
}
|
|
6167
6193
|
return result;
|
|
6168
|
-
}).post(`${path}/sync/:id`, async ({ params, request, set }) => {
|
|
6169
|
-
const
|
|
6194
|
+
}).post(`${path}/sync/:id`, async ({ body, params, request, set }) => {
|
|
6195
|
+
const background = getBooleanProperty(body, "background");
|
|
6196
|
+
const result = await handleSyncSource(typeof params.id === "string" ? params.id.trim() : "", { background });
|
|
6170
6197
|
if (!result.ok) {
|
|
6171
6198
|
set.status = result.error === "sync source id is required" ? HTTP_STATUS_BAD_REQUEST : HTTP_STATUS_NOT_FOUND;
|
|
6172
6199
|
}
|
|
6173
6200
|
if (config.htmx && isHTMXRequest(request)) {
|
|
6174
6201
|
const html = result.ok ? workflowRenderers.mutationResult({
|
|
6175
6202
|
ok: true,
|
|
6176
|
-
status: "source sync started and completed successfully"
|
|
6203
|
+
status: background === true ? "source sync queued in the background" : "source sync started and completed successfully"
|
|
6177
6204
|
}) : workflowRenderers.error(result.error ?? "Failed to sync source");
|
|
6178
6205
|
return toHTMXResponse(html, getNumericStatus(set.status), {
|
|
6179
6206
|
"HX-Trigger": "rag:mutated"
|
|
@@ -7160,7 +7187,23 @@ var resolveRAGStreamStage = ({
|
|
|
7160
7187
|
};
|
|
7161
7188
|
// src/ai/rag/sync.ts
|
|
7162
7189
|
import { createHash } from "crypto";
|
|
7190
|
+
import { mkdir, readFile as readFile2, writeFile } from "fs/promises";
|
|
7191
|
+
import { dirname, resolve as resolve2 } from "path";
|
|
7163
7192
|
var toSyncError = (caught) => caught instanceof Error ? caught.message : String(caught);
|
|
7193
|
+
var wait = async (delayMs) => {
|
|
7194
|
+
if (!(delayMs > 0)) {
|
|
7195
|
+
return;
|
|
7196
|
+
}
|
|
7197
|
+
await new Promise((resolve3) => setTimeout(resolve3, delayMs));
|
|
7198
|
+
};
|
|
7199
|
+
var parseSyncState = (content) => {
|
|
7200
|
+
try {
|
|
7201
|
+
const parsed = JSON.parse(content);
|
|
7202
|
+
return Array.isArray(parsed) ? parsed : [];
|
|
7203
|
+
} catch {
|
|
7204
|
+
return [];
|
|
7205
|
+
}
|
|
7206
|
+
};
|
|
7164
7207
|
var createSyncFingerprint = (document) => createHash("sha1").update(document.source ?? "").update(`
|
|
7165
7208
|
`).update(document.title ?? "").update(`
|
|
7166
7209
|
`).update(document.text).digest("hex");
|
|
@@ -7227,6 +7270,8 @@ var createRAGDirectorySyncSource = (options) => ({
|
|
|
7227
7270
|
kind: "directory",
|
|
7228
7271
|
label: options.label,
|
|
7229
7272
|
metadata: options.metadata,
|
|
7273
|
+
retryAttempts: options.retryAttempts,
|
|
7274
|
+
retryDelayMs: options.retryDelayMs,
|
|
7230
7275
|
target: options.directory,
|
|
7231
7276
|
sync: async ({ collection, deleteDocument, listDocuments }) => {
|
|
7232
7277
|
const loaded = await loadRAGDocumentsFromDirectory({
|
|
@@ -7263,6 +7308,8 @@ var createRAGUrlSyncSource = (options) => ({
|
|
|
7263
7308
|
kind: "url",
|
|
7264
7309
|
label: options.label,
|
|
7265
7310
|
metadata: options.metadata,
|
|
7311
|
+
retryAttempts: options.retryAttempts,
|
|
7312
|
+
retryDelayMs: options.retryDelayMs,
|
|
7266
7313
|
target: options.urls.length === 1 ? options.urls[0]?.url : `${options.urls.length} urls`,
|
|
7267
7314
|
sync: async ({ collection, deleteDocument, listDocuments }) => {
|
|
7268
7315
|
const loaded = await loadRAGDocumentsFromURLs({
|
|
@@ -7293,51 +7340,176 @@ var createRAGUrlSyncSource = (options) => ({
|
|
|
7293
7340
|
var createRAGSyncManager = (options) => {
|
|
7294
7341
|
const sourceMap = new Map(options.sources.map((source) => [source.id, source]));
|
|
7295
7342
|
const state = new Map(options.sources.map((source) => [source.id, toSourceRecord(source)]));
|
|
7343
|
+
const activeRuns = new Map;
|
|
7344
|
+
let hydrationPromise = null;
|
|
7345
|
+
const persistState = async () => {
|
|
7346
|
+
if (!options.saveState) {
|
|
7347
|
+
return;
|
|
7348
|
+
}
|
|
7349
|
+
await options.saveState([...state.values()]);
|
|
7350
|
+
};
|
|
7351
|
+
const ensureHydrated = async () => {
|
|
7352
|
+
if (!options.loadState) {
|
|
7353
|
+
return;
|
|
7354
|
+
}
|
|
7355
|
+
if (!hydrationPromise) {
|
|
7356
|
+
hydrationPromise = Promise.resolve(options.loadState()).then((records) => {
|
|
7357
|
+
for (const record of records ?? []) {
|
|
7358
|
+
const source = sourceMap.get(record.id);
|
|
7359
|
+
if (!source) {
|
|
7360
|
+
continue;
|
|
7361
|
+
}
|
|
7362
|
+
state.set(record.id, toSourceRecord(source, {
|
|
7363
|
+
...record,
|
|
7364
|
+
metadata: {
|
|
7365
|
+
...source.metadata ?? {},
|
|
7366
|
+
...record.metadata ?? {}
|
|
7367
|
+
}
|
|
7368
|
+
}));
|
|
7369
|
+
}
|
|
7370
|
+
});
|
|
7371
|
+
}
|
|
7372
|
+
await hydrationPromise;
|
|
7373
|
+
};
|
|
7374
|
+
const resolveRetryAttempts = (source) => Math.max(0, source.retryAttempts ?? options.retryAttempts ?? 0);
|
|
7375
|
+
const resolveRetryDelayMs = (source) => Math.max(0, source.retryDelayMs ?? options.retryDelayMs ?? 0);
|
|
7376
|
+
const setSourceState = async (record) => {
|
|
7377
|
+
state.set(record.id, record);
|
|
7378
|
+
await persistState();
|
|
7379
|
+
};
|
|
7296
7380
|
const runSource = async (source) => {
|
|
7381
|
+
await ensureHydrated();
|
|
7382
|
+
const existingRun = activeRuns.get(source.id);
|
|
7383
|
+
if (existingRun) {
|
|
7384
|
+
return existingRun;
|
|
7385
|
+
}
|
|
7386
|
+
const previous = state.get(source.id);
|
|
7387
|
+
const retryAttempts = resolveRetryAttempts(source);
|
|
7388
|
+
const retryDelayMs = resolveRetryDelayMs(source);
|
|
7389
|
+
const startedAt = Date.now();
|
|
7297
7390
|
const running = toSourceRecord(source, {
|
|
7391
|
+
chunkCount: previous?.chunkCount,
|
|
7392
|
+
consecutiveFailures: previous?.consecutiveFailures ?? 0,
|
|
7393
|
+
documentCount: previous?.documentCount,
|
|
7298
7394
|
lastError: undefined,
|
|
7395
|
+
lastStartedAt: startedAt,
|
|
7396
|
+
lastSuccessfulSyncAt: previous?.lastSuccessfulSyncAt,
|
|
7397
|
+
lastSyncedAt: previous?.lastSyncedAt,
|
|
7398
|
+
lastSyncDurationMs: previous?.lastSyncDurationMs,
|
|
7399
|
+
nextRetryAt: undefined,
|
|
7400
|
+
retryAttempts,
|
|
7299
7401
|
status: "running"
|
|
7300
7402
|
});
|
|
7301
|
-
|
|
7302
|
-
|
|
7303
|
-
|
|
7304
|
-
|
|
7305
|
-
|
|
7306
|
-
|
|
7307
|
-
|
|
7308
|
-
|
|
7309
|
-
|
|
7310
|
-
|
|
7311
|
-
|
|
7312
|
-
|
|
7313
|
-
|
|
7314
|
-
|
|
7315
|
-
|
|
7316
|
-
|
|
7317
|
-
|
|
7318
|
-
|
|
7319
|
-
|
|
7320
|
-
|
|
7321
|
-
|
|
7322
|
-
|
|
7323
|
-
|
|
7324
|
-
|
|
7325
|
-
|
|
7326
|
-
|
|
7327
|
-
|
|
7328
|
-
|
|
7329
|
-
|
|
7330
|
-
|
|
7331
|
-
|
|
7332
|
-
|
|
7403
|
+
const runPromise = (async () => {
|
|
7404
|
+
await setSourceState(running);
|
|
7405
|
+
for (let attempt = 0;attempt <= retryAttempts; attempt++) {
|
|
7406
|
+
try {
|
|
7407
|
+
const result = await source.sync({
|
|
7408
|
+
collection: options.collection,
|
|
7409
|
+
deleteDocument: options.deleteDocument,
|
|
7410
|
+
listDocuments: options.listDocuments
|
|
7411
|
+
});
|
|
7412
|
+
const finishedAt = Date.now();
|
|
7413
|
+
const completed = toSourceRecord(source, {
|
|
7414
|
+
chunkCount: result.chunkCount,
|
|
7415
|
+
consecutiveFailures: 0,
|
|
7416
|
+
documentCount: result.documentCount,
|
|
7417
|
+
lastError: undefined,
|
|
7418
|
+
lastStartedAt: startedAt,
|
|
7419
|
+
lastSuccessfulSyncAt: finishedAt,
|
|
7420
|
+
lastSyncedAt: finishedAt,
|
|
7421
|
+
lastSyncDurationMs: finishedAt - startedAt,
|
|
7422
|
+
metadata: result.metadata === undefined ? source.metadata : {
|
|
7423
|
+
...source.metadata ?? {},
|
|
7424
|
+
...result.metadata
|
|
7425
|
+
},
|
|
7426
|
+
nextRetryAt: undefined,
|
|
7427
|
+
retryAttempts,
|
|
7428
|
+
status: "completed"
|
|
7429
|
+
});
|
|
7430
|
+
await setSourceState(completed);
|
|
7431
|
+
return completed;
|
|
7432
|
+
} catch (caught) {
|
|
7433
|
+
const message = toSyncError(caught);
|
|
7434
|
+
const finishedAt = Date.now();
|
|
7435
|
+
const hasRetriesRemaining = attempt < retryAttempts;
|
|
7436
|
+
const consecutiveFailures = (previous?.consecutiveFailures ?? 0) + attempt + 1;
|
|
7437
|
+
const failed = toSourceRecord(source, {
|
|
7438
|
+
chunkCount: previous?.chunkCount,
|
|
7439
|
+
consecutiveFailures,
|
|
7440
|
+
documentCount: previous?.documentCount,
|
|
7441
|
+
lastError: message,
|
|
7442
|
+
lastStartedAt: startedAt,
|
|
7443
|
+
lastSuccessfulSyncAt: previous?.lastSuccessfulSyncAt,
|
|
7444
|
+
lastSyncedAt: finishedAt,
|
|
7445
|
+
lastSyncDurationMs: finishedAt - startedAt,
|
|
7446
|
+
nextRetryAt: hasRetriesRemaining ? finishedAt + retryDelayMs : undefined,
|
|
7447
|
+
retryAttempts,
|
|
7448
|
+
status: "failed"
|
|
7449
|
+
});
|
|
7450
|
+
await setSourceState(failed);
|
|
7451
|
+
if (!hasRetriesRemaining) {
|
|
7452
|
+
return failed;
|
|
7453
|
+
}
|
|
7454
|
+
await wait(retryDelayMs);
|
|
7455
|
+
}
|
|
7456
|
+
}
|
|
7457
|
+
return state.get(source.id) ?? toSourceRecord(source, { status: "failed" });
|
|
7458
|
+
})().finally(() => {
|
|
7459
|
+
activeRuns.delete(source.id);
|
|
7460
|
+
});
|
|
7461
|
+
activeRuns.set(source.id, runPromise);
|
|
7462
|
+
return runPromise;
|
|
7333
7463
|
};
|
|
7464
|
+
const resolveBackground = (runOptions) => runOptions?.background ?? options.backgroundByDefault ?? false;
|
|
7334
7465
|
return {
|
|
7335
|
-
listSyncSources: () =>
|
|
7336
|
-
|
|
7337
|
-
|
|
7338
|
-
|
|
7466
|
+
listSyncSources: async () => {
|
|
7467
|
+
await ensureHydrated();
|
|
7468
|
+
return [...state.values()];
|
|
7469
|
+
},
|
|
7470
|
+
syncAllSources: async (runOptions) => {
|
|
7471
|
+
await ensureHydrated();
|
|
7472
|
+
if (resolveBackground(runOptions)) {
|
|
7473
|
+
for (const source of options.sources) {
|
|
7474
|
+
runSource(source);
|
|
7475
|
+
}
|
|
7476
|
+
return {
|
|
7477
|
+
ok: true,
|
|
7478
|
+
sources: [...state.values()]
|
|
7479
|
+
};
|
|
7480
|
+
}
|
|
7481
|
+
const sources = [];
|
|
7482
|
+
const failedSourceIds = [];
|
|
7483
|
+
const errorsBySource = {};
|
|
7484
|
+
for (const source of options.sources) {
|
|
7485
|
+
const record = await runSource(source);
|
|
7486
|
+
sources.push(record);
|
|
7487
|
+
if (record.status === "failed") {
|
|
7488
|
+
failedSourceIds.push(record.id);
|
|
7489
|
+
if (record.lastError) {
|
|
7490
|
+
errorsBySource[record.id] = record.lastError;
|
|
7491
|
+
}
|
|
7492
|
+
if (options.continueOnError === false) {
|
|
7493
|
+
return {
|
|
7494
|
+
errorsBySource,
|
|
7495
|
+
failedSourceIds,
|
|
7496
|
+
ok: true,
|
|
7497
|
+
partial: true,
|
|
7498
|
+
sources
|
|
7499
|
+
};
|
|
7500
|
+
}
|
|
7501
|
+
}
|
|
7502
|
+
}
|
|
7503
|
+
return {
|
|
7504
|
+
errorsBySource: failedSourceIds.length > 0 ? errorsBySource : undefined,
|
|
7505
|
+
failedSourceIds: failedSourceIds.length > 0 ? failedSourceIds : undefined,
|
|
7506
|
+
ok: true,
|
|
7507
|
+
partial: failedSourceIds.length > 0,
|
|
7508
|
+
sources
|
|
7509
|
+
};
|
|
7339
7510
|
},
|
|
7340
|
-
syncSource: async (id) => {
|
|
7511
|
+
syncSource: async (id, runOptions) => {
|
|
7512
|
+
await ensureHydrated();
|
|
7341
7513
|
const source = sourceMap.get(id);
|
|
7342
7514
|
if (!source) {
|
|
7343
7515
|
return {
|
|
@@ -7345,13 +7517,104 @@ var createRAGSyncManager = (options) => {
|
|
|
7345
7517
|
ok: false
|
|
7346
7518
|
};
|
|
7347
7519
|
}
|
|
7520
|
+
if (resolveBackground(runOptions)) {
|
|
7521
|
+
const existingRecord = state.get(id);
|
|
7522
|
+
if (existingRecord?.status !== "running") {
|
|
7523
|
+
const running = toSourceRecord(source, {
|
|
7524
|
+
chunkCount: existingRecord?.chunkCount,
|
|
7525
|
+
consecutiveFailures: existingRecord?.consecutiveFailures ?? 0,
|
|
7526
|
+
documentCount: existingRecord?.documentCount,
|
|
7527
|
+
lastError: undefined,
|
|
7528
|
+
lastStartedAt: Date.now(),
|
|
7529
|
+
lastSuccessfulSyncAt: existingRecord?.lastSuccessfulSyncAt,
|
|
7530
|
+
lastSyncedAt: existingRecord?.lastSyncedAt,
|
|
7531
|
+
lastSyncDurationMs: existingRecord?.lastSyncDurationMs,
|
|
7532
|
+
nextRetryAt: undefined,
|
|
7533
|
+
retryAttempts: resolveRetryAttempts(source),
|
|
7534
|
+
status: "running"
|
|
7535
|
+
});
|
|
7536
|
+
await setSourceState(running);
|
|
7537
|
+
runSource(source);
|
|
7538
|
+
}
|
|
7539
|
+
return {
|
|
7540
|
+
ok: true,
|
|
7541
|
+
source: state.get(id) ?? toSourceRecord(source, {
|
|
7542
|
+
status: "running"
|
|
7543
|
+
})
|
|
7544
|
+
};
|
|
7545
|
+
}
|
|
7546
|
+
const record = await runSource(source);
|
|
7547
|
+
if (record.status === "failed") {
|
|
7548
|
+
return {
|
|
7549
|
+
error: record.lastError ?? `RAG sync source ${id} failed`,
|
|
7550
|
+
ok: false
|
|
7551
|
+
};
|
|
7552
|
+
}
|
|
7348
7553
|
return {
|
|
7349
7554
|
ok: true,
|
|
7350
|
-
source:
|
|
7555
|
+
source: record
|
|
7351
7556
|
};
|
|
7352
7557
|
}
|
|
7353
7558
|
};
|
|
7354
7559
|
};
|
|
7560
|
+
var createRAGFileSyncStateStore = (path) => {
|
|
7561
|
+
const resolvedPath = resolve2(path);
|
|
7562
|
+
return {
|
|
7563
|
+
load: async () => {
|
|
7564
|
+
try {
|
|
7565
|
+
return parseSyncState(await readFile2(resolvedPath, "utf8"));
|
|
7566
|
+
} catch {
|
|
7567
|
+
return [];
|
|
7568
|
+
}
|
|
7569
|
+
},
|
|
7570
|
+
save: async (records) => {
|
|
7571
|
+
await mkdir(dirname(resolvedPath), { recursive: true });
|
|
7572
|
+
await writeFile(resolvedPath, JSON.stringify(records, null, 2), "utf8");
|
|
7573
|
+
}
|
|
7574
|
+
};
|
|
7575
|
+
};
|
|
7576
|
+
var createRAGSyncScheduler = (input) => {
|
|
7577
|
+
const timers = new Map;
|
|
7578
|
+
let running = false;
|
|
7579
|
+
const runSchedule = async (schedule) => {
|
|
7580
|
+
if (schedule.sourceIds?.length) {
|
|
7581
|
+
for (const sourceId of schedule.sourceIds) {
|
|
7582
|
+
await input.manager.syncSource?.(sourceId, {
|
|
7583
|
+
background: schedule.background
|
|
7584
|
+
});
|
|
7585
|
+
}
|
|
7586
|
+
return;
|
|
7587
|
+
}
|
|
7588
|
+
await input.manager.syncAllSources?.({
|
|
7589
|
+
background: schedule.background
|
|
7590
|
+
});
|
|
7591
|
+
};
|
|
7592
|
+
return {
|
|
7593
|
+
start: async () => {
|
|
7594
|
+
if (running) {
|
|
7595
|
+
return;
|
|
7596
|
+
}
|
|
7597
|
+
running = true;
|
|
7598
|
+
for (const schedule of input.schedules) {
|
|
7599
|
+
if (schedule.runImmediately) {
|
|
7600
|
+
runSchedule(schedule);
|
|
7601
|
+
}
|
|
7602
|
+
timers.set(schedule.id, setInterval(() => {
|
|
7603
|
+
runSchedule(schedule);
|
|
7604
|
+
}, schedule.intervalMs));
|
|
7605
|
+
}
|
|
7606
|
+
},
|
|
7607
|
+
stop: () => {
|
|
7608
|
+
for (const timer of timers.values()) {
|
|
7609
|
+
clearInterval(timer);
|
|
7610
|
+
}
|
|
7611
|
+
timers.clear();
|
|
7612
|
+
running = false;
|
|
7613
|
+
},
|
|
7614
|
+
isRunning: () => running,
|
|
7615
|
+
listSchedules: () => [...input.schedules]
|
|
7616
|
+
};
|
|
7617
|
+
};
|
|
7355
7618
|
// src/ai/rag/adapters/utils.ts
|
|
7356
7619
|
var vectorDimensionDefault = 24;
|
|
7357
7620
|
var createRAGVector = (text, dimensions = vectorDimensionDefault) => {
|
|
@@ -7510,7 +7773,7 @@ import { existsSync as existsSync2 } from "fs";
|
|
|
7510
7773
|
import { existsSync, readFileSync } from "fs";
|
|
7511
7774
|
import { createRequire } from "module";
|
|
7512
7775
|
import { arch, platform } from "os";
|
|
7513
|
-
import { dirname, join as join2 } from "path";
|
|
7776
|
+
import { dirname as dirname2, join as join2 } from "path";
|
|
7514
7777
|
var require2 = createRequire(import.meta.url);
|
|
7515
7778
|
var PLATFORM_PACKAGE_MAP = {
|
|
7516
7779
|
"darwin-arm64": {
|
|
@@ -7561,7 +7824,7 @@ var resolveAbsoluteSQLiteVec = () => {
|
|
|
7561
7824
|
}
|
|
7562
7825
|
try {
|
|
7563
7826
|
const packageJsonPath = require2.resolve(`${packageInfo.packageName}/package.json`);
|
|
7564
|
-
const packageRoot =
|
|
7827
|
+
const packageRoot = dirname2(packageJsonPath);
|
|
7565
7828
|
const libraryPath = join2(packageRoot, packageInfo.libraryFile);
|
|
7566
7829
|
const packageVersion = readPackageVersion(packageJsonPath);
|
|
7567
7830
|
if (!existsSync(libraryPath)) {
|
|
@@ -9099,8 +9362,10 @@ var createRAGClient = (options) => {
|
|
|
9099
9362
|
}
|
|
9100
9363
|
return parseJson(response);
|
|
9101
9364
|
},
|
|
9102
|
-
async syncAllSources() {
|
|
9365
|
+
async syncAllSources(options2) {
|
|
9103
9366
|
const response = await fetchImpl(`${basePath}/sync`, {
|
|
9367
|
+
body: options2?.background === true ? JSON.stringify({ background: true }) : undefined,
|
|
9368
|
+
headers: options2?.background === true ? jsonHeaders : undefined,
|
|
9104
9369
|
method: "POST"
|
|
9105
9370
|
});
|
|
9106
9371
|
if (!response.ok) {
|
|
@@ -9111,8 +9376,10 @@ var createRAGClient = (options) => {
|
|
|
9111
9376
|
}
|
|
9112
9377
|
return parseJson(response);
|
|
9113
9378
|
},
|
|
9114
|
-
async syncSource(id) {
|
|
9379
|
+
async syncSource(id, options2) {
|
|
9115
9380
|
const response = await fetchImpl(`${basePath}/sync/${encodeURIComponent(id)}`, {
|
|
9381
|
+
body: options2?.background === true ? JSON.stringify({ background: true }) : undefined,
|
|
9382
|
+
headers: options2?.background === true ? jsonHeaders : undefined,
|
|
9116
9383
|
method: "POST"
|
|
9117
9384
|
});
|
|
9118
9385
|
if (!response.ok) {
|
|
@@ -9267,6 +9534,7 @@ export {
|
|
|
9267
9534
|
createRAGVector,
|
|
9268
9535
|
createRAGUrlSyncSource,
|
|
9269
9536
|
createAIStream as createRAGTransport,
|
|
9537
|
+
createRAGSyncScheduler,
|
|
9270
9538
|
createRAGSyncManager,
|
|
9271
9539
|
createRAGReranker,
|
|
9272
9540
|
createRAGQueryTransform,
|
|
@@ -9277,6 +9545,7 @@ export {
|
|
|
9277
9545
|
createRAGImageOCRExtractor,
|
|
9278
9546
|
createRAGHTMXWorkflowRenderConfig,
|
|
9279
9547
|
createRAGHTMXConfig,
|
|
9548
|
+
createRAGFileSyncStateStore,
|
|
9280
9549
|
createRAGFileExtractor,
|
|
9281
9550
|
createRAGEvaluationSuite,
|
|
9282
9551
|
createRAGEmbeddingProvider,
|
|
@@ -9321,5 +9590,5 @@ export {
|
|
|
9321
9590
|
aiChat
|
|
9322
9591
|
};
|
|
9323
9592
|
|
|
9324
|
-
//# debugId=
|
|
9593
|
+
//# debugId=61173B84573291CC64756E2164756E21
|
|
9325
9594
|
//# sourceMappingURL=index.js.map
|