@eduardo191labs/opencode-free-pi 0.5.4 → 0.5.5

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
@@ -95,13 +95,15 @@ Después de iniciar sesión, ejecuta `/reload` en OpenCode o reinícialo.
95
95
  - **Subagentes identificados**: las sesiones hijas envían
96
96
  `x-freepi-subagent: 1`, igual que los proveedores que el CLI crea para sus
97
97
  subagentes.
98
- - **Pensamiento sin forzar**: el plugin no envía un `reasoning_effort` por
99
- defecto. Forzar `none` (como hacía una versión anterior) apagaba el
100
- razonamiento y los modelos respondían con prisa; dejarlo sin definir usa el
101
- nivel del servidor. El selector sigue ofreciendo `minimal`, `low`, `medium` y
102
- `high` mediante `reasoning_effort`, igual que `pi-ai`. No se anuncian
103
- `thinking_budget` ni `thinking`, porque la ruta `openai-compatible` de
104
- OpenCode los descarta.
98
+ - **Pensamiento por defecto**: el plugin pide `reasoning_effort: "medium"`
99
+ cuando el modelo no trae variante elegida. Dejarlo sin definir hacía que los
100
+ modelos gratuitos respondieran con prisa, gastando apenas unas decenas de
101
+ tokens de razonamiento incluso en tareas que requieren planificar. Si el
102
+ catálogo del modelo solo anuncia `low`/`high`, se usa `high`. El selector
103
+ sigue ofreciendo `none`, `minimal`, `low`, `medium` y `high`, y la opción
104
+ `reasoningEffort: false` del plugin recupera el comportamiento anterior (nivel
105
+ del servidor). No se anuncian `thinking_budget` ni `thinking`, porque la ruta
106
+ `openai-compatible` de OpenCode los descarta.
105
107
  - **Solo modelos utilizables**: al arrancar se consulta `/me` y el selector
106
108
  `/model` incluye únicamente lo que la cuenta puede usar: los modelos
107
109
  `free: true` siempre, los de pago mientras queden créditos de la cuota o
@@ -12,9 +12,23 @@ export declare function modelCost(_model: CatalogModel, _capability?: ModelsDevM
12
12
  export declare function modelRegistryCandidates(registry: ModelRegistry | undefined): RegistryCandidate[];
13
13
  export declare function modelCapability(model: CatalogModel, candidates: RegistryCandidate[]): ModelsDevModel | undefined;
14
14
  export declare function modelVariants(options: ReasoningOption[] | undefined, _outputLimit: number): VariantMap;
15
+ export declare function isReasoningEffort(value: unknown): value is string;
16
+ /**
17
+ * The effort sent when no variant is selected. `false` leaves the gateway's
18
+ * own default untouched; otherwise the catalog's supported levels win over
19
+ * `medium`, so a model that only accepts `low`/`high` never gets an effort it
20
+ * would reject.
21
+ */
22
+ export declare function preferredReasoningEffort(options: ReasoningOption[] | undefined, configured?: string | false): string | undefined;
15
23
  export type BuildModelsOptions = {
16
24
  /** pi's `compact100` arm compacts at 100k instead of the default ceiling. */
17
25
  compact100?: boolean;
26
+ /**
27
+ * Effort sent when the user has not picked a variant. `false` keeps the
28
+ * gateway default. Defaults to `medium` because an unset effort makes the
29
+ * free models answer before they reason.
30
+ */
31
+ reasoningEffort?: string | false;
18
32
  };
19
33
  /**
20
34
  * What the signed-in account can actually use, derived from `GET /me`.
@@ -1,5 +1,5 @@
1
1
  /** Turns the free-pi catalog and models.dev registry into model definitions. */
2
- import { COMPACT100_CONTEXT_WINDOW, CONTEXT_WINDOW, DEFAULT_THINKING_LEVELS, MAX_OUTPUT_TOKENS, } from "../constants.js";
2
+ import { COMPACT100_CONTEXT_WINDOW, CONTEXT_WINDOW, DEFAULT_REASONING_EFFORT, DEFAULT_THINKING_LEVELS, MAX_OUTPUT_TOKENS, REASONING_EFFORTS, } from "../constants.js";
3
3
  import { positiveNumber } from "../utils/numbers.js";
4
4
  import { cleanText } from "../utils/text.js";
5
5
  export function usableModels(catalog) {
@@ -151,6 +151,37 @@ export function modelVariants(options, _outputLimit) {
151
151
  }
152
152
  return variants;
153
153
  }
154
+ export function isReasoningEffort(value) {
155
+ return (typeof value === "string" &&
156
+ REASONING_EFFORTS.includes(value));
157
+ }
158
+ /**
159
+ * The effort sent when no variant is selected. `false` leaves the gateway's
160
+ * own default untouched; otherwise the catalog's supported levels win over
161
+ * `medium`, so a model that only accepts `low`/`high` never gets an effort it
162
+ * would reject.
163
+ */
164
+ export function preferredReasoningEffort(options, configured) {
165
+ if (configured === false)
166
+ return undefined;
167
+ if (configured)
168
+ return configured;
169
+ if (!options || options.length === 0)
170
+ return DEFAULT_REASONING_EFFORT;
171
+ const effort = options.find((option) => option.type === "effort");
172
+ if (effort) {
173
+ if (effort.values.includes(DEFAULT_REASONING_EFFORT))
174
+ return DEFAULT_REASONING_EFFORT;
175
+ if (effort.values.includes("high"))
176
+ return "high";
177
+ return effort.values[effort.values.length - 1];
178
+ }
179
+ if (options.some((option) => option.type === "toggle"))
180
+ return "high";
181
+ if (options.some((option) => option.type === "budget_tokens"))
182
+ return "high";
183
+ return DEFAULT_REASONING_EFFORT;
184
+ }
154
185
  export function accountAccess(me) {
155
186
  if (!me)
156
187
  return undefined;
@@ -207,6 +238,9 @@ export function buildModels(models, candidates = [], options = {}) {
207
238
  : CONTEXT_WINDOW;
208
239
  const limitContext = Math.min(positiveNumber(model.context_window, model.contextWindow, model.limit?.context, capability?.limit?.context) ?? contextCeiling, contextCeiling);
209
240
  const limitOutput = Math.min(positiveNumber(model.max_tokens, model.maxTokens, model.max_output_tokens, model.limit?.output, capability?.limit?.output) ?? MAX_OUTPUT_TOKENS, MAX_OUTPUT_TOKENS);
241
+ const defaultEffort = reasoning
242
+ ? preferredReasoningEffort(reasoningOptions, options.reasoningEffort)
243
+ : undefined;
210
244
  result[model.id] = {
211
245
  id: model.id,
212
246
  name: displayName(model),
@@ -217,6 +251,7 @@ export function buildModels(models, candidates = [], options = {}) {
217
251
  reasoning,
218
252
  reasoning_options: reasoningOptions,
219
253
  variants: reasoning ? modelVariants(reasoningOptions, limitOutput) : {},
254
+ ...(defaultEffort ? { settings: { reasoningEffort: defaultEffort } } : {}),
220
255
  enabled: model.unavailable !== true,
221
256
  temperature: model.temperature ?? capability?.temperature ?? true,
222
257
  tool_call: model.tool_call ?? capability?.tool_call ?? true,
@@ -19,13 +19,15 @@ export declare const SUBAGENT_HEADER = "x-freepi-subagent";
19
19
  export declare const COST_EXPERIMENT_HEADER = "x-freepi-cost-exp";
20
20
  export declare const EFFICIENCY_RULE = "- When several independent reads or searches are needed, issue them in the same turn.";
21
21
  /**
22
- * The provider CLI registers every free-pi model with reasoning enabled and
23
- * defaults to thinking off. OpenCode only sends `reasoning_effort` when a
24
- * variant or model setting provides one, so the model carries the off default
25
- * and the picker offers the levels the CLI would.
22
+ * The provider CLI starts with thinking off, but leaving `reasoning_effort`
23
+ * unset makes the gateway answer in a hurry: the free models spend only a few
24
+ * dozen reasoning tokens even on tasks that need planning. The plugin therefore
25
+ * asks for `medium` by default and keeps the CLI's levels as variants, so
26
+ * `none`/`minimal` are still one pick away when speed matters more than care.
26
27
  */
27
- export declare const DEFAULT_REASONING_EFFORT = "none";
28
- export declare const DEFAULT_THINKING_LEVELS: readonly ["minimal", "low", "medium", "high"];
28
+ export declare const DEFAULT_REASONING_EFFORT = "medium";
29
+ export declare const REASONING_EFFORTS: readonly ["none", "minimal", "low", "medium", "high", "max"];
30
+ export declare const DEFAULT_THINKING_LEVELS: readonly ["none", "minimal", "low", "medium", "high"];
29
31
  /** pi-ai's HTTP idle timeout for headers and body chunks. */
30
32
  export declare const HEADER_TIMEOUT_MS = 300000;
31
33
  export declare const CHUNK_TIMEOUT_MS = 300000;
package/dist/constants.js CHANGED
@@ -19,13 +19,23 @@ export const SUBAGENT_HEADER = "x-freepi-subagent";
19
19
  export const COST_EXPERIMENT_HEADER = "x-freepi-cost-exp";
20
20
  export const EFFICIENCY_RULE = "- When several independent reads or searches are needed, issue them in the same turn.";
21
21
  /**
22
- * The provider CLI registers every free-pi model with reasoning enabled and
23
- * defaults to thinking off. OpenCode only sends `reasoning_effort` when a
24
- * variant or model setting provides one, so the model carries the off default
25
- * and the picker offers the levels the CLI would.
22
+ * The provider CLI starts with thinking off, but leaving `reasoning_effort`
23
+ * unset makes the gateway answer in a hurry: the free models spend only a few
24
+ * dozen reasoning tokens even on tasks that need planning. The plugin therefore
25
+ * asks for `medium` by default and keeps the CLI's levels as variants, so
26
+ * `none`/`minimal` are still one pick away when speed matters more than care.
26
27
  */
27
- export const DEFAULT_REASONING_EFFORT = "none";
28
+ export const DEFAULT_REASONING_EFFORT = "medium";
29
+ export const REASONING_EFFORTS = [
30
+ "none",
31
+ "minimal",
32
+ "low",
33
+ "medium",
34
+ "high",
35
+ "max",
36
+ ];
28
37
  export const DEFAULT_THINKING_LEVELS = [
38
+ "none",
29
39
  "minimal",
30
40
  "low",
31
41
  "medium",
package/dist/plugin.js CHANGED
@@ -7,7 +7,7 @@ import { closeFreePiSession } from "./api/session.js";
7
7
  import { readCredentialsToken } from "./auth/credentials.js";
8
8
  import { tokenFromCredential } from "./auth/credential.js";
9
9
  import { fetchCatalog } from "./catalog/catalog.js";
10
- import { accountAccess, buildModels, filterAccessibleModels, modelRegistryCandidates, partitionModels, } from "./catalog/models.js";
10
+ import { accountAccess, buildModels, filterAccessibleModels, isReasoningEffort, modelRegistryCandidates, partitionModels, } from "./catalog/models.js";
11
11
  import { fetchModelsRegistry } from "./catalog/registry.js";
12
12
  import { applyProvider } from "./catalog/v2.js";
13
13
  import { DEFENSE_PROVIDER_ID, PROVIDER_ID, } from "./constants.js";
@@ -103,7 +103,15 @@ async function setup(ctx) {
103
103
  const main = filterAccessibleModels(catalogMain, access);
104
104
  const defense = filterAccessibleModels(catalogDefense, access);
105
105
  const candidates = modelRegistryCandidates(registry);
106
- const buildOptions = { compact100: state.costExperimentArm === "compact100" };
106
+ const configuredEffort = ctx.options?.reasoningEffort;
107
+ const buildOptions = {
108
+ compact100: state.costExperimentArm === "compact100",
109
+ ...(configuredEffort === false
110
+ ? { reasoningEffort: false }
111
+ : isReasoningEffort(configuredEffort)
112
+ ? { reasoningEffort: configuredEffort }
113
+ : {}),
114
+ };
107
115
  const mainModels = buildModels(main, candidates, buildOptions);
108
116
  const defenseModels = buildModels(defense, candidates, buildOptions);
109
117
  for (const [id, model] of Object.entries(mainModels)) {
package/dist/types.d.ts CHANGED
@@ -133,6 +133,11 @@ export type ModelDefinition = {
133
133
  export type ModelMap = Record<string, ModelDefinition>;
134
134
  export type FreePiOptions = {
135
135
  includeDefense?: boolean;
136
+ /**
137
+ * Effort used when no variant is picked. Defaults to `medium` so the free
138
+ * models plan before answering. Set `false` to keep the gateway default.
139
+ */
140
+ reasoningEffort?: string | false;
136
141
  };
137
142
  export type MeResponse = {
138
143
  handle?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eduardo191labs/opencode-free-pi",
3
- "version": "0.5.4",
3
+ "version": "0.5.5",
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",
@@ -3,8 +3,10 @@
3
3
  import {
4
4
  COMPACT100_CONTEXT_WINDOW,
5
5
  CONTEXT_WINDOW,
6
+ DEFAULT_REASONING_EFFORT,
6
7
  DEFAULT_THINKING_LEVELS,
7
8
  MAX_OUTPUT_TOKENS,
9
+ REASONING_EFFORTS,
8
10
  } from "../constants.js";
9
11
  import type {
10
12
  Catalog,
@@ -202,9 +204,50 @@ export function modelVariants(
202
204
  return variants;
203
205
  }
204
206
 
207
+ export function isReasoningEffort(value: unknown): value is string {
208
+ return (
209
+ typeof value === "string" &&
210
+ (REASONING_EFFORTS as readonly string[]).includes(value)
211
+ );
212
+ }
213
+
214
+ /**
215
+ * The effort sent when no variant is selected. `false` leaves the gateway's
216
+ * own default untouched; otherwise the catalog's supported levels win over
217
+ * `medium`, so a model that only accepts `low`/`high` never gets an effort it
218
+ * would reject.
219
+ */
220
+ export function preferredReasoningEffort(
221
+ options: ReasoningOption[] | undefined,
222
+ configured?: string | false,
223
+ ): string | undefined {
224
+ if (configured === false) return undefined;
225
+ if (configured) return configured;
226
+ if (!options || options.length === 0) return DEFAULT_REASONING_EFFORT;
227
+ const effort = options.find(
228
+ (option): option is Extract<ReasoningOption, { type: "effort" }> =>
229
+ option.type === "effort",
230
+ );
231
+ if (effort) {
232
+ if (effort.values.includes(DEFAULT_REASONING_EFFORT))
233
+ return DEFAULT_REASONING_EFFORT;
234
+ if (effort.values.includes("high")) return "high";
235
+ return effort.values[effort.values.length - 1];
236
+ }
237
+ if (options.some((option) => option.type === "toggle")) return "high";
238
+ if (options.some((option) => option.type === "budget_tokens")) return "high";
239
+ return DEFAULT_REASONING_EFFORT;
240
+ }
241
+
205
242
  export type BuildModelsOptions = {
206
243
  /** pi's `compact100` arm compacts at 100k instead of the default ceiling. */
207
244
  compact100?: boolean;
245
+ /**
246
+ * Effort sent when the user has not picked a variant. `false` keeps the
247
+ * gateway default. Defaults to `medium` because an unset effort makes the
248
+ * free models answer before they reason.
249
+ */
250
+ reasoningEffort?: string | false;
208
251
  };
209
252
 
210
253
  /**
@@ -302,6 +345,9 @@ export function buildModels(
302
345
  ) ?? MAX_OUTPUT_TOKENS,
303
346
  MAX_OUTPUT_TOKENS,
304
347
  );
348
+ const defaultEffort = reasoning
349
+ ? preferredReasoningEffort(reasoningOptions, options.reasoningEffort)
350
+ : undefined;
305
351
  result[model.id] = {
306
352
  id: model.id,
307
353
  name: displayName(model),
@@ -313,6 +359,7 @@ export function buildModels(
313
359
  reasoning,
314
360
  reasoning_options: reasoningOptions,
315
361
  variants: reasoning ? modelVariants(reasoningOptions, limitOutput) : {},
362
+ ...(defaultEffort ? { settings: { reasoningEffort: defaultEffort } } : {}),
316
363
  enabled: model.unavailable !== true,
317
364
  temperature: model.temperature ?? capability?.temperature ?? true,
318
365
  tool_call: model.tool_call ?? capability?.tool_call ?? true,
package/src/constants.ts CHANGED
@@ -26,13 +26,23 @@ export const EFFICIENCY_RULE =
26
26
  "- When several independent reads or searches are needed, issue them in the same turn.";
27
27
 
28
28
  /**
29
- * The provider CLI registers every free-pi model with reasoning enabled and
30
- * defaults to thinking off. OpenCode only sends `reasoning_effort` when a
31
- * variant or model setting provides one, so the model carries the off default
32
- * and the picker offers the levels the CLI would.
29
+ * The provider CLI starts with thinking off, but leaving `reasoning_effort`
30
+ * unset makes the gateway answer in a hurry: the free models spend only a few
31
+ * dozen reasoning tokens even on tasks that need planning. The plugin therefore
32
+ * asks for `medium` by default and keeps the CLI's levels as variants, so
33
+ * `none`/`minimal` are still one pick away when speed matters more than care.
33
34
  */
34
- export const DEFAULT_REASONING_EFFORT = "none";
35
+ export const DEFAULT_REASONING_EFFORT = "medium";
36
+ export const REASONING_EFFORTS = [
37
+ "none",
38
+ "minimal",
39
+ "low",
40
+ "medium",
41
+ "high",
42
+ "max",
43
+ ] as const;
35
44
  export const DEFAULT_THINKING_LEVELS = [
45
+ "none",
36
46
  "minimal",
37
47
  "low",
38
48
  "medium",
package/src/plugin.ts CHANGED
@@ -19,6 +19,7 @@ import {
19
19
  accountAccess,
20
20
  buildModels,
21
21
  filterAccessibleModels,
22
+ isReasoningEffort,
22
23
  modelRegistryCandidates,
23
24
  partitionModels,
24
25
  } from "./catalog/models.js";
@@ -129,7 +130,15 @@ async function setup(ctx: Plugin.Context): Promise<() => Promise<void>> {
129
130
  const main = filterAccessibleModels(catalogMain, access);
130
131
  const defense = filterAccessibleModels(catalogDefense, access);
131
132
  const candidates = modelRegistryCandidates(registry);
132
- const buildOptions = { compact100: state.costExperimentArm === "compact100" };
133
+ const configuredEffort = ctx.options?.reasoningEffort;
134
+ const buildOptions = {
135
+ compact100: state.costExperimentArm === "compact100",
136
+ ...(configuredEffort === false
137
+ ? { reasoningEffort: false as const }
138
+ : isReasoningEffort(configuredEffort)
139
+ ? { reasoningEffort: configuredEffort }
140
+ : {}),
141
+ };
133
142
  const mainModels = buildModels(main, candidates, buildOptions);
134
143
  const defenseModels = buildModels(defense, candidates, buildOptions);
135
144
 
package/src/types.ts CHANGED
@@ -110,6 +110,11 @@ export type ModelMap = Record<string, ModelDefinition>;
110
110
 
111
111
  export type FreePiOptions = {
112
112
  includeDefense?: boolean;
113
+ /**
114
+ * Effort used when no variant is picked. Defaults to `medium` so the free
115
+ * models plan before answering. Set `false` to keep the gateway default.
116
+ */
117
+ reasoningEffort?: string | false;
113
118
  };
114
119
 
115
120
  export type MeResponse = {