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 +156 -242
- package/README.zh.md +156 -242
- package/config.schema.json +13 -0
- package/docs/configuration.md +128 -0
- package/package.json +5 -2
- package/src/config/policy.ts +4 -2
- package/src/config/v2.ts +36 -3
- package/src/config.ts +1 -0
- package/src/responses-websocket/extension.ts +32 -0
- package/src/responses-websocket/transport.ts +577 -0
- package/tsconfig.check.json +2 -0
package/README.md
CHANGED
|
@@ -1,242 +1,156 @@
|
|
|
1
|
-
# pi-openai-toolkit
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
[](https://www.npmjs.com/package/pi-openai-toolkit)
|
|
6
|
-
[
|
|
9
|
-
|
|
10
|
-
##
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
###
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
```
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
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
|
+
[](https://www.npmjs.com/package/pi-openai-toolkit)
|
|
6
|
+
[](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.
|