{"version":3,"file":"citation.d.ts","sourceRoot":"","sources":["../../../src/core/web-research/citation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,eAAe,EACf,oBAAoB,EACpB,mBAAmB,EACnB,gBAAgB,EAChB,iBAAiB,EACjB,MAAM,YAAY,CAAC;AAEpB;;;;;;;;;;GAUG;AAEH,MAAM,WAAW,mBAAmB;IACnC,WAAW,CAAC,EAAE,mBAAmB,CAAC;IAClC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,gBAAgB,CAAC;IAC9B,eAAe,CAAC,EAAE,eAAe,CAAC;CAClC;AAsBD,wBAAgB,iBAAiB,CAChC,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,IAAI,CACX,iBAAiB,EACjB,YAAY,GAAG,cAAc,GAAG,OAAO,GAAG,aAAa,GAAG,aAAa,GAAG,eAAe,GAAG,kBAAkB,CAC9G,EACD,OAAO,GAAE,mBAAwB,GAC/B,oBAAoB,CAsBtB;AAED,8DAA8D;AAC9D,wBAAgB,aAAa,CAAC,OAAO,EAAE,oBAAoB,GAAG,MAAM,CAanE;AAED,8DAA8D;AAC9D,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,oBAAoB,GAAG,MAAM,GAAG,SAAS,CAcxF","sourcesContent":["import type {\n\tEvidenceLocator,\n\tResearchClaimSupport,\n\tResearchSupportType,\n\tSourceConfidence,\n\tWebEvidenceRecord,\n} from \"./types.js\";\n\n/**\n * Addressable citation builder.\n *\n * Policy:\n * - Exact numeric/mechanical claims require a locator; a claim without\n *   coordinates on its source is rejected (`unverified`) unless it is an\n *   inference.\n * - snippet_only support is visibly labeled and never `high` confidence.\n * - A support object must expose evidenceId, sourceUrl, retrievedAt,\n *   contentSha256 and coordinates to satisfy the traceability contract.\n */\n\nexport interface BuildSupportOptions {\n\tsupportType?: ResearchSupportType;\n\teffectiveAt?: string;\n\tconfidence?: SourceConfidence;\n\tlocatorOverride?: EvidenceLocator;\n}\n\nfunction locatorFor(\n\trecord: Pick<WebEvidenceRecord, \"relevantPassages\">,\n\tlocatorOverride?: EvidenceLocator,\n): EvidenceLocator | undefined {\n\tif (locatorOverride) return locatorOverride;\n\tconst passage = record.relevantPassages[0];\n\tif (passage) {\n\t\tif (passage.page !== undefined) {\n\t\t\treturn { kind: \"page\", page: passage.page, passageId: passage.id };\n\t\t}\n\t\treturn {\n\t\t\tkind: \"lines\",\n\t\t\tstart: passage.startLine,\n\t\t\tend: passage.endLine,\n\t\t\tpassageId: passage.id,\n\t\t};\n\t}\n\treturn undefined;\n}\n\nexport function buildClaimSupport(\n\tclaimId: string,\n\trecord: Pick<\n\t\tWebEvidenceRecord,\n\t\t\"evidenceId\" | \"canonicalUrl\" | \"title\" | \"retrievedAt\" | \"publishedAt\" | \"contentSha256\" | \"relevantPassages\"\n\t>,\n\toptions: BuildSupportOptions = {},\n): ResearchClaimSupport {\n\tconst locator = locatorFor(record, options.locatorOverride);\n\tlet supportType: ResearchSupportType = options.supportType ?? \"direct\";\n\tconst effectiveAt = options.effectiveAt;\n\n\t// Missing coordinates on an exact claim => unverified (or inference).\n\tif (!locator && supportType !== \"inference\" && supportType !== \"snippet_only\") {\n\t\tsupportType = \"unverified\";\n\t}\n\n\treturn {\n\t\tclaimId,\n\t\tevidenceId: record.evidenceId,\n\t\tsupportType,\n\t\tsourceUrl: record.canonicalUrl,\n\t\tsourceTitle: record.title,\n\t\tretrievedAt: record.retrievedAt,\n\t\tpublishedAt: record.publishedAt,\n\t\teffectiveAt,\n\t\tcontentSha256: record.contentSha256,\n\t\tlocator: locator ?? { kind: \"lines\" },\n\t};\n}\n\n/** Renders a support object as human-usable citation text. */\nexport function formatSupport(support: ResearchClaimSupport): string {\n\tconst coords =\n\t\tsupport.locator.kind === \"page\"\n\t\t\t? `page ${support.locator.page}`\n\t\t\t: support.locator.kind === \"json_pointer\"\n\t\t\t\t? `json ${support.locator.jsonPointer}`\n\t\t\t\t: `lines ${support.locator.start ?? \"?\"}-${support.locator.end ?? \"?\"}`;\n\tconst date = support.effectiveAt\n\t\t? `eff ${support.effectiveAt}`\n\t\t: support.publishedAt\n\t\t\t? `pub ${support.publishedAt}`\n\t\t\t: \"\";\n\treturn `[${support.evidenceId}:${coords}${date ? `, ${date}` : \"\"}] ${support.sourceUrl}`;\n}\n\n/** Rejects an exact claim whose support lacks coordinates. */\nexport function exactClaimLocatorError(support: ResearchClaimSupport): string | undefined {\n\tif (support.supportType === \"inference\" || support.supportType === \"snippet_only\") return undefined;\n\tconst locator = support.locator;\n\tif (!locator) return `Claim ${support.claimId} lacks a locator; exact claims require coordinates.`;\n\tif (locator.kind === \"lines\" && (locator.start === undefined || locator.end === undefined)) {\n\t\treturn `Claim ${support.claimId} line locator is missing start/end coordinates.`;\n\t}\n\tif (locator.kind === \"page\" && locator.page === undefined) {\n\t\treturn `Claim ${support.claimId} page locator is missing a page number.`;\n\t}\n\tif (!support.evidenceId || !support.sourceUrl || !support.contentSha256) {\n\t\treturn `Claim ${support.claimId} is missing evidence identity (evidenceId/sourceUrl/contentSha256).`;\n\t}\n\treturn undefined;\n}\n"]}