@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.
Files changed (82) 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-3GR7VKUJ.cjs +1 -0
  5. package/lib/chunk-4FGOHQFP.cjs +66 -0
  6. package/lib/chunk-CFXDRAJL.cjs +1 -0
  7. package/lib/chunk-F2MMVEVC.cjs +1 -0
  8. package/lib/chunk-LSKISWWH.cjs +2 -0
  9. package/lib/chunk-O2XFH626.js +1 -0
  10. package/lib/chunk-QGXCOW3E.js +1 -0
  11. package/lib/chunk-RCHWBA6D.js +2 -0
  12. package/lib/chunk-RQPZSRID.js +1 -0
  13. package/lib/client/index.cjs +1 -0
  14. package/lib/client/{DeepCitation.d.ts → index.d.cts} +159 -3
  15. package/lib/client/index.d.ts +342 -2
  16. package/lib/client/index.js +1 -1
  17. package/lib/index.cjs +1 -0
  18. package/lib/index.d.cts +105 -0
  19. package/lib/index.d.ts +103 -21
  20. package/lib/index.js +1 -20
  21. package/lib/prompts/index.cjs +1 -0
  22. package/lib/prompts/index.d.cts +196 -0
  23. package/lib/prompts/index.d.ts +196 -3
  24. package/lib/prompts/index.js +1 -3
  25. package/lib/react/index.cjs +4 -0
  26. package/lib/react/{types.d.ts → index.d.cts} +173 -22
  27. package/lib/react/index.d.ts +461 -12
  28. package/lib/react/index.js +4 -20
  29. package/lib/types/index.cjs +1 -0
  30. package/lib/types/index.d.cts +96 -0
  31. package/lib/types/index.d.ts +96 -11
  32. package/lib/types/index.js +1 -7
  33. package/lib/utils-CSqRI6NU.d.cts +45 -0
  34. package/lib/{react/utils.d.ts → utils-D_wxy_ni.d.ts} +13 -12
  35. package/package.json +46 -11
  36. package/lib/client/DeepCitation.js +0 -374
  37. package/lib/client/types.d.ts +0 -154
  38. package/lib/client/types.js +0 -1
  39. package/lib/parsing/normalizeCitation.d.ts +0 -5
  40. package/lib/parsing/normalizeCitation.js +0 -198
  41. package/lib/parsing/parseCitation.d.ts +0 -79
  42. package/lib/parsing/parseCitation.js +0 -431
  43. package/lib/parsing/parseWorkAround.d.ts +0 -2
  44. package/lib/parsing/parseWorkAround.js +0 -73
  45. package/lib/prompts/citationPrompts.d.ts +0 -138
  46. package/lib/prompts/citationPrompts.js +0 -168
  47. package/lib/prompts/promptCompression.d.ts +0 -14
  48. package/lib/prompts/promptCompression.js +0 -127
  49. package/lib/prompts/types.d.ts +0 -4
  50. package/lib/prompts/types.js +0 -1
  51. package/lib/react/CitationComponent.d.ts +0 -106
  52. package/lib/react/CitationComponent.js +0 -419
  53. package/lib/react/CitationVariants.d.ts +0 -132
  54. package/lib/react/CitationVariants.js +0 -277
  55. package/lib/react/DiffDisplay.d.ts +0 -10
  56. package/lib/react/DiffDisplay.js +0 -33
  57. package/lib/react/Popover.d.ts +0 -15
  58. package/lib/react/Popover.js +0 -20
  59. package/lib/react/UrlCitationComponent.d.ts +0 -83
  60. package/lib/react/UrlCitationComponent.js +0 -224
  61. package/lib/react/VerificationTabs.d.ts +0 -10
  62. package/lib/react/VerificationTabs.js +0 -36
  63. package/lib/react/icons.d.ts +0 -22
  64. package/lib/react/icons.js +0 -16
  65. package/lib/react/primitives.d.ts +0 -99
  66. package/lib/react/primitives.js +0 -187
  67. package/lib/react/types.js +0 -1
  68. package/lib/react/useSmartDiff.d.ts +0 -16
  69. package/lib/react/useSmartDiff.js +0 -64
  70. package/lib/react/utils.js +0 -88
  71. package/lib/types/boxes.d.ts +0 -11
  72. package/lib/types/boxes.js +0 -1
  73. package/lib/types/citation.d.ts +0 -39
  74. package/lib/types/citation.js +0 -1
  75. package/lib/types/search.d.ts +0 -19
  76. package/lib/types/search.js +0 -1
  77. package/lib/types/verification.d.ts +0 -27
  78. package/lib/types/verification.js +0 -11
  79. package/lib/utils/diff.d.ts +0 -60
  80. package/lib/utils/diff.js +0 -414
  81. package/lib/utils/sha.d.ts +0 -10
  82. package/lib/utils/sha.js +0 -108
@@ -1,64 +0,0 @@
1
- import { diffLines, diffWordsWithSpace } from "../utils/diff.js";
2
- import { useMemo } from "react";
3
- export const useSmartDiff = (expected = "", actual = "") => {
4
- return useMemo(() => {
5
- // 1. Sanitize standard noise (CRLF, trailing spaces)
6
- const cleanExpected = (expected || "").trim().replace(/\r\n/g, "\n");
7
- const cleanActual = (actual || "").trim().replace(/\r\n/g, "\n");
8
- // 2. First Pass: Diff by LINES.
9
- // This isolates the "extra line" issue. The extra line becomes one "added" chunk,
10
- // and it prevents the tokenizer from getting confused on the rest of the text.
11
- const lineDiffs = diffLines(cleanExpected, cleanActual);
12
- // 3. Second Pass: Process the line results to find "Modifications"
13
- const processedDiffs = [];
14
- let hasDiff = false;
15
- let totalChange = 0;
16
- for (let i = 0; i < lineDiffs.length; i++) {
17
- const part = lineDiffs[i];
18
- const nextPart = lineDiffs[i + 1];
19
- // CHECK FOR MODIFICATION:
20
- // If we see a "Removed" block immediately followed by an "Added" block,
21
- // it means this specific line changed. We should DIFF WORDS inside this line.
22
- if (part.removed && nextPart && nextPart.added) {
23
- // Run word diff ONLY on this pair of lines
24
- const wordDiffs = diffWordsWithSpace(part.value, nextPart.value);
25
- processedDiffs.push({
26
- type: "modified",
27
- parts: wordDiffs,
28
- });
29
- hasDiff = true;
30
- // Calculate raw change amount for variance score
31
- totalChange += Math.abs(part.value.length - nextPart.value.length);
32
- i++; // Skip the next part since we merged it into this block
33
- }
34
- // CHECK FOR PURE ADDITION/DELETION (The "Extra Line" Scenario)
35
- else if (part.added || part.removed) {
36
- processedDiffs.push({
37
- type: part.added ? "added" : "removed",
38
- parts: [{ value: part.value, added: part.added, removed: part.removed }],
39
- });
40
- hasDiff = true;
41
- totalChange += part.value.length;
42
- }
43
- // UNCHANGED BLOCKS
44
- else {
45
- processedDiffs.push({
46
- type: "unchanged",
47
- parts: [{ value: part.value }],
48
- });
49
- }
50
- }
51
- // 4. Calculate a similarity score to decide UI defaults
52
- // 1.0 = Perfect match, 0.0 = Totally different
53
- const maxLength = Math.max(cleanExpected.length, cleanActual.length);
54
- const similarity = maxLength === 0 ? 1 : 1 - totalChange / maxLength;
55
- return {
56
- diffResult: processedDiffs,
57
- hasDiff,
58
- similarity,
59
- // If similarity is too low (< 60%), the Diff view is likely "Fruit Salad" (messy).
60
- // We can use this boolean to default the UI to the "Source" tab.
61
- isHighVariance: similarity < 0.6,
62
- };
63
- }, [expected, actual]);
64
- };
@@ -1,88 +0,0 @@
1
- import { sha1Hash } from "../utils/sha.js";
2
- import { getCitationPageNumber } from "../parsing/normalizeCitation.js";
3
- // =============================================================================
4
- // UTILITY FUNCTIONS
5
- // =============================================================================
6
- export function cn(...classes) {
7
- return classes.filter(Boolean).join(" ");
8
- }
9
- /**
10
- * Generates a unique, deterministic key for a citation based on its content.
11
- * @param citation - The citation to generate a key for
12
- * @returns A unique, deterministic key for the citation
13
- */
14
- export function generateCitationKey(citation) {
15
- const pageNumber = citation.pageNumber || getCitationPageNumber(citation.startPageKey);
16
- const keyParts = [
17
- citation.attachmentId || "",
18
- pageNumber?.toString() || "",
19
- citation.fullPhrase || "",
20
- citation.keySpan?.toString() || "",
21
- citation.lineIds?.join(",") || "",
22
- citation.timestamps?.startTime || "",
23
- citation.timestamps?.endTime || "",
24
- ];
25
- return sha1Hash(keyParts.join("|")).slice(0, 16);
26
- }
27
- /**
28
- * Generates a unique, deterministic key for a verification based on its content.
29
- * @param verification - The verification to generate a key for
30
- * @returns
31
- */
32
- export function generateVerificationKey(verification) {
33
- const keyParts = [
34
- verification.attachmentId || "",
35
- verification.label || "",
36
- verification.verifiedFullPhrase || "",
37
- verification.verifiedKeySpan || "",
38
- verification.verifiedLineIds?.join(",") || "",
39
- verification.verifiedPageNumber?.toString() || "",
40
- verification.verifiedTimestamps?.startTime || "",
41
- verification.verifiedTimestamps?.endTime || "",
42
- verification.verifiedMatchSnippet || "",
43
- verification.hitIndexWithinPage?.toString() || "",
44
- ];
45
- return sha1Hash(keyParts.join("|")).slice(0, 16);
46
- }
47
- /**
48
- * Generates a unique instance ID for a citation component render.
49
- * Combines the citation key with a random suffix for uniqueness.
50
- */
51
- export function generateCitationInstanceId(citationKey) {
52
- const randomSuffix = Math.random().toString(36).slice(2, 11);
53
- return `${citationKey}-${randomSuffix}`;
54
- }
55
- /**
56
- * Gets the display text for a citation (keySpan with fallback to number).
57
- */
58
- export function getCitationDisplayText(citation, options = {}) {
59
- const { fallbackDisplay } = options;
60
- return (citation.keySpan?.toString() ||
61
- citation.citationNumber?.toString() ||
62
- fallbackDisplay ||
63
- "1");
64
- }
65
- /**
66
- * Gets the citation number as a string.
67
- */
68
- export function getCitationNumber(citation) {
69
- return citation.citationNumber?.toString() || "1";
70
- }
71
- /**
72
- * Gets the keySpan text from a citation.
73
- */
74
- export function getCitationKeySpanText(citation) {
75
- return citation.keySpan?.toString() || "";
76
- }
77
- /**
78
- * Joins class names, filtering out falsy values.
79
- * This is a minimal implementation for the base component.
80
- */
81
- export function classNames(...classes) {
82
- return classes.filter(Boolean).join(" ");
83
- }
84
- /**
85
- * Default padding values for citation styling.
86
- */
87
- export const CITATION_X_PADDING = 4;
88
- export const CITATION_Y_PADDING = 1;
@@ -1,11 +0,0 @@
1
- export interface PdfSpaceItem extends ScreenBox {
2
- text?: string;
3
- }
4
- export type IVertex = {
5
- x: number;
6
- y: number;
7
- };
8
- export interface ScreenBox extends IVertex {
9
- width: number;
10
- height: number;
11
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,39 +0,0 @@
1
- import { type ScreenBox } from "./boxes.js";
2
- import { type Verification } from "./verification.js";
3
- export type OutputImageFormat = "jpeg" | "png" | "avif" | undefined | null;
4
- export declare const DEFAULT_OUTPUT_IMAGE_FORMAT: "avif";
5
- export interface VerifyCitationResponse {
6
- verifications: {
7
- [key: string]: Verification;
8
- };
9
- }
10
- export interface VerifyCitationRequest {
11
- attachmentId: string;
12
- citations: {
13
- [key: string]: Citation;
14
- };
15
- outputImageFormat?: OutputImageFormat;
16
- apiKey?: string;
17
- }
18
- export interface Citation {
19
- attachmentId?: string;
20
- fullPhrase?: string | null;
21
- keySpan?: string | null;
22
- startPageKey?: string | null;
23
- lineIds?: number[] | null;
24
- reasoning?: string | null;
25
- selection?: ScreenBox | null;
26
- citationNumber?: number;
27
- pageNumber?: number | null;
28
- timestamps?: {
29
- endTime?: string;
30
- startTime?: string;
31
- };
32
- beforeCite?: string;
33
- }
34
- export interface CitationStatus {
35
- isVerified: boolean;
36
- isMiss: boolean;
37
- isPartialMatch: boolean;
38
- isPending: boolean;
39
- }
@@ -1 +0,0 @@
1
- export const DEFAULT_OUTPUT_IMAGE_FORMAT = "avif";
@@ -1,19 +0,0 @@
1
- export type SearchStatus = "loading" | "pending" | "not_found" | "partial_text_found" | "found" | "found_key_span_only" | "found_phrase_missed_value" | "found_on_other_page" | "found_on_other_line" | "first_word_found" | "timestamp_wip";
2
- export type SearchMethod = "exact_line_match" | "line_with_buffer" | "current_page" | "keyspan_fallback" | "adjacent_pages" | "expanded_window" | "regex_search" | "bm25_search" | "fuzzy_regex" | "first_word_fallback";
3
- export interface SearchAttempt {
4
- method: SearchMethod;
5
- success: boolean;
6
- searchPhrases: string[];
7
- pageSearched?: number;
8
- matchedPhrases?: string[];
9
- matchedVariation?: string;
10
- phraseVariations?: string[];
11
- matchQuality?: string;
12
- isPartialMatch?: boolean;
13
- matchScore?: number;
14
- matchSnippet?: string;
15
- notes?: string;
16
- startTime?: number;
17
- endTime?: number;
18
- durationMs?: number;
19
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,27 +0,0 @@
1
- import { type Citation } from "./citation.js";
2
- import { type SearchStatus, type SearchAttempt } from "./search.js";
3
- import { type PdfSpaceItem } from "./boxes.js";
4
- export declare const NOT_FOUND_VERIFICATION_INDEX = -1;
5
- export declare const PENDING_VERIFICATION_INDEX = -2;
6
- export declare const BLANK_VERIFICATION: Verification;
7
- export interface Verification {
8
- attachmentId?: string | null;
9
- label?: string | null;
10
- citation?: Citation;
11
- status?: SearchStatus | null;
12
- searchAttempts?: SearchAttempt[];
13
- highlightColor?: string | null;
14
- verifiedPageNumber?: number | null;
15
- verifiedLineIds?: number[] | null;
16
- verifiedTimestamps?: {
17
- startTime?: string;
18
- endTime?: string;
19
- } | null;
20
- verifiedFullPhrase?: string | null;
21
- verifiedKeySpan?: string | null;
22
- verifiedMatchSnippet?: string | null;
23
- hitIndexWithinPage?: number | null;
24
- pdfSpaceItem?: PdfSpaceItem;
25
- verificationImageBase64?: string | null;
26
- verifiedAt?: Date;
27
- }
@@ -1,11 +0,0 @@
1
- export const NOT_FOUND_VERIFICATION_INDEX = -1;
2
- export const PENDING_VERIFICATION_INDEX = -2;
3
- export const BLANK_VERIFICATION = {
4
- attachmentId: null,
5
- verifiedPageNumber: NOT_FOUND_VERIFICATION_INDEX,
6
- verifiedMatchSnippet: null,
7
- citation: {
8
- pageNumber: NOT_FOUND_VERIFICATION_INDEX,
9
- },
10
- status: "not_found",
11
- };
@@ -1,60 +0,0 @@
1
- /**
2
- * Custom diff implementation to replace the 'diff' npm package.
3
- * This avoids dependency issues in Firebase Functions environments.
4
- *
5
- * Implements a Myers diff algorithm with optimizations inspired by jsdiff.
6
- * @see https://github.com/kpdecker/jsdiff
7
- *
8
- * ---
9
- *
10
- * BSD 3-Clause License
11
- *
12
- * Copyright (c) 2009-2015, Kevin Decker <kpdecker@gmail.com>
13
- * All rights reserved.
14
- *
15
- * Redistribution and use in source and binary forms, with or without
16
- * modification, are permitted provided that the following conditions are met:
17
- *
18
- * 1. Redistributions of source code must retain the above copyright notice, this
19
- * list of conditions and the following disclaimer.
20
- *
21
- * 2. Redistributions in binary form must reproduce the above copyright notice,
22
- * this list of conditions and the following disclaimer in the documentation
23
- * and/or other materials provided with the distribution.
24
- *
25
- * 3. Neither the name of the copyright holder nor the names of its
26
- * contributors may be used to endorse or promote products derived from
27
- * this software without specific prior written permission.
28
- *
29
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
30
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
32
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
33
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
36
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
37
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39
- */
40
- export interface Change {
41
- value: string;
42
- added?: boolean;
43
- removed?: boolean;
44
- count?: number;
45
- }
46
- /**
47
- * Compare two strings line by line.
48
- * Similar to Diff.diffLines from the 'diff' package.
49
- */
50
- export declare function diffLines(oldStr: string, newStr: string): Change[];
51
- /**
52
- * Compare two strings word by word, preserving whitespace.
53
- * Similar to Diff.diffWordsWithSpace from the 'diff' package.
54
- *
55
- * Features matching jsdiff:
56
- * - Extended Unicode word character support
57
- * - Proper tokenization (words, whitespace runs, single punctuation)
58
- * - Whitespace deduplication in consecutive changes
59
- */
60
- export declare function diffWordsWithSpace(oldStr: string, newStr: string): Change[];