@absolutejs/rag 0.0.6 → 0.0.7
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/rag/index.js
CHANGED
|
@@ -31820,8 +31820,141 @@ ${tag} OK`) || chunk.startsWith(`${tag} OK`));
|
|
|
31820
31820
|
return { messages };
|
|
31821
31821
|
}
|
|
31822
31822
|
});
|
|
31823
|
-
// src/ai/rag/
|
|
31823
|
+
// src/ai/rag/contactProviders.ts
|
|
31824
31824
|
var defaultFetch2 = Object.assign((...args) => fetch(...args), { preconnect: fetch.preconnect });
|
|
31825
|
+
var GOOGLE_PEOPLE_BASE_URL = "https://people.googleapis.com/v1";
|
|
31826
|
+
var DEFAULT_GOOGLE_CONTACTS_PAGE_SIZE = 200;
|
|
31827
|
+
var GOOGLE_CONTACTS_READ_SCOPES = [
|
|
31828
|
+
"https://www.googleapis.com/auth/contacts.readonly"
|
|
31829
|
+
];
|
|
31830
|
+
var toErrorMessage3 = async (response, label) => {
|
|
31831
|
+
let detailMessage;
|
|
31832
|
+
try {
|
|
31833
|
+
const body = await response.clone().json();
|
|
31834
|
+
detailMessage = body.error?.message;
|
|
31835
|
+
} catch {
|
|
31836
|
+
const text = await response.clone().text();
|
|
31837
|
+
detailMessage = text.trim().length > 0 ? text.trim() : undefined;
|
|
31838
|
+
}
|
|
31839
|
+
return new Error(`${label}: ${response.status} ${response.statusText}${detailMessage ? ` (${detailMessage})` : ""}`);
|
|
31840
|
+
};
|
|
31841
|
+
var normalizeString = (value) => typeof value === "string" && value.trim().length > 0 ? value.trim() : undefined;
|
|
31842
|
+
var toUniqueStringArray = (values) => [...new Set(values.filter((value) => typeof value === "string" && value.length > 0))];
|
|
31843
|
+
var toContactTitle = (person, fallbackId) => {
|
|
31844
|
+
const primaryName = person.names?.find((name) => normalizeString(name.displayName) !== undefined);
|
|
31845
|
+
const displayName = normalizeString(primaryName?.displayName);
|
|
31846
|
+
if (displayName) {
|
|
31847
|
+
return displayName;
|
|
31848
|
+
}
|
|
31849
|
+
const primaryEmail = normalizeString(person.emailAddresses?.[0]?.value);
|
|
31850
|
+
if (primaryEmail) {
|
|
31851
|
+
return primaryEmail;
|
|
31852
|
+
}
|
|
31853
|
+
return `Google contact ${fallbackId}`;
|
|
31854
|
+
};
|
|
31855
|
+
var toContactText = (person) => {
|
|
31856
|
+
const name = normalizeString(person.names?.[0]?.displayName);
|
|
31857
|
+
const givenName = normalizeString(person.names?.[0]?.givenName);
|
|
31858
|
+
const familyName = normalizeString(person.names?.[0]?.familyName);
|
|
31859
|
+
const emails = toUniqueStringArray((person.emailAddresses ?? []).map((entry) => normalizeString(entry.value)));
|
|
31860
|
+
const phones = toUniqueStringArray((person.phoneNumbers ?? []).map((entry) => normalizeString(entry.value) ?? normalizeString(entry.canonicalForm)));
|
|
31861
|
+
const organizations = toUniqueStringArray((person.organizations ?? []).flatMap((entry) => [
|
|
31862
|
+
normalizeString(entry.name),
|
|
31863
|
+
normalizeString(entry.title)
|
|
31864
|
+
]));
|
|
31865
|
+
const biography = normalizeString(person.biographies?.[0]?.value);
|
|
31866
|
+
const urls = toUniqueStringArray((person.urls ?? []).map((entry) => normalizeString(entry.value)));
|
|
31867
|
+
return [
|
|
31868
|
+
name,
|
|
31869
|
+
givenName && familyName ? `${givenName} ${familyName}` : givenName ?? familyName,
|
|
31870
|
+
emails.length > 0 ? `Emails: ${emails.join(", ")}` : undefined,
|
|
31871
|
+
phones.length > 0 ? `Phones: ${phones.join(", ")}` : undefined,
|
|
31872
|
+
organizations.length > 0 ? `Organizations: ${organizations.join(", ")}` : undefined,
|
|
31873
|
+
biography,
|
|
31874
|
+
urls.length > 0 ? `Links: ${urls.join(", ")}` : undefined
|
|
31875
|
+
].filter((value) => typeof value === "string" && value.length > 0).join(`
|
|
31876
|
+
`);
|
|
31877
|
+
};
|
|
31878
|
+
var toContactItem = (person) => {
|
|
31879
|
+
const resourceName = normalizeString(person.resourceName);
|
|
31880
|
+
if (!resourceName) {
|
|
31881
|
+
return null;
|
|
31882
|
+
}
|
|
31883
|
+
const contactId = resourceName.replace(/^people\//, "");
|
|
31884
|
+
const title = toContactTitle(person, contactId);
|
|
31885
|
+
const emails = toUniqueStringArray((person.emailAddresses ?? []).map((entry) => normalizeString(entry.value)));
|
|
31886
|
+
const phones = toUniqueStringArray((person.phoneNumbers ?? []).map((entry) => normalizeString(entry.value) ?? normalizeString(entry.canonicalForm)));
|
|
31887
|
+
const organizations = (person.organizations ?? []).map((entry) => ({
|
|
31888
|
+
name: normalizeString(entry.name),
|
|
31889
|
+
title: normalizeString(entry.title)
|
|
31890
|
+
})).filter((entry) => entry.name || entry.title);
|
|
31891
|
+
const urls = toUniqueStringArray((person.urls ?? []).map((entry) => normalizeString(entry.value)));
|
|
31892
|
+
const photoUrl = normalizeString(person.photos?.find((photo) => normalizeString(photo.url) !== undefined)?.url);
|
|
31893
|
+
const text = toContactText(person);
|
|
31894
|
+
return {
|
|
31895
|
+
id: resourceName,
|
|
31896
|
+
kind: "google_contact",
|
|
31897
|
+
metadata: {
|
|
31898
|
+
emails,
|
|
31899
|
+
etag: normalizeString(person.etag),
|
|
31900
|
+
organizations,
|
|
31901
|
+
phones,
|
|
31902
|
+
photoUrl,
|
|
31903
|
+
provider: "google_contacts",
|
|
31904
|
+
resourceName,
|
|
31905
|
+
urls
|
|
31906
|
+
},
|
|
31907
|
+
text: text.length > 0 ? text : title,
|
|
31908
|
+
title,
|
|
31909
|
+
url: urls[0]
|
|
31910
|
+
};
|
|
31911
|
+
};
|
|
31912
|
+
var createRAGGoogleContactsConnector = (input) => ({
|
|
31913
|
+
provider: "google_contacts",
|
|
31914
|
+
requiredScopes: () => GOOGLE_CONTACTS_READ_SCOPES,
|
|
31915
|
+
sync: async ({ checkpoint, credential, resolver }) => {
|
|
31916
|
+
const lease = await resolver.getAccessToken(credential, {
|
|
31917
|
+
requiredScopes: GOOGLE_CONTACTS_READ_SCOPES
|
|
31918
|
+
});
|
|
31919
|
+
const fetchImpl = input?.fetch ?? defaultFetch2;
|
|
31920
|
+
const url = new URL(`${input?.baseUrl ?? GOOGLE_PEOPLE_BASE_URL}/people/me/connections`);
|
|
31921
|
+
url.searchParams.set("personFields", [
|
|
31922
|
+
"names",
|
|
31923
|
+
"emailAddresses",
|
|
31924
|
+
"phoneNumbers",
|
|
31925
|
+
"organizations",
|
|
31926
|
+
"biographies",
|
|
31927
|
+
"urls",
|
|
31928
|
+
"photos"
|
|
31929
|
+
].join(","));
|
|
31930
|
+
url.searchParams.set("pageSize", String(input?.pageSize ?? DEFAULT_GOOGLE_CONTACTS_PAGE_SIZE));
|
|
31931
|
+
const pageToken = normalizeString(checkpoint?.pageToken);
|
|
31932
|
+
if (pageToken) {
|
|
31933
|
+
url.searchParams.set("pageToken", pageToken);
|
|
31934
|
+
}
|
|
31935
|
+
const response = await fetchImpl(url, {
|
|
31936
|
+
headers: {
|
|
31937
|
+
Authorization: `Bearer ${lease.accessToken}`
|
|
31938
|
+
}
|
|
31939
|
+
});
|
|
31940
|
+
if (!response.ok) {
|
|
31941
|
+
throw await toErrorMessage3(response, `Google Contacts sync failed for ${credential.externalAccountId}`);
|
|
31942
|
+
}
|
|
31943
|
+
const json = await response.json();
|
|
31944
|
+
return {
|
|
31945
|
+
items: (json.connections ?? []).map((person) => toContactItem(person)).filter(Boolean),
|
|
31946
|
+
nextCheckpoint: normalizeString(json.nextPageToken) ? { pageToken: normalizeString(json.nextPageToken) } : undefined,
|
|
31947
|
+
diagnostics: {
|
|
31948
|
+
listedCount: json.connections?.length ?? 0,
|
|
31949
|
+
nextPageToken: normalizeString(json.nextPageToken),
|
|
31950
|
+
totalItems: json.totalItems,
|
|
31951
|
+
totalPeople: json.totalPeople
|
|
31952
|
+
}
|
|
31953
|
+
};
|
|
31954
|
+
}
|
|
31955
|
+
});
|
|
31956
|
+
// src/ai/rag/socialProviders.ts
|
|
31957
|
+
var defaultFetch3 = Object.assign((...args) => fetch(...args), { preconnect: fetch.preconnect });
|
|
31825
31958
|
var META_GRAPH_BASE_URL = "https://graph.facebook.com/v22.0";
|
|
31826
31959
|
var DEFAULT_META_PAGE_SIZE = 25;
|
|
31827
31960
|
var FACEBOOK_PAGE_READ_SCOPES = [
|
|
@@ -31832,7 +31965,7 @@ var INSTAGRAM_BUSINESS_READ_SCOPES = [
|
|
|
31832
31965
|
"pages_show_list",
|
|
31833
31966
|
"instagram_basic"
|
|
31834
31967
|
];
|
|
31835
|
-
var
|
|
31968
|
+
var toErrorMessage4 = async (response, label) => {
|
|
31836
31969
|
let detailMessage;
|
|
31837
31970
|
try {
|
|
31838
31971
|
const body = await response.clone().json();
|
|
@@ -31844,7 +31977,7 @@ var toErrorMessage3 = async (response, label) => {
|
|
|
31844
31977
|
return new Error(`${label}: ${response.status} ${response.statusText}${detailMessage ? ` (${detailMessage})` : ""}`);
|
|
31845
31978
|
};
|
|
31846
31979
|
var fetchGraphList = async (input) => {
|
|
31847
|
-
const fetchImpl = input.fetch ??
|
|
31980
|
+
const fetchImpl = input.fetch ?? defaultFetch3;
|
|
31848
31981
|
const url = new URL(`${input.baseUrl ?? META_GRAPH_BASE_URL}${input.path}`);
|
|
31849
31982
|
url.searchParams.set("access_token", input.accessToken);
|
|
31850
31983
|
url.searchParams.set("fields", input.fields.join(","));
|
|
@@ -31854,7 +31987,7 @@ var fetchGraphList = async (input) => {
|
|
|
31854
31987
|
}
|
|
31855
31988
|
const response = await fetchImpl(url);
|
|
31856
31989
|
if (!response.ok) {
|
|
31857
|
-
throw await
|
|
31990
|
+
throw await toErrorMessage4(response, input.label);
|
|
31858
31991
|
}
|
|
31859
31992
|
return await response.json();
|
|
31860
31993
|
};
|
|
@@ -37195,6 +37328,7 @@ export {
|
|
|
37195
37328
|
createRAGHTMXWorkflowRenderConfig,
|
|
37196
37329
|
createRAGHTMXConfig,
|
|
37197
37330
|
createRAGGraphEmailSyncClient,
|
|
37331
|
+
createRAGGoogleContactsConnector,
|
|
37198
37332
|
createRAGGmailEmailSyncClient,
|
|
37199
37333
|
createRAGGitHubSyncSource,
|
|
37200
37334
|
createRAGFileSyncStateStore,
|
|
@@ -37328,5 +37462,5 @@ export {
|
|
|
37328
37462
|
addRAGEvaluationSuiteCase
|
|
37329
37463
|
};
|
|
37330
37464
|
|
|
37331
|
-
//# debugId=
|
|
37465
|
+
//# debugId=8A6927B24E3DD10164756E2164756E21
|
|
37332
37466
|
//# sourceMappingURL=index.js.map
|