@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.
- package/CHANGELOG.md +48 -0
- package/COMPUTER_USE.md +117 -0
- package/README.md +344 -30
- package/dist/auth.d.ts +4 -2
- package/dist/auth.js +18 -2
- package/dist/box-tool.d.ts +4 -0
- package/dist/box-tool.js +79 -0
- package/dist/box.d.ts +32 -0
- package/dist/box.js +148 -0
- package/dist/choices.js +35 -1
- package/dist/classify.d.ts +6 -0
- package/dist/classify.js +4 -4
- package/dist/computer-use-state.d.ts +9 -0
- package/dist/computer-use-state.js +160 -0
- package/dist/computer-use-tool.d.ts +52 -0
- package/dist/computer-use-tool.js +78 -0
- package/dist/computer-use-types.d.ts +132 -0
- package/dist/computer-use-types.js +1 -0
- package/dist/computer-use.d.ts +22 -0
- package/dist/computer-use.js +223 -0
- package/dist/config.d.ts +140 -3
- package/dist/config.js +405 -20
- package/dist/cost.js +42 -4
- package/dist/durable.d.ts +34 -0
- package/dist/durable.js +237 -0
- package/dist/extension.d.ts +2 -247
- package/dist/extension.js +53 -190
- package/dist/extract.d.ts +11 -0
- package/dist/extract.js +191 -0
- package/dist/http.d.ts +6 -1
- package/dist/http.js +64 -28
- package/dist/image-content.d.ts +12 -0
- package/dist/image-content.js +90 -0
- package/dist/index.d.ts +10 -1
- package/dist/index.js +3 -0
- package/dist/inputs.d.ts +24 -2
- package/dist/inputs.js +565 -134
- package/dist/mcp-cli.d.ts +2 -0
- package/dist/mcp-cli.js +39 -0
- package/dist/mcp-server.d.ts +28 -0
- package/dist/mcp-server.js +121 -0
- package/dist/mcp-tool-definitions.d.ts +19 -0
- package/dist/mcp-tool-definitions.js +64 -0
- package/dist/providers.d.ts +1 -0
- package/dist/providers.js +1218 -124
- package/dist/tool-contracts.d.ts +785 -0
- package/dist/tool-contracts.js +530 -0
- package/dist/tree.js +1 -1
- package/dist/types.d.ts +314 -20
- package/dist/validation.js +181 -44
- package/package.json +33 -5
- package/src/auth.ts +26 -2
- package/src/box-tool.ts +110 -0
- package/src/box.ts +253 -0
- package/src/choices.ts +44 -2
- package/src/classify.ts +10 -6
- package/src/computer-use-state.ts +145 -0
- package/src/computer-use-tool.ts +76 -0
- package/src/computer-use-types.ts +127 -0
- package/src/computer-use.ts +216 -0
- package/src/config.ts +454 -23
- package/src/cost.ts +42 -4
- package/src/durable.ts +298 -0
- package/src/extension.ts +79 -265
- package/src/extract.ts +228 -0
- package/src/http.ts +63 -32
- package/src/image-content.ts +77 -0
- package/src/index.ts +25 -0
- package/src/inputs.ts +603 -184
- package/src/mcp-cli.ts +44 -0
- package/src/mcp-server.ts +179 -0
- package/src/mcp-tool-definitions.ts +104 -0
- package/src/providers.ts +1398 -144
- package/src/tool-contracts.ts +785 -0
- package/src/tree.ts +1 -1
- package/src/types.ts +248 -11
- package/src/validation.ts +169 -96
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,53 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## Unreleased
|
|
4
|
+
|
|
5
|
+
- Added verified built-in routes for Vercel AI Gateway, Google Gemini Decision 1, Inception Mercury Decide, Parallel Decisions, OpenRouter alpha Decisions and Extractions, LiteLLM extraction, and self-hosted llama.cpp/vLLM/Strands/Laya/Nimble System One runtimes with explicit capability tiers.
|
|
6
|
+
- Added Microsoft Foundry Decision-1.1 image assets and Entra bearer auth, TypeSafe long context, Liquid JSON `path` metadata, Clairic image rotation, OpenAI native `input_json`/boolean choices/score descriptions/image detail/prompt-cache controls, and per-route question/media limits.
|
|
7
|
+
- Generalized `classify_extract` to direct Cloudflare Clairic, OpenRouter alpha Extractions and LiteLLM `/v1/extraction`; added an Inception `extract` question primitive and Parallel request-wide citations.
|
|
8
|
+
- Reported gateway/provider charges separately as `providerCost` without replacing the token estimate. Perplexity `maxStaleness` was removed because upstream documents it as ignored.
|
|
9
|
+
- Corrected the legacy `openrouter` alias, native Gemini text blocks, Gemini/local A/V gates, shared images with OpenAI conversations, Inception extract sources and mixed questions, OpenRouter hosted URLs and `d1.2-ultra` images, cache breakpoints, OpenAI's 400-question limit, boolean NONE sentinels, and per-route extraction media and field schemas.
|
|
10
|
+
- Tightened OpenRouter extraction validation to the published model tiers and rejected nested image references, mixed ScaleDown text/asset requests and multi-asset ScaleDown requests before dispatch.
|
|
11
|
+
- Added `providers.cloudflare.gatewayId` for Cloudflare decision and extraction routes; it emits the documented `cf-aig-gateway-id` header and takes precedence over an equivalent custom header.
|
|
12
|
+
- Fixed OpenAI Decisions image input to include the documented `type: "message"` item field, which keeps the payload compatible with LiteLLM's `/v1/decisions` route.
|
|
13
|
+
- Documented verified LiteLLM decision gateways, OpenRouter pricing/choice overrides and Cloudflare gateway settings without adding unverified endpoint support or prices. The LiteLLM example uses `customProviders` because unknown route IDs under `providers` are rejected.
|
|
14
|
+
- Added Sarvam Prism through `sarvam-api` / `sarvam-prism` with `SARVAM_API_KEY`, the documented `api-subscription-key` header, `noul`/choice/score mapping, validated probabilities and safe provider error details. The route is text-only, explicit selection is required, and USD pricing needs an override because the published rate is in INR.
|
|
15
|
+
- Sarvam error field paths and request IDs are omitted when they echo the active API key, and Sarvam score answers now require the documented probability distribution without changing other providers' optional-probability behavior. Response-header request IDs are sanitized for Sarvam only, then fall back to the body request ID.
|
|
16
|
+
- Added Perplexity Decider v1.3 and Flash v1.3 to the built-in catalog, pricing and 255-choice limits. `latest` aliases now resolve to v1.3 upstream.
|
|
17
|
+
- Added Perplexity `locate` answers with Unicode-character spans and explicit `web_grounding`/`maxStaleness` support, including search evidence and documented non-token fee accounting.
|
|
18
|
+
- Added Liquid `d1.2` and `d1.2-ultra` with typed text/number/date reads, `spans`, `box`/`boxes`, ranged estimates, multi-select choices, top-level image/audio uploads and public pricing.
|
|
19
|
+
- Added Cloudflare `@cf/cloudflare/clef-omni` with local audio/video inputs and verified media limits, preserving the model-specific Clef wire branch.
|
|
20
|
+
- Added Cloudflare Clairic extraction through `classify_extract`, with documented field contracts, images/PDFs, grounding metadata, truncation reporting and scheduled pricing.
|
|
21
|
+
- Clairic caller options `includeQuantiles` and `returnStateText` are translated to the provider's documented `include_quantiles` and `return_state_text` wire keys.
|
|
22
|
+
- Liquid multi-select probabilities no longer require a sum of one, estimate ranges and intervals allow negative/fractional numbers, and unparseable number/date values preserve documented `found`/`text`/`span` metadata instead of collapsing to `no_match`.
|
|
23
|
+
- NONE-choice batching now preserves Perplexity web evidence from every call, rebases `locate.searchResult` indices onto the combined evidence, and no longer drops `result.webGrounding`.
|
|
24
|
+
- Shared desktop and Durable tool schemas were updated together. Model-facing JSON Schema avoids `$ref` fragments for `classify_extract` and `classify_tree`; recursive validation stays in runtime code. No live provider calls, paid usage, commits or unit tests were made for these changes.
|
|
25
|
+
|
|
26
|
+
## 0.4.1
|
|
27
|
+
|
|
28
|
+
- Added `@abhishek944/pi-classifier/durable`, a settings-only native Durable extension named `classifier` that registers `classify`, `classify_compare`, `classify_tree`, and `classifier_box_image`.
|
|
29
|
+
- Tool names, descriptions and parameter/result schemas are shared with the desktop extension through `src/tool-contracts.ts`, so the two surfaces cannot drift; desktop-only registration fields stay with the desktop extension.
|
|
30
|
+
- Native credentials are explicit only (`providers.<id>.apiKey`, Cloudflare `accountId`, or the provider environment variable). The native path never reads Pi settings files or stored API-key credentials, and there are no admission, quota, authorization, or host callbacks.
|
|
31
|
+
- `classify`, `classify_compare` and `classify_tree` are marked `replay: "unsafe"` so uncertain or billable executions are never replayed; `classifier_box_image` stays a pure local render marked `replay: "safe"`. Cancellation follows the invocation abort signal.
|
|
32
|
+
- `classifier_computer_use` is not registered natively because Durable 1.1.0 exposes no generic tool-invocation API for Driver calls between decisions; no placeholder is shipped and the desktop extension remains the computer-use surface.
|
|
33
|
+
|
|
34
|
+
Verification: typecheck, build and package dry run passed. No unit tests or live provider calls were run for this release.
|
|
35
|
+
|
|
36
|
+
## 0.4.0
|
|
37
|
+
|
|
38
|
+
- Added the opt-in OpenAI Decisions `classifier_computer_use` tool for a bounded observe/select/act/verify loop through existing Cua Driver MCP tools and Pi permission hooks, without changing the normal classifier default.
|
|
39
|
+
- Added task-scoped semantic controls, supplied nonsecret fill values, explicit supervisor handoff/continuation, fresh observation on resume, cancellation and action limits, no-progress handback, and independent Driver completion predicates. Unknown input outcomes are never automatically replayed.
|
|
40
|
+
- Added validated programmatic in-memory image inputs shared with existing classifier adapters, avoiding per-step screenshot files. Window-only passive text supplements indexed controls, and unrelated global menu-bar branches are excluded.
|
|
41
|
+
- Added bounded decision evidence, stage timings and accumulated provider usage/cost estimates, plus computer-use setup, privacy, supported-scope and handoff guidance in `COMPUTER_USE.md`.
|
|
42
|
+
|
|
43
|
+
- Added named local images and explicit `{$image:id}` references in shared state, Jev/OpenAI question instructions and Jev criteria, while retaining legacy shared image paths.
|
|
44
|
+
- Added OpenAI hosted HTTP(S) image descriptors without local downloads. Unsupported image placements fail before provider requests; Jev batching includes only assets used by the current batch.
|
|
45
|
+
- Added the local-only `classifier_box_image` tool and `renderClassifierBox` export for inline PNG box overlays or crops, without provider calls or automatic file writes.
|
|
46
|
+
- Added current Perplexity v1.2/Flash/latest model catalog entries and support for up to eight Perplexity images. Corrected Jev's minimum side length to 280 pixels.
|
|
47
|
+
- Documented capability differences, image-reference semantics, remote-image limits, experimental box caveats and user-owned verification steps. Video and unverified gateway image support remain excluded.
|
|
48
|
+
|
|
49
|
+
Verification: typecheck, build, package dry run/content checks and whitespace checks passed. Real registered-tool Pi SDK/OpenAI/Cua Driver scenarios on a controlled native macOS window verified multi-action completion, missing-value handoff and supervisor resumption, no-predicate handback, nested hook blocking, action limits and cancellation. Direct source review passed; independent review was unavailable because of session-path tooling. No unit tests were added or run. General browser/Electron typing, arbitrary canvas targets and broad third-party-app coverage remain unverified; no comparative speedup is claimed.
|
|
50
|
+
|
|
3
51
|
## 0.3.0
|
|
4
52
|
|
|
5
53
|
- Added `classify_tree` and `classifyTree` for nested `roots`/`id`/`description`/`children` classification trees supplied inline or as bounded local UTF-8 JSON files. Results contain selected Level1/Level2/etc, model-versus-automatic steps, partial statuses and accumulated token/cost/provider-call totals.
|
package/COMPUTER_USE.md
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
# Computer use with OpenAI Decisions
|
|
2
|
+
|
|
3
|
+
`classifier_computer_use` runs repeated observations, decisions, and Cua Driver actions inside one Pi tool invocation. Pi's main agent remains the supervisor: it owns planning, authorization, content generation, unsupported controls, and final task-level review. The classifier chooses only among supplied, currently grounded controls.
|
|
4
|
+
|
|
5
|
+
This first release supports **one exact accessibility-backed native window per chunk**. Screenshots can supplement semantic state; they do not enable arbitrary pixel targeting. OpenAI Decisions does not generate text, coordinates, scripts, or bounding boxes.
|
|
6
|
+
|
|
7
|
+
## Enable explicitly
|
|
8
|
+
|
|
9
|
+
Add this to trusted Pi settings, preserving your existing classifier configuration:
|
|
10
|
+
|
|
11
|
+
```json
|
|
12
|
+
{
|
|
13
|
+
"pi-classifier": {
|
|
14
|
+
"computerUse": {
|
|
15
|
+
"enabled": true,
|
|
16
|
+
"route": { "provider": "openai-api", "model": "gpt-6-luna" },
|
|
17
|
+
"screenshots": true,
|
|
18
|
+
"minConfidence": 0.75
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Only `openai-api` is supported for computer use initially. Its normal configured endpoint and independent API-key resolution are reused. Missing credentials fail before a window observation. No provider fallback, automatic retry, comparison, sequential choice batching, or global default changes occur. Ordinary `classify` can continue using Jev.
|
|
25
|
+
|
|
26
|
+
The Cua Driver MCP server must already be configured and accessible as `mcp__cua_driver__*`. This extension does not install, launch, or reconfigure the daemon or request OS permissions. After installing/loading the updated extension, use `/reload` to expose the new tool.
|
|
27
|
+
|
|
28
|
+
**Privacy:** the selected endpoint receives the supplied goal, nonsecret values, bounded window labels/values, recent action summaries, and optional window screenshot. Use only the intended authorized window. Structured secure/password controls are excluded, but screenshots are not automatically redacted. Set `screenshots: false` for tree-only use. No screenshots or trajectory files are written by this feature. Do not pass passwords, tokens, payment information, or other secrets.
|
|
29
|
+
|
|
30
|
+
## Supervisor workflow
|
|
31
|
+
|
|
32
|
+
1. Resolve the intended app/account/window through Driver. Inspect its semantic controls. Prefer an existing app API or typed browser route when that is the reliable boundary.
|
|
33
|
+
2. Define one bounded goal and permitted controls. Exact role and label are re-resolved on every observation. Controls can span later screens; their order is not a script. Duplicate matches are never selected arbitrarily.
|
|
34
|
+
3. Supply reusable nonsecret values. Fill uses Driver `set_value`, which replaces native field values. It is not a reliable general browser/Electron typing implementation; use the supervisor's supported browser/input route for those widgets.
|
|
35
|
+
4. Supply Driver completion predicates covering the entire requested result when possible. Every predicate requires an actual condition such as value, selection, enabled state, or existence.
|
|
36
|
+
5. Call the tool and handle its result. Do not observe or mutate the same window in parallel; newer observations invalidate element tokens.
|
|
37
|
+
|
|
38
|
+
Example (replace PID, window ID, and semantic names with your actual observation):
|
|
39
|
+
|
|
40
|
+
```js
|
|
41
|
+
classifier_computer_use({
|
|
42
|
+
goal: "Set City to Lisbon, apply it, and leave the resulting city visible.",
|
|
43
|
+
target: { pid: 1234, window_id: 5678 },
|
|
44
|
+
controls: [
|
|
45
|
+
{ id: "city", operation: "fill", selector: { role: "AXTextField", label: "City" }, valueKey: "city" },
|
|
46
|
+
{ id: "apply", operation: "click", selector: { role: "AXButton", label: "Apply" } }
|
|
47
|
+
],
|
|
48
|
+
values: { city: "Lisbon" },
|
|
49
|
+
expect: [{ element: { selector: { role: "AXTextField", label_contains: "Result" }, value_equals: "Lisbon" } }],
|
|
50
|
+
maxActions: 10,
|
|
51
|
+
timeoutMs: 60000
|
|
52
|
+
});
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Actions supported:
|
|
56
|
+
|
|
57
|
+
- `click`: exact observed invokable/native control.
|
|
58
|
+
- `fill`: exact editable native field and supplied `valueKey`. Already matching values are not offered again. Values are single-line strings; control characters are rejected to avoid implicit submission/focus changes.
|
|
59
|
+
- `key`: one explicit permitted key addressed to an exact observed field/control. No global hotkeys or arbitrary modifiers.
|
|
60
|
+
|
|
61
|
+
The tool defaults to background delivery for clicks/keys. `deliveryMode: "foreground"` is an explicit supervisor choice after an observed background-delivery failure within the same authorized target. Announce the brief focus change and preserve user scope. Do not use it to bypass a refusal. Native `fill` uses Driver's semantic value route regardless of delivery mode; unsupported typing needs a handoff.
|
|
62
|
+
|
|
63
|
+
An allowlist scopes actions; **it does not grant consent**. The main agent must stop before unapproved purchases, sends, publishing, deleting valuable data, account/security changes, credentials, CAPTCHA, or OS consent. Existing Pi nested tool hooks and Driver authorization remain active. A model safety judgment is only additional evidence, not the permission boundary.
|
|
64
|
+
|
|
65
|
+
## Explicit handoff and resumption
|
|
66
|
+
|
|
67
|
+
The result contains:
|
|
68
|
+
|
|
69
|
+
- `status`: `completed`, `handoff`, or `stopped`.
|
|
70
|
+
- `reason` and `message`: verified completion, missing value, supervisor help, low confidence, no progress, incomplete observation, loading timeout, action limit, cancellation/deadline, Driver failure, or failed verification.
|
|
71
|
+
- `actions`: every attempted action, including an interrupted action with `effect: "unknown"`.
|
|
72
|
+
- `metrics`: completed provider calls, token/cost estimates when available, stage durations, and `accountingIncomplete` when an interrupted/failed provider request might have been billed.
|
|
73
|
+
- `decision`: the last selected candidate, confidence, and selected probability, when available. These explain a handback without exposing raw model payloads.
|
|
74
|
+
- `handoff.continuation`: plain task arguments and bounded previous action summaries, **not** an executable capability, saved snapshot, queued action, or authorization token.
|
|
75
|
+
|
|
76
|
+
On missing text or unsupported work:
|
|
77
|
+
|
|
78
|
+
```js
|
|
79
|
+
const next = result.handoff.continuation;
|
|
80
|
+
// The supervisor obtains/writes the nonsecret text or handles the unsupported step.
|
|
81
|
+
classifier_computer_use({
|
|
82
|
+
...next,
|
|
83
|
+
values: { ...next.values, city: "Lisbon" },
|
|
84
|
+
context: "The requested city value is now supplied. Continue the original goal."
|
|
85
|
+
});
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Every chunk takes a fresh observation and asks for a new decision. No snapshot, pixel capture, or element token survives a handoff. The supervisor may adjust controls to match a later screen only when the original task authorizes those effects. If the application switched to a different native window, resolve it explicitly before updating the target.
|
|
89
|
+
|
|
90
|
+
**Unknown action outcome:** inspect application state before resuming. A timeout or tool error does not mean input was not applied. The extension records the attempt and never automatically retries it. No-progress after unverified input returns control rather than replaying a possible submission. Do not lower confidence simply to force progress; the threshold is an uncalibrated handback heuristic.
|
|
91
|
+
|
|
92
|
+
## Completion and stopping
|
|
93
|
+
|
|
94
|
+
A Decisions `DONE` choice is only a claim. It may request read-only verification even below the mutation confidence threshold; it never dispatches uncertain input. With `expect`, the tool requests fresh `verify_state` evidence with two stable satisfied samples. Only all satisfied predicates yield `completed`. Unknown, ambiguous, or unsatisfied results hand back. The supervisor must still check that the predicates cover the **whole** goal and use application-owned state/reopen checks for saves when appropriate.
|
|
95
|
+
|
|
96
|
+
Without `expect`, `DONE` returns `handoff / needs_verification`. This supports visual or semantic goals that Driver predicates cannot independently express without making a false success claim.
|
|
97
|
+
|
|
98
|
+
The observation is bounded to 180 elements, depth 14, and a 1.5-second AX budget. Explicitly truncated/degraded trees hand back. Driver's indexed list omits passive text, so `elements_complete: false` alone is not treated as a truncated walk or evidence of absence. Bounded window-only passive text supplements indexed controls; global menu-bar branches are excluded, independently of their ordering. Missing or duplicate eligible control matches are never guessed. The default chunk is 20 actions and 60 seconds, with bounded waits and model decisions. Caller cancellation/deadline propagates to nested tools and HTTP, but cannot undo an OS event already dispatched. No blind batches or automatic rollback are attempted.
|
|
99
|
+
|
|
100
|
+
## Programmatic use
|
|
101
|
+
|
|
102
|
+
The package exports `runComputerUse(params, { settings, cwd, callTool, signal?, onProgress? })`. `callTool` must dispatch through the host's real approval/tool pipeline and return the raw MCP `CallToolResult`. The Pi tool does this through `ctx.executeTool()`, unwrapping Pi's MCP result envelope. Do not substitute another SDK connection to evade approvals.
|
|
103
|
+
|
|
104
|
+
`classify(params, options)` additionally supports `options.memoryImages`, an array of `{bytes: Uint8Array, mimeType}`. These transient images pass the same byte/pixel/full-decode and route checks as files. They supplement shared input; named references still refer only to normal named descriptors. Model-facing `classify` parameters remain path/descriptor-based. New image ingress does not weaken local-path validation.
|
|
105
|
+
|
|
106
|
+
## Design references
|
|
107
|
+
|
|
108
|
+
This is original implementation, not vendored code. Useful patterns were curated from:
|
|
109
|
+
|
|
110
|
+
- [Browser Use Jev Ultrafast](https://github.com/browser-use/jev-ultrafast): indexed grounded actions, code-owned loop, single decision round trip.
|
|
111
|
+
- [Ying-Kai-Liao/jev-browser](https://github.com/Ying-Kai-Liao/jev-browser): caller values and explicit handback statuses.
|
|
112
|
+
- [Decision Luna Browser Lab](https://github.com/humanity-forever/decision-luna-browse-control): independent completion and waiting evidence.
|
|
113
|
+
- [CUA-JEV](https://github.com/ZJU-REAL/CUA-JEV): legal candidate/executor boundary.
|
|
114
|
+
- [Jev Browser Use](https://github.com/wy-coliney/jev-browser-use): supervisor allowlists and resumption inside an existing connection.
|
|
115
|
+
- [0x7067/jev-browse](https://github.com/0x7067/jev-browse): explicit action phases and bounded progress history.
|
|
116
|
+
|
|
117
|
+
Their speed/reliability results are not performance claims for this extension. Driver pacing is unchanged; stage metrics should identify whether model inference, observation, or Driver waits dominate the actual workload.
|