@retab/node 0.0.45 → 0.0.48
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/api/consensus/client.js +1 -1
- package/dist/api/deployments/client.js +1 -1
- package/dist/api/documents/client.d.ts +2 -1
- package/dist/api/documents/client.d.ts.map +1 -1
- package/dist/api/documents/client.js +15 -6
- package/dist/api/models/client.js +1 -1
- package/dist/api/schemas/client.js +1 -1
- package/dist/client.d.ts +1 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +41 -32
- package/dist/generated_types.d.ts +16462 -22685
- package/dist/generated_types.d.ts.map +1 -1
- package/dist/generated_types.js +1094 -1046
- package/dist/types.d.ts +22 -25
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +2 -2
- package/package.json +1 -1
|
@@ -5,7 +5,7 @@ export default class APIConsensus extends CompositionClient {
|
|
|
5
5
|
super(client);
|
|
6
6
|
}
|
|
7
7
|
async reconcile(params) {
|
|
8
|
-
return
|
|
8
|
+
return this._fetchJson(ZReconciliationResponse, {
|
|
9
9
|
url: "/v1/consensus/reconcile",
|
|
10
10
|
method: "POST",
|
|
11
11
|
body: ZReconciliationRequest.parse(params),
|
|
@@ -10,7 +10,7 @@ export default class APIDeployments extends CompositionClient {
|
|
|
10
10
|
throw new Error("Either 'document' or 'documents' must be provided.");
|
|
11
11
|
}
|
|
12
12
|
let url = `/v1/deployments/extract/${project_id}/${iteration_id}`;
|
|
13
|
-
return
|
|
13
|
+
return this._fetchJson(ZSchema, {
|
|
14
14
|
url,
|
|
15
15
|
method: "POST",
|
|
16
16
|
body: {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { CompositionClient } from "@/client";
|
|
2
|
-
import { DocumentExtractRequest, RetabParsedChatCompletion, ParseRequest, ParseResult, DocumentCreateMessageRequest, DocumentMessage, DocumentCreateInputRequest } from "@/types";
|
|
2
|
+
import { DocumentExtractRequest, RetabParsedChatCompletion, ParseRequest, ParseResult, DocumentCreateMessageRequest, DocumentMessage, DocumentCreateInputRequest, RetabParsedChatCompletionChunk } from "@/types";
|
|
3
3
|
export default class APIDocuments extends CompositionClient {
|
|
4
4
|
constructor(client: CompositionClient);
|
|
5
5
|
extract(params: DocumentExtractRequest): Promise<RetabParsedChatCompletion>;
|
|
6
|
+
extractStream(params: DocumentExtractRequest): Promise<AsyncGenerator<RetabParsedChatCompletionChunk>>;
|
|
6
7
|
parse(params: ParseRequest): Promise<ParseResult>;
|
|
7
8
|
createMessages(params: DocumentCreateMessageRequest): Promise<DocumentMessage>;
|
|
8
9
|
createInputs(params: DocumentCreateInputRequest): Promise<DocumentMessage>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/api/documents/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,EAA2B,sBAAsB,EAAE,yBAAyB,EAA8B,YAAY,EAAE,WAAW,EAA+B,4BAA4B,EAAE,eAAe,EAAmD,0BAA0B,EAA+B,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/api/documents/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,EAA2B,sBAAsB,EAAE,yBAAyB,EAA8B,YAAY,EAAE,WAAW,EAA+B,4BAA4B,EAAE,eAAe,EAAmD,0BAA0B,EAA+B,8BAA8B,EAAmC,MAAM,SAAS,CAAC;AAGnZ,MAAM,CAAC,OAAO,OAAO,YAAa,SAAQ,iBAAiB;gBAC3C,MAAM,EAAE,iBAAiB;IAG/B,OAAO,CAAC,MAAM,EAAE,sBAAsB,GAAG,OAAO,CAAC,yBAAyB,CAAC;IAQ3E,aAAa,CAAC,MAAM,EAAE,sBAAsB,GAAG,OAAO,CAAC,cAAc,CAAC,8BAA8B,CAAC,CAAC;IAQtG,KAAK,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,WAAW,CAAC;IAOjD,cAAc,CAAC,MAAM,EAAE,4BAA4B,GAAG,OAAO,CAAC,eAAe,CAAC;IAO9E,YAAY,CAAC,MAAM,EAAE,0BAA0B,GAAG,OAAO,CAAC,eAAe,CAAC;CAOnF"}
|
|
@@ -1,32 +1,41 @@
|
|
|
1
1
|
import { CompositionClient } from "@/client";
|
|
2
|
-
import { ZDocumentExtractRequest, ZRetabParsedChatCompletion, ZParseResult, ZParseRequest, ZDocumentMessage, ZDocumentCreateMessageRequest, ZDocumentCreateInputRequest } from "@/types";
|
|
2
|
+
import { ZDocumentExtractRequest, ZRetabParsedChatCompletion, ZParseResult, ZParseRequest, ZDocumentMessage, ZDocumentCreateMessageRequest, ZDocumentCreateInputRequest, ZRetabParsedChatCompletionChunk } from "@/types";
|
|
3
3
|
export default class APIDocuments extends CompositionClient {
|
|
4
4
|
constructor(client) {
|
|
5
5
|
super(client);
|
|
6
6
|
}
|
|
7
7
|
async extract(params) {
|
|
8
|
-
|
|
8
|
+
let request = await ZDocumentExtractRequest.parseAsync(params);
|
|
9
|
+
return this._fetchJson(ZRetabParsedChatCompletion, {
|
|
9
10
|
url: "/v1/documents/extract",
|
|
10
11
|
method: "POST",
|
|
11
|
-
body:
|
|
12
|
+
body: request,
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
async extractStream(params) {
|
|
16
|
+
let request = await ZDocumentExtractRequest.parseAsync(params);
|
|
17
|
+
return this._fetchStream(ZRetabParsedChatCompletionChunk, {
|
|
18
|
+
url: "/v1/documents/extract",
|
|
19
|
+
method: "POST",
|
|
20
|
+
body: { ...request, stream: true },
|
|
12
21
|
});
|
|
13
22
|
}
|
|
14
23
|
async parse(params) {
|
|
15
|
-
return
|
|
24
|
+
return this._fetchJson(ZParseResult, {
|
|
16
25
|
url: "/v1/documents/parse",
|
|
17
26
|
method: "POST",
|
|
18
27
|
body: await ZParseRequest.parseAsync(params),
|
|
19
28
|
});
|
|
20
29
|
}
|
|
21
30
|
async createMessages(params) {
|
|
22
|
-
return
|
|
31
|
+
return this._fetchJson(ZDocumentMessage, {
|
|
23
32
|
url: "/v1/documents/create_messages",
|
|
24
33
|
method: "POST",
|
|
25
34
|
body: await ZDocumentCreateMessageRequest.parseAsync(params),
|
|
26
35
|
});
|
|
27
36
|
}
|
|
28
37
|
async createInputs(params) {
|
|
29
|
-
return
|
|
38
|
+
return this._fetchJson(ZDocumentMessage, {
|
|
30
39
|
url: "/v1/documents/create_inputs",
|
|
31
40
|
method: "POST",
|
|
32
41
|
body: await ZDocumentCreateInputRequest.parseAsync(params),
|
|
@@ -6,7 +6,7 @@ export default class APIModels extends CompositionClient {
|
|
|
6
6
|
super(client);
|
|
7
7
|
}
|
|
8
8
|
async list(params) {
|
|
9
|
-
return
|
|
9
|
+
return this._fetchJson(z.object({ data: z.array(ZModel) }), {
|
|
10
10
|
url: "/v1/models",
|
|
11
11
|
method: "GET",
|
|
12
12
|
params: params,
|
|
@@ -5,7 +5,7 @@ export default class APISchemas extends CompositionClient {
|
|
|
5
5
|
super(client);
|
|
6
6
|
}
|
|
7
7
|
async generate(params) {
|
|
8
|
-
return
|
|
8
|
+
return this._fetchJson(ZSchema, {
|
|
9
9
|
url: "/v1/schemas/generate",
|
|
10
10
|
method: "POST",
|
|
11
11
|
body: await ZGenerateSchemaRequest.parseAsync(params),
|
package/dist/client.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ type FetchParams = {
|
|
|
11
11
|
export declare class AbstractClient {
|
|
12
12
|
protected _fetch(_: FetchParams): Promise<Response>;
|
|
13
13
|
protected _fetchJson<ZodSchema extends z.ZodType<any, any, any>>(bodyType: ZodSchema, params: FetchParams): Promise<z.output<ZodSchema>>;
|
|
14
|
+
protected _fetchStream<ZodSchema extends z.ZodType<any, any, any>>(schema: ZodSchema, params: FetchParams): Promise<AsyncGenerator<z.output<ZodSchema>>>;
|
|
14
15
|
}
|
|
15
16
|
export declare class CompositionClient extends AbstractClient {
|
|
16
17
|
protected _client: AbstractClient;
|
|
@@ -22,7 +23,6 @@ export declare class APIError extends Error {
|
|
|
22
23
|
info: string;
|
|
23
24
|
constructor(status: number, info: string);
|
|
24
25
|
}
|
|
25
|
-
export declare function streamResponse<ZodSchema extends z.ZodType<any, any, any>>(response: Response, schema: ZodSchema): AsyncGenerator<z.output<ZodSchema>>;
|
|
26
26
|
export declare const DateOrISO: z.ZodUnion<[z.ZodDate, z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, Date, string>]>;
|
|
27
27
|
type AuthTypes = {
|
|
28
28
|
"bearer": string;
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAEzB,KAAK,WAAW,GAAG;IACjB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC9B,QAAQ,CAAC,EAAE,kBAAkB,GAAG,qBAAqB,CAAC;IACtD,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC3B,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;CACjB,CAAC;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAEzB,KAAK,WAAW,GAAG;IACjB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC7B,OAAO,CAAC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AG;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,GAAG,EAAE,CAAC;AAC5F,MAAM,MAAM,aAAa,GAAG;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,GAAG,SAAS,CAAC;AAEd,qBAAa,aAAc,SAAQ,cAAc;IAC/C,OAAO,EAAE,aAAa,CAAC;gBACX,OAAO,CAAC,EAAE,aAAa;IAK7B,MAAM,CAAC,MAAM,EAAE;QACnB,GAAG,EAAE,MAAM,CAAC;QACZ,MAAM,EAAE,MAAM,CAAC;QACf,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAC7B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAC9B,QAAQ,CAAC,EAAE,kBAAkB,GAAG,qBAAqB,CAAC;QACtD,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;KAC5B,GAAG,OAAO,CAAC,QAAQ,CAAC;CAmDtB"}
|
package/dist/client.js
CHANGED
|
@@ -1,35 +1,5 @@
|
|
|
1
1
|
import * as z from "zod";
|
|
2
|
-
|
|
3
|
-
_fetch(_) {
|
|
4
|
-
throw new Error("Method not implemented");
|
|
5
|
-
}
|
|
6
|
-
async _fetchJson(bodyType, params) {
|
|
7
|
-
let response = await this._fetch(params);
|
|
8
|
-
if (!response.ok) {
|
|
9
|
-
throw new APIError(response.status, await response.text());
|
|
10
|
-
}
|
|
11
|
-
if (response.headers.get("Content-Type") !== "application/json")
|
|
12
|
-
throw new APIError(response.status, "Response is not JSON");
|
|
13
|
-
return bodyType.parse(await response.json());
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
export class CompositionClient extends AbstractClient {
|
|
17
|
-
constructor(client) {
|
|
18
|
-
super();
|
|
19
|
-
this._client = client;
|
|
20
|
-
}
|
|
21
|
-
_fetch(params) {
|
|
22
|
-
return this._client["_fetch"](params);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
export class APIError extends Error {
|
|
26
|
-
constructor(status, info) {
|
|
27
|
-
super(`API Error ${status}: ${info}`);
|
|
28
|
-
this.status = status;
|
|
29
|
-
this.info = info;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
export async function* streamResponse(response, schema) {
|
|
2
|
+
async function* streamResponse(schema, response) {
|
|
33
3
|
let body = "";
|
|
34
4
|
let depth = 0;
|
|
35
5
|
let inString = false;
|
|
@@ -61,7 +31,7 @@ export async function* streamResponse(response, schema) {
|
|
|
61
31
|
else if (char === "}") {
|
|
62
32
|
depth--;
|
|
63
33
|
if (depth === 0) {
|
|
64
|
-
yield schema.
|
|
34
|
+
yield schema.parseAsync(JSON.parse(body.slice(0, prevBodyLength + i + 1)));
|
|
65
35
|
body = body.slice(prevBodyLength + i + 1);
|
|
66
36
|
prevBodyLength = -i - 1;
|
|
67
37
|
}
|
|
@@ -72,6 +42,45 @@ export async function* streamResponse(response, schema) {
|
|
|
72
42
|
break;
|
|
73
43
|
}
|
|
74
44
|
}
|
|
45
|
+
export class AbstractClient {
|
|
46
|
+
_fetch(_) {
|
|
47
|
+
throw new Error("Method not implemented");
|
|
48
|
+
}
|
|
49
|
+
async _fetchJson(bodyType, params) {
|
|
50
|
+
let response = await this._fetch(params);
|
|
51
|
+
if (!response.ok) {
|
|
52
|
+
throw new APIError(response.status, await response.text());
|
|
53
|
+
}
|
|
54
|
+
if (response.headers.get("Content-Type") !== "application/json")
|
|
55
|
+
throw new APIError(response.status, "Response is not JSON");
|
|
56
|
+
return bodyType.parseAsync(await response.json());
|
|
57
|
+
}
|
|
58
|
+
async _fetchStream(schema, params) {
|
|
59
|
+
let response = await this._fetch(params);
|
|
60
|
+
if (!response.ok) {
|
|
61
|
+
throw new APIError(response.status, await response.text());
|
|
62
|
+
}
|
|
63
|
+
if (response.headers.get("Content-Type") !== "application/stream+json")
|
|
64
|
+
throw new APIError(response.status, "Response is not stream JSON");
|
|
65
|
+
return streamResponse(schema, response);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
export class CompositionClient extends AbstractClient {
|
|
69
|
+
constructor(client) {
|
|
70
|
+
super();
|
|
71
|
+
this._client = client;
|
|
72
|
+
}
|
|
73
|
+
_fetch(params) {
|
|
74
|
+
return this._client["_fetch"](params);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
export class APIError extends Error {
|
|
78
|
+
constructor(status, info) {
|
|
79
|
+
super(`API Error ${status}: ${info}`);
|
|
80
|
+
this.status = status;
|
|
81
|
+
this.info = info;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
75
84
|
export const DateOrISO = z.union([
|
|
76
85
|
z.date(),
|
|
77
86
|
z.string().refine(val => !isNaN(Date.parse(val)), {
|