@anyformat/sdk 1.11.0 → 1.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -0
- package/dist/index.cjs +134 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +464 -3
- package/dist/index.d.ts +464 -3
- package/dist/index.js +134 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// package.json
|
|
2
2
|
var package_default = {
|
|
3
3
|
name: "@anyformat/sdk",
|
|
4
|
-
version: "1.
|
|
4
|
+
version: "1.13.0",
|
|
5
5
|
description: "TypeScript SDK for the AnyFormat API",
|
|
6
6
|
license: "MIT",
|
|
7
7
|
author: "Anyformat <info@anyformat.ai>",
|
|
@@ -1127,6 +1127,11 @@ var v3UpdateWorkflow = (options) => (options.client ?? client).patch({
|
|
|
1127
1127
|
...options.headers
|
|
1128
1128
|
}
|
|
1129
1129
|
});
|
|
1130
|
+
var v3ListDatasetTags = (options) => (options.client ?? client).get({
|
|
1131
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1132
|
+
url: "/v3/workflows/{workflow_id}/dataset/tags/",
|
|
1133
|
+
...options
|
|
1134
|
+
});
|
|
1130
1135
|
var v3UploadToDataset = (options) => (options.client ?? client).post({
|
|
1131
1136
|
...formDataBodySerializer,
|
|
1132
1137
|
security: [{ scheme: "bearer", type: "http" }],
|
|
@@ -1142,6 +1147,35 @@ var v3ListWorkflowDocumentPackets = (options) => (options.client ?? client).get(
|
|
|
1142
1147
|
url: "/v3/workflows/{workflow_id}/document-packets/",
|
|
1143
1148
|
...options
|
|
1144
1149
|
});
|
|
1150
|
+
var v3ListEvals = (options) => (options.client ?? client).get({
|
|
1151
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1152
|
+
url: "/v3/workflows/{workflow_id}/evals/",
|
|
1153
|
+
...options
|
|
1154
|
+
});
|
|
1155
|
+
var v3LaunchEval = (options) => (options.client ?? client).post({
|
|
1156
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1157
|
+
url: "/v3/workflows/{workflow_id}/evals/",
|
|
1158
|
+
...options,
|
|
1159
|
+
headers: {
|
|
1160
|
+
"Content-Type": "application/json",
|
|
1161
|
+
...options.headers
|
|
1162
|
+
}
|
|
1163
|
+
});
|
|
1164
|
+
var v3GetEval = (options) => (options.client ?? client).get({
|
|
1165
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1166
|
+
url: "/v3/workflows/{workflow_id}/evals/{eval_id}/",
|
|
1167
|
+
...options
|
|
1168
|
+
});
|
|
1169
|
+
var v3GetEvalAccuracy = (options) => (options.client ?? client).get({
|
|
1170
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1171
|
+
url: "/v3/workflows/{workflow_id}/evals/{eval_id}/accuracy/",
|
|
1172
|
+
...options
|
|
1173
|
+
});
|
|
1174
|
+
var v3GetEvalDocumentPacketFields = (options) => (options.client ?? client).get({
|
|
1175
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1176
|
+
url: "/v3/workflows/{workflow_id}/evals/{eval_id}/document-packets/{document_packet_id}/fields/",
|
|
1177
|
+
...options
|
|
1178
|
+
});
|
|
1145
1179
|
var v3ListWorkflowRuns = (options) => (options.client ?? client).get({
|
|
1146
1180
|
security: [{ scheme: "bearer", type: "http" }],
|
|
1147
1181
|
url: "/v3/workflows/{workflow_id}/runs/",
|
|
@@ -1176,6 +1210,11 @@ var v3UploadAndRunWorkflow = (options) => (options.client ?? client).post({
|
|
|
1176
1210
|
...options.headers
|
|
1177
1211
|
}
|
|
1178
1212
|
});
|
|
1213
|
+
var v3ListWorkflowVersions = (options) => (options.client ?? client).get({
|
|
1214
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1215
|
+
url: "/v3/workflows/{workflow_id}/versions/",
|
|
1216
|
+
...options
|
|
1217
|
+
});
|
|
1179
1218
|
|
|
1180
1219
|
// src/run.ts
|
|
1181
1220
|
function isTransientStatus(status) {
|
|
@@ -1614,9 +1653,16 @@ var Anyformat = class {
|
|
|
1614
1653
|
nextCursor: res.data.next_cursor ?? null
|
|
1615
1654
|
};
|
|
1616
1655
|
}
|
|
1617
|
-
/**
|
|
1618
|
-
|
|
1619
|
-
|
|
1656
|
+
/**
|
|
1657
|
+
* Retrieve a workflow with its complete typed graph inline (round-trippable into `updateWorkflow`).
|
|
1658
|
+
* Pass a `version_id` as `version` to read that version instead of the current one.
|
|
1659
|
+
*/
|
|
1660
|
+
async getWorkflow(workflowId, opts = {}) {
|
|
1661
|
+
const res = await v3GetWorkflow({
|
|
1662
|
+
client: this._client,
|
|
1663
|
+
path: { workflow_id: workflowId },
|
|
1664
|
+
...opts.version ? { query: { version: opts.version } } : {}
|
|
1665
|
+
});
|
|
1620
1666
|
if (res.error) throw toApiError(res.response?.status ?? 500, res.error, res.response?.headers);
|
|
1621
1667
|
return res.data;
|
|
1622
1668
|
}
|
|
@@ -1740,6 +1786,26 @@ var Anyformat = class {
|
|
|
1740
1786
|
cursor = page.nextCursor;
|
|
1741
1787
|
}
|
|
1742
1788
|
}
|
|
1789
|
+
/** A workflow's versions, newest first; item 0 of the first page is the current version. */
|
|
1790
|
+
async listWorkflowVersions(workflowId, opts = {}) {
|
|
1791
|
+
const res = await v3ListWorkflowVersions({
|
|
1792
|
+
client: this._client,
|
|
1793
|
+
path: { workflow_id: workflowId },
|
|
1794
|
+
query: { limit: opts.limit, cursor: opts.cursor }
|
|
1795
|
+
});
|
|
1796
|
+
if (res.error) throw toApiError(res.response?.status ?? 500, res.error, res.response?.headers);
|
|
1797
|
+
return { items: res.data.items, nextCursor: res.data.next_cursor ?? null };
|
|
1798
|
+
}
|
|
1799
|
+
/** Every version of a workflow, newest first, following `nextCursor` across pages. Lazy. */
|
|
1800
|
+
async *iterWorkflowVersions(workflowId, opts = {}) {
|
|
1801
|
+
let cursor;
|
|
1802
|
+
for (; ; ) {
|
|
1803
|
+
const page = await this.listWorkflowVersions(workflowId, { limit: opts.limit, cursor });
|
|
1804
|
+
yield* page.items;
|
|
1805
|
+
if (page.nextCursor === null) return;
|
|
1806
|
+
cursor = page.nextCursor;
|
|
1807
|
+
}
|
|
1808
|
+
}
|
|
1743
1809
|
/** Retrieve one run: lifecycle status plus results inline once `processed`. */
|
|
1744
1810
|
async getRun(runId) {
|
|
1745
1811
|
const res = await v3GetRun({ client: this._client, path: { run_id: runId } });
|
|
@@ -1786,6 +1852,70 @@ var Anyformat = class {
|
|
|
1786
1852
|
if (run.status === "cancelled") throw new ExtractionCancelledError(runId);
|
|
1787
1853
|
return null;
|
|
1788
1854
|
}
|
|
1855
|
+
/** A workflow's dataset tags, ordered by name; a tag's `id` is what `datasetTagIds` takes. */
|
|
1856
|
+
async listDatasetTags(workflowId) {
|
|
1857
|
+
const res = await v3ListDatasetTags({ client: this._client, path: { workflow_id: workflowId } });
|
|
1858
|
+
if (res.error) throw toApiError(res.response?.status ?? 500, res.error, res.response?.headers);
|
|
1859
|
+
return res.data.items;
|
|
1860
|
+
}
|
|
1861
|
+
/**
|
|
1862
|
+
* Launch an eval: extract every dataset document on a version and grade it
|
|
1863
|
+
* against ground truth. Billed per document. Omit `versionId` for the current
|
|
1864
|
+
* version. `idempotencyKey` makes a retry return the original eval instead of
|
|
1865
|
+
* launching a second one. `datasetTagIds: []` without `untagged: true` throws.
|
|
1866
|
+
*/
|
|
1867
|
+
async launchEval(workflowId, opts = {}) {
|
|
1868
|
+
if (opts.datasetTagIds?.length === 0 && !opts.untagged) {
|
|
1869
|
+
throw new AnyformatError(
|
|
1870
|
+
"launchEval() datasetTagIds: [] selects no document; omit datasetTagIds to evaluate the whole dataset, or pass untagged: true"
|
|
1871
|
+
);
|
|
1872
|
+
}
|
|
1873
|
+
const res = await v3LaunchEval({
|
|
1874
|
+
client: this._client,
|
|
1875
|
+
path: { workflow_id: workflowId },
|
|
1876
|
+
body: {
|
|
1877
|
+
...opts.versionId ? { version_id: opts.versionId } : {},
|
|
1878
|
+
...opts.datasetTagIds ? { dataset_tag_ids: opts.datasetTagIds } : {},
|
|
1879
|
+
...opts.untagged ? { untagged: true } : {}
|
|
1880
|
+
},
|
|
1881
|
+
...opts.idempotencyKey ? { headers: { "Idempotency-Key": opts.idempotencyKey } } : {}
|
|
1882
|
+
});
|
|
1883
|
+
if (res.error) throw toApiError(res.response?.status ?? 500, res.error, res.response?.headers);
|
|
1884
|
+
return res.data;
|
|
1885
|
+
}
|
|
1886
|
+
/** One eval's headline; poll it until `status` leaves `in_progress`. */
|
|
1887
|
+
async getEval(workflowId, evalId) {
|
|
1888
|
+
const res = await v3GetEval({ client: this._client, path: { workflow_id: workflowId, eval_id: evalId } });
|
|
1889
|
+
if (res.error) throw toApiError(res.response?.status ?? 500, res.error, res.response?.headers);
|
|
1890
|
+
return res.data;
|
|
1891
|
+
}
|
|
1892
|
+
async listEvals(workflowId, opts = {}) {
|
|
1893
|
+
const res = await v3ListEvals({
|
|
1894
|
+
client: this._client,
|
|
1895
|
+
path: { workflow_id: workflowId },
|
|
1896
|
+
query: { limit: opts.limit, cursor: opts.cursor }
|
|
1897
|
+
});
|
|
1898
|
+
if (res.error) throw toApiError(res.response?.status ?? 500, res.error, res.response?.headers);
|
|
1899
|
+
return { items: res.data.items, nextCursor: res.data.next_cursor ?? null };
|
|
1900
|
+
}
|
|
1901
|
+
/** An eval's accuracy per field, per document and per dataset tag; partial while it runs. */
|
|
1902
|
+
async getEvalAccuracy(workflowId, evalId) {
|
|
1903
|
+
const res = await v3GetEvalAccuracy({
|
|
1904
|
+
client: this._client,
|
|
1905
|
+
path: { workflow_id: workflowId, eval_id: evalId }
|
|
1906
|
+
});
|
|
1907
|
+
if (res.error) throw toApiError(res.response?.status ?? 500, res.error, res.response?.headers);
|
|
1908
|
+
return res.data;
|
|
1909
|
+
}
|
|
1910
|
+
/** One eval document's extracted values beside its ground truth. The id is the dataset copy's. */
|
|
1911
|
+
async getEvalDocumentPacketFields(workflowId, evalId, documentPacketId) {
|
|
1912
|
+
const res = await v3GetEvalDocumentPacketFields({
|
|
1913
|
+
client: this._client,
|
|
1914
|
+
path: { workflow_id: workflowId, eval_id: evalId, document_packet_id: documentPacketId }
|
|
1915
|
+
});
|
|
1916
|
+
if (res.error) throw toApiError(res.response?.status ?? 500, res.error, res.response?.headers);
|
|
1917
|
+
return res.data;
|
|
1918
|
+
}
|
|
1789
1919
|
};
|
|
1790
1920
|
|
|
1791
1921
|
// src/schema.ts
|