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.
Files changed (139) hide show
  1. package/README.md +31 -17
  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-runtime.d.ts +7 -0
  7. package/dist/app/classifier-runtime.js +71 -0
  8. package/dist/app/classifier-spatial.d.ts +31 -0
  9. package/dist/app/classifier-spatial.js +78 -0
  10. package/dist/app/cli-arguments.d.ts +2 -2
  11. package/dist/app/composed-classifier.d.ts +17 -0
  12. package/dist/app/composed-classifier.js +1 -0
  13. package/dist/app/create-classifier.d.ts +9 -33
  14. package/dist/app/create-classifier.js +53 -245
  15. package/dist/cli.js +1 -1
  16. package/dist/entities/classification.d.ts +83 -0
  17. package/dist/entities/classification.js +28 -0
  18. package/dist/entities/contracts.d.ts +6 -475
  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 +30 -0
  25. package/dist/entities/image.js +12 -0
  26. package/dist/entities/localization.d.ts +110 -0
  27. package/dist/entities/localization.js +13 -0
  28. package/dist/entities/object-proposals.d.ts +1 -1
  29. package/dist/entities/representation.d.ts +0 -183
  30. package/dist/entities/representation.js +1 -33
  31. package/dist/entities/segmentation-metadata.d.ts +70 -0
  32. package/dist/entities/segmentation-metadata.js +21 -1
  33. package/dist/entities/segmentation-verification.d.ts +1 -1
  34. package/dist/entities/segmentation.d.ts +5 -20
  35. package/dist/entities/validation.d.ts +2 -0
  36. package/dist/entities/validation.js +9 -0
  37. package/dist/entities/whole-object.d.ts +6 -21
  38. package/dist/features/choice-beam-layout.js +2 -7
  39. package/dist/features/proposals/presentation.d.ts +21 -0
  40. package/dist/features/proposals/presentation.js +122 -0
  41. package/dist/features/proposals/validation.d.ts +138 -0
  42. package/dist/features/proposals/validation.js +125 -0
  43. package/dist/features/segmentation/box-check.js +10 -23
  44. package/dist/features/segmentation/mask.js +2 -7
  45. package/dist/features/segmentation/region-result.d.ts +18 -0
  46. package/dist/features/segmentation/region-result.js +171 -0
  47. package/dist/features/segmentation/source-mask.d.ts +6 -0
  48. package/dist/features/segmentation/source-mask.js +32 -0
  49. package/dist/features/segmentation/validation.d.ts +9 -0
  50. package/dist/features/segmentation/validation.js +94 -0
  51. package/dist/infrastructure/decision-transport/errors.d.ts +8 -0
  52. package/dist/infrastructure/decision-transport/errors.js +34 -0
  53. package/dist/infrastructure/decision-transport/images.d.ts +1 -0
  54. package/dist/infrastructure/decision-transport/images.js +52 -0
  55. package/dist/infrastructure/{openrouter-common.d.ts → decision-transport/request.d.ts} +6 -15
  56. package/dist/infrastructure/decision-transport/request.js +162 -0
  57. package/dist/infrastructure/decision-transport/response.d.ts +1 -0
  58. package/dist/infrastructure/decision-transport/response.js +72 -0
  59. package/dist/infrastructure/decision-transport/route-identity.d.ts +11 -0
  60. package/dist/infrastructure/decision-transport/route-identity.js +23 -0
  61. package/dist/infrastructure/openrouter-vision.js +1 -1
  62. package/dist/infrastructure/openrouter.js +7 -19
  63. package/dist/infrastructure/raster.js +3 -8
  64. package/dist/infrastructure/segmentation/grabcut/index.d.ts +2 -2
  65. package/dist/infrastructure/segmentation/grabcut/index.js +3 -5
  66. package/dist/infrastructure/segmentation/grabcut/masks.d.ts +49 -0
  67. package/dist/infrastructure/segmentation/grabcut/masks.js +89 -0
  68. package/dist/infrastructure/segmentation/grabcut/model-asset.d.ts +4 -0
  69. package/dist/infrastructure/segmentation/grabcut/model-asset.js +4 -0
  70. package/dist/infrastructure/segmentation/grabcut/runtime.d.ts +70 -0
  71. package/dist/infrastructure/segmentation/grabcut/runtime.js +96 -0
  72. package/dist/infrastructure/segmentation/grabcut/worker-inference.d.ts +4 -43
  73. package/dist/infrastructure/segmentation/grabcut/worker-inference.js +4 -187
  74. package/dist/infrastructure/segmentation/mobile-sam/index.d.ts +3 -66
  75. package/dist/infrastructure/segmentation/mobile-sam/index.js +2 -478
  76. package/dist/infrastructure/segmentation/mobile-sam/input.d.ts +46 -0
  77. package/dist/infrastructure/segmentation/mobile-sam/input.js +83 -0
  78. package/dist/infrastructure/segmentation/mobile-sam/model-assets.d.ts +8 -0
  79. package/dist/infrastructure/segmentation/mobile-sam/model-assets.js +8 -0
  80. package/dist/infrastructure/segmentation/mobile-sam/object-proposals.d.ts +7 -0
  81. package/dist/infrastructure/segmentation/mobile-sam/object-proposals.js +124 -0
  82. package/dist/infrastructure/segmentation/mobile-sam/options.d.ts +43 -0
  83. package/dist/infrastructure/segmentation/mobile-sam/options.js +19 -0
  84. package/dist/infrastructure/segmentation/mobile-sam/proposal-masks.d.ts +26 -0
  85. package/dist/infrastructure/segmentation/mobile-sam/proposal-masks.js +71 -0
  86. package/dist/infrastructure/segmentation/mobile-sam/segmentation-masks.d.ts +112 -0
  87. package/dist/infrastructure/segmentation/mobile-sam/segmentation-masks.js +230 -0
  88. package/dist/infrastructure/segmentation/mobile-sam/segmenter.d.ts +22 -0
  89. package/dist/infrastructure/segmentation/mobile-sam/segmenter.js +268 -0
  90. package/dist/infrastructure/segmentation/mobile-sam/worker-expand.d.ts +7 -0
  91. package/dist/infrastructure/segmentation/mobile-sam/worker-expand.js +188 -0
  92. package/dist/infrastructure/segmentation/mobile-sam/worker-inference.d.ts +6 -149
  93. package/dist/infrastructure/segmentation/mobile-sam/worker-inference.js +6 -845
  94. package/dist/infrastructure/segmentation/mobile-sam/worker-models.d.ts +14 -0
  95. package/dist/infrastructure/segmentation/mobile-sam/worker-models.js +72 -0
  96. package/dist/infrastructure/segmentation/mobile-sam/worker-proposals.d.ts +7 -0
  97. package/dist/infrastructure/segmentation/mobile-sam/worker-proposals.js +159 -0
  98. package/dist/infrastructure/segmentation/mobile-sam/worker-segment.d.ts +4 -0
  99. package/dist/infrastructure/segmentation/mobile-sam/worker-segment.js +126 -0
  100. package/dist/infrastructure/segmentation/native-protocol.d.ts +59 -34
  101. package/dist/infrastructure/segmentation/native-protocol.js +26 -16
  102. package/dist/infrastructure/segmentation/proposal-presentation-input.d.ts +20 -0
  103. package/dist/infrastructure/segmentation/proposal-presentation-input.js +107 -0
  104. package/dist/infrastructure/segmentation/proposal-presentation-pixels.d.ts +8 -0
  105. package/dist/infrastructure/segmentation/proposal-presentation-pixels.js +93 -0
  106. package/dist/infrastructure/segmentation/proposal-presentation.js +10 -201
  107. package/dist/infrastructure/vision-chat/options.d.ts +62 -0
  108. package/dist/infrastructure/vision-chat/options.js +46 -0
  109. package/dist/infrastructure/vision-chat/request.d.ts +23 -0
  110. package/dist/infrastructure/vision-chat/request.js +109 -0
  111. package/dist/infrastructure/vision-chat/response.d.ts +3 -0
  112. package/dist/infrastructure/vision-chat/response.js +105 -0
  113. package/dist/infrastructure/vision-chat.d.ts +4 -61
  114. package/dist/infrastructure/vision-chat.js +8 -271
  115. package/dist/openai-compatible.js +1 -1
  116. package/dist/processes/extract-from-region.js +11 -216
  117. package/dist/processes/extract.d.ts +2 -8
  118. package/dist/processes/extract.js +12 -128
  119. package/dist/processes/proposal-location.js +5 -251
  120. package/docs/README.ru.md +50 -33
  121. package/docs/acceptance.md +6 -4
  122. package/docs/agents.ru.md +97 -0
  123. package/docs/api.md +4 -4
  124. package/docs/architecture.md +33 -7
  125. package/docs/architecture.ru.md +146 -0
  126. package/docs/benchmarks.md +3 -1
  127. package/docs/development.ru.md +141 -0
  128. package/docs/migrations/experimental-text-image-removal.ru.md +9 -0
  129. package/docs/provenance.json +288 -1
  130. package/docs/publishing.md +5 -3
  131. package/docs/refactoring-plan.ru.md +183 -0
  132. package/docs/v02-usage.md +8 -8
  133. package/docs/vision-results.md +1 -1
  134. package/package.json +5 -3
  135. package/dist/infrastructure/boundary-view.d.ts +0 -2
  136. package/dist/infrastructure/boundary-view.js +0 -263
  137. package/dist/infrastructure/openrouter-common.js +0 -317
  138. package/dist/infrastructure/text-representation.d.ts +0 -23
  139. package/dist/infrastructure/text-representation.js +0 -226
@@ -1,475 +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
- /** @experimental Unqualified coarse region search; a located grid cell is a hypothesis, not reliable whole-object geometry or proof of absence. */
227
- export type LocateInput = z.input<typeof locateSchema> & {
228
- signal?: AbortSignal;
229
- };
230
- export type ImagePart = {
231
- type: 'image_url';
232
- image_url: {
233
- url: string;
234
- detail: 'high';
235
- };
236
- };
237
- export type DecisionState = (string | ImagePart)[];
238
- export type ChoiceQuestion = {
239
- type: 'choice';
240
- rankingSize?: 1 | 4;
241
- instructions: string;
242
- criteria: Record<string, string>;
243
- };
244
- type NoulQuestion = {
245
- type: 'noul';
246
- instructions: string;
247
- };
248
- type DecisionQuestion = ChoiceQuestion | NoulQuestion;
249
- export type DecisionRequest = {
250
- state: DecisionState;
251
- questions: Record<string, DecisionQuestion>;
252
- };
253
- export interface DecisionMetadata {
254
- model: string | null;
255
- provider: string | null;
256
- requestId: string | null;
257
- durationMs: number;
258
- costUsd: number | null;
259
- attempts: number;
260
- }
261
- declare const choiceAnswerSchema: z.ZodObject<{
262
- type: z.ZodLiteral<"choice">;
263
- choice: z.ZodString;
264
- probabilities: z.ZodRecord<z.ZodString, z.ZodNumber>;
265
- confidence: z.ZodOptional<z.ZodNumber>;
266
- probabilityRoundingStep: z.ZodOptional<z.ZodLiteral<0.01>>;
267
- }, "strip", z.ZodTypeAny, {
268
- type: "choice";
269
- choice: string;
270
- probabilities: Record<string, number>;
271
- confidence?: number | undefined;
272
- probabilityRoundingStep?: 0.01 | undefined;
273
- }, {
274
- type: "choice";
275
- choice: string;
276
- probabilities: Record<string, number>;
277
- confidence?: number | undefined;
278
- probabilityRoundingStep?: 0.01 | undefined;
279
- }>;
280
- export type ChoiceAnswer = z.infer<typeof choiceAnswerSchema>;
281
- export declare const decisionResultSchema: z.ZodObject<{
282
- answers: z.ZodRecord<z.ZodString, z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
283
- type: z.ZodLiteral<"choice">;
284
- choice: z.ZodString;
285
- probabilities: z.ZodRecord<z.ZodString, z.ZodNumber>;
286
- confidence: z.ZodOptional<z.ZodNumber>;
287
- probabilityRoundingStep: z.ZodOptional<z.ZodLiteral<0.01>>;
288
- }, "strip", z.ZodTypeAny, {
289
- type: "choice";
290
- choice: string;
291
- probabilities: Record<string, number>;
292
- confidence?: number | undefined;
293
- probabilityRoundingStep?: 0.01 | undefined;
294
- }, {
295
- type: "choice";
296
- choice: string;
297
- probabilities: Record<string, number>;
298
- confidence?: number | undefined;
299
- probabilityRoundingStep?: 0.01 | undefined;
300
- }>, z.ZodObject<{
301
- type: z.ZodLiteral<"ranked-choice">;
302
- ranking: z.ZodArray<z.ZodString, "many">;
303
- }, "strict", z.ZodTypeAny, {
304
- type: "ranked-choice";
305
- ranking: string[];
306
- }, {
307
- type: "ranked-choice";
308
- ranking: string[];
309
- }>, z.ZodObject<{
310
- type: z.ZodLiteral<"presence">;
311
- presence: z.ZodEnum<["present", "absent", "unknown"]>;
312
- }, "strict", z.ZodTypeAny, {
313
- type: "presence";
314
- presence: "unknown" | "present" | "absent";
315
- }, {
316
- type: "presence";
317
- presence: "unknown" | "present" | "absent";
318
- }>, z.ZodObject<{
319
- type: z.ZodLiteral<"noul">;
320
- noul: z.ZodNumber;
321
- }, "strip", z.ZodTypeAny, {
322
- type: "noul";
323
- noul: number;
324
- }, {
325
- type: "noul";
326
- noul: number;
327
- }>]>>;
328
- metadata: z.ZodObject<{
329
- model: z.ZodNullable<z.ZodString>;
330
- provider: z.ZodNullable<z.ZodString>;
331
- requestId: z.ZodNullable<z.ZodString>;
332
- durationMs: z.ZodNumber;
333
- costUsd: z.ZodNullable<z.ZodNumber>;
334
- attempts: z.ZodNumber;
335
- }, "strip", z.ZodTypeAny, {
336
- model: string | null;
337
- provider: string | null;
338
- requestId: string | null;
339
- durationMs: number;
340
- costUsd: number | null;
341
- attempts: number;
342
- }, {
343
- model: string | null;
344
- provider: string | null;
345
- requestId: string | null;
346
- durationMs: number;
347
- costUsd: number | null;
348
- attempts: number;
349
- }>;
350
- }, "strip", z.ZodTypeAny, {
351
- answers: Record<string, {
352
- type: "choice";
353
- choice: string;
354
- probabilities: Record<string, number>;
355
- confidence?: number | undefined;
356
- probabilityRoundingStep?: 0.01 | undefined;
357
- } | {
358
- type: "ranked-choice";
359
- ranking: string[];
360
- } | {
361
- type: "presence";
362
- presence: "unknown" | "present" | "absent";
363
- } | {
364
- type: "noul";
365
- noul: number;
366
- }>;
367
- metadata: {
368
- model: string | null;
369
- provider: string | null;
370
- requestId: string | null;
371
- durationMs: number;
372
- costUsd: number | null;
373
- attempts: number;
374
- };
375
- }, {
376
- answers: Record<string, {
377
- type: "choice";
378
- choice: string;
379
- probabilities: Record<string, number>;
380
- confidence?: number | undefined;
381
- probabilityRoundingStep?: 0.01 | undefined;
382
- } | {
383
- type: "ranked-choice";
384
- ranking: string[];
385
- } | {
386
- type: "presence";
387
- presence: "unknown" | "present" | "absent";
388
- } | {
389
- type: "noul";
390
- noul: number;
391
- }>;
392
- metadata: {
393
- model: string | null;
394
- provider: string | null;
395
- requestId: string | null;
396
- durationMs: number;
397
- costUsd: number | null;
398
- attempts: number;
399
- };
400
- }>;
401
- export type DecisionResult = z.infer<typeof decisionResultSchema>;
402
- export interface DecisionPort {
403
- decide(request: DecisionRequest, signal: AbortSignal): Promise<DecisionResult>;
404
- }
405
- export interface ChoiceSelection {
406
- choice: string;
407
- nativeChoice: string | null;
408
- probabilities: Record<string, number> | null;
409
- ranking?: string[];
410
- confidence?: number;
411
- probabilityRoundingStep?: 0.01;
412
- tied: string[];
413
- }
414
- export interface ClassificationResult extends ChoiceSelection {
415
- metadata: DecisionMetadata;
416
- }
417
- export interface LocalizationMetadata {
418
- image: {
419
- width: number;
420
- height: number;
421
- coordinateSpace: 'oriented-source-pixels';
422
- };
423
- stages: DecisionMetadata[];
424
- durationMs: number;
425
- knownCostUsd: number;
426
- unknownCostCount: number;
427
- }
428
- /** @experimental Outcome of unqualified spatial localization; grid regions are not semantic object boxes or masks. */
429
- export type LocalizationResult = ({
430
- status: 'located';
431
- region: PixelRect;
432
- normalizedRegion: PixelRect;
433
- selection: ChoiceSelection;
434
- method: 'three-choice-grid-v1';
435
- refinement?: RefinementResult;
436
- } | {
437
- status: 'not-found';
438
- reason: 'absent-in-evaluated-region';
439
- } | {
440
- status: 'unknown';
441
- reason: 'uncertain-presence' | 'candidate-union-empty' | 'contradictory-evidence' | 'layout-limit';
442
- }) & {
443
- metadata: LocalizationMetadata;
444
- };
445
- /** @experimental Optional legacy region refinement with no general quality qualification. */
446
- export type RefinementResult = {
447
- status: 'refined';
448
- region: PixelRect;
449
- method: string;
450
- } | {
451
- status: 'unknown';
452
- reason: string;
453
- };
454
- /** @experimental Caller-owned refinement hook; unqualified for general spatial accuracy. */
455
- export interface RefinementPort {
456
- refine(input: {
457
- image: Uint8Array;
458
- target: string;
459
- region: PixelRect;
460
- signal: AbortSignal;
461
- }): Promise<RefinementResult>;
462
- }
463
- export declare function parse<T>(schema: z.ZodType<T, z.ZodTypeDef, unknown>, value: unknown, code?: 'INVALID_INPUT' | 'INVALID_RESPONSE'): T;
464
- export interface RasterImage {
465
- bytes: Uint8Array;
466
- width: number;
467
- height: number;
468
- }
469
- export interface RasterPort {
470
- normalize(bytes: Uint8Array, signal: AbortSignal): Promise<RasterImage>;
471
- crop(image: RasterImage, region: PixelRect, signal: AbortSignal, scale?: number): Promise<RasterImage>;
472
- imageState(image: RasterImage, signal: AbortSignal): Promise<DecisionState>;
473
- grid(image: RasterImage, region: PixelRect, cells: readonly GridCell[], labels: ReadonlyMap<string, string>, signal: AbortSignal): Promise<RasterImage>;
474
- }
475
- 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';