@abhishek944/pi-classifier 0.5.1 → 0.7.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.
- package/CHANGELOG.md +14 -0
- package/README.md +150 -41
- package/dist/choices.js +1 -1
- package/dist/classify.d.ts +9 -1
- package/dist/classify.js +24 -10
- package/dist/config.d.ts +48 -2
- package/dist/config.js +90 -6
- package/dist/cost.js +23 -2
- package/dist/extension.js +7 -5
- package/dist/extract.d.ts +5 -1
- package/dist/extract.js +190 -3
- package/dist/index.d.ts +1 -1
- package/dist/inputs.d.ts +2 -2
- package/dist/inputs.js +47 -14
- package/dist/providers.js +62 -0
- package/dist/tool-contracts.d.ts +101 -226
- package/dist/tool-contracts.js +61 -116
- package/dist/types.d.ts +42 -8
- package/dist/validation.d.ts +8 -1
- package/dist/validation.js +158 -125
- package/package.json +3 -2
- package/src/choices.ts +1 -1
- package/src/classify.ts +44 -15
- package/src/config.ts +93 -6
- package/src/cost.ts +24 -2
- package/src/extension.ts +7 -5
- package/src/extract.ts +194 -5
- package/src/index.ts +3 -0
- package/src/inputs.ts +51 -18
- package/src/providers.ts +108 -0
- package/src/tool-contracts.ts +107 -150
- package/src/types.ts +46 -7
- package/src/validation.ts +142 -105
package/dist/tool-contracts.js
CHANGED
|
@@ -9,10 +9,10 @@ export const CLASSIFY_TOOL = "classify";
|
|
|
9
9
|
export const CLASSIFY_COMPARE_TOOL = "classify_compare";
|
|
10
10
|
export const CLASSIFY_TREE_TOOL = "classify_tree";
|
|
11
11
|
export const CLASSIFIER_BOX_TOOL = "classifier_box_image";
|
|
12
|
-
export const CLASSIFY_TOOL_DESCRIPTION = "Ask a decision model
|
|
13
|
-
export const CLASSIFY_COMPARE_TOOL_DESCRIPTION = "Explicitly compare the same
|
|
12
|
+
export const CLASSIFY_TOOL_DESCRIPTION = "Ask a decision model classification questions about text, JSON, images and supported audio/video: yes/no (bool), category (choice), multi-choice (multiple labels) and score. Extraction reads (text, numbers, dates, passages, box/boxes locations, locate offsets, estimates, Inception extract) are not classification and are rejected here; send the same question to classify_extract. 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, multi-choice probabilities and scores, plus reported token usage and estimated USD cost (or an explicit unavailable reason). mode: web_grounding is an explicit Perplexity opt-in that sends question text and the start of state to web search and adds billed searches/fetches; cost.nonToken reports the documented fees. 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.";
|
|
13
|
+
export const CLASSIFY_COMPARE_TOOL_DESCRIPTION = "Explicitly compare the same classification 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.";
|
|
14
14
|
export const CLASSIFY_TREE_TOOL_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.";
|
|
15
|
-
export const CLASSIFIER_BOX_TOOL_DESCRIPTION = "Render a normalized bounding box on a local image, or crop to it, entirely locally. Use to inspect a box
|
|
15
|
+
export const CLASSIFIER_BOX_TOOL_DESCRIPTION = "Render a normalized bounding box on a local image, or crop to it, entirely locally. Use to inspect a box value returned by classify_extract. overlay keeps the image and draws a rectangle; crop returns only the clamped region. Returns a PNG plus exact source-pixel box metadata. No provider request, upload, resizing or disk write. A box is a localization hint, not proof that the object exists.";
|
|
16
16
|
const imageReference = Type.Object({ $image: Type.String({ pattern: "^[a-zA-Z0-9_-]{1,64}$" }) }, { additionalProperties: false });
|
|
17
17
|
function imageContent(maxLength, nonempty = false) {
|
|
18
18
|
return Type.Union([
|
|
@@ -26,25 +26,8 @@ function imageContent(maxLength, nonempty = false) {
|
|
|
26
26
|
}
|
|
27
27
|
const shortText = imageContent(4096);
|
|
28
28
|
const instructionContent = imageContent(16384, true);
|
|
29
|
-
const charSpan = Type.Tuple([
|
|
30
|
-
Type.Integer({ minimum: 0 }),
|
|
31
|
-
Type.Integer({ minimum: 0 }),
|
|
32
|
-
]);
|
|
33
29
|
// Numeric estimation ranges may be negative or fractional; they are not text offsets.
|
|
34
30
|
const numericRange = Type.Tuple([Type.Number(), Type.Number()]);
|
|
35
|
-
const boxEdges = Type.Object({
|
|
36
|
-
top: Type.Number(),
|
|
37
|
-
bottom: Type.Number(),
|
|
38
|
-
left: Type.Number(),
|
|
39
|
-
right: Type.Number(),
|
|
40
|
-
}, { additionalProperties: false });
|
|
41
|
-
const textSpan = Type.Object({
|
|
42
|
-
start: Type.Integer({ minimum: 0 }),
|
|
43
|
-
end: Type.Integer({ minimum: 0 }),
|
|
44
|
-
text: Type.String(),
|
|
45
|
-
score: Type.Number({ minimum: 0, maximum: 1 }),
|
|
46
|
-
searchResult: Type.Optional(Type.Integer({ minimum: 0 })),
|
|
47
|
-
}, { additionalProperties: false });
|
|
48
31
|
const webSearchResult = Type.Object({
|
|
49
32
|
title: Type.String(),
|
|
50
33
|
url: Type.String(),
|
|
@@ -65,27 +48,7 @@ const nonTokenCost = Type.Object({
|
|
|
65
48
|
note: Type.String(),
|
|
66
49
|
}, { additionalProperties: false }),
|
|
67
50
|
}, { additionalProperties: false });
|
|
68
|
-
const
|
|
69
|
-
Type.Object({
|
|
70
|
-
type: Type.Literal("bool"),
|
|
71
|
-
instructions: instructionContent,
|
|
72
|
-
criteria: Type.Optional(Type.Object({ true: Type.Optional(shortText), false: Type.Optional(shortText) }, { additionalProperties: false })),
|
|
73
|
-
}, { additionalProperties: false }),
|
|
74
|
-
Type.Object({
|
|
75
|
-
type: Type.Literal("choice"),
|
|
76
|
-
instructions: instructionContent,
|
|
77
|
-
criteria: Type.Record(Type.String({ minLength: 1, maxLength: 128 }), shortText, { minProperties: 1 }),
|
|
78
|
-
booleanValues: Type.Optional(Type.Boolean()),
|
|
79
|
-
}, { additionalProperties: false }),
|
|
80
|
-
Type.Object({
|
|
81
|
-
type: Type.Literal("score"),
|
|
82
|
-
instructions: instructionContent,
|
|
83
|
-
criteria: Type.Array(imageContent(4096, true), {
|
|
84
|
-
minItems: 2,
|
|
85
|
-
maxItems: 10,
|
|
86
|
-
}),
|
|
87
|
-
descriptions: Type.Optional(Type.Array(Type.String({ maxLength: 4096 }))),
|
|
88
|
-
}, { additionalProperties: false }),
|
|
51
|
+
const extractionQuestion = Type.Union([
|
|
89
52
|
Type.Object({
|
|
90
53
|
type: Type.Literal("box"),
|
|
91
54
|
instructions: instructionContent,
|
|
@@ -129,6 +92,29 @@ const question = Type.Union([
|
|
|
129
92
|
step: Type.Optional(Type.Number({ exclusiveMinimum: 0 })),
|
|
130
93
|
unit: Type.Optional(Type.String({ maxLength: 128 })),
|
|
131
94
|
}, { additionalProperties: false }),
|
|
95
|
+
]);
|
|
96
|
+
// Classification decisions are the only question family `classify` accepts.
|
|
97
|
+
const classificationQuestion = Type.Union([
|
|
98
|
+
Type.Object({
|
|
99
|
+
type: Type.Literal("bool"),
|
|
100
|
+
instructions: instructionContent,
|
|
101
|
+
criteria: Type.Optional(Type.Object({ true: Type.Optional(shortText), false: Type.Optional(shortText) }, { additionalProperties: false })),
|
|
102
|
+
}, { additionalProperties: false }),
|
|
103
|
+
Type.Object({
|
|
104
|
+
type: Type.Literal("choice"),
|
|
105
|
+
instructions: instructionContent,
|
|
106
|
+
criteria: Type.Record(Type.String({ minLength: 1, maxLength: 128 }), shortText, { minProperties: 1 }),
|
|
107
|
+
booleanValues: Type.Optional(Type.Boolean()),
|
|
108
|
+
}, { additionalProperties: false }),
|
|
109
|
+
Type.Object({
|
|
110
|
+
type: Type.Literal("score"),
|
|
111
|
+
instructions: instructionContent,
|
|
112
|
+
criteria: Type.Array(imageContent(4096, true), {
|
|
113
|
+
minItems: 2,
|
|
114
|
+
maxItems: 10,
|
|
115
|
+
}),
|
|
116
|
+
descriptions: Type.Optional(Type.Array(Type.String({ maxLength: 4096 }))),
|
|
117
|
+
}, { additionalProperties: false }),
|
|
132
118
|
Type.Object({
|
|
133
119
|
type: Type.Literal("multi_choice"),
|
|
134
120
|
instructions: instructionContent,
|
|
@@ -141,9 +127,13 @@ export const classifyParameters = Type.Object({
|
|
|
141
127
|
Type.Record(Type.String(), Type.Unknown()),
|
|
142
128
|
Type.Array(Type.Unknown()),
|
|
143
129
|
], {
|
|
144
|
-
description: "Text or JSON
|
|
130
|
+
description: "Text or JSON source material. Use explicit {$image:id} objects to place named images in state on supported routes. Other JSON remains data. All questions refer to this same state.",
|
|
131
|
+
}),
|
|
132
|
+
questions: Type.Record(Type.String({ pattern: "^[a-zA-Z0-9_-]{1,64}$" }), classificationQuestion, {
|
|
133
|
+
minProperties: 1,
|
|
134
|
+
maxProperties: 1000,
|
|
135
|
+
description: "Classification decisions only: bool, choice, multi_choice and score. Extraction reads (text, number, date, spans, box, boxes, locate, estimate, extract) belong to classify_extract and are rejected here.",
|
|
145
136
|
}),
|
|
146
|
-
questions: Type.Record(Type.String({ pattern: "^[a-zA-Z0-9_-]{1,64}$" }), question, { minProperties: 1, maxProperties: 1000 }),
|
|
147
137
|
mode: Type.Optional(Type.Literal("web_grounding")),
|
|
148
138
|
conversation: Type.Optional(Type.Array(Type.Unknown({
|
|
149
139
|
description: "An OpenAI Decisions input item: message, function_call, function_call_output, custom_tool_call or custom_tool_call_output.",
|
|
@@ -207,75 +197,6 @@ export const classifyOutput = Type.Object({
|
|
|
207
197
|
confidence: Type.Number({ minimum: 0, maximum: 1 }),
|
|
208
198
|
probabilities: Type.Optional(Type.Record(Type.String(), Type.Number({ minimum: 0, maximum: 1 }))),
|
|
209
199
|
}),
|
|
210
|
-
Type.Object({
|
|
211
|
-
type: Type.Literal("box"),
|
|
212
|
-
box: Type.Object({
|
|
213
|
-
top: Type.Number(),
|
|
214
|
-
bottom: Type.Number(),
|
|
215
|
-
left: Type.Number(),
|
|
216
|
-
right: Type.Number(),
|
|
217
|
-
}),
|
|
218
|
-
confidence: Type.Number({ minimum: 0, maximum: 1 }),
|
|
219
|
-
found: Type.Optional(Type.Number({ minimum: 0, maximum: 1 })),
|
|
220
|
-
}),
|
|
221
|
-
Type.Object({ type: Type.Literal("locate"), spans: Type.Array(textSpan) }),
|
|
222
|
-
Type.Object({
|
|
223
|
-
type: Type.Literal("extract"),
|
|
224
|
-
spans: Type.Record(Type.String(), Type.Array(textSpan)),
|
|
225
|
-
notStated: Type.Record(Type.String(), Type.Number({ minimum: 0, maximum: 1 })),
|
|
226
|
-
}),
|
|
227
|
-
Type.Object({
|
|
228
|
-
type: Type.Literal("text"),
|
|
229
|
-
text: Type.String(),
|
|
230
|
-
span: Type.Optional(Type.Union([charSpan, Type.Null()])),
|
|
231
|
-
found: Type.Optional(Type.Number({ minimum: 0, maximum: 1 })),
|
|
232
|
-
path: Type.Optional(Type.String()),
|
|
233
|
-
}),
|
|
234
|
-
Type.Object({
|
|
235
|
-
type: Type.Literal("number"),
|
|
236
|
-
value: Type.Union([Type.Number(), Type.Null()]),
|
|
237
|
-
unit: Type.Optional(Type.Union([Type.String(), Type.Null()])),
|
|
238
|
-
text: Type.Optional(Type.Union([Type.String(), Type.Null()])),
|
|
239
|
-
span: Type.Optional(Type.Union([charSpan, Type.Null()])),
|
|
240
|
-
found: Type.Optional(Type.Number({ minimum: 0, maximum: 1 })),
|
|
241
|
-
path: Type.Optional(Type.String()),
|
|
242
|
-
}),
|
|
243
|
-
Type.Object({
|
|
244
|
-
type: Type.Literal("date"),
|
|
245
|
-
date: Type.Union([Type.String(), Type.Null()]),
|
|
246
|
-
text: Type.Optional(Type.Union([Type.String(), Type.Null()])),
|
|
247
|
-
span: Type.Optional(Type.Union([charSpan, Type.Null()])),
|
|
248
|
-
found: Type.Optional(Type.Number({ minimum: 0, maximum: 1 })),
|
|
249
|
-
path: Type.Optional(Type.String()),
|
|
250
|
-
}),
|
|
251
|
-
Type.Object({
|
|
252
|
-
type: Type.Literal("spans"),
|
|
253
|
-
spans: Type.Array(Type.Object({
|
|
254
|
-
text: Type.String(),
|
|
255
|
-
span: charSpan,
|
|
256
|
-
found: Type.Number({ minimum: 0, maximum: 1 }),
|
|
257
|
-
}, { additionalProperties: false })),
|
|
258
|
-
count: Type.Integer({ minimum: 0 }),
|
|
259
|
-
atLeast: Type.Boolean(),
|
|
260
|
-
presence: Type.Array(Type.Number({ minimum: 0, maximum: 1 })),
|
|
261
|
-
}),
|
|
262
|
-
Type.Object({
|
|
263
|
-
type: Type.Literal("boxes"),
|
|
264
|
-
boxes: Type.Array(Type.Object({
|
|
265
|
-
box: boxEdges,
|
|
266
|
-
found: Type.Number({ minimum: 0, maximum: 1 }),
|
|
267
|
-
confidence: Type.Number({ minimum: 0, maximum: 1 }),
|
|
268
|
-
}, { additionalProperties: false })),
|
|
269
|
-
count: Type.Integer({ minimum: 0 }),
|
|
270
|
-
atLeast: Type.Boolean(),
|
|
271
|
-
presence: Type.Array(Type.Number({ minimum: 0, maximum: 1 })),
|
|
272
|
-
}),
|
|
273
|
-
Type.Object({
|
|
274
|
-
type: Type.Literal("estimate"),
|
|
275
|
-
value: Type.Number(),
|
|
276
|
-
interval: numericRange,
|
|
277
|
-
unit: Type.Optional(Type.Union([Type.String(), Type.Null()])),
|
|
278
|
-
}),
|
|
279
200
|
Type.Object({
|
|
280
201
|
type: Type.Literal("multi_choice"),
|
|
281
202
|
choices: Type.Array(Type.String()),
|
|
@@ -444,7 +365,7 @@ export const boxOutput = Type.Object({
|
|
|
444
365
|
});
|
|
445
366
|
/* Cloudflare Clairic extraction ------------------------------------------ */
|
|
446
367
|
export const CLASSIFY_EXTRACT_TOOL = "classify_extract";
|
|
447
|
-
export const CLASSIFY_EXTRACT_TOOL_DESCRIPTION = "
|
|
368
|
+
export const CLASSIFY_EXTRACT_TOOL_DESCRIPTION = "Read values out of source material; this tool does not make classification decisions. Use fields for Clairic-shaped field specifications (text, number, date, enum, object, list, estimate, forecast) on clairic-api, openrouter-extractions-api or litellm-extraction-api, or questions for typed extraction reads (text, number, date, spans, box, boxes, locate, estimate and Inception extract) on the configured decision route, including direct liquid-api d1.2 and d1.2-ultra. Supply exactly one of fields or questions. State is text/JSON plus optional images; field mode also accepts PDF documents. Question answers return {type, value, ...metadata} such as span, found, path and confidence. Returns reported token usage and estimated USD cost; truncated reports incomplete generated field output. The tool cannot override the provider or model.";
|
|
448
369
|
// The model-facing JSON schema avoids $ref: validation of nested fields is runtime-owned.
|
|
449
370
|
const extractionFieldDefinition = Type.Object({
|
|
450
371
|
type: Type.Union([
|
|
@@ -500,22 +421,43 @@ const extractionFieldDefinition = Type.Object({
|
|
|
500
421
|
}, { additionalProperties: false });
|
|
501
422
|
export const classifyExtractParameters = Type.Object({
|
|
502
423
|
state: Type.Optional(classifyParameters.properties.state),
|
|
503
|
-
fields: Type.Record(Type.String({ pattern: "^[A-Za-z_][A-Za-z0-9_.-]{0,63}$" }), extractionFieldDefinition, {
|
|
424
|
+
fields: Type.Optional(Type.Record(Type.String({ pattern: "^[A-Za-z_][A-Za-z0-9_.-]{0,63}$" }), extractionFieldDefinition, {
|
|
425
|
+
minProperties: 1,
|
|
426
|
+
description: "Field specifications for clairic-api, openrouter-extractions-api or litellm-extraction-api. Supply exactly one of fields or questions.",
|
|
427
|
+
})),
|
|
428
|
+
questions: Type.Optional(Type.Record(Type.String({ pattern: "^[a-zA-Z0-9_-]{1,64}$" }), extractionQuestion, {
|
|
429
|
+
minProperties: 1,
|
|
430
|
+
maxProperties: 1000,
|
|
431
|
+
description: "Typed extraction reads on the configured decision route: text, number, date, spans, box, boxes, locate, estimate and Inception extract. Supply exactly one of fields or questions.",
|
|
432
|
+
})),
|
|
504
433
|
images: Type.Optional(Type.Array(Type.Union([
|
|
505
434
|
Type.String({ minLength: 1, maxLength: 4096 }),
|
|
435
|
+
Type.Object({
|
|
436
|
+
id: Type.String({ pattern: "^[a-zA-Z0-9_-]{1,64}$" }),
|
|
437
|
+
path: Type.String({ minLength: 1, maxLength: 4096 }),
|
|
438
|
+
}, { additionalProperties: false }),
|
|
439
|
+
Type.Object({
|
|
440
|
+
id: Type.String({ pattern: "^[a-zA-Z0-9_-]{1,64}$" }),
|
|
441
|
+
url: Type.String({ minLength: 1, maxLength: 4096 }),
|
|
442
|
+
}, { additionalProperties: false }),
|
|
506
443
|
Type.Object({
|
|
507
444
|
path: Type.String({ minLength: 1, maxLength: 4096 }),
|
|
508
445
|
rotation: Type.Optional(Type.Union([
|
|
509
446
|
Type.Literal(0), Type.Literal(90), Type.Literal(180), Type.Literal(270),
|
|
510
447
|
])),
|
|
511
448
|
}, { additionalProperties: false }),
|
|
512
|
-
]), {
|
|
513
|
-
|
|
449
|
+
]), {
|
|
450
|
+
maxItems: 128,
|
|
451
|
+
description: "Field mode: local path strings or {path, rotation}, where rotation is Clairic-only. Question mode: local paths or named {id, path}/{id, url} descriptors referenced with {$image:id}. The selected route enforces its own image limit.",
|
|
452
|
+
})),
|
|
453
|
+
media: classifyParameters.properties.media,
|
|
454
|
+
documents: Type.Optional(Type.Array(Type.String({ minLength: 1, maxLength: 4096 }), { maxItems: 4, description: "Field mode only: local unencrypted PDF paths inside cwd." })),
|
|
514
455
|
referenceDate: Type.Optional(Type.String({ pattern: "^\\d{4}-\\d{2}-\\d{2}$" })),
|
|
515
456
|
options: Type.Optional(Type.Object({
|
|
516
457
|
includeQuantiles: Type.Optional(Type.Boolean()),
|
|
517
458
|
returnStateText: Type.Optional(Type.Boolean()),
|
|
518
459
|
}, { additionalProperties: false })),
|
|
460
|
+
mode: Type.Optional(Type.Literal("web_grounding")),
|
|
519
461
|
}, { additionalProperties: false });
|
|
520
462
|
export const classifyExtractOutput = Type.Object({
|
|
521
463
|
provider: Type.String(),
|
|
@@ -527,4 +469,7 @@ export const classifyExtractOutput = Type.Object({
|
|
|
527
469
|
providerCost: classifyOutput.properties.providerCost,
|
|
528
470
|
requestId: Type.Optional(Type.String()),
|
|
529
471
|
stateText: Type.Optional(Type.String()),
|
|
472
|
+
citations: classifyOutput.properties.citations,
|
|
473
|
+
webGrounding: classifyOutput.properties.webGrounding,
|
|
474
|
+
attemptedRoutes: classifyOutput.properties.attemptedRoutes,
|
|
530
475
|
});
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type ApiStyle = "openai-decisions" | "openrouter-decisions" | "gemini-decisions" | "inception-decisions" | "parallel-decisions" | "local-system-one" | "perplexity-decisions" | "sarvam-system-one" | "system-one" | "liquid-system-one" | "cloudflare-system-one" | "cloudflare-clairic" | "openrouter-extractions" | "litellm-extraction" | "microsoft-system-one";
|
|
1
|
+
export type ApiStyle = "openai-decisions" | "openrouter-decisions" | "gemini-decisions" | "inception-decisions" | "parallel-decisions" | "local-system-one" | "perplexity-decisions" | "sarvam-system-one" | "system-one" | "liquid-system-one" | "cloudflare-system-one" | "cloudflare-clairic" | "openrouter-extractions" | "litellm-extraction" | "microsoft-system-one" | "subq-system-one" | "alibaba-system-one" | "fireworks-system-one";
|
|
2
2
|
/** Explicit references are resolved only from the request's named images. */
|
|
3
3
|
export type ImageReference = {
|
|
4
4
|
$image: string;
|
|
@@ -22,7 +22,8 @@ export type BoxEdges = {
|
|
|
22
22
|
left: number;
|
|
23
23
|
right: number;
|
|
24
24
|
};
|
|
25
|
-
|
|
25
|
+
/** Classification decisions: the only question types the `classify` tool accepts. */
|
|
26
|
+
export type ClassificationQuestion = {
|
|
26
27
|
type: "bool";
|
|
27
28
|
instructions: QuestionContent;
|
|
28
29
|
criteria?: {
|
|
@@ -40,6 +41,12 @@ export type Question = {
|
|
|
40
41
|
criteria: QuestionContent[];
|
|
41
42
|
descriptions?: string[];
|
|
42
43
|
} | {
|
|
44
|
+
type: "multi_choice";
|
|
45
|
+
instructions: QuestionContent;
|
|
46
|
+
criteria: Record<string, QuestionContent>;
|
|
47
|
+
};
|
|
48
|
+
/** Extraction reads: accepted by `classify_extract` question mode, never by `classify`. */
|
|
49
|
+
export type ExtractionQuestion = {
|
|
43
50
|
type: "extract";
|
|
44
51
|
instructions?: QuestionContent;
|
|
45
52
|
criteria: Record<string, QuestionContent>;
|
|
@@ -79,11 +86,9 @@ export type Question = {
|
|
|
79
86
|
range: CharSpan;
|
|
80
87
|
step?: number;
|
|
81
88
|
unit?: string;
|
|
82
|
-
} | {
|
|
83
|
-
type: "multi_choice";
|
|
84
|
-
instructions: QuestionContent;
|
|
85
|
-
criteria: Record<string, QuestionContent>;
|
|
86
89
|
};
|
|
90
|
+
/** Provider adapters accept both families; the two tools enforce the boundary. */
|
|
91
|
+
export type Question = ClassificationQuestion | ExtractionQuestion;
|
|
87
92
|
export type TextSpan = {
|
|
88
93
|
start: number;
|
|
89
94
|
end: number;
|
|
@@ -214,7 +219,8 @@ export type Answer = {
|
|
|
214
219
|
} | {
|
|
215
220
|
type: "ambiguous";
|
|
216
221
|
};
|
|
217
|
-
|
|
222
|
+
/** Shared typed-question request; classification and typed extraction both prepare it identically. */
|
|
223
|
+
export interface DecisionInput {
|
|
218
224
|
state: string | Record<string, unknown> | unknown[];
|
|
219
225
|
questions: Record<string, Question>;
|
|
220
226
|
/** Legacy paths are shared in order. Named images require explicit {$image:id} references. */
|
|
@@ -235,6 +241,10 @@ export interface ClassifyParams {
|
|
|
235
241
|
breakpoints?: boolean;
|
|
236
242
|
};
|
|
237
243
|
}
|
|
244
|
+
/** The `classify` tool: classification decisions only. */
|
|
245
|
+
export interface ClassifyParams extends Omit<DecisionInput, "questions"> {
|
|
246
|
+
questions: Record<string, ClassificationQuestion>;
|
|
247
|
+
}
|
|
238
248
|
export type ClassificationTreeNode = {
|
|
239
249
|
id: string;
|
|
240
250
|
description?: string;
|
|
@@ -273,6 +283,8 @@ export interface ModelDefinition {
|
|
|
273
283
|
name?: string;
|
|
274
284
|
input?: ("text" | "image" | "audio" | "video")[];
|
|
275
285
|
box?: boolean;
|
|
286
|
+
/** ISO date after which the provider stops serving this model; the route stays selectable until then. */
|
|
287
|
+
shutdown?: string;
|
|
276
288
|
}
|
|
277
289
|
/** USD per million tokens. Cache counts, when reported, are part of input tokens. */
|
|
278
290
|
export type TokenPricing = {
|
|
@@ -487,19 +499,35 @@ export type ExtractionField = {
|
|
|
487
499
|
horizon?: number;
|
|
488
500
|
interval?: "step" | "minute" | "hour" | "day" | "week" | "month" | "quarter" | "year";
|
|
489
501
|
};
|
|
502
|
+
/** The `classify_extract` tool: field specs or typed extraction questions, never both. */
|
|
490
503
|
export type ExtractParams = {
|
|
491
504
|
state?: ClassifyParams["state"];
|
|
492
|
-
|
|
505
|
+
/** Clairic-shaped field extraction on clairic-api, openrouter-extractions-api or litellm-extraction-api. */
|
|
506
|
+
fields?: Record<string, ExtractionField>;
|
|
507
|
+
/** Typed extraction questions on decision routes, including direct liquid-api. */
|
|
508
|
+
questions?: Record<string, ExtractionQuestion>;
|
|
493
509
|
images?: (string | {
|
|
510
|
+
id: string;
|
|
511
|
+
path: string;
|
|
512
|
+
} | {
|
|
513
|
+
id: string;
|
|
514
|
+
url: string;
|
|
515
|
+
} | {
|
|
494
516
|
path: string;
|
|
495
517
|
rotation?: 0 | 90 | 180 | 270;
|
|
496
518
|
})[];
|
|
519
|
+
/** Audio/video inputs for extraction question routes that document them. */
|
|
520
|
+
media?: MediaInput[];
|
|
521
|
+
/** PDF documents; field mode only. */
|
|
497
522
|
documents?: string[];
|
|
523
|
+
/** Field mode only. */
|
|
498
524
|
referenceDate?: string;
|
|
499
525
|
options?: {
|
|
500
526
|
includeQuantiles?: boolean;
|
|
501
527
|
returnStateText?: boolean;
|
|
502
528
|
};
|
|
529
|
+
/** Extraction question mode: explicit Perplexity web grounding for locate reads. */
|
|
530
|
+
mode?: "web_grounding";
|
|
503
531
|
};
|
|
504
532
|
export type JsonLike = string | number | boolean | null | JsonLike[] | {
|
|
505
533
|
[key: string]: JsonLike;
|
|
@@ -513,10 +541,16 @@ export type ExtractResult = {
|
|
|
513
541
|
provider: string;
|
|
514
542
|
model: string;
|
|
515
543
|
answers: Record<string, ExtractionAnswer>;
|
|
544
|
+
/** True only for generated field output; typed extraction questions never generate text. */
|
|
516
545
|
truncated: boolean;
|
|
517
546
|
usage?: NonNullable<ClassifierResult["usage"]>;
|
|
518
547
|
cost: ClassifierCost;
|
|
519
548
|
providerCost?: ProviderCost;
|
|
520
549
|
requestId?: string;
|
|
521
550
|
stateText?: string;
|
|
551
|
+
/** Request-wide citations from grounded extraction question routes. */
|
|
552
|
+
citations?: DecisionCitation[];
|
|
553
|
+
/** Web evidence for locate answers; each span's searchResult indexes searchResults. */
|
|
554
|
+
webGrounding?: NonNullable<ClassifierResult["webGrounding"]>;
|
|
555
|
+
attemptedRoutes?: ClassifierRoute[];
|
|
522
556
|
};
|
package/dist/validation.d.ts
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
-
import { type ClassifyParams, type Question } from "./types.js";
|
|
1
|
+
import { type ClassifyParams, type ExtractionQuestion, type Question } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* `classify_extract` question mode. Extraction question types only, validated against the same
|
|
4
|
+
* per-type rules the provider adapters rely on. Route capability checks stay in prepareInput.
|
|
5
|
+
*/
|
|
6
|
+
export declare function validateExtractionQuestions(value: unknown): Record<string, ExtractionQuestion>;
|
|
2
7
|
export declare function validateParams(value: unknown): ClassifyParams;
|
|
8
|
+
/** Named/shared image descriptors and {$image:id} resolution, shared by both tools. */
|
|
9
|
+
export declare function validateImageDescriptors(images: unknown, state: unknown, questions: unknown): void;
|
|
3
10
|
export declare function hasBox(questions: Record<string, Question>): boolean;
|