@deepcitation/deepcitation-js 1.1.40 → 1.1.42

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.
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  # @deepcitation/deepcitation-js
4
4
 
5
- **Deterministic AI citation verification. Eliminate hallucination risk by proving every AI citation against source documents.**
5
+ **Deterministic AI citation verification. Eliminate hallucination risk by proving every AI citation against attachments.**
6
6
 
7
7
  [![npm version](https://img.shields.io/npm/v/@deepcitation/deepcitation-js.svg)](https://www.npmjs.com/package/@deepcitation/deepcitation-js)
8
8
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
@@ -16,7 +16,7 @@
16
16
 
17
17
  ## Why DeepCitation?
18
18
 
19
- LLMs hallucinate. Even when given source documents, they make up quotes, invent statistics, and cite pages that don't exist. DeepCitation solves this by **deterministically verifying every citation** against your source documents—and generating visual proof.
19
+ LLMs hallucinate. Even when given attachments, they make up quotes, invent statistics, and cite pages that don't exist. DeepCitation solves this by **deterministically verifying every citation** against your attachments—and generating visual proof.
20
20
 
21
21
  <div align="center">
22
22
  <img src="./examples/assets/deepcitation-medical-demo.gif" alt="DeepCitation medical documentation demo showing verified inline citations" width="700" />
@@ -58,7 +58,7 @@ DeepCitation works in three steps: **Pre-Prompt**, **Post-Prompt**, and **Displa
58
58
 
59
59
  ### Step 1: Pre-Prompt
60
60
 
61
- Upload source documents and enhance your prompt with citation instructions.
61
+ Upload attachments and enhance your prompt with citation instructions.
62
62
 
63
63
  ```typescript
64
64
  import { DeepCitation, wrapCitationPrompt } from "@deepcitation/deepcitation-js";
@@ -88,7 +88,7 @@ const response = await llm.chat({
88
88
 
89
89
  ### Step 2: Post-Prompt
90
90
 
91
- Verify citations against the source documents.
91
+ Verify citations against the attachments.
92
92
 
93
93
  ```typescript
94
94
  const result = await deepcitation.verify({
@@ -2,7 +2,7 @@ var _=`
2
2
  <citation-instructions priority="critical">
3
3
  ## REQUIRED: Citation Format
4
4
 
5
- For every claim, value, or fact; you MUST cite sources using this exact syntax:
5
+ For every claim, value, or fact; you MUST cite the attachment using this exact syntax:
6
6
 
7
7
  <cite attachment_id='ID' reasoning='why this supports the claim' full_phrase='verbatim quote' key_span='1-3 key words' start_page_key='page_number_N_index_I' line_ids='X-Y' />
8
8
 
@@ -35,7 +35,7 @@ The total amount is $500 USD <cite attachment_id='abc123' reasoning='directly st
35
35
  <citation-instructions priority="critical">
36
36
  ## REQUIRED: Audio/Video Citation Format
37
37
 
38
- For every claim, value, or fact; you MUST cite sources using this exact syntax:
38
+ For every claim, value, or fact; you MUST cite the attachment using this exact syntax:
39
39
 
40
40
  <cite attachment_id='ID' reasoning='why this supports the claim' full_phrase='verbatim transcript quote' key_span='1-3 key words' timestamps='HH:MM:SS.SSS-HH:MM:SS.SSS' />
41
41
 
@@ -55,7 +55,7 @@ For every claim, value, or fact; you MUST cite sources using this exact syntax:
55
55
  - The <cite /> tag is self-closing - never use <cite>...</cite>
56
56
 
57
57
  </citation-instructions>
58
- `,d="<citation-reminder>Remember: You MUST use <cite /> tags with all required attributes for every claim, value, or fact from source documents.</citation-reminder>",T="<citation-reminder>Remember: You MUST use <cite /> tags with timestamps for every claim, value, or fact from source media.</citation-reminder>";function x(t){let{systemPrompt:n,isAudioVideo:i=false}=t,e=i?y:_,r=i?T:d;return `${e.trim()}
58
+ `,d="<citation-reminder>Remember: You MUST use <cite /> tags with all required attributes for every claim, value, or fact from attachments.</citation-reminder>",T="<citation-reminder>Remember: You MUST use <cite /> tags with timestamps for every claim, value, or fact from source media.</citation-reminder>";function x(t){let{systemPrompt:n,isAudioVideo:i=false}=t,e=i?y:_,r=i?T:d;return `${e.trim()}
59
59
 
60
60
  ${n.trim()}
61
61
 
@@ -0,0 +1 @@
1
+ 'use strict';function Z(t){return new TextEncoder().encode(t)}function E(t){let e=1732584193,i=4023233417,r=2562383102,n=271733878,c=3285377520,f=t.length,a=f*8,o=f+1+8,l=Math.ceil(o/64)*64,s=new ArrayBuffer(l),C=new Uint8Array(s),h=new DataView(s);C.set(t),C[f]=128,h.setUint32(l-8,Math.floor(a/4294967296),false),h.setUint32(l-4,a>>>0,false);let p=new Uint32Array(80);for(let x=0;x<l;x+=64){for(let d=0;d<16;d++)p[d]=h.getUint32(x+d*4,false);for(let d=16;d<80;d++){let I=p[d-3]^p[d-8]^p[d-14]^p[d-16];p[d]=I<<1|I>>>31;}let u=e,g=i,_=r,k=n,S=c;for(let d=0;d<80;d++){let I,m;d<20?(I=g&_|~g&k,m=1518500249):d<40?(I=g^_^k,m=1859775393):d<60?(I=g&_|g&k|_&k,m=2400959708):(I=g^_^k,m=3395469782);let b=(u<<5|u>>>27)+I+S+m+p[d]>>>0;S=k,k=_,_=(g<<30|g>>>2)>>>0,g=u,u=b;}e=e+u>>>0,i=i+g>>>0,r=r+_>>>0,n=n+k>>>0,c=c+S>>>0;}let y=x=>x.toString(16).padStart(8,"0");return y(e)+y(i)+y(r)+y(n)+y(c)}function N(t){try{if(!t)return "";let e=typeof t=="string"?t:JSON.stringify(t);return E(Z(e))}catch(e){console.error("Error in making the hash:",e);}return ""}function U(t){if(!t)return;let e=[],i=t.split(",");for(let r of i){let n=r.trim();if(n)if(n.includes("-")){let[c,f]=n.split("-"),a=parseInt(c,10),o=parseInt(f,10);if(!isNaN(a)&&!isNaN(o)&&a<=o)for(let l=a;l<=o;l++)e.push(l);else isNaN(a)||e.push(a);}else {let c=parseInt(n,10);isNaN(c)||e.push(c);}}if(e.length!==0)return [...new Set(e)].sort((r,n)=>r-n)}function $(t){let e=t?.status,i=e==="not_found",r=e==="found_phrase_missed_value",n=e==="found_key_span_only",c=e==="partial_text_found"||e==="found_on_other_page"||e==="found_on_other_line"||e==="first_word_found";return {isVerified:e==="found"||n||c||r,isMiss:i,isPartialMatch:c,isPending:e==="pending"||e==="loading"||!e}}var D=(t,e,i,r)=>{let n=m=>m?m.replace(/^['"]|['"]$/g,"").replace(/\\'/g,"'"):void 0,c=i?.current?i.current++:void 0,f=t.substring(0,t.indexOf("<cite")),a=t.includes("/>")?t.slice(t.indexOf("/>")+2):"",o=t.substring(t.indexOf("<cite"),t.indexOf("/>")+2),l=(m,b)=>{for(let O of b){let L=new RegExp(`${O}='((?:[^'\\\\]|\\\\.)*)'`),K=m.match(L);if(K)return K[1]}},s=l(o,["attachment_id","attachmentId","file_id","fileId"]),C=s?.length===20?s:e||s,h=l(o,["start_page_key","startPageKey","start_page"]),p,y;if(h){let m=h.match(/page[\_a-zA-Z]*(\d+)_index_(\d+)/);m&&(p=parseInt(m[1]),y=parseInt(m[2]));}let x=n(l(o,["full_phrase","fullPhrase"])),u=n(l(o,["key_span","keySpan"])),g=n(l(o,["reasoning"])),_=n(l(o,["value"])),k;try{let b=l(o,["line_ids","lineIds"])?.replace(/[A-Za-z_[\](){}:]/g,"");k=b?U(b):void 0;}catch(m){r&&console.error("Error parsing lineIds",m);}let S=l(o,["timestamps"]),d;if(S){let[m,b]=S.split("-")||[];d={startTime:m,endTime:b};}let I={attachmentId:C,pageNumber:p,startPageKey:`page_number_${p||1}_index_${y||0}`,fullPhrase:x,keySpan:u||_,citationNumber:c,lineIds:k,beforeCite:f,timestamps:d,reasoning:g};return {beforeCite:f,afterCite:a,citation:I}},B=(t,e)=>{if(!t)return null;let i=t.fullPhrase??t.full_phrase,r=t.startPageKey??t.start_page_key,n=t.keySpan??t.key_span,c=t.lineIds??t.line_ids,f=t.attachmentId??t.attachment_id??t.fileId??t.file_id,a=t.reasoning,o=t.value;if(!i)return null;let l;if(r){let h=r.match(/page[_a-zA-Z]*(\d+)_index_(\d+)/i);if(h)l=parseInt(h[1],10);else {let p=r.match(/^(\d+)_(\d+)$/);p&&(l=parseInt(p[1],10));}}let s=c?.length?[...c].sort((h,p)=>h-p):void 0;return {attachmentId:f,pageNumber:l,fullPhrase:i,citationNumber:e,lineIds:s,keySpan:n||o,reasoning:a}},V=t=>typeof t=="object"&&t!==null&&("fullPhrase"in t||"full_phrase"in t||"startPageKey"in t||"start_page_key"in t||"keySpan"in t||"key_span"in t||"lineIds"in t||"line_ids"in t),P=t=>Array.isArray(t)?t.length>0&&t.some(V):typeof t=="object"&&t!==null?V(t):false,v=t=>{let e={},i=Array.isArray(t)?t:[t],r=1;for(let n of i){let c=B(n,r++);if(c&&c.fullPhrase){let f=A(c);e[f]=c;}}return e},w=(t,e)=>{if(!(!t||typeof t!="object")){if(t.citation&&P(t.citation)){let i=Array.isArray(t.citation)?t.citation:[t.citation];e.push(...i);}if(t.citations&&P(t.citations)){let i=Array.isArray(t.citations)?t.citations:[t.citations];e.push(...i);}if(Array.isArray(t))for(let i of t)w(i,e);else for(let i of Object.keys(t))i!=="citation"&&i!=="citations"&&w(t[i],e);}},T=t=>{let e=M(t),i=/<cite\s+[^>]*\/>/g,r=e.match(i);if(!r||r.length===0)return {};let n={},c={current:1};for(let f of r){let{citation:a}=D(f,void 0,c);if(a&&a.fullPhrase){let o=A(a);n[o]=a;}}return n},j=t=>{if(!t)return {};let e={};if(typeof t=="object"){if(P(t)){let n=v(t);Object.assign(e,n);}else {let n=[];if(w(t,n),n.length>0){let c=v(n);Object.assign(e,c);}}let i=JSON.stringify(t),r=T(i);Object.assign(e,r);}else if(typeof t=="string"){let i=T(t);Object.assign(e,i);}return e};function Q(t){let e=new Map,i=Array.isArray(t)?t.map((r,n)=>[A(r)||String(n+1),r]):Object.entries(t);for(let[r,n]of i){let c=n.attachmentId||"";e.has(c)||e.set(c,{}),e.get(c)[r]=n;}return e}function tt(t){let e={},i=Array.isArray(t)?t.map((r,n)=>[A(r)||String(n+1),r]):Object.entries(t);for(let[r,n]of i){let c=n.attachmentId||"";e[c]||(e[c]={}),e[c][r]=n;}return e}var J=t=>{let e={},i=/([a-zA-Z_][a-zA-Z0-9_]*)\s*=\s*(['"])((?:[^'"\\]|\\.)*)\2/g,r;for(;(r=i.exec(t))!==null;){let n=r[1].toLowerCase().replace(/([a-z])([A-Z])/g,"$1_$2").toLowerCase(),c=r[3],f=n==="fileid"||n==="file_id"||n==="attachmentid"?"attachment_id":n==="keyspan"?"key_span":n==="fullphrase"?"full_phrase":n==="lineids"?"line_ids":n==="startpagekey"||n==="start_pagekey"?"start_page_key":n;e[f]=c;}return e},F=t=>{if(!t)return "\u25CC";let e=$(t);return e.isPending?"\u25CC":e.isMiss?"\u2717":e.isPartialMatch?"\u26A0":e.isVerified?"\u2713":"\u25CC"},W=F,H=(t,e={})=>{let{leaveKeySpanBehind:i=false,verifications:r,showVerificationStatus:n=false}=e,c=0,f=/<cite\s+[^>]*?\/>/g;return t.replace(f,a=>{c++;let o=J(a),l="";if(i&&o.key_span&&(l=o.key_span.replace(/\\'/g,"'").replace(/\\"/g,'"')),n&&r){let s,C=u=>{if(!u)return;let g=u.match(/page[_a-zA-Z]*(\d+)/);return g?parseInt(g[1],10):void 0},h=u=>{if(!u)return;let g=u.split(",").map(_=>parseInt(_.trim(),10)).filter(_=>!isNaN(_));return g.length>0?g:void 0},p={attachmentId:o.attachment_id,pageNumber:C(o.start_page_key),fullPhrase:o.full_phrase?.replace(/\\'/g,"'").replace(/\\"/g,'"'),keySpan:o.key_span?.replace(/\\'/g,"'").replace(/\\"/g,'"'),lineIds:h(o.line_ids)},y=A(p);if(s=r[y],!s){let u=String(c);s=r[u];}let x=W(s);l=l?`${l}${x}`:x;}return l})},rt=(t,e)=>H(t,{leaveKeySpanBehind:e}),st=t=>t.replace(/<page_number_\d+_index_\d+>/g,"").replace(/<\/page_number_\d+_index_\d+>/g,"").trim(),at=t=>{let e=/<line id="[^"]*">|<\/line>/g;return t.replace(e,"")},z=t=>{if(!t)return null;let e=t.match(/\d+/)?.[0];return e?parseInt(e):null},M=t=>{let e=t?.trim()||"",i=e.split(/(<cite[\s\S]*?(?:\/>|<\/cite>))/gm);return i.length<=1?R(e):(e=i.map(r=>r.startsWith("<cite")?R(r):r).join(""),e)},R=t=>{let e=t;e=e.replace(/\\_/g,"_"),e=e.replace(/><\/cite>/g,"/>");let i=f=>{let a=f.toLowerCase();return a==="fullphrase"||a==="full_phrase"?"full_phrase":a==="lineids"||a==="line_ids"?"line_ids":a==="startpagekey"||a==="start_pagekey"||a==="start_page_key"?"start_page_key":a==="fileid"||a==="file_id"||a==="attachmentid"||a==="attachment_id"?"attachment_id":a==="keyspan"||a==="key_span"?"key_span":a==="reasoning"||a==="value"?a:a==="timestamps"||a==="timestamp"||a==="timestamps"?"timestamps":a},r=f=>f.replace(/&quot;/g,'"').replace(/&apos;/g,"'").replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&amp;/g,"&"),n=/(fullPhrase|full_phrase|keySpan|key_span|reasoning|value)\s*=\s*(['"])([\s\S]*?)(?=\s+(?:line_ids|lineIds|timestamps|fileId|file_id|attachmentId|attachment_id|start_page_key|start_pageKey|startPageKey|keySpan|key_span|reasoning|value|full_phrase)|\s*\/?>)/gm;e=e.replace(n,(f,a,o,l)=>{let s=l;return s.endsWith(o)&&(s=s.slice(0,-1)),s=s.replace(/(\r?\n)+/g," "),s=r(s),s=s.replace(/(\*|_){2,}/g,""),s=s.replace(/\\\\'/g,"'"),s=s.replace(/\\'/g,"'"),s=s.replace(/'/g,"\\'"),s=s.replace(/\\\\"/g,'"'),s=s.replace(/\\"/g,'"'),s=s.replace(/"/g,'\\"'),s=s.replace(/\*/g,""),`${i(a)}='${s}'`}),e=e.replace(/(line_ids|lineIds|timestamps)=['"]?([\[\]\(\){}A-Za-z0-9_\-, ]+)['"]?(\s*\/?>|\s+)/gm,(f,a,o,l)=>{let s=o.replace(/[A-Za-z\[\]\(\){}]/g,"");return s=s.replace(/(\d+)-(\d+)/g,(C,h,p)=>{let y=parseInt(h,10),x=parseInt(p,10),u=[];if(y<=x)for(let g=y;g<=x;g++)u.push(g);else u.push(y);return u.join(",")}),s=s.replace(/,+/g,",").replace(/^,|,$/g,""),`${i(a)}='${s}'${l}`});let c=f=>{let a=/([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(['"])((?:[^'"\\\n]|\\.)*)(?:\2)/g,o={},l;for(;l=a.exec(f);){let u=l[1],g=l[3],_=i(u);o[_]=g;}let s=Object.keys(o);if(s.length===0)return f;let C=typeof o.timestamps=="string"&&o.timestamps.length>0,h=s.filter(u=>u.startsWith("start_page")),p=[];o.attachment_id&&p.push("attachment_id"),C?(o.full_phrase&&p.push("full_phrase"),o.key_span&&p.push("key_span"),p.push("timestamps")):(h.includes("start_page_key")&&p.push("start_page_key"),h.filter(u=>u!=="start_page_key").sort().forEach(u=>p.push(u)),o.full_phrase&&p.push("full_phrase"),o.key_span&&p.push("key_span"),o.line_ids&&p.push("line_ids")),o.reasoning&&p.push("reasoning"),o.value&&p.push("value");let y=new Set(p);return s.filter(u=>!y.has(u)).sort().forEach(u=>p.push(u)),`<cite ${p.map(u=>`${u}='${o[u]}'`).join(" ")} />`};return e=e.replace(/<cite\b[\s\S]*?\/>/gm,f=>c(f)),e};function pt(...t){return t.filter(Boolean).join(" ")}function G(t){return t.type==="url"||typeof t.url=="string"&&t.url.length>0}function A(t){let e=t.pageNumber||z(t.startPageKey),i=[t.attachmentId||"",e?.toString()||"",t.fullPhrase||"",t.keySpan?.toString()||"",t.lineIds?.join(",")||"",t.timestamps?.startTime||"",t.timestamps?.endTime||""];return G(t)&&i.push(t.url||"",t.title||"",t.domain||""),N(i.join("|")).slice(0,16)}function ut(t){let e=[t.attachmentId||"",t.label||"",t.verifiedFullPhrase||"",t.verifiedKeySpan||"",t.verifiedLineIds?.join(",")||"",t.verifiedPageNumber?.toString()||"",t.verifiedTimestamps?.startTime||"",t.verifiedTimestamps?.endTime||"",t.verifiedMatchSnippet||"",t.hitIndexWithinPage?.toString()||""];return N(e.join("|")).slice(0,16)}function ft(t){let e=Math.random().toString(36).slice(2,11);return `${t}-${e}`}function gt(t,e={}){let{fallbackDisplay:i}=e;return t.keySpan?.toString()||t.citationNumber?.toString()||i||"1"}function dt(t){return t.citationNumber?.toString()||"1"}function mt(t){return t.keySpan?.toString()||""}function ht(...t){return t.filter(Boolean).join(" ")}var yt=4,_t=1;exports.a=N;exports.b=pt;exports.c=G;exports.d=A;exports.e=ut;exports.f=ft;exports.g=gt;exports.h=dt;exports.i=mt;exports.j=ht;exports.k=yt;exports.l=_t;exports.m=F;exports.n=H;exports.o=rt;exports.p=st;exports.q=at;exports.r=z;exports.s=M;exports.t=$;exports.u=D;exports.v=j;exports.w=Q;exports.x=tt;
@@ -1,2 +1,2 @@
1
- 'use strict';var chunkSPCFZGGU_cjs=require('./chunk-SPCFZGGU.cjs'),chunkF2MMVEVC_cjs=require('./chunk-F2MMVEVC.cjs');var C="https://api.deepcitation.com";function F(p,t){if(typeof Buffer<"u"&&Buffer.isBuffer(p)){let e=Uint8Array.from(p);return {blob:new Blob([e]),name:t||"document"}}if(p instanceof Blob)return {blob:p,name:t||(p instanceof File?p.name:"document")};throw new Error("Invalid file type. Expected File, Blob, or Buffer.")}async function c(p,t){return (await p.json().catch(()=>({})))?.error?.message||`${t} failed with status ${p.status}`}var h=class{constructor(t){chunkF2MMVEVC_cjs.a(this,"apiKey");chunkF2MMVEVC_cjs.a(this,"apiUrl");if(!t.apiKey)throw new Error("DeepCitation API key is required. Get one at https://deepcitation.com/dashboard");this.apiKey=t.apiKey,this.apiUrl=t.apiUrl?.replace(/\/$/,"")||C;}async uploadFile(t,e){let{blob:l,name:a}=F(t,e?.filename),o=new FormData;o.append("file",l,a),e?.attachmentId&&o.append("attachmentId",e.attachmentId),e?.filename&&o.append("filename",e.filename);let i=await fetch(`${this.apiUrl}/prepareFile`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`},body:o});if(!i.ok)throw new Error(await c(i,"Upload"));return await i.json()}async convertToPdf(t){let e=typeof t=="string"?{url:t}:t,{url:l,file:a,filename:o,attachmentId:i}=e;if(!l&&!a)throw new Error("Either url or file must be provided");let r;if(l)r=await fetch(`${this.apiUrl}/convertFile`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},body:JSON.stringify({url:l,filename:o,attachmentId:i})});else {let{blob:f,name:n}=F(a,o),s=new FormData;s.append("file",f,n),i&&s.append("attachmentId",i),o&&s.append("filename",o),r=await fetch(`${this.apiUrl}/convertFile`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`},body:s});}if(!r.ok)throw new Error(await c(r,"Conversion"));return await r.json()}async prepareConvertedFile(t){let e=await fetch(`${this.apiUrl}/prepareFile`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},body:JSON.stringify({attachmentId:t.attachmentId})});if(!e.ok)throw new Error(await c(e,"Prepare"));return await e.json()}async prepareFiles(t){if(t.length===0)return {fileDataParts:[],deepTextPromptPortion:[]};let e=t.map(({file:i,filename:r,attachmentId:f})=>this.uploadFile(i,{filename:r,attachmentId:f}).then(n=>({result:n,filename:r}))),a=(await Promise.all(e)).map(({result:i,filename:r})=>({attachmentId:i.attachmentId,deepTextPromptPortion:i.deepTextPromptPortion,filename:r||i.metadata?.filename})),o=a.map(i=>i.deepTextPromptPortion);return {fileDataParts:a,deepTextPromptPortion:o}}async verifyAttachment(t,e,l){let a={};if(Array.isArray(e))for(let n of e){let s=chunkSPCFZGGU_cjs.j(n);a[s]=n;}else if(typeof e=="object"&&e!==null)if("fullPhrase"in e||"value"in e){let n=chunkSPCFZGGU_cjs.j(e);a[n]=e;}else Object.assign(a,e);else throw new Error("Invalid citations format");if(Object.keys(a).length===0)return {verifications:{}};let o=`${this.apiUrl}/verifyCitations`,i={data:{attachmentId:t,citations:a,outputImageFormat:l?.outputImageFormat||"avif"}},r=await fetch(o,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},body:JSON.stringify(i)});if(!r.ok)throw new Error(await c(r,"Verification"));return await r.json()}async verify(t,e){let{llmOutput:l,outputImageFormat:a="avif"}=t;if(e||(e=chunkSPCFZGGU_cjs.u(l)),Object.keys(e).length===0)return {verifications:{}};let o=new Map;for(let[n,s]of Object.entries(e)){let m=s.attachmentId||"";o.has(m)||o.set(m,{}),o.get(m)[n]=s;}let i=[];for(let[n,s]of o)n&&i.push(this.verifyAttachment(n,s,{outputImageFormat:a}));let r=await Promise.all(i),f={};for(let n of r)Object.assign(f,n.verifications);return {verifications:f}}};
1
+ 'use strict';var chunk7MQ6SJZV_cjs=require('./chunk-7MQ6SJZV.cjs'),chunkF2MMVEVC_cjs=require('./chunk-F2MMVEVC.cjs');var C="https://api.deepcitation.com";function F(p,t){if(typeof Buffer<"u"&&Buffer.isBuffer(p)){let e=Uint8Array.from(p);return {blob:new Blob([e]),name:t||"document"}}if(p instanceof Blob)return {blob:p,name:t||(p instanceof File?p.name:"document")};throw new Error("Invalid file type. Expected File, Blob, or Buffer.")}async function c(p,t){return (await p.json().catch(()=>({})))?.error?.message||`${t} failed with status ${p.status}`}var h=class{constructor(t){chunkF2MMVEVC_cjs.a(this,"apiKey");chunkF2MMVEVC_cjs.a(this,"apiUrl");if(!t.apiKey)throw new Error("DeepCitation API key is required. Get one at https://deepcitation.com/dashboard");this.apiKey=t.apiKey,this.apiUrl=t.apiUrl?.replace(/\/$/,"")||C;}async uploadFile(t,e){let{blob:l,name:a}=F(t,e?.filename),o=new FormData;o.append("file",l,a),e?.attachmentId&&o.append("attachmentId",e.attachmentId),e?.filename&&o.append("filename",e.filename);let i=await fetch(`${this.apiUrl}/prepareFile`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`},body:o});if(!i.ok)throw new Error(await c(i,"Upload"));return await i.json()}async convertToPdf(t){let e=typeof t=="string"?{url:t}:t,{url:l,file:a,filename:o,attachmentId:i}=e;if(!l&&!a)throw new Error("Either url or file must be provided");let r;if(l)r=await fetch(`${this.apiUrl}/convertFile`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},body:JSON.stringify({url:l,filename:o,attachmentId:i})});else {let{blob:f,name:n}=F(a,o),s=new FormData;s.append("file",f,n),i&&s.append("attachmentId",i),o&&s.append("filename",o),r=await fetch(`${this.apiUrl}/convertFile`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`},body:s});}if(!r.ok)throw new Error(await c(r,"Conversion"));return await r.json()}async prepareConvertedFile(t){let e=await fetch(`${this.apiUrl}/prepareFile`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},body:JSON.stringify({attachmentId:t.attachmentId})});if(!e.ok)throw new Error(await c(e,"Prepare"));return await e.json()}async prepareFiles(t){if(t.length===0)return {fileDataParts:[],deepTextPromptPortion:[]};let e=t.map(({file:i,filename:r,attachmentId:f})=>this.uploadFile(i,{filename:r,attachmentId:f}).then(n=>({result:n,filename:r}))),a=(await Promise.all(e)).map(({result:i,filename:r})=>({attachmentId:i.attachmentId,deepTextPromptPortion:i.deepTextPromptPortion,filename:r||i.metadata?.filename})),o=a.map(i=>i.deepTextPromptPortion);return {fileDataParts:a,deepTextPromptPortion:o}}async verifyAttachment(t,e,l){let a={};if(Array.isArray(e))for(let n of e){let s=chunk7MQ6SJZV_cjs.d(n);a[s]=n;}else if(typeof e=="object"&&e!==null)if("fullPhrase"in e||"value"in e){let n=chunk7MQ6SJZV_cjs.d(e);a[n]=e;}else Object.assign(a,e);else throw new Error("Invalid citations format");if(Object.keys(a).length===0)return {verifications:{}};let o=`${this.apiUrl}/verifyCitations`,i={data:{attachmentId:t,citations:a,outputImageFormat:l?.outputImageFormat||"avif"}},r=await fetch(o,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},body:JSON.stringify(i)});if(!r.ok)throw new Error(await c(r,"Verification"));return await r.json()}async verify(t,e){let{llmOutput:l,outputImageFormat:a="avif"}=t;if(e||(e=chunk7MQ6SJZV_cjs.v(l)),Object.keys(e).length===0)return {verifications:{}};let o=new Map;for(let[n,s]of Object.entries(e)){let m=s.attachmentId||"";o.has(m)||o.set(m,{}),o.get(m)[n]=s;}let i=[];for(let[n,s]of o)n&&i.push(this.verifyAttachment(n,s,{outputImageFormat:a}));let r=await Promise.all(i),f={};for(let n of r)Object.assign(f,n.verifications);return {verifications:f}}};
2
2
  exports.a=h;
@@ -1,2 +1,2 @@
1
- import {j,u}from'./chunk-3PE4VRVE.js';import {a}from'./chunk-O2XFH626.js';var C="https://api.deepcitation.com";function F(p,t){if(typeof Buffer<"u"&&Buffer.isBuffer(p)){let e=Uint8Array.from(p);return {blob:new Blob([e]),name:t||"document"}}if(p instanceof Blob)return {blob:p,name:t||(p instanceof File?p.name:"document")};throw new Error("Invalid file type. Expected File, Blob, or Buffer.")}async function c(p,t){return (await p.json().catch(()=>({})))?.error?.message||`${t} failed with status ${p.status}`}var h=class{constructor(t){a(this,"apiKey");a(this,"apiUrl");if(!t.apiKey)throw new Error("DeepCitation API key is required. Get one at https://deepcitation.com/dashboard");this.apiKey=t.apiKey,this.apiUrl=t.apiUrl?.replace(/\/$/,"")||C;}async uploadFile(t,e){let{blob:l,name:a}=F(t,e?.filename),o=new FormData;o.append("file",l,a),e?.attachmentId&&o.append("attachmentId",e.attachmentId),e?.filename&&o.append("filename",e.filename);let i=await fetch(`${this.apiUrl}/prepareFile`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`},body:o});if(!i.ok)throw new Error(await c(i,"Upload"));return await i.json()}async convertToPdf(t){let e=typeof t=="string"?{url:t}:t,{url:l,file:a,filename:o,attachmentId:i}=e;if(!l&&!a)throw new Error("Either url or file must be provided");let r;if(l)r=await fetch(`${this.apiUrl}/convertFile`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},body:JSON.stringify({url:l,filename:o,attachmentId:i})});else {let{blob:f,name:n}=F(a,o),s=new FormData;s.append("file",f,n),i&&s.append("attachmentId",i),o&&s.append("filename",o),r=await fetch(`${this.apiUrl}/convertFile`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`},body:s});}if(!r.ok)throw new Error(await c(r,"Conversion"));return await r.json()}async prepareConvertedFile(t){let e=await fetch(`${this.apiUrl}/prepareFile`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},body:JSON.stringify({attachmentId:t.attachmentId})});if(!e.ok)throw new Error(await c(e,"Prepare"));return await e.json()}async prepareFiles(t){if(t.length===0)return {fileDataParts:[],deepTextPromptPortion:[]};let e=t.map(({file:i,filename:r,attachmentId:f})=>this.uploadFile(i,{filename:r,attachmentId:f}).then(n=>({result:n,filename:r}))),a=(await Promise.all(e)).map(({result:i,filename:r})=>({attachmentId:i.attachmentId,deepTextPromptPortion:i.deepTextPromptPortion,filename:r||i.metadata?.filename})),o=a.map(i=>i.deepTextPromptPortion);return {fileDataParts:a,deepTextPromptPortion:o}}async verifyAttachment(t,e,l){let a={};if(Array.isArray(e))for(let n of e){let s=j(n);a[s]=n;}else if(typeof e=="object"&&e!==null)if("fullPhrase"in e||"value"in e){let n=j(e);a[n]=e;}else Object.assign(a,e);else throw new Error("Invalid citations format");if(Object.keys(a).length===0)return {verifications:{}};let o=`${this.apiUrl}/verifyCitations`,i={data:{attachmentId:t,citations:a,outputImageFormat:l?.outputImageFormat||"avif"}},r=await fetch(o,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},body:JSON.stringify(i)});if(!r.ok)throw new Error(await c(r,"Verification"));return await r.json()}async verify(t,e){let{llmOutput:l,outputImageFormat:a="avif"}=t;if(e||(e=u(l)),Object.keys(e).length===0)return {verifications:{}};let o=new Map;for(let[n,s]of Object.entries(e)){let m=s.attachmentId||"";o.has(m)||o.set(m,{}),o.get(m)[n]=s;}let i=[];for(let[n,s]of o)n&&i.push(this.verifyAttachment(n,s,{outputImageFormat:a}));let r=await Promise.all(i),f={};for(let n of r)Object.assign(f,n.verifications);return {verifications:f}}};
1
+ import {d,v}from'./chunk-MMVS32W3.js';import {a}from'./chunk-O2XFH626.js';var C="https://api.deepcitation.com";function F(p,t){if(typeof Buffer<"u"&&Buffer.isBuffer(p)){let e=Uint8Array.from(p);return {blob:new Blob([e]),name:t||"document"}}if(p instanceof Blob)return {blob:p,name:t||(p instanceof File?p.name:"document")};throw new Error("Invalid file type. Expected File, Blob, or Buffer.")}async function c(p,t){return (await p.json().catch(()=>({})))?.error?.message||`${t} failed with status ${p.status}`}var h=class{constructor(t){a(this,"apiKey");a(this,"apiUrl");if(!t.apiKey)throw new Error("DeepCitation API key is required. Get one at https://deepcitation.com/dashboard");this.apiKey=t.apiKey,this.apiUrl=t.apiUrl?.replace(/\/$/,"")||C;}async uploadFile(t,e){let{blob:l,name:a}=F(t,e?.filename),o=new FormData;o.append("file",l,a),e?.attachmentId&&o.append("attachmentId",e.attachmentId),e?.filename&&o.append("filename",e.filename);let i=await fetch(`${this.apiUrl}/prepareFile`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`},body:o});if(!i.ok)throw new Error(await c(i,"Upload"));return await i.json()}async convertToPdf(t){let e=typeof t=="string"?{url:t}:t,{url:l,file:a,filename:o,attachmentId:i}=e;if(!l&&!a)throw new Error("Either url or file must be provided");let r;if(l)r=await fetch(`${this.apiUrl}/convertFile`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},body:JSON.stringify({url:l,filename:o,attachmentId:i})});else {let{blob:f,name:n}=F(a,o),s=new FormData;s.append("file",f,n),i&&s.append("attachmentId",i),o&&s.append("filename",o),r=await fetch(`${this.apiUrl}/convertFile`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`},body:s});}if(!r.ok)throw new Error(await c(r,"Conversion"));return await r.json()}async prepareConvertedFile(t){let e=await fetch(`${this.apiUrl}/prepareFile`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},body:JSON.stringify({attachmentId:t.attachmentId})});if(!e.ok)throw new Error(await c(e,"Prepare"));return await e.json()}async prepareFiles(t){if(t.length===0)return {fileDataParts:[],deepTextPromptPortion:[]};let e=t.map(({file:i,filename:r,attachmentId:f})=>this.uploadFile(i,{filename:r,attachmentId:f}).then(n=>({result:n,filename:r}))),a=(await Promise.all(e)).map(({result:i,filename:r})=>({attachmentId:i.attachmentId,deepTextPromptPortion:i.deepTextPromptPortion,filename:r||i.metadata?.filename})),o=a.map(i=>i.deepTextPromptPortion);return {fileDataParts:a,deepTextPromptPortion:o}}async verifyAttachment(t,e,l){let a={};if(Array.isArray(e))for(let n of e){let s=d(n);a[s]=n;}else if(typeof e=="object"&&e!==null)if("fullPhrase"in e||"value"in e){let n=d(e);a[n]=e;}else Object.assign(a,e);else throw new Error("Invalid citations format");if(Object.keys(a).length===0)return {verifications:{}};let o=`${this.apiUrl}/verifyCitations`,i={data:{attachmentId:t,citations:a,outputImageFormat:l?.outputImageFormat||"avif"}},r=await fetch(o,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},body:JSON.stringify(i)});if(!r.ok)throw new Error(await c(r,"Verification"));return await r.json()}async verify(t,e){let{llmOutput:l,outputImageFormat:a="avif"}=t;if(e||(e=v(l)),Object.keys(e).length===0)return {verifications:{}};let o=new Map;for(let[n,s]of Object.entries(e)){let m=s.attachmentId||"";o.has(m)||o.set(m,{}),o.get(m)[n]=s;}let i=[];for(let[n,s]of o)n&&i.push(this.verifyAttachment(n,s,{outputImageFormat:a}));let r=await Promise.all(i),f={};for(let n of r)Object.assign(f,n.verifications);return {verifications:f}}};
2
2
  export{h as a};
@@ -0,0 +1 @@
1
+ function Z(t){return new TextEncoder().encode(t)}function E(t){let e=1732584193,i=4023233417,r=2562383102,n=271733878,c=3285377520,f=t.length,a=f*8,o=f+1+8,l=Math.ceil(o/64)*64,s=new ArrayBuffer(l),C=new Uint8Array(s),h=new DataView(s);C.set(t),C[f]=128,h.setUint32(l-8,Math.floor(a/4294967296),false),h.setUint32(l-4,a>>>0,false);let p=new Uint32Array(80);for(let x=0;x<l;x+=64){for(let d=0;d<16;d++)p[d]=h.getUint32(x+d*4,false);for(let d=16;d<80;d++){let I=p[d-3]^p[d-8]^p[d-14]^p[d-16];p[d]=I<<1|I>>>31;}let u=e,g=i,_=r,k=n,S=c;for(let d=0;d<80;d++){let I,m;d<20?(I=g&_|~g&k,m=1518500249):d<40?(I=g^_^k,m=1859775393):d<60?(I=g&_|g&k|_&k,m=2400959708):(I=g^_^k,m=3395469782);let b=(u<<5|u>>>27)+I+S+m+p[d]>>>0;S=k,k=_,_=(g<<30|g>>>2)>>>0,g=u,u=b;}e=e+u>>>0,i=i+g>>>0,r=r+_>>>0,n=n+k>>>0,c=c+S>>>0;}let y=x=>x.toString(16).padStart(8,"0");return y(e)+y(i)+y(r)+y(n)+y(c)}function N(t){try{if(!t)return "";let e=typeof t=="string"?t:JSON.stringify(t);return E(Z(e))}catch(e){console.error("Error in making the hash:",e);}return ""}function U(t){if(!t)return;let e=[],i=t.split(",");for(let r of i){let n=r.trim();if(n)if(n.includes("-")){let[c,f]=n.split("-"),a=parseInt(c,10),o=parseInt(f,10);if(!isNaN(a)&&!isNaN(o)&&a<=o)for(let l=a;l<=o;l++)e.push(l);else isNaN(a)||e.push(a);}else {let c=parseInt(n,10);isNaN(c)||e.push(c);}}if(e.length!==0)return [...new Set(e)].sort((r,n)=>r-n)}function $(t){let e=t?.status,i=e==="not_found",r=e==="found_phrase_missed_value",n=e==="found_key_span_only",c=e==="partial_text_found"||e==="found_on_other_page"||e==="found_on_other_line"||e==="first_word_found";return {isVerified:e==="found"||n||c||r,isMiss:i,isPartialMatch:c,isPending:e==="pending"||e==="loading"||!e}}var D=(t,e,i,r)=>{let n=m=>m?m.replace(/^['"]|['"]$/g,"").replace(/\\'/g,"'"):void 0,c=i?.current?i.current++:void 0,f=t.substring(0,t.indexOf("<cite")),a=t.includes("/>")?t.slice(t.indexOf("/>")+2):"",o=t.substring(t.indexOf("<cite"),t.indexOf("/>")+2),l=(m,b)=>{for(let O of b){let L=new RegExp(`${O}='((?:[^'\\\\]|\\\\.)*)'`),K=m.match(L);if(K)return K[1]}},s=l(o,["attachment_id","attachmentId","file_id","fileId"]),C=s?.length===20?s:e||s,h=l(o,["start_page_key","startPageKey","start_page"]),p,y;if(h){let m=h.match(/page[\_a-zA-Z]*(\d+)_index_(\d+)/);m&&(p=parseInt(m[1]),y=parseInt(m[2]));}let x=n(l(o,["full_phrase","fullPhrase"])),u=n(l(o,["key_span","keySpan"])),g=n(l(o,["reasoning"])),_=n(l(o,["value"])),k;try{let b=l(o,["line_ids","lineIds"])?.replace(/[A-Za-z_[\](){}:]/g,"");k=b?U(b):void 0;}catch(m){r&&console.error("Error parsing lineIds",m);}let S=l(o,["timestamps"]),d;if(S){let[m,b]=S.split("-")||[];d={startTime:m,endTime:b};}let I={attachmentId:C,pageNumber:p,startPageKey:`page_number_${p||1}_index_${y||0}`,fullPhrase:x,keySpan:u||_,citationNumber:c,lineIds:k,beforeCite:f,timestamps:d,reasoning:g};return {beforeCite:f,afterCite:a,citation:I}},B=(t,e)=>{if(!t)return null;let i=t.fullPhrase??t.full_phrase,r=t.startPageKey??t.start_page_key,n=t.keySpan??t.key_span,c=t.lineIds??t.line_ids,f=t.attachmentId??t.attachment_id??t.fileId??t.file_id,a=t.reasoning,o=t.value;if(!i)return null;let l;if(r){let h=r.match(/page[_a-zA-Z]*(\d+)_index_(\d+)/i);if(h)l=parseInt(h[1],10);else {let p=r.match(/^(\d+)_(\d+)$/);p&&(l=parseInt(p[1],10));}}let s=c?.length?[...c].sort((h,p)=>h-p):void 0;return {attachmentId:f,pageNumber:l,fullPhrase:i,citationNumber:e,lineIds:s,keySpan:n||o,reasoning:a}},V=t=>typeof t=="object"&&t!==null&&("fullPhrase"in t||"full_phrase"in t||"startPageKey"in t||"start_page_key"in t||"keySpan"in t||"key_span"in t||"lineIds"in t||"line_ids"in t),P=t=>Array.isArray(t)?t.length>0&&t.some(V):typeof t=="object"&&t!==null?V(t):false,v=t=>{let e={},i=Array.isArray(t)?t:[t],r=1;for(let n of i){let c=B(n,r++);if(c&&c.fullPhrase){let f=A(c);e[f]=c;}}return e},w=(t,e)=>{if(!(!t||typeof t!="object")){if(t.citation&&P(t.citation)){let i=Array.isArray(t.citation)?t.citation:[t.citation];e.push(...i);}if(t.citations&&P(t.citations)){let i=Array.isArray(t.citations)?t.citations:[t.citations];e.push(...i);}if(Array.isArray(t))for(let i of t)w(i,e);else for(let i of Object.keys(t))i!=="citation"&&i!=="citations"&&w(t[i],e);}},T=t=>{let e=M(t),i=/<cite\s+[^>]*\/>/g,r=e.match(i);if(!r||r.length===0)return {};let n={},c={current:1};for(let f of r){let{citation:a}=D(f,void 0,c);if(a&&a.fullPhrase){let o=A(a);n[o]=a;}}return n},j=t=>{if(!t)return {};let e={};if(typeof t=="object"){if(P(t)){let n=v(t);Object.assign(e,n);}else {let n=[];if(w(t,n),n.length>0){let c=v(n);Object.assign(e,c);}}let i=JSON.stringify(t),r=T(i);Object.assign(e,r);}else if(typeof t=="string"){let i=T(t);Object.assign(e,i);}return e};function Q(t){let e=new Map,i=Array.isArray(t)?t.map((r,n)=>[A(r)||String(n+1),r]):Object.entries(t);for(let[r,n]of i){let c=n.attachmentId||"";e.has(c)||e.set(c,{}),e.get(c)[r]=n;}return e}function tt(t){let e={},i=Array.isArray(t)?t.map((r,n)=>[A(r)||String(n+1),r]):Object.entries(t);for(let[r,n]of i){let c=n.attachmentId||"";e[c]||(e[c]={}),e[c][r]=n;}return e}var J=t=>{let e={},i=/([a-zA-Z_][a-zA-Z0-9_]*)\s*=\s*(['"])((?:[^'"\\]|\\.)*)\2/g,r;for(;(r=i.exec(t))!==null;){let n=r[1].toLowerCase().replace(/([a-z])([A-Z])/g,"$1_$2").toLowerCase(),c=r[3],f=n==="fileid"||n==="file_id"||n==="attachmentid"?"attachment_id":n==="keyspan"?"key_span":n==="fullphrase"?"full_phrase":n==="lineids"?"line_ids":n==="startpagekey"||n==="start_pagekey"?"start_page_key":n;e[f]=c;}return e},F=t=>{if(!t)return "\u25CC";let e=$(t);return e.isPending?"\u25CC":e.isMiss?"\u2717":e.isPartialMatch?"\u26A0":e.isVerified?"\u2713":"\u25CC"},W=F,H=(t,e={})=>{let{leaveKeySpanBehind:i=false,verifications:r,showVerificationStatus:n=false}=e,c=0,f=/<cite\s+[^>]*?\/>/g;return t.replace(f,a=>{c++;let o=J(a),l="";if(i&&o.key_span&&(l=o.key_span.replace(/\\'/g,"'").replace(/\\"/g,'"')),n&&r){let s,C=u=>{if(!u)return;let g=u.match(/page[_a-zA-Z]*(\d+)/);return g?parseInt(g[1],10):void 0},h=u=>{if(!u)return;let g=u.split(",").map(_=>parseInt(_.trim(),10)).filter(_=>!isNaN(_));return g.length>0?g:void 0},p={attachmentId:o.attachment_id,pageNumber:C(o.start_page_key),fullPhrase:o.full_phrase?.replace(/\\'/g,"'").replace(/\\"/g,'"'),keySpan:o.key_span?.replace(/\\'/g,"'").replace(/\\"/g,'"'),lineIds:h(o.line_ids)},y=A(p);if(s=r[y],!s){let u=String(c);s=r[u];}let x=W(s);l=l?`${l}${x}`:x;}return l})},rt=(t,e)=>H(t,{leaveKeySpanBehind:e}),st=t=>t.replace(/<page_number_\d+_index_\d+>/g,"").replace(/<\/page_number_\d+_index_\d+>/g,"").trim(),at=t=>{let e=/<line id="[^"]*">|<\/line>/g;return t.replace(e,"")},z=t=>{if(!t)return null;let e=t.match(/\d+/)?.[0];return e?parseInt(e):null},M=t=>{let e=t?.trim()||"",i=e.split(/(<cite[\s\S]*?(?:\/>|<\/cite>))/gm);return i.length<=1?R(e):(e=i.map(r=>r.startsWith("<cite")?R(r):r).join(""),e)},R=t=>{let e=t;e=e.replace(/\\_/g,"_"),e=e.replace(/><\/cite>/g,"/>");let i=f=>{let a=f.toLowerCase();return a==="fullphrase"||a==="full_phrase"?"full_phrase":a==="lineids"||a==="line_ids"?"line_ids":a==="startpagekey"||a==="start_pagekey"||a==="start_page_key"?"start_page_key":a==="fileid"||a==="file_id"||a==="attachmentid"||a==="attachment_id"?"attachment_id":a==="keyspan"||a==="key_span"?"key_span":a==="reasoning"||a==="value"?a:a==="timestamps"||a==="timestamp"||a==="timestamps"?"timestamps":a},r=f=>f.replace(/&quot;/g,'"').replace(/&apos;/g,"'").replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&amp;/g,"&"),n=/(fullPhrase|full_phrase|keySpan|key_span|reasoning|value)\s*=\s*(['"])([\s\S]*?)(?=\s+(?:line_ids|lineIds|timestamps|fileId|file_id|attachmentId|attachment_id|start_page_key|start_pageKey|startPageKey|keySpan|key_span|reasoning|value|full_phrase)|\s*\/?>)/gm;e=e.replace(n,(f,a,o,l)=>{let s=l;return s.endsWith(o)&&(s=s.slice(0,-1)),s=s.replace(/(\r?\n)+/g," "),s=r(s),s=s.replace(/(\*|_){2,}/g,""),s=s.replace(/\\\\'/g,"'"),s=s.replace(/\\'/g,"'"),s=s.replace(/'/g,"\\'"),s=s.replace(/\\\\"/g,'"'),s=s.replace(/\\"/g,'"'),s=s.replace(/"/g,'\\"'),s=s.replace(/\*/g,""),`${i(a)}='${s}'`}),e=e.replace(/(line_ids|lineIds|timestamps)=['"]?([\[\]\(\){}A-Za-z0-9_\-, ]+)['"]?(\s*\/?>|\s+)/gm,(f,a,o,l)=>{let s=o.replace(/[A-Za-z\[\]\(\){}]/g,"");return s=s.replace(/(\d+)-(\d+)/g,(C,h,p)=>{let y=parseInt(h,10),x=parseInt(p,10),u=[];if(y<=x)for(let g=y;g<=x;g++)u.push(g);else u.push(y);return u.join(",")}),s=s.replace(/,+/g,",").replace(/^,|,$/g,""),`${i(a)}='${s}'${l}`});let c=f=>{let a=/([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(['"])((?:[^'"\\\n]|\\.)*)(?:\2)/g,o={},l;for(;l=a.exec(f);){let u=l[1],g=l[3],_=i(u);o[_]=g;}let s=Object.keys(o);if(s.length===0)return f;let C=typeof o.timestamps=="string"&&o.timestamps.length>0,h=s.filter(u=>u.startsWith("start_page")),p=[];o.attachment_id&&p.push("attachment_id"),C?(o.full_phrase&&p.push("full_phrase"),o.key_span&&p.push("key_span"),p.push("timestamps")):(h.includes("start_page_key")&&p.push("start_page_key"),h.filter(u=>u!=="start_page_key").sort().forEach(u=>p.push(u)),o.full_phrase&&p.push("full_phrase"),o.key_span&&p.push("key_span"),o.line_ids&&p.push("line_ids")),o.reasoning&&p.push("reasoning"),o.value&&p.push("value");let y=new Set(p);return s.filter(u=>!y.has(u)).sort().forEach(u=>p.push(u)),`<cite ${p.map(u=>`${u}='${o[u]}'`).join(" ")} />`};return e=e.replace(/<cite\b[\s\S]*?\/>/gm,f=>c(f)),e};function pt(...t){return t.filter(Boolean).join(" ")}function G(t){return t.type==="url"||typeof t.url=="string"&&t.url.length>0}function A(t){let e=t.pageNumber||z(t.startPageKey),i=[t.attachmentId||"",e?.toString()||"",t.fullPhrase||"",t.keySpan?.toString()||"",t.lineIds?.join(",")||"",t.timestamps?.startTime||"",t.timestamps?.endTime||""];return G(t)&&i.push(t.url||"",t.title||"",t.domain||""),N(i.join("|")).slice(0,16)}function ut(t){let e=[t.attachmentId||"",t.label||"",t.verifiedFullPhrase||"",t.verifiedKeySpan||"",t.verifiedLineIds?.join(",")||"",t.verifiedPageNumber?.toString()||"",t.verifiedTimestamps?.startTime||"",t.verifiedTimestamps?.endTime||"",t.verifiedMatchSnippet||"",t.hitIndexWithinPage?.toString()||""];return N(e.join("|")).slice(0,16)}function ft(t){let e=Math.random().toString(36).slice(2,11);return `${t}-${e}`}function gt(t,e={}){let{fallbackDisplay:i}=e;return t.keySpan?.toString()||t.citationNumber?.toString()||i||"1"}function dt(t){return t.citationNumber?.toString()||"1"}function mt(t){return t.keySpan?.toString()||""}function ht(...t){return t.filter(Boolean).join(" ")}var yt=4,_t=1;export{N as a,pt as b,G as c,A as d,ut as e,ft as f,gt as g,dt as h,mt as i,ht as j,yt as k,_t as l,F as m,H as n,rt as o,st as p,at as q,z as r,M as s,$ as t,D as u,j as v,Q as w,tt as x};
@@ -2,7 +2,7 @@
2
2
  <citation-instructions priority="critical">
3
3
  ## REQUIRED: Citation Format
4
4
 
5
- For every claim, value, or fact; you MUST cite sources using this exact syntax:
5
+ For every claim, value, or fact; you MUST cite the attachment using this exact syntax:
6
6
 
7
7
  <cite attachment_id='ID' reasoning='why this supports the claim' full_phrase='verbatim quote' key_span='1-3 key words' start_page_key='page_number_N_index_I' line_ids='X-Y' />
8
8
 
@@ -35,7 +35,7 @@ The total amount is $500 USD <cite attachment_id='abc123' reasoning='directly st
35
35
  <citation-instructions priority="critical">
36
36
  ## REQUIRED: Audio/Video Citation Format
37
37
 
38
- For every claim, value, or fact; you MUST cite sources using this exact syntax:
38
+ For every claim, value, or fact; you MUST cite the attachment using this exact syntax:
39
39
 
40
40
  <cite attachment_id='ID' reasoning='why this supports the claim' full_phrase='verbatim transcript quote' key_span='1-3 key words' timestamps='HH:MM:SS.SSS-HH:MM:SS.SSS' />
41
41
 
@@ -55,7 +55,7 @@ For every claim, value, or fact; you MUST cite sources using this exact syntax:
55
55
  - The <cite /> tag is self-closing - never use <cite>...</cite>
56
56
 
57
57
  </citation-instructions>
58
- `,d="<citation-reminder>Remember: You MUST use <cite /> tags with all required attributes for every claim, value, or fact from source documents.</citation-reminder>",T="<citation-reminder>Remember: You MUST use <cite /> tags with timestamps for every claim, value, or fact from source media.</citation-reminder>";function x(t){let{systemPrompt:n,isAudioVideo:i=false}=t,e=i?y:_,r=i?T:d;return `${e.trim()}
58
+ `,d="<citation-reminder>Remember: You MUST use <cite /> tags with all required attributes for every claim, value, or fact from attachments.</citation-reminder>",T="<citation-reminder>Remember: You MUST use <cite /> tags with timestamps for every claim, value, or fact from source media.</citation-reminder>";function x(t){let{systemPrompt:n,isAudioVideo:i=false}=t,e=i?y:_,r=i?T:d;return `${e.trim()}
59
59
 
60
60
  ${n.trim()}
61
61
 
@@ -1 +1 @@
1
- 'use strict';var chunkCGNTWQHJ_cjs=require('../chunk-CGNTWQHJ.cjs');require('../chunk-SPCFZGGU.cjs'),require('../chunk-F2MMVEVC.cjs');Object.defineProperty(exports,"DeepCitation",{enumerable:true,get:function(){return chunkCGNTWQHJ_cjs.a}});
1
+ 'use strict';var chunkEYZGBFHV_cjs=require('../chunk-EYZGBFHV.cjs');require('../chunk-7MQ6SJZV.cjs'),require('../chunk-F2MMVEVC.cjs');Object.defineProperty(exports,"DeepCitation",{enumerable:true,get:function(){return chunkEYZGBFHV_cjs.a}});
@@ -1 +1 @@
1
- export{a as DeepCitation}from'../chunk-XTD4YII6.js';import'../chunk-3PE4VRVE.js';import'../chunk-O2XFH626.js';
1
+ export{a as DeepCitation}from'../chunk-HJ7QRKV4.js';import'../chunk-MMVS32W3.js';import'../chunk-O2XFH626.js';
package/lib/index.cjs CHANGED
@@ -1 +1 @@
1
- 'use strict';var chunkCGNTWQHJ_cjs=require('./chunk-CGNTWQHJ.cjs'),chunk4G7LE6P4_cjs=require('./chunk-4G7LE6P4.cjs'),chunkCFXDRAJL_cjs=require('./chunk-CFXDRAJL.cjs'),chunkSPCFZGGU_cjs=require('./chunk-SPCFZGGU.cjs');require('./chunk-F2MMVEVC.cjs');var Y=t=>{if(!t)return false;let e=t.trim();if(e.length<64)return false;let a=e?.[0];for(let r=1;r<e.length;r++)if(e[r]!==a)return false;return true};function z(t){t=t.trim();let e=2,a=10,r=/[.?!](?=\s+|$)/g,c,n=[];for(;(c=r.exec(t))!==null;)n.push(c.index);if(n.length<2)return t;let m=n[n.length-1],l=n[n.length-2],o=t.substring(l+1,m+1),p=o.length;if(o.trim().slice(0,-1).length<a||p<=0||t.length<p*e)return t;let I=0,s=m+1;t.endsWith(o)&&(s=t.length);let f=-1;for(;;){let i=s-p;if(i<0)break;if(t.substring(i,s)===o)I++,f=i,s=i;else break}return I>=e?t.substring(0,f)+o:t}Object.defineProperty(exports,"DeepCitation",{enumerable:true,get:function(){return chunkCGNTWQHJ_cjs.a}});Object.defineProperty(exports,"AV_CITATION_MARKDOWN_SYNTAX_PROMPT",{enumerable:true,get:function(){return chunk4G7LE6P4_cjs.b}});Object.defineProperty(exports,"CITATION_AV_BASED_JSON_OUTPUT_FORMAT",{enumerable:true,get:function(){return chunk4G7LE6P4_cjs.h}});Object.defineProperty(exports,"CITATION_AV_REMINDER",{enumerable:true,get:function(){return chunk4G7LE6P4_cjs.d}});Object.defineProperty(exports,"CITATION_JSON_OUTPUT_FORMAT",{enumerable:true,get:function(){return chunk4G7LE6P4_cjs.g}});Object.defineProperty(exports,"CITATION_MARKDOWN_SYNTAX_PROMPT",{enumerable:true,get:function(){return chunk4G7LE6P4_cjs.a}});Object.defineProperty(exports,"CITATION_REMINDER",{enumerable:true,get:function(){return chunk4G7LE6P4_cjs.c}});Object.defineProperty(exports,"compressPromptIds",{enumerable:true,get:function(){return chunk4G7LE6P4_cjs.i}});Object.defineProperty(exports,"decompressPromptIds",{enumerable:true,get:function(){return chunk4G7LE6P4_cjs.j}});Object.defineProperty(exports,"wrapCitationPrompt",{enumerable:true,get:function(){return chunk4G7LE6P4_cjs.f}});Object.defineProperty(exports,"wrapSystemCitationPrompt",{enumerable:true,get:function(){return chunk4G7LE6P4_cjs.e}});Object.defineProperty(exports,"BLANK_VERIFICATION",{enumerable:true,get:function(){return chunkCFXDRAJL_cjs.d}});Object.defineProperty(exports,"DEFAULT_OUTPUT_IMAGE_FORMAT",{enumerable:true,get:function(){return chunkCFXDRAJL_cjs.a}});Object.defineProperty(exports,"NOT_FOUND_VERIFICATION_INDEX",{enumerable:true,get:function(){return chunkCFXDRAJL_cjs.b}});Object.defineProperty(exports,"PENDING_VERIFICATION_INDEX",{enumerable:true,get:function(){return chunkCFXDRAJL_cjs.c}});Object.defineProperty(exports,"CITATION_X_PADDING",{enumerable:true,get:function(){return chunkSPCFZGGU_cjs.q}});Object.defineProperty(exports,"CITATION_Y_PADDING",{enumerable:true,get:function(){return chunkSPCFZGGU_cjs.r}});Object.defineProperty(exports,"generateCitationInstanceId",{enumerable:true,get:function(){return chunkSPCFZGGU_cjs.l}});Object.defineProperty(exports,"generateCitationKey",{enumerable:true,get:function(){return chunkSPCFZGGU_cjs.j}});Object.defineProperty(exports,"generateVerificationKey",{enumerable:true,get:function(){return chunkSPCFZGGU_cjs.k}});Object.defineProperty(exports,"getAllCitationsFromLlmOutput",{enumerable:true,get:function(){return chunkSPCFZGGU_cjs.u}});Object.defineProperty(exports,"getCitationPageNumber",{enumerable:true,get:function(){return chunkSPCFZGGU_cjs.e}});Object.defineProperty(exports,"getCitationStatus",{enumerable:true,get:function(){return chunkSPCFZGGU_cjs.s}});Object.defineProperty(exports,"groupCitationsByAttachmentId",{enumerable:true,get:function(){return chunkSPCFZGGU_cjs.v}});Object.defineProperty(exports,"groupCitationsByAttachmentIdObject",{enumerable:true,get:function(){return chunkSPCFZGGU_cjs.w}});Object.defineProperty(exports,"normalizeCitations",{enumerable:true,get:function(){return chunkSPCFZGGU_cjs.f}});Object.defineProperty(exports,"parseCitation",{enumerable:true,get:function(){return chunkSPCFZGGU_cjs.t}});Object.defineProperty(exports,"removeCitations",{enumerable:true,get:function(){return chunkSPCFZGGU_cjs.b}});Object.defineProperty(exports,"removeLineIdMetadata",{enumerable:true,get:function(){return chunkSPCFZGGU_cjs.d}});Object.defineProperty(exports,"removePageNumberMetadata",{enumerable:true,get:function(){return chunkSPCFZGGU_cjs.c}});Object.defineProperty(exports,"replaceCitations",{enumerable:true,get:function(){return chunkSPCFZGGU_cjs.a}});Object.defineProperty(exports,"sha1Hash",{enumerable:true,get:function(){return chunkSPCFZGGU_cjs.g}});exports.cleanRepeatingLastSentence=z;exports.isGeminiGarbage=Y;
1
+ 'use strict';var chunkEYZGBFHV_cjs=require('./chunk-EYZGBFHV.cjs'),chunkVRXSLS23_cjs=require('./chunk-VRXSLS23.cjs'),chunkCFXDRAJL_cjs=require('./chunk-CFXDRAJL.cjs'),chunk7MQ6SJZV_cjs=require('./chunk-7MQ6SJZV.cjs');require('./chunk-F2MMVEVC.cjs');var z=t=>{if(!t)return false;let e=t.trim();if(e.length<64)return false;let a=e?.[0];for(let r=1;r<e.length;r++)if(e[r]!==a)return false;return true};function J(t){t=t.trim();let e=2,a=10,r=/[.?!](?=\s+|$)/g,c,n=[];for(;(c=r.exec(t))!==null;)n.push(c.index);if(n.length<2)return t;let I=n[n.length-1],T=n[n.length-2],o=t.substring(T+1,I+1),p=o.length;if(o.trim().slice(0,-1).length<a||p<=0||t.length<p*e)return t;let m=0,s=I+1;t.endsWith(o)&&(s=t.length);let f=-1;for(;;){let i=s-p;if(i<0)break;if(t.substring(i,s)===o)m++,f=i,s=i;else break}return m>=e?t.substring(0,f)+o:t}Object.defineProperty(exports,"DeepCitation",{enumerable:true,get:function(){return chunkEYZGBFHV_cjs.a}});Object.defineProperty(exports,"AV_CITATION_MARKDOWN_SYNTAX_PROMPT",{enumerable:true,get:function(){return chunkVRXSLS23_cjs.b}});Object.defineProperty(exports,"CITATION_AV_BASED_JSON_OUTPUT_FORMAT",{enumerable:true,get:function(){return chunkVRXSLS23_cjs.h}});Object.defineProperty(exports,"CITATION_AV_REMINDER",{enumerable:true,get:function(){return chunkVRXSLS23_cjs.d}});Object.defineProperty(exports,"CITATION_JSON_OUTPUT_FORMAT",{enumerable:true,get:function(){return chunkVRXSLS23_cjs.g}});Object.defineProperty(exports,"CITATION_MARKDOWN_SYNTAX_PROMPT",{enumerable:true,get:function(){return chunkVRXSLS23_cjs.a}});Object.defineProperty(exports,"CITATION_REMINDER",{enumerable:true,get:function(){return chunkVRXSLS23_cjs.c}});Object.defineProperty(exports,"compressPromptIds",{enumerable:true,get:function(){return chunkVRXSLS23_cjs.i}});Object.defineProperty(exports,"decompressPromptIds",{enumerable:true,get:function(){return chunkVRXSLS23_cjs.j}});Object.defineProperty(exports,"wrapCitationPrompt",{enumerable:true,get:function(){return chunkVRXSLS23_cjs.f}});Object.defineProperty(exports,"wrapSystemCitationPrompt",{enumerable:true,get:function(){return chunkVRXSLS23_cjs.e}});Object.defineProperty(exports,"BLANK_VERIFICATION",{enumerable:true,get:function(){return chunkCFXDRAJL_cjs.d}});Object.defineProperty(exports,"DEFAULT_OUTPUT_IMAGE_FORMAT",{enumerable:true,get:function(){return chunkCFXDRAJL_cjs.a}});Object.defineProperty(exports,"NOT_FOUND_VERIFICATION_INDEX",{enumerable:true,get:function(){return chunkCFXDRAJL_cjs.b}});Object.defineProperty(exports,"PENDING_VERIFICATION_INDEX",{enumerable:true,get:function(){return chunkCFXDRAJL_cjs.c}});Object.defineProperty(exports,"CITATION_X_PADDING",{enumerable:true,get:function(){return chunk7MQ6SJZV_cjs.k}});Object.defineProperty(exports,"CITATION_Y_PADDING",{enumerable:true,get:function(){return chunk7MQ6SJZV_cjs.l}});Object.defineProperty(exports,"generateCitationInstanceId",{enumerable:true,get:function(){return chunk7MQ6SJZV_cjs.f}});Object.defineProperty(exports,"generateCitationKey",{enumerable:true,get:function(){return chunk7MQ6SJZV_cjs.d}});Object.defineProperty(exports,"generateVerificationKey",{enumerable:true,get:function(){return chunk7MQ6SJZV_cjs.e}});Object.defineProperty(exports,"getAllCitationsFromLlmOutput",{enumerable:true,get:function(){return chunk7MQ6SJZV_cjs.v}});Object.defineProperty(exports,"getCitationPageNumber",{enumerable:true,get:function(){return chunk7MQ6SJZV_cjs.r}});Object.defineProperty(exports,"getCitationStatus",{enumerable:true,get:function(){return chunk7MQ6SJZV_cjs.t}});Object.defineProperty(exports,"getVerificationTextIndicator",{enumerable:true,get:function(){return chunk7MQ6SJZV_cjs.m}});Object.defineProperty(exports,"groupCitationsByAttachmentId",{enumerable:true,get:function(){return chunk7MQ6SJZV_cjs.w}});Object.defineProperty(exports,"groupCitationsByAttachmentIdObject",{enumerable:true,get:function(){return chunk7MQ6SJZV_cjs.x}});Object.defineProperty(exports,"normalizeCitations",{enumerable:true,get:function(){return chunk7MQ6SJZV_cjs.s}});Object.defineProperty(exports,"parseCitation",{enumerable:true,get:function(){return chunk7MQ6SJZV_cjs.u}});Object.defineProperty(exports,"removeCitations",{enumerable:true,get:function(){return chunk7MQ6SJZV_cjs.o}});Object.defineProperty(exports,"removeLineIdMetadata",{enumerable:true,get:function(){return chunk7MQ6SJZV_cjs.q}});Object.defineProperty(exports,"removePageNumberMetadata",{enumerable:true,get:function(){return chunk7MQ6SJZV_cjs.p}});Object.defineProperty(exports,"replaceCitations",{enumerable:true,get:function(){return chunk7MQ6SJZV_cjs.n}});Object.defineProperty(exports,"sha1Hash",{enumerable:true,get:function(){return chunk7MQ6SJZV_cjs.a}});exports.cleanRepeatingLastSentence=J;exports.isGeminiGarbage=z;
package/lib/index.d.cts CHANGED
@@ -33,7 +33,7 @@ declare const getAllCitationsFromLlmOutput: (llmOutput: any) => {
33
33
  /**
34
34
  * Groups citations by their attachmentId for multi-file verification scenarios.
35
35
  * This is useful when you have citations from multiple files and need to
36
- * verify them against their respective source documents.
36
+ * verify them against their respective attachments.
37
37
  *
38
38
  * @param citations - Array of Citation objects or a dictionary of citations
39
39
  * @returns Map of attachmentId to dictionary of citations from that file
@@ -100,6 +100,14 @@ interface ReplaceCitationsOptions {
100
100
  */
101
101
  showVerificationStatus?: boolean;
102
102
  }
103
+ /**
104
+ * Get verification status indicator character for plain text/terminal output.
105
+ * Returns: ✓ (verified), ⚠ (partial), ✗ (not found), ◌ (pending)
106
+ *
107
+ * For web UI, use the React CitationComponent instead which provides
108
+ * proper styled indicators with colors and accessibility.
109
+ */
110
+ declare const getVerificationTextIndicator: (verification: Verification | null | undefined) => string;
103
111
  /**
104
112
  * Replaces citation tags in markdown text with optional replacement content.
105
113
  *
@@ -148,4 +156,4 @@ declare function cleanRepeatingLastSentence(text: string): string;
148
156
  */
149
157
  declare function sha1Hash(data: string | any): string;
150
158
 
151
- export { Citation, CitationStatus, type ReplaceCitationsOptions, Verification, cleanRepeatingLastSentence, getAllCitationsFromLlmOutput, getCitationPageNumber, getCitationStatus, groupCitationsByAttachmentId, groupCitationsByAttachmentIdObject, isGeminiGarbage, normalizeCitations, parseCitation, removeCitations, removeLineIdMetadata, removePageNumberMetadata, replaceCitations, sha1Hash };
159
+ export { Citation, CitationStatus, type ReplaceCitationsOptions, Verification, cleanRepeatingLastSentence, getAllCitationsFromLlmOutput, getCitationPageNumber, getCitationStatus, getVerificationTextIndicator, groupCitationsByAttachmentId, groupCitationsByAttachmentIdObject, isGeminiGarbage, normalizeCitations, parseCitation, removeCitations, removeLineIdMetadata, removePageNumberMetadata, replaceCitations, sha1Hash };
package/lib/index.d.ts CHANGED
@@ -33,7 +33,7 @@ declare const getAllCitationsFromLlmOutput: (llmOutput: any) => {
33
33
  /**
34
34
  * Groups citations by their attachmentId for multi-file verification scenarios.
35
35
  * This is useful when you have citations from multiple files and need to
36
- * verify them against their respective source documents.
36
+ * verify them against their respective attachments.
37
37
  *
38
38
  * @param citations - Array of Citation objects or a dictionary of citations
39
39
  * @returns Map of attachmentId to dictionary of citations from that file
@@ -100,6 +100,14 @@ interface ReplaceCitationsOptions {
100
100
  */
101
101
  showVerificationStatus?: boolean;
102
102
  }
103
+ /**
104
+ * Get verification status indicator character for plain text/terminal output.
105
+ * Returns: ✓ (verified), ⚠ (partial), ✗ (not found), ◌ (pending)
106
+ *
107
+ * For web UI, use the React CitationComponent instead which provides
108
+ * proper styled indicators with colors and accessibility.
109
+ */
110
+ declare const getVerificationTextIndicator: (verification: Verification | null | undefined) => string;
103
111
  /**
104
112
  * Replaces citation tags in markdown text with optional replacement content.
105
113
  *
@@ -148,4 +156,4 @@ declare function cleanRepeatingLastSentence(text: string): string;
148
156
  */
149
157
  declare function sha1Hash(data: string | any): string;
150
158
 
151
- export { Citation, CitationStatus, type ReplaceCitationsOptions, Verification, cleanRepeatingLastSentence, getAllCitationsFromLlmOutput, getCitationPageNumber, getCitationStatus, groupCitationsByAttachmentId, groupCitationsByAttachmentIdObject, isGeminiGarbage, normalizeCitations, parseCitation, removeCitations, removeLineIdMetadata, removePageNumberMetadata, replaceCitations, sha1Hash };
159
+ export { Citation, CitationStatus, type ReplaceCitationsOptions, Verification, cleanRepeatingLastSentence, getAllCitationsFromLlmOutput, getCitationPageNumber, getCitationStatus, getVerificationTextIndicator, groupCitationsByAttachmentId, groupCitationsByAttachmentIdObject, isGeminiGarbage, normalizeCitations, parseCitation, removeCitations, removeLineIdMetadata, removePageNumberMetadata, replaceCitations, sha1Hash };
package/lib/index.js CHANGED
@@ -1 +1 @@
1
- export{a as DeepCitation}from'./chunk-XTD4YII6.js';export{b as AV_CITATION_MARKDOWN_SYNTAX_PROMPT,h as CITATION_AV_BASED_JSON_OUTPUT_FORMAT,d as CITATION_AV_REMINDER,g as CITATION_JSON_OUTPUT_FORMAT,a as CITATION_MARKDOWN_SYNTAX_PROMPT,c as CITATION_REMINDER,i as compressPromptIds,j as decompressPromptIds,f as wrapCitationPrompt,e as wrapSystemCitationPrompt}from'./chunk-KSQJNKLA.js';export{d as BLANK_VERIFICATION,a as DEFAULT_OUTPUT_IMAGE_FORMAT,b as NOT_FOUND_VERIFICATION_INDEX,c as PENDING_VERIFICATION_INDEX}from'./chunk-RQPZSRID.js';export{q as CITATION_X_PADDING,r as CITATION_Y_PADDING,l as generateCitationInstanceId,j as generateCitationKey,k as generateVerificationKey,u as getAllCitationsFromLlmOutput,e as getCitationPageNumber,s as getCitationStatus,v as groupCitationsByAttachmentId,w as groupCitationsByAttachmentIdObject,f as normalizeCitations,t as parseCitation,b as removeCitations,d as removeLineIdMetadata,c as removePageNumberMetadata,a as replaceCitations,g as sha1Hash}from'./chunk-3PE4VRVE.js';import'./chunk-O2XFH626.js';var Y=t=>{if(!t)return false;let e=t.trim();if(e.length<64)return false;let a=e?.[0];for(let r=1;r<e.length;r++)if(e[r]!==a)return false;return true};function z(t){t=t.trim();let e=2,a=10,r=/[.?!](?=\s+|$)/g,c,n=[];for(;(c=r.exec(t))!==null;)n.push(c.index);if(n.length<2)return t;let m=n[n.length-1],l=n[n.length-2],o=t.substring(l+1,m+1),p=o.length;if(o.trim().slice(0,-1).length<a||p<=0||t.length<p*e)return t;let I=0,s=m+1;t.endsWith(o)&&(s=t.length);let f=-1;for(;;){let i=s-p;if(i<0)break;if(t.substring(i,s)===o)I++,f=i,s=i;else break}return I>=e?t.substring(0,f)+o:t}export{z as cleanRepeatingLastSentence,Y as isGeminiGarbage};
1
+ export{a as DeepCitation}from'./chunk-HJ7QRKV4.js';export{b as AV_CITATION_MARKDOWN_SYNTAX_PROMPT,h as CITATION_AV_BASED_JSON_OUTPUT_FORMAT,d as CITATION_AV_REMINDER,g as CITATION_JSON_OUTPUT_FORMAT,a as CITATION_MARKDOWN_SYNTAX_PROMPT,c as CITATION_REMINDER,i as compressPromptIds,j as decompressPromptIds,f as wrapCitationPrompt,e as wrapSystemCitationPrompt}from'./chunk-7J46JZN5.js';export{d as BLANK_VERIFICATION,a as DEFAULT_OUTPUT_IMAGE_FORMAT,b as NOT_FOUND_VERIFICATION_INDEX,c as PENDING_VERIFICATION_INDEX}from'./chunk-RQPZSRID.js';export{k as CITATION_X_PADDING,l as CITATION_Y_PADDING,f as generateCitationInstanceId,d as generateCitationKey,e as generateVerificationKey,v as getAllCitationsFromLlmOutput,r as getCitationPageNumber,t as getCitationStatus,m as getVerificationTextIndicator,w as groupCitationsByAttachmentId,x as groupCitationsByAttachmentIdObject,s as normalizeCitations,u as parseCitation,o as removeCitations,q as removeLineIdMetadata,p as removePageNumberMetadata,n as replaceCitations,a as sha1Hash}from'./chunk-MMVS32W3.js';import'./chunk-O2XFH626.js';var z=t=>{if(!t)return false;let e=t.trim();if(e.length<64)return false;let a=e?.[0];for(let r=1;r<e.length;r++)if(e[r]!==a)return false;return true};function J(t){t=t.trim();let e=2,a=10,r=/[.?!](?=\s+|$)/g,c,n=[];for(;(c=r.exec(t))!==null;)n.push(c.index);if(n.length<2)return t;let I=n[n.length-1],T=n[n.length-2],o=t.substring(T+1,I+1),p=o.length;if(o.trim().slice(0,-1).length<a||p<=0||t.length<p*e)return t;let m=0,s=I+1;t.endsWith(o)&&(s=t.length);let f=-1;for(;;){let i=s-p;if(i<0)break;if(t.substring(i,s)===o)m++,f=i,s=i;else break}return m>=e?t.substring(0,f)+o:t}export{J as cleanRepeatingLastSentence,z as isGeminiGarbage};
@@ -1 +1 @@
1
- 'use strict';var chunk4G7LE6P4_cjs=require('../chunk-4G7LE6P4.cjs');require('../chunk-F2MMVEVC.cjs');Object.defineProperty(exports,"AV_CITATION_MARKDOWN_SYNTAX_PROMPT",{enumerable:true,get:function(){return chunk4G7LE6P4_cjs.b}});Object.defineProperty(exports,"CITATION_AV_BASED_JSON_OUTPUT_FORMAT",{enumerable:true,get:function(){return chunk4G7LE6P4_cjs.h}});Object.defineProperty(exports,"CITATION_AV_REMINDER",{enumerable:true,get:function(){return chunk4G7LE6P4_cjs.d}});Object.defineProperty(exports,"CITATION_JSON_OUTPUT_FORMAT",{enumerable:true,get:function(){return chunk4G7LE6P4_cjs.g}});Object.defineProperty(exports,"CITATION_MARKDOWN_SYNTAX_PROMPT",{enumerable:true,get:function(){return chunk4G7LE6P4_cjs.a}});Object.defineProperty(exports,"CITATION_REMINDER",{enumerable:true,get:function(){return chunk4G7LE6P4_cjs.c}});Object.defineProperty(exports,"compressPromptIds",{enumerable:true,get:function(){return chunk4G7LE6P4_cjs.i}});Object.defineProperty(exports,"decompressPromptIds",{enumerable:true,get:function(){return chunk4G7LE6P4_cjs.j}});Object.defineProperty(exports,"wrapCitationPrompt",{enumerable:true,get:function(){return chunk4G7LE6P4_cjs.f}});Object.defineProperty(exports,"wrapSystemCitationPrompt",{enumerable:true,get:function(){return chunk4G7LE6P4_cjs.e}});
1
+ 'use strict';var chunkVRXSLS23_cjs=require('../chunk-VRXSLS23.cjs');require('../chunk-F2MMVEVC.cjs');Object.defineProperty(exports,"AV_CITATION_MARKDOWN_SYNTAX_PROMPT",{enumerable:true,get:function(){return chunkVRXSLS23_cjs.b}});Object.defineProperty(exports,"CITATION_AV_BASED_JSON_OUTPUT_FORMAT",{enumerable:true,get:function(){return chunkVRXSLS23_cjs.h}});Object.defineProperty(exports,"CITATION_AV_REMINDER",{enumerable:true,get:function(){return chunkVRXSLS23_cjs.d}});Object.defineProperty(exports,"CITATION_JSON_OUTPUT_FORMAT",{enumerable:true,get:function(){return chunkVRXSLS23_cjs.g}});Object.defineProperty(exports,"CITATION_MARKDOWN_SYNTAX_PROMPT",{enumerable:true,get:function(){return chunkVRXSLS23_cjs.a}});Object.defineProperty(exports,"CITATION_REMINDER",{enumerable:true,get:function(){return chunkVRXSLS23_cjs.c}});Object.defineProperty(exports,"compressPromptIds",{enumerable:true,get:function(){return chunkVRXSLS23_cjs.i}});Object.defineProperty(exports,"decompressPromptIds",{enumerable:true,get:function(){return chunkVRXSLS23_cjs.j}});Object.defineProperty(exports,"wrapCitationPrompt",{enumerable:true,get:function(){return chunkVRXSLS23_cjs.f}});Object.defineProperty(exports,"wrapSystemCitationPrompt",{enumerable:true,get:function(){return chunkVRXSLS23_cjs.e}});
@@ -1,10 +1,10 @@
1
- declare const CITATION_MARKDOWN_SYNTAX_PROMPT = "\n<citation-instructions priority=\"critical\">\n## REQUIRED: Citation Format\n\nFor every claim, value, or fact; you MUST cite sources using this exact syntax:\n\n<cite attachment_id='ID' reasoning='why this supports the claim' full_phrase='verbatim quote' key_span='1-3 key words' start_page_key='page_number_N_index_I' line_ids='X-Y' />\n\n### Syntax Rules (MUST follow)\n\n1. **attachment_id**: Use the exact ID from the source document\n2. **reasoning**: Brief explanation of why this citation supports your claim (think first!)\n3. **full_phrase**: Copy text VERBATIM from source. Escape quotes (\\') and newlines (\\n).\n4. **key_span**: The 1-3 most important words or value from full_phrase\n5. **start_page_key**: ONLY use format `page_number_N_index_I` from page tags (e.g., `<page_number_1_index_0>`). Never extract page numbers from document content.\n6. **line_ids**: Inclusive range (e.g., '2-6' or '4'). Infer intermediate lines since only every 5th line is shown.\n\n### Placement Rules\n\n- Place <cite /> inline, typically at the end of a claim\n- One citation per distinct idea, concept, or value (a sentence citing 3 different values needs 3 citations)\n- Do NOT group citations at the end of the document\n- The <cite /> tag is self-closing - never use <cite>...</cite>\n\n### Example Citation 1\n\nThe company reported strong growth<cite attachment_id='abc123' reasoning='directly states revenue growth percentage' full_phrase='Revenue increased 45% year-over-year to $2.3 billion' key_span='increased 45%' start_page_key='page_number_2_index_1' line_ids='12-14' />\n\n### Example Citation 2\n\nThe total amount is $500 USD <cite attachment_id='abc123' reasoning='directly states the total amount' full_phrase='The total amount is $500 USD' key_span='$500 USD' start_page_key='page_number_2_index_1' line_ids='12-14' />\n\n</citation-instructions>\n";
2
- declare const AV_CITATION_MARKDOWN_SYNTAX_PROMPT = "\n<citation-instructions priority=\"critical\">\n## REQUIRED: Audio/Video Citation Format\n\nFor every claim, value, or fact; you MUST cite sources using this exact syntax:\n\n<cite attachment_id='ID' reasoning='why this supports the claim' full_phrase='verbatim transcript quote' key_span='1-3 key words' timestamps='HH:MM:SS.SSS-HH:MM:SS.SSS' />\n\n### Syntax Rules (MUST follow)\n\n1. **attachment_id**: Use the exact ID from the source\n2. **reasoning**: Brief explanation of why this citation supports your claim (think first!)\n3. **full_phrase**: Copy transcript text VERBATIM. Escape quotes (\\') and newlines (\\n).\n4. **key_span**: The 1-3 most important words or value from full_phrase\n5. **timestamps**: Start and end time with milliseconds (e.g., '00:01:23.456-00:01:45.789')\n\n### Placement Rules\n\n- Place <cite /> inline, typically at the end of a claim\n- One citation per distinct idea, concept, or value (a sentence citing 3 different values needs 3 citations)\n- Do NOT group citations at the end of the document\n- The <cite /> tag is self-closing - never use <cite>...</cite>\n\n</citation-instructions>\n";
1
+ declare const CITATION_MARKDOWN_SYNTAX_PROMPT = "\n<citation-instructions priority=\"critical\">\n## REQUIRED: Citation Format\n\nFor every claim, value, or fact; you MUST cite the attachment using this exact syntax:\n\n<cite attachment_id='ID' reasoning='why this supports the claim' full_phrase='verbatim quote' key_span='1-3 key words' start_page_key='page_number_N_index_I' line_ids='X-Y' />\n\n### Syntax Rules (MUST follow)\n\n1. **attachment_id**: Use the exact ID from the source document\n2. **reasoning**: Brief explanation of why this citation supports your claim (think first!)\n3. **full_phrase**: Copy text VERBATIM from source. Escape quotes (\\') and newlines (\\n).\n4. **key_span**: The 1-3 most important words or value from full_phrase\n5. **start_page_key**: ONLY use format `page_number_N_index_I` from page tags (e.g., `<page_number_1_index_0>`). Never extract page numbers from document content.\n6. **line_ids**: Inclusive range (e.g., '2-6' or '4'). Infer intermediate lines since only every 5th line is shown.\n\n### Placement Rules\n\n- Place <cite /> inline, typically at the end of a claim\n- One citation per distinct idea, concept, or value (a sentence citing 3 different values needs 3 citations)\n- Do NOT group citations at the end of the document\n- The <cite /> tag is self-closing - never use <cite>...</cite>\n\n### Example Citation 1\n\nThe company reported strong growth<cite attachment_id='abc123' reasoning='directly states revenue growth percentage' full_phrase='Revenue increased 45% year-over-year to $2.3 billion' key_span='increased 45%' start_page_key='page_number_2_index_1' line_ids='12-14' />\n\n### Example Citation 2\n\nThe total amount is $500 USD <cite attachment_id='abc123' reasoning='directly states the total amount' full_phrase='The total amount is $500 USD' key_span='$500 USD' start_page_key='page_number_2_index_1' line_ids='12-14' />\n\n</citation-instructions>\n";
2
+ declare const AV_CITATION_MARKDOWN_SYNTAX_PROMPT = "\n<citation-instructions priority=\"critical\">\n## REQUIRED: Audio/Video Citation Format\n\nFor every claim, value, or fact; you MUST cite the attachment using this exact syntax:\n\n<cite attachment_id='ID' reasoning='why this supports the claim' full_phrase='verbatim transcript quote' key_span='1-3 key words' timestamps='HH:MM:SS.SSS-HH:MM:SS.SSS' />\n\n### Syntax Rules (MUST follow)\n\n1. **attachment_id**: Use the exact ID from the source\n2. **reasoning**: Brief explanation of why this citation supports your claim (think first!)\n3. **full_phrase**: Copy transcript text VERBATIM. Escape quotes (\\') and newlines (\\n).\n4. **key_span**: The 1-3 most important words or value from full_phrase\n5. **timestamps**: Start and end time with milliseconds (e.g., '00:01:23.456-00:01:45.789')\n\n### Placement Rules\n\n- Place <cite /> inline, typically at the end of a claim\n- One citation per distinct idea, concept, or value (a sentence citing 3 different values needs 3 citations)\n- Do NOT group citations at the end of the document\n- The <cite /> tag is self-closing - never use <cite>...</cite>\n\n</citation-instructions>\n";
3
3
  /**
4
4
  * A brief reminder to reinforce citation requirements in user messages.
5
5
  * Use this when you want to add emphasis without repeating full instructions.
6
6
  */
7
- declare const CITATION_REMINDER = "<citation-reminder>Remember: You MUST use <cite /> tags with all required attributes for every claim, value, or fact from source documents.</citation-reminder>";
7
+ declare const CITATION_REMINDER = "<citation-reminder>Remember: You MUST use <cite /> tags with all required attributes for every claim, value, or fact from attachments.</citation-reminder>";
8
8
  /**
9
9
  * Audio/video version of the citation reminder.
10
10
  */
@@ -33,7 +33,7 @@ interface WrapCitationPromptResult {
33
33
  }
34
34
  /**
35
35
  * Wraps your existing system prompt with DeepCitation's citation syntax instructions.
36
- * This enables LLMs to output verifiable citations that can be checked against source documents.
36
+ * This enables LLMs to output verifiable citations that can be checked against attachments.
37
37
  *
38
38
  * ## Why We Wrap (Instructions at Start + Reminder at End)
39
39
  *
@@ -1,10 +1,10 @@
1
- declare const CITATION_MARKDOWN_SYNTAX_PROMPT = "\n<citation-instructions priority=\"critical\">\n## REQUIRED: Citation Format\n\nFor every claim, value, or fact; you MUST cite sources using this exact syntax:\n\n<cite attachment_id='ID' reasoning='why this supports the claim' full_phrase='verbatim quote' key_span='1-3 key words' start_page_key='page_number_N_index_I' line_ids='X-Y' />\n\n### Syntax Rules (MUST follow)\n\n1. **attachment_id**: Use the exact ID from the source document\n2. **reasoning**: Brief explanation of why this citation supports your claim (think first!)\n3. **full_phrase**: Copy text VERBATIM from source. Escape quotes (\\') and newlines (\\n).\n4. **key_span**: The 1-3 most important words or value from full_phrase\n5. **start_page_key**: ONLY use format `page_number_N_index_I` from page tags (e.g., `<page_number_1_index_0>`). Never extract page numbers from document content.\n6. **line_ids**: Inclusive range (e.g., '2-6' or '4'). Infer intermediate lines since only every 5th line is shown.\n\n### Placement Rules\n\n- Place <cite /> inline, typically at the end of a claim\n- One citation per distinct idea, concept, or value (a sentence citing 3 different values needs 3 citations)\n- Do NOT group citations at the end of the document\n- The <cite /> tag is self-closing - never use <cite>...</cite>\n\n### Example Citation 1\n\nThe company reported strong growth<cite attachment_id='abc123' reasoning='directly states revenue growth percentage' full_phrase='Revenue increased 45% year-over-year to $2.3 billion' key_span='increased 45%' start_page_key='page_number_2_index_1' line_ids='12-14' />\n\n### Example Citation 2\n\nThe total amount is $500 USD <cite attachment_id='abc123' reasoning='directly states the total amount' full_phrase='The total amount is $500 USD' key_span='$500 USD' start_page_key='page_number_2_index_1' line_ids='12-14' />\n\n</citation-instructions>\n";
2
- declare const AV_CITATION_MARKDOWN_SYNTAX_PROMPT = "\n<citation-instructions priority=\"critical\">\n## REQUIRED: Audio/Video Citation Format\n\nFor every claim, value, or fact; you MUST cite sources using this exact syntax:\n\n<cite attachment_id='ID' reasoning='why this supports the claim' full_phrase='verbatim transcript quote' key_span='1-3 key words' timestamps='HH:MM:SS.SSS-HH:MM:SS.SSS' />\n\n### Syntax Rules (MUST follow)\n\n1. **attachment_id**: Use the exact ID from the source\n2. **reasoning**: Brief explanation of why this citation supports your claim (think first!)\n3. **full_phrase**: Copy transcript text VERBATIM. Escape quotes (\\') and newlines (\\n).\n4. **key_span**: The 1-3 most important words or value from full_phrase\n5. **timestamps**: Start and end time with milliseconds (e.g., '00:01:23.456-00:01:45.789')\n\n### Placement Rules\n\n- Place <cite /> inline, typically at the end of a claim\n- One citation per distinct idea, concept, or value (a sentence citing 3 different values needs 3 citations)\n- Do NOT group citations at the end of the document\n- The <cite /> tag is self-closing - never use <cite>...</cite>\n\n</citation-instructions>\n";
1
+ declare const CITATION_MARKDOWN_SYNTAX_PROMPT = "\n<citation-instructions priority=\"critical\">\n## REQUIRED: Citation Format\n\nFor every claim, value, or fact; you MUST cite the attachment using this exact syntax:\n\n<cite attachment_id='ID' reasoning='why this supports the claim' full_phrase='verbatim quote' key_span='1-3 key words' start_page_key='page_number_N_index_I' line_ids='X-Y' />\n\n### Syntax Rules (MUST follow)\n\n1. **attachment_id**: Use the exact ID from the source document\n2. **reasoning**: Brief explanation of why this citation supports your claim (think first!)\n3. **full_phrase**: Copy text VERBATIM from source. Escape quotes (\\') and newlines (\\n).\n4. **key_span**: The 1-3 most important words or value from full_phrase\n5. **start_page_key**: ONLY use format `page_number_N_index_I` from page tags (e.g., `<page_number_1_index_0>`). Never extract page numbers from document content.\n6. **line_ids**: Inclusive range (e.g., '2-6' or '4'). Infer intermediate lines since only every 5th line is shown.\n\n### Placement Rules\n\n- Place <cite /> inline, typically at the end of a claim\n- One citation per distinct idea, concept, or value (a sentence citing 3 different values needs 3 citations)\n- Do NOT group citations at the end of the document\n- The <cite /> tag is self-closing - never use <cite>...</cite>\n\n### Example Citation 1\n\nThe company reported strong growth<cite attachment_id='abc123' reasoning='directly states revenue growth percentage' full_phrase='Revenue increased 45% year-over-year to $2.3 billion' key_span='increased 45%' start_page_key='page_number_2_index_1' line_ids='12-14' />\n\n### Example Citation 2\n\nThe total amount is $500 USD <cite attachment_id='abc123' reasoning='directly states the total amount' full_phrase='The total amount is $500 USD' key_span='$500 USD' start_page_key='page_number_2_index_1' line_ids='12-14' />\n\n</citation-instructions>\n";
2
+ declare const AV_CITATION_MARKDOWN_SYNTAX_PROMPT = "\n<citation-instructions priority=\"critical\">\n## REQUIRED: Audio/Video Citation Format\n\nFor every claim, value, or fact; you MUST cite the attachment using this exact syntax:\n\n<cite attachment_id='ID' reasoning='why this supports the claim' full_phrase='verbatim transcript quote' key_span='1-3 key words' timestamps='HH:MM:SS.SSS-HH:MM:SS.SSS' />\n\n### Syntax Rules (MUST follow)\n\n1. **attachment_id**: Use the exact ID from the source\n2. **reasoning**: Brief explanation of why this citation supports your claim (think first!)\n3. **full_phrase**: Copy transcript text VERBATIM. Escape quotes (\\') and newlines (\\n).\n4. **key_span**: The 1-3 most important words or value from full_phrase\n5. **timestamps**: Start and end time with milliseconds (e.g., '00:01:23.456-00:01:45.789')\n\n### Placement Rules\n\n- Place <cite /> inline, typically at the end of a claim\n- One citation per distinct idea, concept, or value (a sentence citing 3 different values needs 3 citations)\n- Do NOT group citations at the end of the document\n- The <cite /> tag is self-closing - never use <cite>...</cite>\n\n</citation-instructions>\n";
3
3
  /**
4
4
  * A brief reminder to reinforce citation requirements in user messages.
5
5
  * Use this when you want to add emphasis without repeating full instructions.
6
6
  */
7
- declare const CITATION_REMINDER = "<citation-reminder>Remember: You MUST use <cite /> tags with all required attributes for every claim, value, or fact from source documents.</citation-reminder>";
7
+ declare const CITATION_REMINDER = "<citation-reminder>Remember: You MUST use <cite /> tags with all required attributes for every claim, value, or fact from attachments.</citation-reminder>";
8
8
  /**
9
9
  * Audio/video version of the citation reminder.
10
10
  */
@@ -33,7 +33,7 @@ interface WrapCitationPromptResult {
33
33
  }
34
34
  /**
35
35
  * Wraps your existing system prompt with DeepCitation's citation syntax instructions.
36
- * This enables LLMs to output verifiable citations that can be checked against source documents.
36
+ * This enables LLMs to output verifiable citations that can be checked against attachments.
37
37
  *
38
38
  * ## Why We Wrap (Instructions at Start + Reminder at End)
39
39
  *
@@ -1 +1 @@
1
- export{b as AV_CITATION_MARKDOWN_SYNTAX_PROMPT,h as CITATION_AV_BASED_JSON_OUTPUT_FORMAT,d as CITATION_AV_REMINDER,g as CITATION_JSON_OUTPUT_FORMAT,a as CITATION_MARKDOWN_SYNTAX_PROMPT,c as CITATION_REMINDER,i as compressPromptIds,j as decompressPromptIds,f as wrapCitationPrompt,e as wrapSystemCitationPrompt}from'../chunk-KSQJNKLA.js';import'../chunk-O2XFH626.js';
1
+ export{b as AV_CITATION_MARKDOWN_SYNTAX_PROMPT,h as CITATION_AV_BASED_JSON_OUTPUT_FORMAT,d as CITATION_AV_REMINDER,g as CITATION_JSON_OUTPUT_FORMAT,a as CITATION_MARKDOWN_SYNTAX_PROMPT,c as CITATION_REMINDER,i as compressPromptIds,j as decompressPromptIds,f as wrapCitationPrompt,e as wrapSystemCitationPrompt}from'../chunk-7J46JZN5.js';import'../chunk-O2XFH626.js';