@opencode/ai 0.0.0-dev-20130 → 0.0.0-dev-20131

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.
@@ -7,7 +7,7 @@ import { HttpOptions, ProviderID } from "../schema/index.js";
7
7
  import { SystemOne } from "../experimental/system-one.js";
8
8
  import { OpenAIChat } from "../protocols/openai-chat.js";
9
9
  import { newBreakpoints, ttlBucket } from "../protocols/utils/cache.js";
10
- import { isRecord } from "../protocols/shared.js";
10
+ import { isRecord, ProviderShared } from "../protocols/shared.js";
11
11
  export const id = ProviderID.make("openrouter");
12
12
  const baseURL = "https://openrouter.ai/api/v1";
13
13
  const ADAPTER = "openrouter";
@@ -41,7 +41,7 @@ export const protocol = Protocol.make({
41
41
  return {
42
42
  ...body,
43
43
  messages,
44
- ...bodyOptions(request.providerOptions),
44
+ ...bodyOptions(request.providerOptions, request.generation?.maxTokens),
45
45
  };
46
46
  })),
47
47
  },
@@ -59,7 +59,12 @@ const cacheControl = () => {
59
59
  };
60
60
  };
61
61
  };
62
- const bodyOptions = (input) => {
62
+ // OpenRouter forwards `reasoning.max_tokens` as the upstream thinking budget. Upstreams such as Anthropic and Alibaba
63
+ // reject one that is not below the output limit; 1,024 is Anthropic's minimum budget.
64
+ const fitReasoning = (reasoning, maxTokens) => typeof reasoning.max_tokens === "number"
65
+ ? { ...reasoning, max_tokens: ProviderShared.fitThinkingBudget(reasoning.max_tokens, maxTokens, 1_024) }
66
+ : reasoning;
67
+ const bodyOptions = (input, maxTokens) => {
63
68
  const openrouter = isRecord(input) ? input : {};
64
69
  const { usage, models, provider, plugins, web_search_options, debug, user, reasoning, promptCacheKey, ...options } = openrouter;
65
70
  return {
@@ -77,7 +82,7 @@ const bodyOptions = (input) => {
77
82
  ...(isRecord(web_search_options) ? { web_search_options } : {}),
78
83
  ...(isRecord(debug) ? { debug } : {}),
79
84
  ...(typeof user === "string" ? { user } : {}),
80
- ...(isRecord(reasoning) ? { reasoning } : {}),
85
+ ...(isRecord(reasoning) ? { reasoning: fitReasoning(reasoning, maxTokens) } : {}),
81
86
  };
82
87
  };
83
88
  export const route = Route.make({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
- "version": "0.0.0-dev-20130",
3
+ "version": "0.0.0-dev-20131",
4
4
  "name": "@opencode/ai",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -34,7 +34,7 @@
34
34
  "devDependencies": {
35
35
  "@clack/prompts": "1.0.0-alpha.1",
36
36
  "@effect/platform-node": "4.0.0-rc.112",
37
- "@opencode/http-recorder": "0.0.0-dev-20130",
37
+ "@opencode/http-recorder": "0.0.0-dev-20131",
38
38
  "@tsconfig/bun": "1.0.9",
39
39
  "@types/bun": "1.4.0",
40
40
  "@typescript/native-preview": "7.0.0-dev.20251207.1",
@@ -44,7 +44,7 @@
44
44
  "@aws-sdk/credential-providers": "3.1057.0",
45
45
  "@smithy/eventstream-codec": "4.2.14",
46
46
  "@smithy/util-utf8": "4.2.2",
47
- "@opencode/schema": "0.0.0-dev-20130",
47
+ "@opencode/schema": "0.0.0-dev-20131",
48
48
  "aws4fetch": "1.0.20",
49
49
  "effect": "4.0.0-rc.112",
50
50
  "google-auth-library": "10.5.0"