pi-clawbay 0.0.15 → 0.0.17

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,107 +1,77 @@
1
1
  # TheClawBay Provider for Pi Coding Agent
2
2
 
3
- A provider extension for [pi coding agent](https://github.com/badlogic/pi-mono) that enables access to GPT-5 and Codex models through [TheClawBay](https://theclawbay.com) API.
3
+ `pi-clawbay` is a Pi Coding Agent provider extension for [TheClawBay](https://theclawbay.com). It exposes TheClawBay GPT/Codex models through Pi and includes image generation support through both Codex-style hosted tools and the direct Images API.
4
4
 
5
5
  ## Features
6
6
 
7
- - **GPT-5 & Codex Models** - Access via Codex Responses API with session-based prompt cache
8
- - **Single Provider** - Only `theclawbay` is registered
9
- - **GPT-5.4 Split Options** - `gpt-5.4` and `gpt-5.4[1m]` for clearer cost/context choice
10
- - **High Usage Headroom** - More capacity than standard subscriptions
11
- - **Simple Setup** - Single API key
7
+ - **Single Pi provider:** registers `theclawbay`.
8
+ - **Codex Responses transport:** sends requests to TheClawBay's native Codex route over HTTP streaming.
9
+ - **Dynamic model discovery:** loads model IDs from TheClawBay's `/v1/models` endpoint and caches successful discovery results.
10
+ - **GPT-5.4 variants:** exposes `gpt-5.4` and `gpt-5.4[1m]` as separate Pi selections while remapping both to the upstream `gpt-5.4` model ID.
11
+ - **Hosted image generation:** Codex-style `image_generation` hosted tool support exposed as a model tool; the model decides when to call it with `tool_choice: auto`.
12
+ - **Direct Images API transport:** manual `gpt-image-2` and `gpt-image-1.5` selections call TheClawBay's documented `/v1/images/generations` endpoint and save returned PNGs locally.
13
+ - **Quota command:** adds `/quota` for current TheClawBay usage information.
12
14
 
13
15
  ## Installation
14
16
 
15
- ### Recommended: Install from npm
17
+ ### Recommended: npm
16
18
 
17
19
  ```bash
18
20
  pi install npm:pi-clawbay@latest
19
21
  ```
20
22
 
21
- This uses the published npm package and avoids npm's GitHub dependency path.
23
+ Use the npm package form above. Do not install `npm:chrislopez24/pi-clawbay`; npm treats that as a GitHub-style dependency and it can leave broken global symlinks.
22
24
 
23
- Do not use:
24
-
25
- ```bash
26
- pi install npm:chrislopez24/pi-clawbay
27
- ```
28
-
29
- That form is treated as a GitHub install, not a registry package install, and it can leave broken global symlinks behind.
30
-
31
- ### Local Development
25
+ ### Local development
32
26
 
33
27
  ```bash
34
28
  pi -e /path/to/pi-clawbay
35
29
  ```
36
30
 
37
- Use this only while actively developing the extension locally.
31
+ Use local loading only while developing or testing this extension.
38
32
 
39
33
  ## Configuration
40
34
 
41
- ### Environment Variable
42
-
43
35
  Set your TheClawBay API key:
44
36
 
45
37
  ```bash
46
38
  export THECLAWBAY_API_KEY=your-api-key-here
47
39
  ```
48
40
 
49
- Get your API key from [TheClawBay Dashboard](https://theclawbay.com).
41
+ Get an API key from the [TheClawBay Dashboard](https://theclawbay.com).
50
42
 
51
- ### Available Models
43
+ ## Provider transport
52
44
 
53
- Model IDs are discovered dynamically at extension load from:
45
+ The provider sends `theclawbay/*` requests to TheClawBay's native Codex route:
54
46
 
55
- - `GET https://api.theclawbay.com/v1/models`
56
-
57
- If discovery fails or `THECLAWBAY_API_KEY` is not set yet, the extension falls back to the last successful discovery cache, then to a bundled default list so `/model` still works on startup. Live discovery refreshes the cache in the background after the provider has been registered.
58
-
59
- Requests for `theclawbay/*` models are sent through TheClawBay's native Codex route:
60
-
61
- - `https://api.theclawbay.com/backend-api/codex`
47
+ ```text
48
+ https://api.theclawbay.com/backend-api/codex
49
+ ```
62
50
 
63
- This extension uses a custom Responses transport for that route. It sends:
51
+ The extension uses a custom HTTP streaming Responses transport. It sends:
64
52
 
65
53
  - `Authorization: Bearer $THECLAWBAY_API_KEY`
66
54
  - `chatgpt-account-id: theclawbay`
67
- - `session_id` when Pi provides a session id
55
+ - `originator: pi`
56
+ - `OpenAI-Beta: responses=experimental`
57
+ - `session_id` when Pi provides a session ID
68
58
  - `prompt_cache_key` in the request body
69
59
 
70
- This avoids Pi's built-in `openai-codex-responses` JWT parsing path, which expects a ChatGPT/Codex-style token and can fail with `Failed to extract accountId from token` when given a normal TheClawBay API key.
71
-
72
- Based on the live docs at `https://theclawbay.com/docs`:
60
+ It intentionally does not use Pi's built-in Codex WebSocket transport. That path expects ChatGPT/Codex JWT-style credentials and can fail with normal TheClawBay API keys.
73
61
 
74
- - OpenAI-compatible apps use `https://api.theclawbay.com/v1`
75
- - Native Codex config uses `https://api.theclawbay.com/backend-api/codex`
76
- - The docs recommend calling `/models` first and selecting an available model dynamically
62
+ ## Model discovery and filtering
77
63
 
78
- ### GPT-5.4 Variants In This Extension
64
+ At startup, the extension calls:
79
65
 
80
- The live TheClawBay docs expose `gpt-5.4` as the upstream model. This extension presents it in Pi as two selectable entries:
81
-
82
- - `theclawbay/gpt-5.4` → standard variant, capped to `272k` context in Pi
83
- - `theclawbay/gpt-5.4[1m]` → long-context variant, configured to `1,050,000`
84
-
85
- Internally:
86
-
87
- - `gpt-5.4` stays as-is
88
- - `gpt-5.4[1m]` is remapped to upstream `gpt-5.4` before the request is sent
89
-
90
- Why split it?
91
-
92
- - `gpt-5.4` is the cheaper/default option
93
- - `gpt-5.4[1m]` gives explicit access to long context
94
- - both end up using the same official upstream model id from TheClawBay
95
-
96
- ### Model Limits
66
+ ```text
67
+ GET https://api.theclawbay.com/v1/models
68
+ ```
97
69
 
98
- - `gpt-5.4` is configured with a `272,000` token context window.
99
- - `gpt-5.4[1m]` is configured with a `1,050,000` token context window.
100
- - Current non-5.4 GPT-5/Codex variants default to `400,000` context and `128,000` max output tokens.
70
+ If live discovery fails, it falls back to the last successful cache and then to the bundled default list.
101
71
 
102
- ### Example Model List
72
+ Selectable Pi models include GPT/Codex text models plus two explicit image-only entries, `gpt-image-2` and `gpt-image-1.5`. The image entries are selectable manually, but they do not use the chat/Codex transport; they route directly to TheClawBay's Images API.
103
73
 
104
- Current fallback list in this package:
74
+ ### Default fallback models
105
75
 
106
76
  - `gpt-5.5`
107
77
  - `gpt-5.4`
@@ -112,93 +82,195 @@ Current fallback list in this package:
112
82
  - `gpt-5.2`
113
83
  - `gpt-5.1-codex-max`
114
84
  - `gpt-5.1-codex-mini`
85
+ - `gpt-image-2`
86
+ - `gpt-image-1.5`
115
87
 
116
- ## Usage
88
+ ### GPT-5.4 variants
89
+
90
+ The upstream TheClawBay model ID is `gpt-5.4`. This extension exposes two Pi entries for clearer cost/context selection:
91
+
92
+ | Pi model | Upstream model | Context configured in Pi |
93
+ |----------|----------------|--------------------------|
94
+ | `theclawbay/gpt-5.4` | `gpt-5.4` | `272,000` tokens |
95
+ | `theclawbay/gpt-5.4[1m]` | `gpt-5.4` | `1,050,000` tokens |
96
+
97
+ Other GPT/Codex fallback models use a `272,000` token context window and `128,000` max output tokens.
117
98
 
118
- ### Select a Model
99
+ ## Image generation
119
100
 
120
- Use `/model` command in pi:
101
+ `pi-clawbay` supports two image-generation flows. Prefer the Codex-style hosted tool from a text/Codex model; select a `gpt-image-*` model only when you explicitly want the direct Images API transport documented at <https://theclawbay.com/docs#image-generation>.
102
+
103
+ The provider follows Codex CLI's hosted-tool pattern: for image-capable TheClawBay models, it exposes the hosted `image_generation` tool in the Responses payload and lets the model decide when to call it with `tool_choice: auto`. Normal coding and text requests still return regular assistant text; they do not produce an `image_generation_call` unless the model intentionally uses the hosted tool.
104
+
105
+ Select a text/Codex model, for example:
121
106
 
122
107
  ```text
123
108
  /model theclawbay/gpt-5.5
124
- /model theclawbay/gpt-5.4
125
- /model theclawbay/gpt-5.4[1m]
126
109
  ```
127
110
 
128
- ### Commands
111
+ Ask for an image naturally:
112
+
113
+ ```text
114
+ Generate a minimalist black sailboat icon on a white background. No text.
115
+ ```
116
+
117
+ The hosted Responses tool definition is:
129
118
 
130
- This extension currently registers:
119
+ ```json
120
+ { "type": "image_generation", "output_format": "png" }
121
+ ```
122
+
123
+ The stream parser handles `image_generation_call` items, decodes the returned base64 PNG, and saves it to:
131
124
 
132
125
  ```text
133
- /quota
126
+ ~/.pi/agent/generated_images/<session_id>/<image_generation_call_id>.png
134
127
  ```
135
128
 
136
- `/cachehit` was removed.
129
+ The assistant response includes:
137
130
 
138
- ### Programmatic Usage
131
+ - a `file://` URL
132
+ - the filesystem path
133
+ - the revised prompt, when returned by TheClawBay
139
134
 
140
- ```typescript
141
- import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
135
+ ### Environment controls
142
136
 
143
- export default function (pi: ExtensionAPI) {
144
- // After loading this extension, models are available:
145
- // - theclawbay/gpt-5.5
146
- // - theclawbay/gpt-5.4
147
- // - theclawbay/gpt-5.4[1m]
148
- // - theclawbay/gpt-5.4-mini
149
- // - theclawbay/gpt-5.3-codex
137
+ To disable hosted image generation entirely, use:
138
+
139
+ ```bash
140
+ export PI_CLAWBAY_IMAGE_GENERATION=off
141
+ ```
142
+
143
+ Override the output root when needed:
144
+
145
+ ```bash
146
+ export PI_CLAWBAY_GENERATED_IMAGES_DIR=/absolute/output/dir
147
+ ```
148
+
149
+ ### Manual Direct Images API flow
150
+
151
+ For explicit direct Images API usage, select one of the image models:
152
+
153
+ ```text
154
+ /model theclawbay/gpt-image-2
155
+ /model theclawbay/gpt-image-1.5
156
+ ```
157
+
158
+ These models are not sent through the Codex chat endpoint. `streamSimple` calls:
159
+
160
+ ```text
161
+ POST https://api.theclawbay.com/v1/images/generations
162
+ ```
163
+
164
+ with the documented payload shape:
165
+
166
+ ```json
167
+ {
168
+ "model": "gpt-image-2",
169
+ "prompt": "A minimalist black sailboat icon on a white background. No text.",
170
+ "size": "1024x1024",
171
+ "quality": "low",
172
+ "output_format": "png"
150
173
  }
151
174
  ```
152
175
 
153
- ## API Reference
176
+ The provider decodes `data[0].b64_json`, saves a PNG under `~/.pi/agent/generated_images/<session_id>/`, and returns the `file://` URL, path, and `revised_prompt` when present.
154
177
 
155
- ### Endpoints
178
+ The valid TheClawBay image model IDs exposed here are `gpt-image-2` and `gpt-image-1.5`. `gpt-image-2.0` is not a valid model ID.
156
179
 
157
- | Provider | Base URL | API Type |
158
- |----------|----------|----------|
159
- | `theclawbay` | `https://api.theclawbay.com/backend-api/codex` | OpenAI Codex Responses |
180
+ ### Skill guidance
181
+
182
+ This package includes a Pi skill:
183
+
184
+ ```text
185
+ theclawbay-imagegen
186
+ ```
160
187
 
161
- ### Authentication
188
+ The skill documents the recommended image-generation workflow and fallback behavior. It is helpful guidance for the agent, but it is not a separate runtime requirement. The provider stream implements the actual hosted image generation support.
162
189
 
163
- All requests use Bearer token authentication:
190
+ If needed, load it explicitly inside Pi:
164
191
 
165
192
  ```text
166
- Authorization: Bearer THECLAWBAY_API_KEY
193
+ /skill:theclawbay-imagegen
167
194
  ```
168
195
 
169
- ### Quota Checking
196
+ ### Direct Images API outside Pi
170
197
 
171
- Check your current usage:
198
+ For programmatic image generation outside the Pi provider loop, call TheClawBay's OpenAI-compatible Images API directly:
172
199
 
173
- ```bash
174
- curl "https://theclawbay.com/api/codex-auth/v1/quota" \
175
- -H "Authorization: Bearer $THECLAWBAY_API_KEY"
200
+ ```http
201
+ POST https://api.theclawbay.com/v1/images/generations
202
+ Authorization: Bearer $THECLAWBAY_API_KEY
203
+ Content-Type: application/json
204
+ ```
205
+
206
+ Example payload:
207
+
208
+ ```json
209
+ {
210
+ "model": "gpt-image-2",
211
+ "prompt": "A minimalist black sailboat icon on a white background. No text.",
212
+ "size": "1024x1024",
213
+ "quality": "low",
214
+ "output_format": "png"
215
+ }
176
216
  ```
177
217
 
178
- ## Error Handling
218
+ Use the direct API outside Pi only when you need your own programmatic integration or when hosted generation is unavailable. Inside Pi, selecting `theclawbay/gpt-image-2` or `theclawbay/gpt-image-1.5` uses this same endpoint automatically.
179
219
 
180
- Common error codes:
220
+ ## Usage
181
221
 
182
- | Code | Description |
183
- |------|-------------|
184
- | `weekly_cost_limit_reached` | Weekly spend cap hit |
185
- | `5h_cost_limit_reached` | 5-hour spend cap hit |
186
- | `invalid_api_key` | Key missing or malformed |
187
- | `model_not_found` | Requested model unavailable |
222
+ ### Select a model
188
223
 
189
- ## Building
224
+ ```text
225
+ /model theclawbay/gpt-5.5
226
+ /model theclawbay/gpt-5.4
227
+ /model theclawbay/gpt-5.4[1m]
228
+ ```
229
+
230
+ ### Commands
231
+
232
+ ```text
233
+ /quota
234
+ ```
235
+
236
+ `/quota` shows current TheClawBay usage windows and reset times.
237
+
238
+ ## API reference
239
+
240
+ | Provider | Base URL | API type |
241
+ |----------|----------|----------|
242
+ | `theclawbay` | `https://api.theclawbay.com/backend-api/codex` | Responses over HTTP streaming |
243
+
244
+ All provider requests use Bearer token authentication:
245
+
246
+ ```text
247
+ Authorization: Bearer $THECLAWBAY_API_KEY
248
+ ```
249
+
250
+ Quota endpoint:
251
+
252
+ ```bash
253
+ curl "https://theclawbay.com/api/codex-auth/v1/quota" \
254
+ -H "Authorization: Bearer $THECLAWBAY_API_KEY"
255
+ ```
256
+
257
+ ## Build and test
190
258
 
191
259
  ```bash
192
260
  npm install
193
- npm run build
261
+ npm run check
262
+ npm test
194
263
  npm pack --dry-run
195
264
  ```
196
265
 
197
266
  ## Publishing
198
267
 
268
+ Publishing is handled by the GitHub Actions workflow in `.github/workflows/publish.yml`.
269
+
270
+ Manual local publishing is not recommended. Use the workflow so npm provenance is attached:
271
+
199
272
  ```bash
200
- npm version patch
201
- npm publish
273
+ gh workflow run publish.yml --ref main
202
274
  ```
203
275
 
204
276
  ## Resources
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAYH,OAAO,KAAK,EAAE,YAAY,EAAuB,MAAM,+BAA+B,CAAC;AAsdvF,MAAM,CAAC,OAAO,WAAW,EAAE,EAAE,YAAY,QAsCxC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAqBH,OAAO,KAAK,EAAE,YAAY,EAAuB,MAAM,+BAA+B,CAAC;AA8mCvF,MAAM,CAAC,OAAO,WAAW,EAAE,EAAE,YAAY,QAsCxC"}