@absolutejs/absolute 0.19.0-beta.503 → 0.19.0-beta.505

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.
@@ -27,6 +27,9 @@ export type RAGCitation = {
27
27
  text: string;
28
28
  source?: string;
29
29
  title?: string;
30
+ contextLabel?: string;
31
+ provenanceLabel?: string;
32
+ locatorLabel?: string;
30
33
  metadata?: Record<string, unknown>;
31
34
  };
32
35
  export type RAGCitationReferenceMap = Record<string, number>;
@@ -41,6 +44,9 @@ export type RAGSourceSummary = {
41
44
  chunkIds: string[];
42
45
  citationNumbers: number[];
43
46
  citations: RAGCitation[];
47
+ contextLabel?: string;
48
+ locatorLabel?: string;
49
+ provenanceLabel?: string;
44
50
  };
45
51
  export type RAGGroundingReference = {
46
52
  number: number;
@@ -52,6 +58,8 @@ export type RAGGroundingReference = {
52
58
  text: string;
53
59
  excerpt: string;
54
60
  contextLabel?: string;
61
+ provenanceLabel?: string;
62
+ locatorLabel?: string;
55
63
  metadata?: Record<string, unknown>;
56
64
  };
57
65
  export type RAGGroundedAnswerPart = {
@@ -1098,10 +1098,49 @@ var buildSourceGroupKey = (source) => source.source ?? source.title ?? source.ch
1098
1098
  var buildSourceLabel = (source) => source.source ?? source.title ?? source.chunkId;
1099
1099
  var getContextNumber = (value) => typeof value === "number" && Number.isFinite(value) ? value : undefined;
1100
1100
  var getContextString = (value) => typeof value === "string" && value.trim().length > 0 ? value.trim() : undefined;
1101
+ var formatTimestampLabel = (value) => {
1102
+ const timestamp = typeof value === "number" && Number.isFinite(value) ? value : typeof value === "string" ? Date.parse(value) : Number.NaN;
1103
+ if (!Number.isFinite(timestamp)) {
1104
+ return;
1105
+ }
1106
+ return new Date(timestamp).toLocaleString("en-US", {
1107
+ dateStyle: "medium",
1108
+ timeStyle: "short"
1109
+ });
1110
+ };
1111
+ var formatMediaTimestamp = (value) => {
1112
+ if (typeof value !== "number" || !Number.isFinite(value) || value < 0) {
1113
+ return;
1114
+ }
1115
+ const totalSeconds = Math.floor(value / 1000);
1116
+ const minutes = Math.floor(totalSeconds / 60);
1117
+ const seconds = totalSeconds % 60;
1118
+ const milliseconds = Math.floor(value % 1000);
1119
+ return `${String(minutes).padStart(2, "0")}:${String(seconds).padStart(2, "0")}.${String(milliseconds).padStart(3, "0")}`;
1120
+ };
1121
+ var getAttachmentName = (source, title) => {
1122
+ const sourceAttachment = source?.split("/").at(-1);
1123
+ if (sourceAttachment && sourceAttachment.includes(".")) {
1124
+ return sourceAttachment;
1125
+ }
1126
+ const titleAttachment = title?.split(" \xB7 ").at(-1);
1127
+ if (titleAttachment && titleAttachment.includes(".")) {
1128
+ return titleAttachment;
1129
+ }
1130
+ return;
1131
+ };
1101
1132
  var buildContextLabel = (metadata) => {
1102
1133
  if (!metadata) {
1103
1134
  return;
1104
1135
  }
1136
+ const emailKind = getContextString(metadata.emailKind);
1137
+ if (emailKind === "attachment") {
1138
+ return "Attachment evidence";
1139
+ }
1140
+ if (emailKind === "message") {
1141
+ const from = getContextString(metadata.from);
1142
+ return from ? `Message from ${from}` : "Message evidence";
1143
+ }
1105
1144
  const page = getContextNumber(metadata.page) ?? getContextNumber(metadata.pageNumber) ?? (typeof metadata.pageIndex === "number" ? metadata.pageIndex + 1 : undefined);
1106
1145
  if (page) {
1107
1146
  return `Page ${page}`;
@@ -1128,6 +1167,57 @@ var buildContextLabel = (metadata) => {
1128
1167
  }
1129
1168
  return;
1130
1169
  };
1170
+ var buildLocatorLabel = (metadata, source, title) => {
1171
+ if (!metadata) {
1172
+ return;
1173
+ }
1174
+ const page = getContextNumber(metadata.page) ?? getContextNumber(metadata.pageNumber) ?? (typeof metadata.pageIndex === "number" ? metadata.pageIndex + 1 : undefined);
1175
+ if (page) {
1176
+ return `Page ${page}`;
1177
+ }
1178
+ const sheet = getContextString(metadata.sheetName) ?? (Array.isArray(metadata.sheetNames) ? getContextString(metadata.sheetNames[0]) : undefined);
1179
+ if (sheet) {
1180
+ return `Sheet ${sheet}`;
1181
+ }
1182
+ const slide = getContextNumber(metadata.slide) ?? getContextNumber(metadata.slideNumber) ?? (typeof metadata.slideIndex === "number" ? metadata.slideIndex + 1 : undefined);
1183
+ if (slide) {
1184
+ return `Slide ${slide}`;
1185
+ }
1186
+ const archiveEntry = getContextString(metadata.archiveEntryPath) ?? getContextString(metadata.entryPath);
1187
+ if (archiveEntry) {
1188
+ return `Archive entry ${archiveEntry}`;
1189
+ }
1190
+ const emailKind = getContextString(metadata.emailKind);
1191
+ if (emailKind === "attachment") {
1192
+ const attachmentName = getContextString(metadata.attachmentName) ?? getAttachmentName(source, title);
1193
+ return attachmentName ? `Attachment ${attachmentName}` : "Attachment";
1194
+ }
1195
+ const mediaStart = formatMediaTimestamp(metadata.startMs);
1196
+ const mediaEnd = formatMediaTimestamp(metadata.endMs);
1197
+ if (mediaStart && mediaEnd) {
1198
+ return `Timestamp ${mediaStart} - ${mediaEnd}`;
1199
+ }
1200
+ if (mediaStart) {
1201
+ return `Timestamp ${mediaStart}`;
1202
+ }
1203
+ return;
1204
+ };
1205
+ var buildProvenanceLabel = (metadata) => {
1206
+ if (!metadata) {
1207
+ return;
1208
+ }
1209
+ const threadTopic = getContextString(metadata.threadTopic);
1210
+ const from = getContextString(metadata.from);
1211
+ const sentAt = formatTimestampLabel(metadata.sentAt) ?? formatTimestampLabel(metadata.receivedAt);
1212
+ const speaker = getContextString(metadata.speaker);
1213
+ const labels = [
1214
+ threadTopic ? `Thread ${threadTopic}` : "",
1215
+ speaker ? `Speaker ${speaker}` : "",
1216
+ from ? `Sender ${from}` : "",
1217
+ sentAt ? `Sent ${sentAt}` : ""
1218
+ ].filter((value) => value.length > 0);
1219
+ return labels.length > 0 ? labels.join(" \xB7 ") : undefined;
1220
+ };
1131
1221
  var buildRAGCitationReferenceMap = (citations) => Object.fromEntries(citations.map((citation, index) => [citation.chunkId, index + 1]));
1132
1222
  var buildRAGCitations = (sources) => {
1133
1223
  const unique = new Map;
@@ -1139,9 +1229,12 @@ var buildRAGCitations = (sources) => {
1139
1229
  continue;
1140
1230
  unique.set(key, {
1141
1231
  chunkId: source.chunkId,
1232
+ contextLabel: buildContextLabel(source.metadata),
1142
1233
  key,
1143
1234
  label: buildSourceLabel(source),
1235
+ locatorLabel: buildLocatorLabel(source.metadata, source.source, source.title),
1144
1236
  metadata: source.metadata,
1237
+ provenanceLabel: buildProvenanceLabel(source.metadata),
1145
1238
  score: source.score,
1146
1239
  source: source.source,
1147
1240
  text: source.text,
@@ -1218,8 +1311,10 @@ var buildRAGGroundingReferences = (sources) => {
1218
1311
  contextLabel: buildContextLabel(citation.metadata),
1219
1312
  excerpt: buildExcerpt(citation.text),
1220
1313
  label: citation.label,
1314
+ locatorLabel: citation.locatorLabel ?? buildLocatorLabel(citation.metadata, citation.source, citation.title),
1221
1315
  metadata: citation.metadata,
1222
1316
  number: citationReferenceMap[citation.chunkId] ?? 0,
1317
+ provenanceLabel: citation.provenanceLabel ?? buildProvenanceLabel(citation.metadata),
1223
1318
  score: citation.score,
1224
1319
  source: citation.source,
1225
1320
  text: citation.text,
@@ -1259,10 +1354,13 @@ var buildRAGSourceSummaries = (sources) => {
1259
1354
  citationNumbers: groupCitations.map((citation) => citationReferenceMap[citation.chunkId] ?? 0),
1260
1355
  citations: groupCitations,
1261
1356
  chunkIds: group.chunks.map((chunk) => chunk.chunkId),
1357
+ contextLabel: buildContextLabel(leadChunk?.metadata),
1262
1358
  count: group.count,
1263
1359
  excerpt: buildExcerpt(leadChunk?.text ?? ""),
1264
1360
  key: group.key,
1265
1361
  label: group.label,
1362
+ locatorLabel: buildLocatorLabel(leadChunk?.metadata, leadChunk?.source, leadChunk?.title),
1363
+ provenanceLabel: buildProvenanceLabel(leadChunk?.metadata),
1266
1364
  source: group.source,
1267
1365
  title: group.title
1268
1366
  };
@@ -2492,5 +2590,5 @@ export {
2492
2590
  AIStreamKey
2493
2591
  };
2494
2592
 
2495
- //# debugId=BF2B518DF60A8F4164756E2164756E21
2593
+ //# debugId=5350506D1AE1966564756E2164756E21
2496
2594
  //# sourceMappingURL=index.js.map