@absolutejs/rag 0.0.6 → 0.0.8

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.
@@ -21676,6 +21676,7 @@ var MAX_INGEST_JOBS = 20;
21676
21676
  var MAX_ADMIN_ACTIONS = 20;
21677
21677
  var MAX_ADMIN_JOBS = 20;
21678
21678
  var DEFAULT_STALE_AFTER_MS = 1000 * 60 * 60 * 24 * 7;
21679
+ var REQUEST_USER_SUB_HEADER = "x-absolutejs-user-sub";
21679
21680
  var HTML_HEADERS = { "Content-Type": "text/html; charset=utf-8" };
21680
21681
  var defaultParseProvider = (content) => {
21681
21682
  const colonIdx = content.indexOf(":");
@@ -21689,6 +21690,10 @@ var defaultParseProvider = (content) => {
21689
21690
  var normalizeScore = (value) => Number.isFinite(value) ? value : 0;
21690
21691
  var isHTMXRequest = (request) => request.headers.get("HX-Request") === "true";
21691
21692
  var isObjectRecord3 = (value) => Boolean(value) && typeof value === "object";
21693
+ var resolveRequestUserSub = (request) => {
21694
+ const value = request?.headers.get(REQUEST_USER_SUB_HEADER)?.trim();
21695
+ return value ? value : undefined;
21696
+ };
21692
21697
  var getStringProperty = (value, key) => {
21693
21698
  if (!isObjectRecord3(value)) {
21694
21699
  return;
@@ -22528,11 +22533,12 @@ var ragChat = (config) => {
22528
22533
  throw error;
22529
22534
  }
22530
22535
  };
22531
- const buildSyncSources = async (scope) => {
22536
+ const buildSyncSources = async (scope, request) => {
22532
22537
  if (!indexManager?.listSyncSources) {
22533
22538
  return [];
22534
22539
  }
22535
- const sources = await indexManager.listSyncSources();
22540
+ const userSub = resolveRequestUserSub(request);
22541
+ const sources = await indexManager.listSyncSources(userSub ? { userSub } : undefined);
22536
22542
  return sources.filter((source) => matchesSyncSourceScope(scope, source));
22537
22543
  };
22538
22544
  const toHTMXResponse = (html, status, extraHeaders) => new Response(html, {
@@ -28746,7 +28752,7 @@ var ragChat = (config) => {
28746
28752
  stats: traceStats
28747
28753
  },
28748
28754
  status,
28749
- syncSources: await buildSyncSources(accessScope)
28755
+ syncSources: await buildSyncSources(accessScope, request)
28750
28756
  };
28751
28757
  };
28752
28758
  const handleStatus = async (request) => buildOperationsPayload(request);
@@ -29208,7 +29214,7 @@ var ragChat = (config) => {
29208
29214
  const accessScope = await loadAccessScope(request);
29209
29215
  return {
29210
29216
  ok: true,
29211
- sources: await buildSyncSources(accessScope)
29217
+ sources: await buildSyncSources(accessScope, request)
29212
29218
  };
29213
29219
  };
29214
29220
  const handleSyncAllSources = async (request, options) => {
@@ -29228,7 +29234,10 @@ var ragChat = (config) => {
29228
29234
  const job = createAdminJob("sync_all_sources", undefined, syncJobs);
29229
29235
  const action = createAdminAction("sync_all_sources");
29230
29236
  try {
29231
- const result = await indexManager.syncAllSources(options);
29237
+ const result = await indexManager.syncAllSources({
29238
+ ...options ?? {},
29239
+ userSub: resolveRequestUserSub(request)
29240
+ });
29232
29241
  if (result && "ok" in result) {
29233
29242
  if (!result.ok) {
29234
29243
  failAdminJob(job, result.error);
@@ -29250,7 +29259,7 @@ var ragChat = (config) => {
29250
29259
  completeAdminAction(action);
29251
29260
  return {
29252
29261
  ok: true,
29253
- sources: await buildSyncSources(accessScope)
29262
+ sources: await buildSyncSources(accessScope, request)
29254
29263
  };
29255
29264
  } catch (caught) {
29256
29265
  const message = caught instanceof Error ? caught.message : String(caught);
@@ -29282,7 +29291,10 @@ var ragChat = (config) => {
29282
29291
  const job = createAdminJob("sync_source", id, syncJobs);
29283
29292
  const action = createAdminAction("sync_source", undefined, id);
29284
29293
  try {
29285
- const result = await indexManager.syncSource(id, options);
29294
+ const result = await indexManager.syncSource(id, {
29295
+ ...options ?? {},
29296
+ userSub: resolveRequestUserSub(request)
29297
+ });
29286
29298
  if (result && "ok" in result) {
29287
29299
  if (!result.ok) {
29288
29300
  failAdminJob(job, result.error);
@@ -29295,7 +29307,7 @@ var ragChat = (config) => {
29295
29307
  }
29296
29308
  completeAdminJob(job);
29297
29309
  completeAdminAction(action);
29298
- const source = (await buildSyncSources(accessScope)).find((record) => record.id === id);
29310
+ const source = (await buildSyncSources(accessScope, request)).find((record) => record.id === id);
29299
29311
  return source ? { ok: true, source } : {
29300
29312
  error: "sync source not found",
29301
29313
  ok: false
@@ -31820,8 +31832,141 @@ ${tag} OK`) || chunk.startsWith(`${tag} OK`));
31820
31832
  return { messages };
31821
31833
  }
31822
31834
  });
31823
- // src/ai/rag/socialProviders.ts
31835
+ // src/ai/rag/contactProviders.ts
31824
31836
  var defaultFetch2 = Object.assign((...args) => fetch(...args), { preconnect: fetch.preconnect });
31837
+ var GOOGLE_PEOPLE_BASE_URL = "https://people.googleapis.com/v1";
31838
+ var DEFAULT_GOOGLE_CONTACTS_PAGE_SIZE = 200;
31839
+ var GOOGLE_CONTACTS_READ_SCOPES = [
31840
+ "https://www.googleapis.com/auth/contacts.readonly"
31841
+ ];
31842
+ var toErrorMessage3 = async (response, label) => {
31843
+ let detailMessage;
31844
+ try {
31845
+ const body = await response.clone().json();
31846
+ detailMessage = body.error?.message;
31847
+ } catch {
31848
+ const text = await response.clone().text();
31849
+ detailMessage = text.trim().length > 0 ? text.trim() : undefined;
31850
+ }
31851
+ return new Error(`${label}: ${response.status} ${response.statusText}${detailMessage ? ` (${detailMessage})` : ""}`);
31852
+ };
31853
+ var normalizeString = (value) => typeof value === "string" && value.trim().length > 0 ? value.trim() : undefined;
31854
+ var toUniqueStringArray = (values) => [...new Set(values.filter((value) => typeof value === "string" && value.length > 0))];
31855
+ var toContactTitle = (person, fallbackId) => {
31856
+ const primaryName = person.names?.find((name) => normalizeString(name.displayName) !== undefined);
31857
+ const displayName = normalizeString(primaryName?.displayName);
31858
+ if (displayName) {
31859
+ return displayName;
31860
+ }
31861
+ const primaryEmail = normalizeString(person.emailAddresses?.[0]?.value);
31862
+ if (primaryEmail) {
31863
+ return primaryEmail;
31864
+ }
31865
+ return `Google contact ${fallbackId}`;
31866
+ };
31867
+ var toContactText = (person) => {
31868
+ const name = normalizeString(person.names?.[0]?.displayName);
31869
+ const givenName = normalizeString(person.names?.[0]?.givenName);
31870
+ const familyName = normalizeString(person.names?.[0]?.familyName);
31871
+ const emails = toUniqueStringArray((person.emailAddresses ?? []).map((entry) => normalizeString(entry.value)));
31872
+ const phones = toUniqueStringArray((person.phoneNumbers ?? []).map((entry) => normalizeString(entry.value) ?? normalizeString(entry.canonicalForm)));
31873
+ const organizations = toUniqueStringArray((person.organizations ?? []).flatMap((entry) => [
31874
+ normalizeString(entry.name),
31875
+ normalizeString(entry.title)
31876
+ ]));
31877
+ const biography = normalizeString(person.biographies?.[0]?.value);
31878
+ const urls = toUniqueStringArray((person.urls ?? []).map((entry) => normalizeString(entry.value)));
31879
+ return [
31880
+ name,
31881
+ givenName && familyName ? `${givenName} ${familyName}` : givenName ?? familyName,
31882
+ emails.length > 0 ? `Emails: ${emails.join(", ")}` : undefined,
31883
+ phones.length > 0 ? `Phones: ${phones.join(", ")}` : undefined,
31884
+ organizations.length > 0 ? `Organizations: ${organizations.join(", ")}` : undefined,
31885
+ biography,
31886
+ urls.length > 0 ? `Links: ${urls.join(", ")}` : undefined
31887
+ ].filter((value) => typeof value === "string" && value.length > 0).join(`
31888
+ `);
31889
+ };
31890
+ var toContactItem = (person) => {
31891
+ const resourceName = normalizeString(person.resourceName);
31892
+ if (!resourceName) {
31893
+ return null;
31894
+ }
31895
+ const contactId = resourceName.replace(/^people\//, "");
31896
+ const title = toContactTitle(person, contactId);
31897
+ const emails = toUniqueStringArray((person.emailAddresses ?? []).map((entry) => normalizeString(entry.value)));
31898
+ const phones = toUniqueStringArray((person.phoneNumbers ?? []).map((entry) => normalizeString(entry.value) ?? normalizeString(entry.canonicalForm)));
31899
+ const organizations = (person.organizations ?? []).map((entry) => ({
31900
+ name: normalizeString(entry.name),
31901
+ title: normalizeString(entry.title)
31902
+ })).filter((entry) => entry.name || entry.title);
31903
+ const urls = toUniqueStringArray((person.urls ?? []).map((entry) => normalizeString(entry.value)));
31904
+ const photoUrl = normalizeString(person.photos?.find((photo) => normalizeString(photo.url) !== undefined)?.url);
31905
+ const text = toContactText(person);
31906
+ return {
31907
+ id: resourceName,
31908
+ kind: "google_contact",
31909
+ metadata: {
31910
+ emails,
31911
+ etag: normalizeString(person.etag),
31912
+ organizations,
31913
+ phones,
31914
+ photoUrl,
31915
+ provider: "google_contacts",
31916
+ resourceName,
31917
+ urls
31918
+ },
31919
+ text: text.length > 0 ? text : title,
31920
+ title,
31921
+ url: urls[0]
31922
+ };
31923
+ };
31924
+ var createRAGGoogleContactsConnector = (input) => ({
31925
+ provider: "google_contacts",
31926
+ requiredScopes: () => GOOGLE_CONTACTS_READ_SCOPES,
31927
+ sync: async ({ checkpoint, credential, resolver }) => {
31928
+ const lease = await resolver.getAccessToken(credential, {
31929
+ requiredScopes: GOOGLE_CONTACTS_READ_SCOPES
31930
+ });
31931
+ const fetchImpl = input?.fetch ?? defaultFetch2;
31932
+ const url = new URL(`${input?.baseUrl ?? GOOGLE_PEOPLE_BASE_URL}/people/me/connections`);
31933
+ url.searchParams.set("personFields", [
31934
+ "names",
31935
+ "emailAddresses",
31936
+ "phoneNumbers",
31937
+ "organizations",
31938
+ "biographies",
31939
+ "urls",
31940
+ "photos"
31941
+ ].join(","));
31942
+ url.searchParams.set("pageSize", String(input?.pageSize ?? DEFAULT_GOOGLE_CONTACTS_PAGE_SIZE));
31943
+ const pageToken = normalizeString(checkpoint?.pageToken);
31944
+ if (pageToken) {
31945
+ url.searchParams.set("pageToken", pageToken);
31946
+ }
31947
+ const response = await fetchImpl(url, {
31948
+ headers: {
31949
+ Authorization: `Bearer ${lease.accessToken}`
31950
+ }
31951
+ });
31952
+ if (!response.ok) {
31953
+ throw await toErrorMessage3(response, `Google Contacts sync failed for ${credential.externalAccountId}`);
31954
+ }
31955
+ const json = await response.json();
31956
+ return {
31957
+ items: (json.connections ?? []).map((person) => toContactItem(person)).filter(Boolean),
31958
+ nextCheckpoint: normalizeString(json.nextPageToken) ? { pageToken: normalizeString(json.nextPageToken) } : undefined,
31959
+ diagnostics: {
31960
+ listedCount: json.connections?.length ?? 0,
31961
+ nextPageToken: normalizeString(json.nextPageToken),
31962
+ totalItems: json.totalItems,
31963
+ totalPeople: json.totalPeople
31964
+ }
31965
+ };
31966
+ }
31967
+ });
31968
+ // src/ai/rag/socialProviders.ts
31969
+ var defaultFetch3 = Object.assign((...args) => fetch(...args), { preconnect: fetch.preconnect });
31825
31970
  var META_GRAPH_BASE_URL = "https://graph.facebook.com/v22.0";
31826
31971
  var DEFAULT_META_PAGE_SIZE = 25;
31827
31972
  var FACEBOOK_PAGE_READ_SCOPES = [
@@ -31832,7 +31977,7 @@ var INSTAGRAM_BUSINESS_READ_SCOPES = [
31832
31977
  "pages_show_list",
31833
31978
  "instagram_basic"
31834
31979
  ];
31835
- var toErrorMessage3 = async (response, label) => {
31980
+ var toErrorMessage4 = async (response, label) => {
31836
31981
  let detailMessage;
31837
31982
  try {
31838
31983
  const body = await response.clone().json();
@@ -31844,7 +31989,7 @@ var toErrorMessage3 = async (response, label) => {
31844
31989
  return new Error(`${label}: ${response.status} ${response.statusText}${detailMessage ? ` (${detailMessage})` : ""}`);
31845
31990
  };
31846
31991
  var fetchGraphList = async (input) => {
31847
- const fetchImpl = input.fetch ?? defaultFetch2;
31992
+ const fetchImpl = input.fetch ?? defaultFetch3;
31848
31993
  const url = new URL(`${input.baseUrl ?? META_GRAPH_BASE_URL}${input.path}`);
31849
31994
  url.searchParams.set("access_token", input.accessToken);
31850
31995
  url.searchParams.set("fields", input.fields.join(","));
@@ -31854,7 +31999,7 @@ var fetchGraphList = async (input) => {
31854
31999
  }
31855
32000
  const response = await fetchImpl(url);
31856
32001
  if (!response.ok) {
31857
- throw await toErrorMessage3(response, input.label);
32002
+ throw await toErrorMessage4(response, input.label);
31858
32003
  }
31859
32004
  return await response.json();
31860
32005
  };
@@ -37195,6 +37340,7 @@ export {
37195
37340
  createRAGHTMXWorkflowRenderConfig,
37196
37341
  createRAGHTMXConfig,
37197
37342
  createRAGGraphEmailSyncClient,
37343
+ createRAGGoogleContactsConnector,
37198
37344
  createRAGGmailEmailSyncClient,
37199
37345
  createRAGGitHubSyncSource,
37200
37346
  createRAGFileSyncStateStore,
@@ -37328,5 +37474,5 @@ export {
37328
37474
  addRAGEvaluationSuiteCase
37329
37475
  };
37330
37476
 
37331
- //# debugId=B8D6F85D648EA8ED64756E2164756E21
37477
+ //# debugId=C60E619F8D901C1764756E2164756E21
37332
37478
  //# sourceMappingURL=index.js.map