@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,196 @@
|
|
|
1
|
+
declare const CITATION_MARKDOWN_SYNTAX_PROMPT = "\n<citation-instructions priority=\"critical\">\n## REQUIRED: Citation Format\n\nYou MUST cite sources using this exact syntax:\n\n<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' />\n\n### Syntax Rules (MUST follow)\n\n1. **attachment_id**: Use the exact ID from the source document\n2. **reasoning**: Brief explanation of why this citation supports your claim (think first!)\n3. **key_span**: The 1-3 most important words from full_phrase\n4. **full_phrase**: Copy text VERBATIM from source. Escape quotes (\\') and newlines (\\n).\n5. **start_page_key**: ONLY use format `page_number_N_index_I` from page tags (e.g., `<page_number_1_index_0>`). Never extract page numbers from document content.\n6. **line_ids**: Inclusive range (e.g., '2-6' or '4'). Infer intermediate lines since only every 5th line is shown.\n\n### Placement Rules\n\n- Place <cite /> inline, typically at the end of a claim\n- One citation per distinct idea, concept, or value (a sentence citing 3 different values needs 3 citations)\n- Do NOT group citations at the end of the document\n- The <cite /> tag is self-closing - never use <cite>...</cite>\n\n### Example\n\nThe 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' />\n\n</citation-instructions>\n";
|
|
2
|
+
declare const AV_CITATION_MARKDOWN_SYNTAX_PROMPT = "\n<citation-instructions priority=\"critical\">\n## REQUIRED: Audio/Video Citation Format\n\nYou MUST cite sources using this exact syntax:\n\n<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' />\n\n### Syntax Rules (MUST follow)\n\n1. **attachment_id**: Use the exact ID from the source\n2. **reasoning**: Brief explanation of why this citation supports your claim (think first!)\n3. **key_span**: The 1-3 most important words from full_phrase\n4. **full_phrase**: Copy transcript text VERBATIM. Escape quotes (\\') and newlines (\\n).\n5. **timestamps**: Start and end time with milliseconds (e.g., '00:01:23.456-00:01:45.789')\n\n### Placement Rules\n\n- Place <cite /> inline, typically at the end of a claim\n- One citation per distinct idea, concept, or value (a sentence citing 3 different values needs 3 citations)\n- Do NOT group citations at the end of the document\n- The <cite /> tag is self-closing - never use <cite>...</cite>\n\n</citation-instructions>\n";
|
|
3
|
+
/**
|
|
4
|
+
* A brief reminder to reinforce citation requirements in user messages.
|
|
5
|
+
* Use this when you want to add emphasis without repeating full instructions.
|
|
6
|
+
*/
|
|
7
|
+
declare const CITATION_REMINDER = "<citation-reminder>Remember: You MUST use <cite /> tags with all required attributes for every claim from source documents.</citation-reminder>";
|
|
8
|
+
/**
|
|
9
|
+
* Audio/video version of the citation reminder.
|
|
10
|
+
*/
|
|
11
|
+
declare const CITATION_AV_REMINDER = "<citation-reminder>Remember: You MUST use <cite /> tags with timestamps for every claim from source media.</citation-reminder>";
|
|
12
|
+
interface WrapSystemPromptOptions {
|
|
13
|
+
/** The original system prompt to wrap with citation instructions */
|
|
14
|
+
systemPrompt: string;
|
|
15
|
+
/** Whether to use audio/video citation format (with timestamps) instead of text-based (with line IDs) */
|
|
16
|
+
isAudioVideo?: boolean;
|
|
17
|
+
}
|
|
18
|
+
interface WrapCitationPromptOptions {
|
|
19
|
+
/** The original system prompt to wrap with citation instructions */
|
|
20
|
+
systemPrompt: string;
|
|
21
|
+
/** The original user prompt */
|
|
22
|
+
userPrompt: string;
|
|
23
|
+
/** The extracted file text with metadata (from uploadFile response). Can be a single string or array for multiple files. */
|
|
24
|
+
deepTextPromptPortion?: string | string[];
|
|
25
|
+
/** Whether to use audio/video citation format (with timestamps) instead of text-based (with line IDs) */
|
|
26
|
+
isAudioVideo?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Whether to add a citation reminder to the user prompt.
|
|
29
|
+
* Useful for reinforcing citation requirements.
|
|
30
|
+
* @default false
|
|
31
|
+
*/
|
|
32
|
+
addUserReminder?: boolean;
|
|
33
|
+
}
|
|
34
|
+
interface WrapCitationPromptResult {
|
|
35
|
+
/** Enhanced system prompt with citation instructions */
|
|
36
|
+
enhancedSystemPrompt: string;
|
|
37
|
+
/** Enhanced user prompt (currently passed through unchanged) */
|
|
38
|
+
enhancedUserPrompt: string;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Wraps your existing system prompt with DeepCitation's citation syntax instructions.
|
|
42
|
+
* This enables LLMs to output verifiable citations that can be checked against source documents.
|
|
43
|
+
*
|
|
44
|
+
* ## Why We Wrap (Instructions at Start + Reminder at End)
|
|
45
|
+
*
|
|
46
|
+
* This function places full citation instructions at the **start** of your system prompt
|
|
47
|
+
* and a brief reminder at the **end**. This "wrap" strategy is intentional and based on
|
|
48
|
+
* two key principles:
|
|
49
|
+
*
|
|
50
|
+
* ### 1. Recency Effect (RE2)
|
|
51
|
+
* LLMs exhibit a "recency bias" where instructions closer to the end of the context
|
|
52
|
+
* window have stronger influence on output. The reminder at the end reinforces citation
|
|
53
|
+
* requirements right before generation begins.
|
|
54
|
+
*
|
|
55
|
+
* ### 2. Chain-of-Thought (CoT) Attribute Ordering
|
|
56
|
+
* The citation attributes are ordered to encourage the model to "think first":
|
|
57
|
+
* `attachment_id` → `reasoning` → `key_span` → `full_phrase` → `start_page_key` → `line_ids`
|
|
58
|
+
*
|
|
59
|
+
* By placing `reasoning` early, the model must articulate WHY it's citing before
|
|
60
|
+
* specifying WHAT it's citing, leading to more accurate and relevant citations.
|
|
61
|
+
*
|
|
62
|
+
* ### Why Not Just Append?
|
|
63
|
+
* In large system prompts, appended instructions can get "lost" in the middle of the
|
|
64
|
+
* effective context. Prepending ensures citation instructions have high priority,
|
|
65
|
+
* while the reminder leverages recency for reinforcement.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```typescript
|
|
69
|
+
* import { wrapSystemCitationPrompt } from '@deepcitation/deepcitation-js';
|
|
70
|
+
*
|
|
71
|
+
* const systemPrompt = "You are a helpful assistant that analyzes documents.";
|
|
72
|
+
* const enhanced = wrapSystemCitationPrompt({ systemPrompt });
|
|
73
|
+
*
|
|
74
|
+
* // Use enhanced prompt with your LLM
|
|
75
|
+
* const response = await openai.chat.completions.create({
|
|
76
|
+
* messages: [{ role: "system", content: enhanced }],
|
|
77
|
+
* // ...
|
|
78
|
+
* });
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
declare function wrapSystemCitationPrompt(options: WrapSystemPromptOptions): string;
|
|
82
|
+
/**
|
|
83
|
+
* Wraps both system and user prompts with DeepCitation's citation syntax instructions.
|
|
84
|
+
* This is the recommended way to prepare prompts for citation verification.
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```typescript
|
|
88
|
+
* import { wrapCitationPrompt } from '@deepcitation/deepcitation-js';
|
|
89
|
+
*
|
|
90
|
+
* // Single file
|
|
91
|
+
* const { enhancedSystemPrompt, enhancedUserPrompt } = wrapCitationPrompt({
|
|
92
|
+
* systemPrompt: "You are a helpful assistant.",
|
|
93
|
+
* userPrompt: "Analyze this document and summarize it.",
|
|
94
|
+
* deepTextPromptPortion, // from uploadFile response
|
|
95
|
+
* });
|
|
96
|
+
*
|
|
97
|
+
* // Multiple files
|
|
98
|
+
* const { enhancedSystemPrompt, enhancedUserPrompt } = wrapCitationPrompt({
|
|
99
|
+
* systemPrompt: "You are a helpful assistant.",
|
|
100
|
+
* userPrompt: "Compare these documents.",
|
|
101
|
+
* deepTextPromptPortion: [deepTextPromptPortion1, deepTextPromptPortion2], // array of file texts
|
|
102
|
+
* });
|
|
103
|
+
*
|
|
104
|
+
* // Use enhanced prompts with your LLM
|
|
105
|
+
* const response = await llm.chat({
|
|
106
|
+
* messages: [
|
|
107
|
+
* { role: "system", content: enhancedSystemPrompt },
|
|
108
|
+
* { role: "user", content: enhancedUserPrompt },
|
|
109
|
+
* ],
|
|
110
|
+
* });
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
declare function wrapCitationPrompt(options: WrapCitationPromptOptions): WrapCitationPromptResult;
|
|
114
|
+
declare const CITATION_JSON_OUTPUT_FORMAT: {
|
|
115
|
+
type: string;
|
|
116
|
+
properties: {
|
|
117
|
+
attachmentId: {
|
|
118
|
+
type: string;
|
|
119
|
+
};
|
|
120
|
+
reasoning: {
|
|
121
|
+
type: string;
|
|
122
|
+
description: string;
|
|
123
|
+
};
|
|
124
|
+
keySpan: {
|
|
125
|
+
type: string;
|
|
126
|
+
description: string;
|
|
127
|
+
};
|
|
128
|
+
fullPhrase: {
|
|
129
|
+
type: string;
|
|
130
|
+
description: string;
|
|
131
|
+
};
|
|
132
|
+
startPageKey: {
|
|
133
|
+
type: string;
|
|
134
|
+
description: string;
|
|
135
|
+
};
|
|
136
|
+
lineIds: {
|
|
137
|
+
type: string;
|
|
138
|
+
items: {
|
|
139
|
+
type: string;
|
|
140
|
+
};
|
|
141
|
+
description: string;
|
|
142
|
+
};
|
|
143
|
+
};
|
|
144
|
+
required: string[];
|
|
145
|
+
};
|
|
146
|
+
declare const CITATION_AV_BASED_JSON_OUTPUT_FORMAT: {
|
|
147
|
+
type: string;
|
|
148
|
+
properties: {
|
|
149
|
+
attachmentId: {
|
|
150
|
+
type: string;
|
|
151
|
+
};
|
|
152
|
+
startPageKey: {
|
|
153
|
+
type: string;
|
|
154
|
+
description: string;
|
|
155
|
+
};
|
|
156
|
+
fullPhrase: {
|
|
157
|
+
type: string;
|
|
158
|
+
description: string;
|
|
159
|
+
};
|
|
160
|
+
timestamps: {
|
|
161
|
+
type: string;
|
|
162
|
+
properties: {
|
|
163
|
+
startTime: {
|
|
164
|
+
type: string;
|
|
165
|
+
};
|
|
166
|
+
endTime: {
|
|
167
|
+
type: string;
|
|
168
|
+
};
|
|
169
|
+
};
|
|
170
|
+
required: string[];
|
|
171
|
+
description: string;
|
|
172
|
+
};
|
|
173
|
+
};
|
|
174
|
+
required: string[];
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
interface CompressedResult<T> {
|
|
178
|
+
compressed: T;
|
|
179
|
+
prefixMap: Record<string, string>;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Compress all occurrences of `ids` inside `obj`, returning a new object
|
|
184
|
+
* plus the `prefixMap` needed to decompress.
|
|
185
|
+
*/
|
|
186
|
+
declare function compressPromptIds<T>(obj: T, ids: string[] | undefined): CompressedResult<T>;
|
|
187
|
+
/**
|
|
188
|
+
* Decompress all minimal prefixes back into their full IDs,
|
|
189
|
+
* using the `prefixMap` returned from `compressPromptIds`.
|
|
190
|
+
*
|
|
191
|
+
* If you pass in a string, it will return a string.
|
|
192
|
+
* If you pass in an object, it will JSON‑serialize and parse it back.
|
|
193
|
+
*/
|
|
194
|
+
declare function decompressPromptIds<T>(compressed: T | string, prefixMap: Record<string, string>): T | string;
|
|
195
|
+
|
|
196
|
+
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, type CompressedResult, type WrapCitationPromptOptions, type WrapCitationPromptResult, type WrapSystemPromptOptions, compressPromptIds, decompressPromptIds, wrapCitationPrompt, wrapSystemCitationPrompt };
|
package/lib/prompts/index.d.ts
CHANGED
|
@@ -1,3 +1,196 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
declare const CITATION_MARKDOWN_SYNTAX_PROMPT = "\n<citation-instructions priority=\"critical\">\n## REQUIRED: Citation Format\n\nYou MUST cite sources using this exact syntax:\n\n<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' />\n\n### Syntax Rules (MUST follow)\n\n1. **attachment_id**: Use the exact ID from the source document\n2. **reasoning**: Brief explanation of why this citation supports your claim (think first!)\n3. **key_span**: The 1-3 most important words from full_phrase\n4. **full_phrase**: Copy text VERBATIM from source. Escape quotes (\\') and newlines (\\n).\n5. **start_page_key**: ONLY use format `page_number_N_index_I` from page tags (e.g., `<page_number_1_index_0>`). Never extract page numbers from document content.\n6. **line_ids**: Inclusive range (e.g., '2-6' or '4'). Infer intermediate lines since only every 5th line is shown.\n\n### Placement Rules\n\n- Place <cite /> inline, typically at the end of a claim\n- One citation per distinct idea, concept, or value (a sentence citing 3 different values needs 3 citations)\n- Do NOT group citations at the end of the document\n- The <cite /> tag is self-closing - never use <cite>...</cite>\n\n### Example\n\nThe 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' />\n\n</citation-instructions>\n";
|
|
2
|
+
declare const AV_CITATION_MARKDOWN_SYNTAX_PROMPT = "\n<citation-instructions priority=\"critical\">\n## REQUIRED: Audio/Video Citation Format\n\nYou MUST cite sources using this exact syntax:\n\n<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' />\n\n### Syntax Rules (MUST follow)\n\n1. **attachment_id**: Use the exact ID from the source\n2. **reasoning**: Brief explanation of why this citation supports your claim (think first!)\n3. **key_span**: The 1-3 most important words from full_phrase\n4. **full_phrase**: Copy transcript text VERBATIM. Escape quotes (\\') and newlines (\\n).\n5. **timestamps**: Start and end time with milliseconds (e.g., '00:01:23.456-00:01:45.789')\n\n### Placement Rules\n\n- Place <cite /> inline, typically at the end of a claim\n- One citation per distinct idea, concept, or value (a sentence citing 3 different values needs 3 citations)\n- Do NOT group citations at the end of the document\n- The <cite /> tag is self-closing - never use <cite>...</cite>\n\n</citation-instructions>\n";
|
|
3
|
+
/**
|
|
4
|
+
* A brief reminder to reinforce citation requirements in user messages.
|
|
5
|
+
* Use this when you want to add emphasis without repeating full instructions.
|
|
6
|
+
*/
|
|
7
|
+
declare const CITATION_REMINDER = "<citation-reminder>Remember: You MUST use <cite /> tags with all required attributes for every claim from source documents.</citation-reminder>";
|
|
8
|
+
/**
|
|
9
|
+
* Audio/video version of the citation reminder.
|
|
10
|
+
*/
|
|
11
|
+
declare const CITATION_AV_REMINDER = "<citation-reminder>Remember: You MUST use <cite /> tags with timestamps for every claim from source media.</citation-reminder>";
|
|
12
|
+
interface WrapSystemPromptOptions {
|
|
13
|
+
/** The original system prompt to wrap with citation instructions */
|
|
14
|
+
systemPrompt: string;
|
|
15
|
+
/** Whether to use audio/video citation format (with timestamps) instead of text-based (with line IDs) */
|
|
16
|
+
isAudioVideo?: boolean;
|
|
17
|
+
}
|
|
18
|
+
interface WrapCitationPromptOptions {
|
|
19
|
+
/** The original system prompt to wrap with citation instructions */
|
|
20
|
+
systemPrompt: string;
|
|
21
|
+
/** The original user prompt */
|
|
22
|
+
userPrompt: string;
|
|
23
|
+
/** The extracted file text with metadata (from uploadFile response). Can be a single string or array for multiple files. */
|
|
24
|
+
deepTextPromptPortion?: string | string[];
|
|
25
|
+
/** Whether to use audio/video citation format (with timestamps) instead of text-based (with line IDs) */
|
|
26
|
+
isAudioVideo?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Whether to add a citation reminder to the user prompt.
|
|
29
|
+
* Useful for reinforcing citation requirements.
|
|
30
|
+
* @default false
|
|
31
|
+
*/
|
|
32
|
+
addUserReminder?: boolean;
|
|
33
|
+
}
|
|
34
|
+
interface WrapCitationPromptResult {
|
|
35
|
+
/** Enhanced system prompt with citation instructions */
|
|
36
|
+
enhancedSystemPrompt: string;
|
|
37
|
+
/** Enhanced user prompt (currently passed through unchanged) */
|
|
38
|
+
enhancedUserPrompt: string;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Wraps your existing system prompt with DeepCitation's citation syntax instructions.
|
|
42
|
+
* This enables LLMs to output verifiable citations that can be checked against source documents.
|
|
43
|
+
*
|
|
44
|
+
* ## Why We Wrap (Instructions at Start + Reminder at End)
|
|
45
|
+
*
|
|
46
|
+
* This function places full citation instructions at the **start** of your system prompt
|
|
47
|
+
* and a brief reminder at the **end**. This "wrap" strategy is intentional and based on
|
|
48
|
+
* two key principles:
|
|
49
|
+
*
|
|
50
|
+
* ### 1. Recency Effect (RE2)
|
|
51
|
+
* LLMs exhibit a "recency bias" where instructions closer to the end of the context
|
|
52
|
+
* window have stronger influence on output. The reminder at the end reinforces citation
|
|
53
|
+
* requirements right before generation begins.
|
|
54
|
+
*
|
|
55
|
+
* ### 2. Chain-of-Thought (CoT) Attribute Ordering
|
|
56
|
+
* The citation attributes are ordered to encourage the model to "think first":
|
|
57
|
+
* `attachment_id` → `reasoning` → `key_span` → `full_phrase` → `start_page_key` → `line_ids`
|
|
58
|
+
*
|
|
59
|
+
* By placing `reasoning` early, the model must articulate WHY it's citing before
|
|
60
|
+
* specifying WHAT it's citing, leading to more accurate and relevant citations.
|
|
61
|
+
*
|
|
62
|
+
* ### Why Not Just Append?
|
|
63
|
+
* In large system prompts, appended instructions can get "lost" in the middle of the
|
|
64
|
+
* effective context. Prepending ensures citation instructions have high priority,
|
|
65
|
+
* while the reminder leverages recency for reinforcement.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```typescript
|
|
69
|
+
* import { wrapSystemCitationPrompt } from '@deepcitation/deepcitation-js';
|
|
70
|
+
*
|
|
71
|
+
* const systemPrompt = "You are a helpful assistant that analyzes documents.";
|
|
72
|
+
* const enhanced = wrapSystemCitationPrompt({ systemPrompt });
|
|
73
|
+
*
|
|
74
|
+
* // Use enhanced prompt with your LLM
|
|
75
|
+
* const response = await openai.chat.completions.create({
|
|
76
|
+
* messages: [{ role: "system", content: enhanced }],
|
|
77
|
+
* // ...
|
|
78
|
+
* });
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
declare function wrapSystemCitationPrompt(options: WrapSystemPromptOptions): string;
|
|
82
|
+
/**
|
|
83
|
+
* Wraps both system and user prompts with DeepCitation's citation syntax instructions.
|
|
84
|
+
* This is the recommended way to prepare prompts for citation verification.
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```typescript
|
|
88
|
+
* import { wrapCitationPrompt } from '@deepcitation/deepcitation-js';
|
|
89
|
+
*
|
|
90
|
+
* // Single file
|
|
91
|
+
* const { enhancedSystemPrompt, enhancedUserPrompt } = wrapCitationPrompt({
|
|
92
|
+
* systemPrompt: "You are a helpful assistant.",
|
|
93
|
+
* userPrompt: "Analyze this document and summarize it.",
|
|
94
|
+
* deepTextPromptPortion, // from uploadFile response
|
|
95
|
+
* });
|
|
96
|
+
*
|
|
97
|
+
* // Multiple files
|
|
98
|
+
* const { enhancedSystemPrompt, enhancedUserPrompt } = wrapCitationPrompt({
|
|
99
|
+
* systemPrompt: "You are a helpful assistant.",
|
|
100
|
+
* userPrompt: "Compare these documents.",
|
|
101
|
+
* deepTextPromptPortion: [deepTextPromptPortion1, deepTextPromptPortion2], // array of file texts
|
|
102
|
+
* });
|
|
103
|
+
*
|
|
104
|
+
* // Use enhanced prompts with your LLM
|
|
105
|
+
* const response = await llm.chat({
|
|
106
|
+
* messages: [
|
|
107
|
+
* { role: "system", content: enhancedSystemPrompt },
|
|
108
|
+
* { role: "user", content: enhancedUserPrompt },
|
|
109
|
+
* ],
|
|
110
|
+
* });
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
declare function wrapCitationPrompt(options: WrapCitationPromptOptions): WrapCitationPromptResult;
|
|
114
|
+
declare const CITATION_JSON_OUTPUT_FORMAT: {
|
|
115
|
+
type: string;
|
|
116
|
+
properties: {
|
|
117
|
+
attachmentId: {
|
|
118
|
+
type: string;
|
|
119
|
+
};
|
|
120
|
+
reasoning: {
|
|
121
|
+
type: string;
|
|
122
|
+
description: string;
|
|
123
|
+
};
|
|
124
|
+
keySpan: {
|
|
125
|
+
type: string;
|
|
126
|
+
description: string;
|
|
127
|
+
};
|
|
128
|
+
fullPhrase: {
|
|
129
|
+
type: string;
|
|
130
|
+
description: string;
|
|
131
|
+
};
|
|
132
|
+
startPageKey: {
|
|
133
|
+
type: string;
|
|
134
|
+
description: string;
|
|
135
|
+
};
|
|
136
|
+
lineIds: {
|
|
137
|
+
type: string;
|
|
138
|
+
items: {
|
|
139
|
+
type: string;
|
|
140
|
+
};
|
|
141
|
+
description: string;
|
|
142
|
+
};
|
|
143
|
+
};
|
|
144
|
+
required: string[];
|
|
145
|
+
};
|
|
146
|
+
declare const CITATION_AV_BASED_JSON_OUTPUT_FORMAT: {
|
|
147
|
+
type: string;
|
|
148
|
+
properties: {
|
|
149
|
+
attachmentId: {
|
|
150
|
+
type: string;
|
|
151
|
+
};
|
|
152
|
+
startPageKey: {
|
|
153
|
+
type: string;
|
|
154
|
+
description: string;
|
|
155
|
+
};
|
|
156
|
+
fullPhrase: {
|
|
157
|
+
type: string;
|
|
158
|
+
description: string;
|
|
159
|
+
};
|
|
160
|
+
timestamps: {
|
|
161
|
+
type: string;
|
|
162
|
+
properties: {
|
|
163
|
+
startTime: {
|
|
164
|
+
type: string;
|
|
165
|
+
};
|
|
166
|
+
endTime: {
|
|
167
|
+
type: string;
|
|
168
|
+
};
|
|
169
|
+
};
|
|
170
|
+
required: string[];
|
|
171
|
+
description: string;
|
|
172
|
+
};
|
|
173
|
+
};
|
|
174
|
+
required: string[];
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
interface CompressedResult<T> {
|
|
178
|
+
compressed: T;
|
|
179
|
+
prefixMap: Record<string, string>;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Compress all occurrences of `ids` inside `obj`, returning a new object
|
|
184
|
+
* plus the `prefixMap` needed to decompress.
|
|
185
|
+
*/
|
|
186
|
+
declare function compressPromptIds<T>(obj: T, ids: string[] | undefined): CompressedResult<T>;
|
|
187
|
+
/**
|
|
188
|
+
* Decompress all minimal prefixes back into their full IDs,
|
|
189
|
+
* using the `prefixMap` returned from `compressPromptIds`.
|
|
190
|
+
*
|
|
191
|
+
* If you pass in a string, it will return a string.
|
|
192
|
+
* If you pass in an object, it will JSON‑serialize and parse it back.
|
|
193
|
+
*/
|
|
194
|
+
declare function decompressPromptIds<T>(compressed: T | string, prefixMap: Record<string, string>): T | string;
|
|
195
|
+
|
|
196
|
+
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, type CompressedResult, type WrapCitationPromptOptions, type WrapCitationPromptResult, type WrapSystemPromptOptions, compressPromptIds, decompressPromptIds, wrapCitationPrompt, wrapSystemCitationPrompt };
|
package/lib/prompts/index.js
CHANGED
|
@@ -1,3 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
export * from "./citationPrompts.js";
|
|
3
|
-
export * from "./types.js";
|
|
1
|
+
export{b as AV_CITATION_MARKDOWN_SYNTAX_PROMPT,h as CITATION_AV_BASED_JSON_OUTPUT_FORMAT,d as CITATION_AV_REMINDER,g as CITATION_JSON_OUTPUT_FORMAT,a as CITATION_MARKDOWN_SYNTAX_PROMPT,c as CITATION_REMINDER,i as compressPromptIds,j as decompressPromptIds,f as wrapCitationPrompt,e as wrapSystemCitationPrompt}from'../chunk-2IZXUOQR.js';import'../chunk-O2XFH626.js';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
'use strict';var chunk3GR7VKUJ_cjs=require('../chunk-3GR7VKUJ.cjs');require('../chunk-F2MMVEVC.cjs');var Ie=require('react'),jsxRuntime=require('react/jsx-runtime'),reactDom=require('react-dom'),R=require('@radix-ui/react-popover');function _interopNamespace(e){if(e&&e.__esModule)return e;var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var Ie__namespace=/*#__PURE__*/_interopNamespace(Ie);var R__namespace=/*#__PURE__*/_interopNamespace(R);function le(e){try{return new URL(e).hostname.replace(/^www\./,"")}catch{return e.replace(/^https?:\/\/(www\.)?/,"").split("/")[0]}}function ye(e,t){return e.length<=t?e:e.slice(0,t-1)+"\u2026"}function at(e){try{let t=new URL(e),n=t.pathname+t.search;return n==="/"?"":n}catch{return ""}}var ke={verified:{icon:"\u2713",label:"Verified",className:"text-green-600 dark:text-green-500"},partial:{icon:"~",label:"Partial match",className:"text-amber-600 dark:text-amber-500"},pending:{icon:"\u2026",label:"Verifying",className:"text-gray-400 dark:text-gray-500"},blocked_antibot:{icon:"\u{1F6E1}",label:"Blocked by anti-bot",className:"text-amber-600 dark:text-amber-500"},blocked_login:{icon:"\u{1F512}",label:"Login required",className:"text-amber-600 dark:text-amber-500"},blocked_paywall:{icon:"\u{1F4B3}",label:"Paywall",className:"text-amber-600 dark:text-amber-500"},blocked_geo:{icon:"\u{1F30D}",label:"Geo-restricted",className:"text-amber-600 dark:text-amber-500"},blocked_rate_limit:{icon:"\u23F1",label:"Rate limited",className:"text-amber-600 dark:text-amber-500"},error_timeout:{icon:"\u23F0",label:"Timed out",className:"text-red-500 dark:text-red-400"},error_not_found:{icon:"404",label:"Not found",className:"text-red-500 dark:text-red-400"},error_server:{icon:"\u26A0",label:"Server error",className:"text-red-500 dark:text-red-400"},error_network:{icon:"\u26A1",label:"Network error",className:"text-red-500 dark:text-red-400"},unknown:{icon:"?",label:"Unknown status",className:"text-gray-400 dark:text-gray-500"}};function Pe(e){return e.startsWith("blocked_")}function Ne(e){return e.startsWith("error_")}function rt(e){return e==="verified"||e==="partial"}var ot=({status:e,errorMessage:t})=>{let n=ke[e];return jsxRuntime.jsx("span",{className:chunk3GR7VKUJ_cjs.n("inline-flex items-center gap-1",n.className),title:t||n.label,"aria-label":n.label,children:jsxRuntime.jsx("span",{className:"text-[0.9em]","aria-hidden":"true",children:n.icon})})},ie=({url:e,faviconUrl:t})=>{let n=le(e),r=t||`https://www.google.com/s2/favicons?domain=${n}&sz=16`;return jsxRuntime.jsx("img",{src:r,alt:"",className:"w-3.5 h-3.5 rounded-sm",width:14,height:14,loading:"lazy",onError:a=>{a.target.style.display="none";}})},we=Ie.forwardRef(({urlMeta:e,citation:t,children:n,className:r,variant:a="chip",showFullUrlOnHover:o=true,showFavicon:i=true,showTitle:d=false,maxDisplayLength:s=30,renderBlockedIndicator:l,onUrlClick:u,eventHandlers:p,preventTooltips:h=false},P)=>{let{url:g,domain:A,title:N,fetchStatus:C,faviconUrl:w,errorMessage:B}=e,v=Ie.useMemo(()=>t||{value:g,fullPhrase:N||g},[t,g,N]),m=Ie.useMemo(()=>chunk3GR7VKUJ_cjs.h(v),[v]),K=Ie.useMemo(()=>chunk3GR7VKUJ_cjs.j(m),[m]),M=Ie.useMemo(()=>A||le(g),[A,g]),L=Ie.useMemo(()=>at(g),[g]),D=Ie.useMemo(()=>{if(d&&N)return ye(N,s);let b=L?ye(L,s-M.length-1):"";return b?`${M}${b}`:M},[d,N,M,L,s]),S=ke[C],Z=Pe(C),ee=Ne(C),te=C==="verified",G=C==="partial",T=C==="pending",O=Ie.useCallback(b=>{b.preventDefault(),b.stopPropagation(),u?u(g,b):window.open(g,"_blank","noopener,noreferrer"),p?.onClick?.(v,m,b);},[u,g,p,v,m]),y=Ie.useCallback(()=>{p?.onMouseEnter?.(v,m);},[p,v,m]),E=Ie.useCallback(()=>{p?.onMouseLeave?.(v,m);},[p,v,m]),_=()=>Z||ee?l?l(C,B):jsxRuntime.jsx(ot,{status:C,errorMessage:B}):te?jsxRuntime.jsx("span",{className:"text-[0.85em] text-green-600 dark:text-green-500","aria-hidden":"true",title:"Verified",children:"\u2713"}):G?jsxRuntime.jsx("span",{className:"text-[0.85em] text-amber-600 dark:text-amber-500","aria-hidden":"true",title:"Partial match",children:"~"}):T?jsxRuntime.jsx("span",{className:"opacity-70","aria-hidden":"true",children:"\u2026"}):null;return a==="chip"?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[n,jsxRuntime.jsxs("span",{ref:P,"data-citation-id":m,"data-citation-instance":K,"data-url":g,"data-fetch-status":C,"data-variant":"chip",className:chunk3GR7VKUJ_cjs.n("inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-sm cursor-pointer transition-colors no-underline","bg-blue-100 dark:bg-blue-900/30",S.className,r),title:o?g:void 0,onMouseEnter:h?void 0:y,onMouseLeave:h?void 0:E,onMouseDown:O,onClick:b=>b.stopPropagation(),role:"link","aria-label":`Link to ${M}: ${S.label}`,children:[i&&jsxRuntime.jsx(ie,{url:g,faviconUrl:w}),jsxRuntime.jsx("span",{className:"max-w-[200px] overflow-hidden text-ellipsis whitespace-nowrap",children:D}),_()]})]}):a==="inline"?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[n,jsxRuntime.jsxs("a",{ref:P,href:g,"data-citation-id":m,"data-citation-instance":K,"data-fetch-status":C,"data-variant":"inline",className:chunk3GR7VKUJ_cjs.n("inline-flex items-center gap-1 cursor-pointer transition-colors no-underline border-b border-dotted border-current",S.className,r),title:o?g:void 0,onMouseEnter:h?void 0:y,onMouseLeave:h?void 0:E,onClick:b=>{b.preventDefault(),O(b);},target:"_blank",rel:"noopener noreferrer","aria-label":`Link to ${M}: ${S.label}`,children:[i&&jsxRuntime.jsx(ie,{url:g,faviconUrl:w}),jsxRuntime.jsx("span",{children:D}),_()]})]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[n,jsxRuntime.jsxs("span",{ref:P,"data-citation-id":m,"data-citation-instance":K,"data-url":g,"data-fetch-status":C,"data-variant":"bracket",className:chunk3GR7VKUJ_cjs.n("cursor-pointer transition-colors",S.className,r),title:o?g:void 0,onMouseEnter:h?void 0:y,onMouseLeave:h?void 0:E,onMouseDown:O,onClick:b=>b.stopPropagation(),role:"link","aria-label":`Link to ${M}: ${S.label}`,children:["[",i&&jsxRuntime.jsx(ie,{url:g,faviconUrl:w}),jsxRuntime.jsx("span",{className:"max-w-[200px] overflow-hidden text-ellipsis whitespace-nowrap",children:D}),_(),"]"]})]})});we.displayName="UrlCitationComponent";Ie.memo(we);var it=({className:e})=>jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"square",shapeRendering:"crispEdges",className:e,children:[jsxRuntime.jsx("path",{d:"M7 3 L3 3 L3 21 L7 21"}),jsxRuntime.jsx("path",{d:"M17 3 L21 3 L21 21 L17 21"})]}),Q=({className:e})=>jsxRuntime.jsx("svg",{className:chunk3GR7VKUJ_cjs.g("w-[0.7em] h-[0.7em]",e),viewBox:"0 0 256 256",fill:"currentColor","aria-hidden":"true",children:jsxRuntime.jsx("path",{d:"M229.66,77.66l-128,128a8,8,0,0,1-11.32,0l-56-56a8,8,0,0,1,11.32-11.32L96,188.69,218.34,66.34a8,8,0,0,1,11.32,11.32Z"})}),ce=({className:e})=>jsxRuntime.jsx("svg",{className:chunk3GR7VKUJ_cjs.g("w-[0.7em] h-[0.7em]",e),viewBox:"0 0 256 256",fill:"currentColor","aria-hidden":"true",children:jsxRuntime.jsx("path",{d:"M236.8,188.09,149.35,36.22h0a24.76,24.76,0,0,0-42.7,0L19.2,188.09a23.51,23.51,0,0,0,0,23.72A24.35,24.35,0,0,0,40.55,224h174.9a24.35,24.35,0,0,0,21.33-12.19A23.51,23.51,0,0,0,236.8,188.09ZM120,104a8,8,0,0,1,16,0v40a8,8,0,0,1-16,0Zm8,88a12,12,0,1,1,12-12A12,12,0,0,1,128,192Z"})}),de=({className:e})=>jsxRuntime.jsxs("svg",{className:chunk3GR7VKUJ_cjs.g("w-[0.7em] h-[0.7em] animate-spin",e),xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[jsxRuntime.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),jsxRuntime.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]});function st(...e){return e.filter(Boolean).join(" ")}var Ee=R__namespace.Root,_e=R__namespace.Trigger;var ue=Ie__namespace.forwardRef(({className:e,align:t="center",sideOffset:n=4,...r},a)=>jsxRuntime.jsx(R__namespace.Portal,{children:jsxRuntime.jsx(R__namespace.Content,{ref:a,align:t,sideOffset:n,className:st("z-50 max-w-sm rounded-md border bg-white p-1 shadow-md outline-none","border-gray-200 dark:border-gray-700 dark:bg-gray-900","data-[state=open]:animate-in data-[state=closed]:animate-out","data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0","data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95","data-[side=bottom]:slide-in-from-top-2","data-[side=left]:slide-in-from-right-2","data-[side=right]:slide-in-from-left-2","data-[side=top]:slide-in-from-bottom-2",e),...r})}));ue.displayName=R__namespace.Content.displayName;function Ve(e,t,n=(r,a)=>r===a){let r=e.length,a=t.length;if(r===0&&a===0)return [];if(r===0)return [{value:t.join(""),added:true,count:t.length}];if(a===0)return [{value:e.join(""),removed:true,count:e.length}];let o=0;for(;o<r&&o<a&&n(e[o],t[o]);)o++;let i=0;for(;i<r-o&&i<a-o&&n(e[r-1-i],t[a-1-i]);)i++;let d=e.slice(o,r-i),s=t.slice(o,a-i);if(d.length===0&&s.length===0)return [{value:e.join(""),count:e.length}];let l=lt(d,s,n),u=[];return o>0&&u.push({value:e.slice(0,o).join(""),count:o}),u.push(...l),i>0&&u.push({value:e.slice(r-i).join(""),count:i}),Te(u)}function lt(e,t,n){let r=e.length,a=t.length,o=r+a,i={1:0},d=[];e:for(let s=0;s<=o;s++){d.push({...i});for(let l=-s;l<=s;l+=2){let u;l===-s||l!==s&&i[l-1]<i[l+1]?u=i[l+1]:u=i[l-1]+1;let p=u-l;for(;u<r&&p<a&&n(e[u],t[p]);)u++,p++;if(i[l]=u,u>=r&&p>=a)break e}}return ct(d,e,t)}function ct(e,t,n){let r=[],a=t.length,o=n.length;for(let i=e.length-1;i>=0;i--){let d=e[i],s=a-o,l;s===-i||s!==i&&d[s-1]<d[s+1]?l=s+1:l=s-1;let u=d[l]??0,p=u-l;for(;a>u&&o>p;)a--,o--,r.unshift({value:t[a],count:1});i>0&&(a===u?(o--,r.unshift({value:n[o],added:true,count:1})):(a--,r.unshift({value:t[a],removed:true,count:1})));}return r}function Te(e){if(e.length===0)return [];let t=[];for(let n of e){let r=t[t.length-1];r&&r.added===n.added&&r.removed===n.removed?(r.value+=n.value,r.count=(r.count||1)+(n.count||1)):t.push({...n});}return t}function Le(e){if(!e)return [];let t=[],n="";for(let r=0;r<e.length;r++){let a=e[r];n+=a,a===`
|
|
2
|
+
`&&(t.push(n),n="");}return n.length>0&&t.push(n),t}var De="a-zA-Z0-9_\\u00AD\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02C6\\u02C8-\\u02D7\\u02DE-\\u02FF\\u1E00-\\u1EFF",dt=new RegExp(`[${De}]+|\\s+|[^${De}]`,"gu");function Re(e){return e?e.match(dt)||[]:[]}function Be(e,t){let n=0;for(;n<e.length&&n<t.length&&e[n]===t[n];)n++;return e.slice(0,n)}function pe(e,t){let n=0;for(;n<e.length&&n<t.length&&e[e.length-1-n]===t[t.length-1-n];)n++;return e.slice(e.length-n)}function ut(e){let t=[];for(let n=0;n<e.length;n++){let r=e[n];if(r.removed&&e[n+1]?.added){let a=r,o=e[n+1],d=Be(a.value,o.value).match(/^\s*/)?.[0]||"",s=a.value.slice(d.length),l=o.value.slice(d.length),p=pe(s,l).match(/\s*$/)?.[0]||"";d&&t.push({value:d,count:1});let h=a.value.slice(d.length,a.value.length-p.length),P=o.value.slice(d.length,o.value.length-p.length);h&&t.push({value:h,removed:true,count:1}),P&&t.push({value:P,added:true,count:1}),p&&t.push({value:p,count:1}),n++;continue}if(r.added&&n>0&&!e[n-1].added&&!e[n-1].removed){let a=t[t.length-1];if(a&&!a.added&&!a.removed){let o=r.value.match(/^\s*/)?.[0]||"",i=a.value.match(/\s*$/)?.[0]||"";if(o&&i){let d=pe(i,o);if(d){t.push({value:r.value.slice(d.length),added:true,count:1});continue}}}}if(r.removed&&!e[n+1]?.added&&n>0&&!e[n-1]?.added&&!e[n-1]?.removed){let a=t[t.length-1],o=e[n+1];if(a&&o&&!o.added&&!o.removed){let i=r.value.match(/^\s*/)?.[0]||"",d=r.value.match(/\s*$/)?.[0]||"",s=a.value.match(/\s*$/)?.[0]||"",l=o.value.match(/^\s*/)?.[0]||"";if(i&&s&&pe(s,i).length===i.length){t.push({value:r.value.slice(i.length),removed:true,count:1});continue}if(d&&l&&Be(d,l).length===d.length){t.push({value:r.value.slice(0,-d.length)||r.value,removed:true,count:1});continue}}}t.push({...r});}return Te(t)}function Ue(e,t){let n=Le(e),r=Le(t);return Ve(n,r)}function We(e,t){let n=Re(e),r=Re(t),a=Ve(n,r);return ut(a)}var Ae=(e="",t="")=>Ie.useMemo(()=>{let n=(e||"").trim().replace(/\r\n/g,`
|
|
3
|
+
`),r=(t||"").trim().replace(/\r\n/g,`
|
|
4
|
+
`),a=Ue(n,r),o=[],i=false,d=0;for(let u=0;u<a.length;u++){let p=a[u],h=a[u+1];if(p.removed&&h&&h.added){let P=We(p.value,h.value);o.push({type:"modified",parts:P}),i=true,d+=Math.abs(p.value.length-h.value.length),u++;}else p.added||p.removed?(o.push({type:p.added?"added":"removed",parts:[{value:p.value,added:p.added,removed:p.removed}]}),i=true,d+=p.value.length):o.push({type:"unchanged",parts:[{value:p.value}]});}let s=Math.max(n.length,r.length),l=s===0?1:1-d/s;return {diffResult:o,hasDiff:i,similarity:l,isHighVariance:l<.6}},[e,t]);function xt(e){switch(e){case "chip":case "text":case "brackets":return "keySpan";default:return "number"}}function ht(e){return e.replace(/^\[+\s*/,"").replace(/\s*\]+$/,"")}function vt(e,t,n){if(t==="indicator")return "";if(t==="keySpan"){let r=e.keySpan?.toString()||e.citationNumber?.toString()||n||"1";return ht(r)}return e.citationNumber?.toString()||"1"}function Ct(e){return e.isVerified&&!e.isPartialMatch?"Verified":e.isPartialMatch?"Partial Match":e.isMiss?"Not Found":e.isPending?"Verifying...":""}function bt(e){let t=e?.status;if(!e||!t)return {isVerified:false,isMiss:false,isPartialMatch:false,isPending:false};let n=t==="not_found",r=t==="pending"||t==="loading",a=t==="partial_text_found"||t==="found_on_other_page"||t==="found_on_other_line"||t==="first_word_found";return {isVerified:t==="found"||t==="found_key_span_only"||t==="found_phrase_missed_value"||a,isMiss:n,isPartialMatch:a,isPending:r}}function yt({src:e,alt:t,onClose:n}){return Ie.useEffect(()=>{let r=a=>{a.key==="Escape"&&n();};return document.addEventListener("keydown",r),()=>document.removeEventListener("keydown",r)},[n]),reactDom.createPortal(jsxRuntime.jsx("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center bg-black/80 backdrop-blur-sm animate-in fade-in-0",onClick:n,role:"dialog","aria-modal":"true","aria-label":"Full size verification image",children:jsxRuntime.jsx("div",{className:"relative max-w-[95vw] max-h-[95vh] cursor-zoom-out",children:jsxRuntime.jsx("img",{src:e,alt:t,className:"max-w-full max-h-[95vh] object-contain rounded-lg shadow-2xl",draggable:false})})}),document.body)}var kt=()=>jsxRuntime.jsx("span",{className:"inline-flex relative ml-0.5 text-green-600 dark:text-green-500","aria-hidden":"true",children:jsxRuntime.jsx(Q,{})}),Pt=()=>jsxRuntime.jsx("span",{className:"inline-flex relative ml-0.5 text-amber-600 dark:text-amber-500","aria-hidden":"true",children:jsxRuntime.jsx(Q,{})}),Nt=()=>jsxRuntime.jsx("span",{className:"inline-flex ml-1 text-gray-400 dark:text-gray-500","aria-hidden":"true",children:jsxRuntime.jsx(de,{})}),wt=()=>jsxRuntime.jsx("span",{className:"inline-flex relative ml-0.5 text-red-500 dark:text-red-400","aria-hidden":"true",children:jsxRuntime.jsx(ce,{})});function Mt({citation:e,verification:t,status:n,onImageClick:r}){let a=t?.verificationImageBase64,{isMiss:o,isPartialMatch:i}=n;if(a)return jsxRuntime.jsxs("div",{className:"p-1",children:[jsxRuntime.jsx("button",{type:"button",className:"block cursor-zoom-in",onClick:u=>{u.preventDefault(),u.stopPropagation(),r?.();},"aria-label":"Click to view full size",children:jsxRuntime.jsx("img",{src:t.verificationImageBase64,alt:"Citation verification",className:"max-w-[700px] max-h-[500px] w-auto h-auto object-contain rounded bg-gray-50 dark:bg-gray-800",loading:"lazy"})}),(o||i)&&jsxRuntime.jsx(Oe,{citation:e,verification:t,status:n})]});let d=Ct(n),s=t?.verifiedMatchSnippet,l=t?.verifiedPageNumber;return !s&&!d?null:jsxRuntime.jsxs("div",{className:"p-3 flex flex-col gap-2 min-w-[200px] max-w-[400px]",children:[d&&jsxRuntime.jsx("span",{className:chunk3GR7VKUJ_cjs.g("text-xs font-medium",n.isVerified&&!n.isPartialMatch&&"text-green-600 dark:text-green-500",n.isPartialMatch&&"text-amber-600 dark:text-amber-500",n.isMiss&&"text-red-600 dark:text-red-500",n.isPending&&"text-gray-500 dark:text-gray-400"),children:d}),s&&jsxRuntime.jsxs("span",{className:"text-sm text-gray-700 dark:text-gray-300 italic",children:['"',t.verifiedMatchSnippet,'"']}),l&&l>0&&jsxRuntime.jsxs("span",{className:"text-xs text-gray-500 dark:text-gray-400",children:["Page ",l]}),(o||i)&&jsxRuntime.jsx(Oe,{citation:e,verification:t,status:n})]})}function Oe({citation:e,verification:t,status:n}){let{isMiss:r,isPartialMatch:a}=n,o=e.fullPhrase||e.keySpan?.toString()||"",i=t?.verifiedMatchSnippet||"",{diffResult:d,hasDiff:s,isHighVariance:l}=Ae(o,i);if(!r&&!a)return null;let u=e.lineIds,p=t?.verifiedLineIds,h=u&&p&&JSON.stringify(u)!==JSON.stringify(p),P=e.pageNumber,g=t?.verifiedPageNumber,A=P!=null&&g!=null&&P!==g;return r?jsxRuntime.jsxs("div",{className:"mt-2 pt-2 border-t border-gray-200 dark:border-gray-700 text-xs space-y-2",children:[o&&jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("span",{className:"text-gray-500 dark:text-gray-400 font-medium uppercase text-[10px]",children:"Expected"}),jsxRuntime.jsx("p",{className:"mt-1 p-2 bg-gray-100 dark:bg-gray-800 rounded font-mono text-[11px] break-words text-red-600 dark:text-red-400 line-through opacity-70",children:o.length>100?o.slice(0,100)+"\u2026":o})]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("span",{className:"text-gray-500 dark:text-gray-400 font-medium uppercase text-[10px]",children:"Found"}),jsxRuntime.jsx("p",{className:"mt-1 p-2 bg-gray-100 dark:bg-gray-800 rounded font-mono text-[11px] text-amber-600 dark:text-amber-500 italic",children:"Not found in source"})]})]}):jsxRuntime.jsxs("div",{className:"mt-2 pt-2 border-t border-gray-200 dark:border-gray-700 text-xs space-y-2",children:[o&&i&&s?jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("span",{className:"text-gray-500 dark:text-gray-400 font-medium uppercase text-[10px]",children:"Diff"}),jsxRuntime.jsx("div",{className:"mt-1 p-2 bg-gray-100 dark:bg-gray-800 rounded font-mono text-[11px] break-words text-gray-700 dark:text-gray-300",children:l?jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsxs("span",{className:"text-gray-500 dark:text-gray-400 text-[10px]",children:["Expected:"," "]}),jsxRuntime.jsx("span",{className:"text-red-600 dark:text-red-400 line-through opacity-70",children:o.length>100?o.slice(0,100)+"\u2026":o})]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsxs("span",{className:"text-gray-500 dark:text-gray-400 text-[10px]",children:["Found:"," "]}),jsxRuntime.jsx("span",{className:"text-green-600 dark:text-green-400",children:i.length>100?i.slice(0,100)+"\u2026":i})]})]}):d.map((N,C)=>jsxRuntime.jsx("span",{children:N.parts.map((w,B)=>{let v=`p-${C}-${B}`;return w.removed?jsxRuntime.jsx("span",{className:"bg-red-200 dark:bg-red-900/50 text-red-700 dark:text-red-300 line-through",title:"Expected text",children:w.value},v):w.added?jsxRuntime.jsx("span",{className:"bg-green-200 dark:bg-green-900/50 text-green-700 dark:text-green-300",title:"Actual text found",children:w.value},v):jsxRuntime.jsx("span",{children:w.value},v)})},`block-${C}`))})]}):o&&!s?jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("span",{className:"text-gray-500 dark:text-gray-400 font-medium uppercase text-[10px]",children:"Text"}),jsxRuntime.jsx("p",{className:"mt-1 p-2 bg-gray-100 dark:bg-gray-800 rounded font-mono text-[11px] break-words text-gray-700 dark:text-gray-300",children:o.length>100?o.slice(0,100)+"\u2026":o})]}):null,A&&jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("span",{className:"text-gray-500 dark:text-gray-400 font-medium uppercase text-[10px]",children:"Page"}),jsxRuntime.jsxs("p",{className:"mt-1 font-mono text-[11px] text-gray-700 dark:text-gray-300",children:[jsxRuntime.jsx("span",{className:"text-red-600 dark:text-red-400 line-through opacity-70",children:P})," \u2192 ",g]})]}),h&&jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("span",{className:"text-gray-500 dark:text-gray-400 font-medium uppercase text-[10px]",children:"Line"}),jsxRuntime.jsxs("p",{className:"mt-1 font-mono text-[11px] text-gray-700 dark:text-gray-300",children:[jsxRuntime.jsx("span",{className:"text-red-600 dark:text-red-400 line-through opacity-70",children:u?.join(", ")})," \u2192 ",p?.join(", ")]})]})]})}var xe=Ie.forwardRef(({citation:e,children:t,className:n,fallbackDisplay:r,verification:a,isLoading:o=false,variant:i="brackets",content:d,eventHandlers:s,behaviorConfig:l,isMobile:u=false,renderIndicator:p,renderContent:h,popoverPosition:P="top",renderPopoverContent:g},A)=>{let N=Ie.useMemo(()=>d||xt(i),[d,i]),[C,w]=Ie.useState(false),[B,v]=Ie.useState(null),m=Ie.useMemo(()=>chunk3GR7VKUJ_cjs.h(e),[e]),K=Ie.useMemo(()=>chunk3GR7VKUJ_cjs.j(m),[m]),M=Ie.useMemo(()=>bt(a),[a]),{isMiss:L,isPartialMatch:D,isVerified:S,isPending:Z}=M,ee=5e3,[te,G]=Ie.useState(false),T=Ie.useRef(null),O=a?.verificationImageBase64||a?.status==="found"||a?.status==="found_key_span_only"||a?.status==="found_phrase_missed_value"||a?.status==="not_found"||a?.status==="partial_text_found"||a?.status==="found_on_other_page"||a?.status==="found_on_other_line"||a?.status==="first_word_found",y=(o||Z)&&!O&&!te;Ie.useEffect(()=>(T.current&&(clearTimeout(T.current),T.current=null),(o||Z)&&!O?(G(false),T.current=setTimeout(()=>{G(true);},ee)):G(false),()=>{T.current&&clearTimeout(T.current);}),[o,Z,O]);let E=Ie.useMemo(()=>vt(e,N,r),[e,N,r]),_=Ie.useCallback(()=>({citation:e,citationKey:m,verification:a??null,isTooltipExpanded:C,isImageExpanded:!!B,hasImage:!!a?.verificationImageBase64}),[e,m,a,C,B]),b=Ie.useCallback(x=>{x.setImageExpanded!==void 0&&(typeof x.setImageExpanded=="string"?v(x.setImageExpanded):x.setImageExpanded===true&&a?.verificationImageBase64?v(a.verificationImageBase64):x.setImageExpanded===false&&v(null));},[a?.verificationImageBase64]),ze=Ie.useCallback(x=>{x.preventDefault(),x.stopPropagation();let X=_();if(l?.onClick){let re=l.onClick(X,x);re&&typeof re=="object"&&b(re),s?.onClick?.(e,m,x);return}if(s?.onClick){s.onClick(e,m,x);return}a?.verificationImageBase64&&v(a.verificationImageBase64);},[l,s,e,m,a?.verificationImageBase64,_,b]),he=150,$=Ie.useRef(null),ne=Ie.useRef(false),U=Ie.useCallback(()=>{$.current&&(clearTimeout($.current),$.current=null);},[]),je=Ie.useCallback(()=>{U(),w(true),l?.onHover?.onEnter&&l.onHover.onEnter(_()),s?.onMouseEnter?.(e,m);},[s,l,e,m,_,U]),Fe=Ie.useCallback(()=>{U(),$.current=setTimeout(()=>{ne.current||(w(false),l?.onHover?.onLeave&&l.onHover.onLeave(_()),s?.onMouseLeave?.(e,m));},he);},[s,l,e,m,_,U]),He=Ie.useCallback(()=>{U(),ne.current=true;},[U]),Ke=Ie.useCallback(()=>{ne.current=false,U(),$.current=setTimeout(()=>{w(false),l?.onHover?.onLeave&&l.onHover.onLeave(_()),s?.onMouseLeave?.(e,m);},he);},[s,l,e,m,_,U]);Ie.useEffect(()=>()=>{$.current&&clearTimeout($.current);},[]);let Ze=Ie.useCallback(x=>{u&&(x.preventDefault(),x.stopPropagation(),s?.onTouchEnd?.(e,m,x));},[s,e,m,u]);if(r!=null&&N==="keySpan"&&L)return jsxRuntime.jsx("span",{className:chunk3GR7VKUJ_cjs.g("text-gray-400 dark:text-gray-500",n),children:r});let ae=chunk3GR7VKUJ_cjs.g((S||D)&&i==="brackets"&&"text-blue-600 dark:text-blue-400 hover:text-blue-700 dark:hover:text-blue-300 hover:underline",L&&"opacity-70 line-through text-gray-400 dark:text-gray-500",y&&"text-gray-500 dark:text-gray-400"),z=()=>p?p(M):y?jsxRuntime.jsx(Nt,{}):L?jsxRuntime.jsx(wt,{}):D?jsxRuntime.jsx(Pt,{}):S?jsxRuntime.jsx(kt,{}):null,ve=()=>{if(h)return h({citation:e,status:M,citationKey:m,displayText:E,isMergedDisplay:N==="keySpan"});if(N==="indicator")return jsxRuntime.jsx("span",{children:z()});if(i==="chip"){let x=chunk3GR7VKUJ_cjs.g(S&&!D&&!y&&"bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400",D&&!y&&"bg-amber-100 text-amber-700 dark:bg-amber-900/30 dark:text-amber-400",L&&!y&&"bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-400 line-through",y&&"bg-gray-100 text-gray-600 dark:bg-gray-800 dark:text-gray-400",!S&&!L&&!y&&"bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400");return jsxRuntime.jsxs("span",{className:chunk3GR7VKUJ_cjs.g("inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-sm font-medium",x),children:[jsxRuntime.jsx("span",{className:"max-w-60 overflow-hidden text-ellipsis whitespace-nowrap",children:E}),z()]})}if(i==="superscript"){let x=chunk3GR7VKUJ_cjs.g(S&&!D&&!y&&"text-green-600 dark:text-green-500",D&&!y&&"text-amber-600 dark:text-amber-500",L&&!y&&"text-red-500 dark:text-red-400 line-through",y&&"text-gray-400 dark:text-gray-500",!S&&!L&&!y&&"text-blue-600 dark:text-blue-400");return jsxRuntime.jsxs("sup",{className:chunk3GR7VKUJ_cjs.g("text-xs font-medium transition-colors hover:underline",x),children:["[",E,z(),"]"]})}return i==="text"?jsxRuntime.jsxs("span",{className:ae,children:[E,z()]}):i==="minimal"?jsxRuntime.jsxs("span",{className:chunk3GR7VKUJ_cjs.g("max-w-80 overflow-hidden text-ellipsis",ae),children:[E,z()]}):jsxRuntime.jsxs("span",{className:chunk3GR7VKUJ_cjs.g("inline-flex items-baseline gap-0.5 whitespace-nowrap","font-mono text-xs leading-tight","text-gray-500 dark:text-gray-400","transition-colors"),"aria-hidden":"true",children:["[",jsxRuntime.jsxs("span",{className:chunk3GR7VKUJ_cjs.g("max-w-80 overflow-hidden text-ellipsis",ae),children:[E,z()]}),"]"]})},Ge=!(P==="hidden")&&a&&(a.verificationImageBase64||a.verifiedMatchSnippet),Xe=!!a?.verificationImageBase64,Ce=B?jsxRuntime.jsx(yt,{src:B,alt:"Citation verification - full size",onClose:()=>v(null)}):null,be={"data-citation-id":m,"data-citation-instance":K,className:chunk3GR7VKUJ_cjs.g("relative inline-flex items-baseline cursor-pointer","px-0.5 -mx-0.5 rounded-sm","transition-all duration-150","hover:bg-blue-500/10 dark:hover:bg-blue-400/10",Xe&&"hover:cursor-zoom-in",n),onMouseEnter:je,onMouseLeave:Fe,onClick:ze,onTouchEndCapture:u?Ze:void 0,"aria-label":E?`[${E}]`:void 0};if(Ge){let x=g?g({citation:e,verification:a??null,status:M}):jsxRuntime.jsx(Mt,{citation:e,verification:a??null,status:M,onImageClick:()=>{a?.verificationImageBase64&&v(a.verificationImageBase64);}});return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[t,jsxRuntime.jsxs(Ee,{open:C,children:[jsxRuntime.jsx(_e,{asChild:true,children:jsxRuntime.jsx("span",{ref:A,...be,children:ve()})}),jsxRuntime.jsx(ue,{side:P==="bottom"?"bottom":"top",onPointerDownOutside:X=>X.preventDefault(),onInteractOutside:X=>X.preventDefault(),onMouseEnter:He,onMouseLeave:Ke,children:x})]}),Ce]})}return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[t,jsxRuntime.jsx("span",{ref:A,...be,children:ve()}),Ce]})});xe.displayName="CitationComponent";var St=Ie.memo(xe);Object.defineProperty(exports,"CITATION_X_PADDING",{enumerable:true,get:function(){return chunk3GR7VKUJ_cjs.o}});Object.defineProperty(exports,"CITATION_Y_PADDING",{enumerable:true,get:function(){return chunk3GR7VKUJ_cjs.p}});Object.defineProperty(exports,"classNames",{enumerable:true,get:function(){return chunk3GR7VKUJ_cjs.n}});Object.defineProperty(exports,"generateCitationInstanceId",{enumerable:true,get:function(){return chunk3GR7VKUJ_cjs.j}});Object.defineProperty(exports,"generateCitationKey",{enumerable:true,get:function(){return chunk3GR7VKUJ_cjs.h}});Object.defineProperty(exports,"getCitationDisplayText",{enumerable:true,get:function(){return chunk3GR7VKUJ_cjs.k}});Object.defineProperty(exports,"getCitationKeySpanText",{enumerable:true,get:function(){return chunk3GR7VKUJ_cjs.m}});Object.defineProperty(exports,"getCitationNumber",{enumerable:true,get:function(){return chunk3GR7VKUJ_cjs.l}});exports.CheckIcon=Q;exports.CitationComponent=xe;exports.DeepCitationIcon=it;exports.MemoizedCitationComponent=St;exports.SpinnerIcon=de;exports.WarningIcon=ce;exports.extractDomain=le;exports.isBlockedStatus=Pe;exports.isErrorStatus=Ne;exports.isVerifiedStatus=rt;
|