@deepcitation/deepcitation-js 1.1.27 → 1.1.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +253 -253
  3. package/lib/chunk-2IZXUOQR.js +66 -0
  4. package/lib/chunk-4FGOHQFP.cjs +66 -0
  5. package/lib/chunk-CFXDRAJL.cjs +1 -0
  6. package/lib/chunk-DEUSSEFH.js +2 -0
  7. package/lib/chunk-F2MMVEVC.cjs +1 -0
  8. package/lib/chunk-J7U6YFOI.cjs +2 -0
  9. package/lib/chunk-O2XFH626.js +1 -0
  10. package/lib/chunk-RQPZSRID.js +1 -0
  11. package/lib/client/index.cjs +1 -0
  12. package/lib/client/{DeepCitation.d.ts → index.d.cts} +159 -3
  13. package/lib/client/index.d.ts +342 -2
  14. package/lib/client/index.js +1 -1
  15. package/lib/index.cjs +1 -0
  16. package/lib/index.d.cts +127 -0
  17. package/lib/index.d.ts +126 -22
  18. package/lib/index.js +1 -20
  19. package/lib/prompts/index.cjs +1 -0
  20. package/lib/prompts/index.d.cts +196 -0
  21. package/lib/prompts/index.d.ts +196 -3
  22. package/lib/prompts/index.js +1 -3
  23. package/lib/react/index.cjs +4 -0
  24. package/lib/react/index.js +4 -20
  25. package/lib/types/index.cjs +1 -0
  26. package/lib/types/index.d.cts +96 -0
  27. package/lib/types/index.d.ts +96 -11
  28. package/lib/types/index.js +1 -7
  29. package/package.json +46 -11
  30. package/lib/client/DeepCitation.js +0 -374
  31. package/lib/client/types.d.ts +0 -154
  32. package/lib/client/types.js +0 -1
  33. package/lib/parsing/normalizeCitation.d.ts +0 -5
  34. package/lib/parsing/normalizeCitation.js +0 -198
  35. package/lib/parsing/parseCitation.d.ts +0 -79
  36. package/lib/parsing/parseCitation.js +0 -431
  37. package/lib/parsing/parseWorkAround.d.ts +0 -2
  38. package/lib/parsing/parseWorkAround.js +0 -73
  39. package/lib/prompts/citationPrompts.d.ts +0 -138
  40. package/lib/prompts/citationPrompts.js +0 -168
  41. package/lib/prompts/promptCompression.d.ts +0 -14
  42. package/lib/prompts/promptCompression.js +0 -127
  43. package/lib/prompts/types.d.ts +0 -4
  44. package/lib/prompts/types.js +0 -1
  45. package/lib/react/CitationComponent.d.ts +0 -106
  46. package/lib/react/CitationComponent.js +0 -419
  47. package/lib/react/CitationVariants.d.ts +0 -132
  48. package/lib/react/CitationVariants.js +0 -277
  49. package/lib/react/DiffDisplay.d.ts +0 -10
  50. package/lib/react/DiffDisplay.js +0 -33
  51. package/lib/react/Popover.d.ts +0 -15
  52. package/lib/react/Popover.js +0 -20
  53. package/lib/react/UrlCitationComponent.d.ts +0 -83
  54. package/lib/react/UrlCitationComponent.js +0 -224
  55. package/lib/react/VerificationTabs.d.ts +0 -10
  56. package/lib/react/VerificationTabs.js +0 -36
  57. package/lib/react/icons.d.ts +0 -22
  58. package/lib/react/icons.js +0 -16
  59. package/lib/react/index.d.ts +0 -17
  60. package/lib/react/primitives.d.ts +0 -99
  61. package/lib/react/primitives.js +0 -187
  62. package/lib/react/types.d.ts +0 -315
  63. package/lib/react/types.js +0 -1
  64. package/lib/react/useSmartDiff.d.ts +0 -16
  65. package/lib/react/useSmartDiff.js +0 -64
  66. package/lib/react/utils.d.ts +0 -44
  67. package/lib/react/utils.js +0 -88
  68. package/lib/types/boxes.d.ts +0 -11
  69. package/lib/types/boxes.js +0 -1
  70. package/lib/types/citation.d.ts +0 -39
  71. package/lib/types/citation.js +0 -1
  72. package/lib/types/search.d.ts +0 -19
  73. package/lib/types/search.js +0 -1
  74. package/lib/types/verification.d.ts +0 -27
  75. package/lib/types/verification.js +0 -11
  76. package/lib/utils/diff.d.ts +0 -60
  77. package/lib/utils/diff.js +0 -414
  78. package/lib/utils/sha.d.ts +0 -10
  79. package/lib/utils/sha.js +0 -108
@@ -1,2 +1,342 @@
1
- export { DeepCitation } from "./DeepCitation.js";
2
- export type { DeepCitationConfig, UploadFileResponse, UploadFileOptions, VerifyCitationsResponse, VerifyCitationsOptions, CitationInput, FileInput, FileDataPart, PrepareFilesResult, VerifyCitationsFromLlmOutput, ConvertFileInput, ConvertFileResponse, PrepareConvertedFileOptions, } from "./types.js";
1
+ import { Citation, Verification } from '../types/index.js';
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
+
157
+ /**
158
+ * DeepCitation client for file upload and citation verification.
159
+ *
160
+ * @example
161
+ * ```typescript
162
+ * import { DeepCitation } from '@deepcitation/deepcitation-js';
163
+ *
164
+ * const dc = new DeepCitation({ apiKey: process.env.DEEPCITATION_API_KEY });
165
+ *
166
+ * // Upload a file
167
+ * const { attachmentId, promptContent } = await dc.uploadFile(file);
168
+ *
169
+ * // Include promptContent in your LLM messages
170
+ * const response = await llm.chat({
171
+ * messages: [
172
+ * { role: "system", content: wrapSystemCitationPrompt({ systemPrompt }) },
173
+ * { role: "user", content: userMessage + "\n\n" + promptContent },
174
+ * ]
175
+ * });
176
+ *
177
+ * // Verify citations in the LLM output
178
+ * const citations = getAllCitationsFromLlmOutput(response);
179
+ * const verified = await dc.verifyCitations(attachmentId, citations);
180
+ * ```
181
+ */
182
+ declare class DeepCitation {
183
+ private readonly apiKey;
184
+ private readonly apiUrl;
185
+ /**
186
+ * Create a new DeepCitation client instance.
187
+ *
188
+ * @param config - Configuration options
189
+ * @throws Error if apiKey is not provided
190
+ */
191
+ constructor(config: DeepCitationConfig);
192
+ /**
193
+ * Upload a file for citation verification.
194
+ *
195
+ * Supported file types:
196
+ * - PDF documents
197
+ * - Images (PNG, JPEG, WebP, AVIF, HEIC)
198
+ * - Coming soon: DOCX, XLSX, plain text
199
+ *
200
+ * @param file - The file to upload (File, Blob, or Buffer)
201
+ * @param options - Optional upload options
202
+ * @returns Upload response with attachmentId and extracted text
203
+ *
204
+ * @example
205
+ * ```typescript
206
+ * // Browser with File object
207
+ * const file = document.querySelector('input[type="file"]').files[0];
208
+ * const result = await dc.uploadFile(file);
209
+ *
210
+ * // Node.js with Buffer
211
+ * const buffer = fs.readFileSync('document.pdf');
212
+ * const result = await dc.uploadFile(buffer, { filename: 'document.pdf' });
213
+ * ```
214
+ */
215
+ uploadFile(file: File | Blob | Buffer, options?: UploadFileOptions): Promise<UploadFileResponse>;
216
+ /**
217
+ * Convert a URL or Office file to PDF for citation verification.
218
+ * The converted file can then be processed with prepareConvertedFile().
219
+ *
220
+ * Supported Office formats:
221
+ * - Microsoft Word (.doc, .docx)
222
+ * - Microsoft Excel (.xls, .xlsx)
223
+ * - Microsoft PowerPoint (.ppt, .pptx)
224
+ * - OpenDocument (.odt, .ods, .odp)
225
+ * - Rich Text Format (.rtf)
226
+ * - CSV (.csv)
227
+ *
228
+ * @param input - URL string or object with URL/file options
229
+ * @returns Conversion result with attachmentId for prepareConvertedFile
230
+ *
231
+ * @example
232
+ * ```typescript
233
+ * // Convert a URL to PDF
234
+ * const result = await dc.convertToPdf({ url: "https://example.com/article" });
235
+ *
236
+ * // Convert an Office document
237
+ * const result = await dc.convertToPdf({
238
+ * file: docxBuffer,
239
+ * filename: "report.docx"
240
+ * });
241
+ *
242
+ * // Then prepare the file for verification
243
+ * const { deepTextPromptPortion, attachmentId } = await dc.prepareConvertedFile({
244
+ * attachmentId: result.attachmentId
245
+ * });
246
+ * ```
247
+ */
248
+ convertToPdf(input: ConvertFileInput | string): Promise<ConvertFileResponse>;
249
+ /**
250
+ * Prepare a previously converted file for citation verification.
251
+ * Use this after calling convertToPdf() to extract text and get deepTextPromptPortion.
252
+ *
253
+ * @param options - Options with attachmentId from convertFile
254
+ * @returns Upload response with attachmentId and extracted text
255
+ *
256
+ * @example
257
+ * ```typescript
258
+ * // First convert the file
259
+ * const converted = await dc.convertToPdf({ url: "https://example.com/article" });
260
+ *
261
+ * // Then prepare it for verification
262
+ * const { deepTextPromptPortion, attachmentId } = await dc.prepareConvertedFile({
263
+ * attachmentId: converted.attachmentId
264
+ * });
265
+ *
266
+ * // Use deepTextPromptPortion in your LLM prompt...
267
+ * ```
268
+ */
269
+ prepareConvertedFile(options: PrepareConvertedFileOptions): Promise<UploadFileResponse>;
270
+ /**
271
+ * Upload multiple files for citation verification and get structured content.
272
+ * This is the recommended way to prepare files for LLM prompts.
273
+ *
274
+ * @param files - Array of files to upload with optional filenames and attachmentIds
275
+ * @returns Object containing fileDataParts for verification and deepTextPromptPortion for LLM
276
+ *
277
+ * @example
278
+ * ```typescript
279
+ * const { fileDataParts, deepTextPromptPortion } = await dc.prepareFiles([
280
+ * { file: pdfBuffer, filename: "report.pdf" },
281
+ * { file: invoiceBuffer, filename: "invoice.pdf" },
282
+ * ]);
283
+ *
284
+ * // Use deepTextPromptPortion in wrapCitationPrompt
285
+ * const { enhancedSystemPrompt, enhancedUserPrompt } = wrapCitationPrompt({
286
+ * systemPrompt,
287
+ * userPrompt,
288
+ * deepTextPromptPortion
289
+ * });
290
+ *
291
+ * // Use fileDataParts later for verification
292
+ * const result = await dc.verifyCitationsFromLlmOutput({ llmOutput, fileDataParts });
293
+ * ```
294
+ */
295
+ prepareFiles(files: FileInput[]): Promise<PrepareFilesResult>;
296
+ /**
297
+ * Verify citations against a previously uploaded file.
298
+ *
299
+ * @param attachmentId - The attachment ID returned from uploadFile
300
+ * @param citations - Citations to verify (from getAllCitationsFromLlmOutput)
301
+ * @param options - Optional verification options
302
+ * @returns Verification results with status and proof images
303
+ *
304
+ * @example
305
+ * ```typescript
306
+ * import { getAllCitationsFromLlmOutput } from '@deepcitation/deepcitation-js';
307
+ *
308
+ * const citations = getAllCitationsFromLlmOutput(llmResponse);
309
+ * const verified = await dc.verifyCitations(attachmentId, citations);
310
+ *
311
+ * for (const [key, result] of Object.entries(verified.verifications)) {
312
+ * console.log(key, result.searchState?.status);
313
+ * // "found", "partial_text_found", "not_found", etc.
314
+ * }
315
+ * ```
316
+ */
317
+ verifyCitations(attachmentId: string, citations: CitationInput, options?: VerifyCitationsOptions): Promise<VerifyCitationsResponse>;
318
+ /**
319
+ * Verify citations from LLM output with automatic parsing.
320
+ * This is the recommended way to verify citations for new integrations.
321
+ *
322
+ * @param input - Object containing llmOutput and optional fileDataParts
323
+ * @returns Verification results with status and proof images
324
+ *
325
+ * @example
326
+ * ```typescript
327
+ * const result = await dc.verifyCitationsFromLlmOutput({
328
+ * llmOutput: response.content,
329
+ * fileDataParts, // From prepareFiles()
330
+ * });
331
+ *
332
+ * for (const [key, result] of Object.entries(result.verifications)) {
333
+ * console.log(key, result.searchState?.status);
334
+ * }
335
+ * ```
336
+ */
337
+ verifyCitationsFromLlmOutput(input: VerifyCitationsFromLlmOutput, citations?: {
338
+ [key: string]: Citation;
339
+ }): Promise<VerifyCitationsResponse>;
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 };
@@ -1 +1 @@
1
- export { DeepCitation } from "./DeepCitation.js";
1
+ export{q as DeepCitation}from'../chunk-DEUSSEFH.js';import'../chunk-O2XFH626.js';
package/lib/index.cjs ADDED
@@ -0,0 +1 @@
1
+ 'use strict';var chunkJ7U6YFOI_cjs=require('./chunk-J7U6YFOI.cjs'),chunk4FGOHQFP_cjs=require('./chunk-4FGOHQFP.cjs'),chunkCFXDRAJL_cjs=require('./chunk-CFXDRAJL.cjs');require('./chunk-F2MMVEVC.cjs');var H=t=>{if(!t)return false;let e=t.trim();if(e.length<64)return false;let a=e?.[0];for(let n=1;n<e.length;n++)if(e[n]!==a)return false;return true};function Y(t){t=t.trim();let e=2,a=10,n=/[.?!](?=\s+|$)/g,m,r=[];for(;(m=n.exec(t))!==null;)r.push(m.index);if(r.length<2)return t;let I=r[r.length-1],N=r[r.length-2],o=t.substring(N+1,I+1),p=o.length;if(o.trim().slice(0,-1).length<a||p<=0||t.length<p*e)return t;let c=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)c++,f=i,s=i;else break}return c>=e?t.substring(0,f)+o:t}Object.defineProperty(exports,"CITATION_X_PADDING",{enumerable:true,get:function(){return chunkJ7U6YFOI_cjs.j}});Object.defineProperty(exports,"CITATION_Y_PADDING",{enumerable:true,get:function(){return chunkJ7U6YFOI_cjs.k}});Object.defineProperty(exports,"DeepCitation",{enumerable:true,get:function(){return chunkJ7U6YFOI_cjs.q}});Object.defineProperty(exports,"generateCitationInstanceId",{enumerable:true,get:function(){return chunkJ7U6YFOI_cjs.i}});Object.defineProperty(exports,"generateCitationKey",{enumerable:true,get:function(){return chunkJ7U6YFOI_cjs.g}});Object.defineProperty(exports,"generateVerificationKey",{enumerable:true,get:function(){return chunkJ7U6YFOI_cjs.h}});Object.defineProperty(exports,"getAllCitationsFromLlmOutput",{enumerable:true,get:function(){return chunkJ7U6YFOI_cjs.n}});Object.defineProperty(exports,"getCitationPageNumber",{enumerable:true,get:function(){return chunkJ7U6YFOI_cjs.d}});Object.defineProperty(exports,"getCitationStatus",{enumerable:true,get:function(){return chunkJ7U6YFOI_cjs.l}});Object.defineProperty(exports,"groupCitationsByAttachmentId",{enumerable:true,get:function(){return chunkJ7U6YFOI_cjs.o}});Object.defineProperty(exports,"groupCitationsByAttachmentIdObject",{enumerable:true,get:function(){return chunkJ7U6YFOI_cjs.p}});Object.defineProperty(exports,"normalizeCitations",{enumerable:true,get:function(){return chunkJ7U6YFOI_cjs.e}});Object.defineProperty(exports,"parseCitation",{enumerable:true,get:function(){return chunkJ7U6YFOI_cjs.m}});Object.defineProperty(exports,"removeCitations",{enumerable:true,get:function(){return chunkJ7U6YFOI_cjs.a}});Object.defineProperty(exports,"removeLineIdMetadata",{enumerable:true,get:function(){return chunkJ7U6YFOI_cjs.c}});Object.defineProperty(exports,"removePageNumberMetadata",{enumerable:true,get:function(){return chunkJ7U6YFOI_cjs.b}});Object.defineProperty(exports,"sha1Hash",{enumerable:true,get:function(){return chunkJ7U6YFOI_cjs.f}});Object.defineProperty(exports,"AV_CITATION_MARKDOWN_SYNTAX_PROMPT",{enumerable:true,get:function(){return chunk4FGOHQFP_cjs.b}});Object.defineProperty(exports,"CITATION_AV_BASED_JSON_OUTPUT_FORMAT",{enumerable:true,get:function(){return chunk4FGOHQFP_cjs.h}});Object.defineProperty(exports,"CITATION_AV_REMINDER",{enumerable:true,get:function(){return chunk4FGOHQFP_cjs.d}});Object.defineProperty(exports,"CITATION_JSON_OUTPUT_FORMAT",{enumerable:true,get:function(){return chunk4FGOHQFP_cjs.g}});Object.defineProperty(exports,"CITATION_MARKDOWN_SYNTAX_PROMPT",{enumerable:true,get:function(){return chunk4FGOHQFP_cjs.a}});Object.defineProperty(exports,"CITATION_REMINDER",{enumerable:true,get:function(){return chunk4FGOHQFP_cjs.c}});Object.defineProperty(exports,"compressPromptIds",{enumerable:true,get:function(){return chunk4FGOHQFP_cjs.i}});Object.defineProperty(exports,"decompressPromptIds",{enumerable:true,get:function(){return chunk4FGOHQFP_cjs.j}});Object.defineProperty(exports,"wrapCitationPrompt",{enumerable:true,get:function(){return chunk4FGOHQFP_cjs.f}});Object.defineProperty(exports,"wrapSystemCitationPrompt",{enumerable:true,get:function(){return chunk4FGOHQFP_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}});exports.cleanRepeatingLastSentence=Y;exports.isGeminiGarbage=H;
@@ -0,0 +1,127 @@
1
+ export { CitationInput, DeepCitation, DeepCitationConfig, FileDataPart, FileInput, PrepareFilesResult, UploadFileOptions, UploadFileResponse, VerifyCitationsFromLlmOutput, VerifyCitationsOptions, VerifyCitationsResponse } from './client/index.cjs';
2
+ import { Citation, Verification, CitationStatus } from './types/index.cjs';
3
+ export { BLANK_VERIFICATION, DEFAULT_OUTPUT_IMAGE_FORMAT, IVertex, NOT_FOUND_VERIFICATION_INDEX, OutputImageFormat, PENDING_VERIFICATION_INDEX, PdfSpaceItem, ScreenBox, SearchAttempt, SearchMethod, SearchStatus, VerifyCitationRequest, VerifyCitationResponse } from './types/index.cjs';
4
+ export { AV_CITATION_MARKDOWN_SYNTAX_PROMPT, CITATION_AV_BASED_JSON_OUTPUT_FORMAT, CITATION_AV_REMINDER, CITATION_JSON_OUTPUT_FORMAT, CITATION_MARKDOWN_SYNTAX_PROMPT, CITATION_REMINDER, CompressedResult, WrapCitationPromptOptions, WrapCitationPromptResult, WrapSystemPromptOptions, compressPromptIds, decompressPromptIds, wrapCitationPrompt, wrapSystemCitationPrompt } from './prompts/index.cjs';
5
+
6
+ /**
7
+ * Calculates the verification status of a citation based on the found highlight and search state.
8
+ *
9
+ * @param verification - The found highlight location, or null/undefined if not found
10
+ * @returns An object containing boolean flags for verification status
11
+ */
12
+ declare function getCitationStatus(verification: Verification | null | undefined): CitationStatus;
13
+ declare const parseCitation: (fragment: string, mdAttachmentId?: string | null, citationCounterRef?: any | null, isVerbose?: boolean) => {
14
+ beforeCite: string;
15
+ afterCite: string;
16
+ citation: Citation;
17
+ };
18
+ /**
19
+ * Extracts all citations from LLM output.
20
+ * Supports both XML <cite ... /> tags (embedded in strings/markdown) and JSON-based citation formats.
21
+ *
22
+ * For object input:
23
+ * - Traverses the object looking for `citation` or `citations` properties matching JSON format
24
+ * - Also stringifies the object to find embedded XML citations in markdown content
25
+ *
26
+ * @param llmOutput - The LLM output (string or object)
27
+ * @returns Dictionary of parsed Citation objects keyed by citation key
28
+ */
29
+ declare const getAllCitationsFromLlmOutput: (llmOutput: any) => {
30
+ [key: string]: Citation;
31
+ };
32
+ /**
33
+ * Groups citations by their attachmentId for multi-file verification scenarios.
34
+ * This is useful when you have citations from multiple files and need to
35
+ * verify them against their respective source documents.
36
+ *
37
+ * @param citations - Array of Citation objects or a dictionary of citations
38
+ * @returns Map of attachmentId to dictionary of citations from that file
39
+ *
40
+ * @example
41
+ * ```typescript
42
+ * const citations = getAllCitationsFromLlmOutput(response.content);
43
+ * const citationsByAttachment = groupCitationsByAttachmentId(citations);
44
+ *
45
+ * // Verify citations for each file
46
+ * for (const [attachmentId, fileCitations] of citationsByAttachment) {
47
+ * const verified = await dc.verifyCitations(attachmentId, fileCitations);
48
+ * // Process verification results...
49
+ * }
50
+ * ```
51
+ */
52
+ declare function groupCitationsByAttachmentId(citations: Citation[] | {
53
+ [key: string]: Citation;
54
+ }): Map<string, {
55
+ [key: string]: Citation;
56
+ }>;
57
+ /**
58
+ * Groups citations by their attachmentId and returns as a plain object.
59
+ * Alternative to groupCitationsByAttachmentId that returns a plain object instead of a Map.
60
+ *
61
+ * @param citations - Array of Citation objects or a dictionary of citations
62
+ * @returns Object with attachmentId keys mapping to citation dictionaries
63
+ *
64
+ * @example
65
+ * ```typescript
66
+ * const citations = getAllCitationsFromLlmOutput(response.content);
67
+ * const citationsByAttachment = groupCitationsByAttachmentIdObject(citations);
68
+ *
69
+ * // Verify citations for each file using Promise.all
70
+ * const verificationPromises = Object.entries(citationsByAttachment).map(
71
+ * ([attachmentId, fileCitations]) => dc.verifyCitations(attachmentId, fileCitations)
72
+ * );
73
+ * const results = await Promise.all(verificationPromises);
74
+ * ```
75
+ */
76
+ declare function groupCitationsByAttachmentIdObject(citations: Citation[] | {
77
+ [key: string]: Citation;
78
+ }): {
79
+ [attachmentId: string]: {
80
+ [key: string]: Citation;
81
+ };
82
+ };
83
+
84
+ declare const removeCitations: (pageText: string, leaveKeySpanBehind?: boolean) => string;
85
+ declare const removePageNumberMetadata: (pageText: string) => string;
86
+ declare const removeLineIdMetadata: (pageText: string) => string;
87
+ declare const getCitationPageNumber: (startPageKey?: string | null) => number | null;
88
+ declare const normalizeCitations: (response: string) => string;
89
+
90
+ declare const isGeminiGarbage: (content: string) => boolean;
91
+ declare function cleanRepeatingLastSentence(text: string): string;
92
+
93
+ /**
94
+ * Pure JavaScript SHA-1 implementation.
95
+ * Based on the FIPS 180-4 specification.
96
+ * No external dependencies.
97
+ */
98
+ /**
99
+ * Computes a SHA-1 hash of the provided data.
100
+ * Used internally by generateCitationKey in react/utils.ts
101
+ */
102
+ declare function sha1Hash(data: string | any): string;
103
+
104
+ /**
105
+ * Generates a unique, deterministic key for a citation based on its content.
106
+ * @param citation - The citation to generate a key for
107
+ * @returns A unique, deterministic key for the citation
108
+ */
109
+ declare function generateCitationKey(citation: Citation): string;
110
+ /**
111
+ * Generates a unique, deterministic key for a verification based on its content.
112
+ * @param verification - The verification to generate a key for
113
+ * @returns
114
+ */
115
+ declare function generateVerificationKey(verification: Verification): string;
116
+ /**
117
+ * Generates a unique instance ID for a citation component render.
118
+ * Combines the citation key with a random suffix for uniqueness.
119
+ */
120
+ declare function generateCitationInstanceId(citationKey: string): string;
121
+ /**
122
+ * Default padding values for citation styling.
123
+ */
124
+ declare const CITATION_X_PADDING = 4;
125
+ declare const CITATION_Y_PADDING = 1;
126
+
127
+ export { CITATION_X_PADDING, CITATION_Y_PADDING, Citation, CitationStatus, Verification, cleanRepeatingLastSentence, generateCitationInstanceId, generateCitationKey, generateVerificationKey, getAllCitationsFromLlmOutput, getCitationPageNumber, getCitationStatus, groupCitationsByAttachmentId, groupCitationsByAttachmentIdObject, isGeminiGarbage, normalizeCitations, parseCitation, removeCitations, removeLineIdMetadata, removePageNumberMetadata, sha1Hash };
package/lib/index.d.ts CHANGED
@@ -1,23 +1,127 @@
1
+ export { CitationInput, DeepCitation, DeepCitationConfig, FileDataPart, FileInput, PrepareFilesResult, UploadFileOptions, UploadFileResponse, VerifyCitationsFromLlmOutput, VerifyCitationsOptions, VerifyCitationsResponse } from './client/index.js';
2
+ import { Citation, Verification, CitationStatus } from './types/index.js';
3
+ export { BLANK_VERIFICATION, DEFAULT_OUTPUT_IMAGE_FORMAT, IVertex, NOT_FOUND_VERIFICATION_INDEX, OutputImageFormat, PENDING_VERIFICATION_INDEX, PdfSpaceItem, ScreenBox, SearchAttempt, SearchMethod, SearchStatus, VerifyCitationRequest, VerifyCitationResponse } from './types/index.js';
4
+ export { AV_CITATION_MARKDOWN_SYNTAX_PROMPT, CITATION_AV_BASED_JSON_OUTPUT_FORMAT, CITATION_AV_REMINDER, CITATION_JSON_OUTPUT_FORMAT, CITATION_MARKDOWN_SYNTAX_PROMPT, CITATION_REMINDER, CompressedResult, WrapCitationPromptOptions, WrapCitationPromptResult, WrapSystemPromptOptions, compressPromptIds, decompressPromptIds, wrapCitationPrompt, wrapSystemCitationPrompt } from './prompts/index.js';
5
+
1
6
  /**
2
- * DeepCitation - Citation parsing, verification, and rendering library
3
- * @packageDocumentation
4
- */
5
- export { DeepCitation } from "./client/index.js";
6
- export type { DeepCitationConfig, UploadFileResponse, UploadFileOptions, VerifyCitationsResponse, VerifyCitationsOptions, CitationInput, FileInput, FileDataPart, PrepareFilesResult, VerifyCitationsFromLlmOutput, } from "./client/index.js";
7
- export { parseCitation, getCitationStatus, getAllCitationsFromLlmOutput, groupCitationsByAttachmentId, groupCitationsByAttachmentIdObject, } from "./parsing/parseCitation.js";
8
- export { normalizeCitations, getCitationPageNumber, } from "./parsing/normalizeCitation.js";
9
- export { isGeminiGarbage, cleanRepeatingLastSentence, } from "./parsing/parseWorkAround.js";
10
- export type { Citation, CitationStatus, VerifyCitationRequest, VerifyCitationResponse, OutputImageFormat, } from "./types/citation.js";
11
- export { DEFAULT_OUTPUT_IMAGE_FORMAT } from "./types/citation.js";
12
- export type { Verification } from "./types/verification.js";
13
- export { NOT_FOUND_VERIFICATION_INDEX, PENDING_VERIFICATION_INDEX, BLANK_VERIFICATION, } from "./types/verification.js";
14
- export type { SearchStatus, SearchMethod, SearchAttempt, } from "./types/search.js";
15
- export type { ScreenBox, PdfSpaceItem, IVertex } from "./types/boxes.js";
16
- export { sha1Hash } from "./utils/sha.js";
17
- export { generateCitationKey, generateVerificationKey, generateCitationInstanceId, } from "./react/utils.js";
18
- export { CITATION_X_PADDING, CITATION_Y_PADDING } from "./react/utils.js";
19
- export { CITATION_JSON_OUTPUT_FORMAT, CITATION_MARKDOWN_SYNTAX_PROMPT, AV_CITATION_MARKDOWN_SYNTAX_PROMPT, CITATION_AV_BASED_JSON_OUTPUT_FORMAT, wrapSystemCitationPrompt, wrapCitationPrompt, } from "./prompts/citationPrompts.js";
20
- export type { WrapSystemPromptOptions, WrapCitationPromptOptions, WrapCitationPromptResult, } from "./prompts/citationPrompts.js";
21
- export { removeLineIdMetadata, removePageNumberMetadata, removeCitations, } from "./parsing/normalizeCitation.js";
22
- export { compressPromptIds, decompressPromptIds, } from "./prompts/promptCompression.js";
23
- export type { CompressedResult } from "./prompts/types.js";
7
+ * Calculates the verification status of a citation based on the found highlight and search state.
8
+ *
9
+ * @param verification - The found highlight location, or null/undefined if not found
10
+ * @returns An object containing boolean flags for verification status
11
+ */
12
+ declare function getCitationStatus(verification: Verification | null | undefined): CitationStatus;
13
+ declare const parseCitation: (fragment: string, mdAttachmentId?: string | null, citationCounterRef?: any | null, isVerbose?: boolean) => {
14
+ beforeCite: string;
15
+ afterCite: string;
16
+ citation: Citation;
17
+ };
18
+ /**
19
+ * Extracts all citations from LLM output.
20
+ * Supports both XML <cite ... /> tags (embedded in strings/markdown) and JSON-based citation formats.
21
+ *
22
+ * For object input:
23
+ * - Traverses the object looking for `citation` or `citations` properties matching JSON format
24
+ * - Also stringifies the object to find embedded XML citations in markdown content
25
+ *
26
+ * @param llmOutput - The LLM output (string or object)
27
+ * @returns Dictionary of parsed Citation objects keyed by citation key
28
+ */
29
+ declare const getAllCitationsFromLlmOutput: (llmOutput: any) => {
30
+ [key: string]: Citation;
31
+ };
32
+ /**
33
+ * Groups citations by their attachmentId for multi-file verification scenarios.
34
+ * This is useful when you have citations from multiple files and need to
35
+ * verify them against their respective source documents.
36
+ *
37
+ * @param citations - Array of Citation objects or a dictionary of citations
38
+ * @returns Map of attachmentId to dictionary of citations from that file
39
+ *
40
+ * @example
41
+ * ```typescript
42
+ * const citations = getAllCitationsFromLlmOutput(response.content);
43
+ * const citationsByAttachment = groupCitationsByAttachmentId(citations);
44
+ *
45
+ * // Verify citations for each file
46
+ * for (const [attachmentId, fileCitations] of citationsByAttachment) {
47
+ * const verified = await dc.verifyCitations(attachmentId, fileCitations);
48
+ * // Process verification results...
49
+ * }
50
+ * ```
51
+ */
52
+ declare function groupCitationsByAttachmentId(citations: Citation[] | {
53
+ [key: string]: Citation;
54
+ }): Map<string, {
55
+ [key: string]: Citation;
56
+ }>;
57
+ /**
58
+ * Groups citations by their attachmentId and returns as a plain object.
59
+ * Alternative to groupCitationsByAttachmentId that returns a plain object instead of a Map.
60
+ *
61
+ * @param citations - Array of Citation objects or a dictionary of citations
62
+ * @returns Object with attachmentId keys mapping to citation dictionaries
63
+ *
64
+ * @example
65
+ * ```typescript
66
+ * const citations = getAllCitationsFromLlmOutput(response.content);
67
+ * const citationsByAttachment = groupCitationsByAttachmentIdObject(citations);
68
+ *
69
+ * // Verify citations for each file using Promise.all
70
+ * const verificationPromises = Object.entries(citationsByAttachment).map(
71
+ * ([attachmentId, fileCitations]) => dc.verifyCitations(attachmentId, fileCitations)
72
+ * );
73
+ * const results = await Promise.all(verificationPromises);
74
+ * ```
75
+ */
76
+ declare function groupCitationsByAttachmentIdObject(citations: Citation[] | {
77
+ [key: string]: Citation;
78
+ }): {
79
+ [attachmentId: string]: {
80
+ [key: string]: Citation;
81
+ };
82
+ };
83
+
84
+ declare const removeCitations: (pageText: string, leaveKeySpanBehind?: boolean) => string;
85
+ declare const removePageNumberMetadata: (pageText: string) => string;
86
+ declare const removeLineIdMetadata: (pageText: string) => string;
87
+ declare const getCitationPageNumber: (startPageKey?: string | null) => number | null;
88
+ declare const normalizeCitations: (response: string) => string;
89
+
90
+ declare const isGeminiGarbage: (content: string) => boolean;
91
+ declare function cleanRepeatingLastSentence(text: string): string;
92
+
93
+ /**
94
+ * Pure JavaScript SHA-1 implementation.
95
+ * Based on the FIPS 180-4 specification.
96
+ * No external dependencies.
97
+ */
98
+ /**
99
+ * Computes a SHA-1 hash of the provided data.
100
+ * Used internally by generateCitationKey in react/utils.ts
101
+ */
102
+ declare function sha1Hash(data: string | any): string;
103
+
104
+ /**
105
+ * Generates a unique, deterministic key for a citation based on its content.
106
+ * @param citation - The citation to generate a key for
107
+ * @returns A unique, deterministic key for the citation
108
+ */
109
+ declare function generateCitationKey(citation: Citation): string;
110
+ /**
111
+ * Generates a unique, deterministic key for a verification based on its content.
112
+ * @param verification - The verification to generate a key for
113
+ * @returns
114
+ */
115
+ declare function generateVerificationKey(verification: Verification): string;
116
+ /**
117
+ * Generates a unique instance ID for a citation component render.
118
+ * Combines the citation key with a random suffix for uniqueness.
119
+ */
120
+ declare function generateCitationInstanceId(citationKey: string): string;
121
+ /**
122
+ * Default padding values for citation styling.
123
+ */
124
+ declare const CITATION_X_PADDING = 4;
125
+ declare const CITATION_Y_PADDING = 1;
126
+
127
+ export { CITATION_X_PADDING, CITATION_Y_PADDING, Citation, CitationStatus, Verification, cleanRepeatingLastSentence, generateCitationInstanceId, generateCitationKey, generateVerificationKey, getAllCitationsFromLlmOutput, getCitationPageNumber, getCitationStatus, groupCitationsByAttachmentId, groupCitationsByAttachmentIdObject, isGeminiGarbage, normalizeCitations, parseCitation, removeCitations, removeLineIdMetadata, removePageNumberMetadata, sha1Hash };
package/lib/index.js CHANGED
@@ -1,20 +1 @@
1
- /**
2
- * DeepCitation - Citation parsing, verification, and rendering library
3
- * @packageDocumentation
4
- */
5
- // Client
6
- export { DeepCitation } from "./client/index.js";
7
- // Parsing
8
- export { parseCitation, getCitationStatus, getAllCitationsFromLlmOutput, groupCitationsByAttachmentId, groupCitationsByAttachmentIdObject, } from "./parsing/parseCitation.js";
9
- export { normalizeCitations, getCitationPageNumber, } from "./parsing/normalizeCitation.js";
10
- export { isGeminiGarbage, cleanRepeatingLastSentence, } from "./parsing/parseWorkAround.js";
11
- export { DEFAULT_OUTPUT_IMAGE_FORMAT } from "./types/citation.js";
12
- export { NOT_FOUND_VERIFICATION_INDEX, PENDING_VERIFICATION_INDEX, BLANK_VERIFICATION, } from "./types/verification.js";
13
- // Utilities
14
- export { sha1Hash } from "./utils/sha.js";
15
- export { generateCitationKey, generateVerificationKey, generateCitationInstanceId, } from "./react/utils.js";
16
- export { CITATION_X_PADDING, CITATION_Y_PADDING } from "./react/utils.js";
17
- // Prompts
18
- export { CITATION_JSON_OUTPUT_FORMAT, CITATION_MARKDOWN_SYNTAX_PROMPT, AV_CITATION_MARKDOWN_SYNTAX_PROMPT, CITATION_AV_BASED_JSON_OUTPUT_FORMAT, wrapSystemCitationPrompt, wrapCitationPrompt, } from "./prompts/citationPrompts.js";
19
- export { removeLineIdMetadata, removePageNumberMetadata, removeCitations, } from "./parsing/normalizeCitation.js";
20
- export { compressPromptIds, decompressPromptIds, } from "./prompts/promptCompression.js";
1
+ export{j as CITATION_X_PADDING,k as CITATION_Y_PADDING,q as DeepCitation,i as generateCitationInstanceId,g as generateCitationKey,h as generateVerificationKey,n as getAllCitationsFromLlmOutput,d as getCitationPageNumber,l as getCitationStatus,o as groupCitationsByAttachmentId,p as groupCitationsByAttachmentIdObject,e as normalizeCitations,m as parseCitation,a as removeCitations,c as removeLineIdMetadata,b as removePageNumberMetadata,f as sha1Hash}from'./chunk-DEUSSEFH.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-2IZXUOQR.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';import'./chunk-O2XFH626.js';var H=t=>{if(!t)return false;let e=t.trim();if(e.length<64)return false;let a=e?.[0];for(let n=1;n<e.length;n++)if(e[n]!==a)return false;return true};function Y(t){t=t.trim();let e=2,a=10,n=/[.?!](?=\s+|$)/g,m,r=[];for(;(m=n.exec(t))!==null;)r.push(m.index);if(r.length<2)return t;let I=r[r.length-1],N=r[r.length-2],o=t.substring(N+1,I+1),p=o.length;if(o.trim().slice(0,-1).length<a||p<=0||t.length<p*e)return t;let c=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)c++,f=i,s=i;else break}return c>=e?t.substring(0,f)+o:t}export{Y as cleanRepeatingLastSentence,H as isGeminiGarbage};
@@ -0,0 +1 @@
1
+ 'use strict';var chunk4FGOHQFP_cjs=require('../chunk-4FGOHQFP.cjs');require('../chunk-F2MMVEVC.cjs');Object.defineProperty(exports,"AV_CITATION_MARKDOWN_SYNTAX_PROMPT",{enumerable:true,get:function(){return chunk4FGOHQFP_cjs.b}});Object.defineProperty(exports,"CITATION_AV_BASED_JSON_OUTPUT_FORMAT",{enumerable:true,get:function(){return chunk4FGOHQFP_cjs.h}});Object.defineProperty(exports,"CITATION_AV_REMINDER",{enumerable:true,get:function(){return chunk4FGOHQFP_cjs.d}});Object.defineProperty(exports,"CITATION_JSON_OUTPUT_FORMAT",{enumerable:true,get:function(){return chunk4FGOHQFP_cjs.g}});Object.defineProperty(exports,"CITATION_MARKDOWN_SYNTAX_PROMPT",{enumerable:true,get:function(){return chunk4FGOHQFP_cjs.a}});Object.defineProperty(exports,"CITATION_REMINDER",{enumerable:true,get:function(){return chunk4FGOHQFP_cjs.c}});Object.defineProperty(exports,"compressPromptIds",{enumerable:true,get:function(){return chunk4FGOHQFP_cjs.i}});Object.defineProperty(exports,"decompressPromptIds",{enumerable:true,get:function(){return chunk4FGOHQFP_cjs.j}});Object.defineProperty(exports,"wrapCitationPrompt",{enumerable:true,get:function(){return chunk4FGOHQFP_cjs.f}});Object.defineProperty(exports,"wrapSystemCitationPrompt",{enumerable:true,get:function(){return chunk4FGOHQFP_cjs.e}});