@herbertgao/pi-extensions 2026.11.0 → 2026.11.2
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 +768 -0
- package/README.md +7 -7
- package/THIRD_PARTY_NOTICES.md +2 -2
- package/extensions/clef.mjs +1 -1
- package/node_modules/@herbertgao/pi-agency/CHANGELOG.md +19 -0
- package/node_modules/@herbertgao/pi-agency/package.json +4 -2
- package/node_modules/@herbertgao/pi-agency/src/index.ts +1 -1
- package/node_modules/@herbertgao/pi-bark/CHANGELOG.md +52 -0
- package/node_modules/@herbertgao/pi-bark/package.json +2 -1
- package/node_modules/@herbertgao/pi-cc-extensions/CHANGELOG.md +207 -0
- package/node_modules/@herbertgao/pi-cc-extensions/README.en.md +7 -5
- package/node_modules/@herbertgao/pi-cc-extensions/README.md +10 -7
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/config/config.ts +20 -0
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/config/panel.ts +61 -6
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/feature/agent-summary/core.ts +11 -16
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/feature/agent-summary/index.ts +60 -11
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/feature/compact-thinking.ts +29 -11
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/feature/shell/footer-layout.ts +54 -6
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/feature/shell/footer.ts +23 -5
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/feature/shell/session-tokens.ts +52 -0
- package/node_modules/@herbertgao/pi-cc-extensions/package.json +5 -4
- package/node_modules/@herbertgao/pi-impeccable/CHANGELOG.md +13 -0
- package/node_modules/@herbertgao/pi-impeccable/package.json +2 -1
- package/node_modules/@herbertgao/pi-subagents/CHANGELOG.md +6 -0
- package/node_modules/@herbertgao/pi-subagents/README.md +43 -33
- package/node_modules/@herbertgao/pi-subagents/docs/rpc.md +1 -1
- package/node_modules/@herbertgao/pi-subagents/docs/workflows.md +2 -0
- package/node_modules/@herbertgao/pi-subagents/package.json +4 -4
- package/node_modules/@herbertgao/pi-subagents/src/agent-file-toggle.ts +9 -8
- package/node_modules/@herbertgao/pi-subagents/src/agent-manager.ts +70 -9
- package/node_modules/@herbertgao/pi-subagents/src/agent-record-entry.ts +167 -0
- package/node_modules/@herbertgao/pi-subagents/src/agent-runner.ts +156 -13
- package/node_modules/@herbertgao/pi-subagents/src/custom-agents.ts +52 -8
- package/node_modules/@herbertgao/pi-subagents/src/default-agents.ts +3 -4
- package/node_modules/@herbertgao/pi-subagents/src/index.ts +153 -56
- package/node_modules/@herbertgao/pi-subagents/src/settings.ts +3 -2
- package/node_modules/@herbertgao/pi-subagents/src/status-note.ts +3 -1
- package/node_modules/@herbertgao/pi-subagents/src/types.ts +5 -0
- package/node_modules/@herbertgao/pi-subagents/src/workflow/host.ts +88 -6
- package/node_modules/@herbertgao/pi-subagents/src/workflow/progress.ts +3 -2
- package/node_modules/@herbertgao/sol-pi/CHANGELOG.md +84 -0
- package/node_modules/@herbertgao/sol-pi/README.md +3 -3
- package/node_modules/@herbertgao/sol-pi/THIRD_PARTY_NOTICES.md +4 -4
- package/node_modules/@herbertgao/sol-pi/agents-install.md +3 -3
- package/node_modules/@herbertgao/sol-pi/docs/compatibility.md +1 -1
- package/node_modules/@herbertgao/sol-pi/package.json +2 -1
- package/node_modules/pi-provider-qoder/README.md +40 -0
- package/node_modules/pi-provider-qoder/dist/index.js +69 -1
- package/node_modules/pi-provider-qoder/package.json +4 -3
- package/node_modules/pi-typesafe/README.md +3 -3
- package/node_modules/pi-typesafe/dist/auth.d.ts +21 -4
- package/node_modules/pi-typesafe/dist/auth.js +32 -7
- package/node_modules/pi-typesafe/dist/backends.d.ts +2 -2
- package/node_modules/pi-typesafe/dist/backends.js +9 -0
- package/node_modules/pi-typesafe/dist/client.js +7 -12
- package/node_modules/pi-typesafe/dist/errors.d.ts +3 -2
- package/node_modules/pi-typesafe/dist/errors.js +12 -10
- package/node_modules/pi-typesafe/dist/extension.js +14 -10
- package/node_modules/pi-typesafe/package.json +1 -1
- package/package.json +10 -9
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# @herbertgao/sol-pi
|
|
2
|
+
|
|
3
|
+
## 0.4.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#346](https://github.com/HerbertGao/pi-extensions/pull/346) [`641894f`](https://github.com/HerbertGao/pi-extensions/commit/641894ff5dc34a38ab41905f27a3077cc865ab91) Thanks [@HerbertGao](https://github.com/HerbertGao)! - Document Pi 1.5.0 as the tested host and publish each package changelog so Pi can show Extension Updates after an update. Agency tools and clef keep the same TypeBox schemas, built from typebox because Pi 1.5 no longer re-exports Type. Peer ranges stay open. The BTW fullscreen handoff resolves `@narumitw/pi-tui-kit@0.68.1` inside the existing `^0.68.0` range.
|
|
8
|
+
|
|
9
|
+
## 0.4.2
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#301](https://github.com/HerbertGao/pi-extensions/pull/301) [`b79b640`](https://github.com/HerbertGao/pi-extensions/commit/b79b640048f3e871db5791cf2e6cb8cbb1a183c7) Thanks [@HerbertGao](https://github.com/HerbertGao)! - Sync upstream Pi 1.x and codemode compatibility fixes: preserve fused edit details on command failures, inherit trusted Pi shell settings, leave nested structured results intact, and preserve system-message positions during observation packing. Correct compaction projection, request accounting, and failure continuation. Keep `update_plan` declared to the model in codemode-only mode and disallow calling it from codemode scripts so completion boundaries remain visible to Online Context Compact.
|
|
14
|
+
|
|
15
|
+
- [#301](https://github.com/HerbertGao/pi-extensions/pull/301) [`b79b640`](https://github.com/HerbertGao/pi-extensions/commit/b79b640048f3e871db5791cf2e6cb8cbb1a183c7) Thanks [@HerbertGao](https://github.com/HerbertGao)! - Allow SoL-Pi initialization to retry on the next session after configuration loading fails. Malformed shell settings still report an error, but repairing them no longer leaves all enabled features permanently unregistered.
|
|
16
|
+
|
|
17
|
+
## 0.4.1
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- [#287](https://github.com/HerbertGao/pi-extensions/pull/287) [`3a0deb9`](https://github.com/HerbertGao/pi-extensions/commit/3a0deb96297aa6da94fe40724a3945ef16c34497) Thanks [@HerbertGao](https://github.com/HerbertGao)! - Stop bundling resume-from and lower the Node engines floor to `>=22.19.0`, matching Pi. Node 24 was copied from resume-from's engines field; these packages do not use a Node 24-only API. Pi's bundled Node 22 can install the current release instead of silently selecting an older one.
|
|
22
|
+
|
|
23
|
+
## 0.4.0
|
|
24
|
+
|
|
25
|
+
### Minor Changes
|
|
26
|
+
|
|
27
|
+
- [#258](https://github.com/HerbertGao/pi-extensions/pull/258) [`4f505b1`](https://github.com/HerbertGao/pi-extensions/commit/4f505b1456c5ea766121ee915f14ad29e48973e7) Thanks [@HerbertGao](https://github.com/HerbertGao)! - Replay the locally customized extensions on the latest upstream code while keeping the scoped packages, host-provided Pi SDK, and local rich-diff and Action Fusion compatibility.
|
|
28
|
+
|
|
29
|
+
- Bring in pi-cc-extensions 0.9.10, including codemode call trees, expanded input highlighting, the persistent expanded-card background setting, and MCP status chips.
|
|
30
|
+
- Bring in the latest SoL-Pi mainline, including projection-based compaction economics, cache-debt accounting, compaction-rejection recovery, and temporary evidence archives for non-persistent sessions.
|
|
31
|
+
- Keep all four SoL-Pi features opt-in. Temporary evidence archives remain on disk for consumers and require cleanup by the host or caller.
|
|
32
|
+
|
|
33
|
+
### Patch Changes
|
|
34
|
+
|
|
35
|
+
- [#258](https://github.com/HerbertGao/pi-extensions/pull/258) [`4f505b1`](https://github.com/HerbertGao/pi-extensions/commit/4f505b1456c5ea766121ee915f14ad29e48973e7) Thanks [@HerbertGao](https://github.com/HerbertGao)! - Keep ccstyle write rich diffs when Action Fusion owns the write tool. Capture the bounded previous-file metadata inside Pi's mutation queue while retaining fused follow-up commands, file URL paths, and cancellation checks. Expanded edit/write diffs also retain sanitized follow-up command output. Third-party writers without the collaboration hook and custom write operations retain the existing ownership warning and fallback.
|
|
36
|
+
|
|
37
|
+
- [#258](https://github.com/HerbertGao/pi-extensions/pull/258) [`4f505b1`](https://github.com/HerbertGao/pi-extensions/commit/4f505b1456c5ea766121ee915f14ad29e48973e7) Thanks [@HerbertGao](https://github.com/HerbertGao)! - Fix Action Fusion tool context compatibility with Pi 1.x and preserve failed follow-up reporting when Bash returns an error result instead of throwing. Successful file mutations remain intact when the follow-up command fails.
|
|
38
|
+
|
|
39
|
+
## 0.3.4
|
|
40
|
+
|
|
41
|
+
### Patch Changes
|
|
42
|
+
|
|
43
|
+
- [#248](https://github.com/HerbertGao/pi-extensions/pull/248) [`c14c004`](https://github.com/HerbertGao/pi-extensions/commit/c14c0042a8e02862cd6718dd60e4ffb22314165c) Thanks [@HerbertGao](https://github.com/HerbertGao)! - Use Pi 0.99+'s native MCP implementation instead of registering the removed `pi-mcp-adapter`, declare Pi-hosted packages as wildcard peers, update `@tifan/pi-handoff` to 2.2.2 for its Herdr startup retry fix, and pin `pi-typesafe` to 0.8.0.
|
|
44
|
+
|
|
45
|
+
## 0.3.3
|
|
46
|
+
|
|
47
|
+
### Patch Changes
|
|
48
|
+
|
|
49
|
+
- [#244](https://github.com/HerbertGao/pi-extensions/pull/244) [`50c30b8`](https://github.com/HerbertGao/pi-extensions/commit/50c30b8bf73246d1d87e77d83232781ea62c4ba2) Thanks [@HerbertGao](https://github.com/HerbertGao)! - Stop reporting "Online context compact continuation did not start" after every online compaction on Pi 0.87, which defers `agent_settled` follow-up turns and awaits them itself.
|
|
50
|
+
|
|
51
|
+
## 0.3.2
|
|
52
|
+
|
|
53
|
+
### Patch Changes
|
|
54
|
+
|
|
55
|
+
- [#232](https://github.com/HerbertGao/pi-extensions/pull/232) [`9c3c40f`](https://github.com/HerbertGao/pi-extensions/commit/9c3c40f113c62437f76d300042fc59fbf15954c0) Thanks [@HerbertGao](https://github.com/HerbertGao)! - Require the unified Pi 0.87.1 dependency line across published packages.
|
|
56
|
+
|
|
57
|
+
## 0.3.1
|
|
58
|
+
|
|
59
|
+
### Patch Changes
|
|
60
|
+
|
|
61
|
+
- [#219](https://github.com/HerbertGao/pi-extensions/pull/219) [`6525a59`](https://github.com/HerbertGao/pi-extensions/commit/6525a5995b8bb815517e326f1eef78d25c0a3c5e) Thanks [@HerbertGao](https://github.com/HerbertGao)! - Bundle `pi-multi-account@1.22.0` for automatic multi-account failover and rotation across supported Pi providers. Update the aggregate host to Pi 0.85.1 and widen the maintained child package compatibility ranges.
|
|
62
|
+
|
|
63
|
+
## 0.3.0
|
|
64
|
+
|
|
65
|
+
### Minor Changes
|
|
66
|
+
|
|
67
|
+
- [#200](https://github.com/HerbertGao/pi-extensions/pull/200) [`8b8673c`](https://github.com/HerbertGao/pi-extensions/commit/8b8673c5fc802427ab04419de7e13750f0db6ce2) Thanks [@HerbertGao](https://github.com/HerbertGao)! - Remove the bundled `@czottmann/pi-automode` dependency.
|
|
68
|
+
|
|
69
|
+
Auto mode's enable/disable override lived only in the main session's entry stream, so a subagent session restored no override and fell back to the persisted disk default. Subagents therefore stayed subject to automode interception even after the main session disabled it, and its `permissions.ask` rules hard-blocked inside subagents because `ctx.hasUI` is false there. Removing the companion drops that guardrail entirely instead of propagating a session-scoped toggle across sessions.
|
|
70
|
+
|
|
71
|
+
- Drop `@czottmann/pi-automode` from aggregate dependencies, bundled dependencies, Pi extension entries, and Pi skill entries; remove its pin from `upstreams.json`.
|
|
72
|
+
- Remove the auto-mode real-Pi smoke and the aggregate assertions that verified its bundled manifest, license, extension entry, skills, status key, and `automode_inspect` registration.
|
|
73
|
+
- Restore SoL-Pi Action Fusion to its upstream form by removing the local `automode_inspect` guard, which existed only to defer nested `then_run` authorization to automode. The extension-owned `write` guard is unrelated to automode and is retained.
|
|
74
|
+
- Remove the bundled `examples/pi-footer.json` layout example and its aggregate verification, along with the Auto mode footer status row.
|
|
75
|
+
|
|
76
|
+
## 0.2.0
|
|
77
|
+
|
|
78
|
+
### Minor Changes
|
|
79
|
+
|
|
80
|
+
- [#164](https://github.com/HerbertGao/pi-extensions/pull/164) [`52558be`](https://github.com/HerbertGao/pi-extensions/commit/52558be6f06659cb9354b8d80a1e9321c35acbcb) Thanks [@HerbertGao](https://github.com/HerbertGao)! - Import the MIT-licensed NVlabs/SoL-Pi efficiency mechanisms as a maintained package with upstream provenance, with guards for extension-owned writes, pi-automode, and active subagents.
|
|
81
|
+
|
|
82
|
+
### Patch Changes
|
|
83
|
+
|
|
84
|
+
- [#177](https://github.com/HerbertGao/pi-extensions/pull/177) [`ceeece0`](https://github.com/HerbertGao/pi-extensions/commit/ceeece0b2db2ff962eec513a0b7f766471743057) Thanks [@HerbertGao](https://github.com/HerbertGao)! - Sync the SoL-Pi Action Fusion file-URL resolution fix and its regression coverage from NVlabs/SoL-Pi.
|
|
@@ -69,14 +69,14 @@ Read our paper: [SoL-Pi: Recursively Scaling Auto-Research Loops for Efficient A
|
|
|
69
69
|
|
|
70
70
|
- Node.js 22.19.0 or newer
|
|
71
71
|
- npm
|
|
72
|
-
- `@earendil-works/pi-coding-agent` 1.
|
|
72
|
+
- `@earendil-works/pi-coding-agent` 1.5.0 (the monorepo's tested host; runtime peers remain `*`)
|
|
73
73
|
|
|
74
74
|
### Install
|
|
75
75
|
|
|
76
76
|
Install the tested Pi release:
|
|
77
77
|
|
|
78
78
|
```bash
|
|
79
|
-
npm install --global @earendil-works/pi-coding-agent@1.
|
|
79
|
+
npm install --global @earendil-works/pi-coding-agent@1.5.0
|
|
80
80
|
```
|
|
81
81
|
|
|
82
82
|
Install this independently maintained package, or use `@herbertgao/pi-extensions` for the collection:
|
|
@@ -155,7 +155,7 @@ bun audit
|
|
|
155
155
|
node packages/sol-pi/scripts/check-pi-compat.mjs
|
|
156
156
|
```
|
|
157
157
|
|
|
158
|
-
For package-only checks, run `bun run --cwd packages/sol-pi typecheck` and `bun run --cwd packages/sol-pi test`, then inspect the package with `npm pack --dry-run` from `packages/sol-pi`. Root development dependencies provide Pi 1.
|
|
158
|
+
For package-only checks, run `bun run --cwd packages/sol-pi typecheck` and `bun run --cwd packages/sol-pi test`, then inspect the package with `npm pack --dry-run` from `packages/sol-pi`. Root development dependencies provide Pi 1.5.0; runtime Pi packages remain peer dependencies so Pi owns their installation and upgrades.
|
|
159
159
|
|
|
160
160
|
## Project Status
|
|
161
161
|
|
|
@@ -8,10 +8,10 @@ The following packages are supplied by the user's Pi installation and retain the
|
|
|
8
8
|
|
|
9
9
|
| Package | Development-tested version | License | Source |
|
|
10
10
|
| --- | ---: | --- | --- |
|
|
11
|
-
| `@earendil-works/pi-agent-core` | 1.
|
|
12
|
-
| `@earendil-works/pi-ai` | 1.
|
|
13
|
-
| `@earendil-works/pi-coding-agent` | 1.
|
|
14
|
-
| `@earendil-works/pi-tui` | 1.
|
|
11
|
+
| `@earendil-works/pi-agent-core` | 1.5.0 | MIT | <https://github.com/earendil-works/pi> |
|
|
12
|
+
| `@earendil-works/pi-ai` | 1.5.0 | MIT | <https://github.com/earendil-works/pi> |
|
|
13
|
+
| `@earendil-works/pi-coding-agent` | 1.5.0 | MIT | <https://github.com/earendil-works/pi> |
|
|
14
|
+
| `@earendil-works/pi-tui` | 1.5.0 | MIT | <https://github.com/earendil-works/pi> |
|
|
15
15
|
| `typebox` | 1.3.7 | MIT | <https://github.com/sinclairzx81/typebox> |
|
|
16
16
|
|
|
17
17
|
## Development-only dependencies
|
|
@@ -7,7 +7,7 @@ Installation and configuration are complete only when Pi remains unmodified, the
|
|
|
7
7
|
## Rules
|
|
8
8
|
|
|
9
9
|
- Do not modify, patch, fork, or vendor upstream Pi. SoL-Pi must load as a standalone extension through Pi's public package interface.
|
|
10
|
-
- Use Node.js 22.19.0 or newer and the tested Pi release `@earendil-works/pi-coding-agent@1.
|
|
10
|
+
- Use Node.js 22.19.0 or newer and the tested Pi release `@earendil-works/pi-coding-agent@1.5.0`. Treat a different Pi version as a compatibility change and rerun the full suite before using it.
|
|
11
11
|
- Do not clean, reset, switch, or overwrite unrelated repository changes.
|
|
12
12
|
- Do not print, log, commit, upload, or include any secret in a command line. Check only whether a credential is present.
|
|
13
13
|
- Keep SoL-Pi settings in `sol-pi.json`. The Evidence-Preserving Reducer provider/model route is a SoL-Pi setting; provider URLs, credentials, the main agent model, and shell behavior remain Pi settings.
|
|
@@ -57,11 +57,11 @@ Stop if any command fails. Do not hide a failure with `|| true` or replace the f
|
|
|
57
57
|
Install the tested Pi release without changing its source:
|
|
58
58
|
|
|
59
59
|
```bash
|
|
60
|
-
npm install --global --ignore-scripts @earendil-works/pi-coding-agent@1.
|
|
60
|
+
npm install --global --ignore-scripts @earendil-works/pi-coding-agent@1.5.0
|
|
61
61
|
pi --version
|
|
62
62
|
```
|
|
63
63
|
|
|
64
|
-
Require `pi --version` to report `1.
|
|
64
|
+
Require `pi --version` to report `1.5.0`. Runtime peer ranges remain `*`; other hosts need their own validation.
|
|
65
65
|
|
|
66
66
|
For a project-local registration, run this from `target_project` and substitute the resolved absolute `sol_pi_root`:
|
|
67
67
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Pi Compatibility
|
|
2
2
|
|
|
3
|
-
This monorepo tests `@herbertgao/sol-pi` against the root development host Pi 1.
|
|
3
|
+
This monorepo tests `@herbertgao/sol-pi` against the root development host Pi 1.5.0. Pi runtime peers remain `*`, so Pi owns installation and upgrades; that range is not a guarantee for every host. Upstream reports a 19-file/140-test suite and offline startup passing on 0.85.1 and 0.84.2, with earlier public-API checks on the 0.81.1 fork. Those are historical upstream results, not results for the locally adapted package. Its tests use Pi 1.x `ExtensionToolContext` for tool execution.
|
|
4
4
|
|
|
5
5
|
SoL-Pi imports only public package exports:
|
|
6
6
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@herbertgao/sol-pi",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.3",
|
|
4
4
|
"description": "Token-efficient context and tool extensions for Pi, maintained from NVlabs/SoL-Pi.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package",
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
"scripts/check-sol-pi-config.mjs",
|
|
33
33
|
"agents-install.md",
|
|
34
34
|
"README.md",
|
|
35
|
+
"CHANGELOG.md",
|
|
35
36
|
"LICENSE",
|
|
36
37
|
"CONTRIBUTING.md",
|
|
37
38
|
"SECURITY.md",
|
|
@@ -157,6 +157,46 @@ Sanitized billing samples in `src/__fixtures__/billing/usage.json` cover free Gl
|
|
|
157
157
|
calls, paid Global/CN calls, and two Kimi-K3 calls totaling 1.03185159 Credits.
|
|
158
158
|
Session accounting regression tests use these samples without making live requests.
|
|
159
159
|
|
|
160
|
+
## Version notices
|
|
161
|
+
|
|
162
|
+
npm-installed extensions get no update check from the host, so the extension asks the
|
|
163
|
+
npm registry once at startup and logs a single line when a newer release exists:
|
|
164
|
+
|
|
165
|
+
```text
|
|
166
|
+
[pi-provider-qoder] 0.6.9 is available (running 0.6.1). Upgrade: omp plugin upgrade pi-provider-qoder
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
Nothing is installed automatically. The request has a 2s timeout, failures are silent,
|
|
170
|
+
and `PI_PROVIDER_QODER_SKIP_UPDATE_CHECK=1` turns the check off.
|
|
171
|
+
|
|
172
|
+
## Marketplace install (automatic updates)
|
|
173
|
+
|
|
174
|
+
An npm install never self-updates. To let omp keep this extension current, add this
|
|
175
|
+
repository as a marketplace and install from it:
|
|
176
|
+
|
|
177
|
+
```bash
|
|
178
|
+
omp plugin marketplace add simonsmh/pi-provider-qoder
|
|
179
|
+
omp plugin install pi-provider-qoder@pi-provider-qoder
|
|
180
|
+
omp config set marketplace.autoUpdate auto
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
Marketplace installs clone a repository and symlink it — they never run a build — and
|
|
184
|
+
`dist/` is gitignored on `main`, so releases publish the built extension to a `dist`
|
|
185
|
+
branch (`.github/workflows/dist-branch.yml`). The catalog at `.omp-plugin/marketplace.json`
|
|
186
|
+
must declare the released version: `npm run release:sync-marketplace` keeps it in step,
|
|
187
|
+
and `prepublishOnly` fails when the two drift.
|
|
188
|
+
## Version notices
|
|
189
|
+
|
|
190
|
+
npm-installed extensions get no update check from the host, so the extension asks the
|
|
191
|
+
npm registry once at startup and logs a single line when a newer release exists:
|
|
192
|
+
|
|
193
|
+
```text
|
|
194
|
+
[pi-provider-qoder] 0.6.9 is available (running 0.6.1). Upgrade: omp plugin upgrade pi-provider-qoder
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
Nothing is installed automatically. The request has a 2s timeout, failures are silent,
|
|
198
|
+
and `PI_PROVIDER_QODER_SKIP_UPDATE_CHECK=1` turns the check off.
|
|
199
|
+
|
|
160
200
|
## License
|
|
161
201
|
|
|
162
202
|
MIT
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { createRequire as createRequire3 } from "node:module";
|
|
3
|
+
|
|
1
4
|
// src/auth/oauth.ts
|
|
2
5
|
import { existsSync as existsSync4, mkdirSync as mkdirSync4, readFileSync as readFileSync4, writeFileSync as writeFileSync4 } from "node:fs";
|
|
3
6
|
import { homedir as homedir4 } from "node:os";
|
|
@@ -10106,7 +10109,11 @@ function parseModelBusyRejection(body) {
|
|
|
10106
10109
|
const queue = parseJsonObject(busy.message);
|
|
10107
10110
|
if (!queue) return void 0;
|
|
10108
10111
|
if (queue.serviceAvailable !== true) return void 0;
|
|
10109
|
-
const seconds = (value) =>
|
|
10112
|
+
const seconds = (value) => {
|
|
10113
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value <= 0) return 0;
|
|
10114
|
+
const milliseconds = Math.round(value * 1e3);
|
|
10115
|
+
return Number.isSafeInteger(milliseconds) && milliseconds > 0 ? milliseconds : 0;
|
|
10116
|
+
};
|
|
10110
10117
|
if (queue.isQueued === false) {
|
|
10111
10118
|
return { kind: "ready", retryAfterMs: seconds(queue.retryAfterSeconds) };
|
|
10112
10119
|
}
|
|
@@ -10889,6 +10896,58 @@ function streamQoder(model, context, options) {
|
|
|
10889
10896
|
return stream;
|
|
10890
10897
|
}
|
|
10891
10898
|
|
|
10899
|
+
// src/update-check.ts
|
|
10900
|
+
var PACKAGE_NAME = "pi-provider-qoder";
|
|
10901
|
+
var REGISTRY_URL = `https://registry.npmjs.org/${PACKAGE_NAME}/latest`;
|
|
10902
|
+
var DEFAULT_TIMEOUT_MS2 = 2e3;
|
|
10903
|
+
function parseSemver(version) {
|
|
10904
|
+
const match = /^v?(\d+)\.(\d+)\.(\d+)/.exec(version.trim());
|
|
10905
|
+
if (!match) return null;
|
|
10906
|
+
return [Number(match[1]), Number(match[2]), Number(match[3])];
|
|
10907
|
+
}
|
|
10908
|
+
function compareVersions(a, b2) {
|
|
10909
|
+
const left = parseSemver(a);
|
|
10910
|
+
const right = parseSemver(b2);
|
|
10911
|
+
if (!left || !right) return 0;
|
|
10912
|
+
for (let index = 0; index < left.length; index += 1) {
|
|
10913
|
+
if (left[index] !== right[index]) return left[index] - right[index];
|
|
10914
|
+
}
|
|
10915
|
+
return 0;
|
|
10916
|
+
}
|
|
10917
|
+
function upgradeCommand(hostExecutable) {
|
|
10918
|
+
const binary = (hostExecutable ?? "").split(/[\\/]/).pop() ?? "";
|
|
10919
|
+
if (/omp/i.test(binary)) return `omp plugin upgrade ${PACKAGE_NAME}`;
|
|
10920
|
+
if (/^pi/i.test(binary)) return `pi install npm:${PACKAGE_NAME}`;
|
|
10921
|
+
return `omp plugin upgrade ${PACKAGE_NAME} (pi: pi install npm:${PACKAGE_NAME})`;
|
|
10922
|
+
}
|
|
10923
|
+
function formatUpdateNotice(current, latest, hostExecutable) {
|
|
10924
|
+
if (compareVersions(latest, current) <= 0) return null;
|
|
10925
|
+
return `[${PACKAGE_NAME}] ${latest} is available (running ${current}). Upgrade: ${upgradeCommand(hostExecutable)}`;
|
|
10926
|
+
}
|
|
10927
|
+
async function fetchLatestVersion(fetchImpl = fetch, timeoutMs = DEFAULT_TIMEOUT_MS2) {
|
|
10928
|
+
const controller = new AbortController();
|
|
10929
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
10930
|
+
try {
|
|
10931
|
+
const response = await fetchImpl(REGISTRY_URL, {
|
|
10932
|
+
signal: controller.signal,
|
|
10933
|
+
headers: { accept: "application/json" }
|
|
10934
|
+
});
|
|
10935
|
+
if (!response.ok) return null;
|
|
10936
|
+
const body = await response.json();
|
|
10937
|
+
return typeof body.version === "string" ? body.version : null;
|
|
10938
|
+
} catch {
|
|
10939
|
+
return null;
|
|
10940
|
+
} finally {
|
|
10941
|
+
clearTimeout(timer);
|
|
10942
|
+
}
|
|
10943
|
+
}
|
|
10944
|
+
async function checkForUpdate(options) {
|
|
10945
|
+
if (options.disabled) return null;
|
|
10946
|
+
const latest = await fetchLatestVersion(options.fetchImpl ?? fetch, options.timeoutMs);
|
|
10947
|
+
if (!latest) return null;
|
|
10948
|
+
return formatUpdateNotice(options.currentVersion, latest, options.hostExecutable);
|
|
10949
|
+
}
|
|
10950
|
+
|
|
10892
10951
|
// src/usage-provider.ts
|
|
10893
10952
|
var KNOWN_UNITS = {
|
|
10894
10953
|
percent: true,
|
|
@@ -10975,6 +11034,8 @@ function createQoderUsageProvider(mode, providerID) {
|
|
|
10975
11034
|
|
|
10976
11035
|
// src/index.ts
|
|
10977
11036
|
var QODER_API = "qoder-api";
|
|
11037
|
+
var requirePackageJson = createRequire3(import.meta.url);
|
|
11038
|
+
var CURRENT_VERSION = requirePackageJson("../package.json").version ?? "0.0.0";
|
|
10978
11039
|
async function registerQoderApi() {
|
|
10979
11040
|
try {
|
|
10980
11041
|
const compat = await import("@earendil-works/pi-ai/compat");
|
|
@@ -11042,6 +11103,13 @@ async function refreshModelsAtStartup(mode) {
|
|
|
11042
11103
|
}
|
|
11043
11104
|
async function index_default(pi) {
|
|
11044
11105
|
await registerQoderApi();
|
|
11106
|
+
void checkForUpdate({
|
|
11107
|
+
currentVersion: CURRENT_VERSION,
|
|
11108
|
+
hostExecutable: process.argv[1],
|
|
11109
|
+
disabled: process.env.PI_PROVIDER_QODER_SKIP_UPDATE_CHECK === "1"
|
|
11110
|
+
}).then((notice) => {
|
|
11111
|
+
if (notice) console.error(notice);
|
|
11112
|
+
});
|
|
11045
11113
|
for (const mode of QODER_MODES) {
|
|
11046
11114
|
const providerID = getQoderRegionConfig(mode).providerID;
|
|
11047
11115
|
applyCachedChatEndpoint(mode);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-provider-qoder",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.10",
|
|
4
4
|
"description": "Pi extension for Qoder AI — with OAuth authentication, COSY signatures and WAF bypass",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -28,8 +28,9 @@
|
|
|
28
28
|
"test:live": "tsx scripts/record-live-fixtures.ts",
|
|
29
29
|
"test:watch": "vitest",
|
|
30
30
|
"prepare": "npm run build",
|
|
31
|
-
"prepublishOnly": "npm run check && npm run build",
|
|
32
|
-
"demo:credits": "tsx scripts/demo-credit-footer.ts"
|
|
31
|
+
"prepublishOnly": "npm run check && node scripts/sync-marketplace-version.mjs --check && npm run build",
|
|
32
|
+
"demo:credits": "tsx scripts/demo-credit-footer.ts",
|
|
33
|
+
"release:sync-marketplace": "node scripts/sync-marketplace-version.mjs"
|
|
33
34
|
},
|
|
34
35
|
"pi": {
|
|
35
36
|
"extensions": [
|
|
@@ -20,7 +20,7 @@ pi install npm:pi-typesafe
|
|
|
20
20
|
|
|
21
21
|
Then, inside Pi:
|
|
22
22
|
|
|
23
|
-
1. `/typesafe login` and paste a key from [console.typesafe.ai](https://console.typesafe.ai). Input is hidden; the key is verified against the API and saved to `~/.pi/agent/pi-typesafe/auth.json` with owner-only permissions. `/typesafe login <backend>` does the same for OpenRouter, Command Code, Liquid AI, SubQ, or an endpoint you name, keeping each key under its own name in the same store.
|
|
23
|
+
1. `/typesafe login` and paste a key from [console.typesafe.ai](https://console.typesafe.ai). Input is hidden; the key is verified against the API and saved to `~/.pi/agent/pi-typesafe/auth.json` with owner-only permissions. `/typesafe login <backend>` does the same for OpenRouter, Command Code, Liquid AI, SubQ, Nace.AI, or an endpoint you name, keeping each key under its own name in the same store.
|
|
24
24
|
2. `/typesafe test` sends one built-in sample request and shows the answers.
|
|
25
25
|
3. `/typesafe enable` lets the agent call the tool for this session, after you confirm the data notice.
|
|
26
26
|
|
|
@@ -73,7 +73,7 @@ The [TypeSafe docs](https://docs.typesafe.ai/primitives) cover each primitive in
|
|
|
73
73
|
|
|
74
74
|
An enabled extension with no usable key looks exactly like a working one — one evaluation ran keyless for hours before anyone noticed. Three answers exist now, and `/typesafe status` prints all of them:
|
|
75
75
|
|
|
76
|
-
- **Is Jev reachable?** `authState()` reports the key source, whether it has been accepted, and the last failure that degraded it; `describeAuth()` turns that into a level and one safe line. The extension calls both at session start
|
|
76
|
+
- **Is Jev reachable?** `authState()` reports the key source, whether it has been accepted, and the last failure that degraded it; `describeAuth()` turns that into a level and one safe line. The extension calls both at session start, so a headless run says judgments will fail instead of quietly falling back to its offline path. Only an HTTP 401 rejects the key, and even that stops vetoing it after fifteen minutes; a 403 refuses one request — permissions, a guardrail block, moderation, or a provider cap — and is shown without ever making the key unusable. Every message names the backend that answered.
|
|
77
77
|
- **What has this run cost?** `getSpend()` returns session counters, today's persisted counters, and the cap currently reached. Cost is estimated from input tokens only, because output is free; a count the API did not report counts as nothing.
|
|
78
78
|
- **When does it stop?** `maxRequests` bounds a client instance. Three caps bound a local day, survive restarts, and stop a request before it is submitted:
|
|
79
79
|
|
|
@@ -142,7 +142,7 @@ if (!answer.ok) return { skipped: answer.errorCode === "budget" }; // never thr
|
|
|
142
142
|
|
|
143
143
|
Your extension owns its own user consent and budget; `/typesafe enable` applies only to this package's tool. Check `authState()` rather than your own consent flag before you report that judgments are on.
|
|
144
144
|
|
|
145
|
-
Judgments can also go through OpenRouter: `createTypeSafe({ backend: "openrouter" })` sends them to `openrouter.ai` with the key from `OPENROUTER_API_KEY`. Command Code serves the same protocol: `createTypeSafe({ backend: "commandcode" })` sends them to `api.commandcode.ai` with the key from `COMMANDCODE_API_KEY` and the model `typesafe/jev`. So does Liquid AI: `createTypeSafe({ backend: "liquid" })` sends them to `api.liquid.ai` with the key from `LIQUID_API_KEY` and the model `d1:free`, which is free; pass `model: "d1"` for the paid model, priced at $0.040 per million input tokens. Liquid counts the state once per question, where TypeSafe counts it once per request, so a request with N questions costs about N times the state on Liquid. Speed, measured on 2026-10-03 with one request at a time: `d1:free` took a median of about 14 seconds and sometimes failed with HTTP 504 after about 46 seconds, while `d1` took about 0.5 seconds. With `d1:free`, raise `timeoutMs` above its 15-second default, or pass `model: "d1"`. SubQ too: `createTypeSafe({ backend: "subq" })` sends them to `api.subq.ai` with the key from `SUBQ_API_KEY` and the model `subq-snap-preview`, priced at $0.05 per million input tokens. SubQ takes at most 16 questions in one request, a Choice of at least 2 options, and a Score of at most 10 levels: `evaluate` refuses a larger request before it sends it, `evaluateAll` splits to 16, and `client.limits` tells you the limit without a request. Or pass a `BackendEndpoint` object as `backend` to name any host that serves the protocol: it brings its own key variable, never reads `TYPESAFE_API_KEY`, and `backendHost()` reports its destination host for your consent text. Each backend's key can also be stored with `/typesafe login <backend>`: it prompts once, proves the key with the backend's model list where that list checks the key and otherwise with one judge request, and saves it under that backend's name, so a key stored for one backend is never sent to another. A backend's own environment variable still wins over its stored key. Pass the same `backend` to `authState`, `keySituation`, and `ensureApiKey`, or the status you report describes the TypeSafe key while the requests use another one. The `/typesafe` commands and the `typesafe_evaluate` tool follow `PI_TYPESAFE_BACKEND` (`typesafe` by default) and name that backend's host, key variable, and model in their consent and status text — so the extension sends judgments where it says it sends them. A name the registry does not know is a `configuration` error at session start, not a silent fallback. `PI_TYPESAFE_MODEL` overrides the backend's default model, written as that backend's own id is written (`jev-1.14`; it is mapped to the backend's id form, so OpenRouter sends `typesafe/jev-1.14`). `/typesafe login [backend]` and `/typesafe logout [backend]` act on the backend they name, or on the session's own backend when they name none, and on a backend whose environment variable is set they say that the variable wins. Every export — the client, `ask`, batching, the usage ledger, auth state, the `PI_TYPESAFE_BACKEND` and `PI_TYPESAFE_MODEL` readers, and the `pi-typesafe/calibrate` and `pi-typesafe/ui` entry points — is in [docs/api.md](docs/api.md).
|
|
145
|
+
Judgments can also go through OpenRouter: `createTypeSafe({ backend: "openrouter" })` sends them to `openrouter.ai` with the key from `OPENROUTER_API_KEY`. Command Code serves the same protocol: `createTypeSafe({ backend: "commandcode" })` sends them to `api.commandcode.ai` with the key from `COMMANDCODE_API_KEY` and the model `typesafe/jev`. So does Liquid AI: `createTypeSafe({ backend: "liquid" })` sends them to `api.liquid.ai` with the key from `LIQUID_API_KEY` and the model `d1:free`, which is free; pass `model: "d1"` for the paid model, priced at $0.040 per million input tokens. Liquid counts the state once per question, where TypeSafe counts it once per request, so a request with N questions costs about N times the state on Liquid. Speed, measured on 2026-10-03 with one request at a time: `d1:free` took a median of about 14 seconds and sometimes failed with HTTP 504 after about 46 seconds, while `d1` took about 0.5 seconds. With `d1:free`, raise `timeoutMs` above its 15-second default, or pass `model: "d1"`. SubQ too: `createTypeSafe({ backend: "subq" })` sends them to `api.subq.ai` with the key from `SUBQ_API_KEY` and the model `subq-snap-preview`, priced at $0.05 per million input tokens. SubQ takes at most 16 questions in one request, a Choice of at least 2 options, and a Score of at most 10 levels: `evaluate` refuses a larger request before it sends it, `evaluateAll` splits to 16, and `client.limits` tells you the limit without a request. Nace.AI serves Drex the same way: `createTypeSafe({ backend: "nace" })` sends judgments to `console.nace.ai` with the key from `NACE_API_KEY` and the model `drex-v2.0`, priced at $0.060 per million input tokens; `drex-v1.5` is $0.050, and `drex-max` and `drex-max-v1.1` are $0.030. Nace accepted every request shape the schema allows, so it declares no narrower limits. Drex holds a request for up to 55 seconds upstream, so raise `timeoutMs` above its 15-second default for a heavy request. Or pass a `BackendEndpoint` object as `backend` to name any host that serves the protocol: it brings its own key variable, never reads `TYPESAFE_API_KEY`, and `backendHost()` reports its destination host for your consent text. Each backend's key can also be stored with `/typesafe login <backend>`: it prompts once, proves the key with the backend's model list where that list checks the key and otherwise with one judge request, and saves it under that backend's name, so a key stored for one backend is never sent to another. A backend's own environment variable still wins over its stored key. Pass the same `backend` to `authState`, `keySituation`, and `ensureApiKey`, or the status you report describes the TypeSafe key while the requests use another one. The `/typesafe` commands and the `typesafe_evaluate` tool follow `PI_TYPESAFE_BACKEND` (`typesafe` by default) and name that backend's host, key variable, and model in their consent and status text — so the extension sends judgments where it says it sends them. A name the registry does not know is a `configuration` error at session start, not a silent fallback. `PI_TYPESAFE_MODEL` overrides the backend's default model, written as that backend's own id is written (`jev-1.14`; it is mapped to the backend's id form, so OpenRouter sends `typesafe/jev-1.14`). `/typesafe login [backend]` and `/typesafe logout [backend]` act on the backend they name, or on the session's own backend when they name none, and on a backend whose environment variable is set they say that the variable wins. Every export — the client, `ask`, batching, the usage ledger, auth state, the `PI_TYPESAFE_BACKEND` and `PI_TYPESAFE_MODEL` readers, and the `pi-typesafe/calibrate` and `pi-typesafe/ui` entry points — is in [docs/api.md](docs/api.md).
|
|
146
146
|
|
|
147
147
|
## Development
|
|
148
148
|
|
|
@@ -2,6 +2,17 @@ import type { BackendSpec } from "./backends.js";
|
|
|
2
2
|
import type { KeySource } from "./credentials.js";
|
|
3
3
|
import { TypeSafeIntegrationError } from "./errors.js";
|
|
4
4
|
import type { IntegrationErrorCode } from "./errors.js";
|
|
5
|
+
/**
|
|
6
|
+
* How long a stored 401 vetoes the key. The next request proves the key again once the window passes, so one refusal
|
|
7
|
+
* cannot disable judgments for good. Fifteen minutes is a policy choice, not a measured provider constant.
|
|
8
|
+
*/
|
|
9
|
+
export declare const AUTH_REJECTION_TTL_MS: number;
|
|
10
|
+
/**
|
|
11
|
+
* Only HTTP 401 refuses the key itself. A 403 refuses one request — insufficient permissions, a guardrail block, a
|
|
12
|
+
* moderation flag, or a provider cap — so it never vetoes the key. OpenRouter's error page, checked 2026-11-03, gives
|
|
13
|
+
* 401 invalid credentials, 402 insufficient credits, and 403 forbidden.
|
|
14
|
+
*/
|
|
15
|
+
export declare function isKeyRejection(status: number | undefined): boolean;
|
|
5
16
|
/** The last request that degraded TypeSafe, with no upstream body, header, key, or submitted state. */
|
|
6
17
|
export interface AuthFailure {
|
|
7
18
|
readonly code: IntegrationErrorCode;
|
|
@@ -28,14 +39,17 @@ export interface AuthState {
|
|
|
28
39
|
readonly keyName: string;
|
|
29
40
|
/**
|
|
30
41
|
* True when the key in effect was accepted by the backend (a login proves the backend it was asked for; a successful
|
|
31
|
-
* request proves any key).
|
|
32
|
-
* next request.
|
|
42
|
+
* request proves any key). A 401 rejection younger than `AUTH_REJECTION_TTL_MS` clears it; a 403 never does. The
|
|
43
|
+
* record is shared across backends: switching backends keeps the last outcome until the next request.
|
|
33
44
|
*/
|
|
34
45
|
readonly verified: boolean;
|
|
35
46
|
readonly verifiedAt?: string;
|
|
36
47
|
/** The last failure, cleared by the next successful request. */
|
|
37
48
|
readonly lastFailure?: AuthFailure;
|
|
38
|
-
/**
|
|
49
|
+
/**
|
|
50
|
+
* A key is present and no 401 rejection younger than `AUTH_REJECTION_TTL_MS` stands against it. A 403 never makes it
|
|
51
|
+
* false, because it refuses one request, not the key. False means judgments will fail.
|
|
52
|
+
*/
|
|
39
53
|
readonly usable: boolean;
|
|
40
54
|
}
|
|
41
55
|
/** The auth-state file: one small, owner-only record that outlives the process that wrote it. */
|
|
@@ -56,7 +70,10 @@ export declare function recordAuthFailure(error: TypeSafeIntegrationError, at?:
|
|
|
56
70
|
/** Forget verification and degradation: used when the key itself changes (login or logout). */
|
|
57
71
|
export declare function clearAuthState(): void;
|
|
58
72
|
export interface AuthReport {
|
|
59
|
-
/**
|
|
73
|
+
/**
|
|
74
|
+
* `error` when judgments will fail or the key was rejected, `warning` when the key is unverified or its rejection has
|
|
75
|
+
* expired, otherwise `ok`.
|
|
76
|
+
*/
|
|
60
77
|
readonly level: "ok" | "warning" | "error";
|
|
61
78
|
/** One line naming the key source and, when degraded, the reason. Safe to display. */
|
|
62
79
|
readonly text: string;
|
|
@@ -7,8 +7,29 @@ const AUTH_VERSION = 1;
|
|
|
7
7
|
const CODES = new Set([
|
|
8
8
|
"configuration", "validation", "budget", "aborted", "timeout", "http", "connection", "response",
|
|
9
9
|
]);
|
|
10
|
-
/**
|
|
11
|
-
|
|
10
|
+
/**
|
|
11
|
+
* How long a stored 401 vetoes the key. The next request proves the key again once the window passes, so one refusal
|
|
12
|
+
* cannot disable judgments for good. Fifteen minutes is a policy choice, not a measured provider constant.
|
|
13
|
+
*/
|
|
14
|
+
export const AUTH_REJECTION_TTL_MS = 15 * 60 * 1000;
|
|
15
|
+
/**
|
|
16
|
+
* Only HTTP 401 refuses the key itself. A 403 refuses one request — insufficient permissions, a guardrail block, a
|
|
17
|
+
* moderation flag, or a provider cap — so it never vetoes the key. OpenRouter's error page, checked 2026-11-03, gives
|
|
18
|
+
* 401 invalid credentials, 402 insufficient credits, and 403 forbidden.
|
|
19
|
+
*/
|
|
20
|
+
export function isKeyRejection(status) {
|
|
21
|
+
return status === 401;
|
|
22
|
+
}
|
|
23
|
+
/** `fresh` still vetoes the key, `expired` is only a record of what was refused when: no schema change, no manual reset. */
|
|
24
|
+
function rejectionOf(failure) {
|
|
25
|
+
if (failure === undefined || failure.code !== "http" || !isKeyRejection(failure.status))
|
|
26
|
+
return "none";
|
|
27
|
+
const at = Date.parse(failure.at);
|
|
28
|
+
// A timestamp this code cannot read cannot prove the rejection is current, so it counts as spent.
|
|
29
|
+
if (!Number.isFinite(at))
|
|
30
|
+
return "expired";
|
|
31
|
+
return Date.now() - at < AUTH_REJECTION_TTL_MS ? "fresh" : "expired";
|
|
32
|
+
}
|
|
12
33
|
/** The auth-state file: one small, owner-only record that outlives the process that wrote it. */
|
|
13
34
|
export function authStatePath() {
|
|
14
35
|
return join(piTypesafeDir(), "auth-state.json");
|
|
@@ -61,7 +82,7 @@ export function authState(options = {}) {
|
|
|
61
82
|
const situation = keySituation(backend);
|
|
62
83
|
const stored = readState(path);
|
|
63
84
|
const source = situation.kind === "environment" ? "environment" : situation.kind === "stored" ? "stored" : undefined;
|
|
64
|
-
const rejected = stored.lastFailure
|
|
85
|
+
const rejected = rejectionOf(stored.lastFailure) === "fresh";
|
|
65
86
|
const usable = source !== undefined && !rejected;
|
|
66
87
|
return {
|
|
67
88
|
backend,
|
|
@@ -108,15 +129,19 @@ export function describeAuth(state = authState()) {
|
|
|
108
129
|
const since = state.lastFailure ? ` Last failure: ${state.lastFailure.message}${state.lastFailure.at ? ` (${state.lastFailure.at})` : ""}` : "";
|
|
109
130
|
if (state.kind === "missing") {
|
|
110
131
|
const how = `a key is configured (/typesafe login${config.name && config.name !== DEFAULT_BACKEND ? ` ${config.name}` : ""} or ${config.keyEnv})`;
|
|
111
|
-
return { level: "error", text: `${label}: missing — every Jev judgment
|
|
132
|
+
return { level: "error", text: `${label}: missing — every Jev judgment will fail until ${how}.${since}` };
|
|
112
133
|
}
|
|
113
134
|
if (state.kind === "unusable") {
|
|
114
|
-
return { level: "error", text: `${label}: unusable (${state.reason ?? "unknown reason"}) — judgments
|
|
135
|
+
return { level: "error", text: `${label}: unusable (${state.reason ?? "unknown reason"}) — judgments will fail until the key is fixed.${since}` };
|
|
115
136
|
}
|
|
116
|
-
const
|
|
117
|
-
if (
|
|
137
|
+
const rejection = rejectionOf(state.lastFailure);
|
|
138
|
+
if (rejection === "fresh") {
|
|
118
139
|
return { level: "error", text: `${label}: ${state.keyName} was rejected.${since}` };
|
|
119
140
|
}
|
|
141
|
+
if (rejection === "expired") {
|
|
142
|
+
const at = state.lastFailure?.at;
|
|
143
|
+
return { level: "warning", text: `${label}: ${state.keyName} was rejected${at === undefined ? "" : ` at ${at}`}; that rejection expired, so the next request proves the key.` };
|
|
144
|
+
}
|
|
120
145
|
if (!state.verified) {
|
|
121
146
|
return { level: "warning", text: `${label}: ${state.keyName} (not verified yet — the first request proves it).${since}` };
|
|
122
147
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { BackendLimits } from "./schema.js";
|
|
2
|
-
export type TypeSafeBackend = "typesafe" | "openrouter" | "commandcode" | "liquid" | "subq";
|
|
2
|
+
export type TypeSafeBackend = "typesafe" | "openrouter" | "commandcode" | "liquid" | "subq" | "nace";
|
|
3
3
|
export interface BackendConfig {
|
|
4
|
-
/** Human name for status lines: "TypeSafe", "OpenRouter", "Command Code", "Liquid AI", "SubQ". */
|
|
4
|
+
/** Human name for status lines: "TypeSafe", "OpenRouter", "Command Code", "Liquid AI", "SubQ", "Nace.AI". */
|
|
5
5
|
label: string;
|
|
6
6
|
host: string;
|
|
7
7
|
/** The environment variable that carries this backend's key. Absent means the TypeSafe key resolution applies. */
|
|
@@ -47,6 +47,14 @@ export const DECISIONS_BACKENDS = {
|
|
|
47
47
|
limits: { maxQuestions: 16, minChoiceOptions: 2, maxScoreLevels: 10 },
|
|
48
48
|
prices: { "subq-snap-preview": 0.05 },
|
|
49
49
|
},
|
|
50
|
+
nace: {
|
|
51
|
+
label: "Nace.AI",
|
|
52
|
+
host: "https://console.nace.ai",
|
|
53
|
+
keyEnv: "NACE_API_KEY",
|
|
54
|
+
// No limits: measured on 2026-11-04, Nace accepted 1 option, 2 and 33 score levels, 64 options, and 64 questions.
|
|
55
|
+
// An alias or retired id is billed at the version that answers it; `drex-max-finance` has no published price, so it falls back to the default estimate.
|
|
56
|
+
prices: { "drex-v2.0": 0.06, "drex-v1.5": 0.05, "drex-max": 0.03, "drex-max-v1.1": 0.03, "drex-latest": 0.06, "nacedm-latest": 0.06, "drex-v1.0": 0.03, "drex-v1.1": 0.05 },
|
|
57
|
+
},
|
|
50
58
|
};
|
|
51
59
|
/** The registry entry for a backend name; a `configuration` error for a name the registry does not know. */
|
|
52
60
|
export function backendConfig(name) {
|
|
@@ -86,6 +94,7 @@ const DEFAULT_MODEL = {
|
|
|
86
94
|
commandcode: "typesafe/jev",
|
|
87
95
|
liquid: "d1:free",
|
|
88
96
|
subq: "subq-snap-preview",
|
|
97
|
+
nace: "drex-v2.0",
|
|
89
98
|
};
|
|
90
99
|
/**
|
|
91
100
|
* The model id to send for a caller's `model` on this backend. OpenRouter routes a bare Jev id under the `typesafe`
|
|
@@ -229,9 +229,8 @@ export function createTypeSafe(options = {}) {
|
|
|
229
229
|
const ledger = options.ledger ?? openUsageLedger(callerRate === undefined ? {} : { usdPerMTok: callerRate });
|
|
230
230
|
let sessionUsd = 0;
|
|
231
231
|
const usage = { requestsStarted: 0, requestsSucceeded: 0, requestsFailed: 0, inputTokens: 0, outputTokens: 0 };
|
|
232
|
-
//
|
|
232
|
+
// One verification record per process; every failure is written, because its time is the rejection window's anchor.
|
|
233
233
|
let verificationRecorded = false;
|
|
234
|
-
let lastFailureRecorded;
|
|
235
234
|
const snapshot = () => ({ ...usage, estimatedUsd: Math.round(sessionUsd * 1e6) / 1e6 });
|
|
236
235
|
const blocked = () => (usage.requestsStarted >= maxRequests ? undefined : ledger.blocked(caps));
|
|
237
236
|
const typesafe = {
|
|
@@ -251,7 +250,7 @@ export function createTypeSafe(options = {}) {
|
|
|
251
250
|
try {
|
|
252
251
|
const models = await client.models.list(callOptions);
|
|
253
252
|
if (!Array.isArray(models))
|
|
254
|
-
throw new TypeSafeIntegrationError("response",
|
|
253
|
+
throw new TypeSafeIntegrationError("response", `${backend.label} returned an unexpected model list.`);
|
|
255
254
|
// A backend that serves its list publicly accepts any key, so a success there proves nothing about one.
|
|
256
255
|
if (backend.modelsVerifyKey && !verificationRecorded) {
|
|
257
256
|
verificationRecorded = true;
|
|
@@ -270,14 +269,14 @@ export function createTypeSafe(options = {}) {
|
|
|
270
269
|
const body = JSON.stringify({ ...validated, model: sentModel });
|
|
271
270
|
assertWithinByteLimit(body, maxInputBytes);
|
|
272
271
|
if (callOptions.signal?.aborted)
|
|
273
|
-
throw new TypeSafeIntegrationError("aborted",
|
|
272
|
+
throw new TypeSafeIntegrationError("aborted", `${backend.label} request cancelled before submission.`);
|
|
274
273
|
if (usage.requestsStarted >= maxRequests) {
|
|
275
|
-
throw new TypeSafeIntegrationError("budget",
|
|
274
|
+
throw new TypeSafeIntegrationError("budget", `${backend.label} request limit reached (${maxRequests} attempts per client instance). ${capsDescription(caps)}`);
|
|
276
275
|
}
|
|
277
276
|
const reached = ledger.blocked(caps);
|
|
278
277
|
if (reached) {
|
|
279
278
|
// Name the cap, the used amount, and the day, so a long run stops loudly instead of burning tokens unnoticed.
|
|
280
|
-
throw new TypeSafeIntegrationError("budget",
|
|
279
|
+
throw new TypeSafeIntegrationError("budget", `${backend.label} ${CAP_LABELS[reached.cap]} reached (${reached.used} of ${reached.limit} on ${reached.day}); no request was submitted. Requests resume after the local day rolls over, or raise the cap deliberately.`);
|
|
281
280
|
}
|
|
282
281
|
// Snapshot before awaiting so later mutations cannot change the request or validation.
|
|
283
282
|
const request = JSON.parse(body);
|
|
@@ -287,7 +286,7 @@ export function createTypeSafe(options = {}) {
|
|
|
287
286
|
try {
|
|
288
287
|
const result = await client.systemOne(request, callOptions);
|
|
289
288
|
if (!validResult(result, request.questions))
|
|
290
|
-
throw new TypeSafeIntegrationError("response",
|
|
289
|
+
throw new TypeSafeIntegrationError("response", `${backend.label} returned an unexpected answer or usage format.`);
|
|
291
290
|
usage.requestsSucceeded += 1;
|
|
292
291
|
// An unreported count is not a count this package can add, price, or charge against a token cap.
|
|
293
292
|
const inputTokens = result.usage.input_tokens ?? 0;
|
|
@@ -309,11 +308,7 @@ export function createTypeSafe(options = {}) {
|
|
|
309
308
|
// The request was submitted, so it counts even when it fails; the reason stays visible in `authState()`.
|
|
310
309
|
usage.requestsFailed += 1;
|
|
311
310
|
ledger.recordFailure();
|
|
312
|
-
|
|
313
|
-
if (lastFailureRecorded !== fingerprint) {
|
|
314
|
-
lastFailureRecorded = fingerprint;
|
|
315
|
-
recordAuthFailure(safe);
|
|
316
|
-
}
|
|
311
|
+
recordAuthFailure(safe);
|
|
317
312
|
throw safe;
|
|
318
313
|
}
|
|
319
314
|
},
|
|
@@ -11,7 +11,8 @@ export declare class TypeSafeIntegrationError extends Error {
|
|
|
11
11
|
constructor(code: IntegrationErrorCode, message: string, status?: number | undefined);
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
14
|
-
* Classify an error into a message safe to display.
|
|
15
|
-
*
|
|
14
|
+
* Classify an error into a message safe to display. The subject of every message is the backend that answered — its
|
|
15
|
+
* `label`, or the caller's endpoint label — falling back to TypeSafe when no backend is passed. `backend` also names
|
|
16
|
+
* the key variable the 401 advice tells the user to check and selects the 402 wording.
|
|
16
17
|
*/
|
|
17
18
|
export declare function safeError(error: unknown, backend?: BackendSpec | BackendConfig): TypeSafeIntegrationError;
|