transform.test.ts 75 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623
  1. import { describe, expect, test } from "bun:test"
  2. import { ProviderTransform } from "../../src/provider/transform"
  3. import { ModelID, ProviderID } from "../../src/provider/schema"
  4. const OUTPUT_TOKEN_MAX = 32000
  5. describe("ProviderTransform.options - setCacheKey", () => {
  6. const sessionID = "test-session-123"
  7. const mockModel = {
  8. id: "anthropic/claude-3-5-sonnet",
  9. providerID: "anthropic",
  10. api: {
  11. id: "claude-3-5-sonnet-20241022",
  12. url: "https://api.anthropic.com",
  13. npm: "@ai-sdk/anthropic",
  14. },
  15. name: "Claude 3.5 Sonnet",
  16. capabilities: {
  17. temperature: true,
  18. reasoning: false,
  19. attachment: true,
  20. toolcall: true,
  21. input: { text: true, audio: false, image: true, video: false, pdf: true },
  22. output: { text: true, audio: false, image: false, video: false, pdf: false },
  23. interleaved: false,
  24. },
  25. cost: {
  26. input: 0.003,
  27. output: 0.015,
  28. cache: { read: 0.0003, write: 0.00375 },
  29. },
  30. limit: {
  31. context: 200000,
  32. output: 8192,
  33. },
  34. status: "active",
  35. options: {},
  36. headers: {},
  37. } as any
  38. test("should set promptCacheKey when providerOptions.setCacheKey is true", () => {
  39. const result = ProviderTransform.options({
  40. model: mockModel,
  41. sessionID,
  42. providerOptions: { setCacheKey: true },
  43. })
  44. expect(result.promptCacheKey).toBe(sessionID)
  45. })
  46. test("should not set promptCacheKey when providerOptions.setCacheKey is false", () => {
  47. const result = ProviderTransform.options({
  48. model: mockModel,
  49. sessionID,
  50. providerOptions: { setCacheKey: false },
  51. })
  52. expect(result.promptCacheKey).toBeUndefined()
  53. })
  54. test("should not set promptCacheKey when providerOptions is undefined", () => {
  55. const result = ProviderTransform.options({
  56. model: mockModel,
  57. sessionID,
  58. providerOptions: undefined,
  59. })
  60. expect(result.promptCacheKey).toBeUndefined()
  61. })
  62. test("should not set promptCacheKey when providerOptions does not have setCacheKey", () => {
  63. const result = ProviderTransform.options({ model: mockModel, sessionID, providerOptions: {} })
  64. expect(result.promptCacheKey).toBeUndefined()
  65. })
  66. test("should set promptCacheKey for openai provider regardless of setCacheKey", () => {
  67. const openaiModel = {
  68. ...mockModel,
  69. providerID: "openai",
  70. api: {
  71. id: "gpt-4",
  72. url: "https://api.openai.com",
  73. npm: "@ai-sdk/openai",
  74. },
  75. }
  76. const result = ProviderTransform.options({ model: openaiModel, sessionID, providerOptions: {} })
  77. expect(result.promptCacheKey).toBe(sessionID)
  78. })
  79. test("should set store=false for openai provider", () => {
  80. const openaiModel = {
  81. ...mockModel,
  82. providerID: "openai",
  83. api: {
  84. id: "gpt-4",
  85. url: "https://api.openai.com",
  86. npm: "@ai-sdk/openai",
  87. },
  88. }
  89. const result = ProviderTransform.options({
  90. model: openaiModel,
  91. sessionID,
  92. providerOptions: {},
  93. })
  94. expect(result.store).toBe(false)
  95. })
  96. })
  97. describe("ProviderTransform.options - gpt-5 textVerbosity", () => {
  98. const sessionID = "test-session-123"
  99. const createGpt5Model = (apiId: string) =>
  100. ({
  101. id: `openai/${apiId}`,
  102. providerID: "openai",
  103. api: {
  104. id: apiId,
  105. url: "https://api.openai.com",
  106. npm: "@ai-sdk/openai",
  107. },
  108. name: apiId,
  109. capabilities: {
  110. temperature: true,
  111. reasoning: true,
  112. attachment: true,
  113. toolcall: true,
  114. input: { text: true, audio: false, image: true, video: false, pdf: false },
  115. output: { text: true, audio: false, image: false, video: false, pdf: false },
  116. interleaved: false,
  117. },
  118. cost: { input: 0.03, output: 0.06, cache: { read: 0.001, write: 0.002 } },
  119. limit: { context: 128000, output: 4096 },
  120. status: "active",
  121. options: {},
  122. headers: {},
  123. }) as any
  124. test("gpt-5.2 should have textVerbosity set to low", () => {
  125. const model = createGpt5Model("gpt-5.2")
  126. const result = ProviderTransform.options({ model, sessionID, providerOptions: {} })
  127. expect(result.textVerbosity).toBe("low")
  128. })
  129. test("gpt-5.1 should have textVerbosity set to low", () => {
  130. const model = createGpt5Model("gpt-5.1")
  131. const result = ProviderTransform.options({ model, sessionID, providerOptions: {} })
  132. expect(result.textVerbosity).toBe("low")
  133. })
  134. test("gpt-5.2-chat-latest should NOT have textVerbosity set (only supports medium)", () => {
  135. const model = createGpt5Model("gpt-5.2-chat-latest")
  136. const result = ProviderTransform.options({ model, sessionID, providerOptions: {} })
  137. expect(result.textVerbosity).toBeUndefined()
  138. })
  139. test("gpt-5.1-chat-latest should NOT have textVerbosity set (only supports medium)", () => {
  140. const model = createGpt5Model("gpt-5.1-chat-latest")
  141. const result = ProviderTransform.options({ model, sessionID, providerOptions: {} })
  142. expect(result.textVerbosity).toBeUndefined()
  143. })
  144. test("gpt-5.2-chat should NOT have textVerbosity set", () => {
  145. const model = createGpt5Model("gpt-5.2-chat")
  146. const result = ProviderTransform.options({ model, sessionID, providerOptions: {} })
  147. expect(result.textVerbosity).toBeUndefined()
  148. })
  149. test("gpt-5-chat should NOT have textVerbosity set", () => {
  150. const model = createGpt5Model("gpt-5-chat")
  151. const result = ProviderTransform.options({ model, sessionID, providerOptions: {} })
  152. expect(result.textVerbosity).toBeUndefined()
  153. })
  154. test("gpt-5.2-codex should NOT have textVerbosity set (codex models excluded)", () => {
  155. const model = createGpt5Model("gpt-5.2-codex")
  156. const result = ProviderTransform.options({ model, sessionID, providerOptions: {} })
  157. expect(result.textVerbosity).toBeUndefined()
  158. })
  159. })
  160. describe("ProviderTransform.options - gateway", () => {
  161. const sessionID = "test-session-123"
  162. const createModel = (id: string) =>
  163. ({
  164. id,
  165. providerID: "vercel",
  166. api: {
  167. id,
  168. url: "https://ai-gateway.vercel.sh/v3/ai",
  169. npm: "@ai-sdk/gateway",
  170. },
  171. name: id,
  172. capabilities: {
  173. temperature: true,
  174. reasoning: true,
  175. attachment: true,
  176. toolcall: true,
  177. input: { text: true, audio: false, image: true, video: false, pdf: true },
  178. output: { text: true, audio: false, image: false, video: false, pdf: false },
  179. interleaved: false,
  180. },
  181. cost: {
  182. input: 0.001,
  183. output: 0.002,
  184. cache: { read: 0.0001, write: 0.0002 },
  185. },
  186. limit: {
  187. context: 200_000,
  188. output: 8192,
  189. },
  190. status: "active",
  191. options: {},
  192. headers: {},
  193. release_date: "2024-01-01",
  194. }) as any
  195. test("puts gateway defaults under gateway key", () => {
  196. const model = createModel("anthropic/claude-sonnet-4")
  197. const result = ProviderTransform.options({ model, sessionID, providerOptions: {} })
  198. expect(result).toEqual({
  199. gateway: {
  200. caching: "auto",
  201. },
  202. })
  203. })
  204. })
  205. describe("ProviderTransform.providerOptions", () => {
  206. const createModel = (overrides: Partial<any> = {}) =>
  207. ({
  208. id: "test/test-model",
  209. providerID: "test",
  210. api: {
  211. id: "test-model",
  212. url: "https://api.test.com",
  213. npm: "@ai-sdk/openai",
  214. },
  215. name: "Test Model",
  216. capabilities: {
  217. temperature: true,
  218. reasoning: true,
  219. attachment: true,
  220. toolcall: true,
  221. input: { text: true, audio: false, image: true, video: false, pdf: false },
  222. output: { text: true, audio: false, image: false, video: false, pdf: false },
  223. interleaved: false,
  224. },
  225. cost: {
  226. input: 0.001,
  227. output: 0.002,
  228. cache: { read: 0.0001, write: 0.0002 },
  229. },
  230. limit: {
  231. context: 200_000,
  232. output: 64_000,
  233. },
  234. status: "active",
  235. options: {},
  236. headers: {},
  237. release_date: "2024-01-01",
  238. ...overrides,
  239. }) as any
  240. test("uses sdk key for non-gateway models", () => {
  241. const model = createModel({
  242. providerID: "my-bedrock",
  243. api: {
  244. id: "anthropic.claude-sonnet-4",
  245. url: "https://bedrock.aws",
  246. npm: "@ai-sdk/amazon-bedrock",
  247. },
  248. })
  249. expect(ProviderTransform.providerOptions(model, { cachePoint: { type: "default" } })).toEqual({
  250. bedrock: { cachePoint: { type: "default" } },
  251. })
  252. })
  253. test("uses gateway model provider slug for gateway models", () => {
  254. const model = createModel({
  255. providerID: "vercel",
  256. api: {
  257. id: "anthropic/claude-sonnet-4",
  258. url: "https://ai-gateway.vercel.sh/v3/ai",
  259. npm: "@ai-sdk/gateway",
  260. },
  261. })
  262. expect(ProviderTransform.providerOptions(model, { thinking: { type: "enabled", budgetTokens: 12_000 } })).toEqual({
  263. anthropic: { thinking: { type: "enabled", budgetTokens: 12_000 } },
  264. })
  265. })
  266. test("falls back to gateway key when gateway api id is unscoped", () => {
  267. const model = createModel({
  268. id: "anthropic/claude-sonnet-4",
  269. providerID: "vercel",
  270. api: {
  271. id: "claude-sonnet-4",
  272. url: "https://ai-gateway.vercel.sh/v3/ai",
  273. npm: "@ai-sdk/gateway",
  274. },
  275. })
  276. expect(ProviderTransform.providerOptions(model, { thinking: { type: "enabled", budgetTokens: 12_000 } })).toEqual({
  277. gateway: { thinking: { type: "enabled", budgetTokens: 12_000 } },
  278. })
  279. })
  280. test("splits gateway routing options from provider-specific options", () => {
  281. const model = createModel({
  282. providerID: "vercel",
  283. api: {
  284. id: "anthropic/claude-sonnet-4",
  285. url: "https://ai-gateway.vercel.sh/v3/ai",
  286. npm: "@ai-sdk/gateway",
  287. },
  288. })
  289. expect(
  290. ProviderTransform.providerOptions(model, {
  291. gateway: { order: ["vertex", "anthropic"] },
  292. thinking: { type: "enabled", budgetTokens: 12_000 },
  293. }),
  294. ).toEqual({
  295. gateway: { order: ["vertex", "anthropic"] },
  296. anthropic: { thinking: { type: "enabled", budgetTokens: 12_000 } },
  297. } as any)
  298. })
  299. test("falls back to gateway key when model id has no provider slug", () => {
  300. const model = createModel({
  301. id: "claude-sonnet-4",
  302. providerID: "vercel",
  303. api: {
  304. id: "claude-sonnet-4",
  305. url: "https://ai-gateway.vercel.sh/v3/ai",
  306. npm: "@ai-sdk/gateway",
  307. },
  308. })
  309. expect(ProviderTransform.providerOptions(model, { reasoningEffort: "high" })).toEqual({
  310. gateway: { reasoningEffort: "high" },
  311. })
  312. })
  313. test("maps amazon slug to bedrock for provider options", () => {
  314. const model = createModel({
  315. providerID: "vercel",
  316. api: {
  317. id: "amazon/nova-2-lite",
  318. url: "https://ai-gateway.vercel.sh/v3/ai",
  319. npm: "@ai-sdk/gateway",
  320. },
  321. })
  322. expect(ProviderTransform.providerOptions(model, { reasoningConfig: { type: "enabled" } })).toEqual({
  323. bedrock: { reasoningConfig: { type: "enabled" } },
  324. })
  325. })
  326. test("uses groq slug for groq models", () => {
  327. const model = createModel({
  328. providerID: "vercel",
  329. api: {
  330. id: "groq/llama-3.3-70b-versatile",
  331. url: "https://ai-gateway.vercel.sh/v3/ai",
  332. npm: "@ai-sdk/gateway",
  333. },
  334. })
  335. expect(ProviderTransform.providerOptions(model, { reasoningFormat: "parsed" })).toEqual({
  336. groq: { reasoningFormat: "parsed" },
  337. })
  338. })
  339. })
  340. describe("ProviderTransform.schema - gemini array items", () => {
  341. test("adds missing items for array properties", () => {
  342. const geminiModel = {
  343. providerID: "google",
  344. api: {
  345. id: "gemini-3-pro",
  346. },
  347. } as any
  348. const schema = {
  349. type: "object",
  350. properties: {
  351. nodes: { type: "array" },
  352. edges: { type: "array", items: { type: "string" } },
  353. },
  354. } as any
  355. const result = ProviderTransform.schema(geminiModel, schema) as any
  356. expect(result.properties.nodes.items).toBeDefined()
  357. expect(result.properties.edges.items.type).toBe("string")
  358. })
  359. })
  360. describe("ProviderTransform.schema - gemini nested array items", () => {
  361. const geminiModel = {
  362. providerID: "google",
  363. api: {
  364. id: "gemini-3-pro",
  365. },
  366. } as any
  367. test("adds type to 2D array with empty inner items", () => {
  368. const schema = {
  369. type: "object",
  370. properties: {
  371. values: {
  372. type: "array",
  373. items: {
  374. type: "array",
  375. items: {}, // Empty items object
  376. },
  377. },
  378. },
  379. } as any
  380. const result = ProviderTransform.schema(geminiModel, schema) as any
  381. // Inner items should have a default type
  382. expect(result.properties.values.items.items.type).toBe("string")
  383. })
  384. test("adds items and type to 2D array with missing inner items", () => {
  385. const schema = {
  386. type: "object",
  387. properties: {
  388. data: {
  389. type: "array",
  390. items: { type: "array" }, // No items at all
  391. },
  392. },
  393. } as any
  394. const result = ProviderTransform.schema(geminiModel, schema) as any
  395. expect(result.properties.data.items.items).toBeDefined()
  396. expect(result.properties.data.items.items.type).toBe("string")
  397. })
  398. test("handles deeply nested arrays (3D)", () => {
  399. const schema = {
  400. type: "object",
  401. properties: {
  402. matrix: {
  403. type: "array",
  404. items: {
  405. type: "array",
  406. items: {
  407. type: "array",
  408. // No items
  409. },
  410. },
  411. },
  412. },
  413. } as any
  414. const result = ProviderTransform.schema(geminiModel, schema) as any
  415. expect(result.properties.matrix.items.items.items).toBeDefined()
  416. expect(result.properties.matrix.items.items.items.type).toBe("string")
  417. })
  418. test("preserves existing item types in nested arrays", () => {
  419. const schema = {
  420. type: "object",
  421. properties: {
  422. numbers: {
  423. type: "array",
  424. items: {
  425. type: "array",
  426. items: { type: "number" }, // Has explicit type
  427. },
  428. },
  429. },
  430. } as any
  431. const result = ProviderTransform.schema(geminiModel, schema) as any
  432. // Should preserve the explicit type
  433. expect(result.properties.numbers.items.items.type).toBe("number")
  434. })
  435. test("handles mixed nested structures with objects and arrays", () => {
  436. const schema = {
  437. type: "object",
  438. properties: {
  439. spreadsheetData: {
  440. type: "object",
  441. properties: {
  442. rows: {
  443. type: "array",
  444. items: {
  445. type: "array",
  446. items: {}, // Empty items
  447. },
  448. },
  449. },
  450. },
  451. },
  452. } as any
  453. const result = ProviderTransform.schema(geminiModel, schema) as any
  454. expect(result.properties.spreadsheetData.properties.rows.items.items.type).toBe("string")
  455. })
  456. })
  457. describe("ProviderTransform.schema - gemini combiner nodes", () => {
  458. const geminiModel = {
  459. providerID: "google",
  460. api: {
  461. id: "gemini-3-pro",
  462. },
  463. } as any
  464. const walk = (node: any, cb: (node: any, path: (string | number)[]) => void, path: (string | number)[] = []) => {
  465. if (node === null || typeof node !== "object") {
  466. return
  467. }
  468. if (Array.isArray(node)) {
  469. node.forEach((item, i) => walk(item, cb, [...path, i]))
  470. return
  471. }
  472. cb(node, path)
  473. Object.entries(node).forEach(([key, value]) => walk(value, cb, [...path, key]))
  474. }
  475. test("keeps edits.items.anyOf without adding type", () => {
  476. const schema = {
  477. type: "object",
  478. properties: {
  479. edits: {
  480. type: "array",
  481. items: {
  482. anyOf: [
  483. {
  484. type: "object",
  485. properties: {
  486. old_string: { type: "string" },
  487. new_string: { type: "string" },
  488. },
  489. required: ["old_string", "new_string"],
  490. },
  491. {
  492. type: "object",
  493. properties: {
  494. old_string: { type: "string" },
  495. new_string: { type: "string" },
  496. replace_all: { type: "boolean" },
  497. },
  498. required: ["old_string", "new_string"],
  499. },
  500. ],
  501. },
  502. },
  503. },
  504. required: ["edits"],
  505. } as any
  506. const result = ProviderTransform.schema(geminiModel, schema) as any
  507. expect(Array.isArray(result.properties.edits.items.anyOf)).toBe(true)
  508. expect(result.properties.edits.items.type).toBeUndefined()
  509. })
  510. test("does not add sibling keys to combiner nodes during sanitize", () => {
  511. const schema = {
  512. type: "object",
  513. properties: {
  514. edits: {
  515. type: "array",
  516. items: {
  517. anyOf: [{ type: "string" }, { type: "number" }],
  518. },
  519. },
  520. value: {
  521. oneOf: [{ type: "string" }, { type: "boolean" }],
  522. },
  523. meta: {
  524. allOf: [
  525. {
  526. type: "object",
  527. properties: { a: { type: "string" } },
  528. },
  529. {
  530. type: "object",
  531. properties: { b: { type: "string" } },
  532. },
  533. ],
  534. },
  535. },
  536. } as any
  537. const input = JSON.parse(JSON.stringify(schema))
  538. const result = ProviderTransform.schema(geminiModel, schema) as any
  539. walk(result, (node, path) => {
  540. const hasCombiner = Array.isArray(node.anyOf) || Array.isArray(node.oneOf) || Array.isArray(node.allOf)
  541. if (!hasCombiner) {
  542. return
  543. }
  544. const before = path.reduce((acc: any, key) => acc?.[key], input)
  545. const added = Object.keys(node).filter((key) => !(key in before))
  546. expect(added).toEqual([])
  547. })
  548. })
  549. })
  550. describe("ProviderTransform.schema - gemini non-object properties removal", () => {
  551. const geminiModel = {
  552. providerID: "google",
  553. api: {
  554. id: "gemini-3-pro",
  555. },
  556. } as any
  557. test("removes properties from non-object types", () => {
  558. const schema = {
  559. type: "object",
  560. properties: {
  561. data: {
  562. type: "string",
  563. properties: { invalid: { type: "string" } },
  564. },
  565. },
  566. } as any
  567. const result = ProviderTransform.schema(geminiModel, schema) as any
  568. expect(result.properties.data.type).toBe("string")
  569. expect(result.properties.data.properties).toBeUndefined()
  570. })
  571. test("removes required from non-object types", () => {
  572. const schema = {
  573. type: "object",
  574. properties: {
  575. data: {
  576. type: "array",
  577. items: { type: "string" },
  578. required: ["invalid"],
  579. },
  580. },
  581. } as any
  582. const result = ProviderTransform.schema(geminiModel, schema) as any
  583. expect(result.properties.data.type).toBe("array")
  584. expect(result.properties.data.required).toBeUndefined()
  585. })
  586. test("removes properties and required from nested non-object types", () => {
  587. const schema = {
  588. type: "object",
  589. properties: {
  590. outer: {
  591. type: "object",
  592. properties: {
  593. inner: {
  594. type: "number",
  595. properties: { bad: { type: "string" } },
  596. required: ["bad"],
  597. },
  598. },
  599. },
  600. },
  601. } as any
  602. const result = ProviderTransform.schema(geminiModel, schema) as any
  603. expect(result.properties.outer.properties.inner.type).toBe("number")
  604. expect(result.properties.outer.properties.inner.properties).toBeUndefined()
  605. expect(result.properties.outer.properties.inner.required).toBeUndefined()
  606. })
  607. test("keeps properties and required on object types", () => {
  608. const schema = {
  609. type: "object",
  610. properties: {
  611. data: {
  612. type: "object",
  613. properties: { name: { type: "string" } },
  614. required: ["name"],
  615. },
  616. },
  617. } as any
  618. const result = ProviderTransform.schema(geminiModel, schema) as any
  619. expect(result.properties.data.type).toBe("object")
  620. expect(result.properties.data.properties).toBeDefined()
  621. expect(result.properties.data.required).toEqual(["name"])
  622. })
  623. test("does not affect non-gemini providers", () => {
  624. const openaiModel = {
  625. providerID: "openai",
  626. api: {
  627. id: "gpt-4",
  628. },
  629. } as any
  630. const schema = {
  631. type: "object",
  632. properties: {
  633. data: {
  634. type: "string",
  635. properties: { invalid: { type: "string" } },
  636. },
  637. },
  638. } as any
  639. const result = ProviderTransform.schema(openaiModel, schema) as any
  640. expect(result.properties.data.properties).toBeDefined()
  641. })
  642. })
  643. describe("ProviderTransform.message - DeepSeek reasoning content", () => {
  644. test("DeepSeek with tool calls includes reasoning_content in providerOptions", () => {
  645. const msgs = [
  646. {
  647. role: "assistant",
  648. content: [
  649. { type: "reasoning", text: "Let me think about this..." },
  650. {
  651. type: "tool-call",
  652. toolCallId: "test",
  653. toolName: "bash",
  654. input: { command: "echo hello" },
  655. },
  656. ],
  657. },
  658. ] as any[]
  659. const result = ProviderTransform.message(
  660. msgs,
  661. {
  662. id: ModelID.make("deepseek/deepseek-chat"),
  663. providerID: ProviderID.make("deepseek"),
  664. api: {
  665. id: "deepseek-chat",
  666. url: "https://api.deepseek.com",
  667. npm: "@ai-sdk/openai-compatible",
  668. },
  669. name: "DeepSeek Chat",
  670. capabilities: {
  671. temperature: true,
  672. reasoning: true,
  673. attachment: false,
  674. toolcall: true,
  675. input: { text: true, audio: false, image: false, video: false, pdf: false },
  676. output: { text: true, audio: false, image: false, video: false, pdf: false },
  677. interleaved: {
  678. field: "reasoning_content",
  679. },
  680. },
  681. cost: {
  682. input: 0.001,
  683. output: 0.002,
  684. cache: { read: 0.0001, write: 0.0002 },
  685. },
  686. limit: {
  687. context: 128000,
  688. output: 8192,
  689. },
  690. status: "active",
  691. options: {},
  692. headers: {},
  693. release_date: "2023-04-01",
  694. },
  695. {},
  696. )
  697. expect(result).toHaveLength(1)
  698. expect(result[0].content).toEqual([
  699. {
  700. type: "tool-call",
  701. toolCallId: "test",
  702. toolName: "bash",
  703. input: { command: "echo hello" },
  704. },
  705. ])
  706. expect(result[0].providerOptions?.openaiCompatible?.reasoning_content).toBe("Let me think about this...")
  707. })
  708. test("Non-DeepSeek providers leave reasoning content unchanged", () => {
  709. const msgs = [
  710. {
  711. role: "assistant",
  712. content: [
  713. { type: "reasoning", text: "Should not be processed" },
  714. { type: "text", text: "Answer" },
  715. ],
  716. },
  717. ] as any[]
  718. const result = ProviderTransform.message(
  719. msgs,
  720. {
  721. id: ModelID.make("openai/gpt-4"),
  722. providerID: ProviderID.make("openai"),
  723. api: {
  724. id: "gpt-4",
  725. url: "https://api.openai.com",
  726. npm: "@ai-sdk/openai",
  727. },
  728. name: "GPT-4",
  729. capabilities: {
  730. temperature: true,
  731. reasoning: false,
  732. attachment: true,
  733. toolcall: true,
  734. input: { text: true, audio: false, image: true, video: false, pdf: false },
  735. output: { text: true, audio: false, image: false, video: false, pdf: false },
  736. interleaved: false,
  737. },
  738. cost: {
  739. input: 0.03,
  740. output: 0.06,
  741. cache: { read: 0.001, write: 0.002 },
  742. },
  743. limit: {
  744. context: 128000,
  745. output: 4096,
  746. },
  747. status: "active",
  748. options: {},
  749. headers: {},
  750. release_date: "2023-04-01",
  751. },
  752. {},
  753. )
  754. expect(result[0].content).toEqual([
  755. { type: "reasoning", text: "Should not be processed" },
  756. { type: "text", text: "Answer" },
  757. ])
  758. expect(result[0].providerOptions?.openaiCompatible?.reasoning_content).toBeUndefined()
  759. })
  760. })
  761. describe("ProviderTransform.message - empty image handling", () => {
  762. const mockModel = {
  763. id: "anthropic/claude-3-5-sonnet",
  764. providerID: "anthropic",
  765. api: {
  766. id: "claude-3-5-sonnet-20241022",
  767. url: "https://api.anthropic.com",
  768. npm: "@ai-sdk/anthropic",
  769. },
  770. name: "Claude 3.5 Sonnet",
  771. capabilities: {
  772. temperature: true,
  773. reasoning: false,
  774. attachment: true,
  775. toolcall: true,
  776. input: { text: true, audio: false, image: true, video: false, pdf: true },
  777. output: { text: true, audio: false, image: false, video: false, pdf: false },
  778. interleaved: false,
  779. },
  780. cost: {
  781. input: 0.003,
  782. output: 0.015,
  783. cache: { read: 0.0003, write: 0.00375 },
  784. },
  785. limit: {
  786. context: 200000,
  787. output: 8192,
  788. },
  789. status: "active",
  790. options: {},
  791. headers: {},
  792. } as any
  793. test("should replace empty base64 image with error text", () => {
  794. const msgs = [
  795. {
  796. role: "user",
  797. content: [
  798. { type: "text", text: "What is in this image?" },
  799. { type: "image", image: "data:image/png;base64," },
  800. ],
  801. },
  802. ] as any[]
  803. const result = ProviderTransform.message(msgs, mockModel, {})
  804. expect(result).toHaveLength(1)
  805. expect(result[0].content).toHaveLength(2)
  806. expect(result[0].content[0]).toEqual({ type: "text", text: "What is in this image?" })
  807. expect(result[0].content[1]).toEqual({
  808. type: "text",
  809. text: "ERROR: Image file is empty or corrupted. Please provide a valid image.",
  810. })
  811. })
  812. test("should keep valid base64 images unchanged", () => {
  813. const validBase64 =
  814. "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg=="
  815. const msgs = [
  816. {
  817. role: "user",
  818. content: [
  819. { type: "text", text: "What is in this image?" },
  820. { type: "image", image: `data:image/png;base64,${validBase64}` },
  821. ],
  822. },
  823. ] as any[]
  824. const result = ProviderTransform.message(msgs, mockModel, {})
  825. expect(result).toHaveLength(1)
  826. expect(result[0].content).toHaveLength(2)
  827. expect(result[0].content[0]).toEqual({ type: "text", text: "What is in this image?" })
  828. expect(result[0].content[1]).toEqual({ type: "image", image: `data:image/png;base64,${validBase64}` })
  829. })
  830. test("should handle mixed valid and empty images", () => {
  831. const validBase64 =
  832. "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg=="
  833. const msgs = [
  834. {
  835. role: "user",
  836. content: [
  837. { type: "text", text: "Compare these images" },
  838. { type: "image", image: `data:image/png;base64,${validBase64}` },
  839. { type: "image", image: "data:image/jpeg;base64," },
  840. ],
  841. },
  842. ] as any[]
  843. const result = ProviderTransform.message(msgs, mockModel, {})
  844. expect(result).toHaveLength(1)
  845. expect(result[0].content).toHaveLength(3)
  846. expect(result[0].content[0]).toEqual({ type: "text", text: "Compare these images" })
  847. expect(result[0].content[1]).toEqual({ type: "image", image: `data:image/png;base64,${validBase64}` })
  848. expect(result[0].content[2]).toEqual({
  849. type: "text",
  850. text: "ERROR: Image file is empty or corrupted. Please provide a valid image.",
  851. })
  852. })
  853. })
  854. describe("ProviderTransform.message - anthropic empty content filtering", () => {
  855. const anthropicModel = {
  856. id: "anthropic/claude-3-5-sonnet",
  857. providerID: "anthropic",
  858. api: {
  859. id: "claude-3-5-sonnet-20241022",
  860. url: "https://api.anthropic.com",
  861. npm: "@ai-sdk/anthropic",
  862. },
  863. name: "Claude 3.5 Sonnet",
  864. capabilities: {
  865. temperature: true,
  866. reasoning: false,
  867. attachment: true,
  868. toolcall: true,
  869. input: { text: true, audio: false, image: true, video: false, pdf: true },
  870. output: { text: true, audio: false, image: false, video: false, pdf: false },
  871. interleaved: false,
  872. },
  873. cost: {
  874. input: 0.003,
  875. output: 0.015,
  876. cache: { read: 0.0003, write: 0.00375 },
  877. },
  878. limit: {
  879. context: 200000,
  880. output: 8192,
  881. },
  882. status: "active",
  883. options: {},
  884. headers: {},
  885. } as any
  886. test("filters out messages with empty string content", () => {
  887. const msgs = [
  888. { role: "user", content: "Hello" },
  889. { role: "assistant", content: "" },
  890. { role: "user", content: "World" },
  891. ] as any[]
  892. const result = ProviderTransform.message(msgs, anthropicModel, {})
  893. expect(result).toHaveLength(2)
  894. expect(result[0].content).toBe("Hello")
  895. expect(result[1].content).toBe("World")
  896. })
  897. test("filters out empty text parts from array content", () => {
  898. const msgs = [
  899. {
  900. role: "assistant",
  901. content: [
  902. { type: "text", text: "" },
  903. { type: "text", text: "Hello" },
  904. { type: "text", text: "" },
  905. ],
  906. },
  907. ] as any[]
  908. const result = ProviderTransform.message(msgs, anthropicModel, {})
  909. expect(result).toHaveLength(1)
  910. expect(result[0].content).toHaveLength(1)
  911. expect(result[0].content[0]).toEqual({ type: "text", text: "Hello" })
  912. })
  913. test("filters out empty reasoning parts from array content", () => {
  914. const msgs = [
  915. {
  916. role: "assistant",
  917. content: [
  918. { type: "reasoning", text: "" },
  919. { type: "text", text: "Answer" },
  920. { type: "reasoning", text: "" },
  921. ],
  922. },
  923. ] as any[]
  924. const result = ProviderTransform.message(msgs, anthropicModel, {})
  925. expect(result).toHaveLength(1)
  926. expect(result[0].content).toHaveLength(1)
  927. expect(result[0].content[0]).toEqual({ type: "text", text: "Answer" })
  928. })
  929. test("removes entire message when all parts are empty", () => {
  930. const msgs = [
  931. { role: "user", content: "Hello" },
  932. {
  933. role: "assistant",
  934. content: [
  935. { type: "text", text: "" },
  936. { type: "reasoning", text: "" },
  937. ],
  938. },
  939. { role: "user", content: "World" },
  940. ] as any[]
  941. const result = ProviderTransform.message(msgs, anthropicModel, {})
  942. expect(result).toHaveLength(2)
  943. expect(result[0].content).toBe("Hello")
  944. expect(result[1].content).toBe("World")
  945. })
  946. test("keeps non-text/reasoning parts even if text parts are empty", () => {
  947. const msgs = [
  948. {
  949. role: "assistant",
  950. content: [
  951. { type: "text", text: "" },
  952. { type: "tool-call", toolCallId: "123", toolName: "bash", input: { command: "ls" } },
  953. ],
  954. },
  955. ] as any[]
  956. const result = ProviderTransform.message(msgs, anthropicModel, {})
  957. expect(result).toHaveLength(1)
  958. expect(result[0].content).toHaveLength(1)
  959. expect(result[0].content[0]).toEqual({
  960. type: "tool-call",
  961. toolCallId: "123",
  962. toolName: "bash",
  963. input: { command: "ls" },
  964. })
  965. })
  966. test("keeps messages with valid text alongside empty parts", () => {
  967. const msgs = [
  968. {
  969. role: "assistant",
  970. content: [
  971. { type: "reasoning", text: "Thinking..." },
  972. { type: "text", text: "" },
  973. { type: "text", text: "Result" },
  974. ],
  975. },
  976. ] as any[]
  977. const result = ProviderTransform.message(msgs, anthropicModel, {})
  978. expect(result).toHaveLength(1)
  979. expect(result[0].content).toHaveLength(2)
  980. expect(result[0].content[0]).toEqual({ type: "reasoning", text: "Thinking..." })
  981. expect(result[0].content[1]).toEqual({ type: "text", text: "Result" })
  982. })
  983. test("does not filter for non-anthropic providers", () => {
  984. const openaiModel = {
  985. ...anthropicModel,
  986. providerID: "openai",
  987. api: {
  988. id: "gpt-4",
  989. url: "https://api.openai.com",
  990. npm: "@ai-sdk/openai",
  991. },
  992. }
  993. const msgs = [
  994. { role: "assistant", content: "" },
  995. {
  996. role: "assistant",
  997. content: [{ type: "text", text: "" }],
  998. },
  999. ] as any[]
  1000. const result = ProviderTransform.message(msgs, openaiModel, {})
  1001. expect(result).toHaveLength(2)
  1002. expect(result[0].content).toBe("")
  1003. expect(result[1].content).toHaveLength(1)
  1004. })
  1005. })
  1006. describe("ProviderTransform.message - strip openai metadata when store=false", () => {
  1007. const openaiModel = {
  1008. id: "openai/gpt-5",
  1009. providerID: "openai",
  1010. api: {
  1011. id: "gpt-5",
  1012. url: "https://api.openai.com",
  1013. npm: "@ai-sdk/openai",
  1014. },
  1015. name: "GPT-5",
  1016. capabilities: {
  1017. temperature: true,
  1018. reasoning: true,
  1019. attachment: true,
  1020. toolcall: true,
  1021. input: { text: true, audio: false, image: true, video: false, pdf: false },
  1022. output: { text: true, audio: false, image: false, video: false, pdf: false },
  1023. interleaved: false,
  1024. },
  1025. cost: { input: 0.03, output: 0.06, cache: { read: 0.001, write: 0.002 } },
  1026. limit: { context: 128000, output: 4096 },
  1027. status: "active",
  1028. options: {},
  1029. headers: {},
  1030. } as any
  1031. test("preserves itemId and reasoningEncryptedContent when store=false", () => {
  1032. const msgs = [
  1033. {
  1034. role: "assistant",
  1035. content: [
  1036. {
  1037. type: "reasoning",
  1038. text: "thinking...",
  1039. providerOptions: {
  1040. openai: {
  1041. itemId: "rs_123",
  1042. reasoningEncryptedContent: "encrypted",
  1043. },
  1044. },
  1045. },
  1046. {
  1047. type: "text",
  1048. text: "Hello",
  1049. providerOptions: {
  1050. openai: {
  1051. itemId: "msg_456",
  1052. },
  1053. },
  1054. },
  1055. ],
  1056. },
  1057. ] as any[]
  1058. const result = ProviderTransform.message(msgs, openaiModel, { store: false }) as any[]
  1059. expect(result).toHaveLength(1)
  1060. expect(result[0].content[0].providerOptions?.openai?.itemId).toBe("rs_123")
  1061. expect(result[0].content[1].providerOptions?.openai?.itemId).toBe("msg_456")
  1062. })
  1063. test("preserves itemId and reasoningEncryptedContent when store=false even when not openai", () => {
  1064. const zenModel = {
  1065. ...openaiModel,
  1066. providerID: "zen",
  1067. }
  1068. const msgs = [
  1069. {
  1070. role: "assistant",
  1071. content: [
  1072. {
  1073. type: "reasoning",
  1074. text: "thinking...",
  1075. providerOptions: {
  1076. openai: {
  1077. itemId: "rs_123",
  1078. reasoningEncryptedContent: "encrypted",
  1079. },
  1080. },
  1081. },
  1082. {
  1083. type: "text",
  1084. text: "Hello",
  1085. providerOptions: {
  1086. openai: {
  1087. itemId: "msg_456",
  1088. },
  1089. },
  1090. },
  1091. ],
  1092. },
  1093. ] as any[]
  1094. const result = ProviderTransform.message(msgs, zenModel, { store: false }) as any[]
  1095. expect(result).toHaveLength(1)
  1096. expect(result[0].content[0].providerOptions?.openai?.itemId).toBe("rs_123")
  1097. expect(result[0].content[1].providerOptions?.openai?.itemId).toBe("msg_456")
  1098. })
  1099. test("preserves other openai options including itemId", () => {
  1100. const msgs = [
  1101. {
  1102. role: "assistant",
  1103. content: [
  1104. {
  1105. type: "text",
  1106. text: "Hello",
  1107. providerOptions: {
  1108. openai: {
  1109. itemId: "msg_123",
  1110. otherOption: "value",
  1111. },
  1112. },
  1113. },
  1114. ],
  1115. },
  1116. ] as any[]
  1117. const result = ProviderTransform.message(msgs, openaiModel, { store: false }) as any[]
  1118. expect(result[0].content[0].providerOptions?.openai?.itemId).toBe("msg_123")
  1119. expect(result[0].content[0].providerOptions?.openai?.otherOption).toBe("value")
  1120. })
  1121. test("preserves metadata for openai package when store is true", () => {
  1122. const msgs = [
  1123. {
  1124. role: "assistant",
  1125. content: [
  1126. {
  1127. type: "text",
  1128. text: "Hello",
  1129. providerOptions: {
  1130. openai: {
  1131. itemId: "msg_123",
  1132. },
  1133. },
  1134. },
  1135. ],
  1136. },
  1137. ] as any[]
  1138. // openai package preserves itemId regardless of store value
  1139. const result = ProviderTransform.message(msgs, openaiModel, { store: true }) as any[]
  1140. expect(result[0].content[0].providerOptions?.openai?.itemId).toBe("msg_123")
  1141. })
  1142. test("preserves metadata for non-openai packages when store is false", () => {
  1143. const anthropicModel = {
  1144. ...openaiModel,
  1145. providerID: "anthropic",
  1146. api: {
  1147. id: "claude-3",
  1148. url: "https://api.anthropic.com",
  1149. npm: "@ai-sdk/anthropic",
  1150. },
  1151. }
  1152. const msgs = [
  1153. {
  1154. role: "assistant",
  1155. content: [
  1156. {
  1157. type: "text",
  1158. text: "Hello",
  1159. providerOptions: {
  1160. openai: {
  1161. itemId: "msg_123",
  1162. },
  1163. },
  1164. },
  1165. ],
  1166. },
  1167. ] as any[]
  1168. // store=false preserves metadata for non-openai packages
  1169. const result = ProviderTransform.message(msgs, anthropicModel, { store: false }) as any[]
  1170. expect(result[0].content[0].providerOptions?.openai?.itemId).toBe("msg_123")
  1171. })
  1172. test("preserves metadata using providerID key when store is false", () => {
  1173. const opencodeModel = {
  1174. ...openaiModel,
  1175. providerID: "opencode",
  1176. api: {
  1177. id: "opencode-test",
  1178. url: "https://api.opencode.ai",
  1179. npm: "@ai-sdk/openai-compatible",
  1180. },
  1181. }
  1182. const msgs = [
  1183. {
  1184. role: "assistant",
  1185. content: [
  1186. {
  1187. type: "text",
  1188. text: "Hello",
  1189. providerOptions: {
  1190. opencode: {
  1191. itemId: "msg_123",
  1192. otherOption: "value",
  1193. },
  1194. },
  1195. },
  1196. ],
  1197. },
  1198. ] as any[]
  1199. const result = ProviderTransform.message(msgs, opencodeModel, { store: false }) as any[]
  1200. expect(result[0].content[0].providerOptions?.opencode?.itemId).toBe("msg_123")
  1201. expect(result[0].content[0].providerOptions?.opencode?.otherOption).toBe("value")
  1202. })
  1203. test("preserves itemId across all providerOptions keys", () => {
  1204. const opencodeModel = {
  1205. ...openaiModel,
  1206. providerID: "opencode",
  1207. api: {
  1208. id: "opencode-test",
  1209. url: "https://api.opencode.ai",
  1210. npm: "@ai-sdk/openai-compatible",
  1211. },
  1212. }
  1213. const msgs = [
  1214. {
  1215. role: "assistant",
  1216. providerOptions: {
  1217. openai: { itemId: "msg_root" },
  1218. opencode: { itemId: "msg_opencode" },
  1219. extra: { itemId: "msg_extra" },
  1220. },
  1221. content: [
  1222. {
  1223. type: "text",
  1224. text: "Hello",
  1225. providerOptions: {
  1226. openai: { itemId: "msg_openai_part" },
  1227. opencode: { itemId: "msg_opencode_part" },
  1228. extra: { itemId: "msg_extra_part" },
  1229. },
  1230. },
  1231. ],
  1232. },
  1233. ] as any[]
  1234. const result = ProviderTransform.message(msgs, opencodeModel, { store: false }) as any[]
  1235. expect(result[0].providerOptions?.openai?.itemId).toBe("msg_root")
  1236. expect(result[0].providerOptions?.opencode?.itemId).toBe("msg_opencode")
  1237. expect(result[0].providerOptions?.extra?.itemId).toBe("msg_extra")
  1238. expect(result[0].content[0].providerOptions?.openai?.itemId).toBe("msg_openai_part")
  1239. expect(result[0].content[0].providerOptions?.opencode?.itemId).toBe("msg_opencode_part")
  1240. expect(result[0].content[0].providerOptions?.extra?.itemId).toBe("msg_extra_part")
  1241. })
  1242. test("does not strip metadata for non-openai packages when store is not false", () => {
  1243. const anthropicModel = {
  1244. ...openaiModel,
  1245. providerID: "anthropic",
  1246. api: {
  1247. id: "claude-3",
  1248. url: "https://api.anthropic.com",
  1249. npm: "@ai-sdk/anthropic",
  1250. },
  1251. }
  1252. const msgs = [
  1253. {
  1254. role: "assistant",
  1255. content: [
  1256. {
  1257. type: "text",
  1258. text: "Hello",
  1259. providerOptions: {
  1260. openai: {
  1261. itemId: "msg_123",
  1262. },
  1263. },
  1264. },
  1265. ],
  1266. },
  1267. ] as any[]
  1268. const result = ProviderTransform.message(msgs, anthropicModel, {}) as any[]
  1269. expect(result[0].content[0].providerOptions?.openai?.itemId).toBe("msg_123")
  1270. })
  1271. })
  1272. describe("ProviderTransform.message - providerOptions key remapping", () => {
  1273. const createModel = (providerID: string, npm: string) =>
  1274. ({
  1275. id: `${providerID}/test-model`,
  1276. providerID,
  1277. api: {
  1278. id: "test-model",
  1279. url: "https://api.test.com",
  1280. npm,
  1281. },
  1282. name: "Test Model",
  1283. capabilities: {
  1284. temperature: true,
  1285. reasoning: false,
  1286. attachment: true,
  1287. toolcall: true,
  1288. input: { text: true, audio: false, image: true, video: false, pdf: true },
  1289. output: { text: true, audio: false, image: false, video: false, pdf: false },
  1290. interleaved: false,
  1291. },
  1292. cost: { input: 0.001, output: 0.002, cache: { read: 0.0001, write: 0.0002 } },
  1293. limit: { context: 128000, output: 8192 },
  1294. status: "active",
  1295. options: {},
  1296. headers: {},
  1297. }) as any
  1298. test("azure keeps 'azure' key and does not remap to 'openai'", () => {
  1299. const model = createModel("azure", "@ai-sdk/azure")
  1300. const msgs = [
  1301. {
  1302. role: "user",
  1303. content: "Hello",
  1304. providerOptions: {
  1305. azure: { someOption: "value" },
  1306. },
  1307. },
  1308. ] as any[]
  1309. const result = ProviderTransform.message(msgs, model, {})
  1310. expect(result[0].providerOptions?.azure).toEqual({ someOption: "value" })
  1311. expect(result[0].providerOptions?.openai).toBeUndefined()
  1312. })
  1313. test("copilot remaps providerID to 'copilot' key", () => {
  1314. const model = createModel("github-copilot", "@ai-sdk/github-copilot")
  1315. const msgs = [
  1316. {
  1317. role: "user",
  1318. content: "Hello",
  1319. providerOptions: {
  1320. copilot: { someOption: "value" },
  1321. },
  1322. },
  1323. ] as any[]
  1324. const result = ProviderTransform.message(msgs, model, {})
  1325. expect(result[0].providerOptions?.copilot).toEqual({ someOption: "value" })
  1326. expect(result[0].providerOptions?.["github-copilot"]).toBeUndefined()
  1327. })
  1328. test("bedrock remaps providerID to 'bedrock' key", () => {
  1329. const model = createModel("my-bedrock", "@ai-sdk/amazon-bedrock")
  1330. const msgs = [
  1331. {
  1332. role: "user",
  1333. content: "Hello",
  1334. providerOptions: {
  1335. "my-bedrock": { someOption: "value" },
  1336. },
  1337. },
  1338. ] as any[]
  1339. const result = ProviderTransform.message(msgs, model, {})
  1340. expect(result[0].providerOptions?.bedrock).toEqual({ someOption: "value" })
  1341. expect(result[0].providerOptions?.["my-bedrock"]).toBeUndefined()
  1342. })
  1343. })
  1344. describe("ProviderTransform.message - claude w/bedrock custom inference profile", () => {
  1345. test("adds cachePoint", () => {
  1346. const model = {
  1347. id: "amazon-bedrock/custom-claude-sonnet-4.5",
  1348. providerID: "amazon-bedrock",
  1349. api: {
  1350. id: "arn:aws:bedrock:xxx:yyy:application-inference-profile/zzz",
  1351. url: "https://api.test.com",
  1352. npm: "@ai-sdk/amazon-bedrock",
  1353. },
  1354. name: "Custom inference profile",
  1355. capabilities: {},
  1356. options: {},
  1357. headers: {},
  1358. } as any
  1359. const msgs = [
  1360. {
  1361. role: "user",
  1362. content: "Hello",
  1363. },
  1364. ] as any[]
  1365. const result = ProviderTransform.message(msgs, model, {})
  1366. expect(result[0].providerOptions?.bedrock).toEqual(
  1367. expect.objectContaining({
  1368. cachePoint: {
  1369. type: "default",
  1370. },
  1371. }),
  1372. )
  1373. })
  1374. })
  1375. describe("ProviderTransform.message - cache control on gateway", () => {
  1376. const createModel = (overrides: Partial<any> = {}) =>
  1377. ({
  1378. id: "anthropic/claude-sonnet-4",
  1379. providerID: "vercel",
  1380. api: {
  1381. id: "anthropic/claude-sonnet-4",
  1382. url: "https://ai-gateway.vercel.sh/v3/ai",
  1383. npm: "@ai-sdk/gateway",
  1384. },
  1385. name: "Claude Sonnet 4",
  1386. capabilities: {
  1387. temperature: true,
  1388. reasoning: true,
  1389. attachment: true,
  1390. toolcall: true,
  1391. input: { text: true, audio: false, image: true, video: false, pdf: true },
  1392. output: { text: true, audio: false, image: false, video: false, pdf: false },
  1393. interleaved: false,
  1394. },
  1395. cost: { input: 0.001, output: 0.002, cache: { read: 0.0001, write: 0.0002 } },
  1396. limit: { context: 200_000, output: 8192 },
  1397. status: "active",
  1398. options: {},
  1399. headers: {},
  1400. ...overrides,
  1401. }) as any
  1402. test("gateway does not set cache control for anthropic models", () => {
  1403. const model = createModel()
  1404. const msgs = [
  1405. {
  1406. role: "system",
  1407. content: [{ type: "text", text: "You are a helpful assistant" }],
  1408. },
  1409. {
  1410. role: "user",
  1411. content: "Hello",
  1412. },
  1413. ] as any[]
  1414. const result = ProviderTransform.message(msgs, model, {}) as any[]
  1415. expect(result[0].content[0].providerOptions).toBeUndefined()
  1416. expect(result[0].providerOptions).toBeUndefined()
  1417. })
  1418. test("non-gateway anthropic keeps existing cache control behavior", () => {
  1419. const model = createModel({
  1420. providerID: "anthropic",
  1421. api: {
  1422. id: "claude-sonnet-4",
  1423. url: "https://api.anthropic.com",
  1424. npm: "@ai-sdk/anthropic",
  1425. },
  1426. })
  1427. const msgs = [
  1428. {
  1429. role: "system",
  1430. content: "You are a helpful assistant",
  1431. },
  1432. {
  1433. role: "user",
  1434. content: "Hello",
  1435. },
  1436. ] as any[]
  1437. const result = ProviderTransform.message(msgs, model, {}) as any[]
  1438. expect(result[0].providerOptions).toEqual({
  1439. anthropic: {
  1440. cacheControl: {
  1441. type: "ephemeral",
  1442. },
  1443. },
  1444. openrouter: {
  1445. cacheControl: {
  1446. type: "ephemeral",
  1447. },
  1448. },
  1449. bedrock: {
  1450. cachePoint: {
  1451. type: "default",
  1452. },
  1453. },
  1454. openaiCompatible: {
  1455. cache_control: {
  1456. type: "ephemeral",
  1457. },
  1458. },
  1459. copilot: {
  1460. copilot_cache_control: {
  1461. type: "ephemeral",
  1462. },
  1463. },
  1464. })
  1465. })
  1466. })
  1467. describe("ProviderTransform.variants", () => {
  1468. const createMockModel = (overrides: Partial<any> = {}): any => ({
  1469. id: "test/test-model",
  1470. providerID: "test",
  1471. api: {
  1472. id: "test-model",
  1473. url: "https://api.test.com",
  1474. npm: "@ai-sdk/openai",
  1475. },
  1476. name: "Test Model",
  1477. capabilities: {
  1478. temperature: true,
  1479. reasoning: true,
  1480. attachment: true,
  1481. toolcall: true,
  1482. input: { text: true, audio: false, image: true, video: false, pdf: false },
  1483. output: { text: true, audio: false, image: false, video: false, pdf: false },
  1484. interleaved: false,
  1485. },
  1486. cost: {
  1487. input: 0.001,
  1488. output: 0.002,
  1489. cache: { read: 0.0001, write: 0.0002 },
  1490. },
  1491. limit: {
  1492. context: 200_000,
  1493. output: 64_000,
  1494. },
  1495. status: "active",
  1496. options: {},
  1497. headers: {},
  1498. release_date: "2024-01-01",
  1499. ...overrides,
  1500. })
  1501. test("returns empty object when model has no reasoning capabilities", () => {
  1502. const model = createMockModel({
  1503. capabilities: { reasoning: false },
  1504. })
  1505. const result = ProviderTransform.variants(model)
  1506. expect(result).toEqual({})
  1507. })
  1508. test("deepseek returns empty object", () => {
  1509. const model = createMockModel({
  1510. id: "deepseek/deepseek-chat",
  1511. providerID: "deepseek",
  1512. api: {
  1513. id: "deepseek-chat",
  1514. url: "https://api.deepseek.com",
  1515. npm: "@ai-sdk/openai-compatible",
  1516. },
  1517. })
  1518. const result = ProviderTransform.variants(model)
  1519. expect(result).toEqual({})
  1520. })
  1521. test("minimax returns empty object", () => {
  1522. const model = createMockModel({
  1523. id: "minimax/minimax-model",
  1524. providerID: "minimax",
  1525. api: {
  1526. id: "minimax-model",
  1527. url: "https://api.minimax.com",
  1528. npm: "@ai-sdk/openai-compatible",
  1529. },
  1530. })
  1531. const result = ProviderTransform.variants(model)
  1532. expect(result).toEqual({})
  1533. })
  1534. test("glm returns empty object", () => {
  1535. const model = createMockModel({
  1536. id: "glm/glm-4",
  1537. providerID: "glm",
  1538. api: {
  1539. id: "glm-4",
  1540. url: "https://api.glm.com",
  1541. npm: "@ai-sdk/openai-compatible",
  1542. },
  1543. })
  1544. const result = ProviderTransform.variants(model)
  1545. expect(result).toEqual({})
  1546. })
  1547. test("mistral returns empty object", () => {
  1548. const model = createMockModel({
  1549. id: "mistral/mistral-large",
  1550. providerID: "mistral",
  1551. api: {
  1552. id: "mistral-large-latest",
  1553. url: "https://api.mistral.com",
  1554. npm: "@ai-sdk/mistral",
  1555. },
  1556. })
  1557. const result = ProviderTransform.variants(model)
  1558. expect(result).toEqual({})
  1559. })
  1560. describe("@openrouter/ai-sdk-provider", () => {
  1561. test("returns empty object for non-qualifying models", () => {
  1562. const model = createMockModel({
  1563. id: "openrouter/test-model",
  1564. providerID: "openrouter",
  1565. api: {
  1566. id: "test-model",
  1567. url: "https://openrouter.ai",
  1568. npm: "@openrouter/ai-sdk-provider",
  1569. },
  1570. })
  1571. const result = ProviderTransform.variants(model)
  1572. expect(result).toEqual({})
  1573. })
  1574. test("gpt models return OPENAI_EFFORTS with reasoning", () => {
  1575. const model = createMockModel({
  1576. id: "openrouter/gpt-4",
  1577. providerID: "openrouter",
  1578. api: {
  1579. id: "gpt-4",
  1580. url: "https://openrouter.ai",
  1581. npm: "@openrouter/ai-sdk-provider",
  1582. },
  1583. })
  1584. const result = ProviderTransform.variants(model)
  1585. expect(Object.keys(result)).toEqual(["none", "minimal", "low", "medium", "high", "xhigh"])
  1586. expect(result.low).toEqual({ reasoning: { effort: "low" } })
  1587. expect(result.high).toEqual({ reasoning: { effort: "high" } })
  1588. })
  1589. test("gemini-3 returns OPENAI_EFFORTS with reasoning", () => {
  1590. const model = createMockModel({
  1591. id: "openrouter/gemini-3-5-pro",
  1592. providerID: "openrouter",
  1593. api: {
  1594. id: "gemini-3-5-pro",
  1595. url: "https://openrouter.ai",
  1596. npm: "@openrouter/ai-sdk-provider",
  1597. },
  1598. })
  1599. const result = ProviderTransform.variants(model)
  1600. expect(Object.keys(result)).toEqual(["none", "minimal", "low", "medium", "high", "xhigh"])
  1601. })
  1602. test("grok-4 returns empty object", () => {
  1603. const model = createMockModel({
  1604. id: "openrouter/grok-4",
  1605. providerID: "openrouter",
  1606. api: {
  1607. id: "grok-4",
  1608. url: "https://openrouter.ai",
  1609. npm: "@openrouter/ai-sdk-provider",
  1610. },
  1611. })
  1612. const result = ProviderTransform.variants(model)
  1613. expect(result).toEqual({})
  1614. })
  1615. test("grok-3-mini returns low and high with reasoning", () => {
  1616. const model = createMockModel({
  1617. id: "openrouter/grok-3-mini",
  1618. providerID: "openrouter",
  1619. api: {
  1620. id: "grok-3-mini",
  1621. url: "https://openrouter.ai",
  1622. npm: "@openrouter/ai-sdk-provider",
  1623. },
  1624. })
  1625. const result = ProviderTransform.variants(model)
  1626. expect(Object.keys(result)).toEqual(["low", "high"])
  1627. expect(result.low).toEqual({ reasoning: { effort: "low" } })
  1628. expect(result.high).toEqual({ reasoning: { effort: "high" } })
  1629. })
  1630. })
  1631. describe("@ai-sdk/gateway", () => {
  1632. test("anthropic sonnet 4.6 models return adaptive thinking options", () => {
  1633. const model = createMockModel({
  1634. id: "anthropic/claude-sonnet-4-6",
  1635. providerID: "gateway",
  1636. api: {
  1637. id: "anthropic/claude-sonnet-4-6",
  1638. url: "https://gateway.ai",
  1639. npm: "@ai-sdk/gateway",
  1640. },
  1641. })
  1642. const result = ProviderTransform.variants(model)
  1643. expect(Object.keys(result)).toEqual(["low", "medium", "high", "max"])
  1644. expect(result.medium).toEqual({
  1645. thinking: {
  1646. type: "adaptive",
  1647. },
  1648. effort: "medium",
  1649. })
  1650. })
  1651. test("anthropic sonnet 4.6 dot-format models return adaptive thinking options", () => {
  1652. const model = createMockModel({
  1653. id: "anthropic/claude-sonnet-4-6",
  1654. providerID: "gateway",
  1655. api: {
  1656. id: "anthropic/claude-sonnet-4.6",
  1657. url: "https://gateway.ai",
  1658. npm: "@ai-sdk/gateway",
  1659. },
  1660. })
  1661. const result = ProviderTransform.variants(model)
  1662. expect(Object.keys(result)).toEqual(["low", "medium", "high", "max"])
  1663. expect(result.medium).toEqual({
  1664. thinking: {
  1665. type: "adaptive",
  1666. },
  1667. effort: "medium",
  1668. })
  1669. })
  1670. test("anthropic opus 4.6 dot-format models return adaptive thinking options", () => {
  1671. const model = createMockModel({
  1672. id: "anthropic/claude-opus-4-6",
  1673. providerID: "gateway",
  1674. api: {
  1675. id: "anthropic/claude-opus-4.6",
  1676. url: "https://gateway.ai",
  1677. npm: "@ai-sdk/gateway",
  1678. },
  1679. })
  1680. const result = ProviderTransform.variants(model)
  1681. expect(Object.keys(result)).toEqual(["low", "medium", "high", "max"])
  1682. expect(result.high).toEqual({
  1683. thinking: {
  1684. type: "adaptive",
  1685. },
  1686. effort: "high",
  1687. })
  1688. })
  1689. test("anthropic models return anthropic thinking options", () => {
  1690. const model = createMockModel({
  1691. id: "anthropic/claude-sonnet-4",
  1692. providerID: "gateway",
  1693. api: {
  1694. id: "anthropic/claude-sonnet-4",
  1695. url: "https://gateway.ai",
  1696. npm: "@ai-sdk/gateway",
  1697. },
  1698. })
  1699. const result = ProviderTransform.variants(model)
  1700. expect(Object.keys(result)).toEqual(["high", "max"])
  1701. expect(result.high).toEqual({
  1702. thinking: {
  1703. type: "enabled",
  1704. budgetTokens: 16000,
  1705. },
  1706. })
  1707. expect(result.max).toEqual({
  1708. thinking: {
  1709. type: "enabled",
  1710. budgetTokens: 31999,
  1711. },
  1712. })
  1713. })
  1714. test("returns OPENAI_EFFORTS with reasoningEffort", () => {
  1715. const model = createMockModel({
  1716. id: "gateway/gateway-model",
  1717. providerID: "gateway",
  1718. api: {
  1719. id: "gateway-model",
  1720. url: "https://gateway.ai",
  1721. npm: "@ai-sdk/gateway",
  1722. },
  1723. })
  1724. const result = ProviderTransform.variants(model)
  1725. expect(Object.keys(result)).toEqual(["none", "minimal", "low", "medium", "high", "xhigh"])
  1726. expect(result.low).toEqual({ reasoningEffort: "low" })
  1727. expect(result.high).toEqual({ reasoningEffort: "high" })
  1728. })
  1729. })
  1730. describe("@ai-sdk/github-copilot", () => {
  1731. test("standard models return low, medium, high", () => {
  1732. const model = createMockModel({
  1733. id: "gpt-4.5",
  1734. providerID: "github-copilot",
  1735. api: {
  1736. id: "gpt-4.5",
  1737. url: "https://api.githubcopilot.com",
  1738. npm: "@ai-sdk/github-copilot",
  1739. },
  1740. })
  1741. const result = ProviderTransform.variants(model)
  1742. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  1743. expect(result.low).toEqual({
  1744. reasoningEffort: "low",
  1745. reasoningSummary: "auto",
  1746. include: ["reasoning.encrypted_content"],
  1747. })
  1748. })
  1749. test("gpt-5.1-codex-max includes xhigh", () => {
  1750. const model = createMockModel({
  1751. id: "gpt-5.1-codex-max",
  1752. providerID: "github-copilot",
  1753. api: {
  1754. id: "gpt-5.1-codex-max",
  1755. url: "https://api.githubcopilot.com",
  1756. npm: "@ai-sdk/github-copilot",
  1757. },
  1758. })
  1759. const result = ProviderTransform.variants(model)
  1760. expect(Object.keys(result)).toEqual(["low", "medium", "high", "xhigh"])
  1761. })
  1762. test("gpt-5.1-codex-mini does not include xhigh", () => {
  1763. const model = createMockModel({
  1764. id: "gpt-5.1-codex-mini",
  1765. providerID: "github-copilot",
  1766. api: {
  1767. id: "gpt-5.1-codex-mini",
  1768. url: "https://api.githubcopilot.com",
  1769. npm: "@ai-sdk/github-copilot",
  1770. },
  1771. })
  1772. const result = ProviderTransform.variants(model)
  1773. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  1774. })
  1775. test("gpt-5.1-codex does not include xhigh", () => {
  1776. const model = createMockModel({
  1777. id: "gpt-5.1-codex",
  1778. providerID: "github-copilot",
  1779. api: {
  1780. id: "gpt-5.1-codex",
  1781. url: "https://api.githubcopilot.com",
  1782. npm: "@ai-sdk/github-copilot",
  1783. },
  1784. })
  1785. const result = ProviderTransform.variants(model)
  1786. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  1787. })
  1788. test("gpt-5.2 includes xhigh", () => {
  1789. const model = createMockModel({
  1790. id: "gpt-5.2",
  1791. providerID: "github-copilot",
  1792. api: {
  1793. id: "gpt-5.2",
  1794. url: "https://api.githubcopilot.com",
  1795. npm: "@ai-sdk/github-copilot",
  1796. },
  1797. })
  1798. const result = ProviderTransform.variants(model)
  1799. expect(Object.keys(result)).toEqual(["low", "medium", "high", "xhigh"])
  1800. expect(result.xhigh).toEqual({
  1801. reasoningEffort: "xhigh",
  1802. reasoningSummary: "auto",
  1803. include: ["reasoning.encrypted_content"],
  1804. })
  1805. })
  1806. test("gpt-5.2-codex includes xhigh", () => {
  1807. const model = createMockModel({
  1808. id: "gpt-5.2-codex",
  1809. providerID: "github-copilot",
  1810. api: {
  1811. id: "gpt-5.2-codex",
  1812. url: "https://api.githubcopilot.com",
  1813. npm: "@ai-sdk/github-copilot",
  1814. },
  1815. })
  1816. const result = ProviderTransform.variants(model)
  1817. expect(Object.keys(result)).toEqual(["low", "medium", "high", "xhigh"])
  1818. })
  1819. test("gpt-5.3-codex includes xhigh", () => {
  1820. const model = createMockModel({
  1821. id: "gpt-5.3-codex",
  1822. providerID: "github-copilot",
  1823. api: {
  1824. id: "gpt-5.3-codex",
  1825. url: "https://api.githubcopilot.com",
  1826. npm: "@ai-sdk/github-copilot",
  1827. },
  1828. })
  1829. const result = ProviderTransform.variants(model)
  1830. expect(Object.keys(result)).toEqual(["low", "medium", "high", "xhigh"])
  1831. })
  1832. test("gpt-5.4 includes xhigh", () => {
  1833. const model = createMockModel({
  1834. id: "gpt-5.4",
  1835. release_date: "2026-03-05",
  1836. providerID: "github-copilot",
  1837. api: {
  1838. id: "gpt-5.4",
  1839. url: "https://api.githubcopilot.com",
  1840. npm: "@ai-sdk/github-copilot",
  1841. },
  1842. })
  1843. const result = ProviderTransform.variants(model)
  1844. expect(Object.keys(result)).toEqual(["low", "medium", "high", "xhigh"])
  1845. })
  1846. })
  1847. describe("@ai-sdk/cerebras", () => {
  1848. test("returns WIDELY_SUPPORTED_EFFORTS with reasoningEffort", () => {
  1849. const model = createMockModel({
  1850. id: "cerebras/llama-4",
  1851. providerID: "cerebras",
  1852. api: {
  1853. id: "llama-4-sc",
  1854. url: "https://api.cerebras.ai",
  1855. npm: "@ai-sdk/cerebras",
  1856. },
  1857. })
  1858. const result = ProviderTransform.variants(model)
  1859. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  1860. expect(result.low).toEqual({ reasoningEffort: "low" })
  1861. expect(result.high).toEqual({ reasoningEffort: "high" })
  1862. })
  1863. })
  1864. describe("@ai-sdk/togetherai", () => {
  1865. test("returns WIDELY_SUPPORTED_EFFORTS with reasoningEffort", () => {
  1866. const model = createMockModel({
  1867. id: "togetherai/llama-4",
  1868. providerID: "togetherai",
  1869. api: {
  1870. id: "llama-4-sc",
  1871. url: "https://api.togetherai.com",
  1872. npm: "@ai-sdk/togetherai",
  1873. },
  1874. })
  1875. const result = ProviderTransform.variants(model)
  1876. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  1877. expect(result.low).toEqual({ reasoningEffort: "low" })
  1878. expect(result.high).toEqual({ reasoningEffort: "high" })
  1879. })
  1880. })
  1881. describe("@ai-sdk/xai", () => {
  1882. test("grok-3 returns empty object", () => {
  1883. const model = createMockModel({
  1884. id: "xai/grok-3",
  1885. providerID: "xai",
  1886. api: {
  1887. id: "grok-3",
  1888. url: "https://api.x.ai",
  1889. npm: "@ai-sdk/xai",
  1890. },
  1891. })
  1892. const result = ProviderTransform.variants(model)
  1893. expect(result).toEqual({})
  1894. })
  1895. test("grok-3-mini returns low and high with reasoningEffort", () => {
  1896. const model = createMockModel({
  1897. id: "xai/grok-3-mini",
  1898. providerID: "xai",
  1899. api: {
  1900. id: "grok-3-mini",
  1901. url: "https://api.x.ai",
  1902. npm: "@ai-sdk/xai",
  1903. },
  1904. })
  1905. const result = ProviderTransform.variants(model)
  1906. expect(Object.keys(result)).toEqual(["low", "high"])
  1907. expect(result.low).toEqual({ reasoningEffort: "low" })
  1908. expect(result.high).toEqual({ reasoningEffort: "high" })
  1909. })
  1910. })
  1911. describe("@ai-sdk/deepinfra", () => {
  1912. test("returns WIDELY_SUPPORTED_EFFORTS with reasoningEffort", () => {
  1913. const model = createMockModel({
  1914. id: "deepinfra/llama-4",
  1915. providerID: "deepinfra",
  1916. api: {
  1917. id: "llama-4-sc",
  1918. url: "https://api.deepinfra.com",
  1919. npm: "@ai-sdk/deepinfra",
  1920. },
  1921. })
  1922. const result = ProviderTransform.variants(model)
  1923. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  1924. expect(result.low).toEqual({ reasoningEffort: "low" })
  1925. expect(result.high).toEqual({ reasoningEffort: "high" })
  1926. })
  1927. })
  1928. describe("@ai-sdk/openai-compatible", () => {
  1929. test("returns WIDELY_SUPPORTED_EFFORTS with reasoningEffort", () => {
  1930. const model = createMockModel({
  1931. id: "custom-provider/custom-model",
  1932. providerID: "custom-provider",
  1933. api: {
  1934. id: "custom-model",
  1935. url: "https://api.custom.com",
  1936. npm: "@ai-sdk/openai-compatible",
  1937. },
  1938. })
  1939. const result = ProviderTransform.variants(model)
  1940. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  1941. expect(result.low).toEqual({ reasoningEffort: "low" })
  1942. expect(result.high).toEqual({ reasoningEffort: "high" })
  1943. })
  1944. })
  1945. describe("@ai-sdk/azure", () => {
  1946. test("o1-mini returns empty object", () => {
  1947. const model = createMockModel({
  1948. id: "o1-mini",
  1949. providerID: "azure",
  1950. api: {
  1951. id: "o1-mini",
  1952. url: "https://azure.com",
  1953. npm: "@ai-sdk/azure",
  1954. },
  1955. })
  1956. const result = ProviderTransform.variants(model)
  1957. expect(result).toEqual({})
  1958. })
  1959. test("standard azure models return custom efforts with reasoningSummary", () => {
  1960. const model = createMockModel({
  1961. id: "o1",
  1962. providerID: "azure",
  1963. api: {
  1964. id: "o1",
  1965. url: "https://azure.com",
  1966. npm: "@ai-sdk/azure",
  1967. },
  1968. })
  1969. const result = ProviderTransform.variants(model)
  1970. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  1971. expect(result.low).toEqual({
  1972. reasoningEffort: "low",
  1973. reasoningSummary: "auto",
  1974. include: ["reasoning.encrypted_content"],
  1975. })
  1976. })
  1977. test("gpt-5 adds minimal effort", () => {
  1978. const model = createMockModel({
  1979. id: "gpt-5",
  1980. providerID: "azure",
  1981. api: {
  1982. id: "gpt-5",
  1983. url: "https://azure.com",
  1984. npm: "@ai-sdk/azure",
  1985. },
  1986. })
  1987. const result = ProviderTransform.variants(model)
  1988. expect(Object.keys(result)).toEqual(["minimal", "low", "medium", "high"])
  1989. })
  1990. })
  1991. describe("@ai-sdk/openai", () => {
  1992. test("gpt-5-pro returns empty object", () => {
  1993. const model = createMockModel({
  1994. id: "gpt-5-pro",
  1995. providerID: "openai",
  1996. api: {
  1997. id: "gpt-5-pro",
  1998. url: "https://api.openai.com",
  1999. npm: "@ai-sdk/openai",
  2000. },
  2001. })
  2002. const result = ProviderTransform.variants(model)
  2003. expect(result).toEqual({})
  2004. })
  2005. test("standard openai models return custom efforts with reasoningSummary", () => {
  2006. const model = createMockModel({
  2007. id: "gpt-5",
  2008. providerID: "openai",
  2009. api: {
  2010. id: "gpt-5",
  2011. url: "https://api.openai.com",
  2012. npm: "@ai-sdk/openai",
  2013. },
  2014. release_date: "2024-06-01",
  2015. })
  2016. const result = ProviderTransform.variants(model)
  2017. expect(Object.keys(result)).toEqual(["minimal", "low", "medium", "high"])
  2018. expect(result.low).toEqual({
  2019. reasoningEffort: "low",
  2020. reasoningSummary: "auto",
  2021. include: ["reasoning.encrypted_content"],
  2022. })
  2023. })
  2024. test("models after 2025-11-13 include 'none' effort", () => {
  2025. const model = createMockModel({
  2026. id: "gpt-5-nano",
  2027. providerID: "openai",
  2028. api: {
  2029. id: "gpt-5-nano",
  2030. url: "https://api.openai.com",
  2031. npm: "@ai-sdk/openai",
  2032. },
  2033. release_date: "2025-11-14",
  2034. })
  2035. const result = ProviderTransform.variants(model)
  2036. expect(Object.keys(result)).toEqual(["none", "minimal", "low", "medium", "high"])
  2037. })
  2038. test("models after 2025-12-04 include 'xhigh' effort", () => {
  2039. const model = createMockModel({
  2040. id: "openai/gpt-5-chat",
  2041. providerID: "openai",
  2042. api: {
  2043. id: "gpt-5-chat",
  2044. url: "https://api.openai.com",
  2045. npm: "@ai-sdk/openai",
  2046. },
  2047. release_date: "2025-12-05",
  2048. })
  2049. const result = ProviderTransform.variants(model)
  2050. expect(Object.keys(result)).toEqual(["none", "minimal", "low", "medium", "high", "xhigh"])
  2051. })
  2052. })
  2053. describe("@ai-sdk/anthropic", () => {
  2054. test("sonnet 4.6 returns adaptive thinking options", () => {
  2055. const model = createMockModel({
  2056. id: "anthropic/claude-sonnet-4-6",
  2057. providerID: "anthropic",
  2058. api: {
  2059. id: "claude-sonnet-4-6",
  2060. url: "https://api.anthropic.com",
  2061. npm: "@ai-sdk/anthropic",
  2062. },
  2063. })
  2064. const result = ProviderTransform.variants(model)
  2065. expect(Object.keys(result)).toEqual(["low", "medium", "high", "max"])
  2066. expect(result.high).toEqual({
  2067. thinking: {
  2068. type: "adaptive",
  2069. },
  2070. effort: "high",
  2071. })
  2072. })
  2073. test("returns high and max with thinking config", () => {
  2074. const model = createMockModel({
  2075. id: "anthropic/claude-4",
  2076. providerID: "anthropic",
  2077. api: {
  2078. id: "claude-4",
  2079. url: "https://api.anthropic.com",
  2080. npm: "@ai-sdk/anthropic",
  2081. },
  2082. })
  2083. const result = ProviderTransform.variants(model)
  2084. expect(Object.keys(result)).toEqual(["high", "max"])
  2085. expect(result.high).toEqual({
  2086. thinking: {
  2087. type: "enabled",
  2088. budgetTokens: 16000,
  2089. },
  2090. })
  2091. expect(result.max).toEqual({
  2092. thinking: {
  2093. type: "enabled",
  2094. budgetTokens: 31999,
  2095. },
  2096. })
  2097. })
  2098. })
  2099. describe("@ai-sdk/amazon-bedrock", () => {
  2100. test("anthropic sonnet 4.6 returns adaptive reasoning options", () => {
  2101. const model = createMockModel({
  2102. id: "bedrock/anthropic-claude-sonnet-4-6",
  2103. providerID: "bedrock",
  2104. api: {
  2105. id: "anthropic.claude-sonnet-4-6",
  2106. url: "https://bedrock.amazonaws.com",
  2107. npm: "@ai-sdk/amazon-bedrock",
  2108. },
  2109. })
  2110. const result = ProviderTransform.variants(model)
  2111. expect(Object.keys(result)).toEqual(["low", "medium", "high", "max"])
  2112. expect(result.max).toEqual({
  2113. reasoningConfig: {
  2114. type: "adaptive",
  2115. maxReasoningEffort: "max",
  2116. },
  2117. })
  2118. })
  2119. test("returns WIDELY_SUPPORTED_EFFORTS with reasoningConfig", () => {
  2120. const model = createMockModel({
  2121. id: "bedrock/llama-4",
  2122. providerID: "bedrock",
  2123. api: {
  2124. id: "llama-4-sc",
  2125. url: "https://bedrock.amazonaws.com",
  2126. npm: "@ai-sdk/amazon-bedrock",
  2127. },
  2128. })
  2129. const result = ProviderTransform.variants(model)
  2130. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  2131. expect(result.low).toEqual({
  2132. reasoningConfig: {
  2133. type: "enabled",
  2134. maxReasoningEffort: "low",
  2135. },
  2136. })
  2137. })
  2138. })
  2139. describe("@ai-sdk/google", () => {
  2140. test("gemini-2.5 returns high and max with thinkingConfig and thinkingBudget", () => {
  2141. const model = createMockModel({
  2142. id: "google/gemini-2.5-pro",
  2143. providerID: "google",
  2144. api: {
  2145. id: "gemini-2.5-pro",
  2146. url: "https://generativelanguage.googleapis.com",
  2147. npm: "@ai-sdk/google",
  2148. },
  2149. })
  2150. const result = ProviderTransform.variants(model)
  2151. expect(Object.keys(result)).toEqual(["high", "max"])
  2152. expect(result.high).toEqual({
  2153. thinkingConfig: {
  2154. includeThoughts: true,
  2155. thinkingBudget: 16000,
  2156. },
  2157. })
  2158. expect(result.max).toEqual({
  2159. thinkingConfig: {
  2160. includeThoughts: true,
  2161. thinkingBudget: 24576,
  2162. },
  2163. })
  2164. })
  2165. test("other gemini models return low and high with thinkingLevel", () => {
  2166. const model = createMockModel({
  2167. id: "google/gemini-2.0-pro",
  2168. providerID: "google",
  2169. api: {
  2170. id: "gemini-2.0-pro",
  2171. url: "https://generativelanguage.googleapis.com",
  2172. npm: "@ai-sdk/google",
  2173. },
  2174. })
  2175. const result = ProviderTransform.variants(model)
  2176. expect(Object.keys(result)).toEqual(["low", "high"])
  2177. expect(result.low).toEqual({
  2178. thinkingConfig: {
  2179. includeThoughts: true,
  2180. thinkingLevel: "low",
  2181. },
  2182. })
  2183. expect(result.high).toEqual({
  2184. thinkingConfig: {
  2185. includeThoughts: true,
  2186. thinkingLevel: "high",
  2187. },
  2188. })
  2189. })
  2190. })
  2191. describe("@ai-sdk/google-vertex", () => {
  2192. test("gemini-2.5 returns high and max with thinkingConfig and thinkingBudget", () => {
  2193. const model = createMockModel({
  2194. id: "google-vertex/gemini-2.5-pro",
  2195. providerID: "google-vertex",
  2196. api: {
  2197. id: "gemini-2.5-pro",
  2198. url: "https://vertexai.googleapis.com",
  2199. npm: "@ai-sdk/google-vertex",
  2200. },
  2201. })
  2202. const result = ProviderTransform.variants(model)
  2203. expect(Object.keys(result)).toEqual(["high", "max"])
  2204. })
  2205. test("other vertex models return low and high with thinkingLevel", () => {
  2206. const model = createMockModel({
  2207. id: "google-vertex/gemini-2.0-pro",
  2208. providerID: "google-vertex",
  2209. api: {
  2210. id: "gemini-2.0-pro",
  2211. url: "https://vertexai.googleapis.com",
  2212. npm: "@ai-sdk/google-vertex",
  2213. },
  2214. })
  2215. const result = ProviderTransform.variants(model)
  2216. expect(Object.keys(result)).toEqual(["low", "high"])
  2217. })
  2218. })
  2219. describe("@ai-sdk/cohere", () => {
  2220. test("returns empty object", () => {
  2221. const model = createMockModel({
  2222. id: "cohere/command-r",
  2223. providerID: "cohere",
  2224. api: {
  2225. id: "command-r",
  2226. url: "https://api.cohere.com",
  2227. npm: "@ai-sdk/cohere",
  2228. },
  2229. })
  2230. const result = ProviderTransform.variants(model)
  2231. expect(result).toEqual({})
  2232. })
  2233. })
  2234. describe("@ai-sdk/groq", () => {
  2235. test("returns none and WIDELY_SUPPORTED_EFFORTS with thinkingLevel", () => {
  2236. const model = createMockModel({
  2237. id: "groq/llama-4",
  2238. providerID: "groq",
  2239. api: {
  2240. id: "llama-4-sc",
  2241. url: "https://api.groq.com",
  2242. npm: "@ai-sdk/groq",
  2243. },
  2244. })
  2245. const result = ProviderTransform.variants(model)
  2246. expect(Object.keys(result)).toEqual(["none", "low", "medium", "high"])
  2247. expect(result.none).toEqual({
  2248. reasoningEffort: "none",
  2249. })
  2250. expect(result.low).toEqual({
  2251. reasoningEffort: "low",
  2252. })
  2253. })
  2254. })
  2255. describe("@ai-sdk/perplexity", () => {
  2256. test("returns empty object", () => {
  2257. const model = createMockModel({
  2258. id: "perplexity/sonar-plus",
  2259. providerID: "perplexity",
  2260. api: {
  2261. id: "sonar-plus",
  2262. url: "https://api.perplexity.ai",
  2263. npm: "@ai-sdk/perplexity",
  2264. },
  2265. })
  2266. const result = ProviderTransform.variants(model)
  2267. expect(result).toEqual({})
  2268. })
  2269. })
  2270. describe("@jerome-benoit/sap-ai-provider-v2", () => {
  2271. test("anthropic models return thinking variants", () => {
  2272. const model = createMockModel({
  2273. id: "sap-ai-core/anthropic--claude-sonnet-4",
  2274. providerID: "sap-ai-core",
  2275. api: {
  2276. id: "anthropic--claude-sonnet-4",
  2277. url: "https://api.ai.sap",
  2278. npm: "@jerome-benoit/sap-ai-provider-v2",
  2279. },
  2280. })
  2281. const result = ProviderTransform.variants(model)
  2282. expect(Object.keys(result)).toEqual(["high", "max"])
  2283. expect(result.high).toEqual({
  2284. thinking: {
  2285. type: "enabled",
  2286. budgetTokens: 16000,
  2287. },
  2288. })
  2289. expect(result.max).toEqual({
  2290. thinking: {
  2291. type: "enabled",
  2292. budgetTokens: 31999,
  2293. },
  2294. })
  2295. })
  2296. test("anthropic 4.6 models return adaptive thinking variants", () => {
  2297. const model = createMockModel({
  2298. id: "sap-ai-core/anthropic--claude-sonnet-4-6",
  2299. providerID: "sap-ai-core",
  2300. api: {
  2301. id: "anthropic--claude-sonnet-4-6",
  2302. url: "https://api.ai.sap",
  2303. npm: "@jerome-benoit/sap-ai-provider-v2",
  2304. },
  2305. })
  2306. const result = ProviderTransform.variants(model)
  2307. expect(Object.keys(result)).toEqual(["low", "medium", "high", "max"])
  2308. expect(result.low).toEqual({
  2309. thinking: {
  2310. type: "adaptive",
  2311. },
  2312. effort: "low",
  2313. })
  2314. expect(result.max).toEqual({
  2315. thinking: {
  2316. type: "adaptive",
  2317. },
  2318. effort: "max",
  2319. })
  2320. })
  2321. test("gemini 2.5 models return thinkingConfig variants", () => {
  2322. const model = createMockModel({
  2323. id: "sap-ai-core/gcp--gemini-2.5-pro",
  2324. providerID: "sap-ai-core",
  2325. api: {
  2326. id: "gcp--gemini-2.5-pro",
  2327. url: "https://api.ai.sap",
  2328. npm: "@jerome-benoit/sap-ai-provider-v2",
  2329. },
  2330. })
  2331. const result = ProviderTransform.variants(model)
  2332. expect(Object.keys(result)).toEqual(["high", "max"])
  2333. expect(result.high).toEqual({
  2334. thinkingConfig: {
  2335. includeThoughts: true,
  2336. thinkingBudget: 16000,
  2337. },
  2338. })
  2339. expect(result.max).toEqual({
  2340. thinkingConfig: {
  2341. includeThoughts: true,
  2342. thinkingBudget: 24576,
  2343. },
  2344. })
  2345. })
  2346. test("gpt models return reasoningEffort variants", () => {
  2347. const model = createMockModel({
  2348. id: "sap-ai-core/azure-openai--gpt-4o",
  2349. providerID: "sap-ai-core",
  2350. api: {
  2351. id: "azure-openai--gpt-4o",
  2352. url: "https://api.ai.sap",
  2353. npm: "@jerome-benoit/sap-ai-provider-v2",
  2354. },
  2355. })
  2356. const result = ProviderTransform.variants(model)
  2357. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  2358. expect(result.low).toEqual({ reasoningEffort: "low" })
  2359. expect(result.high).toEqual({ reasoningEffort: "high" })
  2360. })
  2361. test("o-series models return reasoningEffort variants", () => {
  2362. const model = createMockModel({
  2363. id: "sap-ai-core/azure-openai--o3-mini",
  2364. providerID: "sap-ai-core",
  2365. api: {
  2366. id: "azure-openai--o3-mini",
  2367. url: "https://api.ai.sap",
  2368. npm: "@jerome-benoit/sap-ai-provider-v2",
  2369. },
  2370. })
  2371. const result = ProviderTransform.variants(model)
  2372. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  2373. expect(result.low).toEqual({ reasoningEffort: "low" })
  2374. expect(result.high).toEqual({ reasoningEffort: "high" })
  2375. })
  2376. test("sonar models return empty object", () => {
  2377. const model = createMockModel({
  2378. id: "sap-ai-core/perplexity--sonar-pro",
  2379. providerID: "sap-ai-core",
  2380. api: {
  2381. id: "perplexity--sonar-pro",
  2382. url: "https://api.ai.sap",
  2383. npm: "@jerome-benoit/sap-ai-provider-v2",
  2384. },
  2385. })
  2386. const result = ProviderTransform.variants(model)
  2387. expect(result).toEqual({})
  2388. })
  2389. test("mistral models return empty object", () => {
  2390. const model = createMockModel({
  2391. id: "sap-ai-core/mistral--mistral-large",
  2392. providerID: "sap-ai-core",
  2393. api: {
  2394. id: "mistral--mistral-large",
  2395. url: "https://api.ai.sap",
  2396. npm: "@jerome-benoit/sap-ai-provider-v2",
  2397. },
  2398. })
  2399. const result = ProviderTransform.variants(model)
  2400. expect(result).toEqual({})
  2401. })
  2402. })
  2403. })