@absolutejs/absolute 0.19.0-beta.502 → 0.19.0-beta.504
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 +96 -1
- package/dist/ai/client/index.js.map +3 -3
- package/dist/ai/index.js +387 -1
- package/dist/ai/index.js.map +5 -4
- package/dist/ai-client/angular/ai/index.js +95 -0
- package/dist/ai-client/react/ai/index.js +95 -0
- package/dist/ai-client/vue/ai/index.js +95 -0
- package/dist/angular/ai/index.js +96 -1
- package/dist/angular/ai/index.js.map +3 -3
- package/dist/angular/index.js +2 -2
- package/dist/angular/index.js.map +1 -1
- package/dist/angular/server.js +2 -2
- package/dist/angular/server.js.map +1 -1
- package/dist/build.js +2 -2
- package/dist/build.js.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/react/ai/index.js +96 -1
- package/dist/react/ai/index.js.map +3 -3
- package/dist/src/ai/index.d.ts +2 -2
- package/dist/src/ai/rag/emailProviders.d.ts +33 -0
- package/dist/src/ai/rag/index.d.ts +2 -0
- package/dist/svelte/ai/index.js +96 -1
- package/dist/svelte/ai/index.js.map +3 -3
- package/dist/types/ai.d.ts +5 -0
- package/dist/vue/ai/index.js +96 -1
- package/dist/vue/ai/index.js.map +3 -3
- package/package.json +1 -1
package/dist/ai/index.js
CHANGED
|
@@ -6833,15 +6833,342 @@ var openaiTranscriber = (config) => {
|
|
|
6833
6833
|
}
|
|
6834
6834
|
});
|
|
6835
6835
|
};
|
|
6836
|
+
// src/ai/rag/emailProviders.ts
|
|
6837
|
+
import { connect as connectTls } from "tls";
|
|
6838
|
+
var defaultFetch = (...args) => fetch(...args);
|
|
6839
|
+
var stripHtml2 = (value) => value.replace(/<style[\s\S]*?<\/style>/gi, " ").replace(/<script[\s\S]*?<\/script>/gi, " ").replace(/<[^>]+>/g, " ").replace(/ /gi, " ").replace(/&/gi, "&").replace(/\s+/g, " ").trim();
|
|
6840
|
+
var decodeBase64Url = (value) => {
|
|
6841
|
+
const normalized = value.replace(/-/g, "+").replace(/_/g, "/");
|
|
6842
|
+
const padding = normalized.length % 4 === 0 ? "" : "=".repeat(4 - normalized.length % 4);
|
|
6843
|
+
return Buffer.from(normalized + padding, "base64");
|
|
6844
|
+
};
|
|
6845
|
+
var firstHeader = (headers, name) => headers?.find((header) => header.name?.toLowerCase() === name.toLowerCase())?.value;
|
|
6846
|
+
var collectGmailPayloadParts = (payload) => {
|
|
6847
|
+
if (!payload) {
|
|
6848
|
+
return [];
|
|
6849
|
+
}
|
|
6850
|
+
return [
|
|
6851
|
+
payload,
|
|
6852
|
+
...(payload.parts ?? []).flatMap((part) => collectGmailPayloadParts(part))
|
|
6853
|
+
];
|
|
6854
|
+
};
|
|
6855
|
+
var extractGmailBodyText = (payload) => {
|
|
6856
|
+
const parts = collectGmailPayloadParts(payload);
|
|
6857
|
+
const plain = parts.find((part) => part.mimeType?.toLowerCase() === "text/plain" && part.body?.data);
|
|
6858
|
+
if (plain?.body?.data) {
|
|
6859
|
+
return decodeBase64Url(plain.body.data).toString("utf8");
|
|
6860
|
+
}
|
|
6861
|
+
const html = parts.find((part) => part.mimeType?.toLowerCase() === "text/html" && part.body?.data);
|
|
6862
|
+
if (html?.body?.data) {
|
|
6863
|
+
return stripHtml2(decodeBase64Url(html.body.data).toString("utf8"));
|
|
6864
|
+
}
|
|
6865
|
+
if (payload?.body?.data) {
|
|
6866
|
+
return decodeBase64Url(payload.body.data).toString("utf8");
|
|
6867
|
+
}
|
|
6868
|
+
return "";
|
|
6869
|
+
};
|
|
6870
|
+
var toGraphAddressList = (value) => value?.map((entry) => entry.emailAddress?.address).filter(Boolean);
|
|
6871
|
+
var toGraphAttachment = (attachment) => attachment.name && attachment.contentBytes ? {
|
|
6872
|
+
content: attachment.contentBytes,
|
|
6873
|
+
contentType: attachment.contentType,
|
|
6874
|
+
encoding: "base64",
|
|
6875
|
+
id: attachment.id,
|
|
6876
|
+
name: attachment.name
|
|
6877
|
+
} : null;
|
|
6878
|
+
var buildGraphPath = (config) => {
|
|
6879
|
+
const base = config.userId && config.userId !== "me" ? `/users/${encodeURIComponent(config.userId)}` : "/me";
|
|
6880
|
+
return config.folderId ? `${base}/mailFolders/${encodeURIComponent(config.folderId)}/messages` : `${base}/messages`;
|
|
6881
|
+
};
|
|
6882
|
+
var parseRawEmail = (raw) => {
|
|
6883
|
+
const [headerBlock, ...bodyBlocks] = raw.split(/\r?\n\r?\n/);
|
|
6884
|
+
const body = bodyBlocks.join(`
|
|
6885
|
+
|
|
6886
|
+
`).trim();
|
|
6887
|
+
const lines = (headerBlock ?? "").split(/\r?\n/);
|
|
6888
|
+
const headers = new Map;
|
|
6889
|
+
let current = "";
|
|
6890
|
+
for (const line of lines) {
|
|
6891
|
+
if (/^\s/.test(line) && current) {
|
|
6892
|
+
headers.set(current, `${headers.get(current) ?? ""} ${line.trim()}`.trim());
|
|
6893
|
+
continue;
|
|
6894
|
+
}
|
|
6895
|
+
const separator = line.indexOf(":");
|
|
6896
|
+
if (separator < 0) {
|
|
6897
|
+
continue;
|
|
6898
|
+
}
|
|
6899
|
+
current = line.slice(0, separator).trim().toLowerCase();
|
|
6900
|
+
headers.set(current, line.slice(separator + 1).trim());
|
|
6901
|
+
}
|
|
6902
|
+
const toList = (value) => value?.split(",").map((entry) => entry.trim()).filter(Boolean);
|
|
6903
|
+
return {
|
|
6904
|
+
bodyText: body,
|
|
6905
|
+
cc: toList(headers.get("cc")),
|
|
6906
|
+
from: headers.get("from"),
|
|
6907
|
+
id: headers.get("message-id") ?? headers.get("subject") ?? crypto.randomUUID(),
|
|
6908
|
+
receivedAt: headers.get("date"),
|
|
6909
|
+
subject: headers.get("subject"),
|
|
6910
|
+
threadId: headers.get("thread-topic") ?? headers.get("references") ?? headers.get("subject"),
|
|
6911
|
+
to: toList(headers.get("to"))
|
|
6912
|
+
};
|
|
6913
|
+
};
|
|
6914
|
+
var createRAGGmailEmailSyncClient = (config) => ({
|
|
6915
|
+
listMessages: async (input) => {
|
|
6916
|
+
const fetchImpl = config.fetch ?? defaultFetch;
|
|
6917
|
+
const userId = config.userId ?? "me";
|
|
6918
|
+
const listUrl = new URL(`https://gmail.googleapis.com/gmail/v1/users/${encodeURIComponent(userId)}/messages`);
|
|
6919
|
+
listUrl.searchParams.set("maxResults", String(input?.maxResults ?? config.maxResults ?? 100));
|
|
6920
|
+
if (input?.cursor) {
|
|
6921
|
+
listUrl.searchParams.set("pageToken", input.cursor);
|
|
6922
|
+
}
|
|
6923
|
+
if (config.query) {
|
|
6924
|
+
listUrl.searchParams.set("q", config.query);
|
|
6925
|
+
}
|
|
6926
|
+
for (const labelId of config.labelIds ?? []) {
|
|
6927
|
+
listUrl.searchParams.append("labelIds", labelId);
|
|
6928
|
+
}
|
|
6929
|
+
if (config.includeSpamTrash) {
|
|
6930
|
+
listUrl.searchParams.set("includeSpamTrash", "true");
|
|
6931
|
+
}
|
|
6932
|
+
const listResponse = await fetchImpl(listUrl, {
|
|
6933
|
+
headers: { Authorization: `Bearer ${config.accessToken}` }
|
|
6934
|
+
});
|
|
6935
|
+
if (!listResponse.ok) {
|
|
6936
|
+
throw new Error(`Gmail list failed: ${listResponse.status} ${listResponse.statusText}`);
|
|
6937
|
+
}
|
|
6938
|
+
const listJson = await listResponse.json();
|
|
6939
|
+
const messages = await Promise.all((listJson.messages ?? []).map(async (messageRef) => {
|
|
6940
|
+
const getUrl = new URL(`https://gmail.googleapis.com/gmail/v1/users/${encodeURIComponent(userId)}/messages/${encodeURIComponent(messageRef.id)}`);
|
|
6941
|
+
getUrl.searchParams.set("format", "full");
|
|
6942
|
+
const response = await fetchImpl(getUrl, {
|
|
6943
|
+
headers: { Authorization: `Bearer ${config.accessToken}` }
|
|
6944
|
+
});
|
|
6945
|
+
if (!response.ok) {
|
|
6946
|
+
throw new Error(`Gmail get failed for ${messageRef.id}: ${response.status} ${response.statusText}`);
|
|
6947
|
+
}
|
|
6948
|
+
const json = await response.json();
|
|
6949
|
+
const attachments = await Promise.all(collectGmailPayloadParts(json.payload).filter((part) => !!part.filename && !!part.body?.attachmentId).map(async (part) => {
|
|
6950
|
+
const attachmentUrl = new URL(`https://gmail.googleapis.com/gmail/v1/users/${encodeURIComponent(userId)}/messages/${encodeURIComponent(json.id)}/attachments/${encodeURIComponent(part.body?.attachmentId ?? "")}`);
|
|
6951
|
+
const attachmentResponse = await fetchImpl(attachmentUrl, {
|
|
6952
|
+
headers: {
|
|
6953
|
+
Authorization: `Bearer ${config.accessToken}`
|
|
6954
|
+
}
|
|
6955
|
+
});
|
|
6956
|
+
if (!attachmentResponse.ok) {
|
|
6957
|
+
return null;
|
|
6958
|
+
}
|
|
6959
|
+
const attachmentJson = await attachmentResponse.json();
|
|
6960
|
+
if (!attachmentJson.data || !part.filename) {
|
|
6961
|
+
return null;
|
|
6962
|
+
}
|
|
6963
|
+
return {
|
|
6964
|
+
content: decodeBase64Url(attachmentJson.data).toString("base64"),
|
|
6965
|
+
contentType: part.mimeType,
|
|
6966
|
+
encoding: "base64",
|
|
6967
|
+
id: part.body?.attachmentId,
|
|
6968
|
+
name: part.filename
|
|
6969
|
+
};
|
|
6970
|
+
}));
|
|
6971
|
+
return {
|
|
6972
|
+
attachments: attachments.filter(Boolean),
|
|
6973
|
+
bodyText: extractGmailBodyText(json.payload) || json.snippet || "",
|
|
6974
|
+
cc: firstHeader(json.payload?.headers, "Cc")?.split(",").map((entry) => entry.trim()).filter(Boolean),
|
|
6975
|
+
from: firstHeader(json.payload?.headers, "From"),
|
|
6976
|
+
id: json.id,
|
|
6977
|
+
metadata: {
|
|
6978
|
+
gmailLabelIds: json.labelIds,
|
|
6979
|
+
provider: "gmail"
|
|
6980
|
+
},
|
|
6981
|
+
receivedAt: json.internalDate ? Number(json.internalDate) : undefined,
|
|
6982
|
+
subject: firstHeader(json.payload?.headers, "Subject"),
|
|
6983
|
+
threadId: json.threadId ?? messageRef.threadId,
|
|
6984
|
+
to: firstHeader(json.payload?.headers, "To")?.split(",").map((entry) => entry.trim()).filter(Boolean)
|
|
6985
|
+
};
|
|
6986
|
+
}));
|
|
6987
|
+
return {
|
|
6988
|
+
messages,
|
|
6989
|
+
nextCursor: listJson.nextPageToken
|
|
6990
|
+
};
|
|
6991
|
+
}
|
|
6992
|
+
});
|
|
6993
|
+
var createRAGGraphEmailSyncClient = (config) => ({
|
|
6994
|
+
listMessages: async (input) => {
|
|
6995
|
+
const fetchImpl = config.fetch ?? defaultFetch;
|
|
6996
|
+
const url = new URL(`${config.baseUrl ?? "https://graph.microsoft.com/v1.0"}${buildGraphPath(config)}`);
|
|
6997
|
+
url.searchParams.set("$select", "id,conversationId,subject,from,toRecipients,ccRecipients,sentDateTime,receivedDateTime,body,hasAttachments,internetMessageId");
|
|
6998
|
+
url.searchParams.set("$top", String(input?.maxResults ?? config.top ?? 100));
|
|
6999
|
+
if (config.filter) {
|
|
7000
|
+
url.searchParams.set("$filter", config.filter);
|
|
7001
|
+
}
|
|
7002
|
+
if (config.search) {
|
|
7003
|
+
url.searchParams.set("$search", config.search);
|
|
7004
|
+
}
|
|
7005
|
+
if (input?.cursor) {
|
|
7006
|
+
return {
|
|
7007
|
+
messages: [],
|
|
7008
|
+
nextCursor: input.cursor
|
|
7009
|
+
};
|
|
7010
|
+
}
|
|
7011
|
+
const listResponse = await fetchImpl(url, {
|
|
7012
|
+
headers: {
|
|
7013
|
+
Authorization: `Bearer ${config.accessToken}`,
|
|
7014
|
+
Prefer: 'outlook.body-content-type="text"'
|
|
7015
|
+
}
|
|
7016
|
+
});
|
|
7017
|
+
if (!listResponse.ok) {
|
|
7018
|
+
throw new Error(`Graph message list failed: ${listResponse.status} ${listResponse.statusText}`);
|
|
7019
|
+
}
|
|
7020
|
+
const listJson = await listResponse.json();
|
|
7021
|
+
const messages = await Promise.all((listJson.value ?? []).map(async (message) => {
|
|
7022
|
+
const attachments = message.hasAttachments === true ? await (async () => {
|
|
7023
|
+
const attachmentsResponse = await fetchImpl(`${config.baseUrl ?? "https://graph.microsoft.com/v1.0"}${buildGraphPath(config)}/${encodeURIComponent(String(message.id))}/attachments`, {
|
|
7024
|
+
headers: {
|
|
7025
|
+
Authorization: `Bearer ${config.accessToken}`
|
|
7026
|
+
}
|
|
7027
|
+
});
|
|
7028
|
+
if (!attachmentsResponse.ok) {
|
|
7029
|
+
return [];
|
|
7030
|
+
}
|
|
7031
|
+
const attachmentsJson = await attachmentsResponse.json();
|
|
7032
|
+
return (attachmentsJson.value ?? []).map((attachment) => toGraphAttachment(attachment)).filter(Boolean);
|
|
7033
|
+
})() : [];
|
|
7034
|
+
return {
|
|
7035
|
+
attachments,
|
|
7036
|
+
bodyText: typeof message.body?.content === "string" ? String(message.body.content) : "",
|
|
7037
|
+
cc: toGraphAddressList(message.ccRecipients),
|
|
7038
|
+
from: message.from?.emailAddress?.address,
|
|
7039
|
+
id: String(message.id),
|
|
7040
|
+
metadata: {
|
|
7041
|
+
internetMessageId: message.internetMessageId,
|
|
7042
|
+
provider: "graph"
|
|
7043
|
+
},
|
|
7044
|
+
receivedAt: message.receivedDateTime,
|
|
7045
|
+
sentAt: message.sentDateTime,
|
|
7046
|
+
subject: message.subject,
|
|
7047
|
+
threadId: message.conversationId,
|
|
7048
|
+
to: toGraphAddressList(message.toRecipients)
|
|
7049
|
+
};
|
|
7050
|
+
}));
|
|
7051
|
+
return {
|
|
7052
|
+
messages,
|
|
7053
|
+
nextCursor: listJson["@odata.nextLink"]
|
|
7054
|
+
};
|
|
7055
|
+
}
|
|
7056
|
+
});
|
|
7057
|
+
var createRAGIMAPEmailSyncClient = (config) => ({
|
|
7058
|
+
listMessages: async (input) => {
|
|
7059
|
+
const mailbox = config.mailbox ?? "INBOX";
|
|
7060
|
+
const searchTerms = config.search?.length ? config.search : ["ALL"];
|
|
7061
|
+
const maxResults = input?.maxResults ?? config.maxResults ?? 100;
|
|
7062
|
+
const socket = connectTls({
|
|
7063
|
+
host: config.host,
|
|
7064
|
+
port: config.port ?? 993,
|
|
7065
|
+
rejectUnauthorized: true
|
|
7066
|
+
});
|
|
7067
|
+
socket.setEncoding("utf8");
|
|
7068
|
+
let buffer = "";
|
|
7069
|
+
const readUntil = async (predicate) => await new Promise((resolve2, reject) => {
|
|
7070
|
+
const onData = (chunk) => {
|
|
7071
|
+
buffer += chunk;
|
|
7072
|
+
if (predicate(buffer)) {
|
|
7073
|
+
socket.off("data", onData);
|
|
7074
|
+
resolve2(buffer);
|
|
7075
|
+
}
|
|
7076
|
+
};
|
|
7077
|
+
const onError = (error) => {
|
|
7078
|
+
socket.off("data", onData);
|
|
7079
|
+
reject(error);
|
|
7080
|
+
};
|
|
7081
|
+
socket.on("data", onData);
|
|
7082
|
+
socket.once("error", onError);
|
|
7083
|
+
});
|
|
7084
|
+
const send = async (tag, command) => {
|
|
7085
|
+
socket.write(`${tag} ${command}\r
|
|
7086
|
+
`);
|
|
7087
|
+
const response = await readUntil((chunk) => chunk.includes(`\r
|
|
7088
|
+
${tag} OK`) || chunk.startsWith(`${tag} OK`));
|
|
7089
|
+
buffer = "";
|
|
7090
|
+
return response;
|
|
7091
|
+
};
|
|
7092
|
+
await readUntil((chunk) => chunk.includes(`\r
|
|
7093
|
+
`) || chunk.startsWith("*"));
|
|
7094
|
+
buffer = "";
|
|
7095
|
+
await send("A001", `LOGIN "${config.username}" "${config.password}"`);
|
|
7096
|
+
await send("A002", `SELECT "${mailbox}"`);
|
|
7097
|
+
const searchResponse = await send("A003", `UID SEARCH ${searchTerms.join(" ")}`);
|
|
7098
|
+
const uidLine = searchResponse.split(/\r?\n/).find((line) => line.startsWith("* SEARCH"));
|
|
7099
|
+
const uids = (uidLine?.replace("* SEARCH", "").trim().split(/\s+/) ?? []).filter(Boolean).slice(-maxResults);
|
|
7100
|
+
const messages = [];
|
|
7101
|
+
for (const uid of uids) {
|
|
7102
|
+
const response = await send(`F${uid}`, `UID FETCH ${uid} BODY.PEEK[]`);
|
|
7103
|
+
const rawMatch = response.match(/\{(\d+)\}\r\n([\s\S]*?)\r\nF[^\r\n]+ OK/);
|
|
7104
|
+
const raw = rawMatch?.[2]?.trim();
|
|
7105
|
+
if (!raw) {
|
|
7106
|
+
continue;
|
|
7107
|
+
}
|
|
7108
|
+
const parsed = parseRawEmail(raw);
|
|
7109
|
+
messages.push({
|
|
7110
|
+
...parsed,
|
|
7111
|
+
metadata: {
|
|
7112
|
+
...parsed.metadata ?? {},
|
|
7113
|
+
imapMailbox: mailbox,
|
|
7114
|
+
imapUid: uid,
|
|
7115
|
+
provider: "imap"
|
|
7116
|
+
}
|
|
7117
|
+
});
|
|
7118
|
+
}
|
|
7119
|
+
socket.end(`ZZZZ LOGOUT\r
|
|
7120
|
+
`);
|
|
7121
|
+
return { messages };
|
|
7122
|
+
}
|
|
7123
|
+
});
|
|
6836
7124
|
// src/ai/rag/presentation.ts
|
|
6837
7125
|
var buildSourceGroupKey = (source) => source.source ?? source.title ?? source.chunkId;
|
|
6838
7126
|
var buildSourceLabel = (source) => source.source ?? source.title ?? source.chunkId;
|
|
6839
7127
|
var getContextNumber = (value) => typeof value === "number" && Number.isFinite(value) ? value : undefined;
|
|
6840
7128
|
var getContextString = (value) => typeof value === "string" && value.trim().length > 0 ? value.trim() : undefined;
|
|
7129
|
+
var formatTimestampLabel = (value) => {
|
|
7130
|
+
const timestamp = typeof value === "number" && Number.isFinite(value) ? value : typeof value === "string" ? Date.parse(value) : Number.NaN;
|
|
7131
|
+
if (!Number.isFinite(timestamp)) {
|
|
7132
|
+
return;
|
|
7133
|
+
}
|
|
7134
|
+
return new Date(timestamp).toLocaleString("en-US", {
|
|
7135
|
+
dateStyle: "medium",
|
|
7136
|
+
timeStyle: "short"
|
|
7137
|
+
});
|
|
7138
|
+
};
|
|
7139
|
+
var formatMediaTimestamp = (value) => {
|
|
7140
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value < 0) {
|
|
7141
|
+
return;
|
|
7142
|
+
}
|
|
7143
|
+
const totalSeconds = Math.floor(value / 1000);
|
|
7144
|
+
const minutes = Math.floor(totalSeconds / 60);
|
|
7145
|
+
const seconds = totalSeconds % 60;
|
|
7146
|
+
const milliseconds = Math.floor(value % 1000);
|
|
7147
|
+
return `${String(minutes).padStart(2, "0")}:${String(seconds).padStart(2, "0")}.${String(milliseconds).padStart(3, "0")}`;
|
|
7148
|
+
};
|
|
7149
|
+
var getAttachmentName = (source, title) => {
|
|
7150
|
+
const sourceAttachment = source?.split("/").at(-1);
|
|
7151
|
+
if (sourceAttachment && sourceAttachment.includes(".")) {
|
|
7152
|
+
return sourceAttachment;
|
|
7153
|
+
}
|
|
7154
|
+
const titleAttachment = title?.split(" \xB7 ").at(-1);
|
|
7155
|
+
if (titleAttachment && titleAttachment.includes(".")) {
|
|
7156
|
+
return titleAttachment;
|
|
7157
|
+
}
|
|
7158
|
+
return;
|
|
7159
|
+
};
|
|
6841
7160
|
var buildContextLabel = (metadata) => {
|
|
6842
7161
|
if (!metadata) {
|
|
6843
7162
|
return;
|
|
6844
7163
|
}
|
|
7164
|
+
const emailKind = getContextString(metadata.emailKind);
|
|
7165
|
+
if (emailKind === "attachment") {
|
|
7166
|
+
return "Attachment evidence";
|
|
7167
|
+
}
|
|
7168
|
+
if (emailKind === "message") {
|
|
7169
|
+
const from = getContextString(metadata.from);
|
|
7170
|
+
return from ? `Message from ${from}` : "Message evidence";
|
|
7171
|
+
}
|
|
6845
7172
|
const page = getContextNumber(metadata.page) ?? getContextNumber(metadata.pageNumber) ?? (typeof metadata.pageIndex === "number" ? metadata.pageIndex + 1 : undefined);
|
|
6846
7173
|
if (page) {
|
|
6847
7174
|
return `Page ${page}`;
|
|
@@ -6868,6 +7195,57 @@ var buildContextLabel = (metadata) => {
|
|
|
6868
7195
|
}
|
|
6869
7196
|
return;
|
|
6870
7197
|
};
|
|
7198
|
+
var buildLocatorLabel = (metadata, source, title) => {
|
|
7199
|
+
if (!metadata) {
|
|
7200
|
+
return;
|
|
7201
|
+
}
|
|
7202
|
+
const page = getContextNumber(metadata.page) ?? getContextNumber(metadata.pageNumber) ?? (typeof metadata.pageIndex === "number" ? metadata.pageIndex + 1 : undefined);
|
|
7203
|
+
if (page) {
|
|
7204
|
+
return `Page ${page}`;
|
|
7205
|
+
}
|
|
7206
|
+
const sheet = getContextString(metadata.sheetName) ?? (Array.isArray(metadata.sheetNames) ? getContextString(metadata.sheetNames[0]) : undefined);
|
|
7207
|
+
if (sheet) {
|
|
7208
|
+
return `Sheet ${sheet}`;
|
|
7209
|
+
}
|
|
7210
|
+
const slide = getContextNumber(metadata.slide) ?? getContextNumber(metadata.slideNumber) ?? (typeof metadata.slideIndex === "number" ? metadata.slideIndex + 1 : undefined);
|
|
7211
|
+
if (slide) {
|
|
7212
|
+
return `Slide ${slide}`;
|
|
7213
|
+
}
|
|
7214
|
+
const archiveEntry = getContextString(metadata.archiveEntryPath) ?? getContextString(metadata.entryPath);
|
|
7215
|
+
if (archiveEntry) {
|
|
7216
|
+
return `Archive entry ${archiveEntry}`;
|
|
7217
|
+
}
|
|
7218
|
+
const emailKind = getContextString(metadata.emailKind);
|
|
7219
|
+
if (emailKind === "attachment") {
|
|
7220
|
+
const attachmentName = getContextString(metadata.attachmentName) ?? getAttachmentName(source, title);
|
|
7221
|
+
return attachmentName ? `Attachment ${attachmentName}` : "Attachment";
|
|
7222
|
+
}
|
|
7223
|
+
const mediaStart = formatMediaTimestamp(metadata.startMs);
|
|
7224
|
+
const mediaEnd = formatMediaTimestamp(metadata.endMs);
|
|
7225
|
+
if (mediaStart && mediaEnd) {
|
|
7226
|
+
return `Timestamp ${mediaStart} - ${mediaEnd}`;
|
|
7227
|
+
}
|
|
7228
|
+
if (mediaStart) {
|
|
7229
|
+
return `Timestamp ${mediaStart}`;
|
|
7230
|
+
}
|
|
7231
|
+
return;
|
|
7232
|
+
};
|
|
7233
|
+
var buildProvenanceLabel = (metadata) => {
|
|
7234
|
+
if (!metadata) {
|
|
7235
|
+
return;
|
|
7236
|
+
}
|
|
7237
|
+
const threadTopic = getContextString(metadata.threadTopic);
|
|
7238
|
+
const from = getContextString(metadata.from);
|
|
7239
|
+
const sentAt = formatTimestampLabel(metadata.sentAt) ?? formatTimestampLabel(metadata.receivedAt);
|
|
7240
|
+
const speaker = getContextString(metadata.speaker);
|
|
7241
|
+
const labels = [
|
|
7242
|
+
threadTopic ? `Thread ${threadTopic}` : "",
|
|
7243
|
+
speaker ? `Speaker ${speaker}` : "",
|
|
7244
|
+
from ? `Sender ${from}` : "",
|
|
7245
|
+
sentAt ? `Sent ${sentAt}` : ""
|
|
7246
|
+
].filter((value) => value.length > 0);
|
|
7247
|
+
return labels.length > 0 ? labels.join(" \xB7 ") : undefined;
|
|
7248
|
+
};
|
|
6871
7249
|
var buildRAGCitationReferenceMap = (citations) => Object.fromEntries(citations.map((citation, index) => [citation.chunkId, index + 1]));
|
|
6872
7250
|
var buildRAGCitations = (sources) => {
|
|
6873
7251
|
const unique = new Map;
|
|
@@ -6879,9 +7257,12 @@ var buildRAGCitations = (sources) => {
|
|
|
6879
7257
|
continue;
|
|
6880
7258
|
unique.set(key, {
|
|
6881
7259
|
chunkId: source.chunkId,
|
|
7260
|
+
contextLabel: buildContextLabel(source.metadata),
|
|
6882
7261
|
key,
|
|
6883
7262
|
label: buildSourceLabel(source),
|
|
7263
|
+
locatorLabel: buildLocatorLabel(source.metadata, source.source, source.title),
|
|
6884
7264
|
metadata: source.metadata,
|
|
7265
|
+
provenanceLabel: buildProvenanceLabel(source.metadata),
|
|
6885
7266
|
score: source.score,
|
|
6886
7267
|
source: source.source,
|
|
6887
7268
|
text: source.text,
|
|
@@ -6958,8 +7339,10 @@ var buildRAGGroundingReferences = (sources) => {
|
|
|
6958
7339
|
contextLabel: buildContextLabel(citation.metadata),
|
|
6959
7340
|
excerpt: buildExcerpt(citation.text),
|
|
6960
7341
|
label: citation.label,
|
|
7342
|
+
locatorLabel: citation.locatorLabel ?? buildLocatorLabel(citation.metadata, citation.source, citation.title),
|
|
6961
7343
|
metadata: citation.metadata,
|
|
6962
7344
|
number: citationReferenceMap[citation.chunkId] ?? 0,
|
|
7345
|
+
provenanceLabel: citation.provenanceLabel ?? buildProvenanceLabel(citation.metadata),
|
|
6963
7346
|
score: citation.score,
|
|
6964
7347
|
source: citation.source,
|
|
6965
7348
|
text: citation.text,
|
|
@@ -9756,8 +10139,11 @@ export {
|
|
|
9756
10139
|
createRAGMediaTranscriber,
|
|
9757
10140
|
createRAGMediaFileExtractor,
|
|
9758
10141
|
createRAGImageOCRExtractor,
|
|
10142
|
+
createRAGIMAPEmailSyncClient,
|
|
9759
10143
|
createRAGHTMXWorkflowRenderConfig,
|
|
9760
10144
|
createRAGHTMXConfig,
|
|
10145
|
+
createRAGGraphEmailSyncClient,
|
|
10146
|
+
createRAGGmailEmailSyncClient,
|
|
9761
10147
|
createRAGFileSyncStateStore,
|
|
9762
10148
|
createRAGFileExtractor,
|
|
9763
10149
|
createRAGEvaluationSuite,
|
|
@@ -9805,5 +10191,5 @@ export {
|
|
|
9805
10191
|
aiChat
|
|
9806
10192
|
};
|
|
9807
10193
|
|
|
9808
|
-
//# debugId=
|
|
10194
|
+
//# debugId=A6A9C1B546E5A8FD64756E2164756E21
|
|
9809
10195
|
//# sourceMappingURL=index.js.map
|