@abhishek944/pi-classifier 0.3.0 → 0.5.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 (77) hide show
  1. package/CHANGELOG.md +48 -0
  2. package/COMPUTER_USE.md +117 -0
  3. package/README.md +344 -30
  4. package/dist/auth.d.ts +4 -2
  5. package/dist/auth.js +18 -2
  6. package/dist/box-tool.d.ts +4 -0
  7. package/dist/box-tool.js +79 -0
  8. package/dist/box.d.ts +32 -0
  9. package/dist/box.js +148 -0
  10. package/dist/choices.js +35 -1
  11. package/dist/classify.d.ts +6 -0
  12. package/dist/classify.js +4 -4
  13. package/dist/computer-use-state.d.ts +9 -0
  14. package/dist/computer-use-state.js +160 -0
  15. package/dist/computer-use-tool.d.ts +52 -0
  16. package/dist/computer-use-tool.js +78 -0
  17. package/dist/computer-use-types.d.ts +132 -0
  18. package/dist/computer-use-types.js +1 -0
  19. package/dist/computer-use.d.ts +22 -0
  20. package/dist/computer-use.js +223 -0
  21. package/dist/config.d.ts +140 -3
  22. package/dist/config.js +405 -20
  23. package/dist/cost.js +42 -4
  24. package/dist/durable.d.ts +34 -0
  25. package/dist/durable.js +237 -0
  26. package/dist/extension.d.ts +2 -247
  27. package/dist/extension.js +53 -190
  28. package/dist/extract.d.ts +11 -0
  29. package/dist/extract.js +191 -0
  30. package/dist/http.d.ts +6 -1
  31. package/dist/http.js +64 -28
  32. package/dist/image-content.d.ts +12 -0
  33. package/dist/image-content.js +90 -0
  34. package/dist/index.d.ts +10 -1
  35. package/dist/index.js +3 -0
  36. package/dist/inputs.d.ts +24 -2
  37. package/dist/inputs.js +565 -134
  38. package/dist/mcp-cli.d.ts +2 -0
  39. package/dist/mcp-cli.js +39 -0
  40. package/dist/mcp-server.d.ts +28 -0
  41. package/dist/mcp-server.js +121 -0
  42. package/dist/mcp-tool-definitions.d.ts +19 -0
  43. package/dist/mcp-tool-definitions.js +64 -0
  44. package/dist/providers.d.ts +1 -0
  45. package/dist/providers.js +1218 -124
  46. package/dist/tool-contracts.d.ts +785 -0
  47. package/dist/tool-contracts.js +530 -0
  48. package/dist/tree.js +1 -1
  49. package/dist/types.d.ts +314 -20
  50. package/dist/validation.js +181 -44
  51. package/package.json +33 -5
  52. package/src/auth.ts +26 -2
  53. package/src/box-tool.ts +110 -0
  54. package/src/box.ts +253 -0
  55. package/src/choices.ts +44 -2
  56. package/src/classify.ts +10 -6
  57. package/src/computer-use-state.ts +145 -0
  58. package/src/computer-use-tool.ts +76 -0
  59. package/src/computer-use-types.ts +127 -0
  60. package/src/computer-use.ts +216 -0
  61. package/src/config.ts +454 -23
  62. package/src/cost.ts +42 -4
  63. package/src/durable.ts +298 -0
  64. package/src/extension.ts +79 -265
  65. package/src/extract.ts +228 -0
  66. package/src/http.ts +63 -32
  67. package/src/image-content.ts +77 -0
  68. package/src/index.ts +25 -0
  69. package/src/inputs.ts +603 -184
  70. package/src/mcp-cli.ts +44 -0
  71. package/src/mcp-server.ts +179 -0
  72. package/src/mcp-tool-definitions.ts +104 -0
  73. package/src/providers.ts +1398 -144
  74. package/src/tool-contracts.ts +785 -0
  75. package/src/tree.ts +1 -1
  76. package/src/types.ts +248 -11
  77. package/src/validation.ts +169 -96
@@ -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,5 +1,14 @@
1
1
  export { classify, compareClassifiers } from "./classify.js";
2
+ export { extract } from "./extract.js";
3
+ export type { ExtractOptions } from "./extract.js";
4
+ export type { ClassifyOptions } from "./classify.js";
5
+ export type { MemoryImage } from "./inputs.js";
6
+ export { runComputerUse } from "./computer-use.js";
7
+ export type { ComputerUseOptions } from "./computer-use.js";
8
+ export type { ComputerUseParams, ComputerUseResult, ComputerUseSettings, ComputerControl, ComputerExpectation, DriverCall, DriverReply } from "./computer-use-types.js";
2
9
  export { classifyTree } from "./tree.js";
10
+ export { renderClassifierBox } from "./box.js";
11
+ export type { ClassifierBoxMode, ClassifierBoxEdges, ClassifierBoxPixelBox, ClassifierBoxResult } from "./box.js";
3
12
  export { loadClassifierSettings, resolveModel, listModels } from "./config.js";
4
- export type { Answer, Question, ClassifierResult, ClassifierCost, TokenPricing, ClassifierRoute, ClassifierComparisonEntry, ClassifierComparisonResult, ClassifierSettings, ClassifyParams, ClassifyTreeParams, ClassifierTreeResult, ClassificationTree, ClassificationTreeNode, TreeStep, CustomProviderSettings, ModelDefinition, ProviderSettings, ApiStyle, } from "./types.js";
13
+ export type { Answer, Question, QuestionContent, ImageInput, ImageReference, ClassifierResult, ClassifierCost, TokenPricing, ClassifierRoute, ClassifierComparisonEntry, ClassifierComparisonResult, ClassifierSettings, ClassifyParams, ClassifyTreeParams, ClassifierTreeResult, ClassificationTree, ClassificationTreeNode, TreeStep, CustomProviderSettings, ModelDefinition, ProviderSettings, ApiStyle, MediaInput, PreparedMedia, TextSpan, BoxEdges, CharSpan, NonTokenCost, WebSearchResult, WebFetchedResult, ExtractionField, ExtractParams, ExtractResult, ExtractionAnswer, JsonLike, } from "./types.js";
5
14
  export { ClassifierError } from "./types.js";
package/dist/index.js CHANGED
@@ -1,4 +1,7 @@
1
1
  export { classify, compareClassifiers } from "./classify.js";
2
+ export { extract } from "./extract.js";
3
+ export { runComputerUse } from "./computer-use.js";
2
4
  export { classifyTree } from "./tree.js";
5
+ export { renderClassifierBox } from "./box.js";
3
6
  export { loadClassifierSettings, resolveModel, listModels } from "./config.js";
4
7
  export { ClassifierError } from "./types.js";
package/dist/inputs.d.ts CHANGED
@@ -1,4 +1,26 @@
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 ExtractParams, 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>;
3
10
  /** Verify containment of the opened descriptor, not a raceable pre-open path. */
4
11
  export declare function verifyOpenedPath(fd: number, root: string, signal?: AbortSignal): Promise<void>;
12
+ export type PreparedExtractionImage = PreparedLocalImage & {
13
+ rotation?: 0 | 90 | 180 | 270;
14
+ };
15
+ export type PreparedExtractionInput = {
16
+ state: string | Record<string, unknown> | unknown[];
17
+ fields: NonNullable<ExtractParams["fields"]>;
18
+ images: PreparedExtractionImage[];
19
+ documents: {
20
+ mimeType: "application/pdf";
21
+ data: string;
22
+ }[];
23
+ referenceDate?: string;
24
+ options?: ExtractParams["options"];
25
+ };
26
+ export declare function prepareExtractionInput(params: ExtractParams, route: ResolvedModel, cwd: string, signal?: AbortSignal): Promise<PreparedExtractionInput>;