@nestbox-ai/doc-processing-api 1.0.68 → 1.0.70
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/USAGE_GUIDE.md +665 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
## @nestbox-ai/doc-processing-api@1.0.
|
|
1
|
+
## @nestbox-ai/doc-processing-api@1.0.70
|
|
2
2
|
|
|
3
3
|
This generator creates TypeScript/JavaScript client that utilizes [axios](https://github.com/axios/axios). The generated Node module can be used in the following environments:
|
|
4
4
|
|
|
@@ -36,7 +36,7 @@ navigate to the folder of your consuming project and run one of the following co
|
|
|
36
36
|
_published:_
|
|
37
37
|
|
|
38
38
|
```
|
|
39
|
-
npm install @nestbox-ai/doc-processing-api@1.0.
|
|
39
|
+
npm install @nestbox-ai/doc-processing-api@1.0.70 --save
|
|
40
40
|
```
|
|
41
41
|
|
|
42
42
|
_unPublished (not recommended):_
|
package/USAGE_GUIDE.md
ADDED
|
@@ -0,0 +1,665 @@
|
|
|
1
|
+
# Nestbox AI Document Processing API — Usage Guide
|
|
2
|
+
|
|
3
|
+
This guide walks you through using the `@nestbox-ai/doc-processing-api` TypeScript client to interact with the Nestbox Documents Processing API. The library is auto-generated from OpenAPI and uses [axios](https://github.com/axios/axios) under the hood.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Table of Contents
|
|
8
|
+
|
|
9
|
+
- [Installation](#installation)
|
|
10
|
+
- [Configuration](#configuration)
|
|
11
|
+
- [Quick Start — End-to-End Workflow](#quick-start--end-to-end-workflow)
|
|
12
|
+
- [API Reference by Domain](#api-reference-by-domain)
|
|
13
|
+
- [Profiles](#profiles)
|
|
14
|
+
- [Documents](#documents)
|
|
15
|
+
- [Jobs](#jobs)
|
|
16
|
+
- [Evals](#evals)
|
|
17
|
+
- [Queries](#queries)
|
|
18
|
+
- [Sources](#sources)
|
|
19
|
+
- [Artifacts](#artifacts)
|
|
20
|
+
- [Webhooks](#webhooks)
|
|
21
|
+
- [Health](#health)
|
|
22
|
+
- [Pagination](#pagination)
|
|
23
|
+
- [Error Handling](#error-handling)
|
|
24
|
+
- [Models Reference](#models-reference)
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## Installation
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
npm install @nestbox-ai/doc-processing-api
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
The only runtime dependency is `axios ^1.13.5`.
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## Configuration
|
|
39
|
+
|
|
40
|
+
Every API class accepts an optional `Configuration` object that lets you set the base URL, authentication headers, and other request defaults.
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
import { Configuration } from '@nestbox-ai/doc-processing-api';
|
|
44
|
+
|
|
45
|
+
const config = new Configuration({
|
|
46
|
+
basePath: 'https://doc-processing.example.com', // your server URL
|
|
47
|
+
baseOptions: {
|
|
48
|
+
headers: {
|
|
49
|
+
'Authorization': 'Bearer <YOUR_TOKEN>',
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Configuration Options
|
|
56
|
+
|
|
57
|
+
| Option | Type | Description |
|
|
58
|
+
|--------|------|-------------|
|
|
59
|
+
| `basePath` | `string` | Override the default base URL (`http://localhost`). |
|
|
60
|
+
| `apiKey` | `string \| (name: string) => string` | API key for key-based auth. |
|
|
61
|
+
| `accessToken` | `string \| (name?: string, scopes?: string[]) => string` | OAuth2 / Bearer token. |
|
|
62
|
+
| `username` / `password` | `string` | Basic auth credentials. |
|
|
63
|
+
| `baseOptions` | `object` | Default axios request options (headers, timeout, etc.). |
|
|
64
|
+
| `formDataCtor` | `new () => FormData` | Custom `FormData` constructor for environments that don't have a built-in one. |
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
## Quick Start — End-to-End Workflow
|
|
69
|
+
|
|
70
|
+
The typical workflow is: **create a profile → upload a document → poll the job → retrieve results**.
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
import {
|
|
74
|
+
Configuration,
|
|
75
|
+
ProfilesApi,
|
|
76
|
+
DocumentsApi,
|
|
77
|
+
JobsApi,
|
|
78
|
+
SourcesApi,
|
|
79
|
+
ArtifactsApi,
|
|
80
|
+
} from '@nestbox-ai/doc-processing-api';
|
|
81
|
+
import * as fs from 'fs';
|
|
82
|
+
|
|
83
|
+
const config = new Configuration({
|
|
84
|
+
basePath: 'https://doc-processing.example.com',
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
const profiles = new ProfilesApi(config);
|
|
88
|
+
const documents = new DocumentsApi(config);
|
|
89
|
+
const jobs = new JobsApi(config);
|
|
90
|
+
const sources = new SourcesApi(config);
|
|
91
|
+
const artifacts = new ArtifactsApi(config);
|
|
92
|
+
|
|
93
|
+
async function processDocument() {
|
|
94
|
+
// 1. Create a profile from a YAML config file
|
|
95
|
+
const profileYaml = fs.createReadStream('./my-profile.yaml') as any;
|
|
96
|
+
const { data: profile } = await profiles.profilesControllerCreateProfile(
|
|
97
|
+
profileYaml,
|
|
98
|
+
'my-extraction-profile', // optional name override
|
|
99
|
+
['production', 'finance'] // optional tags
|
|
100
|
+
);
|
|
101
|
+
console.log('Profile created:', profile.id);
|
|
102
|
+
|
|
103
|
+
// 2. Upload a document for processing
|
|
104
|
+
const file = fs.createReadStream('./report.pdf') as any;
|
|
105
|
+
const { data: createResponse } = await documents.documentsControllerCreateDocument(
|
|
106
|
+
profile.id, // profileId
|
|
107
|
+
file, // the document file
|
|
108
|
+
undefined, // stages (auto-detected)
|
|
109
|
+
'normal', // priority: 'low' | 'normal' | 'high'
|
|
110
|
+
false, // visualize
|
|
111
|
+
['invoice', '2024'] // tags
|
|
112
|
+
);
|
|
113
|
+
const documentId = createResponse.document.id;
|
|
114
|
+
const jobId = createResponse.job.id;
|
|
115
|
+
console.log('Document created:', documentId, '| Job:', jobId);
|
|
116
|
+
|
|
117
|
+
// 3. Poll job status until completed
|
|
118
|
+
let jobStatus;
|
|
119
|
+
do {
|
|
120
|
+
const { data } = await jobs.jobsControllerGetJobStatus(jobId);
|
|
121
|
+
jobStatus = data;
|
|
122
|
+
console.log(`Job ${jobId}: ${jobStatus.state} (${(jobStatus.progress ?? 0) * 100}%)`);
|
|
123
|
+
if (jobStatus.state === 'completed' || jobStatus.state === 'failed') break;
|
|
124
|
+
await new Promise((r) => setTimeout(r, 3000)); // wait 3s
|
|
125
|
+
} while (true);
|
|
126
|
+
|
|
127
|
+
if (jobStatus.state === 'failed') {
|
|
128
|
+
console.error('Job failed:', jobStatus.error);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// 4. Read back the document (now with metrics)
|
|
133
|
+
const { data: doc } = await documents.documentsControllerGetDocument(documentId);
|
|
134
|
+
console.log('Document status:', doc.status, '| Metrics:', doc.metrics);
|
|
135
|
+
|
|
136
|
+
// 5. Retrieve source chunks
|
|
137
|
+
const { data: sourcesResponse } = await sources.sourcesControllerGetDocumentSources(documentId);
|
|
138
|
+
console.log('Sources:', sourcesResponse.data.length, 'items');
|
|
139
|
+
|
|
140
|
+
// 6. Download pipeline artifacts (zip)
|
|
141
|
+
const { data: archive } = await artifacts.artifactsControllerDownloadDocumentArtifacts(documentId);
|
|
142
|
+
console.log('Artifacts downloaded');
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
processDocument().catch(console.error);
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
---
|
|
149
|
+
|
|
150
|
+
## API Reference by Domain
|
|
151
|
+
|
|
152
|
+
### Profiles
|
|
153
|
+
|
|
154
|
+
Profiles are YAML configuration files that define how documents are processed (extraction rules, pipeline stages, etc.).
|
|
155
|
+
|
|
156
|
+
```typescript
|
|
157
|
+
import { ProfilesApi, Configuration } from '@nestbox-ai/doc-processing-api';
|
|
158
|
+
|
|
159
|
+
const api = new ProfilesApi(new Configuration({ basePath: '...' }));
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
#### Create a Profile
|
|
163
|
+
|
|
164
|
+
Upload a YAML config file via multipart form:
|
|
165
|
+
|
|
166
|
+
```typescript
|
|
167
|
+
const yamlFile = fs.createReadStream('./config.yaml') as any;
|
|
168
|
+
|
|
169
|
+
const { data: profile } = await api.profilesControllerCreateProfile(
|
|
170
|
+
yamlFile, // yaml: File — the YAML config
|
|
171
|
+
'my-profile-name', // name (optional) — overrides name from YAML
|
|
172
|
+
['tag1', 'tag2'] // tags (optional)
|
|
173
|
+
);
|
|
174
|
+
// profile: ProfileDto { id, name, description, createdAt, yamlFileName, ... }
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
#### Get a Profile
|
|
178
|
+
|
|
179
|
+
```typescript
|
|
180
|
+
const { data: profile } = await api.profilesControllerGetProfile('profile-id-here');
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
#### List Profiles
|
|
184
|
+
|
|
185
|
+
```typescript
|
|
186
|
+
const { data: paginated } = await api.profilesControllerListProfiles(
|
|
187
|
+
1, // page (1-based)
|
|
188
|
+
20 // limit
|
|
189
|
+
);
|
|
190
|
+
// paginated: PaginatedProfilesDto { data: ProfileDto[], pagination: PaginationDto }
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
#### Get Profile Schema
|
|
194
|
+
|
|
195
|
+
Returns the JSON schema that YAML profiles must conform to:
|
|
196
|
+
|
|
197
|
+
```typescript
|
|
198
|
+
const { data: schema } = await api.profilesControllerGetProfileSchema();
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
---
|
|
202
|
+
|
|
203
|
+
### Documents
|
|
204
|
+
|
|
205
|
+
Documents represent files uploaded for processing (PDF, DOCX, HTML, Markdown, etc.).
|
|
206
|
+
|
|
207
|
+
```typescript
|
|
208
|
+
import { DocumentsApi, Configuration } from '@nestbox-ai/doc-processing-api';
|
|
209
|
+
|
|
210
|
+
const api = new DocumentsApi(new Configuration({ basePath: '...' }));
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
#### Create a Document (Upload & Process)
|
|
214
|
+
|
|
215
|
+
Uploads a file and starts a background processing job:
|
|
216
|
+
|
|
217
|
+
```typescript
|
|
218
|
+
const file = fs.createReadStream('./document.pdf') as any;
|
|
219
|
+
|
|
220
|
+
const { data } = await api.documentsControllerCreateDocument(
|
|
221
|
+
'profile-id', // profileId — which profile/config to use
|
|
222
|
+
file, // file — the document file
|
|
223
|
+
'docling,chunking', // stages (optional) — pipeline stages to run
|
|
224
|
+
'high', // priority (optional) — 'low' | 'normal' | 'high'
|
|
225
|
+
true, // visualize (optional) — generate graph artifacts
|
|
226
|
+
['invoice', 'quarterly'] // tags (optional)
|
|
227
|
+
);
|
|
228
|
+
|
|
229
|
+
// data: DocumentCreateResponseDto
|
|
230
|
+
// data.document — the created DocumentDto
|
|
231
|
+
// data.job — the processing JobDto (use job.id to track progress)
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
#### Get a Document
|
|
235
|
+
|
|
236
|
+
```typescript
|
|
237
|
+
const { data: doc } = await api.documentsControllerGetDocument('document-id');
|
|
238
|
+
// doc: DocumentDto { id, profileId, status, fileName, contentType, sizeBytes, metrics, tags, ... }
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
**Document statuses:** `queued` → `processing` → `ready` | `failed` | `deleted`
|
|
242
|
+
|
|
243
|
+
#### List Documents
|
|
244
|
+
|
|
245
|
+
```typescript
|
|
246
|
+
const { data: paginated } = await api.documentsControllerListDocuments(
|
|
247
|
+
1, // page
|
|
248
|
+
25, // limit
|
|
249
|
+
'profile-id', // profileId filter (optional)
|
|
250
|
+
['finance'] // tags filter (optional)
|
|
251
|
+
);
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
---
|
|
255
|
+
|
|
256
|
+
### Jobs
|
|
257
|
+
|
|
258
|
+
Jobs track asynchronous processing operations (document processing, evaluations, batch queries).
|
|
259
|
+
|
|
260
|
+
```typescript
|
|
261
|
+
import { JobsApi, Configuration } from '@nestbox-ai/doc-processing-api';
|
|
262
|
+
|
|
263
|
+
const api = new JobsApi(new Configuration({ basePath: '...' }));
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
#### Get Full Job Details
|
|
267
|
+
|
|
268
|
+
```typescript
|
|
269
|
+
const { data: job } = await api.jobsControllerGetJob('job-id');
|
|
270
|
+
// job: JobDto { id, type, state, progress, stage, message, error, links, metadata, ... }
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
**Job types:** `document_processing`, `evaluation`, `batch_query`, `other`
|
|
274
|
+
**Job states:** `pending` → `processing` → `completed` | `failed` | `canceled`
|
|
275
|
+
|
|
276
|
+
#### Poll Job Status (Lightweight)
|
|
277
|
+
|
|
278
|
+
Returns only essential status fields — ideal for polling loops:
|
|
279
|
+
|
|
280
|
+
```typescript
|
|
281
|
+
const { data: status } = await api.jobsControllerGetJobStatus('job-id');
|
|
282
|
+
// status: JobStatusDto { id, state, progress, stage, message, error, updatedAt }
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
#### List Jobs
|
|
286
|
+
|
|
287
|
+
```typescript
|
|
288
|
+
const { data: paginated } = await api.jobsControllerListJobs(
|
|
289
|
+
1, // page
|
|
290
|
+
50 // limit
|
|
291
|
+
);
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
#### Polling Pattern
|
|
295
|
+
|
|
296
|
+
```typescript
|
|
297
|
+
async function waitForJob(api: JobsApi, jobId: string, intervalMs = 3000): Promise<JobStatusDto> {
|
|
298
|
+
while (true) {
|
|
299
|
+
const { data: status } = await api.jobsControllerGetJobStatus(jobId);
|
|
300
|
+
if (status.state === 'completed' || status.state === 'failed' || status.state === 'canceled') {
|
|
301
|
+
return status;
|
|
302
|
+
}
|
|
303
|
+
console.log(`[${jobId}] ${status.state} — ${status.stage ?? ''} (${((status.progress ?? 0) * 100).toFixed(0)}%)`);
|
|
304
|
+
await new Promise((r) => setTimeout(r, intervalMs));
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
---
|
|
310
|
+
|
|
311
|
+
### Evals
|
|
312
|
+
|
|
313
|
+
Evaluations let you run test cases (defined in YAML) against a processed document to measure accuracy and quality.
|
|
314
|
+
|
|
315
|
+
```typescript
|
|
316
|
+
import { EvalsApi, Configuration } from '@nestbox-ai/doc-processing-api';
|
|
317
|
+
|
|
318
|
+
const api = new EvalsApi(new Configuration({ basePath: '...' }));
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
#### Create an Eval
|
|
322
|
+
|
|
323
|
+
```typescript
|
|
324
|
+
const yamlFile = fs.createReadStream('./test-cases.yaml') as any;
|
|
325
|
+
|
|
326
|
+
const { data } = await api.evalsControllerCreateEval(
|
|
327
|
+
'document-id', // documentId
|
|
328
|
+
yamlFile, // yaml — eval YAML file (test cases)
|
|
329
|
+
false // watch (optional) — if true, server may keep request open longer
|
|
330
|
+
);
|
|
331
|
+
// data: EvalCreateResponseDto { eval: EvalDto, job: JobDto }
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
#### Validate Eval YAML Before Submitting
|
|
335
|
+
|
|
336
|
+
Check your YAML for errors before creating an eval:
|
|
337
|
+
|
|
338
|
+
```typescript
|
|
339
|
+
const yamlFile = fs.createReadStream('./test-cases.yaml') as any;
|
|
340
|
+
|
|
341
|
+
const { data: validation } = await api.evalsControllerValidateEvalYaml(
|
|
342
|
+
'document-id',
|
|
343
|
+
yamlFile
|
|
344
|
+
);
|
|
345
|
+
// validation: ValidationResultDto { valid: boolean, warnings?: ValidationIssueDto[], normalized?: object }
|
|
346
|
+
|
|
347
|
+
if (!validation.valid) {
|
|
348
|
+
console.error('YAML validation failed');
|
|
349
|
+
}
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
#### Get an Eval
|
|
353
|
+
|
|
354
|
+
```typescript
|
|
355
|
+
const { data: evalResult } = await api.evalsControllerGetEval('document-id', 'eval-id');
|
|
356
|
+
// evalResult: EvalDto { id, documentId, status, summary, report, ... }
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
**Eval statuses:** `queued` → `running` → `completed` | `failed`
|
|
360
|
+
|
|
361
|
+
#### List Evals for a Document
|
|
362
|
+
|
|
363
|
+
```typescript
|
|
364
|
+
const { data: paginated } = await api.evalsControllerListEvals(
|
|
365
|
+
'document-id',
|
|
366
|
+
1, // page
|
|
367
|
+
20 // limit
|
|
368
|
+
);
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
---
|
|
372
|
+
|
|
373
|
+
### Queries
|
|
374
|
+
|
|
375
|
+
Batch queries let you submit a set of questions (defined in YAML) to run against processed documents.
|
|
376
|
+
|
|
377
|
+
```typescript
|
|
378
|
+
import { QueriesApi, Configuration } from '@nestbox-ai/doc-processing-api';
|
|
379
|
+
|
|
380
|
+
const api = new QueriesApi(new Configuration({ basePath: '...' }));
|
|
381
|
+
```
|
|
382
|
+
|
|
383
|
+
#### Create a Batch Query
|
|
384
|
+
|
|
385
|
+
```typescript
|
|
386
|
+
const yamlFile = fs.createReadStream('./queries.yaml') as any;
|
|
387
|
+
|
|
388
|
+
const { data } = await api.queriesControllerCreateQuery(
|
|
389
|
+
yamlFile, // yaml — batch queries YAML file
|
|
390
|
+
false // watch (optional)
|
|
391
|
+
);
|
|
392
|
+
// data: QueryCreateResponseDto { query: BatchQueryDto, job: JobDto }
|
|
393
|
+
```
|
|
394
|
+
|
|
395
|
+
#### Validate Query YAML Before Submitting
|
|
396
|
+
|
|
397
|
+
```typescript
|
|
398
|
+
const yamlFile = fs.createReadStream('./queries.yaml') as any;
|
|
399
|
+
|
|
400
|
+
const { data: validation } = await api.queriesControllerValidateQueryYaml(yamlFile);
|
|
401
|
+
// validation: ValidationResultDto { valid, warnings?, normalized? }
|
|
402
|
+
```
|
|
403
|
+
|
|
404
|
+
#### Get a Batch Query
|
|
405
|
+
|
|
406
|
+
```typescript
|
|
407
|
+
const { data: query } = await api.queriesControllerGetQuery('query-id');
|
|
408
|
+
// query: BatchQueryDto { id, documentId, status, results, ... }
|
|
409
|
+
```
|
|
410
|
+
|
|
411
|
+
**Query statuses:** `queued` → `running` → `completed` | `failed`
|
|
412
|
+
|
|
413
|
+
#### List Batch Queries
|
|
414
|
+
|
|
415
|
+
```typescript
|
|
416
|
+
const { data: paginated } = await api.queriesControllerListQueries(
|
|
417
|
+
1, // page
|
|
418
|
+
20 // limit
|
|
419
|
+
);
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
---
|
|
423
|
+
|
|
424
|
+
### Sources
|
|
425
|
+
|
|
426
|
+
Sources represent the text chunks and data used to produce answers during queries.
|
|
427
|
+
|
|
428
|
+
```typescript
|
|
429
|
+
import { SourcesApi, Configuration } from '@nestbox-ai/doc-processing-api';
|
|
430
|
+
|
|
431
|
+
const api = new SourcesApi(new Configuration({ basePath: '...' }));
|
|
432
|
+
```
|
|
433
|
+
|
|
434
|
+
#### Get Document Sources
|
|
435
|
+
|
|
436
|
+
```typescript
|
|
437
|
+
const { data: sourcesResponse } = await api.sourcesControllerGetDocumentSources(
|
|
438
|
+
'document-id',
|
|
439
|
+
'job-id', // jobId (optional) — scope to a specific query job
|
|
440
|
+
'source-id' // sourceId (optional) — retrieve a specific source by ID
|
|
441
|
+
);
|
|
442
|
+
// sourcesResponse: DocumentSourcesResponseDto { data: SourceItemDto[] }
|
|
443
|
+
|
|
444
|
+
for (const source of sourcesResponse.data) {
|
|
445
|
+
console.log(`[${source.id}] page=${source.page}, chunk=${source.chunkId}`);
|
|
446
|
+
console.log(source.text);
|
|
447
|
+
}
|
|
448
|
+
```
|
|
449
|
+
|
|
450
|
+
Each `SourceItemDto` contains:
|
|
451
|
+
- `id` — unique source identifier
|
|
452
|
+
- `documentId` — parent document
|
|
453
|
+
- `jobId` — associated job
|
|
454
|
+
- `chunkId` — the chunk within the document
|
|
455
|
+
- `page` — page number
|
|
456
|
+
- `text` — the source text content
|
|
457
|
+
- `metadata` — additional key-value metadata
|
|
458
|
+
|
|
459
|
+
---
|
|
460
|
+
|
|
461
|
+
### Artifacts
|
|
462
|
+
|
|
463
|
+
Download pipeline artifacts (GraphRAG outputs, DB snapshots, visualizations) as a zip archive.
|
|
464
|
+
|
|
465
|
+
```typescript
|
|
466
|
+
import { ArtifactsApi, Configuration } from '@nestbox-ai/doc-processing-api';
|
|
467
|
+
|
|
468
|
+
const api = new ArtifactsApi(new Configuration({ basePath: '...' }));
|
|
469
|
+
```
|
|
470
|
+
|
|
471
|
+
#### Download Document Artifacts
|
|
472
|
+
|
|
473
|
+
```typescript
|
|
474
|
+
const response = await api.artifactsControllerDownloadDocumentArtifacts('document-id');
|
|
475
|
+
// Response body is a zip archive (application/zip)
|
|
476
|
+
```
|
|
477
|
+
|
|
478
|
+
To save the archive to disk, configure axios to handle binary responses:
|
|
479
|
+
|
|
480
|
+
```typescript
|
|
481
|
+
const config = new Configuration({
|
|
482
|
+
basePath: '...',
|
|
483
|
+
baseOptions: { responseType: 'arraybuffer' },
|
|
484
|
+
});
|
|
485
|
+
const api = new ArtifactsApi(config);
|
|
486
|
+
|
|
487
|
+
const { data } = await api.artifactsControllerDownloadDocumentArtifacts('document-id');
|
|
488
|
+
fs.writeFileSync('./artifacts.zip', Buffer.from(data));
|
|
489
|
+
```
|
|
490
|
+
|
|
491
|
+
---
|
|
492
|
+
|
|
493
|
+
### Webhooks
|
|
494
|
+
|
|
495
|
+
Register webhook URLs to receive notifications when processing jobs complete or fail.
|
|
496
|
+
|
|
497
|
+
```typescript
|
|
498
|
+
import { WebhooksApi, Configuration } from '@nestbox-ai/doc-processing-api';
|
|
499
|
+
|
|
500
|
+
const api = new WebhooksApi(new Configuration({ basePath: '...' }));
|
|
501
|
+
```
|
|
502
|
+
|
|
503
|
+
#### Create a Webhook
|
|
504
|
+
|
|
505
|
+
```typescript
|
|
506
|
+
const { data: webhook } = await api.webhooksControllerCreateWebhook({
|
|
507
|
+
url: 'https://your-server.com/webhooks/doc-processing',
|
|
508
|
+
});
|
|
509
|
+
// webhook: WebhookDto { id, url, createdAt, updatedAt }
|
|
510
|
+
```
|
|
511
|
+
|
|
512
|
+
#### Get a Webhook
|
|
513
|
+
|
|
514
|
+
```typescript
|
|
515
|
+
const { data: webhook } = await api.webhooksControllerGetWebhook('webhook-id');
|
|
516
|
+
```
|
|
517
|
+
|
|
518
|
+
#### List Webhooks
|
|
519
|
+
|
|
520
|
+
```typescript
|
|
521
|
+
const { data: paginated } = await api.webhooksControllerListWebhooks(
|
|
522
|
+
1, // page
|
|
523
|
+
20 // limit
|
|
524
|
+
);
|
|
525
|
+
```
|
|
526
|
+
|
|
527
|
+
#### Update a Webhook
|
|
528
|
+
|
|
529
|
+
```typescript
|
|
530
|
+
const { data: updated } = await api.webhooksControllerUpdateWebhook('webhook-id', {
|
|
531
|
+
url: 'https://your-server.com/webhooks/new-endpoint',
|
|
532
|
+
});
|
|
533
|
+
```
|
|
534
|
+
|
|
535
|
+
#### Delete a Webhook
|
|
536
|
+
|
|
537
|
+
```typescript
|
|
538
|
+
await api.webhooksControllerDeleteWebhook('webhook-id');
|
|
539
|
+
```
|
|
540
|
+
|
|
541
|
+
---
|
|
542
|
+
|
|
543
|
+
### Health
|
|
544
|
+
|
|
545
|
+
Check the system health, including Redis, database, and GPU status.
|
|
546
|
+
|
|
547
|
+
```typescript
|
|
548
|
+
import { HealthApi, Configuration } from '@nestbox-ai/doc-processing-api';
|
|
549
|
+
|
|
550
|
+
const api = new HealthApi(new Configuration({ basePath: '...' }));
|
|
551
|
+
|
|
552
|
+
const { data: health } = await api.healthControllerGetHealth();
|
|
553
|
+
// health: HealthResponseDto { status, timestamp, checks }
|
|
554
|
+
|
|
555
|
+
console.log('Overall:', health.status); // 'ok' | 'degraded' | 'down'
|
|
556
|
+
console.log('Redis:', health.checks.redis.status);
|
|
557
|
+
console.log('DB:', health.checks.db.status);
|
|
558
|
+
console.log('GPU:', health.checks.gpu.status, '— devices:', health.checks.gpu.deviceCount);
|
|
559
|
+
```
|
|
560
|
+
|
|
561
|
+
---
|
|
562
|
+
|
|
563
|
+
## Pagination
|
|
564
|
+
|
|
565
|
+
All list endpoints return a paginated response with the shape:
|
|
566
|
+
|
|
567
|
+
```typescript
|
|
568
|
+
interface PaginatedResponse<T> {
|
|
569
|
+
data: T[];
|
|
570
|
+
pagination: {
|
|
571
|
+
page: number; // current page (1-based)
|
|
572
|
+
limit: number; // page size
|
|
573
|
+
total: number; // total items across all pages
|
|
574
|
+
};
|
|
575
|
+
}
|
|
576
|
+
```
|
|
577
|
+
|
|
578
|
+
Example — iterate through all documents:
|
|
579
|
+
|
|
580
|
+
```typescript
|
|
581
|
+
let page = 1;
|
|
582
|
+
const limit = 50;
|
|
583
|
+
let allDocuments: DocumentDto[] = [];
|
|
584
|
+
|
|
585
|
+
while (true) {
|
|
586
|
+
const { data: result } = await documents.documentsControllerListDocuments(page, limit);
|
|
587
|
+
allDocuments.push(...result.data);
|
|
588
|
+
if (allDocuments.length >= result.pagination.total) break;
|
|
589
|
+
page++;
|
|
590
|
+
}
|
|
591
|
+
```
|
|
592
|
+
|
|
593
|
+
---
|
|
594
|
+
|
|
595
|
+
## Error Handling
|
|
596
|
+
|
|
597
|
+
API errors are returned as `AxiosError` responses. The response body typically follows the `ErrorDto` shape:
|
|
598
|
+
|
|
599
|
+
```typescript
|
|
600
|
+
import { AxiosError } from 'axios';
|
|
601
|
+
|
|
602
|
+
try {
|
|
603
|
+
await documents.documentsControllerGetDocument('nonexistent-id');
|
|
604
|
+
} catch (err) {
|
|
605
|
+
if (err instanceof AxiosError && err.response) {
|
|
606
|
+
const error = err.response.data as ErrorDto;
|
|
607
|
+
console.error(`[${err.response.status}] ${error.error}: ${error.message}`);
|
|
608
|
+
// error.requestId — use for support/tracking
|
|
609
|
+
// error.details — additional context
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
```
|
|
613
|
+
|
|
614
|
+
Validation errors (HTTP 422) include granular issue details:
|
|
615
|
+
|
|
616
|
+
```typescript
|
|
617
|
+
// ValidationErrorDto
|
|
618
|
+
{
|
|
619
|
+
error: 'validation_error',
|
|
620
|
+
message: 'YAML validation failed',
|
|
621
|
+
issues: [
|
|
622
|
+
{ path: '/queries/0/question', message: 'Required field missing', severity: 'error' },
|
|
623
|
+
{ path: '/options/model', message: 'Unknown model name', severity: 'warning' },
|
|
624
|
+
],
|
|
625
|
+
requestId: '...'
|
|
626
|
+
}
|
|
627
|
+
```
|
|
628
|
+
|
|
629
|
+
---
|
|
630
|
+
|
|
631
|
+
## Models Reference
|
|
632
|
+
|
|
633
|
+
| Model | Description |
|
|
634
|
+
|-------|-------------|
|
|
635
|
+
| `ProfileDto` | Processing profile/config with name, description, YAML content, and tags |
|
|
636
|
+
| `DocumentDto` | Uploaded document with status, file metadata, processing metrics, and tags |
|
|
637
|
+
| `DocumentCreateResponseDto` | Response from document creation — contains the `DocumentDto` and initial `JobDto` |
|
|
638
|
+
| `JobDto` | Full job details including type, state, progress, stage, and links |
|
|
639
|
+
| `JobStatusDto` | Lightweight job status for polling (state, progress, stage, message) |
|
|
640
|
+
| `JobLinksDto` | Hypermedia links on a job (status URL, resource URL) |
|
|
641
|
+
| `EvalDto` | Evaluation result with status, summary metrics, and detailed report |
|
|
642
|
+
| `EvalCreateResponseDto` | Response from eval creation — contains `EvalDto` and `JobDto` |
|
|
643
|
+
| `BatchQueryDto` | Batch query with status and optional stored results |
|
|
644
|
+
| `QueryCreateResponseDto` | Response from query creation — contains `BatchQueryDto` and `JobDto` |
|
|
645
|
+
| `SourceItemDto` | Individual source chunk with text, page number, and metadata |
|
|
646
|
+
| `DocumentSourcesResponseDto` | Wrapper around an array of `SourceItemDto` |
|
|
647
|
+
| `WebhookDto` | Registered webhook with URL and timestamps |
|
|
648
|
+
| `CreateWebhookInputDto` | Input for creating a webhook (`{ url: string }`) |
|
|
649
|
+
| `UpdateWebhookBodyInputDto` | Input for updating a webhook (`{ url: string }`) |
|
|
650
|
+
| `HealthResponseDto` | System health with overall status and per-component checks |
|
|
651
|
+
| `HealthChecksDto` | Individual checks for Redis, DB, and GPU |
|
|
652
|
+
| `HealthCheckItemDto` | Single health check with status, latency, and message |
|
|
653
|
+
| `GpuHealthCheckDto` | GPU-specific health with device count and per-device info |
|
|
654
|
+
| `GpuDeviceDto` | Individual GPU device (name, memory, utilization) |
|
|
655
|
+
| `PaginationDto` | Pagination metadata (`page`, `limit`, `total`) |
|
|
656
|
+
| `ErrorDto` | Standard error response with error type, message, and request ID |
|
|
657
|
+
| `ValidationResultDto` | YAML validation result (`valid`, `warnings`, `normalized`) |
|
|
658
|
+
| `ValidationErrorDto` | Validation failure with detailed issues |
|
|
659
|
+
| `ValidationIssueDto` | Single validation issue with JSON-pointer path, message, and severity |
|
|
660
|
+
| `PaginatedDocumentsDto` | Paginated list of `DocumentDto` |
|
|
661
|
+
| `PaginatedEvalsDto` | Paginated list of `EvalDto` |
|
|
662
|
+
| `PaginatedJobsDto` | Paginated list of `JobDto` |
|
|
663
|
+
| `PaginatedProfilesDto` | Paginated list of `ProfileDto` |
|
|
664
|
+
| `PaginatedQueriesDto` | Paginated list of `BatchQueryDto` |
|
|
665
|
+
| `PaginatedWebhooksDto` | Paginated list of `WebhookDto` |
|