@abyss-project/tools 1.0.5 → 1.1.1
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/beam.api.d.ts +48 -0
- package/dist/api/beam.api.js +104 -0
- package/dist/api/beam.api.js.map +1 -0
- package/dist/api/extraction-plan-preset.api.d.ts +9 -0
- package/dist/api/extraction-plan-preset.api.js +23 -0
- package/dist/api/extraction-plan-preset.api.js.map +1 -0
- package/dist/api/extraction-plan-preset.api.test.d.ts +1 -0
- package/dist/api/extraction-plan-preset.api.test.js +41 -0
- package/dist/api/extraction-plan-preset.api.test.js.map +1 -0
- package/dist/api/extraction-settings.api.d.ts +4 -0
- package/dist/api/extraction-settings.api.js +22 -0
- package/dist/api/extraction-settings.api.js.map +1 -0
- package/dist/api/extraction.api.d.ts +74 -0
- package/dist/api/extraction.api.js +416 -0
- package/dist/api/extraction.api.js.map +1 -0
- package/dist/api/index.d.ts +4 -1
- package/dist/api/index.js +4 -1
- package/dist/api/index.js.map +1 -1
- package/dist/constants/beam.constants.d.ts +1 -0
- package/dist/constants/beam.constants.js +5 -0
- package/dist/constants/beam.constants.js.map +1 -0
- package/dist/constants/index.d.ts +1 -0
- package/dist/constants/index.js +1 -0
- package/dist/constants/index.js.map +1 -1
- package/dist/index.d.ts +107 -58
- package/dist/index.js +105 -58
- package/dist/index.js.map +1 -1
- package/dist/types/enum/beam.enum.d.ts +12 -0
- package/dist/types/enum/beam.enum.js +18 -0
- package/dist/types/enum/beam.enum.js.map +1 -0
- package/dist/types/enum/combine-strategy.enum.d.ts +5 -0
- package/dist/types/enum/combine-strategy.enum.js +10 -0
- package/dist/types/enum/combine-strategy.enum.js.map +1 -0
- package/dist/types/enum/content-share.enum.d.ts +3 -1
- package/dist/types/enum/content-share.enum.js +2 -0
- package/dist/types/enum/content-share.enum.js.map +1 -1
- package/dist/types/enum/document-type.enum.d.ts +9 -0
- package/dist/types/enum/document-type.enum.js +14 -0
- package/dist/types/enum/document-type.enum.js.map +1 -0
- package/dist/types/enum/extraction-feedback-issue-type.enum.d.ts +8 -0
- package/dist/types/enum/extraction-feedback-issue-type.enum.js +13 -0
- package/dist/types/enum/extraction-feedback-issue-type.enum.js.map +1 -0
- package/dist/types/enum/extraction-warning.enum.d.ts +7 -0
- package/dist/types/enum/extraction-warning.enum.js +12 -0
- package/dist/types/enum/extraction-warning.enum.js.map +1 -0
- package/dist/types/enum/index.d.ts +7 -0
- package/dist/types/enum/index.js +7 -0
- package/dist/types/enum/index.js.map +1 -1
- package/dist/types/enum/interpreter-kind.enum.d.ts +5 -0
- package/dist/types/enum/interpreter-kind.enum.js +10 -0
- package/dist/types/enum/interpreter-kind.enum.js.map +1 -0
- package/dist/types/enum/provider-kind.enum.d.ts +10 -0
- package/dist/types/enum/provider-kind.enum.js +16 -0
- package/dist/types/enum/provider-kind.enum.js.map +1 -0
- package/dist/types/interface/api/requests/beam.request.d.ts +122 -0
- package/dist/types/interface/api/{responses/pdf.response.js → requests/beam.request.js} +1 -1
- package/dist/types/interface/api/requests/beam.request.js.map +1 -0
- package/dist/types/interface/api/requests/{rcb.request.d.ts → extraction.request.d.ts} +81 -52
- package/dist/types/interface/api/requests/{pdf.public.request.js → extraction.request.js} +1 -1
- package/dist/types/interface/api/requests/extraction.request.js.map +1 -0
- package/dist/types/interface/api/requests/index.d.ts +2 -1
- package/dist/types/interface/api/requests/index.js +2 -1
- package/dist/types/interface/api/requests/index.js.map +1 -1
- package/dist/types/interface/api/responses/beam.response.d.ts +92 -0
- package/dist/types/interface/api/responses/{rcb.response.js → beam.response.js} +1 -1
- package/dist/types/interface/api/responses/beam.response.js.map +1 -0
- package/dist/types/interface/api/responses/extraction.response.d.ts +403 -0
- package/dist/types/interface/api/{requests/user-tag.request.js → responses/extraction.response.js} +1 -1
- package/dist/types/interface/api/responses/extraction.response.js.map +1 -0
- package/dist/types/interface/api/responses/index.d.ts +2 -1
- package/dist/types/interface/api/responses/index.js +2 -1
- package/dist/types/interface/api/responses/index.js.map +1 -1
- package/dist/types/interface/models/beam.dto.d.ts +58 -0
- package/dist/types/interface/{api/requests/pdf.request.js → models/beam.dto.js} +1 -1
- package/dist/types/interface/models/beam.dto.js.map +1 -0
- package/dist/types/interface/models/extraction-fetched-provenance.dto.test.d.ts +1 -0
- package/dist/types/interface/models/extraction-fetched-provenance.dto.test.js +159 -0
- package/dist/types/interface/models/extraction-fetched-provenance.dto.test.js.map +1 -0
- package/dist/types/interface/models/extraction-plan.dto.d.ts +163 -0
- package/dist/types/interface/models/extraction-plan.dto.js +11 -0
- package/dist/types/interface/models/extraction-plan.dto.js.map +1 -0
- package/dist/types/interface/models/extraction-plan.dto.test.d.ts +1 -0
- package/dist/types/interface/models/extraction-plan.dto.test.js +35 -0
- package/dist/types/interface/models/extraction-plan.dto.test.js.map +1 -0
- package/dist/types/interface/models/extraction-spatial-template.dto.d.ts +37 -0
- package/dist/types/interface/{api/requests/rcb.request.js → models/extraction-spatial-template.dto.js} +1 -1
- package/dist/types/interface/models/extraction-spatial-template.dto.js.map +1 -0
- package/dist/types/interface/models/extraction-spatial-template.dto.test.d.ts +1 -0
- package/dist/types/interface/models/extraction-spatial-template.dto.test.js +15 -0
- package/dist/types/interface/models/extraction-spatial-template.dto.test.js.map +1 -0
- package/dist/types/interface/models/{rcb.dto.d.ts → extraction.dto.d.ts} +64 -48
- package/dist/types/interface/models/extraction.dto.js +28 -0
- package/dist/types/interface/models/extraction.dto.js.map +1 -0
- package/dist/types/interface/models/index.d.ts +4 -1
- package/dist/types/interface/models/index.js +4 -1
- package/dist/types/interface/models/index.js.map +1 -1
- package/dist/types/interface/models/organization.dto.d.ts +2 -0
- package/dist/utils/{rcb-webhook.utils.d.ts → extraction-webhook.utils.d.ts} +2 -2
- package/dist/utils/{rcb-webhook.utils.js → extraction-webhook.utils.js} +4 -4
- package/dist/utils/extraction-webhook.utils.js.map +1 -0
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.js +1 -1
- package/dist/utils/index.js.map +1 -1
- package/package.json +1 -1
- package/src/api/beam.api.ts +300 -0
- package/src/api/extraction-plan-preset.api.test.ts +24 -0
- package/src/api/extraction-plan-preset.api.ts +51 -0
- package/src/api/extraction-settings.api.ts +59 -0
- package/src/api/extraction.api.ts +899 -0
- package/src/api/index.ts +56 -51
- package/src/api/tests/beam.api.spec.ts +42 -0
- package/src/constants/beam.constants.ts +4 -0
- package/src/constants/index.ts +6 -5
- package/src/index.ts +840 -747
- package/src/types/enum/beam.enum.ts +24 -0
- package/src/types/enum/combine-strategy.enum.ts +7 -0
- package/src/types/enum/content-share.enum.ts +38 -36
- package/src/types/enum/document-type.enum.ts +10 -0
- package/src/types/enum/extraction-feedback-issue-type.enum.ts +10 -0
- package/src/types/enum/extraction-warning.enum.ts +21 -0
- package/src/types/enum/index.ts +13 -6
- package/src/types/enum/interpreter-kind.enum.ts +7 -0
- package/src/types/enum/provider-kind.enum.ts +13 -0
- package/src/types/interface/api/requests/beam.request.ts +152 -0
- package/src/types/interface/api/requests/extraction.request.ts +366 -0
- package/src/types/interface/api/requests/index.ts +29 -28
- package/src/types/interface/api/responses/beam.response.ts +122 -0
- package/src/types/interface/api/responses/extraction.response.ts +454 -0
- package/src/types/interface/api/responses/index.ts +33 -32
- package/src/types/interface/models/beam.dto.ts +67 -0
- package/src/types/interface/models/extraction-fetched-provenance.dto.test.ts +193 -0
- package/src/types/interface/models/extraction-plan.dto.test.ts +47 -0
- package/src/types/interface/models/extraction-plan.dto.ts +241 -0
- package/src/types/interface/models/extraction-spatial-template.dto.test.ts +27 -0
- package/src/types/interface/models/extraction-spatial-template.dto.ts +48 -0
- package/src/types/interface/models/{rcb.dto.ts → extraction.dto.ts} +317 -267
- package/src/types/interface/models/index.ts +34 -31
- package/src/types/interface/models/organization.dto.ts +21 -12
- package/src/types/tests/beam-management-types.spec.ts +38 -0
- package/src/types/tests/beam-share-enums.spec.ts +11 -0
- package/src/types/tests/beam.dto.spec.ts +61 -0
- package/src/types/tests/beam.request-response.spec.ts +43 -0
- package/src/utils/{rcb-webhook.utils.ts → extraction-webhook.utils.ts} +30 -30
- package/src/utils/index.ts +6 -6
- package/tsconfig.json +36 -35
- package/dist/api/atlas-page-content.api.d.ts +0 -0
- package/dist/api/atlas-page-content.api.js +0 -2
- package/dist/api/atlas-page-content.api.js.map +0 -1
- package/dist/api/pdf.api.d.ts +0 -15
- package/dist/api/pdf.api.js +0 -61
- package/dist/api/pdf.api.js.map +0 -1
- package/dist/api/pdf.public.api.d.ts +0 -8
- package/dist/api/pdf.public.api.js +0 -33
- package/dist/api/pdf.public.api.js.map +0 -1
- package/dist/api/rcb.api.d.ts +0 -72
- package/dist/api/rcb.api.js +0 -400
- package/dist/api/rcb.api.js.map +0 -1
- package/dist/api/user-tag.api.d.ts +0 -9
- package/dist/api/user-tag.api.js +0 -37
- package/dist/api/user-tag.api.js.map +0 -1
- package/dist/constants/user-tag.constants.d.ts +0 -3
- package/dist/constants/user-tag.constants.js +0 -7
- package/dist/constants/user-tag.constants.js.map +0 -1
- package/dist/types/enum/pdf-session.enum.d.ts +0 -10
- package/dist/types/enum/pdf-session.enum.js +0 -16
- package/dist/types/enum/pdf-session.enum.js.map +0 -1
- package/dist/types/interface/api/requests/pdf.public.request.d.ts +0 -19
- package/dist/types/interface/api/requests/pdf.public.request.js.map +0 -1
- package/dist/types/interface/api/requests/pdf.request.d.ts +0 -50
- package/dist/types/interface/api/requests/pdf.request.js.map +0 -1
- package/dist/types/interface/api/requests/rcb.request.js.map +0 -1
- package/dist/types/interface/api/requests/user-tag.request.d.ts +0 -44
- package/dist/types/interface/api/requests/user-tag.request.js.map +0 -1
- package/dist/types/interface/api/responses/pdf.public.response.d.ts +0 -33
- package/dist/types/interface/api/responses/pdf.public.response.js +0 -3
- package/dist/types/interface/api/responses/pdf.public.response.js.map +0 -1
- package/dist/types/interface/api/responses/pdf.response.d.ts +0 -35
- package/dist/types/interface/api/responses/pdf.response.js.map +0 -1
- package/dist/types/interface/api/responses/rcb.response.d.ts +0 -376
- package/dist/types/interface/api/responses/rcb.response.js.map +0 -1
- package/dist/types/interface/api/responses/user-tag.response.d.ts +0 -32
- package/dist/types/interface/api/responses/user-tag.response.js +0 -3
- package/dist/types/interface/api/responses/user-tag.response.js.map +0 -1
- package/dist/types/interface/models/pdf-session.dto.d.ts +0 -28
- package/dist/types/interface/models/pdf-session.dto.js +0 -3
- package/dist/types/interface/models/pdf-session.dto.js.map +0 -1
- package/dist/types/interface/models/rcb.dto.js +0 -26
- package/dist/types/interface/models/rcb.dto.js.map +0 -1
- package/dist/types/interface/models/user-tag.dto.d.ts +0 -22
- package/dist/types/interface/models/user-tag.dto.js +0 -3
- package/dist/types/interface/models/user-tag.dto.js.map +0 -1
- package/dist/utils/rcb-webhook.utils.js.map +0 -1
- package/src/api/rcb.api.ts +0 -829
- package/src/types/interface/api/requests/rcb.request.ts +0 -267
- package/src/types/interface/api/responses/rcb.response.ts +0 -399
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
// Type-level compile test — no jest runner in this package.
|
|
2
|
+
// Verifies the FETCHED-extraction DTO (the GET extraction response / IExtraction)
|
|
3
|
+
// surfaces the additive V2-P1 provenance + manifest fields type-safely, while
|
|
4
|
+
// staying backward-compatible for old readers of value+confidence.
|
|
5
|
+
// Run: npx tsc --noEmit (from packages/abyss_tools_core).
|
|
6
|
+
|
|
7
|
+
import { ProviderKind, InterpreterKind, CombineStrategy } from '../../enum';
|
|
8
|
+
import type { IExtraction } from './extraction.dto';
|
|
9
|
+
import type { IFieldValue, IExecutionManifest, IGlobalConfidence } from './extraction-plan.dto';
|
|
10
|
+
import type { IGetExtractionData } from '../api/responses/extraction.response';
|
|
11
|
+
|
|
12
|
+
// A fully-populated plan-path field value (the IFieldValue superset).
|
|
13
|
+
const fv: IFieldValue = {
|
|
14
|
+
value: 120,
|
|
15
|
+
confidence: 0.95,
|
|
16
|
+
chosen: {
|
|
17
|
+
provider: ProviderKind.TEXT,
|
|
18
|
+
interpreter: InterpreterKind.ALGORITHMIC,
|
|
19
|
+
providerId: 'pdf-auto',
|
|
20
|
+
interpreterId: 'algo-v1',
|
|
21
|
+
},
|
|
22
|
+
sources: [
|
|
23
|
+
{
|
|
24
|
+
mode: {
|
|
25
|
+
provider: ProviderKind.TEXT,
|
|
26
|
+
interpreter: InterpreterKind.ALGORITHMIC,
|
|
27
|
+
providerId: 'pdf-auto',
|
|
28
|
+
interpreterId: 'algo-v1',
|
|
29
|
+
},
|
|
30
|
+
value: 120,
|
|
31
|
+
confidence: 0.95,
|
|
32
|
+
signals: [],
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
agreement: { agreed: false, distinctValues: 1 },
|
|
36
|
+
signals: [],
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
// A field value carrying NON-EMPTY signals — exercises every variant of the
|
|
40
|
+
// ISignal discriminated union so a future drift between the SDK union and the
|
|
41
|
+
// backend `Signal` shape (e.g. re-adding the invented `score` field, or
|
|
42
|
+
// dropping `check`/`passed`/`agreed`/`modes`) fails compilation here.
|
|
43
|
+
const fvWithSignals: IFieldValue = {
|
|
44
|
+
value: 'FR7630001007941234567890185',
|
|
45
|
+
confidence: 0.98,
|
|
46
|
+
chosen: {
|
|
47
|
+
provider: ProviderKind.TEXT,
|
|
48
|
+
interpreter: InterpreterKind.ALGORITHMIC,
|
|
49
|
+
providerId: 'pdf-auto',
|
|
50
|
+
interpreterId: 'algo-v1',
|
|
51
|
+
},
|
|
52
|
+
sources: [
|
|
53
|
+
{
|
|
54
|
+
mode: {
|
|
55
|
+
provider: ProviderKind.TEXT,
|
|
56
|
+
interpreter: InterpreterKind.ALGORITHMIC,
|
|
57
|
+
providerId: 'pdf-auto',
|
|
58
|
+
interpreterId: 'algo-v1',
|
|
59
|
+
},
|
|
60
|
+
value: 'FR7630001007941234567890185',
|
|
61
|
+
confidence: 0.98,
|
|
62
|
+
signals: [
|
|
63
|
+
{ kind: 'format', check: 'iban_mod97', passed: true, weight: 0.2 },
|
|
64
|
+
{ kind: 'anchor', detail: "matched near 'IBAN' label", weight: 0.1 },
|
|
65
|
+
],
|
|
66
|
+
},
|
|
67
|
+
],
|
|
68
|
+
agreement: { agreed: true, distinctValues: 1 },
|
|
69
|
+
signals: [
|
|
70
|
+
{ kind: 'format', check: 'iban_mod97', passed: true, weight: 0.2 },
|
|
71
|
+
{ kind: 'coherence', check: 'balance_reconciliation', passed: true, weight: 0.3 },
|
|
72
|
+
{ kind: 'agreement', agreed: true, modes: 2, weight: 0.1 },
|
|
73
|
+
],
|
|
74
|
+
};
|
|
75
|
+
void fvWithSignals;
|
|
76
|
+
|
|
77
|
+
// A CONSUMER narrows the ISignal union by `kind` and reads the discriminant
|
|
78
|
+
// fields that actually exist on the wire — type-safe, no cast.
|
|
79
|
+
for (const sig of fvWithSignals.signals) {
|
|
80
|
+
if (sig.kind === 'format' || sig.kind === 'coherence') {
|
|
81
|
+
const _check: string = sig.check;
|
|
82
|
+
const _passed: boolean = sig.passed;
|
|
83
|
+
void _check; void _passed;
|
|
84
|
+
} else if (sig.kind === 'anchor') {
|
|
85
|
+
const _detail: string = sig.detail;
|
|
86
|
+
void _detail;
|
|
87
|
+
} else {
|
|
88
|
+
const _agreed: boolean = sig.agreed;
|
|
89
|
+
const _modes: number = sig.modes;
|
|
90
|
+
void _agreed; void _modes;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Mirrors the persisted backend ExecutionManifest shape (resolvedPlan + combine
|
|
95
|
+
// + passes + createdAt) — exactly what GET /extractions/:id surfaces via toJSON().
|
|
96
|
+
const manifest: IExecutionManifest = {
|
|
97
|
+
resolvedPlan: {
|
|
98
|
+
stages: [
|
|
99
|
+
{ runParallel: false, passes: [{ providerId: 'pdf-auto', interpreterId: 'algo-v1' }] },
|
|
100
|
+
],
|
|
101
|
+
combine: CombineStrategy.MAX_CONFIDENCE,
|
|
102
|
+
},
|
|
103
|
+
combine: CombineStrategy.MAX_CONFIDENCE,
|
|
104
|
+
passes: [
|
|
105
|
+
{ providerId: 'pdf-auto', providerVersion: '1.0.0', interpreterId: 'algo-v1', interpreterVersion: '1.0.0' },
|
|
106
|
+
],
|
|
107
|
+
createdAt: '2026-06-28T00:00:00.000Z',
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
// Mirrors the persisted backend GlobalConfidence shape (stats + method +
|
|
111
|
+
// aggregation + perPass + lowestFields).
|
|
112
|
+
const globalConfidence: IGlobalConfidence = {
|
|
113
|
+
stats: {
|
|
114
|
+
overall: 0.95,
|
|
115
|
+
mean: 0.95,
|
|
116
|
+
highest: 0.95,
|
|
117
|
+
lowest: 0.95,
|
|
118
|
+
median: 0.95,
|
|
119
|
+
belowThreshold: { threshold: 0.7, count: 0 },
|
|
120
|
+
fieldCount: 1,
|
|
121
|
+
},
|
|
122
|
+
method: CombineStrategy.MAX_CONFIDENCE,
|
|
123
|
+
aggregation: 'weighted-by-field-importance',
|
|
124
|
+
perPass: [
|
|
125
|
+
{
|
|
126
|
+
mode: {
|
|
127
|
+
provider: ProviderKind.TEXT,
|
|
128
|
+
interpreter: InterpreterKind.ALGORITHMIC,
|
|
129
|
+
providerId: 'pdf-auto',
|
|
130
|
+
interpreterId: 'algo-v1',
|
|
131
|
+
},
|
|
132
|
+
confidence: 0.95,
|
|
133
|
+
fieldsContributed: 1,
|
|
134
|
+
ocrPageCount: 0,
|
|
135
|
+
},
|
|
136
|
+
],
|
|
137
|
+
lowestFields: [{ fieldKey: 'totalTtc', confidence: 0.95 }],
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
// The fetched-extraction model carries provenance fieldsJson + manifest +
|
|
141
|
+
// globalConfidence + usedOcr/ocrPageCount type-safely.
|
|
142
|
+
const fetched: Partial<IExtraction> = {
|
|
143
|
+
fieldsJson: { totalTtc: fv },
|
|
144
|
+
executionManifest: manifest,
|
|
145
|
+
globalConfidence,
|
|
146
|
+
usedOcr: true,
|
|
147
|
+
ocrPageCount: 3,
|
|
148
|
+
};
|
|
149
|
+
void fetched;
|
|
150
|
+
|
|
151
|
+
// A CONSUMER reading the chosen impl id + sources off the fetched field value —
|
|
152
|
+
// no cast needed (this is the whole point of the surfacing fix).
|
|
153
|
+
const totalTtc = (fetched.fieldsJson ?? {}).totalTtc;
|
|
154
|
+
if (totalTtc) {
|
|
155
|
+
const _chosenId: string = totalTtc.chosen.interpreterId;
|
|
156
|
+
const _sourceCount: number = totalTtc.sources.length;
|
|
157
|
+
void _chosenId; void _sourceCount;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// Backward-compat: an old reader that only knows value+confidence still works.
|
|
161
|
+
const _legacyRead: { value: unknown; confidence: number } | undefined =
|
|
162
|
+
(fetched.fieldsJson ?? {}).totalTtc;
|
|
163
|
+
void _legacyRead;
|
|
164
|
+
|
|
165
|
+
// The GET extraction response data exposes the same superset under `fields`
|
|
166
|
+
// AND inherits manifest + globalConfidence from IExtraction.
|
|
167
|
+
const getData: Partial<IGetExtractionData> = {
|
|
168
|
+
fields: { totalTtc: fv },
|
|
169
|
+
executionManifest: manifest,
|
|
170
|
+
globalConfidence,
|
|
171
|
+
};
|
|
172
|
+
void getData;
|
|
173
|
+
|
|
174
|
+
// usedOcr/ocrPageCount remain readable as before.
|
|
175
|
+
const _usedOcr: boolean | undefined = fetched.usedOcr;
|
|
176
|
+
const _ocrPages: number | undefined = fetched.ocrPageCount;
|
|
177
|
+
void _usedOcr; void _ocrPages;
|
|
178
|
+
|
|
179
|
+
// A CONSUMER reads the manifest + globalConfidence fields that the backend
|
|
180
|
+
// actually persists/surfaces (createdAt — NOT resolvedAt — and the stats block),
|
|
181
|
+
// type-safely off the fetched extraction.
|
|
182
|
+
if (fetched.executionManifest) {
|
|
183
|
+
const _createdAt: string = fetched.executionManifest.createdAt;
|
|
184
|
+
const _passCount: number = fetched.executionManifest.passes.length;
|
|
185
|
+
void _createdAt; void _passCount;
|
|
186
|
+
}
|
|
187
|
+
if (fetched.globalConfidence) {
|
|
188
|
+
const _overall: number = fetched.globalConfidence.stats.overall;
|
|
189
|
+
const _agg: 'weighted-by-field-importance' = fetched.globalConfidence.aggregation;
|
|
190
|
+
void _overall; void _agg;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export {};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// Type-level compile test — no jest runner in this package.
|
|
2
|
+
// Each block verifies that the SDK types compile correctly.
|
|
3
|
+
// Run: npx tsc --noEmit (from packages/abyss_tools_core).
|
|
4
|
+
|
|
5
|
+
import { ProviderKind, InterpreterKind, CombineStrategy } from '../../enum';
|
|
6
|
+
import type { IExtractionPlan, IFieldValue, IExtractModesData, IPositionedToken } from './extraction-plan.dto';
|
|
7
|
+
|
|
8
|
+
// Verify enum string values match the api side.
|
|
9
|
+
const _pk: string = ProviderKind.TEXT; // 'text'
|
|
10
|
+
const _ik: string = InterpreterKind.TEMPLATE; // 'template'
|
|
11
|
+
const _cs: string = CombineStrategy.MAX_CONFIDENCE; // 'maxConfidence'
|
|
12
|
+
void _pk; void _ik; void _cs;
|
|
13
|
+
|
|
14
|
+
// Verify IFieldValue is a structural superset of {value,confidence}.
|
|
15
|
+
const fv: IFieldValue = {
|
|
16
|
+
value: 1,
|
|
17
|
+
confidence: 0.9,
|
|
18
|
+
chosen: {
|
|
19
|
+
provider: ProviderKind.TEXT,
|
|
20
|
+
interpreter: InterpreterKind.ALGORITHMIC,
|
|
21
|
+
providerId: 'pdf-text',
|
|
22
|
+
interpreterId: 'algo-v1',
|
|
23
|
+
},
|
|
24
|
+
sources: [],
|
|
25
|
+
signals: [],
|
|
26
|
+
};
|
|
27
|
+
// Must be assignable to the legacy shape without cast.
|
|
28
|
+
const _legacy: { value: unknown; confidence: number } = fv;
|
|
29
|
+
void _legacy;
|
|
30
|
+
|
|
31
|
+
// Verify IExtractModesData typing compiles.
|
|
32
|
+
const _modes: IExtractModesData = { providers: [], interpreters: [] };
|
|
33
|
+
void _modes;
|
|
34
|
+
|
|
35
|
+
// Verify IExtractionPlan typing compiles.
|
|
36
|
+
const _plan: IExtractionPlan = {
|
|
37
|
+
stages: [{ runParallel: false, passes: [{ providerId: 'pdf-text', interpreterId: 'algo-v1' }] }],
|
|
38
|
+
combine: CombineStrategy.MAX_CONFIDENCE,
|
|
39
|
+
};
|
|
40
|
+
void _plan;
|
|
41
|
+
|
|
42
|
+
// Verify IPositionedToken is { text, page, bbox{x,y,w,h}, conf? } (conf optional).
|
|
43
|
+
const _tok: IPositionedToken = { text: 'IBAN', page: 1, bbox: { x: 1, y: 2, w: 3, h: 4 }, conf: 95 };
|
|
44
|
+
const _tokNoConf: IPositionedToken = { text: 'x', page: 2, bbox: { x: 0, y: 0, w: 1, h: 1 } };
|
|
45
|
+
void _tok; void _tokNoConf;
|
|
46
|
+
|
|
47
|
+
export {};
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
// ──────────────────────────────────────────────
|
|
2
|
+
// Extraction Plan DTOs.
|
|
3
|
+
// Mirror server-side plan.types.ts shapes. Use SDK enums for kinds.
|
|
4
|
+
// IFieldValue is a structural superset of { value; confidence } so existing
|
|
5
|
+
// consumers do not break.
|
|
6
|
+
// ──────────────────────────────────────────────
|
|
7
|
+
|
|
8
|
+
import { ProviderKind, CostTier } from '../../enum/provider-kind.enum';
|
|
9
|
+
import { InterpreterKind } from '../../enum/interpreter-kind.enum';
|
|
10
|
+
import { CombineStrategy } from '../../enum/combine-strategy.enum';
|
|
11
|
+
|
|
12
|
+
// Re-export for consumers that import from this barrel.
|
|
13
|
+
export { ProviderKind, CostTier, InterpreterKind, CombineStrategy };
|
|
14
|
+
|
|
15
|
+
// ─── Plan building blocks ──────────────────────────────────────────────────
|
|
16
|
+
|
|
17
|
+
/** Reference to the provider+interpreter pair that produced a field value. */
|
|
18
|
+
export interface IModeRef {
|
|
19
|
+
provider: ProviderKind;
|
|
20
|
+
interpreter: InterpreterKind;
|
|
21
|
+
providerId: string;
|
|
22
|
+
interpreterId: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Fallback gate used between stages — the executor continues when not met. */
|
|
26
|
+
export interface IFallbackGate {
|
|
27
|
+
/** Minimum confidence required to skip the next stage. */
|
|
28
|
+
minConfidence: number;
|
|
29
|
+
/**
|
|
30
|
+
* 'global' = global score; 'requiredFields' = min over required fields.
|
|
31
|
+
* Mirrors the backend FallbackGate.scope shape.
|
|
32
|
+
*/
|
|
33
|
+
scope: 'global' | 'requiredFields';
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** A single provider+interpreter pass. */
|
|
37
|
+
export interface IPass {
|
|
38
|
+
providerId: string;
|
|
39
|
+
interpreterId: string;
|
|
40
|
+
/** If set, forces the interpreter to this document type (skips detect()). */
|
|
41
|
+
documentType?: string;
|
|
42
|
+
/** For template interpreters. */
|
|
43
|
+
templateId?: string;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** One stage — a group of passes run sequentially or in parallel. */
|
|
47
|
+
export interface IStage {
|
|
48
|
+
passes: IPass[];
|
|
49
|
+
runParallel: boolean;
|
|
50
|
+
/** When present, executor checks this gate after the stage; if not met continues to the next stage. */
|
|
51
|
+
fallback?: IFallbackGate;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Top-level execution plan handed to the executor. */
|
|
55
|
+
export interface IExtractionPlan {
|
|
56
|
+
stages: IStage[];
|
|
57
|
+
combine: CombineStrategy;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// ─── Confidence / provenance ───────────────────────────────────────────────
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* An evidence signal contributing to a field's confidence score.
|
|
64
|
+
*
|
|
65
|
+
* Discriminated union mirroring the backend `Signal` (plan/plan.types.ts) shape
|
|
66
|
+
* VERBATIM so a consumer reading `IFieldValue.signals[i]` sees exactly what is
|
|
67
|
+
* persisted/surfaced on the wire:
|
|
68
|
+
* - `format`/`coherence` carry `{ check, passed, weight }` (e.g. siret_luhn,
|
|
69
|
+
* iban_mod97, ht_vat_ttc, actif_passif, balance_reconciliation);
|
|
70
|
+
* - `anchor` carries `{ detail, weight }`;
|
|
71
|
+
* - `agreement` carries `{ agreed, modes, weight }` and explains the
|
|
72
|
+
* `IFieldValue.agreement` summary (`modes` = number of contributing sources).
|
|
73
|
+
*/
|
|
74
|
+
export type ISignal =
|
|
75
|
+
| { kind: 'format'; check: string; passed: boolean; weight: number }
|
|
76
|
+
| { kind: 'coherence'; check: string; passed: boolean; weight: number }
|
|
77
|
+
| { kind: 'anchor'; detail: string; weight: number }
|
|
78
|
+
| { kind: 'agreement'; agreed: boolean; modes: number; weight: number };
|
|
79
|
+
|
|
80
|
+
/** One source contribution to a combined field value. */
|
|
81
|
+
export interface IFieldSource {
|
|
82
|
+
mode: IModeRef;
|
|
83
|
+
value: unknown;
|
|
84
|
+
confidence: number;
|
|
85
|
+
signals: ISignal[];
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Combined field value with full provenance.
|
|
90
|
+
* value + confidence are at the SAME path as today's ExtractedField
|
|
91
|
+
* (structural superset — backward-compatible).
|
|
92
|
+
*/
|
|
93
|
+
export interface IFieldValue {
|
|
94
|
+
value: unknown;
|
|
95
|
+
confidence: number;
|
|
96
|
+
chosen: IModeRef;
|
|
97
|
+
sources: IFieldSource[];
|
|
98
|
+
agreement?: {
|
|
99
|
+
agreed: boolean;
|
|
100
|
+
distinctValues: number;
|
|
101
|
+
};
|
|
102
|
+
signals: ISignal[];
|
|
103
|
+
provenanceTruncated?: boolean;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** Per-field importance entry (mirrors field-importance.ts). */
|
|
107
|
+
export interface IFieldImportance {
|
|
108
|
+
fieldKey: string;
|
|
109
|
+
weight: number;
|
|
110
|
+
required: boolean;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Confidence statistics over an extraction's fields.
|
|
115
|
+
* Mirrors the backend ConfidenceStats shape (plan/plan.types.ts) exactly so a
|
|
116
|
+
* consumer reading globalConfidence.stats off a fetched extraction is type-safe.
|
|
117
|
+
*/
|
|
118
|
+
export interface IConfidenceStats {
|
|
119
|
+
overall: number;
|
|
120
|
+
mean: number;
|
|
121
|
+
highest: number;
|
|
122
|
+
lowest: number;
|
|
123
|
+
median: number;
|
|
124
|
+
belowThreshold: { threshold: number; count: number };
|
|
125
|
+
fieldCount: number;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Per-pass contribution in the global confidence summary.
|
|
130
|
+
* Mirrors the backend PassContribution shape (plan/plan.types.ts).
|
|
131
|
+
*/
|
|
132
|
+
export interface IPassContribution {
|
|
133
|
+
mode: IModeRef;
|
|
134
|
+
confidence: number;
|
|
135
|
+
fieldsContributed: number;
|
|
136
|
+
ocrPageCount: number;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Global confidence summary for an extraction run.
|
|
141
|
+
* Mirrors the backend GlobalConfidence shape (plan/plan.types.ts) — the JSON
|
|
142
|
+
* persisted in extractions.globalConfidence and surfaced by GET /extractions/:id.
|
|
143
|
+
*/
|
|
144
|
+
export interface IGlobalConfidence {
|
|
145
|
+
stats: IConfidenceStats;
|
|
146
|
+
method: CombineStrategy;
|
|
147
|
+
aggregation: 'weighted-by-field-importance';
|
|
148
|
+
perPass: IPassContribution[];
|
|
149
|
+
lowestFields: { fieldKey: string; confidence: number }[];
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// ─── Execution manifest ────────────────────────────────────────────────────
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* A pass entry in the execution manifest.
|
|
156
|
+
* Mirrors the backend ManifestPass shape (plan/plan.types.ts).
|
|
157
|
+
*/
|
|
158
|
+
export interface IManifestPass {
|
|
159
|
+
providerId: string;
|
|
160
|
+
providerVersion: string;
|
|
161
|
+
interpreterId: string;
|
|
162
|
+
interpreterVersion: string;
|
|
163
|
+
/** Pinned template version id, when the pass used a template interpreter. */
|
|
164
|
+
templateVersionId?: string;
|
|
165
|
+
/** OCR provider engine + versions, when the pass used the OCR provider. */
|
|
166
|
+
ocrEngine?: string;
|
|
167
|
+
ocrEngineVersion?: string;
|
|
168
|
+
ocrLangpackVersion?: string;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Frozen manifest of the exact recipe used for an extraction run.
|
|
173
|
+
* Mirrors the backend ExecutionManifest shape (plan/plan.types.ts) — the JSON
|
|
174
|
+
* persisted in extractions.executionManifest and surfaced by GET /extractions/:id.
|
|
175
|
+
*/
|
|
176
|
+
export interface IExecutionManifest {
|
|
177
|
+
resolvedPlan: IExtractionPlan;
|
|
178
|
+
combine: CombineStrategy;
|
|
179
|
+
passes: IManifestPass[];
|
|
180
|
+
createdAt: string;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// ─── Plan presets ──────────────────────────────────────────────────────────
|
|
184
|
+
|
|
185
|
+
/** A saved extraction plan preset (DB row + virtual system presets). */
|
|
186
|
+
export interface IExtractionPlanPreset {
|
|
187
|
+
id: string;
|
|
188
|
+
name: string;
|
|
189
|
+
scope:
|
|
190
|
+
| { kind: 'user'; userId: string }
|
|
191
|
+
| { kind: 'org'; organizationId: string };
|
|
192
|
+
plan: IExtractionPlan;
|
|
193
|
+
isDefault: boolean;
|
|
194
|
+
system: boolean;
|
|
195
|
+
createdAt: string;
|
|
196
|
+
updatedAt: string;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// ─── Modes (capabilities endpoint) ────────────────────────────────────────
|
|
200
|
+
|
|
201
|
+
/** Provider capability entry returned by GET /extract/modes. */
|
|
202
|
+
export interface IProviderMode {
|
|
203
|
+
id: string;
|
|
204
|
+
kind: ProviderKind;
|
|
205
|
+
label: string;
|
|
206
|
+
cost: CostTier;
|
|
207
|
+
version: string;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/** Interpreter capability entry returned by GET /extract/modes. */
|
|
211
|
+
export interface IInterpreterMode {
|
|
212
|
+
id: string;
|
|
213
|
+
kind: InterpreterKind;
|
|
214
|
+
label: string;
|
|
215
|
+
cost: CostTier;
|
|
216
|
+
version: string;
|
|
217
|
+
supports: string[];
|
|
218
|
+
accepts: ProviderKind[];
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/** Shape of the data block returned by GET /extract/modes. */
|
|
222
|
+
export interface IExtractModesData {
|
|
223
|
+
providers: IProviderMode[];
|
|
224
|
+
interpreters: IInterpreterMode[];
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// ─── Positioned tokens (OCR word-bbox channel, V2-P2) ──────────────────────
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* A single OCR word with its bounding box (mirrors backend PositionedToken).
|
|
231
|
+
* bbox is in image pixels at the OCR raster scale (origin top-left); a consumer
|
|
232
|
+
* normalizes to 0..1 of the page using the per-page pixel dimensions carried in
|
|
233
|
+
* the provider meta. `page` is 1-based. ADDITIVE — surfaced for V2-P3 spatial
|
|
234
|
+
* templates + auditable per-word confidence; existing consumers are unaffected.
|
|
235
|
+
*/
|
|
236
|
+
export interface IPositionedToken {
|
|
237
|
+
text: string;
|
|
238
|
+
page: number;
|
|
239
|
+
bbox: { x: number; y: number; w: number; h: number };
|
|
240
|
+
conf?: number;
|
|
241
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// Type-level compile test — no jest runner in this package.
|
|
2
|
+
// Each block verifies that the SDK spatial-template DTO types compile correctly.
|
|
3
|
+
// Run: npx tsc --noEmit (from packages/abyss_tools_core).
|
|
4
|
+
|
|
5
|
+
import type {
|
|
6
|
+
ISpatialZone, ISpatialTemplateConfig, IExtractionTemplateVersionDto, ISpatialZoneExtractor,
|
|
7
|
+
} from './extraction-spatial-template.dto';
|
|
8
|
+
import { DocumentType } from '../../enum/document-type.enum';
|
|
9
|
+
|
|
10
|
+
// A spatial zone + config type correctly (mirrors the backend schema).
|
|
11
|
+
const zone: ISpatialZone = { fieldKey: 'totalTtc', page: 1, rect: { x: 0.6, y: 0.8, w: 0.3, h: 0.05 }, extractor: 'amount', amountLocale: 'fr' };
|
|
12
|
+
const config: ISpatialTemplateConfig = { kind: 'spatial', documentType: DocumentType.INVOICE, zones: [zone] };
|
|
13
|
+
// The fieldKey + kind discriminant are reachable.
|
|
14
|
+
const _fieldKey: string = config.zones[0].fieldKey; // 'totalTtc'
|
|
15
|
+
const _kind: 'spatial' = config.kind;
|
|
16
|
+
void _fieldKey; void _kind;
|
|
17
|
+
|
|
18
|
+
// Every extractor literal is assignable to the union.
|
|
19
|
+
const _extractors: ISpatialZoneExtractor[] = ['raw', 'regex', 'date', 'amount', 'iban'];
|
|
20
|
+
void _extractors;
|
|
21
|
+
|
|
22
|
+
// A template version dto types (serialized dates, nullable comment).
|
|
23
|
+
const v: IExtractionTemplateVersionDto = { id: 'v1', templateId: 't1', version: 1, templateJson: { kind: 'spatial' }, comment: null, createdAt: '2026-06-28T00:00:00.000Z' };
|
|
24
|
+
const _version: number = v.version; // 1
|
|
25
|
+
void _version;
|
|
26
|
+
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// packages/abyss_tools_core/src/types/interface/models/extraction-spatial-template.dto.ts
|
|
2
|
+
//
|
|
3
|
+
// Spatial (Karmen) template DTOs. Mirror the backend spatial-template.schema +
|
|
4
|
+
// extraction-template-version shapes VERBATIM so the V2-P4 zone editor types its
|
|
5
|
+
// CRUD payloads/responses. ADDITIVE — does not touch existing template DTOs.
|
|
6
|
+
import { DocumentType } from '../../enum/document-type.enum';
|
|
7
|
+
|
|
8
|
+
export type ISpatialZoneExtractor = 'raw' | 'regex' | 'date' | 'amount' | 'iban';
|
|
9
|
+
|
|
10
|
+
/** A single zone: a normalized 0..1 rect on a page + how to coerce the tokens inside it. */
|
|
11
|
+
export interface ISpatialZone {
|
|
12
|
+
fieldKey: string;
|
|
13
|
+
/** 1-based page number. */
|
|
14
|
+
page: number;
|
|
15
|
+
/** Normalized 0..1 of the page (origin top-left). */
|
|
16
|
+
rect: { x: number; y: number; w: number; h: number };
|
|
17
|
+
extractor: ISpatialZoneExtractor;
|
|
18
|
+
regex?: string;
|
|
19
|
+
captureGroup?: number;
|
|
20
|
+
amountLocale?: 'fr' | 'en';
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** The spatial config stored inside a template version's templateJson. */
|
|
24
|
+
export interface ISpatialTemplateConfig {
|
|
25
|
+
kind: 'spatial';
|
|
26
|
+
documentType: DocumentType;
|
|
27
|
+
zones: ISpatialZone[];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** A template version row (mirrors backend IExtractionTemplateVersion, dates serialized). */
|
|
31
|
+
export interface IExtractionTemplateVersionDto {
|
|
32
|
+
id: string;
|
|
33
|
+
templateId: string;
|
|
34
|
+
version: number;
|
|
35
|
+
templateJson: Record<string, unknown>;
|
|
36
|
+
comment: string | null;
|
|
37
|
+
createdAt: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** A template list item (the spatial-aware list the editor renders). */
|
|
41
|
+
export interface ISpatialTemplateListItem {
|
|
42
|
+
id: string;
|
|
43
|
+
name: string;
|
|
44
|
+
description: string | null;
|
|
45
|
+
isActive: boolean;
|
|
46
|
+
createdAt: string;
|
|
47
|
+
updatedAt: string;
|
|
48
|
+
}
|