@pdfvector/client 0.1.2 → 0.2.0
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 +27 -0
- package/README.md +19 -2
- package/dist/contract.cjs +175 -66
- package/dist/contract.d.cts +22 -1
- package/dist/contract.d.mts +22 -1
- package/dist/contract.mjs +175 -66
- package/dist/index.cjs +17 -1
- package/dist/index.d.cts +24 -1
- package/dist/index.d.mts +24 -1
- package/dist/index.mjs +17 -1
- package/package.json +1 -1
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";
|
|
@@ -1531,11 +1538,17 @@ function inferSuggestion(code, message, data) {
|
|
|
1531
1538
|
}
|
|
1532
1539
|
if (code === "INTERNAL_SERVER_ERROR") 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.";
|
|
1533
1540
|
if (hasHigherModelHint(message, data)) {
|
|
1541
|
+
const suggestedModel = readString(data, "suggestedModel");
|
|
1542
|
+
if (suggestedModel) return `Retry the request with model '${suggestedModel}'.`;
|
|
1534
1543
|
const requestedModel = readString(data, "requestedModel");
|
|
1535
1544
|
return requestedModel ? `Retry with a higher model than '${requestedModel}', or reduce the file size/pages before sending it again.` : "Retry with a higher model, or reduce the file size/pages before sending it again.";
|
|
1536
1545
|
}
|
|
1537
1546
|
const reasonCode = readString(data, "code");
|
|
1538
1547
|
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.";
|
|
1548
|
+
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.";
|
|
1549
|
+
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.";
|
|
1550
|
+
if (reasonCode === "CONTENT_TYPE_MISMATCH") return "Send the original file: its content does not match the declared MIME type or extension.";
|
|
1551
|
+
if (reasonCode === "ARCHIVE_TOO_LARGE") return "Send the document itself or a smaller archive: this one expands beyond the processing limit.";
|
|
1539
1552
|
if (reasonCode === "EXTRACTION_FAILED") return "Simplify the extraction schema or prompt, then retry.";
|
|
1540
1553
|
if (reasonCode === "MODEL_OUTPUT_UNUSABLE") return "Try a simpler question or a clearer document, then retry.";
|
|
1541
1554
|
if (lower.includes("password-protected")) return "Remove the document password or upload an unlocked copy.";
|
|
@@ -1564,6 +1577,7 @@ var PDFVectorError = class extends Error {
|
|
|
1564
1577
|
retryable;
|
|
1565
1578
|
retryableWithHigherModel;
|
|
1566
1579
|
requestedModel;
|
|
1580
|
+
suggestedModel;
|
|
1567
1581
|
reasonCode;
|
|
1568
1582
|
supportMessage;
|
|
1569
1583
|
constructor(options) {
|
|
@@ -1580,8 +1594,9 @@ var PDFVectorError = class extends Error {
|
|
|
1580
1594
|
this.title = inferTitle(this.code, this.name, this.message, readString(this.data, "code")?.startsWith("BILLING_") ?? false);
|
|
1581
1595
|
this.suggestion = inferSuggestion(this.code, this.message, this.data);
|
|
1582
1596
|
this.retryableWithHigherModel = hasHigherModelHint(this.message, this.data);
|
|
1583
|
-
this.retryable = this.retryableWithHigherModel || this.code === "TOO_MANY_REQUESTS" || this.code === "INTERNAL_SERVER_ERROR";
|
|
1597
|
+
this.retryable = this.retryableWithHigherModel || isUpstreamFailure(this.data) || this.code === "TOO_MANY_REQUESTS" || this.code === "INTERNAL_SERVER_ERROR";
|
|
1584
1598
|
this.requestedModel = readString(this.data, "requestedModel");
|
|
1599
|
+
this.suggestedModel = readString(this.data, "suggestedModel");
|
|
1585
1600
|
this.reasonCode = readString(this.data, "code");
|
|
1586
1601
|
this.supportMessage = this.requestId ? `PDF Vector request ${this.requestId} failed with ${this.code}: ${this.message}` : `PDF Vector request failed with ${this.code}: ${this.message}`;
|
|
1587
1602
|
}
|
|
@@ -1602,6 +1617,7 @@ var PDFVectorError = class extends Error {
|
|
|
1602
1617
|
...this.documentId !== void 0 ? { documentId: this.documentId } : {},
|
|
1603
1618
|
...this.reasonCode !== void 0 ? { reasonCode: this.reasonCode } : {},
|
|
1604
1619
|
...this.requestedModel !== void 0 ? { requestedModel: this.requestedModel } : {},
|
|
1620
|
+
...this.suggestedModel !== void 0 ? { suggestedModel: this.suggestedModel } : {},
|
|
1605
1621
|
supportMessage: this.supportMessage,
|
|
1606
1622
|
data: this.data
|
|
1607
1623
|
};
|
package/dist/index.d.cts
CHANGED
|
@@ -2081,6 +2081,22 @@ declare const bankStatementParse: ContractProcedureBuilderWithInputOutput<z.ZodO
|
|
|
2081
2081
|
requestId: z.ZodNumber;
|
|
2082
2082
|
html: z.ZodOptional<z.ZodString>;
|
|
2083
2083
|
}, z.core.$strip>, Record<never, never>, Record<never, never>>;
|
|
2084
|
+
declare const documentParse: ContractProcedureBuilderWithInputOutput<z.ZodObject<{
|
|
2085
|
+
url: z.ZodOptional<z.ZodURL>;
|
|
2086
|
+
file: z.ZodOptional<z.ZodFile>;
|
|
2087
|
+
base64: z.ZodOptional<z.ZodString>;
|
|
2088
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
2089
|
+
markdown: z.ZodString;
|
|
2090
|
+
pageCount: z.ZodNumber;
|
|
2091
|
+
model: z.ZodEnum<{
|
|
2092
|
+
max: "max";
|
|
2093
|
+
mini: "mini";
|
|
2094
|
+
nano: "nano";
|
|
2095
|
+
pro: "pro";
|
|
2096
|
+
}>;
|
|
2097
|
+
requestId: z.ZodNumber;
|
|
2098
|
+
html: z.ZodOptional<z.ZodString>;
|
|
2099
|
+
}, z.core.$strip>, Record<never, never>, Record<never, never>>;
|
|
2084
2100
|
declare const generateSchema: ContractProcedureBuilderWithInputOutput<z.ZodObject<{
|
|
2085
2101
|
instruction: z.ZodString;
|
|
2086
2102
|
}, z.core.$strip>, z.ZodObject<{
|
|
@@ -2103,6 +2119,11 @@ declare const rateLimitStatus: ContractProcedureBuilderWithOutput<Schema$1<unkno
|
|
|
2103
2119
|
used: z.ZodNumber;
|
|
2104
2120
|
remaining: z.ZodNumber;
|
|
2105
2121
|
}, z.core.$strip>;
|
|
2122
|
+
documentParse: z.ZodObject<{
|
|
2123
|
+
limit: z.ZodNumber;
|
|
2124
|
+
used: z.ZodNumber;
|
|
2125
|
+
remaining: z.ZodNumber;
|
|
2126
|
+
}, z.core.$strip>;
|
|
2106
2127
|
generateSchema: z.ZodObject<{
|
|
2107
2128
|
limit: z.ZodNumber;
|
|
2108
2129
|
used: z.ZodNumber;
|
|
@@ -2115,7 +2136,7 @@ declare const rateLimitStatus: ContractProcedureBuilderWithOutput<Schema$1<unkno
|
|
|
2115
2136
|
}, z.core.$strip>;
|
|
2116
2137
|
}, z.core.$strip>, Record<never, never>, Record<never, never>>;
|
|
2117
2138
|
declare namespace index_d_exports$3 {
|
|
2118
|
-
export { bankStatementParse, generateSchema, publicationPdfUrl, rateLimitStatus };
|
|
2139
|
+
export { bankStatementParse, documentParse, generateSchema, publicationPdfUrl, rateLimitStatus };
|
|
2119
2140
|
}
|
|
2120
2141
|
declare const ask$1: ContractProcedureBuilderWithInputOutput<z.ZodObject<{
|
|
2121
2142
|
url: z.ZodOptional<z.ZodURL>;
|
|
@@ -2474,6 +2495,7 @@ interface PDFVectorAgentError {
|
|
|
2474
2495
|
documentId?: string;
|
|
2475
2496
|
reasonCode?: string;
|
|
2476
2497
|
requestedModel?: string;
|
|
2498
|
+
suggestedModel?: string;
|
|
2477
2499
|
supportMessage: string;
|
|
2478
2500
|
data: Record<string, unknown>;
|
|
2479
2501
|
}
|
|
@@ -2491,6 +2513,7 @@ export declare class PDFVectorError extends Error {
|
|
|
2491
2513
|
readonly retryable: boolean;
|
|
2492
2514
|
readonly retryableWithHigherModel: boolean;
|
|
2493
2515
|
readonly requestedModel: string | undefined;
|
|
2516
|
+
readonly suggestedModel: string | undefined;
|
|
2494
2517
|
readonly reasonCode: string | undefined;
|
|
2495
2518
|
readonly supportMessage: string;
|
|
2496
2519
|
constructor(options: PDFVectorErrorOptions);
|
package/dist/index.d.mts
CHANGED
|
@@ -2081,6 +2081,22 @@ declare const bankStatementParse: ContractProcedureBuilderWithInputOutput<z.ZodO
|
|
|
2081
2081
|
requestId: z.ZodNumber;
|
|
2082
2082
|
html: z.ZodOptional<z.ZodString>;
|
|
2083
2083
|
}, z.core.$strip>, Record<never, never>, Record<never, never>>;
|
|
2084
|
+
declare const documentParse: ContractProcedureBuilderWithInputOutput<z.ZodObject<{
|
|
2085
|
+
url: z.ZodOptional<z.ZodURL>;
|
|
2086
|
+
file: z.ZodOptional<z.ZodFile>;
|
|
2087
|
+
base64: z.ZodOptional<z.ZodString>;
|
|
2088
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
2089
|
+
markdown: z.ZodString;
|
|
2090
|
+
pageCount: z.ZodNumber;
|
|
2091
|
+
model: z.ZodEnum<{
|
|
2092
|
+
max: "max";
|
|
2093
|
+
mini: "mini";
|
|
2094
|
+
nano: "nano";
|
|
2095
|
+
pro: "pro";
|
|
2096
|
+
}>;
|
|
2097
|
+
requestId: z.ZodNumber;
|
|
2098
|
+
html: z.ZodOptional<z.ZodString>;
|
|
2099
|
+
}, z.core.$strip>, Record<never, never>, Record<never, never>>;
|
|
2084
2100
|
declare const generateSchema: ContractProcedureBuilderWithInputOutput<z.ZodObject<{
|
|
2085
2101
|
instruction: z.ZodString;
|
|
2086
2102
|
}, z.core.$strip>, z.ZodObject<{
|
|
@@ -2103,6 +2119,11 @@ declare const rateLimitStatus: ContractProcedureBuilderWithOutput<Schema$1<unkno
|
|
|
2103
2119
|
used: z.ZodNumber;
|
|
2104
2120
|
remaining: z.ZodNumber;
|
|
2105
2121
|
}, z.core.$strip>;
|
|
2122
|
+
documentParse: z.ZodObject<{
|
|
2123
|
+
limit: z.ZodNumber;
|
|
2124
|
+
used: z.ZodNumber;
|
|
2125
|
+
remaining: z.ZodNumber;
|
|
2126
|
+
}, z.core.$strip>;
|
|
2106
2127
|
generateSchema: z.ZodObject<{
|
|
2107
2128
|
limit: z.ZodNumber;
|
|
2108
2129
|
used: z.ZodNumber;
|
|
@@ -2115,7 +2136,7 @@ declare const rateLimitStatus: ContractProcedureBuilderWithOutput<Schema$1<unkno
|
|
|
2115
2136
|
}, z.core.$strip>;
|
|
2116
2137
|
}, z.core.$strip>, Record<never, never>, Record<never, never>>;
|
|
2117
2138
|
declare namespace index_d_exports$3 {
|
|
2118
|
-
export { bankStatementParse, generateSchema, publicationPdfUrl, rateLimitStatus };
|
|
2139
|
+
export { bankStatementParse, documentParse, generateSchema, publicationPdfUrl, rateLimitStatus };
|
|
2119
2140
|
}
|
|
2120
2141
|
declare const ask$1: ContractProcedureBuilderWithInputOutput<z.ZodObject<{
|
|
2121
2142
|
url: z.ZodOptional<z.ZodURL>;
|
|
@@ -2474,6 +2495,7 @@ interface PDFVectorAgentError {
|
|
|
2474
2495
|
documentId?: string;
|
|
2475
2496
|
reasonCode?: string;
|
|
2476
2497
|
requestedModel?: string;
|
|
2498
|
+
suggestedModel?: string;
|
|
2477
2499
|
supportMessage: string;
|
|
2478
2500
|
data: Record<string, unknown>;
|
|
2479
2501
|
}
|
|
@@ -2491,6 +2513,7 @@ export declare class PDFVectorError extends Error {
|
|
|
2491
2513
|
readonly retryable: boolean;
|
|
2492
2514
|
readonly retryableWithHigherModel: boolean;
|
|
2493
2515
|
readonly requestedModel: string | undefined;
|
|
2516
|
+
readonly suggestedModel: string | undefined;
|
|
2494
2517
|
readonly reasonCode: string | undefined;
|
|
2495
2518
|
readonly supportMessage: string;
|
|
2496
2519
|
constructor(options: PDFVectorErrorOptions);
|
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";
|
|
@@ -1530,11 +1537,17 @@ function inferSuggestion(code, message, data) {
|
|
|
1530
1537
|
}
|
|
1531
1538
|
if (code === "INTERNAL_SERVER_ERROR") 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.";
|
|
1532
1539
|
if (hasHigherModelHint(message, data)) {
|
|
1540
|
+
const suggestedModel = readString(data, "suggestedModel");
|
|
1541
|
+
if (suggestedModel) return `Retry the request with model '${suggestedModel}'.`;
|
|
1533
1542
|
const requestedModel = readString(data, "requestedModel");
|
|
1534
1543
|
return requestedModel ? `Retry with a higher model than '${requestedModel}', or reduce the file size/pages before sending it again.` : "Retry with a higher model, or reduce the file size/pages before sending it again.";
|
|
1535
1544
|
}
|
|
1536
1545
|
const reasonCode = readString(data, "code");
|
|
1537
1546
|
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.";
|
|
1547
|
+
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.";
|
|
1548
|
+
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.";
|
|
1549
|
+
if (reasonCode === "CONTENT_TYPE_MISMATCH") return "Send the original file: its content does not match the declared MIME type or extension.";
|
|
1550
|
+
if (reasonCode === "ARCHIVE_TOO_LARGE") return "Send the document itself or a smaller archive: this one expands beyond the processing limit.";
|
|
1538
1551
|
if (reasonCode === "EXTRACTION_FAILED") return "Simplify the extraction schema or prompt, then retry.";
|
|
1539
1552
|
if (reasonCode === "MODEL_OUTPUT_UNUSABLE") return "Try a simpler question or a clearer document, then retry.";
|
|
1540
1553
|
if (lower.includes("password-protected")) return "Remove the document password or upload an unlocked copy.";
|
|
@@ -1563,6 +1576,7 @@ var PDFVectorError = class extends Error {
|
|
|
1563
1576
|
retryable;
|
|
1564
1577
|
retryableWithHigherModel;
|
|
1565
1578
|
requestedModel;
|
|
1579
|
+
suggestedModel;
|
|
1566
1580
|
reasonCode;
|
|
1567
1581
|
supportMessage;
|
|
1568
1582
|
constructor(options) {
|
|
@@ -1579,8 +1593,9 @@ var PDFVectorError = class extends Error {
|
|
|
1579
1593
|
this.title = inferTitle(this.code, this.name, this.message, readString(this.data, "code")?.startsWith("BILLING_") ?? false);
|
|
1580
1594
|
this.suggestion = inferSuggestion(this.code, this.message, this.data);
|
|
1581
1595
|
this.retryableWithHigherModel = hasHigherModelHint(this.message, this.data);
|
|
1582
|
-
this.retryable = this.retryableWithHigherModel || this.code === "TOO_MANY_REQUESTS" || this.code === "INTERNAL_SERVER_ERROR";
|
|
1596
|
+
this.retryable = this.retryableWithHigherModel || isUpstreamFailure(this.data) || this.code === "TOO_MANY_REQUESTS" || this.code === "INTERNAL_SERVER_ERROR";
|
|
1583
1597
|
this.requestedModel = readString(this.data, "requestedModel");
|
|
1598
|
+
this.suggestedModel = readString(this.data, "suggestedModel");
|
|
1584
1599
|
this.reasonCode = readString(this.data, "code");
|
|
1585
1600
|
this.supportMessage = this.requestId ? `PDF Vector request ${this.requestId} failed with ${this.code}: ${this.message}` : `PDF Vector request failed with ${this.code}: ${this.message}`;
|
|
1586
1601
|
}
|
|
@@ -1601,6 +1616,7 @@ var PDFVectorError = class extends Error {
|
|
|
1601
1616
|
...this.documentId !== void 0 ? { documentId: this.documentId } : {},
|
|
1602
1617
|
...this.reasonCode !== void 0 ? { reasonCode: this.reasonCode } : {},
|
|
1603
1618
|
...this.requestedModel !== void 0 ? { requestedModel: this.requestedModel } : {},
|
|
1619
|
+
...this.suggestedModel !== void 0 ? { suggestedModel: this.suggestedModel } : {},
|
|
1604
1620
|
supportMessage: this.supportMessage,
|
|
1605
1621
|
data: this.data
|
|
1606
1622
|
};
|