@deepcitation/deepcitation-js 1.1.27 → 1.1.29
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/LICENSE +21 -21
- package/README.md +253 -253
- package/lib/chunk-2IZXUOQR.js +66 -0
- package/lib/chunk-3GR7VKUJ.cjs +1 -0
- package/lib/chunk-4FGOHQFP.cjs +66 -0
- package/lib/chunk-CFXDRAJL.cjs +1 -0
- package/lib/chunk-F2MMVEVC.cjs +1 -0
- package/lib/chunk-LSKISWWH.cjs +2 -0
- package/lib/chunk-O2XFH626.js +1 -0
- package/lib/chunk-QGXCOW3E.js +1 -0
- package/lib/chunk-RCHWBA6D.js +2 -0
- package/lib/chunk-RQPZSRID.js +1 -0
- package/lib/client/index.cjs +1 -0
- package/lib/client/{DeepCitation.d.ts → index.d.cts} +159 -3
- package/lib/client/index.d.ts +342 -2
- package/lib/client/index.js +1 -1
- package/lib/index.cjs +1 -0
- package/lib/index.d.cts +105 -0
- package/lib/index.d.ts +103 -21
- package/lib/index.js +1 -20
- package/lib/prompts/index.cjs +1 -0
- package/lib/prompts/index.d.cts +196 -0
- package/lib/prompts/index.d.ts +196 -3
- package/lib/prompts/index.js +1 -3
- package/lib/react/index.cjs +4 -0
- package/lib/react/{types.d.ts → index.d.cts} +173 -22
- package/lib/react/index.d.ts +461 -12
- package/lib/react/index.js +4 -20
- package/lib/types/index.cjs +1 -0
- package/lib/types/index.d.cts +96 -0
- package/lib/types/index.d.ts +96 -11
- package/lib/types/index.js +1 -7
- package/lib/utils-CSqRI6NU.d.cts +45 -0
- package/lib/{react/utils.d.ts → utils-D_wxy_ni.d.ts} +13 -12
- package/package.json +46 -11
- package/lib/client/DeepCitation.js +0 -374
- package/lib/client/types.d.ts +0 -154
- package/lib/client/types.js +0 -1
- package/lib/parsing/normalizeCitation.d.ts +0 -5
- package/lib/parsing/normalizeCitation.js +0 -198
- package/lib/parsing/parseCitation.d.ts +0 -79
- package/lib/parsing/parseCitation.js +0 -431
- package/lib/parsing/parseWorkAround.d.ts +0 -2
- package/lib/parsing/parseWorkAround.js +0 -73
- package/lib/prompts/citationPrompts.d.ts +0 -138
- package/lib/prompts/citationPrompts.js +0 -168
- package/lib/prompts/promptCompression.d.ts +0 -14
- package/lib/prompts/promptCompression.js +0 -127
- package/lib/prompts/types.d.ts +0 -4
- package/lib/prompts/types.js +0 -1
- package/lib/react/CitationComponent.d.ts +0 -106
- package/lib/react/CitationComponent.js +0 -419
- package/lib/react/CitationVariants.d.ts +0 -132
- package/lib/react/CitationVariants.js +0 -277
- package/lib/react/DiffDisplay.d.ts +0 -10
- package/lib/react/DiffDisplay.js +0 -33
- package/lib/react/Popover.d.ts +0 -15
- package/lib/react/Popover.js +0 -20
- package/lib/react/UrlCitationComponent.d.ts +0 -83
- package/lib/react/UrlCitationComponent.js +0 -224
- package/lib/react/VerificationTabs.d.ts +0 -10
- package/lib/react/VerificationTabs.js +0 -36
- package/lib/react/icons.d.ts +0 -22
- package/lib/react/icons.js +0 -16
- package/lib/react/primitives.d.ts +0 -99
- package/lib/react/primitives.js +0 -187
- package/lib/react/types.js +0 -1
- package/lib/react/useSmartDiff.d.ts +0 -16
- package/lib/react/useSmartDiff.js +0 -64
- package/lib/react/utils.js +0 -88
- package/lib/types/boxes.d.ts +0 -11
- package/lib/types/boxes.js +0 -1
- package/lib/types/citation.d.ts +0 -39
- package/lib/types/citation.js +0 -1
- package/lib/types/search.d.ts +0 -19
- package/lib/types/search.js +0 -1
- package/lib/types/verification.d.ts +0 -27
- package/lib/types/verification.js +0 -11
- package/lib/utils/diff.d.ts +0 -60
- package/lib/utils/diff.js +0 -414
- package/lib/utils/sha.d.ts +0 -10
- package/lib/utils/sha.js +0 -108
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
'use strict';var y=`
|
|
2
|
+
<citation-instructions priority="critical">
|
|
3
|
+
## REQUIRED: Citation Format
|
|
4
|
+
|
|
5
|
+
You MUST cite sources using this exact syntax:
|
|
6
|
+
|
|
7
|
+
<cite attachment_id='ID' reasoning='why this supports the claim' key_span='1-3 key words' full_phrase='verbatim quote' start_page_key='page_number_N_index_I' line_ids='X-Y' />
|
|
8
|
+
|
|
9
|
+
### Syntax Rules (MUST follow)
|
|
10
|
+
|
|
11
|
+
1. **attachment_id**: Use the exact ID from the source document
|
|
12
|
+
2. **reasoning**: Brief explanation of why this citation supports your claim (think first!)
|
|
13
|
+
3. **key_span**: The 1-3 most important words from full_phrase
|
|
14
|
+
4. **full_phrase**: Copy text VERBATIM from source. Escape quotes (\\') and newlines (\\n).
|
|
15
|
+
5. **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.
|
|
16
|
+
6. **line_ids**: Inclusive range (e.g., '2-6' or '4'). Infer intermediate lines since only every 5th line is shown.
|
|
17
|
+
|
|
18
|
+
### Placement Rules
|
|
19
|
+
|
|
20
|
+
- Place <cite /> inline, typically at the end of a claim
|
|
21
|
+
- One citation per distinct idea, concept, or value (a sentence citing 3 different values needs 3 citations)
|
|
22
|
+
- Do NOT group citations at the end of the document
|
|
23
|
+
- The <cite /> tag is self-closing - never use <cite>...</cite>
|
|
24
|
+
|
|
25
|
+
### Example
|
|
26
|
+
|
|
27
|
+
The company reported strong growth<cite attachment_id='abc123' reasoning='directly states revenue growth percentage' key_span='increased 45%' full_phrase='Revenue increased 45% year-over-year to $2.3 billion' start_page_key='page_number_2_index_1' line_ids='12-14' />
|
|
28
|
+
|
|
29
|
+
</citation-instructions>
|
|
30
|
+
`,T=`
|
|
31
|
+
<citation-instructions priority="critical">
|
|
32
|
+
## REQUIRED: Audio/Video Citation Format
|
|
33
|
+
|
|
34
|
+
You MUST cite sources using this exact syntax:
|
|
35
|
+
|
|
36
|
+
<cite attachment_id='ID' reasoning='why this supports the claim' key_span='1-3 key words' full_phrase='verbatim transcript quote' timestamps='HH:MM:SS.SSS-HH:MM:SS.SSS' />
|
|
37
|
+
|
|
38
|
+
### Syntax Rules (MUST follow)
|
|
39
|
+
|
|
40
|
+
1. **attachment_id**: Use the exact ID from the source
|
|
41
|
+
2. **reasoning**: Brief explanation of why this citation supports your claim (think first!)
|
|
42
|
+
3. **key_span**: The 1-3 most important words from full_phrase
|
|
43
|
+
4. **full_phrase**: Copy transcript text VERBATIM. Escape quotes (\\') and newlines (\\n).
|
|
44
|
+
5. **timestamps**: Start and end time with milliseconds (e.g., '00:01:23.456-00:01:45.789')
|
|
45
|
+
|
|
46
|
+
### Placement Rules
|
|
47
|
+
|
|
48
|
+
- Place <cite /> inline, typically at the end of a claim
|
|
49
|
+
- One citation per distinct idea, concept, or value (a sentence citing 3 different values needs 3 citations)
|
|
50
|
+
- Do NOT group citations at the end of the document
|
|
51
|
+
- The <cite /> tag is self-closing - never use <cite>...</cite>
|
|
52
|
+
|
|
53
|
+
</citation-instructions>
|
|
54
|
+
`,u="<citation-reminder>Remember: You MUST use <cite /> tags with all required attributes for every claim from source documents.</citation-reminder>",f="<citation-reminder>Remember: You MUST use <cite /> tags with timestamps for every claim from source media.</citation-reminder>";function x(i){let{systemPrompt:r,isAudioVideo:s=false}=i,e=s?T:y,t=s?f:u;return `${e.trim()}
|
|
55
|
+
|
|
56
|
+
${r.trim()}
|
|
57
|
+
|
|
58
|
+
${t}`}function S(i){let{systemPrompt:r,userPrompt:s,deepTextPromptPortion:e,isAudioVideo:t=false,addUserReminder:o=false}=i,c=x({systemPrompt:r,isAudioVideo:t}),n=s;if(e){let a=Array.isArray(e)?e:[e];n=`${a.map((l,m)=>a.length===1?`
|
|
59
|
+
${l}`:`
|
|
60
|
+
${l}`).join(`
|
|
61
|
+
|
|
62
|
+
`)}
|
|
63
|
+
|
|
64
|
+
${s}`;}return o&&(n=`${n}
|
|
65
|
+
|
|
66
|
+
${t?f:u}`),{enhancedSystemPrompt:c,enhancedUserPrompt:n}}var O={type:"object",properties:{attachmentId:{type:"string"},reasoning:{type:"string",description:"The logic connecting the form section requirements to the supporting source citation (think first!)"},keySpan:{type:"string",description:"The verbatim 1-3 words within fullPhrase that best support the citation"},fullPhrase:{type:"string",description:"The verbatim text of the terse phrase inside <attachment_text /> to support the citation (if there is a detected OCR correction, use the corrected text)"},startPageKey:{type:"string",description:'Only return a result like "page_number_PAGE_index_INDEX" from the provided page keys (e.g. <page_number_1_index_0>) and never from the contents inside the page.'},lineIds:{type:"array",items:{type:"number"},description:"Infer lineIds, as we only provide the first, last, and every 5th line. Provide inclusive lineIds for the fullPhrase."}},required:["attachmentId","reasoning","keySpan","fullPhrase","startPageKey","lineIds"]},A={type:"object",properties:{attachmentId:{type:"string"},startPageKey:{type:"string",description:'Only return a result like "page_number_PAGE_index_INDEX" from the provided page keys (e.g. <page_number_1_index_0>) and never from the contents inside the page.'},fullPhrase:{type:"string",description:"The exact verbatim text of the phrase or paragraph from the source document to support the citation (if there is a detected OCR correction, use the verbatim corrected text)"},timestamps:{type:"object",properties:{startTime:{type:"string"},endTime:{type:"string"}},required:["startTime","endTime"],description:"The timestamp of the audio or video frame including milliseconds formatted as: HH:MM:SS.SSS"}},required:["attachmentId","startPageKey","fullPhrase","timestamps"]};var d=4,I=3,P=5;function R(i,r){let s={};for(let e of i){for(let t=d;t<=e.length;t++){let o=e.slice(0,t),c=(o.match(/\d/g)||[]).length,n=(o.match(/[a-zA-Z]/g)||[]).length;if(o.length<d||c>0&&n<I||c===0&&n<P||i.some(m=>m!==e&&m.startsWith(o)))continue;let a=m=>m.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&"),p=(r.match(new RegExp(a(o),"g"))||[]).length,l=(r.match(new RegExp(a(e),"g"))||[]).length;if(p===l){s[o]=e;break}}if(!Object.values(s).includes(e))throw new Error(`Cannot find a safe unique prefix for ID "${e}" that meets the minimum requirements (length: ${d})`)}return s}function E(i,r){if(!r||r.length===0)return {compressed:i,prefixMap:{}};let s=Array.from(new Set(r)),e=JSON.stringify(i),t=R(s,e),o=Object.keys(t).sort((n,a)=>a.length-n.length),c=e;for(let n of o){let p=t[n].replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&");c=c.replace(new RegExp(p,"g"),n);}return {compressed:JSON.parse(c),prefixMap:t}}function b(i,r){if(!r||Object.keys(r).length===0)return i;let s=Object.entries(r).sort((p,l)=>l[0].length-p[0].length),e,t=false;typeof i=="string"?e=i:(e=JSON.stringify(i),t=true);let o=e?.length;for(let[p,l]of s){let m=p.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&");e=e.replace(new RegExp(m,"g"),l);}let c=["attachmentId","attachment_id","attachment_ID","attachmentID","fileId","file_id","file_ID","fileID","fileid"];for(let[p,l]of s){let m=p.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&"),g=c.join("|"),h="([\"'`])",_=new RegExp(`(${g})(\\s*=\\s*)${h}${m}\\3`,"g");e=e.replace(_,`$1$2$3${l}$3`);}let n=e?.length,a=o-n;if(a>0)throw new Error(`[decompressedPromptIds] diff ${a} originalLength ${o} newLength ${n}`);return t?JSON.parse(e):e}exports.a=y;exports.b=T;exports.c=u;exports.d=f;exports.e=x;exports.f=S;exports.g=O;exports.h=A;exports.i=E;exports.j=b;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';var e="avif";var t=-1,n=-2,r={attachmentId:null,verifiedPageNumber:t,verifiedMatchSnippet:null,citation:{pageNumber:t},status:"not_found"};exports.a=e;exports.b=t;exports.c=n;exports.d=r;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';var d=Object.defineProperty;var e=(b,a,c)=>a in b?d(b,a,{enumerable:true,configurable:true,writable:true,value:c}):b[a]=c;var f=(b,a,c)=>e(b,typeof a!="symbol"?a+"":a,c);exports.a=f;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
'use strict';var chunk3GR7VKUJ_cjs=require('./chunk-3GR7VKUJ.cjs'),chunkF2MMVEVC_cjs=require('./chunk-F2MMVEVC.cjs');function E(t){if(!t)return;let e=[],n=t.split(",");for(let s of n){let i=s.trim();if(i)if(i.includes("-")){let[r,a]=i.split("-"),o=parseInt(r,10),p=parseInt(a,10);if(!isNaN(o)&&!isNaN(p)&&o<=p)for(let c=o;c<=p;c++)e.push(c);else isNaN(o)||e.push(o);}else {let r=parseInt(i,10);isNaN(r)||e.push(r);}}if(e.length!==0)return [...new Set(e)].sort((s,i)=>s-i)}function q(t){let e=t?.status,n=e==="not_found",s=e==="found_phrase_missed_value",i=e==="found_key_span_only",r=e==="partial_text_found"||e==="found_on_other_page"||e==="found_on_other_line"||e==="first_word_found";return {isVerified:e==="found"||i||r||s,isMiss:n,isPartialMatch:r,isPending:e==="pending"||e==="loading"||!e}}var M=(t,e,n,s)=>{let i=f=>f?f.replace(/^['"]|['"]$/g,"").replace(/\\'/g,"'"):void 0,r=n?.current?n.current++:void 0,a=t.substring(0,t.indexOf("<cite")),o=t.includes("/>")?t.slice(t.indexOf("/>")+2):"",p=t.substring(t.indexOf("<cite"),t.indexOf("/>")+2),c=(f,y)=>{for(let N of y){let D=new RegExp(`${N}='((?:[^'\\\\]|\\\\.)*)'`),v=f.match(D);if(v)return v[1]}},l=c(p,["attachment_id","attachmentId","file_id","fileId"]),h=l?.length===20?l:e||l,m=c(p,["start_page_key","startPageKey","start_page"]),d,_;if(m){let f=m.match(/page[\_a-zA-Z]*(\d+)_index_(\d+)/);f&&(d=parseInt(f[1]),_=parseInt(f[2]));}let B=i(c(p,["full_phrase","fullPhrase"])),T=i(c(p,["key_span","keySpan"])),V=i(c(p,["reasoning"])),K=i(c(p,["value"])),b;try{let y=c(p,["line_ids","lineIds"])?.replace(/[A-Za-z_[\](){}:]/g,"");b=y?E(y):void 0;}catch(f){s&&console.error("Error parsing lineIds",f);}let w=c(p,["timestamps"]),k;if(w){let[f,y]=w.split("-")||[];k={startTime:f,endTime:y};}let $={attachmentId:h,pageNumber:d,startPageKey:`page_number_${d||1}_index_${_||0}`,fullPhrase:B,keySpan:T||K,citationNumber:r,lineIds:b,beforeCite:a,timestamps:k,reasoning:V};return {beforeCite:a,afterCite:o,citation:$}},z=(t,e)=>{if(!t)return null;let n=t.fullPhrase??t.full_phrase,s=t.startPageKey??t.start_page_key,i=t.keySpan??t.key_span,r=t.lineIds??t.line_ids,a=t.attachmentId??t.attachment_id??t.fileId??t.file_id,o=t.reasoning,p=t.value;if(!n)return null;let c;if(s){let m=s.match(/page[_a-zA-Z]*(\d+)_index_(\d+)/i);if(m)c=parseInt(m[1],10);else {let d=s.match(/^(\d+)_(\d+)$/);d&&(c=parseInt(d[1],10));}}let l=r?.length?[...r].sort((m,d)=>m-d):void 0;return {attachmentId:a,pageNumber:c,fullPhrase:n,citationNumber:e,lineIds:l,keySpan:i||p,reasoning:o}},O=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),I=t=>Array.isArray(t)?t.length>0&&t.some(O):typeof t=="object"&&t!==null?O(t):false,x=t=>{let e={},n=Array.isArray(t)?t:[t],s=1;for(let i of n){let r=z(i,s++);if(r&&r.fullPhrase){let a=chunk3GR7VKUJ_cjs.h(r);e[a]=r;}}return e},P=(t,e)=>{if(!(!t||typeof t!="object")){if(t.citation&&I(t.citation)){let n=Array.isArray(t.citation)?t.citation:[t.citation];e.push(...n);}if(t.citations&&I(t.citations)){let n=Array.isArray(t.citations)?t.citations:[t.citations];e.push(...n);}if(Array.isArray(t))for(let n of t)P(n,e);else for(let n of Object.keys(t))n!=="citation"&&n!=="citations"&&P(t[n],e);}},R=t=>{let e=chunk3GR7VKUJ_cjs.e(t),n=/<cite\s+[^>]*\/>/g,s=e.match(n);if(!s||s.length===0)return {};let i={},r={current:1};for(let a of s){let{citation:o}=M(a,void 0,r);if(o&&o.fullPhrase){let p=chunk3GR7VKUJ_cjs.h(o);i[p]=o;}}return i},S=t=>{if(!t)return {};let e={};if(typeof t=="object"){if(I(t)){let i=x(t);Object.assign(e,i);}else {let i=[];if(P(t,i),i.length>0){let r=x(i);Object.assign(e,r);}}let n=JSON.stringify(t),s=R(n);Object.assign(e,s);}else if(typeof t=="string"){let n=R(t);Object.assign(e,n);}return e};function Z(t){let e=new Map,n=Array.isArray(t)?t.map((s,i)=>[chunk3GR7VKUJ_cjs.h(s)||String(i+1),s]):Object.entries(t);for(let[s,i]of n){let r=i.attachmentId||"";e.has(r)||e.set(r,{}),e.get(r)[s]=i;}return e}function G(t){let e={},n=Array.isArray(t)?t.map((s,i)=>[chunk3GR7VKUJ_cjs.h(s)||String(i+1),s]):Object.entries(t);for(let[s,i]of n){let r=i.attachmentId||"";e[r]||(e[r]={}),e[r][s]=i;}return e}var L="https://api.deepcitation.com";function U(t,e){if(typeof Buffer<"u"&&Buffer.isBuffer(t)){let n=Uint8Array.from(t);return {blob:new Blob([n]),name:e||"document"}}if(t instanceof Blob)return {blob:t,name:e||(t instanceof File?t.name:"document")};throw new Error("Invalid file type. Expected File, Blob, or Buffer.")}async function g(t,e){return (await t.json().catch(()=>({})))?.error?.message||`${e} failed with status ${t.status}`}var F=class{constructor(e){chunkF2MMVEVC_cjs.a(this,"apiKey");chunkF2MMVEVC_cjs.a(this,"apiUrl");if(!e.apiKey)throw new Error("DeepCitation API key is required. Get one at https://deepcitation.com/dashboard");this.apiKey=e.apiKey,this.apiUrl=e.apiUrl?.replace(/\/$/,"")||L;}async uploadFile(e,n){let{blob:s,name:i}=U(e,n?.filename),r=new FormData;r.append("file",s,i),n?.attachmentId&&r.append("attachmentId",n.attachmentId),n?.filename&&r.append("filename",n.filename);let a=await fetch(`${this.apiUrl}/prepareFile`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`},body:r});if(!a.ok)throw new Error(await g(a,"Upload"));return await a.json()}async convertToPdf(e){let n=typeof e=="string"?{url:e}:e,{url:s,file:i,filename:r,attachmentId:a}=n;if(!s&&!i)throw new Error("Either url or file must be provided");let o;if(s)o=await fetch(`${this.apiUrl}/convertFile`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},body:JSON.stringify({url:s,filename:r,attachmentId:a})});else {let{blob:p,name:c}=U(i,r),l=new FormData;l.append("file",p,c),a&&l.append("attachmentId",a),r&&l.append("filename",r),o=await fetch(`${this.apiUrl}/convertFile`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`},body:l});}if(!o.ok)throw new Error(await g(o,"Conversion"));return await o.json()}async prepareConvertedFile(e){let n=await fetch(`${this.apiUrl}/prepareFile`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},body:JSON.stringify({attachmentId:e.attachmentId})});if(!n.ok)throw new Error(await g(n,"Prepare"));return await n.json()}async prepareFiles(e){if(e.length===0)return {fileDataParts:[],deepTextPromptPortion:[]};let n=e.map(({file:a,filename:o,attachmentId:p})=>this.uploadFile(a,{filename:o,attachmentId:p}).then(c=>({result:c,filename:o}))),i=(await Promise.all(n)).map(({result:a,filename:o})=>({attachmentId:a.attachmentId,deepTextPromptPortion:a.deepTextPromptPortion,filename:o||a.metadata?.filename})),r=i.map(a=>a.deepTextPromptPortion);return {fileDataParts:i,deepTextPromptPortion:r}}async verifyCitations(e,n,s){let i={};if(Array.isArray(n))for(let c of n){let l=chunk3GR7VKUJ_cjs.h(c);i[l]=c;}else if(typeof n=="object"&&n!==null)if("fullPhrase"in n||"value"in n){let c=chunk3GR7VKUJ_cjs.h(n);i[c]=n;}else Object.assign(i,n);else throw new Error("Invalid citations format");let r=`${this.apiUrl}/verifyCitations`,a={data:{attachmentId:e,citations:i,outputImageFormat:s?.outputImageFormat||"avif"}},o=await fetch(r,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},body:JSON.stringify(a)});if(!o.ok)throw new Error(await g(o,"Verification"));return await o.json()}async verifyCitationsFromLlmOutput(e,n){let{llmOutput:s,outputImageFormat:i="avif"}=e;if(n||(n=S(s)),Object.keys(n).length===0)return {verifications:{}};let r=new Map;for(let[c,l]of Object.entries(n)){let h=l.attachmentId||"";r.has(h)||r.set(h,{}),r.get(h)[c]=l;}let a=[];for(let[c,l]of r)c&&a.push(this.verifyCitations(c,l,{outputImageFormat:i}));let o=await Promise.all(a),p={};for(let c of o)Object.assign(p,c.verifications);return {verifications:p}}};
|
|
2
|
+
exports.a=q;exports.b=M;exports.c=S;exports.d=Z;exports.e=G;exports.f=F;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var d=Object.defineProperty;var e=(b,a,c)=>a in b?d(b,a,{enumerable:true,configurable:true,writable:true,value:c}):b[a]=c;var f=(b,a,c)=>e(b,typeof a!="symbol"?a+"":a,c);export{f as a};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var j=(e,t)=>{let o=/<cite\s+(?:fileId|attachmentId)='(\w{0,25})'\s+start_page[\_a-zA-Z]*='page[\_a-zA-Z]*(\d+)_index_(\d+)'\s+full_phrase='((?:[^'\\]|\\.)*)'\s+key_span='((?:[^'\\]|\\.)*)'\s+line(?:_ids|Ids)='([^']+)'(?:\s+(value|reasoning)='((?:[^'\\]|\\.)*)')?\s*\/>/g;return e.replace(o,(u,x,b,p,r,a,g,n)=>t&&a?.replace(/key_span=['"]|['"]/g,"")||"")},v=e=>e.replace(/<page_number_\d+_index_\d+>/g,"").replace(/<\/page_number_\d+_index_\d+>/g,"").trim(),$=e=>{let t=/<line id="[^"]*">|<\/line>/g;return e.replace(t,"")},N=e=>{if(!e)return null;let t=e.match(/\d+/)?.[0];return t?parseInt(t):null},z=e=>{let t=e?.trim()||"",o=t.split(/(<cite[\s\S]*?(?:\/>|<\/cite>))/gm);return o.length<=1?C(t):(t=o.map(u=>u.startsWith("<cite")?C(u):u).join(""),t)},C=e=>{let t=e;t=t.replace(/><\/cite>/g,"/>");let o=p=>{let r=p.toLowerCase();return r==="fullphrase"||r==="full_phrase"?"full_phrase":r==="lineids"||r==="line_ids"?"line_ids":r==="startpagekey"||r==="start_pagekey"||r==="start_page_key"?"start_page_key":r==="fileid"||r==="file_id"||r==="attachmentid"||r==="attachment_id"?"attachment_id":r==="keyspan"||r==="key_span"?"key_span":r==="reasoning"||r==="value"?r:r==="timestamps"||r==="timestamp"||r==="timestamps"?"timestamps":r},u=p=>p.replace(/"/g,'"').replace(/'/g,"'").replace(/</g,"<").replace(/>/g,">").replace(/&/g,"&"),x=/(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;t=t.replace(x,(p,r,a,g)=>{let n=g;return n.endsWith(a)&&(n=n.slice(0,-1)),n=n.replace(/(\r?\n)+/g," "),n=u(n),n=n.replace(/(\*|_){2,}/g,""),n=n.replace(/\\\\'/g,"'"),n=n.replace(/\\'/g,"'"),n=n.replace(/'/g,"\\'"),n=n.replace(/\\\\"/g,'"'),n=n.replace(/\\"/g,'"'),n=n.replace(/"/g,'\\"'),n=n.replace(/\*/g,""),`${o(r)}='${n}'`}),t=t.replace(/(line_ids|lineIds|timestamps)=['"]?([\[\]\(\){}A-Za-z0-9_\-, ]+)['"]?(\s*\/?>|\s+)/gm,(p,r,a,g)=>{let n=a.replace(/[A-Za-z\[\]\(\){}]/g,"");return n=n.replace(/(\d+)-(\d+)/g,(k,h,i)=>{let d=parseInt(h,10),m=parseInt(i,10),s=[];if(d<=m)for(let c=d;c<=m;c++)s.push(c);else s.push(d);return s.join(",")}),n=n.replace(/,+/g,",").replace(/^,|,$/g,""),`${o(r)}='${n}'${g}`});let b=p=>{let r=/([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(['"])((?:[^'"\\\n]|\\.)*)(?:\2)/g,a={},g;for(;g=r.exec(p);){let s=g[1],c=g[3],f=o(s);a[f]=c;}let n=Object.keys(a);if(n.length===0)return p;let k=typeof a.timestamps=="string"&&a.timestamps.length>0,h=n.filter(s=>s.startsWith("start_page")),i=[];a.attachment_id&&i.push("attachment_id"),k?(a.full_phrase&&i.push("full_phrase"),i.push("timestamps")):(h.includes("start_page_key")&&i.push("start_page_key"),h.filter(s=>s!=="start_page_key").sort().forEach(s=>i.push(s)),a.full_phrase&&i.push("full_phrase"),a.key_span&&i.push("key_span"),a.line_ids&&i.push("line_ids")),a.reasoning&&i.push("reasoning"),a.value&&i.push("value");let d=new Set(i);return n.filter(s=>!d.has(s)).sort().forEach(s=>i.push(s)),`<cite ${i.map(s=>`${s}='${a[s]}'`).join(" ")} />`};return t=t.replace(/<cite\b[\s\S]*?\/>/gm,p=>b(p)),t};function w(e){return new TextEncoder().encode(e)}function T(e){let t=1732584193,o=4023233417,u=2562383102,x=271733878,b=3285377520,p=e.length,r=p*8,a=p+1+8,g=Math.ceil(a/64)*64,n=new ArrayBuffer(g),k=new Uint8Array(n),h=new DataView(n);k.set(e),k[p]=128,h.setUint32(g-8,Math.floor(r/4294967296),false),h.setUint32(g-4,r>>>0,false);let i=new Uint32Array(80);for(let m=0;m<g;m+=64){for(let l=0;l<16;l++)i[l]=h.getUint32(m+l*4,false);for(let l=16;l<80;l++){let y=i[l-3]^i[l-8]^i[l-14]^i[l-16];i[l]=y<<1|y>>>31;}let s=t,c=o,f=u,_=x,S=b;for(let l=0;l<80;l++){let y,I;l<20?(y=c&f|~c&_,I=1518500249):l<40?(y=c^f^_,I=1859775393):l<60?(y=c&f|c&_|f&_,I=2400959708):(y=c^f^_,I=3395469782);let P=(s<<5|s>>>27)+y+S+I+i[l]>>>0;S=_,_=f,f=(c<<30|c>>>2)>>>0,c=s,s=P;}t=t+s>>>0,o=o+c>>>0,u=u+f>>>0,x=x+_>>>0,b=b+S>>>0;}let d=m=>m.toString(16).padStart(8,"0");return d(t)+d(o)+d(u)+d(x)+d(b)}function A(e){try{if(!e)return "";let t=typeof e=="string"?e:JSON.stringify(e);return T(w(t))}catch(t){console.error("Error in making the hash:",t);}return ""}function M(...e){return e.filter(Boolean).join(" ")}function R(e){let t=e.pageNumber||N(e.startPageKey),o=[e.attachmentId||"",t?.toString()||"",e.fullPhrase||"",e.keySpan?.toString()||"",e.lineIds?.join(",")||"",e.timestamps?.startTime||"",e.timestamps?.endTime||""];return A(o.join("|")).slice(0,16)}function U(e){let t=[e.attachmentId||"",e.label||"",e.verifiedFullPhrase||"",e.verifiedKeySpan||"",e.verifiedLineIds?.join(",")||"",e.verifiedPageNumber?.toString()||"",e.verifiedTimestamps?.startTime||"",e.verifiedTimestamps?.endTime||"",e.verifiedMatchSnippet||"",e.hitIndexWithinPage?.toString()||""];return A(t.join("|")).slice(0,16)}function V(e){let t=Math.random().toString(36).slice(2,11);return `${e}-${t}`}function Z(e,t={}){let{fallbackDisplay:o}=t;return e.keySpan?.toString()||e.citationNumber?.toString()||o||"1"}function O(e){return e.citationNumber?.toString()||"1"}function W(e){return e.keySpan?.toString()||""}function B(...e){return e.filter(Boolean).join(" ")}var H=4,G=1;export{j as a,v as b,$ as c,N as d,z as e,A as f,M as g,R as h,U as i,V as j,Z as k,O as l,W as m,B as n,H as o,G as p};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import {h,e}from'./chunk-QGXCOW3E.js';import {a}from'./chunk-O2XFH626.js';function E(t){if(!t)return;let e=[],n=t.split(",");for(let s of n){let i=s.trim();if(i)if(i.includes("-")){let[r,a]=i.split("-"),o=parseInt(r,10),p=parseInt(a,10);if(!isNaN(o)&&!isNaN(p)&&o<=p)for(let c=o;c<=p;c++)e.push(c);else isNaN(o)||e.push(o);}else {let r=parseInt(i,10);isNaN(r)||e.push(r);}}if(e.length!==0)return [...new Set(e)].sort((s,i)=>s-i)}function q(t){let e=t?.status,n=e==="not_found",s=e==="found_phrase_missed_value",i=e==="found_key_span_only",r=e==="partial_text_found"||e==="found_on_other_page"||e==="found_on_other_line"||e==="first_word_found";return {isVerified:e==="found"||i||r||s,isMiss:n,isPartialMatch:r,isPending:e==="pending"||e==="loading"||!e}}var M=(t,e,n,s)=>{let i=f=>f?f.replace(/^['"]|['"]$/g,"").replace(/\\'/g,"'"):void 0,r=n?.current?n.current++:void 0,a=t.substring(0,t.indexOf("<cite")),o=t.includes("/>")?t.slice(t.indexOf("/>")+2):"",p=t.substring(t.indexOf("<cite"),t.indexOf("/>")+2),c=(f,y)=>{for(let N of y){let D=new RegExp(`${N}='((?:[^'\\\\]|\\\\.)*)'`),v=f.match(D);if(v)return v[1]}},l=c(p,["attachment_id","attachmentId","file_id","fileId"]),h=l?.length===20?l:e||l,m=c(p,["start_page_key","startPageKey","start_page"]),d,_;if(m){let f=m.match(/page[\_a-zA-Z]*(\d+)_index_(\d+)/);f&&(d=parseInt(f[1]),_=parseInt(f[2]));}let B=i(c(p,["full_phrase","fullPhrase"])),T=i(c(p,["key_span","keySpan"])),V=i(c(p,["reasoning"])),K=i(c(p,["value"])),b;try{let y=c(p,["line_ids","lineIds"])?.replace(/[A-Za-z_[\](){}:]/g,"");b=y?E(y):void 0;}catch(f){s&&console.error("Error parsing lineIds",f);}let w=c(p,["timestamps"]),k;if(w){let[f,y]=w.split("-")||[];k={startTime:f,endTime:y};}let $={attachmentId:h,pageNumber:d,startPageKey:`page_number_${d||1}_index_${_||0}`,fullPhrase:B,keySpan:T||K,citationNumber:r,lineIds:b,beforeCite:a,timestamps:k,reasoning:V};return {beforeCite:a,afterCite:o,citation:$}},z=(t,e)=>{if(!t)return null;let n=t.fullPhrase??t.full_phrase,s=t.startPageKey??t.start_page_key,i=t.keySpan??t.key_span,r=t.lineIds??t.line_ids,a=t.attachmentId??t.attachment_id??t.fileId??t.file_id,o=t.reasoning,p=t.value;if(!n)return null;let c;if(s){let m=s.match(/page[_a-zA-Z]*(\d+)_index_(\d+)/i);if(m)c=parseInt(m[1],10);else {let d=s.match(/^(\d+)_(\d+)$/);d&&(c=parseInt(d[1],10));}}let l=r?.length?[...r].sort((m,d)=>m-d):void 0;return {attachmentId:a,pageNumber:c,fullPhrase:n,citationNumber:e,lineIds:l,keySpan:i||p,reasoning:o}},O=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),I=t=>Array.isArray(t)?t.length>0&&t.some(O):typeof t=="object"&&t!==null?O(t):false,x=t=>{let e={},n=Array.isArray(t)?t:[t],s=1;for(let i of n){let r=z(i,s++);if(r&&r.fullPhrase){let a=h(r);e[a]=r;}}return e},P=(t,e)=>{if(!(!t||typeof t!="object")){if(t.citation&&I(t.citation)){let n=Array.isArray(t.citation)?t.citation:[t.citation];e.push(...n);}if(t.citations&&I(t.citations)){let n=Array.isArray(t.citations)?t.citations:[t.citations];e.push(...n);}if(Array.isArray(t))for(let n of t)P(n,e);else for(let n of Object.keys(t))n!=="citation"&&n!=="citations"&&P(t[n],e);}},R=t=>{let e$1=e(t),n=/<cite\s+[^>]*\/>/g,s=e$1.match(n);if(!s||s.length===0)return {};let i={},r={current:1};for(let a of s){let{citation:o}=M(a,void 0,r);if(o&&o.fullPhrase){let p=h(o);i[p]=o;}}return i},S=t=>{if(!t)return {};let e={};if(typeof t=="object"){if(I(t)){let i=x(t);Object.assign(e,i);}else {let i=[];if(P(t,i),i.length>0){let r=x(i);Object.assign(e,r);}}let n=JSON.stringify(t),s=R(n);Object.assign(e,s);}else if(typeof t=="string"){let n=R(t);Object.assign(e,n);}return e};function Z(t){let e=new Map,n=Array.isArray(t)?t.map((s,i)=>[h(s)||String(i+1),s]):Object.entries(t);for(let[s,i]of n){let r=i.attachmentId||"";e.has(r)||e.set(r,{}),e.get(r)[s]=i;}return e}function G(t){let e={},n=Array.isArray(t)?t.map((s,i)=>[h(s)||String(i+1),s]):Object.entries(t);for(let[s,i]of n){let r=i.attachmentId||"";e[r]||(e[r]={}),e[r][s]=i;}return e}var L="https://api.deepcitation.com";function U(t,e){if(typeof Buffer<"u"&&Buffer.isBuffer(t)){let n=Uint8Array.from(t);return {blob:new Blob([n]),name:e||"document"}}if(t instanceof Blob)return {blob:t,name:e||(t instanceof File?t.name:"document")};throw new Error("Invalid file type. Expected File, Blob, or Buffer.")}async function g(t,e){return (await t.json().catch(()=>({})))?.error?.message||`${e} failed with status ${t.status}`}var F=class{constructor(e){a(this,"apiKey");a(this,"apiUrl");if(!e.apiKey)throw new Error("DeepCitation API key is required. Get one at https://deepcitation.com/dashboard");this.apiKey=e.apiKey,this.apiUrl=e.apiUrl?.replace(/\/$/,"")||L;}async uploadFile(e,n){let{blob:s,name:i}=U(e,n?.filename),r=new FormData;r.append("file",s,i),n?.attachmentId&&r.append("attachmentId",n.attachmentId),n?.filename&&r.append("filename",n.filename);let a=await fetch(`${this.apiUrl}/prepareFile`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`},body:r});if(!a.ok)throw new Error(await g(a,"Upload"));return await a.json()}async convertToPdf(e){let n=typeof e=="string"?{url:e}:e,{url:s,file:i,filename:r,attachmentId:a}=n;if(!s&&!i)throw new Error("Either url or file must be provided");let o;if(s)o=await fetch(`${this.apiUrl}/convertFile`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},body:JSON.stringify({url:s,filename:r,attachmentId:a})});else {let{blob:p,name:c}=U(i,r),l=new FormData;l.append("file",p,c),a&&l.append("attachmentId",a),r&&l.append("filename",r),o=await fetch(`${this.apiUrl}/convertFile`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`},body:l});}if(!o.ok)throw new Error(await g(o,"Conversion"));return await o.json()}async prepareConvertedFile(e){let n=await fetch(`${this.apiUrl}/prepareFile`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},body:JSON.stringify({attachmentId:e.attachmentId})});if(!n.ok)throw new Error(await g(n,"Prepare"));return await n.json()}async prepareFiles(e){if(e.length===0)return {fileDataParts:[],deepTextPromptPortion:[]};let n=e.map(({file:a,filename:o,attachmentId:p})=>this.uploadFile(a,{filename:o,attachmentId:p}).then(c=>({result:c,filename:o}))),i=(await Promise.all(n)).map(({result:a,filename:o})=>({attachmentId:a.attachmentId,deepTextPromptPortion:a.deepTextPromptPortion,filename:o||a.metadata?.filename})),r=i.map(a=>a.deepTextPromptPortion);return {fileDataParts:i,deepTextPromptPortion:r}}async verifyCitations(e,n,s){let i={};if(Array.isArray(n))for(let c of n){let l=h(c);i[l]=c;}else if(typeof n=="object"&&n!==null)if("fullPhrase"in n||"value"in n){let c=h(n);i[c]=n;}else Object.assign(i,n);else throw new Error("Invalid citations format");let r=`${this.apiUrl}/verifyCitations`,a={data:{attachmentId:e,citations:i,outputImageFormat:s?.outputImageFormat||"avif"}},o=await fetch(r,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},body:JSON.stringify(a)});if(!o.ok)throw new Error(await g(o,"Verification"));return await o.json()}async verifyCitationsFromLlmOutput(e,n){let{llmOutput:s,outputImageFormat:i="avif"}=e;if(n||(n=S(s)),Object.keys(n).length===0)return {verifications:{}};let r=new Map;for(let[c,l]of Object.entries(n)){let h=l.attachmentId||"";r.has(h)||r.set(h,{}),r.get(h)[c]=l;}let a=[];for(let[c,l]of r)c&&a.push(this.verifyCitations(c,l,{outputImageFormat:i}));let o=await Promise.all(a),p={};for(let c of o)Object.assign(p,c.verifications);return {verifications:p}}};
|
|
2
|
+
export{q as a,M as b,S as c,Z as d,G as e,F as f};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e="avif";var t=-1,n=-2,r={attachmentId:null,verifiedPageNumber:t,verifiedMatchSnippet:null,citation:{pageNumber:t},status:"not_found"};export{e as a,t as b,n as c,r as d};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';var chunkLSKISWWH_cjs=require('../chunk-LSKISWWH.cjs');require('../chunk-3GR7VKUJ.cjs'),require('../chunk-F2MMVEVC.cjs');Object.defineProperty(exports,"DeepCitation",{enumerable:true,get:function(){return chunkLSKISWWH_cjs.f}});
|
|
@@ -1,5 +1,159 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import { Citation, Verification } from '../types/index.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Configuration options for the DeepCitation client
|
|
5
|
+
*/
|
|
6
|
+
interface DeepCitationConfig {
|
|
7
|
+
/** Your DeepCitation API key (starts with sk-dc-) */
|
|
8
|
+
apiKey: string;
|
|
9
|
+
/** Optional custom API base URL. Defaults to https://api.deepcitation.com */
|
|
10
|
+
apiUrl?: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Response from uploading a file for citation verification
|
|
14
|
+
*/
|
|
15
|
+
interface UploadFileResponse {
|
|
16
|
+
/** The attachment ID assigned by DeepCitation (custom or auto-generated) */
|
|
17
|
+
attachmentId: string;
|
|
18
|
+
/** The full text content formatted for LLM prompts with page markers and line IDs. Use this in your user prompts. */
|
|
19
|
+
deepTextPromptPortion: string;
|
|
20
|
+
/** Form fields extracted from PDF forms */
|
|
21
|
+
formFields?: Array<{
|
|
22
|
+
name: string;
|
|
23
|
+
value?: string;
|
|
24
|
+
pageIndex?: number;
|
|
25
|
+
type?: string;
|
|
26
|
+
}>;
|
|
27
|
+
/** Metadata about the processed file */
|
|
28
|
+
metadata: {
|
|
29
|
+
filename: string;
|
|
30
|
+
mimeType: string;
|
|
31
|
+
pageCount: number;
|
|
32
|
+
textByteSize: number;
|
|
33
|
+
};
|
|
34
|
+
/** Processing status */
|
|
35
|
+
status: "ready" | "error";
|
|
36
|
+
/** Time taken to process the file in milliseconds */
|
|
37
|
+
processingTimeMs?: number;
|
|
38
|
+
/** Error message if status is "error" */
|
|
39
|
+
error?: string;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Options for file upload
|
|
43
|
+
*/
|
|
44
|
+
interface UploadFileOptions {
|
|
45
|
+
/** Optional custom attachment ID to use instead of auto-generated one */
|
|
46
|
+
attachmentId?: string;
|
|
47
|
+
/** Optional custom filename (uses File.name if not provided) */
|
|
48
|
+
filename?: string;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Response from verifying citations
|
|
52
|
+
*/
|
|
53
|
+
interface VerifyCitationsResponse {
|
|
54
|
+
/** Map of citation keys to their verification results */
|
|
55
|
+
verifications: Record<string, Verification>;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Options for citation verification
|
|
59
|
+
*/
|
|
60
|
+
interface VerifyCitationsOptions {
|
|
61
|
+
/** Output image format for verification screenshots */
|
|
62
|
+
outputImageFormat?: "jpeg" | "png" | "avif";
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Simplified citation input for verification
|
|
66
|
+
*/
|
|
67
|
+
type CitationInput = Citation | Record<string, Citation>;
|
|
68
|
+
/**
|
|
69
|
+
* Input for file upload in prepareFiles
|
|
70
|
+
*/
|
|
71
|
+
interface FileInput {
|
|
72
|
+
/** The file content (File, Blob, or Buffer) */
|
|
73
|
+
file: File | Blob | Buffer;
|
|
74
|
+
/** Optional filename */
|
|
75
|
+
filename?: string;
|
|
76
|
+
/** Optional custom attachment ID */
|
|
77
|
+
attachmentId?: string;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* File reference returned from prepareFiles
|
|
81
|
+
*/
|
|
82
|
+
interface FileDataPart {
|
|
83
|
+
/** The attachment ID assigned by DeepCitation */
|
|
84
|
+
attachmentId: string;
|
|
85
|
+
/** The formatted text content for LLM prompts (with page markers and line IDs) */
|
|
86
|
+
deepTextPromptPortion: string;
|
|
87
|
+
/** Optional filename for display purposes */
|
|
88
|
+
filename?: string;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Result from prepareFiles
|
|
92
|
+
*/
|
|
93
|
+
interface PrepareFilesResult {
|
|
94
|
+
/** Array of file references for verification (includes deepTextPromptPortion for each file) */
|
|
95
|
+
fileDataParts: FileDataPart[];
|
|
96
|
+
/**
|
|
97
|
+
* Array of formatted text content for LLM prompts (with page markers and line IDs).
|
|
98
|
+
* @deprecated Use fileDataParts[].deepTextPromptPortion instead for single source of truth.
|
|
99
|
+
* This is kept for backwards compatibility but will be removed in a future version.
|
|
100
|
+
*/
|
|
101
|
+
deepTextPromptPortion: string[];
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Input for verifyCitationsFromLlmOutput
|
|
105
|
+
*/
|
|
106
|
+
interface VerifyCitationsFromLlmOutput {
|
|
107
|
+
/** The LLM response containing citations */
|
|
108
|
+
llmOutput: string;
|
|
109
|
+
/** Optional file references (required for Zero Data Retention or after storage expires) */
|
|
110
|
+
fileDataParts?: FileDataPart[];
|
|
111
|
+
/** Output image format for verification screenshots */
|
|
112
|
+
outputImageFormat?: "jpeg" | "png" | "avif";
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Input for convertFile - convert URL or Office file to PDF
|
|
116
|
+
*/
|
|
117
|
+
interface ConvertFileInput {
|
|
118
|
+
/** URL to convert to PDF (for web pages or direct PDF links) */
|
|
119
|
+
url?: string;
|
|
120
|
+
/** Office file to convert (doc, docx, xls, xlsx, ppt, pptx, odt, ods, odp) */
|
|
121
|
+
file?: File | Blob | Buffer;
|
|
122
|
+
/** Optional custom filename for the converted PDF */
|
|
123
|
+
filename?: string;
|
|
124
|
+
/** Optional custom attachment ID */
|
|
125
|
+
attachmentId?: string;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Response from convertFile
|
|
129
|
+
*/
|
|
130
|
+
interface ConvertFileResponse {
|
|
131
|
+
/** The attachment ID assigned by DeepCitation. Pass this to prepareConvertedFile(). */
|
|
132
|
+
attachmentId: string;
|
|
133
|
+
/** Metadata about the conversion */
|
|
134
|
+
metadata: {
|
|
135
|
+
/** Original filename before conversion */
|
|
136
|
+
originalFilename: string;
|
|
137
|
+
/** Original MIME type before conversion */
|
|
138
|
+
originalMimeType: string;
|
|
139
|
+
/** MIME type after conversion (always application/pdf) */
|
|
140
|
+
convertedMimeType: string;
|
|
141
|
+
/** Time taken for conversion in milliseconds */
|
|
142
|
+
conversionTimeMs: number;
|
|
143
|
+
};
|
|
144
|
+
/** Conversion status */
|
|
145
|
+
status: "converted" | "error";
|
|
146
|
+
/** Error message if status is "error" */
|
|
147
|
+
error?: string;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Options for processing a converted file
|
|
151
|
+
*/
|
|
152
|
+
interface PrepareConvertedFileOptions {
|
|
153
|
+
/** The attachment ID from a previous convertFile call */
|
|
154
|
+
attachmentId: string;
|
|
155
|
+
}
|
|
156
|
+
|
|
3
157
|
/**
|
|
4
158
|
* DeepCitation client for file upload and citation verification.
|
|
5
159
|
*
|
|
@@ -25,7 +179,7 @@ import type { CitationInput, ConvertFileInput, ConvertFileResponse, DeepCitation
|
|
|
25
179
|
* const verified = await dc.verifyCitations(attachmentId, citations);
|
|
26
180
|
* ```
|
|
27
181
|
*/
|
|
28
|
-
|
|
182
|
+
declare class DeepCitation {
|
|
29
183
|
private readonly apiKey;
|
|
30
184
|
private readonly apiUrl;
|
|
31
185
|
/**
|
|
@@ -184,3 +338,5 @@ export declare class DeepCitation {
|
|
|
184
338
|
[key: string]: Citation;
|
|
185
339
|
}): Promise<VerifyCitationsResponse>;
|
|
186
340
|
}
|
|
341
|
+
|
|
342
|
+
export { type CitationInput, type ConvertFileInput, type ConvertFileResponse, DeepCitation, type DeepCitationConfig, type FileDataPart, type FileInput, type PrepareConvertedFileOptions, type PrepareFilesResult, type UploadFileOptions, type UploadFileResponse, type VerifyCitationsFromLlmOutput, type VerifyCitationsOptions, type VerifyCitationsResponse };
|