opencode-model-router 2.0.0 → 2.2.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.
@@ -5,14 +5,14 @@ import type { PluginLogger } from "./logger";
5
5
  * `src/index.ts` turns each tier of the active preset into an opencode agent
6
6
  * definition; this module owns the `options` bag on that definition. It is the
7
7
  * only place that knows how a tier's provider-agnostic `effort` maps onto the
8
- * provider-specific knob (`effort` for Anthropic, `reasoning_effort` for
8
+ * provider-specific knob (`effort` for Anthropic, `reasoningEffort` for
9
9
  * OpenAI) and what to do when a tier asks for something the provider cannot do.
10
10
  *
11
11
  * The display-path builder in `src/commands/output.ts` renders what a tier is
12
12
  * configured with; this one decides what is actually sent. They are kept apart
13
13
  * on purpose: `/tiers` should not warn, downgrade or drop keys.
14
14
  */
15
- import type { TierConfig } from "./config";
15
+ import type { EffortLevel, TierConfig } from "./config";
16
16
  import { EFFORT_LEVELS } from "./config";
17
17
  import { isAdaptiveOnlyClaudeModel, isClaudeModel } from "./protocol";
18
18
 
@@ -55,6 +55,33 @@ function isOpenAIModel(model: string): boolean {
55
55
  return s.startsWith("openai/") || /\bgpt-/.test(s) || /(^|[/\-_])o[134]([/\-_]|$)/.test(s);
56
56
  }
57
57
 
58
+ export function effortRank(level: EffortLevel): number {
59
+ return EFFORT_LEVELS.indexOf(level);
60
+ }
61
+
62
+ export function nextEffort(current: EffortLevel, bound: EffortLevel): EffortLevel | null {
63
+ return effortRank(current) < effortRank(bound)
64
+ ? EFFORT_LEVELS[effortRank(current) + 1]!
65
+ : null;
66
+ }
67
+
68
+ export function minEffort(a: EffortLevel, b: EffortLevel): EffortLevel {
69
+ return effortRank(a) <= effortRank(b) ? a : b;
70
+ }
71
+
72
+ export function effortCeilingFor(tier: TierConfig): EffortLevel | null {
73
+ if (tier.variant || tier.effort === undefined || !isEffortLevel(tier.effort)) return null;
74
+ if (isClaudeModel(tier.model)) {
75
+ if (Boolean(tier.thinking?.budgetTokens) && !isAdaptiveOnlyClaudeModel(tier.model)) return null;
76
+ return "max";
77
+ }
78
+ if (isOpenAIModel(tier.model)) {
79
+ if (tier.reasoning?.effort) return null;
80
+ return "high";
81
+ }
82
+ return null;
83
+ }
84
+
58
85
  /**
59
86
  * Provider-specific agent options for a tier, as registered with opencode.
60
87
  *
@@ -64,8 +91,8 @@ function isOpenAIModel(model: string): boolean {
64
91
  * loses to `effort`, with a one-time notice per tier.
65
92
  *
66
93
  * Explicit fields are gated by model: a Claude model never receives
67
- * `reasoning_effort` / `reasoning_summary`, and an adaptive-only Claude model
68
- * (`isAdaptiveOnlyClaudeModel`) never receives `budget_tokens` — the budget is
94
+ * `reasoningEffort` / `reasoningSummary`, and an adaptive-only Claude model
95
+ * (`isAdaptiveOnlyClaudeModel`) never receives `thinking` — the budget is
69
96
  * then ignored as if unset, so `effort` still applies. Each drop warns once
70
97
  * per tier. A key is
71
98
  * only ever present when something asked for it — an unset `effort` leaves no
@@ -94,8 +121,6 @@ export function buildAgentOptions(
94
121
  `tier ${tierName}: model '${tier.model}' only accepts adaptive thinking and rejects a manual budget, so thinking.budgetTokens is ignored; use effort instead`,
95
122
  logger,
96
123
  );
97
- } else if (hasThinkingBudget) {
98
- opts.budget_tokens = tier.thinking?.budgetTokens;
99
124
  } else if (tier.thinking?.budgetTokens === 0) {
100
125
  warnAgentOptionsEffortOnce(
101
126
  `thinking-zero:${tierName}`,
@@ -116,10 +141,7 @@ export function buildAgentOptions(
116
141
  }
117
142
  } else if (tier.reasoning) {
118
143
  if (tier.reasoning.effort) {
119
- opts.reasoning_effort = tier.reasoning.effort;
120
- }
121
- if (tier.reasoning.summary) {
122
- opts.reasoning_summary = tier.reasoning.summary;
144
+ opts.reasoningEffort = tier.reasoning.effort;
123
145
  }
124
146
  }
125
147
 
@@ -157,9 +179,9 @@ export function buildAgentOptions(
157
179
  `tier ${tierName}: downgrading effort '${effort}' to 'high' because OpenAI reasoning_effort only supports low, medium, or high`,
158
180
  logger,
159
181
  );
160
- opts.reasoning_effort = "high";
182
+ opts.reasoningEffort = "high";
161
183
  } else {
162
- opts.reasoning_effort = effort;
184
+ opts.reasoningEffort = effort;
163
185
  }
164
186
  } else {
165
187
  warnAgentOptionsEffortOnce(
@@ -170,5 +192,14 @@ export function buildAgentOptions(
170
192
  }
171
193
  }
172
194
 
195
+ // Preserve the v2.0.0 bridge's insertion order: ordinary options, then
196
+ // reasoningEffort, reasoningSummary, thinking. Only emission moves; the
197
+ // family checks, warning order and explicit-config precedence stay intact.
198
+ if (!isClaude && tier.reasoning?.summary) {
199
+ opts.reasoningSummary = tier.reasoning.summary;
200
+ }
201
+ if (hasThinkingBudget) {
202
+ opts.thinking = { type: "enabled", budgetTokens: tier.thinking?.budgetTokens };
203
+ }
173
204
  return opts;
174
205
  }