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.
Files changed (140) hide show
  1. package/README.md +24 -8
  2. package/dist/app/classifier-config.d.ts +30 -0
  3. package/dist/app/classifier-config.js +46 -0
  4. package/dist/app/classifier-contracts.d.ts +32 -0
  5. package/dist/app/classifier-contracts.js +1 -0
  6. package/dist/app/classifier-representation.d.ts +5 -0
  7. package/dist/app/classifier-representation.js +33 -0
  8. package/dist/app/classifier-runtime.d.ts +7 -0
  9. package/dist/app/classifier-runtime.js +71 -0
  10. package/dist/app/classifier-spatial.d.ts +31 -0
  11. package/dist/app/classifier-spatial.js +78 -0
  12. package/dist/app/cli-arguments.d.ts +2 -2
  13. package/dist/app/create-classifier.d.ts +4 -29
  14. package/dist/app/create-classifier.js +37 -237
  15. package/dist/cli.js +1 -1
  16. package/dist/entities/classification.d.ts +98 -0
  17. package/dist/entities/classification.js +28 -0
  18. package/dist/entities/contracts.d.ts +6 -471
  19. package/dist/entities/contracts.js +6 -97
  20. package/dist/entities/decision.d.ts +211 -0
  21. package/dist/entities/decision.js +33 -0
  22. package/dist/entities/geometry.d.ts +37 -0
  23. package/dist/entities/geometry.js +26 -0
  24. package/dist/entities/image.d.ts +39 -0
  25. package/dist/entities/image.js +15 -0
  26. package/dist/entities/localization.d.ts +125 -0
  27. package/dist/entities/localization.js +13 -0
  28. package/dist/entities/object-proposals.d.ts +4 -1
  29. package/dist/entities/segmentation-metadata.d.ts +70 -0
  30. package/dist/entities/segmentation-metadata.js +21 -1
  31. package/dist/entities/segmentation-verification.d.ts +1 -0
  32. package/dist/entities/segmentation.d.ts +6 -1
  33. package/dist/entities/validation.d.ts +2 -0
  34. package/dist/entities/validation.js +9 -0
  35. package/dist/entities/whole-object.d.ts +4 -0
  36. package/dist/features/choice-beam-layout.js +2 -7
  37. package/dist/features/proposals/presentation.d.ts +21 -0
  38. package/dist/features/proposals/presentation.js +122 -0
  39. package/dist/features/proposals/validation.d.ts +138 -0
  40. package/dist/features/proposals/validation.js +125 -0
  41. package/dist/features/segmentation/box-check.js +10 -23
  42. package/dist/features/segmentation/mask.js +2 -7
  43. package/dist/features/segmentation/region-result.d.ts +18 -0
  44. package/dist/features/segmentation/region-result.js +171 -0
  45. package/dist/features/segmentation/source-mask.d.ts +6 -0
  46. package/dist/features/segmentation/source-mask.js +32 -0
  47. package/dist/features/segmentation/validation.d.ts +9 -0
  48. package/dist/features/segmentation/validation.js +94 -0
  49. package/dist/infrastructure/decision-transport/errors.d.ts +8 -0
  50. package/dist/infrastructure/decision-transport/errors.js +34 -0
  51. package/dist/infrastructure/decision-transport/images.d.ts +1 -0
  52. package/dist/infrastructure/decision-transport/images.js +52 -0
  53. package/dist/infrastructure/{openrouter-common.d.ts → decision-transport/request.d.ts} +6 -15
  54. package/dist/infrastructure/decision-transport/request.js +162 -0
  55. package/dist/infrastructure/decision-transport/response.d.ts +1 -0
  56. package/dist/infrastructure/decision-transport/response.js +72 -0
  57. package/dist/infrastructure/decision-transport/route-identity.d.ts +11 -0
  58. package/dist/infrastructure/decision-transport/route-identity.js +23 -0
  59. package/dist/infrastructure/openrouter-vision.js +1 -1
  60. package/dist/infrastructure/openrouter.js +7 -19
  61. package/dist/infrastructure/raster.js +3 -8
  62. package/dist/infrastructure/segmentation/grabcut/index.d.ts +5 -1
  63. package/dist/infrastructure/segmentation/grabcut/index.js +6 -5
  64. package/dist/infrastructure/segmentation/grabcut/masks.d.ts +49 -0
  65. package/dist/infrastructure/segmentation/grabcut/masks.js +89 -0
  66. package/dist/infrastructure/segmentation/grabcut/model-asset.d.ts +4 -0
  67. package/dist/infrastructure/segmentation/grabcut/model-asset.js +4 -0
  68. package/dist/infrastructure/segmentation/grabcut/runtime.d.ts +70 -0
  69. package/dist/infrastructure/segmentation/grabcut/runtime.js +96 -0
  70. package/dist/infrastructure/segmentation/grabcut/worker-inference.d.ts +4 -43
  71. package/dist/infrastructure/segmentation/grabcut/worker-inference.js +4 -187
  72. package/dist/infrastructure/segmentation/mobile-sam/index.d.ts +3 -58
  73. package/dist/infrastructure/segmentation/mobile-sam/index.js +2 -472
  74. package/dist/infrastructure/segmentation/mobile-sam/input.d.ts +46 -0
  75. package/dist/infrastructure/segmentation/mobile-sam/input.js +83 -0
  76. package/dist/infrastructure/segmentation/mobile-sam/model-assets.d.ts +8 -0
  77. package/dist/infrastructure/segmentation/mobile-sam/model-assets.js +8 -0
  78. package/dist/infrastructure/segmentation/mobile-sam/object-proposals.d.ts +7 -0
  79. package/dist/infrastructure/segmentation/mobile-sam/object-proposals.js +124 -0
  80. package/dist/infrastructure/segmentation/mobile-sam/options.d.ts +43 -0
  81. package/dist/infrastructure/segmentation/mobile-sam/options.js +19 -0
  82. package/dist/infrastructure/segmentation/mobile-sam/proposal-masks.d.ts +26 -0
  83. package/dist/infrastructure/segmentation/mobile-sam/proposal-masks.js +71 -0
  84. package/dist/infrastructure/segmentation/mobile-sam/segmentation-masks.d.ts +112 -0
  85. package/dist/infrastructure/segmentation/mobile-sam/segmentation-masks.js +230 -0
  86. package/dist/infrastructure/segmentation/mobile-sam/segmenter.d.ts +22 -0
  87. package/dist/infrastructure/segmentation/mobile-sam/segmenter.js +268 -0
  88. package/dist/infrastructure/segmentation/mobile-sam/worker-expand.d.ts +7 -0
  89. package/dist/infrastructure/segmentation/mobile-sam/worker-expand.js +188 -0
  90. package/dist/infrastructure/segmentation/mobile-sam/worker-inference.d.ts +6 -149
  91. package/dist/infrastructure/segmentation/mobile-sam/worker-inference.js +6 -845
  92. package/dist/infrastructure/segmentation/mobile-sam/worker-models.d.ts +14 -0
  93. package/dist/infrastructure/segmentation/mobile-sam/worker-models.js +72 -0
  94. package/dist/infrastructure/segmentation/mobile-sam/worker-proposals.d.ts +7 -0
  95. package/dist/infrastructure/segmentation/mobile-sam/worker-proposals.js +159 -0
  96. package/dist/infrastructure/segmentation/mobile-sam/worker-segment.d.ts +4 -0
  97. package/dist/infrastructure/segmentation/mobile-sam/worker-segment.js +126 -0
  98. package/dist/infrastructure/segmentation/native-protocol.d.ts +59 -34
  99. package/dist/infrastructure/segmentation/native-protocol.js +26 -16
  100. package/dist/infrastructure/segmentation/proposal-presentation-input.d.ts +20 -0
  101. package/dist/infrastructure/segmentation/proposal-presentation-input.js +107 -0
  102. package/dist/infrastructure/segmentation/proposal-presentation-pixels.d.ts +8 -0
  103. package/dist/infrastructure/segmentation/proposal-presentation-pixels.js +93 -0
  104. package/dist/infrastructure/segmentation/proposal-presentation.js +10 -201
  105. package/dist/infrastructure/vision-chat/options.d.ts +62 -0
  106. package/dist/infrastructure/vision-chat/options.js +46 -0
  107. package/dist/infrastructure/vision-chat/request.d.ts +23 -0
  108. package/dist/infrastructure/vision-chat/request.js +109 -0
  109. package/dist/infrastructure/vision-chat/response.d.ts +3 -0
  110. package/dist/infrastructure/vision-chat/response.js +105 -0
  111. package/dist/infrastructure/vision-chat.d.ts +4 -61
  112. package/dist/infrastructure/vision-chat.js +8 -271
  113. package/dist/openai-compatible.js +1 -1
  114. package/dist/processes/extract-from-region.js +11 -216
  115. package/dist/processes/extract.d.ts +2 -8
  116. package/dist/processes/extract.js +12 -128
  117. package/dist/processes/proposal-location.js +5 -251
  118. package/docs/0.2.0-plan.md +3 -3
  119. package/docs/README.ru.md +42 -23
  120. package/docs/acceptance.md +5 -5
  121. package/docs/agents.ru.md +95 -0
  122. package/docs/api.md +4 -2
  123. package/docs/architecture.md +33 -5
  124. package/docs/architecture.ru.md +146 -0
  125. package/docs/benchmarks.md +4 -2
  126. package/docs/development.ru.md +141 -0
  127. package/docs/operations.md +4 -4
  128. package/docs/provenance.json +5 -1
  129. package/docs/publishing.md +8 -0
  130. package/docs/refactoring-plan.ru.md +183 -0
  131. package/docs/v02-usage.md +8 -6
  132. package/docs/vision-results.md +2 -0
  133. package/package.json +5 -3
  134. package/dist/infrastructure/boundary-view.d.ts +0 -2
  135. package/dist/infrastructure/boundary-view.js +0 -263
  136. package/dist/infrastructure/openrouter-common.js +0 -317
  137. package/dist/infrastructure/text-representation.d.ts +0 -23
  138. package/dist/infrastructure/text-representation.js +0 -226
  139. package/docs/evidence/v02/categorical-heldout-v4/README.md +0 -35
  140. package/docs/evidence/v02/proposal-resource-soak-261dc23.md +0 -15
@@ -1,471 +1,6 @@
1
- import { z } from 'zod';
2
- export declare const limits: Readonly<{
3
- imageBytes: number;
4
- imagePixels: 16777216;
5
- bodyBytes: number;
6
- maxClasses: 255;
7
- maxImages: 9;
8
- }>;
9
- export declare const pixelRectSchema: z.ZodObject<{
10
- left: z.ZodNumber;
11
- top: z.ZodNumber;
12
- width: z.ZodNumber;
13
- height: z.ZodNumber;
14
- }, "strict", z.ZodTypeAny, {
15
- left: number;
16
- top: number;
17
- width: number;
18
- height: number;
19
- }, {
20
- left: number;
21
- top: number;
22
- width: number;
23
- height: number;
24
- }>;
25
- export type PixelRect = z.infer<typeof pixelRectSchema>;
26
- export interface GridCell {
27
- id: string;
28
- column: number;
29
- row: number;
30
- region: PixelRect;
31
- xId?: string;
32
- yId?: string;
33
- kind?: 'cell';
34
- }
35
- export interface GridPanel {
36
- id: string;
37
- region: PixelRect;
38
- cells: readonly GridCell[];
39
- }
40
- export declare const classSchema: z.ZodObject<{
41
- id: z.ZodString;
42
- description: z.ZodString;
43
- }, "strict", z.ZodTypeAny, {
44
- id: string;
45
- description: string;
46
- }, {
47
- id: string;
48
- description: string;
49
- }>;
50
- export type ClassDefinition = z.infer<typeof classSchema>;
51
- export declare const representationSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
52
- type: z.ZodLiteral<"vision">;
53
- }, "strict", z.ZodTypeAny, {
54
- type: "vision";
55
- }, {
56
- type: "vision";
57
- }>, z.ZodObject<{
58
- type: z.ZodLiteral<"experimental-text">;
59
- profile: z.ZodLiteral<"text-image-v1">;
60
- }, "strict", z.ZodTypeAny, {
61
- type: "experimental-text";
62
- profile: "text-image-v1";
63
- }, {
64
- type: "experimental-text";
65
- profile: "text-image-v1";
66
- }>]>;
67
- export type Representation = z.infer<typeof representationSchema>;
68
- export declare const classifySchema: z.ZodObject<{
69
- input: z.ZodUnion<[z.ZodString, z.ZodEffects<z.ZodObject<{
70
- text: z.ZodOptional<z.ZodString>;
71
- image: z.ZodOptional<z.ZodEffects<z.ZodType<Uint8Array<ArrayBufferLike>, z.ZodTypeDef, Uint8Array<ArrayBufferLike>>, Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>>>;
72
- }, "strict", z.ZodTypeAny, {
73
- text?: string | undefined;
74
- image?: Uint8Array<ArrayBufferLike> | undefined;
75
- }, {
76
- text?: string | undefined;
77
- image?: Uint8Array<ArrayBufferLike> | undefined;
78
- }>, {
79
- text?: string | undefined;
80
- image?: Uint8Array<ArrayBufferLike> | undefined;
81
- }, {
82
- text?: string | undefined;
83
- image?: Uint8Array<ArrayBufferLike> | undefined;
84
- }>]>;
85
- classes: z.ZodEffects<z.ZodArray<z.ZodObject<{
86
- id: z.ZodString;
87
- description: z.ZodString;
88
- }, "strict", z.ZodTypeAny, {
89
- id: string;
90
- description: string;
91
- }, {
92
- id: string;
93
- description: string;
94
- }>, "many">, {
95
- id: string;
96
- description: string;
97
- }[], {
98
- id: string;
99
- description: string;
100
- }[]>;
101
- instructions: z.ZodOptional<z.ZodString>;
102
- representation: z.ZodOptional<z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
103
- type: z.ZodLiteral<"vision">;
104
- }, "strict", z.ZodTypeAny, {
105
- type: "vision";
106
- }, {
107
- type: "vision";
108
- }>, z.ZodObject<{
109
- type: z.ZodLiteral<"experimental-text">;
110
- profile: z.ZodLiteral<"text-image-v1">;
111
- }, "strict", z.ZodTypeAny, {
112
- type: "experimental-text";
113
- profile: "text-image-v1";
114
- }, {
115
- type: "experimental-text";
116
- profile: "text-image-v1";
117
- }>]>>;
118
- }, "strict", z.ZodTypeAny, {
119
- input: string | {
120
- text?: string | undefined;
121
- image?: Uint8Array<ArrayBufferLike> | undefined;
122
- };
123
- classes: {
124
- id: string;
125
- description: string;
126
- }[];
127
- instructions?: string | undefined;
128
- representation?: {
129
- type: "vision";
130
- } | {
131
- type: "experimental-text";
132
- profile: "text-image-v1";
133
- } | undefined;
134
- }, {
135
- input: string | {
136
- text?: string | undefined;
137
- image?: Uint8Array<ArrayBufferLike> | undefined;
138
- };
139
- classes: {
140
- id: string;
141
- description: string;
142
- }[];
143
- instructions?: string | undefined;
144
- representation?: {
145
- type: "vision";
146
- } | {
147
- type: "experimental-text";
148
- profile: "text-image-v1";
149
- } | undefined;
150
- }>;
151
- export type ClassifyInput = z.input<typeof classifySchema> & {
152
- signal?: AbortSignal;
153
- };
154
- export declare const locateSchema: z.ZodObject<{
155
- image: z.ZodEffects<z.ZodType<Uint8Array<ArrayBufferLike>, z.ZodTypeDef, Uint8Array<ArrayBufferLike>>, Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>>;
156
- target: z.ZodString;
157
- exclusions: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
158
- roi: z.ZodOptional<z.ZodObject<{
159
- left: z.ZodNumber;
160
- top: z.ZodNumber;
161
- width: z.ZodNumber;
162
- height: z.ZodNumber;
163
- }, "strict", z.ZodTypeAny, {
164
- left: number;
165
- top: number;
166
- width: number;
167
- height: number;
168
- }, {
169
- left: number;
170
- top: number;
171
- width: number;
172
- height: number;
173
- }>>;
174
- mode: z.ZodOptional<z.ZodLiteral<"region">>;
175
- representation: z.ZodOptional<z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
176
- type: z.ZodLiteral<"vision">;
177
- }, "strict", z.ZodTypeAny, {
178
- type: "vision";
179
- }, {
180
- type: "vision";
181
- }>, z.ZodObject<{
182
- type: z.ZodLiteral<"experimental-text">;
183
- profile: z.ZodLiteral<"text-image-v1">;
184
- }, "strict", z.ZodTypeAny, {
185
- type: "experimental-text";
186
- profile: "text-image-v1";
187
- }, {
188
- type: "experimental-text";
189
- profile: "text-image-v1";
190
- }>]>>;
191
- }, "strict", z.ZodTypeAny, {
192
- image: Uint8Array<ArrayBufferLike>;
193
- target: string;
194
- exclusions: string[];
195
- representation?: {
196
- type: "vision";
197
- } | {
198
- type: "experimental-text";
199
- profile: "text-image-v1";
200
- } | undefined;
201
- roi?: {
202
- left: number;
203
- top: number;
204
- width: number;
205
- height: number;
206
- } | undefined;
207
- mode?: "region" | undefined;
208
- }, {
209
- image: Uint8Array<ArrayBufferLike>;
210
- target: string;
211
- representation?: {
212
- type: "vision";
213
- } | {
214
- type: "experimental-text";
215
- profile: "text-image-v1";
216
- } | undefined;
217
- exclusions?: string[] | undefined;
218
- roi?: {
219
- left: number;
220
- top: number;
221
- width: number;
222
- height: number;
223
- } | undefined;
224
- mode?: "region" | undefined;
225
- }>;
226
- export type LocateInput = z.input<typeof locateSchema> & {
227
- signal?: AbortSignal;
228
- };
229
- export type ImagePart = {
230
- type: 'image_url';
231
- image_url: {
232
- url: string;
233
- detail: 'high';
234
- };
235
- };
236
- export type DecisionState = (string | ImagePart)[];
237
- export type ChoiceQuestion = {
238
- type: 'choice';
239
- rankingSize?: 1 | 4;
240
- instructions: string;
241
- criteria: Record<string, string>;
242
- };
243
- type NoulQuestion = {
244
- type: 'noul';
245
- instructions: string;
246
- };
247
- type DecisionQuestion = ChoiceQuestion | NoulQuestion;
248
- export type DecisionRequest = {
249
- state: DecisionState;
250
- questions: Record<string, DecisionQuestion>;
251
- };
252
- export interface DecisionMetadata {
253
- model: string | null;
254
- provider: string | null;
255
- requestId: string | null;
256
- durationMs: number;
257
- costUsd: number | null;
258
- attempts: number;
259
- }
260
- declare const choiceAnswerSchema: z.ZodObject<{
261
- type: z.ZodLiteral<"choice">;
262
- choice: z.ZodString;
263
- probabilities: z.ZodRecord<z.ZodString, z.ZodNumber>;
264
- confidence: z.ZodOptional<z.ZodNumber>;
265
- probabilityRoundingStep: z.ZodOptional<z.ZodLiteral<0.01>>;
266
- }, "strip", z.ZodTypeAny, {
267
- type: "choice";
268
- choice: string;
269
- probabilities: Record<string, number>;
270
- confidence?: number | undefined;
271
- probabilityRoundingStep?: 0.01 | undefined;
272
- }, {
273
- type: "choice";
274
- choice: string;
275
- probabilities: Record<string, number>;
276
- confidence?: number | undefined;
277
- probabilityRoundingStep?: 0.01 | undefined;
278
- }>;
279
- export type ChoiceAnswer = z.infer<typeof choiceAnswerSchema>;
280
- export declare const decisionResultSchema: z.ZodObject<{
281
- answers: z.ZodRecord<z.ZodString, z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
282
- type: z.ZodLiteral<"choice">;
283
- choice: z.ZodString;
284
- probabilities: z.ZodRecord<z.ZodString, z.ZodNumber>;
285
- confidence: z.ZodOptional<z.ZodNumber>;
286
- probabilityRoundingStep: z.ZodOptional<z.ZodLiteral<0.01>>;
287
- }, "strip", z.ZodTypeAny, {
288
- type: "choice";
289
- choice: string;
290
- probabilities: Record<string, number>;
291
- confidence?: number | undefined;
292
- probabilityRoundingStep?: 0.01 | undefined;
293
- }, {
294
- type: "choice";
295
- choice: string;
296
- probabilities: Record<string, number>;
297
- confidence?: number | undefined;
298
- probabilityRoundingStep?: 0.01 | undefined;
299
- }>, z.ZodObject<{
300
- type: z.ZodLiteral<"ranked-choice">;
301
- ranking: z.ZodArray<z.ZodString, "many">;
302
- }, "strict", z.ZodTypeAny, {
303
- type: "ranked-choice";
304
- ranking: string[];
305
- }, {
306
- type: "ranked-choice";
307
- ranking: string[];
308
- }>, z.ZodObject<{
309
- type: z.ZodLiteral<"presence">;
310
- presence: z.ZodEnum<["present", "absent", "unknown"]>;
311
- }, "strict", z.ZodTypeAny, {
312
- type: "presence";
313
- presence: "unknown" | "present" | "absent";
314
- }, {
315
- type: "presence";
316
- presence: "unknown" | "present" | "absent";
317
- }>, z.ZodObject<{
318
- type: z.ZodLiteral<"noul">;
319
- noul: z.ZodNumber;
320
- }, "strip", z.ZodTypeAny, {
321
- type: "noul";
322
- noul: number;
323
- }, {
324
- type: "noul";
325
- noul: number;
326
- }>]>>;
327
- metadata: z.ZodObject<{
328
- model: z.ZodNullable<z.ZodString>;
329
- provider: z.ZodNullable<z.ZodString>;
330
- requestId: z.ZodNullable<z.ZodString>;
331
- durationMs: z.ZodNumber;
332
- costUsd: z.ZodNullable<z.ZodNumber>;
333
- attempts: z.ZodNumber;
334
- }, "strip", z.ZodTypeAny, {
335
- model: string | null;
336
- provider: string | null;
337
- requestId: string | null;
338
- durationMs: number;
339
- costUsd: number | null;
340
- attempts: number;
341
- }, {
342
- model: string | null;
343
- provider: string | null;
344
- requestId: string | null;
345
- durationMs: number;
346
- costUsd: number | null;
347
- attempts: number;
348
- }>;
349
- }, "strip", z.ZodTypeAny, {
350
- answers: Record<string, {
351
- type: "choice";
352
- choice: string;
353
- probabilities: Record<string, number>;
354
- confidence?: number | undefined;
355
- probabilityRoundingStep?: 0.01 | undefined;
356
- } | {
357
- type: "ranked-choice";
358
- ranking: string[];
359
- } | {
360
- type: "presence";
361
- presence: "unknown" | "present" | "absent";
362
- } | {
363
- type: "noul";
364
- noul: number;
365
- }>;
366
- metadata: {
367
- model: string | null;
368
- provider: string | null;
369
- requestId: string | null;
370
- durationMs: number;
371
- costUsd: number | null;
372
- attempts: number;
373
- };
374
- }, {
375
- answers: Record<string, {
376
- type: "choice";
377
- choice: string;
378
- probabilities: Record<string, number>;
379
- confidence?: number | undefined;
380
- probabilityRoundingStep?: 0.01 | undefined;
381
- } | {
382
- type: "ranked-choice";
383
- ranking: string[];
384
- } | {
385
- type: "presence";
386
- presence: "unknown" | "present" | "absent";
387
- } | {
388
- type: "noul";
389
- noul: number;
390
- }>;
391
- metadata: {
392
- model: string | null;
393
- provider: string | null;
394
- requestId: string | null;
395
- durationMs: number;
396
- costUsd: number | null;
397
- attempts: number;
398
- };
399
- }>;
400
- export type DecisionResult = z.infer<typeof decisionResultSchema>;
401
- export interface DecisionPort {
402
- decide(request: DecisionRequest, signal: AbortSignal): Promise<DecisionResult>;
403
- }
404
- export interface ChoiceSelection {
405
- choice: string;
406
- nativeChoice: string | null;
407
- probabilities: Record<string, number> | null;
408
- ranking?: string[];
409
- confidence?: number;
410
- probabilityRoundingStep?: 0.01;
411
- tied: string[];
412
- }
413
- export interface ClassificationResult extends ChoiceSelection {
414
- metadata: DecisionMetadata;
415
- }
416
- export interface LocalizationMetadata {
417
- image: {
418
- width: number;
419
- height: number;
420
- coordinateSpace: 'oriented-source-pixels';
421
- };
422
- stages: DecisionMetadata[];
423
- durationMs: number;
424
- knownCostUsd: number;
425
- unknownCostCount: number;
426
- }
427
- export type LocalizationResult = ({
428
- status: 'located';
429
- region: PixelRect;
430
- normalizedRegion: PixelRect;
431
- selection: ChoiceSelection;
432
- method: 'three-choice-grid-v1';
433
- refinement?: RefinementResult;
434
- } | {
435
- status: 'not-found';
436
- reason: 'absent-in-evaluated-region';
437
- } | {
438
- status: 'unknown';
439
- reason: 'uncertain-presence' | 'candidate-union-empty' | 'contradictory-evidence' | 'layout-limit';
440
- }) & {
441
- metadata: LocalizationMetadata;
442
- };
443
- export type RefinementResult = {
444
- status: 'refined';
445
- region: PixelRect;
446
- method: string;
447
- } | {
448
- status: 'unknown';
449
- reason: string;
450
- };
451
- export interface RefinementPort {
452
- refine(input: {
453
- image: Uint8Array;
454
- target: string;
455
- region: PixelRect;
456
- signal: AbortSignal;
457
- }): Promise<RefinementResult>;
458
- }
459
- export declare function parse<T>(schema: z.ZodType<T, z.ZodTypeDef, unknown>, value: unknown, code?: 'INVALID_INPUT' | 'INVALID_RESPONSE'): T;
460
- export interface RasterImage {
461
- bytes: Uint8Array;
462
- width: number;
463
- height: number;
464
- }
465
- export interface RasterPort {
466
- normalize(bytes: Uint8Array, signal: AbortSignal): Promise<RasterImage>;
467
- crop(image: RasterImage, region: PixelRect, signal: AbortSignal, scale?: number): Promise<RasterImage>;
468
- imageState(image: RasterImage, signal: AbortSignal): Promise<DecisionState>;
469
- grid(image: RasterImage, region: PixelRect, cells: readonly GridCell[], labels: ReadonlyMap<string, string>, signal: AbortSignal): Promise<RasterImage>;
470
- }
471
- export {};
1
+ export { limits, representationSchema, type Representation, type RasterImage, type RasterPort, } from './image.js';
2
+ export { pixelRectSchema, type PixelRect, type GridCell, type GridPanel } from './geometry.js';
3
+ export { classSchema, classifySchema, type ClassDefinition, type ClassifyInput, } from './classification.js';
4
+ export { locateSchema, type LocateInput, type LocalizationMetadata, type LocalizationResult, type RefinementPort, type RefinementResult, } from './localization.js';
5
+ export { type ImagePart, type DecisionState, type ChoiceQuestion, type DecisionRequest, type DecisionMetadata, type ChoiceAnswer, decisionResultSchema, type DecisionResult, type DecisionPort, type ChoiceSelection, type ClassificationResult, } from './decision.js';
6
+ export { parse } from './validation.js';
@@ -1,97 +1,6 @@
1
- import { z } from 'zod';
2
- import { ClassifierError } from './errors.js';
3
- export const limits = Object.freeze({
4
- imageBytes: 16 * 1024 * 1024,
5
- imagePixels: 16_777_216,
6
- bodyBytes: 32 * 1024 * 1024,
7
- maxClasses: 255,
8
- maxImages: 9,
9
- });
10
- export const pixelRectSchema = z
11
- .object({
12
- left: z.number().int().nonnegative().safe(),
13
- top: z.number().int().nonnegative().safe(),
14
- width: z.number().int().positive().max(16384),
15
- height: z.number().int().positive().max(16384),
16
- })
17
- .strict();
18
- export const classSchema = z
19
- .object({
20
- id: z
21
- .string()
22
- .min(1)
23
- .max(128)
24
- .regex(/^[a-zA-Z][a-zA-Z0-9_-]*$/),
25
- description: z.string().trim().min(1).max(300),
26
- })
27
- .strict();
28
- const imageSchema = z
29
- .custom((value) => value instanceof Uint8Array)
30
- .refine((v) => v.byteLength > 0 && v.byteLength <= limits.imageBytes, 'Expected 1..16MiB image bytes');
31
- export const representationSchema = z.discriminatedUnion('type', [
32
- z.object({ type: z.literal('vision') }).strict(),
33
- z.object({ type: z.literal('experimental-text'), profile: z.literal('text-image-v1') }).strict(),
34
- ]);
35
- const mediaInputSchema = z
36
- .object({ text: z.string().trim().min(1).max(32000).optional(), image: imageSchema.optional() })
37
- .strict()
38
- .refine((v) => v.text !== undefined || v.image !== undefined, 'Provide text or image');
39
- export const classifySchema = z
40
- .object({
41
- input: z.union([z.string().trim().min(1).max(32000), mediaInputSchema]),
42
- classes: z
43
- .array(classSchema)
44
- .min(2)
45
- .max(limits.maxClasses)
46
- .refine((v) => new Set(v.map((c) => c.id)).size === v.length, 'Class IDs must be unique'),
47
- instructions: z.string().trim().min(1).max(4000).optional(),
48
- representation: representationSchema.optional(),
49
- })
50
- .strict();
51
- export const locateSchema = z
52
- .object({
53
- image: imageSchema,
54
- target: z.string().trim().min(1).max(2000),
55
- exclusions: z.array(z.string().trim().min(1).max(500)).max(16).default([]),
56
- roi: pixelRectSchema.optional(),
57
- mode: z.literal('region').optional(),
58
- representation: representationSchema.optional(),
59
- })
60
- .strict();
61
- const choiceAnswerSchema = z.object({
62
- type: z.literal('choice'),
63
- choice: z.string(),
64
- probabilities: z.record(z.number().finite().min(0).max(1)),
65
- confidence: z.number().finite().min(0).max(1).optional(),
66
- probabilityRoundingStep: z.literal(0.01).optional(),
67
- });
68
- const answersSchema = z.record(z.discriminatedUnion('type', [
69
- choiceAnswerSchema,
70
- z
71
- .object({
72
- type: z.literal('ranked-choice'),
73
- ranking: z.array(z.string().min(1).max(128)).min(1).max(4),
74
- })
75
- .strict(),
76
- z
77
- .object({ type: z.literal('presence'), presence: z.enum(['present', 'absent', 'unknown']) })
78
- .strict(),
79
- z.object({ type: z.literal('noul'), noul: z.number().finite().min(0).max(1) }),
80
- ]));
81
- const metadataSchema = z.object({
82
- model: z.string().nullable(),
83
- provider: z.string().nullable(),
84
- requestId: z.string().nullable(),
85
- durationMs: z.number().finite().nonnegative(),
86
- costUsd: z.number().finite().nonnegative().nullable(),
87
- attempts: z.number().int().positive(),
88
- });
89
- export const decisionResultSchema = z.object({ answers: answersSchema, metadata: metadataSchema });
90
- export function parse(schema, value, code = 'INVALID_INPUT') {
91
- const result = schema.safeParse(value);
92
- if (!result.success)
93
- throw new ClassifierError(code, 'Schema validation failed', {
94
- paths: result.error.issues.map((v) => v.path.join('.')),
95
- });
96
- return result.data;
97
- }
1
+ export { limits, representationSchema, } from './image.js';
2
+ export { pixelRectSchema } from './geometry.js';
3
+ export { classSchema, classifySchema, } from './classification.js';
4
+ export { locateSchema, } from './localization.js';
5
+ export { decisionResultSchema, } from './decision.js';
6
+ export { parse } from './validation.js';