zorya-classifier 0.2.0 → 0.2.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/README.md +24 -8
- package/dist/app/classifier-config.d.ts +30 -0
- package/dist/app/classifier-config.js +46 -0
- package/dist/app/classifier-contracts.d.ts +32 -0
- package/dist/app/classifier-contracts.js +1 -0
- package/dist/app/classifier-representation.d.ts +5 -0
- package/dist/app/classifier-representation.js +33 -0
- package/dist/app/classifier-runtime.d.ts +7 -0
- package/dist/app/classifier-runtime.js +71 -0
- package/dist/app/classifier-spatial.d.ts +31 -0
- package/dist/app/classifier-spatial.js +78 -0
- package/dist/app/cli-arguments.d.ts +2 -2
- package/dist/app/create-classifier.d.ts +4 -29
- package/dist/app/create-classifier.js +37 -237
- package/dist/cli.js +1 -1
- package/dist/entities/classification.d.ts +98 -0
- package/dist/entities/classification.js +28 -0
- package/dist/entities/contracts.d.ts +6 -471
- package/dist/entities/contracts.js +6 -97
- package/dist/entities/decision.d.ts +211 -0
- package/dist/entities/decision.js +33 -0
- package/dist/entities/geometry.d.ts +37 -0
- package/dist/entities/geometry.js +26 -0
- package/dist/entities/image.d.ts +39 -0
- package/dist/entities/image.js +15 -0
- package/dist/entities/localization.d.ts +125 -0
- package/dist/entities/localization.js +13 -0
- package/dist/entities/object-proposals.d.ts +4 -1
- package/dist/entities/segmentation-metadata.d.ts +70 -0
- package/dist/entities/segmentation-metadata.js +21 -1
- package/dist/entities/segmentation-verification.d.ts +1 -0
- package/dist/entities/segmentation.d.ts +6 -1
- package/dist/entities/validation.d.ts +2 -0
- package/dist/entities/validation.js +9 -0
- package/dist/entities/whole-object.d.ts +4 -0
- package/dist/features/choice-beam-layout.js +2 -7
- package/dist/features/proposals/presentation.d.ts +21 -0
- package/dist/features/proposals/presentation.js +122 -0
- package/dist/features/proposals/validation.d.ts +138 -0
- package/dist/features/proposals/validation.js +125 -0
- package/dist/features/segmentation/box-check.js +10 -23
- package/dist/features/segmentation/mask.js +2 -7
- package/dist/features/segmentation/region-result.d.ts +18 -0
- package/dist/features/segmentation/region-result.js +171 -0
- package/dist/features/segmentation/source-mask.d.ts +6 -0
- package/dist/features/segmentation/source-mask.js +32 -0
- package/dist/features/segmentation/validation.d.ts +9 -0
- package/dist/features/segmentation/validation.js +94 -0
- package/dist/infrastructure/decision-transport/errors.d.ts +8 -0
- package/dist/infrastructure/decision-transport/errors.js +34 -0
- package/dist/infrastructure/decision-transport/images.d.ts +1 -0
- package/dist/infrastructure/decision-transport/images.js +52 -0
- package/dist/infrastructure/{openrouter-common.d.ts → decision-transport/request.d.ts} +6 -15
- package/dist/infrastructure/decision-transport/request.js +162 -0
- package/dist/infrastructure/decision-transport/response.d.ts +1 -0
- package/dist/infrastructure/decision-transport/response.js +72 -0
- package/dist/infrastructure/decision-transport/route-identity.d.ts +11 -0
- package/dist/infrastructure/decision-transport/route-identity.js +23 -0
- package/dist/infrastructure/openrouter-vision.js +1 -1
- package/dist/infrastructure/openrouter.js +7 -19
- package/dist/infrastructure/raster.js +3 -8
- package/dist/infrastructure/segmentation/grabcut/index.d.ts +5 -1
- package/dist/infrastructure/segmentation/grabcut/index.js +6 -5
- package/dist/infrastructure/segmentation/grabcut/masks.d.ts +49 -0
- package/dist/infrastructure/segmentation/grabcut/masks.js +89 -0
- package/dist/infrastructure/segmentation/grabcut/model-asset.d.ts +4 -0
- package/dist/infrastructure/segmentation/grabcut/model-asset.js +4 -0
- package/dist/infrastructure/segmentation/grabcut/runtime.d.ts +70 -0
- package/dist/infrastructure/segmentation/grabcut/runtime.js +96 -0
- package/dist/infrastructure/segmentation/grabcut/worker-inference.d.ts +4 -43
- package/dist/infrastructure/segmentation/grabcut/worker-inference.js +4 -187
- package/dist/infrastructure/segmentation/mobile-sam/index.d.ts +3 -58
- package/dist/infrastructure/segmentation/mobile-sam/index.js +2 -472
- package/dist/infrastructure/segmentation/mobile-sam/input.d.ts +46 -0
- package/dist/infrastructure/segmentation/mobile-sam/input.js +83 -0
- package/dist/infrastructure/segmentation/mobile-sam/model-assets.d.ts +8 -0
- package/dist/infrastructure/segmentation/mobile-sam/model-assets.js +8 -0
- package/dist/infrastructure/segmentation/mobile-sam/object-proposals.d.ts +7 -0
- package/dist/infrastructure/segmentation/mobile-sam/object-proposals.js +124 -0
- package/dist/infrastructure/segmentation/mobile-sam/options.d.ts +43 -0
- package/dist/infrastructure/segmentation/mobile-sam/options.js +19 -0
- package/dist/infrastructure/segmentation/mobile-sam/proposal-masks.d.ts +26 -0
- package/dist/infrastructure/segmentation/mobile-sam/proposal-masks.js +71 -0
- package/dist/infrastructure/segmentation/mobile-sam/segmentation-masks.d.ts +112 -0
- package/dist/infrastructure/segmentation/mobile-sam/segmentation-masks.js +230 -0
- package/dist/infrastructure/segmentation/mobile-sam/segmenter.d.ts +22 -0
- package/dist/infrastructure/segmentation/mobile-sam/segmenter.js +268 -0
- package/dist/infrastructure/segmentation/mobile-sam/worker-expand.d.ts +7 -0
- package/dist/infrastructure/segmentation/mobile-sam/worker-expand.js +188 -0
- package/dist/infrastructure/segmentation/mobile-sam/worker-inference.d.ts +6 -149
- package/dist/infrastructure/segmentation/mobile-sam/worker-inference.js +6 -845
- package/dist/infrastructure/segmentation/mobile-sam/worker-models.d.ts +14 -0
- package/dist/infrastructure/segmentation/mobile-sam/worker-models.js +72 -0
- package/dist/infrastructure/segmentation/mobile-sam/worker-proposals.d.ts +7 -0
- package/dist/infrastructure/segmentation/mobile-sam/worker-proposals.js +159 -0
- package/dist/infrastructure/segmentation/mobile-sam/worker-segment.d.ts +4 -0
- package/dist/infrastructure/segmentation/mobile-sam/worker-segment.js +126 -0
- package/dist/infrastructure/segmentation/native-protocol.d.ts +59 -34
- package/dist/infrastructure/segmentation/native-protocol.js +26 -16
- package/dist/infrastructure/segmentation/proposal-presentation-input.d.ts +20 -0
- package/dist/infrastructure/segmentation/proposal-presentation-input.js +107 -0
- package/dist/infrastructure/segmentation/proposal-presentation-pixels.d.ts +8 -0
- package/dist/infrastructure/segmentation/proposal-presentation-pixels.js +93 -0
- package/dist/infrastructure/segmentation/proposal-presentation.js +10 -201
- package/dist/infrastructure/vision-chat/options.d.ts +62 -0
- package/dist/infrastructure/vision-chat/options.js +46 -0
- package/dist/infrastructure/vision-chat/request.d.ts +23 -0
- package/dist/infrastructure/vision-chat/request.js +109 -0
- package/dist/infrastructure/vision-chat/response.d.ts +3 -0
- package/dist/infrastructure/vision-chat/response.js +105 -0
- package/dist/infrastructure/vision-chat.d.ts +4 -61
- package/dist/infrastructure/vision-chat.js +8 -271
- package/dist/openai-compatible.js +1 -1
- package/dist/processes/extract-from-region.js +11 -216
- package/dist/processes/extract.d.ts +2 -8
- package/dist/processes/extract.js +12 -128
- package/dist/processes/proposal-location.js +5 -251
- package/docs/0.2.0-plan.md +3 -3
- package/docs/README.ru.md +42 -23
- package/docs/acceptance.md +5 -5
- package/docs/agents.ru.md +95 -0
- package/docs/api.md +4 -2
- package/docs/architecture.md +33 -5
- package/docs/architecture.ru.md +146 -0
- package/docs/benchmarks.md +4 -2
- package/docs/development.ru.md +141 -0
- package/docs/operations.md +4 -4
- package/docs/provenance.json +5 -1
- package/docs/publishing.md +8 -0
- package/docs/refactoring-plan.ru.md +183 -0
- package/docs/v02-usage.md +8 -6
- package/docs/vision-results.md +2 -0
- package/package.json +5 -3
- package/dist/infrastructure/boundary-view.d.ts +0 -2
- package/dist/infrastructure/boundary-view.js +0 -263
- package/dist/infrastructure/openrouter-common.js +0 -317
- package/dist/infrastructure/text-representation.d.ts +0 -23
- package/dist/infrastructure/text-representation.js +0 -226
- package/docs/evidence/v02/categorical-heldout-v4/README.md +0 -35
- package/docs/evidence/v02/proposal-resource-soak-261dc23.md +0 -15
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export type ImagePart = {
|
|
3
|
+
type: 'image_url';
|
|
4
|
+
image_url: {
|
|
5
|
+
url: string;
|
|
6
|
+
detail: 'high';
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
export type DecisionState = (string | ImagePart)[];
|
|
10
|
+
export type ChoiceQuestion = {
|
|
11
|
+
type: 'choice';
|
|
12
|
+
rankingSize?: 1 | 4;
|
|
13
|
+
instructions: string;
|
|
14
|
+
criteria: Record<string, string>;
|
|
15
|
+
};
|
|
16
|
+
type NoulQuestion = {
|
|
17
|
+
type: 'noul';
|
|
18
|
+
instructions: string;
|
|
19
|
+
};
|
|
20
|
+
type DecisionQuestion = ChoiceQuestion | NoulQuestion;
|
|
21
|
+
export type DecisionRequest = {
|
|
22
|
+
state: DecisionState;
|
|
23
|
+
questions: Record<string, DecisionQuestion>;
|
|
24
|
+
};
|
|
25
|
+
export interface DecisionMetadata {
|
|
26
|
+
model: string | null;
|
|
27
|
+
provider: string | null;
|
|
28
|
+
requestId: string | null;
|
|
29
|
+
durationMs: number;
|
|
30
|
+
costUsd: number | null;
|
|
31
|
+
attempts: number;
|
|
32
|
+
}
|
|
33
|
+
declare const choiceAnswerSchema: z.ZodObject<{
|
|
34
|
+
type: z.ZodLiteral<"choice">;
|
|
35
|
+
choice: z.ZodString;
|
|
36
|
+
probabilities: z.ZodRecord<z.ZodString, z.ZodNumber>;
|
|
37
|
+
confidence: z.ZodOptional<z.ZodNumber>;
|
|
38
|
+
probabilityRoundingStep: z.ZodOptional<z.ZodLiteral<0.01>>;
|
|
39
|
+
}, "strip", z.ZodTypeAny, {
|
|
40
|
+
choice: string;
|
|
41
|
+
type: "choice";
|
|
42
|
+
probabilities: Record<string, number>;
|
|
43
|
+
confidence?: number | undefined;
|
|
44
|
+
probabilityRoundingStep?: 0.01 | undefined;
|
|
45
|
+
}, {
|
|
46
|
+
choice: string;
|
|
47
|
+
type: "choice";
|
|
48
|
+
probabilities: Record<string, number>;
|
|
49
|
+
confidence?: number | undefined;
|
|
50
|
+
probabilityRoundingStep?: 0.01 | undefined;
|
|
51
|
+
}>;
|
|
52
|
+
export type ChoiceAnswer = z.infer<typeof choiceAnswerSchema>;
|
|
53
|
+
export declare const decisionMetadataSchema: z.ZodObject<{
|
|
54
|
+
model: z.ZodNullable<z.ZodString>;
|
|
55
|
+
provider: z.ZodNullable<z.ZodString>;
|
|
56
|
+
requestId: z.ZodNullable<z.ZodString>;
|
|
57
|
+
durationMs: z.ZodNumber;
|
|
58
|
+
costUsd: z.ZodNullable<z.ZodNumber>;
|
|
59
|
+
attempts: z.ZodNumber;
|
|
60
|
+
}, "strip", z.ZodTypeAny, {
|
|
61
|
+
model: string | null;
|
|
62
|
+
provider: string | null;
|
|
63
|
+
requestId: string | null;
|
|
64
|
+
durationMs: number;
|
|
65
|
+
costUsd: number | null;
|
|
66
|
+
attempts: number;
|
|
67
|
+
}, {
|
|
68
|
+
model: string | null;
|
|
69
|
+
provider: string | null;
|
|
70
|
+
requestId: string | null;
|
|
71
|
+
durationMs: number;
|
|
72
|
+
costUsd: number | null;
|
|
73
|
+
attempts: number;
|
|
74
|
+
}>;
|
|
75
|
+
export declare const decisionResultSchema: z.ZodObject<{
|
|
76
|
+
answers: z.ZodRecord<z.ZodString, z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
|
|
77
|
+
type: z.ZodLiteral<"choice">;
|
|
78
|
+
choice: z.ZodString;
|
|
79
|
+
probabilities: z.ZodRecord<z.ZodString, z.ZodNumber>;
|
|
80
|
+
confidence: z.ZodOptional<z.ZodNumber>;
|
|
81
|
+
probabilityRoundingStep: z.ZodOptional<z.ZodLiteral<0.01>>;
|
|
82
|
+
}, "strip", z.ZodTypeAny, {
|
|
83
|
+
choice: string;
|
|
84
|
+
type: "choice";
|
|
85
|
+
probabilities: Record<string, number>;
|
|
86
|
+
confidence?: number | undefined;
|
|
87
|
+
probabilityRoundingStep?: 0.01 | undefined;
|
|
88
|
+
}, {
|
|
89
|
+
choice: string;
|
|
90
|
+
type: "choice";
|
|
91
|
+
probabilities: Record<string, number>;
|
|
92
|
+
confidence?: number | undefined;
|
|
93
|
+
probabilityRoundingStep?: 0.01 | undefined;
|
|
94
|
+
}>, z.ZodObject<{
|
|
95
|
+
type: z.ZodLiteral<"ranked-choice">;
|
|
96
|
+
ranking: z.ZodArray<z.ZodString, "many">;
|
|
97
|
+
}, "strict", z.ZodTypeAny, {
|
|
98
|
+
type: "ranked-choice";
|
|
99
|
+
ranking: string[];
|
|
100
|
+
}, {
|
|
101
|
+
type: "ranked-choice";
|
|
102
|
+
ranking: string[];
|
|
103
|
+
}>, z.ZodObject<{
|
|
104
|
+
type: z.ZodLiteral<"presence">;
|
|
105
|
+
presence: z.ZodEnum<["present", "absent", "unknown"]>;
|
|
106
|
+
}, "strict", z.ZodTypeAny, {
|
|
107
|
+
type: "presence";
|
|
108
|
+
presence: "unknown" | "present" | "absent";
|
|
109
|
+
}, {
|
|
110
|
+
type: "presence";
|
|
111
|
+
presence: "unknown" | "present" | "absent";
|
|
112
|
+
}>, z.ZodObject<{
|
|
113
|
+
type: z.ZodLiteral<"noul">;
|
|
114
|
+
noul: z.ZodNumber;
|
|
115
|
+
}, "strip", z.ZodTypeAny, {
|
|
116
|
+
noul: number;
|
|
117
|
+
type: "noul";
|
|
118
|
+
}, {
|
|
119
|
+
noul: number;
|
|
120
|
+
type: "noul";
|
|
121
|
+
}>]>>;
|
|
122
|
+
metadata: z.ZodObject<{
|
|
123
|
+
model: z.ZodNullable<z.ZodString>;
|
|
124
|
+
provider: z.ZodNullable<z.ZodString>;
|
|
125
|
+
requestId: z.ZodNullable<z.ZodString>;
|
|
126
|
+
durationMs: z.ZodNumber;
|
|
127
|
+
costUsd: z.ZodNullable<z.ZodNumber>;
|
|
128
|
+
attempts: z.ZodNumber;
|
|
129
|
+
}, "strip", z.ZodTypeAny, {
|
|
130
|
+
model: string | null;
|
|
131
|
+
provider: string | null;
|
|
132
|
+
requestId: string | null;
|
|
133
|
+
durationMs: number;
|
|
134
|
+
costUsd: number | null;
|
|
135
|
+
attempts: number;
|
|
136
|
+
}, {
|
|
137
|
+
model: string | null;
|
|
138
|
+
provider: string | null;
|
|
139
|
+
requestId: string | null;
|
|
140
|
+
durationMs: number;
|
|
141
|
+
costUsd: number | null;
|
|
142
|
+
attempts: number;
|
|
143
|
+
}>;
|
|
144
|
+
}, "strip", z.ZodTypeAny, {
|
|
145
|
+
answers: Record<string, {
|
|
146
|
+
choice: string;
|
|
147
|
+
type: "choice";
|
|
148
|
+
probabilities: Record<string, number>;
|
|
149
|
+
confidence?: number | undefined;
|
|
150
|
+
probabilityRoundingStep?: 0.01 | undefined;
|
|
151
|
+
} | {
|
|
152
|
+
type: "ranked-choice";
|
|
153
|
+
ranking: string[];
|
|
154
|
+
} | {
|
|
155
|
+
type: "presence";
|
|
156
|
+
presence: "unknown" | "present" | "absent";
|
|
157
|
+
} | {
|
|
158
|
+
noul: number;
|
|
159
|
+
type: "noul";
|
|
160
|
+
}>;
|
|
161
|
+
metadata: {
|
|
162
|
+
model: string | null;
|
|
163
|
+
provider: string | null;
|
|
164
|
+
requestId: string | null;
|
|
165
|
+
durationMs: number;
|
|
166
|
+
costUsd: number | null;
|
|
167
|
+
attempts: number;
|
|
168
|
+
};
|
|
169
|
+
}, {
|
|
170
|
+
answers: Record<string, {
|
|
171
|
+
choice: string;
|
|
172
|
+
type: "choice";
|
|
173
|
+
probabilities: Record<string, number>;
|
|
174
|
+
confidence?: number | undefined;
|
|
175
|
+
probabilityRoundingStep?: 0.01 | undefined;
|
|
176
|
+
} | {
|
|
177
|
+
type: "ranked-choice";
|
|
178
|
+
ranking: string[];
|
|
179
|
+
} | {
|
|
180
|
+
type: "presence";
|
|
181
|
+
presence: "unknown" | "present" | "absent";
|
|
182
|
+
} | {
|
|
183
|
+
noul: number;
|
|
184
|
+
type: "noul";
|
|
185
|
+
}>;
|
|
186
|
+
metadata: {
|
|
187
|
+
model: string | null;
|
|
188
|
+
provider: string | null;
|
|
189
|
+
requestId: string | null;
|
|
190
|
+
durationMs: number;
|
|
191
|
+
costUsd: number | null;
|
|
192
|
+
attempts: number;
|
|
193
|
+
};
|
|
194
|
+
}>;
|
|
195
|
+
export type DecisionResult = z.infer<typeof decisionResultSchema>;
|
|
196
|
+
export interface DecisionPort {
|
|
197
|
+
decide(request: DecisionRequest, signal: AbortSignal): Promise<DecisionResult>;
|
|
198
|
+
}
|
|
199
|
+
export interface ChoiceSelection {
|
|
200
|
+
choice: string;
|
|
201
|
+
nativeChoice: string | null;
|
|
202
|
+
probabilities: Record<string, number> | null;
|
|
203
|
+
ranking?: string[];
|
|
204
|
+
confidence?: number;
|
|
205
|
+
probabilityRoundingStep?: 0.01;
|
|
206
|
+
tied: string[];
|
|
207
|
+
}
|
|
208
|
+
export interface ClassificationResult extends ChoiceSelection {
|
|
209
|
+
metadata: DecisionMetadata;
|
|
210
|
+
}
|
|
211
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
const choiceAnswerSchema = z.object({
|
|
3
|
+
type: z.literal('choice'),
|
|
4
|
+
choice: z.string(),
|
|
5
|
+
probabilities: z.record(z.number().finite().min(0).max(1)),
|
|
6
|
+
confidence: z.number().finite().min(0).max(1).optional(),
|
|
7
|
+
probabilityRoundingStep: z.literal(0.01).optional(),
|
|
8
|
+
});
|
|
9
|
+
const answersSchema = z.record(z.discriminatedUnion('type', [
|
|
10
|
+
choiceAnswerSchema,
|
|
11
|
+
z
|
|
12
|
+
.object({
|
|
13
|
+
type: z.literal('ranked-choice'),
|
|
14
|
+
ranking: z.array(z.string().min(1).max(128)).min(1).max(4),
|
|
15
|
+
})
|
|
16
|
+
.strict(),
|
|
17
|
+
z
|
|
18
|
+
.object({ type: z.literal('presence'), presence: z.enum(['present', 'absent', 'unknown']) })
|
|
19
|
+
.strict(),
|
|
20
|
+
z.object({ type: z.literal('noul'), noul: z.number().finite().min(0).max(1) }),
|
|
21
|
+
]));
|
|
22
|
+
export const decisionMetadataSchema = z.object({
|
|
23
|
+
model: z.string().nullable(),
|
|
24
|
+
provider: z.string().nullable(),
|
|
25
|
+
requestId: z.string().nullable(),
|
|
26
|
+
durationMs: z.number().finite().nonnegative(),
|
|
27
|
+
costUsd: z.number().finite().nonnegative().nullable(),
|
|
28
|
+
attempts: z.number().int().positive(),
|
|
29
|
+
});
|
|
30
|
+
export const decisionResultSchema = z.object({
|
|
31
|
+
answers: answersSchema,
|
|
32
|
+
metadata: decisionMetadataSchema,
|
|
33
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const pixelRectSchema: z.ZodObject<{
|
|
3
|
+
left: z.ZodNumber;
|
|
4
|
+
top: z.ZodNumber;
|
|
5
|
+
width: z.ZodNumber;
|
|
6
|
+
height: z.ZodNumber;
|
|
7
|
+
}, "strict", z.ZodTypeAny, {
|
|
8
|
+
left: number;
|
|
9
|
+
top: number;
|
|
10
|
+
width: number;
|
|
11
|
+
height: number;
|
|
12
|
+
}, {
|
|
13
|
+
left: number;
|
|
14
|
+
top: number;
|
|
15
|
+
width: number;
|
|
16
|
+
height: number;
|
|
17
|
+
}>;
|
|
18
|
+
export type PixelRect = z.infer<typeof pixelRectSchema>;
|
|
19
|
+
export interface GridCell {
|
|
20
|
+
id: string;
|
|
21
|
+
column: number;
|
|
22
|
+
row: number;
|
|
23
|
+
region: PixelRect;
|
|
24
|
+
xId?: string;
|
|
25
|
+
yId?: string;
|
|
26
|
+
kind?: 'cell';
|
|
27
|
+
}
|
|
28
|
+
export interface GridPanel {
|
|
29
|
+
id: string;
|
|
30
|
+
region: PixelRect;
|
|
31
|
+
cells: readonly GridCell[];
|
|
32
|
+
}
|
|
33
|
+
/** Containment with zero inner width/height allowed when endpoints fit inside outer. */
|
|
34
|
+
export declare function containsRect(outer: PixelRect, inner: PixelRect): boolean;
|
|
35
|
+
/** Containment requiring strictly positive inner width and height. */
|
|
36
|
+
export declare function containsNonEmptyRect(outer: PixelRect, inner: PixelRect): boolean;
|
|
37
|
+
export declare function intersectsRect(first: PixelRect, second: PixelRect): boolean;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export const pixelRectSchema = z
|
|
3
|
+
.object({
|
|
4
|
+
left: z.number().int().nonnegative().safe(),
|
|
5
|
+
top: z.number().int().nonnegative().safe(),
|
|
6
|
+
width: z.number().int().positive().max(16384),
|
|
7
|
+
height: z.number().int().positive().max(16384),
|
|
8
|
+
})
|
|
9
|
+
.strict();
|
|
10
|
+
/** Containment with zero inner width/height allowed when endpoints fit inside outer. */
|
|
11
|
+
export function containsRect(outer, inner) {
|
|
12
|
+
return (inner.left >= outer.left &&
|
|
13
|
+
inner.top >= outer.top &&
|
|
14
|
+
inner.left + inner.width <= outer.left + outer.width &&
|
|
15
|
+
inner.top + inner.height <= outer.top + outer.height);
|
|
16
|
+
}
|
|
17
|
+
/** Containment requiring strictly positive inner width and height. */
|
|
18
|
+
export function containsNonEmptyRect(outer, inner) {
|
|
19
|
+
return inner.width > 0 && inner.height > 0 && containsRect(outer, inner);
|
|
20
|
+
}
|
|
21
|
+
export function intersectsRect(first, second) {
|
|
22
|
+
return (first.left < second.left + second.width &&
|
|
23
|
+
second.left < first.left + first.width &&
|
|
24
|
+
first.top < second.top + second.height &&
|
|
25
|
+
second.top < first.top + first.height);
|
|
26
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { DecisionState } from './decision.js';
|
|
3
|
+
import type { GridCell, PixelRect } from './geometry.js';
|
|
4
|
+
export declare const limits: Readonly<{
|
|
5
|
+
imageBytes: number;
|
|
6
|
+
imagePixels: 16777216;
|
|
7
|
+
bodyBytes: number;
|
|
8
|
+
maxClasses: 255;
|
|
9
|
+
maxImages: 9;
|
|
10
|
+
}>;
|
|
11
|
+
export declare const imageSchema: z.ZodEffects<z.ZodType<Uint8Array<ArrayBufferLike>, z.ZodTypeDef, Uint8Array<ArrayBufferLike>>, Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>>;
|
|
12
|
+
export declare const representationSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
|
|
13
|
+
type: z.ZodLiteral<"vision">;
|
|
14
|
+
}, "strict", z.ZodTypeAny, {
|
|
15
|
+
type: "vision";
|
|
16
|
+
}, {
|
|
17
|
+
type: "vision";
|
|
18
|
+
}>, z.ZodObject<{
|
|
19
|
+
type: z.ZodLiteral<"experimental-text">;
|
|
20
|
+
profile: z.ZodLiteral<"text-image-v1">;
|
|
21
|
+
}, "strict", z.ZodTypeAny, {
|
|
22
|
+
type: "experimental-text";
|
|
23
|
+
profile: "text-image-v1";
|
|
24
|
+
}, {
|
|
25
|
+
type: "experimental-text";
|
|
26
|
+
profile: "text-image-v1";
|
|
27
|
+
}>]>;
|
|
28
|
+
export type Representation = z.infer<typeof representationSchema>;
|
|
29
|
+
export interface RasterImage {
|
|
30
|
+
bytes: Uint8Array;
|
|
31
|
+
width: number;
|
|
32
|
+
height: number;
|
|
33
|
+
}
|
|
34
|
+
export interface RasterPort {
|
|
35
|
+
normalize(bytes: Uint8Array, signal: AbortSignal): Promise<RasterImage>;
|
|
36
|
+
crop(image: RasterImage, region: PixelRect, signal: AbortSignal, scale?: number): Promise<RasterImage>;
|
|
37
|
+
imageState(image: RasterImage, signal: AbortSignal): Promise<DecisionState>;
|
|
38
|
+
grid(image: RasterImage, region: PixelRect, cells: readonly GridCell[], labels: ReadonlyMap<string, string>, signal: AbortSignal): Promise<RasterImage>;
|
|
39
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export const limits = Object.freeze({
|
|
3
|
+
imageBytes: 16 * 1024 * 1024,
|
|
4
|
+
imagePixels: 16_777_216,
|
|
5
|
+
bodyBytes: 32 * 1024 * 1024,
|
|
6
|
+
maxClasses: 255,
|
|
7
|
+
maxImages: 9,
|
|
8
|
+
});
|
|
9
|
+
export const imageSchema = z
|
|
10
|
+
.custom((value) => value instanceof Uint8Array)
|
|
11
|
+
.refine((v) => v.byteLength > 0 && v.byteLength <= limits.imageBytes, 'Expected 1..16MiB image bytes');
|
|
12
|
+
export const representationSchema = z.discriminatedUnion('type', [
|
|
13
|
+
z.object({ type: z.literal('vision') }).strict(),
|
|
14
|
+
z.object({ type: z.literal('experimental-text'), profile: z.literal('text-image-v1') }).strict(),
|
|
15
|
+
]);
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { ChoiceSelection, DecisionMetadata } from './decision.js';
|
|
3
|
+
import { type PixelRect } from './geometry.js';
|
|
4
|
+
export declare const locateSchema: z.ZodObject<{
|
|
5
|
+
image: z.ZodEffects<z.ZodType<Uint8Array<ArrayBufferLike>, z.ZodTypeDef, Uint8Array<ArrayBufferLike>>, Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>>;
|
|
6
|
+
target: z.ZodString;
|
|
7
|
+
exclusions: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
8
|
+
roi: z.ZodOptional<z.ZodObject<{
|
|
9
|
+
left: z.ZodNumber;
|
|
10
|
+
top: z.ZodNumber;
|
|
11
|
+
width: z.ZodNumber;
|
|
12
|
+
height: z.ZodNumber;
|
|
13
|
+
}, "strict", z.ZodTypeAny, {
|
|
14
|
+
left: number;
|
|
15
|
+
top: number;
|
|
16
|
+
width: number;
|
|
17
|
+
height: number;
|
|
18
|
+
}, {
|
|
19
|
+
left: number;
|
|
20
|
+
top: number;
|
|
21
|
+
width: number;
|
|
22
|
+
height: number;
|
|
23
|
+
}>>;
|
|
24
|
+
mode: z.ZodOptional<z.ZodLiteral<"region">>;
|
|
25
|
+
representation: z.ZodOptional<z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
|
|
26
|
+
type: z.ZodLiteral<"vision">;
|
|
27
|
+
}, "strict", z.ZodTypeAny, {
|
|
28
|
+
type: "vision";
|
|
29
|
+
}, {
|
|
30
|
+
type: "vision";
|
|
31
|
+
}>, z.ZodObject<{
|
|
32
|
+
type: z.ZodLiteral<"experimental-text">;
|
|
33
|
+
profile: z.ZodLiteral<"text-image-v1">;
|
|
34
|
+
}, "strict", z.ZodTypeAny, {
|
|
35
|
+
type: "experimental-text";
|
|
36
|
+
profile: "text-image-v1";
|
|
37
|
+
}, {
|
|
38
|
+
type: "experimental-text";
|
|
39
|
+
profile: "text-image-v1";
|
|
40
|
+
}>]>>;
|
|
41
|
+
}, "strict", z.ZodTypeAny, {
|
|
42
|
+
image: Uint8Array<ArrayBufferLike>;
|
|
43
|
+
target: string;
|
|
44
|
+
exclusions: string[];
|
|
45
|
+
representation?: {
|
|
46
|
+
type: "vision";
|
|
47
|
+
} | {
|
|
48
|
+
type: "experimental-text";
|
|
49
|
+
profile: "text-image-v1";
|
|
50
|
+
} | undefined;
|
|
51
|
+
roi?: {
|
|
52
|
+
left: number;
|
|
53
|
+
top: number;
|
|
54
|
+
width: number;
|
|
55
|
+
height: number;
|
|
56
|
+
} | undefined;
|
|
57
|
+
mode?: "region" | undefined;
|
|
58
|
+
}, {
|
|
59
|
+
image: Uint8Array<ArrayBufferLike>;
|
|
60
|
+
target: string;
|
|
61
|
+
representation?: {
|
|
62
|
+
type: "vision";
|
|
63
|
+
} | {
|
|
64
|
+
type: "experimental-text";
|
|
65
|
+
profile: "text-image-v1";
|
|
66
|
+
} | undefined;
|
|
67
|
+
exclusions?: string[] | undefined;
|
|
68
|
+
roi?: {
|
|
69
|
+
left: number;
|
|
70
|
+
top: number;
|
|
71
|
+
width: number;
|
|
72
|
+
height: number;
|
|
73
|
+
} | undefined;
|
|
74
|
+
mode?: "region" | undefined;
|
|
75
|
+
}>;
|
|
76
|
+
/** @experimental Unqualified coarse region search; a located grid cell is a hypothesis, not reliable whole-object geometry or proof of absence. */
|
|
77
|
+
export type LocateInput = z.input<typeof locateSchema> & {
|
|
78
|
+
signal?: AbortSignal;
|
|
79
|
+
};
|
|
80
|
+
export interface LocalizationMetadata {
|
|
81
|
+
image: {
|
|
82
|
+
width: number;
|
|
83
|
+
height: number;
|
|
84
|
+
coordinateSpace: 'oriented-source-pixels';
|
|
85
|
+
};
|
|
86
|
+
stages: DecisionMetadata[];
|
|
87
|
+
durationMs: number;
|
|
88
|
+
knownCostUsd: number;
|
|
89
|
+
unknownCostCount: number;
|
|
90
|
+
}
|
|
91
|
+
/** @experimental Outcome of unqualified spatial localization; grid regions are not semantic object boxes or masks. */
|
|
92
|
+
export type LocalizationResult = ({
|
|
93
|
+
status: 'located';
|
|
94
|
+
region: PixelRect;
|
|
95
|
+
normalizedRegion: PixelRect;
|
|
96
|
+
selection: ChoiceSelection;
|
|
97
|
+
method: 'three-choice-grid-v1';
|
|
98
|
+
refinement?: RefinementResult;
|
|
99
|
+
} | {
|
|
100
|
+
status: 'not-found';
|
|
101
|
+
reason: 'absent-in-evaluated-region';
|
|
102
|
+
} | {
|
|
103
|
+
status: 'unknown';
|
|
104
|
+
reason: 'uncertain-presence' | 'candidate-union-empty' | 'contradictory-evidence' | 'layout-limit';
|
|
105
|
+
}) & {
|
|
106
|
+
metadata: LocalizationMetadata;
|
|
107
|
+
};
|
|
108
|
+
/** @experimental Optional legacy region refinement with no general quality qualification. */
|
|
109
|
+
export type RefinementResult = {
|
|
110
|
+
status: 'refined';
|
|
111
|
+
region: PixelRect;
|
|
112
|
+
method: string;
|
|
113
|
+
} | {
|
|
114
|
+
status: 'unknown';
|
|
115
|
+
reason: string;
|
|
116
|
+
};
|
|
117
|
+
/** @experimental Caller-owned refinement hook; unqualified for general spatial accuracy. */
|
|
118
|
+
export interface RefinementPort {
|
|
119
|
+
refine(input: {
|
|
120
|
+
image: Uint8Array;
|
|
121
|
+
target: string;
|
|
122
|
+
region: PixelRect;
|
|
123
|
+
signal: AbortSignal;
|
|
124
|
+
}): Promise<RefinementResult>;
|
|
125
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { pixelRectSchema } from './geometry.js';
|
|
3
|
+
import { imageSchema, representationSchema } from './image.js';
|
|
4
|
+
export const locateSchema = z
|
|
5
|
+
.object({
|
|
6
|
+
image: imageSchema,
|
|
7
|
+
target: z.string().trim().min(1).max(2000),
|
|
8
|
+
exclusions: z.array(z.string().trim().min(1).max(500)).max(16).default([]),
|
|
9
|
+
roi: pixelRectSchema.optional(),
|
|
10
|
+
mode: z.literal('region').optional(),
|
|
11
|
+
representation: representationSchema.optional(),
|
|
12
|
+
})
|
|
13
|
+
.strict();
|
|
@@ -33,7 +33,10 @@ export interface ObjectProposalBatch {
|
|
|
33
33
|
proposals: readonly ObjectProposal[];
|
|
34
34
|
metadata: SegmentationMetadata;
|
|
35
35
|
}
|
|
36
|
-
/**
|
|
36
|
+
/**
|
|
37
|
+
* Caller-owned. propose settles only after physical work closes; no model calls here.
|
|
38
|
+
* @experimental Mask proposal strategy with no general quality qualification.
|
|
39
|
+
*/
|
|
37
40
|
export interface ObjectProposalPort {
|
|
38
41
|
propose(input: ObjectProposalInput): Promise<ObjectProposalBatch>;
|
|
39
42
|
settle(): Promise<void>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
1
2
|
/** Diagnostic native scores are uncalibrated finite values, not probabilities. */
|
|
2
3
|
export interface SegmentationMetadata {
|
|
3
4
|
method: string;
|
|
@@ -9,3 +10,72 @@ export interface SegmentationMetadata {
|
|
|
9
10
|
};
|
|
10
11
|
qualityScore?: number;
|
|
11
12
|
}
|
|
13
|
+
export declare const segmentationMetadataSchema: z.ZodObject<{
|
|
14
|
+
method: z.ZodString;
|
|
15
|
+
backend: z.ZodString;
|
|
16
|
+
durationMs: z.ZodNumber;
|
|
17
|
+
input: z.ZodObject<{
|
|
18
|
+
width: z.ZodNumber;
|
|
19
|
+
height: z.ZodNumber;
|
|
20
|
+
}, "strict", z.ZodTypeAny, {
|
|
21
|
+
width: number;
|
|
22
|
+
height: number;
|
|
23
|
+
}, {
|
|
24
|
+
width: number;
|
|
25
|
+
height: number;
|
|
26
|
+
}>;
|
|
27
|
+
qualityScore: z.ZodOptional<z.ZodNumber>;
|
|
28
|
+
}, "strict", z.ZodTypeAny, {
|
|
29
|
+
durationMs: number;
|
|
30
|
+
input: {
|
|
31
|
+
width: number;
|
|
32
|
+
height: number;
|
|
33
|
+
};
|
|
34
|
+
method: string;
|
|
35
|
+
backend: string;
|
|
36
|
+
qualityScore?: number | undefined;
|
|
37
|
+
}, {
|
|
38
|
+
durationMs: number;
|
|
39
|
+
input: {
|
|
40
|
+
width: number;
|
|
41
|
+
height: number;
|
|
42
|
+
};
|
|
43
|
+
method: string;
|
|
44
|
+
backend: string;
|
|
45
|
+
qualityScore?: number | undefined;
|
|
46
|
+
}>;
|
|
47
|
+
export declare const segmentationMetadataSafeSchema: z.ZodObject<{
|
|
48
|
+
method: z.ZodString;
|
|
49
|
+
backend: z.ZodString;
|
|
50
|
+
durationMs: z.ZodNumber;
|
|
51
|
+
qualityScore: z.ZodOptional<z.ZodNumber>;
|
|
52
|
+
} & {
|
|
53
|
+
input: z.ZodObject<{
|
|
54
|
+
width: z.ZodNumber;
|
|
55
|
+
height: z.ZodNumber;
|
|
56
|
+
}, "strict", z.ZodTypeAny, {
|
|
57
|
+
width: number;
|
|
58
|
+
height: number;
|
|
59
|
+
}, {
|
|
60
|
+
width: number;
|
|
61
|
+
height: number;
|
|
62
|
+
}>;
|
|
63
|
+
}, "strict", z.ZodTypeAny, {
|
|
64
|
+
durationMs: number;
|
|
65
|
+
input: {
|
|
66
|
+
width: number;
|
|
67
|
+
height: number;
|
|
68
|
+
};
|
|
69
|
+
method: string;
|
|
70
|
+
backend: string;
|
|
71
|
+
qualityScore?: number | undefined;
|
|
72
|
+
}, {
|
|
73
|
+
durationMs: number;
|
|
74
|
+
input: {
|
|
75
|
+
width: number;
|
|
76
|
+
height: number;
|
|
77
|
+
};
|
|
78
|
+
method: string;
|
|
79
|
+
backend: string;
|
|
80
|
+
qualityScore?: number | undefined;
|
|
81
|
+
}>;
|
|
@@ -1 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
const safePositiveDimensionSchema = z
|
|
3
|
+
.object({
|
|
4
|
+
width: z.number().int().positive().safe(),
|
|
5
|
+
height: z.number().int().positive().safe(),
|
|
6
|
+
})
|
|
7
|
+
.strict();
|
|
8
|
+
export const segmentationMetadataSchema = z
|
|
9
|
+
.object({
|
|
10
|
+
method: z.string().min(1).max(128),
|
|
11
|
+
backend: z.string().min(1).max(128),
|
|
12
|
+
durationMs: z.number().finite().nonnegative(),
|
|
13
|
+
input: z
|
|
14
|
+
.object({ width: z.number().int().positive(), height: z.number().int().positive() })
|
|
15
|
+
.strict(),
|
|
16
|
+
qualityScore: z.number().finite().optional(),
|
|
17
|
+
})
|
|
18
|
+
.strict();
|
|
19
|
+
export const segmentationMetadataSafeSchema = segmentationMetadataSchema
|
|
20
|
+
.extend({ input: safePositiveDimensionSchema })
|
|
21
|
+
.strict();
|
|
@@ -16,6 +16,7 @@ export interface SegmentationBoxCheckResult {
|
|
|
16
16
|
selection: ChoiceSelection;
|
|
17
17
|
metadata: DecisionMetadata;
|
|
18
18
|
}
|
|
19
|
+
/** @experimental Closed box containment check; verdicts are unqualified for general spatial accuracy. */
|
|
19
20
|
export interface SegmentationBoxCheckPort {
|
|
20
21
|
check(input: SegmentationBoxCheckInput): Promise<SegmentationBoxCheckResult>;
|
|
21
22
|
}
|
|
@@ -84,6 +84,7 @@ export declare const extractSchema: z.ZodObject<{
|
|
|
84
84
|
boxTolerancePx?: number | undefined;
|
|
85
85
|
maxExtentPasses?: number | undefined;
|
|
86
86
|
}>;
|
|
87
|
+
/** @experimental Region-seeded extraction input; unqualified for general object or mask accuracy. */
|
|
87
88
|
export type ExtractInput = z.input<typeof extractSchema> & {
|
|
88
89
|
signal?: AbortSignal;
|
|
89
90
|
};
|
|
@@ -115,7 +116,10 @@ export type SegmentationResult = {
|
|
|
115
116
|
reason: string;
|
|
116
117
|
metadata: SegmentationMetadata;
|
|
117
118
|
};
|
|
118
|
-
/**
|
|
119
|
+
/**
|
|
120
|
+
* Caller-owned. settle joins physical work; dispose closes this adapter only.
|
|
121
|
+
* @experimental Caller-owned segmentation; structural validation does not establish semantic object or mask quality.
|
|
122
|
+
*/
|
|
119
123
|
export interface SegmentationPort {
|
|
120
124
|
segment(input: SegmentationInput): Promise<SegmentationResult>;
|
|
121
125
|
/** Optional actual enclosing mask on the full source; previousMask is full-source binary-u8. */
|
|
@@ -123,6 +127,7 @@ export interface SegmentationPort {
|
|
|
123
127
|
settle(): Promise<void>;
|
|
124
128
|
dispose(): Promise<void>;
|
|
125
129
|
}
|
|
130
|
+
/** @experimental Extraction outcome; `extracted` reflects validation, not guaranteed semantic correctness. */
|
|
126
131
|
export type ExtractionResult = {
|
|
127
132
|
status: 'extracted';
|
|
128
133
|
location: WholeObjectLocated;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ClassifierError } from './errors.js';
|
|
2
|
+
export function parse(schema, value, code = 'INVALID_INPUT') {
|
|
3
|
+
const result = schema.safeParse(value);
|
|
4
|
+
if (!result.success)
|
|
5
|
+
throw new ClassifierError(code, 'Schema validation failed', {
|
|
6
|
+
paths: result.error.issues.map((v) => v.path.join('.')),
|
|
7
|
+
});
|
|
8
|
+
return result.data;
|
|
9
|
+
}
|