transform.test.ts 125 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120
  1. import { describe, expect, test } from "bun:test"
  2. import { Effect } from "effect"
  3. import { ProviderTransform } from "@/provider/transform"
  4. import { LLMRequestPrep } from "@/session/llm/request"
  5. import { ProviderV2 } from "@opencode-ai/core/provider"
  6. import { ModelV2 } from "@opencode-ai/core/model"
  7. describe("ProviderTransform.options - setCacheKey", () => {
  8. const sessionID = "test-session-123"
  9. const mockModel = {
  10. id: "anthropic/claude-3-5-sonnet",
  11. providerID: "anthropic",
  12. api: {
  13. id: "claude-3-5-sonnet-20241022",
  14. url: "https://api.anthropic.com",
  15. npm: "@ai-sdk/anthropic",
  16. },
  17. name: "Claude 3.5 Sonnet",
  18. capabilities: {
  19. temperature: true,
  20. reasoning: false,
  21. attachment: true,
  22. toolcall: true,
  23. input: { text: true, audio: false, image: true, video: false, pdf: true },
  24. output: { text: true, audio: false, image: false, video: false, pdf: false },
  25. interleaved: false,
  26. },
  27. cost: {
  28. input: 0.003,
  29. output: 0.015,
  30. cache: { read: 0.0003, write: 0.00375 },
  31. },
  32. limit: {
  33. context: 200000,
  34. output: 8192,
  35. },
  36. status: "active",
  37. options: {},
  38. headers: {},
  39. } as any
  40. test("should set promptCacheKey when providerOptions.setCacheKey is true", () => {
  41. const result = ProviderTransform.options({
  42. model: mockModel,
  43. sessionID,
  44. providerOptions: { setCacheKey: true },
  45. })
  46. expect(result.promptCacheKey).toBe(sessionID)
  47. })
  48. test("should not set promptCacheKey when providerOptions.setCacheKey is false", () => {
  49. const result = ProviderTransform.options({
  50. model: mockModel,
  51. sessionID,
  52. providerOptions: { setCacheKey: false },
  53. })
  54. expect(result.promptCacheKey).toBeUndefined()
  55. })
  56. test("should not set promptCacheKey when providerOptions is undefined", () => {
  57. const result = ProviderTransform.options({
  58. model: mockModel,
  59. sessionID,
  60. providerOptions: undefined,
  61. })
  62. expect(result.promptCacheKey).toBeUndefined()
  63. })
  64. test("should not set promptCacheKey when providerOptions does not have setCacheKey", () => {
  65. const result = ProviderTransform.options({ model: mockModel, sessionID, providerOptions: {} })
  66. expect(result.promptCacheKey).toBeUndefined()
  67. })
  68. test("should set promptCacheKey for openai provider regardless of setCacheKey", () => {
  69. const openaiModel = {
  70. ...mockModel,
  71. providerID: "openai",
  72. api: {
  73. id: "gpt-4",
  74. url: "https://api.openai.com",
  75. npm: "@ai-sdk/openai",
  76. },
  77. }
  78. const result = ProviderTransform.options({ model: openaiModel, sessionID, providerOptions: {} })
  79. expect(result.promptCacheKey).toBe(sessionID)
  80. })
  81. test("should set store=false for openai provider", () => {
  82. const openaiModel = {
  83. ...mockModel,
  84. providerID: "openai",
  85. api: {
  86. id: "gpt-4",
  87. url: "https://api.openai.com",
  88. npm: "@ai-sdk/openai",
  89. },
  90. }
  91. const result = ProviderTransform.options({
  92. model: openaiModel,
  93. sessionID,
  94. providerOptions: {},
  95. })
  96. expect(result.store).toBe(false)
  97. })
  98. test("should set store=false for azure provider by default", () => {
  99. const azureModel = {
  100. ...mockModel,
  101. providerID: "azure",
  102. api: {
  103. id: "gpt-4",
  104. url: "https://azure.com",
  105. npm: "@ai-sdk/azure",
  106. },
  107. }
  108. const result = ProviderTransform.options({
  109. model: azureModel,
  110. sessionID,
  111. providerOptions: {},
  112. })
  113. expect(result.store).toBe(false)
  114. })
  115. })
  116. describe("ProviderTransform.options - zai/zhipuai thinking", () => {
  117. const sessionID = "test-session-123"
  118. const createModel = (providerID: string) =>
  119. ({
  120. id: `${providerID}/glm-4.6`,
  121. providerID,
  122. api: {
  123. id: "glm-4.6",
  124. url: "https://open.bigmodel.cn/api/paas/v4",
  125. npm: "@ai-sdk/openai-compatible",
  126. },
  127. name: "GLM 4.6",
  128. capabilities: {
  129. temperature: true,
  130. reasoning: true,
  131. attachment: true,
  132. toolcall: true,
  133. input: { text: true, audio: false, image: true, video: false, pdf: true },
  134. output: { text: true, audio: false, image: false, video: false, pdf: false },
  135. interleaved: false,
  136. },
  137. cost: {
  138. input: 0.001,
  139. output: 0.002,
  140. cache: { read: 0.0001, write: 0.0002 },
  141. },
  142. limit: {
  143. context: 128000,
  144. output: 8192,
  145. },
  146. status: "active",
  147. options: {},
  148. headers: {},
  149. }) as any
  150. for (const providerID of ["zai-coding-plan", "zai", "zhipuai-coding-plan", "zhipuai"]) {
  151. test(`${providerID} should set thinking cfg`, () => {
  152. const result = ProviderTransform.options({
  153. model: createModel(providerID),
  154. sessionID,
  155. providerOptions: {},
  156. })
  157. expect(result.thinking).toEqual({
  158. type: "enabled",
  159. clear_thinking: false,
  160. })
  161. })
  162. }
  163. })
  164. describe("ProviderTransform.options - minimax m3 thinking", () => {
  165. const createModel = (npm: string) =>
  166. ({
  167. id: "minimax/minimax-m3",
  168. providerID: "minimax",
  169. api: {
  170. id: "minimax-m3",
  171. url: "https://api.minimax.com",
  172. npm,
  173. },
  174. capabilities: { reasoning: true },
  175. limit: { output: 64_000 },
  176. }) as any
  177. test("explicitly enables adaptive thinking with the anthropic SDK", () => {
  178. expect(
  179. ProviderTransform.options({
  180. model: createModel("@ai-sdk/anthropic"),
  181. sessionID: "test-session-123",
  182. }).thinking,
  183. ).toEqual({ type: "adaptive" })
  184. })
  185. test("uses the native default with the openai-compatible SDK", () => {
  186. expect(
  187. ProviderTransform.options({
  188. model: createModel("@ai-sdk/openai-compatible"),
  189. sessionID: "test-session-123",
  190. }).thinking,
  191. ).toBeUndefined()
  192. })
  193. })
  194. describe("ProviderTransform.options - google thinkingConfig gating", () => {
  195. const sessionID = "test-session-123"
  196. const createGoogleModel = (reasoning: boolean, npm: "@ai-sdk/google" | "@ai-sdk/google-vertex") =>
  197. ({
  198. id: `${npm === "@ai-sdk/google" ? "google" : "google-vertex"}/gemini-2.0-flash`,
  199. providerID: npm === "@ai-sdk/google" ? "google" : "google-vertex",
  200. api: {
  201. id: "gemini-2.0-flash",
  202. url: npm === "@ai-sdk/google" ? "https://generativelanguage.googleapis.com" : "https://vertexai.googleapis.com",
  203. npm,
  204. },
  205. name: "Gemini 2.0 Flash",
  206. capabilities: {
  207. temperature: true,
  208. reasoning,
  209. attachment: true,
  210. toolcall: true,
  211. input: { text: true, audio: false, image: true, video: false, pdf: true },
  212. output: { text: true, audio: false, image: false, video: false, pdf: false },
  213. interleaved: false,
  214. },
  215. cost: {
  216. input: 0.001,
  217. output: 0.002,
  218. cache: { read: 0.0001, write: 0.0002 },
  219. },
  220. limit: {
  221. context: 1_000_000,
  222. output: 8192,
  223. },
  224. status: "active",
  225. options: {},
  226. headers: {},
  227. }) as any
  228. test("does not set thinkingConfig for google models without reasoning capability", () => {
  229. const result = ProviderTransform.options({
  230. model: createGoogleModel(false, "@ai-sdk/google"),
  231. sessionID,
  232. providerOptions: {},
  233. })
  234. expect(result.thinkingConfig).toBeUndefined()
  235. })
  236. test("sets thinkingConfig for google models with reasoning capability", () => {
  237. const result = ProviderTransform.options({
  238. model: createGoogleModel(true, "@ai-sdk/google"),
  239. sessionID,
  240. providerOptions: {},
  241. })
  242. expect(result.thinkingConfig).toEqual({
  243. includeThoughts: true,
  244. })
  245. })
  246. test("does not set thinkingConfig for vertex models without reasoning capability", () => {
  247. const result = ProviderTransform.options({
  248. model: createGoogleModel(false, "@ai-sdk/google-vertex"),
  249. sessionID,
  250. providerOptions: {},
  251. })
  252. expect(result.thinkingConfig).toBeUndefined()
  253. })
  254. })
  255. describe("ProviderTransform.options - gpt-5 textVerbosity", () => {
  256. const sessionID = "test-session-123"
  257. const createGpt5Model = (apiId: string) =>
  258. ({
  259. id: `openai/${apiId}`,
  260. providerID: "openai",
  261. api: {
  262. id: apiId,
  263. url: "https://api.openai.com",
  264. npm: "@ai-sdk/openai",
  265. },
  266. name: apiId,
  267. capabilities: {
  268. temperature: true,
  269. reasoning: true,
  270. attachment: true,
  271. toolcall: true,
  272. input: { text: true, audio: false, image: true, video: false, pdf: false },
  273. output: { text: true, audio: false, image: false, video: false, pdf: false },
  274. interleaved: false,
  275. },
  276. cost: { input: 0.03, output: 0.06, cache: { read: 0.001, write: 0.002 } },
  277. limit: { context: 128000, output: 4096 },
  278. status: "active",
  279. options: {},
  280. headers: {},
  281. }) as any
  282. test("gpt-5.2 should have textVerbosity set to low", () => {
  283. const model = createGpt5Model("gpt-5.2")
  284. const result = ProviderTransform.options({ model, sessionID, providerOptions: {} })
  285. expect(result.textVerbosity).toBe("low")
  286. expect(result.include).toEqual(["reasoning.encrypted_content"])
  287. })
  288. test("Bedrock Mantle gpt-5.5 uses OpenAI Responses defaults", () => {
  289. const model = {
  290. ...createGpt5Model("openai.gpt-5.5"),
  291. id: "amazon-bedrock/openai.gpt-5.5",
  292. providerID: "amazon-bedrock",
  293. api: {
  294. id: "openai.gpt-5.5",
  295. url: "https://bedrock-mantle.us-east-2.api.aws/openai/v1",
  296. npm: "@ai-sdk/amazon-bedrock/mantle",
  297. },
  298. }
  299. const result = ProviderTransform.options({ model, sessionID, providerOptions: {} })
  300. expect(result.store).toBe(false)
  301. expect(result.reasoningEffort).toBe("medium")
  302. expect(result.reasoningSummary).toBe("auto")
  303. expect(result.include).toEqual(["reasoning.encrypted_content"])
  304. expect(result.textVerbosity).toBe("low")
  305. })
  306. test("openai-compatible gpt-5 models omit Responses-only reasoningSummary", () => {
  307. const model = {
  308. ...createGpt5Model("gpt-5.4"),
  309. id: "cortecs/gpt-5.4",
  310. providerID: "cortecs",
  311. api: {
  312. id: "gpt-5.4",
  313. url: "https://api.cortecs.ai/v1",
  314. npm: "@ai-sdk/openai-compatible",
  315. },
  316. }
  317. const result = ProviderTransform.options({ model, sessionID, providerOptions: {} })
  318. expect(result.reasoningEffort).toBe("medium")
  319. expect(result.reasoningSummary).toBeUndefined()
  320. expect(result.include).toBeUndefined()
  321. })
  322. test("azure chat completions omit Responses-only reasoning options after variants merge", async () => {
  323. const model = {
  324. ...createGpt5Model("gpt-5.4"),
  325. id: "azure/gpt-5.4",
  326. providerID: "azure",
  327. api: {
  328. id: "gpt-5.4",
  329. url: "https://azure.com",
  330. npm: "@ai-sdk/azure",
  331. },
  332. variants: {
  333. high: {
  334. reasoningEffort: "high",
  335. reasoningSummary: "auto",
  336. include: ["reasoning.encrypted_content"],
  337. },
  338. },
  339. }
  340. const result = await Effect.runPromise(
  341. LLMRequestPrep.prepare({
  342. user: {
  343. id: "msg_user-test",
  344. sessionID,
  345. role: "user",
  346. time: { created: Date.now() },
  347. agent: "test",
  348. model: { providerID: "azure", modelID: "gpt-5.4", variant: "high" },
  349. } as any,
  350. sessionID,
  351. model,
  352. agent: {
  353. name: "test",
  354. mode: "primary",
  355. options: {},
  356. permission: [],
  357. } as any,
  358. system: [],
  359. messages: [{ role: "user", content: "Hello" }],
  360. tools: {},
  361. provider: { id: "azure", options: { useCompletionUrls: true } } as any,
  362. auth: undefined,
  363. plugin: {
  364. trigger: (_name: string, _input: unknown, output: unknown) => Effect.succeed(output),
  365. list: () => Effect.succeed([]),
  366. init: () => Effect.void,
  367. } as any,
  368. flags: { outputTokenMax: 32_000, client: "test" } as any,
  369. isWorkflow: false,
  370. }),
  371. )
  372. expect(result.params.options.reasoningEffort).toBe("high")
  373. expect(result.params.options.reasoningSummary).toBeUndefined()
  374. expect(result.params.options.include).toBeUndefined()
  375. })
  376. test("gpt-5.1 should have textVerbosity set to low", () => {
  377. const model = createGpt5Model("gpt-5.1")
  378. const result = ProviderTransform.options({ model, sessionID, providerOptions: {} })
  379. expect(result.textVerbosity).toBe("low")
  380. })
  381. test("gpt-5.2-chat-latest should NOT have textVerbosity set (only supports medium)", () => {
  382. const model = createGpt5Model("gpt-5.2-chat-latest")
  383. const result = ProviderTransform.options({ model, sessionID, providerOptions: {} })
  384. expect(result.textVerbosity).toBeUndefined()
  385. })
  386. test("gpt-5.1-chat-latest should NOT have textVerbosity set (only supports medium)", () => {
  387. const model = createGpt5Model("gpt-5.1-chat-latest")
  388. const result = ProviderTransform.options({ model, sessionID, providerOptions: {} })
  389. expect(result.textVerbosity).toBeUndefined()
  390. })
  391. test("gpt-5.2-chat should NOT have textVerbosity set", () => {
  392. const model = createGpt5Model("gpt-5.2-chat")
  393. const result = ProviderTransform.options({ model, sessionID, providerOptions: {} })
  394. expect(result.textVerbosity).toBeUndefined()
  395. })
  396. test("gpt-5-chat should NOT have textVerbosity set", () => {
  397. const model = createGpt5Model("gpt-5-chat")
  398. const result = ProviderTransform.options({ model, sessionID, providerOptions: {} })
  399. expect(result.textVerbosity).toBeUndefined()
  400. })
  401. test("gpt-5.2-codex should NOT have textVerbosity set (codex models excluded)", () => {
  402. const model = createGpt5Model("gpt-5.2-codex")
  403. const result = ProviderTransform.options({ model, sessionID, providerOptions: {} })
  404. expect(result.textVerbosity).toBeUndefined()
  405. })
  406. })
  407. describe("ProviderTransform.options - gpt-5 reasoningEffort", () => {
  408. const sessionID = "test-session-123"
  409. const createModel = (apiId: string) =>
  410. ({
  411. id: `azure/${apiId}`,
  412. providerID: "azure",
  413. api: {
  414. id: apiId,
  415. url: "https://azure.com",
  416. npm: "@ai-sdk/azure",
  417. },
  418. name: apiId,
  419. capabilities: {
  420. temperature: true,
  421. reasoning: true,
  422. attachment: true,
  423. toolcall: true,
  424. input: {
  425. text: true,
  426. audio: false,
  427. image: true,
  428. video: false,
  429. pdf: false,
  430. },
  431. output: {
  432. text: true,
  433. audio: false,
  434. image: false,
  435. video: false,
  436. pdf: false,
  437. },
  438. interleaved: false,
  439. },
  440. cost: {
  441. input: 0.03,
  442. output: 0.06,
  443. cache: { read: 0.001, write: 0.002 },
  444. },
  445. limit: {
  446. context: 128000,
  447. output: 4096,
  448. },
  449. status: "active",
  450. options: {},
  451. headers: {},
  452. }) as any
  453. test("gpt-5-chat should NOT set reasoningEffort", () => {
  454. const result = ProviderTransform.options({
  455. model: createModel("gpt-5-chat"),
  456. sessionID,
  457. providerOptions: {},
  458. })
  459. expect(result.reasoningEffort).toBeUndefined()
  460. })
  461. test("gpt-5.5 should NOT set reasoningEffort", () => {
  462. const result = ProviderTransform.options({
  463. model: createModel("gpt-5.5"),
  464. sessionID,
  465. providerOptions: {},
  466. })
  467. expect(result.reasoningEffort).toBeUndefined()
  468. })
  469. })
  470. describe("ProviderTransform.options - gateway", () => {
  471. const sessionID = "test-session-123"
  472. const createModel = (id: string) =>
  473. ({
  474. id,
  475. providerID: "vercel",
  476. api: {
  477. id,
  478. url: "https://ai-gateway.vercel.sh/v3/ai",
  479. npm: "@ai-sdk/gateway",
  480. },
  481. name: id,
  482. capabilities: {
  483. temperature: true,
  484. reasoning: true,
  485. attachment: true,
  486. toolcall: true,
  487. input: { text: true, audio: false, image: true, video: false, pdf: true },
  488. output: { text: true, audio: false, image: false, video: false, pdf: false },
  489. interleaved: false,
  490. },
  491. cost: {
  492. input: 0.001,
  493. output: 0.002,
  494. cache: { read: 0.0001, write: 0.0002 },
  495. },
  496. limit: {
  497. context: 200_000,
  498. output: 8192,
  499. },
  500. status: "active",
  501. options: {},
  502. headers: {},
  503. release_date: "2024-01-01",
  504. }) as any
  505. test("puts gateway defaults under gateway key", () => {
  506. const model = createModel("anthropic/claude-sonnet-4")
  507. const result = ProviderTransform.options({ model, sessionID, providerOptions: {} })
  508. expect(result).toEqual({
  509. gateway: {
  510. caching: "auto",
  511. },
  512. })
  513. })
  514. })
  515. describe("ProviderTransform.providerOptions", () => {
  516. const createModel = (overrides: Partial<any> = {}) =>
  517. ({
  518. id: "test/test-model",
  519. providerID: "test",
  520. api: {
  521. id: "test-model",
  522. url: "https://api.test.com",
  523. npm: "@ai-sdk/openai",
  524. },
  525. name: "Test Model",
  526. capabilities: {
  527. temperature: true,
  528. reasoning: true,
  529. attachment: true,
  530. toolcall: true,
  531. input: { text: true, audio: false, image: true, video: false, pdf: false },
  532. output: { text: true, audio: false, image: false, video: false, pdf: false },
  533. interleaved: false,
  534. },
  535. cost: {
  536. input: 0.001,
  537. output: 0.002,
  538. cache: { read: 0.0001, write: 0.0002 },
  539. },
  540. limit: {
  541. context: 200_000,
  542. output: 64_000,
  543. },
  544. status: "active",
  545. options: {},
  546. headers: {},
  547. release_date: "2024-01-01",
  548. ...overrides,
  549. }) as any
  550. test("uses sdk key for non-gateway models", () => {
  551. const model = createModel({
  552. providerID: "my-bedrock",
  553. api: {
  554. id: "anthropic.claude-sonnet-4",
  555. url: "https://bedrock.aws",
  556. npm: "@ai-sdk/amazon-bedrock",
  557. },
  558. })
  559. expect(ProviderTransform.providerOptions(model, { cachePoint: { type: "default" } })).toEqual({
  560. bedrock: { cachePoint: { type: "default" } },
  561. })
  562. })
  563. test("uses gateway model provider slug for gateway models", () => {
  564. const model = createModel({
  565. providerID: "vercel",
  566. api: {
  567. id: "anthropic/claude-sonnet-4",
  568. url: "https://ai-gateway.vercel.sh/v3/ai",
  569. npm: "@ai-sdk/gateway",
  570. },
  571. })
  572. expect(ProviderTransform.providerOptions(model, { thinking: { type: "enabled", budgetTokens: 12_000 } })).toEqual({
  573. anthropic: { thinking: { type: "enabled", budgetTokens: 12_000 } },
  574. })
  575. })
  576. test("falls back to gateway key when gateway api id is unscoped", () => {
  577. const model = createModel({
  578. id: "anthropic/claude-sonnet-4",
  579. providerID: "vercel",
  580. api: {
  581. id: "claude-sonnet-4",
  582. url: "https://ai-gateway.vercel.sh/v3/ai",
  583. npm: "@ai-sdk/gateway",
  584. },
  585. })
  586. expect(ProviderTransform.providerOptions(model, { thinking: { type: "enabled", budgetTokens: 12_000 } })).toEqual({
  587. gateway: { thinking: { type: "enabled", budgetTokens: 12_000 } },
  588. })
  589. })
  590. test("splits gateway routing options from provider-specific options", () => {
  591. const model = createModel({
  592. providerID: "vercel",
  593. api: {
  594. id: "anthropic/claude-sonnet-4",
  595. url: "https://ai-gateway.vercel.sh/v3/ai",
  596. npm: "@ai-sdk/gateway",
  597. },
  598. })
  599. expect(
  600. ProviderTransform.providerOptions(model, {
  601. gateway: { order: ["vertex", "anthropic"] },
  602. thinking: { type: "enabled", budgetTokens: 12_000 },
  603. }),
  604. ).toEqual({
  605. gateway: { order: ["vertex", "anthropic"] },
  606. anthropic: { thinking: { type: "enabled", budgetTokens: 12_000 } },
  607. } as any)
  608. })
  609. test("falls back to gateway key when model id has no provider slug", () => {
  610. const model = createModel({
  611. id: "claude-sonnet-4",
  612. providerID: "vercel",
  613. api: {
  614. id: "claude-sonnet-4",
  615. url: "https://ai-gateway.vercel.sh/v3/ai",
  616. npm: "@ai-sdk/gateway",
  617. },
  618. })
  619. expect(ProviderTransform.providerOptions(model, { reasoningEffort: "high" })).toEqual({
  620. gateway: { reasoningEffort: "high" },
  621. })
  622. })
  623. test("maps amazon slug to bedrock for provider options", () => {
  624. const model = createModel({
  625. providerID: "vercel",
  626. api: {
  627. id: "amazon/nova-2-lite",
  628. url: "https://ai-gateway.vercel.sh/v3/ai",
  629. npm: "@ai-sdk/gateway",
  630. },
  631. })
  632. expect(ProviderTransform.providerOptions(model, { reasoningConfig: { type: "enabled" } })).toEqual({
  633. bedrock: { reasoningConfig: { type: "enabled" } },
  634. })
  635. })
  636. test("maps Bedrock Mantle provider options to OpenAI namespace", () => {
  637. const model = createModel({
  638. providerID: "amazon-bedrock",
  639. api: {
  640. id: "openai.gpt-5.5",
  641. url: "https://bedrock-mantle.us-east-2.api.aws/openai/v1",
  642. npm: "@ai-sdk/amazon-bedrock/mantle",
  643. },
  644. })
  645. expect(ProviderTransform.providerOptions(model, { reasoningEffort: "medium" })).toEqual({
  646. openai: { reasoningEffort: "medium" },
  647. })
  648. })
  649. test("uses groq slug for groq models", () => {
  650. const model = createModel({
  651. providerID: "vercel",
  652. api: {
  653. id: "groq/llama-3.3-70b-versatile",
  654. url: "https://ai-gateway.vercel.sh/v3/ai",
  655. npm: "@ai-sdk/gateway",
  656. },
  657. })
  658. expect(ProviderTransform.providerOptions(model, { reasoningFormat: "parsed" })).toEqual({
  659. groq: { reasoningFormat: "parsed" },
  660. })
  661. })
  662. })
  663. describe("ProviderTransform.schema - gemini array items", () => {
  664. test("adds missing items for array properties", () => {
  665. const geminiModel = {
  666. providerID: "google",
  667. api: {
  668. id: "gemini-3-pro",
  669. },
  670. } as any
  671. const schema = {
  672. type: "object",
  673. properties: {
  674. nodes: { type: "array" },
  675. edges: { type: "array", items: { type: "string" } },
  676. },
  677. } as any
  678. const result = ProviderTransform.schema(geminiModel, schema) as any
  679. expect(result.properties.nodes.items).toBeDefined()
  680. expect(result.properties.edges.items.type).toBe("string")
  681. })
  682. })
  683. describe("ProviderTransform.schema - gemini nested array items", () => {
  684. const geminiModel = {
  685. providerID: "google",
  686. api: {
  687. id: "gemini-3-pro",
  688. },
  689. } as any
  690. test("adds type to 2D array with empty inner items", () => {
  691. const schema = {
  692. type: "object",
  693. properties: {
  694. values: {
  695. type: "array",
  696. items: {
  697. type: "array",
  698. items: {}, // Empty items object
  699. },
  700. },
  701. },
  702. } as any
  703. const result = ProviderTransform.schema(geminiModel, schema) as any
  704. // Inner items should have a default type
  705. expect(result.properties.values.items.items.type).toBe("string")
  706. })
  707. test("adds items and type to 2D array with missing inner items", () => {
  708. const schema = {
  709. type: "object",
  710. properties: {
  711. data: {
  712. type: "array",
  713. items: { type: "array" }, // No items at all
  714. },
  715. },
  716. } as any
  717. const result = ProviderTransform.schema(geminiModel, schema) as any
  718. expect(result.properties.data.items.items).toBeDefined()
  719. expect(result.properties.data.items.items.type).toBe("string")
  720. })
  721. test("handles deeply nested arrays (3D)", () => {
  722. const schema = {
  723. type: "object",
  724. properties: {
  725. matrix: {
  726. type: "array",
  727. items: {
  728. type: "array",
  729. items: {
  730. type: "array",
  731. // No items
  732. },
  733. },
  734. },
  735. },
  736. } as any
  737. const result = ProviderTransform.schema(geminiModel, schema) as any
  738. expect(result.properties.matrix.items.items.items).toBeDefined()
  739. expect(result.properties.matrix.items.items.items.type).toBe("string")
  740. })
  741. test("preserves existing item types in nested arrays", () => {
  742. const schema = {
  743. type: "object",
  744. properties: {
  745. numbers: {
  746. type: "array",
  747. items: {
  748. type: "array",
  749. items: { type: "number" }, // Has explicit type
  750. },
  751. },
  752. },
  753. } as any
  754. const result = ProviderTransform.schema(geminiModel, schema) as any
  755. // Should preserve the explicit type
  756. expect(result.properties.numbers.items.items.type).toBe("number")
  757. })
  758. test("handles mixed nested structures with objects and arrays", () => {
  759. const schema = {
  760. type: "object",
  761. properties: {
  762. spreadsheetData: {
  763. type: "object",
  764. properties: {
  765. rows: {
  766. type: "array",
  767. items: {
  768. type: "array",
  769. items: {}, // Empty items
  770. },
  771. },
  772. },
  773. },
  774. },
  775. } as any
  776. const result = ProviderTransform.schema(geminiModel, schema) as any
  777. expect(result.properties.spreadsheetData.properties.rows.items.items.type).toBe("string")
  778. })
  779. })
  780. describe("ProviderTransform.schema - gemini combiner nodes", () => {
  781. const geminiModel = {
  782. providerID: "google",
  783. api: {
  784. id: "gemini-3-pro",
  785. },
  786. } as any
  787. const walk = (node: any, cb: (node: any, path: (string | number)[]) => void, path: (string | number)[] = []) => {
  788. if (node === null || typeof node !== "object") {
  789. return
  790. }
  791. if (Array.isArray(node)) {
  792. node.forEach((item, i) => walk(item, cb, [...path, i]))
  793. return
  794. }
  795. cb(node, path)
  796. Object.entries(node).forEach(([key, value]) => walk(value, cb, [...path, key]))
  797. }
  798. test("keeps edits.items.anyOf without adding type", () => {
  799. const schema = {
  800. type: "object",
  801. properties: {
  802. edits: {
  803. type: "array",
  804. items: {
  805. anyOf: [
  806. {
  807. type: "object",
  808. properties: {
  809. old_string: { type: "string" },
  810. new_string: { type: "string" },
  811. },
  812. required: ["old_string", "new_string"],
  813. },
  814. {
  815. type: "object",
  816. properties: {
  817. old_string: { type: "string" },
  818. new_string: { type: "string" },
  819. replace_all: { type: "boolean" },
  820. },
  821. required: ["old_string", "new_string"],
  822. },
  823. ],
  824. },
  825. },
  826. },
  827. required: ["edits"],
  828. } as any
  829. const result = ProviderTransform.schema(geminiModel, schema) as any
  830. expect(Array.isArray(result.properties.edits.items.anyOf)).toBe(true)
  831. expect(result.properties.edits.items.type).toBeUndefined()
  832. })
  833. test("does not add sibling keys to combiner nodes during sanitize", () => {
  834. const schema = {
  835. type: "object",
  836. properties: {
  837. edits: {
  838. type: "array",
  839. items: {
  840. anyOf: [{ type: "string" }, { type: "number" }],
  841. },
  842. },
  843. value: {
  844. oneOf: [{ type: "string" }, { type: "boolean" }],
  845. },
  846. meta: {
  847. allOf: [
  848. {
  849. type: "object",
  850. properties: { a: { type: "string" } },
  851. },
  852. {
  853. type: "object",
  854. properties: { b: { type: "string" } },
  855. },
  856. ],
  857. },
  858. },
  859. } as any
  860. const input = JSON.parse(JSON.stringify(schema))
  861. const result = ProviderTransform.schema(geminiModel, schema) as any
  862. walk(result, (node, path) => {
  863. const hasCombiner = Array.isArray(node.anyOf) || Array.isArray(node.oneOf) || Array.isArray(node.allOf)
  864. if (!hasCombiner) {
  865. return
  866. }
  867. const before = path.reduce((acc: any, key) => acc?.[key], input)
  868. const added = Object.keys(node).filter((key) => !(key in before))
  869. expect(added).toEqual([])
  870. })
  871. })
  872. })
  873. describe("ProviderTransform.schema - gemini non-object properties removal", () => {
  874. const geminiModel = {
  875. providerID: "google",
  876. api: {
  877. id: "gemini-3-pro",
  878. },
  879. } as any
  880. test("removes properties from non-object types", () => {
  881. const schema = {
  882. type: "object",
  883. properties: {
  884. data: {
  885. type: "string",
  886. properties: { invalid: { type: "string" } },
  887. },
  888. },
  889. } as any
  890. const result = ProviderTransform.schema(geminiModel, schema) as any
  891. expect(result.properties.data.type).toBe("string")
  892. expect(result.properties.data.properties).toBeUndefined()
  893. })
  894. test("removes required from non-object types", () => {
  895. const schema = {
  896. type: "object",
  897. properties: {
  898. data: {
  899. type: "array",
  900. items: { type: "string" },
  901. required: ["invalid"],
  902. },
  903. },
  904. } as any
  905. const result = ProviderTransform.schema(geminiModel, schema) as any
  906. expect(result.properties.data.type).toBe("array")
  907. expect(result.properties.data.required).toBeUndefined()
  908. })
  909. test("removes properties and required from nested non-object types", () => {
  910. const schema = {
  911. type: "object",
  912. properties: {
  913. outer: {
  914. type: "object",
  915. properties: {
  916. inner: {
  917. type: "number",
  918. properties: { bad: { type: "string" } },
  919. required: ["bad"],
  920. },
  921. },
  922. },
  923. },
  924. } as any
  925. const result = ProviderTransform.schema(geminiModel, schema) as any
  926. expect(result.properties.outer.properties.inner.type).toBe("number")
  927. expect(result.properties.outer.properties.inner.properties).toBeUndefined()
  928. expect(result.properties.outer.properties.inner.required).toBeUndefined()
  929. })
  930. test("keeps properties and required on object types", () => {
  931. const schema = {
  932. type: "object",
  933. properties: {
  934. data: {
  935. type: "object",
  936. properties: { name: { type: "string" } },
  937. required: ["name"],
  938. },
  939. },
  940. } as any
  941. const result = ProviderTransform.schema(geminiModel, schema) as any
  942. expect(result.properties.data.type).toBe("object")
  943. expect(result.properties.data.properties).toBeDefined()
  944. expect(result.properties.data.required).toEqual(["name"])
  945. })
  946. test("does not affect non-gemini providers", () => {
  947. const openaiModel = {
  948. providerID: "openai",
  949. api: {
  950. id: "gpt-4",
  951. },
  952. } as any
  953. const schema = {
  954. type: "object",
  955. properties: {
  956. data: {
  957. type: "string",
  958. properties: { invalid: { type: "string" } },
  959. },
  960. },
  961. } as any
  962. const result = ProviderTransform.schema(openaiModel, schema) as any
  963. expect(result.properties.data.properties).toBeDefined()
  964. })
  965. })
  966. describe("ProviderTransform.schema - moonshot $ref siblings", () => {
  967. const moonshotModel = {
  968. providerID: "moonshotai",
  969. api: {
  970. id: "kimi-k2",
  971. },
  972. } as any
  973. test("removes sibling descriptions from referenced tool parameter schemas", () => {
  974. const schema = {
  975. type: "object",
  976. properties: {
  977. deviceType: {
  978. description: "Optional. The type of device that captured the screenshot, e.g. mobile or desktop.",
  979. enum: ["DEVICE_TYPE_UNSPECIFIED", "MOBILE", "DESKTOP", "TABLET", "AGNOSTIC"],
  980. type: "string",
  981. },
  982. modelId: {
  983. description: "Optional. The model to use for generation.",
  984. enum: ["MODEL_ID_UNSPECIFIED", "GEMINI_3_PRO", "GEMINI_3_FLASH", "GEMINI_3_1_PRO"],
  985. type: "string",
  986. },
  987. projectId: {
  988. description: "Required. The project ID of screens to generate variants for.",
  989. type: "string",
  990. },
  991. prompt: {
  992. description: "Required. The input text used to generate the variants.",
  993. type: "string",
  994. },
  995. selectedScreenIds: {
  996. description: "Required. The screen ids of screen to generate variants for.",
  997. items: {
  998. type: "string",
  999. },
  1000. type: "array",
  1001. },
  1002. variantOptions: {
  1003. $ref: "#/$defs/VariantOptions",
  1004. description:
  1005. "Required. The variant options for generation, including the number of variants, creative range, and aspects to focus on.",
  1006. },
  1007. },
  1008. required: ["projectId", "selectedScreenIds", "prompt", "variantOptions"],
  1009. $defs: {
  1010. VariantOptions: {
  1011. description:
  1012. "Configuration options for design variant generation. This message captures all parameters used to generate variants, allowing the configuration to be stored, replayed, or analyzed.",
  1013. properties: {
  1014. aspects: {
  1015. description: "Optional. Specific aspects to focus on. If empty, all aspects may be varied.",
  1016. items: {
  1017. enum: ["VARIANT_ASPECT_UNSPECIFIED", "LAYOUT", "COLOR_SCHEME", "IMAGES", "TEXT_FONT", "TEXT_CONTENT"],
  1018. type: "string",
  1019. },
  1020. type: "array",
  1021. },
  1022. creativeRange: {
  1023. description: "Optional. Creative range for variations. Default: EXPLORE",
  1024. enum: ["CREATIVE_RANGE_UNSPECIFIED", "REFINE", "EXPLORE", "REIMAGINE"],
  1025. type: "string",
  1026. },
  1027. variantCount: {
  1028. description: "Optional. Number of variants to generate (1-5). Default: 3",
  1029. format: "int32",
  1030. type: "integer",
  1031. },
  1032. },
  1033. type: "object",
  1034. },
  1035. },
  1036. description: "Request message for GenerateVariants.",
  1037. additionalProperties: false,
  1038. } as any
  1039. const result = ProviderTransform.schema(moonshotModel, schema) as any
  1040. expect(result.properties.variantOptions).toEqual({
  1041. $ref: "#/$defs/VariantOptions",
  1042. })
  1043. expect(result.$defs.VariantOptions.description).toBe(schema.$defs.VariantOptions.description)
  1044. })
  1045. test("also runs for kimi models outside the moonshot provider", () => {
  1046. const result = ProviderTransform.schema(
  1047. {
  1048. providerID: "openrouter",
  1049. name: "Kimi K2",
  1050. api: {
  1051. id: "moonshotai/kimi-k2",
  1052. },
  1053. } as any,
  1054. {
  1055. type: "object",
  1056. properties: {
  1057. value: {
  1058. $ref: "#/$defs/Value",
  1059. description: "Moonshot rejects this sibling after ref expansion.",
  1060. },
  1061. },
  1062. $defs: {
  1063. Value: {
  1064. description: "Referenced schema description stays here.",
  1065. type: "object",
  1066. },
  1067. },
  1068. } as any,
  1069. ) as any
  1070. expect(result.properties.value).toEqual({
  1071. $ref: "#/$defs/Value",
  1072. })
  1073. })
  1074. test("converts tuple-style array items to a single item schema", () => {
  1075. const result = ProviderTransform.schema(moonshotModel, {
  1076. type: "object",
  1077. properties: {
  1078. codeSpec: {
  1079. type: "object",
  1080. properties: {
  1081. accessibility: {
  1082. type: "object",
  1083. properties: {
  1084. renderedSize: {
  1085. description: "Rendered size [width, height] in px",
  1086. type: "array",
  1087. items: [{ type: "number" }, { type: "number" }],
  1088. minItems: 2,
  1089. maxItems: 2,
  1090. },
  1091. },
  1092. },
  1093. },
  1094. },
  1095. },
  1096. } as any) as any
  1097. expect(result.properties.codeSpec.properties.accessibility.properties.renderedSize.items).toEqual({
  1098. type: "number",
  1099. })
  1100. })
  1101. })
  1102. describe("ProviderTransform.message - DeepSeek reasoning content", () => {
  1103. test("DeepSeek with tool calls includes reasoning_content in providerOptions", () => {
  1104. const msgs = [
  1105. {
  1106. role: "assistant",
  1107. content: [
  1108. { type: "reasoning", text: "Let me think about this..." },
  1109. {
  1110. type: "tool-call",
  1111. toolCallId: "test",
  1112. toolName: "bash",
  1113. input: { command: "echo hello" },
  1114. },
  1115. ],
  1116. },
  1117. ] as any[]
  1118. const result = ProviderTransform.message(
  1119. msgs,
  1120. {
  1121. id: ModelV2.ID.make("deepseek/deepseek-chat"),
  1122. providerID: ProviderV2.ID.make("deepseek"),
  1123. api: {
  1124. id: "deepseek-chat",
  1125. url: "https://api.deepseek.com",
  1126. npm: "@ai-sdk/openai-compatible",
  1127. },
  1128. name: "DeepSeek Chat",
  1129. capabilities: {
  1130. temperature: true,
  1131. reasoning: true,
  1132. attachment: false,
  1133. toolcall: true,
  1134. input: { text: true, audio: false, image: false, video: false, pdf: false },
  1135. output: { text: true, audio: false, image: false, video: false, pdf: false },
  1136. interleaved: {
  1137. field: "reasoning_content",
  1138. },
  1139. },
  1140. cost: {
  1141. input: 0.001,
  1142. output: 0.002,
  1143. cache: { read: 0.0001, write: 0.0002 },
  1144. },
  1145. limit: {
  1146. context: 128000,
  1147. output: 8192,
  1148. },
  1149. status: "active",
  1150. options: {},
  1151. headers: {},
  1152. release_date: "2023-04-01",
  1153. },
  1154. {},
  1155. )
  1156. expect(result).toHaveLength(1)
  1157. expect(result[0].content).toEqual([
  1158. {
  1159. type: "tool-call",
  1160. toolCallId: "test",
  1161. toolName: "bash",
  1162. input: { command: "echo hello" },
  1163. },
  1164. ])
  1165. expect(result[0].providerOptions?.openaiCompatible?.reasoning_content).toBe("Let me think about this...")
  1166. })
  1167. test("Non-DeepSeek providers leave reasoning content unchanged", () => {
  1168. const msgs = [
  1169. {
  1170. role: "assistant",
  1171. content: [
  1172. { type: "reasoning", text: "Should not be processed" },
  1173. { type: "text", text: "Answer" },
  1174. ],
  1175. },
  1176. ] as any[]
  1177. const result = ProviderTransform.message(
  1178. msgs,
  1179. {
  1180. id: ModelV2.ID.make("openai/gpt-4"),
  1181. providerID: ProviderV2.ID.make("openai"),
  1182. api: {
  1183. id: "gpt-4",
  1184. url: "https://api.openai.com",
  1185. npm: "@ai-sdk/openai",
  1186. },
  1187. name: "GPT-4",
  1188. capabilities: {
  1189. temperature: true,
  1190. reasoning: false,
  1191. attachment: true,
  1192. toolcall: true,
  1193. input: { text: true, audio: false, image: true, video: false, pdf: false },
  1194. output: { text: true, audio: false, image: false, video: false, pdf: false },
  1195. interleaved: false,
  1196. },
  1197. cost: {
  1198. input: 0.03,
  1199. output: 0.06,
  1200. cache: { read: 0.001, write: 0.002 },
  1201. },
  1202. limit: {
  1203. context: 128000,
  1204. output: 4096,
  1205. },
  1206. status: "active",
  1207. options: {},
  1208. headers: {},
  1209. release_date: "2023-04-01",
  1210. },
  1211. {},
  1212. )
  1213. expect(result[0].content).toEqual([
  1214. { type: "reasoning", text: "Should not be processed" },
  1215. { type: "text", text: "Answer" },
  1216. ])
  1217. expect(result[0].providerOptions?.openaiCompatible?.reasoning_content).toBeUndefined()
  1218. })
  1219. })
  1220. describe("ProviderTransform.message - surrogate sanitization", () => {
  1221. const model = {
  1222. id: "test/test-model",
  1223. providerID: "test",
  1224. api: {
  1225. id: "test-model",
  1226. url: "https://api.test.com",
  1227. npm: "@ai-sdk/openai-compatible",
  1228. },
  1229. name: "Test Model",
  1230. capabilities: {
  1231. temperature: true,
  1232. reasoning: true,
  1233. attachment: true,
  1234. toolcall: true,
  1235. input: { text: true, audio: false, image: true, video: false, pdf: false },
  1236. output: { text: true, audio: false, image: false, video: false, pdf: false },
  1237. interleaved: false,
  1238. },
  1239. cost: { input: 0.001, output: 0.002, cache: { read: 0.0001, write: 0.0002 } },
  1240. limit: { context: 128000, output: 8192 },
  1241. status: "active",
  1242. options: {},
  1243. headers: {},
  1244. } as any
  1245. test("replaces lone surrogates in model-visible text", () => {
  1246. const lone = "\uD83D"
  1247. const valid = "🚀"
  1248. const sanitized = "�"
  1249. const text = (label: string) => `${label} ${lone} and ${valid}`
  1250. const expected = (label: string) => `${label} ${sanitized} and ${valid}`
  1251. const msgs = [
  1252. { role: "system", content: text("system") },
  1253. { role: "user", content: text("user string") },
  1254. {
  1255. role: "user",
  1256. content: [
  1257. { type: "text", text: text("user text") },
  1258. { type: "image", image: "data:image/png;base64,abcd" },
  1259. ],
  1260. },
  1261. { role: "assistant", content: text("assistant string") },
  1262. {
  1263. role: "assistant",
  1264. content: [
  1265. { type: "text", text: text("assistant text") },
  1266. { type: "reasoning", text: text("assistant reasoning") },
  1267. { type: "tool-call", toolCallId: "call-1", toolName: "Read", input: { filePath: ".opencode/tool/emoji.ts" } },
  1268. {
  1269. type: "tool-result",
  1270. toolCallId: "call-2",
  1271. toolName: "Read",
  1272. output: { type: "text", value: text("assistant tool text") },
  1273. },
  1274. {
  1275. type: "tool-result",
  1276. toolCallId: "call-3",
  1277. toolName: "Read",
  1278. output: { type: "error-text", value: text("assistant tool error") },
  1279. },
  1280. {
  1281. type: "tool-result",
  1282. toolCallId: "call-4",
  1283. toolName: "Read",
  1284. output: { type: "content", value: [{ type: "text", text: text("assistant tool content") }] },
  1285. },
  1286. ],
  1287. },
  1288. {
  1289. role: "tool",
  1290. content: [
  1291. {
  1292. type: "tool-result",
  1293. toolCallId: "call-5",
  1294. toolName: "Read",
  1295. output: { type: "text", value: text("tool text") },
  1296. },
  1297. {
  1298. type: "tool-result",
  1299. toolCallId: "call-6",
  1300. toolName: "Read",
  1301. output: { type: "error-text", value: text("tool error") },
  1302. },
  1303. {
  1304. type: "tool-result",
  1305. toolCallId: "call-7",
  1306. toolName: "Read",
  1307. output: { type: "content", value: [{ type: "text", text: text("tool content") }] },
  1308. },
  1309. ],
  1310. },
  1311. ] as any[]
  1312. const result = ProviderTransform.message(msgs, model, {}) as any[]
  1313. expect(result[0].content).toBe(expected("system"))
  1314. expect(result[1].content).toBe(expected("user string"))
  1315. expect(result[2].content[0].text).toBe(expected("user text"))
  1316. expect(result[3].content).toBe(expected("assistant string"))
  1317. expect(result[4].content[0].text).toBe(expected("assistant text"))
  1318. expect(result[4].content[1].text).toBe(expected("assistant reasoning"))
  1319. expect(result[4].content[3].output.value).toBe(expected("assistant tool text"))
  1320. expect(result[4].content[4].output.value).toBe(expected("assistant tool error"))
  1321. expect(result[4].content[5].output.value[0].text).toBe(expected("assistant tool content"))
  1322. expect(result[5].content[0].output.value).toBe(expected("tool text"))
  1323. expect(result[5].content[1].output.value).toBe(expected("tool error"))
  1324. expect(result[5].content[2].output.value[0].text).toBe(expected("tool content"))
  1325. expect(result[2].content[1]).toEqual({ type: "image", image: "data:image/png;base64,abcd" })
  1326. })
  1327. })
  1328. describe("ProviderTransform.message - empty image handling", () => {
  1329. const mockModel = {
  1330. id: "anthropic/claude-3-5-sonnet",
  1331. providerID: "anthropic",
  1332. api: {
  1333. id: "claude-3-5-sonnet-20241022",
  1334. url: "https://api.anthropic.com",
  1335. npm: "@ai-sdk/anthropic",
  1336. },
  1337. name: "Claude 3.5 Sonnet",
  1338. capabilities: {
  1339. temperature: true,
  1340. reasoning: false,
  1341. attachment: true,
  1342. toolcall: true,
  1343. input: { text: true, audio: false, image: true, video: false, pdf: true },
  1344. output: { text: true, audio: false, image: false, video: false, pdf: false },
  1345. interleaved: false,
  1346. },
  1347. cost: {
  1348. input: 0.003,
  1349. output: 0.015,
  1350. cache: { read: 0.0003, write: 0.00375 },
  1351. },
  1352. limit: {
  1353. context: 200000,
  1354. output: 8192,
  1355. },
  1356. status: "active",
  1357. options: {},
  1358. headers: {},
  1359. } as any
  1360. test("should replace empty base64 image with error text", () => {
  1361. const msgs = [
  1362. {
  1363. role: "user",
  1364. content: [
  1365. { type: "text", text: "What is in this image?" },
  1366. { type: "image", image: "data:image/png;base64," },
  1367. ],
  1368. },
  1369. ] as any[]
  1370. const result = ProviderTransform.message(msgs, mockModel, {})
  1371. expect(result).toHaveLength(1)
  1372. expect(result[0].content).toHaveLength(2)
  1373. expect(result[0].content[0]).toEqual({ type: "text", text: "What is in this image?" })
  1374. expect(result[0].content[1]).toEqual({
  1375. type: "text",
  1376. text: "ERROR: Image file is empty or corrupted. Please provide a valid image.",
  1377. })
  1378. })
  1379. test("should keep valid base64 images unchanged", () => {
  1380. const validBase64 =
  1381. "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg=="
  1382. const msgs = [
  1383. {
  1384. role: "user",
  1385. content: [
  1386. { type: "text", text: "What is in this image?" },
  1387. { type: "image", image: `data:image/png;base64,${validBase64}` },
  1388. ],
  1389. },
  1390. ] as any[]
  1391. const result = ProviderTransform.message(msgs, mockModel, {})
  1392. expect(result).toHaveLength(1)
  1393. expect(result[0].content).toHaveLength(2)
  1394. expect(result[0].content[0]).toEqual({ type: "text", text: "What is in this image?" })
  1395. expect(result[0].content[1]).toEqual({ type: "image", image: `data:image/png;base64,${validBase64}` })
  1396. })
  1397. test("should handle mixed valid and empty images", () => {
  1398. const validBase64 =
  1399. "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg=="
  1400. const msgs = [
  1401. {
  1402. role: "user",
  1403. content: [
  1404. { type: "text", text: "Compare these images" },
  1405. { type: "image", image: `data:image/png;base64,${validBase64}` },
  1406. { type: "image", image: "data:image/jpeg;base64," },
  1407. ],
  1408. },
  1409. ] as any[]
  1410. const result = ProviderTransform.message(msgs, mockModel, {})
  1411. expect(result).toHaveLength(1)
  1412. expect(result[0].content).toHaveLength(3)
  1413. expect(result[0].content[0]).toEqual({ type: "text", text: "Compare these images" })
  1414. expect(result[0].content[1]).toEqual({ type: "image", image: `data:image/png;base64,${validBase64}` })
  1415. expect(result[0].content[2]).toEqual({
  1416. type: "text",
  1417. text: "ERROR: Image file is empty or corrupted. Please provide a valid image.",
  1418. })
  1419. })
  1420. })
  1421. describe("ProviderTransform.message - anthropic empty content filtering", () => {
  1422. const anthropicModel = {
  1423. id: "anthropic/claude-3-5-sonnet",
  1424. providerID: "anthropic",
  1425. api: {
  1426. id: "claude-3-5-sonnet-20241022",
  1427. url: "https://api.anthropic.com",
  1428. npm: "@ai-sdk/anthropic",
  1429. },
  1430. name: "Claude 3.5 Sonnet",
  1431. capabilities: {
  1432. temperature: true,
  1433. reasoning: false,
  1434. attachment: true,
  1435. toolcall: true,
  1436. input: { text: true, audio: false, image: true, video: false, pdf: true },
  1437. output: { text: true, audio: false, image: false, video: false, pdf: false },
  1438. interleaved: false,
  1439. },
  1440. cost: {
  1441. input: 0.003,
  1442. output: 0.015,
  1443. cache: { read: 0.0003, write: 0.00375 },
  1444. },
  1445. limit: {
  1446. context: 200000,
  1447. output: 8192,
  1448. },
  1449. status: "active",
  1450. options: {},
  1451. headers: {},
  1452. } as any
  1453. test("filters out messages with empty string content", () => {
  1454. const msgs = [
  1455. { role: "user", content: "Hello" },
  1456. { role: "assistant", content: "" },
  1457. { role: "user", content: "World" },
  1458. ] as any[]
  1459. const result = ProviderTransform.message(msgs, anthropicModel, {})
  1460. expect(result).toHaveLength(2)
  1461. expect(result[0].content).toBe("Hello")
  1462. expect(result[1].content).toBe("World")
  1463. })
  1464. test("filters out empty text parts from array content", () => {
  1465. const msgs = [
  1466. {
  1467. role: "assistant",
  1468. content: [
  1469. { type: "text", text: "" },
  1470. { type: "text", text: "Hello" },
  1471. { type: "text", text: "" },
  1472. ],
  1473. },
  1474. ] as any[]
  1475. const result = ProviderTransform.message(msgs, anthropicModel, {})
  1476. expect(result).toHaveLength(1)
  1477. expect(result[0].content).toHaveLength(1)
  1478. expect(result[0].content[0]).toEqual({ type: "text", text: "Hello" })
  1479. })
  1480. test("filters out empty reasoning parts from array content", () => {
  1481. const msgs = [
  1482. {
  1483. role: "assistant",
  1484. content: [
  1485. { type: "reasoning", text: "" },
  1486. { type: "text", text: "Answer" },
  1487. { type: "reasoning", text: "" },
  1488. ],
  1489. },
  1490. ] as any[]
  1491. const result = ProviderTransform.message(msgs, anthropicModel, {})
  1492. expect(result).toHaveLength(1)
  1493. expect(result[0].content).toHaveLength(1)
  1494. expect(result[0].content[0]).toEqual({ type: "text", text: "Answer" })
  1495. })
  1496. test("removes entire message when all parts are empty", () => {
  1497. const msgs = [
  1498. { role: "user", content: "Hello" },
  1499. {
  1500. role: "assistant",
  1501. content: [
  1502. { type: "text", text: "" },
  1503. { type: "reasoning", text: "" },
  1504. ],
  1505. },
  1506. { role: "user", content: "World" },
  1507. ] as any[]
  1508. const result = ProviderTransform.message(msgs, anthropicModel, {})
  1509. expect(result).toHaveLength(2)
  1510. expect(result[0].content).toBe("Hello")
  1511. expect(result[1].content).toBe("World")
  1512. })
  1513. test("keeps non-text/reasoning parts even if text parts are empty", () => {
  1514. const msgs = [
  1515. {
  1516. role: "assistant",
  1517. content: [
  1518. { type: "text", text: "" },
  1519. { type: "tool-call", toolCallId: "123", toolName: "bash", input: { command: "ls" } },
  1520. ],
  1521. },
  1522. ] as any[]
  1523. const result = ProviderTransform.message(msgs, anthropicModel, {})
  1524. expect(result).toHaveLength(1)
  1525. expect(result[0].content).toHaveLength(1)
  1526. expect(result[0].content[0]).toEqual({
  1527. type: "tool-call",
  1528. toolCallId: "123",
  1529. toolName: "bash",
  1530. input: { command: "ls" },
  1531. })
  1532. })
  1533. test("keeps messages with valid text alongside empty parts", () => {
  1534. const msgs = [
  1535. {
  1536. role: "assistant",
  1537. content: [
  1538. { type: "reasoning", text: "Thinking..." },
  1539. { type: "text", text: "" },
  1540. { type: "text", text: "Result" },
  1541. ],
  1542. },
  1543. ] as any[]
  1544. const result = ProviderTransform.message(msgs, anthropicModel, {})
  1545. expect(result).toHaveLength(1)
  1546. expect(result[0].content).toHaveLength(2)
  1547. expect(result[0].content[0]).toEqual({ type: "reasoning", text: "Thinking..." })
  1548. expect(result[0].content[1]).toEqual({ type: "text", text: "Result" })
  1549. })
  1550. test("filters empty content for bedrock provider", () => {
  1551. const bedrockModel = {
  1552. ...anthropicModel,
  1553. id: "amazon-bedrock/anthropic.claude-opus-4-6",
  1554. providerID: "amazon-bedrock",
  1555. api: {
  1556. id: "anthropic.claude-opus-4-6",
  1557. url: "https://bedrock-runtime.us-east-1.amazonaws.com",
  1558. npm: "@ai-sdk/amazon-bedrock",
  1559. },
  1560. }
  1561. const msgs = [
  1562. { role: "user", content: "Hello" },
  1563. { role: "assistant", content: "" },
  1564. {
  1565. role: "assistant",
  1566. content: [
  1567. { type: "text", text: "" },
  1568. { type: "text", text: "Answer" },
  1569. ],
  1570. },
  1571. ] as any[]
  1572. const result = ProviderTransform.message(msgs, bedrockModel, {})
  1573. expect(result).toHaveLength(2)
  1574. expect(result[0].content).toBe("Hello")
  1575. expect(result[1].content).toHaveLength(1)
  1576. expect(result[1].content[0]).toEqual({ type: "text", text: "Answer" })
  1577. })
  1578. test("does not filter for non-anthropic providers", () => {
  1579. const openaiModel = {
  1580. ...anthropicModel,
  1581. providerID: "openai",
  1582. api: {
  1583. id: "gpt-4",
  1584. url: "https://api.openai.com",
  1585. npm: "@ai-sdk/openai",
  1586. },
  1587. }
  1588. const msgs = [
  1589. { role: "assistant", content: "" },
  1590. {
  1591. role: "assistant",
  1592. content: [{ type: "text", text: "" }],
  1593. },
  1594. ] as any[]
  1595. const result = ProviderTransform.message(msgs, openaiModel, {})
  1596. expect(result).toHaveLength(2)
  1597. expect(result[0].content).toBe("")
  1598. expect(result[1].content).toHaveLength(1)
  1599. })
  1600. test("leaves valid anthropic assistant tool ordering unchanged", () => {
  1601. const msgs = [
  1602. {
  1603. role: "assistant",
  1604. content: [
  1605. { type: "text", text: "I checked your home directory and looked for PDF files." },
  1606. { type: "tool-call", toolCallId: "toolu_1", toolName: "read", input: { filePath: "/root" } },
  1607. { type: "tool-call", toolCallId: "toolu_2", toolName: "glob", input: { pattern: "**/*.pdf" } },
  1608. ],
  1609. },
  1610. ] as any[]
  1611. const result = ProviderTransform.message(msgs, anthropicModel, {}) as any[]
  1612. expect(result).toHaveLength(1)
  1613. expect(result[0].content).toMatchObject([
  1614. { type: "text", text: "I checked your home directory and looked for PDF files." },
  1615. { type: "tool-call", toolCallId: "toolu_1", toolName: "read", input: { filePath: "/root" } },
  1616. { type: "tool-call", toolCallId: "toolu_2", toolName: "glob", input: { pattern: "**/*.pdf" } },
  1617. ])
  1618. })
  1619. })
  1620. describe("ProviderTransform.message - strip openai metadata when store=false", () => {
  1621. const openaiModel = {
  1622. id: "openai/gpt-5",
  1623. providerID: "openai",
  1624. api: {
  1625. id: "gpt-5",
  1626. url: "https://api.openai.com",
  1627. npm: "@ai-sdk/openai",
  1628. },
  1629. name: "GPT-5",
  1630. capabilities: {
  1631. temperature: true,
  1632. reasoning: true,
  1633. attachment: true,
  1634. toolcall: true,
  1635. input: { text: true, audio: false, image: true, video: false, pdf: false },
  1636. output: { text: true, audio: false, image: false, video: false, pdf: false },
  1637. interleaved: false,
  1638. },
  1639. cost: { input: 0.03, output: 0.06, cache: { read: 0.001, write: 0.002 } },
  1640. limit: { context: 128000, output: 4096 },
  1641. status: "active",
  1642. options: {},
  1643. headers: {},
  1644. } as any
  1645. test("strips OpenAI itemId and preserves reasoningEncryptedContent when store=false", () => {
  1646. const msgs = [
  1647. {
  1648. role: "assistant",
  1649. content: [
  1650. {
  1651. type: "reasoning",
  1652. text: "thinking...",
  1653. providerOptions: {
  1654. openai: {
  1655. itemId: "rs_123",
  1656. reasoningEncryptedContent: "encrypted",
  1657. },
  1658. },
  1659. },
  1660. {
  1661. type: "text",
  1662. text: "Hello",
  1663. providerOptions: {
  1664. openai: {
  1665. itemId: "msg_456",
  1666. },
  1667. },
  1668. },
  1669. ],
  1670. },
  1671. ] as any[]
  1672. const result = ProviderTransform.message(msgs, openaiModel, { store: false }) as any[]
  1673. expect(result).toHaveLength(1)
  1674. expect(result[0].content[0].providerOptions?.openai?.itemId).toBeUndefined()
  1675. expect(result[0].content[0].providerOptions?.openai?.reasoningEncryptedContent).toBe("encrypted")
  1676. expect(result[0].content[1].providerOptions?.openai?.itemId).toBeUndefined()
  1677. })
  1678. test("uses the SDK package namespace rather than provider ID", () => {
  1679. const zenModel = {
  1680. ...openaiModel,
  1681. providerID: "zen",
  1682. }
  1683. const msgs = [
  1684. {
  1685. role: "assistant",
  1686. content: [
  1687. {
  1688. type: "reasoning",
  1689. text: "thinking...",
  1690. providerOptions: {
  1691. openai: {
  1692. itemId: "rs_123",
  1693. reasoningEncryptedContent: "encrypted",
  1694. },
  1695. },
  1696. },
  1697. {
  1698. type: "text",
  1699. text: "Hello",
  1700. providerOptions: {
  1701. openai: {
  1702. itemId: "msg_456",
  1703. },
  1704. },
  1705. },
  1706. ],
  1707. },
  1708. ] as any[]
  1709. const result = ProviderTransform.message(msgs, zenModel, { store: false }) as any[]
  1710. expect(result).toHaveLength(1)
  1711. expect(result[0].content[0].providerOptions?.openai?.itemId).toBeUndefined()
  1712. expect(result[0].content[0].providerOptions?.openai?.reasoningEncryptedContent).toBe("encrypted")
  1713. expect(result[0].content[1].providerOptions?.openai?.itemId).toBeUndefined()
  1714. })
  1715. test("preserves other OpenAI options", () => {
  1716. const msgs = [
  1717. {
  1718. role: "assistant",
  1719. content: [
  1720. {
  1721. type: "text",
  1722. text: "Hello",
  1723. providerOptions: {
  1724. openai: {
  1725. itemId: "msg_123",
  1726. otherOption: "value",
  1727. },
  1728. },
  1729. },
  1730. ],
  1731. },
  1732. ] as any[]
  1733. const result = ProviderTransform.message(msgs, openaiModel, { store: false }) as any[]
  1734. expect(result[0].content[0].providerOptions?.openai?.itemId).toBeUndefined()
  1735. expect(result[0].content[0].providerOptions?.openai?.otherOption).toBe("value")
  1736. })
  1737. test("strips Azure itemId from the Azure namespace", () => {
  1738. const azureModel = {
  1739. ...openaiModel,
  1740. providerID: "azure",
  1741. api: {
  1742. id: "gpt-5",
  1743. url: "https://example.openai.azure.com",
  1744. npm: "@ai-sdk/azure",
  1745. },
  1746. }
  1747. const msgs = [
  1748. {
  1749. role: "assistant",
  1750. content: [
  1751. {
  1752. type: "text",
  1753. text: "Hello",
  1754. providerOptions: {
  1755. azure: { itemId: "msg_123", otherOption: "value" },
  1756. openai: { itemId: "msg_openai" },
  1757. },
  1758. },
  1759. ],
  1760. },
  1761. ] as any[]
  1762. const result = ProviderTransform.message(msgs, azureModel, { store: false }) as any[]
  1763. expect(result[0].content[0].providerOptions?.azure?.itemId).toBeUndefined()
  1764. expect(result[0].content[0].providerOptions?.azure?.otherOption).toBe("value")
  1765. expect(result[0].content[0].providerOptions?.openai?.itemId).toBe("msg_openai")
  1766. })
  1767. test("strips Bedrock Mantle itemId from the OpenAI namespace", () => {
  1768. const mantleModel = {
  1769. ...openaiModel,
  1770. providerID: "amazon-bedrock",
  1771. api: {
  1772. id: "openai.gpt-5.5",
  1773. url: "https://bedrock-mantle.us-east-2.api.aws/openai/v1",
  1774. npm: "@ai-sdk/amazon-bedrock/mantle",
  1775. },
  1776. }
  1777. const msgs = [
  1778. {
  1779. role: "assistant",
  1780. providerOptions: { openai: { itemId: "msg_root", otherOption: "root-value" } },
  1781. content: [
  1782. {
  1783. type: "reasoning",
  1784. text: "thinking...",
  1785. providerOptions: {
  1786. openai: { itemId: "rs_123", reasoningEncryptedContent: "encrypted" },
  1787. },
  1788. },
  1789. ],
  1790. },
  1791. ] as any[]
  1792. const result = ProviderTransform.message(msgs, mantleModel, { store: false }) as any[]
  1793. expect(result[0].providerOptions?.openai?.itemId).toBeUndefined()
  1794. expect(result[0].providerOptions?.openai?.otherOption).toBe("root-value")
  1795. expect(result[0].content[0].providerOptions?.openai?.itemId).toBeUndefined()
  1796. expect(result[0].content[0].providerOptions?.openai?.reasoningEncryptedContent).toBe("encrypted")
  1797. })
  1798. test("preserves metadata for openai package when store is true", () => {
  1799. const msgs = [
  1800. {
  1801. role: "assistant",
  1802. content: [
  1803. {
  1804. type: "text",
  1805. text: "Hello",
  1806. providerOptions: {
  1807. openai: {
  1808. itemId: "msg_123",
  1809. },
  1810. },
  1811. },
  1812. ],
  1813. },
  1814. ] as any[]
  1815. // openai package preserves itemId regardless of store value
  1816. const result = ProviderTransform.message(msgs, openaiModel, { store: true }) as any[]
  1817. expect(result[0].content[0].providerOptions?.openai?.itemId).toBe("msg_123")
  1818. })
  1819. test("preserves metadata for non-openai packages when store is false", () => {
  1820. const anthropicModel = {
  1821. ...openaiModel,
  1822. providerID: "anthropic",
  1823. api: {
  1824. id: "claude-3",
  1825. url: "https://api.anthropic.com",
  1826. npm: "@ai-sdk/anthropic",
  1827. },
  1828. }
  1829. const msgs = [
  1830. {
  1831. role: "assistant",
  1832. content: [
  1833. {
  1834. type: "text",
  1835. text: "Hello",
  1836. providerOptions: {
  1837. openai: {
  1838. itemId: "msg_123",
  1839. },
  1840. },
  1841. },
  1842. ],
  1843. },
  1844. ] as any[]
  1845. // store=false preserves metadata for non-openai packages
  1846. const result = ProviderTransform.message(msgs, anthropicModel, { store: false }) as any[]
  1847. expect(result[0].content[0].providerOptions?.openai?.itemId).toBe("msg_123")
  1848. })
  1849. test("preserves metadata using providerID key when store is false", () => {
  1850. const opencodeModel = {
  1851. ...openaiModel,
  1852. providerID: "opencode",
  1853. api: {
  1854. id: "opencode-test",
  1855. url: "https://api.opencode.ai",
  1856. npm: "@ai-sdk/openai-compatible",
  1857. },
  1858. }
  1859. const msgs = [
  1860. {
  1861. role: "assistant",
  1862. content: [
  1863. {
  1864. type: "text",
  1865. text: "Hello",
  1866. providerOptions: {
  1867. opencode: {
  1868. itemId: "msg_123",
  1869. otherOption: "value",
  1870. },
  1871. },
  1872. },
  1873. ],
  1874. },
  1875. ] as any[]
  1876. const result = ProviderTransform.message(msgs, opencodeModel, { store: false }) as any[]
  1877. expect(result[0].content[0].providerOptions?.opencode?.itemId).toBe("msg_123")
  1878. expect(result[0].content[0].providerOptions?.opencode?.otherOption).toBe("value")
  1879. })
  1880. test("preserves itemId across all providerOptions keys", () => {
  1881. const opencodeModel = {
  1882. ...openaiModel,
  1883. providerID: "opencode",
  1884. api: {
  1885. id: "opencode-test",
  1886. url: "https://api.opencode.ai",
  1887. npm: "@ai-sdk/openai-compatible",
  1888. },
  1889. }
  1890. const msgs = [
  1891. {
  1892. role: "assistant",
  1893. providerOptions: {
  1894. openai: { itemId: "msg_root" },
  1895. opencode: { itemId: "msg_opencode" },
  1896. extra: { itemId: "msg_extra" },
  1897. },
  1898. content: [
  1899. {
  1900. type: "text",
  1901. text: "Hello",
  1902. providerOptions: {
  1903. openai: { itemId: "msg_openai_part" },
  1904. opencode: { itemId: "msg_opencode_part" },
  1905. extra: { itemId: "msg_extra_part" },
  1906. },
  1907. },
  1908. ],
  1909. },
  1910. ] as any[]
  1911. const result = ProviderTransform.message(msgs, opencodeModel, { store: false }) as any[]
  1912. expect(result[0].providerOptions?.openai?.itemId).toBe("msg_root")
  1913. expect(result[0].providerOptions?.opencode?.itemId).toBe("msg_opencode")
  1914. expect(result[0].providerOptions?.extra?.itemId).toBe("msg_extra")
  1915. expect(result[0].content[0].providerOptions?.openai?.itemId).toBe("msg_openai_part")
  1916. expect(result[0].content[0].providerOptions?.opencode?.itemId).toBe("msg_opencode_part")
  1917. expect(result[0].content[0].providerOptions?.extra?.itemId).toBe("msg_extra_part")
  1918. })
  1919. test("does not strip metadata for non-openai packages when store is not false", () => {
  1920. const anthropicModel = {
  1921. ...openaiModel,
  1922. providerID: "anthropic",
  1923. api: {
  1924. id: "claude-3",
  1925. url: "https://api.anthropic.com",
  1926. npm: "@ai-sdk/anthropic",
  1927. },
  1928. }
  1929. const msgs = [
  1930. {
  1931. role: "assistant",
  1932. content: [
  1933. {
  1934. type: "text",
  1935. text: "Hello",
  1936. providerOptions: {
  1937. openai: {
  1938. itemId: "msg_123",
  1939. },
  1940. },
  1941. },
  1942. ],
  1943. },
  1944. ] as any[]
  1945. const result = ProviderTransform.message(msgs, anthropicModel, {}) as any[]
  1946. expect(result[0].content[0].providerOptions?.openai?.itemId).toBe("msg_123")
  1947. })
  1948. })
  1949. describe("ProviderTransform.message - providerOptions key remapping", () => {
  1950. const createModel = (providerID: string, npm: string) =>
  1951. ({
  1952. id: `${providerID}/test-model`,
  1953. providerID,
  1954. api: {
  1955. id: "test-model",
  1956. url: "https://api.test.com",
  1957. npm,
  1958. },
  1959. name: "Test Model",
  1960. capabilities: {
  1961. temperature: true,
  1962. reasoning: false,
  1963. attachment: true,
  1964. toolcall: true,
  1965. input: { text: true, audio: false, image: true, video: false, pdf: true },
  1966. output: { text: true, audio: false, image: false, video: false, pdf: false },
  1967. interleaved: false,
  1968. },
  1969. cost: { input: 0.001, output: 0.002, cache: { read: 0.0001, write: 0.0002 } },
  1970. limit: { context: 128000, output: 8192 },
  1971. status: "active",
  1972. options: {},
  1973. headers: {},
  1974. }) as any
  1975. test("azure keeps 'azure' key and does not remap to 'openai'", () => {
  1976. const model = createModel("azure", "@ai-sdk/azure")
  1977. const msgs = [
  1978. {
  1979. role: "user",
  1980. content: "Hello",
  1981. providerOptions: {
  1982. azure: { someOption: "value" },
  1983. },
  1984. },
  1985. ] as any[]
  1986. const result = ProviderTransform.message(msgs, model, {})
  1987. expect(result[0].providerOptions?.azure).toEqual({ someOption: "value" })
  1988. expect(result[0].providerOptions?.openai).toBeUndefined()
  1989. })
  1990. test("azure cognitive services remaps providerID to 'azure' key", () => {
  1991. const model = createModel("azure-cognitive-services", "@ai-sdk/azure")
  1992. const msgs = [
  1993. {
  1994. role: "user",
  1995. content: [
  1996. {
  1997. type: "text",
  1998. text: "Hello",
  1999. providerOptions: {
  2000. "azure-cognitive-services": { part: true },
  2001. },
  2002. },
  2003. ],
  2004. providerOptions: {
  2005. "azure-cognitive-services": { someOption: "value" },
  2006. },
  2007. },
  2008. ] as any[]
  2009. const result = ProviderTransform.message(msgs, model, {}) as any[]
  2010. const part = result[0].content[0] as any
  2011. expect(result[0].providerOptions?.azure).toEqual({ someOption: "value" })
  2012. expect(result[0].providerOptions?.["azure-cognitive-services"]).toBeUndefined()
  2013. expect(part.providerOptions?.azure).toEqual({ part: true })
  2014. expect(part.providerOptions?.["azure-cognitive-services"]).toBeUndefined()
  2015. })
  2016. test("copilot remaps providerID to 'copilot' key", () => {
  2017. const model = createModel("github-copilot", "@ai-sdk/github-copilot")
  2018. const msgs = [
  2019. {
  2020. role: "user",
  2021. content: "Hello",
  2022. providerOptions: {
  2023. copilot: { someOption: "value" },
  2024. },
  2025. },
  2026. ] as any[]
  2027. const result = ProviderTransform.message(msgs, model, {})
  2028. expect(result[0].providerOptions?.copilot).toEqual({ someOption: "value" })
  2029. expect(result[0].providerOptions?.["github-copilot"]).toBeUndefined()
  2030. })
  2031. test("bedrock remaps providerID to 'bedrock' key", () => {
  2032. const model = createModel("my-bedrock", "@ai-sdk/amazon-bedrock")
  2033. const msgs = [
  2034. {
  2035. role: "user",
  2036. content: "Hello",
  2037. providerOptions: {
  2038. "my-bedrock": { someOption: "value" },
  2039. },
  2040. },
  2041. ] as any[]
  2042. const result = ProviderTransform.message(msgs, model, {})
  2043. expect(result[0].providerOptions?.bedrock).toEqual({ someOption: "value" })
  2044. expect(result[0].providerOptions?.["my-bedrock"]).toBeUndefined()
  2045. })
  2046. })
  2047. describe("ProviderTransform.message - claude w/bedrock custom inference profile", () => {
  2048. test("adds cachePoint", () => {
  2049. const model = {
  2050. id: "amazon-bedrock/custom-claude-sonnet-4.5",
  2051. providerID: "amazon-bedrock",
  2052. api: {
  2053. id: "arn:aws:bedrock:xxx:yyy:application-inference-profile/zzz",
  2054. url: "https://api.test.com",
  2055. npm: "@ai-sdk/amazon-bedrock",
  2056. },
  2057. name: "Custom inference profile",
  2058. capabilities: {},
  2059. options: {},
  2060. headers: {},
  2061. } as any
  2062. const msgs = [
  2063. {
  2064. role: "user",
  2065. content: "Hello",
  2066. },
  2067. ] as any[]
  2068. const result = ProviderTransform.message(msgs, model, {})
  2069. expect(result[0].providerOptions?.bedrock).toEqual(
  2070. expect.objectContaining({
  2071. cachePoint: {
  2072. type: "default",
  2073. },
  2074. }),
  2075. )
  2076. })
  2077. })
  2078. describe("ProviderTransform.message - bedrock caching with non-bedrock providerID", () => {
  2079. test("applies cache options at message level when npm package is amazon-bedrock", () => {
  2080. const model = {
  2081. id: "aws/us.anthropic.claude-opus-4-6-v1",
  2082. providerID: "aws",
  2083. api: {
  2084. id: "us.anthropic.claude-opus-4-6-v1",
  2085. url: "https://bedrock-runtime.us-east-1.amazonaws.com",
  2086. npm: "@ai-sdk/amazon-bedrock",
  2087. },
  2088. name: "Claude Opus 4.6",
  2089. capabilities: {},
  2090. options: {},
  2091. headers: {},
  2092. } as any
  2093. const msgs = [
  2094. {
  2095. role: "system",
  2096. content: "You are a helpful assistant",
  2097. },
  2098. {
  2099. role: "user",
  2100. content: [{ type: "text", text: "Hello" }],
  2101. },
  2102. ] as any[]
  2103. const result = ProviderTransform.message(msgs, model, {}) as any[]
  2104. // Cache should be at the message level and not the content-part level
  2105. expect(result[0].providerOptions?.bedrock).toEqual({
  2106. cachePoint: { type: "default" },
  2107. })
  2108. expect(result[0].content).toBe("You are a helpful assistant")
  2109. })
  2110. })
  2111. describe("ProviderTransform.message - cache control on gateway", () => {
  2112. const createModel = (overrides: Partial<any> = {}) =>
  2113. ({
  2114. id: "anthropic/claude-sonnet-4",
  2115. providerID: "vercel",
  2116. api: {
  2117. id: "anthropic/claude-sonnet-4",
  2118. url: "https://ai-gateway.vercel.sh/v3/ai",
  2119. npm: "@ai-sdk/gateway",
  2120. },
  2121. name: "Claude Sonnet 4",
  2122. capabilities: {
  2123. temperature: true,
  2124. reasoning: true,
  2125. attachment: true,
  2126. toolcall: true,
  2127. input: { text: true, audio: false, image: true, video: false, pdf: true },
  2128. output: { text: true, audio: false, image: false, video: false, pdf: false },
  2129. interleaved: false,
  2130. },
  2131. cost: { input: 0.001, output: 0.002, cache: { read: 0.0001, write: 0.0002 } },
  2132. limit: { context: 200_000, output: 8192 },
  2133. status: "active",
  2134. options: {},
  2135. headers: {},
  2136. ...overrides,
  2137. }) as any
  2138. test("gateway does not set cache control for anthropic models", () => {
  2139. const model = createModel()
  2140. const msgs = [
  2141. {
  2142. role: "system",
  2143. content: "You are a helpful assistant",
  2144. },
  2145. {
  2146. role: "user",
  2147. content: "Hello",
  2148. },
  2149. ] as any[]
  2150. const result = ProviderTransform.message(msgs, model, {}) as any[]
  2151. expect(result[0].content).toBe("You are a helpful assistant")
  2152. expect(result[0].providerOptions).toBeUndefined()
  2153. })
  2154. test("non-gateway anthropic keeps existing cache control behavior", () => {
  2155. const model = createModel({
  2156. providerID: "anthropic",
  2157. api: {
  2158. id: "claude-sonnet-4",
  2159. url: "https://api.anthropic.com",
  2160. npm: "@ai-sdk/anthropic",
  2161. },
  2162. })
  2163. const msgs = [
  2164. {
  2165. role: "system",
  2166. content: "You are a helpful assistant",
  2167. },
  2168. {
  2169. role: "user",
  2170. content: "Hello",
  2171. },
  2172. ] as any[]
  2173. const result = ProviderTransform.message(msgs, model, {}) as any[]
  2174. expect(result[0].providerOptions).toEqual({
  2175. anthropic: {
  2176. cacheControl: {
  2177. type: "ephemeral",
  2178. },
  2179. },
  2180. openrouter: {
  2181. cacheControl: {
  2182. type: "ephemeral",
  2183. },
  2184. },
  2185. bedrock: {
  2186. cachePoint: {
  2187. type: "default",
  2188. },
  2189. },
  2190. openaiCompatible: {
  2191. cache_control: {
  2192. type: "ephemeral",
  2193. },
  2194. },
  2195. copilot: {
  2196. copilot_cache_control: {
  2197. type: "ephemeral",
  2198. },
  2199. },
  2200. alibaba: {
  2201. cacheControl: {
  2202. type: "ephemeral",
  2203. },
  2204. },
  2205. })
  2206. })
  2207. test("google-vertex-anthropic applies cache control", () => {
  2208. const model = createModel({
  2209. providerID: "google-vertex-anthropic",
  2210. api: {
  2211. id: "google-vertex-anthropic",
  2212. url: "https://us-central1-aiplatform.googleapis.com",
  2213. npm: "@ai-sdk/google-vertex/anthropic",
  2214. },
  2215. id: "claude-sonnet-4@20250514",
  2216. })
  2217. const msgs = [
  2218. {
  2219. role: "system",
  2220. content: "You are a helpful assistant",
  2221. },
  2222. {
  2223. role: "user",
  2224. content: "Hello",
  2225. },
  2226. ] as any[]
  2227. const result = ProviderTransform.message(msgs, model, {}) as any[]
  2228. expect(result[0].providerOptions).toEqual({
  2229. anthropic: {
  2230. cacheControl: {
  2231. type: "ephemeral",
  2232. },
  2233. },
  2234. openrouter: {
  2235. cacheControl: {
  2236. type: "ephemeral",
  2237. },
  2238. },
  2239. bedrock: {
  2240. cachePoint: {
  2241. type: "default",
  2242. },
  2243. },
  2244. openaiCompatible: {
  2245. cache_control: {
  2246. type: "ephemeral",
  2247. },
  2248. },
  2249. copilot: {
  2250. copilot_cache_control: {
  2251. type: "ephemeral",
  2252. },
  2253. },
  2254. alibaba: {
  2255. cacheControl: {
  2256. type: "ephemeral",
  2257. },
  2258. },
  2259. })
  2260. })
  2261. })
  2262. describe("ProviderTransform.temperature - Cohere North", () => {
  2263. test("defaults north-mini-code models to 1.0", () => {
  2264. expect(ProviderTransform.temperature({ id: "cohere/North-Mini-Code-1-0-latest" } as any)).toBe(1.0)
  2265. })
  2266. })
  2267. describe("ProviderTransform.variants", () => {
  2268. const createMockModel = (overrides: Partial<any> = {}): any => ({
  2269. id: "test/test-model",
  2270. providerID: "test",
  2271. api: {
  2272. id: "test-model",
  2273. url: "https://api.test.com",
  2274. npm: "@ai-sdk/openai",
  2275. },
  2276. name: "Test Model",
  2277. capabilities: {
  2278. temperature: true,
  2279. reasoning: true,
  2280. attachment: true,
  2281. toolcall: true,
  2282. input: { text: true, audio: false, image: true, video: false, pdf: false },
  2283. output: { text: true, audio: false, image: false, video: false, pdf: false },
  2284. interleaved: false,
  2285. },
  2286. cost: {
  2287. input: 0.001,
  2288. output: 0.002,
  2289. cache: { read: 0.0001, write: 0.0002 },
  2290. },
  2291. limit: {
  2292. context: 200_000,
  2293. output: 64_000,
  2294. },
  2295. status: "active",
  2296. options: {},
  2297. headers: {},
  2298. release_date: "2024-01-01",
  2299. ...overrides,
  2300. })
  2301. test("returns empty object when model has no reasoning capabilities", () => {
  2302. const model = createMockModel({
  2303. capabilities: { reasoning: false },
  2304. })
  2305. const result = ProviderTransform.variants(model)
  2306. expect(result).toEqual({})
  2307. })
  2308. test("deepseek returns empty object", () => {
  2309. const model = createMockModel({
  2310. id: "deepseek/deepseek-chat",
  2311. providerID: "deepseek",
  2312. api: {
  2313. id: "deepseek-chat",
  2314. url: "https://api.deepseek.com",
  2315. npm: "@ai-sdk/openai-compatible",
  2316. },
  2317. })
  2318. const result = ProviderTransform.variants(model)
  2319. expect(result).toEqual({})
  2320. })
  2321. test("minimax returns empty object", () => {
  2322. const model = createMockModel({
  2323. id: "minimax/minimax-model",
  2324. providerID: "minimax",
  2325. api: {
  2326. id: "minimax-model",
  2327. url: "https://api.minimax.com",
  2328. npm: "@ai-sdk/openai-compatible",
  2329. },
  2330. })
  2331. const result = ProviderTransform.variants(model)
  2332. expect(result).toEqual({})
  2333. })
  2334. test("minimax m3 using anthropic returns thinking toggles", () => {
  2335. const model = createMockModel({
  2336. id: "minimax/minimax-m3",
  2337. providerID: "minimax",
  2338. api: {
  2339. id: "MiniMax-M3",
  2340. url: "https://api.minimax.com/anthropic/v1",
  2341. npm: "@ai-sdk/anthropic",
  2342. },
  2343. })
  2344. const result = ProviderTransform.variants(model)
  2345. expect(result).toEqual({
  2346. none: { thinking: { type: "disabled" } },
  2347. thinking: { thinking: { type: "adaptive" } },
  2348. })
  2349. })
  2350. test("minimax m3 using openai-compatible returns thinking toggles", () => {
  2351. const model = createMockModel({
  2352. id: "minimax/minimax-m3",
  2353. providerID: "minimax",
  2354. api: {
  2355. id: "minimax-m3",
  2356. url: "https://api.minimax.com/v1",
  2357. npm: "@ai-sdk/openai-compatible",
  2358. },
  2359. })
  2360. expect(ProviderTransform.variants(model)).toEqual({
  2361. none: { thinking: { type: "disabled" } },
  2362. thinking: { thinking: { type: "adaptive" } },
  2363. })
  2364. })
  2365. test("glm returns empty object", () => {
  2366. const model = createMockModel({
  2367. id: "glm/glm-4",
  2368. providerID: "glm",
  2369. api: {
  2370. id: "glm-4",
  2371. url: "https://api.glm.com",
  2372. npm: "@ai-sdk/openai-compatible",
  2373. },
  2374. })
  2375. const result = ProviderTransform.variants(model)
  2376. expect(result).toEqual({})
  2377. })
  2378. test("mistral models with reasoning support return variants", () => {
  2379. const model = createMockModel({
  2380. id: "mistral/mistral-small-latest",
  2381. providerID: "mistral",
  2382. api: {
  2383. id: "mistral-small-latest",
  2384. url: "https://api.mistral.com",
  2385. npm: "@ai-sdk/mistral",
  2386. },
  2387. capabilities: { reasoning: true },
  2388. })
  2389. const result = ProviderTransform.variants(model)
  2390. expect(result).toEqual({
  2391. high: { reasoningEffort: "high" },
  2392. })
  2393. })
  2394. test("mistral-medium-3.5 with reasoning returns variants", () => {
  2395. const model = createMockModel({
  2396. id: "mistral/mistral-medium-3.5",
  2397. providerID: "mistral",
  2398. api: {
  2399. id: "mistral-medium-3.5",
  2400. url: "https://api.mistral.com",
  2401. npm: "@ai-sdk/mistral",
  2402. },
  2403. capabilities: { reasoning: true },
  2404. })
  2405. const result = ProviderTransform.variants(model)
  2406. expect(result).toEqual({
  2407. high: { reasoningEffort: "high" },
  2408. })
  2409. })
  2410. test("mistral without reasoning returns empty object", () => {
  2411. const model = createMockModel({
  2412. id: "mistral/mistral-large",
  2413. providerID: "mistral",
  2414. api: {
  2415. id: "mistral-large-latest",
  2416. url: "https://api.mistral.com",
  2417. npm: "@ai-sdk/mistral",
  2418. },
  2419. capabilities: { reasoning: false },
  2420. })
  2421. const result = ProviderTransform.variants(model)
  2422. expect(result).toEqual({})
  2423. })
  2424. test("mistral large with reasoning returns empty object (only small supports reasoning)", () => {
  2425. const model = createMockModel({
  2426. id: "mistral/mistral-large",
  2427. providerID: "mistral",
  2428. api: {
  2429. id: "mistral-large-latest",
  2430. url: "https://api.mistral.com",
  2431. npm: "@ai-sdk/mistral",
  2432. },
  2433. capabilities: { reasoning: true },
  2434. })
  2435. const result = ProviderTransform.variants(model)
  2436. expect(result).toEqual({})
  2437. })
  2438. describe("@openrouter/ai-sdk-provider", () => {
  2439. test("returns widely supported efforts for other reasoning models", () => {
  2440. const model = createMockModel({
  2441. id: "openrouter/test-model",
  2442. providerID: "openrouter",
  2443. api: {
  2444. id: "test-model",
  2445. url: "https://openrouter.ai",
  2446. npm: "@openrouter/ai-sdk-provider",
  2447. },
  2448. })
  2449. const result = ProviderTransform.variants(model)
  2450. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  2451. expect(result.medium).toEqual({ reasoning: { effort: "medium" } })
  2452. })
  2453. test("gpt models return OPENAI_EFFORTS with reasoning", () => {
  2454. const model = createMockModel({
  2455. id: "openrouter/gpt-4",
  2456. providerID: "openrouter",
  2457. api: {
  2458. id: "gpt-4",
  2459. url: "https://openrouter.ai",
  2460. npm: "@openrouter/ai-sdk-provider",
  2461. },
  2462. })
  2463. const result = ProviderTransform.variants(model)
  2464. expect(Object.keys(result)).toEqual(["none", "minimal", "low", "medium", "high", "xhigh"])
  2465. expect(result.low).toEqual({ reasoning: { effort: "low" } })
  2466. expect(result.high).toEqual({ reasoning: { effort: "high" } })
  2467. })
  2468. for (const testCase of [
  2469. { id: "openai/o3-mini", efforts: ["none", "minimal", "low", "medium", "high", "xhigh"] },
  2470. { id: "openai/gpt-5.4", efforts: ["none", "low", "medium", "high", "xhigh"] },
  2471. { id: "openai/gpt-5-pro", efforts: ["high"] },
  2472. { id: "openai/gpt-5.5-pro", efforts: ["medium", "high", "xhigh"] },
  2473. { id: "openai/gpt-5.2-codex", efforts: ["low", "medium", "high", "xhigh"] },
  2474. { id: "openai/gpt-5.3-codex", efforts: ["none", "low", "medium", "high", "xhigh"] },
  2475. { id: "openai/gpt-5.3-codex-max", efforts: ["none", "low", "medium", "high", "xhigh"] },
  2476. { id: "openai/gpt-5-chat-latest", efforts: [] },
  2477. { id: "openai/gpt-5.2-chat-latest", efforts: ["medium"] },
  2478. ]) {
  2479. test(`${testCase.id} returns supported OpenAI reasoning efforts`, () => {
  2480. const result = ProviderTransform.variants(
  2481. createMockModel({
  2482. id: testCase.id,
  2483. providerID: "openrouter",
  2484. api: {
  2485. id: testCase.id,
  2486. url: "https://openrouter.ai",
  2487. npm: "@openrouter/ai-sdk-provider",
  2488. },
  2489. }),
  2490. )
  2491. expect(Object.keys(result)).toEqual(testCase.efforts)
  2492. })
  2493. }
  2494. test("gemini-3 returns widely supported efforts with reasoning", () => {
  2495. const model = createMockModel({
  2496. id: "openrouter/gemini-3-5-pro",
  2497. providerID: "openrouter",
  2498. api: {
  2499. id: "gemini-3-5-pro",
  2500. url: "https://openrouter.ai",
  2501. npm: "@openrouter/ai-sdk-provider",
  2502. },
  2503. })
  2504. const result = ProviderTransform.variants(model)
  2505. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  2506. })
  2507. test("grok-4 returns empty object", () => {
  2508. const model = createMockModel({
  2509. id: "openrouter/grok-4",
  2510. providerID: "openrouter",
  2511. api: {
  2512. id: "grok-4",
  2513. url: "https://openrouter.ai",
  2514. npm: "@openrouter/ai-sdk-provider",
  2515. },
  2516. })
  2517. const result = ProviderTransform.variants(model)
  2518. expect(result).toEqual({})
  2519. })
  2520. test("grok-3-mini returns low and high with reasoning", () => {
  2521. const model = createMockModel({
  2522. id: "openrouter/grok-3-mini",
  2523. providerID: "openrouter",
  2524. api: {
  2525. id: "grok-3-mini",
  2526. url: "https://openrouter.ai",
  2527. npm: "@openrouter/ai-sdk-provider",
  2528. },
  2529. })
  2530. const result = ProviderTransform.variants(model)
  2531. expect(Object.keys(result)).toEqual(["low", "high"])
  2532. expect(result.low).toEqual({ reasoning: { effort: "low" } })
  2533. expect(result.high).toEqual({ reasoning: { effort: "high" } })
  2534. })
  2535. })
  2536. describe("@ai-sdk/gateway", () => {
  2537. test("anthropic sonnet 4.6 models return adaptive thinking options", () => {
  2538. const model = createMockModel({
  2539. id: "anthropic/claude-sonnet-4-6",
  2540. providerID: "gateway",
  2541. api: {
  2542. id: "anthropic/claude-sonnet-4-6",
  2543. url: "https://gateway.ai",
  2544. npm: "@ai-sdk/gateway",
  2545. },
  2546. })
  2547. const result = ProviderTransform.variants(model)
  2548. expect(Object.keys(result)).toEqual(["low", "medium", "high", "max"])
  2549. expect(result.medium).toEqual({
  2550. thinking: {
  2551. type: "adaptive",
  2552. },
  2553. effort: "medium",
  2554. })
  2555. })
  2556. test("anthropic sonnet 4.6 dot-format models return adaptive thinking options", () => {
  2557. const model = createMockModel({
  2558. id: "anthropic/claude-sonnet-4-6",
  2559. providerID: "gateway",
  2560. api: {
  2561. id: "anthropic/claude-sonnet-4.6",
  2562. url: "https://gateway.ai",
  2563. npm: "@ai-sdk/gateway",
  2564. },
  2565. })
  2566. const result = ProviderTransform.variants(model)
  2567. expect(Object.keys(result)).toEqual(["low", "medium", "high", "max"])
  2568. expect(result.medium).toEqual({
  2569. thinking: {
  2570. type: "adaptive",
  2571. },
  2572. effort: "medium",
  2573. })
  2574. })
  2575. test("anthropic opus 4.6 dot-format models return adaptive thinking options", () => {
  2576. const model = createMockModel({
  2577. id: "anthropic/claude-opus-4-6",
  2578. providerID: "gateway",
  2579. api: {
  2580. id: "anthropic/claude-opus-4.6",
  2581. url: "https://gateway.ai",
  2582. npm: "@ai-sdk/gateway",
  2583. },
  2584. })
  2585. const result = ProviderTransform.variants(model)
  2586. expect(Object.keys(result)).toEqual(["low", "medium", "high", "max"])
  2587. expect(result.high).toEqual({
  2588. thinking: {
  2589. type: "adaptive",
  2590. },
  2591. effort: "high",
  2592. })
  2593. })
  2594. test("anthropic opus 4.7 models return adaptive thinking options with xhigh", () => {
  2595. const model = createMockModel({
  2596. id: "anthropic/claude-opus-4-7",
  2597. providerID: "gateway",
  2598. api: {
  2599. id: "anthropic/claude-opus-4-7",
  2600. url: "https://gateway.ai",
  2601. npm: "@ai-sdk/gateway",
  2602. },
  2603. })
  2604. const result = ProviderTransform.variants(model)
  2605. expect(Object.keys(result)).toEqual(["low", "medium", "high", "xhigh", "max"])
  2606. expect(result.xhigh).toEqual({
  2607. thinking: {
  2608. type: "adaptive",
  2609. display: "summarized",
  2610. },
  2611. effort: "xhigh",
  2612. })
  2613. expect(result.max).toEqual({
  2614. thinking: {
  2615. type: "adaptive",
  2616. display: "summarized",
  2617. },
  2618. effort: "max",
  2619. })
  2620. })
  2621. test("anthropic opus 4.7 dot-format models return adaptive thinking options with xhigh", () => {
  2622. const model = createMockModel({
  2623. id: "anthropic/claude-opus-4-7",
  2624. providerID: "gateway",
  2625. api: {
  2626. id: "anthropic/claude-opus-4.7",
  2627. url: "https://gateway.ai",
  2628. npm: "@ai-sdk/gateway",
  2629. },
  2630. })
  2631. const result = ProviderTransform.variants(model)
  2632. expect(Object.keys(result)).toEqual(["low", "medium", "high", "xhigh", "max"])
  2633. })
  2634. test("anthropic opus 4.8 forces display summarized for adaptive reasoning", () => {
  2635. const model = createMockModel({
  2636. id: "anthropic/claude-opus-4-8",
  2637. providerID: "gateway",
  2638. api: {
  2639. id: "anthropic/claude-opus-4-8",
  2640. url: "https://gateway.ai",
  2641. npm: "@ai-sdk/gateway",
  2642. },
  2643. })
  2644. const result = ProviderTransform.variants(model)
  2645. expect(Object.keys(result)).toEqual(["low", "medium", "high", "xhigh", "max"])
  2646. expect(result.high).toEqual({
  2647. thinking: {
  2648. type: "adaptive",
  2649. display: "summarized",
  2650. },
  2651. effort: "high",
  2652. })
  2653. })
  2654. test("anthropic opus 4.6 omits display so it keeps the summarized default", () => {
  2655. const model = createMockModel({
  2656. id: "anthropic/claude-opus-4-6",
  2657. providerID: "gateway",
  2658. api: {
  2659. id: "anthropic/claude-opus-4-6",
  2660. url: "https://gateway.ai",
  2661. npm: "@ai-sdk/gateway",
  2662. },
  2663. })
  2664. const result = ProviderTransform.variants(model)
  2665. expect(Object.keys(result)).toEqual(["low", "medium", "high", "max"])
  2666. expect(result.high).toEqual({
  2667. thinking: {
  2668. type: "adaptive",
  2669. },
  2670. effort: "high",
  2671. })
  2672. })
  2673. test("anthropic models return anthropic thinking options", () => {
  2674. const model = createMockModel({
  2675. id: "anthropic/claude-sonnet-4",
  2676. providerID: "gateway",
  2677. api: {
  2678. id: "anthropic/claude-sonnet-4",
  2679. url: "https://gateway.ai",
  2680. npm: "@ai-sdk/gateway",
  2681. },
  2682. })
  2683. const result = ProviderTransform.variants(model)
  2684. expect(Object.keys(result)).toEqual(["high", "max"])
  2685. expect(result.high).toEqual({
  2686. thinking: {
  2687. type: "enabled",
  2688. budgetTokens: 16000,
  2689. },
  2690. })
  2691. expect(result.max).toEqual({
  2692. thinking: {
  2693. type: "enabled",
  2694. budgetTokens: 31999,
  2695. },
  2696. })
  2697. })
  2698. test("returns OPENAI_EFFORTS with reasoningEffort", () => {
  2699. const model = createMockModel({
  2700. id: "gateway/gateway-model",
  2701. providerID: "gateway",
  2702. api: {
  2703. id: "gateway-model",
  2704. url: "https://gateway.ai",
  2705. npm: "@ai-sdk/gateway",
  2706. },
  2707. })
  2708. const result = ProviderTransform.variants(model)
  2709. expect(Object.keys(result)).toEqual(["none", "minimal", "low", "medium", "high", "xhigh"])
  2710. expect(result.low).toEqual({ reasoningEffort: "low" })
  2711. expect(result.high).toEqual({ reasoningEffort: "high" })
  2712. })
  2713. for (const testCase of [
  2714. { id: "openai/gpt-5-5", efforts: ["none", "low", "medium", "high", "xhigh"] },
  2715. { id: "openai/gpt-5-pro", efforts: ["high"] },
  2716. { id: "openai/gpt-5-5-pro", efforts: ["medium", "high", "xhigh"] },
  2717. { id: "openai/gpt-5-2-codex", efforts: ["low", "medium", "high", "xhigh"] },
  2718. { id: "openai/gpt-5-3-codex", efforts: ["none", "low", "medium", "high", "xhigh"] },
  2719. { id: "openai/gpt-5-3-codex-max", efforts: ["none", "low", "medium", "high", "xhigh"] },
  2720. { id: "openai/gpt-5-chat-latest", efforts: [] },
  2721. { id: "openai/gpt-5-2-chat-latest", efforts: ["medium"] },
  2722. ]) {
  2723. test(`${testCase.id} returns supported OpenAI reasoning efforts`, () => {
  2724. const result = ProviderTransform.variants(
  2725. createMockModel({
  2726. id: testCase.id,
  2727. providerID: "gateway",
  2728. api: {
  2729. id: testCase.id,
  2730. url: "https://gateway.ai",
  2731. npm: "@ai-sdk/gateway",
  2732. },
  2733. }),
  2734. )
  2735. expect(Object.keys(result)).toEqual(testCase.efforts)
  2736. })
  2737. }
  2738. })
  2739. describe("@ai-sdk/github-copilot", () => {
  2740. test("standard models return low, medium, high", () => {
  2741. const model = createMockModel({
  2742. id: "gpt-4.5",
  2743. providerID: "github-copilot",
  2744. api: {
  2745. id: "gpt-4.5",
  2746. url: "https://api.githubcopilot.com",
  2747. npm: "@ai-sdk/github-copilot",
  2748. },
  2749. })
  2750. const result = ProviderTransform.variants(model)
  2751. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  2752. expect(result.low).toEqual({
  2753. reasoningEffort: "low",
  2754. reasoningSummary: "auto",
  2755. include: ["reasoning.encrypted_content"],
  2756. })
  2757. })
  2758. test("gpt-5.1-codex-max includes xhigh", () => {
  2759. const model = createMockModel({
  2760. id: "gpt-5.1-codex-max",
  2761. providerID: "github-copilot",
  2762. api: {
  2763. id: "gpt-5.1-codex-max",
  2764. url: "https://api.githubcopilot.com",
  2765. npm: "@ai-sdk/github-copilot",
  2766. },
  2767. })
  2768. const result = ProviderTransform.variants(model)
  2769. expect(Object.keys(result)).toEqual(["low", "medium", "high", "xhigh"])
  2770. })
  2771. test("gpt-5.1-codex-mini does not include xhigh", () => {
  2772. const model = createMockModel({
  2773. id: "gpt-5.1-codex-mini",
  2774. providerID: "github-copilot",
  2775. api: {
  2776. id: "gpt-5.1-codex-mini",
  2777. url: "https://api.githubcopilot.com",
  2778. npm: "@ai-sdk/github-copilot",
  2779. },
  2780. })
  2781. const result = ProviderTransform.variants(model)
  2782. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  2783. })
  2784. test("gpt-5.1-codex does not include xhigh", () => {
  2785. const model = createMockModel({
  2786. id: "gpt-5.1-codex",
  2787. providerID: "github-copilot",
  2788. api: {
  2789. id: "gpt-5.1-codex",
  2790. url: "https://api.githubcopilot.com",
  2791. npm: "@ai-sdk/github-copilot",
  2792. },
  2793. })
  2794. const result = ProviderTransform.variants(model)
  2795. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  2796. })
  2797. test("gpt-5.2 includes xhigh", () => {
  2798. const model = createMockModel({
  2799. id: "gpt-5.2",
  2800. providerID: "github-copilot",
  2801. api: {
  2802. id: "gpt-5.2",
  2803. url: "https://api.githubcopilot.com",
  2804. npm: "@ai-sdk/github-copilot",
  2805. },
  2806. })
  2807. const result = ProviderTransform.variants(model)
  2808. expect(Object.keys(result)).toEqual(["low", "medium", "high", "xhigh"])
  2809. expect(result.xhigh).toEqual({
  2810. reasoningEffort: "xhigh",
  2811. reasoningSummary: "auto",
  2812. include: ["reasoning.encrypted_content"],
  2813. })
  2814. })
  2815. test("gpt-5.2-codex includes xhigh", () => {
  2816. const model = createMockModel({
  2817. id: "gpt-5.2-codex",
  2818. providerID: "github-copilot",
  2819. api: {
  2820. id: "gpt-5.2-codex",
  2821. url: "https://api.githubcopilot.com",
  2822. npm: "@ai-sdk/github-copilot",
  2823. },
  2824. })
  2825. const result = ProviderTransform.variants(model)
  2826. expect(Object.keys(result)).toEqual(["low", "medium", "high", "xhigh"])
  2827. })
  2828. test("gpt-5.3-codex includes xhigh", () => {
  2829. const model = createMockModel({
  2830. id: "gpt-5.3-codex",
  2831. providerID: "github-copilot",
  2832. api: {
  2833. id: "gpt-5.3-codex",
  2834. url: "https://api.githubcopilot.com",
  2835. npm: "@ai-sdk/github-copilot",
  2836. },
  2837. })
  2838. const result = ProviderTransform.variants(model)
  2839. expect(Object.keys(result)).toEqual(["low", "medium", "high", "xhigh"])
  2840. })
  2841. test("gpt-5.4 includes xhigh", () => {
  2842. const model = createMockModel({
  2843. id: "gpt-5.4",
  2844. release_date: "2026-03-05",
  2845. providerID: "github-copilot",
  2846. api: {
  2847. id: "gpt-5.4",
  2848. url: "https://api.githubcopilot.com",
  2849. npm: "@ai-sdk/github-copilot",
  2850. },
  2851. })
  2852. const result = ProviderTransform.variants(model)
  2853. expect(Object.keys(result)).toEqual(["low", "medium", "high", "xhigh"])
  2854. })
  2855. })
  2856. describe("@ai-sdk/cerebras", () => {
  2857. test("returns WIDELY_SUPPORTED_EFFORTS with reasoningEffort", () => {
  2858. const model = createMockModel({
  2859. id: "cerebras/llama-4",
  2860. providerID: "cerebras",
  2861. api: {
  2862. id: "llama-4-sc",
  2863. url: "https://api.cerebras.ai",
  2864. npm: "@ai-sdk/cerebras",
  2865. },
  2866. })
  2867. const result = ProviderTransform.variants(model)
  2868. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  2869. expect(result.low).toEqual({ reasoningEffort: "low" })
  2870. expect(result.high).toEqual({ reasoningEffort: "high" })
  2871. })
  2872. })
  2873. describe("@ai-sdk/togetherai", () => {
  2874. test("returns WIDELY_SUPPORTED_EFFORTS with reasoningEffort", () => {
  2875. const model = createMockModel({
  2876. id: "togetherai/llama-4",
  2877. providerID: "togetherai",
  2878. api: {
  2879. id: "llama-4-sc",
  2880. url: "https://api.togetherai.com",
  2881. npm: "@ai-sdk/togetherai",
  2882. },
  2883. })
  2884. const result = ProviderTransform.variants(model)
  2885. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  2886. expect(result.low).toEqual({ reasoningEffort: "low" })
  2887. expect(result.high).toEqual({ reasoningEffort: "high" })
  2888. })
  2889. })
  2890. describe("@ai-sdk/xai", () => {
  2891. test("grok-3 returns empty object", () => {
  2892. const model = createMockModel({
  2893. id: "xai/grok-3",
  2894. providerID: "xai",
  2895. api: {
  2896. id: "grok-3",
  2897. url: "https://api.x.ai",
  2898. npm: "@ai-sdk/xai",
  2899. },
  2900. })
  2901. const result = ProviderTransform.variants(model)
  2902. expect(result).toEqual({})
  2903. })
  2904. test("grok-3-mini returns low and high with reasoningEffort", () => {
  2905. const model = createMockModel({
  2906. id: "xai/grok-3-mini",
  2907. providerID: "xai",
  2908. api: {
  2909. id: "grok-3-mini",
  2910. url: "https://api.x.ai",
  2911. npm: "@ai-sdk/xai",
  2912. },
  2913. })
  2914. const result = ProviderTransform.variants(model)
  2915. expect(Object.keys(result)).toEqual(["low", "high"])
  2916. expect(result.low).toEqual({ reasoningEffort: "low" })
  2917. expect(result.high).toEqual({ reasoningEffort: "high" })
  2918. })
  2919. })
  2920. describe("@ai-sdk/deepinfra", () => {
  2921. test("returns WIDELY_SUPPORTED_EFFORTS with reasoningEffort", () => {
  2922. const model = createMockModel({
  2923. id: "deepinfra/llama-4",
  2924. providerID: "deepinfra",
  2925. api: {
  2926. id: "llama-4-sc",
  2927. url: "https://api.deepinfra.com",
  2928. npm: "@ai-sdk/deepinfra",
  2929. },
  2930. })
  2931. const result = ProviderTransform.variants(model)
  2932. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  2933. expect(result.low).toEqual({ reasoningEffort: "low" })
  2934. expect(result.high).toEqual({ reasoningEffort: "high" })
  2935. })
  2936. })
  2937. describe("@ai-sdk/openai-compatible", () => {
  2938. test("returns WIDELY_SUPPORTED_EFFORTS with reasoningEffort", () => {
  2939. const model = createMockModel({
  2940. id: "custom-provider/custom-model",
  2941. providerID: "custom-provider",
  2942. api: {
  2943. id: "custom-model",
  2944. url: "https://api.custom.com",
  2945. npm: "@ai-sdk/openai-compatible",
  2946. },
  2947. })
  2948. const result = ProviderTransform.variants(model)
  2949. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  2950. expect(result.low).toEqual({ reasoningEffort: "low" })
  2951. expect(result.high).toEqual({ reasoningEffort: "high" })
  2952. })
  2953. test("north-mini-code-1-0 returns only none and high", () => {
  2954. const model = createMockModel({
  2955. id: "cohere/north-mini-code-1-0",
  2956. providerID: "cohere",
  2957. api: {
  2958. id: "North-Mini-Code-1-0-latest",
  2959. url: "https://api.cohere.com/compatibility/v1",
  2960. npm: "@ai-sdk/openai-compatible",
  2961. },
  2962. })
  2963. const result = ProviderTransform.variants(model)
  2964. expect(result).toEqual({
  2965. none: { reasoningEffort: "none" },
  2966. high: { reasoningEffort: "high" },
  2967. })
  2968. })
  2969. })
  2970. describe("@ai-sdk/azure", () => {
  2971. test("o1-mini returns empty object", () => {
  2972. const model = createMockModel({
  2973. id: "o1-mini",
  2974. providerID: "azure",
  2975. api: {
  2976. id: "o1-mini",
  2977. url: "https://azure.com",
  2978. npm: "@ai-sdk/azure",
  2979. },
  2980. })
  2981. const result = ProviderTransform.variants(model)
  2982. expect(result).toEqual({})
  2983. })
  2984. test("standard azure models return custom efforts with reasoningSummary", () => {
  2985. const model = createMockModel({
  2986. id: "o1",
  2987. providerID: "azure",
  2988. api: {
  2989. id: "o1",
  2990. url: "https://azure.com",
  2991. npm: "@ai-sdk/azure",
  2992. },
  2993. })
  2994. const result = ProviderTransform.variants(model)
  2995. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  2996. expect(result.low).toEqual({
  2997. reasoningEffort: "low",
  2998. reasoningSummary: "auto",
  2999. include: ["reasoning.encrypted_content"],
  3000. })
  3001. })
  3002. test("gpt-5 adds minimal effort", () => {
  3003. const model = createMockModel({
  3004. id: "gpt-5",
  3005. providerID: "azure",
  3006. api: {
  3007. id: "gpt-5",
  3008. url: "https://azure.com",
  3009. npm: "@ai-sdk/azure",
  3010. },
  3011. })
  3012. const result = ProviderTransform.variants(model)
  3013. expect(Object.keys(result)).toEqual(["minimal", "low", "medium", "high"])
  3014. })
  3015. for (const testCase of [
  3016. { id: "gpt-5-1", efforts: ["none", "low", "medium", "high"] },
  3017. { id: "gpt-5-4", efforts: ["none", "low", "medium", "high", "xhigh"] },
  3018. { id: "gpt-5.4", efforts: ["none", "low", "medium", "high", "xhigh"] },
  3019. { id: "gpt-5-5", efforts: ["none", "low", "medium", "high", "xhigh"] },
  3020. ]) {
  3021. test(`${testCase.id} returns supported Azure reasoning efforts`, () => {
  3022. const result = ProviderTransform.variants(
  3023. createMockModel({
  3024. id: testCase.id,
  3025. providerID: "azure",
  3026. api: {
  3027. id: testCase.id,
  3028. url: "https://azure.com",
  3029. npm: "@ai-sdk/azure",
  3030. },
  3031. }),
  3032. )
  3033. expect(Object.keys(result)).toEqual(testCase.efforts)
  3034. })
  3035. }
  3036. })
  3037. describe("@ai-sdk/openai", () => {
  3038. test("gpt-5-pro returns only high effort", () => {
  3039. const model = createMockModel({
  3040. id: "gpt-5-pro",
  3041. providerID: "openai",
  3042. api: {
  3043. id: "gpt-5-pro",
  3044. url: "https://api.openai.com",
  3045. npm: "@ai-sdk/openai",
  3046. },
  3047. })
  3048. const result = ProviderTransform.variants(model)
  3049. expect(Object.keys(result)).toEqual(["high"])
  3050. })
  3051. test("standard openai models return custom efforts with reasoningSummary", () => {
  3052. const model = createMockModel({
  3053. id: "gpt-5",
  3054. providerID: "openai",
  3055. api: {
  3056. id: "gpt-5",
  3057. url: "https://api.openai.com",
  3058. npm: "@ai-sdk/openai",
  3059. },
  3060. release_date: "2024-06-01",
  3061. })
  3062. const result = ProviderTransform.variants(model)
  3063. expect(Object.keys(result)).toEqual(["minimal", "low", "medium", "high"])
  3064. expect(result.low).toEqual({
  3065. reasoningEffort: "low",
  3066. reasoningSummary: "auto",
  3067. include: ["reasoning.encrypted_content"],
  3068. })
  3069. })
  3070. test("models after 2025-11-13 include 'none' effort", () => {
  3071. const model = createMockModel({
  3072. id: "gpt-5-nano",
  3073. providerID: "openai",
  3074. api: {
  3075. id: "gpt-5-nano",
  3076. url: "https://api.openai.com",
  3077. npm: "@ai-sdk/openai",
  3078. },
  3079. release_date: "2025-11-14",
  3080. })
  3081. const result = ProviderTransform.variants(model)
  3082. expect(Object.keys(result)).toEqual(["none", "minimal", "low", "medium", "high"])
  3083. })
  3084. test("models after 2025-12-04 include 'xhigh' effort", () => {
  3085. const model = createMockModel({
  3086. id: "openai/gpt-5-reasoning",
  3087. providerID: "openai",
  3088. api: {
  3089. id: "gpt-5-reasoning",
  3090. url: "https://api.openai.com",
  3091. npm: "@ai-sdk/openai",
  3092. },
  3093. release_date: "2025-12-05",
  3094. })
  3095. const result = ProviderTransform.variants(model)
  3096. expect(Object.keys(result)).toEqual(["none", "minimal", "low", "medium", "high", "xhigh"])
  3097. })
  3098. for (const testCase of [
  3099. { id: "o1", releaseDate: "2024-12-17", efforts: ["low", "medium", "high"] },
  3100. { id: "o1-pro", releaseDate: "2025-03-19", efforts: ["low", "medium", "high"] },
  3101. { id: "o3", releaseDate: "2025-04-16", efforts: ["low", "medium", "high"] },
  3102. { id: "o3-mini", releaseDate: "2025-01-31", efforts: ["low", "medium", "high"] },
  3103. { id: "o3-pro", releaseDate: "2025-06-10", efforts: ["low", "medium", "high"] },
  3104. { id: "o4-mini", releaseDate: "2025-04-16", efforts: ["low", "medium", "high"] },
  3105. { id: "o3-deep-research", releaseDate: "2025-06-26", efforts: ["medium"] },
  3106. { id: "o4-mini-deep-research", releaseDate: "2025-06-26", efforts: ["medium"] },
  3107. { id: "gpt-5.1", releaseDate: "2025-11-13", efforts: ["none", "low", "medium", "high"] },
  3108. { id: "gpt-5.4", releaseDate: "2026-03-05", efforts: ["none", "low", "medium", "high", "xhigh"] },
  3109. {
  3110. id: "gpt-5.5",
  3111. modelID: "gpt-5-5",
  3112. releaseDate: "2026-04-23",
  3113. efforts: ["none", "low", "medium", "high", "xhigh"],
  3114. },
  3115. { id: "gpt-5.4-pro", releaseDate: "2026-03-05", efforts: ["medium", "high", "xhigh"] },
  3116. { id: "gpt-5.5-pro", releaseDate: "2026-04-23", efforts: ["medium", "high", "xhigh"] },
  3117. { id: "gpt-5-codex", releaseDate: "2025-09-23", efforts: ["low", "medium", "high"] },
  3118. { id: "gpt-5.1-codex", releaseDate: "2025-11-13", efforts: ["low", "medium", "high"] },
  3119. { id: "gpt-5.1-codex-max", releaseDate: "2025-11-13", efforts: ["low", "medium", "high", "xhigh"] },
  3120. { id: "gpt-5.2-codex", releaseDate: "2025-12-11", efforts: ["low", "medium", "high", "xhigh"] },
  3121. { id: "gpt-5.3-codex", releaseDate: "2026-01-22", efforts: ["none", "low", "medium", "high", "xhigh"] },
  3122. { id: "gpt-5.3-codex-max", releaseDate: "2026-01-22", efforts: ["none", "low", "medium", "high", "xhigh"] },
  3123. { id: "gpt-5-chat-latest", releaseDate: "2025-08-07", efforts: [] },
  3124. { id: "gpt-5.1-chat-latest", releaseDate: "2025-11-13", efforts: ["medium"] },
  3125. { id: "gpt-5.2-chat-latest", releaseDate: "2025-12-11", efforts: ["medium"] },
  3126. ]) {
  3127. test(`${testCase.id} returns supported reasoning efforts`, () => {
  3128. const result = ProviderTransform.variants(
  3129. createMockModel({
  3130. id: testCase.modelID ?? testCase.id,
  3131. providerID: "openai",
  3132. api: {
  3133. id: testCase.id,
  3134. url: "https://api.openai.com",
  3135. npm: "@ai-sdk/openai",
  3136. },
  3137. release_date: testCase.releaseDate,
  3138. }),
  3139. )
  3140. expect(Object.keys(result)).toEqual(testCase.efforts)
  3141. })
  3142. }
  3143. test("gpt-50 (lookalike) does not get gpt-5 family treatment", () => {
  3144. const model = createMockModel({
  3145. id: "gpt-50",
  3146. providerID: "openai",
  3147. api: {
  3148. id: "gpt-50",
  3149. url: "https://api.openai.com",
  3150. npm: "@ai-sdk/openai",
  3151. },
  3152. release_date: "2024-01-01",
  3153. })
  3154. const result = ProviderTransform.variants(model)
  3155. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  3156. })
  3157. })
  3158. describe("@ai-sdk/amazon-bedrock/mantle", () => {
  3159. test("gpt-5.5 returns OpenAI-style reasoning variants", () => {
  3160. const model = createMockModel({
  3161. id: "openai.gpt-5.5",
  3162. providerID: "amazon-bedrock",
  3163. api: {
  3164. id: "openai.gpt-5.5",
  3165. url: "https://bedrock-mantle.us-east-2.api.aws/openai/v1",
  3166. npm: "@ai-sdk/amazon-bedrock/mantle",
  3167. },
  3168. release_date: "2026-04-23",
  3169. })
  3170. const result = ProviderTransform.variants(model)
  3171. expect(Object.keys(result)).toEqual(["none", "low", "medium", "high", "xhigh"])
  3172. expect(result.medium).toEqual({
  3173. reasoningEffort: "medium",
  3174. reasoningSummary: "auto",
  3175. include: ["reasoning.encrypted_content"],
  3176. })
  3177. })
  3178. })
  3179. describe("@ai-sdk/anthropic", () => {
  3180. for (const testCase of [
  3181. {
  3182. name: "opus 4.5",
  3183. apiIds: ["claude-opus-4-5-20251101", "claude-opus-4.5-20251101"],
  3184. efforts: ["low", "medium", "high"],
  3185. expectedHigh: { effort: "high" },
  3186. },
  3187. {
  3188. name: "sonnet 4.6",
  3189. apiIds: ["claude-sonnet-4-6", "claude-sonnet-4.6"],
  3190. efforts: ["low", "medium", "high", "max"],
  3191. expectedHigh: { thinking: { type: "adaptive" }, effort: "high" },
  3192. },
  3193. {
  3194. name: "opus 4.6",
  3195. apiIds: ["claude-opus-4-6", "claude-opus-4.6"],
  3196. efforts: ["low", "medium", "high", "max"],
  3197. expectedHigh: { thinking: { type: "adaptive" }, effort: "high" },
  3198. },
  3199. {
  3200. name: "opus 4.7",
  3201. apiIds: ["claude-opus-4-7", "claude-opus-4.7"],
  3202. efforts: ["low", "medium", "high", "xhigh", "max"],
  3203. expectedHigh: { thinking: { type: "adaptive", display: "summarized" }, effort: "high" },
  3204. },
  3205. {
  3206. name: "opus 4.8",
  3207. apiIds: ["claude-opus-4-8", "claude-opus-4.8"],
  3208. efforts: ["low", "medium", "high", "xhigh", "max"],
  3209. expectedHigh: { thinking: { type: "adaptive", display: "summarized" }, effort: "high" },
  3210. },
  3211. {
  3212. name: "fable 5",
  3213. apiIds: ["claude-fable-5"],
  3214. efforts: ["low", "medium", "high", "xhigh", "max"],
  3215. expectedHigh: { thinking: { type: "adaptive", display: "summarized" }, effort: "high" },
  3216. },
  3217. ]) {
  3218. for (const apiId of testCase.apiIds) {
  3219. test(`${testCase.name} ${apiId} returns supported reasoning efforts`, () => {
  3220. const result = ProviderTransform.variants(
  3221. createMockModel({
  3222. id: `anthropic/${apiId}`,
  3223. providerID: "anthropic",
  3224. api: {
  3225. id: apiId,
  3226. url: "https://api.anthropic.com",
  3227. npm: "@ai-sdk/anthropic",
  3228. },
  3229. }),
  3230. )
  3231. expect(Object.keys(result)).toEqual(testCase.efforts)
  3232. expect(result.high).toEqual(testCase.expectedHigh)
  3233. })
  3234. }
  3235. }
  3236. test("github copilot opus 4.7 returns only medium reasoning effort", () => {
  3237. const model = createMockModel({
  3238. id: "claude-opus-4.7",
  3239. providerID: "github-copilot",
  3240. api: {
  3241. id: "claude-opus-4.7",
  3242. url: "https://api.githubcopilot.com/v1",
  3243. npm: "@ai-sdk/anthropic",
  3244. },
  3245. })
  3246. const result = ProviderTransform.variants(model)
  3247. expect(result).toEqual({
  3248. medium: {
  3249. thinking: {
  3250. type: "adaptive",
  3251. display: "summarized",
  3252. },
  3253. effort: "medium",
  3254. },
  3255. })
  3256. })
  3257. test("returns high and max with thinking config", () => {
  3258. const model = createMockModel({
  3259. id: "anthropic/claude-4",
  3260. providerID: "anthropic",
  3261. api: {
  3262. id: "claude-4",
  3263. url: "https://api.anthropic.com",
  3264. npm: "@ai-sdk/anthropic",
  3265. },
  3266. })
  3267. const result = ProviderTransform.variants(model)
  3268. expect(Object.keys(result)).toEqual(["high", "max"])
  3269. expect(result.high).toEqual({
  3270. thinking: {
  3271. type: "enabled",
  3272. budgetTokens: 16000,
  3273. },
  3274. })
  3275. expect(result.max).toEqual({
  3276. thinking: {
  3277. type: "enabled",
  3278. budgetTokens: 31999,
  3279. },
  3280. })
  3281. })
  3282. })
  3283. describe("@ai-sdk/google-vertex/anthropic", () => {
  3284. test("opus 4.8 uses adaptive reasoning for Vertex model IDs", () => {
  3285. const result = ProviderTransform.variants(
  3286. createMockModel({
  3287. id: "google-vertex-anthropic/claude-opus-4-8@default",
  3288. providerID: "google-vertex-anthropic",
  3289. api: {
  3290. id: "claude-opus-4-8@default",
  3291. url: "https://us-central1-aiplatform.googleapis.com",
  3292. npm: "@ai-sdk/google-vertex/anthropic",
  3293. },
  3294. }),
  3295. )
  3296. expect(Object.keys(result)).toEqual(["low", "medium", "high", "xhigh", "max"])
  3297. expect(result.high).toEqual({
  3298. thinking: {
  3299. type: "adaptive",
  3300. display: "summarized",
  3301. },
  3302. effort: "high",
  3303. })
  3304. })
  3305. })
  3306. describe("@ai-sdk/amazon-bedrock", () => {
  3307. test("anthropic sonnet 4.6 returns adaptive reasoning options", () => {
  3308. const model = createMockModel({
  3309. id: "bedrock/anthropic-claude-sonnet-4-6",
  3310. providerID: "bedrock",
  3311. api: {
  3312. id: "anthropic.claude-sonnet-4-6",
  3313. url: "https://bedrock.amazonaws.com",
  3314. npm: "@ai-sdk/amazon-bedrock",
  3315. },
  3316. })
  3317. const result = ProviderTransform.variants(model)
  3318. expect(Object.keys(result)).toEqual(["low", "medium", "high", "max"])
  3319. expect(result.max).toEqual({
  3320. reasoningConfig: {
  3321. type: "adaptive",
  3322. maxReasoningEffort: "max",
  3323. },
  3324. })
  3325. })
  3326. test("anthropic opus 4.7 returns adaptive reasoning options with xhigh", () => {
  3327. const model = createMockModel({
  3328. id: "bedrock/anthropic-claude-opus-4-7",
  3329. providerID: "bedrock",
  3330. api: {
  3331. id: "anthropic.claude-opus-4-7",
  3332. url: "https://bedrock.amazonaws.com",
  3333. npm: "@ai-sdk/amazon-bedrock",
  3334. },
  3335. })
  3336. const result = ProviderTransform.variants(model)
  3337. expect(Object.keys(result)).toEqual(["low", "medium", "high", "xhigh", "max"])
  3338. expect(result.xhigh).toEqual({
  3339. reasoningConfig: {
  3340. type: "adaptive",
  3341. maxReasoningEffort: "xhigh",
  3342. display: "summarized",
  3343. },
  3344. })
  3345. expect(result.max).toEqual({
  3346. reasoningConfig: {
  3347. type: "adaptive",
  3348. maxReasoningEffort: "max",
  3349. display: "summarized",
  3350. },
  3351. })
  3352. })
  3353. test("anthropic opus 4.8 returns adaptive reasoning options with xhigh", () => {
  3354. const result = ProviderTransform.variants(
  3355. createMockModel({
  3356. id: "bedrock/anthropic-claude-opus-4.8",
  3357. providerID: "bedrock",
  3358. api: {
  3359. id: "anthropic.claude-opus-4.8",
  3360. url: "https://bedrock.amazonaws.com",
  3361. npm: "@ai-sdk/amazon-bedrock",
  3362. },
  3363. }),
  3364. )
  3365. expect(Object.keys(result)).toEqual(["low", "medium", "high", "xhigh", "max"])
  3366. expect(result.high).toEqual({
  3367. reasoningConfig: {
  3368. type: "adaptive",
  3369. maxReasoningEffort: "high",
  3370. display: "summarized",
  3371. },
  3372. })
  3373. })
  3374. test("returns WIDELY_SUPPORTED_EFFORTS with reasoningConfig", () => {
  3375. const model = createMockModel({
  3376. id: "bedrock/llama-4",
  3377. providerID: "bedrock",
  3378. api: {
  3379. id: "llama-4-sc",
  3380. url: "https://bedrock.amazonaws.com",
  3381. npm: "@ai-sdk/amazon-bedrock",
  3382. },
  3383. })
  3384. const result = ProviderTransform.variants(model)
  3385. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  3386. expect(result.low).toEqual({
  3387. reasoningConfig: {
  3388. type: "enabled",
  3389. maxReasoningEffort: "low",
  3390. },
  3391. })
  3392. })
  3393. })
  3394. for (const provider of [
  3395. { name: "@ai-sdk/google", providerID: "google", url: "https://generativelanguage.googleapis.com" },
  3396. { name: "@ai-sdk/google-vertex", providerID: "google-vertex", url: "https://vertexai.googleapis.com" },
  3397. ]) {
  3398. describe(provider.name, () => {
  3399. for (const testCase of [
  3400. {
  3401. apiId: "gemini-2.5-pro",
  3402. efforts: ["high", "max"],
  3403. expectedHigh: { thinkingConfig: { includeThoughts: true, thinkingBudget: 16_000 } },
  3404. expectedMax: { thinkingConfig: { includeThoughts: true, thinkingBudget: 32_768 } },
  3405. },
  3406. {
  3407. apiId: "gemini-2.5-flash",
  3408. efforts: ["high", "max"],
  3409. expectedHigh: { thinkingConfig: { includeThoughts: true, thinkingBudget: 16_000 } },
  3410. expectedMax: { thinkingConfig: { includeThoughts: true, thinkingBudget: 24_576 } },
  3411. },
  3412. {
  3413. apiId: "gemini-3-pro-preview",
  3414. efforts: ["low", "medium", "high"],
  3415. expectedHigh: { thinkingConfig: { includeThoughts: true, thinkingLevel: "high" } },
  3416. },
  3417. {
  3418. apiId: "gemini-3.1-pro-preview",
  3419. efforts: ["low", "medium", "high"],
  3420. expectedHigh: { thinkingConfig: { includeThoughts: true, thinkingLevel: "high" } },
  3421. },
  3422. {
  3423. apiId: "gemini-3-flash-preview",
  3424. efforts: ["minimal", "low", "medium", "high"],
  3425. expectedHigh: { thinkingConfig: { includeThoughts: true, thinkingLevel: "high" } },
  3426. },
  3427. {
  3428. apiId: "gemini-3.1-flash-lite",
  3429. efforts: ["minimal", "low", "medium", "high"],
  3430. expectedHigh: { thinkingConfig: { includeThoughts: true, thinkingLevel: "high" } },
  3431. },
  3432. {
  3433. apiId: "gemini-3.1-flash-image-preview",
  3434. efforts: ["minimal", "high"],
  3435. expectedHigh: { thinkingConfig: { includeThoughts: true, thinkingLevel: "high" } },
  3436. },
  3437. {
  3438. apiId: "gemini-3-pro-image-preview",
  3439. efforts: ["high"],
  3440. expectedHigh: { thinkingConfig: { includeThoughts: true, thinkingLevel: "high" } },
  3441. },
  3442. ]) {
  3443. test(`${testCase.apiId} returns supported thinking controls`, () => {
  3444. const result = ProviderTransform.variants(
  3445. createMockModel({
  3446. id: `${provider.providerID}/${testCase.apiId}`,
  3447. providerID: provider.providerID,
  3448. api: {
  3449. id: testCase.apiId,
  3450. url: provider.url,
  3451. npm: provider.name,
  3452. },
  3453. }),
  3454. )
  3455. expect(Object.keys(result)).toEqual(testCase.efforts)
  3456. expect(result.high).toEqual(testCase.expectedHigh)
  3457. if (testCase.expectedMax) expect(result.max).toEqual(testCase.expectedMax)
  3458. })
  3459. }
  3460. })
  3461. }
  3462. describe("@ai-sdk/cohere", () => {
  3463. test("returns empty object", () => {
  3464. const model = createMockModel({
  3465. id: "cohere/command-r",
  3466. providerID: "cohere",
  3467. api: {
  3468. id: "command-r",
  3469. url: "https://api.cohere.com",
  3470. npm: "@ai-sdk/cohere",
  3471. },
  3472. })
  3473. const result = ProviderTransform.variants(model)
  3474. expect(result).toEqual({})
  3475. })
  3476. })
  3477. describe("@ai-sdk/groq", () => {
  3478. test("returns none and WIDELY_SUPPORTED_EFFORTS with thinkingLevel", () => {
  3479. const model = createMockModel({
  3480. id: "groq/llama-4",
  3481. providerID: "groq",
  3482. api: {
  3483. id: "llama-4-sc",
  3484. url: "https://api.groq.com",
  3485. npm: "@ai-sdk/groq",
  3486. },
  3487. })
  3488. const result = ProviderTransform.variants(model)
  3489. expect(Object.keys(result)).toEqual(["none", "low", "medium", "high"])
  3490. expect(result.none).toEqual({
  3491. reasoningEffort: "none",
  3492. })
  3493. expect(result.low).toEqual({
  3494. reasoningEffort: "low",
  3495. })
  3496. })
  3497. })
  3498. describe("@ai-sdk/perplexity", () => {
  3499. test("returns empty object", () => {
  3500. const model = createMockModel({
  3501. id: "perplexity/sonar-plus",
  3502. providerID: "perplexity",
  3503. api: {
  3504. id: "sonar-plus",
  3505. url: "https://api.perplexity.ai",
  3506. npm: "@ai-sdk/perplexity",
  3507. },
  3508. })
  3509. const result = ProviderTransform.variants(model)
  3510. expect(result).toEqual({})
  3511. })
  3512. })
  3513. describe("@jerome-benoit/sap-ai-provider-v2", () => {
  3514. const sapModel = (apiId: string, releaseDate = "2024-01-01") =>
  3515. createMockModel({
  3516. id: `sap-ai-core/${apiId}`,
  3517. providerID: "sap-ai-core",
  3518. api: {
  3519. id: apiId,
  3520. url: "https://api.ai.sap",
  3521. npm: "@jerome-benoit/sap-ai-provider-v2",
  3522. },
  3523. release_date: releaseDate,
  3524. })
  3525. for (const testCase of [
  3526. {
  3527. name: "sonnet 4.6",
  3528. apiIds: ["anthropic--claude-sonnet-4-6"],
  3529. efforts: ["low", "medium", "high", "max"],
  3530. thinking: { type: "adaptive" },
  3531. },
  3532. {
  3533. name: "opus 4.6",
  3534. apiIds: ["anthropic--claude-4.6-opus", "anthropic--claude-4-6-opus"],
  3535. efforts: ["low", "medium", "high", "max"],
  3536. thinking: { type: "adaptive" },
  3537. },
  3538. {
  3539. name: "opus 4.7",
  3540. apiIds: ["anthropic--claude-4.7-opus", "anthropic--claude-4-7-opus"],
  3541. efforts: ["low", "medium", "high", "xhigh", "max"],
  3542. thinking: { type: "adaptive", display: "summarized" },
  3543. },
  3544. {
  3545. name: "opus 4.8",
  3546. apiIds: ["anthropic--claude-4.8-opus", "anthropic--claude-4-8-opus"],
  3547. efforts: ["low", "medium", "high", "xhigh", "max"],
  3548. thinking: { type: "adaptive", display: "summarized" },
  3549. },
  3550. ]) {
  3551. for (const apiId of testCase.apiIds) {
  3552. test(`${testCase.name} ${apiId} returns adaptive thinking variants under modelParams`, () => {
  3553. const result = ProviderTransform.variants(sapModel(apiId))
  3554. expect(Object.keys(result)).toEqual(testCase.efforts)
  3555. for (const effort of testCase.efforts) {
  3556. expect(result[effort]).toEqual({
  3557. modelParams: {
  3558. thinking: testCase.thinking,
  3559. output_config: { effort },
  3560. },
  3561. })
  3562. }
  3563. })
  3564. }
  3565. }
  3566. for (const apiId of ["anthropic--claude-sonnet-4", "anthropic--claude-4.5-opus"]) {
  3567. test(`${apiId} returns budget_tokens variants under modelParams`, () => {
  3568. const result = ProviderTransform.variants(sapModel(apiId))
  3569. expect(Object.keys(result)).toEqual(["high", "max"])
  3570. expect(result.high).toEqual({
  3571. modelParams: { thinking: { type: "enabled", budget_tokens: 16000 } },
  3572. })
  3573. expect(result.max).toEqual({
  3574. modelParams: { thinking: { type: "enabled", budget_tokens: 31999 } },
  3575. })
  3576. })
  3577. }
  3578. for (const testCase of [
  3579. { apiId: "gemini-2.5-pro", maxBudget: 32768 },
  3580. { apiId: "gemini-2.5-flash", maxBudget: 24576 },
  3581. ]) {
  3582. test(`${testCase.apiId} returns thinkingConfig variants under modelParams`, () => {
  3583. const result = ProviderTransform.variants(sapModel(testCase.apiId))
  3584. expect(Object.keys(result)).toEqual(["high", "max"])
  3585. expect(result.high).toEqual({
  3586. modelParams: { thinkingConfig: { includeThoughts: true, thinkingBudget: 16000 } },
  3587. })
  3588. expect(result.max).toEqual({
  3589. modelParams: { thinkingConfig: { includeThoughts: true, thinkingBudget: testCase.maxBudget } },
  3590. })
  3591. })
  3592. }
  3593. for (const testCase of [
  3594. { apiId: "gpt-5", releaseDate: "2025-08-07", efforts: ["minimal", "low", "medium", "high"] },
  3595. { apiId: "gpt-5-mini", releaseDate: "2025-08-07", efforts: ["minimal", "low", "medium", "high"] },
  3596. { apiId: "gpt-5-nano", releaseDate: "2025-08-07", efforts: ["minimal", "low", "medium", "high"] },
  3597. { apiId: "gpt-5.4", releaseDate: "2026-01-15", efforts: ["none", "low", "medium", "high", "xhigh"] },
  3598. { apiId: "azure-openai--o3-mini", releaseDate: "2024-01-01", efforts: ["low", "medium", "high"] },
  3599. ]) {
  3600. test(`${testCase.apiId} returns reasoning_effort variants under modelParams`, () => {
  3601. const result = ProviderTransform.variants(sapModel(testCase.apiId, testCase.releaseDate))
  3602. expect(Object.keys(result)).toEqual(testCase.efforts)
  3603. for (const effort of testCase.efforts) {
  3604. expect(result[effort]).toEqual({ modelParams: { reasoning_effort: effort } })
  3605. }
  3606. })
  3607. }
  3608. for (const apiId of [
  3609. "gemini-3.1-flash-lite",
  3610. "cohere--command-a-reasoning",
  3611. "sonar-deep-research",
  3612. "aws--llama-opus-4.7-fake",
  3613. ]) {
  3614. test(`${apiId} falls through to harmonized reasoning_effort fallback`, () => {
  3615. const result = ProviderTransform.variants(sapModel(apiId))
  3616. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  3617. for (const effort of ["low", "medium", "high"]) {
  3618. expect(result[effort]).toEqual({ modelParams: { reasoning_effort: effort } })
  3619. }
  3620. })
  3621. }
  3622. })
  3623. describe("ai-gateway-provider (cloudflare-ai-gateway)", () => {
  3624. const cfModel = (apiId: string, releaseDate = "2024-01-01") =>
  3625. createMockModel({
  3626. id: `cloudflare-ai-gateway/${apiId}`,
  3627. providerID: "cloudflare-ai-gateway",
  3628. api: {
  3629. id: apiId,
  3630. url: "https://gateway.ai.cloudflare.com/v1/compat",
  3631. npm: "ai-gateway-provider",
  3632. },
  3633. release_date: releaseDate,
  3634. })
  3635. for (const testCase of [
  3636. { id: "openai/gpt-5.4", efforts: ["none", "low", "medium", "high", "xhigh"] },
  3637. { id: "openai/gpt-5.2-codex", efforts: ["low", "medium", "high", "xhigh"] },
  3638. { id: "openai/gpt-5.3-codex", efforts: ["none", "low", "medium", "high", "xhigh"] },
  3639. { id: "openai/gpt-5-pro", efforts: ["high"] },
  3640. { id: "openai/gpt-5.2-pro", efforts: ["medium", "high", "xhigh"] },
  3641. { id: "openai/gpt-5-chat-latest", efforts: [] },
  3642. { id: "openai/gpt-5.2-chat-latest", efforts: ["medium"] },
  3643. ]) {
  3644. test(`${testCase.id} returns supported reasoning efforts`, () => {
  3645. const result = ProviderTransform.variants(cfModel(testCase.id, "2026-03-05"))
  3646. expect(Object.keys(result)).toEqual(testCase.efforts)
  3647. })
  3648. }
  3649. test("openai gpt-4o (no reasoning) returns empty", () => {
  3650. const model = cfModel("openai/gpt-4o")
  3651. model.capabilities.reasoning = false
  3652. const result = ProviderTransform.variants(model)
  3653. expect(result).toEqual({})
  3654. })
  3655. test("non-openai upstream falls back to widely-supported OAI efforts", () => {
  3656. const result = ProviderTransform.variants(cfModel("anthropic/claude-sonnet-4-6"))
  3657. expect(result).toEqual({
  3658. low: { reasoningEffort: "low" },
  3659. medium: { reasoningEffort: "medium" },
  3660. high: { reasoningEffort: "high" },
  3661. })
  3662. })
  3663. })
  3664. })
  3665. describe("ProviderTransform.smallOptions - gpt-5 chat/search", () => {
  3666. const createModel = (apiId: string) => {
  3667. const model = {
  3668. id: `openai/${apiId}`,
  3669. providerID: "openai",
  3670. api: {
  3671. id: apiId,
  3672. url: "https://api.openai.com",
  3673. npm: "@ai-sdk/openai",
  3674. },
  3675. capabilities: { reasoning: true },
  3676. limit: { output: 64_000 },
  3677. release_date: "2026-01-01",
  3678. } as any
  3679. model.variants = ProviderTransform.variants(model)
  3680. return model
  3681. }
  3682. for (const testCase of [
  3683. { id: "gpt-5-chat-latest", options: { store: false } },
  3684. {
  3685. id: "gpt-5.1-chat-latest",
  3686. options: {
  3687. store: false,
  3688. reasoningEffort: "medium",
  3689. reasoningSummary: "auto",
  3690. include: ["reasoning.encrypted_content"],
  3691. },
  3692. },
  3693. {
  3694. id: "gpt-5.2-chat-latest",
  3695. options: {
  3696. store: false,
  3697. reasoningEffort: "medium",
  3698. reasoningSummary: "auto",
  3699. include: ["reasoning.encrypted_content"],
  3700. },
  3701. },
  3702. {
  3703. id: "gpt-5-search-api",
  3704. options: {
  3705. store: false,
  3706. reasoningEffort: "none",
  3707. reasoningSummary: "auto",
  3708. include: ["reasoning.encrypted_content"],
  3709. },
  3710. },
  3711. ]) {
  3712. test(`${testCase.id} returns only supported small options`, () => {
  3713. expect(ProviderTransform.smallOptions(createModel(testCase.id))).toEqual(testCase.options)
  3714. })
  3715. }
  3716. })
  3717. test("ProviderTransform.smallOptions disables OpenRouter reasoning when the weakest effort is low", () => {
  3718. expect(
  3719. ProviderTransform.smallOptions({
  3720. providerID: "openrouter",
  3721. api: {
  3722. id: "anthropic/claude-sonnet-4.6",
  3723. npm: "@openrouter/ai-sdk-provider",
  3724. },
  3725. variants: {
  3726. low: { reasoning: { effort: "low" } },
  3727. medium: { reasoning: { effort: "medium" } },
  3728. high: { reasoning: { effort: "high" } },
  3729. },
  3730. } as any),
  3731. ).toEqual({ reasoning: { effort: "none" } })
  3732. })
  3733. describe("ProviderTransform.smallOptions - google thinking controls", () => {
  3734. const createGoogleModel = (apiId: string) => {
  3735. const model = {
  3736. id: `google/${apiId}`,
  3737. providerID: "google",
  3738. api: {
  3739. id: apiId,
  3740. url: "https://generativelanguage.googleapis.com",
  3741. npm: "@ai-sdk/google",
  3742. },
  3743. capabilities: { reasoning: true },
  3744. limit: { output: 64_000 },
  3745. } as any
  3746. model.variants = ProviderTransform.variants(model)
  3747. return model
  3748. }
  3749. for (const testCase of [
  3750. { id: "gemini-3-pro-preview", options: { thinkingConfig: { includeThoughts: true, thinkingLevel: "low" } } },
  3751. { id: "gemini-3-flash-preview", options: { thinkingConfig: { includeThoughts: true, thinkingLevel: "minimal" } } },
  3752. {
  3753. id: "gemini-3.1-flash-image-preview",
  3754. options: { thinkingConfig: { includeThoughts: true, thinkingLevel: "minimal" } },
  3755. },
  3756. { id: "gemini-3-pro-image-preview", options: { thinkingConfig: { includeThoughts: true, thinkingLevel: "high" } } },
  3757. { id: "gemini-2.5-pro", options: { thinkingConfig: { includeThoughts: true, thinkingBudget: 16000 } } },
  3758. { id: "gemini-2.5-flash", options: { thinkingConfig: { includeThoughts: true, thinkingBudget: 16000 } } },
  3759. ]) {
  3760. test(`${testCase.id} returns supported small thinking options`, () => {
  3761. expect(ProviderTransform.smallOptions(createGoogleModel(testCase.id))).toEqual(testCase.options)
  3762. })
  3763. }
  3764. test("uses the first configured variant when available", () => {
  3765. expect(
  3766. ProviderTransform.smallOptions({
  3767. ...createGoogleModel("gemini-2.5-pro"),
  3768. variants: {
  3769. high: { thinkingConfig: { includeThoughts: true, thinkingBudget: 16000 } },
  3770. max: { thinkingConfig: { includeThoughts: true, thinkingBudget: 32768 } },
  3771. },
  3772. }),
  3773. ).toEqual({ thinkingConfig: { includeThoughts: true, thinkingBudget: 16000 } })
  3774. })
  3775. test("does not synthesize thinking options when variants are empty", () => {
  3776. expect(ProviderTransform.smallOptions({ ...createGoogleModel("gemini-2.5-pro"), variants: {} })).toEqual({})
  3777. })
  3778. })
  3779. describe("ProviderTransform.providerOptions - ai-gateway-provider", () => {
  3780. const createModel = (overrides: Partial<any> = {}) =>
  3781. ({
  3782. id: "cloudflare-ai-gateway/openai/gpt-5.4",
  3783. providerID: "cloudflare-ai-gateway",
  3784. api: {
  3785. id: "openai/gpt-5.4",
  3786. url: "https://gateway.ai.cloudflare.com/v1/compat",
  3787. npm: "ai-gateway-provider",
  3788. },
  3789. capabilities: {
  3790. temperature: false,
  3791. reasoning: true,
  3792. attachment: true,
  3793. toolcall: true,
  3794. input: { text: true, audio: false, image: true, video: false, pdf: true },
  3795. output: { text: true, audio: false, image: false, video: false, pdf: false },
  3796. interleaved: false,
  3797. },
  3798. cost: { input: 1, output: 1, cache: { read: 0, write: 0 } },
  3799. limit: { context: 1_000_000, output: 128_000 },
  3800. status: "active",
  3801. options: {},
  3802. headers: {},
  3803. release_date: "2026-03-05",
  3804. ...overrides,
  3805. }) as any
  3806. test("routes options under openaiCompatible (the key @ai-sdk/openai-compatible reads)", () => {
  3807. // Regression: previously fell back to providerID="cloudflare-ai-gateway",
  3808. // which @ai-sdk/openai-compatible never reads, silently dropping reasoningEffort.
  3809. const result = ProviderTransform.providerOptions(createModel(), { reasoningEffort: "high" })
  3810. expect(result).toEqual({ openaiCompatible: { reasoningEffort: "high" } })
  3811. })
  3812. })