@deepcitation/deepcitation-js 1.1.22 → 1.1.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/lib/index.d.ts +3 -4
- package/lib/index.js +2 -3
- package/lib/parsing/parseCitation.js +10 -12
- package/lib/react/CitationComponent.d.ts +41 -135
- package/lib/react/CitationComponent.js +196 -338
- package/lib/react/CitationVariants.d.ts +0 -3
- package/lib/react/Popover.d.ts +15 -0
- package/lib/react/Popover.js +20 -0
- package/lib/react/primitives.d.ts +0 -3
- package/lib/react/primitives.js +1 -3
- package/lib/react/types.d.ts +3 -4
- package/lib/react/utils.d.ts +9 -1
- package/lib/react/utils.js +22 -1
- package/lib/types/index.d.ts +1 -1
- package/lib/types/search.d.ts +0 -16
- package/lib/types/verification.d.ts +9 -7
- package/lib/types/verification.js +3 -9
- package/package.json +19 -11
- package/lib/react/styles.css +0 -814
package/README.md
CHANGED
package/lib/index.d.ts
CHANGED
|
@@ -10,12 +10,11 @@ export { isGeminiGarbage, cleanRepeatingLastSentence, } from "./parsing/parseWor
|
|
|
10
10
|
export type { Citation, CitationStatus, VerifyCitationRequest, VerifyCitationResponse, OutputImageFormat, } from "./types/citation.js";
|
|
11
11
|
export { DEFAULT_OUTPUT_IMAGE_FORMAT } from "./types/citation.js";
|
|
12
12
|
export type { Verification } from "./types/verification.js";
|
|
13
|
-
export { NOT_FOUND_VERIFICATION_INDEX, PENDING_VERIFICATION_INDEX, BLANK_VERIFICATION,
|
|
14
|
-
export type {
|
|
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
15
|
export type { ScreenBox, PdfSpaceItem, IVertex } from "./types/boxes.js";
|
|
16
16
|
export { sha1Hash } from "./utils/sha.js";
|
|
17
|
-
export { generateCitationKey } from "./react/utils.js";
|
|
18
|
-
export { generateCitationInstanceId } from "./react/utils.js";
|
|
17
|
+
export { generateCitationKey, generateVerificationKey, generateCitationInstanceId, } from "./react/utils.js";
|
|
19
18
|
export { CITATION_X_PADDING, CITATION_Y_PADDING } from "./react/utils.js";
|
|
20
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";
|
|
21
20
|
export type { WrapSystemPromptOptions, WrapCitationPromptOptions, WrapCitationPromptResult, } from "./prompts/citationPrompts.js";
|
package/lib/index.js
CHANGED
|
@@ -9,11 +9,10 @@ export { parseCitation, getCitationStatus, getAllCitationsFromLlmOutput, groupCi
|
|
|
9
9
|
export { normalizeCitations, getCitationPageNumber, } from "./parsing/normalizeCitation.js";
|
|
10
10
|
export { isGeminiGarbage, cleanRepeatingLastSentence, } from "./parsing/parseWorkAround.js";
|
|
11
11
|
export { DEFAULT_OUTPUT_IMAGE_FORMAT } from "./types/citation.js";
|
|
12
|
-
export { NOT_FOUND_VERIFICATION_INDEX, PENDING_VERIFICATION_INDEX, BLANK_VERIFICATION,
|
|
12
|
+
export { NOT_FOUND_VERIFICATION_INDEX, PENDING_VERIFICATION_INDEX, BLANK_VERIFICATION, } from "./types/verification.js";
|
|
13
13
|
// Utilities
|
|
14
14
|
export { sha1Hash } from "./utils/sha.js";
|
|
15
|
-
export { generateCitationKey } from "./react/utils.js";
|
|
16
|
-
export { generateCitationInstanceId } from "./react/utils.js";
|
|
15
|
+
export { generateCitationKey, generateVerificationKey, generateCitationInstanceId, } from "./react/utils.js";
|
|
17
16
|
export { CITATION_X_PADDING, CITATION_Y_PADDING } from "./react/utils.js";
|
|
18
17
|
// Prompts
|
|
19
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";
|
|
@@ -52,21 +52,19 @@ function parseLineIds(lineIdsString) {
|
|
|
52
52
|
* @returns An object containing boolean flags for verification status
|
|
53
53
|
*/
|
|
54
54
|
export function getCitationStatus(verification) {
|
|
55
|
-
const
|
|
56
|
-
const isMiss =
|
|
57
|
-
const isFullMatchWithMissedValue =
|
|
58
|
-
const isFoundValueMissedFullMatch =
|
|
59
|
-
const isPartialMatch =
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const isVerified =
|
|
55
|
+
const status = verification?.status;
|
|
56
|
+
const isMiss = status === "not_found";
|
|
57
|
+
const isFullMatchWithMissedValue = status === "found_phrase_missed_value";
|
|
58
|
+
const isFoundValueMissedFullMatch = status === "found_key_span_only";
|
|
59
|
+
const isPartialMatch = status === "partial_text_found" ||
|
|
60
|
+
status === "found_on_other_page" ||
|
|
61
|
+
status === "found_on_other_line" ||
|
|
62
|
+
status === "first_word_found";
|
|
63
|
+
const isVerified = status === "found" ||
|
|
64
64
|
isFoundValueMissedFullMatch ||
|
|
65
65
|
isPartialMatch ||
|
|
66
66
|
isFullMatchWithMissedValue;
|
|
67
|
-
const isPending =
|
|
68
|
-
searchState?.status === "loading" ||
|
|
69
|
-
!searchState;
|
|
67
|
+
const isPending = status === "pending" || status === "loading" || !status;
|
|
70
68
|
return { isVerified, isMiss, isPartialMatch, isPending };
|
|
71
69
|
}
|
|
72
70
|
export const parseCitation = (fragment, mdAttachmentId, citationCounterRef, isVerbose) => {
|
|
@@ -1,187 +1,93 @@
|
|
|
1
|
-
import React
|
|
1
|
+
import React from "react";
|
|
2
2
|
import { type CitationStatus } from "../types/citation.js";
|
|
3
3
|
import type { Verification } from "../types/verification.js";
|
|
4
4
|
import type { BaseCitationProps, CitationBehaviorConfig, CitationEventHandlers, CitationRenderProps, CitationVariant } from "./types.js";
|
|
5
|
-
import "./styles.css";
|
|
6
5
|
export type { CitationVariant } from "./types.js";
|
|
7
6
|
/**
|
|
8
7
|
* Props for the CitationComponent.
|
|
9
8
|
*
|
|
10
|
-
*
|
|
11
|
-
* ```tsx
|
|
12
|
-
* <CitationComponent
|
|
13
|
-
* citation={{ citationNumber: 1, keySpan: "Revenue grew by 25%" }}
|
|
14
|
-
* verification={verificationResult}
|
|
15
|
-
* />
|
|
16
|
-
* // Renders: [Revenue grew by 25%✓] with blue text
|
|
17
|
-
* ```
|
|
18
|
-
*
|
|
19
|
-
* @example Numeric only - use hideKeySpan=true with brackets variant
|
|
20
|
-
* ```tsx
|
|
21
|
-
* <CitationComponent
|
|
22
|
-
* citation={{ citationNumber: 1, keySpan: "25% growth" }}
|
|
23
|
-
* verification={verificationResult}
|
|
24
|
-
* hideKeySpan={true}
|
|
25
|
-
* />
|
|
26
|
-
* // Renders: [1✓]
|
|
27
|
-
* ```
|
|
28
|
-
*
|
|
29
|
-
* @example Without brackets - use hideBrackets=true
|
|
30
|
-
* ```tsx
|
|
31
|
-
* <CitationComponent
|
|
32
|
-
* citation={{ citationNumber: 1, keySpan: "25% growth" }}
|
|
33
|
-
* verification={verificationResult}
|
|
34
|
-
* hideBrackets={true}
|
|
35
|
-
* />
|
|
36
|
-
* // Renders: 25% growth✓ (no brackets)
|
|
37
|
-
* ```
|
|
9
|
+
* ## Behavior
|
|
38
10
|
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
* verification={verificationResult}
|
|
44
|
-
* variant="text"
|
|
45
|
-
* />
|
|
46
|
-
* // Renders: 25% growth✓ (inherits parent styling)
|
|
47
|
-
* ```
|
|
11
|
+
* Default interaction pattern:
|
|
12
|
+
* - **Hover**: Shows popover with verification image/details
|
|
13
|
+
* - **Click**: Opens full-size image overlay (zoom)
|
|
14
|
+
* - **Escape / Click outside / Click overlay**: Closes image overlay
|
|
48
15
|
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
* citation={citation}
|
|
53
|
-
* verification={verificationResult}
|
|
54
|
-
* variant="minimal"
|
|
55
|
-
* />
|
|
56
|
-
* // Renders: Revenue grew...✓
|
|
57
|
-
* ```
|
|
58
|
-
*
|
|
59
|
-
* @example Indicator-only variant
|
|
60
|
-
* ```tsx
|
|
61
|
-
* <CitationComponent
|
|
62
|
-
* citation={citation}
|
|
63
|
-
* verification={verificationResult}
|
|
64
|
-
* variant="indicator"
|
|
65
|
-
* />
|
|
66
|
-
* // Renders: ✓
|
|
67
|
-
* ```
|
|
16
|
+
* Custom behavior:
|
|
17
|
+
* - Use `behaviorConfig.onClick` to replace the default click behavior
|
|
18
|
+
* - Use `eventHandlers.onClick` to add side effects (disables default)
|
|
68
19
|
*
|
|
69
|
-
* @example
|
|
20
|
+
* @example Default usage
|
|
70
21
|
* ```tsx
|
|
71
22
|
* <CitationComponent
|
|
72
23
|
* citation={citation}
|
|
73
|
-
* verification={
|
|
74
|
-
* popoverPosition="hidden"
|
|
24
|
+
* verification={verification}
|
|
75
25
|
* />
|
|
76
26
|
* ```
|
|
77
27
|
*
|
|
78
|
-
* @example Custom click behavior
|
|
28
|
+
* @example Custom click behavior
|
|
79
29
|
* ```tsx
|
|
80
30
|
* <CitationComponent
|
|
81
31
|
* citation={citation}
|
|
82
|
-
* verification={
|
|
32
|
+
* verification={verification}
|
|
83
33
|
* behaviorConfig={{
|
|
84
|
-
* onClick: (context
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
* }
|
|
34
|
+
* onClick: (context) => {
|
|
35
|
+
* // Custom action
|
|
36
|
+
* console.log('Clicked:', context.citationKey);
|
|
37
|
+
* return { setImageExpanded: true };
|
|
88
38
|
* }
|
|
89
39
|
* }}
|
|
90
40
|
* />
|
|
91
41
|
* ```
|
|
92
|
-
*
|
|
93
|
-
* @example Disable all click behavior
|
|
94
|
-
* ```tsx
|
|
95
|
-
* <CitationComponent
|
|
96
|
-
* citation={citation}
|
|
97
|
-
* verification={verificationResult}
|
|
98
|
-
* behaviorConfig={{ onClick: () => false }}
|
|
99
|
-
* />
|
|
100
|
-
* ```
|
|
101
42
|
*/
|
|
102
43
|
export interface CitationComponentProps extends BaseCitationProps {
|
|
103
|
-
/**
|
|
104
|
-
* Verification result from the DeepCitation API.
|
|
105
|
-
* Contains match snippet, page number, and verification image.
|
|
106
|
-
*/
|
|
44
|
+
/** Verification result from the DeepCitation API */
|
|
107
45
|
verification?: Verification | null;
|
|
108
46
|
/**
|
|
109
47
|
* Display variant for the citation.
|
|
110
|
-
* - `brackets`:
|
|
111
|
-
* - `text`:
|
|
112
|
-
* - `minimal`:
|
|
113
|
-
* - `indicator`:
|
|
48
|
+
* - `brackets`: [keySpan✓] with styling (default)
|
|
49
|
+
* - `text`: keySpan✓ inherits parent styling
|
|
50
|
+
* - `minimal`: text with indicator, no brackets
|
|
51
|
+
* - `indicator`: only the status indicator
|
|
114
52
|
*/
|
|
115
53
|
variant?: CitationVariant;
|
|
116
|
-
/**
|
|
117
|
-
* Whether to hide square brackets around the citation.
|
|
118
|
-
* Only applies to the `brackets` variant.
|
|
119
|
-
* @default false
|
|
120
|
-
*/
|
|
54
|
+
/** Hide square brackets (only for brackets variant) */
|
|
121
55
|
hideBrackets?: boolean;
|
|
122
|
-
/**
|
|
123
|
-
* Event handlers for citation interactions.
|
|
124
|
-
* These are always called regardless of behaviorConfig settings.
|
|
125
|
-
*/
|
|
56
|
+
/** Event handlers for citation interactions */
|
|
126
57
|
eventHandlers?: CitationEventHandlers;
|
|
127
58
|
/**
|
|
128
59
|
* Configuration for customizing default click/hover behaviors.
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
* Default behaviors:
|
|
132
|
-
* - Hover: Shows zoom-in cursor when popover is pinned and has image
|
|
133
|
-
* - Click 1: Pins the popover open (stays visible without hover)
|
|
134
|
-
* - Click 2: Opens full-size image overlay (if image available)
|
|
135
|
-
* - Click 3: Closes image and unpins popover
|
|
136
|
-
*
|
|
137
|
-
* @see CitationBehaviorConfig for all options
|
|
60
|
+
* Providing onClick REPLACES the default click behavior.
|
|
138
61
|
*/
|
|
139
62
|
behaviorConfig?: CitationBehaviorConfig;
|
|
140
|
-
/**
|
|
141
|
-
* Enable mobile touch handlers.
|
|
142
|
-
* @default false
|
|
143
|
-
*/
|
|
63
|
+
/** Enable mobile touch handlers */
|
|
144
64
|
isMobile?: boolean;
|
|
145
|
-
/**
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* Custom render function for the entire citation content.
|
|
152
|
-
* When provided, takes full control of rendering.
|
|
153
|
-
*/
|
|
154
|
-
renderContent?: (props: CitationRenderProps) => ReactNode;
|
|
155
|
-
/**
|
|
156
|
-
* Position of the verification popover.
|
|
157
|
-
* Use "hidden" to disable the popover entirely.
|
|
158
|
-
* @default "top"
|
|
159
|
-
*/
|
|
65
|
+
/** Custom render function for the status indicator */
|
|
66
|
+
renderIndicator?: (status: CitationStatus) => React.ReactNode;
|
|
67
|
+
/** Custom render function for entire citation content */
|
|
68
|
+
renderContent?: (props: CitationRenderProps) => React.ReactNode;
|
|
69
|
+
/** Position of popover. Use "hidden" to disable. */
|
|
160
70
|
popoverPosition?: "top" | "bottom" | "hidden";
|
|
161
|
-
/**
|
|
162
|
-
* Custom render function for popover content.
|
|
163
|
-
*/
|
|
71
|
+
/** Custom render function for popover content */
|
|
164
72
|
renderPopoverContent?: (props: {
|
|
165
73
|
citation: BaseCitationProps["citation"];
|
|
166
74
|
verification: Verification | null;
|
|
167
75
|
status: CitationStatus;
|
|
168
|
-
}) => ReactNode;
|
|
76
|
+
}) => React.ReactNode;
|
|
169
77
|
}
|
|
170
78
|
/**
|
|
171
79
|
* CitationComponent displays a citation with verification status.
|
|
172
80
|
*
|
|
173
|
-
*
|
|
174
|
-
*
|
|
175
|
-
*
|
|
176
|
-
*
|
|
81
|
+
* ## Interaction Pattern
|
|
82
|
+
*
|
|
83
|
+
* - **Hover**: Shows popover with verification image or details
|
|
84
|
+
* - **Click**: Opens full-size image overlay (if image available)
|
|
85
|
+
* - **Escape / Click overlay**: Closes the image overlay
|
|
177
86
|
*
|
|
178
|
-
*
|
|
179
|
-
* - Exact match: green checkmark
|
|
180
|
-
* - Partial match: orange checkmark
|
|
181
|
-
* - Miss: no indicator
|
|
87
|
+
* ## Customization
|
|
182
88
|
*
|
|
183
|
-
*
|
|
184
|
-
*
|
|
89
|
+
* Use `behaviorConfig.onClick` to completely replace the click behavior,
|
|
90
|
+
* or `eventHandlers.onClick` to add side effects (which disables defaults).
|
|
185
91
|
*/
|
|
186
92
|
export declare const CitationComponent: React.ForwardRefExoticComponent<CitationComponentProps & React.RefAttributes<HTMLSpanElement>>;
|
|
187
93
|
export declare const MemoizedCitationComponent: React.NamedExoticComponent<CitationComponentProps & React.RefAttributes<HTMLSpanElement>>;
|