@eduardo191labs/opencode-free-pi 0.7.12 → 0.7.13

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
@@ -155,6 +155,12 @@ Después de iniciar sesión, ejecuta `/reload` en OpenCode o reinícialo.
155
155
  publica el upstream (32k por defecto, hasta 131k). No se fuerza temperatura ni
156
156
  `top_p`: la petición real no los incluye, así que el gateway aplica su propio
157
157
  valor. El prompt se envía con rol `system`, no `developer`.
158
+ - **Sin razonamiento reenviado**: OpenCode guarda el pensamiento del modelo en
159
+ los mensajes del asistente y lo devuelve dentro de `reasoning_content`. La
160
+ captura con `curl_cffi` mostró que el gateway lo cobra como entrada (mismo
161
+ prompt y misma respuesta pasaron de 27 a 188 tokens en `glm-5.3-flash`), así
162
+ que el plugin lo quita antes de enviar. No cambia la respuesta: el modelo ya
163
+ razonó en su turno y el historial conserva el texto visible.
158
164
  - **Límites medidos, no inventados**: `/client-version` solo devuelve id,
159
165
  nombre, `free`, `section`, `note`, `stats_id` y `usage_x`; no hay endpoint de
160
166
  capacidades ni de ventana. El plugin no se queda en constantes: confirma la
@@ -206,6 +206,61 @@ function applyContextDiet(deps, event) {
206
206
  tokensAfter: result.tokensAfter,
207
207
  });
208
208
  }
209
+ /**
210
+ * Drops the reasoning OpenCode stores and echoes back inside assistant
211
+ * messages.
212
+ *
213
+ * The provider request carries it as `reasoning_content`, but it is not input:
214
+ * the gateway billed it on some models (a measured glm-5.3-flash request went
215
+ * from 27 to 188 prompt tokens with the same answer) and the token estimate used
216
+ * for diet/compaction assumes it is not sent. Removing it keeps the request
217
+ * identical in behavior and smaller in credits.
218
+ */
219
+ function stripAssistantReasoning(deps, event) {
220
+ const messages = event.messages;
221
+ if (!Array.isArray(messages) || messages.length === 0)
222
+ return;
223
+ let chars = 0;
224
+ let changed = false;
225
+ const next = messages.map((message) => {
226
+ if (!message || message.role !== "assistant")
227
+ return message;
228
+ let copy;
229
+ const ensureCopy = () => {
230
+ if (!copy)
231
+ copy = { ...message };
232
+ return copy;
233
+ };
234
+ for (const key of ["reasoning_content", "reasoning"]) {
235
+ if (!(key in message))
236
+ continue;
237
+ const value = message[key];
238
+ if (typeof value === "string")
239
+ chars += value.length;
240
+ ensureCopy();
241
+ delete copy[key];
242
+ changed = true;
243
+ }
244
+ if (Array.isArray(message.content)) {
245
+ const kept = message.content.filter((part) => part?.type !== "reasoning" && part?.type !== "thinking");
246
+ if (kept.length !== message.content.length) {
247
+ ensureCopy();
248
+ copy.content = kept;
249
+ changed = true;
250
+ }
251
+ }
252
+ return copy ?? message;
253
+ });
254
+ if (!changed)
255
+ return;
256
+ event.messages = next;
257
+ if (chars > 0) {
258
+ deps.log.info("free-pi dropped stored reasoning from the request", {
259
+ sessionID: event.sessionID,
260
+ chars,
261
+ });
262
+ }
263
+ }
209
264
  /** Caps output tokens, applies the efficiency rule and derives the ad turn. */
210
265
  async function applyGeneration(deps, event, kind) {
211
266
  if (!isFreePiProvider(event.model?.providerID))
@@ -218,6 +273,7 @@ async function applyGeneration(deps, event, kind) {
218
273
  event.result = localTitle(event.messages);
219
274
  return;
220
275
  }
276
+ stripAssistantReasoning(deps, event);
221
277
  const modelID = event.model?.id;
222
278
  const limit = deps.state.outputLimits.get(`${event.model.providerID}/${modelID}`);
223
279
  // The compaction summary is the one response that must never be cut: a
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eduardo191labs/opencode-free-pi",
3
- "version": "0.7.12",
3
+ "version": "0.7.13",
4
4
  "description": "Ad-supported free-pi provider plugin for OpenCode on Windows, Linux, macOS and Termux",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -338,6 +338,58 @@ function applyContextDiet(deps: Deps, event: any): void {
338
338
  );
339
339
  }
340
340
 
341
+ /**
342
+ * Drops the reasoning OpenCode stores and echoes back inside assistant
343
+ * messages.
344
+ *
345
+ * The provider request carries it as `reasoning_content`, but it is not input:
346
+ * the gateway billed it on some models (a measured glm-5.3-flash request went
347
+ * from 27 to 188 prompt tokens with the same answer) and the token estimate used
348
+ * for diet/compaction assumes it is not sent. Removing it keeps the request
349
+ * identical in behavior and smaller in credits.
350
+ */
351
+ function stripAssistantReasoning(deps: Deps, event: any): void {
352
+ const messages = event.messages;
353
+ if (!Array.isArray(messages) || messages.length === 0) return;
354
+ let chars = 0;
355
+ let changed = false;
356
+ const next = messages.map((message: any) => {
357
+ if (!message || message.role !== "assistant") return message;
358
+ let copy: any | undefined;
359
+ const ensureCopy = () => {
360
+ if (!copy) copy = { ...message };
361
+ return copy;
362
+ };
363
+ for (const key of ["reasoning_content", "reasoning"] as const) {
364
+ if (!(key in message)) continue;
365
+ const value = message[key];
366
+ if (typeof value === "string") chars += value.length;
367
+ ensureCopy();
368
+ delete copy[key];
369
+ changed = true;
370
+ }
371
+ if (Array.isArray(message.content)) {
372
+ const kept = message.content.filter(
373
+ (part: any) => part?.type !== "reasoning" && part?.type !== "thinking",
374
+ );
375
+ if (kept.length !== message.content.length) {
376
+ ensureCopy();
377
+ copy.content = kept;
378
+ changed = true;
379
+ }
380
+ }
381
+ return copy ?? message;
382
+ });
383
+ if (!changed) return;
384
+ event.messages = next;
385
+ if (chars > 0) {
386
+ deps.log.info("free-pi dropped stored reasoning from the request", {
387
+ sessionID: event.sessionID,
388
+ chars,
389
+ });
390
+ }
391
+ }
392
+
341
393
  /** Caps output tokens, applies the efficiency rule and derives the ad turn. */
342
394
  async function applyGeneration(
343
395
  deps: Deps,
@@ -355,6 +407,8 @@ async function applyGeneration(
355
407
  return;
356
408
  }
357
409
 
410
+ stripAssistantReasoning(deps, event);
411
+
358
412
  const modelID = event.model?.id;
359
413
  const limit = deps.state.outputLimits.get(
360
414
  `${event.model.providerID}/${modelID}`,