@absolutejs/absolute 0.19.0-beta.363 → 0.19.0-beta.365

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 (55) hide show
  1. package/dist/ai/index.js +383 -36
  2. package/dist/ai/index.js.map +11 -9
  3. package/dist/ai-client/angular/ai/index.js +102 -0
  4. package/dist/ai-client/react/ai/index.js +176 -0
  5. package/dist/ai-client/vue/ai/index.js +172 -0
  6. package/dist/angular/ai/index.js +103 -1
  7. package/dist/angular/ai/index.js.map +5 -3
  8. package/dist/angular/index.js +2 -2
  9. package/dist/angular/index.js.map +2 -2
  10. package/dist/build.js +4 -1
  11. package/dist/build.js.map +3 -3
  12. package/dist/client/index.js +2 -2
  13. package/dist/client/index.js.map +2 -2
  14. package/dist/index.js +5 -2
  15. package/dist/index.js.map +4 -4
  16. package/dist/react/ai/index.js +177 -1
  17. package/dist/react/ai/index.js.map +7 -3
  18. package/dist/react/components/browser/index.js +2 -1
  19. package/dist/react/components/index.js +3 -2
  20. package/dist/react/components/index.js.map +3 -3
  21. package/dist/react/index.js +5 -2
  22. package/dist/react/index.js.map +4 -4
  23. package/dist/react/server.js +4 -1
  24. package/dist/react/server.js.map +3 -3
  25. package/dist/src/ai/client/ragClient.d.ts +16 -0
  26. package/dist/src/ai/index.d.ts +3 -1
  27. package/dist/src/ai/rag/adapters/sqlite.d.ts +2 -11
  28. package/dist/src/ai/rag/chat.d.ts +41 -5
  29. package/dist/src/ai/rag/index.d.ts +3 -2
  30. package/dist/src/ai/rag/resolveAbsoluteSQLiteVec.d.ts +2 -0
  31. package/dist/src/ai/rag/types.d.ts +1 -1
  32. package/dist/src/angular/ai/index.d.ts +1 -0
  33. package/dist/src/angular/ai/rag-client.service.d.ts +11 -0
  34. package/dist/src/react/ai/index.d.ts +3 -0
  35. package/dist/src/react/ai/useRAGIngest.d.ts +8 -0
  36. package/dist/src/react/ai/useRAGSearch.d.ts +9 -0
  37. package/dist/src/react/ai/useRAGStatus.d.ts +9 -0
  38. package/dist/src/svelte/ai/createRAGIngest.d.ts +7 -0
  39. package/dist/src/svelte/ai/createRAGSearch.d.ts +7 -0
  40. package/dist/src/svelte/ai/createRAGStatus.d.ts +8 -0
  41. package/dist/src/svelte/ai/index.d.ts +3 -0
  42. package/dist/src/vue/ai/index.d.ts +3 -0
  43. package/dist/src/vue/ai/useRAGIngest.d.ts +7 -0
  44. package/dist/src/vue/ai/useRAGSearch.d.ts +21 -0
  45. package/dist/src/vue/ai/useRAGStatus.d.ts +8 -0
  46. package/dist/svelte/ai/index.js +171 -1
  47. package/dist/svelte/ai/index.js.map +8 -4
  48. package/dist/svelte/index.js +2 -2
  49. package/dist/svelte/index.js.map +2 -2
  50. package/dist/types/ai.d.ts +54 -0
  51. package/dist/vue/ai/index.js +173 -1
  52. package/dist/vue/ai/index.js.map +7 -3
  53. package/dist/vue/index.js +2 -2
  54. package/dist/vue/index.js.map +2 -2
  55. package/package.json +1 -1
package/dist/ai/index.js CHANGED
@@ -2101,6 +2101,42 @@ var aiChat = (config) => {
2101
2101
  // src/ai/rag/chat.ts
2102
2102
  import { Elysia as Elysia2 } from "elysia";
2103
2103
 
2104
+ // src/ai/rag/collection.ts
2105
+ var DEFAULT_TOP_K = 6;
2106
+ var searchDocuments = async (collection, input) => collection.search(input);
2107
+ var ingestDocuments = async (collection, input) => collection.ingest(input);
2108
+ var createRAGCollection = (options) => {
2109
+ const defaultTopK = options.defaultTopK ?? DEFAULT_TOP_K;
2110
+ const getCapabilities = options.store.getCapabilities;
2111
+ const getStatus = options.store.getStatus;
2112
+ const search = async (input) => {
2113
+ const queryVector = await options.store.embed({
2114
+ model: input.model ?? options.defaultModel,
2115
+ signal: input.signal,
2116
+ text: input.query
2117
+ });
2118
+ const topK = input.topK ?? defaultTopK;
2119
+ const results = await options.store.query({
2120
+ filter: input.filter,
2121
+ queryVector,
2122
+ topK
2123
+ });
2124
+ if (typeof input.scoreThreshold !== "number") {
2125
+ return results;
2126
+ }
2127
+ const scoreThreshold = input.scoreThreshold;
2128
+ return results.filter((entry) => entry.score >= scoreThreshold);
2129
+ };
2130
+ return {
2131
+ clear: typeof options.store.clear === "function" ? () => options.store.clear?.() : undefined,
2132
+ getCapabilities: typeof getCapabilities === "function" ? () => getCapabilities() : undefined,
2133
+ getStatus: typeof getStatus === "function" ? () => getStatus() : undefined,
2134
+ ingest: (input) => options.store.upsert(input),
2135
+ search,
2136
+ store: options.store
2137
+ };
2138
+ };
2139
+
2104
2140
  // src/ai/rag/types.ts
2105
2141
  var buildRAGContext = (hits) => {
2106
2142
  if (hits.length === 0) {
@@ -2122,7 +2158,7 @@ Answer with citations like [1], [2] when you use specific context.`;
2122
2158
 
2123
2159
  // src/ai/rag/chat.ts
2124
2160
  var DEFAULT_PATH2 = "/rag";
2125
- var DEFAULT_TOP_K = 6;
2161
+ var DEFAULT_TOP_K2 = 6;
2126
2162
  var DEFAULT_PREFIX_LEN = 12;
2127
2163
  var DEFAULT_PROVIDER = "anthropic";
2128
2164
  var TITLE_MAX_LENGTH2 = 80;
@@ -2219,34 +2255,35 @@ var branchConversation2 = (source, fromMessageId) => {
2219
2255
  messages: branchedMessages
2220
2256
  };
2221
2257
  };
2222
- var buildRAGContextFromQuery = async (ragStore, topK, scoreThreshold, queryText, ragModel) => {
2223
- if (!ragStore) {
2258
+ var buildRAGContextFromQuery = async (config, topK, scoreThreshold, queryText, ragModel) => {
2259
+ const collection = config.collection ?? (config.ragStore ? createRAGCollection({
2260
+ defaultModel: ragModel,
2261
+ defaultTopK: topK,
2262
+ store: config.ragStore
2263
+ }) : null);
2264
+ if (!collection) {
2224
2265
  return {
2225
2266
  ragContext: "",
2226
2267
  sources: []
2227
2268
  };
2228
2269
  }
2229
- const queryVector = await ragStore.embed({
2270
+ const queried = await collection.search({
2230
2271
  model: ragModel,
2231
- text: queryText
2232
- });
2233
- const queried = await ragStore.query({
2234
- queryVector,
2235
- topK,
2236
- filter: undefined
2272
+ query: queryText,
2273
+ scoreThreshold,
2274
+ topK
2237
2275
  });
2238
- const filtered = typeof scoreThreshold === "number" ? queried.filter((entry) => entry.score >= scoreThreshold) : queried;
2239
- const sources = buildSources(filtered);
2276
+ const sources = buildSources(queried);
2240
2277
  return {
2241
- ragContext: buildRAGContext(filtered),
2278
+ ragContext: buildRAGContext(queried),
2242
2279
  sources
2243
2280
  };
2244
2281
  };
2245
2282
  var ragChat = (config) => {
2246
2283
  const path = config.path ?? DEFAULT_PATH2;
2247
- const topK = config.topK ?? DEFAULT_TOP_K;
2284
+ const topK = config.topK ?? DEFAULT_TOP_K2;
2248
2285
  const scoreThreshold = config.scoreThreshold;
2249
- const ragStore = config.ragStore;
2286
+ const ragStore = config.ragStore ?? config.collection?.store;
2250
2287
  const parseProvider = config.parseProvider ?? defaultParseProvider2;
2251
2288
  const store = config.store ?? createMemoryStore();
2252
2289
  const abortControllers = new Map;
@@ -2319,7 +2356,7 @@ var ragChat = (config) => {
2319
2356
  const model = resolveModel2(config, parsed);
2320
2357
  const ragModel = parsed.model ?? model;
2321
2358
  const provider = config.provider(providerName);
2322
- const rag = await buildRAGContextFromQuery(ragStore, topK, scoreThreshold, content, ragModel);
2359
+ const rag = await buildRAGContextFromQuery(config, topK, scoreThreshold, content, ragModel);
2323
2360
  appendMessage2(conversation, {
2324
2361
  attachments: rawAttachments,
2325
2362
  content,
@@ -2372,6 +2409,42 @@ var ragChat = (config) => {
2372
2409
  await ragStore.upsert({ chunks: chunksValue });
2373
2410
  return { count: chunksValue.length, ok: true };
2374
2411
  };
2412
+ const handleSearch = async (body) => {
2413
+ if (!body || typeof body !== "object") {
2414
+ return { ok: false, error: "Invalid payload" };
2415
+ }
2416
+ const payload = body;
2417
+ const query = typeof payload.query === "string" ? payload.query.trim() : "";
2418
+ if (!query) {
2419
+ return { ok: false, error: "Expected payload shape: { query: string }" };
2420
+ }
2421
+ const collection = config.collection ?? (ragStore ? createRAGCollection({
2422
+ defaultTopK: topK,
2423
+ store: ragStore
2424
+ }) : null);
2425
+ if (!collection) {
2426
+ return { ok: false, error: "RAG collection is not configured" };
2427
+ }
2428
+ const results = await collection.search({
2429
+ filter: payload.filter,
2430
+ model: payload.model,
2431
+ query,
2432
+ scoreThreshold: payload.scoreThreshold,
2433
+ topK: payload.topK
2434
+ });
2435
+ return { ok: true, results: buildSources(results) };
2436
+ };
2437
+ const handleStatus = () => {
2438
+ const collection = config.collection ?? (ragStore ? createRAGCollection({
2439
+ defaultTopK: topK,
2440
+ store: ragStore
2441
+ }) : null);
2442
+ return {
2443
+ ok: true,
2444
+ status: collection?.getStatus?.(),
2445
+ capabilities: collection?.getCapabilities?.()
2446
+ };
2447
+ };
2375
2448
  const htmxRoutes = () => {
2376
2449
  if (!config.htmx) {
2377
2450
  return new Elysia2;
@@ -2425,7 +2498,7 @@ var ragChat = (config) => {
2425
2498
  const model = resolveModel2(config, parsed);
2426
2499
  const ragModel = parsed.model ?? model;
2427
2500
  const provider = config.provider(providerName);
2428
- const { ragContext, sources } = await buildRAGContextFromQuery(ragStore, topK, scoreThreshold, content, ragModel);
2501
+ const { ragContext, sources } = await buildRAGContextFromQuery(config, topK, scoreThreshold, content, ragModel);
2429
2502
  const assistantMessageId = generateId();
2430
2503
  if (sources.length > 0) {
2431
2504
  yield {
@@ -2478,7 +2551,7 @@ var ragChat = (config) => {
2478
2551
  await handleMessage(ws, msg.content, msg.conversationId, msg.attachments);
2479
2552
  }
2480
2553
  }
2481
- }).post(`${path}/ingest`, async ({ body }) => handleIngest(body)).delete(`${path}/index`, async () => {
2554
+ }).post(`${path}/search`, async ({ body }) => handleSearch(body)).get(`${path}/status`, () => handleStatus()).post(`${path}/ingest`, async ({ body }) => handleIngest(body)).delete(`${path}/index`, async () => {
2482
2555
  if (!ragStore) {
2483
2556
  return { ok: false };
2484
2557
  }
@@ -2585,14 +2658,27 @@ var createInMemoryRAGStore = (options = {}) => {
2585
2658
  embed,
2586
2659
  query,
2587
2660
  upsert,
2588
- clear
2661
+ clear,
2662
+ getCapabilities: () => ({
2663
+ backend: "in_memory",
2664
+ persistence: "memory_only",
2665
+ nativeVectorSearch: false,
2666
+ serverSideFiltering: false,
2667
+ streamingIngestStatus: false
2668
+ }),
2669
+ getStatus: () => ({
2670
+ backend: "in_memory",
2671
+ vectorMode: "in_memory",
2672
+ dimensions
2673
+ })
2589
2674
  };
2590
2675
  };
2591
2676
  // src/ai/rag/adapters/sqlite.ts
2592
2677
  import { Database } from "bun:sqlite";
2678
+ import { existsSync as existsSync2 } from "fs";
2593
2679
 
2594
2680
  // src/ai/rag/resolveAbsoluteSQLiteVec.ts
2595
- import { existsSync } from "fs";
2681
+ import { existsSync, readFileSync } from "fs";
2596
2682
  import { createRequire } from "module";
2597
2683
  import { arch, platform } from "os";
2598
2684
  import { dirname, join } from "path";
@@ -2623,19 +2709,64 @@ var PLATFORM_PACKAGE_MAP = {
2623
2709
  libraryFile: "sqlite-vec.dll"
2624
2710
  }
2625
2711
  };
2626
- var resolveAbsoluteSQLiteVecExtensionPath = () => {
2627
- const platformKey = `${platform()}-${arch()}`;
2712
+ var currentPlatformKey = () => `${platform()}-${arch()}`;
2713
+ var getErrorMessage = (error) => error instanceof Error ? error.message : String(error);
2714
+ var readPackageVersion = (packageJsonPath) => {
2715
+ try {
2716
+ const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf8"));
2717
+ return typeof packageJson.version === "string" ? packageJson.version : undefined;
2718
+ } catch {
2719
+ return;
2720
+ }
2721
+ };
2722
+ var resolveAbsoluteSQLiteVec = () => {
2723
+ const platformKey = currentPlatformKey();
2628
2724
  const packageInfo = PLATFORM_PACKAGE_MAP[platformKey];
2629
2725
  if (!packageInfo) {
2630
- return null;
2726
+ return {
2727
+ status: "unsupported_platform",
2728
+ source: "absolute-package",
2729
+ platformKey,
2730
+ reason: `No AbsoluteJS sqlite-vec package is defined for ${platformKey}.`
2731
+ };
2631
2732
  }
2632
2733
  try {
2633
2734
  const packageJsonPath = require2.resolve(`${packageInfo.packageName}/package.json`);
2634
2735
  const packageRoot = dirname(packageJsonPath);
2635
2736
  const libraryPath = join(packageRoot, packageInfo.libraryFile);
2636
- return existsSync(libraryPath) ? libraryPath : null;
2637
- } catch {
2638
- return null;
2737
+ const packageVersion = readPackageVersion(packageJsonPath);
2738
+ if (!existsSync(libraryPath)) {
2739
+ return {
2740
+ status: "binary_missing",
2741
+ source: "absolute-package",
2742
+ platformKey,
2743
+ packageName: packageInfo.packageName,
2744
+ packageVersion,
2745
+ packageRoot,
2746
+ libraryFile: packageInfo.libraryFile,
2747
+ libraryPath,
2748
+ reason: `Resolved ${packageInfo.packageName} but ${packageInfo.libraryFile} was not found.`
2749
+ };
2750
+ }
2751
+ return {
2752
+ status: "resolved",
2753
+ source: "absolute-package",
2754
+ platformKey,
2755
+ packageName: packageInfo.packageName,
2756
+ packageVersion,
2757
+ packageRoot,
2758
+ libraryFile: packageInfo.libraryFile,
2759
+ libraryPath
2760
+ };
2761
+ } catch (error) {
2762
+ return {
2763
+ status: "package_not_installed",
2764
+ source: "absolute-package",
2765
+ platformKey,
2766
+ packageName: packageInfo.packageName,
2767
+ libraryFile: packageInfo.libraryFile,
2768
+ reason: getErrorMessage(error)
2769
+ };
2639
2770
  }
2640
2771
  };
2641
2772
 
@@ -2827,6 +2958,90 @@ var executeNativeInitSql = (db, initSql) => {
2827
2958
  db.exec(command);
2828
2959
  }
2829
2960
  };
2961
+ var getErrorMessage2 = (error) => error instanceof Error ? error.message : String(error);
2962
+ var resolveConfiguredNativeExtension = (nativeConfig) => {
2963
+ const platformKey = `${process.platform}-${process.arch}`;
2964
+ if (nativeConfig?.extensionPath) {
2965
+ return existsSync2(nativeConfig.extensionPath) ? {
2966
+ status: "resolved",
2967
+ source: "explicit",
2968
+ platformKey,
2969
+ libraryPath: nativeConfig.extensionPath
2970
+ } : {
2971
+ status: "binary_missing",
2972
+ source: "explicit",
2973
+ platformKey,
2974
+ libraryPath: nativeConfig.extensionPath,
2975
+ reason: `Configured native.extensionPath was not found: ${nativeConfig.extensionPath}`
2976
+ };
2977
+ }
2978
+ if (nativeConfig?.resolveFromAbsolutePackages !== false) {
2979
+ const packageResolution = resolveAbsoluteSQLiteVec();
2980
+ if (packageResolution.status === "resolved") {
2981
+ return packageResolution;
2982
+ }
2983
+ if (packageResolution.status === "binary_missing" || packageResolution.status === "package_not_installed" || packageResolution.status === "unsupported_platform") {
2984
+ const envPath2 = process.env.SQLITE_VEC_EXTENSION_PATH;
2985
+ if (envPath2) {
2986
+ return existsSync2(envPath2) ? {
2987
+ status: "resolved",
2988
+ source: "env",
2989
+ platformKey,
2990
+ libraryPath: envPath2
2991
+ } : {
2992
+ status: "binary_missing",
2993
+ source: "env",
2994
+ platformKey,
2995
+ libraryPath: envPath2,
2996
+ reason: `SQLITE_VEC_EXTENSION_PATH was set but not found: ${envPath2}`
2997
+ };
2998
+ }
2999
+ }
3000
+ return packageResolution;
3001
+ }
3002
+ const envPath = process.env.SQLITE_VEC_EXTENSION_PATH;
3003
+ if (envPath) {
3004
+ return existsSync2(envPath) ? {
3005
+ status: "resolved",
3006
+ source: "env",
3007
+ platformKey,
3008
+ libraryPath: envPath
3009
+ } : {
3010
+ status: "binary_missing",
3011
+ source: "env",
3012
+ platformKey,
3013
+ libraryPath: envPath,
3014
+ reason: `SQLITE_VEC_EXTENSION_PATH was set but not found: ${envPath}`
3015
+ };
3016
+ }
3017
+ return {
3018
+ status: "not_configured",
3019
+ source: "database",
3020
+ platformKey,
3021
+ reason: "No native sqlite-vec path was configured. AbsoluteJS will still attempt vec0 initialization in case the extension is already registered on the Database connection."
3022
+ };
3023
+ };
3024
+ var describeNativeFallbackReason = (resolution) => {
3025
+ if (!resolution) {
3026
+ return "Native sqlite vec0 was not configured.";
3027
+ }
3028
+ switch (resolution.status) {
3029
+ case "resolved":
3030
+ return;
3031
+ case "package_not_installed":
3032
+ return `Install ${resolution.packageName ?? "@absolutejs/absolute-rag-sqlite"} for ${resolution.platformKey}, or provide native.extensionPath.`;
3033
+ case "binary_missing":
3034
+ return resolution.reason ?? "Resolved sqlite-vec binary was missing.";
3035
+ case "unsupported_platform":
3036
+ return resolution.reason ?? "This platform is not yet supported by AbsoluteJS sqlite-vec packages.";
3037
+ case "not_configured":
3038
+ return resolution.reason ?? "No sqlite-vec binary path was configured.";
3039
+ case "package_invalid":
3040
+ return resolution.reason ?? "The sqlite-vec package manifest was invalid.";
3041
+ default:
3042
+ return "Native sqlite vec0 could not be initialized.";
3043
+ }
3044
+ };
2830
3045
  var createSQLiteRAGStore = (options = {}) => {
2831
3046
  const dimensions = options.dimensions ?? DEFAULT_DIMENSIONS;
2832
3047
  const tableName = options.tableName ?? DEFAULT_TABLE_NAME;
@@ -2842,23 +3057,52 @@ var createSQLiteRAGStore = (options = {}) => {
2842
3057
  const db = options.db ?? new Database(options.path ?? ":memory:");
2843
3058
  const nativeDistanceMetric = nativeConfig?.distanceMetric === "l2" ? "l2" : "cosine";
2844
3059
  const nativeQueryMultiplier = normalizeQueryMultiplier(nativeConfig?.queryMultiplier);
2845
- const resolvedNativeExtensionPath = nativeConfig?.extensionPath ?? (nativeConfig?.resolveFromAbsolutePackages === false ? undefined : resolveAbsoluteSQLiteVecExtensionPath()) ?? process.env.SQLITE_VEC_EXTENSION_PATH;
3060
+ const nativeResolution = nativeConfig?.mode === "vec0" ? resolveConfiguredNativeExtension(nativeConfig) : undefined;
3061
+ const nativeDiagnostics = nativeConfig?.mode === "vec0" ? {
3062
+ requested: true,
3063
+ available: false,
3064
+ active: false,
3065
+ mode: nativeConfig.mode,
3066
+ tableName: nativeTableName,
3067
+ distanceMetric: nativeDistanceMetric,
3068
+ resolution: nativeResolution,
3069
+ fallbackReason: describeNativeFallbackReason(nativeResolution)
3070
+ } : undefined;
2846
3071
  const jsonStatements = createJsonStatements(db, tableName);
2847
3072
  jsonStatements.init();
2848
3073
  let useNative = false;
2849
3074
  let nativeStatements;
2850
3075
  if (nativeConfig?.mode === "vec0") {
2851
3076
  try {
2852
- if (resolvedNativeExtensionPath) {
2853
- db.loadExtension(resolvedNativeExtensionPath);
3077
+ if (nativeResolution?.status === "resolved" && nativeResolution.libraryPath) {
3078
+ db.loadExtension(nativeResolution.libraryPath);
2854
3079
  }
2855
3080
  executeNativeInitSql(db, nativeConfig.extensionInitSql);
2856
3081
  createNativeVec0Table(db, nativeTableName, dimensions, nativeDistanceMetric);
2857
3082
  nativeStatements = createNativeVec0Statements(db, nativeTableName);
2858
3083
  useNative = true;
3084
+ if (nativeDiagnostics) {
3085
+ nativeDiagnostics.available = true;
3086
+ nativeDiagnostics.active = true;
3087
+ nativeDiagnostics.fallbackReason = undefined;
3088
+ if (!nativeDiagnostics.resolution || nativeDiagnostics.resolution.status !== "resolved") {
3089
+ nativeDiagnostics.resolution = {
3090
+ status: "resolved",
3091
+ source: "database",
3092
+ platformKey: `${process.platform}-${process.arch}`,
3093
+ reason: "sqlite-vec was already available on the Database connection or loaded by native.extensionInitSql."
3094
+ };
3095
+ }
3096
+ }
2859
3097
  } catch (error) {
3098
+ if (nativeDiagnostics) {
3099
+ nativeDiagnostics.available = false;
3100
+ nativeDiagnostics.active = false;
3101
+ nativeDiagnostics.lastLoadError = getErrorMessage2(error);
3102
+ nativeDiagnostics.fallbackReason = describeNativeFallbackReason(nativeResolution) ?? nativeDiagnostics.lastLoadError;
3103
+ }
2860
3104
  if (nativeConfig.requireAvailable) {
2861
- throw new Error(`Failed to initialize sqlite vec0 backend for table "${nativeTableName}". ` + `Install @absolutejs/absolute-rag-sqlite for your platform, set native.extensionPath, or pre-register the sqlite-vec extension in the Database connection.`);
3105
+ throw new Error(`Failed to initialize sqlite vec0 backend for table "${nativeTableName}". ` + `Install @absolutejs/absolute-rag-sqlite for your platform, set native.extensionPath, or pre-register the sqlite-vec extension in the Database connection. ` + `Details: ${getErrorMessage2(error)}`);
2862
3106
  }
2863
3107
  useNative = false;
2864
3108
  }
@@ -2924,11 +3168,18 @@ var createSQLiteRAGStore = (options = {}) => {
2924
3168
  }
2925
3169
  try {
2926
3170
  return await queryNative(input);
2927
- } catch {
3171
+ } catch (error) {
3172
+ if (nativeDiagnostics) {
3173
+ nativeDiagnostics.lastQueryError = getErrorMessage2(error);
3174
+ }
2928
3175
  if (!nativeConfig?.requireAvailable) {
3176
+ if (nativeDiagnostics) {
3177
+ nativeDiagnostics.active = false;
3178
+ nativeDiagnostics.fallbackReason = nativeDiagnostics.lastQueryError;
3179
+ }
2929
3180
  return queryFallback(input);
2930
3181
  }
2931
- throw new Error(`Native vector query failed for table "${nativeTableName}".`);
3182
+ throw new Error(`Native vector query failed for table "${nativeTableName}". ${getErrorMessage2(error)}`);
2932
3183
  }
2933
3184
  };
2934
3185
  const upsert = async (input) => {
@@ -2955,11 +3206,18 @@ var createSQLiteRAGStore = (options = {}) => {
2955
3206
  nativeStatements.insert.run(chunk.chunkId, toVectorText(chunk.vector), chunk.text, chunk.title ?? null, chunk.source ?? null, toJSONString(chunk.metadata));
2956
3207
  }
2957
3208
  return;
2958
- } catch {
3209
+ } catch (error) {
3210
+ if (nativeDiagnostics) {
3211
+ nativeDiagnostics.lastUpsertError = getErrorMessage2(error);
3212
+ }
2959
3213
  if (nativeConfig?.requireAvailable) {
2960
- throw new Error(`Native vector upsert failed for table "${nativeTableName}".`);
3214
+ throw new Error(`Native vector upsert failed for table "${nativeTableName}". ${getErrorMessage2(error)}`);
2961
3215
  }
2962
3216
  useNative = false;
3217
+ if (nativeDiagnostics) {
3218
+ nativeDiagnostics.active = false;
3219
+ nativeDiagnostics.fallbackReason = nativeDiagnostics.lastUpsertError;
3220
+ }
2963
3221
  for (const chunk of chunks) {
2964
3222
  jsonStatements.insert.run(chunk.chunkId, chunk.text, chunk.title ?? null, chunk.source ?? null, toJSONString(chunk.metadata), toVectorText(chunk.vector));
2965
3223
  }
@@ -2976,11 +3234,26 @@ var createSQLiteRAGStore = (options = {}) => {
2976
3234
  jsonStatements.clear.run();
2977
3235
  }
2978
3236
  };
3237
+ const getStatus = () => ({
3238
+ backend: "sqlite",
3239
+ vectorMode: useNative ? "native_vec0" : "json_fallback",
3240
+ dimensions,
3241
+ native: nativeDiagnostics
3242
+ });
3243
+ const getCapabilities = () => ({
3244
+ backend: "sqlite",
3245
+ persistence: "embedded",
3246
+ nativeVectorSearch: useNative,
3247
+ serverSideFiltering: useNative,
3248
+ streamingIngestStatus: false
3249
+ });
2979
3250
  return {
2980
3251
  embed,
2981
3252
  query,
2982
3253
  upsert,
2983
- clear
3254
+ clear,
3255
+ getCapabilities,
3256
+ getStatus
2984
3257
  };
2985
3258
  };
2986
3259
  // src/ai/conversationManager.ts
@@ -3078,10 +3351,81 @@ var createConversationManager = () => {
3078
3351
  remove
3079
3352
  };
3080
3353
  };
3354
+ // src/ai/client/ragClient.ts
3355
+ var jsonHeaders = {
3356
+ "Content-Type": "application/json"
3357
+ };
3358
+ var normalizeBasePath = (path) => path.endsWith("/") ? path.slice(0, -1) : path;
3359
+ var parseJson = async (response) => {
3360
+ const payload = await response.json();
3361
+ return payload;
3362
+ };
3363
+ var toErrorMessage = async (response) => {
3364
+ try {
3365
+ const payload = await response.json();
3366
+ if (typeof payload.error === "string" && payload.error) {
3367
+ return payload.error;
3368
+ }
3369
+ } catch {}
3370
+ return `Request failed with status ${response.status}`;
3371
+ };
3372
+ var createRAGClient = (options) => {
3373
+ const basePath = normalizeBasePath(options.path);
3374
+ const fetchImpl = options.fetch ?? fetch;
3375
+ return {
3376
+ async ingest(chunks) {
3377
+ const response = await fetchImpl(`${basePath}/ingest`, {
3378
+ body: JSON.stringify({ chunks }),
3379
+ headers: jsonHeaders,
3380
+ method: "POST"
3381
+ });
3382
+ if (!response.ok) {
3383
+ return {
3384
+ ok: false,
3385
+ error: await toErrorMessage(response)
3386
+ };
3387
+ }
3388
+ return parseJson(response);
3389
+ },
3390
+ async search(input) {
3391
+ const response = await fetchImpl(`${basePath}/search`, {
3392
+ body: JSON.stringify(input),
3393
+ headers: jsonHeaders,
3394
+ method: "POST"
3395
+ });
3396
+ if (!response.ok) {
3397
+ throw new Error(await toErrorMessage(response));
3398
+ }
3399
+ const payload = await parseJson(response);
3400
+ if (!payload.ok) {
3401
+ throw new Error(payload.error ?? "RAG search failed");
3402
+ }
3403
+ return payload.results ?? [];
3404
+ },
3405
+ async status() {
3406
+ const response = await fetchImpl(`${basePath}/status`);
3407
+ if (!response.ok) {
3408
+ throw new Error(await toErrorMessage(response));
3409
+ }
3410
+ return parseJson(response);
3411
+ },
3412
+ async clearIndex() {
3413
+ const response = await fetchImpl(`${basePath}/index`, {
3414
+ method: "DELETE"
3415
+ });
3416
+ if (!response.ok) {
3417
+ throw new Error(await toErrorMessage(response));
3418
+ }
3419
+ return parseJson(response);
3420
+ }
3421
+ };
3422
+ };
3081
3423
  export {
3082
3424
  xai,
3083
3425
  streamAI,
3084
3426
  serializeAIMessage,
3427
+ searchDocuments,
3428
+ ragChat as ragPlugin,
3085
3429
  ragChat,
3086
3430
  querySimilarity,
3087
3431
  parseAIMessage,
@@ -3091,12 +3435,15 @@ export {
3091
3435
  moonshot,
3092
3436
  mistralai,
3093
3437
  meta,
3438
+ ingestDocuments,
3094
3439
  google,
3095
3440
  generateId,
3096
3441
  gemini,
3097
3442
  deepseek,
3098
3443
  createSQLiteRAGStore,
3099
3444
  createRAGVector,
3445
+ createRAGCollection,
3446
+ createRAGClient,
3100
3447
  createMemoryStore,
3101
3448
  createInMemoryRAGStore,
3102
3449
  createConversationManager,
@@ -3104,5 +3451,5 @@ export {
3104
3451
  aiChat
3105
3452
  };
3106
3453
 
3107
- //# debugId=F6B4CCC409C4C38264756E2164756E21
3454
+ //# debugId=CA562F087EBA565564756E2164756E21
3108
3455
  //# sourceMappingURL=index.js.map