@deepcitation/deepcitation-js 1.1.30 → 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-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.js +1 -1
- package/package.json +1 -1
- package/lib/chunk-67NZP2UZ.js +0 -2
- package/lib/chunk-CQF2MESM.cjs +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,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}});
|
package/lib/client/index.d.cts
CHANGED
|
@@ -306,35 +306,34 @@ declare class DeepCitation {
|
|
|
306
306
|
* import { getAllCitationsFromLlmOutput } from '@deepcitation/deepcitation-js';
|
|
307
307
|
*
|
|
308
308
|
* const citations = getAllCitationsFromLlmOutput(llmResponse);
|
|
309
|
-
* const verified = await dc.
|
|
309
|
+
* const verified = await dc.verify(attachmentId, citations);
|
|
310
310
|
*
|
|
311
311
|
* for (const [key, result] of Object.entries(verified.verifications)) {
|
|
312
|
-
* console.log(key, result.
|
|
312
|
+
* console.log(key, result.status);
|
|
313
313
|
* // "found", "partial_text_found", "not_found", etc.
|
|
314
314
|
* }
|
|
315
315
|
* ```
|
|
316
316
|
*/
|
|
317
|
-
|
|
317
|
+
verify(attachmentId: string, citations: CitationInput, options?: VerifyCitationsOptions): Promise<VerifyCitationsResponse>;
|
|
318
318
|
/**
|
|
319
|
-
*
|
|
319
|
+
* Parse and verify all citations from LLM output.
|
|
320
320
|
* This is the recommended way to verify citations for new integrations.
|
|
321
321
|
*
|
|
322
|
-
* @param input - Object containing llmOutput and optional
|
|
322
|
+
* @param input - Object containing llmOutput and optional outputImageFormat
|
|
323
323
|
* @returns Verification results with status and proof images
|
|
324
324
|
*
|
|
325
325
|
* @example
|
|
326
326
|
* ```typescript
|
|
327
|
-
* const result = await dc.
|
|
327
|
+
* const result = await dc.verifyAll({
|
|
328
328
|
* llmOutput: response.content,
|
|
329
|
-
* fileDataParts, // From prepareFiles()
|
|
330
329
|
* });
|
|
331
330
|
*
|
|
332
|
-
* for (const [key,
|
|
333
|
-
* console.log(key,
|
|
331
|
+
* for (const [key, verification] of Object.entries(result.verifications)) {
|
|
332
|
+
* console.log(key, verification.status);
|
|
334
333
|
* }
|
|
335
334
|
* ```
|
|
336
335
|
*/
|
|
337
|
-
|
|
336
|
+
verifyAll(input: VerifyCitationsFromLlmOutput, citations?: {
|
|
338
337
|
[key: string]: Citation;
|
|
339
338
|
}): Promise<VerifyCitationsResponse>;
|
|
340
339
|
}
|
package/lib/client/index.d.ts
CHANGED
|
@@ -306,35 +306,34 @@ declare class DeepCitation {
|
|
|
306
306
|
* import { getAllCitationsFromLlmOutput } from '@deepcitation/deepcitation-js';
|
|
307
307
|
*
|
|
308
308
|
* const citations = getAllCitationsFromLlmOutput(llmResponse);
|
|
309
|
-
* const verified = await dc.
|
|
309
|
+
* const verified = await dc.verify(attachmentId, citations);
|
|
310
310
|
*
|
|
311
311
|
* for (const [key, result] of Object.entries(verified.verifications)) {
|
|
312
|
-
* console.log(key, result.
|
|
312
|
+
* console.log(key, result.status);
|
|
313
313
|
* // "found", "partial_text_found", "not_found", etc.
|
|
314
314
|
* }
|
|
315
315
|
* ```
|
|
316
316
|
*/
|
|
317
|
-
|
|
317
|
+
verify(attachmentId: string, citations: CitationInput, options?: VerifyCitationsOptions): Promise<VerifyCitationsResponse>;
|
|
318
318
|
/**
|
|
319
|
-
*
|
|
319
|
+
* Parse and verify all citations from LLM output.
|
|
320
320
|
* This is the recommended way to verify citations for new integrations.
|
|
321
321
|
*
|
|
322
|
-
* @param input - Object containing llmOutput and optional
|
|
322
|
+
* @param input - Object containing llmOutput and optional outputImageFormat
|
|
323
323
|
* @returns Verification results with status and proof images
|
|
324
324
|
*
|
|
325
325
|
* @example
|
|
326
326
|
* ```typescript
|
|
327
|
-
* const result = await dc.
|
|
327
|
+
* const result = await dc.verifyAll({
|
|
328
328
|
* llmOutput: response.content,
|
|
329
|
-
* fileDataParts, // From prepareFiles()
|
|
330
329
|
* });
|
|
331
330
|
*
|
|
332
|
-
* for (const [key,
|
|
333
|
-
* console.log(key,
|
|
331
|
+
* for (const [key, verification] of Object.entries(result.verifications)) {
|
|
332
|
+
* console.log(key, verification.status);
|
|
334
333
|
* }
|
|
335
334
|
* ```
|
|
336
335
|
*/
|
|
337
|
-
|
|
336
|
+
verifyAll(input: VerifyCitationsFromLlmOutput, citations?: {
|
|
338
337
|
[key: string]: Citation;
|
|
339
338
|
}): Promise<VerifyCitationsResponse>;
|
|
340
339
|
}
|
package/lib/client/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{a as DeepCitation}from'../chunk-
|
|
1
|
+
export{a as DeepCitation}from'../chunk-G6RPOT3H.js';import'../chunk-ETIDLMKZ.js';import'../chunk-O2XFH626.js';
|
package/lib/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var chunkURRIEXFH_cjs=require('./chunk-URRIEXFH.cjs'),chunk4FGOHQFP_cjs=require('./chunk-4FGOHQFP.cjs'),chunkCFXDRAJL_cjs=require('./chunk-CFXDRAJL.cjs'),chunk4HRWJSX6_cjs=require('./chunk-4HRWJSX6.cjs');require('./chunk-F2MMVEVC.cjs');var Y=t=>{if(!t)return false;let e=t.trim();if(e.length<64)return false;let a=e?.[0];for(let r=1;r<e.length;r++)if(e[r]!==a)return false;return true};function z(t){t=t.trim();let e=2,a=10,r=/[.?!](?=\s+|$)/g,m,n=[];for(;(m=r.exec(t))!==null;)n.push(m.index);if(n.length<2)return t;let I=n[n.length-1],C=n[n.length-2],o=t.substring(C+1,I+1),p=o.length;if(o.trim().slice(0,-1).length<a||p<=0||t.length<p*e)return t;let c=0,s=I+1;t.endsWith(o)&&(s=t.length);let f=-1;for(;;){let i=s-p;if(i<0)break;if(t.substring(i,s)===o)c++,f=i,s=i;else break}return c>=e?t.substring(0,f)+o:t}Object.defineProperty(exports,"DeepCitation",{enumerable:true,get:function(){return chunkURRIEXFH_cjs.a}});Object.defineProperty(exports,"AV_CITATION_MARKDOWN_SYNTAX_PROMPT",{enumerable:true,get:function(){return chunk4FGOHQFP_cjs.b}});Object.defineProperty(exports,"CITATION_AV_BASED_JSON_OUTPUT_FORMAT",{enumerable:true,get:function(){return chunk4FGOHQFP_cjs.h}});Object.defineProperty(exports,"CITATION_AV_REMINDER",{enumerable:true,get:function(){return chunk4FGOHQFP_cjs.d}});Object.defineProperty(exports,"CITATION_JSON_OUTPUT_FORMAT",{enumerable:true,get:function(){return chunk4FGOHQFP_cjs.g}});Object.defineProperty(exports,"CITATION_MARKDOWN_SYNTAX_PROMPT",{enumerable:true,get:function(){return chunk4FGOHQFP_cjs.a}});Object.defineProperty(exports,"CITATION_REMINDER",{enumerable:true,get:function(){return chunk4FGOHQFP_cjs.c}});Object.defineProperty(exports,"compressPromptIds",{enumerable:true,get:function(){return chunk4FGOHQFP_cjs.i}});Object.defineProperty(exports,"decompressPromptIds",{enumerable:true,get:function(){return chunk4FGOHQFP_cjs.j}});Object.defineProperty(exports,"wrapCitationPrompt",{enumerable:true,get:function(){return chunk4FGOHQFP_cjs.f}});Object.defineProperty(exports,"wrapSystemCitationPrompt",{enumerable:true,get:function(){return chunk4FGOHQFP_cjs.e}});Object.defineProperty(exports,"BLANK_VERIFICATION",{enumerable:true,get:function(){return chunkCFXDRAJL_cjs.d}});Object.defineProperty(exports,"DEFAULT_OUTPUT_IMAGE_FORMAT",{enumerable:true,get:function(){return chunkCFXDRAJL_cjs.a}});Object.defineProperty(exports,"NOT_FOUND_VERIFICATION_INDEX",{enumerable:true,get:function(){return chunkCFXDRAJL_cjs.b}});Object.defineProperty(exports,"PENDING_VERIFICATION_INDEX",{enumerable:true,get:function(){return chunkCFXDRAJL_cjs.c}});Object.defineProperty(exports,"CITATION_X_PADDING",{enumerable:true,get:function(){return chunk4HRWJSX6_cjs.p}});Object.defineProperty(exports,"CITATION_Y_PADDING",{enumerable:true,get:function(){return chunk4HRWJSX6_cjs.q}});Object.defineProperty(exports,"generateCitationInstanceId",{enumerable:true,get:function(){return chunk4HRWJSX6_cjs.k}});Object.defineProperty(exports,"generateCitationKey",{enumerable:true,get:function(){return chunk4HRWJSX6_cjs.i}});Object.defineProperty(exports,"generateVerificationKey",{enumerable:true,get:function(){return chunk4HRWJSX6_cjs.j}});Object.defineProperty(exports,"getAllCitationsFromLlmOutput",{enumerable:true,get:function(){return chunk4HRWJSX6_cjs.t}});Object.defineProperty(exports,"getCitationPageNumber",{enumerable:true,get:function(){return chunk4HRWJSX6_cjs.e}});Object.defineProperty(exports,"getCitationStatus",{enumerable:true,get:function(){return chunk4HRWJSX6_cjs.r}});Object.defineProperty(exports,"groupCitationsByAttachmentId",{enumerable:true,get:function(){return chunk4HRWJSX6_cjs.u}});Object.defineProperty(exports,"groupCitationsByAttachmentIdObject",{enumerable:true,get:function(){return chunk4HRWJSX6_cjs.v}});Object.defineProperty(exports,"normalizeCitations",{enumerable:true,get:function(){return chunk4HRWJSX6_cjs.f}});Object.defineProperty(exports,"parseCitation",{enumerable:true,get:function(){return chunk4HRWJSX6_cjs.s}});Object.defineProperty(exports,"removeCitations",{enumerable:true,get:function(){return chunk4HRWJSX6_cjs.b}});Object.defineProperty(exports,"removeLineIdMetadata",{enumerable:true,get:function(){return chunk4HRWJSX6_cjs.d}});Object.defineProperty(exports,"removePageNumberMetadata",{enumerable:true,get:function(){return chunk4HRWJSX6_cjs.c}});Object.defineProperty(exports,"replaceCitations",{enumerable:true,get:function(){return chunk4HRWJSX6_cjs.a}});Object.defineProperty(exports,"sha1Hash",{enumerable:true,get:function(){return chunk4HRWJSX6_cjs.g}});exports.cleanRepeatingLastSentence=z;exports.isGeminiGarbage=Y;
|
package/lib/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{a as DeepCitation}from'./chunk-
|
|
1
|
+
export{a as DeepCitation}from'./chunk-G6RPOT3H.js';export{b as AV_CITATION_MARKDOWN_SYNTAX_PROMPT,h as CITATION_AV_BASED_JSON_OUTPUT_FORMAT,d as CITATION_AV_REMINDER,g as CITATION_JSON_OUTPUT_FORMAT,a as CITATION_MARKDOWN_SYNTAX_PROMPT,c as CITATION_REMINDER,i as compressPromptIds,j as decompressPromptIds,f as wrapCitationPrompt,e as wrapSystemCitationPrompt}from'./chunk-2IZXUOQR.js';export{d as BLANK_VERIFICATION,a as DEFAULT_OUTPUT_IMAGE_FORMAT,b as NOT_FOUND_VERIFICATION_INDEX,c as PENDING_VERIFICATION_INDEX}from'./chunk-RQPZSRID.js';export{p as CITATION_X_PADDING,q as CITATION_Y_PADDING,k as generateCitationInstanceId,i as generateCitationKey,j as generateVerificationKey,t as getAllCitationsFromLlmOutput,e as getCitationPageNumber,r as getCitationStatus,u as groupCitationsByAttachmentId,v as groupCitationsByAttachmentIdObject,f as normalizeCitations,s as parseCitation,b as removeCitations,d as removeLineIdMetadata,c as removePageNumberMetadata,a as replaceCitations,g as sha1Hash}from'./chunk-ETIDLMKZ.js';import'./chunk-O2XFH626.js';var Y=t=>{if(!t)return false;let e=t.trim();if(e.length<64)return false;let a=e?.[0];for(let r=1;r<e.length;r++)if(e[r]!==a)return false;return true};function z(t){t=t.trim();let e=2,a=10,r=/[.?!](?=\s+|$)/g,m,n=[];for(;(m=r.exec(t))!==null;)n.push(m.index);if(n.length<2)return t;let I=n[n.length-1],C=n[n.length-2],o=t.substring(C+1,I+1),p=o.length;if(o.trim().slice(0,-1).length<a||p<=0||t.length<p*e)return t;let c=0,s=I+1;t.endsWith(o)&&(s=t.length);let f=-1;for(;;){let i=s-p;if(i<0)break;if(t.substring(i,s)===o)c++,f=i,s=i;else break}return c>=e?t.substring(0,f)+o:t}export{z as cleanRepeatingLastSentence,Y as isGeminiGarbage};
|
package/package.json
CHANGED
package/lib/chunk-67NZP2UZ.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import {i,t}from'./chunk-ETIDLMKZ.js';import {a}from'./chunk-O2XFH626.js';var F="https://api.deepcitation.com";function C(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 m(p,t){return (await p.json().catch(()=>({})))?.error?.message||`${t} failed with status ${p.status}`}var h=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(/\/$/,"")||F;}async uploadFile(t,e){let{blob:l,name:n}=C(t,e?.filename),o=new FormData;o.append("file",l,n),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 m(i,"Upload"));return await i.json()}async convertToPdf(t){let e=typeof t=="string"?{url:t}:t,{url:l,file:n,filename:o,attachmentId:i}=e;if(!l&&!n)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:a}=C(n,o),s=new FormData;s.append("file",f,a),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 m(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 m(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(a=>({result:a,filename:r}))),n=(await Promise.all(e)).map(({result:i,filename:r})=>({attachmentId:i.attachmentId,deepTextPromptPortion:i.deepTextPromptPortion,filename:r||i.metadata?.filename})),o=n.map(i=>i.deepTextPromptPortion);return {fileDataParts:n,deepTextPromptPortion:o}}async verifyCitations(t,e,l){let n={};if(Array.isArray(e))for(let a of e){let s=i(a);n[s]=a;}else if(typeof e=="object"&&e!==null)if("fullPhrase"in e||"value"in e){let a=i(e);n[a]=e;}else Object.assign(n,e);else throw new Error("Invalid citations format");let o=`${this.apiUrl}/verifyCitations`,i$1={data:{attachmentId:t,citations:n,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 m(r,"Verification"));return await r.json()}async verifyCitationsFromLlmOutput(t$1,e){let{llmOutput:l,outputImageFormat:n="avif"}=t$1;if(e||(e=t(l)),Object.keys(e).length===0)return {verifications:{}};let o=new Map;for(let[a,s]of Object.entries(e)){let c=s.attachmentId||"";o.has(c)||o.set(c,{}),o.get(c)[a]=s;}let i=[];for(let[a,s]of o)a&&i.push(this.verifyCitations(a,s,{outputImageFormat:n}));let r=await Promise.all(i),f={};for(let a of r)Object.assign(f,a.verifications);return {verifications:f}}};
|
|
2
|
-
export{h as a};
|
package/lib/chunk-CQF2MESM.cjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
'use strict';var chunk4HRWJSX6_cjs=require('./chunk-4HRWJSX6.cjs'),chunkF2MMVEVC_cjs=require('./chunk-F2MMVEVC.cjs');var F="https://api.deepcitation.com";function C(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 m(p,t){return (await p.json().catch(()=>({})))?.error?.message||`${t} failed with status ${p.status}`}var h=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(/\/$/,"")||F;}async uploadFile(t,e){let{blob:l,name:n}=C(t,e?.filename),o=new FormData;o.append("file",l,n),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 m(i,"Upload"));return await i.json()}async convertToPdf(t){let e=typeof t=="string"?{url:t}:t,{url:l,file:n,filename:o,attachmentId:i}=e;if(!l&&!n)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:a}=C(n,o),s=new FormData;s.append("file",f,a),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 m(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 m(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(a=>({result:a,filename:r}))),n=(await Promise.all(e)).map(({result:i,filename:r})=>({attachmentId:i.attachmentId,deepTextPromptPortion:i.deepTextPromptPortion,filename:r||i.metadata?.filename})),o=n.map(i=>i.deepTextPromptPortion);return {fileDataParts:n,deepTextPromptPortion:o}}async verifyCitations(t,e,l){let n={};if(Array.isArray(e))for(let a of e){let s=chunk4HRWJSX6_cjs.i(a);n[s]=a;}else if(typeof e=="object"&&e!==null)if("fullPhrase"in e||"value"in e){let a=chunk4HRWJSX6_cjs.i(e);n[a]=e;}else Object.assign(n,e);else throw new Error("Invalid citations format");let o=`${this.apiUrl}/verifyCitations`,i={data:{attachmentId:t,citations:n,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 m(r,"Verification"));return await r.json()}async verifyCitationsFromLlmOutput(t,e){let{llmOutput:l,outputImageFormat:n="avif"}=t;if(e||(e=chunk4HRWJSX6_cjs.t(l)),Object.keys(e).length===0)return {verifications:{}};let o=new Map;for(let[a,s]of Object.entries(e)){let c=s.attachmentId||"";o.has(c)||o.set(c,{}),o.get(c)[a]=s;}let i=[];for(let[a,s]of o)a&&i.push(this.verifyCitations(a,s,{outputImageFormat:n}));let r=await Promise.all(i),f={};for(let a of r)Object.assign(f,a.verifications);return {verifications:f}}};
|
|
2
|
-
exports.a=h;
|