@abhishek944/pi-classifier 0.2.0 → 0.4.0

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 (57) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/COMPUTER_USE.md +117 -0
  3. package/README.md +268 -8
  4. package/dist/box-tool.d.ts +26 -0
  5. package/dist/box-tool.js +109 -0
  6. package/dist/box.d.ts +32 -0
  7. package/dist/box.js +148 -0
  8. package/dist/choices.d.ts +8 -0
  9. package/dist/choices.js +131 -0
  10. package/dist/classification-tree.d.ts +4 -0
  11. package/dist/classification-tree.js +143 -0
  12. package/dist/classify.d.ts +4 -2
  13. package/dist/classify.js +5 -2
  14. package/dist/computer-use-state.d.ts +9 -0
  15. package/dist/computer-use-state.js +160 -0
  16. package/dist/computer-use-tool.d.ts +52 -0
  17. package/dist/computer-use-tool.js +78 -0
  18. package/dist/computer-use-types.d.ts +132 -0
  19. package/dist/computer-use-types.js +1 -0
  20. package/dist/computer-use.d.ts +22 -0
  21. package/dist/computer-use.js +223 -0
  22. package/dist/config.js +44 -0
  23. package/dist/cost.d.ts +8 -0
  24. package/dist/cost.js +202 -0
  25. package/dist/extension.d.ts +164 -9
  26. package/dist/extension.js +164 -14
  27. package/dist/image-content.d.ts +12 -0
  28. package/dist/image-content.js +90 -0
  29. package/dist/index.d.ts +9 -1
  30. package/dist/index.js +3 -0
  31. package/dist/inputs.d.ts +11 -2
  32. package/dist/inputs.js +155 -131
  33. package/dist/providers.js +113 -100
  34. package/dist/tree.d.ts +4 -0
  35. package/dist/tree.js +136 -0
  36. package/dist/types.d.ts +113 -11
  37. package/dist/validation.js +63 -39
  38. package/package.json +2 -1
  39. package/src/box-tool.ts +145 -0
  40. package/src/box.ts +253 -0
  41. package/src/choices.ts +174 -0
  42. package/src/classification-tree.ts +181 -0
  43. package/src/classify.ts +16 -4
  44. package/src/computer-use-state.ts +145 -0
  45. package/src/computer-use-tool.ts +76 -0
  46. package/src/computer-use-types.ts +127 -0
  47. package/src/computer-use.ts +216 -0
  48. package/src/config.ts +55 -0
  49. package/src/cost.ts +250 -0
  50. package/src/extension.ts +191 -15
  51. package/src/image-content.ts +77 -0
  52. package/src/index.ts +18 -0
  53. package/src/inputs.ts +163 -185
  54. package/src/providers.ts +113 -119
  55. package/src/tree.ts +157 -0
  56. package/src/types.ts +117 -10
  57. package/src/validation.ts +62 -95
@@ -4,24 +4,46 @@ export declare const classifyParameters: Type.TObject<{
4
4
  state: Type.TUnion<[Type.TString, Type.TRecord<"^.*$", Type.TUnknown>, Type.TArray<Type.TUnknown>]>;
5
5
  questions: Type.TRecord<"^.*$", Type.TUnion<[Type.TObject<{
6
6
  type: Type.TLiteral<"bool">;
7
- instructions: Type.TString;
7
+ instructions: Type.TUnion<[Type.TString, Type.TArray<Type.TUnion<[Type.TString, Type.TObject<{
8
+ $image: Type.TString;
9
+ }>]>>]>;
8
10
  criteria: Type.TOptional<Type.TObject<{
9
- true: Type.TOptional<Type.TString>;
10
- false: Type.TOptional<Type.TString>;
11
+ true: Type.TOptional<Type.TUnion<[Type.TString, Type.TArray<Type.TUnion<[Type.TString, Type.TObject<{
12
+ $image: Type.TString;
13
+ }>]>>]>>;
14
+ false: Type.TOptional<Type.TUnion<[Type.TString, Type.TArray<Type.TUnion<[Type.TString, Type.TObject<{
15
+ $image: Type.TString;
16
+ }>]>>]>>;
11
17
  }>>;
12
18
  }>, Type.TObject<{
13
19
  type: Type.TLiteral<"choice">;
14
- instructions: Type.TString;
15
- criteria: Type.TRecord<"^.*$", Type.TString>;
20
+ instructions: Type.TUnion<[Type.TString, Type.TArray<Type.TUnion<[Type.TString, Type.TObject<{
21
+ $image: Type.TString;
22
+ }>]>>]>;
23
+ criteria: Type.TRecord<"^.*$", Type.TUnion<[Type.TString, Type.TArray<Type.TUnion<[Type.TString, Type.TObject<{
24
+ $image: Type.TString;
25
+ }>]>>]>>;
16
26
  }>, Type.TObject<{
17
27
  type: Type.TLiteral<"score">;
18
- instructions: Type.TString;
19
- criteria: Type.TArray<Type.TString>;
28
+ instructions: Type.TUnion<[Type.TString, Type.TArray<Type.TUnion<[Type.TString, Type.TObject<{
29
+ $image: Type.TString;
30
+ }>]>>]>;
31
+ criteria: Type.TArray<Type.TUnion<[Type.TString, Type.TArray<Type.TUnion<[Type.TString, Type.TObject<{
32
+ $image: Type.TString;
33
+ }>]>>]>>;
20
34
  }>, Type.TObject<{
21
35
  type: Type.TLiteral<"box">;
22
- instructions: Type.TString;
36
+ instructions: Type.TUnion<[Type.TString, Type.TArray<Type.TUnion<[Type.TString, Type.TObject<{
37
+ $image: Type.TString;
38
+ }>]>>]>;
23
39
  }>]>>;
24
- images: Type.TOptional<Type.TArray<Type.TString>>;
40
+ images: Type.TOptional<Type.TArray<Type.TUnion<[Type.TString, Type.TObject<{
41
+ id: Type.TString;
42
+ path: Type.TString;
43
+ }>, Type.TObject<{
44
+ id: Type.TString;
45
+ url: Type.TString;
46
+ }>]>>>;
25
47
  }>;
26
48
  export declare const classifyOutput: Type.TObject<{
27
49
  provider: Type.TString;
@@ -34,6 +56,8 @@ export declare const classifyOutput: Type.TObject<{
34
56
  choice: Type.TString;
35
57
  probabilities: Type.TRecord<"^.*$", Type.TNumber>;
36
58
  confidence: Type.TNumber;
59
+ probabilityScope: Type.TOptional<Type.TLiteral<"batch">>;
60
+ noneOfAboveProbability: Type.TOptional<Type.TNumber>;
37
61
  }>, Type.TObject<{
38
62
  type: Type.TLiteral<"score">;
39
63
  score: Type.TNumber;
@@ -50,12 +74,44 @@ export declare const classifyOutput: Type.TObject<{
50
74
  confidence: Type.TNumber;
51
75
  }>, Type.TObject<{
52
76
  type: Type.TLiteral<"refusal">;
77
+ }>, Type.TObject<{
78
+ type: Type.TLiteral<"no_match">;
79
+ }>, Type.TObject<{
80
+ type: Type.TLiteral<"ambiguous">;
53
81
  }>]>>;
82
+ providerCalls: Type.TOptional<Type.TInteger>;
54
83
  usage: Type.TOptional<Type.TObject<{
55
84
  inputTokens: Type.TNumber;
56
85
  outputTokens: Type.TNumber;
57
86
  totalTokens: Type.TNumber;
87
+ cachedInputTokens: Type.TOptional<Type.TNumber>;
88
+ cacheWriteTokens: Type.TOptional<Type.TNumber>;
58
89
  }>>;
90
+ cost: Type.TUnion<[Type.TObject<{
91
+ status: Type.TLiteral<"estimated">;
92
+ currency: Type.TLiteral<"USD">;
93
+ input: Type.TNumber;
94
+ output: Type.TNumber;
95
+ total: Type.TNumber;
96
+ source: Type.TUnion<[Type.TLiteral<"builtin">, Type.TLiteral<"configured">]>;
97
+ rates: Type.TObject<{
98
+ inputPerMillion: Type.TNumber;
99
+ outputPerMillion: Type.TNumber;
100
+ cachedInputPerMillion: Type.TOptional<Type.TNumber>;
101
+ cacheWritePerMillion: Type.TOptional<Type.TNumber>;
102
+ }>;
103
+ }>, Type.TObject<{
104
+ status: Type.TLiteral<"estimated">;
105
+ currency: Type.TLiteral<"USD">;
106
+ input: Type.TNumber;
107
+ output: Type.TNumber;
108
+ total: Type.TNumber;
109
+ source: Type.TLiteral<"aggregated">;
110
+ }>, Type.TObject<{
111
+ status: Type.TLiteral<"unavailable">;
112
+ currency: Type.TLiteral<"USD">;
113
+ reason: Type.TUnion<[Type.TLiteral<"unknown_pricing">, Type.TLiteral<"missing_usage">, Type.TLiteral<"invalid_usage">, Type.TLiteral<"missing_cache_pricing">, Type.TLiteral<"calculation_overflow">]>;
114
+ }>]>;
59
115
  requestId: Type.TOptional<Type.TString>;
60
116
  attemptedRoutes: Type.TOptional<Type.TArray<Type.TObject<{
61
117
  provider: Type.TString;
@@ -80,6 +136,8 @@ export declare const classifyCompareOutput: Type.TObject<{
80
136
  choice: Type.TString;
81
137
  probabilities: Type.TRecord<"^.*$", Type.TNumber>;
82
138
  confidence: Type.TNumber;
139
+ probabilityScope: Type.TOptional<Type.TLiteral<"batch">>;
140
+ noneOfAboveProbability: Type.TOptional<Type.TNumber>;
83
141
  }>, Type.TObject<{
84
142
  type: Type.TLiteral<"score">;
85
143
  score: Type.TNumber;
@@ -96,12 +154,44 @@ export declare const classifyCompareOutput: Type.TObject<{
96
154
  confidence: Type.TNumber;
97
155
  }>, Type.TObject<{
98
156
  type: Type.TLiteral<"refusal">;
157
+ }>, Type.TObject<{
158
+ type: Type.TLiteral<"no_match">;
159
+ }>, Type.TObject<{
160
+ type: Type.TLiteral<"ambiguous">;
99
161
  }>]>>;
162
+ providerCalls: Type.TOptional<Type.TInteger>;
100
163
  usage: Type.TOptional<Type.TObject<{
101
164
  inputTokens: Type.TNumber;
102
165
  outputTokens: Type.TNumber;
103
166
  totalTokens: Type.TNumber;
167
+ cachedInputTokens: Type.TOptional<Type.TNumber>;
168
+ cacheWriteTokens: Type.TOptional<Type.TNumber>;
104
169
  }>>;
170
+ cost: Type.TUnion<[Type.TObject<{
171
+ status: Type.TLiteral<"estimated">;
172
+ currency: Type.TLiteral<"USD">;
173
+ input: Type.TNumber;
174
+ output: Type.TNumber;
175
+ total: Type.TNumber;
176
+ source: Type.TUnion<[Type.TLiteral<"builtin">, Type.TLiteral<"configured">]>;
177
+ rates: Type.TObject<{
178
+ inputPerMillion: Type.TNumber;
179
+ outputPerMillion: Type.TNumber;
180
+ cachedInputPerMillion: Type.TOptional<Type.TNumber>;
181
+ cacheWritePerMillion: Type.TOptional<Type.TNumber>;
182
+ }>;
183
+ }>, Type.TObject<{
184
+ status: Type.TLiteral<"estimated">;
185
+ currency: Type.TLiteral<"USD">;
186
+ input: Type.TNumber;
187
+ output: Type.TNumber;
188
+ total: Type.TNumber;
189
+ source: Type.TLiteral<"aggregated">;
190
+ }>, Type.TObject<{
191
+ status: Type.TLiteral<"unavailable">;
192
+ currency: Type.TLiteral<"USD">;
193
+ reason: Type.TUnion<[Type.TLiteral<"unknown_pricing">, Type.TLiteral<"missing_usage">, Type.TLiteral<"invalid_usage">, Type.TLiteral<"missing_cache_pricing">, Type.TLiteral<"calculation_overflow">]>;
194
+ }>]>;
105
195
  requestId: Type.TOptional<Type.TString>;
106
196
  attemptedRoutes: Type.TOptional<Type.TArray<Type.TObject<{
107
197
  provider: Type.TString;
@@ -119,4 +209,69 @@ export declare const classifyCompareOutput: Type.TObject<{
119
209
  }>;
120
210
  }>]>>;
121
211
  }>;
212
+ export declare const classifyTreeParameters: Type.TObject<{
213
+ state: Type.TUnion<[Type.TString, Type.TRecord<"^.*$", Type.TUnknown>, Type.TArray<Type.TUnknown>]>;
214
+ tree: Type.TUnion<[Type.TString, Type.TObject<{
215
+ roots: Type.TArray<Type.TRef<"#/$defs/ClassificationTreeNode">>;
216
+ }>]>;
217
+ instructions: Type.TOptional<Type.TString>;
218
+ images: Type.TOptional<Type.TArray<Type.TUnion<[Type.TString, Type.TObject<{
219
+ id: Type.TString;
220
+ path: Type.TString;
221
+ }>, Type.TObject<{
222
+ id: Type.TString;
223
+ url: Type.TString;
224
+ }>]>>>;
225
+ }>;
226
+ export declare const classifyTreeOutput: Type.TObject<{
227
+ provider: Type.TString;
228
+ model: Type.TString;
229
+ status: Type.TUnion<[Type.TLiteral<"complete">, Type.TLiteral<"no_match">, Type.TLiteral<"ambiguous">, Type.TLiteral<"refusal">]>;
230
+ levels: Type.TRecord<"^.*$", Type.TString>;
231
+ steps: Type.TArray<Type.TObject<{
232
+ level: Type.TInteger;
233
+ id: Type.TString;
234
+ source: Type.TUnion<[Type.TLiteral<"automatic">, Type.TLiteral<"model">]>;
235
+ confidence: Type.TOptional<Type.TNumber>;
236
+ probabilityScope: Type.TOptional<Type.TUnion<[Type.TLiteral<"siblings">, Type.TLiteral<"batch">]>>;
237
+ noneOfAboveProbability: Type.TOptional<Type.TNumber>;
238
+ }>>;
239
+ providerCalls: Type.TInteger;
240
+ cost: Type.TUnion<[Type.TObject<{
241
+ status: Type.TLiteral<"estimated">;
242
+ currency: Type.TLiteral<"USD">;
243
+ input: Type.TNumber;
244
+ output: Type.TNumber;
245
+ total: Type.TNumber;
246
+ source: Type.TUnion<[Type.TLiteral<"builtin">, Type.TLiteral<"configured">]>;
247
+ rates: Type.TObject<{
248
+ inputPerMillion: Type.TNumber;
249
+ outputPerMillion: Type.TNumber;
250
+ cachedInputPerMillion: Type.TOptional<Type.TNumber>;
251
+ cacheWritePerMillion: Type.TOptional<Type.TNumber>;
252
+ }>;
253
+ }>, Type.TObject<{
254
+ status: Type.TLiteral<"estimated">;
255
+ currency: Type.TLiteral<"USD">;
256
+ input: Type.TNumber;
257
+ output: Type.TNumber;
258
+ total: Type.TNumber;
259
+ source: Type.TLiteral<"aggregated">;
260
+ }>, Type.TObject<{
261
+ status: Type.TLiteral<"unavailable">;
262
+ currency: Type.TLiteral<"USD">;
263
+ reason: Type.TUnion<[Type.TLiteral<"unknown_pricing">, Type.TLiteral<"missing_usage">, Type.TLiteral<"invalid_usage">, Type.TLiteral<"missing_cache_pricing">, Type.TLiteral<"calculation_overflow">]>;
264
+ }>]>;
265
+ usage: Type.TOptional<Type.TObject<{
266
+ inputTokens: Type.TNumber;
267
+ outputTokens: Type.TNumber;
268
+ totalTokens: Type.TNumber;
269
+ cachedInputTokens: Type.TOptional<Type.TNumber>;
270
+ cacheWriteTokens: Type.TOptional<Type.TNumber>;
271
+ }>>;
272
+ attemptedRoutes: Type.TOptional<Type.TArray<Type.TObject<{
273
+ provider: Type.TString;
274
+ model: Type.TString;
275
+ }>>>;
276
+ }>;
122
277
  export default function piClassifier(pi: ExtensionAPI): void;
package/dist/extension.js CHANGED
@@ -2,32 +2,46 @@ import { isProjectTrusted } from "@amaster.ai/pi-shared/settings";
2
2
  import { defineTool, } from "@earendil-works/pi-coding-agent";
3
3
  import { Type } from "typebox";
4
4
  import { classify, compareClassifiers } from "./classify.js";
5
+ import { classifyTree } from "./tree.js";
6
+ import { registerBoxTool } from "./box-tool.js";
7
+ import { registerComputerUseTool } from "./computer-use-tool.js";
5
8
  import { configuredRoutes, listModels, loadClassifierSettings, resolveModel, } from "./config.js";
6
9
  import { updateProjectClassifierSettings } from "./settings-write.js";
7
10
  import { ClassifierError, userError } from "./types.js";
8
- const shortText = Type.String({ maxLength: 4096 });
11
+ const imageReference = Type.Object({ $image: Type.String({ pattern: "^[a-zA-Z0-9_-]{1,64}$" }) }, { additionalProperties: false });
12
+ function imageContent(maxLength, nonempty = false) {
13
+ return Type.Union([
14
+ Type.String({ maxLength, ...(nonempty ? { minLength: 1 } : {}) }),
15
+ Type.Array(Type.Union([Type.String({ maxLength }), imageReference]), {
16
+ minItems: 1, maxItems: 128,
17
+ description: "Ordered text and explicit {$image:id} references. References require named images; supported placements depend on the route.",
18
+ }),
19
+ ]);
20
+ }
21
+ const shortText = imageContent(4096);
22
+ const instructionContent = imageContent(16384, true);
9
23
  const question = Type.Union([
10
24
  Type.Object({
11
25
  type: Type.Literal("bool"),
12
- instructions: Type.String({ minLength: 1, maxLength: 16384 }),
26
+ instructions: instructionContent,
13
27
  criteria: Type.Optional(Type.Object({ true: Type.Optional(shortText), false: Type.Optional(shortText) }, { additionalProperties: false })),
14
28
  }, { additionalProperties: false }),
15
29
  Type.Object({
16
30
  type: Type.Literal("choice"),
17
- instructions: Type.String({ minLength: 1, maxLength: 16384 }),
18
- criteria: Type.Record(Type.String({ minLength: 1, maxLength: 128 }), shortText, { minProperties: 1, maxProperties: 64 }),
31
+ instructions: instructionContent,
32
+ criteria: Type.Record(Type.String({ minLength: 1, maxLength: 128 }), shortText, { minProperties: 1 }),
19
33
  }, { additionalProperties: false }),
20
34
  Type.Object({
21
35
  type: Type.Literal("score"),
22
- instructions: Type.String({ minLength: 1, maxLength: 16384 }),
23
- criteria: Type.Array(Type.String({ minLength: 1, maxLength: 4096 }), {
36
+ instructions: instructionContent,
37
+ criteria: Type.Array(imageContent(4096, true), {
24
38
  minItems: 2,
25
39
  maxItems: 10,
26
40
  }),
27
41
  }, { additionalProperties: false }),
28
42
  Type.Object({
29
43
  type: Type.Literal("box"),
30
- instructions: Type.String({ minLength: 1, maxLength: 16384 }),
44
+ instructions: instructionContent,
31
45
  }, { additionalProperties: false }),
32
46
  ]);
33
47
  export const classifyParameters = Type.Object({
@@ -36,14 +50,30 @@ export const classifyParameters = Type.Object({
36
50
  Type.Record(Type.String(), Type.Unknown()),
37
51
  Type.Array(Type.Unknown()),
38
52
  ], {
39
- description: "Text or JSON data to classify. All questions refer to this same state.",
53
+ description: "Text or JSON data to classify. Use explicit {$image:id} objects to place named images in state on Jev, OpenAI or Perplexity. Other JSON remains data. All questions refer to this same state.",
40
54
  }),
41
55
  questions: Type.Record(Type.String({ pattern: "^[a-zA-Z0-9_-]{1,64}$" }), question, { minProperties: 1, maxProperties: 32 }),
42
- images: Type.Optional(Type.Array(Type.String({ minLength: 1, maxLength: 4096 }), {
43
- maxItems: 5,
44
- description: "Local PNG/JPEG/WebP files inside cwd, in order. No URLs, symlinks or inline base64. Requires an image-capable model.",
56
+ images: Type.Optional(Type.Array(Type.Union([
57
+ Type.String({ minLength: 1, maxLength: 4096 }),
58
+ Type.Object({
59
+ id: Type.String({ pattern: "^[a-zA-Z0-9_-]{1,64}$" }),
60
+ path: Type.String({ minLength: 1, maxLength: 4096 }),
61
+ }, { additionalProperties: false }),
62
+ Type.Object({
63
+ id: Type.String({ pattern: "^[a-zA-Z0-9_-]{1,64}$" }),
64
+ url: Type.String({ minLength: 1, maxLength: 4096 }),
65
+ }, { additionalProperties: false }),
66
+ ]), {
67
+ maxItems: 8,
68
+ description: "Legacy local paths are shared in order. Named {id,path} or {id,url} images must be referenced using {$image:id} in state or supported question content. URLs are OpenAI-only and sent to the provider, never fetched locally. No inline base64 or symlinks. Limits: Perplexity 8 images, Clef 4, others 5.",
45
69
  })),
46
70
  }, { additionalProperties: false });
71
+ const tokenPricing = Type.Object({
72
+ inputPerMillion: Type.Number({ minimum: 0 }),
73
+ outputPerMillion: Type.Number({ minimum: 0 }),
74
+ cachedInputPerMillion: Type.Optional(Type.Number({ minimum: 0 })),
75
+ cacheWritePerMillion: Type.Optional(Type.Number({ minimum: 0 })),
76
+ });
47
77
  export const classifyOutput = Type.Object({
48
78
  provider: Type.String(),
49
79
  model: Type.String(),
@@ -57,6 +87,8 @@ export const classifyOutput = Type.Object({
57
87
  choice: Type.String(),
58
88
  probabilities: Type.Record(Type.String(), Type.Number({ minimum: 0, maximum: 1 })),
59
89
  confidence: Type.Number({ minimum: 0, maximum: 1 }),
90
+ probabilityScope: Type.Optional(Type.Literal("batch")),
91
+ noneOfAboveProbability: Type.Optional(Type.Number({ minimum: 0, maximum: 1 })),
60
92
  }),
61
93
  Type.Object({
62
94
  type: Type.Literal("score"),
@@ -75,12 +107,47 @@ export const classifyOutput = Type.Object({
75
107
  confidence: Type.Number({ minimum: 0, maximum: 1 }),
76
108
  }),
77
109
  Type.Object({ type: Type.Literal("refusal") }),
110
+ Type.Object({ type: Type.Literal("no_match") }),
111
+ Type.Object({ type: Type.Literal("ambiguous") }),
78
112
  ])),
113
+ providerCalls: Type.Optional(Type.Integer({ minimum: 1 })),
79
114
  usage: Type.Optional(Type.Object({
80
115
  inputTokens: Type.Number(),
81
116
  outputTokens: Type.Number(),
82
117
  totalTokens: Type.Number(),
118
+ cachedInputTokens: Type.Optional(Type.Number()),
119
+ cacheWriteTokens: Type.Optional(Type.Number()),
83
120
  })),
121
+ cost: Type.Union([
122
+ Type.Object({
123
+ status: Type.Literal("estimated"),
124
+ currency: Type.Literal("USD"),
125
+ input: Type.Number({ minimum: 0 }),
126
+ output: Type.Number({ minimum: 0 }),
127
+ total: Type.Number({ minimum: 0 }),
128
+ source: Type.Union([Type.Literal("builtin"), Type.Literal("configured")]),
129
+ rates: tokenPricing,
130
+ }),
131
+ Type.Object({
132
+ status: Type.Literal("estimated"),
133
+ currency: Type.Literal("USD"),
134
+ input: Type.Number({ minimum: 0 }),
135
+ output: Type.Number({ minimum: 0 }),
136
+ total: Type.Number({ minimum: 0 }),
137
+ source: Type.Literal("aggregated"),
138
+ }),
139
+ Type.Object({
140
+ status: Type.Literal("unavailable"),
141
+ currency: Type.Literal("USD"),
142
+ reason: Type.Union([
143
+ Type.Literal("unknown_pricing"),
144
+ Type.Literal("missing_usage"),
145
+ Type.Literal("invalid_usage"),
146
+ Type.Literal("missing_cache_pricing"),
147
+ Type.Literal("calculation_overflow"),
148
+ ]),
149
+ }),
150
+ ]),
84
151
  requestId: Type.Optional(Type.String()),
85
152
  attemptedRoutes: Type.Optional(Type.Array(Type.Object({ provider: Type.String(), model: Type.String() }))),
86
153
  });
@@ -103,15 +170,59 @@ export const classifyCompareOutput = Type.Object({
103
170
  }),
104
171
  ])),
105
172
  });
173
+ const classificationTreeNode = Type.Object({
174
+ id: Type.String({ minLength: 1, maxLength: 128 }),
175
+ description: Type.Optional(Type.String({ maxLength: 4096 })),
176
+ children: Type.Optional(Type.Array(Type.Ref("#/$defs/ClassificationTreeNode"))),
177
+ }, { additionalProperties: false });
178
+ export const classifyTreeParameters = Type.Object({
179
+ state: classifyParameters.properties.state,
180
+ tree: Type.Union([
181
+ Type.String({
182
+ minLength: 1,
183
+ maxLength: 4096,
184
+ description: "Local UTF-8 JSON file inside cwd; no URLs or symlinks.",
185
+ }),
186
+ Type.Object({ roots: Type.Array(Type.Ref("#/$defs/ClassificationTreeNode"), { minItems: 1 }) }, { additionalProperties: false }),
187
+ ]),
188
+ instructions: Type.Optional(Type.String({ minLength: 1, maxLength: 8192 })),
189
+ images: classifyParameters.properties.images,
190
+ }, { additionalProperties: false, $defs: { ClassificationTreeNode: classificationTreeNode } });
191
+ export const classifyTreeOutput = Type.Object({
192
+ provider: Type.String(),
193
+ model: Type.String(),
194
+ status: Type.Union([
195
+ Type.Literal("complete"),
196
+ Type.Literal("no_match"),
197
+ Type.Literal("ambiguous"),
198
+ Type.Literal("refusal"),
199
+ ]),
200
+ levels: Type.Record(Type.String({ pattern: "^Level[1-9][0-9]*$" }), Type.String()),
201
+ steps: Type.Array(Type.Object({
202
+ level: Type.Integer({ minimum: 1 }),
203
+ id: Type.String(),
204
+ source: Type.Union([Type.Literal("automatic"), Type.Literal("model")]),
205
+ confidence: Type.Optional(Type.Number({ minimum: 0, maximum: 1 })),
206
+ probabilityScope: Type.Optional(Type.Union([Type.Literal("siblings"), Type.Literal("batch")])),
207
+ noneOfAboveProbability: Type.Optional(Type.Number({ minimum: 0, maximum: 1 })),
208
+ })),
209
+ providerCalls: Type.Integer({ minimum: 0 }),
210
+ cost: classifyOutput.properties.cost,
211
+ usage: classifyOutput.properties.usage,
212
+ attemptedRoutes: classifyOutput.properties.attemptedRoutes,
213
+ });
106
214
  export default function piClassifier(pi) {
215
+ registerBoxTool(pi);
216
+ registerComputerUseTool(pi);
107
217
  pi.registerTool(defineTool({
108
218
  name: "classify",
109
219
  label: "Classify",
110
- description: "Ask a decision model typed questions about text, JSON and supported local images. Returns bool probabilities, choices with probabilities, or scores. Experimental box answers require explicit Jev configuration. Provider/model are fixed by pi-classifier.default (or legacy defaultProvider/defaultModel); this tool cannot override them. API-key authentication is independent of Codex chat login. Only explicitly configured fallback routes may be used after a missing key or HTTP 401/404/429; never after uncertainty, refusals, timeouts or network failures. Use /classifier list or status to inspect configuration.",
220
+ description: "Ask a decision model typed questions about text, JSON and supported images. Legacy image paths are shared; named path/url descriptors require explicit {$image:id} references. Jev supports images in instructions/criteria; OpenAI supports instruction images and hosted URLs. Unsupported placements fail locally. Returns bool probabilities, choices with probabilities, or scores, plus reported token usage and estimated USD cost (or an explicit unavailable reason). Experimental box answers require explicit Jev configuration. Provider/model are fixed by pi-classifier.default (or legacy defaultProvider/defaultModel); this tool cannot override them. API-key authentication is independent of Codex chat login. Only explicitly configured fallback routes may be used after a missing key or HTTP 401/404/429 before any batch has completed; never after uncertainty, refusals, timeouts or network failures. Use /classifier list or status to inspect configuration.",
111
221
  promptSnippet: "Classify text, JSON or supported images into typed probabilistic decisions.",
112
222
  promptGuidelines: [
113
223
  "Use for bounded judgments, classification and rubric scoring, not open-ended prose.",
114
- "Treat low confidence as uncertainty, not permission to switch models or retry.",
224
+ "Treat low confidence as uncertainty, not permission to switch models or retry. Only configured remove_choice_limits with none_of_above_choice permits internal sequential choice batches; this is first-match selection, not a global ranking.",
225
+ "Handle no_match and ambiguous answers explicitly. probabilityScope=batch and noneOfAboveProbability describe only the winning batch; they are not a full-list probability distribution.",
115
226
  "Send only data the user intends to share with the configured provider.",
116
227
  "Ask /classifier status for the active model. Do not change provider settings without user direction.",
117
228
  ],
@@ -145,7 +256,7 @@ export default function piClassifier(pi) {
145
256
  pi.registerTool(defineTool({
146
257
  name: "classify_compare",
147
258
  label: "Compare classifiers",
148
- description: "Explicitly compare the same typed questions and state using exactly pi-classifier.compare provider/model pairs. Each entry is a separate potentially billable request. No fallback, default substitution, provider/model overrides, or default changes. Returns labeled results, duration, usage and safe per-entry failures; cancellation retains completed results and prevents later requests.",
259
+ description: "Explicitly compare the same typed questions and state using exactly pi-classifier.compare provider/model pairs. Each entry makes potentially billable requests, including multiple requests when choice batching is configured. No fallback, default substitution, provider/model overrides, or default changes. Returns labeled results, duration, usage, estimated USD costs (or unavailable reasons) and safe per-entry failures; cancellation retains completed results and prevents later requests.",
149
260
  promptSnippet: "Compare configured decision models only when the user explicitly requests a model comparison.",
150
261
  promptGuidelines: [
151
262
  "Use only when the user explicitly asks to compare classifier models; never use automatically for low confidence or refusals.",
@@ -176,6 +287,42 @@ export default function piClassifier(pi) {
176
287
  }
177
288
  },
178
289
  }));
290
+ pi.registerTool(defineTool({
291
+ name: "classify_tree",
292
+ label: "Classify tree",
293
+ description: "Classify text, JSON or supported images through a nested classification tree. tree is an inline roots/id/description/children object or a local JSON file inside cwd. Choose among siblings, automatically follow sole children without model calls, and return Level1/Level2/etc under levels with per-step provenance, total providerCalls, reported usage and estimated USD cost. NONE, batching and initial fallback follow configured settings; after a successful decision the route is pinned. no_match, ambiguous and refusal retain only the selected prefix. Automatic steps are structural, not model confirmation; greedy traversal is not a global best-path guarantee. No provider/model override or comparison.",
294
+ promptSnippet: "Classify through a supplied classification tree and return the selected levels.",
295
+ promptGuidelines: [
296
+ "Use classify_tree only when the user supplies or requests a classification tree; do not invent category branches.",
297
+ "Use meaningful node descriptions. Only the current siblings and selected parent path are submitted per decision, not every descendant.",
298
+ "Inspect status and steps: automatic steps have no model confidence, and partial paths are not complete classifications.",
299
+ "Configured choice batching may cause multiple billable requests per level. No fallback may replay completed model decisions.",
300
+ ],
301
+ parameters: classifyTreeParameters,
302
+ outputSchema: classifyTreeOutput,
303
+ annotations: {
304
+ readOnlyHint: true,
305
+ destructiveHint: false,
306
+ openWorldHint: true,
307
+ },
308
+ async execute(_id, params, signal, _onUpdate, ctx) {
309
+ try {
310
+ const result = await classifyTree(params, {
311
+ settings: loadClassifierSettings(ctx.cwd, isProjectTrusted(ctx)),
312
+ cwd: ctx.cwd,
313
+ ...(signal ? { signal } : {}),
314
+ });
315
+ return {
316
+ content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
317
+ details: result,
318
+ structuredContent: { ...result },
319
+ };
320
+ }
321
+ catch (error) {
322
+ throw new Error(userError(error));
323
+ }
324
+ },
325
+ }));
179
326
  pi.registerCommand("classifier", {
180
327
  description: "Classifier: status, list, reload, use <route> <model>, compare <JSON params>. Use writes trusted project defaults; compare makes potentially billable calls.",
181
328
  handler: async (args, ctx) => {
@@ -214,6 +361,9 @@ export default function piClassifier(pi) {
214
361
  images: route.images,
215
362
  box: route.box,
216
363
  requestTimeoutMs: route.requestTimeoutMs,
364
+ none_of_above_choice: settings.none_of_above_choice ?? false,
365
+ remove_choice_limits: settings.remove_choice_limits ?? false,
366
+ maxChoicesPerRequest: route.maxChoices ?? "provider-defined",
217
367
  authentication: "API key only; independent of chat login",
218
368
  fallback: configuredRoutes(settings, "fallback"),
219
369
  compare: configuredRoutes(settings, "compare"),
@@ -0,0 +1,12 @@
1
+ import { type ImageReference, type PreparedImage, type Question } from "./types.js";
2
+ export declare function isImageReference(value: unknown): value is ImageReference;
3
+ /** Only explicit reference objects are special; provider-native-looking user JSON stays data. */
4
+ export declare function imageReferences(value: unknown): string[];
5
+ export declare function questionImageReferences(questions: Record<string, Question>): string[];
6
+ export declare function mapImageReferences(value: unknown, image: (id: string) => unknown): unknown;
7
+ export declare function namedImage(images: PreparedImage[], id: string): PreparedImage;
8
+ export declare function imageUrl(image: PreparedImage): string;
9
+ /** Preserve JSON punctuation as text, interleaving only explicitly referenced images.
10
+ * Raw user objects never become provider-native content parts.
11
+ */
12
+ export declare function imageContentParts(value: unknown, image: (id: string) => unknown): unknown[];
@@ -0,0 +1,90 @@
1
+ import { ClassifierError, isRecord } from "./types.js";
2
+ export function isImageReference(value) {
3
+ return isRecord(value) && Object.hasOwn(value, "$image");
4
+ }
5
+ /** Only explicit reference objects are special; provider-native-looking user JSON stays data. */
6
+ export function imageReferences(value) {
7
+ if (isImageReference(value))
8
+ return [value.$image];
9
+ if (Array.isArray(value))
10
+ return value.flatMap(imageReferences);
11
+ if (isRecord(value))
12
+ return Object.values(value).flatMap(imageReferences);
13
+ return [];
14
+ }
15
+ export function questionImageReferences(questions) {
16
+ return Object.values(questions).flatMap((question) => [
17
+ ...imageReferences(question.instructions),
18
+ ...("criteria" in question && question.criteria ? Object.values(question.criteria).flatMap(imageReferences) : []),
19
+ ]);
20
+ }
21
+ export function mapImageReferences(value, image) {
22
+ if (isImageReference(value))
23
+ return image(value.$image);
24
+ if (Array.isArray(value))
25
+ return value.map((entry) => mapImageReferences(entry, image));
26
+ if (isRecord(value))
27
+ return Object.fromEntries(Object.entries(value).map(([key, entry]) => [key, mapImageReferences(entry, image)]));
28
+ return value;
29
+ }
30
+ export function namedImage(images, id) {
31
+ const image = images.find((entry) => entry.id === id);
32
+ if (!image)
33
+ throw new ClassifierError("input", "Unknown named image reference.");
34
+ return image;
35
+ }
36
+ export function imageUrl(image) {
37
+ return "url" in image ? image.url : "data:" + image.mimeType + ";base64," + image.data;
38
+ }
39
+ /** Preserve JSON punctuation as text, interleaving only explicitly referenced images.
40
+ * Raw user objects never become provider-native content parts.
41
+ */
42
+ export function imageContentParts(value, image) {
43
+ const parts = [];
44
+ let text = "";
45
+ const flush = () => { if (text) {
46
+ parts.push(text);
47
+ text = "";
48
+ } };
49
+ const visit = (entry) => {
50
+ if (isImageReference(entry)) {
51
+ flush();
52
+ parts.push(image(entry.$image));
53
+ }
54
+ else if (Array.isArray(entry)) {
55
+ text += "[";
56
+ entry.forEach((child, i) => { if (i)
57
+ text += ","; visit(child); });
58
+ text += "]";
59
+ }
60
+ else if (isRecord(entry)) {
61
+ text += "{";
62
+ Object.entries(entry).forEach(([key, child], i) => {
63
+ if (i)
64
+ text += ",";
65
+ text += JSON.stringify(key) + ":";
66
+ visit(child);
67
+ });
68
+ text += "}";
69
+ }
70
+ else
71
+ text += JSON.stringify(entry);
72
+ };
73
+ // Ordered content arrays are convenient for instructions and simple multimodal state.
74
+ if (Array.isArray(value) && value.every((entry) => typeof entry === "string" || isImageReference(entry))) {
75
+ for (const entry of value) {
76
+ if (typeof entry === "string")
77
+ text += entry;
78
+ else {
79
+ flush();
80
+ parts.push(image(entry.$image));
81
+ }
82
+ }
83
+ }
84
+ else if (typeof value === "string")
85
+ text = value;
86
+ else
87
+ visit(value);
88
+ flush();
89
+ return parts;
90
+ }
package/dist/index.d.ts CHANGED
@@ -1,4 +1,12 @@
1
1
  export { classify, compareClassifiers } from "./classify.js";
2
+ export type { ClassifyOptions } from "./classify.js";
3
+ export type { MemoryImage } from "./inputs.js";
4
+ export { runComputerUse } from "./computer-use.js";
5
+ export type { ComputerUseOptions } from "./computer-use.js";
6
+ export type { ComputerUseParams, ComputerUseResult, ComputerUseSettings, ComputerControl, ComputerExpectation, DriverCall, DriverReply } from "./computer-use-types.js";
7
+ export { classifyTree } from "./tree.js";
8
+ export { renderClassifierBox } from "./box.js";
9
+ export type { ClassifierBoxMode, ClassifierBoxEdges, ClassifierBoxPixelBox, ClassifierBoxResult } from "./box.js";
2
10
  export { loadClassifierSettings, resolveModel, listModels } from "./config.js";
3
- export type { Answer, Question, ClassifierResult, ClassifierRoute, ClassifierComparisonEntry, ClassifierComparisonResult, ClassifierSettings, ClassifyParams, CustomProviderSettings, ModelDefinition, ProviderSettings, ApiStyle, } from "./types.js";
11
+ export type { Answer, Question, QuestionContent, ImageInput, ImageReference, ClassifierResult, ClassifierCost, TokenPricing, ClassifierRoute, ClassifierComparisonEntry, ClassifierComparisonResult, ClassifierSettings, ClassifyParams, ClassifyTreeParams, ClassifierTreeResult, ClassificationTree, ClassificationTreeNode, TreeStep, CustomProviderSettings, ModelDefinition, ProviderSettings, ApiStyle, } from "./types.js";
4
12
  export { ClassifierError } from "./types.js";
package/dist/index.js CHANGED
@@ -1,3 +1,6 @@
1
1
  export { classify, compareClassifiers } from "./classify.js";
2
+ export { runComputerUse } from "./computer-use.js";
3
+ export { classifyTree } from "./tree.js";
4
+ export { renderClassifierBox } from "./box.js";
2
5
  export { loadClassifierSettings, resolveModel, listModels } from "./config.js";
3
6
  export { ClassifierError } from "./types.js";
package/dist/inputs.d.ts CHANGED
@@ -1,2 +1,11 @@
1
- import { type ClassifyParams, type PreparedInput, type ResolvedModel } from "./types.js";
2
- export declare function prepareInput(params: ClassifyParams, route: ResolvedModel, cwd: string, signal?: AbortSignal): Promise<PreparedInput>;
1
+ import { type ClassifyParams, type PreparedLocalImage, type PreparedInput, type ResolvedModel } from "./types.js";
2
+ /** Programmatic image ingress. Never accepted as model-facing tool arguments. */
3
+ export interface MemoryImage {
4
+ bytes: Uint8Array;
5
+ mimeType: "image/png" | "image/jpeg" | "image/webp";
6
+ }
7
+ export declare function prepareInput(params: ClassifyParams, route: ResolvedModel, cwd: string, signal?: AbortSignal, memoryImages?: readonly MemoryImage[]): Promise<PreparedInput>;
8
+ /** Bounded, fully decoded local image; shared by uploads and local box rendering. */
9
+ export declare function loadLocalImage(path: string, cwd: string, signal?: AbortSignal, maxBytes?: number): Promise<PreparedLocalImage>;
10
+ /** Verify containment of the opened descriptor, not a raceable pre-open path. */
11
+ export declare function verifyOpenedPath(fd: number, root: string, signal?: AbortSignal): Promise<void>;