@pdfvector/instance-contract 0.2.7 → 0.2.9
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/.tsc/lib/index.d.ts +1 -11
- package/.tsc/lib/index.d.ts.map +1 -1
- package/.tsc/lib/index.js +1 -7
- package/CHANGELOG.md +23 -0
- package/package.json +6 -6
- package/.tsc/lib/fetchable-url-schema.d.ts +0 -3
- package/.tsc/lib/fetchable-url-schema.d.ts.map +0 -1
- package/.tsc/lib/fetchable-url-schema.js +0 -13
- package/.tsc/lib/json-schema-input.d.ts +0 -3
- package/.tsc/lib/json-schema-input.d.ts.map +0 -1
- package/.tsc/lib/json-schema-input.js +0 -25
- package/.tsc/lib/page-markdown-schema.d.ts +0 -6
- package/.tsc/lib/page-markdown-schema.d.ts.map +0 -1
- package/.tsc/lib/page-markdown-schema.js +0 -9
- package/.tsc/lib/pdfvector-model-schema.d.ts +0 -8
- package/.tsc/lib/pdfvector-model-schema.d.ts.map +0 -1
- package/.tsc/lib/pdfvector-model-schema.js +0 -4
- package/.tsc/lib/pdfvector-model.d.ts +0 -4
- package/.tsc/lib/pdfvector-model.d.ts.map +0 -1
- package/.tsc/lib/pdfvector-model.js +0 -0
- package/.tsc/lib/router/academic/fetch.d.ts +0 -69
- package/.tsc/lib/router/academic/fetch.d.ts.map +0 -1
- package/.tsc/lib/router/academic/fetch.js +0 -119
- package/.tsc/lib/router/academic/find-citations.d.ts +0 -70
- package/.tsc/lib/router/academic/find-citations.d.ts.map +0 -1
- package/.tsc/lib/router/academic/find-citations.js +0 -116
- package/.tsc/lib/router/academic/index.d.ts +0 -8
- package/.tsc/lib/router/academic/index.d.ts.map +0 -1
- package/.tsc/lib/router/academic/index.js +0 -7
- package/.tsc/lib/router/academic/paper-graph.d.ts +0 -113
- package/.tsc/lib/router/academic/paper-graph.d.ts.map +0 -1
- package/.tsc/lib/router/academic/paper-graph.js +0 -144
- package/.tsc/lib/router/academic/parse.d.ts +0 -50
- package/.tsc/lib/router/academic/parse.d.ts.map +0 -1
- package/.tsc/lib/router/academic/parse.js +0 -146
- package/.tsc/lib/router/academic/provider.d.ts +0 -18
- package/.tsc/lib/router/academic/provider.d.ts.map +0 -1
- package/.tsc/lib/router/academic/provider.js +0 -16
- package/.tsc/lib/router/academic/search-grants.d.ts +0 -84
- package/.tsc/lib/router/academic/search-grants.d.ts.map +0 -1
- package/.tsc/lib/router/academic/search-grants.js +0 -171
- package/.tsc/lib/router/academic/search.d.ts +0 -83
- package/.tsc/lib/router/academic/search.d.ts.map +0 -1
- package/.tsc/lib/router/academic/search.js +0 -154
- package/.tsc/lib/router/academic/similar-papers.d.ts +0 -89
- package/.tsc/lib/router/academic/similar-papers.d.ts.map +0 -1
- package/.tsc/lib/router/academic/similar-papers.js +0 -143
- package/.tsc/lib/router/admin/get-environment.d.ts +0 -5
- package/.tsc/lib/router/admin/get-environment.d.ts.map +0 -1
- package/.tsc/lib/router/admin/get-environment.js +0 -13
- package/.tsc/lib/router/admin/get-free-usage-records.d.ts +0 -34
- package/.tsc/lib/router/admin/get-free-usage-records.d.ts.map +0 -1
- package/.tsc/lib/router/admin/get-free-usage-records.js +0 -38
- package/.tsc/lib/router/admin/get-provider-usage-records.d.ts +0 -36
- package/.tsc/lib/router/admin/get-provider-usage-records.d.ts.map +0 -1
- package/.tsc/lib/router/admin/get-provider-usage-records.js +0 -45
- package/.tsc/lib/router/admin/get-usage-records.d.ts +0 -48
- package/.tsc/lib/router/admin/get-usage-records.d.ts.map +0 -1
- package/.tsc/lib/router/admin/get-usage-records.js +0 -44
- package/.tsc/lib/router/admin/health-check.d.ts +0 -5
- package/.tsc/lib/router/admin/health-check.d.ts.map +0 -1
- package/.tsc/lib/router/admin/health-check.js +0 -14
- package/.tsc/lib/router/admin/index.d.ts +0 -9
- package/.tsc/lib/router/admin/index.d.ts.map +0 -1
- package/.tsc/lib/router/admin/index.js +0 -8
- package/.tsc/lib/router/admin/set-domain.d.ts +0 -7
- package/.tsc/lib/router/admin/set-domain.d.ts.map +0 -1
- package/.tsc/lib/router/admin/set-domain.js +0 -20
- package/.tsc/lib/router/admin/set-environment.d.ts +0 -7
- package/.tsc/lib/router/admin/set-environment.d.ts.map +0 -1
- package/.tsc/lib/router/admin/set-environment.js +0 -41
- package/.tsc/lib/router/admin/set-version.d.ts +0 -7
- package/.tsc/lib/router/admin/set-version.d.ts.map +0 -1
- package/.tsc/lib/router/admin/set-version.js +0 -21
- package/.tsc/lib/router/authenticate/index.d.ts +0 -2
- package/.tsc/lib/router/authenticate/index.d.ts.map +0 -1
- package/.tsc/lib/router/authenticate/index.js +0 -1
- package/.tsc/lib/router/authenticate/validate-credential.d.ts +0 -7
- package/.tsc/lib/router/authenticate/validate-credential.d.ts.map +0 -1
- package/.tsc/lib/router/authenticate/validate-credential.js +0 -20
- package/.tsc/lib/router/bankStatement/ask.d.ts +0 -32
- package/.tsc/lib/router/bankStatement/ask.d.ts.map +0 -1
- package/.tsc/lib/router/bankStatement/ask.js +0 -88
- package/.tsc/lib/router/bankStatement/extract.d.ts +0 -33
- package/.tsc/lib/router/bankStatement/extract.d.ts.map +0 -1
- package/.tsc/lib/router/bankStatement/extract.js +0 -113
- package/.tsc/lib/router/bankStatement/get-default-spec.d.ts +0 -2
- package/.tsc/lib/router/bankStatement/get-default-spec.d.ts.map +0 -1
- package/.tsc/lib/router/bankStatement/get-default-spec.js +0 -19
- package/.tsc/lib/router/bankStatement/index.d.ts +0 -4
- package/.tsc/lib/router/bankStatement/index.d.ts.map +0 -1
- package/.tsc/lib/router/bankStatement/index.js +0 -3
- package/.tsc/lib/router/bankStatement/parse.d.ts +0 -28
- package/.tsc/lib/router/bankStatement/parse.d.ts.map +0 -1
- package/.tsc/lib/router/bankStatement/parse.js +0 -105
- package/.tsc/lib/router/document/ask.d.ts +0 -32
- package/.tsc/lib/router/document/ask.d.ts.map +0 -1
- package/.tsc/lib/router/document/ask.js +0 -134
- package/.tsc/lib/router/document/extract.d.ts +0 -33
- package/.tsc/lib/router/document/extract.d.ts.map +0 -1
- package/.tsc/lib/router/document/extract.js +0 -152
- package/.tsc/lib/router/document/get-default-spec.d.ts +0 -2
- package/.tsc/lib/router/document/get-default-spec.d.ts.map +0 -1
- package/.tsc/lib/router/document/get-default-spec.js +0 -19
- package/.tsc/lib/router/document/index.d.ts +0 -4
- package/.tsc/lib/router/document/index.d.ts.map +0 -1
- package/.tsc/lib/router/document/index.js +0 -3
- package/.tsc/lib/router/document/parse.d.ts +0 -40
- package/.tsc/lib/router/document/parse.d.ts.map +0 -1
- package/.tsc/lib/router/document/parse.js +0 -142
- package/.tsc/lib/router/free/bank-statement-parse.d.ts +0 -16
- package/.tsc/lib/router/free/bank-statement-parse.d.ts.map +0 -1
- package/.tsc/lib/router/free/bank-statement-parse.js +0 -87
- package/.tsc/lib/router/free/generate-schema.d.ts +0 -8
- package/.tsc/lib/router/free/generate-schema.d.ts.map +0 -1
- package/.tsc/lib/router/free/generate-schema.js +0 -110
- package/.tsc/lib/router/free/index.d.ts +0 -5
- package/.tsc/lib/router/free/index.d.ts.map +0 -1
- package/.tsc/lib/router/free/index.js +0 -4
- package/.tsc/lib/router/free/publication-pdf-url.d.ts +0 -12
- package/.tsc/lib/router/free/publication-pdf-url.d.ts.map +0 -1
- package/.tsc/lib/router/free/publication-pdf-url.js +0 -86
- package/.tsc/lib/router/free/rate-limit-status.d.ts +0 -19
- package/.tsc/lib/router/free/rate-limit-status.d.ts.map +0 -1
- package/.tsc/lib/router/free/rate-limit-status.js +0 -36
- package/.tsc/lib/router/identity/ask.d.ts +0 -32
- package/.tsc/lib/router/identity/ask.d.ts.map +0 -1
- package/.tsc/lib/router/identity/ask.js +0 -95
- package/.tsc/lib/router/identity/extract.d.ts +0 -33
- package/.tsc/lib/router/identity/extract.d.ts.map +0 -1
- package/.tsc/lib/router/identity/extract.js +0 -103
- package/.tsc/lib/router/identity/get-default-spec.d.ts +0 -2
- package/.tsc/lib/router/identity/get-default-spec.d.ts.map +0 -1
- package/.tsc/lib/router/identity/get-default-spec.js +0 -19
- package/.tsc/lib/router/identity/index.d.ts +0 -4
- package/.tsc/lib/router/identity/index.d.ts.map +0 -1
- package/.tsc/lib/router/identity/index.js +0 -3
- package/.tsc/lib/router/identity/parse.d.ts +0 -29
- package/.tsc/lib/router/identity/parse.d.ts.map +0 -1
- package/.tsc/lib/router/identity/parse.js +0 -109
- package/.tsc/lib/router/index.d.ts +0 -9
- package/.tsc/lib/router/index.d.ts.map +0 -1
- package/.tsc/lib/router/index.js +0 -8
- package/.tsc/lib/router/invoice/ask.d.ts +0 -32
- package/.tsc/lib/router/invoice/ask.d.ts.map +0 -1
- package/.tsc/lib/router/invoice/ask.js +0 -85
- package/.tsc/lib/router/invoice/extract.d.ts +0 -33
- package/.tsc/lib/router/invoice/extract.d.ts.map +0 -1
- package/.tsc/lib/router/invoice/extract.js +0 -109
- package/.tsc/lib/router/invoice/get-default-spec.d.ts +0 -2
- package/.tsc/lib/router/invoice/get-default-spec.d.ts.map +0 -1
- package/.tsc/lib/router/invoice/get-default-spec.js +0 -19
- package/.tsc/lib/router/invoice/index.d.ts +0 -4
- package/.tsc/lib/router/invoice/index.d.ts.map +0 -1
- package/.tsc/lib/router/invoice/index.js +0 -3
- package/.tsc/lib/router/invoice/parse.d.ts +0 -28
- package/.tsc/lib/router/invoice/parse.d.ts.map +0 -1
- package/.tsc/lib/router/invoice/parse.js +0 -100
- package/.tsc/lib/supported-mimes.d.ts +0 -35
- package/.tsc/lib/supported-mimes.d.ts.map +0 -1
- package/.tsc/lib/supported-mimes.js +0 -130
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import { oc } from "@orpc/contract";
|
|
2
|
-
import { getOpenApiCodeSamples } from "@pdfvector/api-docs";
|
|
3
|
-
import { z } from "zod";
|
|
4
|
-
import { fetchableUrlSchema } from "../../fetchable-url-schema.js";
|
|
5
|
-
import { jsonSchemaInput } from "../../json-schema-input.js";
|
|
6
|
-
import { pdfvectorModelSchema } from "../../pdfvector-model-schema.js";
|
|
7
|
-
import { outputExtractModelDescription, specializedExtractModelDescription, supportedFileFormatsDescription, supportedFileMimeErrorMessage, supportedFileMimes, supportedFileTypesLong, } from "../../supported-mimes.js";
|
|
8
|
-
import { getDefaultSpec } from "./get-default-spec.js";
|
|
9
|
-
const specializedModelSchema = z
|
|
10
|
-
.enum(["auto", ...pdfvectorModelSchema.options])
|
|
11
|
-
.default("auto");
|
|
12
|
-
const extractInputSchema = z.object({
|
|
13
|
-
url: fetchableUrlSchema
|
|
14
|
-
.optional()
|
|
15
|
-
.describe("URL of the invoice file to fetch and parse"),
|
|
16
|
-
file: z
|
|
17
|
-
.file()
|
|
18
|
-
.mime([...supportedFileMimes], supportedFileMimeErrorMessage)
|
|
19
|
-
.optional()
|
|
20
|
-
.describe(`Invoice file upload via multipart form-data (${supportedFileFormatsDescription})`),
|
|
21
|
-
base64: z.string().optional().describe("Base64-encoded invoice file content"),
|
|
22
|
-
prompt: z
|
|
23
|
-
.string()
|
|
24
|
-
.min(4, "prompt must be at least 4 characters")
|
|
25
|
-
.describe("The prompt instructing the AI how to extract data from the invoice"),
|
|
26
|
-
schema: jsonSchemaInput.describe("JSON Schema describing the structure of the data to extract from the invoice. Can be a JSON object or a JSON string."),
|
|
27
|
-
model: specializedModelSchema.describe(specializedExtractModelDescription),
|
|
28
|
-
documentId: z
|
|
29
|
-
.string()
|
|
30
|
-
.trim()
|
|
31
|
-
.min(1)
|
|
32
|
-
.max(512)
|
|
33
|
-
.optional()
|
|
34
|
-
.describe("Optional external document ID for usage attribution. The x-pdfvector-document-id header takes precedence when both are provided."),
|
|
35
|
-
callback: z
|
|
36
|
-
.object({
|
|
37
|
-
url: fetchableUrlSchema.describe("Webhook URL where results will be POSTed when processing completes"),
|
|
38
|
-
type: z
|
|
39
|
-
.string()
|
|
40
|
-
.optional()
|
|
41
|
-
.describe("Callback type identifier (e.g. 'zapier')"),
|
|
42
|
-
})
|
|
43
|
-
.optional()
|
|
44
|
-
.describe("Optional webhook callback for async processing. " +
|
|
45
|
-
"When provided, the server returns 202 immediately and POSTs the full response payload to the callback URL when processing completes. " +
|
|
46
|
-
"On error, the callback receives a POST with X-Pdfvector-Callback-Failed: true header and error details in the body. " +
|
|
47
|
-
"Useful for long-running operations that may exceed client timeout limits."),
|
|
48
|
-
});
|
|
49
|
-
const extractOutputSchema = z.object({
|
|
50
|
-
data: z
|
|
51
|
-
.unknown()
|
|
52
|
-
.refine((val) => val != null &&
|
|
53
|
-
(typeof val !== "object" || Object.keys(val).length > 0), { message: "Extracted data must not be empty" })
|
|
54
|
-
.describe("Extracted structured data matching the provided JSON Schema"),
|
|
55
|
-
pageCount: z.number().int().describe("Total number of pages in the document"),
|
|
56
|
-
model: pdfvectorModelSchema.describe(outputExtractModelDescription),
|
|
57
|
-
credits: z
|
|
58
|
-
.number()
|
|
59
|
-
.int()
|
|
60
|
-
.describe("Number of credits consumed by this API call. Cost per page: nano=6, mini=10, pro=14, max=18."),
|
|
61
|
-
requestId: z
|
|
62
|
-
.number()
|
|
63
|
-
.int()
|
|
64
|
-
.describe("Unique request identifier for this API call"),
|
|
65
|
-
documentId: z
|
|
66
|
-
.string()
|
|
67
|
-
.optional()
|
|
68
|
-
.describe("Document ID if provided via x-pdfvector-document-id header or request body"),
|
|
69
|
-
});
|
|
70
|
-
const requestExamples = {
|
|
71
|
-
"Extract from URL": {
|
|
72
|
-
summary: "Extract from URL",
|
|
73
|
-
value: {
|
|
74
|
-
url: "https://example.com/invoice.pdf",
|
|
75
|
-
prompt: "Extract the vendor name, total amount, and line items",
|
|
76
|
-
schema: JSON.stringify({
|
|
77
|
-
type: "object",
|
|
78
|
-
properties: {
|
|
79
|
-
vendorName: { type: "string" },
|
|
80
|
-
totalAmount: { type: "number" },
|
|
81
|
-
lineItems: {
|
|
82
|
-
type: "array",
|
|
83
|
-
items: {
|
|
84
|
-
type: "object",
|
|
85
|
-
properties: {
|
|
86
|
-
description: { type: "string" },
|
|
87
|
-
amount: { type: "number" },
|
|
88
|
-
},
|
|
89
|
-
},
|
|
90
|
-
},
|
|
91
|
-
},
|
|
92
|
-
required: ["vendorName", "totalAmount"],
|
|
93
|
-
}),
|
|
94
|
-
},
|
|
95
|
-
},
|
|
96
|
-
};
|
|
97
|
-
export const extract = oc
|
|
98
|
-
.route({
|
|
99
|
-
summary: "Extract structured data from an invoice",
|
|
100
|
-
description: `Parse an invoice and extract structured data matching a provided JSON Schema using AI. Supports ${supportedFileTypesLong}. Provide the document via file upload, a public URL, or a base64-encoded string.`,
|
|
101
|
-
tags: ["Invoice"],
|
|
102
|
-
spec: (op) => {
|
|
103
|
-
const spec = getDefaultSpec(op, requestExamples);
|
|
104
|
-
spec["x-codeSamples"] = getOpenApiCodeSamples("invoice-extract");
|
|
105
|
-
return spec;
|
|
106
|
-
},
|
|
107
|
-
})
|
|
108
|
-
.input(extractInputSchema)
|
|
109
|
-
.output(extractOutputSchema);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"get-default-spec.d.ts","sourceRoot":"","sources":["../../../../lib/router/invoice/get-default-spec.ts"],"names":[],"mappings":"AAAA,wBAAgB,cAAc,CAC7B,EAAE,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC3B,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACtC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAuBzB"}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export function getDefaultSpec(op, requestExamples) {
|
|
2
|
-
op["security"] = [{ bearerAuth: [] }];
|
|
3
|
-
const params = (op["parameters"] ?? []);
|
|
4
|
-
params.push({
|
|
5
|
-
name: "x-pdfvector-document-id",
|
|
6
|
-
in: "header",
|
|
7
|
-
required: false,
|
|
8
|
-
schema: { type: "string", default: "my-doc-123" },
|
|
9
|
-
description: "Optional document ID to associate with this request. Returned in the response and saved for usage tracking.",
|
|
10
|
-
});
|
|
11
|
-
op["parameters"] = params;
|
|
12
|
-
const reqBody = op["requestBody"];
|
|
13
|
-
if (reqBody?.content) {
|
|
14
|
-
for (const mediaType of Object.values(reqBody.content)) {
|
|
15
|
-
mediaType["examples"] = requestExamples;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
return op;
|
|
19
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../lib/router/invoice/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC"}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
export declare const parse: import("@orpc/contract").ContractProcedureBuilderWithInputOutput<z.ZodObject<{
|
|
3
|
-
url: z.ZodOptional<z.ZodURL>;
|
|
4
|
-
file: z.ZodOptional<z.ZodFile>;
|
|
5
|
-
base64: z.ZodOptional<z.ZodString>;
|
|
6
|
-
model: z.ZodDefault<z.ZodEnum<{
|
|
7
|
-
auto: "auto";
|
|
8
|
-
max: "max";
|
|
9
|
-
pro: "pro";
|
|
10
|
-
}>>;
|
|
11
|
-
documentId: z.ZodOptional<z.ZodString>;
|
|
12
|
-
callback: z.ZodOptional<z.ZodObject<{
|
|
13
|
-
url: z.ZodURL;
|
|
14
|
-
type: z.ZodOptional<z.ZodString>;
|
|
15
|
-
}, z.core.$strip>>;
|
|
16
|
-
}, z.core.$strip>, z.ZodObject<{
|
|
17
|
-
markdown: z.ZodString;
|
|
18
|
-
pageCount: z.ZodNumber;
|
|
19
|
-
model: z.ZodEnum<{
|
|
20
|
-
max: "max";
|
|
21
|
-
pro: "pro";
|
|
22
|
-
}>;
|
|
23
|
-
credits: z.ZodNumber;
|
|
24
|
-
requestId: z.ZodNumber;
|
|
25
|
-
html: z.ZodOptional<z.ZodString>;
|
|
26
|
-
documentId: z.ZodOptional<z.ZodString>;
|
|
27
|
-
}, z.core.$strip>, Record<never, never>, Record<never, never>>;
|
|
28
|
-
//# sourceMappingURL=parse.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../../../lib/router/invoice/parse.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAiHxB,eAAO,MAAM,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;8DAYS,CAAC"}
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import { oc } from "@orpc/contract";
|
|
2
|
-
import { getOpenApiCodeSamples } from "@pdfvector/api-docs";
|
|
3
|
-
import { z } from "zod";
|
|
4
|
-
import { fetchableUrlSchema } from "../../fetchable-url-schema.js";
|
|
5
|
-
import { specializedParseModelDescription, supportedFileFormatsDescription, supportedFileMimeErrorMessage, supportedFileMimes, supportedFileTypesLong, } from "../../supported-mimes.js";
|
|
6
|
-
import { getDefaultSpec } from "./get-default-spec.js";
|
|
7
|
-
const specializedParseModelSchema = z
|
|
8
|
-
.enum(["pro", "max", "auto"], {
|
|
9
|
-
message: "model must be one of: pro, max, auto",
|
|
10
|
-
})
|
|
11
|
-
.default("auto");
|
|
12
|
-
const parseInputSchema = z.object({
|
|
13
|
-
url: fetchableUrlSchema
|
|
14
|
-
.optional()
|
|
15
|
-
.describe("URL of the invoice file to fetch and parse"),
|
|
16
|
-
file: z
|
|
17
|
-
.file()
|
|
18
|
-
.mime([...supportedFileMimes], supportedFileMimeErrorMessage)
|
|
19
|
-
.optional()
|
|
20
|
-
.describe(`Invoice file upload via multipart form-data (${supportedFileFormatsDescription})`),
|
|
21
|
-
base64: z.string().optional().describe("Base64-encoded invoice file content"),
|
|
22
|
-
model: specializedParseModelSchema.describe(specializedParseModelDescription("invoice")),
|
|
23
|
-
documentId: z
|
|
24
|
-
.string()
|
|
25
|
-
.trim()
|
|
26
|
-
.min(1)
|
|
27
|
-
.max(512)
|
|
28
|
-
.optional()
|
|
29
|
-
.describe("Optional external document ID for usage attribution. The x-pdfvector-document-id header takes precedence when both are provided."),
|
|
30
|
-
callback: z
|
|
31
|
-
.object({
|
|
32
|
-
url: fetchableUrlSchema.describe("Webhook URL where results will be POSTed when processing completes"),
|
|
33
|
-
type: z
|
|
34
|
-
.string()
|
|
35
|
-
.optional()
|
|
36
|
-
.describe("Callback type identifier (e.g. 'zapier')"),
|
|
37
|
-
})
|
|
38
|
-
.optional()
|
|
39
|
-
.describe("Optional webhook callback for async processing. " +
|
|
40
|
-
"When provided, the server returns 202 immediately and POSTs the full response payload to the callback URL when processing completes. " +
|
|
41
|
-
"On error, the callback receives a POST with X-Pdfvector-Callback-Failed: true header and error details in the body. " +
|
|
42
|
-
"Useful for long-running operations that may exceed client timeout limits."),
|
|
43
|
-
});
|
|
44
|
-
const parseOutputSchema = z.object({
|
|
45
|
-
markdown: z.string().describe("Extracted text content from the invoice"),
|
|
46
|
-
pageCount: z.number().int().describe("Total number of pages in the document"),
|
|
47
|
-
model: z
|
|
48
|
-
.enum(["pro", "max"])
|
|
49
|
-
.describe("Model tier used to parse the invoice"),
|
|
50
|
-
credits: z
|
|
51
|
-
.number()
|
|
52
|
-
.int()
|
|
53
|
-
.describe("Number of credits consumed by this API call. Cost per page: pro=6, max=10."),
|
|
54
|
-
requestId: z
|
|
55
|
-
.number()
|
|
56
|
-
.int()
|
|
57
|
-
.describe("Unique request identifier for this API call"),
|
|
58
|
-
html: z
|
|
59
|
-
.string()
|
|
60
|
-
.optional()
|
|
61
|
-
.describe("Full HTML representation of the document content. Only available when using the 'max' model. " +
|
|
62
|
-
"Preserves rich formatting, tables, selection marks, and visual layout that cannot be fully represented in markdown."),
|
|
63
|
-
documentId: z
|
|
64
|
-
.string()
|
|
65
|
-
.optional()
|
|
66
|
-
.describe("Document ID if provided via x-pdfvector-document-id header or request body"),
|
|
67
|
-
});
|
|
68
|
-
const requestExamples = {
|
|
69
|
-
"Parse from URL": {
|
|
70
|
-
summary: "Parse from URL",
|
|
71
|
-
value: {
|
|
72
|
-
url: "https://example.com/invoice.pdf",
|
|
73
|
-
},
|
|
74
|
-
},
|
|
75
|
-
"Parse from base64": {
|
|
76
|
-
summary: "Parse from base64",
|
|
77
|
-
value: {
|
|
78
|
-
base64: "JVBERi0xLjAKMSAwIG9iajw8L1R5cGUvQ2F0YWxvZy9QYWdlcyAyIDAgUj4+ZW5kb2JqIDIgMCBvYmo8PC9UeXBlL1BhZ2VzL0tpZHNbMyAwIFJdL0NvdW50IDE+PmVuZG9iaiAzIDAgb2JqPDwvVHlwZS9QYWdlL01lZGlhQm94WzAgMCAzIDNdL1BhcmVudCAyIDAgUj4+ZW5kb2JqCnhyZWYKMCA0CjAwMDAwMDAwMDAgNjU1MzUgZiAKMDAwMDAwMDAwOSAwMDAwMCBuIAowMDAwMDAwMDU4IDAwMDAwIG4gCjAwMDAwMDAxMTUgMDAwMDAgbiAKdHJhaWxlcjw8L1NpemUgNC9Sb290IDEgMCBSPj4Kc3RhcnR4cmVmCjE5MAolJUVPRg==",
|
|
79
|
-
},
|
|
80
|
-
},
|
|
81
|
-
"Parse from file upload": {
|
|
82
|
-
summary: "Parse from file upload",
|
|
83
|
-
value: {
|
|
84
|
-
file: "(binary)",
|
|
85
|
-
},
|
|
86
|
-
},
|
|
87
|
-
};
|
|
88
|
-
export const parse = oc
|
|
89
|
-
.route({
|
|
90
|
-
summary: "Parse an invoice",
|
|
91
|
-
description: `Extract text and structured data from an invoice. Supports ${supportedFileTypesLong}. Provide the document via file upload, a public URL, or a base64-encoded string.`,
|
|
92
|
-
tags: ["Invoice"],
|
|
93
|
-
spec: (op) => {
|
|
94
|
-
const spec = getDefaultSpec(op, requestExamples);
|
|
95
|
-
spec["x-codeSamples"] = getOpenApiCodeSamples("invoice-parse");
|
|
96
|
-
return spec;
|
|
97
|
-
},
|
|
98
|
-
})
|
|
99
|
-
.input(parseInputSchema)
|
|
100
|
-
.output(parseOutputSchema);
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* All MIME types accepted for file uploads across all API endpoints.
|
|
3
|
-
* Single source of truth — imported by all contract schemas.
|
|
4
|
-
*/
|
|
5
|
-
export declare const supportedFileMimes: readonly ["application/pdf", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "application/vnd.openxmlformats-officedocument.presentationml.presentation", "text/csv", "application/csv", "image/png", "image/jpeg", "image/tiff", "image/bmp", "image/heif", "image/heic", "text/plain", "text/markdown", "text/tab-separated-values", "text/xml", "application/xml", "application/rtf", "text/rtf", "text/html", "application/epub+zip", "application/vnd.oasis.opendocument.text", "application/vnd.oasis.opendocument.spreadsheet", "application/vnd.oasis.opendocument.presentation", "application/x-bibtex"];
|
|
6
|
-
export declare const supportedFileFormatsDescription = "PDF, DOCX, XLSX, PPTX, CSV, PNG, JPG, TIFF, BMP, HEIF, TXT, MD, TSV, XML, RTF, HTML, ODT, ODS, ODP, EPUB, BIB, RIS, NBIB, ENW";
|
|
7
|
-
/**
|
|
8
|
-
* Friendly validation error when an uploaded file's MIME type is not supported.
|
|
9
|
-
* Lists the human-readable extensions instead of raw MIME types.
|
|
10
|
-
*/
|
|
11
|
-
export declare const supportedFileMimeErrorMessage = "file must be a supported format: PDF, DOCX, XLSX, PPTX, CSV, PNG, JPG, TIFF, BMP, HEIF, TXT, MD, TSV, XML, RTF, HTML, ODT, ODS, ODP, EPUB, BIB, RIS, NBIB, ENW";
|
|
12
|
-
/**
|
|
13
|
-
* Human-readable description of supported file types with extensions.
|
|
14
|
-
* Used in route-level API descriptions.
|
|
15
|
-
*/
|
|
16
|
-
export declare const supportedFileTypesLong: string;
|
|
17
|
-
/** Model tier descriptions for document parse endpoints. */
|
|
18
|
-
export declare const documentParseModelDescription: string;
|
|
19
|
-
/** Model tier descriptions for document extract endpoints. */
|
|
20
|
-
export declare const documentExtractModelDescription: string;
|
|
21
|
-
/** Model tier descriptions for document ask endpoints. */
|
|
22
|
-
export declare const documentAskModelDescription: string;
|
|
23
|
-
/** Model tier descriptions for invoice/identity/bankStatement parse endpoints (pro/max/auto only). */
|
|
24
|
-
export declare const specializedParseModelDescription: (type: string) => string;
|
|
25
|
-
/** Model tier descriptions for invoice/identity/bankStatement extract endpoints. */
|
|
26
|
-
export declare const specializedExtractModelDescription: string;
|
|
27
|
-
/** Model tier descriptions for invoice/identity/bankStatement ask endpoints. */
|
|
28
|
-
export declare const specializedAskModelDescription: string;
|
|
29
|
-
/** Output model description for parse results. */
|
|
30
|
-
export declare const outputModelDescription: string;
|
|
31
|
-
/** Output model description for extract results. */
|
|
32
|
-
export declare const outputExtractModelDescription: string;
|
|
33
|
-
/** Output model description for ask results. */
|
|
34
|
-
export declare const outputAskModelDescription: string;
|
|
35
|
-
//# sourceMappingURL=supported-mimes.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"supported-mimes.d.ts","sourceRoot":"","sources":["../../lib/supported-mimes.ts"],"names":[],"mappings":"AAWA;;;GAGG;AACH,eAAO,MAAM,kBAAkB,YAE9B,iBAAiB,EAGjB,yEAAyE,EACzE,mEAAmE,EACnE,2EAA2E,EAG3E,UAAU,EACV,iBAAiB,EAGjB,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,YAAY,EAGZ,YAAY,EACZ,eAAe,EACf,2BAA2B,EAC3B,UAAU,EACV,iBAAiB,EAGjB,iBAAiB,EACjB,UAAU,EAGV,WAAW,EAGX,sBAAsB,EACtB,yCAAyC,EACzC,gDAAgD,EAChD,iDAAiD,EAGjD,sBAAsB,CACb,CAAC;AAEX,eAAO,MAAM,+BAA+B,kIAA2B,CAAC;AAExE;;;GAGG;AACH,eAAO,MAAM,6BAA6B,mKAAiE,CAAC;AAE5G;;;GAGG;AACH,eAAO,MAAM,sBAAsB,QAA0B,CAAC;AAyB9D,4DAA4D;AAC5D,eAAO,MAAM,6BAA6B,QAO/B,CAAC;AAEZ,8DAA8D;AAC9D,eAAO,MAAM,+BAA+B,QAOjC,CAAC;AAEZ,0DAA0D;AAC1D,eAAO,MAAM,2BAA2B,QAO7B,CAAC;AAEZ,sGAAsG;AACtG,eAAO,MAAM,gCAAgC,SAAU,MAAM,WAI8D,CAAC;AAE5H,oFAAoF;AACpF,eAAO,MAAM,kCAAkC,QAOpC,CAAC;AAEZ,gFAAgF;AAChF,eAAO,MAAM,8BAA8B,QAOhC,CAAC;AAEZ,kDAAkD;AAClD,eAAO,MAAM,sBAAsB,QAKY,CAAC;AAEhD,oDAAoD;AACpD,eAAO,MAAM,6BAA6B,QAKK,CAAC;AAEhD,gDAAgD;AAChD,eAAO,MAAM,yBAAyB,QAKS,CAAC"}
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import { allSupportedFormatsLong, allSupportedFormatsShort, documentAskExtractCosts, documentParseCosts, formatsByTierDescription, specializedAskExtractCosts, specializedParseCosts, tierLimits, } from "@pdfvector/util";
|
|
2
|
-
/**
|
|
3
|
-
* All MIME types accepted for file uploads across all API endpoints.
|
|
4
|
-
* Single source of truth — imported by all contract schemas.
|
|
5
|
-
*/
|
|
6
|
-
export const supportedFileMimes = [
|
|
7
|
-
// PDF
|
|
8
|
-
"application/pdf",
|
|
9
|
-
// Office documents
|
|
10
|
-
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
11
|
-
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
12
|
-
"application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
13
|
-
// CSV
|
|
14
|
-
"text/csv",
|
|
15
|
-
"application/csv",
|
|
16
|
-
// Images
|
|
17
|
-
"image/png",
|
|
18
|
-
"image/jpeg",
|
|
19
|
-
"image/tiff",
|
|
20
|
-
"image/bmp",
|
|
21
|
-
"image/heif",
|
|
22
|
-
"image/heic",
|
|
23
|
-
// Plain text & structured text
|
|
24
|
-
"text/plain",
|
|
25
|
-
"text/markdown",
|
|
26
|
-
"text/tab-separated-values",
|
|
27
|
-
"text/xml",
|
|
28
|
-
"application/xml",
|
|
29
|
-
// RTF
|
|
30
|
-
"application/rtf",
|
|
31
|
-
"text/rtf",
|
|
32
|
-
// HTML
|
|
33
|
-
"text/html",
|
|
34
|
-
// OpenDocument & EPUB
|
|
35
|
-
"application/epub+zip",
|
|
36
|
-
"application/vnd.oasis.opendocument.text",
|
|
37
|
-
"application/vnd.oasis.opendocument.spreadsheet",
|
|
38
|
-
"application/vnd.oasis.opendocument.presentation",
|
|
39
|
-
// Bibliography / Academic
|
|
40
|
-
"application/x-bibtex",
|
|
41
|
-
];
|
|
42
|
-
export const supportedFileFormatsDescription = allSupportedFormatsShort;
|
|
43
|
-
/**
|
|
44
|
-
* Friendly validation error when an uploaded file's MIME type is not supported.
|
|
45
|
-
* Lists the human-readable extensions instead of raw MIME types.
|
|
46
|
-
*/
|
|
47
|
-
export const supportedFileMimeErrorMessage = `file must be a supported format: ${allSupportedFormatsShort}`;
|
|
48
|
-
/**
|
|
49
|
-
* Human-readable description of supported file types with extensions.
|
|
50
|
-
* Used in route-level API descriptions.
|
|
51
|
-
*/
|
|
52
|
-
export const supportedFileTypesLong = allSupportedFormatsLong;
|
|
53
|
-
const formatNote = `\n\n${formatsByTierDescription}`;
|
|
54
|
-
function fmtSize(bytes) {
|
|
55
|
-
return `${bytes / (1024 * 1024)}MB`;
|
|
56
|
-
}
|
|
57
|
-
function tierDesc(tier, credits, unit, extra) {
|
|
58
|
-
const limit = tierLimits[tier];
|
|
59
|
-
const limitStr = limit
|
|
60
|
-
? `Up to ${limit.maxPages} pages, ${fmtSize(limit.maxFileSize)}.`
|
|
61
|
-
: "";
|
|
62
|
-
return `- ${tier}: ${credits} ${unit}. ${extra}${limitStr ? ` ${limitStr}` : ""}`;
|
|
63
|
-
}
|
|
64
|
-
const autoLimit = tierLimits["auto"];
|
|
65
|
-
if (!autoLimit)
|
|
66
|
-
throw new Error("Missing auto tier limits");
|
|
67
|
-
const autoLimitStr = `Up to ${autoLimit.maxPages} pages, ${fmtSize(autoLimit.maxFileSize)}.`;
|
|
68
|
-
/** Model tier descriptions for document parse endpoints. */
|
|
69
|
-
export const documentParseModelDescription = "Model tier for parsing.\n\n" +
|
|
70
|
-
`- auto (default): Intelligent fallback — credits based on the tier selected automatically. ${autoLimitStr}\n` +
|
|
71
|
-
`${tierDesc("nano", documentParseCosts.nano, "credit/page", "Simple plain text documents.")}\n` +
|
|
72
|
-
`${tierDesc("mini", documentParseCosts.mini, "credits/page", "Documents with tables and structured content.")}\n` +
|
|
73
|
-
`${tierDesc("pro", documentParseCosts.pro, "credits/page", "Tables, handwritten text, figures, math, Arabic, image support.")}\n` +
|
|
74
|
-
`${tierDesc("max", documentParseCosts.max, "credits/page", "Full Pro capabilities + enhanced multilingual.")}` +
|
|
75
|
-
formatNote;
|
|
76
|
-
/** Model tier descriptions for document extract endpoints. */
|
|
77
|
-
export const documentExtractModelDescription = "Model tier for extracting structured data.\n\n" +
|
|
78
|
-
"- auto (default): Automatically selects the best tier — credits based on the tier selected.\n" +
|
|
79
|
-
`- nano: ${documentAskExtractCosts.nano} credits/page. Fastest. Best for simple documents with straightforward schemas.\n` +
|
|
80
|
-
`- mini: ${documentAskExtractCosts.mini} credits/page. Balanced speed and accuracy. Moderately complex schemas.\n` +
|
|
81
|
-
`- pro: ${documentAskExtractCosts.pro} credits/page. High accuracy for complex documents with large or nested schemas.\n` +
|
|
82
|
-
`- max: ${documentAskExtractCosts.max} credits/page. Maximum accuracy. Best for difficult extractions requiring deep reasoning.` +
|
|
83
|
-
formatNote;
|
|
84
|
-
/** Model tier descriptions for document ask endpoints. */
|
|
85
|
-
export const documentAskModelDescription = "Model tier for answering the question.\n\n" +
|
|
86
|
-
"- auto (default): Automatically selects the best tier — credits based on the tier selected.\n" +
|
|
87
|
-
`- nano: ${documentAskExtractCosts.nano} credits/page. Fastest. Best for simple questions about straightforward documents.\n` +
|
|
88
|
-
`- mini: ${documentAskExtractCosts.mini} credits/page. Balanced speed and accuracy. Moderately complex questions.\n` +
|
|
89
|
-
`- pro: ${documentAskExtractCosts.pro} credits/page. High accuracy for nuanced questions about complex documents.\n` +
|
|
90
|
-
`- max: ${documentAskExtractCosts.max} credits/page. Maximum accuracy. Best for difficult questions requiring deep reasoning.` +
|
|
91
|
-
formatNote;
|
|
92
|
-
/** Model tier descriptions for invoice/identity/bankStatement parse endpoints (pro/max/auto only). */
|
|
93
|
-
export const specializedParseModelDescription = (type) => "Model tier for parsing.\n\n" +
|
|
94
|
-
"- auto (default): Intelligent fallback — credits based on the tier selected.\n" +
|
|
95
|
-
`- pro: ${specializedParseCosts.pro} credits/page. Extracts structured ${type} fields with standard accuracy.\n` +
|
|
96
|
-
`- max: ${specializedParseCosts.max} credits/page. Extracts structured ${type} fields with highest accuracy and fallback.`;
|
|
97
|
-
/** Model tier descriptions for invoice/identity/bankStatement extract endpoints. */
|
|
98
|
-
export const specializedExtractModelDescription = "Model tier for extracting structured data.\n\n" +
|
|
99
|
-
"- auto (default): Automatically selects the best tier — credits based on the tier selected.\n" +
|
|
100
|
-
`- nano: ${specializedAskExtractCosts.nano} credits/page. Fastest. Best for simple documents with straightforward schemas.\n` +
|
|
101
|
-
`- mini: ${specializedAskExtractCosts.mini} credits/page. Balanced speed and accuracy. Moderately complex schemas.\n` +
|
|
102
|
-
`- pro: ${specializedAskExtractCosts.pro} credits/page. High accuracy for complex documents with large or nested schemas.\n` +
|
|
103
|
-
`- max: ${specializedAskExtractCosts.max} credits/page. Maximum accuracy. Best for difficult extractions requiring deep reasoning.` +
|
|
104
|
-
formatNote;
|
|
105
|
-
/** Model tier descriptions for invoice/identity/bankStatement ask endpoints. */
|
|
106
|
-
export const specializedAskModelDescription = "Model tier for answering the question.\n\n" +
|
|
107
|
-
"- auto (default): Automatically selects the best tier — credits based on the tier selected.\n" +
|
|
108
|
-
`- nano: ${specializedAskExtractCosts.nano} credits/page. Fastest. Best for simple questions about straightforward documents.\n` +
|
|
109
|
-
`- mini: ${specializedAskExtractCosts.mini} credits/page. Balanced speed and accuracy. Moderately complex questions.\n` +
|
|
110
|
-
`- pro: ${specializedAskExtractCosts.pro} credits/page. High accuracy for nuanced questions about complex documents.\n` +
|
|
111
|
-
`- max: ${specializedAskExtractCosts.max} credits/page. Maximum accuracy. Best for difficult questions requiring deep reasoning.` +
|
|
112
|
-
formatNote;
|
|
113
|
-
/** Output model description for parse results. */
|
|
114
|
-
export const outputModelDescription = "Model tier used to parse the document.\n\n" +
|
|
115
|
-
"- nano: Fastest, best for simple documents.\n" +
|
|
116
|
-
"- mini: Balanced speed and accuracy.\n" +
|
|
117
|
-
"- pro: High accuracy for complex documents.\n" +
|
|
118
|
-
"- max: Maximum accuracy with deep reasoning.";
|
|
119
|
-
/** Output model description for extract results. */
|
|
120
|
-
export const outputExtractModelDescription = "Model tier used to extract the data.\n\n" +
|
|
121
|
-
"- nano: Fastest, best for simple documents.\n" +
|
|
122
|
-
"- mini: Balanced speed and accuracy.\n" +
|
|
123
|
-
"- pro: High accuracy for complex documents.\n" +
|
|
124
|
-
"- max: Maximum accuracy with deep reasoning.";
|
|
125
|
-
/** Output model description for ask results. */
|
|
126
|
-
export const outputAskModelDescription = "Model tier used to answer the question.\n\n" +
|
|
127
|
-
"- nano: Fastest, best for simple questions.\n" +
|
|
128
|
-
"- mini: Balanced speed and accuracy.\n" +
|
|
129
|
-
"- pro: High accuracy for complex questions.\n" +
|
|
130
|
-
"- max: Maximum accuracy with deep reasoning.";
|