@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
@@ -2186,160 +2186,532 @@ var buildRAGGroundingReferences = (sources) => {
2186
2186
  });
2187
2187
  };
2188
2188
 
2189
- // src/ai/rag/presentation.ts
2190
- var buildSourceGroupKey = (source) => source.source ?? source.title ?? source.chunkId;
2191
- var buildSourceLabel2 = (source) => source.source ?? source.title ?? source.chunkId;
2192
- var getContextNumber2 = (value) => typeof value === "number" && Number.isFinite(value) ? value : undefined;
2193
- var getContextString2 = (value) => typeof value === "string" && value.trim().length > 0 ? value.trim() : undefined;
2194
- var isRAGRetrievalTrace = (value) => {
2195
- if (!value || typeof value !== "object") {
2196
- return false;
2197
- }
2198
- const candidate = value;
2199
- return typeof candidate.query === "string" && typeof candidate.transformedQuery === "string" && Array.isArray(candidate.variantQueries) && Array.isArray(candidate.steps);
2200
- };
2201
- var formatTimestampLabel2 = (value) => {
2202
- const timestamp = typeof value === "number" && Number.isFinite(value) ? value : typeof value === "string" ? Date.parse(value) : Number.NaN;
2203
- if (!Number.isFinite(timestamp)) {
2204
- return;
2205
- }
2206
- return new Date(timestamp).toLocaleString("en-US", {
2207
- dateStyle: "medium",
2208
- timeStyle: "short"
2209
- });
2210
- };
2211
- var formatSourceAwareChunkReason = (value) => {
2212
- const reason = getContextString2(value);
2213
- if (reason === "section_boundary") {
2214
- return "Chunk boundary section";
2215
- }
2216
- if (reason === "size_limit") {
2217
- return "Chunk boundary size limit";
2218
- }
2219
- if (reason === "source_native_unit") {
2220
- return "Chunk boundary source-native unit";
2221
- }
2222
- return;
2223
- };
2224
- var buildSourceAwareUnitScopeLabel = (metadata) => {
2225
- if (!metadata) {
2226
- return;
2227
- }
2228
- const sectionKind = getContextString2(metadata.sectionKind);
2229
- const sectionPath = Array.isArray(metadata.sectionPath) ? metadata.sectionPath.map((value) => getContextString2(value)).filter((value) => typeof value === "string") : [];
2230
- const sectionTitle = getContextString2(metadata.sectionTitle) ?? sectionPath.at(-1);
2231
- const pdfTextKind = getContextString2(metadata.pdfTextKind);
2232
- const officeBlockKind = getContextString2(metadata.officeBlockKind);
2233
- const sheetName = getContextString2(metadata.sheetName);
2234
- const spreadsheetTableLabel = formatSpreadsheetTableLabel(getContextNumber2(metadata.spreadsheetTableIndex), getContextNumber2(metadata.spreadsheetTableCount));
2235
- const slideTitle = getContextString2(metadata.slideTitle);
2236
- const slideNumber = getContextNumber2(metadata.slideNumber) ?? (typeof metadata.slideIndex === "number" ? metadata.slideIndex + 1 : undefined);
2237
- if (sectionPath.length > 0 && (sectionKind === "markdown_heading" || sectionKind === "html_heading" || sectionKind === "office_heading" || sectionKind === undefined)) {
2238
- return `Source-aware section ${sectionPath.join(" > ")}`;
2239
- }
2240
- if (sectionKind === "pdf_block") {
2241
- if (pdfTextKind === "table_like" && sectionTitle) {
2242
- return `Source-aware PDF table block ${sectionTitle}`;
2243
- }
2244
- if (sectionTitle) {
2245
- return `Source-aware PDF block ${sectionTitle}`;
2246
- }
2247
- return "Source-aware PDF block";
2189
+ // src/ai/rag/quality.ts
2190
+ var {mkdir, readFile, writeFile} = (() => ({}));
2191
+
2192
+ // node:path
2193
+ function assertPath(path) {
2194
+ if (typeof path !== "string")
2195
+ throw TypeError("Path must be a string. Received " + JSON.stringify(path));
2196
+ }
2197
+ function normalizeStringPosix(path, allowAboveRoot) {
2198
+ var res = "", lastSegmentLength = 0, lastSlash = -1, dots = 0, code;
2199
+ for (var i = 0;i <= path.length; ++i) {
2200
+ if (i < path.length)
2201
+ code = path.charCodeAt(i);
2202
+ else if (code === 47)
2203
+ break;
2204
+ else
2205
+ code = 47;
2206
+ if (code === 47) {
2207
+ if (lastSlash === i - 1 || dots === 1)
2208
+ ;
2209
+ else if (lastSlash !== i - 1 && dots === 2) {
2210
+ if (res.length < 2 || lastSegmentLength !== 2 || res.charCodeAt(res.length - 1) !== 46 || res.charCodeAt(res.length - 2) !== 46) {
2211
+ if (res.length > 2) {
2212
+ var lastSlashIndex = res.lastIndexOf("/");
2213
+ if (lastSlashIndex !== res.length - 1) {
2214
+ if (lastSlashIndex === -1)
2215
+ res = "", lastSegmentLength = 0;
2216
+ else
2217
+ res = res.slice(0, lastSlashIndex), lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
2218
+ lastSlash = i, dots = 0;
2219
+ continue;
2220
+ }
2221
+ } else if (res.length === 2 || res.length === 1) {
2222
+ res = "", lastSegmentLength = 0, lastSlash = i, dots = 0;
2223
+ continue;
2224
+ }
2225
+ }
2226
+ if (allowAboveRoot) {
2227
+ if (res.length > 0)
2228
+ res += "/..";
2229
+ else
2230
+ res = "..";
2231
+ lastSegmentLength = 2;
2232
+ }
2233
+ } else {
2234
+ if (res.length > 0)
2235
+ res += "/" + path.slice(lastSlash + 1, i);
2236
+ else
2237
+ res = path.slice(lastSlash + 1, i);
2238
+ lastSegmentLength = i - lastSlash - 1;
2239
+ }
2240
+ lastSlash = i, dots = 0;
2241
+ } else if (code === 46 && dots !== -1)
2242
+ ++dots;
2243
+ else
2244
+ dots = -1;
2248
2245
  }
2249
- if (sectionKind === "office_block") {
2250
- if (officeBlockKind && sectionTitle) {
2251
- return `Source-aware office ${officeBlockKind} block ${sectionTitle}`;
2252
- }
2253
- if (sectionTitle) {
2254
- return `Source-aware office block ${sectionTitle}`;
2246
+ return res;
2247
+ }
2248
+ function _format(sep, pathObject) {
2249
+ var dir = pathObject.dir || pathObject.root, base = pathObject.base || (pathObject.name || "") + (pathObject.ext || "");
2250
+ if (!dir)
2251
+ return base;
2252
+ if (dir === pathObject.root)
2253
+ return dir + base;
2254
+ return dir + sep + base;
2255
+ }
2256
+ function resolve() {
2257
+ var resolvedPath = "", resolvedAbsolute = false, cwd;
2258
+ for (var i = arguments.length - 1;i >= -1 && !resolvedAbsolute; i--) {
2259
+ var path;
2260
+ if (i >= 0)
2261
+ path = arguments[i];
2262
+ else {
2263
+ if (cwd === undefined)
2264
+ cwd = process.cwd();
2265
+ path = cwd;
2255
2266
  }
2256
- return "Source-aware office block";
2267
+ if (assertPath(path), path.length === 0)
2268
+ continue;
2269
+ resolvedPath = path + "/" + resolvedPath, resolvedAbsolute = path.charCodeAt(0) === 47;
2257
2270
  }
2258
- if (sectionKind === "spreadsheet_rows" || sectionKind === undefined && (sheetName || spreadsheetTableLabel || getContextNumber2(metadata.spreadsheetRowStart) !== undefined || getContextNumber2(metadata.spreadsheetRowEnd) !== undefined)) {
2259
- if (sheetName && spreadsheetTableLabel) {
2260
- return `Source-aware spreadsheet ${sheetName} ${spreadsheetTableLabel}`;
2261
- }
2262
- if (sheetName) {
2263
- return `Source-aware spreadsheet ${sheetName}`;
2264
- }
2265
- return "Source-aware spreadsheet";
2271
+ if (resolvedPath = normalizeStringPosix(resolvedPath, !resolvedAbsolute), resolvedAbsolute)
2272
+ if (resolvedPath.length > 0)
2273
+ return "/" + resolvedPath;
2274
+ else
2275
+ return "/";
2276
+ else if (resolvedPath.length > 0)
2277
+ return resolvedPath;
2278
+ else
2279
+ return ".";
2280
+ }
2281
+ function normalize(path) {
2282
+ if (assertPath(path), path.length === 0)
2283
+ return ".";
2284
+ var isAbsolute = path.charCodeAt(0) === 47, trailingSeparator = path.charCodeAt(path.length - 1) === 47;
2285
+ if (path = normalizeStringPosix(path, !isAbsolute), path.length === 0 && !isAbsolute)
2286
+ path = ".";
2287
+ if (path.length > 0 && trailingSeparator)
2288
+ path += "/";
2289
+ if (isAbsolute)
2290
+ return "/" + path;
2291
+ return path;
2292
+ }
2293
+ function isAbsolute(path) {
2294
+ return assertPath(path), path.length > 0 && path.charCodeAt(0) === 47;
2295
+ }
2296
+ function join() {
2297
+ if (arguments.length === 0)
2298
+ return ".";
2299
+ var joined;
2300
+ for (var i = 0;i < arguments.length; ++i) {
2301
+ var arg = arguments[i];
2302
+ if (assertPath(arg), arg.length > 0)
2303
+ if (joined === undefined)
2304
+ joined = arg;
2305
+ else
2306
+ joined += "/" + arg;
2266
2307
  }
2267
- if (sectionKind === "presentation_slide") {
2268
- if (slideNumber && slideTitle) {
2269
- return `Source-aware slide ${slideNumber} ${slideTitle}`;
2270
- }
2271
- if (slideTitle) {
2272
- return `Source-aware slide ${slideTitle}`;
2273
- }
2274
- if (slideNumber) {
2275
- return `Source-aware slide ${slideNumber}`;
2308
+ if (joined === undefined)
2309
+ return ".";
2310
+ return normalize(joined);
2311
+ }
2312
+ function relative(from, to) {
2313
+ if (assertPath(from), assertPath(to), from === to)
2314
+ return "";
2315
+ if (from = resolve(from), to = resolve(to), from === to)
2316
+ return "";
2317
+ var fromStart = 1;
2318
+ for (;fromStart < from.length; ++fromStart)
2319
+ if (from.charCodeAt(fromStart) !== 47)
2320
+ break;
2321
+ var fromEnd = from.length, fromLen = fromEnd - fromStart, toStart = 1;
2322
+ for (;toStart < to.length; ++toStart)
2323
+ if (to.charCodeAt(toStart) !== 47)
2324
+ break;
2325
+ var toEnd = to.length, toLen = toEnd - toStart, length = fromLen < toLen ? fromLen : toLen, lastCommonSep = -1, i = 0;
2326
+ for (;i <= length; ++i) {
2327
+ if (i === length) {
2328
+ if (toLen > length) {
2329
+ if (to.charCodeAt(toStart + i) === 47)
2330
+ return to.slice(toStart + i + 1);
2331
+ else if (i === 0)
2332
+ return to.slice(toStart + i);
2333
+ } else if (fromLen > length) {
2334
+ if (from.charCodeAt(fromStart + i) === 47)
2335
+ lastCommonSep = i;
2336
+ else if (i === 0)
2337
+ lastCommonSep = 0;
2338
+ }
2339
+ break;
2276
2340
  }
2277
- return "Source-aware slide";
2341
+ var fromCode = from.charCodeAt(fromStart + i), toCode = to.charCodeAt(toStart + i);
2342
+ if (fromCode !== toCode)
2343
+ break;
2344
+ else if (fromCode === 47)
2345
+ lastCommonSep = i;
2278
2346
  }
2279
- return;
2280
- };
2281
- var formatMediaTimestamp2 = (value) => {
2282
- if (typeof value !== "number" || !Number.isFinite(value) || value < 0) {
2283
- return;
2347
+ var out = "";
2348
+ for (i = fromStart + lastCommonSep + 1;i <= fromEnd; ++i)
2349
+ if (i === fromEnd || from.charCodeAt(i) === 47)
2350
+ if (out.length === 0)
2351
+ out += "..";
2352
+ else
2353
+ out += "/..";
2354
+ if (out.length > 0)
2355
+ return out + to.slice(toStart + lastCommonSep);
2356
+ else {
2357
+ if (toStart += lastCommonSep, to.charCodeAt(toStart) === 47)
2358
+ ++toStart;
2359
+ return to.slice(toStart);
2284
2360
  }
2285
- const totalSeconds = Math.floor(value / 1000);
2286
- const minutes = Math.floor(totalSeconds / 60);
2287
- const seconds = totalSeconds % 60;
2288
- const milliseconds = Math.floor(value % 1000);
2289
- return `${String(minutes).padStart(2, "0")}:${String(seconds).padStart(2, "0")}.${String(milliseconds).padStart(3, "0")}`;
2290
- };
2291
- var getAttachmentName2 = (source, title) => {
2292
- const sourceAttachment = source?.split("/").at(-1);
2293
- if (sourceAttachment && sourceAttachment.includes(".")) {
2294
- return sourceAttachment;
2295
- }
2296
- const titleAttachment = title?.split(" · ").at(-1);
2297
- if (titleAttachment && titleAttachment.includes(".")) {
2298
- return titleAttachment;
2361
+ }
2362
+ function _makeLong(path) {
2363
+ return path;
2364
+ }
2365
+ function dirname(path) {
2366
+ if (assertPath(path), path.length === 0)
2367
+ return ".";
2368
+ var code = path.charCodeAt(0), hasRoot = code === 47, end = -1, matchedSlash = true;
2369
+ for (var i = path.length - 1;i >= 1; --i)
2370
+ if (code = path.charCodeAt(i), code === 47) {
2371
+ if (!matchedSlash) {
2372
+ end = i;
2373
+ break;
2374
+ }
2375
+ } else
2376
+ matchedSlash = false;
2377
+ if (end === -1)
2378
+ return hasRoot ? "/" : ".";
2379
+ if (hasRoot && end === 1)
2380
+ return "//";
2381
+ return path.slice(0, end);
2382
+ }
2383
+ function basename(path, ext) {
2384
+ if (ext !== undefined && typeof ext !== "string")
2385
+ throw TypeError('"ext" argument must be a string');
2386
+ assertPath(path);
2387
+ var start = 0, end = -1, matchedSlash = true, i;
2388
+ if (ext !== undefined && ext.length > 0 && ext.length <= path.length) {
2389
+ if (ext.length === path.length && ext === path)
2390
+ return "";
2391
+ var extIdx = ext.length - 1, firstNonSlashEnd = -1;
2392
+ for (i = path.length - 1;i >= 0; --i) {
2393
+ var code = path.charCodeAt(i);
2394
+ if (code === 47) {
2395
+ if (!matchedSlash) {
2396
+ start = i + 1;
2397
+ break;
2398
+ }
2399
+ } else {
2400
+ if (firstNonSlashEnd === -1)
2401
+ matchedSlash = false, firstNonSlashEnd = i + 1;
2402
+ if (extIdx >= 0)
2403
+ if (code === ext.charCodeAt(extIdx)) {
2404
+ if (--extIdx === -1)
2405
+ end = i;
2406
+ } else
2407
+ extIdx = -1, end = firstNonSlashEnd;
2408
+ }
2409
+ }
2410
+ if (start === end)
2411
+ end = firstNonSlashEnd;
2412
+ else if (end === -1)
2413
+ end = path.length;
2414
+ return path.slice(start, end);
2415
+ } else {
2416
+ for (i = path.length - 1;i >= 0; --i)
2417
+ if (path.charCodeAt(i) === 47) {
2418
+ if (!matchedSlash) {
2419
+ start = i + 1;
2420
+ break;
2421
+ }
2422
+ } else if (end === -1)
2423
+ matchedSlash = false, end = i + 1;
2424
+ if (end === -1)
2425
+ return "";
2426
+ return path.slice(start, end);
2299
2427
  }
2300
- return;
2301
- };
2302
- var getSpreadsheetHeaders = (metadata) => Array.isArray(metadata?.spreadsheetHeaders) ? metadata.spreadsheetHeaders.map((value) => getContextString2(value)).filter((value) => typeof value === "string") : [];
2303
- var formatSpreadsheetColumnRange = (columnStart, columnEnd) => {
2304
- if (typeof columnStart !== "string" || columnStart.length === 0) {
2305
- return;
2428
+ }
2429
+ function extname(path) {
2430
+ assertPath(path);
2431
+ var startDot = -1, startPart = 0, end = -1, matchedSlash = true, preDotState = 0;
2432
+ for (var i = path.length - 1;i >= 0; --i) {
2433
+ var code = path.charCodeAt(i);
2434
+ if (code === 47) {
2435
+ if (!matchedSlash) {
2436
+ startPart = i + 1;
2437
+ break;
2438
+ }
2439
+ continue;
2440
+ }
2441
+ if (end === -1)
2442
+ matchedSlash = false, end = i + 1;
2443
+ if (code === 46) {
2444
+ if (startDot === -1)
2445
+ startDot = i;
2446
+ else if (preDotState !== 1)
2447
+ preDotState = 1;
2448
+ } else if (startDot !== -1)
2449
+ preDotState = -1;
2306
2450
  }
2307
- if (typeof columnEnd !== "string" || columnEnd.length === 0) {
2308
- return `Columns ${columnStart}`;
2451
+ if (startDot === -1 || end === -1 || preDotState === 0 || preDotState === 1 && startDot === end - 1 && startDot === startPart + 1)
2452
+ return "";
2453
+ return path.slice(startDot, end);
2454
+ }
2455
+ function format(pathObject) {
2456
+ if (pathObject === null || typeof pathObject !== "object")
2457
+ throw TypeError('The "pathObject" argument must be of type Object. Received type ' + typeof pathObject);
2458
+ return _format("/", pathObject);
2459
+ }
2460
+ function parse(path) {
2461
+ assertPath(path);
2462
+ var ret = { root: "", dir: "", base: "", ext: "", name: "" };
2463
+ if (path.length === 0)
2464
+ return ret;
2465
+ var code = path.charCodeAt(0), isAbsolute2 = code === 47, start;
2466
+ if (isAbsolute2)
2467
+ ret.root = "/", start = 1;
2468
+ else
2469
+ start = 0;
2470
+ var startDot = -1, startPart = 0, end = -1, matchedSlash = true, i = path.length - 1, preDotState = 0;
2471
+ for (;i >= start; --i) {
2472
+ if (code = path.charCodeAt(i), code === 47) {
2473
+ if (!matchedSlash) {
2474
+ startPart = i + 1;
2475
+ break;
2476
+ }
2477
+ continue;
2478
+ }
2479
+ if (end === -1)
2480
+ matchedSlash = false, end = i + 1;
2481
+ if (code === 46) {
2482
+ if (startDot === -1)
2483
+ startDot = i;
2484
+ else if (preDotState !== 1)
2485
+ preDotState = 1;
2486
+ } else if (startDot !== -1)
2487
+ preDotState = -1;
2309
2488
  }
2310
- if (columnStart === columnEnd) {
2311
- return `Columns ${columnStart}`;
2489
+ if (startDot === -1 || end === -1 || preDotState === 0 || preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
2490
+ if (end !== -1)
2491
+ if (startPart === 0 && isAbsolute2)
2492
+ ret.base = ret.name = path.slice(1, end);
2493
+ else
2494
+ ret.base = ret.name = path.slice(startPart, end);
2495
+ } else {
2496
+ if (startPart === 0 && isAbsolute2)
2497
+ ret.name = path.slice(1, startDot), ret.base = path.slice(1, end);
2498
+ else
2499
+ ret.name = path.slice(startPart, startDot), ret.base = path.slice(startPart, end);
2500
+ ret.ext = path.slice(startDot, end);
2312
2501
  }
2313
- return `Columns ${columnStart}-${columnEnd}`;
2502
+ if (startPart > 0)
2503
+ ret.dir = path.slice(0, startPart - 1);
2504
+ else if (isAbsolute2)
2505
+ ret.dir = "/";
2506
+ return ret;
2507
+ }
2508
+ var sep = "/";
2509
+ var delimiter = ":";
2510
+ var posix = ((p) => (p.posix = p, p))({ resolve, normalize, isAbsolute, join, relative, _makeLong, dirname, basename, extname, format, parse, sep, delimiter, win32: null, posix: null });
2511
+
2512
+ // src/ai/rag/quality.ts
2513
+ var buildRAGEvaluationLeaderboard = (runs) => {
2514
+ const sorted = [...runs].sort((left, right) => {
2515
+ if (right.response.passingRate !== left.response.passingRate) {
2516
+ return right.response.passingRate - left.response.passingRate;
2517
+ }
2518
+ if (right.response.summary.averageF1 !== left.response.summary.averageF1) {
2519
+ return right.response.summary.averageF1 - left.response.summary.averageF1;
2520
+ }
2521
+ return left.response.summary.averageLatencyMs - right.response.summary.averageLatencyMs;
2522
+ });
2523
+ return sorted.map((run, index) => ({
2524
+ averageF1: run.response.summary.averageF1,
2525
+ averageLatencyMs: run.response.summary.averageLatencyMs,
2526
+ label: run.label,
2527
+ passingRate: run.response.passingRate,
2528
+ rank: index + 1,
2529
+ runId: run.id,
2530
+ suiteId: run.suiteId,
2531
+ totalCases: run.response.totalCases
2532
+ }));
2314
2533
  };
2315
- var formatSpreadsheetRowRange = (rowStart, rowEnd) => {
2316
- if (typeof rowStart !== "number" || !Number.isFinite(rowStart)) {
2317
- return;
2318
- }
2319
- if (typeof rowEnd !== "number" && typeof rowStart === "number" && Number.isFinite(rowStart)) {
2320
- return `Rows ${rowStart}`;
2321
- }
2322
- if (rowStart === rowEnd) {
2323
- return `Rows ${rowStart}`;
2324
- }
2325
- return `Rows ${rowStart}-${rowEnd}`;
2534
+ var runRAGEvaluationSuite = async ({
2535
+ suite,
2536
+ evaluate,
2537
+ overrides,
2538
+ artifacts
2539
+ }) => {
2540
+ const startedAt = Date.now();
2541
+ const response = await evaluate({
2542
+ ...suite.input,
2543
+ ...overrides,
2544
+ cases: overrides?.cases ?? suite.input.cases
2545
+ });
2546
+ const finishedAt = Date.now();
2547
+ return {
2548
+ caseTraceSnapshots: artifacts?.caseTraceSnapshots,
2549
+ elapsedMs: finishedAt - startedAt,
2550
+ finishedAt,
2551
+ id: generateId(),
2552
+ label: suite.label ?? suite.id,
2553
+ metadata: suite.metadata,
2554
+ response,
2555
+ startedAt,
2556
+ suiteId: suite.id,
2557
+ traceSummary: artifacts?.traceSummary
2558
+ };
2326
2559
  };
2327
- var formatSpreadsheetTableLabel = (tableIndex, tableCount) => {
2328
- if (typeof tableIndex !== "number" || !Number.isFinite(tableIndex) || tableIndex < 1) {
2329
- return;
2330
- }
2331
- if (typeof tableCount === "number" && Number.isFinite(tableCount) && tableCount >= tableIndex) {
2332
- return `Table ${tableIndex} of ${tableCount}`;
2560
+
2561
+ // src/ai/rag/presentation.ts
2562
+ var buildSourceGroupKey = (source) => source.source ?? source.title ?? source.chunkId;
2563
+ var buildSourceLabel2 = (source) => source.source ?? source.title ?? source.chunkId;
2564
+ var getContextNumber2 = (value) => typeof value === "number" && Number.isFinite(value) ? value : undefined;
2565
+ var getContextString2 = (value) => typeof value === "string" && value.trim().length > 0 ? value.trim() : undefined;
2566
+ var isRAGRetrievalTrace = (value) => {
2567
+ if (!value || typeof value !== "object") {
2568
+ return false;
2333
2569
  }
2334
- return `Table ${tableIndex}`;
2570
+ const candidate = value;
2571
+ return typeof candidate.query === "string" && typeof candidate.transformedQuery === "string" && Array.isArray(candidate.variantQueries) && Array.isArray(candidate.steps);
2335
2572
  };
2336
- var formatMediaDurationLabel2 = (value) => {
2337
- if (typeof value !== "number" || !Number.isFinite(value) || value < 0) {
2573
+ var formatTimestampLabel2 = (value) => {
2574
+ const timestamp = typeof value === "number" && Number.isFinite(value) ? value : typeof value === "string" ? Date.parse(value) : Number.NaN;
2575
+ if (!Number.isFinite(timestamp)) {
2338
2576
  return;
2339
2577
  }
2340
- return formatMediaTimestamp2(value);
2578
+ return new Date(timestamp).toLocaleString("en-US", {
2579
+ dateStyle: "medium",
2580
+ timeStyle: "short"
2581
+ });
2341
2582
  };
2342
- var buildContextLabel2 = (metadata) => {
2583
+ var formatSourceAwareChunkReason = (value) => {
2584
+ const reason = getContextString2(value);
2585
+ if (reason === "section_boundary") {
2586
+ return "Chunk boundary section";
2587
+ }
2588
+ if (reason === "size_limit") {
2589
+ return "Chunk boundary size limit";
2590
+ }
2591
+ if (reason === "source_native_unit") {
2592
+ return "Chunk boundary source-native unit";
2593
+ }
2594
+ return;
2595
+ };
2596
+ var buildSourceAwareUnitScopeLabel = (metadata) => {
2597
+ if (!metadata) {
2598
+ return;
2599
+ }
2600
+ const sectionKind = getContextString2(metadata.sectionKind);
2601
+ const sectionPath = Array.isArray(metadata.sectionPath) ? metadata.sectionPath.map((value) => getContextString2(value)).filter((value) => typeof value === "string") : [];
2602
+ const sectionTitle = getContextString2(metadata.sectionTitle) ?? sectionPath.at(-1);
2603
+ const pdfTextKind = getContextString2(metadata.pdfTextKind);
2604
+ const officeBlockKind = getContextString2(metadata.officeBlockKind);
2605
+ const sheetName = getContextString2(metadata.sheetName);
2606
+ const spreadsheetTableLabel = formatSpreadsheetTableLabel(getContextNumber2(metadata.spreadsheetTableIndex), getContextNumber2(metadata.spreadsheetTableCount));
2607
+ const slideTitle = getContextString2(metadata.slideTitle);
2608
+ const slideNumber = getContextNumber2(metadata.slideNumber) ?? (typeof metadata.slideIndex === "number" ? metadata.slideIndex + 1 : undefined);
2609
+ if (sectionPath.length > 0 && (sectionKind === "markdown_heading" || sectionKind === "html_heading" || sectionKind === "office_heading" || sectionKind === undefined)) {
2610
+ return `Source-aware section ${sectionPath.join(" > ")}`;
2611
+ }
2612
+ if (sectionKind === "pdf_block") {
2613
+ if (pdfTextKind === "table_like" && sectionTitle) {
2614
+ return `Source-aware PDF table block ${sectionTitle}`;
2615
+ }
2616
+ if (sectionTitle) {
2617
+ return `Source-aware PDF block ${sectionTitle}`;
2618
+ }
2619
+ return "Source-aware PDF block";
2620
+ }
2621
+ if (sectionKind === "office_block") {
2622
+ if (officeBlockKind && sectionTitle) {
2623
+ return `Source-aware office ${officeBlockKind} block ${sectionTitle}`;
2624
+ }
2625
+ if (sectionTitle) {
2626
+ return `Source-aware office block ${sectionTitle}`;
2627
+ }
2628
+ return "Source-aware office block";
2629
+ }
2630
+ if (sectionKind === "spreadsheet_rows" || sectionKind === undefined && (sheetName || spreadsheetTableLabel || getContextNumber2(metadata.spreadsheetRowStart) !== undefined || getContextNumber2(metadata.spreadsheetRowEnd) !== undefined)) {
2631
+ if (sheetName && spreadsheetTableLabel) {
2632
+ return `Source-aware spreadsheet ${sheetName} ${spreadsheetTableLabel}`;
2633
+ }
2634
+ if (sheetName) {
2635
+ return `Source-aware spreadsheet ${sheetName}`;
2636
+ }
2637
+ return "Source-aware spreadsheet";
2638
+ }
2639
+ if (sectionKind === "presentation_slide") {
2640
+ if (slideNumber && slideTitle) {
2641
+ return `Source-aware slide ${slideNumber} ${slideTitle}`;
2642
+ }
2643
+ if (slideTitle) {
2644
+ return `Source-aware slide ${slideTitle}`;
2645
+ }
2646
+ if (slideNumber) {
2647
+ return `Source-aware slide ${slideNumber}`;
2648
+ }
2649
+ return "Source-aware slide";
2650
+ }
2651
+ return;
2652
+ };
2653
+ var formatMediaTimestamp2 = (value) => {
2654
+ if (typeof value !== "number" || !Number.isFinite(value) || value < 0) {
2655
+ return;
2656
+ }
2657
+ const totalSeconds = Math.floor(value / 1000);
2658
+ const minutes = Math.floor(totalSeconds / 60);
2659
+ const seconds = totalSeconds % 60;
2660
+ const milliseconds = Math.floor(value % 1000);
2661
+ return `${String(minutes).padStart(2, "0")}:${String(seconds).padStart(2, "0")}.${String(milliseconds).padStart(3, "0")}`;
2662
+ };
2663
+ var getAttachmentName2 = (source, title) => {
2664
+ const sourceAttachment = source?.split("/").at(-1);
2665
+ if (sourceAttachment && sourceAttachment.includes(".")) {
2666
+ return sourceAttachment;
2667
+ }
2668
+ const titleAttachment = title?.split(" · ").at(-1);
2669
+ if (titleAttachment && titleAttachment.includes(".")) {
2670
+ return titleAttachment;
2671
+ }
2672
+ return;
2673
+ };
2674
+ var getSpreadsheetHeaders = (metadata) => Array.isArray(metadata?.spreadsheetHeaders) ? metadata.spreadsheetHeaders.map((value) => getContextString2(value)).filter((value) => typeof value === "string") : [];
2675
+ var formatSpreadsheetColumnRange = (columnStart, columnEnd) => {
2676
+ if (typeof columnStart !== "string" || columnStart.length === 0) {
2677
+ return;
2678
+ }
2679
+ if (typeof columnEnd !== "string" || columnEnd.length === 0) {
2680
+ return `Columns ${columnStart}`;
2681
+ }
2682
+ if (columnStart === columnEnd) {
2683
+ return `Columns ${columnStart}`;
2684
+ }
2685
+ return `Columns ${columnStart}-${columnEnd}`;
2686
+ };
2687
+ var formatSpreadsheetRowRange = (rowStart, rowEnd) => {
2688
+ if (typeof rowStart !== "number" || !Number.isFinite(rowStart)) {
2689
+ return;
2690
+ }
2691
+ if (typeof rowEnd !== "number" && typeof rowStart === "number" && Number.isFinite(rowStart)) {
2692
+ return `Rows ${rowStart}`;
2693
+ }
2694
+ if (rowStart === rowEnd) {
2695
+ return `Rows ${rowStart}`;
2696
+ }
2697
+ return `Rows ${rowStart}-${rowEnd}`;
2698
+ };
2699
+ var formatSpreadsheetTableLabel = (tableIndex, tableCount) => {
2700
+ if (typeof tableIndex !== "number" || !Number.isFinite(tableIndex) || tableIndex < 1) {
2701
+ return;
2702
+ }
2703
+ if (typeof tableCount === "number" && Number.isFinite(tableCount) && tableCount >= tableIndex) {
2704
+ return `Table ${tableIndex} of ${tableCount}`;
2705
+ }
2706
+ return `Table ${tableIndex}`;
2707
+ };
2708
+ var formatMediaDurationLabel2 = (value) => {
2709
+ if (typeof value !== "number" || !Number.isFinite(value) || value < 0) {
2710
+ return;
2711
+ }
2712
+ return formatMediaTimestamp2(value);
2713
+ };
2714
+ var buildContextLabel2 = (metadata) => {
2343
2715
  if (!metadata) {
2344
2716
  return;
2345
2717
  }
@@ -2379,6 +2751,8 @@ var buildContextLabel2 = (metadata) => {
2379
2751
  const page = getContextNumber2(metadata.page) ?? getContextNumber2(metadata.pageNumber) ?? (typeof metadata.pageIndex === "number" ? metadata.pageIndex + 1 : undefined);
2380
2752
  const region = getContextNumber2(metadata.regionNumber) ?? (typeof metadata.regionIndex === "number" ? metadata.regionIndex + 1 : undefined);
2381
2753
  const hasOCRTrace = typeof metadata.ocrRegionConfidence === "number" || typeof metadata.ocrConfidence === "number" || getContextString2(metadata.pdfTextMode) === "ocr" || typeof metadata.ocrRegionCount === "number";
2754
+ const ocrPageStart = getContextNumber2(metadata.ocrPageStart);
2755
+ const ocrPageEnd = getContextNumber2(metadata.ocrPageEnd);
2382
2756
  if (page && region) {
2383
2757
  if (hasOCRTrace) {
2384
2758
  return `OCR page ${page} region ${region}`;
@@ -2391,6 +2765,9 @@ var buildContextLabel2 = (metadata) => {
2391
2765
  }
2392
2766
  return `Page ${page}`;
2393
2767
  }
2768
+ if (hasOCRTrace && typeof ocrPageStart === "number" && typeof ocrPageEnd === "number") {
2769
+ return ocrPageStart === ocrPageEnd ? `OCR page ${ocrPageStart}` : `OCR pages ${ocrPageStart}-${ocrPageEnd}`;
2770
+ }
2394
2771
  const sheet = getContextString2(metadata.sheetName) ?? (Array.isArray(metadata.sheetNames) ? getContextString2(metadata.sheetNames[0]) : undefined);
2395
2772
  if (sheet) {
2396
2773
  const tableLabel = formatSpreadsheetTableLabel(getContextNumber2(metadata.spreadsheetTableIndex), getContextNumber2(metadata.spreadsheetTableCount));
@@ -2461,6 +2838,8 @@ var buildLocatorLabel2 = (metadata, source, title) => {
2461
2838
  const slideTitle = getContextString2(metadata.slideTitle);
2462
2839
  const page = getContextNumber2(metadata.page) ?? getContextNumber2(metadata.pageNumber) ?? (typeof metadata.pageIndex === "number" ? metadata.pageIndex + 1 : undefined);
2463
2840
  const region = getContextNumber2(metadata.regionNumber) ?? (typeof metadata.regionIndex === "number" ? metadata.regionIndex + 1 : undefined);
2841
+ const ocrPageStart = getContextNumber2(metadata.ocrPageStart);
2842
+ const ocrPageEnd = getContextNumber2(metadata.ocrPageEnd);
2464
2843
  if (page && region) {
2465
2844
  return `Page ${page} · Region ${region}`;
2466
2845
  }
@@ -2473,6 +2852,9 @@ var buildLocatorLabel2 = (metadata, source, title) => {
2473
2852
  if (page) {
2474
2853
  return `Page ${page}`;
2475
2854
  }
2855
+ if (typeof ocrPageStart === "number" && typeof ocrPageEnd === "number") {
2856
+ return ocrPageStart === ocrPageEnd ? `Page ${ocrPageStart}` : `Pages ${ocrPageStart}-${ocrPageEnd}`;
2857
+ }
2476
2858
  const sheet = getContextString2(metadata.sheetName) ?? (Array.isArray(metadata.sheetNames) ? getContextString2(metadata.sheetNames[0]) : undefined);
2477
2859
  if (sheet) {
2478
2860
  const tableLabel = formatSpreadsheetTableLabel(getContextNumber2(metadata.spreadsheetTableIndex), getContextNumber2(metadata.spreadsheetTableCount));
@@ -2577,6 +2959,8 @@ var buildProvenanceLabel2 = (metadata) => {
2577
2959
  const spreadsheetTableLabel = formatSpreadsheetTableLabel(getContextNumber2(metadata.spreadsheetTableIndex), getContextNumber2(metadata.spreadsheetTableCount));
2578
2960
  const ocrConfidence = getContextNumber2(metadata.ocrRegionConfidence) ?? getContextNumber2(metadata.ocrConfidence);
2579
2961
  const ocrAverageConfidence = getContextNumber2(metadata.ocrPageAverageConfidence) ?? getContextNumber2(metadata.ocrAverageConfidence);
2962
+ const ocrMinConfidence = getContextNumber2(metadata.ocrPageMinConfidence) ?? getContextNumber2(metadata.ocrMinConfidence);
2963
+ const ocrMaxConfidence = getContextNumber2(metadata.ocrPageMaxConfidence) ?? getContextNumber2(metadata.ocrMaxConfidence);
2580
2964
  const ocrRegionCount = getContextNumber2(metadata.ocrRegionCount);
2581
2965
  const labels = [
2582
2966
  pdfTextMode ? `PDF ${pdfTextMode}` : "",
@@ -2589,6 +2973,7 @@ var buildProvenanceLabel2 = (metadata) => {
2589
2973
  sourceAwareUnitScope ?? "",
2590
2974
  typeof ocrConfidence === "number" ? `Confidence ${ocrConfidence.toFixed(2)}` : "",
2591
2975
  typeof ocrAverageConfidence === "number" && ocrAverageConfidence !== ocrConfidence ? `Average ${ocrAverageConfidence.toFixed(2)}` : "",
2976
+ typeof ocrMinConfidence === "number" && typeof ocrMaxConfidence === "number" && ocrMinConfidence !== ocrMaxConfidence ? `Range ${ocrMinConfidence.toFixed(2)}-${ocrMaxConfidence.toFixed(2)}` : "",
2592
2977
  typeof ocrRegionCount === "number" ? `${ocrRegionCount} regions` : "",
2593
2978
  spreadsheetHeaders.length > 0 ? `Spreadsheet ${spreadsheetHeaders.join(", ")}` : "",
2594
2979
  spreadsheetColumnRange ? `Spreadsheet ${spreadsheetColumnRange}` : "",
@@ -2684,12 +3069,17 @@ var buildRAGChunkExcerpts = (chunks, activeChunkId) => {
2684
3069
  return;
2685
3070
  }
2686
3071
  const chunkMap = new Map(chunks.map((chunk) => [chunk.chunkId, chunk]));
2687
- const orderedWindowIds = [
3072
+ const orderedSectionIds = navigation.sectionNodes.length > 0 ? navigation.sectionNodes.map((node) => node.chunkId) : [activeChunk.chunkId];
3073
+ const orderedWindowIds = navigation.sectionNodes.length > 0 ? (() => {
3074
+ const activeIndex = navigation.sectionNodes.findIndex((node) => node.chunkId === activeChunk.chunkId);
3075
+ const startIndex = Math.max(0, activeIndex - 2);
3076
+ const endIndex = Math.min(navigation.sectionNodes.length, activeIndex + 3);
3077
+ return navigation.sectionNodes.slice(startIndex, endIndex).map((node) => node.chunkId);
3078
+ })() : [
2688
3079
  navigation.previousNode?.chunkId,
2689
3080
  activeChunk.chunkId,
2690
3081
  navigation.nextNode?.chunkId
2691
3082
  ].filter((chunkId, index, ids) => Boolean(chunkId) && ids.indexOf(chunkId) === index);
2692
- const orderedSectionIds = navigation.sectionNodes.length > 0 ? navigation.sectionNodes.map((node) => node.chunkId) : [activeChunk.chunkId];
2693
3083
  const collectText = (chunkIds) => chunkIds.map((chunkId) => chunkMap.get(chunkId)?.text).filter((text) => typeof text === "string").join(`
2694
3084
 
2695
3085
  `);
@@ -3104,6 +3494,9 @@ var buildRAGSectionRetrievalDiagnostics = (sources, trace) => {
3104
3494
  const parentShare = parentTotal > 0 ? section.totalScore / parentTotal : undefined;
3105
3495
  const topChunk = sources.find((source) => source.chunkId === section.topChunkId);
3106
3496
  const topContextLabel = topChunk?.labels?.contextLabel ?? buildContextLabel2(topChunk?.metadata);
3497
+ const topLocatorLabel = topChunk?.labels?.locatorLabel ?? buildLocatorLabel2(topChunk?.metadata, topChunk?.source, topChunk?.title);
3498
+ const sourceAwareChunkReason = formatSourceAwareChunkReason(topChunk?.metadata?.sourceAwareChunkReason);
3499
+ const sourceAwareUnitScopeLabel = buildSourceAwareUnitScopeLabel(topChunk?.metadata);
3107
3500
  const parentDistribution = parentTotal > 0 ? siblingPool.map((entry) => ({
3108
3501
  count: entry.count,
3109
3502
  isActive: entry.key === section.key,
@@ -3234,8 +3627,8 @@ var buildRAGSectionRetrievalDiagnostics = (sources, trace) => {
3234
3627
  `${(scoreShare * 100).toFixed(0)}% score share`,
3235
3628
  `vector ${section.vectorHits} · lexical ${section.lexicalHits} · hybrid ${section.hybridHits}`,
3236
3629
  typeof parentShare === "number" ? `${(parentShare * 100).toFixed(0)}% of parent section set` : "",
3237
- formatSourceAwareChunkReason(topChunk?.metadata?.sourceAwareChunkReason),
3238
- buildSourceAwareUnitScopeLabel(topChunk?.metadata),
3630
+ sourceAwareChunkReason ? `boundary ${sourceAwareChunkReason}` : "",
3631
+ sourceAwareUnitScopeLabel ? `scope ${sourceAwareUnitScopeLabel}` : "",
3239
3632
  strongestSibling ? `ahead of ${strongestSibling.label} by ${(section.totalScore - strongestSibling.totalScore).toFixed(2)}` : "no sibling competition"
3240
3633
  ].filter(Boolean);
3241
3634
  return {
@@ -3280,6 +3673,10 @@ var buildRAGSectionRetrievalDiagnostics = (sources, trace) => {
3280
3673
  siblingCount: siblings.length,
3281
3674
  siblingScoreGap: strongestSibling ? section.totalScore - strongestSibling.totalScore : undefined,
3282
3675
  sourceCount: section.sourceSet.size,
3676
+ sourceAwareChunkReasonLabel: sourceAwareChunkReason,
3677
+ sourceAwareUnitScopeLabel,
3678
+ topContextLabel,
3679
+ topLocatorLabel,
3283
3680
  sourceBalanceApplied: trace?.steps.some((step) => step.stage === "source_balance"),
3284
3681
  strongestSiblingLabel: strongestSibling?.label,
3285
3682
  strongestSiblingScore: strongestSibling?.totalScore,
@@ -3434,597 +3831,223 @@ var buildSourceGroup = (source, key) => ({
3434
3831
  }),
3435
3832
  structure: source.structure ?? buildRAGChunkStructure(source.metadata),
3436
3833
  source: source.source,
3437
- title: source.title
3438
- });
3439
- var updateSourceGroup = (groups, source) => {
3440
- const key = buildSourceGroupKey(source);
3441
- const existing = groups.get(key);
3442
- if (!existing) {
3443
- groups.set(key, buildSourceGroup(source, key));
3444
- return;
3445
- }
3446
- existing.bestScore = Math.max(existing.bestScore, source.score);
3447
- existing.count += 1;
3448
- existing.chunks.push(source);
3449
- const leadChunk = getPreferredSourceLeadChunk(existing.chunks);
3450
- if (leadChunk) {
3451
- existing.label = buildSourceLabel2(leadChunk);
3452
- existing.labels = leadChunk.labels ?? buildRAGSourceLabels({
3453
- metadata: leadChunk.metadata,
3454
- source: leadChunk.source,
3455
- title: leadChunk.title
3456
- });
3457
- existing.structure = leadChunk.structure ?? buildRAGChunkStructure(leadChunk.metadata);
3458
- existing.source = leadChunk.source;
3459
- existing.title = leadChunk.title;
3460
- }
3461
- };
3462
- var getLatestAssistantMessage = (messages) => {
3463
- for (let index = messages.length - 1;index >= 0; index -= 1) {
3464
- const message = messages[index];
3465
- if (message?.role === "assistant") {
3466
- return message;
3467
- }
3468
- }
3469
- return;
3470
- };
3471
- var getLatestRAGSources = (messages) => getLatestAssistantMessage(messages)?.sources ?? [];
3472
- var getLatestRetrievedMessage = (messages) => {
3473
- for (let index = messages.length - 1;index >= 0; index -= 1) {
3474
- const message = messages[index];
3475
- if (message?.role === "assistant" && (typeof message.retrievedAt === "number" || (message.sources?.length ?? 0) > 0)) {
3476
- return message;
3477
- }
3478
- }
3479
- return;
3480
- };
3481
- var resolveRAGStreamStage = ({
3482
- error,
3483
- isStreaming,
3484
- messages
3485
- }) => {
3486
- if (error) {
3487
- return "error";
3488
- }
3489
- const assistantMessage = getLatestAssistantMessage(messages);
3490
- if (!assistantMessage) {
3491
- return isStreaming ? "submitting" : "idle";
3492
- }
3493
- const isRetrieving = typeof assistantMessage.retrievalStartedAt === "number" && typeof assistantMessage.retrievedAt !== "number";
3494
- if (isRetrieving) {
3495
- return "retrieving";
3496
- }
3497
- if (!isStreaming) {
3498
- return "complete";
3499
- }
3500
- const hasRetrieved = typeof assistantMessage.retrievedAt === "number";
3501
- const hasContent = assistantMessage.content.trim().length > 0 || assistantMessage.thinking?.trim().length || (assistantMessage.toolCalls?.length ?? 0) > 0 || (assistantMessage.images?.length ?? 0) > 0;
3502
- if (hasRetrieved && !hasContent) {
3503
- return "retrieved";
3504
- }
3505
- return "streaming";
3506
- };
3507
- // src/vue/ai/useRAGChunkPreview.ts
3508
- var useRAGChunkPreview = (path) => {
3509
- const client = createRAGClient({ path });
3510
- const preview = ref2(null);
3511
- const activeChunkId = ref2(null);
3512
- const error = ref2(null);
3513
- const isLoading = ref2(false);
3514
- const chunkGraph = computed(() => preview.value ? buildRAGChunkPreviewGraph(preview.value) : null);
3515
- const navigation = computed(() => preview.value ? buildRAGChunkPreviewNavigation(preview.value, activeChunkId.value ?? undefined) : null);
3516
- const previewSources = computed(() => preview.value ? preview.value.chunks.map((chunk, index) => ({
3517
- chunkId: chunk.chunkId,
3518
- labels: chunk.labels,
3519
- metadata: chunk.metadata,
3520
- score: Math.max(0, preview.value.chunks.length - index),
3521
- source: chunk.source ?? preview.value.document.source,
3522
- structure: chunk.structure,
3523
- text: chunk.text,
3524
- title: chunk.title ?? preview.value.document.title
3525
- })) : []);
3526
- const sectionDiagnostics = computed(() => buildRAGSectionRetrievalDiagnostics(previewSources.value));
3527
- const activeSectionDiagnostic = computed(() => {
3528
- const sectionKey = navigation.value?.section?.path?.join(" > ");
3529
- return sectionKey ? sectionDiagnostics.value.find((diagnostic) => diagnostic.key === sectionKey) ?? null : null;
3530
- });
3531
- const inspect = async (id) => {
3532
- isLoading.value = true;
3533
- error.value = null;
3534
- try {
3535
- const response = await client.documentChunks(id);
3536
- if (!response.ok) {
3537
- throw new Error(response.error);
3538
- }
3539
- preview.value = response;
3540
- activeChunkId.value = response.chunks[0]?.chunkId ?? null;
3541
- return response;
3542
- } catch (caught) {
3543
- error.value = caught instanceof Error ? caught.message : String(caught);
3544
- throw caught;
3545
- } finally {
3546
- isLoading.value = false;
3547
- }
3548
- };
3549
- const clear = () => {
3550
- error.value = null;
3551
- isLoading.value = false;
3552
- activeChunkId.value = null;
3553
- preview.value = null;
3554
- };
3555
- const selectChunk = (id) => {
3556
- activeChunkId.value = id;
3557
- };
3558
- const selectParentSection = () => {
3559
- const leadChunkId = navigation.value?.parentSection?.leadChunkId;
3560
- if (leadChunkId) {
3561
- activeChunkId.value = leadChunkId;
3562
- }
3563
- };
3564
- const selectChildSection = (sectionId) => {
3565
- const leadChunkId = navigation.value?.childSections.find((section) => section.id === sectionId)?.leadChunkId;
3566
- if (leadChunkId) {
3567
- activeChunkId.value = leadChunkId;
3568
- }
3569
- };
3570
- const selectSiblingSection = (sectionId) => {
3571
- const leadChunkId = navigation.value?.siblingSections.find((section) => section.id === sectionId)?.leadChunkId;
3572
- if (leadChunkId) {
3573
- activeChunkId.value = leadChunkId;
3574
- }
3575
- };
3576
- return {
3577
- activeChunkId,
3578
- activeSectionDiagnostic,
3579
- clear,
3580
- chunkGraph,
3581
- error,
3582
- inspect,
3583
- isLoading,
3584
- navigation,
3585
- preview,
3586
- sectionDiagnostics,
3587
- selectChildSection,
3588
- selectChunk,
3589
- selectParentSection,
3590
- selectSiblingSection
3591
- };
3592
- };
3593
- // src/vue/ai/useRAG.ts
3594
- import { computed as computed9 } from "vue";
3595
-
3596
- // src/vue/ai/useRAGCitations.ts
3597
- import { computed as computed2 } from "vue";
3598
- var useRAGCitations = (sources) => {
3599
- const citations = computed2(() => buildRAGCitations(sources.value));
3600
- const citationReferenceMap = computed2(() => buildRAGCitationReferenceMap(citations.value));
3601
- const sourceGroups = computed2(() => buildRAGSourceGroups(sources.value));
3602
- const sourceSummaries = computed2(() => buildRAGSourceSummaries(sources.value));
3603
- const hasCitations = computed2(() => citations.value.length > 0);
3604
- return {
3605
- citationReferenceMap,
3606
- citations,
3607
- hasCitations,
3608
- sourceGroups,
3609
- sourceSummaries
3610
- };
3611
- };
3612
-
3613
- // src/vue/ai/useRAGDocuments.ts
3614
- import { ref as ref3 } from "vue";
3615
- var useRAGDocuments = (path) => {
3616
- const client = createRAGClient({ path });
3617
- const documents = ref3([]);
3618
- const error = ref3(null);
3619
- const isLoading = ref3(false);
3620
- const lastResponse = ref3(null);
3621
- const load = async (kind) => {
3622
- isLoading.value = true;
3623
- error.value = null;
3624
- try {
3625
- const response = await client.documents(kind);
3626
- documents.value = response.documents;
3627
- lastResponse.value = response;
3628
- return response;
3629
- } catch (caught) {
3630
- error.value = caught instanceof Error ? caught.message : String(caught);
3631
- throw caught;
3632
- } finally {
3633
- isLoading.value = false;
3634
- }
3635
- };
3636
- const reset = () => {
3637
- documents.value = [];
3638
- error.value = null;
3639
- isLoading.value = false;
3640
- lastResponse.value = null;
3641
- };
3642
- return {
3643
- documents,
3644
- error,
3645
- isLoading,
3646
- lastResponse,
3647
- load,
3648
- reset
3649
- };
3650
- };
3651
-
3652
- // src/vue/ai/useRAGEvaluate.ts
3653
- import { computed as computed3, ref as ref4 } from "vue";
3654
-
3655
- // src/ai/rag/quality.ts
3656
- var {mkdir, readFile, writeFile} = (() => ({}));
3657
-
3658
- // node:path
3659
- function assertPath(path) {
3660
- if (typeof path !== "string")
3661
- throw TypeError("Path must be a string. Received " + JSON.stringify(path));
3662
- }
3663
- function normalizeStringPosix(path, allowAboveRoot) {
3664
- var res = "", lastSegmentLength = 0, lastSlash = -1, dots = 0, code;
3665
- for (var i = 0;i <= path.length; ++i) {
3666
- if (i < path.length)
3667
- code = path.charCodeAt(i);
3668
- else if (code === 47)
3669
- break;
3670
- else
3671
- code = 47;
3672
- if (code === 47) {
3673
- if (lastSlash === i - 1 || dots === 1)
3674
- ;
3675
- else if (lastSlash !== i - 1 && dots === 2) {
3676
- if (res.length < 2 || lastSegmentLength !== 2 || res.charCodeAt(res.length - 1) !== 46 || res.charCodeAt(res.length - 2) !== 46) {
3677
- if (res.length > 2) {
3678
- var lastSlashIndex = res.lastIndexOf("/");
3679
- if (lastSlashIndex !== res.length - 1) {
3680
- if (lastSlashIndex === -1)
3681
- res = "", lastSegmentLength = 0;
3682
- else
3683
- res = res.slice(0, lastSlashIndex), lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
3684
- lastSlash = i, dots = 0;
3685
- continue;
3686
- }
3687
- } else if (res.length === 2 || res.length === 1) {
3688
- res = "", lastSegmentLength = 0, lastSlash = i, dots = 0;
3689
- continue;
3690
- }
3691
- }
3692
- if (allowAboveRoot) {
3693
- if (res.length > 0)
3694
- res += "/..";
3695
- else
3696
- res = "..";
3697
- lastSegmentLength = 2;
3698
- }
3699
- } else {
3700
- if (res.length > 0)
3701
- res += "/" + path.slice(lastSlash + 1, i);
3702
- else
3703
- res = path.slice(lastSlash + 1, i);
3704
- lastSegmentLength = i - lastSlash - 1;
3705
- }
3706
- lastSlash = i, dots = 0;
3707
- } else if (code === 46 && dots !== -1)
3708
- ++dots;
3709
- else
3710
- dots = -1;
3711
- }
3712
- return res;
3713
- }
3714
- function _format(sep, pathObject) {
3715
- var dir = pathObject.dir || pathObject.root, base = pathObject.base || (pathObject.name || "") + (pathObject.ext || "");
3716
- if (!dir)
3717
- return base;
3718
- if (dir === pathObject.root)
3719
- return dir + base;
3720
- return dir + sep + base;
3721
- }
3722
- function resolve() {
3723
- var resolvedPath = "", resolvedAbsolute = false, cwd;
3724
- for (var i = arguments.length - 1;i >= -1 && !resolvedAbsolute; i--) {
3725
- var path;
3726
- if (i >= 0)
3727
- path = arguments[i];
3728
- else {
3729
- if (cwd === undefined)
3730
- cwd = process.cwd();
3731
- path = cwd;
3732
- }
3733
- if (assertPath(path), path.length === 0)
3734
- continue;
3735
- resolvedPath = path + "/" + resolvedPath, resolvedAbsolute = path.charCodeAt(0) === 47;
3736
- }
3737
- if (resolvedPath = normalizeStringPosix(resolvedPath, !resolvedAbsolute), resolvedAbsolute)
3738
- if (resolvedPath.length > 0)
3739
- return "/" + resolvedPath;
3740
- else
3741
- return "/";
3742
- else if (resolvedPath.length > 0)
3743
- return resolvedPath;
3744
- else
3745
- return ".";
3746
- }
3747
- function normalize(path) {
3748
- if (assertPath(path), path.length === 0)
3749
- return ".";
3750
- var isAbsolute = path.charCodeAt(0) === 47, trailingSeparator = path.charCodeAt(path.length - 1) === 47;
3751
- if (path = normalizeStringPosix(path, !isAbsolute), path.length === 0 && !isAbsolute)
3752
- path = ".";
3753
- if (path.length > 0 && trailingSeparator)
3754
- path += "/";
3755
- if (isAbsolute)
3756
- return "/" + path;
3757
- return path;
3758
- }
3759
- function isAbsolute(path) {
3760
- return assertPath(path), path.length > 0 && path.charCodeAt(0) === 47;
3761
- }
3762
- function join() {
3763
- if (arguments.length === 0)
3764
- return ".";
3765
- var joined;
3766
- for (var i = 0;i < arguments.length; ++i) {
3767
- var arg = arguments[i];
3768
- if (assertPath(arg), arg.length > 0)
3769
- if (joined === undefined)
3770
- joined = arg;
3771
- else
3772
- joined += "/" + arg;
3773
- }
3774
- if (joined === undefined)
3775
- return ".";
3776
- return normalize(joined);
3777
- }
3778
- function relative(from, to) {
3779
- if (assertPath(from), assertPath(to), from === to)
3780
- return "";
3781
- if (from = resolve(from), to = resolve(to), from === to)
3782
- return "";
3783
- var fromStart = 1;
3784
- for (;fromStart < from.length; ++fromStart)
3785
- if (from.charCodeAt(fromStart) !== 47)
3786
- break;
3787
- var fromEnd = from.length, fromLen = fromEnd - fromStart, toStart = 1;
3788
- for (;toStart < to.length; ++toStart)
3789
- if (to.charCodeAt(toStart) !== 47)
3790
- break;
3791
- var toEnd = to.length, toLen = toEnd - toStart, length = fromLen < toLen ? fromLen : toLen, lastCommonSep = -1, i = 0;
3792
- for (;i <= length; ++i) {
3793
- if (i === length) {
3794
- if (toLen > length) {
3795
- if (to.charCodeAt(toStart + i) === 47)
3796
- return to.slice(toStart + i + 1);
3797
- else if (i === 0)
3798
- return to.slice(toStart + i);
3799
- } else if (fromLen > length) {
3800
- if (from.charCodeAt(fromStart + i) === 47)
3801
- lastCommonSep = i;
3802
- else if (i === 0)
3803
- lastCommonSep = 0;
3804
- }
3805
- break;
3806
- }
3807
- var fromCode = from.charCodeAt(fromStart + i), toCode = to.charCodeAt(toStart + i);
3808
- if (fromCode !== toCode)
3809
- break;
3810
- else if (fromCode === 47)
3811
- lastCommonSep = i;
3812
- }
3813
- var out = "";
3814
- for (i = fromStart + lastCommonSep + 1;i <= fromEnd; ++i)
3815
- if (i === fromEnd || from.charCodeAt(i) === 47)
3816
- if (out.length === 0)
3817
- out += "..";
3818
- else
3819
- out += "/..";
3820
- if (out.length > 0)
3821
- return out + to.slice(toStart + lastCommonSep);
3822
- else {
3823
- if (toStart += lastCommonSep, to.charCodeAt(toStart) === 47)
3824
- ++toStart;
3825
- return to.slice(toStart);
3826
- }
3827
- }
3828
- function _makeLong(path) {
3829
- return path;
3830
- }
3831
- function dirname(path) {
3832
- if (assertPath(path), path.length === 0)
3833
- return ".";
3834
- var code = path.charCodeAt(0), hasRoot = code === 47, end = -1, matchedSlash = true;
3835
- for (var i = path.length - 1;i >= 1; --i)
3836
- if (code = path.charCodeAt(i), code === 47) {
3837
- if (!matchedSlash) {
3838
- end = i;
3839
- break;
3840
- }
3841
- } else
3842
- matchedSlash = false;
3843
- if (end === -1)
3844
- return hasRoot ? "/" : ".";
3845
- if (hasRoot && end === 1)
3846
- return "//";
3847
- return path.slice(0, end);
3848
- }
3849
- function basename(path, ext) {
3850
- if (ext !== undefined && typeof ext !== "string")
3851
- throw TypeError('"ext" argument must be a string');
3852
- assertPath(path);
3853
- var start = 0, end = -1, matchedSlash = true, i;
3854
- if (ext !== undefined && ext.length > 0 && ext.length <= path.length) {
3855
- if (ext.length === path.length && ext === path)
3856
- return "";
3857
- var extIdx = ext.length - 1, firstNonSlashEnd = -1;
3858
- for (i = path.length - 1;i >= 0; --i) {
3859
- var code = path.charCodeAt(i);
3860
- if (code === 47) {
3861
- if (!matchedSlash) {
3862
- start = i + 1;
3863
- break;
3864
- }
3865
- } else {
3866
- if (firstNonSlashEnd === -1)
3867
- matchedSlash = false, firstNonSlashEnd = i + 1;
3868
- if (extIdx >= 0)
3869
- if (code === ext.charCodeAt(extIdx)) {
3870
- if (--extIdx === -1)
3871
- end = i;
3872
- } else
3873
- extIdx = -1, end = firstNonSlashEnd;
3874
- }
3875
- }
3876
- if (start === end)
3877
- end = firstNonSlashEnd;
3878
- else if (end === -1)
3879
- end = path.length;
3880
- return path.slice(start, end);
3881
- } else {
3882
- for (i = path.length - 1;i >= 0; --i)
3883
- if (path.charCodeAt(i) === 47) {
3884
- if (!matchedSlash) {
3885
- start = i + 1;
3886
- break;
3887
- }
3888
- } else if (end === -1)
3889
- matchedSlash = false, end = i + 1;
3890
- if (end === -1)
3891
- return "";
3892
- return path.slice(start, end);
3893
- }
3894
- }
3895
- function extname(path) {
3896
- assertPath(path);
3897
- var startDot = -1, startPart = 0, end = -1, matchedSlash = true, preDotState = 0;
3898
- for (var i = path.length - 1;i >= 0; --i) {
3899
- var code = path.charCodeAt(i);
3900
- if (code === 47) {
3901
- if (!matchedSlash) {
3902
- startPart = i + 1;
3903
- break;
3904
- }
3905
- continue;
3906
- }
3907
- if (end === -1)
3908
- matchedSlash = false, end = i + 1;
3909
- if (code === 46) {
3910
- if (startDot === -1)
3911
- startDot = i;
3912
- else if (preDotState !== 1)
3913
- preDotState = 1;
3914
- } else if (startDot !== -1)
3915
- preDotState = -1;
3916
- }
3917
- if (startDot === -1 || end === -1 || preDotState === 0 || preDotState === 1 && startDot === end - 1 && startDot === startPart + 1)
3918
- return "";
3919
- return path.slice(startDot, end);
3920
- }
3921
- function format(pathObject) {
3922
- if (pathObject === null || typeof pathObject !== "object")
3923
- throw TypeError('The "pathObject" argument must be of type Object. Received type ' + typeof pathObject);
3924
- return _format("/", pathObject);
3925
- }
3926
- function parse(path) {
3927
- assertPath(path);
3928
- var ret = { root: "", dir: "", base: "", ext: "", name: "" };
3929
- if (path.length === 0)
3930
- return ret;
3931
- var code = path.charCodeAt(0), isAbsolute2 = code === 47, start;
3932
- if (isAbsolute2)
3933
- ret.root = "/", start = 1;
3934
- else
3935
- start = 0;
3936
- var startDot = -1, startPart = 0, end = -1, matchedSlash = true, i = path.length - 1, preDotState = 0;
3937
- for (;i >= start; --i) {
3938
- if (code = path.charCodeAt(i), code === 47) {
3939
- if (!matchedSlash) {
3940
- startPart = i + 1;
3941
- break;
3942
- }
3943
- continue;
3944
- }
3945
- if (end === -1)
3946
- matchedSlash = false, end = i + 1;
3947
- if (code === 46) {
3948
- if (startDot === -1)
3949
- startDot = i;
3950
- else if (preDotState !== 1)
3951
- preDotState = 1;
3952
- } else if (startDot !== -1)
3953
- preDotState = -1;
3954
- }
3955
- if (startDot === -1 || end === -1 || preDotState === 0 || preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
3956
- if (end !== -1)
3957
- if (startPart === 0 && isAbsolute2)
3958
- ret.base = ret.name = path.slice(1, end);
3959
- else
3960
- ret.base = ret.name = path.slice(startPart, end);
3961
- } else {
3962
- if (startPart === 0 && isAbsolute2)
3963
- ret.name = path.slice(1, startDot), ret.base = path.slice(1, end);
3964
- else
3965
- ret.name = path.slice(startPart, startDot), ret.base = path.slice(startPart, end);
3966
- ret.ext = path.slice(startDot, end);
3834
+ title: source.title
3835
+ });
3836
+ var updateSourceGroup = (groups, source) => {
3837
+ const key = buildSourceGroupKey(source);
3838
+ const existing = groups.get(key);
3839
+ if (!existing) {
3840
+ groups.set(key, buildSourceGroup(source, key));
3841
+ return;
3967
3842
  }
3968
- if (startPart > 0)
3969
- ret.dir = path.slice(0, startPart - 1);
3970
- else if (isAbsolute2)
3971
- ret.dir = "/";
3972
- return ret;
3973
- }
3974
- var sep = "/";
3975
- var delimiter = ":";
3976
- var posix = ((p) => (p.posix = p, p))({ resolve, normalize, isAbsolute, join, relative, _makeLong, dirname, basename, extname, format, parse, sep, delimiter, win32: null, posix: null });
3977
-
3978
- // src/ai/rag/quality.ts
3979
- var buildRAGEvaluationLeaderboard = (runs) => {
3980
- const sorted = [...runs].sort((left, right) => {
3981
- if (right.response.passingRate !== left.response.passingRate) {
3982
- return right.response.passingRate - left.response.passingRate;
3843
+ existing.bestScore = Math.max(existing.bestScore, source.score);
3844
+ existing.count += 1;
3845
+ existing.chunks.push(source);
3846
+ const leadChunk = getPreferredSourceLeadChunk(existing.chunks);
3847
+ if (leadChunk) {
3848
+ existing.label = buildSourceLabel2(leadChunk);
3849
+ existing.labels = leadChunk.labels ?? buildRAGSourceLabels({
3850
+ metadata: leadChunk.metadata,
3851
+ source: leadChunk.source,
3852
+ title: leadChunk.title
3853
+ });
3854
+ existing.structure = leadChunk.structure ?? buildRAGChunkStructure(leadChunk.metadata);
3855
+ existing.source = leadChunk.source;
3856
+ existing.title = leadChunk.title;
3857
+ }
3858
+ };
3859
+ var getLatestAssistantMessage = (messages) => {
3860
+ for (let index = messages.length - 1;index >= 0; index -= 1) {
3861
+ const message = messages[index];
3862
+ if (message?.role === "assistant") {
3863
+ return message;
3983
3864
  }
3984
- if (right.response.summary.averageF1 !== left.response.summary.averageF1) {
3985
- return right.response.summary.averageF1 - left.response.summary.averageF1;
3865
+ }
3866
+ return;
3867
+ };
3868
+ var getLatestRAGSources = (messages) => getLatestAssistantMessage(messages)?.sources ?? [];
3869
+ var getLatestRetrievedMessage = (messages) => {
3870
+ for (let index = messages.length - 1;index >= 0; index -= 1) {
3871
+ const message = messages[index];
3872
+ if (message?.role === "assistant" && (typeof message.retrievedAt === "number" || (message.sources?.length ?? 0) > 0)) {
3873
+ return message;
3986
3874
  }
3987
- return left.response.summary.averageLatencyMs - right.response.summary.averageLatencyMs;
3988
- });
3989
- return sorted.map((run, index) => ({
3990
- averageF1: run.response.summary.averageF1,
3991
- averageLatencyMs: run.response.summary.averageLatencyMs,
3992
- label: run.label,
3993
- passingRate: run.response.passingRate,
3994
- rank: index + 1,
3995
- runId: run.id,
3996
- suiteId: run.suiteId,
3997
- totalCases: run.response.totalCases
3998
- }));
3875
+ }
3876
+ return;
3999
3877
  };
4000
- var runRAGEvaluationSuite = async ({
4001
- suite,
4002
- evaluate,
4003
- overrides,
4004
- artifacts
3878
+ var resolveRAGStreamStage = ({
3879
+ error,
3880
+ isStreaming,
3881
+ messages
4005
3882
  }) => {
4006
- const startedAt = Date.now();
4007
- const response = await evaluate({
4008
- ...suite.input,
4009
- ...overrides,
4010
- cases: overrides?.cases ?? suite.input.cases
3883
+ if (error) {
3884
+ return "error";
3885
+ }
3886
+ const assistantMessage = getLatestAssistantMessage(messages);
3887
+ if (!assistantMessage) {
3888
+ return isStreaming ? "submitting" : "idle";
3889
+ }
3890
+ const isRetrieving = typeof assistantMessage.retrievalStartedAt === "number" && typeof assistantMessage.retrievedAt !== "number";
3891
+ if (isRetrieving) {
3892
+ return "retrieving";
3893
+ }
3894
+ if (!isStreaming) {
3895
+ return "complete";
3896
+ }
3897
+ const hasRetrieved = typeof assistantMessage.retrievedAt === "number";
3898
+ const hasContent = assistantMessage.content.trim().length > 0 || assistantMessage.thinking?.trim().length || (assistantMessage.toolCalls?.length ?? 0) > 0 || (assistantMessage.images?.length ?? 0) > 0;
3899
+ if (hasRetrieved && !hasContent) {
3900
+ return "retrieved";
3901
+ }
3902
+ return "streaming";
3903
+ };
3904
+ // src/vue/ai/useRAGChunkPreview.ts
3905
+ var useRAGChunkPreview = (path) => {
3906
+ const client = createRAGClient({ path });
3907
+ const preview = ref2(null);
3908
+ const activeChunkId = ref2(null);
3909
+ const error = ref2(null);
3910
+ const isLoading = ref2(false);
3911
+ const chunkGraph = computed(() => preview.value ? buildRAGChunkPreviewGraph(preview.value) : null);
3912
+ const navigation = computed(() => preview.value ? buildRAGChunkPreviewNavigation(preview.value, activeChunkId.value ?? undefined) : null);
3913
+ const previewSources = computed(() => preview.value ? preview.value.chunks.map((chunk, index) => ({
3914
+ chunkId: chunk.chunkId,
3915
+ labels: chunk.labels,
3916
+ metadata: chunk.metadata,
3917
+ score: Math.max(0, preview.value.chunks.length - index),
3918
+ source: chunk.source ?? preview.value.document.source,
3919
+ structure: chunk.structure,
3920
+ text: chunk.text,
3921
+ title: chunk.title ?? preview.value.document.title
3922
+ })) : []);
3923
+ const sectionDiagnostics = computed(() => buildRAGSectionRetrievalDiagnostics(previewSources.value));
3924
+ const activeSectionDiagnostic = computed(() => {
3925
+ const sectionKey = navigation.value?.section?.path?.join(" > ");
3926
+ return sectionKey ? sectionDiagnostics.value.find((diagnostic) => diagnostic.key === sectionKey) ?? null : null;
4011
3927
  });
4012
- const finishedAt = Date.now();
3928
+ const inspect = async (id) => {
3929
+ isLoading.value = true;
3930
+ error.value = null;
3931
+ try {
3932
+ const response = await client.documentChunks(id);
3933
+ if (!response.ok) {
3934
+ throw new Error(response.error);
3935
+ }
3936
+ preview.value = response;
3937
+ activeChunkId.value = response.chunks[0]?.chunkId ?? null;
3938
+ return response;
3939
+ } catch (caught) {
3940
+ error.value = caught instanceof Error ? caught.message : String(caught);
3941
+ throw caught;
3942
+ } finally {
3943
+ isLoading.value = false;
3944
+ }
3945
+ };
3946
+ const clear = () => {
3947
+ error.value = null;
3948
+ isLoading.value = false;
3949
+ activeChunkId.value = null;
3950
+ preview.value = null;
3951
+ };
3952
+ const selectChunk = (id) => {
3953
+ activeChunkId.value = id;
3954
+ };
3955
+ const selectParentSection = () => {
3956
+ const leadChunkId = navigation.value?.parentSection?.leadChunkId;
3957
+ if (leadChunkId) {
3958
+ activeChunkId.value = leadChunkId;
3959
+ }
3960
+ };
3961
+ const selectChildSection = (sectionId) => {
3962
+ const leadChunkId = navigation.value?.childSections.find((section) => section.id === sectionId)?.leadChunkId;
3963
+ if (leadChunkId) {
3964
+ activeChunkId.value = leadChunkId;
3965
+ }
3966
+ };
3967
+ const selectSiblingSection = (sectionId) => {
3968
+ const leadChunkId = navigation.value?.siblingSections.find((section) => section.id === sectionId)?.leadChunkId;
3969
+ if (leadChunkId) {
3970
+ activeChunkId.value = leadChunkId;
3971
+ }
3972
+ };
4013
3973
  return {
4014
- caseTraceSnapshots: artifacts?.caseTraceSnapshots,
4015
- elapsedMs: finishedAt - startedAt,
4016
- finishedAt,
4017
- id: generateId(),
4018
- label: suite.label ?? suite.id,
4019
- metadata: suite.metadata,
4020
- response,
4021
- startedAt,
4022
- suiteId: suite.id,
4023
- traceSummary: artifacts?.traceSummary
3974
+ activeChunkId,
3975
+ activeSectionDiagnostic,
3976
+ clear,
3977
+ chunkGraph,
3978
+ error,
3979
+ inspect,
3980
+ isLoading,
3981
+ navigation,
3982
+ preview,
3983
+ sectionDiagnostics,
3984
+ selectChildSection,
3985
+ selectChunk,
3986
+ selectParentSection,
3987
+ selectSiblingSection
3988
+ };
3989
+ };
3990
+ // src/vue/ai/useRAG.ts
3991
+ import { computed as computed9 } from "vue";
3992
+
3993
+ // src/vue/ai/useRAGCitations.ts
3994
+ import { computed as computed2 } from "vue";
3995
+ var useRAGCitations = (sources) => {
3996
+ const citations = computed2(() => buildRAGCitations(sources.value));
3997
+ const citationReferenceMap = computed2(() => buildRAGCitationReferenceMap(citations.value));
3998
+ const sourceGroups = computed2(() => buildRAGSourceGroups(sources.value));
3999
+ const sourceSummaries = computed2(() => buildRAGSourceSummaries(sources.value));
4000
+ const hasCitations = computed2(() => citations.value.length > 0);
4001
+ return {
4002
+ citationReferenceMap,
4003
+ citations,
4004
+ hasCitations,
4005
+ sourceGroups,
4006
+ sourceSummaries
4007
+ };
4008
+ };
4009
+
4010
+ // src/vue/ai/useRAGDocuments.ts
4011
+ import { ref as ref3 } from "vue";
4012
+ var useRAGDocuments = (path) => {
4013
+ const client = createRAGClient({ path });
4014
+ const documents = ref3([]);
4015
+ const error = ref3(null);
4016
+ const isLoading = ref3(false);
4017
+ const lastResponse = ref3(null);
4018
+ const load = async (kind) => {
4019
+ isLoading.value = true;
4020
+ error.value = null;
4021
+ try {
4022
+ const response = await client.documents(kind);
4023
+ documents.value = response.documents;
4024
+ lastResponse.value = response;
4025
+ return response;
4026
+ } catch (caught) {
4027
+ error.value = caught instanceof Error ? caught.message : String(caught);
4028
+ throw caught;
4029
+ } finally {
4030
+ isLoading.value = false;
4031
+ }
4032
+ };
4033
+ const reset = () => {
4034
+ documents.value = [];
4035
+ error.value = null;
4036
+ isLoading.value = false;
4037
+ lastResponse.value = null;
4038
+ };
4039
+ return {
4040
+ documents,
4041
+ error,
4042
+ isLoading,
4043
+ lastResponse,
4044
+ load,
4045
+ reset
4024
4046
  };
4025
4047
  };
4026
4048
 
4027
4049
  // src/vue/ai/useRAGEvaluate.ts
4050
+ import { computed as computed3, ref as ref4 } from "vue";
4028
4051
  var useRAGEvaluate = (path) => {
4029
4052
  const client = createRAGClient({ path });
4030
4053
  const error = ref4(null);