pi-freeflow 1.4.2 → 1.4.4

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,279 +1,323 @@
1
- # pi-freeflow 🌊
2
-
3
- > **23 free models. Up to 1M context. Zero API keys. Infinite scale via your own relay pool.**
4
-
5
- Thin by design: model list + dumb relay + log. Host `pi-ai` owns thinking, normalization & provider magic. We just make it free, fast, and unbreakable.
6
-
7
- [![npm version](https://img.shields.io/npm/v/pi-freeflow?style=flat-square&color=00E5FF)](https://www.npmjs.com/package/pi-freeflow)
8
- [![npm downloads](https://img.shields.io/npm/dm/pi-freeflow?style=flat-square)](https://www.npmjs.com/package/pi-freeflow)
9
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg?style=flat-square)](https://opensource.org/licenses/MIT)
10
- [![Pi](https://img.shields.io/badge/Powered%20by-Pi-7c3aed?style=flat-square)](https://github.com/badlogic/pi-ai)
11
- [![Oh My Pi](https://img.shields.io/badge/Compatible-OMP-black?style=flat-square)](https://github.com/coder/oh-my-pi)
12
-
13
- **Join devs bypassing rate limits with their own relay pools BYO, add as many as you need.**
14
-
15
- ---
16
-
17
- ### Features at a Glance
18
-
19
- | Feature | Description | Value | Cost |
20
- | :--- | :--- | :--- | :--- |
21
- | **23 Curated Free Models** | 9 OpenCode Zen + 14 KiloCode Gateway models, up to 1M context & 512K output | Ceiling Unlocked | **$0** |
22
- | **BYO Relay Pool** | Round-robin load balancing across your Cloudflare Workers & Vercel Edges | Zero Rate Limits | **$0** (your free tiers) |
23
- | **Adaptive Health & Error Detection** | Auto-cooldown on 429 rate limits, 504 timeouts, and socket drops | 0ms Wasted Latency | **$0** |
24
- | **Stream Truncation Resilience** | Stateful SSE terminal tracking (`response.failed` / `response.incomplete` injection) | Zero Host Crashes | **$0** |
25
- | **Smart Model Aliasing** | Clean slash-free & colon-free CLI model names compatible with thinking selectors | DX Optimized | **$0** |
26
- | **Auto-Enabled on Session** | Relay stays enabled in `auto` mode on session start and model switch | Zero Friction | **$0** |
27
- | **Interactive CLI Management** | 10+ `/freeflow` subcommands (`status`, `list`, `use`, `add`, `label`, `remove`, `deploy`, `logs`, `debug`) | Full Control | **$0** |
28
- | **Dumb Proxy That Never Breaks** | `127.0.0.1:18080`, host-normalized, pathname-guarded `/v1/models` | 100% Uptime | **$0** |
29
- | **Observable Real Logs** | `~/.pi/agent/pi-freeflow.log`, 5MB auto-rotation, real-time debug toggle | Observable | **$0** |
30
-
31
- Philosophy: **Thin by design.** We only ship model list + relay proxy + log. Host owns thinking & normalization.
32
-
33
- ---
34
-
35
- ### 23 Curated Models One Command
36
-
37
- ```bash
38
- /model → freeflow → pick
39
- ```
40
-
41
- #### OpenCode Zen (9 Models) Responses & Chat API
42
- Optimized for deep reasoning, long-horizon coding & autonomous agentic workflows.
43
-
44
- | Model ID | Creator / Lab | Context | Max Output | Thinking | Vision |
45
- | :--- | :--- | :--- | :--- | :--- | :--- |
46
- | `muse-spark-1.2-contributor-free` | Meta Superintelligence Labs | **1M** (1.048.576) | **131K** (131.072) | `minimal max` | ✅ |
47
- | `x-preview-f-free` | Ox Alpha | **1M** (1.048.576) | **131K** (131.072) | `low / high / max` | ✅ |
48
- | `mimo-v2.5-free` | Xiaomi MiMo | **1M** (1.048.576) | **131K** (131.072) | `low / medium / high` | |
49
- | `deepseek-v4-flash-free` | DeepSeek | **1M** (1.000.000) | **384K** (384.000) | `low max` | ❌ |
50
- | `laguna-s-2.1-free` | Poolside | **1M** (1.048.576) | **131K** (131.072) | `low max` | ❌ |
51
- | `nemotron-3.5-lightning-free` | NVIDIA | **1M** (1.000.000) | **262K** (262.144) | `low max` | ❌ |
52
- | `nemotron-3-ultra-free` | NVIDIA | **1M** (1.000.000) | **128K** (128.000) | `low max` | ❌ |
53
- | `hy3-free` | Tencent Hunyuan | **262K** (262.144) | **262K** (262.144) | `low → max` | ❌ |
54
- | `big-pickle` | Big Pickle | **200K** (200.000) | **32K** (32.000) | `high / max` | ❌ |
55
-
56
- #### KiloCode Gateway (14 Models) — OpenRouter Compatible
57
- Keyless access with `Bearer kilo-free`. Clean slash-free and colon-free CLI aliases supported.
58
-
59
- | Model ID | Creator / Lab | Context | Max Output | Thinking | Vision |
60
- | :--- | :--- | :--- | :--- | :--- | :--- |
61
- | `dots-3-note-preview` (`dots-studio/...:free`) | Dots Studio | **512K** (512.000) | **512K** (512.000) | `openrouter` (auto) | ✅ |
62
- | `step-3.7-flash` (`stepfun/...:free`) | StepFun | **262K** (262.144) | **262K** (262.144) | `openrouter` (auto) | |
63
- | `nemotron-3-nano-omni` (`nvidia/...:free`) | NVIDIA | **256K** (256.000) | **65K** (65.536) | `openrouter` (auto) | |
64
- | `nemotron-3-ultra-550b` (`nvidia/...:free`) | NVIDIA | **1M** (1.000.000) | **65K** (65.536) | `openrouter` (auto) | ❌ |
65
- | `nvidia/nemotron-3.5-lightning:free` | NVIDIA | **1M** (1.000.000) | **131K** (131.072) | `openrouter` (auto) | ❌ |
66
- | `nemotron-3-super` (`nvidia/...:free`) | NVIDIA | **262K** (262.144) | **262K** (262.144) | `openrouter` (auto) | ❌ |
67
- | `hy3:free` (`tencent/hy3:free`) | Tencent Hunyuan | **262K** (262.144) | **262K** (262.144) | `openrouter` (auto) | ❌ |
68
- | `north-mini-code` (`cohere/...:free`) | Cohere | **256K** (256.000) | **64K** (64.000) | `openrouter` (auto) | ❌ |
69
- | `laguna-s-2.1:free` (`poolside/...:free`) | Poolside | **1M** (1.048.576) | **131K** (131.072) | `openrouter` (auto) | ❌ |
70
- | `laguna-xs-2.1:free` (`poolside/...:free`) | Poolside | **262K** (262.144) | **32K** (32.768) | `openrouter` (auto) | ❌ |
71
- | `lfm-2.5` (`liquid/lfm-2.5-2.6b:free`) | Liquid AI | **128K** (128.000) | **32K** (32.768) | `openrouter` (auto) | |
72
- | `kilo-auto` (`kilo-auto/free`) | Kilo Gateway Auto | **256K** (256.000) | **10K** (10.000) | ❌ *(non-thinking)* | |
73
- | `openrouter` (`openrouter/free`) | OpenRouter Free | **200K** (200.000) | **65K** (65.536) | ❌ *(non-thinking)* | ✅ |
74
- | `content-safety` (`nvidia/...:free`) | NVIDIA | **128K** (128.000) | **8K** (8.192) | *(non-thinking)* | |
75
-
76
- ---
77
-
78
- ### How It Works — The Magic: BYO Relays, Zero Rate Limits
79
-
80
- ```
81
- You → 127.0.0.1:18080 (dumb proxy, host-normalized) → x-relay-target → N egress IPs (your pool) → opencode.ai / api.kilo.ai
82
- ↑ host already normalized thinking → proxy just forwards
83
- ```
84
-
85
- 1. **Per-Request Round-Robin**: 10 parallel subagents hit N different egress IPs (your pool size). No thundering herd.
86
- 2. **Adaptive Health & Error Cooldown**: Relays hitting 429, 504, or socket disconnects enter temporary cooldown (30-90s) and automatically move behind healthy candidates. Healthy relays handle traffic with 0ms wasted delay.
87
- 3. **Seamless 429 Roll**: `429 / 408 / 502 / 503 / 504 / 520-530` → instant roll to next relay, never 429 to agent.
88
- 4. **Stream Truncation Resilience**: Stateful SSE terminal tracking prevents fatal unhandled stream closed errors when connections drop.
89
- 5. **Direct Fallback Safety Net**: If all relays in the pool are exhausted, transparent direct fetch to upstream.
90
- 6. **Zero Subagent Connect Errors**: 24h `DISK_CACHE_ONLY` model catalog avoids subagents hammering remote catalogs.
91
-
92
- You bring the relays (free tiers). We bring the rolling.
93
-
94
- ---
95
-
96
- ### Interactive Commands Reference (`/freeflow`)
97
-
98
- Manage your relay pool directly from the OMP / Pi terminal:
99
-
100
- ```bash
101
- /freeflow status # View active relay, pool status, and candidates
102
- /freeflow list # List all relays with real-time health badges (✓ / ⚠️ [cooling])
103
- /freeflow use <url|index|label> # Switch active relay
104
- /freeflow add <url> [label] # Add new relay to the pool
105
- /freeflow label <index|url> <name># Assign a friendly label to a relay
106
- /freeflow remove <index|url|label># Remove a relay from the pool
107
- /freeflow on | off | auto # Toggle relay mode (auto = enabled for freeflow)
108
- /freeflow deploy # Guided deploy of ONE Vercel Edge relay (in-memory token)
109
- /freeflow logs [lines] # Inspect recent proxy logs
110
- /freeflow debug on | off # Toggle full HTTP lifecycle debug logging
111
- ```
112
-
113
- ---
114
-
115
- ### Quick Start 30 Seconds
116
-
117
- #### 1. Install
118
-
119
- **Oh My Pi (Recommended):**
120
- ```bash
121
- omp plugin install pi-freeflow
122
- # or local dev
123
- omp plugin link /path/to/pi-freeflow
124
- ```
125
-
126
- **Pi:**
127
- ```bash
128
- pi install npm:pi-freeflow
129
- ```
130
-
131
- #### 2. Pick a Model
132
-
133
- ```bash
134
- omp
135
- /model → freeflow → muse-spark-1.2-contributor-free (1M) → max
136
-
137
- # or CLI
138
- omp -p --model freeflow/muse-spark-1.2-contributor-free "build me a SaaS"
139
- # or with short alias & thinking level
140
- omp -p --model freeflow/step-3.7-flash:high "solve this bug"
141
- ```
142
-
143
- #### 3. Add Your Free Relays (Scale Infinitely)
144
-
145
- Default ships direct. Add relays via `/freeflow add <url> [label]`.
146
-
147
- **Option A: Cloudflare Workers (100k req/day, no 25s timeout)**
148
- 1. Go to `dash.cloudflare.com` → Workers → Create → Deploy → Edit code
149
- 2. Paste this Worker relay snippet:
150
-
151
- ```js
152
- // Only the 2 upstreams pi-freeflow talks to. Anything else = open proxy abuse.
153
- const ALLOWED_TARGETS = ["https://opencode.ai", "https://api.kilo.ai"];
154
-
155
- export default {
156
- async fetch(req) {
157
- const target = req.headers.get("x-relay-target");
158
- const relayPath = req.headers.get("x-relay-path") || "/";
159
- if (!target) return new Response(JSON.stringify({ error: "Missing x-relay-target header" }), { status: 400 });
160
- const cleanTarget = target.replace(/\/$/, "");
161
- if (!ALLOWED_TARGETS.includes(cleanTarget)) return new Response(JSON.stringify({ error: "Forbidden target" }), { status: 403 });
162
- if (!relayPath.startsWith("/")) return new Response(JSON.stringify({ error: "Bad path" }), { status: 400 });
163
- const headers = new Headers(req.headers);
164
- headers.delete("x-relay-target"); headers.delete("x-relay-path"); headers.delete("host");
165
- return fetch(cleanTarget + relayPath, { method: req.method, headers, body: req.method !== "GET" && req.method !== "HEAD" ? req.body : undefined });
166
- },
167
- };
168
- ```
169
- 3. Deploy and add it:
170
-
171
- ```bash
172
- omp → /freeflow add https://your.workers.dev cf-worker-1
173
- ```
174
-
175
- **Option B: Vercel Edge Relay (1M req/mo) — Auto Deploy**
176
- ```bash
177
- /freeflow deploy # prompts token in-memory, auto-adds to pool
178
- ```
179
-
180
- **Option C: Deno Deploy (100k req/day)**
181
- 1. Go to `dash.deno.com` → New Project → Playground
182
- 2. Paste this relay and click **Deploy**:
183
-
184
- ```ts
185
- const ALLOWED_TARGETS = ["https://opencode.ai", "https://api.kilo.ai"];
186
-
187
- Deno.serve(async (req) => {
188
- const target = req.headers.get("x-relay-target");
189
- const relayPath = req.headers.get("x-relay-path") || "/";
190
- if (!target || !ALLOWED_TARGETS.includes(target.replace(/\/$/, ""))) {
191
- return new Response(JSON.stringify({ error: "Forbidden target" }), { status: 403 });
192
- }
193
- const headers = new Headers(req.headers);
194
- headers.delete("x-relay-target"); headers.delete("x-relay-path"); headers.delete("host");
195
- const res = await fetch(target.replace(/\/$/, "") + relayPath, { method: req.method, headers, body: req.method !== "GET" && req.method !== "HEAD" ? req.body : undefined });
196
- return new Response(res.body, { status: res.status, headers: res.headers });
197
- });
198
- ```
199
-
200
- 3. Add it:
201
-
202
- ```bash
203
- /freeflow add https://your-project.deno.dev deno-relay-1
204
- ```
205
-
206
- **Verify your pool:**
207
- ```bash
208
- /freeflow status # relay-A 1/N (ON) → candidates:N
209
- /freeflow list # lists all relays with health status
210
- /freeflow logs # tail -25
211
- cat ~/.pi/agent/pi-freeflow.log | tail -n 20
212
- ```
213
-
214
- ---
215
-
216
- ### Logs & Debugging
217
-
218
- ```bash
219
- /freeflow logs
220
- cat ~/.pi/agent/pi-freeflow.log | tail -n 50
221
-
222
- # debug toggle
223
- /freeflow debug on
224
- ```
225
-
226
- Log rotation at 5MB. Clean, parseable, real-time HTTP lifecycle tracking.
227
-
228
- ---
229
-
230
- ### Philosophy: Thin vs Fat
231
-
232
- | Fat Plugin (Before) | Thin FreeFlow (Now) |
233
- | :--- | :--- |
234
- | `src/normalizer.ts` 200 LOC duplicates host | Deleted host `pi-ai` owns 10 `thinkingFormat` |
235
- | Live fetch 10s in subagent → timeout | Disk-only 24h, proxy-only |
236
- | 400 loops relays | Narrow 429/5xx only, 400 surfaces instantly |
237
- | `GET /v1/models?foo` leaks paid | Pathname-guarded |
238
-
239
- **Result: ~3.6k LOC total, 53 tests PASS, typecheck PASS.**
240
-
241
- ---
242
-
243
- ### FAQ
244
-
245
- **Do I need API keys?**
246
- No. Kilo uses `Bearer kilo-free`, OpenCode uses `opencodeHeaders()`.
247
-
248
- **What if all relays are 429?**
249
- Proxy tries direct. If that's also 429, Pi shows rate limit — that means global upstream limit, even without relay you'd be 429.
250
-
251
- **Can I use without relays?**
252
- Yes. `/freeflow off` direct. Add relays later to scale.
253
-
254
- **Where's the normalizer?**
255
- Deleted in 1.3.0. If zai/qwen/deepseek thinking broke before, it's fixed now because host handles it.
256
-
257
- **Why is context free?**
258
- We use OpenCode Zen & Kilo free tiers. You pay only with your own Cloudflare/Vercel free tiers for egress.
259
-
260
- ---
261
-
262
- ### Contributing
263
-
264
- ```bash
265
- git clone https://github.com/trefeon/pi-freeflow
266
- pnpm install
267
- pnpm test
268
- ```
269
-
270
- PRs welcome. `reference/` holds pi, oh-my-pi, opencode, kilocode shallow clones for audit (gitignored).
271
-
272
- ### License
273
-
274
- MIT © trefeon
275
-
276
- Start now:
277
- ```bash
278
- omp plugin install pi-freeflow && omp --model freeflow/muse-spark-1.2-contributor-free --thinking max "make it sell"
279
- ```
1
+ # pi-freeflow 🌊
2
+
3
+ > **21 free models. Up to 1M context. Zero API keys. Infinite scale via your own relay pool.**
4
+
5
+ Thin by design: model list + dumb relay + log. Host `pi-ai` owns thinking, normalization & provider magic. We just make it free, fast, and unbreakable.
6
+
7
+ [![npm version](https://img.shields.io/npm/v/pi-freeflow?style=flat-square&color=00E5FF)](https://www.npmjs.com/package/pi-freeflow)
8
+ [![npm downloads](https://img.shields.io/npm/dm/pi-freeflow?style=flat-square)](https://www.npmjs.com/package/pi-freeflow)
9
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg?style=flat-square)](https://opensource.org/licenses/MIT)
10
+ [![Pi](https://img.shields.io/badge/Powered%20by-Pi-7c3aed?style=flat-square)](https://github.com/badlogic/pi-ai)
11
+ [![Oh My Pi](https://img.shields.io/badge/Compatible-OMP-black?style=flat-square)](https://github.com/coder/oh-my-pi)
12
+
13
+ Join devs bypassing rate limits with their own relay pools. BYO, add as many as you need.
14
+
15
+ ---
16
+
17
+ ### Features at a Glance
18
+
19
+ | Feature | Description | Value | Cost |
20
+ | :--- | :--- | :--- | :--- |
21
+ | **21 Curated Free Models** | 7 OpenCode Zen + 14 KiloCode Gateway models, up to 1M context & 512K output | Ceiling Unlocked | **$0** |
22
+ | **BYO Relay Pool** | Round-robin load balancing across your Cloudflare Workers & Vercel Edges | Zero Rate Limits | **$0** (your free tiers) |
23
+ | **Adaptive Health & Error Detection** | Auto-cooldown on 429 rate limits, 504 timeouts, and socket drops | 0ms Wasted Latency | **$0** |
24
+ | **Stream Truncation Resilience** | Stateful SSE terminal tracking (`response.failed` / `response.incomplete` injection) | Zero Host Crashes | **$0** |
25
+ | **Smart Model Aliasing** | Clean slash-free & colon-free CLI model names compatible with thinking selectors | DX Optimized | **$0** |
26
+ | **Auto-Enabled on Session** | Relay stays enabled in `auto` mode on session start and model switch | Zero Friction | **$0** |
27
+ | **Interactive CLI Management** | 10+ `/freeflow` subcommands (`status`, `list`, `use`, `add`, `label`, `remove`, `deploy`, `logs`, `debug`) | Full Control | **$0** |
28
+ | **Dumb Proxy That Never Breaks** | `127.0.0.1:18080`, host-normalized, pathname-guarded `/v1/models` | 100% Uptime | **$0** |
29
+ | **Observable Real Logs** | `~/.pi/agent/pi-freeflow.log`, 5MB auto-rotation, real-time debug toggle | Observable | **$0** |
30
+
31
+ Philosophy: **Thin by design.** We only ship model list + relay proxy + log. Host owns thinking & normalization.
32
+
33
+ ---
34
+
35
+ ### 21 Curated Models, One Command
36
+
37
+ ```bash
38
+ /model → freeflow → pick
39
+ ```
40
+
41
+ #### OpenCode Zen (7 Models), Responses & Chat API
42
+ Optimized for deep reasoning, long-horizon coding & autonomous agentic workflows.
43
+
44
+ | Model ID | Creator / Lab | Context | Max Output | Thinking | Vision |
45
+ | :--- | :--- | :--- | :--- | :--- | :--- |
46
+ | `muse-spark-1.2-contributor-free` | Meta Superintelligence Labs | **1M** (1.048.576) | **131K** (131.072) | `minimal / low / medium / high / xhigh / max` | ✅ |
47
+ | `mimo-v2.5-free` | Xiaomi MiMo | **1M** (1.048.576) | **131K** (131.072) | `low / medium / high` | ✅ |
48
+ | `laguna-s-2.1-free` | Poolside | **1M** (1.048.576) | **131K** (131.072) | `low / high / max` | |
49
+ | `nemotron-3.5-lightning-free` | NVIDIA | **1M** (1.000.000) | **262K** (262.144) | `low / high / max` | ❌ |
50
+ | `nemotron-3-ultra-free` | NVIDIA | **1M** (1.000.000) | **128K** (128.000) | `low / high / max` | ❌ |
51
+ | `hy3-free` | Tencent Hunyuan | **262K** (262.144) | **262K** (262.144) | `low / high / max` | ❌ |
52
+ | `big-pickle` | Big Pickle | **200K** (200.000) | **32K** (32.000) | `high / max` | ❌ |
53
+
54
+ #### KiloCode Gateway (14 Models), OpenRouter Compatible
55
+ Keyless access with `Bearer kilo-free`. Clean slash-free and colon-free CLI aliases supported.
56
+
57
+ | Model ID | Creator / Lab | Context | Max Output | Thinking | Vision |
58
+ | :--- | :--- | :--- | :--- | :--- | :--- |
59
+ | `dots-3-note-preview` (`dots-studio/...:free`) | Dots Studio | **512K** (512.000) | **512K** (512.000) | `minimal…xhigh`\* | |
60
+ | `step-3.7-flash` (`stepfun/...:free`) | StepFun | **262K** (262.144) | **262K** (262.144) | `minimal…xhigh`\* | |
61
+ | `nemotron-3-nano-omni` (`nvidia/...:free`) | NVIDIA | **256K** (256.000) | **65K** (65.536) | `minimal…xhigh`\* | ✅ |
62
+ | `nemotron-3-ultra-550b` (`nvidia/...:free`) | NVIDIA | **1M** (1.000.000) | **65K** (65.536) | `minimal…xhigh`\* | |
63
+ | `nvidia/nemotron-3.5-lightning:free` | NVIDIA | **1M** (1.000.000) | **131K** (131.072) | `minimal…xhigh`\* | |
64
+ | `nemotron-3-super` (`nvidia/...:free`) | NVIDIA | **262K** (262.144) | **262K** (262.144) | `minimal…xhigh`\* | ❌ |
65
+ | `hy3:free` (`tencent/hy3:free`) | Tencent Hunyuan | **262K** (262.144) | **262K** (262.144) | *(none sent)* | ❌ |
66
+ | `north-mini-code` (`cohere/...:free`) | Cohere | **256K** (256.000) | **64K** (64.000) | `minimal…xhigh`\* | ❌ |
67
+ | `laguna-s-2.1:free` (`poolside/...:free`) | Poolside | **1M** (1.048.576) | **131K** (131.072) | `minimal…xhigh`\* | ❌ |
68
+ | `laguna-xs-2.1:free` (`poolside/...:free`) | Poolside | **262K** (262.144) | **32K** (32.768) | `minimal…xhigh`\* | ❌ |
69
+ | `lfm-2.5` (`liquid/lfm-2.5-2.6b:free`) | Liquid AI | **128K** (128.000) | **32K** (32.768) | `minimal…xhigh`\* | ❌ |
70
+ | `kilo-auto` (`kilo-auto/free`) | Kilo Gateway Auto | **256K** (256.000) | **10K** (10.000) | *(non-thinking)* | ❌ |
71
+ | `openrouter` (`openrouter/free`) | OpenRouter Free | **200K** (200.000) | **65K** (65.536) | *(non-thinking)* | |
72
+ | `content-safety` (`nvidia/...:free`) | NVIDIA | **128K** (128.000) | **8K** (8.192) | ❌ *(non-thinking)* | |
73
+
74
+ \* Levels are forwarded as-is through the OpenRouter-style nested `reasoning` parameter; effort mapping is decided by each model. hy3 accepts no reasoning parameter today.
75
+
76
+ ---
77
+
78
+ ### How It Works: BYO Relays, Zero Rate Limits
79
+
80
+ ```
81
+ You → 127.0.0.1:18080 (dumb proxy, host-normalized) → x-relay-target → N egress IPs (your pool) → opencode.ai / api.kilo.ai
82
+ ↑ host already normalized thinking → proxy just forwards
83
+ ```
84
+
85
+ 1. **Per-Request Round-Robin**: 10 parallel subagents hit N different egress IPs (your pool size). No thundering herd.
86
+ 2. **Adaptive Health & Error Cooldown**: Relays hitting 429, 504, or socket disconnects enter temporary cooldown (30-90s) and automatically move behind healthy candidates. Healthy relays handle traffic with 0ms wasted delay.
87
+ 3. **Seamless 429 Roll**: `429 / 408 / 502 / 503 / 504 / 520-530` → instant roll to next relay, never 429 to agent.
88
+ 4. **Stream Truncation Resilience**: Stateful SSE terminal tracking prevents fatal unhandled stream closed errors when connections drop.
89
+ 5. **Direct Fallback Safety Net**: If all relays in the pool are exhausted, transparent direct fetch to upstream.
90
+ 6. **Zero Subagent Connect Errors**: 24h `DISK_CACHE_ONLY` model catalog avoids subagents hammering remote catalogs.
91
+
92
+ You bring the relays (free tiers). We bring the rolling.
93
+
94
+ ---
95
+
96
+ ### Interactive Commands Reference (`/freeflow`)
97
+
98
+ Manage your relay pool directly from the OMP / Pi terminal:
99
+
100
+ ```bash
101
+ /freeflow status # View active relay, pool status, and candidates
102
+ /freeflow list # List all relays with real-time health badges (✓ / ⚠️ [cooling])
103
+ /freeflow use <url|index|label> # Switch active relay
104
+ /freeflow add <url> [label] # Add new relay to the pool
105
+ /freeflow label <index|url> <name># Assign a friendly label to a relay
106
+ /freeflow remove <index|url|label># Remove a relay from the pool
107
+ /freeflow on | off | auto # Toggle relay mode (auto = enabled for freeflow)
108
+ /freeflow deploy vercel # Guided Vercel Edge relay deploy (also: deploy cloudflare, deploy deno)
109
+ /freeflow logs [lines] # Inspect recent proxy logs
110
+ /freeflow debug on | off # Toggle full HTTP lifecycle debug logging
111
+ ```
112
+
113
+ ---
114
+
115
+ ### Quick Start in 30 Seconds
116
+
117
+ #### 1. Install
118
+
119
+ **Oh My Pi (Recommended):**
120
+ ```bash
121
+ omp plugin install pi-freeflow
122
+ # or local dev
123
+ omp plugin link /path/to/pi-freeflow
124
+ ```
125
+
126
+ **Pi:**
127
+ ```bash
128
+ pi install npm:pi-freeflow
129
+ ```
130
+
131
+ #### 2. Pick a Model
132
+
133
+ ```bash
134
+ omp
135
+ /model → freeflow → muse-spark-1.2-contributor-free (1M) → max
136
+
137
+ # or CLI
138
+ omp -p --model freeflow/muse-spark-1.2-contributor-free "build me a SaaS"
139
+ # or with short alias & thinking level
140
+ omp -p --model freeflow/step-3.7-flash:high "solve this bug"
141
+ ```
142
+
143
+ #### 3. Add Your Free Relays (Scale Infinitely)
144
+
145
+ Default ships direct. Add relays via `/freeflow add <url> [label]`.
146
+
147
+ **Zero setup?** Run `/freeflow deploy cloudflare` (or `deno`, `vercel`), paste your platform token once, and the relay is created and activated for you. Manual snippets below.
148
+
149
+ **Option A: Cloudflare Workers (100k req/day, no 25s timeout)**
150
+ 1. Go to `dash.cloudflare.com` → Workers → Create → Deploy → Edit code
151
+ 2. Paste this Worker relay snippet:
152
+
153
+ ```js
154
+ // Only the 2 upstreams pi-freeflow talks to. Anything else = open proxy abuse.
155
+ const ALLOWED_TARGETS = ["https://opencode.ai", "https://api.kilo.ai"];
156
+
157
+ export default {
158
+ async fetch(req) {
159
+ const target = req.headers.get("x-relay-target");
160
+ const relayPath = req.headers.get("x-relay-path") || "/";
161
+ if (!target) return new Response(JSON.stringify({ error: "Missing x-relay-target header" }), { status: 400 });
162
+ const cleanTarget = target.replace(/\/$/, "");
163
+ if (!ALLOWED_TARGETS.includes(cleanTarget)) return new Response(JSON.stringify({ error: "Forbidden target" }), { status: 403 });
164
+ if (!relayPath.startsWith("/")) return new Response(JSON.stringify({ error: "Bad path" }), { status: 400 });
165
+ const headers = new Headers(req.headers);
166
+ headers.delete("x-relay-target"); headers.delete("x-relay-path"); headers.delete("host");
167
+ return fetch(cleanTarget + relayPath, { method: req.method, headers, body: req.method !== "GET" && req.method !== "HEAD" ? req.body : undefined });
168
+ },
169
+ };
170
+ ```
171
+ 3. Deploy and add it:
172
+
173
+ ```bash
174
+ omp → /freeflow add https://your.workers.dev cf-worker-1
175
+ ```
176
+
177
+ **Option B: Vercel Edge Relay (1M req/mo), Auto Deploy**
178
+ ```bash
179
+ /freeflow deploy # prompts token in-memory, auto-adds to pool
180
+ ```
181
+
182
+ **Option C: Deno Deploy (100k req/day)**
183
+ 1. Go to `dash.deno.com` → New Project → Playground
184
+ 2. Paste this relay and click **Deploy**:
185
+
186
+ ```ts
187
+ const ALLOWED_TARGETS = ["https://opencode.ai", "https://api.kilo.ai"];
188
+
189
+ Deno.serve(async (req) => {
190
+ const target = req.headers.get("x-relay-target");
191
+ const relayPath = req.headers.get("x-relay-path") || "/";
192
+ if (!target || !ALLOWED_TARGETS.includes(target.replace(/\/$/, ""))) {
193
+ return new Response(JSON.stringify({ error: "Forbidden target" }), { status: 403 });
194
+ }
195
+ const headers = new Headers(req.headers);
196
+ headers.delete("x-relay-target"); headers.delete("x-relay-path"); headers.delete("host");
197
+ const res = await fetch(target.replace(/\/$/, "") + relayPath, { method: req.method, headers, body: req.method !== "GET" && req.method !== "HEAD" ? req.body : undefined });
198
+ return new Response(res.body, { status: res.status, headers: res.headers });
199
+ });
200
+ ```
201
+
202
+ 3. Add it:
203
+
204
+ ```bash
205
+ /freeflow add https://your-project.deno.dev deno-relay-1
206
+ ```
207
+
208
+ **Verify your pool:**
209
+ ```bash
210
+ /freeflow status # relay-A 1/N (ON) → candidates:N
211
+ /freeflow list # lists all relays with health status
212
+ /freeflow logs # tail -25
213
+ cat ~/.pi/agent/pi-freeflow.log | tail -n 20
214
+ ```
215
+
216
+ ---
217
+
218
+ ### Logs & Debugging
219
+
220
+ ```bash
221
+ /freeflow logs
222
+ cat ~/.pi/agent/pi-freeflow.log | tail -n 50
223
+
224
+ # debug toggle
225
+ /freeflow debug on
226
+ ```
227
+
228
+ Log rotation at 5MB. Clean, parseable, real-time HTTP lifecycle tracking.
229
+
230
+ ---
231
+
232
+ ### Design
233
+
234
+ This package stays thin. It ships three things: a model catalog, a relay proxy, and a log. There is no build step and there are no runtime dependencies. Thinking and prompt normalization stay with the host (`pi-ai`).
235
+
236
+ Current size: about 4.6k lines including tests. 16 tests pass, typecheck clean.
237
+
238
+ ---
239
+
240
+ ### FAQ
241
+
242
+ **Do I need API keys?**
243
+ No. Kilo uses `Bearer kilo-free`, OpenCode uses `opencodeHeaders()`.
244
+
245
+ **What if all relays are 429?**
246
+ Proxy tries direct. If that is also 429, Pi shows the rate limit. That number is the global upstream cap; without relays you would hit the same wall.
247
+
248
+ **Can I use without relays?**
249
+ Yes. `/freeflow off` direct. Add relays later to scale.
250
+
251
+ **Where's the normalizer?**
252
+ Deleted in 1.3.0. If zai/qwen/deepseek thinking broke before, it's fixed now because host handles it.
253
+
254
+ **Why is context free?**
255
+ We use OpenCode Zen & Kilo free tiers. You pay only with your own Cloudflare/Vercel free tiers for egress.
256
+
257
+ ---
258
+
259
+ ### Contributing
260
+
261
+ Contributions welcome — bug fixes, new relay platforms, model additions, docs improvements.
262
+
263
+ #### Prerequisites
264
+
265
+ - **Node.js ≥ 22.6.0** (uses `--experimental-strip-types`, no build step)
266
+ - **pnpm** (package manager)
267
+
268
+ #### Setup & Verify
269
+
270
+ ```bash
271
+ git clone https://github.com/trefeon/pi-freeflow
272
+ cd pi-freeflow
273
+ pnpm install
274
+
275
+ # run all three before opening a PR
276
+ pnpm test # 16 tests across 2 test files
277
+ pnpm typecheck # tsc --noEmit, must pass clean
278
+ pnpm smoke # verifies extensions/index.ts loads without crashing
279
+ ```
280
+
281
+ #### Project Structure
282
+
283
+ ```
284
+ src/
285
+ ├── index.ts # extension entry, lifecycle hooks
286
+ ├── models.ts # 21-model catalog definitions
287
+ ├── catalog.ts # model catalog cache (24h disk)
288
+ ├── proxy.ts # local proxy server (127.0.0.1:18080)
289
+ ├── relay.ts # relay selection & round-robin
290
+ ├── relay-state.ts # relay pool state, health tracking
291
+ ├── rate-limiter.ts # adaptive cooldown on 429/504/socket errors
292
+ ├── stream-pipe.ts # SSE stream piping & truncation resilience
293
+ ├── commands.ts # /freeflow CLI subcommands
294
+ ├── deploy.ts # guided relay deploy (vercel/cloudflare/deno)
295
+ ├── config.ts # relay pool persistence
296
+ ├── logger.ts # file logger with 5MB rotation
297
+ └── types.ts # shared type definitions
298
+ extensions/
299
+ └── index.ts # OMP/Pi extension manifest
300
+ test/
301
+ └── *.test.ts # mirrors src/, node:test runner
302
+ ```
303
+
304
+ #### Guidelines
305
+
306
+ - **Stay thin.** No runtime dependencies. No build step. If it belongs in the host (`pi-ai`), don't add it here.
307
+ - **Test what you touch.** Every `src/*.ts` has a matching `test/*.test.ts`. Add or update tests for your change.
308
+ - **Keep model IDs clean.** Slash-free, colon-free aliases for CLI compatibility. See existing patterns in `models.ts`.
309
+ - **One concern per PR.** Bug fix? One PR. New relay platform? Separate PR. Easier to review, faster to merge.
310
+
311
+ #### Reporting Issues
312
+
313
+ Found a bug or want a feature? [Open an issue](https://github.com/trefeon/pi-freeflow/issues) with:
314
+ - What happened vs what you expected
315
+ - Your relay setup (`/freeflow status` output helps)
316
+ - Relevant logs (`/freeflow logs` or `~/.pi/agent/pi-freeflow.log`)
317
+
318
+ ---
319
+
320
+ ### License
321
+
322
+ MIT © trefeon
323
+
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pi-freeflow",
3
3
  "type": "module",
4
- "version": "1.4.2",
4
+ "version": "1.4.4",
5
5
  "description": "Thin provider for OMP/Pi — model list + dumb relay proxy + log; host pi-ai owns thinking/normalization",
6
6
  "main": "extensions/index.ts",
7
7
  "types": "src/index.ts",