@prestyj/ai 4.14.0 → 5.0.1

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/dist/index.js CHANGED
@@ -1094,7 +1094,13 @@ async function prewarmAnthropicCache(options) {
1094
1094
  },
1095
1095
  {
1096
1096
  signal: options.signal ?? void 0,
1097
- ...isOAuth ? { headers: { "anthropic-beta": "claude-code-20250219,oauth-2025-04-20" } } : {}
1097
+ ...(() => {
1098
+ const betas = [
1099
+ ...isOAuth ? ["claude-code-20250219", "oauth-2025-04-20"] : [],
1100
+ ...cacheControl?.ttl === "1h" ? ["extended-cache-ttl-2025-04-11"] : []
1101
+ ];
1102
+ return betas.length ? { headers: { "anthropic-beta": betas.join(",") } } : {};
1103
+ })()
1098
1104
  }
1099
1105
  );
1100
1106
  } catch {
@@ -1178,7 +1184,12 @@ async function* runStream(options) {
1178
1184
  ...options.compaction ? ["compact-2026-01-12"] : [],
1179
1185
  ...options.clearToolUses ? ["context-management-2025-06-27"] : [],
1180
1186
  "fine-grained-tool-streaming-2025-05-14",
1181
- ...!hasAdaptiveThinking ? ["interleaved-thinking-2025-05-14"] : []
1187
+ ...!hasAdaptiveThinking ? ["interleaved-thinking-2025-05-14"] : [],
1188
+ // The 1-h cache TTL (cacheRetention "long") is gated behind this beta. Without
1189
+ // it Anthropic silently ignores ttl:"1h" and falls back to the 5-min default,
1190
+ // so a pre-warmed cache expires before the user's first turn. cacheControl.ttl
1191
+ // is only "1h" on the first-party endpoint (see toAnthropicCacheControl).
1192
+ ...cacheControl?.ttl === "1h" ? ["extended-cache-ttl-2025-04-11"] : []
1182
1193
  ];
1183
1194
  const requestOptions = {
1184
1195
  signal: options.signal ?? void 0,
@@ -3092,11 +3103,17 @@ providerRegistry.register("anthropic", {
3092
3103
  stream: (options) => streamAnthropic(options)
3093
3104
  });
3094
3105
  providerRegistry.register("xiaomi", {
3095
- stream: (options) => streamOpenAI({
3096
- ...options,
3097
- baseUrl: options.baseUrl ?? "https://token-plan-sgp.xiaomimimo.com/v1",
3098
- webSearch: false
3099
- })
3106
+ stream: (options) => {
3107
+ const TOKEN_PLAN_URL = "https://token-plan-sgp.xiaomimimo.com/v1";
3108
+ const PLATFORM_URL = "https://api.xiaomimimo.com/v1";
3109
+ let baseUrl;
3110
+ if (options.model === "mimo-v2.5-pro-ultraspeed") {
3111
+ baseUrl = options.baseUrl && options.baseUrl !== TOKEN_PLAN_URL ? options.baseUrl : PLATFORM_URL;
3112
+ } else {
3113
+ baseUrl = options.baseUrl ?? TOKEN_PLAN_URL;
3114
+ }
3115
+ return streamOpenAI({ ...options, baseUrl, webSearch: false });
3116
+ }
3100
3117
  });
3101
3118
  providerRegistry.register("openai", {
3102
3119
  stream: (options) => {