@absolutejs/rag 0.0.5 → 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 +421 -18
- package/dist/ai/rag/index.js.map +7 -5
- package/dist/src/ai/rag/contactProviders.d.ts +7 -0
- package/dist/src/ai/rag/index.d.ts +4 -2
- package/dist/src/ai/rag/socialProviders.d.ts +13 -0
- package/dist/src/ai/rag/sync.d.ts +2 -0
- package/dist/src/ai/rag/types.d.ts +24 -2
- package/package.json +1 -1
package/dist/ai/rag/index.js
CHANGED
|
@@ -31820,6 +31820,308 @@ ${tag} OK`) || chunk.startsWith(`${tag} OK`));
|
|
|
31820
31820
|
return { messages };
|
|
31821
31821
|
}
|
|
31822
31822
|
});
|
|
31823
|
+
// src/ai/rag/contactProviders.ts
|
|
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 });
|
|
31958
|
+
var META_GRAPH_BASE_URL = "https://graph.facebook.com/v22.0";
|
|
31959
|
+
var DEFAULT_META_PAGE_SIZE = 25;
|
|
31960
|
+
var FACEBOOK_PAGE_READ_SCOPES = [
|
|
31961
|
+
"pages_show_list",
|
|
31962
|
+
"pages_read_engagement"
|
|
31963
|
+
];
|
|
31964
|
+
var INSTAGRAM_BUSINESS_READ_SCOPES = [
|
|
31965
|
+
"pages_show_list",
|
|
31966
|
+
"instagram_basic"
|
|
31967
|
+
];
|
|
31968
|
+
var toErrorMessage4 = async (response, label) => {
|
|
31969
|
+
let detailMessage;
|
|
31970
|
+
try {
|
|
31971
|
+
const body = await response.clone().json();
|
|
31972
|
+
detailMessage = body.error?.message;
|
|
31973
|
+
} catch {
|
|
31974
|
+
const text = await response.clone().text();
|
|
31975
|
+
detailMessage = text.trim().length > 0 ? text.trim() : undefined;
|
|
31976
|
+
}
|
|
31977
|
+
return new Error(`${label}: ${response.status} ${response.statusText}${detailMessage ? ` (${detailMessage})` : ""}`);
|
|
31978
|
+
};
|
|
31979
|
+
var fetchGraphList = async (input) => {
|
|
31980
|
+
const fetchImpl = input.fetch ?? defaultFetch3;
|
|
31981
|
+
const url = new URL(`${input.baseUrl ?? META_GRAPH_BASE_URL}${input.path}`);
|
|
31982
|
+
url.searchParams.set("access_token", input.accessToken);
|
|
31983
|
+
url.searchParams.set("fields", input.fields.join(","));
|
|
31984
|
+
url.searchParams.set("limit", String(input.limit ?? DEFAULT_META_PAGE_SIZE));
|
|
31985
|
+
if (typeof input.after === "string" && input.after.length > 0) {
|
|
31986
|
+
url.searchParams.set("after", input.after);
|
|
31987
|
+
}
|
|
31988
|
+
const response = await fetchImpl(url);
|
|
31989
|
+
if (!response.ok) {
|
|
31990
|
+
throw await toErrorMessage4(response, input.label);
|
|
31991
|
+
}
|
|
31992
|
+
return await response.json();
|
|
31993
|
+
};
|
|
31994
|
+
var getCheckpointAfter = (checkpoint) => {
|
|
31995
|
+
const after = checkpoint?.after;
|
|
31996
|
+
return typeof after === "string" && after.trim().length > 0 ? after.trim() : undefined;
|
|
31997
|
+
};
|
|
31998
|
+
var getCredentialMetadataString = (metadata, key) => {
|
|
31999
|
+
const value = metadata?.[key];
|
|
32000
|
+
return typeof value === "string" && value.trim().length > 0 ? value.trim() : undefined;
|
|
32001
|
+
};
|
|
32002
|
+
var toFacebookPostItem = (credential, post) => {
|
|
32003
|
+
if (typeof post.id !== "string" || post.id.trim().length === 0) {
|
|
32004
|
+
return null;
|
|
32005
|
+
}
|
|
32006
|
+
const pageName = getCredentialMetadataString(credential.metadata, "label") ?? getCredentialMetadataString(credential.metadata, "pageName") ?? getCredentialMetadataString(credential.metadata, "parentPageName");
|
|
32007
|
+
const message = post.message?.trim() ?? "";
|
|
32008
|
+
return {
|
|
32009
|
+
createdAt: post.created_time,
|
|
32010
|
+
html: undefined,
|
|
32011
|
+
id: post.id,
|
|
32012
|
+
kind: "facebook_post",
|
|
32013
|
+
metadata: {
|
|
32014
|
+
facebookPageId: credential.externalAccountId,
|
|
32015
|
+
facebookPageName: pageName,
|
|
32016
|
+
facebookPictureUrl: post.full_picture,
|
|
32017
|
+
facebookStatusType: post.status_type,
|
|
32018
|
+
provider: "facebook",
|
|
32019
|
+
providerAuthorId: post.from?.id,
|
|
32020
|
+
providerAuthorName: post.from?.name
|
|
32021
|
+
},
|
|
32022
|
+
text: message.length > 0 ? message : post.permalink_url,
|
|
32023
|
+
title: message.length > 0 ? message.slice(0, 120) : `Facebook post ${post.id}`,
|
|
32024
|
+
updatedAt: post.updated_time,
|
|
32025
|
+
url: post.permalink_url
|
|
32026
|
+
};
|
|
32027
|
+
};
|
|
32028
|
+
var toInstagramMediaItem = (credential, media) => {
|
|
32029
|
+
if (typeof media.id !== "string" || media.id.trim().length === 0) {
|
|
32030
|
+
return null;
|
|
32031
|
+
}
|
|
32032
|
+
const caption = media.caption?.trim() ?? "";
|
|
32033
|
+
const username = getCredentialMetadataString(credential.metadata, "instagramUsername");
|
|
32034
|
+
return {
|
|
32035
|
+
createdAt: media.timestamp,
|
|
32036
|
+
id: media.id,
|
|
32037
|
+
kind: "instagram_media",
|
|
32038
|
+
metadata: {
|
|
32039
|
+
instagramMediaType: media.media_type,
|
|
32040
|
+
instagramThumbnailUrl: media.thumbnail_url,
|
|
32041
|
+
instagramUsername: media.username ?? username,
|
|
32042
|
+
provider: "instagram",
|
|
32043
|
+
providerAccountId: credential.externalAccountId,
|
|
32044
|
+
providerMediaUrl: media.media_url
|
|
32045
|
+
},
|
|
32046
|
+
text: caption.length > 0 ? caption : media.permalink,
|
|
32047
|
+
title: caption.length > 0 ? caption.slice(0, 120) : `Instagram media ${media.id}`,
|
|
32048
|
+
url: media.permalink
|
|
32049
|
+
};
|
|
32050
|
+
};
|
|
32051
|
+
var createRAGFacebookPageConnector = (input) => ({
|
|
32052
|
+
provider: "facebook",
|
|
32053
|
+
requiredScopes: () => FACEBOOK_PAGE_READ_SCOPES,
|
|
32054
|
+
sync: async ({ checkpoint, credential, resolver }) => {
|
|
32055
|
+
const lease = await resolver.getAccessToken(credential, {
|
|
32056
|
+
requiredScopes: FACEBOOK_PAGE_READ_SCOPES
|
|
32057
|
+
});
|
|
32058
|
+
const pageAccessToken = getCredentialMetadataString(credential.metadata, "pageAccessToken") ?? lease.accessToken;
|
|
32059
|
+
const response = await fetchGraphList({
|
|
32060
|
+
accessToken: pageAccessToken,
|
|
32061
|
+
after: getCheckpointAfter(checkpoint),
|
|
32062
|
+
baseUrl: input?.baseUrl,
|
|
32063
|
+
fetch: input?.fetch,
|
|
32064
|
+
fields: [
|
|
32065
|
+
"id",
|
|
32066
|
+
"message",
|
|
32067
|
+
"created_time",
|
|
32068
|
+
"updated_time",
|
|
32069
|
+
"permalink_url",
|
|
32070
|
+
"full_picture",
|
|
32071
|
+
"status_type",
|
|
32072
|
+
"from{id,name}"
|
|
32073
|
+
],
|
|
32074
|
+
label: `Facebook Page sync failed for ${credential.externalAccountId}`,
|
|
32075
|
+
limit: input?.limit,
|
|
32076
|
+
path: `/${encodeURIComponent(credential.externalAccountId)}/posts`
|
|
32077
|
+
});
|
|
32078
|
+
return {
|
|
32079
|
+
items: (response.data ?? []).map((post) => toFacebookPostItem(credential, post)).filter(Boolean),
|
|
32080
|
+
nextCheckpoint: response.paging?.cursors?.after ? { after: response.paging.cursors.after } : undefined,
|
|
32081
|
+
diagnostics: {
|
|
32082
|
+
listedCount: response.data?.length ?? 0,
|
|
32083
|
+
nextAfter: response.paging?.cursors?.after
|
|
32084
|
+
}
|
|
32085
|
+
};
|
|
32086
|
+
}
|
|
32087
|
+
});
|
|
32088
|
+
var createRAGInstagramBusinessConnector = (input) => ({
|
|
32089
|
+
provider: "instagram",
|
|
32090
|
+
requiredScopes: () => INSTAGRAM_BUSINESS_READ_SCOPES,
|
|
32091
|
+
sync: async ({ checkpoint, credential, resolver }) => {
|
|
32092
|
+
const lease = await resolver.getAccessToken(credential, {
|
|
32093
|
+
requiredScopes: INSTAGRAM_BUSINESS_READ_SCOPES
|
|
32094
|
+
});
|
|
32095
|
+
const accessToken = getCredentialMetadataString(credential.metadata, "parentPageAccessToken") ?? lease.accessToken;
|
|
32096
|
+
const response = await fetchGraphList({
|
|
32097
|
+
accessToken,
|
|
32098
|
+
after: getCheckpointAfter(checkpoint),
|
|
32099
|
+
baseUrl: input?.baseUrl,
|
|
32100
|
+
fetch: input?.fetch,
|
|
32101
|
+
fields: [
|
|
32102
|
+
"id",
|
|
32103
|
+
"caption",
|
|
32104
|
+
"media_type",
|
|
32105
|
+
"media_url",
|
|
32106
|
+
"permalink",
|
|
32107
|
+
"thumbnail_url",
|
|
32108
|
+
"timestamp",
|
|
32109
|
+
"username"
|
|
32110
|
+
],
|
|
32111
|
+
label: `Instagram business sync failed for ${credential.externalAccountId}`,
|
|
32112
|
+
limit: input?.limit,
|
|
32113
|
+
path: `/${encodeURIComponent(credential.externalAccountId)}/media`
|
|
32114
|
+
});
|
|
32115
|
+
return {
|
|
32116
|
+
items: (response.data ?? []).map((media) => toInstagramMediaItem(credential, media)).filter(Boolean),
|
|
32117
|
+
nextCheckpoint: response.paging?.cursors?.after ? { after: response.paging.cursors.after } : undefined,
|
|
32118
|
+
diagnostics: {
|
|
32119
|
+
listedCount: response.data?.length ?? 0,
|
|
32120
|
+
nextAfter: response.paging?.cursors?.after
|
|
32121
|
+
}
|
|
32122
|
+
};
|
|
32123
|
+
}
|
|
32124
|
+
});
|
|
31823
32125
|
// src/ai/rag/sync.ts
|
|
31824
32126
|
var {S3Client } = globalThis.Bun;
|
|
31825
32127
|
import { createHash } from "crypto";
|
|
@@ -31834,6 +32136,10 @@ var wait = async (delayMs) => {
|
|
|
31834
32136
|
};
|
|
31835
32137
|
var getSyncMetadataString = (metadata, key) => typeof metadata?.[key] === "string" ? metadata[key] : undefined;
|
|
31836
32138
|
var getSyncMetadataBoolean = (metadata, key) => metadata?.[key] === true;
|
|
32139
|
+
var getSyncMetadataRecord = (metadata, key) => {
|
|
32140
|
+
const value = metadata?.[key];
|
|
32141
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : undefined;
|
|
32142
|
+
};
|
|
31837
32143
|
var DEFAULT_DIRECTORY_EXTENSIONS2 = [
|
|
31838
32144
|
".txt",
|
|
31839
32145
|
".md",
|
|
@@ -32172,12 +32478,30 @@ var toManagedSyncDocument = (sourceId, document, syncKey) => ({
|
|
|
32172
32478
|
}
|
|
32173
32479
|
});
|
|
32174
32480
|
var encodeAttachmentContent = (attachment) => typeof attachment.content === "string" ? {
|
|
32175
|
-
content: attachment.content,
|
|
32481
|
+
content: sanitizeSyncString(attachment.content),
|
|
32176
32482
|
encoding: attachment.encoding ?? "utf8"
|
|
32177
32483
|
} : {
|
|
32178
32484
|
content: Buffer.from(attachment.content).toString("base64"),
|
|
32179
32485
|
encoding: "base64"
|
|
32180
32486
|
};
|
|
32487
|
+
var sanitizeSyncString = (value) => value.replace(/\u0000/g, "");
|
|
32488
|
+
var sanitizeOptionalSyncString = (value) => typeof value === "string" ? sanitizeSyncString(value) : value;
|
|
32489
|
+
var sanitizeSyncStringList = (value) => value?.map((entry) => sanitizeSyncString(entry)).filter((entry) => typeof entry === "string");
|
|
32490
|
+
var sanitizeSyncMetadataValue = (value) => {
|
|
32491
|
+
if (typeof value === "string") {
|
|
32492
|
+
return sanitizeSyncString(value);
|
|
32493
|
+
}
|
|
32494
|
+
if (Array.isArray(value)) {
|
|
32495
|
+
return value.map((entry) => sanitizeSyncMetadataValue(entry));
|
|
32496
|
+
}
|
|
32497
|
+
if (value && typeof value === "object") {
|
|
32498
|
+
return Object.fromEntries(Object.entries(value).map(([key, entry]) => [
|
|
32499
|
+
key,
|
|
32500
|
+
sanitizeSyncMetadataValue(entry)
|
|
32501
|
+
]));
|
|
32502
|
+
}
|
|
32503
|
+
return value;
|
|
32504
|
+
};
|
|
32181
32505
|
var toTimestamp = (value) => {
|
|
32182
32506
|
if (typeof value === "number" && Number.isFinite(value)) {
|
|
32183
32507
|
return value;
|
|
@@ -33893,21 +34217,21 @@ var createRAGEmailSyncSource = (options) => ({
|
|
|
33893
34217
|
id: `email-${message.id}`,
|
|
33894
34218
|
metadata: {
|
|
33895
34219
|
...options.baseMetadata ?? {},
|
|
33896
|
-
...message.metadata ?? {},
|
|
34220
|
+
...sanitizeSyncMetadataValue(message.metadata ?? {}) ?? {},
|
|
33897
34221
|
emailKind: "message",
|
|
33898
|
-
from: message.from,
|
|
34222
|
+
from: sanitizeOptionalSyncString(message.from),
|
|
33899
34223
|
hasAttachments: (message.attachments?.length ?? 0) > 0,
|
|
33900
34224
|
messageId: message.id,
|
|
33901
34225
|
receivedAt: toTimestamp(message.receivedAt),
|
|
33902
34226
|
sentAt: toTimestamp(message.sentAt),
|
|
33903
|
-
threadId: message.threadId,
|
|
33904
|
-
threadTopic: message.subject,
|
|
33905
|
-
to: message.to,
|
|
33906
|
-
cc: message.cc
|
|
34227
|
+
threadId: sanitizeOptionalSyncString(message.threadId),
|
|
34228
|
+
threadTopic: sanitizeOptionalSyncString(message.subject),
|
|
34229
|
+
to: sanitizeSyncStringList(message.to),
|
|
34230
|
+
cc: sanitizeSyncStringList(message.cc)
|
|
33907
34231
|
},
|
|
33908
|
-
source: `email/${message.threadId ?? message.id}`,
|
|
33909
|
-
text: message.bodyText,
|
|
33910
|
-
title: message.subject ?? message.id
|
|
34232
|
+
source: `email/${sanitizeOptionalSyncString(message.threadId) ?? message.id}`,
|
|
34233
|
+
text: sanitizeOptionalSyncString(message.bodyText) ?? "",
|
|
34234
|
+
title: sanitizeOptionalSyncString(message.subject) ?? message.id
|
|
33911
34235
|
}));
|
|
33912
34236
|
const attachmentUploads = listed.messages.flatMap((message) => (message.attachments ?? []).map((attachment, index) => ({
|
|
33913
34237
|
...encodeAttachmentContent(attachment),
|
|
@@ -33916,18 +34240,18 @@ var createRAGEmailSyncSource = (options) => ({
|
|
|
33916
34240
|
format: attachment.format,
|
|
33917
34241
|
metadata: {
|
|
33918
34242
|
...options.baseMetadata ?? {},
|
|
33919
|
-
...attachment.metadata ?? {},
|
|
34243
|
+
...sanitizeSyncMetadataValue(attachment.metadata ?? {}) ?? {},
|
|
33920
34244
|
attachmentId: attachment.id ?? `${message.id}-attachment-${index + 1}`,
|
|
33921
34245
|
emailKind: "attachment",
|
|
33922
|
-
from: message.from,
|
|
34246
|
+
from: sanitizeOptionalSyncString(message.from),
|
|
33923
34247
|
messageId: message.id,
|
|
33924
34248
|
sentAt: toTimestamp(message.sentAt),
|
|
33925
|
-
threadId: message.threadId,
|
|
33926
|
-
threadTopic: message.subject
|
|
34249
|
+
threadId: sanitizeOptionalSyncString(message.threadId),
|
|
34250
|
+
threadTopic: sanitizeOptionalSyncString(message.subject)
|
|
33927
34251
|
},
|
|
33928
|
-
name: attachment.name
|
|
33929
|
-
source: attachment.source ?? `email/${message.threadId ?? message.id}/attachments/${attachment.name}`,
|
|
33930
|
-
title: attachment.title ?? `${message.subject ?? message.id} \xB7 ${attachment.name}`
|
|
34252
|
+
name: sanitizeOptionalSyncString(attachment.name) ?? `attachment-${index + 1}`,
|
|
34253
|
+
source: sanitizeOptionalSyncString(attachment.source) ?? `email/${sanitizeOptionalSyncString(message.threadId) ?? message.id}/attachments/${sanitizeOptionalSyncString(attachment.name) ?? `attachment-${index + 1}`}`,
|
|
34254
|
+
title: sanitizeOptionalSyncString(attachment.title) ?? `${sanitizeOptionalSyncString(message.subject) ?? message.id} \xB7 ${sanitizeOptionalSyncString(attachment.name) ?? `attachment-${index + 1}`}`
|
|
33931
34255
|
})));
|
|
33932
34256
|
const extractionFailures = [];
|
|
33933
34257
|
const loadedAttachments = attachmentUploads.length > 0 ? (await Promise.all(attachmentUploads.map(async (upload) => {
|
|
@@ -33987,6 +34311,81 @@ var createRAGEmailSyncSource = (options) => ({
|
|
|
33987
34311
|
};
|
|
33988
34312
|
}
|
|
33989
34313
|
});
|
|
34314
|
+
var createRAGLinkedConnectorSyncSource = (options) => ({
|
|
34315
|
+
description: options.description,
|
|
34316
|
+
id: options.id,
|
|
34317
|
+
kind: "custom",
|
|
34318
|
+
label: options.label,
|
|
34319
|
+
metadata: options.metadata,
|
|
34320
|
+
retryAttempts: options.retryAttempts,
|
|
34321
|
+
retryDelayMs: options.retryDelayMs,
|
|
34322
|
+
target: options.externalAccountId ?? options.bindingId ?? options.label,
|
|
34323
|
+
sync: async ({ collection, deleteDocument, listDocuments, sourceRecord }) => {
|
|
34324
|
+
const requiredScopes = options.requiredScopes ?? options.runtime.requiredScopes({ mode: "read" });
|
|
34325
|
+
const credential = await options.resolver.resolveCredential({
|
|
34326
|
+
bindingId: options.bindingId,
|
|
34327
|
+
connectorProvider: options.runtime.provider,
|
|
34328
|
+
externalAccountId: options.externalAccountId,
|
|
34329
|
+
ownerRef: options.ownerRef,
|
|
34330
|
+
purpose: options.purpose ?? "background_sync",
|
|
34331
|
+
requiredScopes
|
|
34332
|
+
});
|
|
34333
|
+
if (!credential) {
|
|
34334
|
+
throw new Error(`No linked ${options.runtime.provider} credential could be resolved`);
|
|
34335
|
+
}
|
|
34336
|
+
const checkpoint = getSyncMetadataRecord(sourceRecord?.metadata, "connectorCheckpoint");
|
|
34337
|
+
const result = await options.runtime.sync({
|
|
34338
|
+
checkpoint,
|
|
34339
|
+
credential,
|
|
34340
|
+
resolver: options.resolver
|
|
34341
|
+
});
|
|
34342
|
+
const managedDocuments = result.items.map((item, index) => toManagedSyncDocument(options.id, {
|
|
34343
|
+
chunking: options.defaultChunking,
|
|
34344
|
+
format: item.html ? "html" : "text",
|
|
34345
|
+
id: `${options.runtime.provider}-${item.id}`,
|
|
34346
|
+
metadata: {
|
|
34347
|
+
...options.baseMetadata ?? {},
|
|
34348
|
+
...sanitizeSyncMetadataValue(item.metadata ?? {}) ?? {},
|
|
34349
|
+
connectorBindingId: credential.bindingId,
|
|
34350
|
+
connectorExternalAccountId: credential.externalAccountId,
|
|
34351
|
+
connectorKind: item.kind,
|
|
34352
|
+
connectorProvider: options.runtime.provider,
|
|
34353
|
+
createdAt: toTimestamp(item.createdAt),
|
|
34354
|
+
itemId: item.id,
|
|
34355
|
+
threadId: sanitizeOptionalSyncString(item.threadId),
|
|
34356
|
+
updatedAt: toTimestamp(item.updatedAt),
|
|
34357
|
+
url: sanitizeOptionalSyncString(item.url)
|
|
34358
|
+
},
|
|
34359
|
+
source: sanitizeOptionalSyncString(item.url) ?? `connector/${options.runtime.provider}/${sanitizeOptionalSyncString(item.threadId) ?? item.id}`,
|
|
34360
|
+
text: sanitizeOptionalSyncString(item.text) ?? sanitizeOptionalSyncString(item.html) ?? "",
|
|
34361
|
+
title: sanitizeOptionalSyncString(item.title) ?? item.id
|
|
34362
|
+
}, `${item.kind}:${item.id}:${index + 1}`));
|
|
34363
|
+
const reconciled = await reconcileManagedDocuments({
|
|
34364
|
+
chunkingRegistry: options.chunkingRegistry,
|
|
34365
|
+
collection,
|
|
34366
|
+
defaultChunking: options.defaultChunking,
|
|
34367
|
+
deleteDocument,
|
|
34368
|
+
documents: managedDocuments,
|
|
34369
|
+
listDocuments,
|
|
34370
|
+
sourceId: options.id,
|
|
34371
|
+
allowDeletions: result.nextCheckpoint === undefined
|
|
34372
|
+
});
|
|
34373
|
+
return {
|
|
34374
|
+
chunkCount: reconciled.chunkCount,
|
|
34375
|
+
documentCount: reconciled.documentCount,
|
|
34376
|
+
metadata: {
|
|
34377
|
+
connectorCheckpoint: result.nextCheckpoint,
|
|
34378
|
+
connectorDiagnostics: result.diagnostics,
|
|
34379
|
+
connectorItemCount: result.items.length,
|
|
34380
|
+
connectorProvider: options.runtime.provider,
|
|
34381
|
+
deletedCount: reconciled.deletedCount,
|
|
34382
|
+
resumePending: result.nextCheckpoint !== undefined,
|
|
34383
|
+
updatedCount: reconciled.updatedCount
|
|
34384
|
+
},
|
|
34385
|
+
reconciliation: reconciled.reconciliation
|
|
34386
|
+
};
|
|
34387
|
+
}
|
|
34388
|
+
});
|
|
33990
34389
|
var createRAGLinkedGmailEmailSyncSource = (options) => createRAGEmailSyncSource({
|
|
33991
34390
|
...options,
|
|
33992
34391
|
client: createRAGLinkedGmailEmailSyncClient(options)
|
|
@@ -36922,11 +37321,14 @@ export {
|
|
|
36922
37321
|
createRAGMediaFileExtractor,
|
|
36923
37322
|
createRAGLinkedGmailEmailSyncSource,
|
|
36924
37323
|
createRAGLinkedGmailEmailSyncClient,
|
|
37324
|
+
createRAGLinkedConnectorSyncSource,
|
|
37325
|
+
createRAGInstagramBusinessConnector,
|
|
36925
37326
|
createRAGImageOCRExtractor,
|
|
36926
37327
|
createRAGIMAPEmailSyncClient,
|
|
36927
37328
|
createRAGHTMXWorkflowRenderConfig,
|
|
36928
37329
|
createRAGHTMXConfig,
|
|
36929
37330
|
createRAGGraphEmailSyncClient,
|
|
37331
|
+
createRAGGoogleContactsConnector,
|
|
36930
37332
|
createRAGGmailEmailSyncClient,
|
|
36931
37333
|
createRAGGitHubSyncSource,
|
|
36932
37334
|
createRAGFileSyncStateStore,
|
|
@@ -36953,6 +37355,7 @@ export {
|
|
|
36953
37355
|
createRAGFileAnswerGroundingEvaluationHistoryStore,
|
|
36954
37356
|
createRAGFileAnswerGroundingCaseDifficultyHistoryStore,
|
|
36955
37357
|
createRAGFeedSyncSource,
|
|
37358
|
+
createRAGFacebookPageConnector,
|
|
36956
37359
|
createRAGEvaluationSuiteSnapshot,
|
|
36957
37360
|
createRAGEvaluationSuite,
|
|
36958
37361
|
createRAGEmbeddingProvider,
|
|
@@ -37059,5 +37462,5 @@ export {
|
|
|
37059
37462
|
addRAGEvaluationSuiteCase
|
|
37060
37463
|
};
|
|
37061
37464
|
|
|
37062
|
-
//# debugId=
|
|
37465
|
+
//# debugId=8A6927B24E3DD10164756E2164756E21
|
|
37063
37466
|
//# sourceMappingURL=index.js.map
|