@opencode/ai 0.0.0-dev-21915 → 0.0.0-dev-21922

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.
Files changed (57) hide show
  1. package/README.md +22 -2
  2. package/dist/cache-policy.d.ts +4 -0
  3. package/dist/cache-policy.js +20 -6
  4. package/dist/protocols/alibaba-chat.d.ts +4 -0
  5. package/dist/protocols/alibaba-messages.d.ts +19 -19
  6. package/dist/protocols/anthropic-messages.d.ts +59 -59
  7. package/dist/protocols/anthropic-messages.js +3 -5
  8. package/dist/protocols/bedrock-converse.d.ts +12 -12
  9. package/dist/protocols/meta-messages.d.ts +19 -19
  10. package/dist/protocols/meta-messages.js +2 -1
  11. package/dist/protocols/openai-chat.d.ts +585 -1
  12. package/dist/protocols/openai-chat.js +7 -2
  13. package/dist/protocols/openai-compatible-chat.d.ts +4 -0
  14. package/dist/protocols/openai-responses.d.ts +24 -0
  15. package/dist/protocols/openai-responses.js +5 -0
  16. package/dist/protocols/utils/bedrock-cache.d.ts +2 -2
  17. package/dist/protocols/utils/bedrock-cache.js +7 -6
  18. package/dist/protocols/utils/cache.d.ts +14 -3
  19. package/dist/protocols/utils/cache.js +11 -4
  20. package/dist/protocols/venice-chat.d.ts +3 -0
  21. package/dist/protocols/venice-chat.js +1 -1
  22. package/dist/protocols/zai-chat.d.ts +4 -0
  23. package/dist/protocols/zai-messages.d.ts +19 -19
  24. package/dist/providers/alibaba.d.ts +23 -19
  25. package/dist/providers/amazon-bedrock-mantle.d.ts +23 -19
  26. package/dist/providers/amazon-bedrock.d.ts +4 -4
  27. package/dist/providers/anthropic-compatible.d.ts +19 -19
  28. package/dist/providers/anthropic.d.ts +19 -19
  29. package/dist/providers/azure.d.ts +12 -0
  30. package/dist/providers/baseten.d.ts +8 -0
  31. package/dist/providers/cerebras.d.ts +8 -0
  32. package/dist/providers/cloudflare-ai-gateway.d.ts +54 -38
  33. package/dist/providers/cloudflare-workers-ai.d.ts +8 -0
  34. package/dist/providers/cohere.d.ts +8 -0
  35. package/dist/providers/deepinfra.d.ts +8 -0
  36. package/dist/providers/deepseek.d.ts +8 -0
  37. package/dist/providers/digitalocean.d.ts +12 -0
  38. package/dist/providers/fireworks.d.ts +8 -0
  39. package/dist/providers/google-vertex-chat.d.ts +4 -0
  40. package/dist/providers/google-vertex-messages.d.ts +19 -19
  41. package/dist/providers/groq.d.ts +8 -0
  42. package/dist/providers/meta.d.ts +23 -19
  43. package/dist/providers/minimax.d.ts +23 -19
  44. package/dist/providers/moonshot.d.ts +23 -19
  45. package/dist/providers/openai-compatible.d.ts +4 -0
  46. package/dist/providers/openai.d.ts +8 -0
  47. package/dist/providers/openrouter.d.ts +16 -0
  48. package/dist/providers/togetherai.d.ts +8 -0
  49. package/dist/providers/venice.d.ts +3 -0
  50. package/dist/providers/xai.d.ts +4 -0
  51. package/dist/providers/zai-coding-plan.d.ts +23 -19
  52. package/dist/providers/zai.d.ts +4 -0
  53. package/dist/schema/messages.d.ts +2 -2
  54. package/dist/schema/options.d.ts +5 -3
  55. package/dist/schema/options.js +8 -3
  56. package/dist/utils/media-type.js +4 -0
  57. package/package.json +3 -3
package/README.md CHANGED
@@ -1322,13 +1322,33 @@ cache: {
1322
1322
  tools?: boolean,
1323
1323
  system?: boolean,
1324
1324
  messages?: "latest-user-message" | "latest-assistant" | { tail: number },
1325
- ttlSeconds?: number, // ≥ 3600 → 1h on Anthropic/Bedrock; else 5m
1325
+ ttl?: CacheTTL, // "5m", "30m", "1h", "12h", "24h", ...
1326
1326
  }
1327
1327
  ```
1328
1328
 
1329
+ An object with placement fields places exactly those breakpoints. An object with only `ttl` keeps automatic placement.
1330
+
1331
+ ### Cache lifetime
1332
+
1333
+ `ttl` is a duration in models.dev's format (`<number>` followed by `ms`, `s`, `m`, `h` or `d`). It is sent to the provider as given, so use one the provider accepts. Leaving it unset keeps the provider default.
1334
+
1335
+ ```ts
1336
+ LLM.request({ model, system, prompt, cache: { ttl: "1h" } })
1337
+ ```
1338
+
1339
+ | Protocol | How `ttl` is sent |
1340
+ | ------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------ |
1341
+ | Anthropic Messages family, Meta Messages | `ttl` on every `cache_control` marker |
1342
+ | Bedrock Converse | `ttl` on every `cachePoint`; older Claude releases that only cache for 5m drop `"1h"` |
1343
+ | OpenRouter, DigitalOcean, Alibaba Chat markers | `ttl` on every `cache_control` marker |
1344
+ | OpenAI Responses (OpenAI, Azure, Cloudflare AI Gateway) | `"24h"` → `prompt_cache_retention: "24h"`; anything else → `prompt_cache_options: { ttl }` |
1345
+ | Chat Completions without markers (OpenAI-compatible, Moonshot, DeepInfra) | same mapping as OpenAI Responses |
1346
+
1347
+ OpenAI's two fields cover different models: `prompt_cache_retention` (`"in_memory"` or `"24h"`) is the only control before GPT-5.6, and GPT-5.6+ reads `prompt_cache_options.ttl` (`"30m"` or `"12h"`). Sending `prompt_cache_options` to an older model returns a 400. `"in_memory"` is not a duration; send it with an HTTP body overlay.
1348
+
1329
1349
  ### Manual hints
1330
1350
 
1331
- Inline `CacheHint` on any text / system / tool / tool-result part overrides automatic placement. The auto policy preserves manual hints, counts them against Anthropic and Bedrock's four-breakpoint limit, and only fills the remaining slots.
1351
+ Inline `CacheHint` (`{ type: "ephemeral", ttl? }`) on any text / system / tool / tool-result part overrides automatic placement. The auto policy preserves manual hints, counts them against Anthropic and Bedrock's four-breakpoint limit, and only fills the remaining slots.
1332
1352
 
1333
1353
  ```ts
1334
1354
  LLM.request({
@@ -1,2 +1,6 @@
1
1
  import { LLMRequest } from "./schema/messages.js";
2
+ /** The requested cache lifetime, for routes that send it as a request-level option instead of on markers. */
3
+ export declare const requestTTL: (request: LLMRequest) => `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
2
4
  export declare const applyCachePolicy: (request: LLMRequest) => LLMRequest;
5
+ /** Whether the cache policy places inline markers, which then carry the requested lifetime. */
6
+ export declare const placesMarkers: (request: LLMRequest) => boolean;
@@ -24,14 +24,23 @@ const BREAKPOINT_CAP = 4;
24
24
  // - undefined → "auto" — caching is on by default.
25
25
  // - "auto" → tools + first/last system + final message boundary.
26
26
  // - "none" → no auto placement; manual `CacheHint`s still flow.
27
+ // - `{ ttl }` → "auto" with that lifetime.
27
28
  // - object form → exactly what the caller asked for.
28
29
  const resolve = (policy) => {
29
- if (policy === undefined || policy === "auto")
30
- return AUTO;
31
30
  if (policy === "none")
32
31
  return NONE;
33
- return policy;
32
+ if (typeof policy === "object" && !isAuto(policy))
33
+ return policy;
34
+ return AUTO;
34
35
  };
36
+ const isAuto = (policy) => policy === undefined ||
37
+ policy === "auto" ||
38
+ (typeof policy === "object" &&
39
+ policy.tools === undefined &&
40
+ policy.system === undefined &&
41
+ policy.messages === undefined);
42
+ /** The requested cache lifetime, for routes that send it as a request-level option instead of on markers. */
43
+ export const requestTTL = (request) => (typeof request.cache === "object" ? request.cache.ttl : undefined);
35
44
  // Protocols whose wire format ignores inline cache markers (OpenAI's implicit
36
45
  // prefix caching, Gemini's implicit + out-of-band CachedContent). Skip the
37
46
  // whole policy pass for these — emitting hints would be harmless but pointless.
@@ -65,7 +74,7 @@ const gatewayPolicy = (modelID) => {
65
74
  return QWEN;
66
75
  return NONE;
67
76
  };
68
- const makeHint = (ttlSeconds) => ttlSeconds !== undefined ? new CacheHint({ type: "ephemeral", ttlSeconds }) : new CacheHint({ type: "ephemeral" });
77
+ const makeHint = (ttl) => ttl !== undefined ? new CacheHint({ type: "ephemeral", ttl }) : new CacheHint({ type: "ephemeral" });
69
78
  const markLastTool = (tools, hint, budget) => {
70
79
  const target = tools.at(-1);
71
80
  if (target === undefined)
@@ -147,7 +156,7 @@ export const applyCachePolicy = (request) => {
147
156
  const policy = selectPolicy(request);
148
157
  if (!policy.tools && !policy.system && !policy.messages)
149
158
  return request;
150
- const hint = makeHint(policy.ttlSeconds);
159
+ const hint = makeHint(requestTTL(request));
151
160
  const budget = { remaining: Math.max(0, BREAKPOINT_CAP - countHints(request)) };
152
161
  const tools = policy.tools ? markLastTool(request.tools, hint, budget) : request.tools;
153
162
  const system = policy.system ? markSystemBoundaries(request.system, hint, budget) : request.system;
@@ -156,11 +165,16 @@ export const applyCachePolicy = (request) => {
156
165
  return request;
157
166
  return LLMRequest.update(request, { tools, system, messages });
158
167
  };
168
+ /** Whether the cache policy places inline markers, which then carry the requested lifetime. */
169
+ export const placesMarkers = (request) => {
170
+ const policy = selectPolicy(request);
171
+ return Boolean(policy.tools || policy.system || policy.messages);
172
+ };
159
173
  // A declared cache format overrides the route allowlist and its model-ID heuristics.
160
174
  const selectPolicy = (request) => {
161
175
  const format = request.model.compatibility?.cacheFormat;
162
176
  const route = request.model.route.id;
163
- const auto = request.cache === undefined || request.cache === "auto";
177
+ const auto = isAuto(request.cache);
164
178
  if (format === "alibaba")
165
179
  return auto ? QWEN : { ...resolve(request.cache), tools: false };
166
180
  if (format === "anthropic")
@@ -154,6 +154,10 @@ export declare const protocol: Protocol<{
154
154
  } | undefined;
155
155
  readonly store?: boolean | undefined;
156
156
  readonly prompt_cache_key?: string | undefined;
157
+ readonly prompt_cache_retention?: string | undefined;
158
+ readonly prompt_cache_options?: {
159
+ readonly ttl?: string | undefined;
160
+ } | undefined;
157
161
  readonly reasoning_effort?: OpenResponsesOptions.ReasoningEffort | undefined;
158
162
  readonly verbosity?: import("../schema/options.js").OpenString<"high" | "low" | "medium"> | undefined;
159
163
  readonly service_tier?: import("../schema/options.js").OpenString<"auto" | "default" | "flex" | "priority"> | undefined;
@@ -29,7 +29,7 @@ export declare const protocol: Protocol<{
29
29
  readonly text: string;
30
30
  readonly cache_control?: {
31
31
  readonly type: "ephemeral";
32
- readonly ttl?: "1h" | "5m" | undefined;
32
+ readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
33
33
  } | undefined;
34
34
  }[] | undefined;
35
35
  readonly messages: readonly ({
@@ -39,7 +39,7 @@ export declare const protocol: Protocol<{
39
39
  readonly text: string;
40
40
  readonly cache_control?: {
41
41
  readonly type: "ephemeral";
42
- readonly ttl?: "1h" | "5m" | undefined;
42
+ readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
43
43
  } | undefined;
44
44
  } | {
45
45
  readonly type: "image";
@@ -56,7 +56,7 @@ export declare const protocol: Protocol<{
56
56
  };
57
57
  readonly cache_control?: {
58
58
  readonly type: "ephemeral";
59
- readonly ttl?: "1h" | "5m" | undefined;
59
+ readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
60
60
  } | undefined;
61
61
  readonly transformations?: {
62
62
  readonly oversized_image?: "downsize" | "error" | undefined;
@@ -76,7 +76,7 @@ export declare const protocol: Protocol<{
76
76
  };
77
77
  readonly cache_control?: {
78
78
  readonly type: "ephemeral";
79
- readonly ttl?: "1h" | "5m" | undefined;
79
+ readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
80
80
  } | undefined;
81
81
  } | {
82
82
  readonly type: "document";
@@ -97,7 +97,7 @@ export declare const protocol: Protocol<{
97
97
  };
98
98
  readonly cache_control?: {
99
99
  readonly type: "ephemeral";
100
- readonly ttl?: "1h" | "5m" | undefined;
100
+ readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
101
101
  } | undefined;
102
102
  readonly title?: string | undefined;
103
103
  readonly context?: string | undefined;
@@ -112,7 +112,7 @@ export declare const protocol: Protocol<{
112
112
  readonly text: string;
113
113
  readonly cache_control?: {
114
114
  readonly type: "ephemeral";
115
- readonly ttl?: "1h" | "5m" | undefined;
115
+ readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
116
116
  } | undefined;
117
117
  } | {
118
118
  readonly type: "image";
@@ -129,7 +129,7 @@ export declare const protocol: Protocol<{
129
129
  };
130
130
  readonly cache_control?: {
131
131
  readonly type: "ephemeral";
132
- readonly ttl?: "1h" | "5m" | undefined;
132
+ readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
133
133
  } | undefined;
134
134
  readonly transformations?: {
135
135
  readonly oversized_image?: "downsize" | "error" | undefined;
@@ -149,7 +149,7 @@ export declare const protocol: Protocol<{
149
149
  };
150
150
  readonly cache_control?: {
151
151
  readonly type: "ephemeral";
152
- readonly ttl?: "1h" | "5m" | undefined;
152
+ readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
153
153
  } | undefined;
154
154
  } | {
155
155
  readonly type: "document";
@@ -170,7 +170,7 @@ export declare const protocol: Protocol<{
170
170
  };
171
171
  readonly cache_control?: {
172
172
  readonly type: "ephemeral";
173
- readonly ttl?: "1h" | "5m" | undefined;
173
+ readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
174
174
  } | undefined;
175
175
  readonly title?: string | undefined;
176
176
  readonly context?: string | undefined;
@@ -181,7 +181,7 @@ export declare const protocol: Protocol<{
181
181
  readonly is_error?: boolean | undefined;
182
182
  readonly cache_control?: {
183
183
  readonly type: "ephemeral";
184
- readonly ttl?: "1h" | "5m" | undefined;
184
+ readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
185
185
  } | undefined;
186
186
  })[];
187
187
  } | {
@@ -194,7 +194,7 @@ export declare const protocol: Protocol<{
194
194
  readonly text: string;
195
195
  readonly cache_control?: {
196
196
  readonly type: "ephemeral";
197
- readonly ttl?: "1h" | "5m" | undefined;
197
+ readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
198
198
  } | undefined;
199
199
  } | {
200
200
  readonly type: "thinking";
@@ -202,14 +202,14 @@ export declare const protocol: Protocol<{
202
202
  readonly signature: string;
203
203
  readonly cache_control?: {
204
204
  readonly type: "ephemeral";
205
- readonly ttl?: "1h" | "5m" | undefined;
205
+ readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
206
206
  } | undefined;
207
207
  } | {
208
208
  readonly type: "redacted_thinking";
209
209
  readonly data: string;
210
210
  readonly cache_control?: {
211
211
  readonly type: "ephemeral";
212
- readonly ttl?: "1h" | "5m" | undefined;
212
+ readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
213
213
  } | undefined;
214
214
  } | {
215
215
  readonly type: "tool_use";
@@ -218,7 +218,7 @@ export declare const protocol: Protocol<{
218
218
  readonly input: unknown;
219
219
  readonly cache_control?: {
220
220
  readonly type: "ephemeral";
221
- readonly ttl?: "1h" | "5m" | undefined;
221
+ readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
222
222
  } | undefined;
223
223
  } | {
224
224
  readonly type: "server_tool_use";
@@ -227,7 +227,7 @@ export declare const protocol: Protocol<{
227
227
  readonly input: unknown;
228
228
  readonly cache_control?: {
229
229
  readonly type: "ephemeral";
230
- readonly ttl?: "1h" | "5m" | undefined;
230
+ readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
231
231
  } | undefined;
232
232
  } | {
233
233
  readonly type: "code_execution_tool_result" | "web_fetch_tool_result" | "web_search_tool_result";
@@ -235,7 +235,7 @@ export declare const protocol: Protocol<{
235
235
  readonly content: unknown;
236
236
  readonly cache_control?: {
237
237
  readonly type: "ephemeral";
238
- readonly ttl?: "1h" | "5m" | undefined;
238
+ readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
239
239
  } | undefined;
240
240
  })[];
241
241
  } | {
@@ -245,7 +245,7 @@ export declare const protocol: Protocol<{
245
245
  readonly text: string;
246
246
  readonly cache_control?: {
247
247
  readonly type: "ephemeral";
248
- readonly ttl?: "1h" | "5m" | undefined;
248
+ readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
249
249
  } | undefined;
250
250
  }[];
251
251
  readonly output_config?: {
@@ -260,7 +260,7 @@ export declare const protocol: Protocol<{
260
260
  };
261
261
  readonly cache_control?: {
262
262
  readonly type: "ephemeral";
263
- readonly ttl?: "1h" | "5m" | undefined;
263
+ readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
264
264
  } | undefined;
265
265
  }[] | undefined;
266
266
  readonly tool_choice?: {
@@ -288,7 +288,7 @@ export declare const protocol: Protocol<{
288
288
  } | undefined;
289
289
  readonly cache_control?: {
290
290
  readonly type: "ephemeral";
291
- readonly ttl?: "1h" | "5m" | undefined;
291
+ readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
292
292
  } | undefined;
293
293
  readonly container?: string | {
294
294
  readonly id?: string | null | undefined;