transform.test.ts 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980
  1. import { describe, expect, test } from "bun:test"
  2. import { ProviderTransform } from "../../src/provider/transform"
  3. const OUTPUT_TOKEN_MAX = 32000
  4. describe("ProviderTransform.options - setCacheKey", () => {
  5. const sessionID = "test-session-123"
  6. const mockModel = {
  7. id: "anthropic/claude-3-5-sonnet",
  8. providerID: "anthropic",
  9. api: {
  10. id: "claude-3-5-sonnet-20241022",
  11. url: "https://api.anthropic.com",
  12. npm: "@ai-sdk/anthropic",
  13. },
  14. name: "Claude 3.5 Sonnet",
  15. capabilities: {
  16. temperature: true,
  17. reasoning: false,
  18. attachment: true,
  19. toolcall: true,
  20. input: { text: true, audio: false, image: true, video: false, pdf: true },
  21. output: { text: true, audio: false, image: false, video: false, pdf: false },
  22. interleaved: false,
  23. },
  24. cost: {
  25. input: 0.003,
  26. output: 0.015,
  27. cache: { read: 0.0003, write: 0.00375 },
  28. },
  29. limit: {
  30. context: 200000,
  31. output: 8192,
  32. },
  33. status: "active",
  34. options: {},
  35. headers: {},
  36. } as any
  37. test("should set promptCacheKey when providerOptions.setCacheKey is true", () => {
  38. const result = ProviderTransform.options(mockModel, sessionID, { setCacheKey: true })
  39. expect(result.promptCacheKey).toBe(sessionID)
  40. })
  41. test("should not set promptCacheKey when providerOptions.setCacheKey is false", () => {
  42. const result = ProviderTransform.options(mockModel, sessionID, { setCacheKey: false })
  43. expect(result.promptCacheKey).toBeUndefined()
  44. })
  45. test("should not set promptCacheKey when providerOptions is undefined", () => {
  46. const result = ProviderTransform.options(mockModel, sessionID, undefined)
  47. expect(result.promptCacheKey).toBeUndefined()
  48. })
  49. test("should not set promptCacheKey when providerOptions does not have setCacheKey", () => {
  50. const result = ProviderTransform.options(mockModel, sessionID, {})
  51. expect(result.promptCacheKey).toBeUndefined()
  52. })
  53. test("should set promptCacheKey for openai provider regardless of setCacheKey", () => {
  54. const openaiModel = {
  55. ...mockModel,
  56. providerID: "openai",
  57. api: {
  58. id: "gpt-4",
  59. url: "https://api.openai.com",
  60. npm: "@ai-sdk/openai",
  61. },
  62. }
  63. const result = ProviderTransform.options(openaiModel, sessionID, {})
  64. expect(result.promptCacheKey).toBe(sessionID)
  65. })
  66. })
  67. describe("ProviderTransform.maxOutputTokens", () => {
  68. test("returns 32k when modelLimit > 32k", () => {
  69. const modelLimit = 100000
  70. const result = ProviderTransform.maxOutputTokens("@ai-sdk/openai", {}, modelLimit, OUTPUT_TOKEN_MAX)
  71. expect(result).toBe(OUTPUT_TOKEN_MAX)
  72. })
  73. test("returns modelLimit when modelLimit < 32k", () => {
  74. const modelLimit = 16000
  75. const result = ProviderTransform.maxOutputTokens("@ai-sdk/openai", {}, modelLimit, OUTPUT_TOKEN_MAX)
  76. expect(result).toBe(16000)
  77. })
  78. describe("azure", () => {
  79. test("returns 32k when modelLimit > 32k", () => {
  80. const modelLimit = 100000
  81. const result = ProviderTransform.maxOutputTokens("@ai-sdk/azure", {}, modelLimit, OUTPUT_TOKEN_MAX)
  82. expect(result).toBe(OUTPUT_TOKEN_MAX)
  83. })
  84. test("returns modelLimit when modelLimit < 32k", () => {
  85. const modelLimit = 16000
  86. const result = ProviderTransform.maxOutputTokens("@ai-sdk/azure", {}, modelLimit, OUTPUT_TOKEN_MAX)
  87. expect(result).toBe(16000)
  88. })
  89. })
  90. describe("bedrock", () => {
  91. test("returns 32k when modelLimit > 32k", () => {
  92. const modelLimit = 100000
  93. const result = ProviderTransform.maxOutputTokens("@ai-sdk/amazon-bedrock", {}, modelLimit, OUTPUT_TOKEN_MAX)
  94. expect(result).toBe(OUTPUT_TOKEN_MAX)
  95. })
  96. test("returns modelLimit when modelLimit < 32k", () => {
  97. const modelLimit = 16000
  98. const result = ProviderTransform.maxOutputTokens("@ai-sdk/amazon-bedrock", {}, modelLimit, OUTPUT_TOKEN_MAX)
  99. expect(result).toBe(16000)
  100. })
  101. })
  102. describe("anthropic without thinking options", () => {
  103. test("returns 32k when modelLimit > 32k", () => {
  104. const modelLimit = 100000
  105. const result = ProviderTransform.maxOutputTokens("@ai-sdk/anthropic", {}, modelLimit, OUTPUT_TOKEN_MAX)
  106. expect(result).toBe(OUTPUT_TOKEN_MAX)
  107. })
  108. test("returns modelLimit when modelLimit < 32k", () => {
  109. const modelLimit = 16000
  110. const result = ProviderTransform.maxOutputTokens("@ai-sdk/anthropic", {}, modelLimit, OUTPUT_TOKEN_MAX)
  111. expect(result).toBe(16000)
  112. })
  113. })
  114. describe("anthropic with thinking options", () => {
  115. test("returns 32k when budgetTokens + 32k <= modelLimit", () => {
  116. const modelLimit = 100000
  117. const options = {
  118. thinking: {
  119. type: "enabled",
  120. budgetTokens: 10000,
  121. },
  122. }
  123. const result = ProviderTransform.maxOutputTokens("@ai-sdk/anthropic", options, modelLimit, OUTPUT_TOKEN_MAX)
  124. expect(result).toBe(OUTPUT_TOKEN_MAX)
  125. })
  126. test("returns modelLimit - budgetTokens when budgetTokens + 32k > modelLimit", () => {
  127. const modelLimit = 50000
  128. const options = {
  129. thinking: {
  130. type: "enabled",
  131. budgetTokens: 30000,
  132. },
  133. }
  134. const result = ProviderTransform.maxOutputTokens("@ai-sdk/anthropic", options, modelLimit, OUTPUT_TOKEN_MAX)
  135. expect(result).toBe(20000)
  136. })
  137. test("returns 32k when thinking type is not enabled", () => {
  138. const modelLimit = 100000
  139. const options = {
  140. thinking: {
  141. type: "disabled",
  142. budgetTokens: 10000,
  143. },
  144. }
  145. const result = ProviderTransform.maxOutputTokens("@ai-sdk/anthropic", options, modelLimit, OUTPUT_TOKEN_MAX)
  146. expect(result).toBe(OUTPUT_TOKEN_MAX)
  147. })
  148. })
  149. })
  150. describe("ProviderTransform.schema - gemini array items", () => {
  151. test("adds missing items for array properties", () => {
  152. const geminiModel = {
  153. providerID: "google",
  154. api: {
  155. id: "gemini-3-pro",
  156. },
  157. } as any
  158. const schema = {
  159. type: "object",
  160. properties: {
  161. nodes: { type: "array" },
  162. edges: { type: "array", items: { type: "string" } },
  163. },
  164. } as any
  165. const result = ProviderTransform.schema(geminiModel, schema) as any
  166. expect(result.properties.nodes.items).toBeDefined()
  167. expect(result.properties.edges.items.type).toBe("string")
  168. })
  169. })
  170. describe("ProviderTransform.message - DeepSeek reasoning content", () => {
  171. test("DeepSeek with tool calls includes reasoning_content in providerOptions", () => {
  172. const msgs = [
  173. {
  174. role: "assistant",
  175. content: [
  176. { type: "reasoning", text: "Let me think about this..." },
  177. {
  178. type: "tool-call",
  179. toolCallId: "test",
  180. toolName: "bash",
  181. input: { command: "echo hello" },
  182. },
  183. ],
  184. },
  185. ] as any[]
  186. const result = ProviderTransform.message(msgs, {
  187. id: "deepseek/deepseek-chat",
  188. providerID: "deepseek",
  189. api: {
  190. id: "deepseek-chat",
  191. url: "https://api.deepseek.com",
  192. npm: "@ai-sdk/openai-compatible",
  193. },
  194. name: "DeepSeek Chat",
  195. capabilities: {
  196. temperature: true,
  197. reasoning: true,
  198. attachment: false,
  199. toolcall: true,
  200. input: { text: true, audio: false, image: false, video: false, pdf: false },
  201. output: { text: true, audio: false, image: false, video: false, pdf: false },
  202. interleaved: {
  203. field: "reasoning_content",
  204. },
  205. },
  206. cost: {
  207. input: 0.001,
  208. output: 0.002,
  209. cache: { read: 0.0001, write: 0.0002 },
  210. },
  211. limit: {
  212. context: 128000,
  213. output: 8192,
  214. },
  215. status: "active",
  216. options: {},
  217. headers: {},
  218. release_date: "2023-04-01",
  219. })
  220. expect(result).toHaveLength(1)
  221. expect(result[0].content).toEqual([
  222. {
  223. type: "tool-call",
  224. toolCallId: "test",
  225. toolName: "bash",
  226. input: { command: "echo hello" },
  227. },
  228. ])
  229. expect(result[0].providerOptions?.openaiCompatible?.reasoning_content).toBe("Let me think about this...")
  230. })
  231. test("Non-DeepSeek providers leave reasoning content unchanged", () => {
  232. const msgs = [
  233. {
  234. role: "assistant",
  235. content: [
  236. { type: "reasoning", text: "Should not be processed" },
  237. { type: "text", text: "Answer" },
  238. ],
  239. },
  240. ] as any[]
  241. const result = ProviderTransform.message(msgs, {
  242. id: "openai/gpt-4",
  243. providerID: "openai",
  244. api: {
  245. id: "gpt-4",
  246. url: "https://api.openai.com",
  247. npm: "@ai-sdk/openai",
  248. },
  249. name: "GPT-4",
  250. capabilities: {
  251. temperature: true,
  252. reasoning: false,
  253. attachment: true,
  254. toolcall: true,
  255. input: { text: true, audio: false, image: true, video: false, pdf: false },
  256. output: { text: true, audio: false, image: false, video: false, pdf: false },
  257. interleaved: false,
  258. },
  259. cost: {
  260. input: 0.03,
  261. output: 0.06,
  262. cache: { read: 0.001, write: 0.002 },
  263. },
  264. limit: {
  265. context: 128000,
  266. output: 4096,
  267. },
  268. status: "active",
  269. options: {},
  270. headers: {},
  271. release_date: "2023-04-01",
  272. })
  273. expect(result[0].content).toEqual([
  274. { type: "reasoning", text: "Should not be processed" },
  275. { type: "text", text: "Answer" },
  276. ])
  277. expect(result[0].providerOptions?.openaiCompatible?.reasoning_content).toBeUndefined()
  278. })
  279. })
  280. describe("ProviderTransform.message - empty image handling", () => {
  281. const mockModel = {
  282. id: "anthropic/claude-3-5-sonnet",
  283. providerID: "anthropic",
  284. api: {
  285. id: "claude-3-5-sonnet-20241022",
  286. url: "https://api.anthropic.com",
  287. npm: "@ai-sdk/anthropic",
  288. },
  289. name: "Claude 3.5 Sonnet",
  290. capabilities: {
  291. temperature: true,
  292. reasoning: false,
  293. attachment: true,
  294. toolcall: true,
  295. input: { text: true, audio: false, image: true, video: false, pdf: true },
  296. output: { text: true, audio: false, image: false, video: false, pdf: false },
  297. interleaved: false,
  298. },
  299. cost: {
  300. input: 0.003,
  301. output: 0.015,
  302. cache: { read: 0.0003, write: 0.00375 },
  303. },
  304. limit: {
  305. context: 200000,
  306. output: 8192,
  307. },
  308. status: "active",
  309. options: {},
  310. headers: {},
  311. } as any
  312. test("should replace empty base64 image with error text", () => {
  313. const msgs = [
  314. {
  315. role: "user",
  316. content: [
  317. { type: "text", text: "What is in this image?" },
  318. { type: "image", image: "data:image/png;base64," },
  319. ],
  320. },
  321. ] as any[]
  322. const result = ProviderTransform.message(msgs, mockModel)
  323. expect(result).toHaveLength(1)
  324. expect(result[0].content).toHaveLength(2)
  325. expect(result[0].content[0]).toEqual({ type: "text", text: "What is in this image?" })
  326. expect(result[0].content[1]).toEqual({
  327. type: "text",
  328. text: "ERROR: Image file is empty or corrupted. Please provide a valid image.",
  329. })
  330. })
  331. test("should keep valid base64 images unchanged", () => {
  332. const validBase64 =
  333. "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg=="
  334. const msgs = [
  335. {
  336. role: "user",
  337. content: [
  338. { type: "text", text: "What is in this image?" },
  339. { type: "image", image: `data:image/png;base64,${validBase64}` },
  340. ],
  341. },
  342. ] as any[]
  343. const result = ProviderTransform.message(msgs, mockModel)
  344. expect(result).toHaveLength(1)
  345. expect(result[0].content).toHaveLength(2)
  346. expect(result[0].content[0]).toEqual({ type: "text", text: "What is in this image?" })
  347. expect(result[0].content[1]).toEqual({ type: "image", image: `data:image/png;base64,${validBase64}` })
  348. })
  349. test("should handle mixed valid and empty images", () => {
  350. const validBase64 =
  351. "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg=="
  352. const msgs = [
  353. {
  354. role: "user",
  355. content: [
  356. { type: "text", text: "Compare these images" },
  357. { type: "image", image: `data:image/png;base64,${validBase64}` },
  358. { type: "image", image: "data:image/jpeg;base64," },
  359. ],
  360. },
  361. ] as any[]
  362. const result = ProviderTransform.message(msgs, mockModel)
  363. expect(result).toHaveLength(1)
  364. expect(result[0].content).toHaveLength(3)
  365. expect(result[0].content[0]).toEqual({ type: "text", text: "Compare these images" })
  366. expect(result[0].content[1]).toEqual({ type: "image", image: `data:image/png;base64,${validBase64}` })
  367. expect(result[0].content[2]).toEqual({
  368. type: "text",
  369. text: "ERROR: Image file is empty or corrupted. Please provide a valid image.",
  370. })
  371. })
  372. })
  373. describe("ProviderTransform.variants", () => {
  374. const createMockModel = (overrides: Partial<any> = {}): any => ({
  375. id: "test/test-model",
  376. providerID: "test",
  377. api: {
  378. id: "test-model",
  379. url: "https://api.test.com",
  380. npm: "@ai-sdk/openai",
  381. },
  382. name: "Test Model",
  383. capabilities: {
  384. temperature: true,
  385. reasoning: true,
  386. attachment: true,
  387. toolcall: true,
  388. input: { text: true, audio: false, image: true, video: false, pdf: false },
  389. output: { text: true, audio: false, image: false, video: false, pdf: false },
  390. interleaved: false,
  391. },
  392. cost: {
  393. input: 0.001,
  394. output: 0.002,
  395. cache: { read: 0.0001, write: 0.0002 },
  396. },
  397. limit: {
  398. context: 128000,
  399. output: 8192,
  400. },
  401. status: "active",
  402. options: {},
  403. headers: {},
  404. release_date: "2024-01-01",
  405. ...overrides,
  406. })
  407. test("returns empty object when model has no reasoning capabilities", () => {
  408. const model = createMockModel({
  409. capabilities: { reasoning: false },
  410. })
  411. const result = ProviderTransform.variants(model)
  412. expect(result).toEqual({})
  413. })
  414. test("deepseek returns empty object", () => {
  415. const model = createMockModel({
  416. id: "deepseek/deepseek-chat",
  417. providerID: "deepseek",
  418. api: {
  419. id: "deepseek-chat",
  420. url: "https://api.deepseek.com",
  421. npm: "@ai-sdk/openai-compatible",
  422. },
  423. })
  424. const result = ProviderTransform.variants(model)
  425. expect(result).toEqual({})
  426. })
  427. test("minimax returns empty object", () => {
  428. const model = createMockModel({
  429. id: "minimax/minimax-model",
  430. providerID: "minimax",
  431. api: {
  432. id: "minimax-model",
  433. url: "https://api.minimax.com",
  434. npm: "@ai-sdk/openai-compatible",
  435. },
  436. })
  437. const result = ProviderTransform.variants(model)
  438. expect(result).toEqual({})
  439. })
  440. test("glm returns empty object", () => {
  441. const model = createMockModel({
  442. id: "glm/glm-4",
  443. providerID: "glm",
  444. api: {
  445. id: "glm-4",
  446. url: "https://api.glm.com",
  447. npm: "@ai-sdk/openai-compatible",
  448. },
  449. })
  450. const result = ProviderTransform.variants(model)
  451. expect(result).toEqual({})
  452. })
  453. test("mistral returns empty object", () => {
  454. const model = createMockModel({
  455. id: "mistral/mistral-large",
  456. providerID: "mistral",
  457. api: {
  458. id: "mistral-large-latest",
  459. url: "https://api.mistral.com",
  460. npm: "@ai-sdk/mistral",
  461. },
  462. })
  463. const result = ProviderTransform.variants(model)
  464. expect(result).toEqual({})
  465. })
  466. describe("@openrouter/ai-sdk-provider", () => {
  467. test("returns empty object for non-qualifying models", () => {
  468. const model = createMockModel({
  469. id: "openrouter/test-model",
  470. providerID: "openrouter",
  471. api: {
  472. id: "test-model",
  473. url: "https://openrouter.ai",
  474. npm: "@openrouter/ai-sdk-provider",
  475. },
  476. })
  477. const result = ProviderTransform.variants(model)
  478. expect(result).toEqual({})
  479. })
  480. test("gpt models return OPENAI_EFFORTS with reasoning", () => {
  481. const model = createMockModel({
  482. id: "openrouter/gpt-4",
  483. providerID: "openrouter",
  484. api: {
  485. id: "gpt-4",
  486. url: "https://openrouter.ai",
  487. npm: "@openrouter/ai-sdk-provider",
  488. },
  489. })
  490. const result = ProviderTransform.variants(model)
  491. expect(Object.keys(result)).toEqual(["none", "minimal", "low", "medium", "high", "xhigh"])
  492. expect(result.low).toEqual({ reasoning: { effort: "low" } })
  493. expect(result.high).toEqual({ reasoning: { effort: "high" } })
  494. })
  495. test("gemini-3 returns OPENAI_EFFORTS with reasoning", () => {
  496. const model = createMockModel({
  497. id: "openrouter/gemini-3-5-pro",
  498. providerID: "openrouter",
  499. api: {
  500. id: "gemini-3-5-pro",
  501. url: "https://openrouter.ai",
  502. npm: "@openrouter/ai-sdk-provider",
  503. },
  504. })
  505. const result = ProviderTransform.variants(model)
  506. expect(Object.keys(result)).toEqual(["none", "minimal", "low", "medium", "high", "xhigh"])
  507. })
  508. test("grok-4 returns OPENAI_EFFORTS with reasoning", () => {
  509. const model = createMockModel({
  510. id: "openrouter/grok-4",
  511. providerID: "openrouter",
  512. api: {
  513. id: "grok-4",
  514. url: "https://openrouter.ai",
  515. npm: "@openrouter/ai-sdk-provider",
  516. },
  517. })
  518. const result = ProviderTransform.variants(model)
  519. expect(Object.keys(result)).toEqual(["none", "minimal", "low", "medium", "high", "xhigh"])
  520. })
  521. })
  522. describe("@ai-sdk/gateway", () => {
  523. test("returns OPENAI_EFFORTS with reasoningEffort", () => {
  524. const model = createMockModel({
  525. id: "gateway/gateway-model",
  526. providerID: "gateway",
  527. api: {
  528. id: "gateway-model",
  529. url: "https://gateway.ai",
  530. npm: "@ai-sdk/gateway",
  531. },
  532. })
  533. const result = ProviderTransform.variants(model)
  534. expect(Object.keys(result)).toEqual(["none", "minimal", "low", "medium", "high", "xhigh"])
  535. expect(result.low).toEqual({ reasoningEffort: "low" })
  536. expect(result.high).toEqual({ reasoningEffort: "high" })
  537. })
  538. })
  539. describe("@ai-sdk/cerebras", () => {
  540. test("returns WIDELY_SUPPORTED_EFFORTS with reasoningEffort", () => {
  541. const model = createMockModel({
  542. id: "cerebras/llama-4",
  543. providerID: "cerebras",
  544. api: {
  545. id: "llama-4-sc",
  546. url: "https://api.cerebras.ai",
  547. npm: "@ai-sdk/cerebras",
  548. },
  549. })
  550. const result = ProviderTransform.variants(model)
  551. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  552. expect(result.low).toEqual({ reasoningEffort: "low" })
  553. expect(result.high).toEqual({ reasoningEffort: "high" })
  554. })
  555. })
  556. describe("@ai-sdk/togetherai", () => {
  557. test("returns WIDELY_SUPPORTED_EFFORTS with reasoningEffort", () => {
  558. const model = createMockModel({
  559. id: "togetherai/llama-4",
  560. providerID: "togetherai",
  561. api: {
  562. id: "llama-4-sc",
  563. url: "https://api.togetherai.com",
  564. npm: "@ai-sdk/togetherai",
  565. },
  566. })
  567. const result = ProviderTransform.variants(model)
  568. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  569. expect(result.low).toEqual({ reasoningEffort: "low" })
  570. expect(result.high).toEqual({ reasoningEffort: "high" })
  571. })
  572. })
  573. describe("@ai-sdk/xai", () => {
  574. test("returns WIDELY_SUPPORTED_EFFORTS with reasoningEffort", () => {
  575. const model = createMockModel({
  576. id: "xai/grok-3",
  577. providerID: "xai",
  578. api: {
  579. id: "grok-3",
  580. url: "https://api.x.ai",
  581. npm: "@ai-sdk/xai",
  582. },
  583. })
  584. const result = ProviderTransform.variants(model)
  585. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  586. expect(result.low).toEqual({ reasoningEffort: "low" })
  587. expect(result.high).toEqual({ reasoningEffort: "high" })
  588. })
  589. })
  590. describe("@ai-sdk/deepinfra", () => {
  591. test("returns WIDELY_SUPPORTED_EFFORTS with reasoningEffort", () => {
  592. const model = createMockModel({
  593. id: "deepinfra/llama-4",
  594. providerID: "deepinfra",
  595. api: {
  596. id: "llama-4-sc",
  597. url: "https://api.deepinfra.com",
  598. npm: "@ai-sdk/deepinfra",
  599. },
  600. })
  601. const result = ProviderTransform.variants(model)
  602. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  603. expect(result.low).toEqual({ reasoningEffort: "low" })
  604. expect(result.high).toEqual({ reasoningEffort: "high" })
  605. })
  606. })
  607. describe("@ai-sdk/openai-compatible", () => {
  608. test("returns WIDELY_SUPPORTED_EFFORTS with reasoningEffort", () => {
  609. const model = createMockModel({
  610. id: "custom-provider/custom-model",
  611. providerID: "custom-provider",
  612. api: {
  613. id: "custom-model",
  614. url: "https://api.custom.com",
  615. npm: "@ai-sdk/openai-compatible",
  616. },
  617. })
  618. const result = ProviderTransform.variants(model)
  619. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  620. expect(result.low).toEqual({ reasoningEffort: "low" })
  621. expect(result.high).toEqual({ reasoningEffort: "high" })
  622. })
  623. })
  624. describe("@ai-sdk/azure", () => {
  625. test("o1-mini returns empty object", () => {
  626. const model = createMockModel({
  627. id: "o1-mini",
  628. providerID: "azure",
  629. api: {
  630. id: "o1-mini",
  631. url: "https://azure.com",
  632. npm: "@ai-sdk/azure",
  633. },
  634. })
  635. const result = ProviderTransform.variants(model)
  636. expect(result).toEqual({})
  637. })
  638. test("standard azure models return custom efforts with reasoningSummary", () => {
  639. const model = createMockModel({
  640. id: "o1",
  641. providerID: "azure",
  642. api: {
  643. id: "o1",
  644. url: "https://azure.com",
  645. npm: "@ai-sdk/azure",
  646. },
  647. })
  648. const result = ProviderTransform.variants(model)
  649. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  650. expect(result.low).toEqual({
  651. reasoningEffort: "low",
  652. reasoningSummary: "auto",
  653. include: ["reasoning.encrypted_content"],
  654. })
  655. })
  656. test("gpt-5 adds minimal effort", () => {
  657. const model = createMockModel({
  658. id: "gpt-5",
  659. providerID: "azure",
  660. api: {
  661. id: "gpt-5",
  662. url: "https://azure.com",
  663. npm: "@ai-sdk/azure",
  664. },
  665. })
  666. const result = ProviderTransform.variants(model)
  667. expect(Object.keys(result)).toEqual(["minimal", "low", "medium", "high"])
  668. })
  669. })
  670. describe("@ai-sdk/openai", () => {
  671. test("gpt-5-pro returns empty object", () => {
  672. const model = createMockModel({
  673. id: "gpt-5-pro",
  674. providerID: "openai",
  675. api: {
  676. id: "gpt-5-pro",
  677. url: "https://api.openai.com",
  678. npm: "@ai-sdk/openai",
  679. },
  680. })
  681. const result = ProviderTransform.variants(model)
  682. expect(result).toEqual({})
  683. })
  684. test("standard openai models return custom efforts with reasoningSummary", () => {
  685. const model = createMockModel({
  686. id: "gpt-5",
  687. providerID: "openai",
  688. api: {
  689. id: "gpt-5",
  690. url: "https://api.openai.com",
  691. npm: "@ai-sdk/openai",
  692. },
  693. release_date: "2024-06-01",
  694. })
  695. const result = ProviderTransform.variants(model)
  696. expect(Object.keys(result)).toEqual(["minimal", "low", "medium", "high"])
  697. expect(result.low).toEqual({
  698. reasoningEffort: "low",
  699. reasoningSummary: "auto",
  700. include: ["reasoning.encrypted_content"],
  701. })
  702. })
  703. test("models after 2025-11-13 include 'none' effort", () => {
  704. const model = createMockModel({
  705. id: "gpt-5-nano",
  706. providerID: "openai",
  707. api: {
  708. id: "gpt-5-nano",
  709. url: "https://api.openai.com",
  710. npm: "@ai-sdk/openai",
  711. },
  712. release_date: "2025-11-14",
  713. })
  714. const result = ProviderTransform.variants(model)
  715. expect(Object.keys(result)).toEqual(["none", "minimal", "low", "medium", "high"])
  716. })
  717. test("models after 2025-12-04 include 'xhigh' effort", () => {
  718. const model = createMockModel({
  719. id: "openai/gpt-5-chat",
  720. providerID: "openai",
  721. api: {
  722. id: "gpt-5-chat",
  723. url: "https://api.openai.com",
  724. npm: "@ai-sdk/openai",
  725. },
  726. release_date: "2025-12-05",
  727. })
  728. const result = ProviderTransform.variants(model)
  729. expect(Object.keys(result)).toEqual(["none", "minimal", "low", "medium", "high", "xhigh"])
  730. })
  731. })
  732. describe("@ai-sdk/anthropic", () => {
  733. test("returns high and max with thinking config", () => {
  734. const model = createMockModel({
  735. id: "anthropic/claude-4",
  736. providerID: "anthropic",
  737. api: {
  738. id: "claude-4",
  739. url: "https://api.anthropic.com",
  740. npm: "@ai-sdk/anthropic",
  741. },
  742. })
  743. const result = ProviderTransform.variants(model)
  744. expect(Object.keys(result)).toEqual(["high", "max"])
  745. expect(result.high).toEqual({
  746. thinking: {
  747. type: "enabled",
  748. budgetTokens: 16000,
  749. },
  750. })
  751. expect(result.max).toEqual({
  752. thinking: {
  753. type: "enabled",
  754. budgetTokens: 31999,
  755. },
  756. })
  757. })
  758. })
  759. describe("@ai-sdk/amazon-bedrock", () => {
  760. test("returns WIDELY_SUPPORTED_EFFORTS with reasoningConfig", () => {
  761. const model = createMockModel({
  762. id: "bedrock/llama-4",
  763. providerID: "bedrock",
  764. api: {
  765. id: "llama-4-sc",
  766. url: "https://bedrock.amazonaws.com",
  767. npm: "@ai-sdk/amazon-bedrock",
  768. },
  769. })
  770. const result = ProviderTransform.variants(model)
  771. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  772. expect(result.low).toEqual({
  773. reasoningConfig: {
  774. type: "enabled",
  775. maxReasoningEffort: "low",
  776. },
  777. })
  778. })
  779. })
  780. describe("@ai-sdk/google", () => {
  781. test("gemini-2.5 returns high and max with thinkingConfig and thinkingBudget", () => {
  782. const model = createMockModel({
  783. id: "google/gemini-2.5-pro",
  784. providerID: "google",
  785. api: {
  786. id: "gemini-2.5-pro",
  787. url: "https://generativelanguage.googleapis.com",
  788. npm: "@ai-sdk/google",
  789. },
  790. })
  791. const result = ProviderTransform.variants(model)
  792. expect(Object.keys(result)).toEqual(["high", "max"])
  793. expect(result.high).toEqual({
  794. thinkingConfig: {
  795. includeThoughts: true,
  796. thinkingBudget: 16000,
  797. },
  798. })
  799. expect(result.max).toEqual({
  800. thinkingConfig: {
  801. includeThoughts: true,
  802. thinkingBudget: 24576,
  803. },
  804. })
  805. })
  806. test("other gemini models return low and high with thinkingLevel", () => {
  807. const model = createMockModel({
  808. id: "google/gemini-2.0-pro",
  809. providerID: "google",
  810. api: {
  811. id: "gemini-2.0-pro",
  812. url: "https://generativelanguage.googleapis.com",
  813. npm: "@ai-sdk/google",
  814. },
  815. })
  816. const result = ProviderTransform.variants(model)
  817. expect(Object.keys(result)).toEqual(["low", "high"])
  818. expect(result.low).toEqual({
  819. includeThoughts: true,
  820. thinkingLevel: "low",
  821. })
  822. expect(result.high).toEqual({
  823. includeThoughts: true,
  824. thinkingLevel: "high",
  825. })
  826. })
  827. })
  828. describe("@ai-sdk/google-vertex", () => {
  829. test("gemini-2.5 returns high and max with thinkingConfig and thinkingBudget", () => {
  830. const model = createMockModel({
  831. id: "google-vertex/gemini-2.5-pro",
  832. providerID: "google-vertex",
  833. api: {
  834. id: "gemini-2.5-pro",
  835. url: "https://vertexai.googleapis.com",
  836. npm: "@ai-sdk/google-vertex",
  837. },
  838. })
  839. const result = ProviderTransform.variants(model)
  840. expect(Object.keys(result)).toEqual(["high", "max"])
  841. })
  842. test("other vertex models return low and high with thinkingLevel", () => {
  843. const model = createMockModel({
  844. id: "google-vertex/gemini-2.0-pro",
  845. providerID: "google-vertex",
  846. api: {
  847. id: "gemini-2.0-pro",
  848. url: "https://vertexai.googleapis.com",
  849. npm: "@ai-sdk/google-vertex",
  850. },
  851. })
  852. const result = ProviderTransform.variants(model)
  853. expect(Object.keys(result)).toEqual(["low", "high"])
  854. })
  855. })
  856. describe("@ai-sdk/cohere", () => {
  857. test("returns empty object", () => {
  858. const model = createMockModel({
  859. id: "cohere/command-r",
  860. providerID: "cohere",
  861. api: {
  862. id: "command-r",
  863. url: "https://api.cohere.com",
  864. npm: "@ai-sdk/cohere",
  865. },
  866. })
  867. const result = ProviderTransform.variants(model)
  868. expect(result).toEqual({})
  869. })
  870. })
  871. describe("@ai-sdk/groq", () => {
  872. test("returns none and WIDELY_SUPPORTED_EFFORTS with thinkingLevel", () => {
  873. const model = createMockModel({
  874. id: "groq/llama-4",
  875. providerID: "groq",
  876. api: {
  877. id: "llama-4-sc",
  878. url: "https://api.groq.com",
  879. npm: "@ai-sdk/groq",
  880. },
  881. })
  882. const result = ProviderTransform.variants(model)
  883. expect(Object.keys(result)).toEqual(["none", "low", "medium", "high"])
  884. expect(result.none).toEqual({
  885. includeThoughts: true,
  886. thinkingLevel: "none",
  887. })
  888. expect(result.low).toEqual({
  889. includeThoughts: true,
  890. thinkingLevel: "low",
  891. })
  892. })
  893. })
  894. describe("@ai-sdk/perplexity", () => {
  895. test("returns empty object", () => {
  896. const model = createMockModel({
  897. id: "perplexity/sonar-plus",
  898. providerID: "perplexity",
  899. api: {
  900. id: "sonar-plus",
  901. url: "https://api.perplexity.ai",
  902. npm: "@ai-sdk/perplexity",
  903. },
  904. })
  905. const result = ProviderTransform.variants(model)
  906. expect(result).toEqual({})
  907. })
  908. })
  909. })