@opencode-ai/ai 0.0.0-next-16996 → 0.0.0-next-16998

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
@@ -368,11 +368,12 @@ Other provider exports listed above remain direct facades until they explicitly
368
368
 
369
369
  ## Provider options & HTTP overlays
370
370
 
371
- Three escape hatches in order of stability:
371
+ Request options in order of stability:
372
372
 
373
373
  1. **`generation`** — portable knobs (`maxTokens`, `temperature`, `topP`, `topK`, penalties, seed, stop).
374
- 2. **`providerOptions: { <provider>: {...} }`** — typed-at-the-facade provider-specific knobs (OpenAI `promptCacheKey`, Anthropic `thinking`, Gemini `thinkingConfig`, OpenRouter routing).
375
- 3. **`http: { body, headers, query }`** — last-resort serializable overlays merged into the final HTTP request. Reach for this only when a stable typed path doesn't yet exist.
374
+ 2. **`promptCacheKey`** — stable cache affinity lowered by every protocol that supports it.
375
+ 3. **`providerOptions: { <provider>: {...} }`** — typed-at-the-facade provider-specific knobs (OpenAI `store`, Anthropic `thinking`, Gemini `thinkingConfig`, OpenRouter routing).
376
+ 4. **`http: { body, headers, query }`** — last-resort serializable overlays merged into the final HTTP request. Reach for this only when a stable typed path doesn't yet exist.
376
377
 
377
378
  Route/provider defaults are overridden by request-level values for each axis.
378
379
 
@@ -83,6 +83,9 @@ declare const GeminiBody: Schema.Struct<{
83
83
  readonly temperature: Schema.optional<Schema.Number>;
84
84
  readonly topP: Schema.optional<Schema.Number>;
85
85
  readonly topK: Schema.optional<Schema.Number>;
86
+ readonly frequencyPenalty: Schema.optional<Schema.Number>;
87
+ readonly presencePenalty: Schema.optional<Schema.Number>;
88
+ readonly seed: Schema.optional<Schema.Number>;
86
89
  readonly stopSequences: Schema.optional<Schema.$Array<Schema.String>>;
87
90
  readonly thinkingConfig: Schema.optional<Schema.Struct<{
88
91
  readonly thinkingBudget: Schema.optional<Schema.Number>;
@@ -160,6 +163,9 @@ export declare const protocol: Protocol<{
160
163
  readonly temperature?: number | undefined;
161
164
  readonly topP?: number | undefined;
162
165
  readonly topK?: number | undefined;
166
+ readonly frequencyPenalty?: number | undefined;
167
+ readonly presencePenalty?: number | undefined;
168
+ readonly seed?: number | undefined;
163
169
  readonly stopSequences?: readonly string[] | undefined;
164
170
  readonly thinkingConfig?: {
165
171
  readonly thinkingBudget?: number | undefined;
@@ -279,6 +285,9 @@ export declare const route: Route<{
279
285
  readonly temperature?: number | undefined;
280
286
  readonly topP?: number | undefined;
281
287
  readonly topK?: number | undefined;
288
+ readonly frequencyPenalty?: number | undefined;
289
+ readonly presencePenalty?: number | undefined;
290
+ readonly seed?: number | undefined;
282
291
  readonly stopSequences?: readonly string[] | undefined;
283
292
  readonly thinkingConfig?: {
284
293
  readonly thinkingBudget?: number | undefined;
@@ -12,7 +12,21 @@ import { Lifecycle } from "./utils/lifecycle";
12
12
  import { ToolSchemaProjection } from "./utils/tool-schema";
13
13
  const ADAPTER = "gemini";
14
14
  const MEDIA_MIMES = new Set(ProviderShared.MEDIA_MIMES);
15
+ // Google documents this sentinel for replaying Gemini 3 function calls after their original signature was lost.
16
+ const SKIP_THOUGHT_SIGNATURE_VALIDATOR = "skip_thought_signature_validator";
15
17
  export const DEFAULT_BASE_URL = "https://generativelanguage.googleapis.com/v1beta";
18
+ // Gemini 3 rejects replayed function calls without a thought signature. Google's SDKs avoid that in normal chats by
19
+ // retaining complete model responses, but OpenCode reconstructs durable history and may encounter an unsigned call
20
+ // from an older or external session. Model IDs are open-ended, so unknown Gemini aliases inherit current behavior.
21
+ const requiresThoughtSignatureFallback = (modelID) => {
22
+ if (!/(^|\/)gemini-/i.test(modelID))
23
+ return false;
24
+ if (/(^|\/)gemini-(?:1|2)(?:[.-]|$)/i.test(modelID))
25
+ return false;
26
+ if (/(^|\/)gemini-pro(?:-vision)?$/i.test(modelID))
27
+ return false;
28
+ return !/(^|\/)gemini-robotics-er-1\.5(?:[.-]|$)/i.test(modelID);
29
+ };
16
30
  // =============================================================================
17
31
  // Request Body Schema
18
32
  // =============================================================================
@@ -84,6 +98,9 @@ const GeminiGenerationConfig = Schema.Struct({
84
98
  temperature: Schema.optional(Schema.Number),
85
99
  topP: Schema.optional(Schema.Number),
86
100
  topK: Schema.optional(Schema.Number),
101
+ frequencyPenalty: Schema.optional(Schema.Number),
102
+ presencePenalty: Schema.optional(Schema.Number),
103
+ seed: Schema.optional(Schema.Number),
87
104
  stopSequences: optionalArray(Schema.String),
88
105
  thinkingConfig: Schema.optional(GeminiThinkingConfig),
89
106
  });
@@ -124,11 +141,13 @@ const GeminiEvent = Schema.Struct({
124
141
  // keys on non-object scalars. Mirrors OpenCode's historical Gemini rules.
125
142
  //
126
143
  // 2. Project — lossy mapping from JSON Schema to Gemini's schema dialect:
127
- // drop empty objects, derive `nullable: true` from `type: [..., "null"]`,
128
- // coerce `const` to `[const]` enum, recurse properties/items, propagate
144
+ // drop empty root parameter schemas while preserving nested empty objects,
145
+ // expand type arrays into `anyOf`, derive `nullable: true` from null members,
146
+ // coerce `const` to `[const]` enum, recurse properties/items, and propagate
129
147
  // only an allowlisted set of keys (description, required, format, type,
130
- // properties, items, allOf, anyOf, oneOf, minLength). Anything outside the
131
- // allowlist (e.g. `additionalProperties`, `$ref`) is silently dropped.
148
+ // nullable, enum, properties, items, allOf, anyOf, oneOf, minLength).
149
+ // Anything outside the allowlist (e.g. `additionalProperties`, `$ref`) is
150
+ // silently dropped.
132
151
  //
133
152
  // Sanitize runs first, then project. The implementation lives in
134
153
  // `utils/gemini-tool-schema` so this protocol keeps the same shape as the other
@@ -194,6 +213,8 @@ const lowerMessages = Effect.fn("Gemini.lowerMessages")(function* (request) {
194
213
  }
195
214
  if (message.role === "assistant") {
196
215
  const parts = [];
216
+ // Parallel Gemini 3 calls may carry one signature on the first call; unsigned sibling calls are valid.
217
+ let hasSignedToolCall = false;
197
218
  for (const part of message.content) {
198
219
  if (!ProviderShared.supportsContent(part, ["text", "reasoning", "tool-call"]))
199
220
  return yield* ProviderShared.unsupportedContent("Gemini", "assistant", ["text", "reasoning", "tool-call"]);
@@ -206,7 +227,17 @@ const lowerMessages = Effect.fn("Gemini.lowerMessages")(function* (request) {
206
227
  continue;
207
228
  }
208
229
  if (part.type === "tool-call") {
209
- parts.push(lowerToolCall(part));
230
+ const lowered = lowerToolCall(part);
231
+ const signature = lowered.thoughtSignature;
232
+ parts.push({
233
+ ...lowered,
234
+ thoughtSignature: signature ??
235
+ (requiresThoughtSignatureFallback(request.model.id) && !hasSignedToolCall
236
+ ? SKIP_THOUGHT_SIGNATURE_VALIDATOR
237
+ : undefined),
238
+ });
239
+ if (signature !== undefined)
240
+ hasSignedToolCall = true;
210
241
  continue;
211
242
  }
212
243
  }
@@ -292,6 +323,9 @@ const fromRequest = Effect.fn("Gemini.fromRequest")(function* (request) {
292
323
  temperature: generation?.temperature,
293
324
  topP: generation?.topP,
294
325
  topK: generation?.topK,
326
+ frequencyPenalty: generation?.frequencyPenalty,
327
+ presencePenalty: generation?.presencePenalty,
328
+ seed: generation?.seed,
295
329
  stopSequences: generation?.stop,
296
330
  thinkingConfig: options.thinkingConfig,
297
331
  };
@@ -392,7 +392,7 @@ const lowerOptions = (request) => {
392
392
  return {
393
393
  ...(options.instructions ? { instructions: options.instructions } : {}),
394
394
  ...(options.store !== undefined ? { store: options.store } : {}),
395
- ...(options.promptCacheKey ? { prompt_cache_key: options.promptCacheKey } : {}),
395
+ ...(request.promptCacheKey ? { prompt_cache_key: request.promptCacheKey } : {}),
396
396
  ...(options.include ? { include: options.include } : {}),
397
397
  ...(options.reasoningEffort || options.reasoningSummary
398
398
  ? { reasoning: { effort: options.reasoningEffort, summary: options.reasoningSummary } }
@@ -47,37 +47,57 @@ const sanitizeNode = (schema) => {
47
47
  const emptyObjectSchema = (schema) => schema.type === "object" &&
48
48
  (!isRecord(schema.properties) || Object.keys(schema.properties).length === 0) &&
49
49
  !schema.additionalProperties;
50
- const projectNode = (schema) => {
50
+ const projectNode = (schema, nested = false) => {
51
51
  if (!isRecord(schema))
52
52
  return undefined;
53
- if (emptyObjectSchema(schema))
53
+ if (!nested && emptyObjectSchema(schema))
54
54
  return undefined;
55
- return Object.fromEntries([
55
+ const types = Array.isArray(schema.type) ? schema.type.filter((type) => type !== "null") : undefined;
56
+ const anyOf = Array.isArray(schema.anyOf) ? schema.anyOf : undefined;
57
+ const hasNullAnyOf = anyOf?.some((item) => isRecord(item) && item.type === "null") ?? false;
58
+ const anyOfTypes = hasNullAnyOf ? anyOf?.filter((item) => !isRecord(item) || item.type !== "null") : anyOf;
59
+ const flattenedAnyOf = hasNullAnyOf && anyOfTypes?.length === 1 ? projectNode(anyOfTypes[0], true) : undefined;
60
+ const result = Object.fromEntries([
56
61
  ["description", schema.description],
57
62
  ["required", schema.required],
58
63
  ["format", schema.format],
59
- ["type", Array.isArray(schema.type) ? schema.type.filter((type) => type !== "null")[0] : schema.type],
60
- ["nullable", Array.isArray(schema.type) && schema.type.includes("null") ? true : undefined],
64
+ ["type", types ? (types.length === 0 ? "null" : undefined) : schema.type],
65
+ [
66
+ "nullable",
67
+ (Array.isArray(schema.type) && schema.type.includes("null") && types && types.length > 0) || hasNullAnyOf
68
+ ? true
69
+ : undefined,
70
+ ],
61
71
  ["enum", schema.const !== undefined ? [schema.const] : schema.enum],
62
72
  [
63
73
  "properties",
64
74
  isRecord(schema.properties)
65
- ? Object.fromEntries(Object.entries(schema.properties).map(([key, value]) => [key, projectNode(value)]))
75
+ ? Object.fromEntries(Object.entries(schema.properties).map(([key, value]) => [key, projectNode(value, true)]))
66
76
  : undefined,
67
77
  ],
68
78
  [
69
79
  "items",
70
80
  Array.isArray(schema.items)
71
- ? schema.items.map(projectNode)
81
+ ? schema.items.map((item) => projectNode(item, true))
72
82
  : schema.items === undefined
73
83
  ? undefined
74
- : projectNode(schema.items),
84
+ : projectNode(schema.items, true),
85
+ ],
86
+ ["allOf", Array.isArray(schema.allOf) ? schema.allOf.map((item) => projectNode(item, true)) : undefined],
87
+ [
88
+ "anyOf",
89
+ anyOfTypes
90
+ ? hasNullAnyOf && anyOfTypes.length === 1
91
+ ? undefined
92
+ : anyOfTypes.map((item) => projectNode(item, true))
93
+ : types && types.length > 0
94
+ ? types.map((type) => ({ type }))
95
+ : undefined,
75
96
  ],
76
- ["allOf", Array.isArray(schema.allOf) ? schema.allOf.map(projectNode) : undefined],
77
- ["anyOf", Array.isArray(schema.anyOf) ? schema.anyOf.map(projectNode) : undefined],
78
- ["oneOf", Array.isArray(schema.oneOf) ? schema.oneOf.map(projectNode) : undefined],
97
+ ["oneOf", Array.isArray(schema.oneOf) ? schema.oneOf.map((item) => projectNode(item, true)) : undefined],
79
98
  ["minLength", schema.minLength],
80
99
  ].filter((entry) => entry[1] !== undefined));
100
+ return flattenedAnyOf ? { ...result, ...flattenedAnyOf } : result;
81
101
  };
82
102
  export const convert = (schema) => projectNode(sanitizeNode(schema));
83
103
  export * as GeminiToolSchema from "./gemini-tool-schema";
@@ -11,7 +11,6 @@ export declare const ServiceTierSchema: Schema.Literals<readonly ["auto", "defau
11
11
  export interface Resolved {
12
12
  readonly instructions?: string;
13
13
  readonly store?: boolean;
14
- readonly promptCacheKey?: string;
15
14
  readonly reasoningEffort?: string;
16
15
  readonly reasoningSummary?: "auto" | "concise" | "detailed";
17
16
  readonly include?: ReadonlyArray<ResponseIncludable>;
@@ -29,7 +29,6 @@ export const resolve = (request) => {
29
29
  return {
30
30
  instructions: typeof input?.instructions === "string" ? input.instructions : undefined,
31
31
  store: typeof input?.store === "boolean" ? input.store : undefined,
32
- promptCacheKey: typeof input?.promptCacheKey === "string" ? input.promptCacheKey : undefined,
33
32
  reasoningEffort: typeof input?.reasoningEffort === "string" ? input.reasoningEffort : undefined,
34
33
  reasoningSummary: reasoningSummary === "auto" || reasoningSummary === "concise" || reasoningSummary === "detailed"
35
34
  ? reasoningSummary
@@ -87,6 +87,9 @@ export declare const routes: Route<{
87
87
  readonly temperature?: number | undefined;
88
88
  readonly topP?: number | undefined;
89
89
  readonly topK?: number | undefined;
90
+ readonly frequencyPenalty?: number | undefined;
91
+ readonly presencePenalty?: number | undefined;
92
+ readonly seed?: number | undefined;
90
93
  readonly stopSequences?: readonly string[] | undefined;
91
94
  readonly thinkingConfig?: {
92
95
  readonly thinkingBudget?: number | undefined;
@@ -70,6 +70,9 @@ export declare const routes: import("../route").Route<{
70
70
  readonly temperature?: number | undefined;
71
71
  readonly topP?: number | undefined;
72
72
  readonly topK?: number | undefined;
73
+ readonly frequencyPenalty?: number | undefined;
74
+ readonly presencePenalty?: number | undefined;
75
+ readonly seed?: number | undefined;
73
76
  readonly stopSequences?: readonly string[] | undefined;
74
77
  readonly thinkingConfig?: {
75
78
  readonly thinkingBudget?: number | undefined;
@@ -4,7 +4,6 @@ export interface OpenResponsesOptionsInput {
4
4
  readonly [key: string]: unknown;
5
5
  readonly instructions?: string;
6
6
  readonly store?: boolean;
7
- readonly promptCacheKey?: string;
8
7
  readonly reasoningEffort?: ReasoningEffort;
9
8
  readonly reasoningSummary?: "auto" | "concise" | "detailed";
10
9
  readonly include?: ReadonlyArray<ResponseIncludable>;
@@ -3,7 +3,6 @@ const definedEntries = (input) => Object.entries(input).filter((entry) => entry[
3
3
  const openAIProviderOptions = (options) => {
4
4
  const openai = Object.fromEntries(definedEntries({
5
5
  store: options?.store,
6
- promptCacheKey: options?.promptCacheKey,
7
6
  reasoningEffort: options?.reasoningEffort,
8
7
  reasoningSummary: options?.reasoningSummary,
9
8
  include: options?.include,
@@ -59,7 +59,6 @@ export interface OpenRouterOptions {
59
59
  }>;
60
60
  readonly models?: ReadonlyArray<string>;
61
61
  readonly plugins?: ReadonlyArray<OpenRouterPlugin>;
62
- readonly promptCacheKey?: string;
63
62
  readonly provider?: OpenRouterProviderRouting;
64
63
  readonly reasoning?: Readonly<{
65
64
  enabled?: boolean;
@@ -43,6 +43,7 @@ export const protocol = Protocol.make({
43
43
  ...body,
44
44
  messages,
45
45
  ...bodyOptions(request.providerOptions?.openrouter),
46
+ ...(request.promptCacheKey ? { prompt_cache_key: request.promptCacheKey } : {}),
46
47
  };
47
48
  })),
48
49
  },
@@ -79,7 +80,6 @@ const bodyOptions = (input) => {
79
80
  ...(isRecord(debug) ? { debug } : {}),
80
81
  ...(typeof user === "string" ? { user } : {}),
81
82
  ...(isRecord(reasoning) ? { reasoning } : {}),
82
- ...(typeof promptCacheKey === "string" ? { prompt_cache_key: promptCacheKey } : {}),
83
83
  };
84
84
  };
85
85
  export const route = Route.make({
@@ -368,6 +368,7 @@ declare const LLMRequest_base: Schema.Class<LLMRequest, Schema.Struct<{
368
368
  }>]>>;
369
369
  readonly ttlSeconds: Schema.optional<Schema.Number>;
370
370
  }>]>>;
371
+ readonly promptCacheKey: Schema.optional<Schema.String>;
371
372
  readonly metadata: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
372
373
  }>, {}>;
373
374
  export declare class LLMRequest extends LLMRequest_base {
@@ -211,6 +211,8 @@ export class LLMRequest extends Schema.Class("LLM.Request")({
211
211
  providerOptions: Schema.optional(ProviderOptions),
212
212
  http: Schema.optional(HttpOptions),
213
213
  cache: Schema.optional(CachePolicy),
214
+ // Stable cache affinity for protocols that support provider-managed prompt caching.
215
+ promptCacheKey: Schema.optional(Schema.String),
214
216
  metadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
215
217
  }) {
216
218
  }
@@ -226,6 +228,7 @@ export class LLMRequest extends Schema.Class("LLM.Request")({
226
228
  providerOptions: request.providerOptions,
227
229
  http: request.http,
228
230
  cache: request.cache,
231
+ promptCacheKey: request.promptCacheKey,
229
232
  metadata: request.metadata,
230
233
  });
231
234
  LLMRequest.update = (request, patch) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
- "version": "0.0.0-next-16996",
3
+ "version": "0.0.0-next-16998",
4
4
  "name": "@opencode-ai/ai",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -30,7 +30,7 @@
30
30
  "devDependencies": {
31
31
  "@clack/prompts": "1.0.0-alpha.1",
32
32
  "@effect/platform-node": "4.0.0-beta.101",
33
- "@opencode-ai/http-recorder": "0.0.0-next-16996",
33
+ "@opencode-ai/http-recorder": "0.0.0-next-16998",
34
34
  "@tsconfig/bun": "1.0.9",
35
35
  "@types/bun": "1.3.13",
36
36
  "@typescript/native-preview": "7.0.0-dev.20251207.1",
@@ -39,7 +39,7 @@
39
39
  "dependencies": {
40
40
  "@smithy/eventstream-codec": "4.2.14",
41
41
  "@smithy/util-utf8": "4.2.2",
42
- "@opencode-ai/schema": "0.0.0-next-16996",
42
+ "@opencode-ai/schema": "0.0.0-next-16998",
43
43
  "aws4fetch": "1.0.20",
44
44
  "effect": "4.0.0-beta.101",
45
45
  "google-auth-library": "10.5.0"