transform.test.ts 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727
  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("preserves 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).toBe("rs_123")
  617. expect(result[0].content[1].providerOptions?.openai?.itemId).toBe("msg_456")
  618. })
  619. test("preserves 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).toBe("rs_123")
  653. expect(result[0].content[1].providerOptions?.openai?.itemId).toBe("msg_456")
  654. })
  655. test("preserves other openai options including 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).toBe("msg_123")
  675. expect(result[0].content[0].providerOptions?.openai?.otherOption).toBe("value")
  676. })
  677. test("preserves metadata for openai package 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 preserves 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).toBe("msg_123")
  697. })
  698. test("preserves 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 preserves metadata for non-openai packages
  725. const result = ProviderTransform.message(msgs, anthropicModel, { store: false }) as any[]
  726. expect(result[0].content[0].providerOptions?.openai?.itemId).toBe("msg_123")
  727. })
  728. test("preserves 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).toBe("msg_123")
  757. expect(result[0].content[0].providerOptions?.opencode?.otherOption).toBe("value")
  758. })
  759. test("preserves 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).toBe("msg_root")
  792. expect(result[0].providerOptions?.opencode?.itemId).toBe("msg_opencode")
  793. expect(result[0].providerOptions?.extra?.itemId).toBe("msg_extra")
  794. expect(result[0].content[0].providerOptions?.openai?.itemId).toBe("msg_openai_part")
  795. expect(result[0].content[0].providerOptions?.opencode?.itemId).toBe("msg_opencode_part")
  796. expect(result[0].content[0].providerOptions?.extra?.itemId).toBe("msg_extra_part")
  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.message - providerOptions key remapping", () => {
  829. const createModel = (providerID: string, npm: string) =>
  830. ({
  831. id: `${providerID}/test-model`,
  832. providerID,
  833. api: {
  834. id: "test-model",
  835. url: "https://api.test.com",
  836. npm,
  837. },
  838. name: "Test Model",
  839. capabilities: {
  840. temperature: true,
  841. reasoning: false,
  842. attachment: true,
  843. toolcall: true,
  844. input: { text: true, audio: false, image: true, video: false, pdf: true },
  845. output: { text: true, audio: false, image: false, video: false, pdf: false },
  846. interleaved: false,
  847. },
  848. cost: { input: 0.001, output: 0.002, cache: { read: 0.0001, write: 0.0002 } },
  849. limit: { context: 128000, output: 8192 },
  850. status: "active",
  851. options: {},
  852. headers: {},
  853. }) as any
  854. test("azure keeps 'azure' key and does not remap to 'openai'", () => {
  855. const model = createModel("azure", "@ai-sdk/azure")
  856. const msgs = [
  857. {
  858. role: "user",
  859. content: "Hello",
  860. providerOptions: {
  861. azure: { someOption: "value" },
  862. },
  863. },
  864. ] as any[]
  865. const result = ProviderTransform.message(msgs, model, {})
  866. expect(result[0].providerOptions?.azure).toEqual({ someOption: "value" })
  867. expect(result[0].providerOptions?.openai).toBeUndefined()
  868. })
  869. test("openai with github-copilot npm remaps providerID to 'openai'", () => {
  870. const model = createModel("github-copilot", "@ai-sdk/github-copilot")
  871. const msgs = [
  872. {
  873. role: "user",
  874. content: "Hello",
  875. providerOptions: {
  876. "github-copilot": { someOption: "value" },
  877. },
  878. },
  879. ] as any[]
  880. const result = ProviderTransform.message(msgs, model, {})
  881. expect(result[0].providerOptions?.openai).toEqual({ someOption: "value" })
  882. expect(result[0].providerOptions?.["github-copilot"]).toBeUndefined()
  883. })
  884. test("bedrock remaps providerID to 'bedrock' key", () => {
  885. const model = createModel("my-bedrock", "@ai-sdk/amazon-bedrock")
  886. const msgs = [
  887. {
  888. role: "user",
  889. content: "Hello",
  890. providerOptions: {
  891. "my-bedrock": { someOption: "value" },
  892. },
  893. },
  894. ] as any[]
  895. const result = ProviderTransform.message(msgs, model, {})
  896. expect(result[0].providerOptions?.bedrock).toEqual({ someOption: "value" })
  897. expect(result[0].providerOptions?.["my-bedrock"]).toBeUndefined()
  898. })
  899. })
  900. describe("ProviderTransform.message - claude w/bedrock custom inference profile", () => {
  901. test("adds cachePoint", () => {
  902. const model = {
  903. id: "amazon-bedrock/custom-claude-sonnet-4.5",
  904. providerID: "amazon-bedrock",
  905. api: {
  906. id: "arn:aws:bedrock:xxx:yyy:application-inference-profile/zzz",
  907. url: "https://api.test.com",
  908. npm: "@ai-sdk/amazon-bedrock",
  909. },
  910. name: "Custom inference profile",
  911. capabilities: {},
  912. options: {},
  913. headers: {},
  914. } as any
  915. const msgs = [
  916. {
  917. role: "user",
  918. content: "Hello",
  919. },
  920. ] as any[]
  921. const result = ProviderTransform.message(msgs, model, {})
  922. expect(result[0].providerOptions?.bedrock).toEqual(
  923. expect.objectContaining({
  924. cachePoint: {
  925. type: "ephemeral",
  926. },
  927. }),
  928. )
  929. })
  930. })
  931. describe("ProviderTransform.variants", () => {
  932. const createMockModel = (overrides: Partial<any> = {}): any => ({
  933. id: "test/test-model",
  934. providerID: "test",
  935. api: {
  936. id: "test-model",
  937. url: "https://api.test.com",
  938. npm: "@ai-sdk/openai",
  939. },
  940. name: "Test Model",
  941. capabilities: {
  942. temperature: true,
  943. reasoning: true,
  944. attachment: true,
  945. toolcall: true,
  946. input: { text: true, audio: false, image: true, video: false, pdf: false },
  947. output: { text: true, audio: false, image: false, video: false, pdf: false },
  948. interleaved: false,
  949. },
  950. cost: {
  951. input: 0.001,
  952. output: 0.002,
  953. cache: { read: 0.0001, write: 0.0002 },
  954. },
  955. limit: {
  956. context: 128000,
  957. output: 8192,
  958. },
  959. status: "active",
  960. options: {},
  961. headers: {},
  962. release_date: "2024-01-01",
  963. ...overrides,
  964. })
  965. test("returns empty object when model has no reasoning capabilities", () => {
  966. const model = createMockModel({
  967. capabilities: { reasoning: false },
  968. })
  969. const result = ProviderTransform.variants(model)
  970. expect(result).toEqual({})
  971. })
  972. test("deepseek returns empty object", () => {
  973. const model = createMockModel({
  974. id: "deepseek/deepseek-chat",
  975. providerID: "deepseek",
  976. api: {
  977. id: "deepseek-chat",
  978. url: "https://api.deepseek.com",
  979. npm: "@ai-sdk/openai-compatible",
  980. },
  981. })
  982. const result = ProviderTransform.variants(model)
  983. expect(result).toEqual({})
  984. })
  985. test("minimax returns empty object", () => {
  986. const model = createMockModel({
  987. id: "minimax/minimax-model",
  988. providerID: "minimax",
  989. api: {
  990. id: "minimax-model",
  991. url: "https://api.minimax.com",
  992. npm: "@ai-sdk/openai-compatible",
  993. },
  994. })
  995. const result = ProviderTransform.variants(model)
  996. expect(result).toEqual({})
  997. })
  998. test("glm returns empty object", () => {
  999. const model = createMockModel({
  1000. id: "glm/glm-4",
  1001. providerID: "glm",
  1002. api: {
  1003. id: "glm-4",
  1004. url: "https://api.glm.com",
  1005. npm: "@ai-sdk/openai-compatible",
  1006. },
  1007. })
  1008. const result = ProviderTransform.variants(model)
  1009. expect(result).toEqual({})
  1010. })
  1011. test("mistral returns empty object", () => {
  1012. const model = createMockModel({
  1013. id: "mistral/mistral-large",
  1014. providerID: "mistral",
  1015. api: {
  1016. id: "mistral-large-latest",
  1017. url: "https://api.mistral.com",
  1018. npm: "@ai-sdk/mistral",
  1019. },
  1020. })
  1021. const result = ProviderTransform.variants(model)
  1022. expect(result).toEqual({})
  1023. })
  1024. describe("@openrouter/ai-sdk-provider", () => {
  1025. test("returns empty object for non-qualifying models", () => {
  1026. const model = createMockModel({
  1027. id: "openrouter/test-model",
  1028. providerID: "openrouter",
  1029. api: {
  1030. id: "test-model",
  1031. url: "https://openrouter.ai",
  1032. npm: "@openrouter/ai-sdk-provider",
  1033. },
  1034. })
  1035. const result = ProviderTransform.variants(model)
  1036. expect(result).toEqual({})
  1037. })
  1038. test("gpt models return OPENAI_EFFORTS with reasoning", () => {
  1039. const model = createMockModel({
  1040. id: "openrouter/gpt-4",
  1041. providerID: "openrouter",
  1042. api: {
  1043. id: "gpt-4",
  1044. url: "https://openrouter.ai",
  1045. npm: "@openrouter/ai-sdk-provider",
  1046. },
  1047. })
  1048. const result = ProviderTransform.variants(model)
  1049. expect(Object.keys(result)).toEqual(["none", "minimal", "low", "medium", "high", "xhigh"])
  1050. expect(result.low).toEqual({ reasoning: { effort: "low" } })
  1051. expect(result.high).toEqual({ reasoning: { effort: "high" } })
  1052. })
  1053. test("gemini-3 returns OPENAI_EFFORTS with reasoning", () => {
  1054. const model = createMockModel({
  1055. id: "openrouter/gemini-3-5-pro",
  1056. providerID: "openrouter",
  1057. api: {
  1058. id: "gemini-3-5-pro",
  1059. url: "https://openrouter.ai",
  1060. npm: "@openrouter/ai-sdk-provider",
  1061. },
  1062. })
  1063. const result = ProviderTransform.variants(model)
  1064. expect(Object.keys(result)).toEqual(["none", "minimal", "low", "medium", "high", "xhigh"])
  1065. })
  1066. test("grok-4 returns empty object", () => {
  1067. const model = createMockModel({
  1068. id: "openrouter/grok-4",
  1069. providerID: "openrouter",
  1070. api: {
  1071. id: "grok-4",
  1072. url: "https://openrouter.ai",
  1073. npm: "@openrouter/ai-sdk-provider",
  1074. },
  1075. })
  1076. const result = ProviderTransform.variants(model)
  1077. expect(result).toEqual({})
  1078. })
  1079. test("grok-3-mini returns low and high with reasoning", () => {
  1080. const model = createMockModel({
  1081. id: "openrouter/grok-3-mini",
  1082. providerID: "openrouter",
  1083. api: {
  1084. id: "grok-3-mini",
  1085. url: "https://openrouter.ai",
  1086. npm: "@openrouter/ai-sdk-provider",
  1087. },
  1088. })
  1089. const result = ProviderTransform.variants(model)
  1090. expect(Object.keys(result)).toEqual(["low", "high"])
  1091. expect(result.low).toEqual({ reasoning: { effort: "low" } })
  1092. expect(result.high).toEqual({ reasoning: { effort: "high" } })
  1093. })
  1094. })
  1095. describe("@ai-sdk/gateway", () => {
  1096. test("returns OPENAI_EFFORTS with reasoningEffort", () => {
  1097. const model = createMockModel({
  1098. id: "gateway/gateway-model",
  1099. providerID: "gateway",
  1100. api: {
  1101. id: "gateway-model",
  1102. url: "https://gateway.ai",
  1103. npm: "@ai-sdk/gateway",
  1104. },
  1105. })
  1106. const result = ProviderTransform.variants(model)
  1107. expect(Object.keys(result)).toEqual(["none", "minimal", "low", "medium", "high", "xhigh"])
  1108. expect(result.low).toEqual({ reasoningEffort: "low" })
  1109. expect(result.high).toEqual({ reasoningEffort: "high" })
  1110. })
  1111. })
  1112. describe("@ai-sdk/github-copilot", () => {
  1113. test("standard models return low, medium, high", () => {
  1114. const model = createMockModel({
  1115. id: "gpt-4.5",
  1116. providerID: "github-copilot",
  1117. api: {
  1118. id: "gpt-4.5",
  1119. url: "https://api.githubcopilot.com",
  1120. npm: "@ai-sdk/github-copilot",
  1121. },
  1122. })
  1123. const result = ProviderTransform.variants(model)
  1124. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  1125. expect(result.low).toEqual({
  1126. reasoningEffort: "low",
  1127. reasoningSummary: "auto",
  1128. include: ["reasoning.encrypted_content"],
  1129. })
  1130. })
  1131. test("gpt-5.1-codex-max includes xhigh", () => {
  1132. const model = createMockModel({
  1133. id: "gpt-5.1-codex-max",
  1134. providerID: "github-copilot",
  1135. api: {
  1136. id: "gpt-5.1-codex-max",
  1137. url: "https://api.githubcopilot.com",
  1138. npm: "@ai-sdk/github-copilot",
  1139. },
  1140. })
  1141. const result = ProviderTransform.variants(model)
  1142. expect(Object.keys(result)).toEqual(["low", "medium", "high", "xhigh"])
  1143. })
  1144. test("gpt-5.1-codex-mini does not include xhigh", () => {
  1145. const model = createMockModel({
  1146. id: "gpt-5.1-codex-mini",
  1147. providerID: "github-copilot",
  1148. api: {
  1149. id: "gpt-5.1-codex-mini",
  1150. url: "https://api.githubcopilot.com",
  1151. npm: "@ai-sdk/github-copilot",
  1152. },
  1153. })
  1154. const result = ProviderTransform.variants(model)
  1155. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  1156. })
  1157. test("gpt-5.1-codex does not include xhigh", () => {
  1158. const model = createMockModel({
  1159. id: "gpt-5.1-codex",
  1160. providerID: "github-copilot",
  1161. api: {
  1162. id: "gpt-5.1-codex",
  1163. url: "https://api.githubcopilot.com",
  1164. npm: "@ai-sdk/github-copilot",
  1165. },
  1166. })
  1167. const result = ProviderTransform.variants(model)
  1168. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  1169. })
  1170. test("gpt-5.2 includes xhigh", () => {
  1171. const model = createMockModel({
  1172. id: "gpt-5.2",
  1173. providerID: "github-copilot",
  1174. api: {
  1175. id: "gpt-5.2",
  1176. url: "https://api.githubcopilot.com",
  1177. npm: "@ai-sdk/github-copilot",
  1178. },
  1179. })
  1180. const result = ProviderTransform.variants(model)
  1181. expect(Object.keys(result)).toEqual(["low", "medium", "high", "xhigh"])
  1182. expect(result.xhigh).toEqual({
  1183. reasoningEffort: "xhigh",
  1184. reasoningSummary: "auto",
  1185. include: ["reasoning.encrypted_content"],
  1186. })
  1187. })
  1188. test("gpt-5.2-codex includes xhigh", () => {
  1189. const model = createMockModel({
  1190. id: "gpt-5.2-codex",
  1191. providerID: "github-copilot",
  1192. api: {
  1193. id: "gpt-5.2-codex",
  1194. url: "https://api.githubcopilot.com",
  1195. npm: "@ai-sdk/github-copilot",
  1196. },
  1197. })
  1198. const result = ProviderTransform.variants(model)
  1199. expect(Object.keys(result)).toEqual(["low", "medium", "high", "xhigh"])
  1200. })
  1201. })
  1202. describe("@ai-sdk/cerebras", () => {
  1203. test("returns WIDELY_SUPPORTED_EFFORTS with reasoningEffort", () => {
  1204. const model = createMockModel({
  1205. id: "cerebras/llama-4",
  1206. providerID: "cerebras",
  1207. api: {
  1208. id: "llama-4-sc",
  1209. url: "https://api.cerebras.ai",
  1210. npm: "@ai-sdk/cerebras",
  1211. },
  1212. })
  1213. const result = ProviderTransform.variants(model)
  1214. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  1215. expect(result.low).toEqual({ reasoningEffort: "low" })
  1216. expect(result.high).toEqual({ reasoningEffort: "high" })
  1217. })
  1218. })
  1219. describe("@ai-sdk/togetherai", () => {
  1220. test("returns WIDELY_SUPPORTED_EFFORTS with reasoningEffort", () => {
  1221. const model = createMockModel({
  1222. id: "togetherai/llama-4",
  1223. providerID: "togetherai",
  1224. api: {
  1225. id: "llama-4-sc",
  1226. url: "https://api.togetherai.com",
  1227. npm: "@ai-sdk/togetherai",
  1228. },
  1229. })
  1230. const result = ProviderTransform.variants(model)
  1231. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  1232. expect(result.low).toEqual({ reasoningEffort: "low" })
  1233. expect(result.high).toEqual({ reasoningEffort: "high" })
  1234. })
  1235. })
  1236. describe("@ai-sdk/xai", () => {
  1237. test("grok-3 returns empty object", () => {
  1238. const model = createMockModel({
  1239. id: "xai/grok-3",
  1240. providerID: "xai",
  1241. api: {
  1242. id: "grok-3",
  1243. url: "https://api.x.ai",
  1244. npm: "@ai-sdk/xai",
  1245. },
  1246. })
  1247. const result = ProviderTransform.variants(model)
  1248. expect(result).toEqual({})
  1249. })
  1250. test("grok-3-mini returns low and high with reasoningEffort", () => {
  1251. const model = createMockModel({
  1252. id: "xai/grok-3-mini",
  1253. providerID: "xai",
  1254. api: {
  1255. id: "grok-3-mini",
  1256. url: "https://api.x.ai",
  1257. npm: "@ai-sdk/xai",
  1258. },
  1259. })
  1260. const result = ProviderTransform.variants(model)
  1261. expect(Object.keys(result)).toEqual(["low", "high"])
  1262. expect(result.low).toEqual({ reasoningEffort: "low" })
  1263. expect(result.high).toEqual({ reasoningEffort: "high" })
  1264. })
  1265. })
  1266. describe("@ai-sdk/deepinfra", () => {
  1267. test("returns WIDELY_SUPPORTED_EFFORTS with reasoningEffort", () => {
  1268. const model = createMockModel({
  1269. id: "deepinfra/llama-4",
  1270. providerID: "deepinfra",
  1271. api: {
  1272. id: "llama-4-sc",
  1273. url: "https://api.deepinfra.com",
  1274. npm: "@ai-sdk/deepinfra",
  1275. },
  1276. })
  1277. const result = ProviderTransform.variants(model)
  1278. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  1279. expect(result.low).toEqual({ reasoningEffort: "low" })
  1280. expect(result.high).toEqual({ reasoningEffort: "high" })
  1281. })
  1282. })
  1283. describe("@ai-sdk/openai-compatible", () => {
  1284. test("returns WIDELY_SUPPORTED_EFFORTS with reasoningEffort", () => {
  1285. const model = createMockModel({
  1286. id: "custom-provider/custom-model",
  1287. providerID: "custom-provider",
  1288. api: {
  1289. id: "custom-model",
  1290. url: "https://api.custom.com",
  1291. npm: "@ai-sdk/openai-compatible",
  1292. },
  1293. })
  1294. const result = ProviderTransform.variants(model)
  1295. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  1296. expect(result.low).toEqual({ reasoningEffort: "low" })
  1297. expect(result.high).toEqual({ reasoningEffort: "high" })
  1298. })
  1299. })
  1300. describe("@ai-sdk/azure", () => {
  1301. test("o1-mini returns empty object", () => {
  1302. const model = createMockModel({
  1303. id: "o1-mini",
  1304. providerID: "azure",
  1305. api: {
  1306. id: "o1-mini",
  1307. url: "https://azure.com",
  1308. npm: "@ai-sdk/azure",
  1309. },
  1310. })
  1311. const result = ProviderTransform.variants(model)
  1312. expect(result).toEqual({})
  1313. })
  1314. test("standard azure models return custom efforts with reasoningSummary", () => {
  1315. const model = createMockModel({
  1316. id: "o1",
  1317. providerID: "azure",
  1318. api: {
  1319. id: "o1",
  1320. url: "https://azure.com",
  1321. npm: "@ai-sdk/azure",
  1322. },
  1323. })
  1324. const result = ProviderTransform.variants(model)
  1325. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  1326. expect(result.low).toEqual({
  1327. reasoningEffort: "low",
  1328. reasoningSummary: "auto",
  1329. include: ["reasoning.encrypted_content"],
  1330. })
  1331. })
  1332. test("gpt-5 adds minimal effort", () => {
  1333. const model = createMockModel({
  1334. id: "gpt-5",
  1335. providerID: "azure",
  1336. api: {
  1337. id: "gpt-5",
  1338. url: "https://azure.com",
  1339. npm: "@ai-sdk/azure",
  1340. },
  1341. })
  1342. const result = ProviderTransform.variants(model)
  1343. expect(Object.keys(result)).toEqual(["minimal", "low", "medium", "high"])
  1344. })
  1345. })
  1346. describe("@ai-sdk/openai", () => {
  1347. test("gpt-5-pro returns empty object", () => {
  1348. const model = createMockModel({
  1349. id: "gpt-5-pro",
  1350. providerID: "openai",
  1351. api: {
  1352. id: "gpt-5-pro",
  1353. url: "https://api.openai.com",
  1354. npm: "@ai-sdk/openai",
  1355. },
  1356. })
  1357. const result = ProviderTransform.variants(model)
  1358. expect(result).toEqual({})
  1359. })
  1360. test("standard openai models return custom efforts with reasoningSummary", () => {
  1361. const model = createMockModel({
  1362. id: "gpt-5",
  1363. providerID: "openai",
  1364. api: {
  1365. id: "gpt-5",
  1366. url: "https://api.openai.com",
  1367. npm: "@ai-sdk/openai",
  1368. },
  1369. release_date: "2024-06-01",
  1370. })
  1371. const result = ProviderTransform.variants(model)
  1372. expect(Object.keys(result)).toEqual(["minimal", "low", "medium", "high"])
  1373. expect(result.low).toEqual({
  1374. reasoningEffort: "low",
  1375. reasoningSummary: "auto",
  1376. include: ["reasoning.encrypted_content"],
  1377. })
  1378. })
  1379. test("models after 2025-11-13 include 'none' effort", () => {
  1380. const model = createMockModel({
  1381. id: "gpt-5-nano",
  1382. providerID: "openai",
  1383. api: {
  1384. id: "gpt-5-nano",
  1385. url: "https://api.openai.com",
  1386. npm: "@ai-sdk/openai",
  1387. },
  1388. release_date: "2025-11-14",
  1389. })
  1390. const result = ProviderTransform.variants(model)
  1391. expect(Object.keys(result)).toEqual(["none", "minimal", "low", "medium", "high"])
  1392. })
  1393. test("models after 2025-12-04 include 'xhigh' effort", () => {
  1394. const model = createMockModel({
  1395. id: "openai/gpt-5-chat",
  1396. providerID: "openai",
  1397. api: {
  1398. id: "gpt-5-chat",
  1399. url: "https://api.openai.com",
  1400. npm: "@ai-sdk/openai",
  1401. },
  1402. release_date: "2025-12-05",
  1403. })
  1404. const result = ProviderTransform.variants(model)
  1405. expect(Object.keys(result)).toEqual(["none", "minimal", "low", "medium", "high", "xhigh"])
  1406. })
  1407. })
  1408. describe("@ai-sdk/anthropic", () => {
  1409. test("returns high and max with thinking config", () => {
  1410. const model = createMockModel({
  1411. id: "anthropic/claude-4",
  1412. providerID: "anthropic",
  1413. api: {
  1414. id: "claude-4",
  1415. url: "https://api.anthropic.com",
  1416. npm: "@ai-sdk/anthropic",
  1417. },
  1418. })
  1419. const result = ProviderTransform.variants(model)
  1420. expect(Object.keys(result)).toEqual(["high", "max"])
  1421. expect(result.high).toEqual({
  1422. thinking: {
  1423. type: "enabled",
  1424. budgetTokens: 16000,
  1425. },
  1426. })
  1427. expect(result.max).toEqual({
  1428. thinking: {
  1429. type: "enabled",
  1430. budgetTokens: 31999,
  1431. },
  1432. })
  1433. })
  1434. })
  1435. describe("@ai-sdk/amazon-bedrock", () => {
  1436. test("returns WIDELY_SUPPORTED_EFFORTS with reasoningConfig", () => {
  1437. const model = createMockModel({
  1438. id: "bedrock/llama-4",
  1439. providerID: "bedrock",
  1440. api: {
  1441. id: "llama-4-sc",
  1442. url: "https://bedrock.amazonaws.com",
  1443. npm: "@ai-sdk/amazon-bedrock",
  1444. },
  1445. })
  1446. const result = ProviderTransform.variants(model)
  1447. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  1448. expect(result.low).toEqual({
  1449. reasoningConfig: {
  1450. type: "enabled",
  1451. maxReasoningEffort: "low",
  1452. },
  1453. })
  1454. })
  1455. })
  1456. describe("@ai-sdk/google", () => {
  1457. test("gemini-2.5 returns high and max with thinkingConfig and thinkingBudget", () => {
  1458. const model = createMockModel({
  1459. id: "google/gemini-2.5-pro",
  1460. providerID: "google",
  1461. api: {
  1462. id: "gemini-2.5-pro",
  1463. url: "https://generativelanguage.googleapis.com",
  1464. npm: "@ai-sdk/google",
  1465. },
  1466. })
  1467. const result = ProviderTransform.variants(model)
  1468. expect(Object.keys(result)).toEqual(["high", "max"])
  1469. expect(result.high).toEqual({
  1470. thinkingConfig: {
  1471. includeThoughts: true,
  1472. thinkingBudget: 16000,
  1473. },
  1474. })
  1475. expect(result.max).toEqual({
  1476. thinkingConfig: {
  1477. includeThoughts: true,
  1478. thinkingBudget: 24576,
  1479. },
  1480. })
  1481. })
  1482. test("other gemini models return low and high with thinkingLevel", () => {
  1483. const model = createMockModel({
  1484. id: "google/gemini-2.0-pro",
  1485. providerID: "google",
  1486. api: {
  1487. id: "gemini-2.0-pro",
  1488. url: "https://generativelanguage.googleapis.com",
  1489. npm: "@ai-sdk/google",
  1490. },
  1491. })
  1492. const result = ProviderTransform.variants(model)
  1493. expect(Object.keys(result)).toEqual(["low", "high"])
  1494. expect(result.low).toEqual({
  1495. includeThoughts: true,
  1496. thinkingLevel: "low",
  1497. })
  1498. expect(result.high).toEqual({
  1499. includeThoughts: true,
  1500. thinkingLevel: "high",
  1501. })
  1502. })
  1503. })
  1504. describe("@ai-sdk/google-vertex", () => {
  1505. test("gemini-2.5 returns high and max with thinkingConfig and thinkingBudget", () => {
  1506. const model = createMockModel({
  1507. id: "google-vertex/gemini-2.5-pro",
  1508. providerID: "google-vertex",
  1509. api: {
  1510. id: "gemini-2.5-pro",
  1511. url: "https://vertexai.googleapis.com",
  1512. npm: "@ai-sdk/google-vertex",
  1513. },
  1514. })
  1515. const result = ProviderTransform.variants(model)
  1516. expect(Object.keys(result)).toEqual(["high", "max"])
  1517. })
  1518. test("other vertex models return low and high with thinkingLevel", () => {
  1519. const model = createMockModel({
  1520. id: "google-vertex/gemini-2.0-pro",
  1521. providerID: "google-vertex",
  1522. api: {
  1523. id: "gemini-2.0-pro",
  1524. url: "https://vertexai.googleapis.com",
  1525. npm: "@ai-sdk/google-vertex",
  1526. },
  1527. })
  1528. const result = ProviderTransform.variants(model)
  1529. expect(Object.keys(result)).toEqual(["low", "high"])
  1530. })
  1531. })
  1532. describe("@ai-sdk/cohere", () => {
  1533. test("returns empty object", () => {
  1534. const model = createMockModel({
  1535. id: "cohere/command-r",
  1536. providerID: "cohere",
  1537. api: {
  1538. id: "command-r",
  1539. url: "https://api.cohere.com",
  1540. npm: "@ai-sdk/cohere",
  1541. },
  1542. })
  1543. const result = ProviderTransform.variants(model)
  1544. expect(result).toEqual({})
  1545. })
  1546. })
  1547. describe("@ai-sdk/groq", () => {
  1548. test("returns none and WIDELY_SUPPORTED_EFFORTS with thinkingLevel", () => {
  1549. const model = createMockModel({
  1550. id: "groq/llama-4",
  1551. providerID: "groq",
  1552. api: {
  1553. id: "llama-4-sc",
  1554. url: "https://api.groq.com",
  1555. npm: "@ai-sdk/groq",
  1556. },
  1557. })
  1558. const result = ProviderTransform.variants(model)
  1559. expect(Object.keys(result)).toEqual(["none", "low", "medium", "high"])
  1560. expect(result.none).toEqual({
  1561. includeThoughts: true,
  1562. thinkingLevel: "none",
  1563. })
  1564. expect(result.low).toEqual({
  1565. includeThoughts: true,
  1566. thinkingLevel: "low",
  1567. })
  1568. })
  1569. })
  1570. describe("@ai-sdk/perplexity", () => {
  1571. test("returns empty object", () => {
  1572. const model = createMockModel({
  1573. id: "perplexity/sonar-plus",
  1574. providerID: "perplexity",
  1575. api: {
  1576. id: "sonar-plus",
  1577. url: "https://api.perplexity.ai",
  1578. npm: "@ai-sdk/perplexity",
  1579. },
  1580. })
  1581. const result = ProviderTransform.variants(model)
  1582. expect(result).toEqual({})
  1583. })
  1584. })
  1585. })