pi-openai-toolkit 0.19.0 → 0.20.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/README.md CHANGED
@@ -1,242 +1,156 @@
1
- # pi-openai-toolkit
2
-
3
- Add Codex context windows, Responses compaction, hosted tools, and tool-call review to Pi.
4
-
5
- [![npm version](https://img.shields.io/npm/v/pi-openai-toolkit.svg)](https://www.npmjs.com/package/pi-openai-toolkit)
6
- [![License: MIT](https://img.shields.io/npm/l/pi-openai-toolkit.svg)](LICENSE)
7
-
8
- [简体中文](README.zh.md)
9
-
10
- ## Features
11
-
12
- | Feature | Use it to |
13
- | --- | --- |
14
- | Codex Remote Context | Start new windows with the adapted Codex protocol and retrieve earlier work through `history`. |
15
- | Remote Compaction v2 | Continue Responses sessions with encrypted server checkpoints. |
16
- | Web Search | Choose local `pi-web-access`, Responses `web_search`, or experimental CPA `web_run` per model. |
17
- | Image generation | Generate or edit raster images through a separate Images API request. |
18
- | Tool-call review | Have a reviewer model approve selected calls through Toolkit's approval gate. |
19
-
20
- The package uses Pi's existing models, authentication, and sessions. It does not add a provider or model.
21
-
22
- ## Install
23
-
24
- Requires Pi 0.87.0+ and Node.js 22.19.0+.
25
-
26
- ```bash
27
- pi install npm:pi-openai-toolkit
28
- ```
29
-
30
- Add `--local` for a project-local installation. Toolkit configuration is global in either case:
31
-
32
- `~/.pi/agent/extensions/pi-openai-toolkit/config.json`
33
-
34
- Create the file and parent directory if needed. Merge the Toolkit examples below into an existing **schema v2** config; do not replace unrelated settings. For an unversioned legacy config, run `/toolkit-config migration-preview` first. See the [migration guide](docs/configuration.md#legacy-compatibility-and-migration).
35
-
36
- By default, eligible models use Remote Compaction v2. Remote Context windows, image generation, and Auto Mode are off; search is unmanaged. Backend support is still required.
37
-
38
- ## Quick start: enable Remote Context
39
-
40
- For search, images, or tool-call review only, skip to [Common tasks](#common-tasks).
41
-
42
- ### Use Pi's built-in Codex provider
43
-
44
- Sign in to Pi's `openai-codex` provider, then add this Toolkit config:
45
-
46
- ```json
47
- {
48
- "schemaVersion": 2,
49
- "defaults": {
50
- "context": { "mode": "remote-windows" }
51
- }
52
- }
53
- ```
54
-
55
- Start Pi with a model ID from your Codex catalog:
56
-
57
- ```bash
58
- pi --model openai-codex/<model-id>
59
- ```
60
-
61
- Look for `new_context`, `get_context_remaining`, `history`, and `notes`. Their presence confirms activation, not backend compatibility. Earlier windows stay accessible through `history` without being loaded into every request.
62
-
63
- ### Use a compatible gateway
64
-
65
- The gateway must support `openai-responses` and the Codex Remote Context protocol. Ordinary chat support is not enough.
66
-
67
- If your model is already registered in `~/.pi/agent/models.json`, skip the registration example.
68
-
69
- <details>
70
- <summary>Register a gateway model in Pi</summary>
71
-
72
- Merge this into Pi's models file. Replace the provider name, URL, key variable, model ID, and limits with your setup; the numbers are examples.
73
-
74
- ```json
75
- {
76
- "providers": {
77
- "my-gateway": {
78
- "baseUrl": "https://your-gateway.example/v1",
79
- "api": "openai-responses",
80
- "apiKey": "$MY_GATEWAY_KEY",
81
- "models": [{
82
- "id": "gpt-5.6-luna",
83
- "name": "GPT-5.6 Luna",
84
- "reasoning": true,
85
- "input": ["text"],
86
- "contextWindow": 272000,
87
- "maxTokens": 128000
88
- }]
89
- }
90
- }
91
- }
92
- ```
93
-
94
- Set the key in PowerShell:
95
-
96
- ```powershell
97
- $env:MY_GATEWAY_KEY = "replace-with-your-gateway-key"
98
- ```
99
-
100
- Or in a POSIX shell:
101
-
102
- ```bash
103
- export MY_GATEWAY_KEY="replace-with-your-gateway-key"
104
- ```
105
-
106
- Start Pi from the same terminal.
107
-
108
- </details>
109
-
110
- Add the exact registered `provider/model-id` to Toolkit's config:
111
-
112
- ```json
113
- {
114
- "schemaVersion": 2,
115
- "models": {
116
- "my-gateway/gpt-5.6-luna": {
117
- "context": { "mode": "remote-windows" },
118
- "compatibility": { "transport": "codex-gateway" }
119
- }
120
- }
121
- }
122
- ```
123
-
124
- ```bash
125
- pi --model my-gateway/gpt-5.6-luna
126
- ```
127
-
128
- Check for the same context tools listed above. If they are missing, use `/toolkit-config` and check the notification, model key, API, credentials, and URL.
129
-
130
- ## Common tasks
131
-
132
- ### Save work and switch windows with `/compact`
133
-
134
- In an active Remote Context session, run `/compact` to save work to notes and enter a new window without a conversation summary. You can append instructions to the command.
135
-
136
- To use a separate checkpoint model, set `context.remoteCompaction.model` under `defaults` or an exact model override. It must support Remote Context on the same backend/account; leaving it unset uses the current model. Toolkit restores your original model and thinking level before continuing. See [context settings and requirements](docs/configuration.md#context).
137
-
138
- ### Use server-side compaction
139
-
140
- Set `context.mode` to `"remote-compaction"` (the default) for encrypted Responses checkpoints, or `"pi"` to leave context management to Pi. Advanced input and fallback options are in the [configuration reference](docs/configuration.md#context).
141
-
142
- ### Choose a Web Search route
143
-
144
- Set a default route and override it for individual models:
145
-
146
- ```json
147
- {
148
- "schemaVersion": 2,
149
- "defaults": {
150
- "webSearch": { "route": "local" }
151
- },
152
- "models": {
153
- "my-gateway/gpt-5.6-luna": {
154
- "webSearch": { "route": "hosted" }
155
- }
156
- }
157
- }
158
- ```
159
-
160
- | Route | Behavior |
161
- | --- | --- |
162
- | `unmanaged` | Leave search to Pi and other extensions. |
163
- | `local` | Keep the existing local `pi-web-access` tools. |
164
- | `hosted` | Use Responses `web_search` with source annotations. |
165
- | `standalone-alpha` | Use experimental `web_run` on a CPA/Codex gateway that supports `/alpha/search`. |
166
-
167
- Toolkit does not fall back between routes. See [search configuration](docs/configuration.md#web-search) for backend requirements.
168
-
169
- ### Generate an image
170
-
171
- Requires an eligible Responses-capable session and may incur provider charges. The local Pi tool sends a separate Images API request to the current provider (`/images/generations` or `/images/edits`; Codex uses `/codex/images/...`) rather than adding an image tool to the conversation request. Enable it with an image model your provider supports:
172
-
173
- ```json
174
- {
175
- "schemaVersion": 2,
176
- "defaults": {
177
- "imageGeneration": {
178
- "enabled": true,
179
- "defaultModel": "grok-imagine-image-2.0",
180
- "allowedModels": ["grok-imagine-image-2.0"]
181
- }
182
- }
183
- }
184
- ```
185
-
186
- Ask Pi to generate an image or edit explicitly supplied local references using `openai_generate_image`. The selected image model is sent in the independent request; the active conversation model remains the routing/auth model. PNG, JPEG, and WebP responses are validated and saved in their actual format. Set the tool's optional `model` to another exact `allowedModels` entry, or use `batchSize` (1-10) for concurrent independent variants. Batch calls save canonical artifacts and cannot use a single-file `outputPath`; when `quality` is `auto`, the field is omitted so compatible gateways can apply their own default. Image settings are global. See [image configuration](docs/configuration.md#images).
187
-
188
- ### Review tool calls automatically
189
-
190
- Enable Auto Mode for a model and choose its reviewer:
191
-
192
- ```json
193
- {
194
- "schemaVersion": 2,
195
- "models": {
196
- "my-gateway/gpt-5.6-luna": {
197
- "autoMode": {
198
- "available": true,
199
- "reviewerModel": "my-gateway/gpt-5.6-luna"
200
- }
201
- }
202
- }
203
- }
204
- ```
205
-
206
- Turn it on with `/auto on` or `--auto`, and off with `/auto off`. By default it reviews `bash`, `write`, `edit`, and configured extra tools; `gate: "all"` reviews every call. A reviewer timeout never approves a call. See [Auto Mode settings](docs/configuration.md#auto-mode).
207
-
208
- ## Common configuration
209
-
210
- Use `defaults` for shared settings and `models["provider/model-id"]` for exact model overrides. Toolkit reads only the global config file.
211
-
212
- | Command | Purpose |
213
- | --- | --- |
214
- | `/toolkit-config` | Show effective settings and their origins. |
215
- | `/toolkit-config validate` | Check for configuration errors. |
216
- | `/toolkit-config migration-preview` | Preview a legacy-to-v2 migration without writing files. |
217
-
218
- These commands require Pi's interactive UI. See the [full configuration reference](docs/configuration.md), [editor schema](config.schema.json), and [implementation details](docs/internals.md).
219
-
220
- ## Development
221
-
222
- After installing dependencies in the repository root:
223
-
224
- ```bash
225
- npm run typecheck
226
- ```
227
-
228
- ```bash
229
- bun test
230
- ```
231
-
232
- ```bash
233
- npm run test:pi
234
- ```
235
-
236
- ```bash
237
- npm pack --dry-run
238
- ```
239
-
240
- ## License
241
-
242
- MIT © awoaCrim and contributors. See [LICENSE](LICENSE) and [NOTICE](NOTICE).
1
+ # pi-openai-toolkit
2
+
3
+ Remote context windows, Responses compaction, web search, image generation, and tool-call review for Pi. Uses Pi's existing models, endpoints, authentication, and sessions without registering another provider or model.
4
+
5
+ [![npm version](https://img.shields.io/npm/v/pi-openai-toolkit.svg)](https://www.npmjs.com/package/pi-openai-toolkit)
6
+ [![MIT](https://img.shields.io/npm/l/pi-openai-toolkit.svg)](LICENSE)
7
+
8
+ [简体中文](README.zh.md)
9
+
10
+ ## Install and start
11
+
12
+ Requires Node.js **22.19.0+** and Pi **0.87.0+**. Current development dependencies pin Pi **0.99.1**; backend features also depend on the selected model, API, and account access.
13
+
14
+ ```bash
15
+ pi install npm:pi-openai-toolkit
16
+ ```
17
+
18
+ Configure your model and credentials in Pi, then start Pi normally. Without a Toolkit config file, eligible models use remote compaction by default. Search remains managed by Pi and other extensions; image generation and Auto Mode are off.
19
+
20
+ Toolkit reads one global configuration file, even for a project-local installation:
21
+
22
+ ```text
23
+ ~/.pi/agent/extensions/pi-openai-toolkit/config.json
24
+ ```
25
+
26
+ Create the parent directory if needed. New configurations use schema v2:
27
+
28
+ ```json
29
+ {
30
+ "schemaVersion": 2,
31
+ "defaults": {
32
+ "context": { "mode": "remote-compaction" }
33
+ }
34
+ }
35
+ ```
36
+
37
+ Check the configuration from Pi:
38
+
39
+ - `/toolkit-config`: show effective values and their sources
40
+ - `/toolkit-config validate`: check configuration errors
41
+ - `/toolkit-config migration-preview`: preview a legacy migration without writing files
42
+
43
+ Settings resolve in this order: built-in defaults → `defaults` → `models["provider/model-id"]`. Model keys are exact and case-sensitive; wildcards and project-level policy are not supported. Merge the examples below into your existing file without replacing unrelated settings. For an unversioned configuration, read the [migration guide](docs/configuration.md#legacy-compatibility-and-migration) first.
44
+
45
+ ## Context management
46
+
47
+ Set `defaults.context.mode` or an individual model's `context.mode`:
48
+
49
+ - `remote-compaction`: the default; continue with encrypted checkpoints returned by the server
50
+ - `remote-windows`: use Codex remote context windows, retrieve earlier work with `history`, and save handoff notes with `notes`
51
+ - `pi`: leave context management to Pi
52
+
53
+ **Remote compaction** accepts the `openai-responses`, `openai-codex-responses`, and `azure-openai-responses` API types. The backend must still support the checkpoint protocol. Set `context.remoteCompaction.model` to use a separate compaction model; remote compaction requires the same effective base URL as the active model. Native summary fallback has separate settings and does not apply to every failure: empty checkpoints, incompatible provenance, or edits to sealed history block storage or replay. See [context settings](docs/configuration.md#context) and [checkpoint rules](docs/internals.md#remote-compaction-v2-wire-contract).
54
+
55
+ **Remote windows** require the native `openai-codex` provider with `openai-codex-responses`, or an `openai-responses` gateway implementing the protocol. Gateways require `compatibility.transport: "codex-gateway"` on the exact model entry. This setting does not add the capability to an ordinary compatible endpoint.
56
+
57
+ Change `mode` in the example above to `remote-windows`. Eligible sessions expose `new_context`, `get_context_remaining`, `history`, and `notes`. Manual `/compact [instructions]` starts a checkpoint handoff: write notes successfully, then switch windows. Models without window capability retain the compaction flow; a failed window activation does not silently switch to a summary.
58
+
59
+ Remote windows use alpha endpoints that may change upstream. When switching models, also watch for retired-window history that has not yet been trimmed. See the [window lifecycle](docs/internals.md#rollover-lifecycle).
60
+
61
+ ## Search, images, and tool review
62
+
63
+ ### Web search
64
+
65
+ Set `defaults.webSearch.route` or an exact model's `webSearch.route`:
66
+
67
+ - `unmanaged`: the default; leave search ownership alone. This does not disable network access
68
+ - `local`: retain existing local search tools, such as `pi-web-access`; do not install or activate previously inactive tools
69
+ - `hosted`: use Responses `web_search` with source annotations and suppress conflicting local search tools
70
+ - `standalone-alpha`: experimental `web_run`, using a separate `/alpha/search` request for searches, page opening, and related operations
71
+
72
+ `hosted` accepts the three Responses API types listed above, subject to backend support and account access. `standalone-alpha` is restricted to verified OpenAI/Codex routes; a gateway must expose the endpoint and capability. An unavailable route, missing authentication, or a tool conflict never causes an automatic switch to another route. See [search configuration](docs/configuration.md#web-search) for supported operations.
73
+
74
+ ### Image generation
75
+
76
+ Image settings belong only under global `defaults.imageGeneration`. Replace `image-model-id` with an image model your backend supports:
77
+
78
+ ```json
79
+ {
80
+ "schemaVersion": 2,
81
+ "defaults": {
82
+ "imageGeneration": {
83
+ "enabled": true,
84
+ "defaultModel": "image-model-id",
85
+ "allowedModels": ["image-model-id"]
86
+ }
87
+ }
88
+ }
89
+ ```
90
+
91
+ Eligible sessions expose `openai_generate_image` for generation, reference-image editing, and batches. The conversation model supplies routing and authentication; the image model is called through a separate Images API without replacing the conversation model. The built-in image default is `grok-imagine-image-2.0`, which your backend may not support. `defaultModel` must be included in `allowedModels`.
92
+
93
+ Requires an `openai-responses` or `openai-codex-responses` route and a working Images API. Responses must contain base64-encoded PNG, JPEG, or WebP output. `batchSize` accepts 1–10; each image is a separate request and may incur a separate charge. Partial failure preserves images already saved. Editing sends reference images to the provider, so make sure those images can be uploaded. See [image configuration](docs/configuration.md#images).
94
+
95
+ ### Responses WebSocket transport
96
+
97
+ The Toolkit WebSocket adapter is disabled by default. Enable it globally for GPT models that use Pi's `openai-responses` API:
98
+
99
+ ```json
100
+ {
101
+ "schemaVersion": 2,
102
+ "defaults": {
103
+ "responsesWebSocket": { "enabled": true }
104
+ }
105
+ }
106
+ ```
107
+
108
+ It reuses the selected model's provider, base URL, credentials, headers, and model ID without registering another provider. Pi's `transport: "auto"` tries WebSocket first and falls back to SSE before streaming starts; `transport: "sse"` keeps the original HTTP/SSE path. Restart or reload Pi after changing the Toolkit setting. See [WebSocket configuration](docs/configuration.md#responses-websocket-transport).
109
+
110
+ ### Auto Mode
111
+
112
+ Auto Mode uses model-based review before tool execution. Permit it and select a reviewer registered and authenticated in Pi, then engage it explicitly:
113
+
114
+ ```json
115
+ {
116
+ "schemaVersion": 2,
117
+ "defaults": {
118
+ "autoMode": {
119
+ "available": true,
120
+ "reviewerModel": "provider/reviewer-model-id"
121
+ }
122
+ }
123
+ }
124
+ ```
125
+
126
+ Replace `provider/reviewer-model-id` with a real model reference. Use `/auto on` or the `--auto` startup flag to engage, and `/auto off` to disengage. Setting `available: true` alone does not engage the gate.
127
+
128
+ The default `gate: "side-effect"` reviews `bash`, `write`, `edit`, and `extraTools`. Use `gate: "all"` to cover every tool. Read-only evidence gathering, denial circuit breakers, and optional background classifier pre-scoring are supported. With the classifier enabled, some calls can pass based on a pre-score.
129
+
130
+ A timeout or unavailable review is never approval: interactive sessions ask for confirmation, while headless sessions block the call. This is not a sandbox or a guarantee of correct decisions. Selecting an ineligible model disengages Auto Mode. See [Auto Mode settings](docs/configuration.md#auto-mode).
131
+
132
+ ## Compatibility and troubleshooting
133
+
134
+ - Keep providers, endpoints, and credentials in Pi, not Toolkit configuration. See [provider setup](docs/configuration.md#provider-specific-responses-endpoints) for Azure deployment mapping, `api-version`, and authentication
135
+ - `pi-virtual` capability checks use the physical provider/model resolved by Pi, without inferring support from the virtual model's name
136
+ - Compaction and replay honor `inputLimits.images` resizing and count limits from Pi model metadata without changing the persisted session or original request object
137
+ - Invalid settings block dependent operations. Run `/toolkit-config validate`, then check the model, authentication, and backend capabilities. Valid configuration is not a successful endpoint test
138
+ - Request and compact-response capture are off by default. Enable `diagnostics.captureRequests` / `captureResponses` only for troubleshooting, and check logs for conversation content before sharing
139
+
140
+ See the [configuration reference](docs/configuration.md) and [JSON Schema](config.schema.json) for all fields and defaults. Protocol, checkpoint, and debugging details are in [internals](docs/internals.md).
141
+
142
+ ## Development
143
+
144
+ From the repository root:
145
+
146
+ ```bash
147
+ npm ci
148
+ npm run typecheck
149
+ npm test
150
+ npm run test:pi
151
+ npm pack --dry-run
152
+ ```
153
+
154
+ Tests use Bun, included in the development dependencies. Keep JSON examples identical in both READMEs; the documentation tests check this.
155
+
156
+ MIT © awoaCrim and contributors. See [LICENSE](LICENSE) and [NOTICE](NOTICE) for third-party attribution.