sarvamai 1.1.2-alpha.9 → 1.1.2
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/dist/cjs/BaseClient.js +2 -2
- package/dist/cjs/api/resources/documentIntelligence/DocumentIntelligenceJob.d.ts +87 -0
- package/dist/cjs/api/resources/documentIntelligence/DocumentIntelligenceJob.js +279 -0
- package/dist/cjs/api/resources/documentIntelligence/client/Client.d.ts +33 -0
- package/dist/cjs/api/resources/documentIntelligence/client/Client.js +53 -0
- package/dist/cjs/api/resources/documentIntelligence/client/requests/DocumentIntelligenceJobRequest.d.ts +1 -1
- package/dist/cjs/api/resources/documentIntelligence/index.d.ts +1 -0
- package/dist/cjs/api/resources/documentIntelligence/index.js +1 -0
- package/dist/cjs/api/types/DocDigitizationCreateJobResponse.d.ts +1 -1
- package/dist/cjs/api/types/DocDigitizationJobParameters.d.ts +3 -5
- package/dist/cjs/api/types/DocDigitizationOutputFormat.d.ts +2 -0
- package/dist/cjs/api/types/DocDigitizationOutputFormat.js +2 -0
- package/dist/cjs/api/types/DocDigitizationSupportedLanguage.d.ts +1 -1
- package/dist/cjs/api/types/DocDigitizationSupportedLanguage.js +1 -1
- package/dist/cjs/api/types/index.d.ts +0 -1
- package/dist/cjs/api/types/index.js +0 -1
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/BaseClient.mjs +2 -2
- package/dist/esm/api/resources/documentIntelligence/DocumentIntelligenceJob.d.mts +87 -0
- package/dist/esm/api/resources/documentIntelligence/DocumentIntelligenceJob.mjs +242 -0
- package/dist/esm/api/resources/documentIntelligence/client/Client.d.mts +33 -0
- package/dist/esm/api/resources/documentIntelligence/client/Client.mjs +53 -0
- package/dist/esm/api/resources/documentIntelligence/client/requests/DocumentIntelligenceJobRequest.d.mts +1 -1
- package/dist/esm/api/resources/documentIntelligence/index.d.mts +1 -0
- package/dist/esm/api/resources/documentIntelligence/index.mjs +1 -0
- package/dist/esm/api/types/DocDigitizationCreateJobResponse.d.mts +1 -1
- package/dist/esm/api/types/DocDigitizationJobParameters.d.mts +3 -5
- package/dist/esm/api/types/DocDigitizationOutputFormat.d.mts +2 -0
- package/dist/esm/api/types/DocDigitizationOutputFormat.mjs +2 -0
- package/dist/esm/api/types/DocDigitizationSupportedLanguage.d.mts +1 -1
- package/dist/esm/api/types/DocDigitizationSupportedLanguage.mjs +1 -1
- package/dist/esm/api/types/index.d.mts +0 -1
- package/dist/esm/api/types/index.mjs +0 -1
- package/dist/esm/version.d.mts +1 -1
- package/dist/esm/version.mjs +1 -1
- package/package.json +1 -1
- package/reference.md +5 -18
- package/dist/cjs/api/types/DocDigitizationPromptType.d.ts +0 -23
- package/dist/cjs/api/types/DocDigitizationPromptType.js +0 -26
- package/dist/esm/api/types/DocDigitizationPromptType.d.mts +0 -23
- package/dist/esm/api/types/DocDigitizationPromptType.mjs +0 -23
package/dist/cjs/BaseClient.js
CHANGED
|
@@ -43,8 +43,8 @@ function normalizeClientOptions(options) {
|
|
|
43
43
|
const headers = (0, headers_js_1.mergeHeaders)({
|
|
44
44
|
"X-Fern-Language": "JavaScript",
|
|
45
45
|
"X-Fern-SDK-Name": "sarvamai",
|
|
46
|
-
"X-Fern-SDK-Version": "1.1.2
|
|
47
|
-
"User-Agent": "sarvamai/1.1.2
|
|
46
|
+
"X-Fern-SDK-Version": "1.1.2",
|
|
47
|
+
"User-Agent": "sarvamai/1.1.2",
|
|
48
48
|
"X-Fern-Runtime": core.RUNTIME.type,
|
|
49
49
|
"X-Fern-Runtime-Version": core.RUNTIME.version,
|
|
50
50
|
}, options === null || options === void 0 ? void 0 : options.headers);
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import type { DocumentIntelligenceClient } from "./client/Client.js";
|
|
2
|
+
import type * as SarvamAI from "../../index.js";
|
|
3
|
+
export interface DocumentIntelligenceJobOptions {
|
|
4
|
+
/** Language code (e.g., "hi-IN", "en-IN") */
|
|
5
|
+
language?: SarvamAI.DocDigitizationSupportedLanguage;
|
|
6
|
+
/** Output format ("html", "md", or "json") */
|
|
7
|
+
outputFormat?: SarvamAI.DocDigitizationOutputFormat;
|
|
8
|
+
/** Webhook callback URL */
|
|
9
|
+
callbackUrl?: string;
|
|
10
|
+
/** Polling interval in milliseconds for waitUntilComplete (default: 2000) */
|
|
11
|
+
pollingIntervalMs?: number;
|
|
12
|
+
/** Maximum polling attempts for waitUntilComplete (default: 150 = 5 minutes at 2s intervals) */
|
|
13
|
+
maxPollingAttempts?: number;
|
|
14
|
+
}
|
|
15
|
+
export interface PageMetrics {
|
|
16
|
+
totalPages: number;
|
|
17
|
+
pagesProcessed: number;
|
|
18
|
+
pagesSucceeded: number;
|
|
19
|
+
pagesFailed: number;
|
|
20
|
+
pageErrors: SarvamAI.DocDigitizationPageError[];
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* A convenience wrapper around a Document Intelligence job that provides
|
|
24
|
+
* a fluent API matching the Python SDK.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* const job = await client.documentIntelligence.createJob({
|
|
29
|
+
* language: "hi-IN",
|
|
30
|
+
* outputFormat: "html"
|
|
31
|
+
* });
|
|
32
|
+
*
|
|
33
|
+
* await job.uploadFile("./document.pdf");
|
|
34
|
+
* await job.start();
|
|
35
|
+
* const status = await job.waitUntilComplete();
|
|
36
|
+
* const metrics = job.getPageMetrics();
|
|
37
|
+
* await job.downloadOutput("./output.html");
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export declare class DocumentIntelligenceJob {
|
|
41
|
+
private _client;
|
|
42
|
+
private _jobId;
|
|
43
|
+
private _status;
|
|
44
|
+
private _pollingIntervalMs;
|
|
45
|
+
private _maxPollingAttempts;
|
|
46
|
+
constructor(client: DocumentIntelligenceClient, jobId: string, options?: DocumentIntelligenceJobOptions);
|
|
47
|
+
/** The unique job ID */
|
|
48
|
+
get jobId(): string;
|
|
49
|
+
/** Alias for jobId (Python SDK compatibility) */
|
|
50
|
+
get job_id(): string;
|
|
51
|
+
/** The last fetched status (may be null if not yet polled) */
|
|
52
|
+
get status(): SarvamAI.DocDigitizationJobStatusResponse | null;
|
|
53
|
+
/**
|
|
54
|
+
* Upload a file to the job using a presigned URL.
|
|
55
|
+
* Supports file path (Node.js) or File/Blob (browser).
|
|
56
|
+
*/
|
|
57
|
+
uploadFile(file: string | File | Blob): Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Start processing the job.
|
|
60
|
+
*/
|
|
61
|
+
start(): Promise<SarvamAI.DocDigitizationJobStatusResponse>;
|
|
62
|
+
/**
|
|
63
|
+
* Get the current status of the job.
|
|
64
|
+
*/
|
|
65
|
+
getStatus(): Promise<SarvamAI.DocDigitizationJobStatusResponse>;
|
|
66
|
+
/**
|
|
67
|
+
* Poll until the job completes (Completed, PartiallyCompleted, or Failed).
|
|
68
|
+
*/
|
|
69
|
+
waitUntilComplete(): Promise<SarvamAI.DocDigitizationJobStatusResponse>;
|
|
70
|
+
/**
|
|
71
|
+
* Get page-level metrics from the last status.
|
|
72
|
+
*/
|
|
73
|
+
getPageMetrics(): PageMetrics;
|
|
74
|
+
/**
|
|
75
|
+
* Download the output file(s) to the specified path.
|
|
76
|
+
* The output is a ZIP file containing the processed documents.
|
|
77
|
+
*
|
|
78
|
+
* @param outputPath - Path where the output file will be saved
|
|
79
|
+
* @returns The path to the downloaded file
|
|
80
|
+
*/
|
|
81
|
+
downloadOutput(outputPath: string): Promise<string>;
|
|
82
|
+
/**
|
|
83
|
+
* Get download links for the output files.
|
|
84
|
+
*/
|
|
85
|
+
getDownloadLinks(): Promise<SarvamAI.DocDigitizationDownloadFilesResponse>;
|
|
86
|
+
private _sleep;
|
|
87
|
+
}
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Document Intelligence Job wrapper with convenience methods (matching Python SDK API)
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
+
}) : function(o, v) {
|
|
17
|
+
o["default"] = v;
|
|
18
|
+
});
|
|
19
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
20
|
+
var ownKeys = function(o) {
|
|
21
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
22
|
+
var ar = [];
|
|
23
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
24
|
+
return ar;
|
|
25
|
+
};
|
|
26
|
+
return ownKeys(o);
|
|
27
|
+
};
|
|
28
|
+
return function (mod) {
|
|
29
|
+
if (mod && mod.__esModule) return mod;
|
|
30
|
+
var result = {};
|
|
31
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
32
|
+
__setModuleDefault(result, mod);
|
|
33
|
+
return result;
|
|
34
|
+
};
|
|
35
|
+
})();
|
|
36
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
37
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
38
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
39
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
40
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
41
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
42
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
|
+
exports.DocumentIntelligenceJob = void 0;
|
|
47
|
+
/**
|
|
48
|
+
* A convenience wrapper around a Document Intelligence job that provides
|
|
49
|
+
* a fluent API matching the Python SDK.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* const job = await client.documentIntelligence.createJob({
|
|
54
|
+
* language: "hi-IN",
|
|
55
|
+
* outputFormat: "html"
|
|
56
|
+
* });
|
|
57
|
+
*
|
|
58
|
+
* await job.uploadFile("./document.pdf");
|
|
59
|
+
* await job.start();
|
|
60
|
+
* const status = await job.waitUntilComplete();
|
|
61
|
+
* const metrics = job.getPageMetrics();
|
|
62
|
+
* await job.downloadOutput("./output.html");
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
class DocumentIntelligenceJob {
|
|
66
|
+
constructor(client, jobId, options = {}) {
|
|
67
|
+
var _a, _b;
|
|
68
|
+
this._status = null;
|
|
69
|
+
this._client = client;
|
|
70
|
+
this._jobId = jobId;
|
|
71
|
+
this._pollingIntervalMs = (_a = options.pollingIntervalMs) !== null && _a !== void 0 ? _a : 2000;
|
|
72
|
+
this._maxPollingAttempts = (_b = options.maxPollingAttempts) !== null && _b !== void 0 ? _b : 150;
|
|
73
|
+
}
|
|
74
|
+
/** The unique job ID */
|
|
75
|
+
get jobId() {
|
|
76
|
+
return this._jobId;
|
|
77
|
+
}
|
|
78
|
+
/** Alias for jobId (Python SDK compatibility) */
|
|
79
|
+
get job_id() {
|
|
80
|
+
return this._jobId;
|
|
81
|
+
}
|
|
82
|
+
/** The last fetched status (may be null if not yet polled) */
|
|
83
|
+
get status() {
|
|
84
|
+
return this._status;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Upload a file to the job using a presigned URL.
|
|
88
|
+
* Supports file path (Node.js) or File/Blob (browser).
|
|
89
|
+
*/
|
|
90
|
+
uploadFile(file) {
|
|
91
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
92
|
+
// Get filename
|
|
93
|
+
let filename;
|
|
94
|
+
let fileContent;
|
|
95
|
+
if (typeof file === "string") {
|
|
96
|
+
// Node.js: file path
|
|
97
|
+
const fs = yield Promise.resolve().then(() => __importStar(require("fs")));
|
|
98
|
+
const path = yield Promise.resolve().then(() => __importStar(require("path")));
|
|
99
|
+
filename = path.basename(file);
|
|
100
|
+
const buffer = yield fs.promises.readFile(file);
|
|
101
|
+
fileContent = buffer;
|
|
102
|
+
}
|
|
103
|
+
else if (file instanceof File) {
|
|
104
|
+
// Browser: File object
|
|
105
|
+
filename = file.name;
|
|
106
|
+
fileContent = file;
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
// Blob - need a filename
|
|
110
|
+
filename = "document.pdf";
|
|
111
|
+
fileContent = file;
|
|
112
|
+
}
|
|
113
|
+
// Get upload link
|
|
114
|
+
const uploadResponse = yield this._client.getUploadLinks({
|
|
115
|
+
job_id: this._jobId,
|
|
116
|
+
files: [filename],
|
|
117
|
+
});
|
|
118
|
+
const uploadUrls = uploadResponse.upload_urls;
|
|
119
|
+
if (!uploadUrls || Object.keys(uploadUrls).length === 0) {
|
|
120
|
+
throw new Error("No upload URL returned from server");
|
|
121
|
+
}
|
|
122
|
+
// Get the first upload URL
|
|
123
|
+
const uploadInfo = Object.values(uploadUrls)[0];
|
|
124
|
+
if (!(uploadInfo === null || uploadInfo === void 0 ? void 0 : uploadInfo.file_url)) {
|
|
125
|
+
throw new Error("Invalid upload URL response");
|
|
126
|
+
}
|
|
127
|
+
// Upload the file using PUT request
|
|
128
|
+
const headers = {
|
|
129
|
+
"x-ms-blob-type": "BlockBlob",
|
|
130
|
+
};
|
|
131
|
+
// Add any metadata headers from the response
|
|
132
|
+
if (uploadInfo.file_metadata) {
|
|
133
|
+
for (const [key, value] of Object.entries(uploadInfo.file_metadata)) {
|
|
134
|
+
if (typeof value === "string") {
|
|
135
|
+
headers[key] = value;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
const response = yield fetch(uploadInfo.file_url, {
|
|
140
|
+
method: "PUT",
|
|
141
|
+
headers,
|
|
142
|
+
body: fileContent,
|
|
143
|
+
});
|
|
144
|
+
if (!response.ok) {
|
|
145
|
+
throw new Error(`Failed to upload file: ${response.status} ${response.statusText}`);
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Start processing the job.
|
|
151
|
+
*/
|
|
152
|
+
start() {
|
|
153
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
154
|
+
const response = yield this._client.start(this._jobId);
|
|
155
|
+
this._status = response;
|
|
156
|
+
return response;
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Get the current status of the job.
|
|
161
|
+
*/
|
|
162
|
+
getStatus() {
|
|
163
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
164
|
+
const response = yield this._client.getStatus(this._jobId);
|
|
165
|
+
this._status = response;
|
|
166
|
+
return response;
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Poll until the job completes (Completed, PartiallyCompleted, or Failed).
|
|
171
|
+
*/
|
|
172
|
+
waitUntilComplete() {
|
|
173
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
174
|
+
const terminalStates = ["Completed", "PartiallyCompleted", "Failed"];
|
|
175
|
+
let attempts = 0;
|
|
176
|
+
while (attempts < this._maxPollingAttempts) {
|
|
177
|
+
const status = yield this.getStatus();
|
|
178
|
+
if (terminalStates.includes(status.job_state)) {
|
|
179
|
+
return status;
|
|
180
|
+
}
|
|
181
|
+
yield this._sleep(this._pollingIntervalMs);
|
|
182
|
+
attempts++;
|
|
183
|
+
}
|
|
184
|
+
throw new Error(`Job did not complete within ${this._maxPollingAttempts * this._pollingIntervalMs / 1000} seconds`);
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Get page-level metrics from the last status.
|
|
189
|
+
*/
|
|
190
|
+
getPageMetrics() {
|
|
191
|
+
var _a, _b, _c, _d, _e, _f;
|
|
192
|
+
if (!this._status) {
|
|
193
|
+
throw new Error("No status available. Call getStatus() or waitUntilComplete() first.");
|
|
194
|
+
}
|
|
195
|
+
const jobDetails = (_a = this._status.job_details) === null || _a === void 0 ? void 0 : _a[0];
|
|
196
|
+
return {
|
|
197
|
+
totalPages: (_b = jobDetails === null || jobDetails === void 0 ? void 0 : jobDetails.total_pages) !== null && _b !== void 0 ? _b : 0,
|
|
198
|
+
pagesProcessed: (_c = jobDetails === null || jobDetails === void 0 ? void 0 : jobDetails.pages_processed) !== null && _c !== void 0 ? _c : 0,
|
|
199
|
+
pagesSucceeded: (_d = jobDetails === null || jobDetails === void 0 ? void 0 : jobDetails.pages_succeeded) !== null && _d !== void 0 ? _d : 0,
|
|
200
|
+
pagesFailed: (_e = jobDetails === null || jobDetails === void 0 ? void 0 : jobDetails.pages_failed) !== null && _e !== void 0 ? _e : 0,
|
|
201
|
+
pageErrors: (_f = jobDetails === null || jobDetails === void 0 ? void 0 : jobDetails.page_errors) !== null && _f !== void 0 ? _f : [],
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Download the output file(s) to the specified path.
|
|
206
|
+
* The output is a ZIP file containing the processed documents.
|
|
207
|
+
*
|
|
208
|
+
* @param outputPath - Path where the output file will be saved
|
|
209
|
+
* @returns The path to the downloaded file
|
|
210
|
+
*/
|
|
211
|
+
downloadOutput(outputPath) {
|
|
212
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
213
|
+
const downloadResponse = yield this._client.getDownloadLinks(this._jobId);
|
|
214
|
+
const downloadUrls = downloadResponse.download_urls;
|
|
215
|
+
if (!downloadUrls || Object.keys(downloadUrls).length === 0) {
|
|
216
|
+
throw new Error("No download URLs available. Job may not be complete.");
|
|
217
|
+
}
|
|
218
|
+
// Download the first output file
|
|
219
|
+
const downloadInfo = Object.values(downloadUrls)[0];
|
|
220
|
+
if (!(downloadInfo === null || downloadInfo === void 0 ? void 0 : downloadInfo.file_url)) {
|
|
221
|
+
throw new Error("Invalid download URL response");
|
|
222
|
+
}
|
|
223
|
+
// Fetch with timeout (matching Python SDK's 300s timeout)
|
|
224
|
+
const controller = new AbortController();
|
|
225
|
+
const timeoutId = setTimeout(() => controller.abort(), 300000);
|
|
226
|
+
try {
|
|
227
|
+
const response = yield fetch(downloadInfo.file_url, {
|
|
228
|
+
signal: controller.signal,
|
|
229
|
+
});
|
|
230
|
+
if (!response.ok) {
|
|
231
|
+
throw new Error(`Failed to download file: ${response.status} ${response.statusText}`);
|
|
232
|
+
}
|
|
233
|
+
// Use arrayBuffer for binary data (ZIP files)
|
|
234
|
+
const arrayBuffer = yield response.arrayBuffer();
|
|
235
|
+
const content = new Uint8Array(arrayBuffer);
|
|
236
|
+
// Save to file (Node.js) or trigger download (browser)
|
|
237
|
+
if (typeof window === "undefined") {
|
|
238
|
+
// Node.js
|
|
239
|
+
const fs = yield Promise.resolve().then(() => __importStar(require("fs")));
|
|
240
|
+
const path = yield Promise.resolve().then(() => __importStar(require("path")));
|
|
241
|
+
// Ensure output directory exists (matching Python SDK behavior)
|
|
242
|
+
const outputDir = path.dirname(outputPath);
|
|
243
|
+
if (outputDir) {
|
|
244
|
+
yield fs.promises.mkdir(outputDir, { recursive: true });
|
|
245
|
+
}
|
|
246
|
+
yield fs.promises.writeFile(outputPath, content);
|
|
247
|
+
}
|
|
248
|
+
else {
|
|
249
|
+
// Browser - trigger download
|
|
250
|
+
const blob = new Blob([content], { type: "application/zip" });
|
|
251
|
+
const url = URL.createObjectURL(blob);
|
|
252
|
+
const a = document.createElement("a");
|
|
253
|
+
a.href = url;
|
|
254
|
+
a.download = outputPath;
|
|
255
|
+
document.body.appendChild(a);
|
|
256
|
+
a.click();
|
|
257
|
+
a.remove();
|
|
258
|
+
URL.revokeObjectURL(url);
|
|
259
|
+
}
|
|
260
|
+
return outputPath;
|
|
261
|
+
}
|
|
262
|
+
finally {
|
|
263
|
+
clearTimeout(timeoutId);
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Get download links for the output files.
|
|
269
|
+
*/
|
|
270
|
+
getDownloadLinks() {
|
|
271
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
272
|
+
return this._client.getDownloadLinks(this._jobId);
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
_sleep(ms) {
|
|
276
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
exports.DocumentIntelligenceJob = DocumentIntelligenceJob;
|
|
@@ -2,6 +2,7 @@ import type { BaseClientOptions, BaseRequestOptions } from "../../../../BaseClie
|
|
|
2
2
|
import { type NormalizedClientOptionsWithAuth } from "../../../../BaseClient.js";
|
|
3
3
|
import * as core from "../../../../core/index.js";
|
|
4
4
|
import * as SarvamAI from "../../../index.js";
|
|
5
|
+
import { DocumentIntelligenceJob, type DocumentIntelligenceJobOptions } from "../DocumentIntelligenceJob.js";
|
|
5
6
|
export declare namespace DocumentIntelligenceClient {
|
|
6
7
|
interface Options extends BaseClientOptions {
|
|
7
8
|
}
|
|
@@ -70,6 +71,38 @@ export declare class DocumentIntelligenceClient {
|
|
|
70
71
|
* await client.documentIntelligence.initialise()
|
|
71
72
|
*/
|
|
72
73
|
initialise(request?: SarvamAI.DocumentIntelligenceJobRequest, requestOptions?: DocumentIntelligenceClient.RequestOptions): core.HttpResponsePromise<SarvamAI.DocDigitizationCreateJobResponse>;
|
|
74
|
+
/**
|
|
75
|
+
* Creates a new document intelligence job with a fluent API (matching Python SDK).
|
|
76
|
+
*
|
|
77
|
+
* Returns a {@link DocumentIntelligenceJob} instance with convenience methods:
|
|
78
|
+
* - `uploadFile(path)` - Upload a file
|
|
79
|
+
* - `start()` - Start processing
|
|
80
|
+
* - `waitUntilComplete()` - Poll until done
|
|
81
|
+
* - `getPageMetrics()` - Get processing metrics
|
|
82
|
+
* - `downloadOutput(path)` - Download results
|
|
83
|
+
*
|
|
84
|
+
* @param {DocumentIntelligenceJobOptions} options - Job configuration options
|
|
85
|
+
* @param {DocumentIntelligenceClient.RequestOptions} requestOptions - Request-specific configuration
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```typescript
|
|
89
|
+
* const job = await client.documentIntelligence.createJob({
|
|
90
|
+
* language: "hi-IN",
|
|
91
|
+
* outputFormat: "html"
|
|
92
|
+
* });
|
|
93
|
+
*
|
|
94
|
+
* await job.uploadFile("./document.pdf");
|
|
95
|
+
* await job.start();
|
|
96
|
+
* const status = await job.waitUntilComplete();
|
|
97
|
+
* console.log(`Completed: ${status.job_state}`);
|
|
98
|
+
*
|
|
99
|
+
* const metrics = job.getPageMetrics();
|
|
100
|
+
* console.log(`Processed ${metrics.pagesSucceeded} pages`);
|
|
101
|
+
*
|
|
102
|
+
* await job.downloadOutput("./output.html");
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
createJob(options?: DocumentIntelligenceJobOptions, requestOptions?: DocumentIntelligenceClient.RequestOptions): Promise<DocumentIntelligenceJob>;
|
|
73
106
|
private __initialise;
|
|
74
107
|
/**
|
|
75
108
|
* Returns presigned URLs for uploading input files.
|
|
@@ -50,6 +50,7 @@ const core = __importStar(require("../../../../core/index.js"));
|
|
|
50
50
|
const environments = __importStar(require("../../../../environments.js"));
|
|
51
51
|
const errors = __importStar(require("../../../../errors/index.js"));
|
|
52
52
|
const SarvamAI = __importStar(require("../../../index.js"));
|
|
53
|
+
const DocumentIntelligenceJob_js_1 = require("../DocumentIntelligenceJob.js");
|
|
53
54
|
class DocumentIntelligenceClient {
|
|
54
55
|
constructor(options = {}) {
|
|
55
56
|
this._options = (0, BaseClient_js_1.normalizeClientOptionsWithAuth)(options);
|
|
@@ -115,6 +116,58 @@ class DocumentIntelligenceClient {
|
|
|
115
116
|
initialise(request = {}, requestOptions) {
|
|
116
117
|
return core.HttpResponsePromise.fromPromise(this.__initialise(request, requestOptions));
|
|
117
118
|
}
|
|
119
|
+
/**
|
|
120
|
+
* Creates a new document intelligence job with a fluent API (matching Python SDK).
|
|
121
|
+
*
|
|
122
|
+
* Returns a {@link DocumentIntelligenceJob} instance with convenience methods:
|
|
123
|
+
* - `uploadFile(path)` - Upload a file
|
|
124
|
+
* - `start()` - Start processing
|
|
125
|
+
* - `waitUntilComplete()` - Poll until done
|
|
126
|
+
* - `getPageMetrics()` - Get processing metrics
|
|
127
|
+
* - `downloadOutput(path)` - Download results
|
|
128
|
+
*
|
|
129
|
+
* @param {DocumentIntelligenceJobOptions} options - Job configuration options
|
|
130
|
+
* @param {DocumentIntelligenceClient.RequestOptions} requestOptions - Request-specific configuration
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* ```typescript
|
|
134
|
+
* const job = await client.documentIntelligence.createJob({
|
|
135
|
+
* language: "hi-IN",
|
|
136
|
+
* outputFormat: "html"
|
|
137
|
+
* });
|
|
138
|
+
*
|
|
139
|
+
* await job.uploadFile("./document.pdf");
|
|
140
|
+
* await job.start();
|
|
141
|
+
* const status = await job.waitUntilComplete();
|
|
142
|
+
* console.log(`Completed: ${status.job_state}`);
|
|
143
|
+
*
|
|
144
|
+
* const metrics = job.getPageMetrics();
|
|
145
|
+
* console.log(`Processed ${metrics.pagesSucceeded} pages`);
|
|
146
|
+
*
|
|
147
|
+
* await job.downloadOutput("./output.html");
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
150
|
+
createJob() {
|
|
151
|
+
return __awaiter(this, arguments, void 0, function* (options = {}, requestOptions) {
|
|
152
|
+
// Build the request from simplified options
|
|
153
|
+
const request = {};
|
|
154
|
+
if (options.language || options.outputFormat) {
|
|
155
|
+
request.job_parameters = {
|
|
156
|
+
language: options.language,
|
|
157
|
+
output_format: options.outputFormat,
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
if (options.callbackUrl) {
|
|
161
|
+
request.callback = {
|
|
162
|
+
url: options.callbackUrl,
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
// Create the job
|
|
166
|
+
const response = yield this.initialise(request, requestOptions);
|
|
167
|
+
// Return a job wrapper with convenience methods
|
|
168
|
+
return new DocumentIntelligenceJob_js_1.DocumentIntelligenceJob(this, response.job_id, options);
|
|
169
|
+
});
|
|
170
|
+
}
|
|
118
171
|
__initialise() {
|
|
119
172
|
return __awaiter(this, arguments, void 0, function* (request = {}, requestOptions) {
|
|
120
173
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
@@ -4,7 +4,7 @@ import type * as SarvamAI from "../../../../index.js";
|
|
|
4
4
|
* {}
|
|
5
5
|
*/
|
|
6
6
|
export interface DocumentIntelligenceJobRequest {
|
|
7
|
-
/**
|
|
7
|
+
/** Configuration parameters for the Document Intelligence job including language and output format. Defaults to Hindi (hi-IN) and Markdown output if omitted. */
|
|
8
8
|
job_parameters?: SarvamAI.DocDigitizationJobParameters;
|
|
9
9
|
/** Optional webhook for completion notification */
|
|
10
10
|
callback?: SarvamAI.DocDigitizationWebhookCallback;
|
|
@@ -4,7 +4,7 @@ export interface DocDigitizationCreateJobResponse {
|
|
|
4
4
|
job_id: string;
|
|
5
5
|
/** Storage Container Type */
|
|
6
6
|
storage_container_type: SarvamAI.StorageContainerType;
|
|
7
|
-
/**
|
|
7
|
+
/** Job configuration parameters */
|
|
8
8
|
job_parameters: SarvamAI.DocDigitizationJobParameters;
|
|
9
9
|
job_state: SarvamAI.DocDigitizationJobState;
|
|
10
10
|
}
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import type * as SarvamAI from "../index.js";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Configuration parameters for Document Intelligence job. Specify the document language and desired output format.
|
|
4
4
|
*/
|
|
5
5
|
export interface DocDigitizationJobParameters {
|
|
6
|
-
/** BCP-47
|
|
6
|
+
/** Primary language of the document in BCP-47 format. This helps optimize text extraction accuracy for the specified language. */
|
|
7
7
|
language?: SarvamAI.DocDigitizationSupportedLanguage;
|
|
8
|
-
/** Output format
|
|
8
|
+
/** Output format for the extracted content (delivered as a ZIP file). Use 'html' for structured HTML, 'md' for Markdown, or 'json' for structured JSON data. */
|
|
9
9
|
output_format?: SarvamAI.DocDigitizationOutputFormat;
|
|
10
|
-
/** Processing mode for content extraction. When null (default), standard OCR is applied to text blocks, tables are converted based on output_format, and images/diagrams receive captions in the document language. */
|
|
11
|
-
prompt_type?: SarvamAI.DocDigitizationPromptType;
|
|
12
10
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
/** Output format for extracted document content, delivered as a ZIP file. 'html' returns structured HTML files, 'md' returns human-readable Markdown files, 'json' returns structured JSON files for programmatic processing. */
|
|
1
2
|
export declare const DocDigitizationOutputFormat: {
|
|
2
3
|
readonly Html: "html";
|
|
3
4
|
readonly Md: "md";
|
|
5
|
+
readonly Json: "json";
|
|
4
6
|
};
|
|
5
7
|
export type DocDigitizationOutputFormat = (typeof DocDigitizationOutputFormat)[keyof typeof DocDigitizationOutputFormat];
|
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
// This file was auto-generated by Fern from our API Definition.
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.DocDigitizationOutputFormat = void 0;
|
|
5
|
+
/** Output format for extracted document content, delivered as a ZIP file. 'html' returns structured HTML files, 'md' returns human-readable Markdown files, 'json' returns structured JSON files for programmatic processing. */
|
|
5
6
|
exports.DocDigitizationOutputFormat = {
|
|
6
7
|
Html: "html",
|
|
7
8
|
Md: "md",
|
|
9
|
+
Json: "json",
|
|
8
10
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** BCP-47 language code
|
|
1
|
+
/** BCP-47 language code specifying the primary language of the document. Supports 23 languages: 22 Indian languages (Hindi, Bengali, Tamil, Telugu, Marathi, Gujarati, Kannada, Malayalam, Odia, Punjabi, Assamese, Urdu, Sanskrit, Nepali, Konkani, Maithili, Sindhi, Kashmiri, Dogri, Manipuri, Bodo, Santali) and English language. */
|
|
2
2
|
export declare const DocDigitizationSupportedLanguage: {
|
|
3
3
|
readonly HiIn: "hi-IN";
|
|
4
4
|
readonly EnIn: "en-IN";
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// This file was auto-generated by Fern from our API Definition.
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.DocDigitizationSupportedLanguage = void 0;
|
|
5
|
-
/** BCP-47 language code
|
|
5
|
+
/** BCP-47 language code specifying the primary language of the document. Supports 23 languages: 22 Indian languages (Hindi, Bengali, Tamil, Telugu, Marathi, Gujarati, Kannada, Malayalam, Odia, Punjabi, Assamese, Urdu, Sanskrit, Nepali, Konkani, Maithili, Sindhi, Kashmiri, Dogri, Manipuri, Bodo, Santali) and English language. */
|
|
6
6
|
exports.DocDigitizationSupportedLanguage = {
|
|
7
7
|
HiIn: "hi-IN",
|
|
8
8
|
EnIn: "en-IN",
|
|
@@ -30,7 +30,6 @@ export * from "./DocDigitizationJobState.js";
|
|
|
30
30
|
export * from "./DocDigitizationJobStatusResponse.js";
|
|
31
31
|
export * from "./DocDigitizationOutputFormat.js";
|
|
32
32
|
export * from "./DocDigitizationPageError.js";
|
|
33
|
-
export * from "./DocDigitizationPromptType.js";
|
|
34
33
|
export * from "./DocDigitizationSupportedLanguage.js";
|
|
35
34
|
export * from "./DocDigitizationUploadFilesResponse.js";
|
|
36
35
|
export * from "./DocDigitizationWebhookCallback.js";
|
|
@@ -46,7 +46,6 @@ __exportStar(require("./DocDigitizationJobState.js"), exports);
|
|
|
46
46
|
__exportStar(require("./DocDigitizationJobStatusResponse.js"), exports);
|
|
47
47
|
__exportStar(require("./DocDigitizationOutputFormat.js"), exports);
|
|
48
48
|
__exportStar(require("./DocDigitizationPageError.js"), exports);
|
|
49
|
-
__exportStar(require("./DocDigitizationPromptType.js"), exports);
|
|
50
49
|
__exportStar(require("./DocDigitizationSupportedLanguage.js"), exports);
|
|
51
50
|
__exportStar(require("./DocDigitizationUploadFilesResponse.js"), exports);
|
|
52
51
|
__exportStar(require("./DocDigitizationWebhookCallback.js"), exports);
|
package/dist/cjs/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "1.1.2
|
|
1
|
+
export declare const SDK_VERSION = "1.1.2";
|
package/dist/cjs/version.js
CHANGED
package/dist/esm/BaseClient.mjs
CHANGED
|
@@ -6,8 +6,8 @@ export function normalizeClientOptions(options) {
|
|
|
6
6
|
const headers = mergeHeaders({
|
|
7
7
|
"X-Fern-Language": "JavaScript",
|
|
8
8
|
"X-Fern-SDK-Name": "sarvamai",
|
|
9
|
-
"X-Fern-SDK-Version": "1.1.2
|
|
10
|
-
"User-Agent": "sarvamai/1.1.2
|
|
9
|
+
"X-Fern-SDK-Version": "1.1.2",
|
|
10
|
+
"User-Agent": "sarvamai/1.1.2",
|
|
11
11
|
"X-Fern-Runtime": core.RUNTIME.type,
|
|
12
12
|
"X-Fern-Runtime-Version": core.RUNTIME.version,
|
|
13
13
|
}, options === null || options === void 0 ? void 0 : options.headers);
|