transform.test.ts 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484
  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({
  39. model: mockModel,
  40. sessionID,
  41. providerOptions: { setCacheKey: true },
  42. })
  43. expect(result.promptCacheKey).toBe(sessionID)
  44. })
  45. test("should not set promptCacheKey when providerOptions.setCacheKey is false", () => {
  46. const result = ProviderTransform.options({
  47. model: mockModel,
  48. sessionID,
  49. providerOptions: { setCacheKey: false },
  50. })
  51. expect(result.promptCacheKey).toBeUndefined()
  52. })
  53. test("should not set promptCacheKey when providerOptions is undefined", () => {
  54. const result = ProviderTransform.options({
  55. model: mockModel,
  56. sessionID,
  57. providerOptions: undefined,
  58. })
  59. expect(result.promptCacheKey).toBeUndefined()
  60. })
  61. test("should not set promptCacheKey when providerOptions does not have setCacheKey", () => {
  62. const result = ProviderTransform.options({ model: mockModel, sessionID, providerOptions: {} })
  63. expect(result.promptCacheKey).toBeUndefined()
  64. })
  65. test("should set promptCacheKey for openai provider regardless of setCacheKey", () => {
  66. const openaiModel = {
  67. ...mockModel,
  68. providerID: "openai",
  69. api: {
  70. id: "gpt-4",
  71. url: "https://api.openai.com",
  72. npm: "@ai-sdk/openai",
  73. },
  74. }
  75. const result = ProviderTransform.options({ model: openaiModel, sessionID, providerOptions: {} })
  76. expect(result.promptCacheKey).toBe(sessionID)
  77. })
  78. test("should set store=false for openai provider", () => {
  79. const openaiModel = {
  80. ...mockModel,
  81. providerID: "openai",
  82. api: {
  83. id: "gpt-4",
  84. url: "https://api.openai.com",
  85. npm: "@ai-sdk/openai",
  86. },
  87. }
  88. const result = ProviderTransform.options({
  89. model: openaiModel,
  90. sessionID,
  91. providerOptions: {},
  92. })
  93. expect(result.store).toBe(false)
  94. })
  95. })
  96. describe("ProviderTransform.maxOutputTokens", () => {
  97. test("returns 32k when modelLimit > 32k", () => {
  98. const modelLimit = 100000
  99. const result = ProviderTransform.maxOutputTokens("@ai-sdk/openai", {}, modelLimit, OUTPUT_TOKEN_MAX)
  100. expect(result).toBe(OUTPUT_TOKEN_MAX)
  101. })
  102. test("returns modelLimit when modelLimit < 32k", () => {
  103. const modelLimit = 16000
  104. const result = ProviderTransform.maxOutputTokens("@ai-sdk/openai", {}, modelLimit, OUTPUT_TOKEN_MAX)
  105. expect(result).toBe(16000)
  106. })
  107. describe("azure", () => {
  108. test("returns 32k when modelLimit > 32k", () => {
  109. const modelLimit = 100000
  110. const result = ProviderTransform.maxOutputTokens("@ai-sdk/azure", {}, modelLimit, OUTPUT_TOKEN_MAX)
  111. expect(result).toBe(OUTPUT_TOKEN_MAX)
  112. })
  113. test("returns modelLimit when modelLimit < 32k", () => {
  114. const modelLimit = 16000
  115. const result = ProviderTransform.maxOutputTokens("@ai-sdk/azure", {}, modelLimit, OUTPUT_TOKEN_MAX)
  116. expect(result).toBe(16000)
  117. })
  118. })
  119. describe("bedrock", () => {
  120. test("returns 32k when modelLimit > 32k", () => {
  121. const modelLimit = 100000
  122. const result = ProviderTransform.maxOutputTokens("@ai-sdk/amazon-bedrock", {}, modelLimit, OUTPUT_TOKEN_MAX)
  123. expect(result).toBe(OUTPUT_TOKEN_MAX)
  124. })
  125. test("returns modelLimit when modelLimit < 32k", () => {
  126. const modelLimit = 16000
  127. const result = ProviderTransform.maxOutputTokens("@ai-sdk/amazon-bedrock", {}, modelLimit, OUTPUT_TOKEN_MAX)
  128. expect(result).toBe(16000)
  129. })
  130. })
  131. describe("anthropic without thinking options", () => {
  132. test("returns 32k when modelLimit > 32k", () => {
  133. const modelLimit = 100000
  134. const result = ProviderTransform.maxOutputTokens("@ai-sdk/anthropic", {}, modelLimit, OUTPUT_TOKEN_MAX)
  135. expect(result).toBe(OUTPUT_TOKEN_MAX)
  136. })
  137. test("returns modelLimit when modelLimit < 32k", () => {
  138. const modelLimit = 16000
  139. const result = ProviderTransform.maxOutputTokens("@ai-sdk/anthropic", {}, modelLimit, OUTPUT_TOKEN_MAX)
  140. expect(result).toBe(16000)
  141. })
  142. })
  143. describe("anthropic with thinking options", () => {
  144. test("returns 32k when budgetTokens + 32k <= modelLimit", () => {
  145. const modelLimit = 100000
  146. const options = {
  147. thinking: {
  148. type: "enabled",
  149. budgetTokens: 10000,
  150. },
  151. }
  152. const result = ProviderTransform.maxOutputTokens("@ai-sdk/anthropic", options, modelLimit, OUTPUT_TOKEN_MAX)
  153. expect(result).toBe(OUTPUT_TOKEN_MAX)
  154. })
  155. test("returns modelLimit - budgetTokens when budgetTokens + 32k > modelLimit", () => {
  156. const modelLimit = 50000
  157. const options = {
  158. thinking: {
  159. type: "enabled",
  160. budgetTokens: 30000,
  161. },
  162. }
  163. const result = ProviderTransform.maxOutputTokens("@ai-sdk/anthropic", options, modelLimit, OUTPUT_TOKEN_MAX)
  164. expect(result).toBe(20000)
  165. })
  166. test("returns 32k when thinking type is not enabled", () => {
  167. const modelLimit = 100000
  168. const options = {
  169. thinking: {
  170. type: "disabled",
  171. budgetTokens: 10000,
  172. },
  173. }
  174. const result = ProviderTransform.maxOutputTokens("@ai-sdk/anthropic", options, modelLimit, OUTPUT_TOKEN_MAX)
  175. expect(result).toBe(OUTPUT_TOKEN_MAX)
  176. })
  177. })
  178. })
  179. describe("ProviderTransform.schema - gemini array items", () => {
  180. test("adds missing items for array properties", () => {
  181. const geminiModel = {
  182. providerID: "google",
  183. api: {
  184. id: "gemini-3-pro",
  185. },
  186. } as any
  187. const schema = {
  188. type: "object",
  189. properties: {
  190. nodes: { type: "array" },
  191. edges: { type: "array", items: { type: "string" } },
  192. },
  193. } as any
  194. const result = ProviderTransform.schema(geminiModel, schema) as any
  195. expect(result.properties.nodes.items).toBeDefined()
  196. expect(result.properties.edges.items.type).toBe("string")
  197. })
  198. })
  199. describe("ProviderTransform.message - DeepSeek reasoning content", () => {
  200. test("DeepSeek with tool calls includes reasoning_content in providerOptions", () => {
  201. const msgs = [
  202. {
  203. role: "assistant",
  204. content: [
  205. { type: "reasoning", text: "Let me think about this..." },
  206. {
  207. type: "tool-call",
  208. toolCallId: "test",
  209. toolName: "bash",
  210. input: { command: "echo hello" },
  211. },
  212. ],
  213. },
  214. ] as any[]
  215. const result = ProviderTransform.message(
  216. msgs,
  217. {
  218. id: "deepseek/deepseek-chat",
  219. providerID: "deepseek",
  220. api: {
  221. id: "deepseek-chat",
  222. url: "https://api.deepseek.com",
  223. npm: "@ai-sdk/openai-compatible",
  224. },
  225. name: "DeepSeek Chat",
  226. capabilities: {
  227. temperature: true,
  228. reasoning: true,
  229. attachment: false,
  230. toolcall: true,
  231. input: { text: true, audio: false, image: false, video: false, pdf: false },
  232. output: { text: true, audio: false, image: false, video: false, pdf: false },
  233. interleaved: {
  234. field: "reasoning_content",
  235. },
  236. },
  237. cost: {
  238. input: 0.001,
  239. output: 0.002,
  240. cache: { read: 0.0001, write: 0.0002 },
  241. },
  242. limit: {
  243. context: 128000,
  244. output: 8192,
  245. },
  246. status: "active",
  247. options: {},
  248. headers: {},
  249. release_date: "2023-04-01",
  250. },
  251. {},
  252. )
  253. expect(result).toHaveLength(1)
  254. expect(result[0].content).toEqual([
  255. {
  256. type: "tool-call",
  257. toolCallId: "test",
  258. toolName: "bash",
  259. input: { command: "echo hello" },
  260. },
  261. ])
  262. expect(result[0].providerOptions?.openaiCompatible?.reasoning_content).toBe("Let me think about this...")
  263. })
  264. test("Non-DeepSeek providers leave reasoning content unchanged", () => {
  265. const msgs = [
  266. {
  267. role: "assistant",
  268. content: [
  269. { type: "reasoning", text: "Should not be processed" },
  270. { type: "text", text: "Answer" },
  271. ],
  272. },
  273. ] as any[]
  274. const result = ProviderTransform.message(
  275. msgs,
  276. {
  277. id: "openai/gpt-4",
  278. providerID: "openai",
  279. api: {
  280. id: "gpt-4",
  281. url: "https://api.openai.com",
  282. npm: "@ai-sdk/openai",
  283. },
  284. name: "GPT-4",
  285. capabilities: {
  286. temperature: true,
  287. reasoning: false,
  288. attachment: true,
  289. toolcall: true,
  290. input: { text: true, audio: false, image: true, video: false, pdf: false },
  291. output: { text: true, audio: false, image: false, video: false, pdf: false },
  292. interleaved: false,
  293. },
  294. cost: {
  295. input: 0.03,
  296. output: 0.06,
  297. cache: { read: 0.001, write: 0.002 },
  298. },
  299. limit: {
  300. context: 128000,
  301. output: 4096,
  302. },
  303. status: "active",
  304. options: {},
  305. headers: {},
  306. release_date: "2023-04-01",
  307. },
  308. {},
  309. )
  310. expect(result[0].content).toEqual([
  311. { type: "reasoning", text: "Should not be processed" },
  312. { type: "text", text: "Answer" },
  313. ])
  314. expect(result[0].providerOptions?.openaiCompatible?.reasoning_content).toBeUndefined()
  315. })
  316. })
  317. describe("ProviderTransform.message - empty image handling", () => {
  318. const mockModel = {
  319. id: "anthropic/claude-3-5-sonnet",
  320. providerID: "anthropic",
  321. api: {
  322. id: "claude-3-5-sonnet-20241022",
  323. url: "https://api.anthropic.com",
  324. npm: "@ai-sdk/anthropic",
  325. },
  326. name: "Claude 3.5 Sonnet",
  327. capabilities: {
  328. temperature: true,
  329. reasoning: false,
  330. attachment: true,
  331. toolcall: true,
  332. input: { text: true, audio: false, image: true, video: false, pdf: true },
  333. output: { text: true, audio: false, image: false, video: false, pdf: false },
  334. interleaved: false,
  335. },
  336. cost: {
  337. input: 0.003,
  338. output: 0.015,
  339. cache: { read: 0.0003, write: 0.00375 },
  340. },
  341. limit: {
  342. context: 200000,
  343. output: 8192,
  344. },
  345. status: "active",
  346. options: {},
  347. headers: {},
  348. } as any
  349. test("should replace empty base64 image with error text", () => {
  350. const msgs = [
  351. {
  352. role: "user",
  353. content: [
  354. { type: "text", text: "What is in this image?" },
  355. { type: "image", image: "data:image/png;base64," },
  356. ],
  357. },
  358. ] as any[]
  359. const result = ProviderTransform.message(msgs, mockModel, {})
  360. expect(result).toHaveLength(1)
  361. expect(result[0].content).toHaveLength(2)
  362. expect(result[0].content[0]).toEqual({ type: "text", text: "What is in this image?" })
  363. expect(result[0].content[1]).toEqual({
  364. type: "text",
  365. text: "ERROR: Image file is empty or corrupted. Please provide a valid image.",
  366. })
  367. })
  368. test("should keep valid base64 images unchanged", () => {
  369. const validBase64 =
  370. "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg=="
  371. const msgs = [
  372. {
  373. role: "user",
  374. content: [
  375. { type: "text", text: "What is in this image?" },
  376. { type: "image", image: `data:image/png;base64,${validBase64}` },
  377. ],
  378. },
  379. ] as any[]
  380. const result = ProviderTransform.message(msgs, mockModel, {})
  381. expect(result).toHaveLength(1)
  382. expect(result[0].content).toHaveLength(2)
  383. expect(result[0].content[0]).toEqual({ type: "text", text: "What is in this image?" })
  384. expect(result[0].content[1]).toEqual({ type: "image", image: `data:image/png;base64,${validBase64}` })
  385. })
  386. test("should handle mixed valid and empty images", () => {
  387. const validBase64 =
  388. "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg=="
  389. const msgs = [
  390. {
  391. role: "user",
  392. content: [
  393. { type: "text", text: "Compare these images" },
  394. { type: "image", image: `data:image/png;base64,${validBase64}` },
  395. { type: "image", image: "data:image/jpeg;base64," },
  396. ],
  397. },
  398. ] as any[]
  399. const result = ProviderTransform.message(msgs, mockModel, {})
  400. expect(result).toHaveLength(1)
  401. expect(result[0].content).toHaveLength(3)
  402. expect(result[0].content[0]).toEqual({ type: "text", text: "Compare these images" })
  403. expect(result[0].content[1]).toEqual({ type: "image", image: `data:image/png;base64,${validBase64}` })
  404. expect(result[0].content[2]).toEqual({
  405. type: "text",
  406. text: "ERROR: Image file is empty or corrupted. Please provide a valid image.",
  407. })
  408. })
  409. })
  410. describe("ProviderTransform.message - anthropic empty content filtering", () => {
  411. const anthropicModel = {
  412. id: "anthropic/claude-3-5-sonnet",
  413. providerID: "anthropic",
  414. api: {
  415. id: "claude-3-5-sonnet-20241022",
  416. url: "https://api.anthropic.com",
  417. npm: "@ai-sdk/anthropic",
  418. },
  419. name: "Claude 3.5 Sonnet",
  420. capabilities: {
  421. temperature: true,
  422. reasoning: false,
  423. attachment: true,
  424. toolcall: true,
  425. input: { text: true, audio: false, image: true, video: false, pdf: true },
  426. output: { text: true, audio: false, image: false, video: false, pdf: false },
  427. interleaved: false,
  428. },
  429. cost: {
  430. input: 0.003,
  431. output: 0.015,
  432. cache: { read: 0.0003, write: 0.00375 },
  433. },
  434. limit: {
  435. context: 200000,
  436. output: 8192,
  437. },
  438. status: "active",
  439. options: {},
  440. headers: {},
  441. } as any
  442. test("filters out messages with empty string content", () => {
  443. const msgs = [
  444. { role: "user", content: "Hello" },
  445. { role: "assistant", content: "" },
  446. { role: "user", content: "World" },
  447. ] as any[]
  448. const result = ProviderTransform.message(msgs, anthropicModel, {})
  449. expect(result).toHaveLength(2)
  450. expect(result[0].content).toBe("Hello")
  451. expect(result[1].content).toBe("World")
  452. })
  453. test("filters out empty text parts from array content", () => {
  454. const msgs = [
  455. {
  456. role: "assistant",
  457. content: [
  458. { type: "text", text: "" },
  459. { type: "text", text: "Hello" },
  460. { type: "text", text: "" },
  461. ],
  462. },
  463. ] as any[]
  464. const result = ProviderTransform.message(msgs, anthropicModel, {})
  465. expect(result).toHaveLength(1)
  466. expect(result[0].content).toHaveLength(1)
  467. expect(result[0].content[0]).toEqual({ type: "text", text: "Hello" })
  468. })
  469. test("filters out empty reasoning parts from array content", () => {
  470. const msgs = [
  471. {
  472. role: "assistant",
  473. content: [
  474. { type: "reasoning", text: "" },
  475. { type: "text", text: "Answer" },
  476. { type: "reasoning", text: "" },
  477. ],
  478. },
  479. ] as any[]
  480. const result = ProviderTransform.message(msgs, anthropicModel, {})
  481. expect(result).toHaveLength(1)
  482. expect(result[0].content).toHaveLength(1)
  483. expect(result[0].content[0]).toEqual({ type: "text", text: "Answer" })
  484. })
  485. test("removes entire message when all parts are empty", () => {
  486. const msgs = [
  487. { role: "user", content: "Hello" },
  488. {
  489. role: "assistant",
  490. content: [
  491. { type: "text", text: "" },
  492. { type: "reasoning", text: "" },
  493. ],
  494. },
  495. { role: "user", content: "World" },
  496. ] as any[]
  497. const result = ProviderTransform.message(msgs, anthropicModel, {})
  498. expect(result).toHaveLength(2)
  499. expect(result[0].content).toBe("Hello")
  500. expect(result[1].content).toBe("World")
  501. })
  502. test("keeps non-text/reasoning parts even if text parts are empty", () => {
  503. const msgs = [
  504. {
  505. role: "assistant",
  506. content: [
  507. { type: "text", text: "" },
  508. { type: "tool-call", toolCallId: "123", toolName: "bash", input: { command: "ls" } },
  509. ],
  510. },
  511. ] as any[]
  512. const result = ProviderTransform.message(msgs, anthropicModel, {})
  513. expect(result).toHaveLength(1)
  514. expect(result[0].content).toHaveLength(1)
  515. expect(result[0].content[0]).toEqual({
  516. type: "tool-call",
  517. toolCallId: "123",
  518. toolName: "bash",
  519. input: { command: "ls" },
  520. })
  521. })
  522. test("keeps messages with valid text alongside empty parts", () => {
  523. const msgs = [
  524. {
  525. role: "assistant",
  526. content: [
  527. { type: "reasoning", text: "Thinking..." },
  528. { type: "text", text: "" },
  529. { type: "text", text: "Result" },
  530. ],
  531. },
  532. ] as any[]
  533. const result = ProviderTransform.message(msgs, anthropicModel, {})
  534. expect(result).toHaveLength(1)
  535. expect(result[0].content).toHaveLength(2)
  536. expect(result[0].content[0]).toEqual({ type: "reasoning", text: "Thinking..." })
  537. expect(result[0].content[1]).toEqual({ type: "text", text: "Result" })
  538. })
  539. test("does not filter for non-anthropic providers", () => {
  540. const openaiModel = {
  541. ...anthropicModel,
  542. providerID: "openai",
  543. api: {
  544. id: "gpt-4",
  545. url: "https://api.openai.com",
  546. npm: "@ai-sdk/openai",
  547. },
  548. }
  549. const msgs = [
  550. { role: "assistant", content: "" },
  551. {
  552. role: "assistant",
  553. content: [{ type: "text", text: "" }],
  554. },
  555. ] as any[]
  556. const result = ProviderTransform.message(msgs, openaiModel, {})
  557. expect(result).toHaveLength(2)
  558. expect(result[0].content).toBe("")
  559. expect(result[1].content).toHaveLength(1)
  560. })
  561. })
  562. describe("ProviderTransform.message - strip openai metadata when store=false", () => {
  563. const openaiModel = {
  564. id: "openai/gpt-5",
  565. providerID: "openai",
  566. api: {
  567. id: "gpt-5",
  568. url: "https://api.openai.com",
  569. npm: "@ai-sdk/openai",
  570. },
  571. name: "GPT-5",
  572. capabilities: {
  573. temperature: true,
  574. reasoning: true,
  575. attachment: true,
  576. toolcall: true,
  577. input: { text: true, audio: false, image: true, video: false, pdf: false },
  578. output: { text: true, audio: false, image: false, video: false, pdf: false },
  579. interleaved: false,
  580. },
  581. cost: { input: 0.03, output: 0.06, cache: { read: 0.001, write: 0.002 } },
  582. limit: { context: 128000, output: 4096 },
  583. status: "active",
  584. options: {},
  585. headers: {},
  586. } as any
  587. test("strips itemId and reasoningEncryptedContent when store=false", () => {
  588. const msgs = [
  589. {
  590. role: "assistant",
  591. content: [
  592. {
  593. type: "reasoning",
  594. text: "thinking...",
  595. providerOptions: {
  596. openai: {
  597. itemId: "rs_123",
  598. reasoningEncryptedContent: "encrypted",
  599. },
  600. },
  601. },
  602. {
  603. type: "text",
  604. text: "Hello",
  605. providerOptions: {
  606. openai: {
  607. itemId: "msg_456",
  608. },
  609. },
  610. },
  611. ],
  612. },
  613. ] as any[]
  614. const result = ProviderTransform.message(msgs, openaiModel, { store: false }) as any[]
  615. expect(result).toHaveLength(1)
  616. expect(result[0].content[0].providerOptions?.openai?.itemId).toBeUndefined()
  617. expect(result[0].content[1].providerOptions?.openai?.itemId).toBeUndefined()
  618. })
  619. test("strips itemId and reasoningEncryptedContent when store=false even when not openai", () => {
  620. const zenModel = {
  621. ...openaiModel,
  622. providerID: "zen",
  623. }
  624. const msgs = [
  625. {
  626. role: "assistant",
  627. content: [
  628. {
  629. type: "reasoning",
  630. text: "thinking...",
  631. providerOptions: {
  632. openai: {
  633. itemId: "rs_123",
  634. reasoningEncryptedContent: "encrypted",
  635. },
  636. },
  637. },
  638. {
  639. type: "text",
  640. text: "Hello",
  641. providerOptions: {
  642. openai: {
  643. itemId: "msg_456",
  644. },
  645. },
  646. },
  647. ],
  648. },
  649. ] as any[]
  650. const result = ProviderTransform.message(msgs, zenModel, { store: false }) as any[]
  651. expect(result).toHaveLength(1)
  652. expect(result[0].content[0].providerOptions?.openai?.itemId).toBeUndefined()
  653. expect(result[0].content[1].providerOptions?.openai?.itemId).toBeUndefined()
  654. })
  655. test("preserves other openai options when stripping itemId", () => {
  656. const msgs = [
  657. {
  658. role: "assistant",
  659. content: [
  660. {
  661. type: "text",
  662. text: "Hello",
  663. providerOptions: {
  664. openai: {
  665. itemId: "msg_123",
  666. otherOption: "value",
  667. },
  668. },
  669. },
  670. ],
  671. },
  672. ] as any[]
  673. const result = ProviderTransform.message(msgs, openaiModel, { store: false }) as any[]
  674. expect(result[0].content[0].providerOptions?.openai?.itemId).toBeUndefined()
  675. expect(result[0].content[0].providerOptions?.openai?.otherOption).toBe("value")
  676. })
  677. test("strips metadata for openai package even when store is true", () => {
  678. const msgs = [
  679. {
  680. role: "assistant",
  681. content: [
  682. {
  683. type: "text",
  684. text: "Hello",
  685. providerOptions: {
  686. openai: {
  687. itemId: "msg_123",
  688. },
  689. },
  690. },
  691. ],
  692. },
  693. ] as any[]
  694. // openai package always strips itemId regardless of store value
  695. const result = ProviderTransform.message(msgs, openaiModel, { store: true }) as any[]
  696. expect(result[0].content[0].providerOptions?.openai?.itemId).toBeUndefined()
  697. })
  698. test("strips metadata for non-openai packages when store is false", () => {
  699. const anthropicModel = {
  700. ...openaiModel,
  701. providerID: "anthropic",
  702. api: {
  703. id: "claude-3",
  704. url: "https://api.anthropic.com",
  705. npm: "@ai-sdk/anthropic",
  706. },
  707. }
  708. const msgs = [
  709. {
  710. role: "assistant",
  711. content: [
  712. {
  713. type: "text",
  714. text: "Hello",
  715. providerOptions: {
  716. openai: {
  717. itemId: "msg_123",
  718. },
  719. },
  720. },
  721. ],
  722. },
  723. ] as any[]
  724. // store=false triggers stripping even for non-openai packages
  725. const result = ProviderTransform.message(msgs, anthropicModel, { store: false }) as any[]
  726. expect(result[0].content[0].providerOptions?.openai?.itemId).toBeUndefined()
  727. })
  728. test("strips metadata using providerID key when store is false", () => {
  729. const opencodeModel = {
  730. ...openaiModel,
  731. providerID: "opencode",
  732. api: {
  733. id: "opencode-test",
  734. url: "https://api.opencode.ai",
  735. npm: "@ai-sdk/openai-compatible",
  736. },
  737. }
  738. const msgs = [
  739. {
  740. role: "assistant",
  741. content: [
  742. {
  743. type: "text",
  744. text: "Hello",
  745. providerOptions: {
  746. opencode: {
  747. itemId: "msg_123",
  748. otherOption: "value",
  749. },
  750. },
  751. },
  752. ],
  753. },
  754. ] as any[]
  755. const result = ProviderTransform.message(msgs, opencodeModel, { store: false }) as any[]
  756. expect(result[0].content[0].providerOptions?.opencode?.itemId).toBeUndefined()
  757. expect(result[0].content[0].providerOptions?.opencode?.otherOption).toBe("value")
  758. })
  759. test("strips itemId across all providerOptions keys", () => {
  760. const opencodeModel = {
  761. ...openaiModel,
  762. providerID: "opencode",
  763. api: {
  764. id: "opencode-test",
  765. url: "https://api.opencode.ai",
  766. npm: "@ai-sdk/openai-compatible",
  767. },
  768. }
  769. const msgs = [
  770. {
  771. role: "assistant",
  772. providerOptions: {
  773. openai: { itemId: "msg_root" },
  774. opencode: { itemId: "msg_opencode" },
  775. extra: { itemId: "msg_extra" },
  776. },
  777. content: [
  778. {
  779. type: "text",
  780. text: "Hello",
  781. providerOptions: {
  782. openai: { itemId: "msg_openai_part" },
  783. opencode: { itemId: "msg_opencode_part" },
  784. extra: { itemId: "msg_extra_part" },
  785. },
  786. },
  787. ],
  788. },
  789. ] as any[]
  790. const result = ProviderTransform.message(msgs, opencodeModel, { store: false }) as any[]
  791. expect(result[0].providerOptions?.openai?.itemId).toBeUndefined()
  792. expect(result[0].providerOptions?.opencode?.itemId).toBeUndefined()
  793. expect(result[0].providerOptions?.extra?.itemId).toBeUndefined()
  794. expect(result[0].content[0].providerOptions?.openai?.itemId).toBeUndefined()
  795. expect(result[0].content[0].providerOptions?.opencode?.itemId).toBeUndefined()
  796. expect(result[0].content[0].providerOptions?.extra?.itemId).toBeUndefined()
  797. })
  798. test("does not strip metadata for non-openai packages when store is not false", () => {
  799. const anthropicModel = {
  800. ...openaiModel,
  801. providerID: "anthropic",
  802. api: {
  803. id: "claude-3",
  804. url: "https://api.anthropic.com",
  805. npm: "@ai-sdk/anthropic",
  806. },
  807. }
  808. const msgs = [
  809. {
  810. role: "assistant",
  811. content: [
  812. {
  813. type: "text",
  814. text: "Hello",
  815. providerOptions: {
  816. openai: {
  817. itemId: "msg_123",
  818. },
  819. },
  820. },
  821. ],
  822. },
  823. ] as any[]
  824. const result = ProviderTransform.message(msgs, anthropicModel, {}) as any[]
  825. expect(result[0].content[0].providerOptions?.openai?.itemId).toBe("msg_123")
  826. })
  827. })
  828. describe("ProviderTransform.variants", () => {
  829. const createMockModel = (overrides: Partial<any> = {}): any => ({
  830. id: "test/test-model",
  831. providerID: "test",
  832. api: {
  833. id: "test-model",
  834. url: "https://api.test.com",
  835. npm: "@ai-sdk/openai",
  836. },
  837. name: "Test Model",
  838. capabilities: {
  839. temperature: true,
  840. reasoning: true,
  841. attachment: true,
  842. toolcall: true,
  843. input: { text: true, audio: false, image: true, video: false, pdf: false },
  844. output: { text: true, audio: false, image: false, video: false, pdf: false },
  845. interleaved: false,
  846. },
  847. cost: {
  848. input: 0.001,
  849. output: 0.002,
  850. cache: { read: 0.0001, write: 0.0002 },
  851. },
  852. limit: {
  853. context: 128000,
  854. output: 8192,
  855. },
  856. status: "active",
  857. options: {},
  858. headers: {},
  859. release_date: "2024-01-01",
  860. ...overrides,
  861. })
  862. test("returns empty object when model has no reasoning capabilities", () => {
  863. const model = createMockModel({
  864. capabilities: { reasoning: false },
  865. })
  866. const result = ProviderTransform.variants(model)
  867. expect(result).toEqual({})
  868. })
  869. test("deepseek returns empty object", () => {
  870. const model = createMockModel({
  871. id: "deepseek/deepseek-chat",
  872. providerID: "deepseek",
  873. api: {
  874. id: "deepseek-chat",
  875. url: "https://api.deepseek.com",
  876. npm: "@ai-sdk/openai-compatible",
  877. },
  878. })
  879. const result = ProviderTransform.variants(model)
  880. expect(result).toEqual({})
  881. })
  882. test("minimax returns empty object", () => {
  883. const model = createMockModel({
  884. id: "minimax/minimax-model",
  885. providerID: "minimax",
  886. api: {
  887. id: "minimax-model",
  888. url: "https://api.minimax.com",
  889. npm: "@ai-sdk/openai-compatible",
  890. },
  891. })
  892. const result = ProviderTransform.variants(model)
  893. expect(result).toEqual({})
  894. })
  895. test("glm returns empty object", () => {
  896. const model = createMockModel({
  897. id: "glm/glm-4",
  898. providerID: "glm",
  899. api: {
  900. id: "glm-4",
  901. url: "https://api.glm.com",
  902. npm: "@ai-sdk/openai-compatible",
  903. },
  904. })
  905. const result = ProviderTransform.variants(model)
  906. expect(result).toEqual({})
  907. })
  908. test("mistral returns empty object", () => {
  909. const model = createMockModel({
  910. id: "mistral/mistral-large",
  911. providerID: "mistral",
  912. api: {
  913. id: "mistral-large-latest",
  914. url: "https://api.mistral.com",
  915. npm: "@ai-sdk/mistral",
  916. },
  917. })
  918. const result = ProviderTransform.variants(model)
  919. expect(result).toEqual({})
  920. })
  921. describe("@openrouter/ai-sdk-provider", () => {
  922. test("returns empty object for non-qualifying models", () => {
  923. const model = createMockModel({
  924. id: "openrouter/test-model",
  925. providerID: "openrouter",
  926. api: {
  927. id: "test-model",
  928. url: "https://openrouter.ai",
  929. npm: "@openrouter/ai-sdk-provider",
  930. },
  931. })
  932. const result = ProviderTransform.variants(model)
  933. expect(result).toEqual({})
  934. })
  935. test("gpt models return OPENAI_EFFORTS with reasoning", () => {
  936. const model = createMockModel({
  937. id: "openrouter/gpt-4",
  938. providerID: "openrouter",
  939. api: {
  940. id: "gpt-4",
  941. url: "https://openrouter.ai",
  942. npm: "@openrouter/ai-sdk-provider",
  943. },
  944. })
  945. const result = ProviderTransform.variants(model)
  946. expect(Object.keys(result)).toEqual(["none", "minimal", "low", "medium", "high", "xhigh"])
  947. expect(result.low).toEqual({ reasoning: { effort: "low" } })
  948. expect(result.high).toEqual({ reasoning: { effort: "high" } })
  949. })
  950. test("gemini-3 returns OPENAI_EFFORTS with reasoning", () => {
  951. const model = createMockModel({
  952. id: "openrouter/gemini-3-5-pro",
  953. providerID: "openrouter",
  954. api: {
  955. id: "gemini-3-5-pro",
  956. url: "https://openrouter.ai",
  957. npm: "@openrouter/ai-sdk-provider",
  958. },
  959. })
  960. const result = ProviderTransform.variants(model)
  961. expect(Object.keys(result)).toEqual(["none", "minimal", "low", "medium", "high", "xhigh"])
  962. })
  963. test("grok-4 returns OPENAI_EFFORTS with reasoning", () => {
  964. const model = createMockModel({
  965. id: "openrouter/grok-4",
  966. providerID: "openrouter",
  967. api: {
  968. id: "grok-4",
  969. url: "https://openrouter.ai",
  970. npm: "@openrouter/ai-sdk-provider",
  971. },
  972. })
  973. const result = ProviderTransform.variants(model)
  974. expect(Object.keys(result)).toEqual(["none", "minimal", "low", "medium", "high", "xhigh"])
  975. })
  976. })
  977. describe("@ai-sdk/gateway", () => {
  978. test("returns OPENAI_EFFORTS with reasoningEffort", () => {
  979. const model = createMockModel({
  980. id: "gateway/gateway-model",
  981. providerID: "gateway",
  982. api: {
  983. id: "gateway-model",
  984. url: "https://gateway.ai",
  985. npm: "@ai-sdk/gateway",
  986. },
  987. })
  988. const result = ProviderTransform.variants(model)
  989. expect(Object.keys(result)).toEqual(["none", "minimal", "low", "medium", "high", "xhigh"])
  990. expect(result.low).toEqual({ reasoningEffort: "low" })
  991. expect(result.high).toEqual({ reasoningEffort: "high" })
  992. })
  993. })
  994. describe("@ai-sdk/cerebras", () => {
  995. test("returns WIDELY_SUPPORTED_EFFORTS with reasoningEffort", () => {
  996. const model = createMockModel({
  997. id: "cerebras/llama-4",
  998. providerID: "cerebras",
  999. api: {
  1000. id: "llama-4-sc",
  1001. url: "https://api.cerebras.ai",
  1002. npm: "@ai-sdk/cerebras",
  1003. },
  1004. })
  1005. const result = ProviderTransform.variants(model)
  1006. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  1007. expect(result.low).toEqual({ reasoningEffort: "low" })
  1008. expect(result.high).toEqual({ reasoningEffort: "high" })
  1009. })
  1010. })
  1011. describe("@ai-sdk/togetherai", () => {
  1012. test("returns WIDELY_SUPPORTED_EFFORTS with reasoningEffort", () => {
  1013. const model = createMockModel({
  1014. id: "togetherai/llama-4",
  1015. providerID: "togetherai",
  1016. api: {
  1017. id: "llama-4-sc",
  1018. url: "https://api.togetherai.com",
  1019. npm: "@ai-sdk/togetherai",
  1020. },
  1021. })
  1022. const result = ProviderTransform.variants(model)
  1023. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  1024. expect(result.low).toEqual({ reasoningEffort: "low" })
  1025. expect(result.high).toEqual({ reasoningEffort: "high" })
  1026. })
  1027. })
  1028. describe("@ai-sdk/xai", () => {
  1029. test("returns WIDELY_SUPPORTED_EFFORTS with reasoningEffort", () => {
  1030. const model = createMockModel({
  1031. id: "xai/grok-3",
  1032. providerID: "xai",
  1033. api: {
  1034. id: "grok-3",
  1035. url: "https://api.x.ai",
  1036. npm: "@ai-sdk/xai",
  1037. },
  1038. })
  1039. const result = ProviderTransform.variants(model)
  1040. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  1041. expect(result.low).toEqual({ reasoningEffort: "low" })
  1042. expect(result.high).toEqual({ reasoningEffort: "high" })
  1043. })
  1044. })
  1045. describe("@ai-sdk/deepinfra", () => {
  1046. test("returns WIDELY_SUPPORTED_EFFORTS with reasoningEffort", () => {
  1047. const model = createMockModel({
  1048. id: "deepinfra/llama-4",
  1049. providerID: "deepinfra",
  1050. api: {
  1051. id: "llama-4-sc",
  1052. url: "https://api.deepinfra.com",
  1053. npm: "@ai-sdk/deepinfra",
  1054. },
  1055. })
  1056. const result = ProviderTransform.variants(model)
  1057. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  1058. expect(result.low).toEqual({ reasoningEffort: "low" })
  1059. expect(result.high).toEqual({ reasoningEffort: "high" })
  1060. })
  1061. })
  1062. describe("@ai-sdk/openai-compatible", () => {
  1063. test("returns WIDELY_SUPPORTED_EFFORTS with reasoningEffort", () => {
  1064. const model = createMockModel({
  1065. id: "custom-provider/custom-model",
  1066. providerID: "custom-provider",
  1067. api: {
  1068. id: "custom-model",
  1069. url: "https://api.custom.com",
  1070. npm: "@ai-sdk/openai-compatible",
  1071. },
  1072. })
  1073. const result = ProviderTransform.variants(model)
  1074. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  1075. expect(result.low).toEqual({ reasoningEffort: "low" })
  1076. expect(result.high).toEqual({ reasoningEffort: "high" })
  1077. })
  1078. })
  1079. describe("@ai-sdk/azure", () => {
  1080. test("o1-mini returns empty object", () => {
  1081. const model = createMockModel({
  1082. id: "o1-mini",
  1083. providerID: "azure",
  1084. api: {
  1085. id: "o1-mini",
  1086. url: "https://azure.com",
  1087. npm: "@ai-sdk/azure",
  1088. },
  1089. })
  1090. const result = ProviderTransform.variants(model)
  1091. expect(result).toEqual({})
  1092. })
  1093. test("standard azure models return custom efforts with reasoningSummary", () => {
  1094. const model = createMockModel({
  1095. id: "o1",
  1096. providerID: "azure",
  1097. api: {
  1098. id: "o1",
  1099. url: "https://azure.com",
  1100. npm: "@ai-sdk/azure",
  1101. },
  1102. })
  1103. const result = ProviderTransform.variants(model)
  1104. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  1105. expect(result.low).toEqual({
  1106. reasoningEffort: "low",
  1107. reasoningSummary: "auto",
  1108. include: ["reasoning.encrypted_content"],
  1109. })
  1110. })
  1111. test("gpt-5 adds minimal effort", () => {
  1112. const model = createMockModel({
  1113. id: "gpt-5",
  1114. providerID: "azure",
  1115. api: {
  1116. id: "gpt-5",
  1117. url: "https://azure.com",
  1118. npm: "@ai-sdk/azure",
  1119. },
  1120. })
  1121. const result = ProviderTransform.variants(model)
  1122. expect(Object.keys(result)).toEqual(["minimal", "low", "medium", "high"])
  1123. })
  1124. })
  1125. describe("@ai-sdk/openai", () => {
  1126. test("gpt-5-pro returns empty object", () => {
  1127. const model = createMockModel({
  1128. id: "gpt-5-pro",
  1129. providerID: "openai",
  1130. api: {
  1131. id: "gpt-5-pro",
  1132. url: "https://api.openai.com",
  1133. npm: "@ai-sdk/openai",
  1134. },
  1135. })
  1136. const result = ProviderTransform.variants(model)
  1137. expect(result).toEqual({})
  1138. })
  1139. test("standard openai models return custom efforts with reasoningSummary", () => {
  1140. const model = createMockModel({
  1141. id: "gpt-5",
  1142. providerID: "openai",
  1143. api: {
  1144. id: "gpt-5",
  1145. url: "https://api.openai.com",
  1146. npm: "@ai-sdk/openai",
  1147. },
  1148. release_date: "2024-06-01",
  1149. })
  1150. const result = ProviderTransform.variants(model)
  1151. expect(Object.keys(result)).toEqual(["minimal", "low", "medium", "high"])
  1152. expect(result.low).toEqual({
  1153. reasoningEffort: "low",
  1154. reasoningSummary: "auto",
  1155. include: ["reasoning.encrypted_content"],
  1156. })
  1157. })
  1158. test("models after 2025-11-13 include 'none' effort", () => {
  1159. const model = createMockModel({
  1160. id: "gpt-5-nano",
  1161. providerID: "openai",
  1162. api: {
  1163. id: "gpt-5-nano",
  1164. url: "https://api.openai.com",
  1165. npm: "@ai-sdk/openai",
  1166. },
  1167. release_date: "2025-11-14",
  1168. })
  1169. const result = ProviderTransform.variants(model)
  1170. expect(Object.keys(result)).toEqual(["none", "minimal", "low", "medium", "high"])
  1171. })
  1172. test("models after 2025-12-04 include 'xhigh' effort", () => {
  1173. const model = createMockModel({
  1174. id: "openai/gpt-5-chat",
  1175. providerID: "openai",
  1176. api: {
  1177. id: "gpt-5-chat",
  1178. url: "https://api.openai.com",
  1179. npm: "@ai-sdk/openai",
  1180. },
  1181. release_date: "2025-12-05",
  1182. })
  1183. const result = ProviderTransform.variants(model)
  1184. expect(Object.keys(result)).toEqual(["none", "minimal", "low", "medium", "high", "xhigh"])
  1185. })
  1186. })
  1187. describe("@ai-sdk/anthropic", () => {
  1188. test("returns high and max with thinking config", () => {
  1189. const model = createMockModel({
  1190. id: "anthropic/claude-4",
  1191. providerID: "anthropic",
  1192. api: {
  1193. id: "claude-4",
  1194. url: "https://api.anthropic.com",
  1195. npm: "@ai-sdk/anthropic",
  1196. },
  1197. })
  1198. const result = ProviderTransform.variants(model)
  1199. expect(Object.keys(result)).toEqual(["high", "max"])
  1200. expect(result.high).toEqual({
  1201. thinking: {
  1202. type: "enabled",
  1203. budgetTokens: 16000,
  1204. },
  1205. })
  1206. expect(result.max).toEqual({
  1207. thinking: {
  1208. type: "enabled",
  1209. budgetTokens: 31999,
  1210. },
  1211. })
  1212. })
  1213. })
  1214. describe("@ai-sdk/amazon-bedrock", () => {
  1215. test("returns WIDELY_SUPPORTED_EFFORTS with reasoningConfig", () => {
  1216. const model = createMockModel({
  1217. id: "bedrock/llama-4",
  1218. providerID: "bedrock",
  1219. api: {
  1220. id: "llama-4-sc",
  1221. url: "https://bedrock.amazonaws.com",
  1222. npm: "@ai-sdk/amazon-bedrock",
  1223. },
  1224. })
  1225. const result = ProviderTransform.variants(model)
  1226. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  1227. expect(result.low).toEqual({
  1228. reasoningConfig: {
  1229. type: "enabled",
  1230. maxReasoningEffort: "low",
  1231. },
  1232. })
  1233. })
  1234. })
  1235. describe("@ai-sdk/google", () => {
  1236. test("gemini-2.5 returns high and max with thinkingConfig and thinkingBudget", () => {
  1237. const model = createMockModel({
  1238. id: "google/gemini-2.5-pro",
  1239. providerID: "google",
  1240. api: {
  1241. id: "gemini-2.5-pro",
  1242. url: "https://generativelanguage.googleapis.com",
  1243. npm: "@ai-sdk/google",
  1244. },
  1245. })
  1246. const result = ProviderTransform.variants(model)
  1247. expect(Object.keys(result)).toEqual(["high", "max"])
  1248. expect(result.high).toEqual({
  1249. thinkingConfig: {
  1250. includeThoughts: true,
  1251. thinkingBudget: 16000,
  1252. },
  1253. })
  1254. expect(result.max).toEqual({
  1255. thinkingConfig: {
  1256. includeThoughts: true,
  1257. thinkingBudget: 24576,
  1258. },
  1259. })
  1260. })
  1261. test("other gemini models return low and high with thinkingLevel", () => {
  1262. const model = createMockModel({
  1263. id: "google/gemini-2.0-pro",
  1264. providerID: "google",
  1265. api: {
  1266. id: "gemini-2.0-pro",
  1267. url: "https://generativelanguage.googleapis.com",
  1268. npm: "@ai-sdk/google",
  1269. },
  1270. })
  1271. const result = ProviderTransform.variants(model)
  1272. expect(Object.keys(result)).toEqual(["low", "high"])
  1273. expect(result.low).toEqual({
  1274. includeThoughts: true,
  1275. thinkingLevel: "low",
  1276. })
  1277. expect(result.high).toEqual({
  1278. includeThoughts: true,
  1279. thinkingLevel: "high",
  1280. })
  1281. })
  1282. })
  1283. describe("@ai-sdk/google-vertex", () => {
  1284. test("gemini-2.5 returns high and max with thinkingConfig and thinkingBudget", () => {
  1285. const model = createMockModel({
  1286. id: "google-vertex/gemini-2.5-pro",
  1287. providerID: "google-vertex",
  1288. api: {
  1289. id: "gemini-2.5-pro",
  1290. url: "https://vertexai.googleapis.com",
  1291. npm: "@ai-sdk/google-vertex",
  1292. },
  1293. })
  1294. const result = ProviderTransform.variants(model)
  1295. expect(Object.keys(result)).toEqual(["high", "max"])
  1296. })
  1297. test("other vertex models return low and high with thinkingLevel", () => {
  1298. const model = createMockModel({
  1299. id: "google-vertex/gemini-2.0-pro",
  1300. providerID: "google-vertex",
  1301. api: {
  1302. id: "gemini-2.0-pro",
  1303. url: "https://vertexai.googleapis.com",
  1304. npm: "@ai-sdk/google-vertex",
  1305. },
  1306. })
  1307. const result = ProviderTransform.variants(model)
  1308. expect(Object.keys(result)).toEqual(["low", "high"])
  1309. })
  1310. })
  1311. describe("@ai-sdk/cohere", () => {
  1312. test("returns empty object", () => {
  1313. const model = createMockModel({
  1314. id: "cohere/command-r",
  1315. providerID: "cohere",
  1316. api: {
  1317. id: "command-r",
  1318. url: "https://api.cohere.com",
  1319. npm: "@ai-sdk/cohere",
  1320. },
  1321. })
  1322. const result = ProviderTransform.variants(model)
  1323. expect(result).toEqual({})
  1324. })
  1325. })
  1326. describe("@ai-sdk/groq", () => {
  1327. test("returns none and WIDELY_SUPPORTED_EFFORTS with thinkingLevel", () => {
  1328. const model = createMockModel({
  1329. id: "groq/llama-4",
  1330. providerID: "groq",
  1331. api: {
  1332. id: "llama-4-sc",
  1333. url: "https://api.groq.com",
  1334. npm: "@ai-sdk/groq",
  1335. },
  1336. })
  1337. const result = ProviderTransform.variants(model)
  1338. expect(Object.keys(result)).toEqual(["none", "low", "medium", "high"])
  1339. expect(result.none).toEqual({
  1340. includeThoughts: true,
  1341. thinkingLevel: "none",
  1342. })
  1343. expect(result.low).toEqual({
  1344. includeThoughts: true,
  1345. thinkingLevel: "low",
  1346. })
  1347. })
  1348. })
  1349. describe("@ai-sdk/perplexity", () => {
  1350. test("returns empty object", () => {
  1351. const model = createMockModel({
  1352. id: "perplexity/sonar-plus",
  1353. providerID: "perplexity",
  1354. api: {
  1355. id: "sonar-plus",
  1356. url: "https://api.perplexity.ai",
  1357. npm: "@ai-sdk/perplexity",
  1358. },
  1359. })
  1360. const result = ProviderTransform.variants(model)
  1361. expect(result).toEqual({})
  1362. })
  1363. })
  1364. })