@absolutejs/absolute 0.19.0-beta.623 → 0.19.0-beta.625

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.
Files changed (51) hide show
  1. package/dist/ai/client/index.js +8751 -6935
  2. package/dist/ai/client/index.js.map +5 -5
  3. package/dist/ai/client/ui.js +6402 -42
  4. package/dist/ai/client/ui.js.map +7 -4
  5. package/dist/ai/index.js +12994 -8132
  6. package/dist/ai/index.js.map +15 -13
  7. package/dist/ai/rag/quality.js +4194 -37
  8. package/dist/ai/rag/quality.js.map +6 -5
  9. package/dist/ai/rag/ui.js +6407 -42
  10. package/dist/ai/rag/ui.js.map +7 -4
  11. package/dist/ai-client/angular/ai/index.js +401 -4
  12. package/dist/ai-client/react/ai/index.js +537 -511
  13. package/dist/ai-client/vue/ai/index.js +743 -720
  14. package/dist/angular/ai/index.js +9400 -3140
  15. package/dist/angular/ai/index.js.map +7 -6
  16. package/dist/react/ai/index.js +8187 -6372
  17. package/dist/react/ai/index.js.map +5 -5
  18. package/dist/src/ai/index.d.ts +2 -2
  19. package/dist/src/ai/rag/adapters/filtering.d.ts +2 -0
  20. package/dist/src/ai/rag/adapters/queryPlanning.d.ts +11 -0
  21. package/dist/src/ai/rag/index.d.ts +4 -4
  22. package/dist/src/ai/rag/ingestion.d.ts +3 -0
  23. package/dist/src/ai/rag/presentation.d.ts +6 -1
  24. package/dist/src/ai/rag/quality.d.ts +95 -2
  25. package/dist/src/ai/rag/sync.d.ts +20 -1
  26. package/dist/src/ai/rag/types.d.ts +1 -1
  27. package/dist/src/ai/rag/ui.d.ts +1 -1
  28. package/dist/src/react/ai/useRAG.d.ts +1 -1
  29. package/dist/src/react/ai/useRAGIndexAdmin.d.ts +2 -2
  30. package/dist/src/vue/ai/useRAG.d.ts +408 -0
  31. package/dist/src/vue/ai/useRAGEvaluate.d.ts +84 -0
  32. package/dist/src/vue/ai/useRAGIndexAdmin.d.ts +222 -0
  33. package/dist/src/vue/ai/useRAGOps.d.ts +102 -0
  34. package/dist/src/vue/components/Image.d.ts +74 -0
  35. package/dist/src/vue/components/index.d.ts +1 -1
  36. package/dist/src/vue/index.d.ts +1 -1
  37. package/dist/svelte/ai/index.js +8186 -6371
  38. package/dist/svelte/ai/index.js.map +4 -4
  39. package/dist/types/ai.d.ts +389 -1
  40. package/dist/vue/ai/index.js +8186 -6371
  41. package/dist/vue/ai/index.js.map +4 -4
  42. package/dist/vue/components/Image.js +253 -0
  43. package/dist/vue/components/Image.js.map +11 -0
  44. package/dist/vue/components/index.js +181 -16
  45. package/dist/vue/components/index.js.map +5 -3
  46. package/dist/vue/index.js +195 -30
  47. package/dist/vue/index.js.map +6 -4
  48. package/package.json +11 -11
  49. package/dist/Image-0pe96k20.vue +0 -186
  50. package/dist/vue/components/Image.vue +0 -186
  51. package/dist/vue/components/Image.vue.d.ts +0 -4
@@ -1143,160 +1143,532 @@ var buildRAGGroundingReferences = (sources) => {
1143
1143
  });
1144
1144
  };
1145
1145
 
1146
- // src/ai/rag/presentation.ts
1147
- var buildSourceGroupKey = (source) => source.source ?? source.title ?? source.chunkId;
1148
- var buildSourceLabel2 = (source) => source.source ?? source.title ?? source.chunkId;
1149
- var getContextNumber2 = (value) => typeof value === "number" && Number.isFinite(value) ? value : undefined;
1150
- var getContextString2 = (value) => typeof value === "string" && value.trim().length > 0 ? value.trim() : undefined;
1151
- var isRAGRetrievalTrace = (value) => {
1152
- if (!value || typeof value !== "object") {
1153
- return false;
1154
- }
1155
- const candidate = value;
1156
- return typeof candidate.query === "string" && typeof candidate.transformedQuery === "string" && Array.isArray(candidate.variantQueries) && Array.isArray(candidate.steps);
1157
- };
1158
- var formatTimestampLabel2 = (value) => {
1159
- const timestamp = typeof value === "number" && Number.isFinite(value) ? value : typeof value === "string" ? Date.parse(value) : Number.NaN;
1160
- if (!Number.isFinite(timestamp)) {
1161
- return;
1162
- }
1163
- return new Date(timestamp).toLocaleString("en-US", {
1164
- dateStyle: "medium",
1165
- timeStyle: "short"
1166
- });
1167
- };
1168
- var formatSourceAwareChunkReason = (value) => {
1169
- const reason = getContextString2(value);
1170
- if (reason === "section_boundary") {
1171
- return "Chunk boundary section";
1172
- }
1173
- if (reason === "size_limit") {
1174
- return "Chunk boundary size limit";
1175
- }
1176
- if (reason === "source_native_unit") {
1177
- return "Chunk boundary source-native unit";
1178
- }
1179
- return;
1180
- };
1181
- var buildSourceAwareUnitScopeLabel = (metadata) => {
1182
- if (!metadata) {
1183
- return;
1184
- }
1185
- const sectionKind = getContextString2(metadata.sectionKind);
1186
- const sectionPath = Array.isArray(metadata.sectionPath) ? metadata.sectionPath.map((value) => getContextString2(value)).filter((value) => typeof value === "string") : [];
1187
- const sectionTitle = getContextString2(metadata.sectionTitle) ?? sectionPath.at(-1);
1188
- const pdfTextKind = getContextString2(metadata.pdfTextKind);
1189
- const officeBlockKind = getContextString2(metadata.officeBlockKind);
1190
- const sheetName = getContextString2(metadata.sheetName);
1191
- const spreadsheetTableLabel = formatSpreadsheetTableLabel(getContextNumber2(metadata.spreadsheetTableIndex), getContextNumber2(metadata.spreadsheetTableCount));
1192
- const slideTitle = getContextString2(metadata.slideTitle);
1193
- const slideNumber = getContextNumber2(metadata.slideNumber) ?? (typeof metadata.slideIndex === "number" ? metadata.slideIndex + 1 : undefined);
1194
- if (sectionPath.length > 0 && (sectionKind === "markdown_heading" || sectionKind === "html_heading" || sectionKind === "office_heading" || sectionKind === undefined)) {
1195
- return `Source-aware section ${sectionPath.join(" > ")}`;
1196
- }
1197
- if (sectionKind === "pdf_block") {
1198
- if (pdfTextKind === "table_like" && sectionTitle) {
1199
- return `Source-aware PDF table block ${sectionTitle}`;
1200
- }
1201
- if (sectionTitle) {
1202
- return `Source-aware PDF block ${sectionTitle}`;
1203
- }
1204
- return "Source-aware PDF block";
1146
+ // src/ai/rag/quality.ts
1147
+ var {mkdir, readFile, writeFile} = (() => ({}));
1148
+
1149
+ // node:path
1150
+ function assertPath(path) {
1151
+ if (typeof path !== "string")
1152
+ throw TypeError("Path must be a string. Received " + JSON.stringify(path));
1153
+ }
1154
+ function normalizeStringPosix(path, allowAboveRoot) {
1155
+ var res = "", lastSegmentLength = 0, lastSlash = -1, dots = 0, code;
1156
+ for (var i = 0;i <= path.length; ++i) {
1157
+ if (i < path.length)
1158
+ code = path.charCodeAt(i);
1159
+ else if (code === 47)
1160
+ break;
1161
+ else
1162
+ code = 47;
1163
+ if (code === 47) {
1164
+ if (lastSlash === i - 1 || dots === 1)
1165
+ ;
1166
+ else if (lastSlash !== i - 1 && dots === 2) {
1167
+ if (res.length < 2 || lastSegmentLength !== 2 || res.charCodeAt(res.length - 1) !== 46 || res.charCodeAt(res.length - 2) !== 46) {
1168
+ if (res.length > 2) {
1169
+ var lastSlashIndex = res.lastIndexOf("/");
1170
+ if (lastSlashIndex !== res.length - 1) {
1171
+ if (lastSlashIndex === -1)
1172
+ res = "", lastSegmentLength = 0;
1173
+ else
1174
+ res = res.slice(0, lastSlashIndex), lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
1175
+ lastSlash = i, dots = 0;
1176
+ continue;
1177
+ }
1178
+ } else if (res.length === 2 || res.length === 1) {
1179
+ res = "", lastSegmentLength = 0, lastSlash = i, dots = 0;
1180
+ continue;
1181
+ }
1182
+ }
1183
+ if (allowAboveRoot) {
1184
+ if (res.length > 0)
1185
+ res += "/..";
1186
+ else
1187
+ res = "..";
1188
+ lastSegmentLength = 2;
1189
+ }
1190
+ } else {
1191
+ if (res.length > 0)
1192
+ res += "/" + path.slice(lastSlash + 1, i);
1193
+ else
1194
+ res = path.slice(lastSlash + 1, i);
1195
+ lastSegmentLength = i - lastSlash - 1;
1196
+ }
1197
+ lastSlash = i, dots = 0;
1198
+ } else if (code === 46 && dots !== -1)
1199
+ ++dots;
1200
+ else
1201
+ dots = -1;
1205
1202
  }
1206
- if (sectionKind === "office_block") {
1207
- if (officeBlockKind && sectionTitle) {
1208
- return `Source-aware office ${officeBlockKind} block ${sectionTitle}`;
1209
- }
1210
- if (sectionTitle) {
1211
- return `Source-aware office block ${sectionTitle}`;
1203
+ return res;
1204
+ }
1205
+ function _format(sep, pathObject) {
1206
+ var dir = pathObject.dir || pathObject.root, base = pathObject.base || (pathObject.name || "") + (pathObject.ext || "");
1207
+ if (!dir)
1208
+ return base;
1209
+ if (dir === pathObject.root)
1210
+ return dir + base;
1211
+ return dir + sep + base;
1212
+ }
1213
+ function resolve() {
1214
+ var resolvedPath = "", resolvedAbsolute = false, cwd;
1215
+ for (var i = arguments.length - 1;i >= -1 && !resolvedAbsolute; i--) {
1216
+ var path;
1217
+ if (i >= 0)
1218
+ path = arguments[i];
1219
+ else {
1220
+ if (cwd === undefined)
1221
+ cwd = process.cwd();
1222
+ path = cwd;
1212
1223
  }
1213
- return "Source-aware office block";
1224
+ if (assertPath(path), path.length === 0)
1225
+ continue;
1226
+ resolvedPath = path + "/" + resolvedPath, resolvedAbsolute = path.charCodeAt(0) === 47;
1214
1227
  }
1215
- if (sectionKind === "spreadsheet_rows" || sectionKind === undefined && (sheetName || spreadsheetTableLabel || getContextNumber2(metadata.spreadsheetRowStart) !== undefined || getContextNumber2(metadata.spreadsheetRowEnd) !== undefined)) {
1216
- if (sheetName && spreadsheetTableLabel) {
1217
- return `Source-aware spreadsheet ${sheetName} ${spreadsheetTableLabel}`;
1218
- }
1219
- if (sheetName) {
1220
- return `Source-aware spreadsheet ${sheetName}`;
1221
- }
1222
- return "Source-aware spreadsheet";
1228
+ if (resolvedPath = normalizeStringPosix(resolvedPath, !resolvedAbsolute), resolvedAbsolute)
1229
+ if (resolvedPath.length > 0)
1230
+ return "/" + resolvedPath;
1231
+ else
1232
+ return "/";
1233
+ else if (resolvedPath.length > 0)
1234
+ return resolvedPath;
1235
+ else
1236
+ return ".";
1237
+ }
1238
+ function normalize(path) {
1239
+ if (assertPath(path), path.length === 0)
1240
+ return ".";
1241
+ var isAbsolute = path.charCodeAt(0) === 47, trailingSeparator = path.charCodeAt(path.length - 1) === 47;
1242
+ if (path = normalizeStringPosix(path, !isAbsolute), path.length === 0 && !isAbsolute)
1243
+ path = ".";
1244
+ if (path.length > 0 && trailingSeparator)
1245
+ path += "/";
1246
+ if (isAbsolute)
1247
+ return "/" + path;
1248
+ return path;
1249
+ }
1250
+ function isAbsolute(path) {
1251
+ return assertPath(path), path.length > 0 && path.charCodeAt(0) === 47;
1252
+ }
1253
+ function join() {
1254
+ if (arguments.length === 0)
1255
+ return ".";
1256
+ var joined;
1257
+ for (var i = 0;i < arguments.length; ++i) {
1258
+ var arg = arguments[i];
1259
+ if (assertPath(arg), arg.length > 0)
1260
+ if (joined === undefined)
1261
+ joined = arg;
1262
+ else
1263
+ joined += "/" + arg;
1223
1264
  }
1224
- if (sectionKind === "presentation_slide") {
1225
- if (slideNumber && slideTitle) {
1226
- return `Source-aware slide ${slideNumber} ${slideTitle}`;
1227
- }
1228
- if (slideTitle) {
1229
- return `Source-aware slide ${slideTitle}`;
1230
- }
1231
- if (slideNumber) {
1232
- return `Source-aware slide ${slideNumber}`;
1265
+ if (joined === undefined)
1266
+ return ".";
1267
+ return normalize(joined);
1268
+ }
1269
+ function relative(from, to) {
1270
+ if (assertPath(from), assertPath(to), from === to)
1271
+ return "";
1272
+ if (from = resolve(from), to = resolve(to), from === to)
1273
+ return "";
1274
+ var fromStart = 1;
1275
+ for (;fromStart < from.length; ++fromStart)
1276
+ if (from.charCodeAt(fromStart) !== 47)
1277
+ break;
1278
+ var fromEnd = from.length, fromLen = fromEnd - fromStart, toStart = 1;
1279
+ for (;toStart < to.length; ++toStart)
1280
+ if (to.charCodeAt(toStart) !== 47)
1281
+ break;
1282
+ var toEnd = to.length, toLen = toEnd - toStart, length = fromLen < toLen ? fromLen : toLen, lastCommonSep = -1, i = 0;
1283
+ for (;i <= length; ++i) {
1284
+ if (i === length) {
1285
+ if (toLen > length) {
1286
+ if (to.charCodeAt(toStart + i) === 47)
1287
+ return to.slice(toStart + i + 1);
1288
+ else if (i === 0)
1289
+ return to.slice(toStart + i);
1290
+ } else if (fromLen > length) {
1291
+ if (from.charCodeAt(fromStart + i) === 47)
1292
+ lastCommonSep = i;
1293
+ else if (i === 0)
1294
+ lastCommonSep = 0;
1295
+ }
1296
+ break;
1233
1297
  }
1234
- return "Source-aware slide";
1298
+ var fromCode = from.charCodeAt(fromStart + i), toCode = to.charCodeAt(toStart + i);
1299
+ if (fromCode !== toCode)
1300
+ break;
1301
+ else if (fromCode === 47)
1302
+ lastCommonSep = i;
1235
1303
  }
1236
- return;
1237
- };
1238
- var formatMediaTimestamp2 = (value) => {
1239
- if (typeof value !== "number" || !Number.isFinite(value) || value < 0) {
1240
- return;
1304
+ var out = "";
1305
+ for (i = fromStart + lastCommonSep + 1;i <= fromEnd; ++i)
1306
+ if (i === fromEnd || from.charCodeAt(i) === 47)
1307
+ if (out.length === 0)
1308
+ out += "..";
1309
+ else
1310
+ out += "/..";
1311
+ if (out.length > 0)
1312
+ return out + to.slice(toStart + lastCommonSep);
1313
+ else {
1314
+ if (toStart += lastCommonSep, to.charCodeAt(toStart) === 47)
1315
+ ++toStart;
1316
+ return to.slice(toStart);
1241
1317
  }
1242
- const totalSeconds = Math.floor(value / 1000);
1243
- const minutes = Math.floor(totalSeconds / 60);
1244
- const seconds = totalSeconds % 60;
1245
- const milliseconds = Math.floor(value % 1000);
1246
- return `${String(minutes).padStart(2, "0")}:${String(seconds).padStart(2, "0")}.${String(milliseconds).padStart(3, "0")}`;
1247
- };
1248
- var getAttachmentName2 = (source, title) => {
1249
- const sourceAttachment = source?.split("/").at(-1);
1250
- if (sourceAttachment && sourceAttachment.includes(".")) {
1251
- return sourceAttachment;
1252
- }
1253
- const titleAttachment = title?.split(" · ").at(-1);
1254
- if (titleAttachment && titleAttachment.includes(".")) {
1255
- return titleAttachment;
1318
+ }
1319
+ function _makeLong(path) {
1320
+ return path;
1321
+ }
1322
+ function dirname(path) {
1323
+ if (assertPath(path), path.length === 0)
1324
+ return ".";
1325
+ var code = path.charCodeAt(0), hasRoot = code === 47, end = -1, matchedSlash = true;
1326
+ for (var i = path.length - 1;i >= 1; --i)
1327
+ if (code = path.charCodeAt(i), code === 47) {
1328
+ if (!matchedSlash) {
1329
+ end = i;
1330
+ break;
1331
+ }
1332
+ } else
1333
+ matchedSlash = false;
1334
+ if (end === -1)
1335
+ return hasRoot ? "/" : ".";
1336
+ if (hasRoot && end === 1)
1337
+ return "//";
1338
+ return path.slice(0, end);
1339
+ }
1340
+ function basename(path, ext) {
1341
+ if (ext !== undefined && typeof ext !== "string")
1342
+ throw TypeError('"ext" argument must be a string');
1343
+ assertPath(path);
1344
+ var start = 0, end = -1, matchedSlash = true, i;
1345
+ if (ext !== undefined && ext.length > 0 && ext.length <= path.length) {
1346
+ if (ext.length === path.length && ext === path)
1347
+ return "";
1348
+ var extIdx = ext.length - 1, firstNonSlashEnd = -1;
1349
+ for (i = path.length - 1;i >= 0; --i) {
1350
+ var code = path.charCodeAt(i);
1351
+ if (code === 47) {
1352
+ if (!matchedSlash) {
1353
+ start = i + 1;
1354
+ break;
1355
+ }
1356
+ } else {
1357
+ if (firstNonSlashEnd === -1)
1358
+ matchedSlash = false, firstNonSlashEnd = i + 1;
1359
+ if (extIdx >= 0)
1360
+ if (code === ext.charCodeAt(extIdx)) {
1361
+ if (--extIdx === -1)
1362
+ end = i;
1363
+ } else
1364
+ extIdx = -1, end = firstNonSlashEnd;
1365
+ }
1366
+ }
1367
+ if (start === end)
1368
+ end = firstNonSlashEnd;
1369
+ else if (end === -1)
1370
+ end = path.length;
1371
+ return path.slice(start, end);
1372
+ } else {
1373
+ for (i = path.length - 1;i >= 0; --i)
1374
+ if (path.charCodeAt(i) === 47) {
1375
+ if (!matchedSlash) {
1376
+ start = i + 1;
1377
+ break;
1378
+ }
1379
+ } else if (end === -1)
1380
+ matchedSlash = false, end = i + 1;
1381
+ if (end === -1)
1382
+ return "";
1383
+ return path.slice(start, end);
1256
1384
  }
1257
- return;
1258
- };
1259
- var getSpreadsheetHeaders = (metadata) => Array.isArray(metadata?.spreadsheetHeaders) ? metadata.spreadsheetHeaders.map((value) => getContextString2(value)).filter((value) => typeof value === "string") : [];
1260
- var formatSpreadsheetColumnRange = (columnStart, columnEnd) => {
1261
- if (typeof columnStart !== "string" || columnStart.length === 0) {
1262
- return;
1385
+ }
1386
+ function extname(path) {
1387
+ assertPath(path);
1388
+ var startDot = -1, startPart = 0, end = -1, matchedSlash = true, preDotState = 0;
1389
+ for (var i = path.length - 1;i >= 0; --i) {
1390
+ var code = path.charCodeAt(i);
1391
+ if (code === 47) {
1392
+ if (!matchedSlash) {
1393
+ startPart = i + 1;
1394
+ break;
1395
+ }
1396
+ continue;
1397
+ }
1398
+ if (end === -1)
1399
+ matchedSlash = false, end = i + 1;
1400
+ if (code === 46) {
1401
+ if (startDot === -1)
1402
+ startDot = i;
1403
+ else if (preDotState !== 1)
1404
+ preDotState = 1;
1405
+ } else if (startDot !== -1)
1406
+ preDotState = -1;
1263
1407
  }
1264
- if (typeof columnEnd !== "string" || columnEnd.length === 0) {
1265
- return `Columns ${columnStart}`;
1408
+ if (startDot === -1 || end === -1 || preDotState === 0 || preDotState === 1 && startDot === end - 1 && startDot === startPart + 1)
1409
+ return "";
1410
+ return path.slice(startDot, end);
1411
+ }
1412
+ function format(pathObject) {
1413
+ if (pathObject === null || typeof pathObject !== "object")
1414
+ throw TypeError('The "pathObject" argument must be of type Object. Received type ' + typeof pathObject);
1415
+ return _format("/", pathObject);
1416
+ }
1417
+ function parse(path) {
1418
+ assertPath(path);
1419
+ var ret = { root: "", dir: "", base: "", ext: "", name: "" };
1420
+ if (path.length === 0)
1421
+ return ret;
1422
+ var code = path.charCodeAt(0), isAbsolute2 = code === 47, start;
1423
+ if (isAbsolute2)
1424
+ ret.root = "/", start = 1;
1425
+ else
1426
+ start = 0;
1427
+ var startDot = -1, startPart = 0, end = -1, matchedSlash = true, i = path.length - 1, preDotState = 0;
1428
+ for (;i >= start; --i) {
1429
+ if (code = path.charCodeAt(i), code === 47) {
1430
+ if (!matchedSlash) {
1431
+ startPart = i + 1;
1432
+ break;
1433
+ }
1434
+ continue;
1435
+ }
1436
+ if (end === -1)
1437
+ matchedSlash = false, end = i + 1;
1438
+ if (code === 46) {
1439
+ if (startDot === -1)
1440
+ startDot = i;
1441
+ else if (preDotState !== 1)
1442
+ preDotState = 1;
1443
+ } else if (startDot !== -1)
1444
+ preDotState = -1;
1266
1445
  }
1267
- if (columnStart === columnEnd) {
1268
- return `Columns ${columnStart}`;
1446
+ if (startDot === -1 || end === -1 || preDotState === 0 || preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
1447
+ if (end !== -1)
1448
+ if (startPart === 0 && isAbsolute2)
1449
+ ret.base = ret.name = path.slice(1, end);
1450
+ else
1451
+ ret.base = ret.name = path.slice(startPart, end);
1452
+ } else {
1453
+ if (startPart === 0 && isAbsolute2)
1454
+ ret.name = path.slice(1, startDot), ret.base = path.slice(1, end);
1455
+ else
1456
+ ret.name = path.slice(startPart, startDot), ret.base = path.slice(startPart, end);
1457
+ ret.ext = path.slice(startDot, end);
1269
1458
  }
1270
- return `Columns ${columnStart}-${columnEnd}`;
1459
+ if (startPart > 0)
1460
+ ret.dir = path.slice(0, startPart - 1);
1461
+ else if (isAbsolute2)
1462
+ ret.dir = "/";
1463
+ return ret;
1464
+ }
1465
+ var sep = "/";
1466
+ var delimiter = ":";
1467
+ var posix = ((p) => (p.posix = p, p))({ resolve, normalize, isAbsolute, join, relative, _makeLong, dirname, basename, extname, format, parse, sep, delimiter, win32: null, posix: null });
1468
+
1469
+ // src/ai/rag/quality.ts
1470
+ var buildRAGEvaluationLeaderboard = (runs) => {
1471
+ const sorted = [...runs].sort((left, right) => {
1472
+ if (right.response.passingRate !== left.response.passingRate) {
1473
+ return right.response.passingRate - left.response.passingRate;
1474
+ }
1475
+ if (right.response.summary.averageF1 !== left.response.summary.averageF1) {
1476
+ return right.response.summary.averageF1 - left.response.summary.averageF1;
1477
+ }
1478
+ return left.response.summary.averageLatencyMs - right.response.summary.averageLatencyMs;
1479
+ });
1480
+ return sorted.map((run, index) => ({
1481
+ averageF1: run.response.summary.averageF1,
1482
+ averageLatencyMs: run.response.summary.averageLatencyMs,
1483
+ label: run.label,
1484
+ passingRate: run.response.passingRate,
1485
+ rank: index + 1,
1486
+ runId: run.id,
1487
+ suiteId: run.suiteId,
1488
+ totalCases: run.response.totalCases
1489
+ }));
1271
1490
  };
1272
- var formatSpreadsheetRowRange = (rowStart, rowEnd) => {
1273
- if (typeof rowStart !== "number" || !Number.isFinite(rowStart)) {
1274
- return;
1275
- }
1276
- if (typeof rowEnd !== "number" && typeof rowStart === "number" && Number.isFinite(rowStart)) {
1277
- return `Rows ${rowStart}`;
1278
- }
1279
- if (rowStart === rowEnd) {
1280
- return `Rows ${rowStart}`;
1281
- }
1282
- return `Rows ${rowStart}-${rowEnd}`;
1491
+ var runRAGEvaluationSuite = async ({
1492
+ suite,
1493
+ evaluate,
1494
+ overrides,
1495
+ artifacts
1496
+ }) => {
1497
+ const startedAt = Date.now();
1498
+ const response = await evaluate({
1499
+ ...suite.input,
1500
+ ...overrides,
1501
+ cases: overrides?.cases ?? suite.input.cases
1502
+ });
1503
+ const finishedAt = Date.now();
1504
+ return {
1505
+ caseTraceSnapshots: artifacts?.caseTraceSnapshots,
1506
+ elapsedMs: finishedAt - startedAt,
1507
+ finishedAt,
1508
+ id: generateId(),
1509
+ label: suite.label ?? suite.id,
1510
+ metadata: suite.metadata,
1511
+ response,
1512
+ startedAt,
1513
+ suiteId: suite.id,
1514
+ traceSummary: artifacts?.traceSummary
1515
+ };
1283
1516
  };
1284
- var formatSpreadsheetTableLabel = (tableIndex, tableCount) => {
1285
- if (typeof tableIndex !== "number" || !Number.isFinite(tableIndex) || tableIndex < 1) {
1286
- return;
1287
- }
1288
- if (typeof tableCount === "number" && Number.isFinite(tableCount) && tableCount >= tableIndex) {
1289
- return `Table ${tableIndex} of ${tableCount}`;
1517
+
1518
+ // src/ai/rag/presentation.ts
1519
+ var buildSourceGroupKey = (source) => source.source ?? source.title ?? source.chunkId;
1520
+ var buildSourceLabel2 = (source) => source.source ?? source.title ?? source.chunkId;
1521
+ var getContextNumber2 = (value) => typeof value === "number" && Number.isFinite(value) ? value : undefined;
1522
+ var getContextString2 = (value) => typeof value === "string" && value.trim().length > 0 ? value.trim() : undefined;
1523
+ var isRAGRetrievalTrace = (value) => {
1524
+ if (!value || typeof value !== "object") {
1525
+ return false;
1290
1526
  }
1291
- return `Table ${tableIndex}`;
1527
+ const candidate = value;
1528
+ return typeof candidate.query === "string" && typeof candidate.transformedQuery === "string" && Array.isArray(candidate.variantQueries) && Array.isArray(candidate.steps);
1292
1529
  };
1293
- var formatMediaDurationLabel2 = (value) => {
1294
- if (typeof value !== "number" || !Number.isFinite(value) || value < 0) {
1530
+ var formatTimestampLabel2 = (value) => {
1531
+ const timestamp = typeof value === "number" && Number.isFinite(value) ? value : typeof value === "string" ? Date.parse(value) : Number.NaN;
1532
+ if (!Number.isFinite(timestamp)) {
1295
1533
  return;
1296
1534
  }
1297
- return formatMediaTimestamp2(value);
1535
+ return new Date(timestamp).toLocaleString("en-US", {
1536
+ dateStyle: "medium",
1537
+ timeStyle: "short"
1538
+ });
1298
1539
  };
1299
- var buildContextLabel2 = (metadata) => {
1540
+ var formatSourceAwareChunkReason = (value) => {
1541
+ const reason = getContextString2(value);
1542
+ if (reason === "section_boundary") {
1543
+ return "Chunk boundary section";
1544
+ }
1545
+ if (reason === "size_limit") {
1546
+ return "Chunk boundary size limit";
1547
+ }
1548
+ if (reason === "source_native_unit") {
1549
+ return "Chunk boundary source-native unit";
1550
+ }
1551
+ return;
1552
+ };
1553
+ var buildSourceAwareUnitScopeLabel = (metadata) => {
1554
+ if (!metadata) {
1555
+ return;
1556
+ }
1557
+ const sectionKind = getContextString2(metadata.sectionKind);
1558
+ const sectionPath = Array.isArray(metadata.sectionPath) ? metadata.sectionPath.map((value) => getContextString2(value)).filter((value) => typeof value === "string") : [];
1559
+ const sectionTitle = getContextString2(metadata.sectionTitle) ?? sectionPath.at(-1);
1560
+ const pdfTextKind = getContextString2(metadata.pdfTextKind);
1561
+ const officeBlockKind = getContextString2(metadata.officeBlockKind);
1562
+ const sheetName = getContextString2(metadata.sheetName);
1563
+ const spreadsheetTableLabel = formatSpreadsheetTableLabel(getContextNumber2(metadata.spreadsheetTableIndex), getContextNumber2(metadata.spreadsheetTableCount));
1564
+ const slideTitle = getContextString2(metadata.slideTitle);
1565
+ const slideNumber = getContextNumber2(metadata.slideNumber) ?? (typeof metadata.slideIndex === "number" ? metadata.slideIndex + 1 : undefined);
1566
+ if (sectionPath.length > 0 && (sectionKind === "markdown_heading" || sectionKind === "html_heading" || sectionKind === "office_heading" || sectionKind === undefined)) {
1567
+ return `Source-aware section ${sectionPath.join(" > ")}`;
1568
+ }
1569
+ if (sectionKind === "pdf_block") {
1570
+ if (pdfTextKind === "table_like" && sectionTitle) {
1571
+ return `Source-aware PDF table block ${sectionTitle}`;
1572
+ }
1573
+ if (sectionTitle) {
1574
+ return `Source-aware PDF block ${sectionTitle}`;
1575
+ }
1576
+ return "Source-aware PDF block";
1577
+ }
1578
+ if (sectionKind === "office_block") {
1579
+ if (officeBlockKind && sectionTitle) {
1580
+ return `Source-aware office ${officeBlockKind} block ${sectionTitle}`;
1581
+ }
1582
+ if (sectionTitle) {
1583
+ return `Source-aware office block ${sectionTitle}`;
1584
+ }
1585
+ return "Source-aware office block";
1586
+ }
1587
+ if (sectionKind === "spreadsheet_rows" || sectionKind === undefined && (sheetName || spreadsheetTableLabel || getContextNumber2(metadata.spreadsheetRowStart) !== undefined || getContextNumber2(metadata.spreadsheetRowEnd) !== undefined)) {
1588
+ if (sheetName && spreadsheetTableLabel) {
1589
+ return `Source-aware spreadsheet ${sheetName} ${spreadsheetTableLabel}`;
1590
+ }
1591
+ if (sheetName) {
1592
+ return `Source-aware spreadsheet ${sheetName}`;
1593
+ }
1594
+ return "Source-aware spreadsheet";
1595
+ }
1596
+ if (sectionKind === "presentation_slide") {
1597
+ if (slideNumber && slideTitle) {
1598
+ return `Source-aware slide ${slideNumber} ${slideTitle}`;
1599
+ }
1600
+ if (slideTitle) {
1601
+ return `Source-aware slide ${slideTitle}`;
1602
+ }
1603
+ if (slideNumber) {
1604
+ return `Source-aware slide ${slideNumber}`;
1605
+ }
1606
+ return "Source-aware slide";
1607
+ }
1608
+ return;
1609
+ };
1610
+ var formatMediaTimestamp2 = (value) => {
1611
+ if (typeof value !== "number" || !Number.isFinite(value) || value < 0) {
1612
+ return;
1613
+ }
1614
+ const totalSeconds = Math.floor(value / 1000);
1615
+ const minutes = Math.floor(totalSeconds / 60);
1616
+ const seconds = totalSeconds % 60;
1617
+ const milliseconds = Math.floor(value % 1000);
1618
+ return `${String(minutes).padStart(2, "0")}:${String(seconds).padStart(2, "0")}.${String(milliseconds).padStart(3, "0")}`;
1619
+ };
1620
+ var getAttachmentName2 = (source, title) => {
1621
+ const sourceAttachment = source?.split("/").at(-1);
1622
+ if (sourceAttachment && sourceAttachment.includes(".")) {
1623
+ return sourceAttachment;
1624
+ }
1625
+ const titleAttachment = title?.split(" · ").at(-1);
1626
+ if (titleAttachment && titleAttachment.includes(".")) {
1627
+ return titleAttachment;
1628
+ }
1629
+ return;
1630
+ };
1631
+ var getSpreadsheetHeaders = (metadata) => Array.isArray(metadata?.spreadsheetHeaders) ? metadata.spreadsheetHeaders.map((value) => getContextString2(value)).filter((value) => typeof value === "string") : [];
1632
+ var formatSpreadsheetColumnRange = (columnStart, columnEnd) => {
1633
+ if (typeof columnStart !== "string" || columnStart.length === 0) {
1634
+ return;
1635
+ }
1636
+ if (typeof columnEnd !== "string" || columnEnd.length === 0) {
1637
+ return `Columns ${columnStart}`;
1638
+ }
1639
+ if (columnStart === columnEnd) {
1640
+ return `Columns ${columnStart}`;
1641
+ }
1642
+ return `Columns ${columnStart}-${columnEnd}`;
1643
+ };
1644
+ var formatSpreadsheetRowRange = (rowStart, rowEnd) => {
1645
+ if (typeof rowStart !== "number" || !Number.isFinite(rowStart)) {
1646
+ return;
1647
+ }
1648
+ if (typeof rowEnd !== "number" && typeof rowStart === "number" && Number.isFinite(rowStart)) {
1649
+ return `Rows ${rowStart}`;
1650
+ }
1651
+ if (rowStart === rowEnd) {
1652
+ return `Rows ${rowStart}`;
1653
+ }
1654
+ return `Rows ${rowStart}-${rowEnd}`;
1655
+ };
1656
+ var formatSpreadsheetTableLabel = (tableIndex, tableCount) => {
1657
+ if (typeof tableIndex !== "number" || !Number.isFinite(tableIndex) || tableIndex < 1) {
1658
+ return;
1659
+ }
1660
+ if (typeof tableCount === "number" && Number.isFinite(tableCount) && tableCount >= tableIndex) {
1661
+ return `Table ${tableIndex} of ${tableCount}`;
1662
+ }
1663
+ return `Table ${tableIndex}`;
1664
+ };
1665
+ var formatMediaDurationLabel2 = (value) => {
1666
+ if (typeof value !== "number" || !Number.isFinite(value) || value < 0) {
1667
+ return;
1668
+ }
1669
+ return formatMediaTimestamp2(value);
1670
+ };
1671
+ var buildContextLabel2 = (metadata) => {
1300
1672
  if (!metadata) {
1301
1673
  return;
1302
1674
  }
@@ -1336,6 +1708,8 @@ var buildContextLabel2 = (metadata) => {
1336
1708
  const page = getContextNumber2(metadata.page) ?? getContextNumber2(metadata.pageNumber) ?? (typeof metadata.pageIndex === "number" ? metadata.pageIndex + 1 : undefined);
1337
1709
  const region = getContextNumber2(metadata.regionNumber) ?? (typeof metadata.regionIndex === "number" ? metadata.regionIndex + 1 : undefined);
1338
1710
  const hasOCRTrace = typeof metadata.ocrRegionConfidence === "number" || typeof metadata.ocrConfidence === "number" || getContextString2(metadata.pdfTextMode) === "ocr" || typeof metadata.ocrRegionCount === "number";
1711
+ const ocrPageStart = getContextNumber2(metadata.ocrPageStart);
1712
+ const ocrPageEnd = getContextNumber2(metadata.ocrPageEnd);
1339
1713
  if (page && region) {
1340
1714
  if (hasOCRTrace) {
1341
1715
  return `OCR page ${page} region ${region}`;
@@ -1348,6 +1722,9 @@ var buildContextLabel2 = (metadata) => {
1348
1722
  }
1349
1723
  return `Page ${page}`;
1350
1724
  }
1725
+ if (hasOCRTrace && typeof ocrPageStart === "number" && typeof ocrPageEnd === "number") {
1726
+ return ocrPageStart === ocrPageEnd ? `OCR page ${ocrPageStart}` : `OCR pages ${ocrPageStart}-${ocrPageEnd}`;
1727
+ }
1351
1728
  const sheet = getContextString2(metadata.sheetName) ?? (Array.isArray(metadata.sheetNames) ? getContextString2(metadata.sheetNames[0]) : undefined);
1352
1729
  if (sheet) {
1353
1730
  const tableLabel = formatSpreadsheetTableLabel(getContextNumber2(metadata.spreadsheetTableIndex), getContextNumber2(metadata.spreadsheetTableCount));
@@ -1418,6 +1795,8 @@ var buildLocatorLabel2 = (metadata, source, title) => {
1418
1795
  const slideTitle = getContextString2(metadata.slideTitle);
1419
1796
  const page = getContextNumber2(metadata.page) ?? getContextNumber2(metadata.pageNumber) ?? (typeof metadata.pageIndex === "number" ? metadata.pageIndex + 1 : undefined);
1420
1797
  const region = getContextNumber2(metadata.regionNumber) ?? (typeof metadata.regionIndex === "number" ? metadata.regionIndex + 1 : undefined);
1798
+ const ocrPageStart = getContextNumber2(metadata.ocrPageStart);
1799
+ const ocrPageEnd = getContextNumber2(metadata.ocrPageEnd);
1421
1800
  if (page && region) {
1422
1801
  return `Page ${page} · Region ${region}`;
1423
1802
  }
@@ -1430,6 +1809,9 @@ var buildLocatorLabel2 = (metadata, source, title) => {
1430
1809
  if (page) {
1431
1810
  return `Page ${page}`;
1432
1811
  }
1812
+ if (typeof ocrPageStart === "number" && typeof ocrPageEnd === "number") {
1813
+ return ocrPageStart === ocrPageEnd ? `Page ${ocrPageStart}` : `Pages ${ocrPageStart}-${ocrPageEnd}`;
1814
+ }
1433
1815
  const sheet = getContextString2(metadata.sheetName) ?? (Array.isArray(metadata.sheetNames) ? getContextString2(metadata.sheetNames[0]) : undefined);
1434
1816
  if (sheet) {
1435
1817
  const tableLabel = formatSpreadsheetTableLabel(getContextNumber2(metadata.spreadsheetTableIndex), getContextNumber2(metadata.spreadsheetTableCount));
@@ -1534,6 +1916,8 @@ var buildProvenanceLabel2 = (metadata) => {
1534
1916
  const spreadsheetTableLabel = formatSpreadsheetTableLabel(getContextNumber2(metadata.spreadsheetTableIndex), getContextNumber2(metadata.spreadsheetTableCount));
1535
1917
  const ocrConfidence = getContextNumber2(metadata.ocrRegionConfidence) ?? getContextNumber2(metadata.ocrConfidence);
1536
1918
  const ocrAverageConfidence = getContextNumber2(metadata.ocrPageAverageConfidence) ?? getContextNumber2(metadata.ocrAverageConfidence);
1919
+ const ocrMinConfidence = getContextNumber2(metadata.ocrPageMinConfidence) ?? getContextNumber2(metadata.ocrMinConfidence);
1920
+ const ocrMaxConfidence = getContextNumber2(metadata.ocrPageMaxConfidence) ?? getContextNumber2(metadata.ocrMaxConfidence);
1537
1921
  const ocrRegionCount = getContextNumber2(metadata.ocrRegionCount);
1538
1922
  const labels = [
1539
1923
  pdfTextMode ? `PDF ${pdfTextMode}` : "",
@@ -1546,6 +1930,7 @@ var buildProvenanceLabel2 = (metadata) => {
1546
1930
  sourceAwareUnitScope ?? "",
1547
1931
  typeof ocrConfidence === "number" ? `Confidence ${ocrConfidence.toFixed(2)}` : "",
1548
1932
  typeof ocrAverageConfidence === "number" && ocrAverageConfidence !== ocrConfidence ? `Average ${ocrAverageConfidence.toFixed(2)}` : "",
1933
+ typeof ocrMinConfidence === "number" && typeof ocrMaxConfidence === "number" && ocrMinConfidence !== ocrMaxConfidence ? `Range ${ocrMinConfidence.toFixed(2)}-${ocrMaxConfidence.toFixed(2)}` : "",
1549
1934
  typeof ocrRegionCount === "number" ? `${ocrRegionCount} regions` : "",
1550
1935
  spreadsheetHeaders.length > 0 ? `Spreadsheet ${spreadsheetHeaders.join(", ")}` : "",
1551
1936
  spreadsheetColumnRange ? `Spreadsheet ${spreadsheetColumnRange}` : "",
@@ -1641,12 +2026,17 @@ var buildRAGChunkExcerpts = (chunks, activeChunkId) => {
1641
2026
  return;
1642
2027
  }
1643
2028
  const chunkMap = new Map(chunks.map((chunk) => [chunk.chunkId, chunk]));
1644
- const orderedWindowIds = [
2029
+ const orderedSectionIds = navigation.sectionNodes.length > 0 ? navigation.sectionNodes.map((node) => node.chunkId) : [activeChunk.chunkId];
2030
+ const orderedWindowIds = navigation.sectionNodes.length > 0 ? (() => {
2031
+ const activeIndex = navigation.sectionNodes.findIndex((node) => node.chunkId === activeChunk.chunkId);
2032
+ const startIndex = Math.max(0, activeIndex - 2);
2033
+ const endIndex = Math.min(navigation.sectionNodes.length, activeIndex + 3);
2034
+ return navigation.sectionNodes.slice(startIndex, endIndex).map((node) => node.chunkId);
2035
+ })() : [
1645
2036
  navigation.previousNode?.chunkId,
1646
2037
  activeChunk.chunkId,
1647
2038
  navigation.nextNode?.chunkId
1648
2039
  ].filter((chunkId, index, ids) => Boolean(chunkId) && ids.indexOf(chunkId) === index);
1649
- const orderedSectionIds = navigation.sectionNodes.length > 0 ? navigation.sectionNodes.map((node) => node.chunkId) : [activeChunk.chunkId];
1650
2040
  const collectText = (chunkIds) => chunkIds.map((chunkId) => chunkMap.get(chunkId)?.text).filter((text) => typeof text === "string").join(`
1651
2041
 
1652
2042
  `);
@@ -2061,6 +2451,9 @@ var buildRAGSectionRetrievalDiagnostics = (sources, trace) => {
2061
2451
  const parentShare = parentTotal > 0 ? section.totalScore / parentTotal : undefined;
2062
2452
  const topChunk = sources.find((source) => source.chunkId === section.topChunkId);
2063
2453
  const topContextLabel = topChunk?.labels?.contextLabel ?? buildContextLabel2(topChunk?.metadata);
2454
+ const topLocatorLabel = topChunk?.labels?.locatorLabel ?? buildLocatorLabel2(topChunk?.metadata, topChunk?.source, topChunk?.title);
2455
+ const sourceAwareChunkReason = formatSourceAwareChunkReason(topChunk?.metadata?.sourceAwareChunkReason);
2456
+ const sourceAwareUnitScopeLabel = buildSourceAwareUnitScopeLabel(topChunk?.metadata);
2064
2457
  const parentDistribution = parentTotal > 0 ? siblingPool.map((entry) => ({
2065
2458
  count: entry.count,
2066
2459
  isActive: entry.key === section.key,
@@ -2191,8 +2584,8 @@ var buildRAGSectionRetrievalDiagnostics = (sources, trace) => {
2191
2584
  `${(scoreShare * 100).toFixed(0)}% score share`,
2192
2585
  `vector ${section.vectorHits} · lexical ${section.lexicalHits} · hybrid ${section.hybridHits}`,
2193
2586
  typeof parentShare === "number" ? `${(parentShare * 100).toFixed(0)}% of parent section set` : "",
2194
- formatSourceAwareChunkReason(topChunk?.metadata?.sourceAwareChunkReason),
2195
- buildSourceAwareUnitScopeLabel(topChunk?.metadata),
2587
+ sourceAwareChunkReason ? `boundary ${sourceAwareChunkReason}` : "",
2588
+ sourceAwareUnitScopeLabel ? `scope ${sourceAwareUnitScopeLabel}` : "",
2196
2589
  strongestSibling ? `ahead of ${strongestSibling.label} by ${(section.totalScore - strongestSibling.totalScore).toFixed(2)}` : "no sibling competition"
2197
2590
  ].filter(Boolean);
2198
2591
  return {
@@ -2237,6 +2630,10 @@ var buildRAGSectionRetrievalDiagnostics = (sources, trace) => {
2237
2630
  siblingCount: siblings.length,
2238
2631
  siblingScoreGap: strongestSibling ? section.totalScore - strongestSibling.totalScore : undefined,
2239
2632
  sourceCount: section.sourceSet.size,
2633
+ sourceAwareChunkReasonLabel: sourceAwareChunkReason,
2634
+ sourceAwareUnitScopeLabel,
2635
+ topContextLabel,
2636
+ topLocatorLabel,
2240
2637
  sourceBalanceApplied: trace?.steps.some((step) => step.stage === "source_balance"),
2241
2638
  strongestSiblingLabel: strongestSibling?.label,
2242
2639
  strongestSiblingScore: strongestSibling?.totalScore,
@@ -3541,377 +3938,6 @@ var createRAGClient = (options) => {
3541
3938
  }
3542
3939
  };
3543
3940
  };
3544
- // src/ai/rag/quality.ts
3545
- var {mkdir, readFile, writeFile} = (() => ({}));
3546
-
3547
- // node:path
3548
- function assertPath(path) {
3549
- if (typeof path !== "string")
3550
- throw TypeError("Path must be a string. Received " + JSON.stringify(path));
3551
- }
3552
- function normalizeStringPosix(path, allowAboveRoot) {
3553
- var res = "", lastSegmentLength = 0, lastSlash = -1, dots = 0, code;
3554
- for (var i = 0;i <= path.length; ++i) {
3555
- if (i < path.length)
3556
- code = path.charCodeAt(i);
3557
- else if (code === 47)
3558
- break;
3559
- else
3560
- code = 47;
3561
- if (code === 47) {
3562
- if (lastSlash === i - 1 || dots === 1)
3563
- ;
3564
- else if (lastSlash !== i - 1 && dots === 2) {
3565
- if (res.length < 2 || lastSegmentLength !== 2 || res.charCodeAt(res.length - 1) !== 46 || res.charCodeAt(res.length - 2) !== 46) {
3566
- if (res.length > 2) {
3567
- var lastSlashIndex = res.lastIndexOf("/");
3568
- if (lastSlashIndex !== res.length - 1) {
3569
- if (lastSlashIndex === -1)
3570
- res = "", lastSegmentLength = 0;
3571
- else
3572
- res = res.slice(0, lastSlashIndex), lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
3573
- lastSlash = i, dots = 0;
3574
- continue;
3575
- }
3576
- } else if (res.length === 2 || res.length === 1) {
3577
- res = "", lastSegmentLength = 0, lastSlash = i, dots = 0;
3578
- continue;
3579
- }
3580
- }
3581
- if (allowAboveRoot) {
3582
- if (res.length > 0)
3583
- res += "/..";
3584
- else
3585
- res = "..";
3586
- lastSegmentLength = 2;
3587
- }
3588
- } else {
3589
- if (res.length > 0)
3590
- res += "/" + path.slice(lastSlash + 1, i);
3591
- else
3592
- res = path.slice(lastSlash + 1, i);
3593
- lastSegmentLength = i - lastSlash - 1;
3594
- }
3595
- lastSlash = i, dots = 0;
3596
- } else if (code === 46 && dots !== -1)
3597
- ++dots;
3598
- else
3599
- dots = -1;
3600
- }
3601
- return res;
3602
- }
3603
- function _format(sep, pathObject) {
3604
- var dir = pathObject.dir || pathObject.root, base = pathObject.base || (pathObject.name || "") + (pathObject.ext || "");
3605
- if (!dir)
3606
- return base;
3607
- if (dir === pathObject.root)
3608
- return dir + base;
3609
- return dir + sep + base;
3610
- }
3611
- function resolve() {
3612
- var resolvedPath = "", resolvedAbsolute = false, cwd;
3613
- for (var i = arguments.length - 1;i >= -1 && !resolvedAbsolute; i--) {
3614
- var path;
3615
- if (i >= 0)
3616
- path = arguments[i];
3617
- else {
3618
- if (cwd === undefined)
3619
- cwd = process.cwd();
3620
- path = cwd;
3621
- }
3622
- if (assertPath(path), path.length === 0)
3623
- continue;
3624
- resolvedPath = path + "/" + resolvedPath, resolvedAbsolute = path.charCodeAt(0) === 47;
3625
- }
3626
- if (resolvedPath = normalizeStringPosix(resolvedPath, !resolvedAbsolute), resolvedAbsolute)
3627
- if (resolvedPath.length > 0)
3628
- return "/" + resolvedPath;
3629
- else
3630
- return "/";
3631
- else if (resolvedPath.length > 0)
3632
- return resolvedPath;
3633
- else
3634
- return ".";
3635
- }
3636
- function normalize(path) {
3637
- if (assertPath(path), path.length === 0)
3638
- return ".";
3639
- var isAbsolute = path.charCodeAt(0) === 47, trailingSeparator = path.charCodeAt(path.length - 1) === 47;
3640
- if (path = normalizeStringPosix(path, !isAbsolute), path.length === 0 && !isAbsolute)
3641
- path = ".";
3642
- if (path.length > 0 && trailingSeparator)
3643
- path += "/";
3644
- if (isAbsolute)
3645
- return "/" + path;
3646
- return path;
3647
- }
3648
- function isAbsolute(path) {
3649
- return assertPath(path), path.length > 0 && path.charCodeAt(0) === 47;
3650
- }
3651
- function join() {
3652
- if (arguments.length === 0)
3653
- return ".";
3654
- var joined;
3655
- for (var i = 0;i < arguments.length; ++i) {
3656
- var arg = arguments[i];
3657
- if (assertPath(arg), arg.length > 0)
3658
- if (joined === undefined)
3659
- joined = arg;
3660
- else
3661
- joined += "/" + arg;
3662
- }
3663
- if (joined === undefined)
3664
- return ".";
3665
- return normalize(joined);
3666
- }
3667
- function relative(from, to) {
3668
- if (assertPath(from), assertPath(to), from === to)
3669
- return "";
3670
- if (from = resolve(from), to = resolve(to), from === to)
3671
- return "";
3672
- var fromStart = 1;
3673
- for (;fromStart < from.length; ++fromStart)
3674
- if (from.charCodeAt(fromStart) !== 47)
3675
- break;
3676
- var fromEnd = from.length, fromLen = fromEnd - fromStart, toStart = 1;
3677
- for (;toStart < to.length; ++toStart)
3678
- if (to.charCodeAt(toStart) !== 47)
3679
- break;
3680
- var toEnd = to.length, toLen = toEnd - toStart, length = fromLen < toLen ? fromLen : toLen, lastCommonSep = -1, i = 0;
3681
- for (;i <= length; ++i) {
3682
- if (i === length) {
3683
- if (toLen > length) {
3684
- if (to.charCodeAt(toStart + i) === 47)
3685
- return to.slice(toStart + i + 1);
3686
- else if (i === 0)
3687
- return to.slice(toStart + i);
3688
- } else if (fromLen > length) {
3689
- if (from.charCodeAt(fromStart + i) === 47)
3690
- lastCommonSep = i;
3691
- else if (i === 0)
3692
- lastCommonSep = 0;
3693
- }
3694
- break;
3695
- }
3696
- var fromCode = from.charCodeAt(fromStart + i), toCode = to.charCodeAt(toStart + i);
3697
- if (fromCode !== toCode)
3698
- break;
3699
- else if (fromCode === 47)
3700
- lastCommonSep = i;
3701
- }
3702
- var out = "";
3703
- for (i = fromStart + lastCommonSep + 1;i <= fromEnd; ++i)
3704
- if (i === fromEnd || from.charCodeAt(i) === 47)
3705
- if (out.length === 0)
3706
- out += "..";
3707
- else
3708
- out += "/..";
3709
- if (out.length > 0)
3710
- return out + to.slice(toStart + lastCommonSep);
3711
- else {
3712
- if (toStart += lastCommonSep, to.charCodeAt(toStart) === 47)
3713
- ++toStart;
3714
- return to.slice(toStart);
3715
- }
3716
- }
3717
- function _makeLong(path) {
3718
- return path;
3719
- }
3720
- function dirname(path) {
3721
- if (assertPath(path), path.length === 0)
3722
- return ".";
3723
- var code = path.charCodeAt(0), hasRoot = code === 47, end = -1, matchedSlash = true;
3724
- for (var i = path.length - 1;i >= 1; --i)
3725
- if (code = path.charCodeAt(i), code === 47) {
3726
- if (!matchedSlash) {
3727
- end = i;
3728
- break;
3729
- }
3730
- } else
3731
- matchedSlash = false;
3732
- if (end === -1)
3733
- return hasRoot ? "/" : ".";
3734
- if (hasRoot && end === 1)
3735
- return "//";
3736
- return path.slice(0, end);
3737
- }
3738
- function basename(path, ext) {
3739
- if (ext !== undefined && typeof ext !== "string")
3740
- throw TypeError('"ext" argument must be a string');
3741
- assertPath(path);
3742
- var start = 0, end = -1, matchedSlash = true, i;
3743
- if (ext !== undefined && ext.length > 0 && ext.length <= path.length) {
3744
- if (ext.length === path.length && ext === path)
3745
- return "";
3746
- var extIdx = ext.length - 1, firstNonSlashEnd = -1;
3747
- for (i = path.length - 1;i >= 0; --i) {
3748
- var code = path.charCodeAt(i);
3749
- if (code === 47) {
3750
- if (!matchedSlash) {
3751
- start = i + 1;
3752
- break;
3753
- }
3754
- } else {
3755
- if (firstNonSlashEnd === -1)
3756
- matchedSlash = false, firstNonSlashEnd = i + 1;
3757
- if (extIdx >= 0)
3758
- if (code === ext.charCodeAt(extIdx)) {
3759
- if (--extIdx === -1)
3760
- end = i;
3761
- } else
3762
- extIdx = -1, end = firstNonSlashEnd;
3763
- }
3764
- }
3765
- if (start === end)
3766
- end = firstNonSlashEnd;
3767
- else if (end === -1)
3768
- end = path.length;
3769
- return path.slice(start, end);
3770
- } else {
3771
- for (i = path.length - 1;i >= 0; --i)
3772
- if (path.charCodeAt(i) === 47) {
3773
- if (!matchedSlash) {
3774
- start = i + 1;
3775
- break;
3776
- }
3777
- } else if (end === -1)
3778
- matchedSlash = false, end = i + 1;
3779
- if (end === -1)
3780
- return "";
3781
- return path.slice(start, end);
3782
- }
3783
- }
3784
- function extname(path) {
3785
- assertPath(path);
3786
- var startDot = -1, startPart = 0, end = -1, matchedSlash = true, preDotState = 0;
3787
- for (var i = path.length - 1;i >= 0; --i) {
3788
- var code = path.charCodeAt(i);
3789
- if (code === 47) {
3790
- if (!matchedSlash) {
3791
- startPart = i + 1;
3792
- break;
3793
- }
3794
- continue;
3795
- }
3796
- if (end === -1)
3797
- matchedSlash = false, end = i + 1;
3798
- if (code === 46) {
3799
- if (startDot === -1)
3800
- startDot = i;
3801
- else if (preDotState !== 1)
3802
- preDotState = 1;
3803
- } else if (startDot !== -1)
3804
- preDotState = -1;
3805
- }
3806
- if (startDot === -1 || end === -1 || preDotState === 0 || preDotState === 1 && startDot === end - 1 && startDot === startPart + 1)
3807
- return "";
3808
- return path.slice(startDot, end);
3809
- }
3810
- function format(pathObject) {
3811
- if (pathObject === null || typeof pathObject !== "object")
3812
- throw TypeError('The "pathObject" argument must be of type Object. Received type ' + typeof pathObject);
3813
- return _format("/", pathObject);
3814
- }
3815
- function parse(path) {
3816
- assertPath(path);
3817
- var ret = { root: "", dir: "", base: "", ext: "", name: "" };
3818
- if (path.length === 0)
3819
- return ret;
3820
- var code = path.charCodeAt(0), isAbsolute2 = code === 47, start;
3821
- if (isAbsolute2)
3822
- ret.root = "/", start = 1;
3823
- else
3824
- start = 0;
3825
- var startDot = -1, startPart = 0, end = -1, matchedSlash = true, i = path.length - 1, preDotState = 0;
3826
- for (;i >= start; --i) {
3827
- if (code = path.charCodeAt(i), code === 47) {
3828
- if (!matchedSlash) {
3829
- startPart = i + 1;
3830
- break;
3831
- }
3832
- continue;
3833
- }
3834
- if (end === -1)
3835
- matchedSlash = false, end = i + 1;
3836
- if (code === 46) {
3837
- if (startDot === -1)
3838
- startDot = i;
3839
- else if (preDotState !== 1)
3840
- preDotState = 1;
3841
- } else if (startDot !== -1)
3842
- preDotState = -1;
3843
- }
3844
- if (startDot === -1 || end === -1 || preDotState === 0 || preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
3845
- if (end !== -1)
3846
- if (startPart === 0 && isAbsolute2)
3847
- ret.base = ret.name = path.slice(1, end);
3848
- else
3849
- ret.base = ret.name = path.slice(startPart, end);
3850
- } else {
3851
- if (startPart === 0 && isAbsolute2)
3852
- ret.name = path.slice(1, startDot), ret.base = path.slice(1, end);
3853
- else
3854
- ret.name = path.slice(startPart, startDot), ret.base = path.slice(startPart, end);
3855
- ret.ext = path.slice(startDot, end);
3856
- }
3857
- if (startPart > 0)
3858
- ret.dir = path.slice(0, startPart - 1);
3859
- else if (isAbsolute2)
3860
- ret.dir = "/";
3861
- return ret;
3862
- }
3863
- var sep = "/";
3864
- var delimiter = ":";
3865
- var posix = ((p) => (p.posix = p, p))({ resolve, normalize, isAbsolute, join, relative, _makeLong, dirname, basename, extname, format, parse, sep, delimiter, win32: null, posix: null });
3866
-
3867
- // src/ai/rag/quality.ts
3868
- var buildRAGEvaluationLeaderboard = (runs) => {
3869
- const sorted = [...runs].sort((left, right) => {
3870
- if (right.response.passingRate !== left.response.passingRate) {
3871
- return right.response.passingRate - left.response.passingRate;
3872
- }
3873
- if (right.response.summary.averageF1 !== left.response.summary.averageF1) {
3874
- return right.response.summary.averageF1 - left.response.summary.averageF1;
3875
- }
3876
- return left.response.summary.averageLatencyMs - right.response.summary.averageLatencyMs;
3877
- });
3878
- return sorted.map((run, index) => ({
3879
- averageF1: run.response.summary.averageF1,
3880
- averageLatencyMs: run.response.summary.averageLatencyMs,
3881
- label: run.label,
3882
- passingRate: run.response.passingRate,
3883
- rank: index + 1,
3884
- runId: run.id,
3885
- suiteId: run.suiteId,
3886
- totalCases: run.response.totalCases
3887
- }));
3888
- };
3889
- var runRAGEvaluationSuite = async ({
3890
- suite,
3891
- evaluate,
3892
- overrides,
3893
- artifacts
3894
- }) => {
3895
- const startedAt = Date.now();
3896
- const response = await evaluate({
3897
- ...suite.input,
3898
- ...overrides,
3899
- cases: overrides?.cases ?? suite.input.cases
3900
- });
3901
- const finishedAt = Date.now();
3902
- return {
3903
- caseTraceSnapshots: artifacts?.caseTraceSnapshots,
3904
- elapsedMs: finishedAt - startedAt,
3905
- finishedAt,
3906
- id: generateId(),
3907
- label: suite.label ?? suite.id,
3908
- metadata: suite.metadata,
3909
- response,
3910
- startedAt,
3911
- suiteId: suite.id,
3912
- traceSummary: artifacts?.traceSummary
3913
- };
3914
- };
3915
3941
  // src/react/ai/useRAGChunkPreview.ts
3916
3942
  var useRAGChunkPreview = (path) => {
3917
3943
  const client = useMemo(() => createRAGClient({ path }), [path]);