@deepcitation/deepcitation-js 1.1.29 → 1.1.31
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 +254 -253
- package/lib/chunk-4HRWJSX6.cjs +1 -0
- package/lib/chunk-ETIDLMKZ.js +1 -0
- package/lib/chunk-G6RPOT3H.js +2 -0
- package/lib/chunk-URRIEXFH.cjs +2 -0
- package/lib/client/index.cjs +1 -1
- package/lib/client/index.d.cts +9 -10
- package/lib/client/index.d.ts +9 -10
- package/lib/client/index.js +1 -1
- package/lib/index.cjs +1 -1
- package/lib/index.d.cts +48 -2
- package/lib/index.d.ts +48 -2
- package/lib/index.js +1 -1
- package/lib/react/index.cjs +2 -2
- package/lib/react/index.js +2 -2
- package/package.json +1 -1
- package/lib/chunk-3GR7VKUJ.cjs +0 -1
- package/lib/chunk-LSKISWWH.cjs +0 -2
- package/lib/chunk-QGXCOW3E.js +0 -1
- package/lib/chunk-RCHWBA6D.js +0 -2
package/README.md
CHANGED
|
@@ -1,253 +1,254 @@
|
|
|
1
|
-
<div align="center">
|
|
2
|
-
|
|
3
|
-
# @deepcitation/deepcitation-js
|
|
4
|
-
|
|
5
|
-
**Deterministic AI citation verification. Eliminate hallucination risk by proving every AI citation against source documents.**
|
|
6
|
-
|
|
7
|
-
[](https://www.npmjs.com/package/@deepcitation/deepcitation-js)
|
|
8
|
-
[](https://opensource.org/licenses/MIT)
|
|
9
|
-
[](https://www.typescriptlang.org/)
|
|
10
|
-
|
|
11
|
-
[Documentation](https://deepcitation.com/docs) · [Get Free API Key](https://deepcitation.com/signup) · [Examples](./examples) · [Discord](https://discord.gg/deepcitation)
|
|
12
|
-
|
|
13
|
-
</div>
|
|
14
|
-
|
|
15
|
-
---
|
|
16
|
-
|
|
17
|
-
## Why DeepCitation?
|
|
18
|
-
|
|
19
|
-
LLMs hallucinate. Even when given source documents, they make up quotes, invent statistics, and cite pages that don't exist. DeepCitation solves this by **deterministically verifying every citation** against your source documents—and generating visual proof.
|
|
20
|
-
|
|
21
|
-
<div align="center">
|
|
22
|
-
<img src="./examples/assets/deepcitation-medical-demo.gif" alt="DeepCitation medical documentation demo showing verified inline citations" width="700" />
|
|
23
|
-
<br />
|
|
24
|
-
<em>Medical documentation with verified inline citations — certainty at a glance</em>
|
|
25
|
-
</div>
|
|
26
|
-
|
|
27
|
-
```
|
|
28
|
-
Before: "Revenue grew 45% [1]" → ❓ Did the LLM make this up?
|
|
29
|
-
After: "Revenue grew 45% [1]" → ✅ Verified on page 3, line 12 (with screenshot)
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
## Features
|
|
33
|
-
|
|
34
|
-
- **Deterministic Matching** – Every citation traced to its exact location. No fuzzy matching, no guessing.
|
|
35
|
-
- **Visual Proof** – Automated screenshots with highlighted text show exactly where citations come from.
|
|
36
|
-
- **Any LLM Provider** – Works with OpenAI, Anthropic, Google, Azure, or your own models.
|
|
37
|
-
- **React Components** – Pre-built components + composable primitives for citation UIs.
|
|
38
|
-
- **TypeScript Native** – Full type safety with comprehensive type definitions.
|
|
39
|
-
|
|
40
|
-
## Installation
|
|
41
|
-
|
|
42
|
-
```bash
|
|
43
|
-
npm install @deepcitation/deepcitation-js
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
Get a free API key at [deepcitation.com](https://deepcitation.com/signup) — no credit card required.
|
|
47
|
-
|
|
48
|
-
```bash
|
|
49
|
-
# .env
|
|
50
|
-
DEEPCITATION_API_KEY=sk-dc-your_api_key_here
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
---
|
|
54
|
-
|
|
55
|
-
## Quick Start
|
|
56
|
-
|
|
57
|
-
DeepCitation works in three steps: **Pre-Prompt**, **Post-Prompt**, and **Display**.
|
|
58
|
-
|
|
59
|
-
### Step 1: Pre-Prompt
|
|
60
|
-
|
|
61
|
-
Upload source documents and enhance your prompt with citation instructions.
|
|
62
|
-
|
|
63
|
-
```typescript
|
|
64
|
-
import { DeepCitation, wrapCitationPrompt } from "@deepcitation/deepcitation-js";
|
|
65
|
-
|
|
66
|
-
const dc = new DeepCitation({ apiKey: process.env.DEEPCITATION_API_KEY });
|
|
67
|
-
|
|
68
|
-
// Upload source files, this can be done before the user types their prompt
|
|
69
|
-
const { fileDataParts, deepTextPromptPortion } = await dc.prepareFiles([
|
|
70
|
-
{ file: pdfBuffer, filename: "report.pdf" },
|
|
71
|
-
]);
|
|
72
|
-
|
|
73
|
-
// Wrap prompts with citation instructions
|
|
74
|
-
const { enhancedSystemPrompt, enhancedUserPrompt } = wrapCitationPrompt({
|
|
75
|
-
systemPrompt: "You are a helpful assistant...",
|
|
76
|
-
userPrompt: "Analyze this document",
|
|
77
|
-
deepTextPromptPortion,
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
// Call your LLM
|
|
81
|
-
const response = await llm.chat({
|
|
82
|
-
messages: [
|
|
83
|
-
{ role: "system", content: enhancedSystemPrompt },
|
|
84
|
-
{ role: "user", content: enhancedUserPrompt },
|
|
85
|
-
],
|
|
86
|
-
});
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
### Step 2: Post-Prompt
|
|
90
|
-
|
|
91
|
-
Verify citations against the source documents.
|
|
92
|
-
|
|
93
|
-
```typescript
|
|
94
|
-
const result = await dc.
|
|
95
|
-
llmOutput: response.content,
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
- [**
|
|
203
|
-
- [**
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
-
|
|
219
|
-
-
|
|
220
|
-
-
|
|
221
|
-
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
**
|
|
231
|
-
**
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
- [
|
|
251
|
-
- [
|
|
252
|
-
- [
|
|
253
|
-
- [
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# @deepcitation/deepcitation-js
|
|
4
|
+
|
|
5
|
+
**Deterministic AI citation verification. Eliminate hallucination risk by proving every AI citation against source documents.**
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/@deepcitation/deepcitation-js)
|
|
8
|
+
[](https://opensource.org/licenses/MIT)
|
|
9
|
+
[](https://www.typescriptlang.org/)
|
|
10
|
+
|
|
11
|
+
[Documentation](https://deepcitation.com/docs) · [Get Free API Key](https://deepcitation.com/signup) · [Examples](./examples) · [Discord](https://discord.gg/deepcitation)
|
|
12
|
+
|
|
13
|
+
</div>
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## Why DeepCitation?
|
|
18
|
+
|
|
19
|
+
LLMs hallucinate. Even when given source documents, they make up quotes, invent statistics, and cite pages that don't exist. DeepCitation solves this by **deterministically verifying every citation** against your source documents—and generating visual proof.
|
|
20
|
+
|
|
21
|
+
<div align="center">
|
|
22
|
+
<img src="./examples/assets/deepcitation-medical-demo.gif" alt="DeepCitation medical documentation demo showing verified inline citations" width="700" />
|
|
23
|
+
<br />
|
|
24
|
+
<em>Medical documentation with verified inline citations — certainty at a glance</em>
|
|
25
|
+
</div>
|
|
26
|
+
|
|
27
|
+
```
|
|
28
|
+
Before: "Revenue grew 45% [1]" → ❓ Did the LLM make this up?
|
|
29
|
+
After: "Revenue grew 45% [1]" → ✅ Verified on page 3, line 12 (with screenshot)
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Features
|
|
33
|
+
|
|
34
|
+
- **Deterministic Matching** – Every citation traced to its exact location. No fuzzy matching, no guessing.
|
|
35
|
+
- **Visual Proof** – Automated screenshots with highlighted text show exactly where citations come from.
|
|
36
|
+
- **Any LLM Provider** – Works with OpenAI, Anthropic, Google, Azure, or your own models.
|
|
37
|
+
- **React Components** – Pre-built components + composable primitives for citation UIs.
|
|
38
|
+
- **TypeScript Native** – Full type safety with comprehensive type definitions.
|
|
39
|
+
|
|
40
|
+
## Installation
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
npm install @deepcitation/deepcitation-js
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Get a free API key at [deepcitation.com](https://deepcitation.com/signup) — no credit card required.
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
# .env
|
|
50
|
+
DEEPCITATION_API_KEY=sk-dc-your_api_key_here
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## Quick Start
|
|
56
|
+
|
|
57
|
+
DeepCitation works in three steps: **Pre-Prompt**, **Post-Prompt**, and **Display**.
|
|
58
|
+
|
|
59
|
+
### Step 1: Pre-Prompt
|
|
60
|
+
|
|
61
|
+
Upload source documents and enhance your prompt with citation instructions.
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
import { DeepCitation, wrapCitationPrompt } from "@deepcitation/deepcitation-js";
|
|
65
|
+
|
|
66
|
+
const dc = new DeepCitation({ apiKey: process.env.DEEPCITATION_API_KEY });
|
|
67
|
+
|
|
68
|
+
// Upload source files, this can be done before the user types their prompt
|
|
69
|
+
const { fileDataParts, deepTextPromptPortion } = await dc.prepareFiles([
|
|
70
|
+
{ file: pdfBuffer, filename: "report.pdf" },
|
|
71
|
+
]);
|
|
72
|
+
|
|
73
|
+
// Wrap prompts with citation instructions
|
|
74
|
+
const { enhancedSystemPrompt, enhancedUserPrompt } = wrapCitationPrompt({
|
|
75
|
+
systemPrompt: "You are a helpful assistant...",
|
|
76
|
+
userPrompt: "Analyze this document",
|
|
77
|
+
deepTextPromptPortion,
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
// Call your LLM
|
|
81
|
+
const response = await llm.chat({
|
|
82
|
+
messages: [
|
|
83
|
+
{ role: "system", content: enhancedSystemPrompt },
|
|
84
|
+
{ role: "user", content: enhancedUserPrompt },
|
|
85
|
+
],
|
|
86
|
+
});
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Step 2: Post-Prompt
|
|
90
|
+
|
|
91
|
+
Verify citations against the source documents.
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
const result = await dc.verifyAll({
|
|
95
|
+
llmOutput: response.content,
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
// result.verifications contains verification status + visual proof
|
|
99
|
+
const { verifications } = result;
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Step 3: Display
|
|
103
|
+
|
|
104
|
+
Parse the LLM output and render verified citations inline with React components.
|
|
105
|
+
|
|
106
|
+
```tsx
|
|
107
|
+
import { CitationComponent } from "@deepcitation/deepcitation-js/react";
|
|
108
|
+
import {
|
|
109
|
+
parseCitation,
|
|
110
|
+
generateCitationKey,
|
|
111
|
+
} from "@deepcitation/deepcitation-js";
|
|
112
|
+
import "@deepcitation/deepcitation-js/react/styles.css";
|
|
113
|
+
|
|
114
|
+
function Response({ llmOutput, verifications }) {
|
|
115
|
+
// Split LLM output by citation tags and render inline
|
|
116
|
+
const renderWithCitations = (text: string) => {
|
|
117
|
+
const parts = text.split(/(<cite\s+[^>]*\/>)/g);
|
|
118
|
+
|
|
119
|
+
return parts.map((part, index) => {
|
|
120
|
+
if (part.startsWith("<cite")) {
|
|
121
|
+
const { citation } = parseCitation(part);
|
|
122
|
+
const citationKey = generateCitationKey(citation);
|
|
123
|
+
|
|
124
|
+
return (
|
|
125
|
+
<CitationComponent
|
|
126
|
+
key={index}
|
|
127
|
+
citation={citation}
|
|
128
|
+
verification={verifications[citationKey]}
|
|
129
|
+
/>
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
return <span key={index}>{part}</span>;
|
|
133
|
+
});
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
return <div>{renderWithCitations(llmOutput)}</div>;
|
|
137
|
+
}
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
---
|
|
141
|
+
|
|
142
|
+
## Core API
|
|
143
|
+
|
|
144
|
+
### DeepCitation Client
|
|
145
|
+
|
|
146
|
+
```typescript
|
|
147
|
+
const dc = new DeepCitation({
|
|
148
|
+
apiKey: string // Your API key (sk-dc-*)
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
// Upload and prepare source files
|
|
152
|
+
await dc.prepareFiles(files: FileInput[])
|
|
153
|
+
|
|
154
|
+
// Convert URLs/Office docs to PDF
|
|
155
|
+
await dc.convertToPdf(urlOrOptions: string | ConvertOptions)
|
|
156
|
+
|
|
157
|
+
// Verify LLM citations (parse and verify all)
|
|
158
|
+
await dc.verifyAll({ llmOutput, outputImageFormat? })
|
|
159
|
+
|
|
160
|
+
// Verify pre-parsed citations against a specific file
|
|
161
|
+
await dc.verify(attachmentId, citations, options?)
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### Prompt Utilities
|
|
165
|
+
|
|
166
|
+
```typescript
|
|
167
|
+
import {
|
|
168
|
+
wrapCitationPrompt, // Wrap system + user prompts
|
|
169
|
+
wrapSystemCitationPrompt, // Wrap system prompt only
|
|
170
|
+
getAllCitationsFromLlmOutput, // Extract citations from response
|
|
171
|
+
CITATION_JSON_OUTPUT_FORMAT, // JSON schema for structured output
|
|
172
|
+
} from "@deepcitation/deepcitation-js";
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### React Components
|
|
176
|
+
|
|
177
|
+
```typescript
|
|
178
|
+
import {
|
|
179
|
+
CitationComponent, // Primary citation display component
|
|
180
|
+
CitationVariants, // Alternative citation styles
|
|
181
|
+
UrlCitationComponent, // For URL-based citations
|
|
182
|
+
} from "@deepcitation/deepcitation-js/react";
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### Types
|
|
186
|
+
|
|
187
|
+
```typescript
|
|
188
|
+
import type {
|
|
189
|
+
Citation,
|
|
190
|
+
Verification,
|
|
191
|
+
SearchStatus,
|
|
192
|
+
SearchAttempt,
|
|
193
|
+
} from "@deepcitation/deepcitation-js";
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
---
|
|
197
|
+
|
|
198
|
+
## Examples
|
|
199
|
+
|
|
200
|
+
Check out the [examples directory](./examples) for complete, runnable examples:
|
|
201
|
+
|
|
202
|
+
- [**basic-verification**](./examples/basic-verification) – Core 3-step workflow
|
|
203
|
+
- [**support-bot**](./examples/support-bot) – Customer support bot with invisible citations
|
|
204
|
+
- [**nextjs-ai-sdk**](./examples/nextjs-ai-sdk) – Full-stack Next.js chat app
|
|
205
|
+
|
|
206
|
+
```bash
|
|
207
|
+
cd examples/basic-verification
|
|
208
|
+
npm install
|
|
209
|
+
cp .env.example .env # Add your API keys
|
|
210
|
+
npm run start:openai
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
---
|
|
214
|
+
|
|
215
|
+
## Documentation
|
|
216
|
+
|
|
217
|
+
For comprehensive documentation including:
|
|
218
|
+
- Full API reference
|
|
219
|
+
- Integration patterns
|
|
220
|
+
- Error handling
|
|
221
|
+
- Advanced React components
|
|
222
|
+
- TypeScript types
|
|
223
|
+
|
|
224
|
+
Visit **[deepcitation.com/docs](https://deepcitation.com/docs)**
|
|
225
|
+
|
|
226
|
+
---
|
|
227
|
+
|
|
228
|
+
## Supported File Types
|
|
229
|
+
|
|
230
|
+
**Documents:** PDF (native and scanned), URLs, Office formats (`.docx`, `.xlsx`, `.pptx`, etc.)
|
|
231
|
+
**Images:** PNG, JPEG, TIFF, WebP, AVIF, HEIC
|
|
232
|
+
**Media:** Audio and video (with timestamp-based citations)
|
|
233
|
+
|
|
234
|
+
---
|
|
235
|
+
|
|
236
|
+
## Contributing
|
|
237
|
+
|
|
238
|
+
Contributions are welcome! Please see [CONTRIBUTING.md](./CONTRIBUTING.md) for guidelines.
|
|
239
|
+
|
|
240
|
+
---
|
|
241
|
+
|
|
242
|
+
## License
|
|
243
|
+
|
|
244
|
+
MIT License - see [LICENSE](./LICENSE) for details.
|
|
245
|
+
|
|
246
|
+
---
|
|
247
|
+
|
|
248
|
+
## Links
|
|
249
|
+
|
|
250
|
+
- [Documentation](https://deepcitation.com/docs)
|
|
251
|
+
- [Get API Key](https://deepcitation.com/signup)
|
|
252
|
+
- [Discord Community](https://discord.gg/deepcitation)
|
|
253
|
+
- [GitHub Issues](https://github.com/deepcitation/deepcitation-js/issues)
|
|
254
|
+
- [Examples](./examples)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';function E(t){return new TextEncoder().encode(t)}function Z(t){let e=1732584193,i=4023233417,r=2562383102,n=271733878,o=3285377520,p=t.length,a=p*8,c=p+1+8,l=Math.ceil(c/64)*64,s=new ArrayBuffer(l),C=new Uint8Array(s),d=new DataView(s);C.set(t),C[p]=128,d.setUint32(l-8,Math.floor(a/4294967296),false),d.setUint32(l-4,a>>>0,false);let u=new Uint32Array(80);for(let x=0;x<l;x+=64){for(let g=0;g<16;g++)u[g]=d.getUint32(x+g*4,false);for(let g=16;g<80;g++){let I=u[g-3]^u[g-8]^u[g-14]^u[g-16];u[g]=I<<1|I>>>31;}let f=e,h=i,_=r,k=n,S=o;for(let g=0;g<80;g++){let I,m;g<20?(I=h&_|~h&k,m=1518500249):g<40?(I=h^_^k,m=1859775393):g<60?(I=h&_|h&k|_&k,m=2400959708):(I=h^_^k,m=3395469782);let b=(f<<5|f>>>27)+I+S+m+u[g]>>>0;S=k,k=_,_=(h<<30|h>>>2)>>>0,h=f,f=b;}e=e+f>>>0,i=i+h>>>0,r=r+_>>>0,n=n+k>>>0,o=o+S>>>0;}let y=x=>x.toString(16).padStart(8,"0");return y(e)+y(i)+y(r)+y(n)+y(o)}function P(t){try{if(!t)return "";let e=typeof t=="string"?t:JSON.stringify(t);return Z(E(e))}catch(e){console.error("Error in making the hash:",e);}return ""}function q(...t){return t.filter(Boolean).join(" ")}function A(t){let e=t.pageNumber||v(t.startPageKey),i=[t.attachmentId||"",e?.toString()||"",t.fullPhrase||"",t.keySpan?.toString()||"",t.lineIds?.join(",")||"",t.timestamps?.startTime||"",t.timestamps?.endTime||""];return P(i.join("|")).slice(0,16)}function Y(t){let e=[t.attachmentId||"",t.label||"",t.verifiedFullPhrase||"",t.verifiedKeySpan||"",t.verifiedLineIds?.join(",")||"",t.verifiedPageNumber?.toString()||"",t.verifiedTimestamps?.startTime||"",t.verifiedTimestamps?.endTime||"",t.verifiedMatchSnippet||"",t.hitIndexWithinPage?.toString()||""];return P(e.join("|")).slice(0,16)}function j(t){let e=Math.random().toString(36).slice(2,11);return `${t}-${e}`}function Q(t,e={}){let{fallbackDisplay:i}=e;return t.keySpan?.toString()||t.citationNumber?.toString()||i||"1"}function tt(t){return t.citationNumber?.toString()||"1"}function et(t){return t.keySpan?.toString()||""}function nt(...t){return t.filter(Boolean).join(" ")}var it=4,rt=1;function D(t){if(!t)return;let e=[],i=t.split(",");for(let r of i){let n=r.trim();if(n)if(n.includes("-")){let[o,p]=n.split("-"),a=parseInt(o,10),c=parseInt(p,10);if(!isNaN(a)&&!isNaN(c)&&a<=c)for(let l=a;l<=c;l++)e.push(l);else isNaN(a)||e.push(a);}else {let o=parseInt(n,10);isNaN(o)||e.push(o);}}if(e.length!==0)return [...new Set(e)].sort((r,n)=>r-n)}function R(t){let e=t?.status,i=e==="not_found",r=e==="found_phrase_missed_value",n=e==="found_key_span_only",o=e==="partial_text_found"||e==="found_on_other_page"||e==="found_on_other_line"||e==="first_word_found";return {isVerified:e==="found"||n||o||r,isMiss:i,isPartialMatch:o,isPending:e==="pending"||e==="loading"||!e}}var U=(t,e,i,r)=>{let n=m=>m?m.replace(/^['"]|['"]$/g,"").replace(/\\'/g,"'"):void 0,o=i?.current?i.current++:void 0,p=t.substring(0,t.indexOf("<cite")),a=t.includes("/>")?t.slice(t.indexOf("/>")+2):"",c=t.substring(t.indexOf("<cite"),t.indexOf("/>")+2),l=(m,b)=>{for(let O of b){let L=new RegExp(`${O}='((?:[^'\\\\]|\\\\.)*)'`),K=m.match(L);if(K)return K[1]}},s=l(c,["attachment_id","attachmentId","file_id","fileId"]),C=s?.length===20?s:e||s,d=l(c,["start_page_key","startPageKey","start_page"]),u,y;if(d){let m=d.match(/page[\_a-zA-Z]*(\d+)_index_(\d+)/);m&&(u=parseInt(m[1]),y=parseInt(m[2]));}let x=n(l(c,["full_phrase","fullPhrase"])),f=n(l(c,["key_span","keySpan"])),h=n(l(c,["reasoning"])),_=n(l(c,["value"])),k;try{let b=l(c,["line_ids","lineIds"])?.replace(/[A-Za-z_[\](){}:]/g,"");k=b?D(b):void 0;}catch(m){r&&console.error("Error parsing lineIds",m);}let S=l(c,["timestamps"]),g;if(S){let[m,b]=S.split("-")||[];g={startTime:m,endTime:b};}let I={attachmentId:C,pageNumber:u,startPageKey:`page_number_${u||1}_index_${y||0}`,fullPhrase:x,keySpan:f||_,citationNumber:o,lineIds:k,beforeCite:p,timestamps:g,reasoning:h};return {beforeCite:p,afterCite:a,citation:I}},B=(t,e)=>{if(!t)return null;let i=t.fullPhrase??t.full_phrase,r=t.startPageKey??t.start_page_key,n=t.keySpan??t.key_span,o=t.lineIds??t.line_ids,p=t.attachmentId??t.attachment_id??t.fileId??t.file_id,a=t.reasoning,c=t.value;if(!i)return null;let l;if(r){let d=r.match(/page[_a-zA-Z]*(\d+)_index_(\d+)/i);if(d)l=parseInt(d[1],10);else {let u=r.match(/^(\d+)_(\d+)$/);u&&(l=parseInt(u[1],10));}}let s=o?.length?[...o].sort((d,u)=>d-u):void 0;return {attachmentId:p,pageNumber:l,fullPhrase:i,citationNumber:e,lineIds:s,keySpan:n||c,reasoning:a}},V=t=>typeof t=="object"&&t!==null&&("fullPhrase"in t||"full_phrase"in t||"startPageKey"in t||"start_page_key"in t||"keySpan"in t||"key_span"in t||"lineIds"in t||"line_ids"in t),N=t=>Array.isArray(t)?t.length>0&&t.some(V):typeof t=="object"&&t!==null?V(t):false,M=t=>{let e={},i=Array.isArray(t)?t:[t],r=1;for(let n of i){let o=B(n,r++);if(o&&o.fullPhrase){let p=A(o);e[p]=o;}}return e},w=(t,e)=>{if(!(!t||typeof t!="object")){if(t.citation&&N(t.citation)){let i=Array.isArray(t.citation)?t.citation:[t.citation];e.push(...i);}if(t.citations&&N(t.citations)){let i=Array.isArray(t.citations)?t.citations:[t.citations];e.push(...i);}if(Array.isArray(t))for(let i of t)w(i,e);else for(let i of Object.keys(t))i!=="citation"&&i!=="citations"&&w(t[i],e);}},T=t=>{let e=$(t),i=/<cite\s+[^>]*\/>/g,r=e.match(i);if(!r||r.length===0)return {};let n={},o={current:1};for(let p of r){let{citation:a}=U(p,void 0,o);if(a&&a.fullPhrase){let c=A(a);n[c]=a;}}return n},ct=t=>{if(!t)return {};let e={};if(typeof t=="object"){if(N(t)){let n=M(t);Object.assign(e,n);}else {let n=[];if(w(t,n),n.length>0){let o=M(n);Object.assign(e,o);}}let i=JSON.stringify(t),r=T(i);Object.assign(e,r);}else if(typeof t=="string"){let i=T(t);Object.assign(e,i);}return e};function lt(t){let e=new Map,i=Array.isArray(t)?t.map((r,n)=>[A(r)||String(n+1),r]):Object.entries(t);for(let[r,n]of i){let o=n.attachmentId||"";e.has(o)||e.set(o,{}),e.get(o)[r]=n;}return e}function ut(t){let e={},i=Array.isArray(t)?t.map((r,n)=>[A(r)||String(n+1),r]):Object.entries(t);for(let[r,n]of i){let o=n.attachmentId||"";e[o]||(e[o]={}),e[o][r]=n;}return e}var J=t=>{let e={},i=/([a-zA-Z_][a-zA-Z0-9_]*)\s*=\s*(['"])((?:[^'"\\]|\\.)*)\2/g,r;for(;(r=i.exec(t))!==null;){let n=r[1].toLowerCase().replace(/([a-z])([A-Z])/g,"$1_$2").toLowerCase(),o=r[3],p=n==="fileid"||n==="file_id"||n==="attachmentid"?"attachment_id":n==="keyspan"?"key_span":n==="fullphrase"?"full_phrase":n==="lineids"?"line_ids":n==="startpagekey"||n==="start_pagekey"?"start_page_key":n;e[p]=o;}return e},F=t=>{if(!t)return "\u25CC";let e=R(t);return e.isPending?"\u25CC":e.isMiss?"\u2717":e.isPartialMatch?"\u26A0":e.isVerified?"\u2713":"\u25CC"},W=(t,e={})=>{let{leaveKeySpanBehind:i=false,verifications:r,showVerificationStatus:n=false}=e,o=0,p=/<cite\s+[^>]*?\/>/g;return t.replace(p,a=>{o++;let c=J(a),l="";if(i&&c.key_span&&(l=c.key_span.replace(/\\'/g,"'").replace(/\\"/g,'"')),n&&r){let s,C=String(o);if(s=r[C],!s&&c.attachment_id){for(let[,u]of Object.entries(r))if(u.attachmentId===c.attachment_id){s=u;break}}let d=F(s);l=l?`${l}${d}`:d;}return l})},gt=(t,e)=>W(t,{leaveKeySpanBehind:e}),dt=t=>t.replace(/<page_number_\d+_index_\d+>/g,"").replace(/<\/page_number_\d+_index_\d+>/g,"").trim(),mt=t=>{let e=/<line id="[^"]*">|<\/line>/g;return t.replace(e,"")},v=t=>{if(!t)return null;let e=t.match(/\d+/)?.[0];return e?parseInt(e):null},$=t=>{let e=t?.trim()||"",i=e.split(/(<cite[\s\S]*?(?:\/>|<\/cite>))/gm);return i.length<=1?z(e):(e=i.map(r=>r.startsWith("<cite")?z(r):r).join(""),e)},z=t=>{let e=t;e=e.replace(/><\/cite>/g,"/>");let i=p=>{let a=p.toLowerCase();return a==="fullphrase"||a==="full_phrase"?"full_phrase":a==="lineids"||a==="line_ids"?"line_ids":a==="startpagekey"||a==="start_pagekey"||a==="start_page_key"?"start_page_key":a==="fileid"||a==="file_id"||a==="attachmentid"||a==="attachment_id"?"attachment_id":a==="keyspan"||a==="key_span"?"key_span":a==="reasoning"||a==="value"?a:a==="timestamps"||a==="timestamp"||a==="timestamps"?"timestamps":a},r=p=>p.replace(/"/g,'"').replace(/'/g,"'").replace(/</g,"<").replace(/>/g,">").replace(/&/g,"&"),n=/(fullPhrase|full_phrase|keySpan|key_span|reasoning|value)\s*=\s*(['"])([\s\S]*?)(?=\s+(?:line_ids|lineIds|timestamps|fileId|file_id|attachmentId|attachment_id|start_page_key|start_pageKey|startPageKey|keySpan|key_span|reasoning|value|full_phrase)|\s*\/?>)/gm;e=e.replace(n,(p,a,c,l)=>{let s=l;return s.endsWith(c)&&(s=s.slice(0,-1)),s=s.replace(/(\r?\n)+/g," "),s=r(s),s=s.replace(/(\*|_){2,}/g,""),s=s.replace(/\\\\'/g,"'"),s=s.replace(/\\'/g,"'"),s=s.replace(/'/g,"\\'"),s=s.replace(/\\\\"/g,'"'),s=s.replace(/\\"/g,'"'),s=s.replace(/"/g,'\\"'),s=s.replace(/\*/g,""),`${i(a)}='${s}'`}),e=e.replace(/(line_ids|lineIds|timestamps)=['"]?([\[\]\(\){}A-Za-z0-9_\-, ]+)['"]?(\s*\/?>|\s+)/gm,(p,a,c,l)=>{let s=c.replace(/[A-Za-z\[\]\(\){}]/g,"");return s=s.replace(/(\d+)-(\d+)/g,(C,d,u)=>{let y=parseInt(d,10),x=parseInt(u,10),f=[];if(y<=x)for(let h=y;h<=x;h++)f.push(h);else f.push(y);return f.join(",")}),s=s.replace(/,+/g,",").replace(/^,|,$/g,""),`${i(a)}='${s}'${l}`});let o=p=>{let a=/([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(['"])((?:[^'"\\\n]|\\.)*)(?:\2)/g,c={},l;for(;l=a.exec(p);){let f=l[1],h=l[3],_=i(f);c[_]=h;}let s=Object.keys(c);if(s.length===0)return p;let C=typeof c.timestamps=="string"&&c.timestamps.length>0,d=s.filter(f=>f.startsWith("start_page")),u=[];c.attachment_id&&u.push("attachment_id"),C?(c.full_phrase&&u.push("full_phrase"),u.push("timestamps")):(d.includes("start_page_key")&&u.push("start_page_key"),d.filter(f=>f!=="start_page_key").sort().forEach(f=>u.push(f)),c.full_phrase&&u.push("full_phrase"),c.key_span&&u.push("key_span"),c.line_ids&&u.push("line_ids")),c.reasoning&&u.push("reasoning"),c.value&&u.push("value");let y=new Set(u);return s.filter(f=>!y.has(f)).sort().forEach(f=>u.push(f)),`<cite ${u.map(f=>`${f}='${c[f]}'`).join(" ")} />`};return e=e.replace(/<cite\b[\s\S]*?\/>/gm,p=>o(p)),e};exports.a=W;exports.b=gt;exports.c=dt;exports.d=mt;exports.e=v;exports.f=$;exports.g=P;exports.h=q;exports.i=A;exports.j=Y;exports.k=j;exports.l=Q;exports.m=tt;exports.n=et;exports.o=nt;exports.p=it;exports.q=rt;exports.r=R;exports.s=U;exports.t=ct;exports.u=lt;exports.v=ut;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function E(t){return new TextEncoder().encode(t)}function Z(t){let e=1732584193,i=4023233417,r=2562383102,n=271733878,o=3285377520,p=t.length,a=p*8,c=p+1+8,l=Math.ceil(c/64)*64,s=new ArrayBuffer(l),C=new Uint8Array(s),d=new DataView(s);C.set(t),C[p]=128,d.setUint32(l-8,Math.floor(a/4294967296),false),d.setUint32(l-4,a>>>0,false);let u=new Uint32Array(80);for(let x=0;x<l;x+=64){for(let g=0;g<16;g++)u[g]=d.getUint32(x+g*4,false);for(let g=16;g<80;g++){let I=u[g-3]^u[g-8]^u[g-14]^u[g-16];u[g]=I<<1|I>>>31;}let f=e,h=i,_=r,k=n,S=o;for(let g=0;g<80;g++){let I,m;g<20?(I=h&_|~h&k,m=1518500249):g<40?(I=h^_^k,m=1859775393):g<60?(I=h&_|h&k|_&k,m=2400959708):(I=h^_^k,m=3395469782);let b=(f<<5|f>>>27)+I+S+m+u[g]>>>0;S=k,k=_,_=(h<<30|h>>>2)>>>0,h=f,f=b;}e=e+f>>>0,i=i+h>>>0,r=r+_>>>0,n=n+k>>>0,o=o+S>>>0;}let y=x=>x.toString(16).padStart(8,"0");return y(e)+y(i)+y(r)+y(n)+y(o)}function P(t){try{if(!t)return "";let e=typeof t=="string"?t:JSON.stringify(t);return Z(E(e))}catch(e){console.error("Error in making the hash:",e);}return ""}function q(...t){return t.filter(Boolean).join(" ")}function A(t){let e=t.pageNumber||v(t.startPageKey),i=[t.attachmentId||"",e?.toString()||"",t.fullPhrase||"",t.keySpan?.toString()||"",t.lineIds?.join(",")||"",t.timestamps?.startTime||"",t.timestamps?.endTime||""];return P(i.join("|")).slice(0,16)}function Y(t){let e=[t.attachmentId||"",t.label||"",t.verifiedFullPhrase||"",t.verifiedKeySpan||"",t.verifiedLineIds?.join(",")||"",t.verifiedPageNumber?.toString()||"",t.verifiedTimestamps?.startTime||"",t.verifiedTimestamps?.endTime||"",t.verifiedMatchSnippet||"",t.hitIndexWithinPage?.toString()||""];return P(e.join("|")).slice(0,16)}function j(t){let e=Math.random().toString(36).slice(2,11);return `${t}-${e}`}function Q(t,e={}){let{fallbackDisplay:i}=e;return t.keySpan?.toString()||t.citationNumber?.toString()||i||"1"}function tt(t){return t.citationNumber?.toString()||"1"}function et(t){return t.keySpan?.toString()||""}function nt(...t){return t.filter(Boolean).join(" ")}var it=4,rt=1;function D(t){if(!t)return;let e=[],i=t.split(",");for(let r of i){let n=r.trim();if(n)if(n.includes("-")){let[o,p]=n.split("-"),a=parseInt(o,10),c=parseInt(p,10);if(!isNaN(a)&&!isNaN(c)&&a<=c)for(let l=a;l<=c;l++)e.push(l);else isNaN(a)||e.push(a);}else {let o=parseInt(n,10);isNaN(o)||e.push(o);}}if(e.length!==0)return [...new Set(e)].sort((r,n)=>r-n)}function R(t){let e=t?.status,i=e==="not_found",r=e==="found_phrase_missed_value",n=e==="found_key_span_only",o=e==="partial_text_found"||e==="found_on_other_page"||e==="found_on_other_line"||e==="first_word_found";return {isVerified:e==="found"||n||o||r,isMiss:i,isPartialMatch:o,isPending:e==="pending"||e==="loading"||!e}}var U=(t,e,i,r)=>{let n=m=>m?m.replace(/^['"]|['"]$/g,"").replace(/\\'/g,"'"):void 0,o=i?.current?i.current++:void 0,p=t.substring(0,t.indexOf("<cite")),a=t.includes("/>")?t.slice(t.indexOf("/>")+2):"",c=t.substring(t.indexOf("<cite"),t.indexOf("/>")+2),l=(m,b)=>{for(let O of b){let L=new RegExp(`${O}='((?:[^'\\\\]|\\\\.)*)'`),K=m.match(L);if(K)return K[1]}},s=l(c,["attachment_id","attachmentId","file_id","fileId"]),C=s?.length===20?s:e||s,d=l(c,["start_page_key","startPageKey","start_page"]),u,y;if(d){let m=d.match(/page[\_a-zA-Z]*(\d+)_index_(\d+)/);m&&(u=parseInt(m[1]),y=parseInt(m[2]));}let x=n(l(c,["full_phrase","fullPhrase"])),f=n(l(c,["key_span","keySpan"])),h=n(l(c,["reasoning"])),_=n(l(c,["value"])),k;try{let b=l(c,["line_ids","lineIds"])?.replace(/[A-Za-z_[\](){}:]/g,"");k=b?D(b):void 0;}catch(m){r&&console.error("Error parsing lineIds",m);}let S=l(c,["timestamps"]),g;if(S){let[m,b]=S.split("-")||[];g={startTime:m,endTime:b};}let I={attachmentId:C,pageNumber:u,startPageKey:`page_number_${u||1}_index_${y||0}`,fullPhrase:x,keySpan:f||_,citationNumber:o,lineIds:k,beforeCite:p,timestamps:g,reasoning:h};return {beforeCite:p,afterCite:a,citation:I}},B=(t,e)=>{if(!t)return null;let i=t.fullPhrase??t.full_phrase,r=t.startPageKey??t.start_page_key,n=t.keySpan??t.key_span,o=t.lineIds??t.line_ids,p=t.attachmentId??t.attachment_id??t.fileId??t.file_id,a=t.reasoning,c=t.value;if(!i)return null;let l;if(r){let d=r.match(/page[_a-zA-Z]*(\d+)_index_(\d+)/i);if(d)l=parseInt(d[1],10);else {let u=r.match(/^(\d+)_(\d+)$/);u&&(l=parseInt(u[1],10));}}let s=o?.length?[...o].sort((d,u)=>d-u):void 0;return {attachmentId:p,pageNumber:l,fullPhrase:i,citationNumber:e,lineIds:s,keySpan:n||c,reasoning:a}},V=t=>typeof t=="object"&&t!==null&&("fullPhrase"in t||"full_phrase"in t||"startPageKey"in t||"start_page_key"in t||"keySpan"in t||"key_span"in t||"lineIds"in t||"line_ids"in t),N=t=>Array.isArray(t)?t.length>0&&t.some(V):typeof t=="object"&&t!==null?V(t):false,M=t=>{let e={},i=Array.isArray(t)?t:[t],r=1;for(let n of i){let o=B(n,r++);if(o&&o.fullPhrase){let p=A(o);e[p]=o;}}return e},w=(t,e)=>{if(!(!t||typeof t!="object")){if(t.citation&&N(t.citation)){let i=Array.isArray(t.citation)?t.citation:[t.citation];e.push(...i);}if(t.citations&&N(t.citations)){let i=Array.isArray(t.citations)?t.citations:[t.citations];e.push(...i);}if(Array.isArray(t))for(let i of t)w(i,e);else for(let i of Object.keys(t))i!=="citation"&&i!=="citations"&&w(t[i],e);}},T=t=>{let e=$(t),i=/<cite\s+[^>]*\/>/g,r=e.match(i);if(!r||r.length===0)return {};let n={},o={current:1};for(let p of r){let{citation:a}=U(p,void 0,o);if(a&&a.fullPhrase){let c=A(a);n[c]=a;}}return n},ct=t=>{if(!t)return {};let e={};if(typeof t=="object"){if(N(t)){let n=M(t);Object.assign(e,n);}else {let n=[];if(w(t,n),n.length>0){let o=M(n);Object.assign(e,o);}}let i=JSON.stringify(t),r=T(i);Object.assign(e,r);}else if(typeof t=="string"){let i=T(t);Object.assign(e,i);}return e};function lt(t){let e=new Map,i=Array.isArray(t)?t.map((r,n)=>[A(r)||String(n+1),r]):Object.entries(t);for(let[r,n]of i){let o=n.attachmentId||"";e.has(o)||e.set(o,{}),e.get(o)[r]=n;}return e}function ut(t){let e={},i=Array.isArray(t)?t.map((r,n)=>[A(r)||String(n+1),r]):Object.entries(t);for(let[r,n]of i){let o=n.attachmentId||"";e[o]||(e[o]={}),e[o][r]=n;}return e}var J=t=>{let e={},i=/([a-zA-Z_][a-zA-Z0-9_]*)\s*=\s*(['"])((?:[^'"\\]|\\.)*)\2/g,r;for(;(r=i.exec(t))!==null;){let n=r[1].toLowerCase().replace(/([a-z])([A-Z])/g,"$1_$2").toLowerCase(),o=r[3],p=n==="fileid"||n==="file_id"||n==="attachmentid"?"attachment_id":n==="keyspan"?"key_span":n==="fullphrase"?"full_phrase":n==="lineids"?"line_ids":n==="startpagekey"||n==="start_pagekey"?"start_page_key":n;e[p]=o;}return e},F=t=>{if(!t)return "\u25CC";let e=R(t);return e.isPending?"\u25CC":e.isMiss?"\u2717":e.isPartialMatch?"\u26A0":e.isVerified?"\u2713":"\u25CC"},W=(t,e={})=>{let{leaveKeySpanBehind:i=false,verifications:r,showVerificationStatus:n=false}=e,o=0,p=/<cite\s+[^>]*?\/>/g;return t.replace(p,a=>{o++;let c=J(a),l="";if(i&&c.key_span&&(l=c.key_span.replace(/\\'/g,"'").replace(/\\"/g,'"')),n&&r){let s,C=String(o);if(s=r[C],!s&&c.attachment_id){for(let[,u]of Object.entries(r))if(u.attachmentId===c.attachment_id){s=u;break}}let d=F(s);l=l?`${l}${d}`:d;}return l})},gt=(t,e)=>W(t,{leaveKeySpanBehind:e}),dt=t=>t.replace(/<page_number_\d+_index_\d+>/g,"").replace(/<\/page_number_\d+_index_\d+>/g,"").trim(),mt=t=>{let e=/<line id="[^"]*">|<\/line>/g;return t.replace(e,"")},v=t=>{if(!t)return null;let e=t.match(/\d+/)?.[0];return e?parseInt(e):null},$=t=>{let e=t?.trim()||"",i=e.split(/(<cite[\s\S]*?(?:\/>|<\/cite>))/gm);return i.length<=1?z(e):(e=i.map(r=>r.startsWith("<cite")?z(r):r).join(""),e)},z=t=>{let e=t;e=e.replace(/><\/cite>/g,"/>");let i=p=>{let a=p.toLowerCase();return a==="fullphrase"||a==="full_phrase"?"full_phrase":a==="lineids"||a==="line_ids"?"line_ids":a==="startpagekey"||a==="start_pagekey"||a==="start_page_key"?"start_page_key":a==="fileid"||a==="file_id"||a==="attachmentid"||a==="attachment_id"?"attachment_id":a==="keyspan"||a==="key_span"?"key_span":a==="reasoning"||a==="value"?a:a==="timestamps"||a==="timestamp"||a==="timestamps"?"timestamps":a},r=p=>p.replace(/"/g,'"').replace(/'/g,"'").replace(/</g,"<").replace(/>/g,">").replace(/&/g,"&"),n=/(fullPhrase|full_phrase|keySpan|key_span|reasoning|value)\s*=\s*(['"])([\s\S]*?)(?=\s+(?:line_ids|lineIds|timestamps|fileId|file_id|attachmentId|attachment_id|start_page_key|start_pageKey|startPageKey|keySpan|key_span|reasoning|value|full_phrase)|\s*\/?>)/gm;e=e.replace(n,(p,a,c,l)=>{let s=l;return s.endsWith(c)&&(s=s.slice(0,-1)),s=s.replace(/(\r?\n)+/g," "),s=r(s),s=s.replace(/(\*|_){2,}/g,""),s=s.replace(/\\\\'/g,"'"),s=s.replace(/\\'/g,"'"),s=s.replace(/'/g,"\\'"),s=s.replace(/\\\\"/g,'"'),s=s.replace(/\\"/g,'"'),s=s.replace(/"/g,'\\"'),s=s.replace(/\*/g,""),`${i(a)}='${s}'`}),e=e.replace(/(line_ids|lineIds|timestamps)=['"]?([\[\]\(\){}A-Za-z0-9_\-, ]+)['"]?(\s*\/?>|\s+)/gm,(p,a,c,l)=>{let s=c.replace(/[A-Za-z\[\]\(\){}]/g,"");return s=s.replace(/(\d+)-(\d+)/g,(C,d,u)=>{let y=parseInt(d,10),x=parseInt(u,10),f=[];if(y<=x)for(let h=y;h<=x;h++)f.push(h);else f.push(y);return f.join(",")}),s=s.replace(/,+/g,",").replace(/^,|,$/g,""),`${i(a)}='${s}'${l}`});let o=p=>{let a=/([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(['"])((?:[^'"\\\n]|\\.)*)(?:\2)/g,c={},l;for(;l=a.exec(p);){let f=l[1],h=l[3],_=i(f);c[_]=h;}let s=Object.keys(c);if(s.length===0)return p;let C=typeof c.timestamps=="string"&&c.timestamps.length>0,d=s.filter(f=>f.startsWith("start_page")),u=[];c.attachment_id&&u.push("attachment_id"),C?(c.full_phrase&&u.push("full_phrase"),u.push("timestamps")):(d.includes("start_page_key")&&u.push("start_page_key"),d.filter(f=>f!=="start_page_key").sort().forEach(f=>u.push(f)),c.full_phrase&&u.push("full_phrase"),c.key_span&&u.push("key_span"),c.line_ids&&u.push("line_ids")),c.reasoning&&u.push("reasoning"),c.value&&u.push("value");let y=new Set(u);return s.filter(f=>!y.has(f)).sort().forEach(f=>u.push(f)),`<cite ${u.map(f=>`${f}='${c[f]}'`).join(" ")} />`};return e=e.replace(/<cite\b[\s\S]*?\/>/gm,p=>o(p)),e};export{W as a,gt as b,dt as c,mt as d,v as e,$ as f,P as g,q as h,A as i,Y as j,j as k,Q as l,tt as m,et as n,nt as o,it as p,rt as q,R as r,U as s,ct as t,lt as u,ut as v};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import {i,t}from'./chunk-ETIDLMKZ.js';import {a}from'./chunk-O2XFH626.js';var C="https://api.deepcitation.com";function F(p,t){if(typeof Buffer<"u"&&Buffer.isBuffer(p)){let e=Uint8Array.from(p);return {blob:new Blob([e]),name:t||"document"}}if(p instanceof Blob)return {blob:p,name:t||(p instanceof File?p.name:"document")};throw new Error("Invalid file type. Expected File, Blob, or Buffer.")}async function c(p,t){return (await p.json().catch(()=>({})))?.error?.message||`${t} failed with status ${p.status}`}var y=class{constructor(t){a(this,"apiKey");a(this,"apiUrl");if(!t.apiKey)throw new Error("DeepCitation API key is required. Get one at https://deepcitation.com/dashboard");this.apiKey=t.apiKey,this.apiUrl=t.apiUrl?.replace(/\/$/,"")||C;}async uploadFile(t,e){let{blob:l,name:a}=F(t,e?.filename),o=new FormData;o.append("file",l,a),e?.attachmentId&&o.append("attachmentId",e.attachmentId),e?.filename&&o.append("filename",e.filename);let i=await fetch(`${this.apiUrl}/prepareFile`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`},body:o});if(!i.ok)throw new Error(await c(i,"Upload"));return await i.json()}async convertToPdf(t){let e=typeof t=="string"?{url:t}:t,{url:l,file:a,filename:o,attachmentId:i}=e;if(!l&&!a)throw new Error("Either url or file must be provided");let r;if(l)r=await fetch(`${this.apiUrl}/convertFile`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},body:JSON.stringify({url:l,filename:o,attachmentId:i})});else {let{blob:f,name:n}=F(a,o),s=new FormData;s.append("file",f,n),i&&s.append("attachmentId",i),o&&s.append("filename",o),r=await fetch(`${this.apiUrl}/convertFile`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`},body:s});}if(!r.ok)throw new Error(await c(r,"Conversion"));return await r.json()}async prepareConvertedFile(t){let e=await fetch(`${this.apiUrl}/prepareFile`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},body:JSON.stringify({attachmentId:t.attachmentId})});if(!e.ok)throw new Error(await c(e,"Prepare"));return await e.json()}async prepareFiles(t){if(t.length===0)return {fileDataParts:[],deepTextPromptPortion:[]};let e=t.map(({file:i,filename:r,attachmentId:f})=>this.uploadFile(i,{filename:r,attachmentId:f}).then(n=>({result:n,filename:r}))),a=(await Promise.all(e)).map(({result:i,filename:r})=>({attachmentId:i.attachmentId,deepTextPromptPortion:i.deepTextPromptPortion,filename:r||i.metadata?.filename})),o=a.map(i=>i.deepTextPromptPortion);return {fileDataParts:a,deepTextPromptPortion:o}}async verify(t,e,l){let a={};if(Array.isArray(e))for(let n of e){let s=i(n);a[s]=n;}else if(typeof e=="object"&&e!==null)if("fullPhrase"in e||"value"in e){let n=i(e);a[n]=e;}else Object.assign(a,e);else throw new Error("Invalid citations format");if(Object.keys(a).length===0)return {verifications:{}};let o=`${this.apiUrl}/verifyCitations`,i$1={data:{attachmentId:t,citations:a,outputImageFormat:l?.outputImageFormat||"avif"}},r=await fetch(o,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},body:JSON.stringify(i$1)});if(!r.ok)throw new Error(await c(r,"Verification"));return await r.json()}async verifyAll(t$1,e){let{llmOutput:l,outputImageFormat:a="avif"}=t$1;if(e||(e=t(l)),Object.keys(e).length===0)return {verifications:{}};let o=new Map;for(let[n,s]of Object.entries(e)){let m=s.attachmentId||"";o.has(m)||o.set(m,{}),o.get(m)[n]=s;}let i=[];for(let[n,s]of o)n&&i.push(this.verify(n,s,{outputImageFormat:a}));let r=await Promise.all(i),f={};for(let n of r)Object.assign(f,n.verifications);return {verifications:f}}};
|
|
2
|
+
export{y as a};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
'use strict';var chunk4HRWJSX6_cjs=require('./chunk-4HRWJSX6.cjs'),chunkF2MMVEVC_cjs=require('./chunk-F2MMVEVC.cjs');var C="https://api.deepcitation.com";function F(p,t){if(typeof Buffer<"u"&&Buffer.isBuffer(p)){let e=Uint8Array.from(p);return {blob:new Blob([e]),name:t||"document"}}if(p instanceof Blob)return {blob:p,name:t||(p instanceof File?p.name:"document")};throw new Error("Invalid file type. Expected File, Blob, or Buffer.")}async function c(p,t){return (await p.json().catch(()=>({})))?.error?.message||`${t} failed with status ${p.status}`}var y=class{constructor(t){chunkF2MMVEVC_cjs.a(this,"apiKey");chunkF2MMVEVC_cjs.a(this,"apiUrl");if(!t.apiKey)throw new Error("DeepCitation API key is required. Get one at https://deepcitation.com/dashboard");this.apiKey=t.apiKey,this.apiUrl=t.apiUrl?.replace(/\/$/,"")||C;}async uploadFile(t,e){let{blob:l,name:a}=F(t,e?.filename),o=new FormData;o.append("file",l,a),e?.attachmentId&&o.append("attachmentId",e.attachmentId),e?.filename&&o.append("filename",e.filename);let i=await fetch(`${this.apiUrl}/prepareFile`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`},body:o});if(!i.ok)throw new Error(await c(i,"Upload"));return await i.json()}async convertToPdf(t){let e=typeof t=="string"?{url:t}:t,{url:l,file:a,filename:o,attachmentId:i}=e;if(!l&&!a)throw new Error("Either url or file must be provided");let r;if(l)r=await fetch(`${this.apiUrl}/convertFile`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},body:JSON.stringify({url:l,filename:o,attachmentId:i})});else {let{blob:f,name:n}=F(a,o),s=new FormData;s.append("file",f,n),i&&s.append("attachmentId",i),o&&s.append("filename",o),r=await fetch(`${this.apiUrl}/convertFile`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`},body:s});}if(!r.ok)throw new Error(await c(r,"Conversion"));return await r.json()}async prepareConvertedFile(t){let e=await fetch(`${this.apiUrl}/prepareFile`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},body:JSON.stringify({attachmentId:t.attachmentId})});if(!e.ok)throw new Error(await c(e,"Prepare"));return await e.json()}async prepareFiles(t){if(t.length===0)return {fileDataParts:[],deepTextPromptPortion:[]};let e=t.map(({file:i,filename:r,attachmentId:f})=>this.uploadFile(i,{filename:r,attachmentId:f}).then(n=>({result:n,filename:r}))),a=(await Promise.all(e)).map(({result:i,filename:r})=>({attachmentId:i.attachmentId,deepTextPromptPortion:i.deepTextPromptPortion,filename:r||i.metadata?.filename})),o=a.map(i=>i.deepTextPromptPortion);return {fileDataParts:a,deepTextPromptPortion:o}}async verify(t,e,l){let a={};if(Array.isArray(e))for(let n of e){let s=chunk4HRWJSX6_cjs.i(n);a[s]=n;}else if(typeof e=="object"&&e!==null)if("fullPhrase"in e||"value"in e){let n=chunk4HRWJSX6_cjs.i(e);a[n]=e;}else Object.assign(a,e);else throw new Error("Invalid citations format");if(Object.keys(a).length===0)return {verifications:{}};let o=`${this.apiUrl}/verifyCitations`,i={data:{attachmentId:t,citations:a,outputImageFormat:l?.outputImageFormat||"avif"}},r=await fetch(o,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},body:JSON.stringify(i)});if(!r.ok)throw new Error(await c(r,"Verification"));return await r.json()}async verifyAll(t,e){let{llmOutput:l,outputImageFormat:a="avif"}=t;if(e||(e=chunk4HRWJSX6_cjs.t(l)),Object.keys(e).length===0)return {verifications:{}};let o=new Map;for(let[n,s]of Object.entries(e)){let m=s.attachmentId||"";o.has(m)||o.set(m,{}),o.get(m)[n]=s;}let i=[];for(let[n,s]of o)n&&i.push(this.verify(n,s,{outputImageFormat:a}));let r=await Promise.all(i),f={};for(let n of r)Object.assign(f,n.verifications);return {verifications:f}}};
|
|
2
|
+
exports.a=y;
|
package/lib/client/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var chunkURRIEXFH_cjs=require('../chunk-URRIEXFH.cjs');require('../chunk-4HRWJSX6.cjs'),require('../chunk-F2MMVEVC.cjs');Object.defineProperty(exports,"DeepCitation",{enumerable:true,get:function(){return chunkURRIEXFH_cjs.a}});
|