@pdfvector/client 0.1.2 → 0.1.3
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/CHANGELOG.md +16 -0
- package/README.md +12 -1
- package/dist/contract.cjs +1 -1
- package/dist/contract.mjs +1 -1
- package/dist/index.cjs +12 -1
- package/dist/index.mjs +12 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @pdfvector/client
|
|
2
2
|
|
|
3
|
+
## 0.1.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#564](https://github.com/phuctm97/pdfvector/pull/564) [`6dcf020`](https://github.com/phuctm97/pdfvector/commit/6dcf0205899627e57b7824d7d7a2837f4537e336) Thanks [@khanhduyvt0101](https://github.com/khanhduyvt0101)! - Failed requests are never charged and our own failures are no longer reported as the caller's.
|
|
8
|
+
|
|
9
|
+
- Billing: a request that ends in an error (any class) is billed 0 credits; provider calls it made stay in provider usage as our cost (before: an error after a successful provider call, such as the nano/mini text validator or the image text pre-check, was charged).
|
|
10
|
+
- Classification: user_error only for explicit caller faults (`data.userError`: input validation, size/page limits, unreadable uploads), contract validation and rate limits; an untagged BAD_REQUEST is a system error and reaches Sentry. "Retry with a higher model" is recorded as user_error with the usage code `HIGHER_MODEL_REQUIRED` so its rate stays visible. Ask/extract keep a system parse failure (e.g. `DOCUMENT_PROCESSING_FAILED`) instead of wrapping it in "try a higher model"; mini/pro OCR outages are system errors instead of "try a higher model"; a provider page limit within the tier's own limit is a processing failure, not a user BAD_REQUEST; when one engine failed on our side and another called the input bad, the system error wins; auto PDFs over Document AI's default page cap get a chunked Document AI pass before "no text" and report a system error if an engine was skipped.
|
|
11
|
+
- URL input: browser-like headers, 90 s timeout, a streaming size cap at the tier's file limit, a retry of 403/408/429/5xx and network errors through the residential proxy (redirect hops re-checked against private addresses). A site that still refuses is `UPSTREAM_FETCH_FAILED` (BAD_REQUEST, `statusCode`, `host`; not a user error, tracked instead of sent to Sentry); 401/404/410, unresolvable hosts, private share links and expired signed links stay user errors.
|
|
12
|
+
- academic.parse tries up to three open-access copies (OpenAlex locations, arXiv, Europe PMC) and the proxy; when none downloads, `PDF_NOT_FETCHABLE` keeps NOT_FOUND but is a system error with every attempt in `data.attempts`, and each download is a `other/document_fetch` provider-health event.
|
|
13
|
+
- Input validation: uploads and URL bodies are sniffed; a different supported format is processed as such, a mismatch (an HTML page sent as PDF) is `CONTENT_TYPE_MISMATCH`. ZIP uploads and ZIP-based Office/ODF/EPUB files are bounded (20,000 entries, 1 GB expanded, 200x past 100 MB: `ARCHIVE_TOO_LARGE`). A DOCX whose text is only in headers, footers or notes is no longer rejected as empty.
|
|
14
|
+
- Sentry events are rate limited per error key (10 per hour).
|
|
15
|
+
- SDK: `UPSTREAM_FETCH_FAILED` and `PDF_NOT_FETCHABLE` are system-origin, retryable errors with their own suggestions; `CONTENT_TYPE_MISMATCH` and `ARCHIVE_TOO_LARGE` get suggestions. The README lists the reason codes.
|
|
16
|
+
- Updated dependencies [[`6dcf020`](https://github.com/phuctm97/pdfvector/commit/6dcf0205899627e57b7824d7d7a2837f4537e336)]:
|
|
17
|
+
- @pdfvector/instance-client@0.1.2
|
|
18
|
+
|
|
3
19
|
## 0.1.2
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -637,6 +637,17 @@ All API errors are thrown as `PDFVectorError` instances. The SDK maps server err
|
|
|
637
637
|
|
|
638
638
|
For `INTERNAL_SERVER_ERROR`, the API returns a safe message and keeps the original provider failure in server diagnostics. Use `requestId` when contacting support. For document processing failures, check `reasonCode` and `retryableWithHigherModel` instead of parsing the message; `EXTRACTION_FAILED` identifies unusable structured output even if message wording changes. `DOCUMENT_PROCESSING_FAILED` identifies a processing rejection that was not confirmed to be a caller-input error, so the SDK suggests retrying or contacting support rather than changing the document. Error responses do not include raw AI output.
|
|
639
639
|
|
|
640
|
+
Reason codes (`reasonCode`, from the response's `data.code`) for document input:
|
|
641
|
+
|
|
642
|
+
| `reasonCode` | Status | Meaning |
|
|
643
|
+
| --- | --- | --- |
|
|
644
|
+
| `UPSTREAM_FETCH_FAILED` | 400 (`URLFetchError`) | The website behind `url` blocked, rate limited, failed or timed out the download, even through a retry from another network. Not a caller fault: `userError` is `false`, `retryable` is `true`; `statusCode` and `data.host` say what the site answered. Download the file and send it as `file`/`base64`, or retry later. A 401/404/410, a private share link or an expired signed link stays a user error. |
|
|
645
|
+
| `PDF_NOT_FETCHABLE` | 404 (`academic.parse`) | No open-access copy of the paper could be downloaded (each copy tried is in `data.attempts`). Retryable, not a caller fault. |
|
|
646
|
+
| `CONTENT_TYPE_MISMATCH` | 400 | The uploaded bytes are not the declared format (for example an HTML page sent as a PDF). A file whose real format differs but is supported is processed as its real format instead. |
|
|
647
|
+
| `ARCHIVE_TOO_LARGE` | 400 | A ZIP upload or ZIP-based Office/EPUB/ODF file has more than 20,000 entries or expands beyond 1 GB (or 200x its size past 100 MB). |
|
|
648
|
+
|
|
649
|
+
A request that ends in an error is never charged credits.
|
|
650
|
+
|
|
640
651
|
```typescript
|
|
641
652
|
import {
|
|
642
653
|
PDFVectorError,
|
|
@@ -788,7 +799,7 @@ PDFVectorError
|
|
|
788
799
|
│ ├── PageLimitExceededError — pageCount, pageLimit, model
|
|
789
800
|
│ ├── PasswordProtectedError
|
|
790
801
|
│ ├── UnsupportedFormatError — format, supportedFormats
|
|
791
|
-
│ ├── URLFetchError — url, statusCode, statusText
|
|
802
|
+
│ ├── URLFetchError — url, statusCode, statusText (reasonCode UPSTREAM_FETCH_FAILED: the site refused)
|
|
792
803
|
│ ├── InvalidDocumentURLError
|
|
793
804
|
│ ├── InvalidBase64Error
|
|
794
805
|
│ ├── TierNotSupportedError — documentType, model, allowedTypes
|
package/dist/contract.cjs
CHANGED
|
@@ -467,7 +467,7 @@ const imageDimensionLimits = {
|
|
|
467
467
|
};
|
|
468
468
|
/** Pre-built format note for API descriptions (used in contract model descriptions). */
|
|
469
469
|
const formatsByTierDescription = `Supported formats by tier:
|
|
470
|
-
- All tiers: ${allTierFormats.join(", ")}.\n- Pro/Max/Auto adds: ${proTierAdditionalFormats.join(", ")}. Image dimensions must be between ${imageDimensionLimits.minPixels}×${imageDimensionLimits.minPixels} and ${imageDimensionLimits.maxPixels}×${imageDimensionLimits.maxPixels} pixels.\nHow pages are counted: PDF and TIFF pages as they are; Word (.docx, .doc), RTF, OpenDocument text, HTML and EPUB: every 3,000 characters of text is one page;
|
|
470
|
+
- All tiers: ${allTierFormats.join(", ")}.\n- Pro/Max/Auto adds: ${proTierAdditionalFormats.join(", ")}. Image dimensions must be between ${imageDimensionLimits.minPixels}×${imageDimensionLimits.minPixels} and ${imageDimensionLimits.maxPixels}×${imageDimensionLimits.maxPixels} pixels.\nHow pages are counted: PDF and TIFF pages as they are; Word (.docx, .doc), Excel (.xlsx, .xls), RTF, OpenDocument text and spreadsheets, HTML and EPUB: every 3,000 characters of text is one page; PowerPoint (.pptx, .ppt) and OpenDocument presentations: one page per slide; images: one page per image; CSV and plain text: every 3,000 characters is one page; bibliographies: every 10 entries is one page. Credits follow the requested tier, whichever engine reads the file. Auto bills the tier it selects for the document, but at most mini when a local engine reads it without OCR (text PDFs, CSV, spreadsheets, Office and text files); scans, images and provider parses bill the tier that ran.`;
|
|
471
471
|
/** Academic/grant API: fixed credits per request */
|
|
472
472
|
const academicCreditCosts = {
|
|
473
473
|
academicSearch: 2,
|
package/dist/contract.mjs
CHANGED
|
@@ -456,7 +456,7 @@ const imageDimensionLimits = {
|
|
|
456
456
|
};
|
|
457
457
|
/** Pre-built format note for API descriptions (used in contract model descriptions). */
|
|
458
458
|
const formatsByTierDescription = `Supported formats by tier:
|
|
459
|
-
- All tiers: ${allTierFormats.join(", ")}.\n- Pro/Max/Auto adds: ${proTierAdditionalFormats.join(", ")}. Image dimensions must be between ${imageDimensionLimits.minPixels}×${imageDimensionLimits.minPixels} and ${imageDimensionLimits.maxPixels}×${imageDimensionLimits.maxPixels} pixels.\nHow pages are counted: PDF and TIFF pages as they are; Word (.docx, .doc), RTF, OpenDocument text, HTML and EPUB: every 3,000 characters of text is one page;
|
|
459
|
+
- All tiers: ${allTierFormats.join(", ")}.\n- Pro/Max/Auto adds: ${proTierAdditionalFormats.join(", ")}. Image dimensions must be between ${imageDimensionLimits.minPixels}×${imageDimensionLimits.minPixels} and ${imageDimensionLimits.maxPixels}×${imageDimensionLimits.maxPixels} pixels.\nHow pages are counted: PDF and TIFF pages as they are; Word (.docx, .doc), Excel (.xlsx, .xls), RTF, OpenDocument text and spreadsheets, HTML and EPUB: every 3,000 characters of text is one page; PowerPoint (.pptx, .ppt) and OpenDocument presentations: one page per slide; images: one page per image; CSV and plain text: every 3,000 characters is one page; bibliographies: every 10 entries is one page. Credits follow the requested tier, whichever engine reads the file. Auto bills the tier it selects for the document, but at most mini when a local engine reads it without OCR (text PDFs, CSV, spreadsheets, Office and text files); scans, images and provider parses bill the tier that ran.`;
|
|
460
460
|
/** Academic/grant API: fixed credits per request */
|
|
461
461
|
const academicCreditCosts = {
|
|
462
462
|
academicSearch: 2,
|
package/dist/index.cjs
CHANGED
|
@@ -1475,8 +1475,15 @@ function inferCategory(code, message, data) {
|
|
|
1475
1475
|
if (lower.includes("json schema") || lower.includes("invalid input") || lower.includes("invalid type") || lower.includes("expected")) return "validation";
|
|
1476
1476
|
return "document_input";
|
|
1477
1477
|
}
|
|
1478
|
+
/** A source website refused or failed a download: neither the caller's input nor a PDF Vector bug, retry later. */
|
|
1479
|
+
const upstreamReasonCodes = /* @__PURE__ */ new Set(["UPSTREAM_FETCH_FAILED", "PDF_NOT_FETCHABLE"]);
|
|
1480
|
+
function isUpstreamFailure(data) {
|
|
1481
|
+
const code = data["code"];
|
|
1482
|
+
return typeof code === "string" && upstreamReasonCodes.has(code);
|
|
1483
|
+
}
|
|
1478
1484
|
function inferOrigin(code, category, data) {
|
|
1479
1485
|
if (data["userError"] === true) return "user";
|
|
1486
|
+
if (isUpstreamFailure(data)) return "system";
|
|
1480
1487
|
if (code === "INTERNAL_SERVER_ERROR") return "system";
|
|
1481
1488
|
if (category === "document_processing" && data["userError"] !== true) return "system";
|
|
1482
1489
|
return "user";
|
|
@@ -1536,6 +1543,10 @@ function inferSuggestion(code, message, data) {
|
|
|
1536
1543
|
}
|
|
1537
1544
|
const reasonCode = readString(data, "code");
|
|
1538
1545
|
if (reasonCode === "DOCUMENT_PROCESSING_FAILED" || reasonCode === "DOCUMENT_AI_INVALID_ARGUMENT" || reasonCode === "DOCUMENT_INTELLIGENCE_INVALID_REQUEST") return requestId ? `Retry the request. If it keeps failing, contact support with requestId ${requestId}.` : "Retry the request. If it keeps failing, contact support with the request details.";
|
|
1546
|
+
if (reasonCode === "UPSTREAM_FETCH_FAILED") return "The website blocked or failed the download. Download the file yourself and send it as file or base64, or retry later.";
|
|
1547
|
+
if (reasonCode === "PDF_NOT_FETCHABLE") return "The paper's open-access PDF could not be downloaded right now. Retry later, upload the PDF, or pass a direct PDF URL to document.parse.";
|
|
1548
|
+
if (reasonCode === "CONTENT_TYPE_MISMATCH") return "Send the original file: its content does not match the declared MIME type or extension.";
|
|
1549
|
+
if (reasonCode === "ARCHIVE_TOO_LARGE") return "Send the document itself or a smaller archive: this one expands beyond the processing limit.";
|
|
1539
1550
|
if (reasonCode === "EXTRACTION_FAILED") return "Simplify the extraction schema or prompt, then retry.";
|
|
1540
1551
|
if (reasonCode === "MODEL_OUTPUT_UNUSABLE") return "Try a simpler question or a clearer document, then retry.";
|
|
1541
1552
|
if (lower.includes("password-protected")) return "Remove the document password or upload an unlocked copy.";
|
|
@@ -1580,7 +1591,7 @@ var PDFVectorError = class extends Error {
|
|
|
1580
1591
|
this.title = inferTitle(this.code, this.name, this.message, readString(this.data, "code")?.startsWith("BILLING_") ?? false);
|
|
1581
1592
|
this.suggestion = inferSuggestion(this.code, this.message, this.data);
|
|
1582
1593
|
this.retryableWithHigherModel = hasHigherModelHint(this.message, this.data);
|
|
1583
|
-
this.retryable = this.retryableWithHigherModel || this.code === "TOO_MANY_REQUESTS" || this.code === "INTERNAL_SERVER_ERROR";
|
|
1594
|
+
this.retryable = this.retryableWithHigherModel || isUpstreamFailure(this.data) || this.code === "TOO_MANY_REQUESTS" || this.code === "INTERNAL_SERVER_ERROR";
|
|
1584
1595
|
this.requestedModel = readString(this.data, "requestedModel");
|
|
1585
1596
|
this.reasonCode = readString(this.data, "code");
|
|
1586
1597
|
this.supportMessage = this.requestId ? `PDF Vector request ${this.requestId} failed with ${this.code}: ${this.message}` : `PDF Vector request failed with ${this.code}: ${this.message}`;
|
package/dist/index.mjs
CHANGED
|
@@ -1474,8 +1474,15 @@ function inferCategory(code, message, data) {
|
|
|
1474
1474
|
if (lower.includes("json schema") || lower.includes("invalid input") || lower.includes("invalid type") || lower.includes("expected")) return "validation";
|
|
1475
1475
|
return "document_input";
|
|
1476
1476
|
}
|
|
1477
|
+
/** A source website refused or failed a download: neither the caller's input nor a PDF Vector bug, retry later. */
|
|
1478
|
+
const upstreamReasonCodes = /* @__PURE__ */ new Set(["UPSTREAM_FETCH_FAILED", "PDF_NOT_FETCHABLE"]);
|
|
1479
|
+
function isUpstreamFailure(data) {
|
|
1480
|
+
const code = data["code"];
|
|
1481
|
+
return typeof code === "string" && upstreamReasonCodes.has(code);
|
|
1482
|
+
}
|
|
1477
1483
|
function inferOrigin(code, category, data) {
|
|
1478
1484
|
if (data["userError"] === true) return "user";
|
|
1485
|
+
if (isUpstreamFailure(data)) return "system";
|
|
1479
1486
|
if (code === "INTERNAL_SERVER_ERROR") return "system";
|
|
1480
1487
|
if (category === "document_processing" && data["userError"] !== true) return "system";
|
|
1481
1488
|
return "user";
|
|
@@ -1535,6 +1542,10 @@ function inferSuggestion(code, message, data) {
|
|
|
1535
1542
|
}
|
|
1536
1543
|
const reasonCode = readString(data, "code");
|
|
1537
1544
|
if (reasonCode === "DOCUMENT_PROCESSING_FAILED" || reasonCode === "DOCUMENT_AI_INVALID_ARGUMENT" || reasonCode === "DOCUMENT_INTELLIGENCE_INVALID_REQUEST") return requestId ? `Retry the request. If it keeps failing, contact support with requestId ${requestId}.` : "Retry the request. If it keeps failing, contact support with the request details.";
|
|
1545
|
+
if (reasonCode === "UPSTREAM_FETCH_FAILED") return "The website blocked or failed the download. Download the file yourself and send it as file or base64, or retry later.";
|
|
1546
|
+
if (reasonCode === "PDF_NOT_FETCHABLE") return "The paper's open-access PDF could not be downloaded right now. Retry later, upload the PDF, or pass a direct PDF URL to document.parse.";
|
|
1547
|
+
if (reasonCode === "CONTENT_TYPE_MISMATCH") return "Send the original file: its content does not match the declared MIME type or extension.";
|
|
1548
|
+
if (reasonCode === "ARCHIVE_TOO_LARGE") return "Send the document itself or a smaller archive: this one expands beyond the processing limit.";
|
|
1538
1549
|
if (reasonCode === "EXTRACTION_FAILED") return "Simplify the extraction schema or prompt, then retry.";
|
|
1539
1550
|
if (reasonCode === "MODEL_OUTPUT_UNUSABLE") return "Try a simpler question or a clearer document, then retry.";
|
|
1540
1551
|
if (lower.includes("password-protected")) return "Remove the document password or upload an unlocked copy.";
|
|
@@ -1579,7 +1590,7 @@ var PDFVectorError = class extends Error {
|
|
|
1579
1590
|
this.title = inferTitle(this.code, this.name, this.message, readString(this.data, "code")?.startsWith("BILLING_") ?? false);
|
|
1580
1591
|
this.suggestion = inferSuggestion(this.code, this.message, this.data);
|
|
1581
1592
|
this.retryableWithHigherModel = hasHigherModelHint(this.message, this.data);
|
|
1582
|
-
this.retryable = this.retryableWithHigherModel || this.code === "TOO_MANY_REQUESTS" || this.code === "INTERNAL_SERVER_ERROR";
|
|
1593
|
+
this.retryable = this.retryableWithHigherModel || isUpstreamFailure(this.data) || this.code === "TOO_MANY_REQUESTS" || this.code === "INTERNAL_SERVER_ERROR";
|
|
1583
1594
|
this.requestedModel = readString(this.data, "requestedModel");
|
|
1584
1595
|
this.reasonCode = readString(this.data, "code");
|
|
1585
1596
|
this.supportMessage = this.requestId ? `PDF Vector request ${this.requestId} failed with ${this.code}: ${this.message}` : `PDF Vector request failed with ${this.code}: ${this.message}`;
|