transform.test.ts 128 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207
  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 type arrays", () => {
  781. // Mirrors @ai-sdk/google's convertJSONSchemaToOpenAPISchema: JSON Schema type
  782. // arrays (e.g. `["number","string"]`, common in MCP tool schemas) become an
  783. // `anyOf` of single-type schemas, with `null` lifted into `nullable`. Plain
  784. // @ai-sdk/google rewrites these, but OpenAI-compatible transports such as
  785. // GitHub Copilot (proxying to Gemini) forward them verbatim and the backend
  786. // rejects the array form.
  787. const geminiModel = {
  788. providerID: "google",
  789. api: {
  790. id: "gemini-3-pro",
  791. },
  792. } as any
  793. test("splits a multi-type array into anyOf and drops the type array", () => {
  794. const schema = {
  795. type: "object",
  796. properties: {
  797. status: { type: ["number", "string"], description: "status filter" },
  798. },
  799. } as any
  800. const result = ProviderTransform.schema(geminiModel, schema) as any
  801. expect(result.properties.status.type).toBeUndefined()
  802. expect(result.properties.status.anyOf).toEqual([{ type: "number" }, { type: "string" }])
  803. expect(result.properties.status.nullable).toBeUndefined()
  804. // Sibling keywords stay alongside the generated anyOf.
  805. expect(result.properties.status.description).toBe("status filter")
  806. })
  807. test("lifts null into nullable for a nullable type array", () => {
  808. const schema = {
  809. type: "object",
  810. properties: {
  811. maybe: { type: ["string", "null"], description: "nullable string" },
  812. },
  813. } as any
  814. const result = ProviderTransform.schema(geminiModel, schema) as any
  815. expect(result.properties.maybe.type).toBeUndefined()
  816. expect(result.properties.maybe.anyOf).toEqual([{ type: "string" }])
  817. expect(result.properties.maybe.nullable).toBe(true)
  818. })
  819. test("collapses an all-null type array to type null", () => {
  820. const schema = {
  821. type: "object",
  822. properties: {
  823. nothing: { type: ["null"] },
  824. },
  825. } as any
  826. const result = ProviderTransform.schema(geminiModel, schema) as any
  827. expect(result.properties.nothing.type).toBe("null")
  828. expect(result.properties.nothing.anyOf).toBeUndefined()
  829. })
  830. test("rewrites type arrays for gemini served through github-copilot", () => {
  831. const copilotGeminiModel = {
  832. providerID: "github-copilot",
  833. api: {
  834. id: "gemini-3.5-flash",
  835. npm: "@ai-sdk/github-copilot",
  836. },
  837. } as any
  838. const schema = {
  839. type: "object",
  840. properties: {
  841. hook_id: { type: "number", description: "ID of the webhook" },
  842. status: { type: ["number", "string"], description: "Filter by response status code" },
  843. },
  844. required: ["hook_id"],
  845. additionalProperties: false,
  846. } as any
  847. const result = ProviderTransform.schema(copilotGeminiModel, schema) as any
  848. expect(result.properties.status.anyOf).toEqual([{ type: "number" }, { type: "string" }])
  849. expect(result.properties.status.type).toBeUndefined()
  850. expect(result.properties.hook_id.type).toBe("number")
  851. })
  852. })
  853. describe("ProviderTransform.schema - gemini combiner nodes", () => {
  854. const geminiModel = {
  855. providerID: "google",
  856. api: {
  857. id: "gemini-3-pro",
  858. },
  859. } as any
  860. const walk = (node: any, cb: (node: any, path: (string | number)[]) => void, path: (string | number)[] = []) => {
  861. if (node === null || typeof node !== "object") {
  862. return
  863. }
  864. if (Array.isArray(node)) {
  865. node.forEach((item, i) => walk(item, cb, [...path, i]))
  866. return
  867. }
  868. cb(node, path)
  869. Object.entries(node).forEach(([key, value]) => walk(value, cb, [...path, key]))
  870. }
  871. test("keeps edits.items.anyOf without adding type", () => {
  872. const schema = {
  873. type: "object",
  874. properties: {
  875. edits: {
  876. type: "array",
  877. items: {
  878. anyOf: [
  879. {
  880. type: "object",
  881. properties: {
  882. old_string: { type: "string" },
  883. new_string: { type: "string" },
  884. },
  885. required: ["old_string", "new_string"],
  886. },
  887. {
  888. type: "object",
  889. properties: {
  890. old_string: { type: "string" },
  891. new_string: { type: "string" },
  892. replace_all: { type: "boolean" },
  893. },
  894. required: ["old_string", "new_string"],
  895. },
  896. ],
  897. },
  898. },
  899. },
  900. required: ["edits"],
  901. } as any
  902. const result = ProviderTransform.schema(geminiModel, schema) as any
  903. expect(Array.isArray(result.properties.edits.items.anyOf)).toBe(true)
  904. expect(result.properties.edits.items.type).toBeUndefined()
  905. })
  906. test("does not add sibling keys to combiner nodes during sanitize", () => {
  907. const schema = {
  908. type: "object",
  909. properties: {
  910. edits: {
  911. type: "array",
  912. items: {
  913. anyOf: [{ type: "string" }, { type: "number" }],
  914. },
  915. },
  916. value: {
  917. oneOf: [{ type: "string" }, { type: "boolean" }],
  918. },
  919. meta: {
  920. allOf: [
  921. {
  922. type: "object",
  923. properties: { a: { type: "string" } },
  924. },
  925. {
  926. type: "object",
  927. properties: { b: { type: "string" } },
  928. },
  929. ],
  930. },
  931. },
  932. } as any
  933. const input = JSON.parse(JSON.stringify(schema))
  934. const result = ProviderTransform.schema(geminiModel, schema) as any
  935. walk(result, (node, path) => {
  936. const hasCombiner = Array.isArray(node.anyOf) || Array.isArray(node.oneOf) || Array.isArray(node.allOf)
  937. if (!hasCombiner) {
  938. return
  939. }
  940. const before = path.reduce((acc: any, key) => acc?.[key], input)
  941. const added = Object.keys(node).filter((key) => !(key in before))
  942. expect(added).toEqual([])
  943. })
  944. })
  945. })
  946. describe("ProviderTransform.schema - gemini non-object properties removal", () => {
  947. const geminiModel = {
  948. providerID: "google",
  949. api: {
  950. id: "gemini-3-pro",
  951. },
  952. } as any
  953. test("removes properties from non-object types", () => {
  954. const schema = {
  955. type: "object",
  956. properties: {
  957. data: {
  958. type: "string",
  959. properties: { invalid: { type: "string" } },
  960. },
  961. },
  962. } as any
  963. const result = ProviderTransform.schema(geminiModel, schema) as any
  964. expect(result.properties.data.type).toBe("string")
  965. expect(result.properties.data.properties).toBeUndefined()
  966. })
  967. test("removes required from non-object types", () => {
  968. const schema = {
  969. type: "object",
  970. properties: {
  971. data: {
  972. type: "array",
  973. items: { type: "string" },
  974. required: ["invalid"],
  975. },
  976. },
  977. } as any
  978. const result = ProviderTransform.schema(geminiModel, schema) as any
  979. expect(result.properties.data.type).toBe("array")
  980. expect(result.properties.data.required).toBeUndefined()
  981. })
  982. test("removes properties and required from nested non-object types", () => {
  983. const schema = {
  984. type: "object",
  985. properties: {
  986. outer: {
  987. type: "object",
  988. properties: {
  989. inner: {
  990. type: "number",
  991. properties: { bad: { type: "string" } },
  992. required: ["bad"],
  993. },
  994. },
  995. },
  996. },
  997. } as any
  998. const result = ProviderTransform.schema(geminiModel, schema) as any
  999. expect(result.properties.outer.properties.inner.type).toBe("number")
  1000. expect(result.properties.outer.properties.inner.properties).toBeUndefined()
  1001. expect(result.properties.outer.properties.inner.required).toBeUndefined()
  1002. })
  1003. test("keeps properties and required on object types", () => {
  1004. const schema = {
  1005. type: "object",
  1006. properties: {
  1007. data: {
  1008. type: "object",
  1009. properties: { name: { type: "string" } },
  1010. required: ["name"],
  1011. },
  1012. },
  1013. } as any
  1014. const result = ProviderTransform.schema(geminiModel, schema) as any
  1015. expect(result.properties.data.type).toBe("object")
  1016. expect(result.properties.data.properties).toBeDefined()
  1017. expect(result.properties.data.required).toEqual(["name"])
  1018. })
  1019. test("does not affect non-gemini providers", () => {
  1020. const openaiModel = {
  1021. providerID: "openai",
  1022. api: {
  1023. id: "gpt-4",
  1024. },
  1025. } as any
  1026. const schema = {
  1027. type: "object",
  1028. properties: {
  1029. data: {
  1030. type: "string",
  1031. properties: { invalid: { type: "string" } },
  1032. },
  1033. },
  1034. } as any
  1035. const result = ProviderTransform.schema(openaiModel, schema) as any
  1036. expect(result.properties.data.properties).toBeDefined()
  1037. })
  1038. })
  1039. describe("ProviderTransform.schema - moonshot $ref siblings", () => {
  1040. const moonshotModel = {
  1041. providerID: "moonshotai",
  1042. api: {
  1043. id: "kimi-k2",
  1044. },
  1045. } as any
  1046. test("removes sibling descriptions from referenced tool parameter schemas", () => {
  1047. const schema = {
  1048. type: "object",
  1049. properties: {
  1050. deviceType: {
  1051. description: "Optional. The type of device that captured the screenshot, e.g. mobile or desktop.",
  1052. enum: ["DEVICE_TYPE_UNSPECIFIED", "MOBILE", "DESKTOP", "TABLET", "AGNOSTIC"],
  1053. type: "string",
  1054. },
  1055. modelId: {
  1056. description: "Optional. The model to use for generation.",
  1057. enum: ["MODEL_ID_UNSPECIFIED", "GEMINI_3_PRO", "GEMINI_3_FLASH", "GEMINI_3_1_PRO"],
  1058. type: "string",
  1059. },
  1060. projectId: {
  1061. description: "Required. The project ID of screens to generate variants for.",
  1062. type: "string",
  1063. },
  1064. prompt: {
  1065. description: "Required. The input text used to generate the variants.",
  1066. type: "string",
  1067. },
  1068. selectedScreenIds: {
  1069. description: "Required. The screen ids of screen to generate variants for.",
  1070. items: {
  1071. type: "string",
  1072. },
  1073. type: "array",
  1074. },
  1075. variantOptions: {
  1076. $ref: "#/$defs/VariantOptions",
  1077. description:
  1078. "Required. The variant options for generation, including the number of variants, creative range, and aspects to focus on.",
  1079. },
  1080. },
  1081. required: ["projectId", "selectedScreenIds", "prompt", "variantOptions"],
  1082. $defs: {
  1083. VariantOptions: {
  1084. description:
  1085. "Configuration options for design variant generation. This message captures all parameters used to generate variants, allowing the configuration to be stored, replayed, or analyzed.",
  1086. properties: {
  1087. aspects: {
  1088. description: "Optional. Specific aspects to focus on. If empty, all aspects may be varied.",
  1089. items: {
  1090. enum: ["VARIANT_ASPECT_UNSPECIFIED", "LAYOUT", "COLOR_SCHEME", "IMAGES", "TEXT_FONT", "TEXT_CONTENT"],
  1091. type: "string",
  1092. },
  1093. type: "array",
  1094. },
  1095. creativeRange: {
  1096. description: "Optional. Creative range for variations. Default: EXPLORE",
  1097. enum: ["CREATIVE_RANGE_UNSPECIFIED", "REFINE", "EXPLORE", "REIMAGINE"],
  1098. type: "string",
  1099. },
  1100. variantCount: {
  1101. description: "Optional. Number of variants to generate (1-5). Default: 3",
  1102. format: "int32",
  1103. type: "integer",
  1104. },
  1105. },
  1106. type: "object",
  1107. },
  1108. },
  1109. description: "Request message for GenerateVariants.",
  1110. additionalProperties: false,
  1111. } as any
  1112. const result = ProviderTransform.schema(moonshotModel, schema) as any
  1113. expect(result.properties.variantOptions).toEqual({
  1114. $ref: "#/$defs/VariantOptions",
  1115. })
  1116. expect(result.$defs.VariantOptions.description).toBe(schema.$defs.VariantOptions.description)
  1117. })
  1118. test("also runs for kimi models outside the moonshot provider", () => {
  1119. const result = ProviderTransform.schema(
  1120. {
  1121. providerID: "openrouter",
  1122. name: "Kimi K2",
  1123. api: {
  1124. id: "moonshotai/kimi-k2",
  1125. },
  1126. } as any,
  1127. {
  1128. type: "object",
  1129. properties: {
  1130. value: {
  1131. $ref: "#/$defs/Value",
  1132. description: "Moonshot rejects this sibling after ref expansion.",
  1133. },
  1134. },
  1135. $defs: {
  1136. Value: {
  1137. description: "Referenced schema description stays here.",
  1138. type: "object",
  1139. },
  1140. },
  1141. } as any,
  1142. ) as any
  1143. expect(result.properties.value).toEqual({
  1144. $ref: "#/$defs/Value",
  1145. })
  1146. })
  1147. test("converts tuple-style array items to a single item schema", () => {
  1148. const result = ProviderTransform.schema(moonshotModel, {
  1149. type: "object",
  1150. properties: {
  1151. codeSpec: {
  1152. type: "object",
  1153. properties: {
  1154. accessibility: {
  1155. type: "object",
  1156. properties: {
  1157. renderedSize: {
  1158. description: "Rendered size [width, height] in px",
  1159. type: "array",
  1160. items: [{ type: "number" }, { type: "number" }],
  1161. minItems: 2,
  1162. maxItems: 2,
  1163. },
  1164. },
  1165. },
  1166. },
  1167. },
  1168. },
  1169. } as any) as any
  1170. expect(result.properties.codeSpec.properties.accessibility.properties.renderedSize.items).toEqual({
  1171. type: "number",
  1172. })
  1173. })
  1174. })
  1175. describe("ProviderTransform.message - DeepSeek reasoning content", () => {
  1176. test("DeepSeek with tool calls includes reasoning_content in providerOptions", () => {
  1177. const msgs = [
  1178. {
  1179. role: "assistant",
  1180. content: [
  1181. { type: "reasoning", text: "Let me think about this..." },
  1182. {
  1183. type: "tool-call",
  1184. toolCallId: "test",
  1185. toolName: "bash",
  1186. input: { command: "echo hello" },
  1187. },
  1188. ],
  1189. },
  1190. ] as any[]
  1191. const result = ProviderTransform.message(
  1192. msgs,
  1193. {
  1194. id: ModelV2.ID.make("deepseek/deepseek-chat"),
  1195. providerID: ProviderV2.ID.make("deepseek"),
  1196. api: {
  1197. id: "deepseek-chat",
  1198. url: "https://api.deepseek.com",
  1199. npm: "@ai-sdk/openai-compatible",
  1200. },
  1201. name: "DeepSeek Chat",
  1202. capabilities: {
  1203. temperature: true,
  1204. reasoning: true,
  1205. attachment: false,
  1206. toolcall: true,
  1207. input: { text: true, audio: false, image: false, video: false, pdf: false },
  1208. output: { text: true, audio: false, image: false, video: false, pdf: false },
  1209. interleaved: {
  1210. field: "reasoning_content",
  1211. },
  1212. },
  1213. cost: {
  1214. input: 0.001,
  1215. output: 0.002,
  1216. cache: { read: 0.0001, write: 0.0002 },
  1217. },
  1218. limit: {
  1219. context: 128000,
  1220. output: 8192,
  1221. },
  1222. status: "active",
  1223. options: {},
  1224. headers: {},
  1225. release_date: "2023-04-01",
  1226. },
  1227. {},
  1228. )
  1229. expect(result).toHaveLength(1)
  1230. expect(result[0].content).toEqual([
  1231. {
  1232. type: "tool-call",
  1233. toolCallId: "test",
  1234. toolName: "bash",
  1235. input: { command: "echo hello" },
  1236. },
  1237. ])
  1238. expect(result[0].providerOptions?.openaiCompatible?.reasoning_content).toBe("Let me think about this...")
  1239. })
  1240. test("Non-DeepSeek providers leave reasoning content unchanged", () => {
  1241. const msgs = [
  1242. {
  1243. role: "assistant",
  1244. content: [
  1245. { type: "reasoning", text: "Should not be processed" },
  1246. { type: "text", text: "Answer" },
  1247. ],
  1248. },
  1249. ] as any[]
  1250. const result = ProviderTransform.message(
  1251. msgs,
  1252. {
  1253. id: ModelV2.ID.make("openai/gpt-4"),
  1254. providerID: ProviderV2.ID.make("openai"),
  1255. api: {
  1256. id: "gpt-4",
  1257. url: "https://api.openai.com",
  1258. npm: "@ai-sdk/openai",
  1259. },
  1260. name: "GPT-4",
  1261. capabilities: {
  1262. temperature: true,
  1263. reasoning: false,
  1264. attachment: true,
  1265. toolcall: true,
  1266. input: { text: true, audio: false, image: true, video: false, pdf: false },
  1267. output: { text: true, audio: false, image: false, video: false, pdf: false },
  1268. interleaved: false,
  1269. },
  1270. cost: {
  1271. input: 0.03,
  1272. output: 0.06,
  1273. cache: { read: 0.001, write: 0.002 },
  1274. },
  1275. limit: {
  1276. context: 128000,
  1277. output: 4096,
  1278. },
  1279. status: "active",
  1280. options: {},
  1281. headers: {},
  1282. release_date: "2023-04-01",
  1283. },
  1284. {},
  1285. )
  1286. expect(result[0].content).toEqual([
  1287. { type: "reasoning", text: "Should not be processed" },
  1288. { type: "text", text: "Answer" },
  1289. ])
  1290. expect(result[0].providerOptions?.openaiCompatible?.reasoning_content).toBeUndefined()
  1291. })
  1292. })
  1293. describe("ProviderTransform.message - surrogate sanitization", () => {
  1294. const model = {
  1295. id: "test/test-model",
  1296. providerID: "test",
  1297. api: {
  1298. id: "test-model",
  1299. url: "https://api.test.com",
  1300. npm: "@ai-sdk/openai-compatible",
  1301. },
  1302. name: "Test Model",
  1303. capabilities: {
  1304. temperature: true,
  1305. reasoning: true,
  1306. attachment: true,
  1307. toolcall: true,
  1308. input: { text: true, audio: false, image: true, video: false, pdf: false },
  1309. output: { text: true, audio: false, image: false, video: false, pdf: false },
  1310. interleaved: false,
  1311. },
  1312. cost: { input: 0.001, output: 0.002, cache: { read: 0.0001, write: 0.0002 } },
  1313. limit: { context: 128000, output: 8192 },
  1314. status: "active",
  1315. options: {},
  1316. headers: {},
  1317. } as any
  1318. test("replaces lone surrogates in model-visible text", () => {
  1319. const lone = "\uD83D"
  1320. const valid = "🚀"
  1321. const sanitized = "�"
  1322. const text = (label: string) => `${label} ${lone} and ${valid}`
  1323. const expected = (label: string) => `${label} ${sanitized} and ${valid}`
  1324. const msgs = [
  1325. { role: "system", content: text("system") },
  1326. { role: "user", content: text("user string") },
  1327. {
  1328. role: "user",
  1329. content: [
  1330. { type: "text", text: text("user text") },
  1331. { type: "image", image: "data:image/png;base64,abcd" },
  1332. ],
  1333. },
  1334. { role: "assistant", content: text("assistant string") },
  1335. {
  1336. role: "assistant",
  1337. content: [
  1338. { type: "text", text: text("assistant text") },
  1339. { type: "reasoning", text: text("assistant reasoning") },
  1340. { type: "tool-call", toolCallId: "call-1", toolName: "Read", input: { filePath: ".opencode/tool/emoji.ts" } },
  1341. {
  1342. type: "tool-result",
  1343. toolCallId: "call-2",
  1344. toolName: "Read",
  1345. output: { type: "text", value: text("assistant tool text") },
  1346. },
  1347. {
  1348. type: "tool-result",
  1349. toolCallId: "call-3",
  1350. toolName: "Read",
  1351. output: { type: "error-text", value: text("assistant tool error") },
  1352. },
  1353. {
  1354. type: "tool-result",
  1355. toolCallId: "call-4",
  1356. toolName: "Read",
  1357. output: { type: "content", value: [{ type: "text", text: text("assistant tool content") }] },
  1358. },
  1359. ],
  1360. },
  1361. {
  1362. role: "tool",
  1363. content: [
  1364. {
  1365. type: "tool-result",
  1366. toolCallId: "call-5",
  1367. toolName: "Read",
  1368. output: { type: "text", value: text("tool text") },
  1369. },
  1370. {
  1371. type: "tool-result",
  1372. toolCallId: "call-6",
  1373. toolName: "Read",
  1374. output: { type: "error-text", value: text("tool error") },
  1375. },
  1376. {
  1377. type: "tool-result",
  1378. toolCallId: "call-7",
  1379. toolName: "Read",
  1380. output: { type: "content", value: [{ type: "text", text: text("tool content") }] },
  1381. },
  1382. ],
  1383. },
  1384. ] as any[]
  1385. const result = ProviderTransform.message(msgs, model, {}) as any[]
  1386. expect(result[0].content).toBe(expected("system"))
  1387. expect(result[1].content).toBe(expected("user string"))
  1388. expect(result[2].content[0].text).toBe(expected("user text"))
  1389. expect(result[3].content).toBe(expected("assistant string"))
  1390. expect(result[4].content[0].text).toBe(expected("assistant text"))
  1391. expect(result[4].content[1].text).toBe(expected("assistant reasoning"))
  1392. expect(result[4].content[3].output.value).toBe(expected("assistant tool text"))
  1393. expect(result[4].content[4].output.value).toBe(expected("assistant tool error"))
  1394. expect(result[4].content[5].output.value[0].text).toBe(expected("assistant tool content"))
  1395. expect(result[5].content[0].output.value).toBe(expected("tool text"))
  1396. expect(result[5].content[1].output.value).toBe(expected("tool error"))
  1397. expect(result[5].content[2].output.value[0].text).toBe(expected("tool content"))
  1398. expect(result[2].content[1]).toEqual({ type: "image", image: "data:image/png;base64,abcd" })
  1399. })
  1400. })
  1401. describe("ProviderTransform.message - empty image handling", () => {
  1402. const mockModel = {
  1403. id: "anthropic/claude-3-5-sonnet",
  1404. providerID: "anthropic",
  1405. api: {
  1406. id: "claude-3-5-sonnet-20241022",
  1407. url: "https://api.anthropic.com",
  1408. npm: "@ai-sdk/anthropic",
  1409. },
  1410. name: "Claude 3.5 Sonnet",
  1411. capabilities: {
  1412. temperature: true,
  1413. reasoning: false,
  1414. attachment: true,
  1415. toolcall: true,
  1416. input: { text: true, audio: false, image: true, video: false, pdf: true },
  1417. output: { text: true, audio: false, image: false, video: false, pdf: false },
  1418. interleaved: false,
  1419. },
  1420. cost: {
  1421. input: 0.003,
  1422. output: 0.015,
  1423. cache: { read: 0.0003, write: 0.00375 },
  1424. },
  1425. limit: {
  1426. context: 200000,
  1427. output: 8192,
  1428. },
  1429. status: "active",
  1430. options: {},
  1431. headers: {},
  1432. } as any
  1433. test("should replace empty base64 image with error text", () => {
  1434. const msgs = [
  1435. {
  1436. role: "user",
  1437. content: [
  1438. { type: "text", text: "What is in this image?" },
  1439. { type: "image", image: "data:image/png;base64," },
  1440. ],
  1441. },
  1442. ] as any[]
  1443. const result = ProviderTransform.message(msgs, mockModel, {})
  1444. expect(result).toHaveLength(1)
  1445. expect(result[0].content).toHaveLength(2)
  1446. expect(result[0].content[0]).toEqual({ type: "text", text: "What is in this image?" })
  1447. expect(result[0].content[1]).toEqual({
  1448. type: "text",
  1449. text: "ERROR: Image file is empty or corrupted. Please provide a valid image.",
  1450. })
  1451. })
  1452. test("should keep valid base64 images unchanged", () => {
  1453. const validBase64 =
  1454. "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg=="
  1455. const msgs = [
  1456. {
  1457. role: "user",
  1458. content: [
  1459. { type: "text", text: "What is in this image?" },
  1460. { type: "image", image: `data:image/png;base64,${validBase64}` },
  1461. ],
  1462. },
  1463. ] as any[]
  1464. const result = ProviderTransform.message(msgs, mockModel, {})
  1465. expect(result).toHaveLength(1)
  1466. expect(result[0].content).toHaveLength(2)
  1467. expect(result[0].content[0]).toEqual({ type: "text", text: "What is in this image?" })
  1468. expect(result[0].content[1]).toEqual({ type: "image", image: `data:image/png;base64,${validBase64}` })
  1469. })
  1470. test("should handle mixed valid and empty images", () => {
  1471. const validBase64 =
  1472. "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg=="
  1473. const msgs = [
  1474. {
  1475. role: "user",
  1476. content: [
  1477. { type: "text", text: "Compare these images" },
  1478. { type: "image", image: `data:image/png;base64,${validBase64}` },
  1479. { type: "image", image: "data:image/jpeg;base64," },
  1480. ],
  1481. },
  1482. ] as any[]
  1483. const result = ProviderTransform.message(msgs, mockModel, {})
  1484. expect(result).toHaveLength(1)
  1485. expect(result[0].content).toHaveLength(3)
  1486. expect(result[0].content[0]).toEqual({ type: "text", text: "Compare these images" })
  1487. expect(result[0].content[1]).toEqual({ type: "image", image: `data:image/png;base64,${validBase64}` })
  1488. expect(result[0].content[2]).toEqual({
  1489. type: "text",
  1490. text: "ERROR: Image file is empty or corrupted. Please provide a valid image.",
  1491. })
  1492. })
  1493. })
  1494. describe("ProviderTransform.message - anthropic empty content filtering", () => {
  1495. const anthropicModel = {
  1496. id: "anthropic/claude-3-5-sonnet",
  1497. providerID: "anthropic",
  1498. api: {
  1499. id: "claude-3-5-sonnet-20241022",
  1500. url: "https://api.anthropic.com",
  1501. npm: "@ai-sdk/anthropic",
  1502. },
  1503. name: "Claude 3.5 Sonnet",
  1504. capabilities: {
  1505. temperature: true,
  1506. reasoning: false,
  1507. attachment: true,
  1508. toolcall: true,
  1509. input: { text: true, audio: false, image: true, video: false, pdf: true },
  1510. output: { text: true, audio: false, image: false, video: false, pdf: false },
  1511. interleaved: false,
  1512. },
  1513. cost: {
  1514. input: 0.003,
  1515. output: 0.015,
  1516. cache: { read: 0.0003, write: 0.00375 },
  1517. },
  1518. limit: {
  1519. context: 200000,
  1520. output: 8192,
  1521. },
  1522. status: "active",
  1523. options: {},
  1524. headers: {},
  1525. } as any
  1526. test("filters out messages with empty string content", () => {
  1527. const msgs = [
  1528. { role: "user", content: "Hello" },
  1529. { role: "assistant", content: "" },
  1530. { role: "user", content: "World" },
  1531. ] as any[]
  1532. const result = ProviderTransform.message(msgs, anthropicModel, {})
  1533. expect(result).toHaveLength(2)
  1534. expect(result[0].content).toBe("Hello")
  1535. expect(result[1].content).toBe("World")
  1536. })
  1537. test("filters out empty text parts from array content", () => {
  1538. const msgs = [
  1539. {
  1540. role: "assistant",
  1541. content: [
  1542. { type: "text", text: "" },
  1543. { type: "text", text: "Hello" },
  1544. { type: "text", text: "" },
  1545. ],
  1546. },
  1547. ] as any[]
  1548. const result = ProviderTransform.message(msgs, anthropicModel, {})
  1549. expect(result).toHaveLength(1)
  1550. expect(result[0].content).toHaveLength(1)
  1551. expect(result[0].content[0]).toEqual({ type: "text", text: "Hello" })
  1552. })
  1553. test("filters out empty reasoning parts from array content", () => {
  1554. const msgs = [
  1555. {
  1556. role: "assistant",
  1557. content: [
  1558. { type: "reasoning", text: "" },
  1559. { type: "text", text: "Answer" },
  1560. { type: "reasoning", text: "" },
  1561. ],
  1562. },
  1563. ] as any[]
  1564. const result = ProviderTransform.message(msgs, anthropicModel, {})
  1565. expect(result).toHaveLength(1)
  1566. expect(result[0].content).toHaveLength(1)
  1567. expect(result[0].content[0]).toEqual({ type: "text", text: "Answer" })
  1568. })
  1569. test("removes entire message when all parts are empty", () => {
  1570. const msgs = [
  1571. { role: "user", content: "Hello" },
  1572. {
  1573. role: "assistant",
  1574. content: [
  1575. { type: "text", text: "" },
  1576. { type: "reasoning", text: "" },
  1577. ],
  1578. },
  1579. { role: "user", content: "World" },
  1580. ] as any[]
  1581. const result = ProviderTransform.message(msgs, anthropicModel, {})
  1582. expect(result).toHaveLength(2)
  1583. expect(result[0].content).toBe("Hello")
  1584. expect(result[1].content).toBe("World")
  1585. })
  1586. test("keeps non-text/reasoning parts even if text parts are empty", () => {
  1587. const msgs = [
  1588. {
  1589. role: "assistant",
  1590. content: [
  1591. { type: "text", text: "" },
  1592. { type: "tool-call", toolCallId: "123", toolName: "bash", input: { command: "ls" } },
  1593. ],
  1594. },
  1595. ] as any[]
  1596. const result = ProviderTransform.message(msgs, anthropicModel, {})
  1597. expect(result).toHaveLength(1)
  1598. expect(result[0].content).toHaveLength(1)
  1599. expect(result[0].content[0]).toEqual({
  1600. type: "tool-call",
  1601. toolCallId: "123",
  1602. toolName: "bash",
  1603. input: { command: "ls" },
  1604. })
  1605. })
  1606. test("keeps messages with valid text alongside empty parts", () => {
  1607. const msgs = [
  1608. {
  1609. role: "assistant",
  1610. content: [
  1611. { type: "reasoning", text: "Thinking..." },
  1612. { type: "text", text: "" },
  1613. { type: "text", text: "Result" },
  1614. ],
  1615. },
  1616. ] as any[]
  1617. const result = ProviderTransform.message(msgs, anthropicModel, {})
  1618. expect(result).toHaveLength(1)
  1619. expect(result[0].content).toHaveLength(2)
  1620. expect(result[0].content[0]).toEqual({ type: "reasoning", text: "Thinking..." })
  1621. expect(result[0].content[1]).toEqual({ type: "text", text: "Result" })
  1622. })
  1623. test("filters empty content for bedrock provider", () => {
  1624. const bedrockModel = {
  1625. ...anthropicModel,
  1626. id: "amazon-bedrock/anthropic.claude-opus-4-6",
  1627. providerID: "amazon-bedrock",
  1628. api: {
  1629. id: "anthropic.claude-opus-4-6",
  1630. url: "https://bedrock-runtime.us-east-1.amazonaws.com",
  1631. npm: "@ai-sdk/amazon-bedrock",
  1632. },
  1633. }
  1634. const msgs = [
  1635. { role: "user", content: "Hello" },
  1636. { role: "assistant", content: "" },
  1637. {
  1638. role: "assistant",
  1639. content: [
  1640. { type: "text", text: "" },
  1641. { type: "text", text: "Answer" },
  1642. ],
  1643. },
  1644. ] as any[]
  1645. const result = ProviderTransform.message(msgs, bedrockModel, {})
  1646. expect(result).toHaveLength(2)
  1647. expect(result[0].content).toBe("Hello")
  1648. expect(result[1].content).toHaveLength(1)
  1649. expect(result[1].content[0]).toEqual({ type: "text", text: "Answer" })
  1650. })
  1651. test("does not filter for non-anthropic providers", () => {
  1652. const openaiModel = {
  1653. ...anthropicModel,
  1654. providerID: "openai",
  1655. api: {
  1656. id: "gpt-4",
  1657. url: "https://api.openai.com",
  1658. npm: "@ai-sdk/openai",
  1659. },
  1660. }
  1661. const msgs = [
  1662. { role: "assistant", content: "" },
  1663. {
  1664. role: "assistant",
  1665. content: [{ type: "text", text: "" }],
  1666. },
  1667. ] as any[]
  1668. const result = ProviderTransform.message(msgs, openaiModel, {})
  1669. expect(result).toHaveLength(2)
  1670. expect(result[0].content).toBe("")
  1671. expect(result[1].content).toHaveLength(1)
  1672. })
  1673. test("leaves valid anthropic assistant tool ordering unchanged", () => {
  1674. const msgs = [
  1675. {
  1676. role: "assistant",
  1677. content: [
  1678. { type: "text", text: "I checked your home directory and looked for PDF files." },
  1679. { type: "tool-call", toolCallId: "toolu_1", toolName: "read", input: { filePath: "/root" } },
  1680. { type: "tool-call", toolCallId: "toolu_2", toolName: "glob", input: { pattern: "**/*.pdf" } },
  1681. ],
  1682. },
  1683. ] as any[]
  1684. const result = ProviderTransform.message(msgs, anthropicModel, {}) as any[]
  1685. expect(result).toHaveLength(1)
  1686. expect(result[0].content).toMatchObject([
  1687. { type: "text", text: "I checked your home directory and looked for PDF files." },
  1688. { type: "tool-call", toolCallId: "toolu_1", toolName: "read", input: { filePath: "/root" } },
  1689. { type: "tool-call", toolCallId: "toolu_2", toolName: "glob", input: { pattern: "**/*.pdf" } },
  1690. ])
  1691. })
  1692. })
  1693. describe("ProviderTransform.message - strip openai metadata when store=false", () => {
  1694. const openaiModel = {
  1695. id: "openai/gpt-5",
  1696. providerID: "openai",
  1697. api: {
  1698. id: "gpt-5",
  1699. url: "https://api.openai.com",
  1700. npm: "@ai-sdk/openai",
  1701. },
  1702. name: "GPT-5",
  1703. capabilities: {
  1704. temperature: true,
  1705. reasoning: true,
  1706. attachment: true,
  1707. toolcall: true,
  1708. input: { text: true, audio: false, image: true, video: false, pdf: false },
  1709. output: { text: true, audio: false, image: false, video: false, pdf: false },
  1710. interleaved: false,
  1711. },
  1712. cost: { input: 0.03, output: 0.06, cache: { read: 0.001, write: 0.002 } },
  1713. limit: { context: 128000, output: 4096 },
  1714. status: "active",
  1715. options: {},
  1716. headers: {},
  1717. } as any
  1718. test("strips OpenAI itemId and preserves reasoningEncryptedContent when store=false", () => {
  1719. const msgs = [
  1720. {
  1721. role: "assistant",
  1722. content: [
  1723. {
  1724. type: "reasoning",
  1725. text: "thinking...",
  1726. providerOptions: {
  1727. openai: {
  1728. itemId: "rs_123",
  1729. reasoningEncryptedContent: "encrypted",
  1730. },
  1731. },
  1732. },
  1733. {
  1734. type: "text",
  1735. text: "Hello",
  1736. providerOptions: {
  1737. openai: {
  1738. itemId: "msg_456",
  1739. },
  1740. },
  1741. },
  1742. ],
  1743. },
  1744. ] as any[]
  1745. const result = ProviderTransform.message(msgs, openaiModel, { store: false }) as any[]
  1746. expect(result).toHaveLength(1)
  1747. expect(result[0].content[0].providerOptions?.openai?.itemId).toBeUndefined()
  1748. expect(result[0].content[0].providerOptions?.openai?.reasoningEncryptedContent).toBe("encrypted")
  1749. expect(result[0].content[1].providerOptions?.openai?.itemId).toBeUndefined()
  1750. })
  1751. test("uses the SDK package namespace rather than provider ID", () => {
  1752. const zenModel = {
  1753. ...openaiModel,
  1754. providerID: "zen",
  1755. }
  1756. const msgs = [
  1757. {
  1758. role: "assistant",
  1759. content: [
  1760. {
  1761. type: "reasoning",
  1762. text: "thinking...",
  1763. providerOptions: {
  1764. openai: {
  1765. itemId: "rs_123",
  1766. reasoningEncryptedContent: "encrypted",
  1767. },
  1768. },
  1769. },
  1770. {
  1771. type: "text",
  1772. text: "Hello",
  1773. providerOptions: {
  1774. openai: {
  1775. itemId: "msg_456",
  1776. },
  1777. },
  1778. },
  1779. ],
  1780. },
  1781. ] as any[]
  1782. const result = ProviderTransform.message(msgs, zenModel, { store: false }) as any[]
  1783. expect(result).toHaveLength(1)
  1784. expect(result[0].content[0].providerOptions?.openai?.itemId).toBeUndefined()
  1785. expect(result[0].content[0].providerOptions?.openai?.reasoningEncryptedContent).toBe("encrypted")
  1786. expect(result[0].content[1].providerOptions?.openai?.itemId).toBeUndefined()
  1787. })
  1788. test("preserves other OpenAI options", () => {
  1789. const msgs = [
  1790. {
  1791. role: "assistant",
  1792. content: [
  1793. {
  1794. type: "text",
  1795. text: "Hello",
  1796. providerOptions: {
  1797. openai: {
  1798. itemId: "msg_123",
  1799. otherOption: "value",
  1800. },
  1801. },
  1802. },
  1803. ],
  1804. },
  1805. ] as any[]
  1806. const result = ProviderTransform.message(msgs, openaiModel, { store: false }) as any[]
  1807. expect(result[0].content[0].providerOptions?.openai?.itemId).toBeUndefined()
  1808. expect(result[0].content[0].providerOptions?.openai?.otherOption).toBe("value")
  1809. })
  1810. test("strips Azure itemId from the Azure namespace", () => {
  1811. const azureModel = {
  1812. ...openaiModel,
  1813. providerID: "azure",
  1814. api: {
  1815. id: "gpt-5",
  1816. url: "https://example.openai.azure.com",
  1817. npm: "@ai-sdk/azure",
  1818. },
  1819. }
  1820. const msgs = [
  1821. {
  1822. role: "assistant",
  1823. content: [
  1824. {
  1825. type: "text",
  1826. text: "Hello",
  1827. providerOptions: {
  1828. azure: { itemId: "msg_123", otherOption: "value" },
  1829. openai: { itemId: "msg_openai" },
  1830. },
  1831. },
  1832. ],
  1833. },
  1834. ] as any[]
  1835. const result = ProviderTransform.message(msgs, azureModel, { store: false }) as any[]
  1836. expect(result[0].content[0].providerOptions?.azure?.itemId).toBeUndefined()
  1837. expect(result[0].content[0].providerOptions?.azure?.otherOption).toBe("value")
  1838. expect(result[0].content[0].providerOptions?.openai?.itemId).toBe("msg_openai")
  1839. })
  1840. test("strips Bedrock Mantle itemId from the OpenAI namespace", () => {
  1841. const mantleModel = {
  1842. ...openaiModel,
  1843. providerID: "amazon-bedrock",
  1844. api: {
  1845. id: "openai.gpt-5.5",
  1846. url: "https://bedrock-mantle.us-east-2.api.aws/openai/v1",
  1847. npm: "@ai-sdk/amazon-bedrock/mantle",
  1848. },
  1849. }
  1850. const msgs = [
  1851. {
  1852. role: "assistant",
  1853. providerOptions: { openai: { itemId: "msg_root", otherOption: "root-value" } },
  1854. content: [
  1855. {
  1856. type: "reasoning",
  1857. text: "thinking...",
  1858. providerOptions: {
  1859. openai: { itemId: "rs_123", reasoningEncryptedContent: "encrypted" },
  1860. },
  1861. },
  1862. ],
  1863. },
  1864. ] as any[]
  1865. const result = ProviderTransform.message(msgs, mantleModel, { store: false }) as any[]
  1866. expect(result[0].providerOptions?.openai?.itemId).toBeUndefined()
  1867. expect(result[0].providerOptions?.openai?.otherOption).toBe("root-value")
  1868. expect(result[0].content[0].providerOptions?.openai?.itemId).toBeUndefined()
  1869. expect(result[0].content[0].providerOptions?.openai?.reasoningEncryptedContent).toBe("encrypted")
  1870. })
  1871. test("preserves metadata for openai package when store is true", () => {
  1872. const msgs = [
  1873. {
  1874. role: "assistant",
  1875. content: [
  1876. {
  1877. type: "text",
  1878. text: "Hello",
  1879. providerOptions: {
  1880. openai: {
  1881. itemId: "msg_123",
  1882. },
  1883. },
  1884. },
  1885. ],
  1886. },
  1887. ] as any[]
  1888. // openai package preserves itemId regardless of store value
  1889. const result = ProviderTransform.message(msgs, openaiModel, { store: true }) as any[]
  1890. expect(result[0].content[0].providerOptions?.openai?.itemId).toBe("msg_123")
  1891. })
  1892. test("preserves metadata for non-openai packages when store is false", () => {
  1893. const anthropicModel = {
  1894. ...openaiModel,
  1895. providerID: "anthropic",
  1896. api: {
  1897. id: "claude-3",
  1898. url: "https://api.anthropic.com",
  1899. npm: "@ai-sdk/anthropic",
  1900. },
  1901. }
  1902. const msgs = [
  1903. {
  1904. role: "assistant",
  1905. content: [
  1906. {
  1907. type: "text",
  1908. text: "Hello",
  1909. providerOptions: {
  1910. openai: {
  1911. itemId: "msg_123",
  1912. },
  1913. },
  1914. },
  1915. ],
  1916. },
  1917. ] as any[]
  1918. // store=false preserves metadata for non-openai packages
  1919. const result = ProviderTransform.message(msgs, anthropicModel, { store: false }) as any[]
  1920. expect(result[0].content[0].providerOptions?.openai?.itemId).toBe("msg_123")
  1921. })
  1922. test("preserves metadata using providerID key when store is false", () => {
  1923. const opencodeModel = {
  1924. ...openaiModel,
  1925. providerID: "opencode",
  1926. api: {
  1927. id: "opencode-test",
  1928. url: "https://api.opencode.ai",
  1929. npm: "@ai-sdk/openai-compatible",
  1930. },
  1931. }
  1932. const msgs = [
  1933. {
  1934. role: "assistant",
  1935. content: [
  1936. {
  1937. type: "text",
  1938. text: "Hello",
  1939. providerOptions: {
  1940. opencode: {
  1941. itemId: "msg_123",
  1942. otherOption: "value",
  1943. },
  1944. },
  1945. },
  1946. ],
  1947. },
  1948. ] as any[]
  1949. const result = ProviderTransform.message(msgs, opencodeModel, { store: false }) as any[]
  1950. expect(result[0].content[0].providerOptions?.opencode?.itemId).toBe("msg_123")
  1951. expect(result[0].content[0].providerOptions?.opencode?.otherOption).toBe("value")
  1952. })
  1953. test("preserves itemId across all providerOptions keys", () => {
  1954. const opencodeModel = {
  1955. ...openaiModel,
  1956. providerID: "opencode",
  1957. api: {
  1958. id: "opencode-test",
  1959. url: "https://api.opencode.ai",
  1960. npm: "@ai-sdk/openai-compatible",
  1961. },
  1962. }
  1963. const msgs = [
  1964. {
  1965. role: "assistant",
  1966. providerOptions: {
  1967. openai: { itemId: "msg_root" },
  1968. opencode: { itemId: "msg_opencode" },
  1969. extra: { itemId: "msg_extra" },
  1970. },
  1971. content: [
  1972. {
  1973. type: "text",
  1974. text: "Hello",
  1975. providerOptions: {
  1976. openai: { itemId: "msg_openai_part" },
  1977. opencode: { itemId: "msg_opencode_part" },
  1978. extra: { itemId: "msg_extra_part" },
  1979. },
  1980. },
  1981. ],
  1982. },
  1983. ] as any[]
  1984. const result = ProviderTransform.message(msgs, opencodeModel, { store: false }) as any[]
  1985. expect(result[0].providerOptions?.openai?.itemId).toBe("msg_root")
  1986. expect(result[0].providerOptions?.opencode?.itemId).toBe("msg_opencode")
  1987. expect(result[0].providerOptions?.extra?.itemId).toBe("msg_extra")
  1988. expect(result[0].content[0].providerOptions?.openai?.itemId).toBe("msg_openai_part")
  1989. expect(result[0].content[0].providerOptions?.opencode?.itemId).toBe("msg_opencode_part")
  1990. expect(result[0].content[0].providerOptions?.extra?.itemId).toBe("msg_extra_part")
  1991. })
  1992. test("does not strip metadata for non-openai packages when store is not false", () => {
  1993. const anthropicModel = {
  1994. ...openaiModel,
  1995. providerID: "anthropic",
  1996. api: {
  1997. id: "claude-3",
  1998. url: "https://api.anthropic.com",
  1999. npm: "@ai-sdk/anthropic",
  2000. },
  2001. }
  2002. const msgs = [
  2003. {
  2004. role: "assistant",
  2005. content: [
  2006. {
  2007. type: "text",
  2008. text: "Hello",
  2009. providerOptions: {
  2010. openai: {
  2011. itemId: "msg_123",
  2012. },
  2013. },
  2014. },
  2015. ],
  2016. },
  2017. ] as any[]
  2018. const result = ProviderTransform.message(msgs, anthropicModel, {}) as any[]
  2019. expect(result[0].content[0].providerOptions?.openai?.itemId).toBe("msg_123")
  2020. })
  2021. })
  2022. describe("ProviderTransform.message - providerOptions key remapping", () => {
  2023. const createModel = (providerID: string, npm: string) =>
  2024. ({
  2025. id: `${providerID}/test-model`,
  2026. providerID,
  2027. api: {
  2028. id: "test-model",
  2029. url: "https://api.test.com",
  2030. npm,
  2031. },
  2032. name: "Test Model",
  2033. capabilities: {
  2034. temperature: true,
  2035. reasoning: false,
  2036. attachment: true,
  2037. toolcall: true,
  2038. input: { text: true, audio: false, image: true, video: false, pdf: true },
  2039. output: { text: true, audio: false, image: false, video: false, pdf: false },
  2040. interleaved: false,
  2041. },
  2042. cost: { input: 0.001, output: 0.002, cache: { read: 0.0001, write: 0.0002 } },
  2043. limit: { context: 128000, output: 8192 },
  2044. status: "active",
  2045. options: {},
  2046. headers: {},
  2047. }) as any
  2048. test("azure keeps 'azure' key and does not remap to 'openai'", () => {
  2049. const model = createModel("azure", "@ai-sdk/azure")
  2050. const msgs = [
  2051. {
  2052. role: "user",
  2053. content: "Hello",
  2054. providerOptions: {
  2055. azure: { someOption: "value" },
  2056. },
  2057. },
  2058. ] as any[]
  2059. const result = ProviderTransform.message(msgs, model, {})
  2060. expect(result[0].providerOptions?.azure).toEqual({ someOption: "value" })
  2061. expect(result[0].providerOptions?.openai).toBeUndefined()
  2062. })
  2063. test("azure cognitive services remaps providerID to 'azure' key", () => {
  2064. const model = createModel("azure-cognitive-services", "@ai-sdk/azure")
  2065. const msgs = [
  2066. {
  2067. role: "user",
  2068. content: [
  2069. {
  2070. type: "text",
  2071. text: "Hello",
  2072. providerOptions: {
  2073. "azure-cognitive-services": { part: true },
  2074. },
  2075. },
  2076. ],
  2077. providerOptions: {
  2078. "azure-cognitive-services": { someOption: "value" },
  2079. },
  2080. },
  2081. ] as any[]
  2082. const result = ProviderTransform.message(msgs, model, {}) as any[]
  2083. const part = result[0].content[0] as any
  2084. expect(result[0].providerOptions?.azure).toEqual({ someOption: "value" })
  2085. expect(result[0].providerOptions?.["azure-cognitive-services"]).toBeUndefined()
  2086. expect(part.providerOptions?.azure).toEqual({ part: true })
  2087. expect(part.providerOptions?.["azure-cognitive-services"]).toBeUndefined()
  2088. })
  2089. test("copilot remaps providerID to 'copilot' key", () => {
  2090. const model = createModel("github-copilot", "@ai-sdk/github-copilot")
  2091. const msgs = [
  2092. {
  2093. role: "user",
  2094. content: "Hello",
  2095. providerOptions: {
  2096. copilot: { someOption: "value" },
  2097. },
  2098. },
  2099. ] as any[]
  2100. const result = ProviderTransform.message(msgs, model, {})
  2101. expect(result[0].providerOptions?.copilot).toEqual({ someOption: "value" })
  2102. expect(result[0].providerOptions?.["github-copilot"]).toBeUndefined()
  2103. })
  2104. test("bedrock remaps providerID to 'bedrock' key", () => {
  2105. const model = createModel("my-bedrock", "@ai-sdk/amazon-bedrock")
  2106. const msgs = [
  2107. {
  2108. role: "user",
  2109. content: "Hello",
  2110. providerOptions: {
  2111. "my-bedrock": { someOption: "value" },
  2112. },
  2113. },
  2114. ] as any[]
  2115. const result = ProviderTransform.message(msgs, model, {})
  2116. expect(result[0].providerOptions?.bedrock).toEqual({ someOption: "value" })
  2117. expect(result[0].providerOptions?.["my-bedrock"]).toBeUndefined()
  2118. })
  2119. })
  2120. describe("ProviderTransform.message - claude w/bedrock custom inference profile", () => {
  2121. test("adds cachePoint", () => {
  2122. const model = {
  2123. id: "amazon-bedrock/custom-claude-sonnet-4.5",
  2124. providerID: "amazon-bedrock",
  2125. api: {
  2126. id: "arn:aws:bedrock:xxx:yyy:application-inference-profile/zzz",
  2127. url: "https://api.test.com",
  2128. npm: "@ai-sdk/amazon-bedrock",
  2129. },
  2130. name: "Custom inference profile",
  2131. capabilities: {},
  2132. options: {},
  2133. headers: {},
  2134. } as any
  2135. const msgs = [
  2136. {
  2137. role: "user",
  2138. content: "Hello",
  2139. },
  2140. ] as any[]
  2141. const result = ProviderTransform.message(msgs, model, {})
  2142. expect(result[0].providerOptions?.bedrock).toEqual(
  2143. expect.objectContaining({
  2144. cachePoint: {
  2145. type: "default",
  2146. },
  2147. }),
  2148. )
  2149. })
  2150. })
  2151. describe("ProviderTransform.message - bedrock caching with non-bedrock providerID", () => {
  2152. test("applies cache options at message level when npm package is amazon-bedrock", () => {
  2153. const model = {
  2154. id: "aws/us.anthropic.claude-opus-4-6-v1",
  2155. providerID: "aws",
  2156. api: {
  2157. id: "us.anthropic.claude-opus-4-6-v1",
  2158. url: "https://bedrock-runtime.us-east-1.amazonaws.com",
  2159. npm: "@ai-sdk/amazon-bedrock",
  2160. },
  2161. name: "Claude Opus 4.6",
  2162. capabilities: {},
  2163. options: {},
  2164. headers: {},
  2165. } as any
  2166. const msgs = [
  2167. {
  2168. role: "system",
  2169. content: "You are a helpful assistant",
  2170. },
  2171. {
  2172. role: "user",
  2173. content: [{ type: "text", text: "Hello" }],
  2174. },
  2175. ] as any[]
  2176. const result = ProviderTransform.message(msgs, model, {}) as any[]
  2177. // Cache should be at the message level and not the content-part level
  2178. expect(result[0].providerOptions?.bedrock).toEqual({
  2179. cachePoint: { type: "default" },
  2180. })
  2181. expect(result[0].content).toBe("You are a helpful assistant")
  2182. })
  2183. })
  2184. describe("ProviderTransform.message - cache control on gateway", () => {
  2185. const createModel = (overrides: Partial<any> = {}) =>
  2186. ({
  2187. id: "anthropic/claude-sonnet-4",
  2188. providerID: "vercel",
  2189. api: {
  2190. id: "anthropic/claude-sonnet-4",
  2191. url: "https://ai-gateway.vercel.sh/v3/ai",
  2192. npm: "@ai-sdk/gateway",
  2193. },
  2194. name: "Claude Sonnet 4",
  2195. capabilities: {
  2196. temperature: true,
  2197. reasoning: true,
  2198. attachment: true,
  2199. toolcall: true,
  2200. input: { text: true, audio: false, image: true, video: false, pdf: true },
  2201. output: { text: true, audio: false, image: false, video: false, pdf: false },
  2202. interleaved: false,
  2203. },
  2204. cost: { input: 0.001, output: 0.002, cache: { read: 0.0001, write: 0.0002 } },
  2205. limit: { context: 200_000, output: 8192 },
  2206. status: "active",
  2207. options: {},
  2208. headers: {},
  2209. ...overrides,
  2210. }) as any
  2211. test("gateway does not set cache control for anthropic models", () => {
  2212. const model = createModel()
  2213. const msgs = [
  2214. {
  2215. role: "system",
  2216. content: "You are a helpful assistant",
  2217. },
  2218. {
  2219. role: "user",
  2220. content: "Hello",
  2221. },
  2222. ] as any[]
  2223. const result = ProviderTransform.message(msgs, model, {}) as any[]
  2224. expect(result[0].content).toBe("You are a helpful assistant")
  2225. expect(result[0].providerOptions).toBeUndefined()
  2226. })
  2227. test("non-gateway anthropic keeps existing cache control behavior", () => {
  2228. const model = createModel({
  2229. providerID: "anthropic",
  2230. api: {
  2231. id: "claude-sonnet-4",
  2232. url: "https://api.anthropic.com",
  2233. npm: "@ai-sdk/anthropic",
  2234. },
  2235. })
  2236. const msgs = [
  2237. {
  2238. role: "system",
  2239. content: "You are a helpful assistant",
  2240. },
  2241. {
  2242. role: "user",
  2243. content: "Hello",
  2244. },
  2245. ] as any[]
  2246. const result = ProviderTransform.message(msgs, model, {}) as any[]
  2247. expect(result[0].providerOptions).toEqual({
  2248. anthropic: {
  2249. cacheControl: {
  2250. type: "ephemeral",
  2251. },
  2252. },
  2253. openrouter: {
  2254. cacheControl: {
  2255. type: "ephemeral",
  2256. },
  2257. },
  2258. bedrock: {
  2259. cachePoint: {
  2260. type: "default",
  2261. },
  2262. },
  2263. openaiCompatible: {
  2264. cache_control: {
  2265. type: "ephemeral",
  2266. },
  2267. },
  2268. copilot: {
  2269. copilot_cache_control: {
  2270. type: "ephemeral",
  2271. },
  2272. },
  2273. alibaba: {
  2274. cacheControl: {
  2275. type: "ephemeral",
  2276. },
  2277. },
  2278. })
  2279. })
  2280. test("google-vertex-anthropic applies cache control", () => {
  2281. const model = createModel({
  2282. providerID: "google-vertex-anthropic",
  2283. api: {
  2284. id: "google-vertex-anthropic",
  2285. url: "https://us-central1-aiplatform.googleapis.com",
  2286. npm: "@ai-sdk/google-vertex/anthropic",
  2287. },
  2288. id: "claude-sonnet-4@20250514",
  2289. })
  2290. const msgs = [
  2291. {
  2292. role: "system",
  2293. content: "You are a helpful assistant",
  2294. },
  2295. {
  2296. role: "user",
  2297. content: "Hello",
  2298. },
  2299. ] as any[]
  2300. const result = ProviderTransform.message(msgs, model, {}) as any[]
  2301. expect(result[0].providerOptions).toEqual({
  2302. anthropic: {
  2303. cacheControl: {
  2304. type: "ephemeral",
  2305. },
  2306. },
  2307. openrouter: {
  2308. cacheControl: {
  2309. type: "ephemeral",
  2310. },
  2311. },
  2312. bedrock: {
  2313. cachePoint: {
  2314. type: "default",
  2315. },
  2316. },
  2317. openaiCompatible: {
  2318. cache_control: {
  2319. type: "ephemeral",
  2320. },
  2321. },
  2322. copilot: {
  2323. copilot_cache_control: {
  2324. type: "ephemeral",
  2325. },
  2326. },
  2327. alibaba: {
  2328. cacheControl: {
  2329. type: "ephemeral",
  2330. },
  2331. },
  2332. })
  2333. })
  2334. })
  2335. describe("ProviderTransform.temperature - Cohere North", () => {
  2336. test("defaults north-mini-code models to 1.0", () => {
  2337. expect(ProviderTransform.temperature({ id: "cohere/North-Mini-Code-1-0-latest" } as any)).toBe(1.0)
  2338. })
  2339. })
  2340. describe("ProviderTransform.variants", () => {
  2341. const createMockModel = (overrides: Partial<any> = {}): any => ({
  2342. id: "test/test-model",
  2343. providerID: "test",
  2344. api: {
  2345. id: "test-model",
  2346. url: "https://api.test.com",
  2347. npm: "@ai-sdk/openai",
  2348. },
  2349. name: "Test Model",
  2350. capabilities: {
  2351. temperature: true,
  2352. reasoning: true,
  2353. attachment: true,
  2354. toolcall: true,
  2355. input: { text: true, audio: false, image: true, video: false, pdf: false },
  2356. output: { text: true, audio: false, image: false, video: false, pdf: false },
  2357. interleaved: false,
  2358. },
  2359. cost: {
  2360. input: 0.001,
  2361. output: 0.002,
  2362. cache: { read: 0.0001, write: 0.0002 },
  2363. },
  2364. limit: {
  2365. context: 200_000,
  2366. output: 64_000,
  2367. },
  2368. status: "active",
  2369. options: {},
  2370. headers: {},
  2371. release_date: "2024-01-01",
  2372. ...overrides,
  2373. })
  2374. test("returns empty object when model has no reasoning capabilities", () => {
  2375. const model = createMockModel({
  2376. capabilities: { reasoning: false },
  2377. })
  2378. const result = ProviderTransform.variants(model)
  2379. expect(result).toEqual({})
  2380. })
  2381. test("deepseek returns empty object", () => {
  2382. const model = createMockModel({
  2383. id: "deepseek/deepseek-chat",
  2384. providerID: "deepseek",
  2385. api: {
  2386. id: "deepseek-chat",
  2387. url: "https://api.deepseek.com",
  2388. npm: "@ai-sdk/openai-compatible",
  2389. },
  2390. })
  2391. const result = ProviderTransform.variants(model)
  2392. expect(result).toEqual({})
  2393. })
  2394. test("minimax returns empty object", () => {
  2395. const model = createMockModel({
  2396. id: "minimax/minimax-model",
  2397. providerID: "minimax",
  2398. api: {
  2399. id: "minimax-model",
  2400. url: "https://api.minimax.com",
  2401. npm: "@ai-sdk/openai-compatible",
  2402. },
  2403. })
  2404. const result = ProviderTransform.variants(model)
  2405. expect(result).toEqual({})
  2406. })
  2407. test("minimax m3 using anthropic returns thinking toggles", () => {
  2408. const model = createMockModel({
  2409. id: "minimax/minimax-m3",
  2410. providerID: "minimax",
  2411. api: {
  2412. id: "MiniMax-M3",
  2413. url: "https://api.minimax.com/anthropic/v1",
  2414. npm: "@ai-sdk/anthropic",
  2415. },
  2416. })
  2417. const result = ProviderTransform.variants(model)
  2418. expect(result).toEqual({
  2419. none: { thinking: { type: "disabled" } },
  2420. thinking: { thinking: { type: "adaptive" } },
  2421. })
  2422. })
  2423. test("minimax m3 using openai-compatible returns thinking toggles", () => {
  2424. const model = createMockModel({
  2425. id: "minimax/minimax-m3",
  2426. providerID: "minimax",
  2427. api: {
  2428. id: "minimax-m3",
  2429. url: "https://api.minimax.com/v1",
  2430. npm: "@ai-sdk/openai-compatible",
  2431. },
  2432. })
  2433. expect(ProviderTransform.variants(model)).toEqual({
  2434. none: { thinking: { type: "disabled" } },
  2435. thinking: { thinking: { type: "adaptive" } },
  2436. })
  2437. })
  2438. test("glm returns empty object", () => {
  2439. const model = createMockModel({
  2440. id: "glm/glm-4",
  2441. providerID: "glm",
  2442. api: {
  2443. id: "glm-4",
  2444. url: "https://api.glm.com",
  2445. npm: "@ai-sdk/openai-compatible",
  2446. },
  2447. })
  2448. const result = ProviderTransform.variants(model)
  2449. expect(result).toEqual({})
  2450. })
  2451. test("mistral models with reasoning support return variants", () => {
  2452. const model = createMockModel({
  2453. id: "mistral/mistral-small-latest",
  2454. providerID: "mistral",
  2455. api: {
  2456. id: "mistral-small-latest",
  2457. url: "https://api.mistral.com",
  2458. npm: "@ai-sdk/mistral",
  2459. },
  2460. capabilities: { reasoning: true },
  2461. })
  2462. const result = ProviderTransform.variants(model)
  2463. expect(result).toEqual({
  2464. high: { reasoningEffort: "high" },
  2465. })
  2466. })
  2467. test("mistral-medium-3.5 with reasoning returns variants", () => {
  2468. const model = createMockModel({
  2469. id: "mistral/mistral-medium-3.5",
  2470. providerID: "mistral",
  2471. api: {
  2472. id: "mistral-medium-3.5",
  2473. url: "https://api.mistral.com",
  2474. npm: "@ai-sdk/mistral",
  2475. },
  2476. capabilities: { reasoning: true },
  2477. })
  2478. const result = ProviderTransform.variants(model)
  2479. expect(result).toEqual({
  2480. high: { reasoningEffort: "high" },
  2481. })
  2482. })
  2483. test("mistral without reasoning returns empty object", () => {
  2484. const model = createMockModel({
  2485. id: "mistral/mistral-large",
  2486. providerID: "mistral",
  2487. api: {
  2488. id: "mistral-large-latest",
  2489. url: "https://api.mistral.com",
  2490. npm: "@ai-sdk/mistral",
  2491. },
  2492. capabilities: { reasoning: false },
  2493. })
  2494. const result = ProviderTransform.variants(model)
  2495. expect(result).toEqual({})
  2496. })
  2497. test("mistral large with reasoning returns empty object (only small supports reasoning)", () => {
  2498. const model = createMockModel({
  2499. id: "mistral/mistral-large",
  2500. providerID: "mistral",
  2501. api: {
  2502. id: "mistral-large-latest",
  2503. url: "https://api.mistral.com",
  2504. npm: "@ai-sdk/mistral",
  2505. },
  2506. capabilities: { reasoning: true },
  2507. })
  2508. const result = ProviderTransform.variants(model)
  2509. expect(result).toEqual({})
  2510. })
  2511. describe("@openrouter/ai-sdk-provider", () => {
  2512. test("returns widely supported efforts for other reasoning models", () => {
  2513. const model = createMockModel({
  2514. id: "openrouter/test-model",
  2515. providerID: "openrouter",
  2516. api: {
  2517. id: "test-model",
  2518. url: "https://openrouter.ai",
  2519. npm: "@openrouter/ai-sdk-provider",
  2520. },
  2521. })
  2522. const result = ProviderTransform.variants(model)
  2523. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  2524. expect(result.medium).toEqual({ reasoning: { effort: "medium" } })
  2525. })
  2526. test("gpt models return OPENAI_EFFORTS with reasoning", () => {
  2527. const model = createMockModel({
  2528. id: "openrouter/gpt-4",
  2529. providerID: "openrouter",
  2530. api: {
  2531. id: "gpt-4",
  2532. url: "https://openrouter.ai",
  2533. npm: "@openrouter/ai-sdk-provider",
  2534. },
  2535. })
  2536. const result = ProviderTransform.variants(model)
  2537. expect(Object.keys(result)).toEqual(["none", "minimal", "low", "medium", "high", "xhigh"])
  2538. expect(result.low).toEqual({ reasoning: { effort: "low" } })
  2539. expect(result.high).toEqual({ reasoning: { effort: "high" } })
  2540. })
  2541. for (const testCase of [
  2542. { id: "openai/o3-mini", efforts: ["none", "minimal", "low", "medium", "high", "xhigh"] },
  2543. { id: "openai/gpt-5.4", efforts: ["none", "low", "medium", "high", "xhigh"] },
  2544. { id: "openai/gpt-5-pro", efforts: ["high"] },
  2545. { id: "openai/gpt-5.5-pro", efforts: ["medium", "high", "xhigh"] },
  2546. { id: "openai/gpt-5.2-codex", efforts: ["low", "medium", "high", "xhigh"] },
  2547. { id: "openai/gpt-5.3-codex", efforts: ["none", "low", "medium", "high", "xhigh"] },
  2548. { id: "openai/gpt-5.3-codex-max", efforts: ["none", "low", "medium", "high", "xhigh"] },
  2549. { id: "openai/gpt-5-chat-latest", efforts: [] },
  2550. { id: "openai/gpt-5.2-chat-latest", efforts: ["medium"] },
  2551. ]) {
  2552. test(`${testCase.id} returns supported OpenAI reasoning efforts`, () => {
  2553. const result = ProviderTransform.variants(
  2554. createMockModel({
  2555. id: testCase.id,
  2556. providerID: "openrouter",
  2557. api: {
  2558. id: testCase.id,
  2559. url: "https://openrouter.ai",
  2560. npm: "@openrouter/ai-sdk-provider",
  2561. },
  2562. }),
  2563. )
  2564. expect(Object.keys(result)).toEqual(testCase.efforts)
  2565. })
  2566. }
  2567. test("gemini-3 returns widely supported efforts with reasoning", () => {
  2568. const model = createMockModel({
  2569. id: "openrouter/gemini-3-5-pro",
  2570. providerID: "openrouter",
  2571. api: {
  2572. id: "gemini-3-5-pro",
  2573. url: "https://openrouter.ai",
  2574. npm: "@openrouter/ai-sdk-provider",
  2575. },
  2576. })
  2577. const result = ProviderTransform.variants(model)
  2578. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  2579. })
  2580. test("grok-4 returns empty object", () => {
  2581. const model = createMockModel({
  2582. id: "openrouter/grok-4",
  2583. providerID: "openrouter",
  2584. api: {
  2585. id: "grok-4",
  2586. url: "https://openrouter.ai",
  2587. npm: "@openrouter/ai-sdk-provider",
  2588. },
  2589. })
  2590. const result = ProviderTransform.variants(model)
  2591. expect(result).toEqual({})
  2592. })
  2593. test("grok-3-mini returns low and high with reasoning", () => {
  2594. const model = createMockModel({
  2595. id: "openrouter/grok-3-mini",
  2596. providerID: "openrouter",
  2597. api: {
  2598. id: "grok-3-mini",
  2599. url: "https://openrouter.ai",
  2600. npm: "@openrouter/ai-sdk-provider",
  2601. },
  2602. })
  2603. const result = ProviderTransform.variants(model)
  2604. expect(Object.keys(result)).toEqual(["low", "high"])
  2605. expect(result.low).toEqual({ reasoning: { effort: "low" } })
  2606. expect(result.high).toEqual({ reasoning: { effort: "high" } })
  2607. })
  2608. })
  2609. describe("@ai-sdk/gateway", () => {
  2610. test("anthropic sonnet 4.6 models return adaptive thinking options", () => {
  2611. const model = createMockModel({
  2612. id: "anthropic/claude-sonnet-4-6",
  2613. providerID: "gateway",
  2614. api: {
  2615. id: "anthropic/claude-sonnet-4-6",
  2616. url: "https://gateway.ai",
  2617. npm: "@ai-sdk/gateway",
  2618. },
  2619. })
  2620. const result = ProviderTransform.variants(model)
  2621. expect(Object.keys(result)).toEqual(["low", "medium", "high", "max"])
  2622. expect(result.medium).toEqual({
  2623. thinking: {
  2624. type: "adaptive",
  2625. },
  2626. effort: "medium",
  2627. })
  2628. })
  2629. test("anthropic sonnet 4.6 dot-format models return adaptive thinking options", () => {
  2630. const model = createMockModel({
  2631. id: "anthropic/claude-sonnet-4-6",
  2632. providerID: "gateway",
  2633. api: {
  2634. id: "anthropic/claude-sonnet-4.6",
  2635. url: "https://gateway.ai",
  2636. npm: "@ai-sdk/gateway",
  2637. },
  2638. })
  2639. const result = ProviderTransform.variants(model)
  2640. expect(Object.keys(result)).toEqual(["low", "medium", "high", "max"])
  2641. expect(result.medium).toEqual({
  2642. thinking: {
  2643. type: "adaptive",
  2644. },
  2645. effort: "medium",
  2646. })
  2647. })
  2648. test("anthropic opus 4.6 dot-format models return adaptive thinking options", () => {
  2649. const model = createMockModel({
  2650. id: "anthropic/claude-opus-4-6",
  2651. providerID: "gateway",
  2652. api: {
  2653. id: "anthropic/claude-opus-4.6",
  2654. url: "https://gateway.ai",
  2655. npm: "@ai-sdk/gateway",
  2656. },
  2657. })
  2658. const result = ProviderTransform.variants(model)
  2659. expect(Object.keys(result)).toEqual(["low", "medium", "high", "max"])
  2660. expect(result.high).toEqual({
  2661. thinking: {
  2662. type: "adaptive",
  2663. },
  2664. effort: "high",
  2665. })
  2666. })
  2667. test("anthropic opus 4.7 models return adaptive thinking options with xhigh", () => {
  2668. const model = createMockModel({
  2669. id: "anthropic/claude-opus-4-7",
  2670. providerID: "gateway",
  2671. api: {
  2672. id: "anthropic/claude-opus-4-7",
  2673. url: "https://gateway.ai",
  2674. npm: "@ai-sdk/gateway",
  2675. },
  2676. })
  2677. const result = ProviderTransform.variants(model)
  2678. expect(Object.keys(result)).toEqual(["low", "medium", "high", "xhigh", "max"])
  2679. expect(result.xhigh).toEqual({
  2680. thinking: {
  2681. type: "adaptive",
  2682. display: "summarized",
  2683. },
  2684. effort: "xhigh",
  2685. })
  2686. expect(result.max).toEqual({
  2687. thinking: {
  2688. type: "adaptive",
  2689. display: "summarized",
  2690. },
  2691. effort: "max",
  2692. })
  2693. })
  2694. test("anthropic opus 4.7 dot-format models return adaptive thinking options with xhigh", () => {
  2695. const model = createMockModel({
  2696. id: "anthropic/claude-opus-4-7",
  2697. providerID: "gateway",
  2698. api: {
  2699. id: "anthropic/claude-opus-4.7",
  2700. url: "https://gateway.ai",
  2701. npm: "@ai-sdk/gateway",
  2702. },
  2703. })
  2704. const result = ProviderTransform.variants(model)
  2705. expect(Object.keys(result)).toEqual(["low", "medium", "high", "xhigh", "max"])
  2706. })
  2707. test("anthropic opus 4.8 forces display summarized for adaptive reasoning", () => {
  2708. const model = createMockModel({
  2709. id: "anthropic/claude-opus-4-8",
  2710. providerID: "gateway",
  2711. api: {
  2712. id: "anthropic/claude-opus-4-8",
  2713. url: "https://gateway.ai",
  2714. npm: "@ai-sdk/gateway",
  2715. },
  2716. })
  2717. const result = ProviderTransform.variants(model)
  2718. expect(Object.keys(result)).toEqual(["low", "medium", "high", "xhigh", "max"])
  2719. expect(result.high).toEqual({
  2720. thinking: {
  2721. type: "adaptive",
  2722. display: "summarized",
  2723. },
  2724. effort: "high",
  2725. })
  2726. })
  2727. test("anthropic opus 4.6 omits display so it keeps the summarized default", () => {
  2728. const model = createMockModel({
  2729. id: "anthropic/claude-opus-4-6",
  2730. providerID: "gateway",
  2731. api: {
  2732. id: "anthropic/claude-opus-4-6",
  2733. url: "https://gateway.ai",
  2734. npm: "@ai-sdk/gateway",
  2735. },
  2736. })
  2737. const result = ProviderTransform.variants(model)
  2738. expect(Object.keys(result)).toEqual(["low", "medium", "high", "max"])
  2739. expect(result.high).toEqual({
  2740. thinking: {
  2741. type: "adaptive",
  2742. },
  2743. effort: "high",
  2744. })
  2745. })
  2746. test("anthropic models return anthropic thinking options", () => {
  2747. const model = createMockModel({
  2748. id: "anthropic/claude-sonnet-4",
  2749. providerID: "gateway",
  2750. api: {
  2751. id: "anthropic/claude-sonnet-4",
  2752. url: "https://gateway.ai",
  2753. npm: "@ai-sdk/gateway",
  2754. },
  2755. })
  2756. const result = ProviderTransform.variants(model)
  2757. expect(Object.keys(result)).toEqual(["high", "max"])
  2758. expect(result.high).toEqual({
  2759. thinking: {
  2760. type: "enabled",
  2761. budgetTokens: 16000,
  2762. },
  2763. })
  2764. expect(result.max).toEqual({
  2765. thinking: {
  2766. type: "enabled",
  2767. budgetTokens: 31999,
  2768. },
  2769. })
  2770. })
  2771. test("returns OPENAI_EFFORTS with reasoningEffort", () => {
  2772. const model = createMockModel({
  2773. id: "gateway/gateway-model",
  2774. providerID: "gateway",
  2775. api: {
  2776. id: "gateway-model",
  2777. url: "https://gateway.ai",
  2778. npm: "@ai-sdk/gateway",
  2779. },
  2780. })
  2781. const result = ProviderTransform.variants(model)
  2782. expect(Object.keys(result)).toEqual(["none", "minimal", "low", "medium", "high", "xhigh"])
  2783. expect(result.low).toEqual({ reasoningEffort: "low" })
  2784. expect(result.high).toEqual({ reasoningEffort: "high" })
  2785. })
  2786. for (const testCase of [
  2787. { id: "openai/gpt-5-5", efforts: ["none", "low", "medium", "high", "xhigh"] },
  2788. { id: "openai/gpt-5-pro", efforts: ["high"] },
  2789. { id: "openai/gpt-5-5-pro", efforts: ["medium", "high", "xhigh"] },
  2790. { id: "openai/gpt-5-2-codex", efforts: ["low", "medium", "high", "xhigh"] },
  2791. { id: "openai/gpt-5-3-codex", efforts: ["none", "low", "medium", "high", "xhigh"] },
  2792. { id: "openai/gpt-5-3-codex-max", efforts: ["none", "low", "medium", "high", "xhigh"] },
  2793. { id: "openai/gpt-5-chat-latest", efforts: [] },
  2794. { id: "openai/gpt-5-2-chat-latest", efforts: ["medium"] },
  2795. ]) {
  2796. test(`${testCase.id} returns supported OpenAI reasoning efforts`, () => {
  2797. const result = ProviderTransform.variants(
  2798. createMockModel({
  2799. id: testCase.id,
  2800. providerID: "gateway",
  2801. api: {
  2802. id: testCase.id,
  2803. url: "https://gateway.ai",
  2804. npm: "@ai-sdk/gateway",
  2805. },
  2806. }),
  2807. )
  2808. expect(Object.keys(result)).toEqual(testCase.efforts)
  2809. })
  2810. }
  2811. })
  2812. describe("@ai-sdk/github-copilot", () => {
  2813. test("standard models return low, medium, high", () => {
  2814. const model = createMockModel({
  2815. id: "gpt-4.5",
  2816. providerID: "github-copilot",
  2817. api: {
  2818. id: "gpt-4.5",
  2819. url: "https://api.githubcopilot.com",
  2820. npm: "@ai-sdk/github-copilot",
  2821. },
  2822. })
  2823. const result = ProviderTransform.variants(model)
  2824. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  2825. expect(result.low).toEqual({
  2826. reasoningEffort: "low",
  2827. reasoningSummary: "auto",
  2828. include: ["reasoning.encrypted_content"],
  2829. })
  2830. })
  2831. test("gpt-5.1-codex-max includes xhigh", () => {
  2832. const model = createMockModel({
  2833. id: "gpt-5.1-codex-max",
  2834. providerID: "github-copilot",
  2835. api: {
  2836. id: "gpt-5.1-codex-max",
  2837. url: "https://api.githubcopilot.com",
  2838. npm: "@ai-sdk/github-copilot",
  2839. },
  2840. })
  2841. const result = ProviderTransform.variants(model)
  2842. expect(Object.keys(result)).toEqual(["low", "medium", "high", "xhigh"])
  2843. })
  2844. test("gpt-5.1-codex-mini does not include xhigh", () => {
  2845. const model = createMockModel({
  2846. id: "gpt-5.1-codex-mini",
  2847. providerID: "github-copilot",
  2848. api: {
  2849. id: "gpt-5.1-codex-mini",
  2850. url: "https://api.githubcopilot.com",
  2851. npm: "@ai-sdk/github-copilot",
  2852. },
  2853. })
  2854. const result = ProviderTransform.variants(model)
  2855. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  2856. })
  2857. test("gpt-5.1-codex does not include xhigh", () => {
  2858. const model = createMockModel({
  2859. id: "gpt-5.1-codex",
  2860. providerID: "github-copilot",
  2861. api: {
  2862. id: "gpt-5.1-codex",
  2863. url: "https://api.githubcopilot.com",
  2864. npm: "@ai-sdk/github-copilot",
  2865. },
  2866. })
  2867. const result = ProviderTransform.variants(model)
  2868. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  2869. })
  2870. test("gpt-5.2 includes xhigh", () => {
  2871. const model = createMockModel({
  2872. id: "gpt-5.2",
  2873. providerID: "github-copilot",
  2874. api: {
  2875. id: "gpt-5.2",
  2876. url: "https://api.githubcopilot.com",
  2877. npm: "@ai-sdk/github-copilot",
  2878. },
  2879. })
  2880. const result = ProviderTransform.variants(model)
  2881. expect(Object.keys(result)).toEqual(["low", "medium", "high", "xhigh"])
  2882. expect(result.xhigh).toEqual({
  2883. reasoningEffort: "xhigh",
  2884. reasoningSummary: "auto",
  2885. include: ["reasoning.encrypted_content"],
  2886. })
  2887. })
  2888. test("gpt-5.2-codex includes xhigh", () => {
  2889. const model = createMockModel({
  2890. id: "gpt-5.2-codex",
  2891. providerID: "github-copilot",
  2892. api: {
  2893. id: "gpt-5.2-codex",
  2894. url: "https://api.githubcopilot.com",
  2895. npm: "@ai-sdk/github-copilot",
  2896. },
  2897. })
  2898. const result = ProviderTransform.variants(model)
  2899. expect(Object.keys(result)).toEqual(["low", "medium", "high", "xhigh"])
  2900. })
  2901. test("gpt-5.3-codex includes xhigh", () => {
  2902. const model = createMockModel({
  2903. id: "gpt-5.3-codex",
  2904. providerID: "github-copilot",
  2905. api: {
  2906. id: "gpt-5.3-codex",
  2907. url: "https://api.githubcopilot.com",
  2908. npm: "@ai-sdk/github-copilot",
  2909. },
  2910. })
  2911. const result = ProviderTransform.variants(model)
  2912. expect(Object.keys(result)).toEqual(["low", "medium", "high", "xhigh"])
  2913. })
  2914. test("gpt-5.4 includes xhigh", () => {
  2915. const model = createMockModel({
  2916. id: "gpt-5.4",
  2917. release_date: "2026-03-05",
  2918. providerID: "github-copilot",
  2919. api: {
  2920. id: "gpt-5.4",
  2921. url: "https://api.githubcopilot.com",
  2922. npm: "@ai-sdk/github-copilot",
  2923. },
  2924. })
  2925. const result = ProviderTransform.variants(model)
  2926. expect(Object.keys(result)).toEqual(["low", "medium", "high", "xhigh"])
  2927. })
  2928. })
  2929. describe("@ai-sdk/cerebras", () => {
  2930. test("returns WIDELY_SUPPORTED_EFFORTS with reasoningEffort", () => {
  2931. const model = createMockModel({
  2932. id: "cerebras/llama-4",
  2933. providerID: "cerebras",
  2934. api: {
  2935. id: "llama-4-sc",
  2936. url: "https://api.cerebras.ai",
  2937. npm: "@ai-sdk/cerebras",
  2938. },
  2939. })
  2940. const result = ProviderTransform.variants(model)
  2941. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  2942. expect(result.low).toEqual({ reasoningEffort: "low" })
  2943. expect(result.high).toEqual({ reasoningEffort: "high" })
  2944. })
  2945. })
  2946. describe("@ai-sdk/togetherai", () => {
  2947. test("returns WIDELY_SUPPORTED_EFFORTS with reasoningEffort", () => {
  2948. const model = createMockModel({
  2949. id: "togetherai/llama-4",
  2950. providerID: "togetherai",
  2951. api: {
  2952. id: "llama-4-sc",
  2953. url: "https://api.togetherai.com",
  2954. npm: "@ai-sdk/togetherai",
  2955. },
  2956. })
  2957. const result = ProviderTransform.variants(model)
  2958. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  2959. expect(result.low).toEqual({ reasoningEffort: "low" })
  2960. expect(result.high).toEqual({ reasoningEffort: "high" })
  2961. })
  2962. })
  2963. describe("@ai-sdk/xai", () => {
  2964. test("grok-3 returns empty object", () => {
  2965. const model = createMockModel({
  2966. id: "xai/grok-3",
  2967. providerID: "xai",
  2968. api: {
  2969. id: "grok-3",
  2970. url: "https://api.x.ai",
  2971. npm: "@ai-sdk/xai",
  2972. },
  2973. })
  2974. const result = ProviderTransform.variants(model)
  2975. expect(result).toEqual({})
  2976. })
  2977. test("grok-3-mini returns low and high with reasoningEffort", () => {
  2978. const model = createMockModel({
  2979. id: "xai/grok-3-mini",
  2980. providerID: "xai",
  2981. api: {
  2982. id: "grok-3-mini",
  2983. url: "https://api.x.ai",
  2984. npm: "@ai-sdk/xai",
  2985. },
  2986. })
  2987. const result = ProviderTransform.variants(model)
  2988. expect(Object.keys(result)).toEqual(["low", "high"])
  2989. expect(result.low).toEqual({ reasoningEffort: "low" })
  2990. expect(result.high).toEqual({ reasoningEffort: "high" })
  2991. })
  2992. })
  2993. describe("@ai-sdk/deepinfra", () => {
  2994. test("returns WIDELY_SUPPORTED_EFFORTS with reasoningEffort", () => {
  2995. const model = createMockModel({
  2996. id: "deepinfra/llama-4",
  2997. providerID: "deepinfra",
  2998. api: {
  2999. id: "llama-4-sc",
  3000. url: "https://api.deepinfra.com",
  3001. npm: "@ai-sdk/deepinfra",
  3002. },
  3003. })
  3004. const result = ProviderTransform.variants(model)
  3005. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  3006. expect(result.low).toEqual({ reasoningEffort: "low" })
  3007. expect(result.high).toEqual({ reasoningEffort: "high" })
  3008. })
  3009. })
  3010. describe("@ai-sdk/openai-compatible", () => {
  3011. test("returns WIDELY_SUPPORTED_EFFORTS with reasoningEffort", () => {
  3012. const model = createMockModel({
  3013. id: "custom-provider/custom-model",
  3014. providerID: "custom-provider",
  3015. api: {
  3016. id: "custom-model",
  3017. url: "https://api.custom.com",
  3018. npm: "@ai-sdk/openai-compatible",
  3019. },
  3020. })
  3021. const result = ProviderTransform.variants(model)
  3022. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  3023. expect(result.low).toEqual({ reasoningEffort: "low" })
  3024. expect(result.high).toEqual({ reasoningEffort: "high" })
  3025. })
  3026. test("north-mini-code-1-0 returns only none and high", () => {
  3027. const model = createMockModel({
  3028. id: "cohere/north-mini-code-1-0",
  3029. providerID: "cohere",
  3030. api: {
  3031. id: "North-Mini-Code-1-0-latest",
  3032. url: "https://api.cohere.com/compatibility/v1",
  3033. npm: "@ai-sdk/openai-compatible",
  3034. },
  3035. })
  3036. const result = ProviderTransform.variants(model)
  3037. expect(result).toEqual({
  3038. none: { reasoningEffort: "none" },
  3039. high: { reasoningEffort: "high" },
  3040. })
  3041. })
  3042. })
  3043. describe("@ai-sdk/azure", () => {
  3044. test("o1-mini returns empty object", () => {
  3045. const model = createMockModel({
  3046. id: "o1-mini",
  3047. providerID: "azure",
  3048. api: {
  3049. id: "o1-mini",
  3050. url: "https://azure.com",
  3051. npm: "@ai-sdk/azure",
  3052. },
  3053. })
  3054. const result = ProviderTransform.variants(model)
  3055. expect(result).toEqual({})
  3056. })
  3057. test("standard azure models return custom efforts with reasoningSummary", () => {
  3058. const model = createMockModel({
  3059. id: "o1",
  3060. providerID: "azure",
  3061. api: {
  3062. id: "o1",
  3063. url: "https://azure.com",
  3064. npm: "@ai-sdk/azure",
  3065. },
  3066. })
  3067. const result = ProviderTransform.variants(model)
  3068. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  3069. expect(result.low).toEqual({
  3070. reasoningEffort: "low",
  3071. reasoningSummary: "auto",
  3072. include: ["reasoning.encrypted_content"],
  3073. })
  3074. })
  3075. test("gpt-5 adds minimal effort", () => {
  3076. const model = createMockModel({
  3077. id: "gpt-5",
  3078. providerID: "azure",
  3079. api: {
  3080. id: "gpt-5",
  3081. url: "https://azure.com",
  3082. npm: "@ai-sdk/azure",
  3083. },
  3084. })
  3085. const result = ProviderTransform.variants(model)
  3086. expect(Object.keys(result)).toEqual(["minimal", "low", "medium", "high"])
  3087. })
  3088. for (const testCase of [
  3089. { id: "gpt-5-1", efforts: ["none", "low", "medium", "high"] },
  3090. { id: "gpt-5-4", efforts: ["none", "low", "medium", "high", "xhigh"] },
  3091. { id: "gpt-5.4", efforts: ["none", "low", "medium", "high", "xhigh"] },
  3092. { id: "gpt-5-5", efforts: ["none", "low", "medium", "high", "xhigh"] },
  3093. ]) {
  3094. test(`${testCase.id} returns supported Azure reasoning efforts`, () => {
  3095. const result = ProviderTransform.variants(
  3096. createMockModel({
  3097. id: testCase.id,
  3098. providerID: "azure",
  3099. api: {
  3100. id: testCase.id,
  3101. url: "https://azure.com",
  3102. npm: "@ai-sdk/azure",
  3103. },
  3104. }),
  3105. )
  3106. expect(Object.keys(result)).toEqual(testCase.efforts)
  3107. })
  3108. }
  3109. })
  3110. describe("@ai-sdk/openai", () => {
  3111. test("gpt-5-pro returns only high effort", () => {
  3112. const model = createMockModel({
  3113. id: "gpt-5-pro",
  3114. providerID: "openai",
  3115. api: {
  3116. id: "gpt-5-pro",
  3117. url: "https://api.openai.com",
  3118. npm: "@ai-sdk/openai",
  3119. },
  3120. })
  3121. const result = ProviderTransform.variants(model)
  3122. expect(Object.keys(result)).toEqual(["high"])
  3123. })
  3124. test("standard openai models return custom efforts with reasoningSummary", () => {
  3125. const model = createMockModel({
  3126. id: "gpt-5",
  3127. providerID: "openai",
  3128. api: {
  3129. id: "gpt-5",
  3130. url: "https://api.openai.com",
  3131. npm: "@ai-sdk/openai",
  3132. },
  3133. release_date: "2024-06-01",
  3134. })
  3135. const result = ProviderTransform.variants(model)
  3136. expect(Object.keys(result)).toEqual(["minimal", "low", "medium", "high"])
  3137. expect(result.low).toEqual({
  3138. reasoningEffort: "low",
  3139. reasoningSummary: "auto",
  3140. include: ["reasoning.encrypted_content"],
  3141. })
  3142. })
  3143. test("models after 2025-11-13 include 'none' effort", () => {
  3144. const model = createMockModel({
  3145. id: "gpt-5-nano",
  3146. providerID: "openai",
  3147. api: {
  3148. id: "gpt-5-nano",
  3149. url: "https://api.openai.com",
  3150. npm: "@ai-sdk/openai",
  3151. },
  3152. release_date: "2025-11-14",
  3153. })
  3154. const result = ProviderTransform.variants(model)
  3155. expect(Object.keys(result)).toEqual(["none", "minimal", "low", "medium", "high"])
  3156. })
  3157. test("models after 2025-12-04 include 'xhigh' effort", () => {
  3158. const model = createMockModel({
  3159. id: "openai/gpt-5-reasoning",
  3160. providerID: "openai",
  3161. api: {
  3162. id: "gpt-5-reasoning",
  3163. url: "https://api.openai.com",
  3164. npm: "@ai-sdk/openai",
  3165. },
  3166. release_date: "2025-12-05",
  3167. })
  3168. const result = ProviderTransform.variants(model)
  3169. expect(Object.keys(result)).toEqual(["none", "minimal", "low", "medium", "high", "xhigh"])
  3170. })
  3171. for (const testCase of [
  3172. { id: "o1", releaseDate: "2024-12-17", efforts: ["low", "medium", "high"] },
  3173. { id: "o1-pro", releaseDate: "2025-03-19", efforts: ["low", "medium", "high"] },
  3174. { id: "o3", releaseDate: "2025-04-16", efforts: ["low", "medium", "high"] },
  3175. { id: "o3-mini", releaseDate: "2025-01-31", efforts: ["low", "medium", "high"] },
  3176. { id: "o3-pro", releaseDate: "2025-06-10", efforts: ["low", "medium", "high"] },
  3177. { id: "o4-mini", releaseDate: "2025-04-16", efforts: ["low", "medium", "high"] },
  3178. { id: "o3-deep-research", releaseDate: "2025-06-26", efforts: ["medium"] },
  3179. { id: "o4-mini-deep-research", releaseDate: "2025-06-26", efforts: ["medium"] },
  3180. { id: "gpt-5.1", releaseDate: "2025-11-13", efforts: ["none", "low", "medium", "high"] },
  3181. { id: "gpt-5.4", releaseDate: "2026-03-05", efforts: ["none", "low", "medium", "high", "xhigh"] },
  3182. {
  3183. id: "gpt-5.5",
  3184. modelID: "gpt-5-5",
  3185. releaseDate: "2026-04-23",
  3186. efforts: ["none", "low", "medium", "high", "xhigh"],
  3187. },
  3188. { id: "gpt-5.4-pro", releaseDate: "2026-03-05", efforts: ["medium", "high", "xhigh"] },
  3189. { id: "gpt-5.5-pro", releaseDate: "2026-04-23", efforts: ["medium", "high", "xhigh"] },
  3190. { id: "gpt-5-codex", releaseDate: "2025-09-23", efforts: ["low", "medium", "high"] },
  3191. { id: "gpt-5.1-codex", releaseDate: "2025-11-13", efforts: ["low", "medium", "high"] },
  3192. { id: "gpt-5.1-codex-max", releaseDate: "2025-11-13", efforts: ["low", "medium", "high", "xhigh"] },
  3193. { id: "gpt-5.2-codex", releaseDate: "2025-12-11", efforts: ["low", "medium", "high", "xhigh"] },
  3194. { id: "gpt-5.3-codex", releaseDate: "2026-01-22", efforts: ["none", "low", "medium", "high", "xhigh"] },
  3195. { id: "gpt-5.3-codex-max", releaseDate: "2026-01-22", efforts: ["none", "low", "medium", "high", "xhigh"] },
  3196. { id: "gpt-5-chat-latest", releaseDate: "2025-08-07", efforts: [] },
  3197. { id: "gpt-5.1-chat-latest", releaseDate: "2025-11-13", efforts: ["medium"] },
  3198. { id: "gpt-5.2-chat-latest", releaseDate: "2025-12-11", efforts: ["medium"] },
  3199. ]) {
  3200. test(`${testCase.id} returns supported reasoning efforts`, () => {
  3201. const result = ProviderTransform.variants(
  3202. createMockModel({
  3203. id: testCase.modelID ?? testCase.id,
  3204. providerID: "openai",
  3205. api: {
  3206. id: testCase.id,
  3207. url: "https://api.openai.com",
  3208. npm: "@ai-sdk/openai",
  3209. },
  3210. release_date: testCase.releaseDate,
  3211. }),
  3212. )
  3213. expect(Object.keys(result)).toEqual(testCase.efforts)
  3214. })
  3215. }
  3216. test("gpt-50 (lookalike) does not get gpt-5 family treatment", () => {
  3217. const model = createMockModel({
  3218. id: "gpt-50",
  3219. providerID: "openai",
  3220. api: {
  3221. id: "gpt-50",
  3222. url: "https://api.openai.com",
  3223. npm: "@ai-sdk/openai",
  3224. },
  3225. release_date: "2024-01-01",
  3226. })
  3227. const result = ProviderTransform.variants(model)
  3228. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  3229. })
  3230. })
  3231. describe("@ai-sdk/amazon-bedrock/mantle", () => {
  3232. test("gpt-5.5 returns OpenAI-style reasoning variants", () => {
  3233. const model = createMockModel({
  3234. id: "openai.gpt-5.5",
  3235. providerID: "amazon-bedrock",
  3236. api: {
  3237. id: "openai.gpt-5.5",
  3238. url: "https://bedrock-mantle.us-east-2.api.aws/openai/v1",
  3239. npm: "@ai-sdk/amazon-bedrock/mantle",
  3240. },
  3241. release_date: "2026-04-23",
  3242. })
  3243. const result = ProviderTransform.variants(model)
  3244. expect(Object.keys(result)).toEqual(["none", "low", "medium", "high", "xhigh"])
  3245. expect(result.medium).toEqual({
  3246. reasoningEffort: "medium",
  3247. reasoningSummary: "auto",
  3248. include: ["reasoning.encrypted_content"],
  3249. })
  3250. })
  3251. })
  3252. describe("@ai-sdk/anthropic", () => {
  3253. for (const testCase of [
  3254. {
  3255. name: "opus 4.5",
  3256. apiIds: ["claude-opus-4-5-20251101", "claude-opus-4.5-20251101"],
  3257. efforts: ["low", "medium", "high"],
  3258. expectedHigh: { effort: "high" },
  3259. },
  3260. {
  3261. name: "sonnet 4.6",
  3262. apiIds: ["claude-sonnet-4-6", "claude-sonnet-4.6"],
  3263. efforts: ["low", "medium", "high", "max"],
  3264. expectedHigh: { thinking: { type: "adaptive" }, effort: "high" },
  3265. },
  3266. {
  3267. name: "opus 4.6",
  3268. apiIds: ["claude-opus-4-6", "claude-opus-4.6"],
  3269. efforts: ["low", "medium", "high", "max"],
  3270. expectedHigh: { thinking: { type: "adaptive" }, effort: "high" },
  3271. },
  3272. {
  3273. name: "opus 4.7",
  3274. apiIds: ["claude-opus-4-7", "claude-opus-4.7"],
  3275. efforts: ["low", "medium", "high", "xhigh", "max"],
  3276. expectedHigh: { thinking: { type: "adaptive", display: "summarized" }, effort: "high" },
  3277. },
  3278. {
  3279. name: "opus 4.8",
  3280. apiIds: ["claude-opus-4-8", "claude-opus-4.8"],
  3281. efforts: ["low", "medium", "high", "xhigh", "max"],
  3282. expectedHigh: { thinking: { type: "adaptive", display: "summarized" }, effort: "high" },
  3283. },
  3284. {
  3285. name: "fable 5",
  3286. apiIds: ["claude-fable-5"],
  3287. efforts: ["low", "medium", "high", "xhigh", "max"],
  3288. expectedHigh: { thinking: { type: "adaptive", display: "summarized" }, effort: "high" },
  3289. },
  3290. ]) {
  3291. for (const apiId of testCase.apiIds) {
  3292. test(`${testCase.name} ${apiId} returns supported reasoning efforts`, () => {
  3293. const result = ProviderTransform.variants(
  3294. createMockModel({
  3295. id: `anthropic/${apiId}`,
  3296. providerID: "anthropic",
  3297. api: {
  3298. id: apiId,
  3299. url: "https://api.anthropic.com",
  3300. npm: "@ai-sdk/anthropic",
  3301. },
  3302. }),
  3303. )
  3304. expect(Object.keys(result)).toEqual(testCase.efforts)
  3305. expect(result.high).toEqual(testCase.expectedHigh)
  3306. })
  3307. }
  3308. }
  3309. test("github copilot opus 4.7 returns only medium reasoning effort", () => {
  3310. const model = createMockModel({
  3311. id: "claude-opus-4.7",
  3312. providerID: "github-copilot",
  3313. api: {
  3314. id: "claude-opus-4.7",
  3315. url: "https://api.githubcopilot.com/v1",
  3316. npm: "@ai-sdk/anthropic",
  3317. },
  3318. })
  3319. const result = ProviderTransform.variants(model)
  3320. expect(result).toEqual({
  3321. medium: {
  3322. thinking: {
  3323. type: "adaptive",
  3324. display: "summarized",
  3325. },
  3326. effort: "medium",
  3327. },
  3328. })
  3329. })
  3330. test("returns high and max with thinking config", () => {
  3331. const model = createMockModel({
  3332. id: "anthropic/claude-4",
  3333. providerID: "anthropic",
  3334. api: {
  3335. id: "claude-4",
  3336. url: "https://api.anthropic.com",
  3337. npm: "@ai-sdk/anthropic",
  3338. },
  3339. })
  3340. const result = ProviderTransform.variants(model)
  3341. expect(Object.keys(result)).toEqual(["high", "max"])
  3342. expect(result.high).toEqual({
  3343. thinking: {
  3344. type: "enabled",
  3345. budgetTokens: 16000,
  3346. },
  3347. })
  3348. expect(result.max).toEqual({
  3349. thinking: {
  3350. type: "enabled",
  3351. budgetTokens: 31999,
  3352. },
  3353. })
  3354. })
  3355. })
  3356. describe("@ai-sdk/google-vertex/anthropic", () => {
  3357. test("opus 4.8 uses adaptive reasoning for Vertex model IDs", () => {
  3358. const result = ProviderTransform.variants(
  3359. createMockModel({
  3360. id: "google-vertex-anthropic/claude-opus-4-8@default",
  3361. providerID: "google-vertex-anthropic",
  3362. api: {
  3363. id: "claude-opus-4-8@default",
  3364. url: "https://us-central1-aiplatform.googleapis.com",
  3365. npm: "@ai-sdk/google-vertex/anthropic",
  3366. },
  3367. }),
  3368. )
  3369. expect(Object.keys(result)).toEqual(["low", "medium", "high", "xhigh", "max"])
  3370. expect(result.high).toEqual({
  3371. thinking: {
  3372. type: "adaptive",
  3373. display: "summarized",
  3374. },
  3375. effort: "high",
  3376. })
  3377. })
  3378. })
  3379. describe("@ai-sdk/amazon-bedrock", () => {
  3380. test("anthropic sonnet 4.6 returns adaptive reasoning options", () => {
  3381. const model = createMockModel({
  3382. id: "bedrock/anthropic-claude-sonnet-4-6",
  3383. providerID: "bedrock",
  3384. api: {
  3385. id: "anthropic.claude-sonnet-4-6",
  3386. url: "https://bedrock.amazonaws.com",
  3387. npm: "@ai-sdk/amazon-bedrock",
  3388. },
  3389. })
  3390. const result = ProviderTransform.variants(model)
  3391. expect(Object.keys(result)).toEqual(["low", "medium", "high", "max"])
  3392. expect(result.max).toEqual({
  3393. reasoningConfig: {
  3394. type: "adaptive",
  3395. maxReasoningEffort: "max",
  3396. },
  3397. })
  3398. })
  3399. test("anthropic opus 4.7 returns adaptive reasoning options with xhigh", () => {
  3400. const model = createMockModel({
  3401. id: "bedrock/anthropic-claude-opus-4-7",
  3402. providerID: "bedrock",
  3403. api: {
  3404. id: "anthropic.claude-opus-4-7",
  3405. url: "https://bedrock.amazonaws.com",
  3406. npm: "@ai-sdk/amazon-bedrock",
  3407. },
  3408. })
  3409. const result = ProviderTransform.variants(model)
  3410. expect(Object.keys(result)).toEqual(["low", "medium", "high", "xhigh", "max"])
  3411. expect(result.xhigh).toEqual({
  3412. reasoningConfig: {
  3413. type: "adaptive",
  3414. maxReasoningEffort: "xhigh",
  3415. display: "summarized",
  3416. },
  3417. })
  3418. expect(result.max).toEqual({
  3419. reasoningConfig: {
  3420. type: "adaptive",
  3421. maxReasoningEffort: "max",
  3422. display: "summarized",
  3423. },
  3424. })
  3425. })
  3426. test("anthropic opus 4.8 returns adaptive reasoning options with xhigh", () => {
  3427. const result = ProviderTransform.variants(
  3428. createMockModel({
  3429. id: "bedrock/anthropic-claude-opus-4.8",
  3430. providerID: "bedrock",
  3431. api: {
  3432. id: "anthropic.claude-opus-4.8",
  3433. url: "https://bedrock.amazonaws.com",
  3434. npm: "@ai-sdk/amazon-bedrock",
  3435. },
  3436. }),
  3437. )
  3438. expect(Object.keys(result)).toEqual(["low", "medium", "high", "xhigh", "max"])
  3439. expect(result.high).toEqual({
  3440. reasoningConfig: {
  3441. type: "adaptive",
  3442. maxReasoningEffort: "high",
  3443. display: "summarized",
  3444. },
  3445. })
  3446. })
  3447. test("returns WIDELY_SUPPORTED_EFFORTS with reasoningConfig", () => {
  3448. const model = createMockModel({
  3449. id: "bedrock/llama-4",
  3450. providerID: "bedrock",
  3451. api: {
  3452. id: "llama-4-sc",
  3453. url: "https://bedrock.amazonaws.com",
  3454. npm: "@ai-sdk/amazon-bedrock",
  3455. },
  3456. })
  3457. const result = ProviderTransform.variants(model)
  3458. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  3459. expect(result.low).toEqual({
  3460. reasoningConfig: {
  3461. type: "enabled",
  3462. maxReasoningEffort: "low",
  3463. },
  3464. })
  3465. })
  3466. })
  3467. for (const provider of [
  3468. { name: "@ai-sdk/google", providerID: "google", url: "https://generativelanguage.googleapis.com" },
  3469. { name: "@ai-sdk/google-vertex", providerID: "google-vertex", url: "https://vertexai.googleapis.com" },
  3470. ]) {
  3471. describe(provider.name, () => {
  3472. for (const testCase of [
  3473. {
  3474. apiId: "gemini-2.5-pro",
  3475. efforts: ["high", "max"],
  3476. expectedHigh: { thinkingConfig: { includeThoughts: true, thinkingBudget: 16_000 } },
  3477. expectedMax: { thinkingConfig: { includeThoughts: true, thinkingBudget: 32_768 } },
  3478. },
  3479. {
  3480. apiId: "gemini-2.5-flash",
  3481. efforts: ["high", "max"],
  3482. expectedHigh: { thinkingConfig: { includeThoughts: true, thinkingBudget: 16_000 } },
  3483. expectedMax: { thinkingConfig: { includeThoughts: true, thinkingBudget: 24_576 } },
  3484. },
  3485. {
  3486. apiId: "gemini-3-pro-preview",
  3487. efforts: ["low", "medium", "high"],
  3488. expectedHigh: { thinkingConfig: { includeThoughts: true, thinkingLevel: "high" } },
  3489. },
  3490. {
  3491. apiId: "gemini-3.1-pro-preview",
  3492. efforts: ["low", "medium", "high"],
  3493. expectedHigh: { thinkingConfig: { includeThoughts: true, thinkingLevel: "high" } },
  3494. },
  3495. {
  3496. apiId: "gemini-3-flash-preview",
  3497. efforts: ["minimal", "low", "medium", "high"],
  3498. expectedHigh: { thinkingConfig: { includeThoughts: true, thinkingLevel: "high" } },
  3499. },
  3500. {
  3501. apiId: "gemini-3.1-flash-lite",
  3502. efforts: ["minimal", "low", "medium", "high"],
  3503. expectedHigh: { thinkingConfig: { includeThoughts: true, thinkingLevel: "high" } },
  3504. },
  3505. {
  3506. apiId: "gemini-3.1-flash-image-preview",
  3507. efforts: ["minimal", "high"],
  3508. expectedHigh: { thinkingConfig: { includeThoughts: true, thinkingLevel: "high" } },
  3509. },
  3510. {
  3511. apiId: "gemini-3-pro-image-preview",
  3512. efforts: ["high"],
  3513. expectedHigh: { thinkingConfig: { includeThoughts: true, thinkingLevel: "high" } },
  3514. },
  3515. ]) {
  3516. test(`${testCase.apiId} returns supported thinking controls`, () => {
  3517. const result = ProviderTransform.variants(
  3518. createMockModel({
  3519. id: `${provider.providerID}/${testCase.apiId}`,
  3520. providerID: provider.providerID,
  3521. api: {
  3522. id: testCase.apiId,
  3523. url: provider.url,
  3524. npm: provider.name,
  3525. },
  3526. }),
  3527. )
  3528. expect(Object.keys(result)).toEqual(testCase.efforts)
  3529. expect(result.high).toEqual(testCase.expectedHigh)
  3530. if (testCase.expectedMax) expect(result.max).toEqual(testCase.expectedMax)
  3531. })
  3532. }
  3533. })
  3534. }
  3535. describe("@ai-sdk/cohere", () => {
  3536. test("returns empty object", () => {
  3537. const model = createMockModel({
  3538. id: "cohere/command-r",
  3539. providerID: "cohere",
  3540. api: {
  3541. id: "command-r",
  3542. url: "https://api.cohere.com",
  3543. npm: "@ai-sdk/cohere",
  3544. },
  3545. })
  3546. const result = ProviderTransform.variants(model)
  3547. expect(result).toEqual({})
  3548. })
  3549. })
  3550. describe("@ai-sdk/groq", () => {
  3551. test("returns none and WIDELY_SUPPORTED_EFFORTS with thinkingLevel", () => {
  3552. const model = createMockModel({
  3553. id: "groq/llama-4",
  3554. providerID: "groq",
  3555. api: {
  3556. id: "llama-4-sc",
  3557. url: "https://api.groq.com",
  3558. npm: "@ai-sdk/groq",
  3559. },
  3560. })
  3561. const result = ProviderTransform.variants(model)
  3562. expect(Object.keys(result)).toEqual(["none", "low", "medium", "high"])
  3563. expect(result.none).toEqual({
  3564. reasoningEffort: "none",
  3565. })
  3566. expect(result.low).toEqual({
  3567. reasoningEffort: "low",
  3568. })
  3569. })
  3570. })
  3571. describe("@ai-sdk/perplexity", () => {
  3572. test("returns empty object", () => {
  3573. const model = createMockModel({
  3574. id: "perplexity/sonar-plus",
  3575. providerID: "perplexity",
  3576. api: {
  3577. id: "sonar-plus",
  3578. url: "https://api.perplexity.ai",
  3579. npm: "@ai-sdk/perplexity",
  3580. },
  3581. })
  3582. const result = ProviderTransform.variants(model)
  3583. expect(result).toEqual({})
  3584. })
  3585. })
  3586. describe("@jerome-benoit/sap-ai-provider-v2", () => {
  3587. const sapModel = (apiId: string, releaseDate = "2024-01-01") =>
  3588. createMockModel({
  3589. id: `sap-ai-core/${apiId}`,
  3590. providerID: "sap-ai-core",
  3591. api: {
  3592. id: apiId,
  3593. url: "https://api.ai.sap",
  3594. npm: "@jerome-benoit/sap-ai-provider-v2",
  3595. },
  3596. release_date: releaseDate,
  3597. })
  3598. for (const testCase of [
  3599. {
  3600. name: "sonnet 4.6",
  3601. apiIds: ["anthropic--claude-sonnet-4-6"],
  3602. efforts: ["low", "medium", "high", "max"],
  3603. thinking: { type: "adaptive" },
  3604. },
  3605. {
  3606. name: "opus 4.6",
  3607. apiIds: ["anthropic--claude-4.6-opus", "anthropic--claude-4-6-opus"],
  3608. efforts: ["low", "medium", "high", "max"],
  3609. thinking: { type: "adaptive" },
  3610. },
  3611. {
  3612. name: "opus 4.7",
  3613. apiIds: ["anthropic--claude-4.7-opus", "anthropic--claude-4-7-opus"],
  3614. efforts: ["low", "medium", "high", "xhigh", "max"],
  3615. thinking: { type: "adaptive", display: "summarized" },
  3616. },
  3617. {
  3618. name: "opus 4.8",
  3619. apiIds: ["anthropic--claude-4.8-opus", "anthropic--claude-4-8-opus"],
  3620. efforts: ["low", "medium", "high", "xhigh", "max"],
  3621. thinking: { type: "adaptive", display: "summarized" },
  3622. },
  3623. ]) {
  3624. for (const apiId of testCase.apiIds) {
  3625. test(`${testCase.name} ${apiId} returns adaptive thinking variants under modelParams`, () => {
  3626. const result = ProviderTransform.variants(sapModel(apiId))
  3627. expect(Object.keys(result)).toEqual(testCase.efforts)
  3628. for (const effort of testCase.efforts) {
  3629. expect(result[effort]).toEqual({
  3630. modelParams: {
  3631. thinking: testCase.thinking,
  3632. output_config: { effort },
  3633. },
  3634. })
  3635. }
  3636. })
  3637. }
  3638. }
  3639. for (const apiId of ["anthropic--claude-sonnet-4", "anthropic--claude-4.5-opus"]) {
  3640. test(`${apiId} returns budget_tokens variants under modelParams`, () => {
  3641. const result = ProviderTransform.variants(sapModel(apiId))
  3642. expect(Object.keys(result)).toEqual(["high", "max"])
  3643. expect(result.high).toEqual({
  3644. modelParams: { thinking: { type: "enabled", budget_tokens: 16000 } },
  3645. })
  3646. expect(result.max).toEqual({
  3647. modelParams: { thinking: { type: "enabled", budget_tokens: 31999 } },
  3648. })
  3649. })
  3650. }
  3651. for (const testCase of [
  3652. { apiId: "gemini-2.5-pro", maxBudget: 32768 },
  3653. { apiId: "gemini-2.5-flash", maxBudget: 24576 },
  3654. ]) {
  3655. test(`${testCase.apiId} returns thinkingConfig variants under modelParams`, () => {
  3656. const result = ProviderTransform.variants(sapModel(testCase.apiId))
  3657. expect(Object.keys(result)).toEqual(["high", "max"])
  3658. expect(result.high).toEqual({
  3659. modelParams: { thinkingConfig: { includeThoughts: true, thinkingBudget: 16000 } },
  3660. })
  3661. expect(result.max).toEqual({
  3662. modelParams: { thinkingConfig: { includeThoughts: true, thinkingBudget: testCase.maxBudget } },
  3663. })
  3664. })
  3665. }
  3666. for (const testCase of [
  3667. { apiId: "gpt-5", releaseDate: "2025-08-07", efforts: ["minimal", "low", "medium", "high"] },
  3668. { apiId: "gpt-5-mini", releaseDate: "2025-08-07", efforts: ["minimal", "low", "medium", "high"] },
  3669. { apiId: "gpt-5-nano", releaseDate: "2025-08-07", efforts: ["minimal", "low", "medium", "high"] },
  3670. { apiId: "gpt-5.4", releaseDate: "2026-01-15", efforts: ["none", "low", "medium", "high", "xhigh"] },
  3671. { apiId: "azure-openai--o3-mini", releaseDate: "2024-01-01", efforts: ["low", "medium", "high"] },
  3672. ]) {
  3673. test(`${testCase.apiId} returns reasoning_effort variants under modelParams`, () => {
  3674. const result = ProviderTransform.variants(sapModel(testCase.apiId, testCase.releaseDate))
  3675. expect(Object.keys(result)).toEqual(testCase.efforts)
  3676. for (const effort of testCase.efforts) {
  3677. expect(result[effort]).toEqual({ modelParams: { reasoning_effort: effort } })
  3678. }
  3679. })
  3680. }
  3681. for (const apiId of [
  3682. "gemini-3.1-flash-lite",
  3683. "cohere--command-a-reasoning",
  3684. "sonar-deep-research",
  3685. "aws--llama-opus-4.7-fake",
  3686. ]) {
  3687. test(`${apiId} falls through to harmonized reasoning_effort fallback`, () => {
  3688. const result = ProviderTransform.variants(sapModel(apiId))
  3689. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  3690. for (const effort of ["low", "medium", "high"]) {
  3691. expect(result[effort]).toEqual({ modelParams: { reasoning_effort: effort } })
  3692. }
  3693. })
  3694. }
  3695. })
  3696. describe("ai-gateway-provider (cloudflare-ai-gateway)", () => {
  3697. const cfModel = (apiId: string, releaseDate = "2024-01-01") =>
  3698. createMockModel({
  3699. id: `cloudflare-ai-gateway/${apiId}`,
  3700. providerID: "cloudflare-ai-gateway",
  3701. api: {
  3702. id: apiId,
  3703. url: "https://gateway.ai.cloudflare.com/v1/compat",
  3704. npm: "ai-gateway-provider",
  3705. },
  3706. release_date: releaseDate,
  3707. })
  3708. for (const testCase of [
  3709. { id: "openai/gpt-5.4", efforts: ["none", "low", "medium", "high", "xhigh"] },
  3710. { id: "openai/gpt-5.2-codex", efforts: ["low", "medium", "high", "xhigh"] },
  3711. { id: "openai/gpt-5.3-codex", efforts: ["none", "low", "medium", "high", "xhigh"] },
  3712. { id: "openai/gpt-5-pro", efforts: ["high"] },
  3713. { id: "openai/gpt-5.2-pro", efforts: ["medium", "high", "xhigh"] },
  3714. { id: "openai/gpt-5-chat-latest", efforts: [] },
  3715. { id: "openai/gpt-5.2-chat-latest", efforts: ["medium"] },
  3716. ]) {
  3717. test(`${testCase.id} returns supported reasoning efforts`, () => {
  3718. const result = ProviderTransform.variants(cfModel(testCase.id, "2026-03-05"))
  3719. expect(Object.keys(result)).toEqual(testCase.efforts)
  3720. })
  3721. }
  3722. test("openai gpt-4o (no reasoning) returns empty", () => {
  3723. const model = cfModel("openai/gpt-4o")
  3724. model.capabilities.reasoning = false
  3725. const result = ProviderTransform.variants(model)
  3726. expect(result).toEqual({})
  3727. })
  3728. test("non-openai upstream falls back to widely-supported OAI efforts", () => {
  3729. const result = ProviderTransform.variants(cfModel("anthropic/claude-sonnet-4-6"))
  3730. expect(result).toEqual({
  3731. low: { reasoningEffort: "low" },
  3732. medium: { reasoningEffort: "medium" },
  3733. high: { reasoningEffort: "high" },
  3734. })
  3735. })
  3736. })
  3737. })
  3738. describe("ProviderTransform.smallOptions - gpt-5 chat/search", () => {
  3739. const createModel = (apiId: string) => {
  3740. const model = {
  3741. id: `openai/${apiId}`,
  3742. providerID: "openai",
  3743. api: {
  3744. id: apiId,
  3745. url: "https://api.openai.com",
  3746. npm: "@ai-sdk/openai",
  3747. },
  3748. capabilities: { reasoning: true },
  3749. limit: { output: 64_000 },
  3750. release_date: "2026-01-01",
  3751. } as any
  3752. model.variants = ProviderTransform.variants(model)
  3753. return model
  3754. }
  3755. for (const testCase of [
  3756. { id: "gpt-5-chat-latest", options: { store: false } },
  3757. {
  3758. id: "gpt-5.1-chat-latest",
  3759. options: {
  3760. store: false,
  3761. reasoningEffort: "medium",
  3762. reasoningSummary: "auto",
  3763. include: ["reasoning.encrypted_content"],
  3764. },
  3765. },
  3766. {
  3767. id: "gpt-5.2-chat-latest",
  3768. options: {
  3769. store: false,
  3770. reasoningEffort: "medium",
  3771. reasoningSummary: "auto",
  3772. include: ["reasoning.encrypted_content"],
  3773. },
  3774. },
  3775. {
  3776. id: "gpt-5-search-api",
  3777. options: {
  3778. store: false,
  3779. reasoningEffort: "none",
  3780. reasoningSummary: "auto",
  3781. include: ["reasoning.encrypted_content"],
  3782. },
  3783. },
  3784. ]) {
  3785. test(`${testCase.id} returns only supported small options`, () => {
  3786. expect(ProviderTransform.smallOptions(createModel(testCase.id))).toEqual(testCase.options)
  3787. })
  3788. }
  3789. })
  3790. test("ProviderTransform.smallOptions disables OpenRouter reasoning when the weakest effort is low", () => {
  3791. expect(
  3792. ProviderTransform.smallOptions({
  3793. providerID: "openrouter",
  3794. api: {
  3795. id: "anthropic/claude-sonnet-4.6",
  3796. npm: "@openrouter/ai-sdk-provider",
  3797. },
  3798. variants: {
  3799. low: { reasoning: { effort: "low" } },
  3800. medium: { reasoning: { effort: "medium" } },
  3801. high: { reasoning: { effort: "high" } },
  3802. },
  3803. } as any),
  3804. ).toEqual({ reasoning: { effort: "none" } })
  3805. })
  3806. describe("ProviderTransform.smallOptions - google thinking controls", () => {
  3807. const createGoogleModel = (apiId: string) => {
  3808. const model = {
  3809. id: `google/${apiId}`,
  3810. providerID: "google",
  3811. api: {
  3812. id: apiId,
  3813. url: "https://generativelanguage.googleapis.com",
  3814. npm: "@ai-sdk/google",
  3815. },
  3816. capabilities: { reasoning: true },
  3817. limit: { output: 64_000 },
  3818. } as any
  3819. model.variants = ProviderTransform.variants(model)
  3820. return model
  3821. }
  3822. for (const testCase of [
  3823. { id: "gemini-3-pro-preview", options: { thinkingConfig: { includeThoughts: true, thinkingLevel: "low" } } },
  3824. { id: "gemini-3-flash-preview", options: { thinkingConfig: { includeThoughts: true, thinkingLevel: "minimal" } } },
  3825. {
  3826. id: "gemini-3.1-flash-image-preview",
  3827. options: { thinkingConfig: { includeThoughts: true, thinkingLevel: "minimal" } },
  3828. },
  3829. { id: "gemini-3-pro-image-preview", options: { thinkingConfig: { includeThoughts: true, thinkingLevel: "high" } } },
  3830. { id: "gemini-2.5-pro", options: { thinkingConfig: { includeThoughts: true, thinkingBudget: 16000 } } },
  3831. { id: "gemini-2.5-flash", options: { thinkingConfig: { includeThoughts: true, thinkingBudget: 16000 } } },
  3832. ]) {
  3833. test(`${testCase.id} returns supported small thinking options`, () => {
  3834. expect(ProviderTransform.smallOptions(createGoogleModel(testCase.id))).toEqual(testCase.options)
  3835. })
  3836. }
  3837. test("uses the first configured variant when available", () => {
  3838. expect(
  3839. ProviderTransform.smallOptions({
  3840. ...createGoogleModel("gemini-2.5-pro"),
  3841. variants: {
  3842. high: { thinkingConfig: { includeThoughts: true, thinkingBudget: 16000 } },
  3843. max: { thinkingConfig: { includeThoughts: true, thinkingBudget: 32768 } },
  3844. },
  3845. }),
  3846. ).toEqual({ thinkingConfig: { includeThoughts: true, thinkingBudget: 16000 } })
  3847. })
  3848. test("does not synthesize thinking options when variants are empty", () => {
  3849. expect(ProviderTransform.smallOptions({ ...createGoogleModel("gemini-2.5-pro"), variants: {} })).toEqual({})
  3850. })
  3851. })
  3852. describe("ProviderTransform.providerOptions - ai-gateway-provider", () => {
  3853. const createModel = (overrides: Partial<any> = {}) =>
  3854. ({
  3855. id: "cloudflare-ai-gateway/openai/gpt-5.4",
  3856. providerID: "cloudflare-ai-gateway",
  3857. api: {
  3858. id: "openai/gpt-5.4",
  3859. url: "https://gateway.ai.cloudflare.com/v1/compat",
  3860. npm: "ai-gateway-provider",
  3861. },
  3862. capabilities: {
  3863. temperature: false,
  3864. reasoning: true,
  3865. attachment: true,
  3866. toolcall: true,
  3867. input: { text: true, audio: false, image: true, video: false, pdf: true },
  3868. output: { text: true, audio: false, image: false, video: false, pdf: false },
  3869. interleaved: false,
  3870. },
  3871. cost: { input: 1, output: 1, cache: { read: 0, write: 0 } },
  3872. limit: { context: 1_000_000, output: 128_000 },
  3873. status: "active",
  3874. options: {},
  3875. headers: {},
  3876. release_date: "2026-03-05",
  3877. ...overrides,
  3878. }) as any
  3879. test("routes options under openaiCompatible (the key @ai-sdk/openai-compatible reads)", () => {
  3880. // Regression: previously fell back to providerID="cloudflare-ai-gateway",
  3881. // which @ai-sdk/openai-compatible never reads, silently dropping reasoningEffort.
  3882. const result = ProviderTransform.providerOptions(createModel(), { reasoningEffort: "high" })
  3883. expect(result).toEqual({ openaiCompatible: { reasoningEffort: "high" } })
  3884. })
  3885. })