@absolutejs/rag 0.0.15 → 0.0.17

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.
@@ -11221,10 +11221,460 @@ var summarizeRAGRetrievalComparison = (entries) => ({
11221
11221
  bestByLowestRuntimeCandidateBudgetExhaustedCases: selectComparisonEntryByLowestTraceMetric(entries, "retrievalId", "runtimeCandidateBudgetExhaustedCases"),
11222
11222
  bestByLowestRuntimeUnderfilledTopKCases: selectComparisonEntryByLowestTraceMetric(entries, "retrievalId", "runtimeUnderfilledTopKCases")
11223
11223
  });
11224
+ // src/presentation/htmxCitationFragments.ts
11225
+ var formatScore = (value) => Number.isFinite(value) ? value.toFixed(3) : "0.000";
11226
+ var buildSearchTargetId = (prefix, value) => {
11227
+ const normalized = value.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
11228
+ return `${prefix}-${normalized || "item"}`;
11229
+ };
11230
+ var buildSourceSummarySectionGroups = (summaries) => {
11231
+ const groups = new Map;
11232
+ for (const summary of summaries ?? []) {
11233
+ const label = summary.contextLabel ?? summary.label;
11234
+ const id = buildSearchTargetId("source-summary-section", label);
11235
+ const existing = groups.get(id);
11236
+ if (existing) {
11237
+ existing.summaries.push(summary);
11238
+ existing.summary = `${existing.summaries.length} evidence summar${existing.summaries.length === 1 ? "y" : "ies"}`;
11239
+ continue;
11240
+ }
11241
+ groups.set(id, {
11242
+ id,
11243
+ label,
11244
+ targetId: id,
11245
+ summary: "1 evidence summary",
11246
+ summaries: [summary]
11247
+ });
11248
+ }
11249
+ return [...groups.values()].sort((left, right) => {
11250
+ const leftScore = Math.max(...left.summaries.map((summary) => summary.bestScore));
11251
+ const rightScore = Math.max(...right.summaries.map((summary) => summary.bestScore));
11252
+ return rightScore - leftScore;
11253
+ });
11254
+ };
11255
+ var buildGroundingReferenceGroups = (references) => {
11256
+ const groups = new Map;
11257
+ for (const reference of references ?? []) {
11258
+ const label = reference.contextLabel ?? reference.label ?? reference.source ?? reference.chunkId;
11259
+ const id = buildSearchTargetId("grounding-reference-section", label);
11260
+ const existing = groups.get(id);
11261
+ if (existing) {
11262
+ existing.references.push(reference);
11263
+ existing.summary = `${existing.references.length} grounding reference${existing.references.length === 1 ? "" : "s"}`;
11264
+ continue;
11265
+ }
11266
+ groups.set(id, {
11267
+ id,
11268
+ label,
11269
+ targetId: id,
11270
+ summary: "1 grounding reference",
11271
+ references: [reference]
11272
+ });
11273
+ }
11274
+ return [...groups.values()].sort((left, right) => {
11275
+ const leftScore = Math.max(...left.references.map((reference) => reference.score));
11276
+ const rightScore = Math.max(...right.references.map((reference) => reference.score));
11277
+ return rightScore - leftScore;
11278
+ });
11279
+ };
11280
+ var buildCitationGroups = (citations) => {
11281
+ const groups = new Map;
11282
+ for (const citation of citations ?? []) {
11283
+ const label = citation.contextLabel ?? citation.label ?? citation.source ?? citation.chunkId;
11284
+ const id = buildSearchTargetId("citation-section", label);
11285
+ const existing = groups.get(id);
11286
+ if (existing) {
11287
+ existing.citations.push(citation);
11288
+ existing.summary = `${existing.citations.length} citation${existing.citations.length === 1 ? "" : "s"}`;
11289
+ continue;
11290
+ }
11291
+ groups.set(id, {
11292
+ id,
11293
+ label,
11294
+ targetId: id,
11295
+ summary: "1 citation",
11296
+ citations: [citation]
11297
+ });
11298
+ }
11299
+ return [...groups.values()].sort((left, right) => {
11300
+ const leftScore = Math.max(...left.citations.map((citation) => citation.score));
11301
+ const rightScore = Math.max(...right.citations.map((citation) => citation.score));
11302
+ return rightScore - leftScore;
11303
+ });
11304
+ };
11305
+ var formatCitationLabel = (citation) => [citation.label, citation.contextLabel, citation.locatorLabel].filter(Boolean).join(" \xB7 ");
11306
+ var formatCitationSummary = (citation) => citation.source ?? citation.title ?? citation.chunkId;
11307
+ var formatCitationExcerpt = (citation) => citation.excerpt || citation.text;
11308
+ var formatEvidenceDetailLine = (label, value) => value && value.length > 0 ? `${label}: ${value}` : "";
11309
+ var formatEvidenceContextLine = (contextLabel, locatorLabel) => {
11310
+ const value = [locatorLabel, contextLabel].filter((entry) => Boolean(entry && entry.length > 0)).join(" \xB7 ");
11311
+ return value.length > 0 ? `location: ${value}` : "";
11312
+ };
11313
+ var formatSourceSummaryDetails = (summary) => [
11314
+ `best score: ${formatScore(summary.bestScore)}`,
11315
+ `coverage: ${summary.count} chunk(s) \xB7 citations ${summary.citationNumbers.map((value) => `[${value}]`).join(" ") || "none"}`,
11316
+ formatEvidenceContextLine(summary.contextLabel, summary.locatorLabel),
11317
+ formatEvidenceDetailLine("provenance", summary.provenanceLabel)
11318
+ ].filter((value) => value.length > 0);
11319
+ var formatCitationDetails = (citation) => [
11320
+ formatEvidenceDetailLine("evidence", citation.source ?? citation.title ?? citation.chunkId),
11321
+ formatEvidenceContextLine(citation.contextLabel, citation.locatorLabel),
11322
+ formatEvidenceDetailLine("provenance", citation.provenanceLabel),
11323
+ `score: ${formatScore(citation.score)}`
11324
+ ].filter((value) => value.length > 0);
11325
+ var formatSectionDiagnosticPercent = (value) => typeof value === "number" ? `${Math.round(value * 100)}%` : null;
11326
+ var formatSectionDiagnosticReason = (reason) => reason.replaceAll("_", " ");
11327
+ var formatSectionDiagnosticStage = (stage) => stage.replaceAll("_", " ");
11328
+ var formatSectionDiagnosticWeightReason = (reason) => ({
11329
+ final_stage_concentration: "final stage concentrated on this section",
11330
+ final_stage_dominant_within_parent: "final stage stayed ahead inside its parent",
11331
+ rerank_preserved_lead: "rerank kept this section in front",
11332
+ stage_runner_up_pressure: "runner-up stayed close in this stage",
11333
+ stage_expanded: "this section expanded in this stage",
11334
+ stage_held: "this section held steady in this stage",
11335
+ stage_narrowed: "this section narrowed in this stage"
11336
+ })[reason] ?? reason.replaceAll("_", " ");
11337
+ var formatSectionQueryAttributionReason = (reason) => ({
11338
+ base_query_only: "came only from the base query",
11339
+ transformed_query_only: "came only from the transformed query",
11340
+ variant_only: "came only from query variants",
11341
+ transform_introduced: "the transformed query introduced this section",
11342
+ variant_supported: "query variants reinforced this section",
11343
+ mixed_query_sources: "multiple query forms contributed"
11344
+ })[reason] ?? reason.replaceAll("_", " ");
11345
+ var formatSectionDiagnosticChannels = (diagnostic) => `Channels \xB7 hybrid ${diagnostic.hybridHits} \xB7 vector ${diagnostic.vectorHits} \xB7 lexical ${diagnostic.lexicalHits}`;
11346
+ var formatSectionDiagnosticAttributionFocus = (diagnostic) => {
11347
+ const mode = diagnostic.queryAttribution?.mode ?? "mixed";
11348
+ const label = mode === "primary" ? "Attribution \xB7 base-query-only" : mode === "transformed" ? "Attribution \xB7 transformed-only" : mode === "variant" ? "Attribution \xB7 variant-only" : "Attribution \xB7 mixed";
11349
+ const parts = [label];
11350
+ if ((diagnostic.queryAttribution?.primaryHits ?? 0) > 0)
11351
+ parts.push(`base ${diagnostic.queryAttribution?.primaryHits}`);
11352
+ if ((diagnostic.queryAttribution?.transformedHits ?? 0) > 0)
11353
+ parts.push(`transformed ${diagnostic.queryAttribution?.transformedHits}`);
11354
+ if ((diagnostic.queryAttribution?.variantHits ?? 0) > 0)
11355
+ parts.push(`variant ${diagnostic.queryAttribution?.variantHits}`);
11356
+ return parts.join(" \xB7 ");
11357
+ };
11358
+ var formatSectionDiagnosticPipeline = (diagnostic) => {
11359
+ const requestedMode = diagnostic.requestedMode ?? diagnostic.retrievalMode ?? "n/a";
11360
+ const selectedMode = diagnostic.retrievalMode ?? "n/a";
11361
+ const routeLabel = diagnostic.routingLabel ?? "default route";
11362
+ const transformLabel = diagnostic.queryTransformLabel ?? "no transform";
11363
+ return `Mode ${selectedMode} \xB7 requested ${requestedMode} \xB7 route ${routeLabel} \xB7 transform ${transformLabel} \xB7 rerank ${diagnostic.rerankApplied ? "on" : "off"} \xB7 source balance ${diagnostic.sourceBalanceApplied ? "on" : "off"} \xB7 threshold ${diagnostic.scoreThresholdApplied ? "on" : "off"} \xB7 query ${diagnostic.queryAttribution?.mode ?? "n/a"}`;
11364
+ };
11365
+ var formatSectionDiagnosticStageFlow = (diagnostic) => diagnostic.stageCounts.length > 0 ? `Stage flow \xB7 ${diagnostic.stageCounts.map((entry) => `${formatSectionDiagnosticStage(entry.stage)} ${entry.count}`).join(" \u2192 ")}` : null;
11366
+ var formatSectionDiagnosticStageBounds = (diagnostic) => {
11367
+ const parts = [];
11368
+ if (diagnostic.firstSeenStage)
11369
+ parts.push(`first seen ${formatSectionDiagnosticStage(diagnostic.firstSeenStage)}`);
11370
+ if (diagnostic.lastSeenStage)
11371
+ parts.push(`last seen ${formatSectionDiagnosticStage(diagnostic.lastSeenStage)}`);
11372
+ if (diagnostic.peakStage)
11373
+ parts.push(`peak ${formatSectionDiagnosticStage(diagnostic.peakStage)} ${diagnostic.peakCount}`);
11374
+ const finalRetention = formatSectionDiagnosticPercent(diagnostic.finalRetentionRate);
11375
+ if (finalRetention)
11376
+ parts.push(`final retention ${finalRetention}`);
11377
+ if (typeof diagnostic.dropFromPeak === "number")
11378
+ parts.push(`drop from peak ${diagnostic.dropFromPeak}`);
11379
+ return parts.length > 0 ? parts.join(" \xB7 ") : null;
11380
+ };
11381
+ var formatSectionDiagnosticStageWeightRows = (diagnostic) => (diagnostic.stageWeights ?? []).filter((entry) => entry.reasons.length > 0 || entry.stage === "rerank" || entry.stage === "finalize").map((entry) => {
11382
+ const parts = [
11383
+ `${formatSectionDiagnosticStage(entry.stage)} ${(entry.stageShare * 100).toFixed(0)}% of stage`,
11384
+ typeof entry.stageScoreShare === "number" ? `${(entry.stageScoreShare * 100).toFixed(0)}% of stage score` : null,
11385
+ typeof entry.retentionRate === "number" && entry.previousStage && entry.retentionRate !== 1 ? `${(entry.retentionRate * 100).toFixed(0)}% retained from ${formatSectionDiagnosticStage(entry.previousStage)}` : null,
11386
+ typeof entry.countDelta === "number" && entry.countDelta !== 0 ? `delta ${entry.countDelta >= 0 ? "+" : ""}${entry.countDelta}` : null,
11387
+ typeof entry.parentStageShare === "number" && entry.strongestSiblingLabel ? `${(entry.parentStageShare * 100).toFixed(0)}% of parent stage` : null,
11388
+ typeof entry.parentStageScoreShare === "number" && entry.strongestSiblingLabel ? `${(entry.parentStageScoreShare * 100).toFixed(0)}% of parent stage score` : null,
11389
+ typeof entry.stageShareGap === "number" ? `gap ${(entry.stageShareGap * 100).toFixed(0)}%` : null,
11390
+ typeof entry.stageScoreShareGap === "number" ? `score gap ${(entry.stageScoreShareGap * 100).toFixed(0)}%` : null,
11391
+ entry.strongestSiblingLabel ? `runner-up ${entry.strongestSiblingLabel}` : null
11392
+ ].filter((value) => Boolean(value));
11393
+ return parts.join(" \xB7 ");
11394
+ });
11395
+ var formatSectionDiagnosticStageWeightReasons = (diagnostic) => (diagnostic.stageWeights ?? []).flatMap((entry) => entry.reasons.map((reason) => `${formatSectionDiagnosticStage(entry.stage)} \xB7 ${formatSectionDiagnosticWeightReason(reason)}`));
11396
+ var formatSectionDiagnosticQueryAttributionReasons = (diagnostic) => (diagnostic.queryAttribution?.reasons ?? []).map((reason) => formatSectionQueryAttributionReason(reason));
11397
+ var formatSectionDiagnosticCompetition = (diagnostic) => {
11398
+ const parts = [];
11399
+ const parentShare = formatSectionDiagnosticPercent(diagnostic.parentShare);
11400
+ const parentShareGap = formatSectionDiagnosticPercent(diagnostic.parentShareGap);
11401
+ if (!diagnostic.strongestSiblingLabel)
11402
+ return "";
11403
+ if (parentShare)
11404
+ parts.push(`parent share ${parentShare}`);
11405
+ if (parentShareGap)
11406
+ parts.push(`gap ${parentShareGap}`);
11407
+ parts.push(`runner-up ${diagnostic.strongestSiblingLabel}`);
11408
+ return parts.join(" \xB7 ");
11409
+ };
11410
+ var formatSectionDiagnosticTopEntry = (diagnostic) => {
11411
+ const parts = [];
11412
+ if (diagnostic.topSource)
11413
+ parts.push(`top source ${diagnostic.topSource}`);
11414
+ if (diagnostic.topChunkId)
11415
+ parts.push(`lead chunk ${diagnostic.topChunkId}`);
11416
+ parts.push(`${diagnostic.sourceCount} source${diagnostic.sourceCount === 1 ? "" : "s"}`);
11417
+ parts.push(`primary ${diagnostic.queryAttribution?.primaryHits ?? 0} \xB7 transformed ${diagnostic.queryAttribution?.transformedHits ?? 0} \xB7 variant ${diagnostic.queryAttribution?.variantHits ?? 0}`);
11418
+ return parts.join(" \xB7 ");
11419
+ };
11420
+ var formatSectionDiagnosticReasons = (diagnostic) => [
11421
+ ...diagnostic.reasons.map((reason) => formatSectionDiagnosticReason(reason)),
11422
+ ...formatSectionDiagnosticQueryAttributionReasons(diagnostic),
11423
+ ...diagnostic.routingReason ? [`routing \xB7 ${diagnostic.routingReason}`] : [],
11424
+ ...diagnostic.queryTransformReason ? [`transform \xB7 ${diagnostic.queryTransformReason}`] : []
11425
+ ];
11426
+ var formatSectionDiagnosticDistributionRows = (diagnostic) => diagnostic.parentDistribution.map((entry) => `${entry.isActive ? "Active" : "Peer"} \xB7 ${entry.label} \xB7 ${entry.count} hit${entry.count === 1 ? "" : "s"} \xB7 ${formatSectionDiagnosticPercent(entry.parentShare) ?? "0%"}`);
11427
+
11428
+ // src/presentation/htmxRenderers.ts
11429
+ var STREAM_STAGES = [
11430
+ "submitting",
11431
+ "retrieving",
11432
+ "retrieved",
11433
+ "streaming",
11434
+ "complete"
11435
+ ];
11436
+ var escapeHtml = (text) => text.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;");
11437
+ var formatTime = (timestamp) => {
11438
+ if (!timestamp) {
11439
+ return "n/a";
11440
+ }
11441
+ return new Date(timestamp).toLocaleTimeString([], {
11442
+ hour: "numeric",
11443
+ minute: "2-digit",
11444
+ second: "2-digit"
11445
+ });
11446
+ };
11447
+ var formatDuration = (durationMs) => typeof durationMs !== "number" || durationMs < 0 ? "n/a" : `${durationMs}ms`;
11448
+ var makeTracePanel = (prefix) => ({
11449
+ title,
11450
+ summary,
11451
+ trace
11452
+ }) => {
11453
+ if (!trace) {
11454
+ return "";
11455
+ }
11456
+ const presentation = buildRAGRetrievalTracePresentation(trace);
11457
+ return [
11458
+ `<div class="${prefix}-results">`,
11459
+ `<h4>${escapeHtml(title)}</h4>`,
11460
+ `<p class="${prefix}-metadata">${escapeHtml(summary)}</p>`,
11461
+ `<div class="${prefix}-stat-grid">`,
11462
+ presentation.stats.map((row) => `<article class="${prefix}-stat-card"><p class="${prefix}-section-caption">${escapeHtml(row.label)}</p><strong>${escapeHtml(row.value)}</strong></article>`).join(""),
11463
+ "</div>",
11464
+ "<div>",
11465
+ presentation.details.map((row) => `<p class="${prefix}-key-value-row"><strong>${escapeHtml(row.label)}</strong><span>${escapeHtml(row.value)}</span></p>`).join(""),
11466
+ "</div>",
11467
+ `<div class="${prefix}-result-grid">`,
11468
+ presentation.steps.map((step, index) => `<details class="${prefix}-collapsible ${prefix}-result-item" ${index === 0 ? "open" : ""}><summary><strong>${index + 1}. ${escapeHtml(step.label)}</strong></summary>${step.rows.map((row) => `<p class="${prefix}-key-value-row"><strong>${escapeHtml(row.label)}</strong><span>${escapeHtml(row.value)}</span></p>`).join("")}</details>`).join(""),
11469
+ "</div>",
11470
+ "</div>"
11471
+ ].join("");
11472
+ };
11473
+ var makeStageRow = (prefix) => (currentStage) => `<div class="${prefix}-stage-row">${STREAM_STAGES.map((stage) => {
11474
+ const classNames = [`${prefix}-stage-pill`];
11475
+ if (stage === "complete") {
11476
+ classNames.push("complete");
11477
+ }
11478
+ if (stage === currentStage) {
11479
+ classNames.push("current");
11480
+ }
11481
+ return `<span class="${classNames.join(" ")}">${escapeHtml(stage)}</span>`;
11482
+ }).join("")}</div>`;
11483
+ var makeCapabilities = (prefix) => (capabilities) => {
11484
+ if (!capabilities) {
11485
+ return `<p class="${prefix}-metadata">Backend capabilities unavailable.</p>`;
11486
+ }
11487
+ const values = [
11488
+ capabilities.backend,
11489
+ capabilities.persistence,
11490
+ capabilities.nativeVectorSearch ? "native vector search" : "managed fallback search",
11491
+ capabilities.serverSideFiltering ? "server-side filters" : "client-side filters",
11492
+ capabilities.streamingIngestStatus ? "streaming ingest status" : "polled ingest status"
11493
+ ];
11494
+ return `<p class="${prefix}-metadata">Backend capabilities: <strong>${escapeHtml(values.join(" \xB7 "))}</strong></p>`;
11495
+ };
11496
+ var defaultNativeSource = (status) => {
11497
+ const native = status?.native;
11498
+ if (!native || !native.active) {
11499
+ return "Not applicable";
11500
+ }
11501
+ if (status?.backend === "sqlite") {
11502
+ return "Packaged sqlite-vec";
11503
+ }
11504
+ if (status?.backend === "postgres") {
11505
+ return "PostgreSQL pgvector extension";
11506
+ }
11507
+ return "Managed by AbsoluteJS";
11508
+ };
11509
+ var defaultStatusSummary = (status) => {
11510
+ if (!status) {
11511
+ return "No backend status is available.";
11512
+ }
11513
+ if (status.native?.active) {
11514
+ return "Native vector acceleration is active.";
11515
+ }
11516
+ if (status.vectorMode === "json_fallback") {
11517
+ return "Owned JSON fallback retrieval is active.";
11518
+ }
11519
+ return `Vector mode ${status.vectorMode} is active.`;
11520
+ };
11521
+ var defaultStatusMessage = (status) => {
11522
+ if (!status) {
11523
+ return "Backend status unavailable.";
11524
+ }
11525
+ return status.native?.fallbackReason ?? defaultStatusSummary(status);
11526
+ };
11527
+ var makeDetailList = (prefix) => (lines, fallback) => {
11528
+ const values = lines.length > 0 ? lines : [fallback];
11529
+ return `<ul class="${prefix}-detail-list">${values.map((line) => `<li>${escapeHtml(line)}</li>`).join("")}</ul>`;
11530
+ };
11531
+ var makeAdminJobCards = (prefix) => (jobs) => {
11532
+ const records = (jobs ?? []).slice(0, 3);
11533
+ if (records.length === 0) {
11534
+ return `<p class="${prefix}-metadata">No admin jobs recorded yet.</p>`;
11535
+ }
11536
+ return `<div class="${prefix}-stat-grid">${records.map((job) => {
11537
+ const target = job.target ?? "global";
11538
+ const timing = typeof job.startedAt === "number" ? formatTime(job.startedAt) : "n/a";
11539
+ return `<article class="${prefix}-stat-card">
11540
+ <span class="${prefix}-stat-label">${escapeHtml(job.action)}</span>
11541
+ <strong>${escapeHtml(job.status.toUpperCase())}</strong>
11542
+ <p>${escapeHtml(target)}</p>
11543
+ <div class="${prefix}-key-value-list">
11544
+ <div class="${prefix}-key-value-row"><span>Started</span><strong>${escapeHtml(timing)}</strong></div>
11545
+ ${typeof job.elapsedMs === "number" ? `<div class="${prefix}-key-value-row"><span>Elapsed</span><strong>${escapeHtml(formatDuration(job.elapsedMs))}</strong></div>` : ""}
11546
+ </div>
11547
+ </article>`;
11548
+ }).join("")}</div>`;
11549
+ };
11550
+ var makeAdminActionCards = (prefix) => (actions) => {
11551
+ const records = (actions ?? []).slice(0, 3);
11552
+ if (records.length === 0) {
11553
+ return `<p class="${prefix}-metadata">No admin actions recorded yet.</p>`;
11554
+ }
11555
+ return `<div class="${prefix}-stat-grid">${records.map((action) => {
11556
+ const target = action.documentId ?? action.target ?? "global";
11557
+ const timing = typeof action.elapsedMs === "number" ? formatDuration(action.elapsedMs) : typeof action.startedAt === "number" ? formatTime(action.startedAt) : "n/a";
11558
+ return `<article class="${prefix}-stat-card">
11559
+ <span class="${prefix}-stat-label">${escapeHtml(action.action)}</span>
11560
+ <strong>${escapeHtml(action.status.toUpperCase())}</strong>
11561
+ <p>${escapeHtml(target)}</p>
11562
+ <div class="${prefix}-key-value-list">
11563
+ <div class="${prefix}-key-value-row"><span>When</span><strong>${escapeHtml(timing)}</strong></div>
11564
+ </div>
11565
+ </article>`;
11566
+ }).join("")}</div>`;
11567
+ };
11568
+ var makeCitations = (prefix) => (sources) => {
11569
+ const citations = buildRAGCitations(sources);
11570
+ if (citations.length === 0) {
11571
+ return "";
11572
+ }
11573
+ return [
11574
+ `<div class="${prefix}-results">`,
11575
+ "<h4>Citation Trail</h4>",
11576
+ `<p class="${prefix}-metadata">Each citation maps a concrete retrieved chunk to a stable reference number you can carry into the answer UI.</p>`,
11577
+ `<div class="${prefix}-result-grid">`,
11578
+ buildCitationGroups(citations).map((group) => `
11579
+ <article class="${prefix}-result-item" id="${escapeHtml(group.targetId)}">
11580
+ <h3>${escapeHtml(group.label)}</h3>
11581
+ <p class="${prefix}-result-source">${escapeHtml(group.summary)}</p>
11582
+ <div class="${prefix}-result-grid">
11583
+ ${group.citations.map((citation, index) => `
11584
+ <article class="${prefix}-result-item ${prefix}-citation-card">
11585
+ <p class="${prefix}-citation-badge">[${index + 1}] ${escapeHtml(formatCitationLabel(citation))}</p>
11586
+ <p class="${prefix}-result-score">${escapeHtml(formatCitationSummary(citation))}</p>
11587
+ ${formatCitationDetails(citation).map((line) => `<p class="${prefix}-metadata">${escapeHtml(line)}</p>`).join("")}
11588
+ <p class="${prefix}-result-text">${escapeHtml(formatCitationExcerpt(citation))}</p>
11589
+ </article>`).join("")}
11590
+ </div>
11591
+ </article>`).join(""),
11592
+ "</div>",
11593
+ "</div>"
11594
+ ].join("");
11595
+ };
11596
+ var makeSourceSummaries = (prefix) => (sources) => {
11597
+ const summaries = buildRAGSourceSummaries(sources);
11598
+ if (summaries.length === 0) {
11599
+ return `<p class="${prefix}-metadata">Retrieved source groups: 0</p>`;
11600
+ }
11601
+ const groups = buildSourceSummarySectionGroups(summaries);
11602
+ return [
11603
+ `<p class="${prefix}-metadata">Retrieved source groups: ${summaries.length}</p>`,
11604
+ `<div class="${prefix}-result-grid">`,
11605
+ groups.map((group) => `
11606
+ <article class="${prefix}-result-item" id="${escapeHtml(group.targetId)}">
11607
+ <h3>${escapeHtml(group.label)}</h3>
11608
+ <p class="${prefix}-result-source">${escapeHtml(group.summary)}</p>
11609
+ <div class="${prefix}-result-grid">
11610
+ ${group.summaries.map((summary) => `
11611
+ <article class="${prefix}-result-item">
11612
+ <h4>${escapeHtml(summary.label)}</h4>
11613
+ ${formatSourceSummaryDetails(summary).map((line) => `<p class="${prefix}-metadata">${escapeHtml(line)}</p>`).join("")}
11614
+ <p class="${prefix}-result-text">${escapeHtml(summary.excerpt)}</p>
11615
+ </article>`).join("")}
11616
+ </div>
11617
+ </article>`).join(""),
11618
+ "</div>"
11619
+ ].join("");
11620
+ };
11621
+ var makeSectionDiagnosticCard = (prefix) => (diagnostic) => [
11622
+ `<article class="${prefix}-result-item">`,
11623
+ `<h4>${escapeHtml(diagnostic.label)}</h4>`,
11624
+ `<p class="${prefix}-result-source">${escapeHtml(diagnostic.summary)}</p>`,
11625
+ `<p class="${prefix}-metadata">${escapeHtml(formatSectionDiagnosticChannels(diagnostic))}</p>`,
11626
+ `<p class="${prefix}-metadata">${escapeHtml(formatSectionDiagnosticAttributionFocus(diagnostic))}</p>`,
11627
+ `<p class="${prefix}-metadata">${escapeHtml(formatSectionDiagnosticPipeline(diagnostic))}</p>`,
11628
+ `${formatSectionDiagnosticStageFlow(diagnostic) ? `<p class="${prefix}-metadata">${escapeHtml(formatSectionDiagnosticStageFlow(diagnostic) ?? "")}</p>` : ""}`,
11629
+ `${formatSectionDiagnosticStageBounds(diagnostic) ? `<p class="${prefix}-metadata">${escapeHtml(formatSectionDiagnosticStageBounds(diagnostic) ?? "")}</p>` : ""}`,
11630
+ `${formatSectionDiagnosticStageWeightRows(diagnostic).map((line) => `<p class="${prefix}-metadata">${escapeHtml(line)}</p>`).join("")}`,
11631
+ `<p class="${prefix}-metadata">${escapeHtml(formatSectionDiagnosticTopEntry(diagnostic))}</p>`,
11632
+ `${formatSectionDiagnosticCompetition(diagnostic) ? `<p class="${prefix}-metadata">${escapeHtml(formatSectionDiagnosticCompetition(diagnostic) ?? "")}</p>` : ""}`,
11633
+ `${[...formatSectionDiagnosticReasons(diagnostic), ...formatSectionDiagnosticStageWeightReasons(diagnostic)].length > 0 ? `<div class="${prefix}-badge-row">${[...formatSectionDiagnosticReasons(diagnostic), ...formatSectionDiagnosticStageWeightReasons(diagnostic)].map((reason) => `<span class="${prefix}-state-chip">${escapeHtml(reason)}</span>`).join("")}</div>` : ""}`,
11634
+ `${formatSectionDiagnosticDistributionRows(diagnostic).map((line) => `<p class="${prefix}-metadata">${escapeHtml(line)}</p>`).join("")}`,
11635
+ `</article>`
11636
+ ].join("");
11637
+ var resolveRAGHTMXRenderers = (custom = {}) => {
11638
+ const classPrefix = custom.classPrefix ?? "rag";
11639
+ return {
11640
+ adminActionCards: custom.adminActionCards ?? makeAdminActionCards(classPrefix),
11641
+ adminJobCards: custom.adminJobCards ?? makeAdminJobCards(classPrefix),
11642
+ capabilities: custom.capabilities ?? makeCapabilities(classPrefix),
11643
+ citations: custom.citations ?? makeCitations(classPrefix),
11644
+ classPrefix,
11645
+ detailList: custom.detailList ?? makeDetailList(classPrefix),
11646
+ nativeSource: custom.nativeSource ?? defaultNativeSource,
11647
+ sectionDiagnosticCard: custom.sectionDiagnosticCard ?? makeSectionDiagnosticCard(classPrefix),
11648
+ sourceSummaries: custom.sourceSummaries ?? makeSourceSummaries(classPrefix),
11649
+ stageRow: custom.stageRow ?? makeStageRow(classPrefix),
11650
+ statusMessage: custom.statusMessage ?? defaultStatusMessage,
11651
+ statusSummary: custom.statusSummary ?? defaultStatusSummary,
11652
+ tracePanel: custom.tracePanel ?? makeTracePanel(classPrefix)
11653
+ };
11654
+ };
11224
11655
  export {
11225
11656
  resolveRAGStreamStage,
11657
+ resolveRAGHTMXRenderers,
11226
11658
  getLatestRAGSources,
11227
11659
  getLatestAssistantMessage,
11660
+ formatSourceSummaryDetails,
11661
+ formatSectionDiagnosticTopEntry,
11662
+ formatSectionDiagnosticStageWeightRows,
11663
+ formatSectionDiagnosticStageWeightReasons,
11664
+ formatSectionDiagnosticStageFlow,
11665
+ formatSectionDiagnosticStageBounds,
11666
+ formatSectionDiagnosticReasons,
11667
+ formatSectionDiagnosticPipeline,
11668
+ formatSectionDiagnosticDistributionRows,
11669
+ formatSectionDiagnosticCompetition,
11670
+ formatSectionDiagnosticChannels,
11671
+ formatSectionDiagnosticAttributionFocus,
11672
+ formatCitationSummary,
11673
+ formatCitationLabel,
11674
+ formatCitationExcerpt,
11675
+ formatCitationDetails,
11676
+ buildSourceSummarySectionGroups,
11677
+ buildSearchTargetId,
11228
11678
  buildRAGSyncSourcePresentations,
11229
11679
  buildRAGSyncSourcePresentation,
11230
11680
  buildRAGSyncOverviewPresentation,
@@ -11275,8 +11725,10 @@ export {
11275
11725
  buildRAGAdminJobPresentations,
11276
11726
  buildRAGAdminJobPresentation,
11277
11727
  buildRAGAdminActionPresentations,
11278
- buildRAGAdminActionPresentation
11728
+ buildRAGAdminActionPresentation,
11729
+ buildGroundingReferenceGroups,
11730
+ buildCitationGroups
11279
11731
  };
11280
11732
 
11281
- //# debugId=0B42478F5A2EE0B364756E2164756E21
11733
+ //# debugId=FCAE71C0401EF18B64756E2164756E21
11282
11734
  //# sourceMappingURL=ui.js.map