zorya-classifier 0.2.1 → 0.2.3
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 +31 -17
- 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-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/composed-classifier.d.ts +17 -0
- package/dist/app/composed-classifier.js +1 -0
- package/dist/app/create-classifier.d.ts +9 -33
- package/dist/app/create-classifier.js +53 -245
- package/dist/cli.js +1 -1
- package/dist/entities/classification.d.ts +83 -0
- package/dist/entities/classification.js +28 -0
- package/dist/entities/contracts.d.ts +6 -475
- 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 +30 -0
- package/dist/entities/image.js +12 -0
- package/dist/entities/localization.d.ts +110 -0
- package/dist/entities/localization.js +13 -0
- package/dist/entities/object-proposals.d.ts +1 -1
- package/dist/entities/representation.d.ts +0 -183
- package/dist/entities/representation.js +1 -33
- 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 -1
- package/dist/entities/segmentation.d.ts +5 -20
- package/dist/entities/validation.d.ts +2 -0
- package/dist/entities/validation.js +9 -0
- package/dist/entities/whole-object.d.ts +6 -21
- 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 +2 -2
- package/dist/infrastructure/segmentation/grabcut/index.js +3 -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 -66
- package/dist/infrastructure/segmentation/mobile-sam/index.js +2 -478
- 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/README.ru.md +50 -33
- package/docs/acceptance.md +6 -4
- package/docs/agents.ru.md +97 -0
- package/docs/api.md +4 -4
- package/docs/architecture.md +33 -7
- package/docs/architecture.ru.md +146 -0
- package/docs/benchmarks.md +3 -1
- package/docs/development.ru.md +141 -0
- package/docs/migrations/experimental-text-image-removal.ru.md +9 -0
- package/docs/provenance.json +288 -1
- package/docs/publishing.md +5 -3
- package/docs/refactoring-plan.ru.md +183 -0
- package/docs/v02-usage.md +8 -8
- package/docs/vision-results.md +1 -1
- 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
|
@@ -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,30 @@
|
|
|
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.ZodObject<{
|
|
13
|
+
type: z.ZodLiteral<"vision">;
|
|
14
|
+
}, "strict", z.ZodTypeAny, {
|
|
15
|
+
type: "vision";
|
|
16
|
+
}, {
|
|
17
|
+
type: "vision";
|
|
18
|
+
}>;
|
|
19
|
+
export type Representation = z.infer<typeof representationSchema>;
|
|
20
|
+
export interface RasterImage {
|
|
21
|
+
bytes: Uint8Array;
|
|
22
|
+
width: number;
|
|
23
|
+
height: number;
|
|
24
|
+
}
|
|
25
|
+
export interface RasterPort {
|
|
26
|
+
normalize(bytes: Uint8Array, signal: AbortSignal): Promise<RasterImage>;
|
|
27
|
+
crop(image: RasterImage, region: PixelRect, signal: AbortSignal, scale?: number): Promise<RasterImage>;
|
|
28
|
+
imageState(image: RasterImage, signal: AbortSignal): Promise<DecisionState>;
|
|
29
|
+
grid(image: RasterImage, region: PixelRect, cells: readonly GridCell[], labels: ReadonlyMap<string, string>, signal: AbortSignal): Promise<RasterImage>;
|
|
30
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
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.object({ type: z.literal('vision') }).strict();
|
|
@@ -0,0 +1,110 @@
|
|
|
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.ZodObject<{
|
|
26
|
+
type: z.ZodLiteral<"vision">;
|
|
27
|
+
}, "strict", z.ZodTypeAny, {
|
|
28
|
+
type: "vision";
|
|
29
|
+
}, {
|
|
30
|
+
type: "vision";
|
|
31
|
+
}>>;
|
|
32
|
+
}, "strict", z.ZodTypeAny, {
|
|
33
|
+
image: Uint8Array<ArrayBufferLike>;
|
|
34
|
+
target: string;
|
|
35
|
+
exclusions: string[];
|
|
36
|
+
representation?: {
|
|
37
|
+
type: "vision";
|
|
38
|
+
} | undefined;
|
|
39
|
+
roi?: {
|
|
40
|
+
left: number;
|
|
41
|
+
top: number;
|
|
42
|
+
width: number;
|
|
43
|
+
height: number;
|
|
44
|
+
} | undefined;
|
|
45
|
+
mode?: "region" | undefined;
|
|
46
|
+
}, {
|
|
47
|
+
image: Uint8Array<ArrayBufferLike>;
|
|
48
|
+
target: string;
|
|
49
|
+
representation?: {
|
|
50
|
+
type: "vision";
|
|
51
|
+
} | undefined;
|
|
52
|
+
exclusions?: string[] | undefined;
|
|
53
|
+
roi?: {
|
|
54
|
+
left: number;
|
|
55
|
+
top: number;
|
|
56
|
+
width: number;
|
|
57
|
+
height: number;
|
|
58
|
+
} | undefined;
|
|
59
|
+
mode?: "region" | undefined;
|
|
60
|
+
}>;
|
|
61
|
+
/** Coarse region search; a located grid cell is a hypothesis, not reliable whole-object geometry or proof of absence. */
|
|
62
|
+
export type LocateInput = z.input<typeof locateSchema> & {
|
|
63
|
+
signal?: AbortSignal;
|
|
64
|
+
};
|
|
65
|
+
export interface LocalizationMetadata {
|
|
66
|
+
image: {
|
|
67
|
+
width: number;
|
|
68
|
+
height: number;
|
|
69
|
+
coordinateSpace: 'oriented-source-pixels';
|
|
70
|
+
};
|
|
71
|
+
stages: DecisionMetadata[];
|
|
72
|
+
durationMs: number;
|
|
73
|
+
knownCostUsd: number;
|
|
74
|
+
unknownCostCount: number;
|
|
75
|
+
}
|
|
76
|
+
/** Outcome of spatial localization; grid regions are not semantic object boxes or masks. */
|
|
77
|
+
export type LocalizationResult = ({
|
|
78
|
+
status: 'located';
|
|
79
|
+
region: PixelRect;
|
|
80
|
+
normalizedRegion: PixelRect;
|
|
81
|
+
selection: ChoiceSelection;
|
|
82
|
+
method: 'three-choice-grid-v1';
|
|
83
|
+
refinement?: RefinementResult;
|
|
84
|
+
} | {
|
|
85
|
+
status: 'not-found';
|
|
86
|
+
reason: 'absent-in-evaluated-region';
|
|
87
|
+
} | {
|
|
88
|
+
status: 'unknown';
|
|
89
|
+
reason: 'uncertain-presence' | 'candidate-union-empty' | 'contradictory-evidence' | 'layout-limit';
|
|
90
|
+
}) & {
|
|
91
|
+
metadata: LocalizationMetadata;
|
|
92
|
+
};
|
|
93
|
+
/** Optional legacy region refinement. */
|
|
94
|
+
export type RefinementResult = {
|
|
95
|
+
status: 'refined';
|
|
96
|
+
region: PixelRect;
|
|
97
|
+
method: string;
|
|
98
|
+
} | {
|
|
99
|
+
status: 'unknown';
|
|
100
|
+
reason: string;
|
|
101
|
+
};
|
|
102
|
+
/** Caller-owned refinement hook. */
|
|
103
|
+
export interface RefinementPort {
|
|
104
|
+
refine(input: {
|
|
105
|
+
image: Uint8Array;
|
|
106
|
+
target: string;
|
|
107
|
+
region: PixelRect;
|
|
108
|
+
signal: AbortSignal;
|
|
109
|
+
}): Promise<RefinementResult>;
|
|
110
|
+
}
|
|
@@ -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();
|
|
@@ -35,7 +35,7 @@ export interface ObjectProposalBatch {
|
|
|
35
35
|
}
|
|
36
36
|
/**
|
|
37
37
|
* Caller-owned. propose settles only after physical work closes; no model calls here.
|
|
38
|
-
*
|
|
38
|
+
* Mask proposal strategy; no general quality qualification is implied.
|
|
39
39
|
*/
|
|
40
40
|
export interface ObjectProposalPort {
|
|
41
41
|
propose(input: ObjectProposalInput): Promise<ObjectProposalBatch>;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { DecisionState, GridCell, PixelRect, RasterImage } from './contracts.js';
|
|
2
|
-
import { z } from 'zod';
|
|
3
2
|
/** Canonical oriented RGBA8. Alpha remains meaningful; transparent is not black. */
|
|
4
3
|
export interface RgbaRaster {
|
|
5
4
|
data: Uint8Array;
|
|
@@ -41,185 +40,3 @@ export interface ImageRepresentationPort {
|
|
|
41
40
|
metadata: RepresentationMetadata;
|
|
42
41
|
}>;
|
|
43
42
|
}
|
|
44
|
-
export declare const representationLimits: Readonly<{
|
|
45
|
-
totalBytes: number;
|
|
46
|
-
partCharacters: 64000;
|
|
47
|
-
maxSide: 64;
|
|
48
|
-
maxViews: 9;
|
|
49
|
-
}>;
|
|
50
|
-
export declare const preparedTextSchema: z.ZodObject<{
|
|
51
|
-
state: z.ZodArray<z.ZodString, "many">;
|
|
52
|
-
metadata: z.ZodObject<{
|
|
53
|
-
profile: z.ZodString;
|
|
54
|
-
bytes: z.ZodNumber;
|
|
55
|
-
views: z.ZodArray<z.ZodObject<{
|
|
56
|
-
id: z.ZodString;
|
|
57
|
-
sourceRegion: z.ZodObject<{
|
|
58
|
-
left: z.ZodNumber;
|
|
59
|
-
top: z.ZodNumber;
|
|
60
|
-
width: z.ZodNumber;
|
|
61
|
-
height: z.ZodNumber;
|
|
62
|
-
}, "strict", z.ZodTypeAny, {
|
|
63
|
-
left: number;
|
|
64
|
-
top: number;
|
|
65
|
-
width: number;
|
|
66
|
-
height: number;
|
|
67
|
-
}, {
|
|
68
|
-
left: number;
|
|
69
|
-
top: number;
|
|
70
|
-
width: number;
|
|
71
|
-
height: number;
|
|
72
|
-
}>;
|
|
73
|
-
width: z.ZodNumber;
|
|
74
|
-
height: z.ZodNumber;
|
|
75
|
-
scaleX: z.ZodNumber;
|
|
76
|
-
scaleY: z.ZodNumber;
|
|
77
|
-
content: z.ZodOptional<z.ZodObject<{
|
|
78
|
-
left: z.ZodNumber;
|
|
79
|
-
top: z.ZodNumber;
|
|
80
|
-
width: z.ZodNumber;
|
|
81
|
-
height: z.ZodNumber;
|
|
82
|
-
}, "strict", z.ZodTypeAny, {
|
|
83
|
-
left: number;
|
|
84
|
-
top: number;
|
|
85
|
-
width: number;
|
|
86
|
-
height: number;
|
|
87
|
-
}, {
|
|
88
|
-
left: number;
|
|
89
|
-
top: number;
|
|
90
|
-
width: number;
|
|
91
|
-
height: number;
|
|
92
|
-
}>>;
|
|
93
|
-
}, "strict", z.ZodTypeAny, {
|
|
94
|
-
width: number;
|
|
95
|
-
height: number;
|
|
96
|
-
id: string;
|
|
97
|
-
sourceRegion: {
|
|
98
|
-
left: number;
|
|
99
|
-
top: number;
|
|
100
|
-
width: number;
|
|
101
|
-
height: number;
|
|
102
|
-
};
|
|
103
|
-
scaleX: number;
|
|
104
|
-
scaleY: number;
|
|
105
|
-
content?: {
|
|
106
|
-
left: number;
|
|
107
|
-
top: number;
|
|
108
|
-
width: number;
|
|
109
|
-
height: number;
|
|
110
|
-
} | undefined;
|
|
111
|
-
}, {
|
|
112
|
-
width: number;
|
|
113
|
-
height: number;
|
|
114
|
-
id: string;
|
|
115
|
-
sourceRegion: {
|
|
116
|
-
left: number;
|
|
117
|
-
top: number;
|
|
118
|
-
width: number;
|
|
119
|
-
height: number;
|
|
120
|
-
};
|
|
121
|
-
scaleX: number;
|
|
122
|
-
scaleY: number;
|
|
123
|
-
content?: {
|
|
124
|
-
left: number;
|
|
125
|
-
top: number;
|
|
126
|
-
width: number;
|
|
127
|
-
height: number;
|
|
128
|
-
} | undefined;
|
|
129
|
-
}>, "many">;
|
|
130
|
-
}, "strict", z.ZodTypeAny, {
|
|
131
|
-
profile: string;
|
|
132
|
-
bytes: number;
|
|
133
|
-
views: {
|
|
134
|
-
width: number;
|
|
135
|
-
height: number;
|
|
136
|
-
id: string;
|
|
137
|
-
sourceRegion: {
|
|
138
|
-
left: number;
|
|
139
|
-
top: number;
|
|
140
|
-
width: number;
|
|
141
|
-
height: number;
|
|
142
|
-
};
|
|
143
|
-
scaleX: number;
|
|
144
|
-
scaleY: number;
|
|
145
|
-
content?: {
|
|
146
|
-
left: number;
|
|
147
|
-
top: number;
|
|
148
|
-
width: number;
|
|
149
|
-
height: number;
|
|
150
|
-
} | undefined;
|
|
151
|
-
}[];
|
|
152
|
-
}, {
|
|
153
|
-
profile: string;
|
|
154
|
-
bytes: number;
|
|
155
|
-
views: {
|
|
156
|
-
width: number;
|
|
157
|
-
height: number;
|
|
158
|
-
id: string;
|
|
159
|
-
sourceRegion: {
|
|
160
|
-
left: number;
|
|
161
|
-
top: number;
|
|
162
|
-
width: number;
|
|
163
|
-
height: number;
|
|
164
|
-
};
|
|
165
|
-
scaleX: number;
|
|
166
|
-
scaleY: number;
|
|
167
|
-
content?: {
|
|
168
|
-
left: number;
|
|
169
|
-
top: number;
|
|
170
|
-
width: number;
|
|
171
|
-
height: number;
|
|
172
|
-
} | undefined;
|
|
173
|
-
}[];
|
|
174
|
-
}>;
|
|
175
|
-
}, "strict", z.ZodTypeAny, {
|
|
176
|
-
metadata: {
|
|
177
|
-
profile: string;
|
|
178
|
-
bytes: number;
|
|
179
|
-
views: {
|
|
180
|
-
width: number;
|
|
181
|
-
height: number;
|
|
182
|
-
id: string;
|
|
183
|
-
sourceRegion: {
|
|
184
|
-
left: number;
|
|
185
|
-
top: number;
|
|
186
|
-
width: number;
|
|
187
|
-
height: number;
|
|
188
|
-
};
|
|
189
|
-
scaleX: number;
|
|
190
|
-
scaleY: number;
|
|
191
|
-
content?: {
|
|
192
|
-
left: number;
|
|
193
|
-
top: number;
|
|
194
|
-
width: number;
|
|
195
|
-
height: number;
|
|
196
|
-
} | undefined;
|
|
197
|
-
}[];
|
|
198
|
-
};
|
|
199
|
-
state: string[];
|
|
200
|
-
}, {
|
|
201
|
-
metadata: {
|
|
202
|
-
profile: string;
|
|
203
|
-
bytes: number;
|
|
204
|
-
views: {
|
|
205
|
-
width: number;
|
|
206
|
-
height: number;
|
|
207
|
-
id: string;
|
|
208
|
-
sourceRegion: {
|
|
209
|
-
left: number;
|
|
210
|
-
top: number;
|
|
211
|
-
width: number;
|
|
212
|
-
height: number;
|
|
213
|
-
};
|
|
214
|
-
scaleX: number;
|
|
215
|
-
scaleY: number;
|
|
216
|
-
content?: {
|
|
217
|
-
left: number;
|
|
218
|
-
top: number;
|
|
219
|
-
width: number;
|
|
220
|
-
height: number;
|
|
221
|
-
} | undefined;
|
|
222
|
-
}[];
|
|
223
|
-
};
|
|
224
|
-
state: string[];
|
|
225
|
-
}>;
|