@abhishek944/pi-classifier 0.0.0-stage → 0.2.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 +25 -0
- package/LICENSE +201 -0
- package/README.md +241 -2
- package/THIRD_PARTY_NOTICES.md +48 -0
- package/dist/auth.d.ts +5 -0
- package/dist/auth.js +56 -0
- package/dist/classify.d.ts +11 -0
- package/dist/classify.js +117 -0
- package/dist/config.d.ts +82 -0
- package/dist/config.js +298 -0
- package/dist/extension.d.ts +122 -0
- package/dist/extension.js +255 -0
- package/dist/http.d.ts +5 -0
- package/dist/http.js +85 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +3 -0
- package/dist/inputs.d.ts +2 -0
- package/dist/inputs.js +184 -0
- package/dist/providers.d.ts +2 -0
- package/dist/providers.js +614 -0
- package/dist/settings-write.d.ts +10 -0
- package/dist/settings-write.js +110 -0
- package/dist/types.d.ts +144 -0
- package/dist/types.js +18 -0
- package/dist/validation.d.ts +3 -0
- package/dist/validation.js +95 -0
- package/package.json +72 -4
- package/src/auth.ts +74 -0
- package/src/classify.ts +157 -0
- package/src/config.ts +391 -0
- package/src/extension.ts +362 -0
- package/src/http.ts +108 -0
- package/src/index.ts +17 -0
- package/src/inputs.ts +239 -0
- package/src/providers.ts +898 -0
- package/src/settings-write.ts +145 -0
- package/src/types.ts +152 -0
- package/src/validation.ts +139 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
- Microsoft Decision-1 via Foundry resource endpoints and deployment names, API-key authentication, and text/JSON bool/choice/score questions.
|
|
6
|
+
- Nested `default` provider/model pairs with legacy default-key compatibility, ordered selective `fallback`, and explicit `compare` routes.
|
|
7
|
+
- `classify_compare`, `/classifier compare <JSON params>`, and the `compareClassifiers` library export, with labeled successes/errors, per-entry duration, and cancellation preserving completed results.
|
|
8
|
+
- Automatic alternatives only for missing API keys or HTTP 401/404/429; no route retries, fallback after uncertain outcomes, or automatic model comparisons.
|
|
9
|
+
- `/classifier use` writes the nested default while preserving fallback/comparison lists and unrelated settings.
|
|
10
|
+
|
|
11
|
+
Verification: typecheck, build, package dry run, whitespace checks, and independent source review passed. No unit tests or live provider calls were run for this release. Microsoft response shapes remain unverified against a live Foundry deployment. Nested defaults take precedence over legacy keys in merged classifier settings; mixed-format global/project overrides are not yet normalized per layer like image-gen.
|
|
12
|
+
|
|
13
|
+
## 0.1.0
|
|
14
|
+
|
|
15
|
+
Initial public baseline.
|
|
16
|
+
|
|
17
|
+
- Config-driven `classify` tool with typed bool, choice and score answers; experimental Jev bounding boxes.
|
|
18
|
+
- OpenAI Decisions, Perplexity Decisions, TypeSafe Jev, Cloudflare Clef/Clef Flash, OpenRouter and supported custom protocols.
|
|
19
|
+
- Configuration shape aligned with pi-image-gen: defaultProvider, defaultModel, providers and customProviders.
|
|
20
|
+
- API-key calls independent of Codex chat login, using configured key, stored Pi API-key credential or environment key.
|
|
21
|
+
- Local image validation, bounded requests/results, cancellation, safe errors and explicit experimental capabilities.
|
|
22
|
+
- `/classifier` configuration commands and a TypeScript source entrypoint for Git-based installation.
|
|
23
|
+
- No automatic fallback, retry, model switching or permission automation.
|
|
24
|
+
|
|
25
|
+
Verification: typecheck/build/format/package/schema checks passed. Live OpenAI text/JSON and synthetic image acceptance checks passed; the first text call required one manual repeat after an HTTP error. Other providers, interactive commands and live cancellation remain unverified. See README for platform, image, BOM and experimental-feature limitations.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,242 @@
|
|
|
1
|
-
#
|
|
1
|
+
# pi-classifier
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A Pi extension for typed, probabilistic decisions across Microsoft Decision-1, OpenAI Decisions, Perplexity Decisions, TypeSafe Jev, Cloudflare Clef/Clef Flash and SystemOne-compatible gateways.
|
|
4
|
+
|
|
5
|
+
One configured default, optional selective fallback, and explicit model comparisons. No automatic retries or permission auto-approval.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
Requires Node.js 22.19+ and Pi 1.2+. Install the tagged release from GitHub:
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
pi install git:github.com/abhishek944/pi-classifier@v0.2.0
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
The Pi package entrypoint is TypeScript source, so Git installs do not depend on committed build artifacts or a TypeScript compiler. Runtime dependencies are installed by Pi. The compiled `dist` exports remain available for library consumers after a build.
|
|
16
|
+
|
|
17
|
+
### Local development
|
|
18
|
+
|
|
19
|
+
From this package:
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
npm install
|
|
23
|
+
npm run build
|
|
24
|
+
pi -e ./dist/extension.js
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
To install persistently after trying it:
|
|
28
|
+
|
|
29
|
+
```sh
|
|
30
|
+
pi install /absolute/path/to/pi-classifier
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
The package version and Git tag are `0.2.0` / `v0.2.0`. Installation is explicit. This release is prepared for GitHub; npm publication is a separate manual step.
|
|
34
|
+
|
|
35
|
+
## Configuration: same shape as pi-image-gen
|
|
36
|
+
|
|
37
|
+
Use the `pi-classifier` namespace in Pi settings. Like `pi-image-gen`, route selection uses `default: { provider, model }`, optional ordered `fallback` pairs, and explicit `compare` pairs. Legacy `defaultProvider` and `defaultModel` remain supported when `default` is absent; a present but malformed `default` fails closed. No settings are automatically migrated; credentials/endpoints are nested under `providers.<provider-id>`. Default selection happens after settings layers are merged: if a user/agent layer has a nested `default`, a project's legacy default keys do not override it. Use a nested `default` in the project too; mixed-format per-layer normalization is not implemented. The two extensions have independent settings and do not change one another.
|
|
38
|
+
|
|
39
|
+
```json
|
|
40
|
+
{
|
|
41
|
+
"pi-classifier": {
|
|
42
|
+
"default": { "provider": "openai-api", "model": "gpt-6-luna" },
|
|
43
|
+
"fallback": [{ "provider": "typesafe-api", "model": "jev-latest" }],
|
|
44
|
+
"compare": [
|
|
45
|
+
{ "provider": "openai-api", "model": "gpt-6-luna" },
|
|
46
|
+
{ "provider": "typesafe-api", "model": "jev-latest" }
|
|
47
|
+
],
|
|
48
|
+
"requestTimeoutMs": 30000,
|
|
49
|
+
"providers": {
|
|
50
|
+
"openai": { "apiKey": "${OPENAI_API_KEY}" },
|
|
51
|
+
"perplexity": { "apiKey": "${PERPLEXITY_API_KEY}" },
|
|
52
|
+
"typesafe": { "apiKey": "${TYPESAFE_API_KEY}" },
|
|
53
|
+
"cloudflare": {
|
|
54
|
+
"apiKey": "${CLOUDFLARE_API_KEY}",
|
|
55
|
+
"accountId": "${CLOUDFLARE_ACCOUNT_ID}"
|
|
56
|
+
},
|
|
57
|
+
"openrouter": { "apiKey": "${OPENROUTER_API_KEY}" }
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Put environment references and secrets in global/agent settings, not project settings. Global/agent environment interpolation follows `@amaster.ai/pi-shared/settings`. Trusted project settings override the namespace's top-level keys, but are never environment-expanded. Nested `providers` maps follow the shared loader's shallow-merge behavior. Untrusted project settings are ignored. Malformed settings or a null namespace fail closed. Settings must be UTF-8 without a BOM; unlike Pi's main loader, the shared extension loader does not support BOM-prefixed files, so this package reports an explicit error rather than silently using another configuration. Configure endpoint overrides only for services you trust: the selected endpoint receives the API key and submitted state.
|
|
64
|
+
|
|
65
|
+
Do not add placeholder API-key fields for keys you want loaded from Pi's credential store. Omit those fields instead.
|
|
66
|
+
|
|
67
|
+
### API-key selection, independent of Codex login
|
|
68
|
+
|
|
69
|
+
Credential priority is:
|
|
70
|
+
|
|
71
|
+
1. Non-empty `providers.<id>.apiKey` (or the custom provider's `apiKey`).
|
|
72
|
+
2. Pi's stored `api_key` credential for the provider, using Pi's own credential-store path.
|
|
73
|
+
3. The provider's environment variable.
|
|
74
|
+
|
|
75
|
+
OAuth credentials are never used as API keys, never refreshed by this extension, and never changed. You can remain logged in to Codex for chat while using `openai-api` for classifier calls. If the stored `openai` slot contains OAuth rather than an API key, the extension skips it and uses your configured or environment API key.
|
|
76
|
+
|
|
77
|
+
Pi keeps one credential per provider ID, not both OAuth and an API key in the same slot. An OpenAI key stored under `openai` is distinct from Codex login under `openai-codex`.
|
|
78
|
+
|
|
79
|
+
Stored API-key values support literal strings and `$NAME`/`${NAME}` references, including provider-scoped stored environment values before process environment values. A missing reference leaves the stored key unresolved rather than sending a partial key. Shell-command credentials are intentionally not executed. Credentials and headers are never printed by status/list. This stored-key support is an addition in the classifier package: the current image-gen API route reads configuration/environment keys, while its subscription route resolves Pi's OAuth login.
|
|
80
|
+
|
|
81
|
+
### Providers and models
|
|
82
|
+
|
|
83
|
+
| Route | Provider settings key | Models | Environment key |
|
|
84
|
+
| ---------------- | --------------------- | ------------------------------------------------------------------ | -------------------- |
|
|
85
|
+
| `microsoft-api` | `microsoft` | `Microsoft-Decision-1` (select your actual deployment name) | `AZURE_API_KEY` |
|
|
86
|
+
| `openai-api` | `openai` | `gpt-6-luna` | `OPENAI_API_KEY` |
|
|
87
|
+
| `perplexity-api` | `perplexity` | `pplx-decider-v1.1-27b`, `pplx-decider-v1-27b` | `PERPLEXITY_API_KEY` |
|
|
88
|
+
| `typesafe-api` | `typesafe` | `jev-latest`, `jev-1.13.0`, `jev-preview`, `jev-1.14.0` | `TYPESAFE_API_KEY` |
|
|
89
|
+
| `cloudflare-api` | `cloudflare` | `@cf/cloudflare/clef`, `@cf/cloudflare/clef-flash`, `typesafe/jev` | `CLOUDFLARE_API_KEY` |
|
|
90
|
+
| `openrouter-api` | `openrouter` | `typesafe/jev-1.13`, `~typesafe/jev-latest` | `OPENROUTER_API_KEY` |
|
|
91
|
+
|
|
92
|
+
Cloudflare also needs `providers.cloudflare.accountId`, the stored `cloudflare-workers-ai` API-key credential's `env.CLOUDFLARE_ACCOUNT_ID`, or `CLOUDFLARE_ACCOUNT_ID`, in that order. Its stored API token lives under `cloudflare-workers-ai`, not `cloudflare`.
|
|
93
|
+
|
|
94
|
+
A provider's `baseUrl` replaces the API root (before `decisions`, `systemone`, Microsoft's `providers/microsoft/v1/systemone`, or Cloudflare's run path). Authentication/transport headers cannot be overridden. Custom headers are supported. HTTPS is required except for loopback HTTP.
|
|
95
|
+
|
|
96
|
+
New text model IDs on built-in routes can be selected without a package release. They must actually implement that route's API; a normal chat model is not a decision model. New image capabilities require a known model or explicit custom model declaration.
|
|
97
|
+
|
|
98
|
+
## Use
|
|
99
|
+
|
|
100
|
+
```text
|
|
101
|
+
/classifier list
|
|
102
|
+
/classifier status
|
|
103
|
+
/classifier use cloudflare-api @cf/cloudflare/clef-flash
|
|
104
|
+
/classifier reload
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
`use` writes only the nested `default` into trusted project `.pi/settings.json`, removing local legacy default keys and preserving unrelated settings, `fallback`, and `compare`. The project must be trusted. All calls load current settings, so `reload` validates and displays the current route rather than maintaining a separate configuration cache. To change global defaults, edit the global `pi-classifier` settings.
|
|
108
|
+
|
|
109
|
+
The model calls:
|
|
110
|
+
|
|
111
|
+
```js
|
|
112
|
+
classify({
|
|
113
|
+
state: { ticket: "Checkout fails for every customer." },
|
|
114
|
+
questions: {
|
|
115
|
+
urgent: { type: "bool", instructions: "Is this urgent?" },
|
|
116
|
+
team: {
|
|
117
|
+
type: "choice",
|
|
118
|
+
instructions: "Which team should handle this?",
|
|
119
|
+
criteria: {
|
|
120
|
+
billing: "Charges and refunds",
|
|
121
|
+
engineering: "Errors and outages",
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
severity: {
|
|
125
|
+
type: "score",
|
|
126
|
+
instructions: "How severe is the customer impact?",
|
|
127
|
+
criteria: ["Minor", "Major", "Critical"],
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
});
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
The tool takes no provider/model parameter. Its structured result identifies the configured route and model, typed answers, reported token usage and an available request ID. `bool.probability` is the probability of true; `choice` includes a probability per label and confidence; `score` is a probability-weighted level index (starting at zero), not necessarily an integer. Refusals are explicit typed answers. Token counts are reported, but this initial version does not estimate monetary cost or add it to Pi's session billing totals.
|
|
134
|
+
|
|
135
|
+
Provider results are checked for probability ranges/distribution sums and decision consistency (selected choices must be most likely; supplied score distributions must match the expected score within rounding tolerance). Low confidence is a valid answer, not an error. Calibrate thresholds on your own data; scores from different providers are not interchangeable.
|
|
136
|
+
|
|
137
|
+
## Microsoft Decision-1 on Foundry
|
|
138
|
+
|
|
139
|
+
Deploy `Microsoft-Decision-1` in Microsoft Foundry, then configure the **resource endpoint**, API key, and actual **deployment name**:
|
|
140
|
+
|
|
141
|
+
```json
|
|
142
|
+
{
|
|
143
|
+
"pi-classifier": {
|
|
144
|
+
"default": { "provider": "microsoft-api", "model": "my-decision-deployment" },
|
|
145
|
+
"providers": {
|
|
146
|
+
"microsoft": {
|
|
147
|
+
"baseUrl": "https://YOUR-RESOURCE.services.ai.azure.com",
|
|
148
|
+
"apiKey": "${AZURE_API_KEY}"
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
The extension appends `/providers/microsoft/v1/systemone` and uses the `api-key` header, not bearer API-key authentication. The catalog name is only a discovery entry: `model` must match your deployment, which may have another name. Microsoft currently supports text/JSON bool (wire type `noul`), choice, and score; images and box are rejected locally. Entra token authentication is not implemented. The selected deployment is reported in results even if Foundry returns a different underlying model name. If Microsoft omits confidence, choice confidence is derived from the selected probability and score confidence from the largest level probability. The official guide does not include a complete response JSON example; verify actual bool/choice/score responses on your deployment before relying on this integration.
|
|
156
|
+
|
|
157
|
+
## Fallback and explicit comparison
|
|
158
|
+
|
|
159
|
+
`classify` uses the default first. It tries configured `fallback` entries in order **only** after a missing API key or an explicit HTTP **401, 404, or 429**. Each resolved endpoint/model is attempted at most once. When fallback is exercised, `attemptedRoutes` identifies the routes considered, including missing-key failures.
|
|
160
|
+
|
|
161
|
+
No automatic fallback occurs after 403/policy refusal, 400/422, 5xx, timeout, network failure, cancellation, malformed answers, input/capability/configuration errors, low confidence, or typed refusals. Each candidate validates the original input against its own capabilities; incompatible images or box questions stop the chain, never silently drop input. Every attempted request has its own timeout. Crossing billing providers and sharing state with them happens only through explicitly configured route pairs. Omit `fallback` or use `[]` to disable it.
|
|
162
|
+
|
|
163
|
+
Use **`classify_compare`** only when you explicitly want a model comparison. It accepts the same `{ state, questions, images? }` as `classify`, runs exactly the entries in `compare` sequentially, and never substitutes the default, uses fallback, or changes settings. Every entry is a separate potentially billable call. Responses contain labeled `results` with status, duration in milliseconds, typed answers/token usage on success, or safe errors. A failed entry does not discard successes. Duplicate endpoint/model entries report an error without another call. Cancellation retains completed results, records an in-flight cancellation when present, sets `cancelled`, and prevents later requests. Scores from different models are not assumed to be calibrated equally.
|
|
164
|
+
|
|
165
|
+
You can also run `/classifier compare <JSON params>`, for example:
|
|
166
|
+
|
|
167
|
+
```text
|
|
168
|
+
/classifier compare {"state":"Checkout is down.","questions":{"urgent":{"type":"bool","instructions":"Is this urgent?"}}}
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
The library exports `compareClassifiers(params, { settings, cwd, signal? })`. Neither tool accepts provider/model overrides. A missing or empty `compare` list is a configuration error and makes no calls. Comparison output can be larger than a single result; use the tool rather than the command for full structured results (command messages are truncated to 16,000 characters).
|
|
172
|
+
|
|
173
|
+
### Images and experimental Jev box answers
|
|
174
|
+
|
|
175
|
+
Pass `images: ["photo.png"]`. Images are attached in order alongside state. OpenAI, Perplexity and Clef/Clef Flash support images. Cloudflare-hosted Jev and the built-in OpenRouter route are text-only in this package.
|
|
176
|
+
|
|
177
|
+
Image inputs are local non-animated PNG/JPEG/WebP regular files inside the session cwd, with no symlink components, URLs or inline base64. Safe descriptor-based loading currently supports macOS (requires the OS `/usr/sbin/lsof`) and Linux (`/proc`); other platforms support text classification only. Images are fully decoded locally before upload. Limits: five images; 5 MiB each, 10 MiB total and 16 megapixels each. Clef has stricter limits: four images, 4 MiB each and 8 MiB total. Perplexity requires at most 2048 tiles of 32×32 pixels per image; resize before sending. Images are not silently resized. Text/JSON plus questions are limited to 2 MiB, with at most 32 questions per call.
|
|
178
|
+
|
|
179
|
+
TypeSafe Jev images are experimental and require opt-in. Use PNG/JPEG. Each side must be 256–1568 pixels, with total area 78,400–2,458,624 pixels; resize or pad beforehand. These limits also apply to custom SystemOne image routes using Jev's assets protocol:
|
|
180
|
+
|
|
181
|
+
```json
|
|
182
|
+
{
|
|
183
|
+
"pi-classifier": {
|
|
184
|
+
"defaultProvider": "typesafe-api",
|
|
185
|
+
"defaultModel": "jev-preview",
|
|
186
|
+
"providers": {
|
|
187
|
+
"typesafe": {
|
|
188
|
+
"experimentalImages": true,
|
|
189
|
+
"experimentalBox": true
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
With an image, a question such as `{ "type": "box", "instructions": "Find the mug in the first image." }` returns normalized `top`, `bottom`, `left`, `right` edges and confidence. Box needs Jev 1.14 (`jev-preview` or `jev-1.14.0`) and both opt-ins. It is not production-grade localization. A box does not mean the object exists: pair it with a bool existence question when necessary.
|
|
197
|
+
|
|
198
|
+
## Custom providers
|
|
199
|
+
|
|
200
|
+
Like image-gen, `customProviders` adds a named endpoint and explicit model list. Supported protocols are `openai-decisions`, `perplexity-decisions`, `system-one`, `cloudflare-system-one`, and `microsoft-system-one` (Foundry resource root and API-key authentication). A custom URL cannot make an arbitrary API compatible. Custom IDs must not shadow built-in provider/route IDs.
|
|
201
|
+
|
|
202
|
+
```json
|
|
203
|
+
{
|
|
204
|
+
"pi-classifier": {
|
|
205
|
+
"defaultProvider": "local-decisions",
|
|
206
|
+
"defaultModel": "my-decision-model",
|
|
207
|
+
"customProviders": {
|
|
208
|
+
"local-decisions": {
|
|
209
|
+
"api": "system-one",
|
|
210
|
+
"baseUrl": "http://127.0.0.1:8133/v1",
|
|
211
|
+
"apiKey": "${LOCAL_DECISIONS_KEY}",
|
|
212
|
+
"models": [{ "id": "my-decision-model", "input": ["text"] }]
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
Custom endpoints use their route ID as the Pi stored-credential provider ID. They have no implicit environment variable; use an explicit key reference. SystemOne image endpoints must implement Jev's assets protocol, declare image input and opt into `experimentalImages`. Box additionally requires `box: true` on the model and `experimentalBox: true` on the provider.
|
|
220
|
+
|
|
221
|
+
## Development and live verification
|
|
222
|
+
|
|
223
|
+
```sh
|
|
224
|
+
npm run typecheck
|
|
225
|
+
npm run build
|
|
226
|
+
npm pack --dry-run
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
No provider calls are made by these commands. Live tests belong to the user:
|
|
230
|
+
|
|
231
|
+
1. Keep Codex logged in and configure an OpenAI API key. Select `openai-api/gpt-6-luna`, classify one bool, and verify chat login did not change.
|
|
232
|
+
2. Select each provider and ask bool/choice/score questions; check probabilities, selected model and usage.
|
|
233
|
+
3. Try a small PNG on OpenAI, Perplexity and Clef. Enable Jev images explicitly before trying its preview; verify box coordinates separately.
|
|
234
|
+
4. Cancel an in-flight call and check a deliberately invalid model/key. Errors must be safe; only missing keys and HTTP 401/404/429 may select an explicitly configured fallback. Timeout/network/403/5xx/malformed results must not trigger another route.
|
|
235
|
+
5. Use `/classifier use` in a trusted project and confirm unrelated settings and both route lists remain intact. Check legacy-only defaults as well as nested defaults.
|
|
236
|
+
6. Configure your Foundry endpoint and deployment name, select `microsoft-api`, and verify bool/choice/score responses and token usage. Verify an image is rejected locally.
|
|
237
|
+
7. Configure two `compare` pairs and explicitly invoke `classify_compare`; confirm labeled successes/errors, duration, unchanged defaults, and that cancellation prevents subsequent calls. Each valid entry may be billed.
|
|
238
|
+
8. In your own controlled deployment, verify missing keys and HTTP 401/404/429 allow only configured fallbacks; duplicate routes are never called twice. Verify low confidence and refusals return normally without switching models.
|
|
239
|
+
|
|
240
|
+
Provider schemas and previews can change; no live entitlement or model-accuracy claim is made by a local build.
|
|
241
|
+
|
|
242
|
+
Sources: [Microsoft Decision-1](https://learn.microsoft.com/en-us/azure/foundry/foundry-models/how-to/use-foundry-models-microsoft-decision), [OpenAI Decisions](https://developers.openai.com/api/docs/guides/decisions), [Perplexity Decisions](https://docs.perplexity.ai/docs/decisions/quickstart), [TypeSafe images](https://docs.typesafe.ai/images), [TypeSafe box](https://docs.typesafe.ai/primitives/box), [Cloudflare Clef](https://developers.cloudflare.com/workers-ai/models/clef/).
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# Third-party notices
|
|
2
|
+
|
|
3
|
+
## Pi
|
|
4
|
+
|
|
5
|
+
Provider protocol mappings were informed by the Pi classifier adapters:
|
|
6
|
+
|
|
7
|
+
- https://github.com/earendil-works/pi/tree/main/packages/ai/src/api
|
|
8
|
+
- OpenAI Decisions and SystemOne/Cloudflare classification adapters.
|
|
9
|
+
|
|
10
|
+
MIT License
|
|
11
|
+
|
|
12
|
+
Copyright (c) 2025 Mario Zechner
|
|
13
|
+
|
|
14
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
15
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
16
|
+
in the Software without restriction, including without limitation the rights
|
|
17
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
18
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
19
|
+
furnished to do so, subject to the following conditions:
|
|
20
|
+
|
|
21
|
+
The above copyright notice and this permission notice shall be included in all
|
|
22
|
+
copies or substantial portions of the Software.
|
|
23
|
+
|
|
24
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
25
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
26
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
27
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
28
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
29
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
30
|
+
SOFTWARE.
|
|
31
|
+
|
|
32
|
+
## pi-image-gen
|
|
33
|
+
|
|
34
|
+
The configuration conventions and safe atomic project-settings writer follow the sibling pi-image-gen extension:
|
|
35
|
+
|
|
36
|
+
- https://github.com/abhishek944/pi-image-gen
|
|
37
|
+
- Licensed under Apache License 2.0. See LICENSE.
|
|
38
|
+
- Its original extension attribution is TGYD-helige/pi, packages/pi-image-gen (Apache License 2.0).
|
|
39
|
+
|
|
40
|
+
No Codex image transport, UPNG, or sprite-generation code is included here.
|
|
41
|
+
|
|
42
|
+
## Sharp and libvips
|
|
43
|
+
|
|
44
|
+
Sharp validates and decodes local image inputs:
|
|
45
|
+
|
|
46
|
+
- https://github.com/lovell/sharp
|
|
47
|
+
- Sharp is Apache License 2.0; its package includes its license and dependency notices.
|
|
48
|
+
- Its native dependencies include libvips (LGPL-2.1-or-later) and image codecs, whose packages include their applicable licenses/notices. They are dependencies, not embedded in this package's tarball.
|
package/dist/auth.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type ResolvedModel } from "./types.js";
|
|
2
|
+
/** Read the API-key entry only. Never resolve OAuth or mutate Pi's login state. */
|
|
3
|
+
export declare function storedApiCredential(provider: string): import("@earendil-works/pi-ai").ApiKeyCredential | undefined;
|
|
4
|
+
export declare function resolveApiKey(route: ResolvedModel): string;
|
|
5
|
+
export declare function cloudflareAccountId(configured: string | undefined): string;
|
package/dist/auth.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { readStoredCredential } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { ClassifierError } from "./types.js";
|
|
3
|
+
/** Read the API-key entry only. Never resolve OAuth or mutate Pi's login state. */
|
|
4
|
+
export function storedApiCredential(provider) {
|
|
5
|
+
try {
|
|
6
|
+
const value = readStoredCredential(provider);
|
|
7
|
+
return value?.type === "api_key" ? value : undefined;
|
|
8
|
+
}
|
|
9
|
+
catch {
|
|
10
|
+
throw new ClassifierError("credentials", "Could not read Pi API-key credentials.");
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
function storedValue(value, env = {}) {
|
|
14
|
+
if (!value?.trim())
|
|
15
|
+
return undefined;
|
|
16
|
+
value = value.trim();
|
|
17
|
+
if (value.startsWith("!")) {
|
|
18
|
+
throw new ClassifierError("credentials", "Stored API-key shell commands are not supported. Use a literal key or an environment reference.");
|
|
19
|
+
}
|
|
20
|
+
let missing = false;
|
|
21
|
+
const resolved = value.replace(/\$\$|\$!|\$\{([A-Za-z_][A-Za-z0-9_]*)\}|\$([A-Za-z_][A-Za-z0-9_]*)/g, (match, braced, bare) => {
|
|
22
|
+
if (match === "$$")
|
|
23
|
+
return "$";
|
|
24
|
+
if (match === "$!")
|
|
25
|
+
return "!";
|
|
26
|
+
const name = braced ?? bare ?? "";
|
|
27
|
+
const replacement = env[name] ?? process.env[name];
|
|
28
|
+
if (!replacement)
|
|
29
|
+
missing = true;
|
|
30
|
+
return replacement ?? "";
|
|
31
|
+
});
|
|
32
|
+
return missing ? undefined : resolved.trim() || undefined;
|
|
33
|
+
}
|
|
34
|
+
export function resolveApiKey(route) {
|
|
35
|
+
if (route.configuredApiKey)
|
|
36
|
+
return route.configuredApiKey;
|
|
37
|
+
const credential = storedApiCredential(route.credentialProvider);
|
|
38
|
+
const key = storedValue(credential?.key, credential?.env) ??
|
|
39
|
+
(route.envVar ? process.env[route.envVar]?.trim() : undefined);
|
|
40
|
+
if (!key) {
|
|
41
|
+
throw new ClassifierError("missing_credentials", "No API key is configured for the selected classifier. Set providers.<id>.apiKey, save an API-key credential in Pi, or set the provider environment variable. Codex/OAuth tokens are not used.");
|
|
42
|
+
}
|
|
43
|
+
return key;
|
|
44
|
+
}
|
|
45
|
+
export function cloudflareAccountId(configured) {
|
|
46
|
+
const stored = configured
|
|
47
|
+
? undefined
|
|
48
|
+
: storedApiCredential("cloudflare-workers-ai");
|
|
49
|
+
const id = configured?.trim() ??
|
|
50
|
+
storedValue(stored?.env?.CLOUDFLARE_ACCOUNT_ID, stored?.env) ??
|
|
51
|
+
process.env.CLOUDFLARE_ACCOUNT_ID?.trim();
|
|
52
|
+
if (!id || !/^[a-zA-Z0-9_-]+$/.test(id)) {
|
|
53
|
+
throw new ClassifierError("configuration", "Cloudflare requires a valid accountId or CLOUDFLARE_ACCOUNT_ID.");
|
|
54
|
+
}
|
|
55
|
+
return id;
|
|
56
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type ClassifierComparisonResult, type ClassifierResult, type ClassifierSettings } from "./types.js";
|
|
2
|
+
type ClassifyOptions = {
|
|
3
|
+
settings: ClassifierSettings;
|
|
4
|
+
cwd: string;
|
|
5
|
+
signal?: AbortSignal;
|
|
6
|
+
};
|
|
7
|
+
/** Default plus explicitly configured, selective fallback. Never retries a route. */
|
|
8
|
+
export declare function classify(params: unknown, options: ClassifyOptions): Promise<ClassifierResult>;
|
|
9
|
+
/** Explicit comparisons only: configured entries, no default substitution or fallback. */
|
|
10
|
+
export declare function compareClassifiers(params: unknown, options: ClassifyOptions): Promise<ClassifierComparisonResult>;
|
|
11
|
+
export {};
|