transform.test.ts 167 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429
  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. import { ModelsDev } from "@opencode-ai/core/models-dev"
  8. import { jsonSchema } from "ai"
  9. describe("ProviderTransform.options - setCacheKey", () => {
  10. const sessionID = "test-session-123"
  11. const mockModel = {
  12. id: "anthropic/claude-3-5-sonnet",
  13. providerID: "anthropic",
  14. api: {
  15. id: "claude-3-5-sonnet-20241022",
  16. url: "https://api.anthropic.com",
  17. npm: "@ai-sdk/anthropic",
  18. },
  19. name: "Claude 3.5 Sonnet",
  20. capabilities: {
  21. temperature: true,
  22. reasoning: false,
  23. attachment: true,
  24. toolcall: true,
  25. input: { text: true, audio: false, image: true, video: false, pdf: true },
  26. output: { text: true, audio: false, image: false, video: false, pdf: false },
  27. interleaved: false,
  28. },
  29. cost: {
  30. input: 0.003,
  31. output: 0.015,
  32. cache: { read: 0.0003, write: 0.00375 },
  33. },
  34. limit: {
  35. context: 200000,
  36. output: 8192,
  37. },
  38. status: "active",
  39. options: {},
  40. headers: {},
  41. } as any
  42. test("should set promptCacheKey when providerOptions.setCacheKey is true", () => {
  43. const result = ProviderTransform.options({
  44. model: mockModel,
  45. sessionID,
  46. providerOptions: { setCacheKey: true },
  47. })
  48. expect(result.promptCacheKey).toBe(sessionID)
  49. })
  50. test("should not set promptCacheKey when providerOptions.setCacheKey is false", () => {
  51. const result = ProviderTransform.options({
  52. model: mockModel,
  53. sessionID,
  54. providerOptions: { setCacheKey: false },
  55. })
  56. expect(result.promptCacheKey).toBeUndefined()
  57. })
  58. test("should not set promptCacheKey when providerOptions is undefined", () => {
  59. const result = ProviderTransform.options({
  60. model: mockModel,
  61. sessionID,
  62. providerOptions: undefined,
  63. })
  64. expect(result.promptCacheKey).toBeUndefined()
  65. })
  66. test("should not set promptCacheKey when providerOptions does not have setCacheKey", () => {
  67. const result = ProviderTransform.options({ model: mockModel, sessionID, providerOptions: {} })
  68. expect(result.promptCacheKey).toBeUndefined()
  69. })
  70. test("should set promptCacheKey for openai provider by default", () => {
  71. const openaiModel = {
  72. ...mockModel,
  73. providerID: "openai",
  74. api: {
  75. id: "gpt-4",
  76. url: "https://api.openai.com",
  77. npm: "@ai-sdk/openai",
  78. },
  79. }
  80. const result = ProviderTransform.options({ model: openaiModel, sessionID, providerOptions: {} })
  81. expect(result.promptCacheKey).toBe(sessionID)
  82. })
  83. test("should set promptCacheKey for the OpenAI SDK regardless of provider ID", () => {
  84. const result = ProviderTransform.options({
  85. model: {
  86. ...mockModel,
  87. providerID: "custom-openai",
  88. api: { id: "gpt-5", url: "https://example.com", npm: "@ai-sdk/openai" },
  89. },
  90. sessionID,
  91. providerOptions: {},
  92. })
  93. expect(result.promptCacheKey).toBe(sessionID)
  94. })
  95. test("should not set promptCacheKey for the OpenAI-compatible SDK by provider name", () => {
  96. const result = ProviderTransform.options({
  97. model: {
  98. ...mockModel,
  99. providerID: "openai",
  100. api: { id: "gpt-5", url: "https://example.com", npm: "@ai-sdk/openai-compatible" },
  101. },
  102. sessionID,
  103. providerOptions: {},
  104. })
  105. expect(result.promptCacheKey).toBeUndefined()
  106. })
  107. test("should not set promptCacheKey for openai when explicitly disabled", () => {
  108. const openaiModel = {
  109. ...mockModel,
  110. providerID: "openai",
  111. api: {
  112. id: "gpt-4",
  113. url: "https://api.openai.com",
  114. npm: "@ai-sdk/openai",
  115. },
  116. }
  117. const result = ProviderTransform.options({
  118. model: openaiModel,
  119. sessionID,
  120. providerOptions: { setCacheKey: false },
  121. })
  122. expect(result.promptCacheKey).toBeUndefined()
  123. })
  124. test("should set promptCacheKey for the xAI SDK by default regardless of provider ID", () => {
  125. const xaiModel = {
  126. ...mockModel,
  127. providerID: "custom-xai",
  128. api: {
  129. id: "grok-4",
  130. url: "https://api.x.ai",
  131. npm: "@ai-sdk/xai",
  132. },
  133. }
  134. const result = ProviderTransform.options({ model: xaiModel, sessionID, providerOptions: {} })
  135. expect(result.promptCacheKey).toBe(sessionID)
  136. })
  137. test("should not set promptCacheKey for the xAI SDK when explicitly disabled", () => {
  138. const xaiModel = {
  139. ...mockModel,
  140. providerID: "xai",
  141. api: {
  142. id: "grok-4",
  143. url: "https://api.x.ai",
  144. npm: "@ai-sdk/xai",
  145. },
  146. }
  147. const result = ProviderTransform.options({
  148. model: xaiModel,
  149. sessionID,
  150. providerOptions: { setCacheKey: false },
  151. })
  152. expect(result.promptCacheKey).toBeUndefined()
  153. })
  154. test("should set store=false for openai provider", () => {
  155. const openaiModel = {
  156. ...mockModel,
  157. providerID: "openai",
  158. api: {
  159. id: "gpt-4",
  160. url: "https://api.openai.com",
  161. npm: "@ai-sdk/openai",
  162. },
  163. }
  164. const result = ProviderTransform.options({
  165. model: openaiModel,
  166. sessionID,
  167. providerOptions: {},
  168. })
  169. expect(result.store).toBe(false)
  170. })
  171. test("should set store=false for xAI provider by default", () => {
  172. const xaiModel = {
  173. ...mockModel,
  174. providerID: "xai",
  175. api: {
  176. id: "grok-4",
  177. url: "https://api.x.ai",
  178. npm: "@ai-sdk/xai",
  179. },
  180. }
  181. const result = ProviderTransform.options({
  182. model: xaiModel,
  183. sessionID,
  184. providerOptions: {},
  185. })
  186. expect(result.store).toBe(false)
  187. expect(result.promptCacheKey).toBe(sessionID)
  188. })
  189. test("should set store=false for xAI SDK regardless of provider ID", () => {
  190. const xaiModel = {
  191. ...mockModel,
  192. providerID: "custom-xai",
  193. api: {
  194. id: "grok-4",
  195. url: "https://api.x.ai",
  196. npm: "@ai-sdk/xai",
  197. },
  198. }
  199. const result = ProviderTransform.options({
  200. model: xaiModel,
  201. sessionID,
  202. providerOptions: {},
  203. })
  204. expect(result.store).toBe(false)
  205. })
  206. test("should set store=false for azure provider by default", () => {
  207. const azureModel = {
  208. ...mockModel,
  209. providerID: "azure",
  210. api: {
  211. id: "gpt-4",
  212. url: "https://azure.com",
  213. npm: "@ai-sdk/azure",
  214. },
  215. }
  216. const result = ProviderTransform.options({
  217. model: azureModel,
  218. sessionID,
  219. providerOptions: {},
  220. })
  221. expect(result.store).toBe(false)
  222. expect(result.promptCacheKey).toBe(sessionID)
  223. })
  224. test("should disable the Azure cache key without disabling store=false", () => {
  225. const result = ProviderTransform.options({
  226. model: {
  227. ...mockModel,
  228. providerID: "azure",
  229. api: { id: "gpt-5", url: "https://azure.com", npm: "@ai-sdk/azure" },
  230. },
  231. sessionID,
  232. providerOptions: { setCacheKey: false },
  233. })
  234. expect(result.store).toBe(false)
  235. expect(result.promptCacheKey).toBeUndefined()
  236. })
  237. test("should keep the Azure cache key for gpt-5.5 early return", () => {
  238. const result = ProviderTransform.options({
  239. model: {
  240. ...mockModel,
  241. providerID: "azure",
  242. api: { id: "gpt-5.5", url: "https://azure.com", npm: "@ai-sdk/azure" },
  243. },
  244. sessionID,
  245. providerOptions: {},
  246. })
  247. expect(result.store).toBe(false)
  248. expect(result.reasoningSummary).toBe("auto")
  249. expect(result.promptCacheKey).toBe(sessionID)
  250. })
  251. for (const npm of ["@ai-sdk/deepinfra", "@ai-sdk/cerebras"]) {
  252. test(`should set the snake-case cache key for ${npm}`, () => {
  253. const result = ProviderTransform.options({
  254. model: { ...mockModel, providerID: "custom", api: { ...mockModel.api, npm } },
  255. sessionID,
  256. providerOptions: {},
  257. })
  258. expect(result.prompt_cache_key).toBe(sessionID)
  259. expect(result.promptCacheKey).toBeUndefined()
  260. })
  261. }
  262. test("should set promptCacheKey for the Mistral SDK", () => {
  263. const result = ProviderTransform.options({
  264. model: { ...mockModel, providerID: "custom", api: { ...mockModel.api, npm: "@ai-sdk/mistral" } },
  265. sessionID,
  266. providerOptions: {},
  267. })
  268. expect(result.promptCacheKey).toBe(sessionID)
  269. })
  270. test("should not send an undocumented OpenRouter prompt_cache_key", () => {
  271. const result = ProviderTransform.options({
  272. model: {
  273. ...mockModel,
  274. providerID: "openrouter",
  275. api: { ...mockModel.api, npm: "@openrouter/ai-sdk-provider" },
  276. },
  277. sessionID,
  278. providerOptions: {},
  279. })
  280. expect(result.prompt_cache_key).toBeUndefined()
  281. })
  282. })
  283. describe("ProviderTransform.options - zai/zhipuai thinking", () => {
  284. const sessionID = "test-session-123"
  285. const createModel = (providerID: string) =>
  286. ({
  287. id: `${providerID}/glm-4.6`,
  288. providerID,
  289. api: {
  290. id: "glm-4.6",
  291. url: "https://open.bigmodel.cn/api/paas/v4",
  292. npm: "@ai-sdk/openai-compatible",
  293. },
  294. name: "GLM 4.6",
  295. capabilities: {
  296. temperature: true,
  297. reasoning: true,
  298. attachment: true,
  299. toolcall: true,
  300. input: { text: true, audio: false, image: true, video: false, pdf: true },
  301. output: { text: true, audio: false, image: false, video: false, pdf: false },
  302. interleaved: false,
  303. },
  304. cost: {
  305. input: 0.001,
  306. output: 0.002,
  307. cache: { read: 0.0001, write: 0.0002 },
  308. },
  309. limit: {
  310. context: 128000,
  311. output: 8192,
  312. },
  313. status: "active",
  314. options: {},
  315. headers: {},
  316. }) as any
  317. for (const providerID of ["zai-coding-plan", "zai", "zhipuai-coding-plan", "zhipuai"]) {
  318. test(`${providerID} should set thinking cfg`, () => {
  319. const result = ProviderTransform.options({
  320. model: createModel(providerID),
  321. sessionID,
  322. providerOptions: {},
  323. })
  324. expect(result.thinking).toEqual({
  325. type: "enabled",
  326. clear_thinking: false,
  327. })
  328. })
  329. }
  330. })
  331. describe("ProviderTransform.options - minimax m3 thinking", () => {
  332. const createModel = (npm: string) =>
  333. ({
  334. id: "minimax/minimax-m3",
  335. providerID: "minimax",
  336. api: {
  337. id: "minimax-m3",
  338. url: "https://api.minimax.com",
  339. npm,
  340. },
  341. capabilities: { reasoning: true },
  342. limit: { output: 64_000 },
  343. }) as any
  344. test("explicitly enables adaptive thinking with the anthropic SDK", () => {
  345. expect(
  346. ProviderTransform.options({
  347. model: createModel("@ai-sdk/anthropic"),
  348. sessionID: "test-session-123",
  349. }).thinking,
  350. ).toEqual({ type: "adaptive" })
  351. })
  352. test("uses the native default with the openai-compatible SDK", () => {
  353. expect(
  354. ProviderTransform.options({
  355. model: createModel("@ai-sdk/openai-compatible"),
  356. sessionID: "test-session-123",
  357. }).thinking,
  358. ).toBeUndefined()
  359. })
  360. })
  361. describe("ProviderTransform.options - google thinkingConfig gating", () => {
  362. const sessionID = "test-session-123"
  363. const createGoogleModel = (reasoning: boolean, npm: "@ai-sdk/google" | "@ai-sdk/google-vertex") =>
  364. ({
  365. id: `${npm === "@ai-sdk/google" ? "google" : "google-vertex"}/gemini-2.0-flash`,
  366. providerID: npm === "@ai-sdk/google" ? "google" : "google-vertex",
  367. api: {
  368. id: "gemini-2.0-flash",
  369. url: npm === "@ai-sdk/google" ? "https://generativelanguage.googleapis.com" : "https://vertexai.googleapis.com",
  370. npm,
  371. },
  372. name: "Gemini 2.0 Flash",
  373. capabilities: {
  374. temperature: true,
  375. reasoning,
  376. attachment: true,
  377. toolcall: true,
  378. input: { text: true, audio: false, image: true, video: false, pdf: true },
  379. output: { text: true, audio: false, image: false, video: false, pdf: false },
  380. interleaved: false,
  381. },
  382. cost: {
  383. input: 0.001,
  384. output: 0.002,
  385. cache: { read: 0.0001, write: 0.0002 },
  386. },
  387. limit: {
  388. context: 1_000_000,
  389. output: 8192,
  390. },
  391. status: "active",
  392. options: {},
  393. headers: {},
  394. }) as any
  395. test("does not set thinkingConfig for google models without reasoning capability", () => {
  396. const result = ProviderTransform.options({
  397. model: createGoogleModel(false, "@ai-sdk/google"),
  398. sessionID,
  399. providerOptions: {},
  400. })
  401. expect(result.thinkingConfig).toBeUndefined()
  402. })
  403. test("sets thinkingConfig for google models with reasoning capability", () => {
  404. const result = ProviderTransform.options({
  405. model: createGoogleModel(true, "@ai-sdk/google"),
  406. sessionID,
  407. providerOptions: {},
  408. })
  409. expect(result.thinkingConfig).toEqual({
  410. includeThoughts: true,
  411. })
  412. })
  413. test("does not set thinkingConfig for vertex models without reasoning capability", () => {
  414. const result = ProviderTransform.options({
  415. model: createGoogleModel(false, "@ai-sdk/google-vertex"),
  416. sessionID,
  417. providerOptions: {},
  418. })
  419. expect(result.thinkingConfig).toBeUndefined()
  420. })
  421. })
  422. describe("ProviderTransform.options - gpt-5 textVerbosity", () => {
  423. const sessionID = "test-session-123"
  424. const createGpt5Model = (apiId: string) =>
  425. ({
  426. id: `openai/${apiId}`,
  427. providerID: "openai",
  428. api: {
  429. id: apiId,
  430. url: "https://api.openai.com",
  431. npm: "@ai-sdk/openai",
  432. },
  433. name: apiId,
  434. capabilities: {
  435. temperature: true,
  436. reasoning: true,
  437. attachment: true,
  438. toolcall: true,
  439. input: { text: true, audio: false, image: true, video: false, pdf: false },
  440. output: { text: true, audio: false, image: false, video: false, pdf: false },
  441. interleaved: false,
  442. },
  443. cost: { input: 0.03, output: 0.06, cache: { read: 0.001, write: 0.002 } },
  444. limit: { context: 128000, output: 4096 },
  445. status: "active",
  446. options: {},
  447. headers: {},
  448. }) as any
  449. test("gpt-5.2 should have textVerbosity set to low", () => {
  450. const model = createGpt5Model("gpt-5.2")
  451. const result = ProviderTransform.options({ model, sessionID, providerOptions: {} })
  452. expect(result.textVerbosity).toBe("low")
  453. expect(result.include).toEqual(["reasoning.encrypted_content"])
  454. })
  455. test("Bedrock Mantle gpt-5.5 uses OpenAI Responses defaults", () => {
  456. const model = {
  457. ...createGpt5Model("openai.gpt-5.5"),
  458. id: "amazon-bedrock/openai.gpt-5.5",
  459. providerID: "amazon-bedrock",
  460. api: {
  461. id: "openai.gpt-5.5",
  462. url: "https://bedrock-mantle.us-east-2.api.aws/openai/v1",
  463. npm: "@ai-sdk/amazon-bedrock/mantle",
  464. },
  465. }
  466. const result = ProviderTransform.options({ model, sessionID, providerOptions: {} })
  467. expect(result.store).toBe(false)
  468. expect(result.reasoningEffort).toBe("medium")
  469. expect(result.reasoningSummary).toBe("auto")
  470. expect(result.include).toEqual(["reasoning.encrypted_content"])
  471. expect(result.textVerbosity).toBe("low")
  472. })
  473. test("openai-compatible gpt-5 models omit Responses-only reasoningSummary", () => {
  474. const model = {
  475. ...createGpt5Model("gpt-5.4"),
  476. id: "cortecs/gpt-5.4",
  477. providerID: "cortecs",
  478. api: {
  479. id: "gpt-5.4",
  480. url: "https://api.cortecs.ai/v1",
  481. npm: "@ai-sdk/openai-compatible",
  482. },
  483. }
  484. const result = ProviderTransform.options({ model, sessionID, providerOptions: {} })
  485. expect(result.reasoningEffort).toBe("medium")
  486. expect(result.reasoningSummary).toBeUndefined()
  487. expect(result.include).toBeUndefined()
  488. })
  489. test("azure chat completions omit Responses-only reasoning options after variants merge", async () => {
  490. const model = {
  491. ...createGpt5Model("gpt-5.4"),
  492. id: "azure/gpt-5.4",
  493. providerID: "azure",
  494. api: {
  495. id: "gpt-5.4",
  496. url: "https://azure.com",
  497. npm: "@ai-sdk/azure",
  498. },
  499. variants: {
  500. high: {
  501. reasoningEffort: "high",
  502. reasoningSummary: "auto",
  503. include: ["reasoning.encrypted_content"],
  504. },
  505. },
  506. }
  507. const result = await Effect.runPromise(
  508. LLMRequestPrep.prepare({
  509. user: {
  510. id: "msg_user-test",
  511. sessionID,
  512. role: "user",
  513. time: { created: Date.now() },
  514. agent: "test",
  515. model: { providerID: "azure", modelID: "gpt-5.4", variant: "high" },
  516. } as any,
  517. sessionID,
  518. model,
  519. agent: {
  520. name: "test",
  521. mode: "primary",
  522. options: {},
  523. permission: [],
  524. } as any,
  525. system: [],
  526. messages: [{ role: "user", content: "Hello" }],
  527. tools: {
  528. lookup: {
  529. description: "Look up a value",
  530. inputSchema: jsonSchema({ type: "object", properties: {} }),
  531. },
  532. },
  533. provider: { id: "azure", options: { useCompletionUrls: true } } as any,
  534. auth: undefined,
  535. plugin: {
  536. trigger: (_name: string, _input: unknown, output: unknown) => Effect.succeed(output),
  537. list: () => Effect.succeed([]),
  538. init: () => Effect.void,
  539. } as any,
  540. flags: { outputTokenMax: 32_000, client: "test" } as any,
  541. isWorkflow: false,
  542. }),
  543. )
  544. expect(result.params.options.reasoningEffort).toBe("high")
  545. expect(result.params.options.reasoningSummary).toBeUndefined()
  546. expect(result.params.options.include).toBeUndefined()
  547. expect(result.tools.lookup.strict).toBe(false)
  548. })
  549. test("gpt-5.1 should have textVerbosity set to low", () => {
  550. const model = createGpt5Model("gpt-5.1")
  551. const result = ProviderTransform.options({ model, sessionID, providerOptions: {} })
  552. expect(result.textVerbosity).toBe("low")
  553. })
  554. test("gpt-5.2-chat-latest should NOT have textVerbosity set (only supports medium)", () => {
  555. const model = createGpt5Model("gpt-5.2-chat-latest")
  556. const result = ProviderTransform.options({ model, sessionID, providerOptions: {} })
  557. expect(result.textVerbosity).toBeUndefined()
  558. })
  559. test("gpt-5.1-chat-latest should NOT have textVerbosity set (only supports medium)", () => {
  560. const model = createGpt5Model("gpt-5.1-chat-latest")
  561. const result = ProviderTransform.options({ model, sessionID, providerOptions: {} })
  562. expect(result.textVerbosity).toBeUndefined()
  563. })
  564. test("gpt-5.2-chat should NOT have textVerbosity set", () => {
  565. const model = createGpt5Model("gpt-5.2-chat")
  566. const result = ProviderTransform.options({ model, sessionID, providerOptions: {} })
  567. expect(result.textVerbosity).toBeUndefined()
  568. })
  569. test("gpt-5-chat should NOT have textVerbosity set", () => {
  570. const model = createGpt5Model("gpt-5-chat")
  571. const result = ProviderTransform.options({ model, sessionID, providerOptions: {} })
  572. expect(result.textVerbosity).toBeUndefined()
  573. })
  574. test("gpt-5.2-codex should NOT have textVerbosity set (codex models excluded)", () => {
  575. const model = createGpt5Model("gpt-5.2-codex")
  576. const result = ProviderTransform.options({ model, sessionID, providerOptions: {} })
  577. expect(result.textVerbosity).toBeUndefined()
  578. })
  579. })
  580. describe("ProviderTransform.options - gpt-5 reasoningEffort", () => {
  581. const sessionID = "test-session-123"
  582. const createModel = (apiId: string) =>
  583. ({
  584. id: `azure/${apiId}`,
  585. providerID: "azure",
  586. api: {
  587. id: apiId,
  588. url: "https://azure.com",
  589. npm: "@ai-sdk/azure",
  590. },
  591. name: apiId,
  592. capabilities: {
  593. temperature: true,
  594. reasoning: true,
  595. attachment: true,
  596. toolcall: true,
  597. input: {
  598. text: true,
  599. audio: false,
  600. image: true,
  601. video: false,
  602. pdf: false,
  603. },
  604. output: {
  605. text: true,
  606. audio: false,
  607. image: false,
  608. video: false,
  609. pdf: false,
  610. },
  611. interleaved: false,
  612. },
  613. cost: {
  614. input: 0.03,
  615. output: 0.06,
  616. cache: { read: 0.001, write: 0.002 },
  617. },
  618. limit: {
  619. context: 128000,
  620. output: 4096,
  621. },
  622. status: "active",
  623. options: {},
  624. headers: {},
  625. }) as any
  626. test("gpt-5-chat should NOT set reasoningEffort", () => {
  627. const result = ProviderTransform.options({
  628. model: createModel("gpt-5-chat"),
  629. sessionID,
  630. providerOptions: {},
  631. })
  632. expect(result.reasoningEffort).toBeUndefined()
  633. })
  634. test("gpt-5.5 should NOT set reasoningEffort", () => {
  635. const result = ProviderTransform.options({
  636. model: createModel("gpt-5.5"),
  637. sessionID,
  638. providerOptions: {},
  639. })
  640. expect(result.reasoningEffort).toBeUndefined()
  641. })
  642. })
  643. describe("ProviderTransform.options - gateway", () => {
  644. const sessionID = "test-session-123"
  645. const createModel = (id: string) =>
  646. ({
  647. id,
  648. providerID: "vercel",
  649. api: {
  650. id,
  651. url: "https://ai-gateway.vercel.sh/v3/ai",
  652. npm: "@ai-sdk/gateway",
  653. },
  654. name: id,
  655. capabilities: {
  656. temperature: true,
  657. reasoning: true,
  658. attachment: true,
  659. toolcall: true,
  660. input: { text: true, audio: false, image: true, video: false, pdf: true },
  661. output: { text: true, audio: false, image: false, video: false, pdf: false },
  662. interleaved: false,
  663. },
  664. cost: {
  665. input: 0.001,
  666. output: 0.002,
  667. cache: { read: 0.0001, write: 0.0002 },
  668. },
  669. limit: {
  670. context: 200_000,
  671. output: 8192,
  672. },
  673. status: "active",
  674. options: {},
  675. headers: {},
  676. release_date: "2024-01-01",
  677. }) as any
  678. test("puts gateway defaults under gateway key", () => {
  679. const model = createModel("anthropic/claude-sonnet-4")
  680. const result = ProviderTransform.options({ model, sessionID, providerOptions: {} })
  681. expect(result).toEqual({
  682. gateway: {
  683. caching: "auto",
  684. },
  685. })
  686. })
  687. })
  688. describe("ProviderTransform.providerOptions", () => {
  689. const createModel = (overrides: Partial<any> = {}) =>
  690. ({
  691. id: "test/test-model",
  692. providerID: "test",
  693. api: {
  694. id: "test-model",
  695. url: "https://api.test.com",
  696. npm: "@ai-sdk/openai",
  697. },
  698. name: "Test Model",
  699. capabilities: {
  700. temperature: true,
  701. reasoning: true,
  702. attachment: true,
  703. toolcall: true,
  704. input: { text: true, audio: false, image: true, video: false, pdf: false },
  705. output: { text: true, audio: false, image: false, video: false, pdf: false },
  706. interleaved: false,
  707. },
  708. cost: {
  709. input: 0.001,
  710. output: 0.002,
  711. cache: { read: 0.0001, write: 0.0002 },
  712. },
  713. limit: {
  714. context: 200_000,
  715. output: 64_000,
  716. },
  717. status: "active",
  718. options: {},
  719. headers: {},
  720. release_date: "2024-01-01",
  721. ...overrides,
  722. }) as any
  723. test("uses sdk key for non-gateway models", () => {
  724. const model = createModel({
  725. providerID: "my-bedrock",
  726. api: {
  727. id: "anthropic.claude-sonnet-4",
  728. url: "https://bedrock.aws",
  729. npm: "@ai-sdk/amazon-bedrock",
  730. },
  731. })
  732. expect(ProviderTransform.providerOptions(model, { cachePoint: { type: "default" } })).toEqual({
  733. bedrock: { cachePoint: { type: "default" } },
  734. })
  735. })
  736. test("forces reasoning for custom OpenAI package models with explicit effort", () => {
  737. const model = createModel({
  738. providerID: "meta",
  739. api: {
  740. id: "muse-spark",
  741. url: "https://api.ai.meta.com/v1",
  742. npm: "@ai-sdk/openai",
  743. },
  744. })
  745. expect(ProviderTransform.providerOptions(model, { reasoningEffort: "xhigh", reasoningSummary: "auto" })).toEqual({
  746. openai: { forceReasoning: true, reasoningEffort: "xhigh", reasoningSummary: "auto" },
  747. })
  748. })
  749. test("forces reasoning for OpenAI package models marked reasoning-capable", () => {
  750. expect(ProviderTransform.providerOptions(createModel(), { store: false })).toEqual({
  751. openai: { forceReasoning: true, store: false },
  752. })
  753. })
  754. test("uses canonical sdk key for custom xAI models", () => {
  755. const model = createModel({
  756. providerID: "my-xai",
  757. api: { id: "grok-4", url: "https://api.x.ai", npm: "@ai-sdk/xai" },
  758. })
  759. expect(ProviderTransform.providerOptions(model, { promptCacheKey: "session" })).toEqual({
  760. xai: { promptCacheKey: "session" },
  761. })
  762. })
  763. test("forces reasoning for explicit effort even when model is not marked reasoning-capable", () => {
  764. const model = createModel({
  765. capabilities: {
  766. temperature: true,
  767. reasoning: false,
  768. attachment: true,
  769. toolcall: true,
  770. input: { text: true, audio: false, image: true, video: false, pdf: false },
  771. output: { text: true, audio: false, image: false, video: false, pdf: false },
  772. interleaved: false,
  773. },
  774. })
  775. expect(ProviderTransform.providerOptions(model, { reasoningEffort: "xhigh" })).toEqual({
  776. openai: { forceReasoning: true, reasoningEffort: "xhigh" },
  777. })
  778. })
  779. test("forces reasoning for Azure OpenAI models with explicit effort", () => {
  780. const model = createModel({
  781. providerID: "azure",
  782. api: {
  783. id: "custom-gpt-5-deployment",
  784. url: "https://azure.openai.example.com/openai/v1",
  785. npm: "@ai-sdk/azure",
  786. },
  787. })
  788. expect(ProviderTransform.providerOptions(model, { reasoningEffort: "xhigh" })).toEqual({
  789. openai: { forceReasoning: true, reasoningEffort: "xhigh" },
  790. azure: { forceReasoning: true, reasoningEffort: "xhigh" },
  791. })
  792. })
  793. test("forces reasoning for Bedrock Mantle OpenAI models with explicit effort", () => {
  794. const model = createModel({
  795. providerID: "amazon-bedrock",
  796. api: {
  797. id: "openai.gpt-5-custom",
  798. url: "https://bedrock-mantle.us-east-2.api.aws/openai/v1",
  799. npm: "@ai-sdk/amazon-bedrock/mantle",
  800. },
  801. })
  802. expect(ProviderTransform.providerOptions(model, { reasoningEffort: "xhigh" })).toEqual({
  803. openai: { forceReasoning: true, reasoningEffort: "xhigh" },
  804. })
  805. })
  806. test("overrides forceReasoning false when reasoning should be forced", () => {
  807. expect(
  808. ProviderTransform.providerOptions(createModel(), { forceReasoning: false, reasoningEffort: "xhigh" }),
  809. ).toEqual({
  810. openai: { forceReasoning: true, reasoningEffort: "xhigh" },
  811. })
  812. })
  813. test("uses gateway model provider slug for gateway models", () => {
  814. const model = createModel({
  815. providerID: "vercel",
  816. api: {
  817. id: "anthropic/claude-sonnet-4",
  818. url: "https://ai-gateway.vercel.sh/v3/ai",
  819. npm: "@ai-sdk/gateway",
  820. },
  821. })
  822. expect(ProviderTransform.providerOptions(model, { thinking: { type: "enabled", budgetTokens: 12_000 } })).toEqual({
  823. anthropic: { thinking: { type: "enabled", budgetTokens: 12_000 } },
  824. })
  825. })
  826. test("falls back to gateway key when gateway api id is unscoped", () => {
  827. const model = createModel({
  828. id: "anthropic/claude-sonnet-4",
  829. providerID: "vercel",
  830. api: {
  831. id: "claude-sonnet-4",
  832. url: "https://ai-gateway.vercel.sh/v3/ai",
  833. npm: "@ai-sdk/gateway",
  834. },
  835. })
  836. expect(ProviderTransform.providerOptions(model, { thinking: { type: "enabled", budgetTokens: 12_000 } })).toEqual({
  837. gateway: { thinking: { type: "enabled", budgetTokens: 12_000 } },
  838. })
  839. })
  840. test("splits gateway routing options from provider-specific options", () => {
  841. const model = createModel({
  842. providerID: "vercel",
  843. api: {
  844. id: "anthropic/claude-sonnet-4",
  845. url: "https://ai-gateway.vercel.sh/v3/ai",
  846. npm: "@ai-sdk/gateway",
  847. },
  848. })
  849. expect(
  850. ProviderTransform.providerOptions(model, {
  851. gateway: { order: ["vertex", "anthropic"] },
  852. thinking: { type: "enabled", budgetTokens: 12_000 },
  853. }),
  854. ).toEqual({
  855. gateway: { order: ["vertex", "anthropic"] },
  856. anthropic: { thinking: { type: "enabled", budgetTokens: 12_000 } },
  857. } as any)
  858. })
  859. test("falls back to gateway key when model id has no provider slug", () => {
  860. const model = createModel({
  861. id: "claude-sonnet-4",
  862. providerID: "vercel",
  863. api: {
  864. id: "claude-sonnet-4",
  865. url: "https://ai-gateway.vercel.sh/v3/ai",
  866. npm: "@ai-sdk/gateway",
  867. },
  868. })
  869. expect(ProviderTransform.providerOptions(model, { reasoningEffort: "high" })).toEqual({
  870. gateway: { reasoningEffort: "high" },
  871. })
  872. })
  873. test("maps amazon slug to bedrock for provider options", () => {
  874. const model = createModel({
  875. providerID: "vercel",
  876. api: {
  877. id: "amazon/nova-2-lite",
  878. url: "https://ai-gateway.vercel.sh/v3/ai",
  879. npm: "@ai-sdk/gateway",
  880. },
  881. })
  882. expect(ProviderTransform.providerOptions(model, { reasoningConfig: { type: "enabled" } })).toEqual({
  883. bedrock: { reasoningConfig: { type: "enabled" } },
  884. })
  885. })
  886. test("maps Bedrock Mantle provider options to OpenAI namespace", () => {
  887. const model = createModel({
  888. providerID: "amazon-bedrock",
  889. api: {
  890. id: "openai.gpt-5.5",
  891. url: "https://bedrock-mantle.us-east-2.api.aws/openai/v1",
  892. npm: "@ai-sdk/amazon-bedrock/mantle",
  893. },
  894. })
  895. expect(ProviderTransform.providerOptions(model, { reasoningEffort: "medium" })).toEqual({
  896. openai: { forceReasoning: true, reasoningEffort: "medium" },
  897. })
  898. })
  899. test("uses groq slug for groq models", () => {
  900. const model = createModel({
  901. providerID: "vercel",
  902. api: {
  903. id: "groq/llama-3.3-70b-versatile",
  904. url: "https://ai-gateway.vercel.sh/v3/ai",
  905. npm: "@ai-sdk/gateway",
  906. },
  907. })
  908. expect(ProviderTransform.providerOptions(model, { reasoningFormat: "parsed" })).toEqual({
  909. groq: { reasoningFormat: "parsed" },
  910. })
  911. })
  912. })
  913. describe("ProviderTransform.schema - gemini array items", () => {
  914. test("adds missing items for array properties", () => {
  915. const geminiModel = {
  916. providerID: "google",
  917. api: {
  918. id: "gemini-3-pro",
  919. },
  920. } as any
  921. const schema = {
  922. type: "object",
  923. properties: {
  924. nodes: { type: "array" },
  925. edges: { type: "array", items: { type: "string" } },
  926. },
  927. } as any
  928. const result = ProviderTransform.schema(geminiModel, schema) as any
  929. expect(result.properties.nodes.items).toBeDefined()
  930. expect(result.properties.edges.items.type).toBe("string")
  931. })
  932. })
  933. describe("ProviderTransform.schema - gemini nested array items", () => {
  934. const geminiModel = {
  935. providerID: "google",
  936. api: {
  937. id: "gemini-3-pro",
  938. },
  939. } as any
  940. test("adds type to 2D array with empty inner items", () => {
  941. const schema = {
  942. type: "object",
  943. properties: {
  944. values: {
  945. type: "array",
  946. items: {
  947. type: "array",
  948. items: {}, // Empty items object
  949. },
  950. },
  951. },
  952. } as any
  953. const result = ProviderTransform.schema(geminiModel, schema) as any
  954. // Inner items should have a default type
  955. expect(result.properties.values.items.items.type).toBe("string")
  956. })
  957. test("adds items and type to 2D array with missing inner items", () => {
  958. const schema = {
  959. type: "object",
  960. properties: {
  961. data: {
  962. type: "array",
  963. items: { type: "array" }, // No items at all
  964. },
  965. },
  966. } as any
  967. const result = ProviderTransform.schema(geminiModel, schema) as any
  968. expect(result.properties.data.items.items).toBeDefined()
  969. expect(result.properties.data.items.items.type).toBe("string")
  970. })
  971. test("handles deeply nested arrays (3D)", () => {
  972. const schema = {
  973. type: "object",
  974. properties: {
  975. matrix: {
  976. type: "array",
  977. items: {
  978. type: "array",
  979. items: {
  980. type: "array",
  981. // No items
  982. },
  983. },
  984. },
  985. },
  986. } as any
  987. const result = ProviderTransform.schema(geminiModel, schema) as any
  988. expect(result.properties.matrix.items.items.items).toBeDefined()
  989. expect(result.properties.matrix.items.items.items.type).toBe("string")
  990. })
  991. test("preserves existing item types in nested arrays", () => {
  992. const schema = {
  993. type: "object",
  994. properties: {
  995. numbers: {
  996. type: "array",
  997. items: {
  998. type: "array",
  999. items: { type: "number" }, // Has explicit type
  1000. },
  1001. },
  1002. },
  1003. } as any
  1004. const result = ProviderTransform.schema(geminiModel, schema) as any
  1005. // Should preserve the explicit type
  1006. expect(result.properties.numbers.items.items.type).toBe("number")
  1007. })
  1008. test("handles mixed nested structures with objects and arrays", () => {
  1009. const schema = {
  1010. type: "object",
  1011. properties: {
  1012. spreadsheetData: {
  1013. type: "object",
  1014. properties: {
  1015. rows: {
  1016. type: "array",
  1017. items: {
  1018. type: "array",
  1019. items: {}, // Empty items
  1020. },
  1021. },
  1022. },
  1023. },
  1024. },
  1025. } as any
  1026. const result = ProviderTransform.schema(geminiModel, schema) as any
  1027. expect(result.properties.spreadsheetData.properties.rows.items.items.type).toBe("string")
  1028. })
  1029. })
  1030. describe("ProviderTransform.schema - gemini type arrays", () => {
  1031. // Mirrors @ai-sdk/google's convertJSONSchemaToOpenAPISchema: JSON Schema type
  1032. // arrays (e.g. `["number","string"]`, common in MCP tool schemas) become an
  1033. // `anyOf` of single-type schemas, with `null` lifted into `nullable`. Plain
  1034. // @ai-sdk/google rewrites these, but OpenAI-compatible transports such as
  1035. // GitHub Copilot (proxying to Gemini) forward them verbatim and the backend
  1036. // rejects the array form.
  1037. const geminiModel = {
  1038. providerID: "google",
  1039. api: {
  1040. id: "gemini-3-pro",
  1041. },
  1042. } as any
  1043. test("splits a multi-type array into anyOf and drops the type array", () => {
  1044. const schema = {
  1045. type: "object",
  1046. properties: {
  1047. status: { type: ["number", "string"], description: "status filter" },
  1048. },
  1049. } as any
  1050. const result = ProviderTransform.schema(geminiModel, schema) as any
  1051. expect(result.properties.status.type).toBeUndefined()
  1052. expect(result.properties.status.anyOf).toEqual([{ type: "number" }, { type: "string" }])
  1053. expect(result.properties.status.nullable).toBeUndefined()
  1054. // Sibling keywords stay alongside the generated anyOf.
  1055. expect(result.properties.status.description).toBe("status filter")
  1056. })
  1057. test("lifts null into nullable for a nullable type array", () => {
  1058. const schema = {
  1059. type: "object",
  1060. properties: {
  1061. maybe: { type: ["string", "null"], description: "nullable string" },
  1062. },
  1063. } as any
  1064. const result = ProviderTransform.schema(geminiModel, schema) as any
  1065. expect(result.properties.maybe.type).toBeUndefined()
  1066. expect(result.properties.maybe.anyOf).toEqual([{ type: "string" }])
  1067. expect(result.properties.maybe.nullable).toBe(true)
  1068. })
  1069. test("collapses an all-null type array to type null", () => {
  1070. const schema = {
  1071. type: "object",
  1072. properties: {
  1073. nothing: { type: ["null"] },
  1074. },
  1075. } as any
  1076. const result = ProviderTransform.schema(geminiModel, schema) as any
  1077. expect(result.properties.nothing.type).toBe("null")
  1078. expect(result.properties.nothing.anyOf).toBeUndefined()
  1079. })
  1080. test("rewrites type arrays for gemini served through github-copilot", () => {
  1081. const copilotGeminiModel = {
  1082. providerID: "github-copilot",
  1083. api: {
  1084. id: "gemini-3.5-flash",
  1085. npm: "@ai-sdk/github-copilot",
  1086. },
  1087. } as any
  1088. const schema = {
  1089. type: "object",
  1090. properties: {
  1091. hook_id: { type: "number", description: "ID of the webhook" },
  1092. status: { type: ["number", "string"], description: "Filter by response status code" },
  1093. },
  1094. required: ["hook_id"],
  1095. additionalProperties: false,
  1096. } as any
  1097. const result = ProviderTransform.schema(copilotGeminiModel, schema) as any
  1098. expect(result.properties.status.anyOf).toEqual([{ type: "number" }, { type: "string" }])
  1099. expect(result.properties.status.type).toBeUndefined()
  1100. expect(result.properties.hook_id.type).toBe("number")
  1101. })
  1102. })
  1103. describe("ProviderTransform.schema - gemini combiner nodes", () => {
  1104. const geminiModel = {
  1105. providerID: "google",
  1106. api: {
  1107. id: "gemini-3-pro",
  1108. },
  1109. } as any
  1110. const walk = (node: any, cb: (node: any, path: (string | number)[]) => void, path: (string | number)[] = []) => {
  1111. if (node === null || typeof node !== "object") {
  1112. return
  1113. }
  1114. if (Array.isArray(node)) {
  1115. node.forEach((item, i) => walk(item, cb, [...path, i]))
  1116. return
  1117. }
  1118. cb(node, path)
  1119. Object.entries(node).forEach(([key, value]) => walk(value, cb, [...path, key]))
  1120. }
  1121. test("keeps edits.items.anyOf without adding type", () => {
  1122. const schema = {
  1123. type: "object",
  1124. properties: {
  1125. edits: {
  1126. type: "array",
  1127. items: {
  1128. anyOf: [
  1129. {
  1130. type: "object",
  1131. properties: {
  1132. old_string: { type: "string" },
  1133. new_string: { type: "string" },
  1134. },
  1135. required: ["old_string", "new_string"],
  1136. },
  1137. {
  1138. type: "object",
  1139. properties: {
  1140. old_string: { type: "string" },
  1141. new_string: { type: "string" },
  1142. replace_all: { type: "boolean" },
  1143. },
  1144. required: ["old_string", "new_string"],
  1145. },
  1146. ],
  1147. },
  1148. },
  1149. },
  1150. required: ["edits"],
  1151. } as any
  1152. const result = ProviderTransform.schema(geminiModel, schema) as any
  1153. expect(Array.isArray(result.properties.edits.items.anyOf)).toBe(true)
  1154. expect(result.properties.edits.items.type).toBeUndefined()
  1155. })
  1156. test("does not add sibling keys to combiner nodes during sanitize", () => {
  1157. const schema = {
  1158. type: "object",
  1159. properties: {
  1160. edits: {
  1161. type: "array",
  1162. items: {
  1163. anyOf: [{ type: "string" }, { type: "number" }],
  1164. },
  1165. },
  1166. value: {
  1167. oneOf: [{ type: "string" }, { type: "boolean" }],
  1168. },
  1169. meta: {
  1170. allOf: [
  1171. {
  1172. type: "object",
  1173. properties: { a: { type: "string" } },
  1174. },
  1175. {
  1176. type: "object",
  1177. properties: { b: { type: "string" } },
  1178. },
  1179. ],
  1180. },
  1181. },
  1182. } as any
  1183. const input = JSON.parse(JSON.stringify(schema))
  1184. const result = ProviderTransform.schema(geminiModel, schema) as any
  1185. walk(result, (node, path) => {
  1186. const hasCombiner = Array.isArray(node.anyOf) || Array.isArray(node.oneOf) || Array.isArray(node.allOf)
  1187. if (!hasCombiner) {
  1188. return
  1189. }
  1190. const before = path.reduce((acc: any, key) => acc?.[key], input)
  1191. const added = Object.keys(node).filter((key) => !(key in before))
  1192. expect(added).toEqual([])
  1193. })
  1194. })
  1195. })
  1196. describe("ProviderTransform.schema - gemini non-object properties removal", () => {
  1197. const geminiModel = {
  1198. providerID: "google",
  1199. api: {
  1200. id: "gemini-3-pro",
  1201. },
  1202. } as any
  1203. test("removes properties from non-object types", () => {
  1204. const schema = {
  1205. type: "object",
  1206. properties: {
  1207. data: {
  1208. type: "string",
  1209. properties: { invalid: { type: "string" } },
  1210. },
  1211. },
  1212. } as any
  1213. const result = ProviderTransform.schema(geminiModel, schema) as any
  1214. expect(result.properties.data.type).toBe("string")
  1215. expect(result.properties.data.properties).toBeUndefined()
  1216. })
  1217. test("removes required from non-object types", () => {
  1218. const schema = {
  1219. type: "object",
  1220. properties: {
  1221. data: {
  1222. type: "array",
  1223. items: { type: "string" },
  1224. required: ["invalid"],
  1225. },
  1226. },
  1227. } as any
  1228. const result = ProviderTransform.schema(geminiModel, schema) as any
  1229. expect(result.properties.data.type).toBe("array")
  1230. expect(result.properties.data.required).toBeUndefined()
  1231. })
  1232. test("removes properties and required from nested non-object types", () => {
  1233. const schema = {
  1234. type: "object",
  1235. properties: {
  1236. outer: {
  1237. type: "object",
  1238. properties: {
  1239. inner: {
  1240. type: "number",
  1241. properties: { bad: { type: "string" } },
  1242. required: ["bad"],
  1243. },
  1244. },
  1245. },
  1246. },
  1247. } as any
  1248. const result = ProviderTransform.schema(geminiModel, schema) as any
  1249. expect(result.properties.outer.properties.inner.type).toBe("number")
  1250. expect(result.properties.outer.properties.inner.properties).toBeUndefined()
  1251. expect(result.properties.outer.properties.inner.required).toBeUndefined()
  1252. })
  1253. test("keeps properties and required on object types", () => {
  1254. const schema = {
  1255. type: "object",
  1256. properties: {
  1257. data: {
  1258. type: "object",
  1259. properties: { name: { type: "string" } },
  1260. required: ["name"],
  1261. },
  1262. },
  1263. } as any
  1264. const result = ProviderTransform.schema(geminiModel, schema) as any
  1265. expect(result.properties.data.type).toBe("object")
  1266. expect(result.properties.data.properties).toBeDefined()
  1267. expect(result.properties.data.required).toEqual(["name"])
  1268. })
  1269. test("does not affect non-gemini providers", () => {
  1270. const openaiModel = {
  1271. providerID: "openai",
  1272. api: {
  1273. id: "gpt-4",
  1274. },
  1275. } as any
  1276. const schema = {
  1277. type: "object",
  1278. properties: {
  1279. data: {
  1280. type: "string",
  1281. properties: { invalid: { type: "string" } },
  1282. },
  1283. },
  1284. } as any
  1285. const result = ProviderTransform.schema(openaiModel, schema) as any
  1286. expect(result.properties.data.properties).toBeDefined()
  1287. })
  1288. })
  1289. describe("ProviderTransform.schema - openai supported schema subset", () => {
  1290. const openaiModel = {
  1291. providerID: "openai",
  1292. api: {
  1293. id: "gpt-4.1",
  1294. npm: "@ai-sdk/openai",
  1295. },
  1296. } as any
  1297. test("removes unsupported JSON Schema keywords recursively", () => {
  1298. const result = ProviderTransform.schema(openaiModel, {
  1299. $schema: "https://json-schema.org/draft/2020-12/schema",
  1300. title: "Search",
  1301. type: "object",
  1302. properties: {
  1303. query: {
  1304. type: "string",
  1305. description: "Search query",
  1306. format: "uri",
  1307. pattern: "^https://",
  1308. minLength: 1,
  1309. maxLength: 100,
  1310. default: "https://example.com",
  1311. },
  1312. count: {
  1313. type: "integer",
  1314. minimum: 1,
  1315. maximum: 10,
  1316. multipleOf: 1,
  1317. },
  1318. createdAt: {
  1319. format: "date-time",
  1320. },
  1321. mode: {
  1322. const: "fast",
  1323. },
  1324. tags: {
  1325. type: "array",
  1326. minItems: 1,
  1327. maxItems: 3,
  1328. uniqueItems: true,
  1329. },
  1330. tuple: {
  1331. type: "array",
  1332. items: [
  1333. { type: "number", minimum: 0 },
  1334. { type: "string", pattern: "^ok$" },
  1335. ],
  1336. },
  1337. metadata: {
  1338. type: "object",
  1339. patternProperties: {
  1340. "^x-": { type: "string" },
  1341. },
  1342. additionalProperties: {
  1343. type: "string",
  1344. pattern: "^safe$",
  1345. },
  1346. },
  1347. },
  1348. patternProperties: {
  1349. "^extra": { type: "string" },
  1350. },
  1351. required: ["query"],
  1352. additionalProperties: false,
  1353. } as any) as any
  1354. expect(result).toEqual({
  1355. type: "object",
  1356. properties: {
  1357. query: {
  1358. type: "string",
  1359. description: "Search query",
  1360. },
  1361. count: {
  1362. type: "integer",
  1363. },
  1364. createdAt: {
  1365. type: "string",
  1366. },
  1367. mode: {
  1368. enum: ["fast"],
  1369. type: "string",
  1370. },
  1371. tags: {
  1372. type: "array",
  1373. items: { type: "string" },
  1374. },
  1375. tuple: {
  1376. type: "array",
  1377. items: [{ type: "number" }, { type: "string" }],
  1378. },
  1379. metadata: {
  1380. type: "object",
  1381. properties: {},
  1382. additionalProperties: {
  1383. type: "string",
  1384. },
  1385. },
  1386. },
  1387. required: ["query"],
  1388. additionalProperties: false,
  1389. })
  1390. })
  1391. test("keeps local references and sanitizes definitions", () => {
  1392. const result = ProviderTransform.schema(openaiModel, {
  1393. type: "object",
  1394. properties: {
  1395. value: {
  1396. $ref: "#/$defs/Value",
  1397. description: "Referenced value",
  1398. examples: ["ignored"],
  1399. },
  1400. },
  1401. $defs: {
  1402. Value: {
  1403. type: "string",
  1404. pattern: "^value$",
  1405. description: "Definition description",
  1406. },
  1407. Unused: {
  1408. type: "number",
  1409. minimum: 0,
  1410. },
  1411. },
  1412. } as any) as any
  1413. expect(result.properties.value).toEqual({
  1414. $ref: "#/$defs/Value",
  1415. description: "Referenced value",
  1416. })
  1417. expect(result.$defs).toEqual({
  1418. Value: {
  1419. type: "string",
  1420. description: "Definition description",
  1421. },
  1422. Unused: {
  1423. type: "number",
  1424. },
  1425. })
  1426. })
  1427. test("does not sanitize non-openai providers", () => {
  1428. const result = ProviderTransform.schema(
  1429. {
  1430. providerID: "anthropic",
  1431. api: {
  1432. id: "claude-sonnet-4",
  1433. npm: "@ai-sdk/anthropic",
  1434. },
  1435. } as any,
  1436. {
  1437. type: "object",
  1438. properties: {
  1439. query: {
  1440. type: "string",
  1441. pattern: "^https://",
  1442. },
  1443. },
  1444. } as any,
  1445. ) as any
  1446. expect(result.properties.query.pattern).toBe("^https://")
  1447. })
  1448. test.each([
  1449. ["opencode", "@ai-sdk/openai"],
  1450. ["custom-openai-compatible", "@ai-sdk/openai"],
  1451. ["azure", "@ai-sdk/azure"],
  1452. ])("sanitizes %s models using %s", (providerID, npm) => {
  1453. expect(
  1454. ProviderTransform.schema(
  1455. {
  1456. providerID,
  1457. api: {
  1458. id: "custom-model",
  1459. npm,
  1460. },
  1461. } as any,
  1462. {
  1463. type: "object",
  1464. properties: {
  1465. query: {
  1466. type: "string",
  1467. pattern: "^https://",
  1468. },
  1469. },
  1470. } as any,
  1471. ),
  1472. ).toEqual({
  1473. type: "object",
  1474. properties: {
  1475. query: {
  1476. type: "string",
  1477. },
  1478. },
  1479. })
  1480. })
  1481. })
  1482. describe("ProviderTransform.schema - moonshot $ref siblings", () => {
  1483. const moonshotModel = {
  1484. providerID: "moonshotai",
  1485. api: {
  1486. id: "kimi-k2",
  1487. },
  1488. } as any
  1489. test("removes sibling descriptions from referenced tool parameter schemas", () => {
  1490. const schema = {
  1491. type: "object",
  1492. properties: {
  1493. deviceType: {
  1494. description: "Optional. The type of device that captured the screenshot, e.g. mobile or desktop.",
  1495. enum: ["DEVICE_TYPE_UNSPECIFIED", "MOBILE", "DESKTOP", "TABLET", "AGNOSTIC"],
  1496. type: "string",
  1497. },
  1498. modelId: {
  1499. description: "Optional. The model to use for generation.",
  1500. enum: ["MODEL_ID_UNSPECIFIED", "GEMINI_3_PRO", "GEMINI_3_FLASH", "GEMINI_3_1_PRO"],
  1501. type: "string",
  1502. },
  1503. projectId: {
  1504. description: "Required. The project ID of screens to generate variants for.",
  1505. type: "string",
  1506. },
  1507. prompt: {
  1508. description: "Required. The input text used to generate the variants.",
  1509. type: "string",
  1510. },
  1511. selectedScreenIds: {
  1512. description: "Required. The screen ids of screen to generate variants for.",
  1513. items: {
  1514. type: "string",
  1515. },
  1516. type: "array",
  1517. },
  1518. variantOptions: {
  1519. $ref: "#/$defs/VariantOptions",
  1520. description:
  1521. "Required. The variant options for generation, including the number of variants, creative range, and aspects to focus on.",
  1522. },
  1523. },
  1524. required: ["projectId", "selectedScreenIds", "prompt", "variantOptions"],
  1525. $defs: {
  1526. VariantOptions: {
  1527. description:
  1528. "Configuration options for design variant generation. This message captures all parameters used to generate variants, allowing the configuration to be stored, replayed, or analyzed.",
  1529. properties: {
  1530. aspects: {
  1531. description: "Optional. Specific aspects to focus on. If empty, all aspects may be varied.",
  1532. items: {
  1533. enum: ["VARIANT_ASPECT_UNSPECIFIED", "LAYOUT", "COLOR_SCHEME", "IMAGES", "TEXT_FONT", "TEXT_CONTENT"],
  1534. type: "string",
  1535. },
  1536. type: "array",
  1537. },
  1538. creativeRange: {
  1539. description: "Optional. Creative range for variations. Default: EXPLORE",
  1540. enum: ["CREATIVE_RANGE_UNSPECIFIED", "REFINE", "EXPLORE", "REIMAGINE"],
  1541. type: "string",
  1542. },
  1543. variantCount: {
  1544. description: "Optional. Number of variants to generate (1-5). Default: 3",
  1545. format: "int32",
  1546. type: "integer",
  1547. },
  1548. },
  1549. type: "object",
  1550. },
  1551. },
  1552. description: "Request message for GenerateVariants.",
  1553. additionalProperties: false,
  1554. } as any
  1555. const result = ProviderTransform.schema(moonshotModel, schema) as any
  1556. expect(result.properties.variantOptions).toEqual({
  1557. $ref: "#/$defs/VariantOptions",
  1558. })
  1559. expect(result.$defs.VariantOptions.description).toBe(schema.$defs.VariantOptions.description)
  1560. })
  1561. test("also runs for kimi models outside the moonshot provider", () => {
  1562. const result = ProviderTransform.schema(
  1563. {
  1564. providerID: "openrouter",
  1565. name: "Kimi K2",
  1566. api: {
  1567. id: "moonshotai/kimi-k2",
  1568. },
  1569. } as any,
  1570. {
  1571. type: "object",
  1572. properties: {
  1573. value: {
  1574. $ref: "#/$defs/Value",
  1575. description: "Moonshot rejects this sibling after ref expansion.",
  1576. },
  1577. },
  1578. $defs: {
  1579. Value: {
  1580. description: "Referenced schema description stays here.",
  1581. type: "object",
  1582. },
  1583. },
  1584. } as any,
  1585. ) as any
  1586. expect(result.properties.value).toEqual({
  1587. $ref: "#/$defs/Value",
  1588. })
  1589. })
  1590. test("converts tuple-style array items to a single item schema", () => {
  1591. const result = ProviderTransform.schema(moonshotModel, {
  1592. type: "object",
  1593. properties: {
  1594. codeSpec: {
  1595. type: "object",
  1596. properties: {
  1597. accessibility: {
  1598. type: "object",
  1599. properties: {
  1600. renderedSize: {
  1601. description: "Rendered size [width, height] in px",
  1602. type: "array",
  1603. items: [{ type: "number" }, { type: "number" }],
  1604. minItems: 2,
  1605. maxItems: 2,
  1606. },
  1607. },
  1608. },
  1609. },
  1610. },
  1611. },
  1612. } as any) as any
  1613. expect(result.properties.codeSpec.properties.accessibility.properties.renderedSize.items).toEqual({
  1614. type: "number",
  1615. })
  1616. })
  1617. })
  1618. describe("ProviderTransform.message - Mistral tool call IDs", () => {
  1619. test.each(["codestral-latest", "pixtral-large-latest", "open-mixtral-8x22b"])(
  1620. "normalizes IDs for custom OpenAI-compatible %s models",
  1621. (id) => {
  1622. const result = ProviderTransform.message(
  1623. [
  1624. {
  1625. role: "assistant",
  1626. content: [
  1627. {
  1628. type: "tool-call",
  1629. toolCallId: "toolu_01CBhTTz95qkd9LJMdC9sf8t",
  1630. toolName: "read",
  1631. input: { filePath: "/tmp/test" },
  1632. },
  1633. ],
  1634. },
  1635. {
  1636. role: "tool",
  1637. content: [
  1638. {
  1639. type: "tool-result",
  1640. toolCallId: "toolu_01CBhTTz95qkd9LJMdC9sf8t",
  1641. toolName: "read",
  1642. output: { type: "text", value: "test" },
  1643. },
  1644. ],
  1645. },
  1646. ] as any,
  1647. {
  1648. id: `custom/${id}`,
  1649. providerID: "custom",
  1650. api: {
  1651. id,
  1652. url: "https://example.com/v1",
  1653. npm: "@ai-sdk/openai-compatible",
  1654. },
  1655. } as any,
  1656. {},
  1657. )
  1658. expect(result).toMatchObject([
  1659. { role: "assistant", content: [{ type: "tool-call", toolCallId: "toolu01CB" }] },
  1660. { role: "tool", content: [{ type: "tool-result", toolCallId: "toolu01CB" }] },
  1661. ])
  1662. },
  1663. )
  1664. })
  1665. describe("ProviderTransform.message - DeepSeek reasoning content", () => {
  1666. test("DeepSeek with tool calls includes reasoning_content in providerOptions", () => {
  1667. const msgs = [
  1668. {
  1669. role: "assistant",
  1670. content: [
  1671. { type: "reasoning", text: "Let me think about this..." },
  1672. {
  1673. type: "tool-call",
  1674. toolCallId: "test",
  1675. toolName: "bash",
  1676. input: { command: "echo hello" },
  1677. },
  1678. ],
  1679. },
  1680. ] as any[]
  1681. const result = ProviderTransform.message(
  1682. msgs,
  1683. {
  1684. id: ModelV2.ID.make("deepseek/deepseek-chat"),
  1685. providerID: ProviderV2.ID.make("deepseek"),
  1686. api: {
  1687. id: "deepseek-chat",
  1688. url: "https://api.deepseek.com",
  1689. npm: "@ai-sdk/openai-compatible",
  1690. },
  1691. name: "DeepSeek Chat",
  1692. capabilities: {
  1693. temperature: true,
  1694. reasoning: true,
  1695. attachment: false,
  1696. toolcall: true,
  1697. input: { text: true, audio: false, image: false, video: false, pdf: false },
  1698. output: { text: true, audio: false, image: false, video: false, pdf: false },
  1699. interleaved: {
  1700. field: "reasoning_content",
  1701. },
  1702. },
  1703. cost: {
  1704. input: 0.001,
  1705. output: 0.002,
  1706. cache: { read: 0.0001, write: 0.0002 },
  1707. },
  1708. limit: {
  1709. context: 128000,
  1710. output: 8192,
  1711. },
  1712. status: "active",
  1713. options: {},
  1714. headers: {},
  1715. release_date: "2023-04-01",
  1716. },
  1717. {},
  1718. )
  1719. expect(result).toHaveLength(1)
  1720. expect(result[0].content).toEqual([
  1721. {
  1722. type: "tool-call",
  1723. toolCallId: "test",
  1724. toolName: "bash",
  1725. input: { command: "echo hello" },
  1726. },
  1727. ])
  1728. expect(result[0].providerOptions?.openaiCompatible?.reasoning_content).toBe("Let me think about this...")
  1729. })
  1730. test("Non-DeepSeek providers leave reasoning content unchanged", () => {
  1731. const msgs = [
  1732. {
  1733. role: "assistant",
  1734. content: [
  1735. { type: "reasoning", text: "Should not be processed" },
  1736. { type: "text", text: "Answer" },
  1737. ],
  1738. },
  1739. ] as any[]
  1740. const result = ProviderTransform.message(
  1741. msgs,
  1742. {
  1743. id: ModelV2.ID.make("openai/gpt-4"),
  1744. providerID: ProviderV2.ID.make("openai"),
  1745. api: {
  1746. id: "gpt-4",
  1747. url: "https://api.openai.com",
  1748. npm: "@ai-sdk/openai",
  1749. },
  1750. name: "GPT-4",
  1751. capabilities: {
  1752. temperature: true,
  1753. reasoning: false,
  1754. attachment: true,
  1755. toolcall: true,
  1756. input: { text: true, audio: false, image: true, video: false, pdf: false },
  1757. output: { text: true, audio: false, image: false, video: false, pdf: false },
  1758. interleaved: false,
  1759. },
  1760. cost: {
  1761. input: 0.03,
  1762. output: 0.06,
  1763. cache: { read: 0.001, write: 0.002 },
  1764. },
  1765. limit: {
  1766. context: 128000,
  1767. output: 4096,
  1768. },
  1769. status: "active",
  1770. options: {},
  1771. headers: {},
  1772. release_date: "2023-04-01",
  1773. },
  1774. {},
  1775. )
  1776. expect(result[0].content).toEqual([
  1777. { type: "reasoning", text: "Should not be processed" },
  1778. { type: "text", text: "Answer" },
  1779. ])
  1780. expect(result[0].providerOptions?.openaiCompatible?.reasoning_content).toBeUndefined()
  1781. })
  1782. })
  1783. describe("ProviderTransform.message - surrogate sanitization", () => {
  1784. const model = {
  1785. id: "test/test-model",
  1786. providerID: "test",
  1787. api: {
  1788. id: "test-model",
  1789. url: "https://api.test.com",
  1790. npm: "@ai-sdk/openai-compatible",
  1791. },
  1792. name: "Test Model",
  1793. capabilities: {
  1794. temperature: true,
  1795. reasoning: true,
  1796. attachment: true,
  1797. toolcall: true,
  1798. input: { text: true, audio: false, image: true, video: false, pdf: false },
  1799. output: { text: true, audio: false, image: false, video: false, pdf: false },
  1800. interleaved: false,
  1801. },
  1802. cost: { input: 0.001, output: 0.002, cache: { read: 0.0001, write: 0.0002 } },
  1803. limit: { context: 128000, output: 8192 },
  1804. status: "active",
  1805. options: {},
  1806. headers: {},
  1807. } as any
  1808. test("replaces lone surrogates in model-visible text", () => {
  1809. const lone = "\uD83D"
  1810. const valid = "🚀"
  1811. const sanitized = "�"
  1812. const text = (label: string) => `${label} ${lone} and ${valid}`
  1813. const expected = (label: string) => `${label} ${sanitized} and ${valid}`
  1814. const msgs = [
  1815. { role: "system", content: text("system") },
  1816. { role: "user", content: text("user string") },
  1817. {
  1818. role: "user",
  1819. content: [
  1820. { type: "text", text: text("user text") },
  1821. { type: "image", image: "data:image/png;base64,abcd" },
  1822. ],
  1823. },
  1824. { role: "assistant", content: text("assistant string") },
  1825. {
  1826. role: "assistant",
  1827. content: [
  1828. { type: "text", text: text("assistant text") },
  1829. { type: "reasoning", text: text("assistant reasoning") },
  1830. { type: "tool-call", toolCallId: "call-1", toolName: "Read", input: { filePath: ".opencode/tool/emoji.ts" } },
  1831. {
  1832. type: "tool-result",
  1833. toolCallId: "call-2",
  1834. toolName: "Read",
  1835. output: { type: "text", value: text("assistant tool text") },
  1836. },
  1837. {
  1838. type: "tool-result",
  1839. toolCallId: "call-3",
  1840. toolName: "Read",
  1841. output: { type: "error-text", value: text("assistant tool error") },
  1842. },
  1843. {
  1844. type: "tool-result",
  1845. toolCallId: "call-4",
  1846. toolName: "Read",
  1847. output: { type: "content", value: [{ type: "text", text: text("assistant tool content") }] },
  1848. },
  1849. ],
  1850. },
  1851. {
  1852. role: "tool",
  1853. content: [
  1854. {
  1855. type: "tool-result",
  1856. toolCallId: "call-5",
  1857. toolName: "Read",
  1858. output: { type: "text", value: text("tool text") },
  1859. },
  1860. {
  1861. type: "tool-result",
  1862. toolCallId: "call-6",
  1863. toolName: "Read",
  1864. output: { type: "error-text", value: text("tool error") },
  1865. },
  1866. {
  1867. type: "tool-result",
  1868. toolCallId: "call-7",
  1869. toolName: "Read",
  1870. output: { type: "content", value: [{ type: "text", text: text("tool content") }] },
  1871. },
  1872. ],
  1873. },
  1874. ] as any[]
  1875. const result = ProviderTransform.message(msgs, model, {}) as any[]
  1876. expect(result[0].content).toBe(expected("system"))
  1877. expect(result[1].content).toBe(expected("user string"))
  1878. expect(result[2].content[0].text).toBe(expected("user text"))
  1879. expect(result[3].content).toBe(expected("assistant string"))
  1880. expect(result[4].content[0].text).toBe(expected("assistant text"))
  1881. expect(result[4].content[1].text).toBe(expected("assistant reasoning"))
  1882. expect(result[4].content[3].output.value).toBe(expected("assistant tool text"))
  1883. expect(result[4].content[4].output.value).toBe(expected("assistant tool error"))
  1884. expect(result[4].content[5].output.value[0].text).toBe(expected("assistant tool content"))
  1885. expect(result[5].content[0].output.value).toBe(expected("tool text"))
  1886. expect(result[5].content[1].output.value).toBe(expected("tool error"))
  1887. expect(result[5].content[2].output.value[0].text).toBe(expected("tool content"))
  1888. expect(result[2].content[1]).toEqual({ type: "image", image: "data:image/png;base64,abcd" })
  1889. })
  1890. })
  1891. describe("ProviderTransform.message - empty image handling", () => {
  1892. const mockModel = {
  1893. id: "anthropic/claude-3-5-sonnet",
  1894. providerID: "anthropic",
  1895. api: {
  1896. id: "claude-3-5-sonnet-20241022",
  1897. url: "https://api.anthropic.com",
  1898. npm: "@ai-sdk/anthropic",
  1899. },
  1900. name: "Claude 3.5 Sonnet",
  1901. capabilities: {
  1902. temperature: true,
  1903. reasoning: false,
  1904. attachment: true,
  1905. toolcall: true,
  1906. input: { text: true, audio: false, image: true, video: false, pdf: true },
  1907. output: { text: true, audio: false, image: false, video: false, pdf: false },
  1908. interleaved: false,
  1909. },
  1910. cost: {
  1911. input: 0.003,
  1912. output: 0.015,
  1913. cache: { read: 0.0003, write: 0.00375 },
  1914. },
  1915. limit: {
  1916. context: 200000,
  1917. output: 8192,
  1918. },
  1919. status: "active",
  1920. options: {},
  1921. headers: {},
  1922. } as any
  1923. test("should replace empty base64 image with error text", () => {
  1924. const msgs = [
  1925. {
  1926. role: "user",
  1927. content: [
  1928. { type: "text", text: "What is in this image?" },
  1929. { type: "image", image: "data:image/png;base64," },
  1930. ],
  1931. },
  1932. ] as any[]
  1933. const result = ProviderTransform.message(msgs, mockModel, {})
  1934. expect(result).toHaveLength(1)
  1935. expect(result[0].content).toHaveLength(2)
  1936. expect(result[0].content[0]).toEqual({ type: "text", text: "What is in this image?" })
  1937. expect(result[0].content[1]).toEqual({
  1938. type: "text",
  1939. text: "ERROR: Image file is empty or corrupted. Please provide a valid image.",
  1940. })
  1941. })
  1942. test("should keep valid base64 images unchanged", () => {
  1943. const validBase64 =
  1944. "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg=="
  1945. const msgs = [
  1946. {
  1947. role: "user",
  1948. content: [
  1949. { type: "text", text: "What is in this image?" },
  1950. { type: "image", image: `data:image/png;base64,${validBase64}` },
  1951. ],
  1952. },
  1953. ] as any[]
  1954. const result = ProviderTransform.message(msgs, mockModel, {})
  1955. expect(result).toHaveLength(1)
  1956. expect(result[0].content).toHaveLength(2)
  1957. expect(result[0].content[0]).toEqual({ type: "text", text: "What is in this image?" })
  1958. expect(result[0].content[1]).toEqual({ type: "image", image: `data:image/png;base64,${validBase64}` })
  1959. })
  1960. test("should handle mixed valid and empty images", () => {
  1961. const validBase64 =
  1962. "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg=="
  1963. const msgs = [
  1964. {
  1965. role: "user",
  1966. content: [
  1967. { type: "text", text: "Compare these images" },
  1968. { type: "image", image: `data:image/png;base64,${validBase64}` },
  1969. { type: "image", image: "data:image/jpeg;base64," },
  1970. ],
  1971. },
  1972. ] as any[]
  1973. const result = ProviderTransform.message(msgs, mockModel, {})
  1974. expect(result).toHaveLength(1)
  1975. expect(result[0].content).toHaveLength(3)
  1976. expect(result[0].content[0]).toEqual({ type: "text", text: "Compare these images" })
  1977. expect(result[0].content[1]).toEqual({ type: "image", image: `data:image/png;base64,${validBase64}` })
  1978. expect(result[0].content[2]).toEqual({
  1979. type: "text",
  1980. text: "ERROR: Image file is empty or corrupted. Please provide a valid image.",
  1981. })
  1982. })
  1983. })
  1984. describe("ProviderTransform.message - anthropic empty content filtering", () => {
  1985. const anthropicModel = {
  1986. id: "anthropic/claude-3-5-sonnet",
  1987. providerID: "anthropic",
  1988. api: {
  1989. id: "claude-3-5-sonnet-20241022",
  1990. url: "https://api.anthropic.com",
  1991. npm: "@ai-sdk/anthropic",
  1992. },
  1993. name: "Claude 3.5 Sonnet",
  1994. capabilities: {
  1995. temperature: true,
  1996. reasoning: false,
  1997. attachment: true,
  1998. toolcall: true,
  1999. input: { text: true, audio: false, image: true, video: false, pdf: true },
  2000. output: { text: true, audio: false, image: false, video: false, pdf: false },
  2001. interleaved: false,
  2002. },
  2003. cost: {
  2004. input: 0.003,
  2005. output: 0.015,
  2006. cache: { read: 0.0003, write: 0.00375 },
  2007. },
  2008. limit: {
  2009. context: 200000,
  2010. output: 8192,
  2011. },
  2012. status: "active",
  2013. options: {},
  2014. headers: {},
  2015. } as any
  2016. test("filters out messages with empty string content", () => {
  2017. const msgs = [
  2018. { role: "user", content: "Hello" },
  2019. { role: "assistant", content: "" },
  2020. { role: "user", content: "World" },
  2021. ] as any[]
  2022. const result = ProviderTransform.message(msgs, anthropicModel, {})
  2023. expect(result).toHaveLength(2)
  2024. expect(result[0].content).toBe("Hello")
  2025. expect(result[1].content).toBe("World")
  2026. })
  2027. test("filters out empty text parts from array content", () => {
  2028. const msgs = [
  2029. {
  2030. role: "assistant",
  2031. content: [
  2032. { type: "text", text: "" },
  2033. { type: "text", text: "Hello" },
  2034. { type: "text", text: "" },
  2035. ],
  2036. },
  2037. ] as any[]
  2038. const result = ProviderTransform.message(msgs, anthropicModel, {})
  2039. expect(result).toHaveLength(1)
  2040. expect(result[0].content).toHaveLength(1)
  2041. expect(result[0].content[0]).toEqual({ type: "text", text: "Hello" })
  2042. })
  2043. test("filters out empty reasoning parts from array content", () => {
  2044. const msgs = [
  2045. {
  2046. role: "assistant",
  2047. content: [
  2048. { type: "reasoning", text: "" },
  2049. { type: "text", text: "Answer" },
  2050. { type: "reasoning", text: "" },
  2051. ],
  2052. },
  2053. ] as any[]
  2054. const result = ProviderTransform.message(msgs, anthropicModel, {})
  2055. expect(result).toHaveLength(1)
  2056. expect(result[0].content).toHaveLength(1)
  2057. expect(result[0].content[0]).toEqual({ type: "text", text: "Answer" })
  2058. })
  2059. test("removes entire message when all parts are empty", () => {
  2060. const msgs = [
  2061. { role: "user", content: "Hello" },
  2062. {
  2063. role: "assistant",
  2064. content: [
  2065. { type: "text", text: "" },
  2066. { type: "reasoning", text: "" },
  2067. ],
  2068. },
  2069. { role: "user", content: "World" },
  2070. ] as any[]
  2071. const result = ProviderTransform.message(msgs, anthropicModel, {})
  2072. expect(result).toHaveLength(2)
  2073. expect(result[0].content).toBe("Hello")
  2074. expect(result[1].content).toBe("World")
  2075. })
  2076. test("keeps non-text/reasoning parts even if text parts are empty", () => {
  2077. const msgs = [
  2078. {
  2079. role: "assistant",
  2080. content: [
  2081. { type: "text", text: "" },
  2082. { type: "tool-call", toolCallId: "123", toolName: "bash", input: { command: "ls" } },
  2083. ],
  2084. },
  2085. ] as any[]
  2086. const result = ProviderTransform.message(msgs, anthropicModel, {})
  2087. expect(result).toHaveLength(1)
  2088. expect(result[0].content).toHaveLength(1)
  2089. expect(result[0].content[0]).toEqual({
  2090. type: "tool-call",
  2091. toolCallId: "123",
  2092. toolName: "bash",
  2093. input: { command: "ls" },
  2094. })
  2095. })
  2096. test("keeps messages with valid text alongside empty parts", () => {
  2097. const msgs = [
  2098. {
  2099. role: "assistant",
  2100. content: [
  2101. { type: "reasoning", text: "Thinking..." },
  2102. { type: "text", text: "" },
  2103. { type: "text", text: "Result" },
  2104. ],
  2105. },
  2106. ] as any[]
  2107. const result = ProviderTransform.message(msgs, anthropicModel, {})
  2108. expect(result).toHaveLength(1)
  2109. expect(result[0].content).toHaveLength(2)
  2110. expect(result[0].content[0]).toEqual({ type: "reasoning", text: "Thinking..." })
  2111. expect(result[0].content[1]).toEqual({ type: "text", text: "Result" })
  2112. })
  2113. test("filters empty content for bedrock provider", () => {
  2114. const bedrockModel = {
  2115. ...anthropicModel,
  2116. id: "amazon-bedrock/anthropic.claude-opus-4-6",
  2117. providerID: "amazon-bedrock",
  2118. api: {
  2119. id: "anthropic.claude-opus-4-6",
  2120. url: "https://bedrock-runtime.us-east-1.amazonaws.com",
  2121. npm: "@ai-sdk/amazon-bedrock",
  2122. },
  2123. }
  2124. const msgs = [
  2125. { role: "user", content: "Hello" },
  2126. { role: "assistant", content: "" },
  2127. {
  2128. role: "assistant",
  2129. content: [
  2130. { type: "text", text: "" },
  2131. { type: "text", text: "Answer" },
  2132. ],
  2133. },
  2134. ] as any[]
  2135. const result = ProviderTransform.message(msgs, bedrockModel, {})
  2136. expect(result).toHaveLength(2)
  2137. expect(result[0].content).toBe("Hello")
  2138. expect(result[1].content).toHaveLength(1)
  2139. expect(result[1].content[0]).toEqual({ type: "text", text: "Answer" })
  2140. })
  2141. test("does not filter for non-anthropic providers", () => {
  2142. const openaiModel = {
  2143. ...anthropicModel,
  2144. providerID: "openai",
  2145. api: {
  2146. id: "gpt-4",
  2147. url: "https://api.openai.com",
  2148. npm: "@ai-sdk/openai",
  2149. },
  2150. }
  2151. const msgs = [
  2152. { role: "assistant", content: "" },
  2153. {
  2154. role: "assistant",
  2155. content: [{ type: "text", text: "" }],
  2156. },
  2157. ] as any[]
  2158. const result = ProviderTransform.message(msgs, openaiModel, {})
  2159. expect(result).toHaveLength(2)
  2160. expect(result[0].content).toBe("")
  2161. expect(result[1].content).toHaveLength(1)
  2162. })
  2163. test("leaves valid anthropic assistant tool ordering unchanged", () => {
  2164. const msgs = [
  2165. {
  2166. role: "assistant",
  2167. content: [
  2168. { type: "text", text: "I checked your home directory and looked for PDF files." },
  2169. { type: "tool-call", toolCallId: "toolu_1", toolName: "read", input: { filePath: "/root" } },
  2170. { type: "tool-call", toolCallId: "toolu_2", toolName: "glob", input: { pattern: "**/*.pdf" } },
  2171. ],
  2172. },
  2173. ] as any[]
  2174. const result = ProviderTransform.message(msgs, anthropicModel, {}) as any[]
  2175. expect(result).toHaveLength(1)
  2176. expect(result[0].content).toMatchObject([
  2177. { type: "text", text: "I checked your home directory and looked for PDF files." },
  2178. { type: "tool-call", toolCallId: "toolu_1", toolName: "read", input: { filePath: "/root" } },
  2179. { type: "tool-call", toolCallId: "toolu_2", toolName: "glob", input: { pattern: "**/*.pdf" } },
  2180. ])
  2181. })
  2182. })
  2183. describe("ProviderTransform.message - strip openai metadata when store=false", () => {
  2184. const openaiModel = {
  2185. id: "openai/gpt-5",
  2186. providerID: "openai",
  2187. api: {
  2188. id: "gpt-5",
  2189. url: "https://api.openai.com",
  2190. npm: "@ai-sdk/openai",
  2191. },
  2192. name: "GPT-5",
  2193. capabilities: {
  2194. temperature: true,
  2195. reasoning: true,
  2196. attachment: true,
  2197. toolcall: true,
  2198. input: { text: true, audio: false, image: true, video: false, pdf: false },
  2199. output: { text: true, audio: false, image: false, video: false, pdf: false },
  2200. interleaved: false,
  2201. },
  2202. cost: { input: 0.03, output: 0.06, cache: { read: 0.001, write: 0.002 } },
  2203. limit: { context: 128000, output: 4096 },
  2204. status: "active",
  2205. options: {},
  2206. headers: {},
  2207. } as any
  2208. test("strips OpenAI itemId and preserves reasoningEncryptedContent when store=false", () => {
  2209. const msgs = [
  2210. {
  2211. role: "assistant",
  2212. content: [
  2213. {
  2214. type: "reasoning",
  2215. text: "thinking...",
  2216. providerOptions: {
  2217. openai: {
  2218. itemId: "rs_123",
  2219. reasoningEncryptedContent: "encrypted",
  2220. },
  2221. },
  2222. },
  2223. {
  2224. type: "text",
  2225. text: "Hello",
  2226. providerOptions: {
  2227. openai: {
  2228. itemId: "msg_456",
  2229. },
  2230. },
  2231. },
  2232. ],
  2233. },
  2234. ] as any[]
  2235. const result = ProviderTransform.message(msgs, openaiModel, { store: false }) as any[]
  2236. expect(result).toHaveLength(1)
  2237. expect(result[0].content[0].providerOptions?.openai?.itemId).toBeUndefined()
  2238. expect(result[0].content[0].providerOptions?.openai?.reasoningEncryptedContent).toBe("encrypted")
  2239. expect(result[0].content[1].providerOptions?.openai?.itemId).toBeUndefined()
  2240. })
  2241. test("uses the SDK package namespace rather than provider ID", () => {
  2242. const zenModel = {
  2243. ...openaiModel,
  2244. providerID: "zen",
  2245. }
  2246. const msgs = [
  2247. {
  2248. role: "assistant",
  2249. content: [
  2250. {
  2251. type: "reasoning",
  2252. text: "thinking...",
  2253. providerOptions: {
  2254. openai: {
  2255. itemId: "rs_123",
  2256. reasoningEncryptedContent: "encrypted",
  2257. },
  2258. },
  2259. },
  2260. {
  2261. type: "text",
  2262. text: "Hello",
  2263. providerOptions: {
  2264. openai: {
  2265. itemId: "msg_456",
  2266. },
  2267. },
  2268. },
  2269. ],
  2270. },
  2271. ] as any[]
  2272. const result = ProviderTransform.message(msgs, zenModel, { store: false }) as any[]
  2273. expect(result).toHaveLength(1)
  2274. expect(result[0].content[0].providerOptions?.openai?.itemId).toBeUndefined()
  2275. expect(result[0].content[0].providerOptions?.openai?.reasoningEncryptedContent).toBe("encrypted")
  2276. expect(result[0].content[1].providerOptions?.openai?.itemId).toBeUndefined()
  2277. })
  2278. test("preserves other OpenAI options", () => {
  2279. const msgs = [
  2280. {
  2281. role: "assistant",
  2282. content: [
  2283. {
  2284. type: "text",
  2285. text: "Hello",
  2286. providerOptions: {
  2287. openai: {
  2288. itemId: "msg_123",
  2289. otherOption: "value",
  2290. },
  2291. },
  2292. },
  2293. ],
  2294. },
  2295. ] as any[]
  2296. const result = ProviderTransform.message(msgs, openaiModel, { store: false }) as any[]
  2297. expect(result[0].content[0].providerOptions?.openai?.itemId).toBeUndefined()
  2298. expect(result[0].content[0].providerOptions?.openai?.otherOption).toBe("value")
  2299. })
  2300. test("strips Azure itemId from the Azure namespace", () => {
  2301. const azureModel = {
  2302. ...openaiModel,
  2303. providerID: "azure",
  2304. api: {
  2305. id: "gpt-5",
  2306. url: "https://example.openai.azure.com",
  2307. npm: "@ai-sdk/azure",
  2308. },
  2309. }
  2310. const msgs = [
  2311. {
  2312. role: "assistant",
  2313. content: [
  2314. {
  2315. type: "text",
  2316. text: "Hello",
  2317. providerOptions: {
  2318. azure: { itemId: "msg_123", otherOption: "value" },
  2319. openai: { itemId: "msg_openai" },
  2320. },
  2321. },
  2322. ],
  2323. },
  2324. ] as any[]
  2325. const result = ProviderTransform.message(msgs, azureModel, { store: false }) as any[]
  2326. expect(result[0].content[0].providerOptions?.azure?.itemId).toBeUndefined()
  2327. expect(result[0].content[0].providerOptions?.azure?.otherOption).toBe("value")
  2328. expect(result[0].content[0].providerOptions?.openai?.itemId).toBe("msg_openai")
  2329. })
  2330. test("strips Bedrock Mantle itemId from the OpenAI namespace", () => {
  2331. const mantleModel = {
  2332. ...openaiModel,
  2333. providerID: "amazon-bedrock",
  2334. api: {
  2335. id: "openai.gpt-5.5",
  2336. url: "https://bedrock-mantle.us-east-2.api.aws/openai/v1",
  2337. npm: "@ai-sdk/amazon-bedrock/mantle",
  2338. },
  2339. }
  2340. const msgs = [
  2341. {
  2342. role: "assistant",
  2343. providerOptions: { openai: { itemId: "msg_root", otherOption: "root-value" } },
  2344. content: [
  2345. {
  2346. type: "reasoning",
  2347. text: "thinking...",
  2348. providerOptions: {
  2349. openai: { itemId: "rs_123", reasoningEncryptedContent: "encrypted" },
  2350. },
  2351. },
  2352. ],
  2353. },
  2354. ] as any[]
  2355. const result = ProviderTransform.message(msgs, mantleModel, { store: false }) as any[]
  2356. expect(result[0].providerOptions?.openai?.itemId).toBeUndefined()
  2357. expect(result[0].providerOptions?.openai?.otherOption).toBe("root-value")
  2358. expect(result[0].content[0].providerOptions?.openai?.itemId).toBeUndefined()
  2359. expect(result[0].content[0].providerOptions?.openai?.reasoningEncryptedContent).toBe("encrypted")
  2360. })
  2361. test("strips GitHub Copilot itemId from the copilot namespace, preserving other copilot options", () => {
  2362. const copilotModel = {
  2363. ...openaiModel,
  2364. id: "github-copilot/gpt-5.5",
  2365. providerID: "github-copilot",
  2366. api: {
  2367. id: "gpt-5.5",
  2368. url: "https://api.githubcopilot.com",
  2369. npm: "@ai-sdk/github-copilot",
  2370. },
  2371. }
  2372. const msgs = [
  2373. {
  2374. role: "assistant",
  2375. content: [
  2376. {
  2377. type: "reasoning",
  2378. text: "thinking...",
  2379. providerOptions: {
  2380. copilot: { itemId: "rs_123", reasoningEncryptedContent: "encrypted" },
  2381. },
  2382. },
  2383. {
  2384. // The stale itemId on tool-call parts is what Copilot echoes back as the
  2385. // `function_call` item `id`, which is what the upstream connection rejects.
  2386. type: "tool-call",
  2387. toolCallId: "call_1",
  2388. toolName: "bash",
  2389. input: { command: "ls" },
  2390. providerOptions: {
  2391. copilot: { itemId: "fc_456", reasoningEffort: "medium" },
  2392. },
  2393. },
  2394. ],
  2395. },
  2396. ] as any[]
  2397. const result = ProviderTransform.message(msgs, copilotModel, { store: false }) as any[]
  2398. expect(result[0].content[0].providerOptions?.copilot?.itemId).toBeUndefined()
  2399. expect(result[0].content[0].providerOptions?.copilot?.reasoningEncryptedContent).toBe("encrypted")
  2400. expect(result[0].content[1].providerOptions?.copilot?.itemId).toBeUndefined()
  2401. expect(result[0].content[1].providerOptions?.copilot?.reasoningEffort).toBe("medium")
  2402. })
  2403. test("leaves a stray openai namespace on a Copilot model untouched, since Copilot's Responses model only reads the copilot namespace", () => {
  2404. const copilotModel = {
  2405. ...openaiModel,
  2406. id: "github-copilot/gpt-5.5",
  2407. providerID: "github-copilot",
  2408. api: {
  2409. id: "gpt-5.5",
  2410. url: "https://api.githubcopilot.com",
  2411. npm: "@ai-sdk/github-copilot",
  2412. },
  2413. }
  2414. const msgs = [
  2415. {
  2416. role: "assistant",
  2417. content: [
  2418. {
  2419. type: "text",
  2420. text: "Hello",
  2421. providerOptions: {
  2422. openai: { itemId: "msg_456" },
  2423. },
  2424. },
  2425. ],
  2426. },
  2427. ] as any[]
  2428. const result = ProviderTransform.message(msgs, copilotModel, { store: false }) as any[]
  2429. expect(result[0].content[0].providerOptions?.openai?.itemId).toBe("msg_456")
  2430. })
  2431. test("preserves metadata for openai package when store is true", () => {
  2432. const msgs = [
  2433. {
  2434. role: "assistant",
  2435. content: [
  2436. {
  2437. type: "text",
  2438. text: "Hello",
  2439. providerOptions: {
  2440. openai: {
  2441. itemId: "msg_123",
  2442. },
  2443. },
  2444. },
  2445. ],
  2446. },
  2447. ] as any[]
  2448. // openai package preserves itemId regardless of store value
  2449. const result = ProviderTransform.message(msgs, openaiModel, { store: true }) as any[]
  2450. expect(result[0].content[0].providerOptions?.openai?.itemId).toBe("msg_123")
  2451. })
  2452. test("preserves metadata for non-openai packages when store is false", () => {
  2453. const anthropicModel = {
  2454. ...openaiModel,
  2455. providerID: "anthropic",
  2456. api: {
  2457. id: "claude-3",
  2458. url: "https://api.anthropic.com",
  2459. npm: "@ai-sdk/anthropic",
  2460. },
  2461. }
  2462. const msgs = [
  2463. {
  2464. role: "assistant",
  2465. content: [
  2466. {
  2467. type: "text",
  2468. text: "Hello",
  2469. providerOptions: {
  2470. openai: {
  2471. itemId: "msg_123",
  2472. },
  2473. },
  2474. },
  2475. ],
  2476. },
  2477. ] as any[]
  2478. // store=false preserves metadata for non-openai packages
  2479. const result = ProviderTransform.message(msgs, anthropicModel, { store: false }) as any[]
  2480. expect(result[0].content[0].providerOptions?.openai?.itemId).toBe("msg_123")
  2481. })
  2482. test("preserves metadata using providerID key when store is false", () => {
  2483. const opencodeModel = {
  2484. ...openaiModel,
  2485. providerID: "opencode",
  2486. api: {
  2487. id: "opencode-test",
  2488. url: "https://api.opencode.ai",
  2489. npm: "@ai-sdk/openai-compatible",
  2490. },
  2491. }
  2492. const msgs = [
  2493. {
  2494. role: "assistant",
  2495. content: [
  2496. {
  2497. type: "text",
  2498. text: "Hello",
  2499. providerOptions: {
  2500. opencode: {
  2501. itemId: "msg_123",
  2502. otherOption: "value",
  2503. },
  2504. },
  2505. },
  2506. ],
  2507. },
  2508. ] as any[]
  2509. const result = ProviderTransform.message(msgs, opencodeModel, { store: false }) as any[]
  2510. expect(result[0].content[0].providerOptions?.opencode?.itemId).toBe("msg_123")
  2511. expect(result[0].content[0].providerOptions?.opencode?.otherOption).toBe("value")
  2512. })
  2513. test("preserves itemId across all providerOptions keys", () => {
  2514. const opencodeModel = {
  2515. ...openaiModel,
  2516. providerID: "opencode",
  2517. api: {
  2518. id: "opencode-test",
  2519. url: "https://api.opencode.ai",
  2520. npm: "@ai-sdk/openai-compatible",
  2521. },
  2522. }
  2523. const msgs = [
  2524. {
  2525. role: "assistant",
  2526. providerOptions: {
  2527. openai: { itemId: "msg_root" },
  2528. opencode: { itemId: "msg_opencode" },
  2529. extra: { itemId: "msg_extra" },
  2530. },
  2531. content: [
  2532. {
  2533. type: "text",
  2534. text: "Hello",
  2535. providerOptions: {
  2536. openai: { itemId: "msg_openai_part" },
  2537. opencode: { itemId: "msg_opencode_part" },
  2538. extra: { itemId: "msg_extra_part" },
  2539. },
  2540. },
  2541. ],
  2542. },
  2543. ] as any[]
  2544. const result = ProviderTransform.message(msgs, opencodeModel, { store: false }) as any[]
  2545. expect(result[0].providerOptions?.openai?.itemId).toBe("msg_root")
  2546. expect(result[0].providerOptions?.opencode?.itemId).toBe("msg_opencode")
  2547. expect(result[0].providerOptions?.extra?.itemId).toBe("msg_extra")
  2548. expect(result[0].content[0].providerOptions?.openai?.itemId).toBe("msg_openai_part")
  2549. expect(result[0].content[0].providerOptions?.opencode?.itemId).toBe("msg_opencode_part")
  2550. expect(result[0].content[0].providerOptions?.extra?.itemId).toBe("msg_extra_part")
  2551. })
  2552. test("does not strip metadata for non-openai packages when store is not false", () => {
  2553. const anthropicModel = {
  2554. ...openaiModel,
  2555. providerID: "anthropic",
  2556. api: {
  2557. id: "claude-3",
  2558. url: "https://api.anthropic.com",
  2559. npm: "@ai-sdk/anthropic",
  2560. },
  2561. }
  2562. const msgs = [
  2563. {
  2564. role: "assistant",
  2565. content: [
  2566. {
  2567. type: "text",
  2568. text: "Hello",
  2569. providerOptions: {
  2570. openai: {
  2571. itemId: "msg_123",
  2572. },
  2573. },
  2574. },
  2575. ],
  2576. },
  2577. ] as any[]
  2578. const result = ProviderTransform.message(msgs, anthropicModel, {}) as any[]
  2579. expect(result[0].content[0].providerOptions?.openai?.itemId).toBe("msg_123")
  2580. })
  2581. })
  2582. describe("ProviderTransform.message - providerOptions key remapping", () => {
  2583. const createModel = (providerID: string, npm: string) =>
  2584. ({
  2585. id: `${providerID}/test-model`,
  2586. providerID,
  2587. api: {
  2588. id: "test-model",
  2589. url: "https://api.test.com",
  2590. npm,
  2591. },
  2592. name: "Test Model",
  2593. capabilities: {
  2594. temperature: true,
  2595. reasoning: false,
  2596. attachment: true,
  2597. toolcall: true,
  2598. input: { text: true, audio: false, image: true, video: false, pdf: true },
  2599. output: { text: true, audio: false, image: false, video: false, pdf: false },
  2600. interleaved: false,
  2601. },
  2602. cost: { input: 0.001, output: 0.002, cache: { read: 0.0001, write: 0.0002 } },
  2603. limit: { context: 128000, output: 8192 },
  2604. status: "active",
  2605. options: {},
  2606. headers: {},
  2607. }) as any
  2608. test("azure keeps 'azure' key and does not remap to 'openai'", () => {
  2609. const model = createModel("azure", "@ai-sdk/azure")
  2610. const msgs = [
  2611. {
  2612. role: "user",
  2613. content: "Hello",
  2614. providerOptions: {
  2615. azure: { someOption: "value" },
  2616. },
  2617. },
  2618. ] as any[]
  2619. const result = ProviderTransform.message(msgs, model, {})
  2620. expect(result[0].providerOptions?.azure).toEqual({ someOption: "value" })
  2621. expect(result[0].providerOptions?.openai).toBeUndefined()
  2622. })
  2623. test("azure cognitive services remaps providerID to 'azure' key", () => {
  2624. const model = createModel("azure-cognitive-services", "@ai-sdk/azure")
  2625. const msgs = [
  2626. {
  2627. role: "user",
  2628. content: [
  2629. {
  2630. type: "text",
  2631. text: "Hello",
  2632. providerOptions: {
  2633. "azure-cognitive-services": { part: true },
  2634. },
  2635. },
  2636. ],
  2637. providerOptions: {
  2638. "azure-cognitive-services": { someOption: "value" },
  2639. },
  2640. },
  2641. ] as any[]
  2642. const result = ProviderTransform.message(msgs, model, {}) as any[]
  2643. const part = result[0].content[0] as any
  2644. expect(result[0].providerOptions?.azure).toEqual({ someOption: "value" })
  2645. expect(result[0].providerOptions?.["azure-cognitive-services"]).toBeUndefined()
  2646. expect(part.providerOptions?.azure).toEqual({ part: true })
  2647. expect(part.providerOptions?.["azure-cognitive-services"]).toBeUndefined()
  2648. })
  2649. test("copilot remaps providerID to 'copilot' key", () => {
  2650. const model = createModel("github-copilot", "@ai-sdk/github-copilot")
  2651. const msgs = [
  2652. {
  2653. role: "user",
  2654. content: "Hello",
  2655. providerOptions: {
  2656. copilot: { someOption: "value" },
  2657. },
  2658. },
  2659. ] as any[]
  2660. const result = ProviderTransform.message(msgs, model, {})
  2661. expect(result[0].providerOptions?.copilot).toEqual({ someOption: "value" })
  2662. expect(result[0].providerOptions?.["github-copilot"]).toBeUndefined()
  2663. })
  2664. test("bedrock remaps providerID to 'bedrock' key", () => {
  2665. const model = createModel("my-bedrock", "@ai-sdk/amazon-bedrock")
  2666. const msgs = [
  2667. {
  2668. role: "user",
  2669. content: "Hello",
  2670. providerOptions: {
  2671. "my-bedrock": { someOption: "value" },
  2672. },
  2673. },
  2674. ] as any[]
  2675. const result = ProviderTransform.message(msgs, model, {})
  2676. expect(result[0].providerOptions?.bedrock).toEqual({ someOption: "value" })
  2677. expect(result[0].providerOptions?.["my-bedrock"]).toBeUndefined()
  2678. })
  2679. })
  2680. describe("ProviderTransform.message - claude w/bedrock custom inference profile", () => {
  2681. test("adds cachePoint", () => {
  2682. const model = {
  2683. id: "amazon-bedrock/custom-claude-sonnet-4.5",
  2684. providerID: "amazon-bedrock",
  2685. api: {
  2686. id: "arn:aws:bedrock:xxx:yyy:application-inference-profile/zzz",
  2687. url: "https://api.test.com",
  2688. npm: "@ai-sdk/amazon-bedrock",
  2689. },
  2690. name: "Custom inference profile",
  2691. capabilities: {},
  2692. options: {},
  2693. headers: {},
  2694. } as any
  2695. const msgs = [
  2696. {
  2697. role: "user",
  2698. content: "Hello",
  2699. },
  2700. ] as any[]
  2701. const result = ProviderTransform.message(msgs, model, {})
  2702. expect(result[0].providerOptions?.bedrock).toEqual(
  2703. expect.objectContaining({
  2704. cachePoint: {
  2705. type: "default",
  2706. },
  2707. }),
  2708. )
  2709. })
  2710. })
  2711. describe("ProviderTransform.message - bedrock caching with non-bedrock providerID", () => {
  2712. test("applies cache options at message level when npm package is amazon-bedrock", () => {
  2713. const model = {
  2714. id: "aws/us.anthropic.claude-opus-4-6-v1",
  2715. providerID: "aws",
  2716. api: {
  2717. id: "us.anthropic.claude-opus-4-6-v1",
  2718. url: "https://bedrock-runtime.us-east-1.amazonaws.com",
  2719. npm: "@ai-sdk/amazon-bedrock",
  2720. },
  2721. name: "Claude Opus 4.6",
  2722. capabilities: {},
  2723. options: {},
  2724. headers: {},
  2725. } as any
  2726. const msgs = [
  2727. {
  2728. role: "system",
  2729. content: "You are a helpful assistant",
  2730. },
  2731. {
  2732. role: "user",
  2733. content: [{ type: "text", text: "Hello" }],
  2734. },
  2735. ] as any[]
  2736. const result = ProviderTransform.message(msgs, model, {}) as any[]
  2737. // Cache should be at the message level and not the content-part level
  2738. expect(result[0].providerOptions?.bedrock).toEqual({
  2739. cachePoint: { type: "default" },
  2740. })
  2741. expect(result[0].content).toBe("You are a helpful assistant")
  2742. })
  2743. })
  2744. describe("ProviderTransform.message - cache control on gateway", () => {
  2745. const createModel = (overrides: Partial<any> = {}) =>
  2746. ({
  2747. id: "anthropic/claude-sonnet-4",
  2748. providerID: "vercel",
  2749. api: {
  2750. id: "anthropic/claude-sonnet-4",
  2751. url: "https://ai-gateway.vercel.sh/v3/ai",
  2752. npm: "@ai-sdk/gateway",
  2753. },
  2754. name: "Claude Sonnet 4",
  2755. capabilities: {
  2756. temperature: true,
  2757. reasoning: true,
  2758. attachment: true,
  2759. toolcall: true,
  2760. input: { text: true, audio: false, image: true, video: false, pdf: true },
  2761. output: { text: true, audio: false, image: false, video: false, pdf: false },
  2762. interleaved: false,
  2763. },
  2764. cost: { input: 0.001, output: 0.002, cache: { read: 0.0001, write: 0.0002 } },
  2765. limit: { context: 200_000, output: 8192 },
  2766. status: "active",
  2767. options: {},
  2768. headers: {},
  2769. ...overrides,
  2770. }) as any
  2771. test("gateway does not set cache control for anthropic models", () => {
  2772. const model = createModel()
  2773. const msgs = [
  2774. {
  2775. role: "system",
  2776. content: "You are a helpful assistant",
  2777. },
  2778. {
  2779. role: "user",
  2780. content: "Hello",
  2781. },
  2782. ] as any[]
  2783. const result = ProviderTransform.message(msgs, model, {}) as any[]
  2784. expect(result[0].content).toBe("You are a helpful assistant")
  2785. expect(result[0].providerOptions).toBeUndefined()
  2786. })
  2787. test("non-gateway anthropic keeps existing cache control behavior", () => {
  2788. const model = createModel({
  2789. providerID: "anthropic",
  2790. api: {
  2791. id: "claude-sonnet-4",
  2792. url: "https://api.anthropic.com",
  2793. npm: "@ai-sdk/anthropic",
  2794. },
  2795. })
  2796. const msgs = [
  2797. {
  2798. role: "system",
  2799. content: "You are a helpful assistant",
  2800. },
  2801. {
  2802. role: "user",
  2803. content: "Hello",
  2804. },
  2805. ] as any[]
  2806. const result = ProviderTransform.message(msgs, model, {}) as any[]
  2807. expect(result[0].providerOptions).toEqual({
  2808. anthropic: {
  2809. cacheControl: {
  2810. type: "ephemeral",
  2811. },
  2812. },
  2813. openrouter: {
  2814. cacheControl: {
  2815. type: "ephemeral",
  2816. },
  2817. },
  2818. bedrock: {
  2819. cachePoint: {
  2820. type: "default",
  2821. },
  2822. },
  2823. openaiCompatible: {
  2824. cache_control: {
  2825. type: "ephemeral",
  2826. },
  2827. },
  2828. copilot: {
  2829. copilot_cache_control: {
  2830. type: "ephemeral",
  2831. },
  2832. },
  2833. alibaba: {
  2834. cacheControl: {
  2835. type: "ephemeral",
  2836. },
  2837. },
  2838. })
  2839. })
  2840. test("does not add explicit breakpoints when Anthropic automatic caching is enabled", () => {
  2841. const model = createModel({
  2842. providerID: "anthropic",
  2843. api: { id: "claude-sonnet-4", url: "https://api.anthropic.com", npm: "@ai-sdk/anthropic" },
  2844. })
  2845. const msgs = [
  2846. { role: "system", content: "You are a helpful assistant" },
  2847. { role: "user", content: "Hello" },
  2848. ] as any[]
  2849. const result = ProviderTransform.message(msgs, model, { cacheControl: { type: "ephemeral" } }) as any[]
  2850. expect(result.every((message) => message.providerOptions === undefined)).toBe(true)
  2851. })
  2852. test("google-vertex-anthropic applies cache control", () => {
  2853. const model = createModel({
  2854. providerID: "google-vertex-anthropic",
  2855. api: {
  2856. id: "google-vertex-anthropic",
  2857. url: "https://us-central1-aiplatform.googleapis.com",
  2858. npm: "@ai-sdk/google-vertex/anthropic",
  2859. },
  2860. id: "claude-sonnet-4@20250514",
  2861. })
  2862. const msgs = [
  2863. {
  2864. role: "system",
  2865. content: "You are a helpful assistant",
  2866. },
  2867. {
  2868. role: "user",
  2869. content: "Hello",
  2870. },
  2871. ] as any[]
  2872. const result = ProviderTransform.message(msgs, model, {}) as any[]
  2873. expect(result[0].providerOptions).toEqual({
  2874. anthropic: {
  2875. cacheControl: {
  2876. type: "ephemeral",
  2877. },
  2878. },
  2879. openrouter: {
  2880. cacheControl: {
  2881. type: "ephemeral",
  2882. },
  2883. },
  2884. bedrock: {
  2885. cachePoint: {
  2886. type: "default",
  2887. },
  2888. },
  2889. openaiCompatible: {
  2890. cache_control: {
  2891. type: "ephemeral",
  2892. },
  2893. },
  2894. copilot: {
  2895. copilot_cache_control: {
  2896. type: "ephemeral",
  2897. },
  2898. },
  2899. alibaba: {
  2900. cacheControl: {
  2901. type: "ephemeral",
  2902. },
  2903. },
  2904. })
  2905. })
  2906. })
  2907. describe("ProviderTransform.temperature - Cohere North", () => {
  2908. test("defaults north-mini-code models to 1.0", () => {
  2909. expect(ProviderTransform.temperature({ id: "cohere/North-Mini-Code-1-0-latest" } as any)).toBe(1.0)
  2910. })
  2911. })
  2912. describe("ProviderTransform.reasoningVariants", () => {
  2913. const model = (reasoning_options: ModelsDev.Model["reasoning_options"]) => ({ reasoning_options }) as ModelsDev.Model
  2914. const target = (npm: string, id = "test-model") =>
  2915. ({
  2916. id,
  2917. providerID: "test",
  2918. api: { id, npm, url: "" },
  2919. capabilities: { reasoning: true },
  2920. limit: { output: 64_000 },
  2921. }) as any
  2922. test("respects explicitly empty reasoning options", () => {
  2923. expect(ProviderTransform.reasoningVariants(model([]), target("@ai-sdk/openai"))).toEqual({})
  2924. })
  2925. test.each([
  2926. ["@openrouter/ai-sdk-provider", { reasoning: { effort: "high" } }],
  2927. ["@ai-sdk/anthropic", { thinking: { type: "adaptive" }, effort: "high" }, "claude-opus-4-6"],
  2928. [
  2929. "@ai-sdk/google-vertex/anthropic",
  2930. { thinking: { type: "adaptive", display: "summarized" }, effort: "high" },
  2931. "claude-opus-4-7",
  2932. ],
  2933. ["@ai-sdk/google", { thinkingConfig: { includeThoughts: true, thinkingLevel: "high" } }],
  2934. ["@ai-sdk/google-vertex", { thinkingConfig: { includeThoughts: true, thinkingLevel: "high" } }],
  2935. [
  2936. "@ai-sdk/azure",
  2937. {
  2938. reasoningEffort: "high",
  2939. reasoningSummary: "auto",
  2940. include: ["reasoning.encrypted_content"],
  2941. },
  2942. ],
  2943. [
  2944. "@ai-sdk/openai",
  2945. {
  2946. reasoningEffort: "high",
  2947. reasoningSummary: "auto",
  2948. include: ["reasoning.encrypted_content"],
  2949. },
  2950. ],
  2951. [
  2952. "@ai-sdk/amazon-bedrock/mantle",
  2953. {
  2954. reasoningEffort: "high",
  2955. reasoningSummary: "auto",
  2956. include: ["reasoning.encrypted_content"],
  2957. },
  2958. ],
  2959. [
  2960. "@ai-sdk/github-copilot",
  2961. {
  2962. reasoningEffort: "high",
  2963. reasoningSummary: "auto",
  2964. include: ["reasoning.encrypted_content"],
  2965. },
  2966. ],
  2967. ["@ai-sdk/openai-compatible", { reasoningEffort: "high" }],
  2968. ["@ai-sdk/xai", { reasoningEffort: "high" }],
  2969. ["@ai-sdk/mistral", { reasoningEffort: "high" }],
  2970. ["@ai-sdk/groq", { reasoningEffort: "high" }],
  2971. ["@ai-sdk/cerebras", { reasoningEffort: "high" }],
  2972. ["@ai-sdk/deepinfra", { reasoningEffort: "high" }],
  2973. ["@ai-sdk/togetherai", { reasoningEffort: "high" }],
  2974. ["venice-ai-sdk-provider", { reasoningEffort: "high" }],
  2975. ["ai-gateway-provider", { reasoningEffort: "high" }],
  2976. ["@ai-sdk/amazon-bedrock", { reasoningConfig: { type: "enabled", maxReasoningEffort: "high" } }],
  2977. ])("converts effort for %s", (npm, expected, ...args) => {
  2978. const id = args[0] as string | undefined
  2979. expect(ProviderTransform.reasoningVariants(model([{ type: "effort", values: ["high"] }]), target(npm, id))).toEqual(
  2980. { high: expected },
  2981. )
  2982. })
  2983. test("uses bare effort for Claude Opus 4.5", () => {
  2984. expect(
  2985. ProviderTransform.reasoningVariants(
  2986. model([{ type: "effort", values: ["high"] }]),
  2987. target("@ai-sdk/anthropic", "claude-opus-4-5"),
  2988. ),
  2989. ).toEqual({ high: { effort: "high" } })
  2990. })
  2991. test("uses explicit effort metadata for Anthropic-compatible models", () => {
  2992. expect(
  2993. ProviderTransform.reasoningVariants(
  2994. model([{ type: "effort", values: ["high"] }]),
  2995. target("@ai-sdk/anthropic", "claude-sonnet-4"),
  2996. ),
  2997. ).toEqual({ high: { effort: "high" } })
  2998. expect(
  2999. ProviderTransform.reasoningVariants(
  3000. model([{ type: "effort", values: ["max"] }]),
  3001. target("@ai-sdk/anthropic", "k3"),
  3002. ),
  3003. ).toEqual({ max: { effort: "max" } })
  3004. })
  3005. test("maps Kimi effort metadata to adaptive thinking", () => {
  3006. expect(
  3007. ProviderTransform.reasoningVariants(
  3008. model([{ type: "effort", values: ["low", "high", "max"] }]),
  3009. target("@ai-sdk/anthropic", "kimi-k3"),
  3010. ),
  3011. ).toEqual({
  3012. low: { thinking: { type: "adaptive", display: "summarized" }, effort: "low" },
  3013. high: { thinking: { type: "adaptive", display: "summarized" }, effort: "high" },
  3014. max: { thinking: { type: "adaptive", display: "summarized" }, effort: "max" },
  3015. })
  3016. })
  3017. test("uses adaptive reasoning config for Anthropic models on Bedrock", () => {
  3018. expect(
  3019. ProviderTransform.reasoningVariants(
  3020. model([{ type: "effort", values: ["high"] }]),
  3021. target("@ai-sdk/amazon-bedrock", "anthropic.claude-opus-4-7-v1:0"),
  3022. ),
  3023. ).toEqual({
  3024. high: {
  3025. reasoningConfig: {
  3026. type: "adaptive",
  3027. maxReasoningEffort: "high",
  3028. display: "summarized",
  3029. },
  3030. },
  3031. })
  3032. })
  3033. test("does not replace unsupported Anthropic Bedrock effort options with token budgets", () => {
  3034. expect(
  3035. ProviderTransform.reasoningVariants(
  3036. model([{ type: "effort", values: ["high"] }]),
  3037. target("@ai-sdk/amazon-bedrock", "anthropic.claude-sonnet-4-v1:0"),
  3038. ),
  3039. ).toEqual({})
  3040. })
  3041. test.each([
  3042. ["@openrouter/ai-sdk-provider", { reasoning: { max_tokens: 16_000 } }],
  3043. ["@ai-sdk/anthropic", { thinking: { type: "enabled", budgetTokens: 16_000 } }],
  3044. ["@ai-sdk/google-vertex/anthropic", { thinking: { type: "enabled", budgetTokens: 16_000 } }],
  3045. ["@ai-sdk/google", { thinkingConfig: { includeThoughts: true, thinkingBudget: 16_000 } }],
  3046. ["@ai-sdk/google-vertex", { thinkingConfig: { includeThoughts: true, thinkingBudget: 16_000 } }],
  3047. ["@ai-sdk/amazon-bedrock", { reasoningConfig: { type: "enabled", budgetTokens: 16_000 } }],
  3048. ["@ai-sdk/cohere", { thinking: { type: "enabled", tokenBudget: 16_000 } }],
  3049. ["@ai-sdk/alibaba", { enableThinking: true, thinkingBudget: 16_000 }],
  3050. ])("converts token budgets for %s", (npm, high) => {
  3051. const variants = ProviderTransform.reasoningVariants(model([{ type: "budget_tokens", min: 1_024 }]), target(npm))
  3052. expect(variants?.high).toEqual(high)
  3053. expect(Object.keys(variants ?? {})).toEqual(["high", "max"])
  3054. })
  3055. test("maps null effort to none", () => {
  3056. expect(
  3057. ProviderTransform.reasoningVariants(model([{ type: "effort", values: [null] }]), target("@ai-sdk/openai")),
  3058. ).toEqual({
  3059. none: {
  3060. reasoningEffort: "none",
  3061. reasoningSummary: "auto",
  3062. include: ["reasoning.encrypted_content"],
  3063. },
  3064. })
  3065. })
  3066. test.each([
  3067. ["@ai-sdk/alibaba", { none: { enableThinking: false }, high: { enableThinking: true } }],
  3068. [
  3069. "@ai-sdk/cohere",
  3070. {
  3071. none: { thinking: { type: "disabled" } },
  3072. high: { thinking: { type: "enabled" } },
  3073. },
  3074. ],
  3075. ])("converts toggle options for %s", (npm, expected) => {
  3076. expect(ProviderTransform.reasoningVariants(model([{ type: "toggle" }]), target(npm))).toEqual(expected)
  3077. })
  3078. test("combines Cohere toggle and budget options", () => {
  3079. expect(
  3080. ProviderTransform.reasoningVariants(
  3081. model([{ type: "toggle" }, { type: "budget_tokens", min: 1 }]),
  3082. target("@ai-sdk/cohere"),
  3083. ),
  3084. ).toEqual({
  3085. none: { thinking: { type: "disabled" } },
  3086. high: { thinking: { type: "enabled", tokenBudget: 16_000 } },
  3087. max: { thinking: { type: "enabled", tokenBudget: 31_999 } },
  3088. })
  3089. })
  3090. test("generates bounded high and max token budgets", () => {
  3091. expect(
  3092. ProviderTransform.reasoningVariants(
  3093. model([{ type: "budget_tokens", min: 1_024, max: 64_000 }]),
  3094. target("@ai-sdk/anthropic"),
  3095. ),
  3096. ).toEqual({
  3097. high: { thinking: { type: "enabled", budgetTokens: 16_000 } },
  3098. max: { thinking: { type: "enabled", budgetTokens: 31_999 } },
  3099. })
  3100. })
  3101. test("caps token budgets below the model output limit", () => {
  3102. const anthropic = target("@ai-sdk/anthropic")
  3103. anthropic.limit.output = 5_000
  3104. expect(
  3105. ProviderTransform.reasoningVariants(model([{ type: "budget_tokens", min: 1_024, max: 64_000 }]), anthropic),
  3106. ).toEqual({
  3107. high: { thinking: { type: "enabled", budgetTokens: 2_500 } },
  3108. max: { thinking: { type: "enabled", budgetTokens: 4_999 } },
  3109. })
  3110. })
  3111. test("derives high and max budgets when models.dev omits max", () => {
  3112. expect(
  3113. ProviderTransform.reasoningVariants(
  3114. model([{ type: "budget_tokens", min: 1_024 }]),
  3115. target("@ai-sdk/anthropic", "claude-haiku-4-5"),
  3116. ),
  3117. ).toEqual({
  3118. high: { thinking: { type: "enabled", budgetTokens: 16_000 } },
  3119. max: { thinking: { type: "enabled", budgetTokens: 31_999 } },
  3120. })
  3121. })
  3122. test("preserves explicit inclusive budget maxima", () => {
  3123. expect(
  3124. ProviderTransform.reasoningVariants(
  3125. model([{ type: "budget_tokens", min: 1_024, max: 24_576 }]),
  3126. target("@ai-sdk/google", "gemini-2.5-pro"),
  3127. ),
  3128. ).toEqual({
  3129. high: { thinkingConfig: { includeThoughts: true, thinkingBudget: 12_288 } },
  3130. max: { thinkingConfig: { includeThoughts: true, thinkingBudget: 24_576 } },
  3131. })
  3132. })
  3133. test("prefers effort options over token budgets", () => {
  3134. expect(
  3135. ProviderTransform.reasoningVariants(
  3136. model([
  3137. { type: "budget_tokens", min: 1_024, max: 64_000 },
  3138. { type: "effort", values: ["low"] },
  3139. ]),
  3140. target("@ai-sdk/openai"),
  3141. ),
  3142. ).toEqual({
  3143. low: {
  3144. reasoningEffort: "low",
  3145. reasoningSummary: "auto",
  3146. include: ["reasoning.encrypted_content"],
  3147. },
  3148. })
  3149. })
  3150. test("does not replace unsupported effort options with heuristic variants", () => {
  3151. expect(
  3152. ProviderTransform.reasoningVariants(model([{ type: "effort", values: ["high"] }]), target("@ai-sdk/perplexity")),
  3153. ).toEqual({})
  3154. })
  3155. test("leaves unsupported toggle options for heuristic fallback", () => {
  3156. expect(ProviderTransform.reasoningVariants(model([{ type: "toggle" }]), target("@ai-sdk/openai"))).toBeUndefined()
  3157. })
  3158. test("uses model-family options for gateway and GitHub Copilot", () => {
  3159. const effort = model([{ type: "effort", values: ["high"] }])
  3160. expect(ProviderTransform.reasoningVariants(effort, target("@ai-sdk/gateway", "anthropic/claude-sonnet-4"))).toEqual(
  3161. {
  3162. high: { thinking: { type: "adaptive", display: "summarized" }, effort: "high" },
  3163. },
  3164. )
  3165. expect(ProviderTransform.reasoningVariants(effort, target("@ai-sdk/gateway", "google/gemini-3-pro"))).toEqual({
  3166. high: { thinkingConfig: { includeThoughts: true, thinkingLevel: "high" } },
  3167. })
  3168. expect(ProviderTransform.reasoningVariants(effort, target("@ai-sdk/github-copilot", "gemini-3-pro"))).toEqual({})
  3169. })
  3170. test.each(["@ai-sdk/cohere", "@ai-sdk/perplexity", "@ai-sdk/vercel", "@ai-sdk/alibaba", "gitlab-ai-provider"])(
  3171. "does not invent effort controls for %s",
  3172. (npm) => {
  3173. expect(ProviderTransform.reasoningVariants(model([{ type: "effort", values: ["high"] }]), target(npm))).toEqual(
  3174. {},
  3175. )
  3176. },
  3177. )
  3178. })
  3179. describe("ProviderTransform.variants", () => {
  3180. const createMockModel = (overrides: Partial<any> = {}): any => ({
  3181. id: "test/test-model",
  3182. providerID: "test",
  3183. api: {
  3184. id: "test-model",
  3185. url: "https://api.test.com",
  3186. npm: "@ai-sdk/openai",
  3187. },
  3188. name: "Test Model",
  3189. capabilities: {
  3190. temperature: true,
  3191. reasoning: true,
  3192. attachment: true,
  3193. toolcall: true,
  3194. input: { text: true, audio: false, image: true, video: false, pdf: false },
  3195. output: { text: true, audio: false, image: false, video: false, pdf: false },
  3196. interleaved: false,
  3197. },
  3198. cost: {
  3199. input: 0.001,
  3200. output: 0.002,
  3201. cache: { read: 0.0001, write: 0.0002 },
  3202. },
  3203. limit: {
  3204. context: 200_000,
  3205. output: 64_000,
  3206. },
  3207. status: "active",
  3208. options: {},
  3209. headers: {},
  3210. release_date: "2024-01-01",
  3211. ...overrides,
  3212. })
  3213. test("returns empty object when model has no reasoning capabilities", () => {
  3214. const model = createMockModel({
  3215. capabilities: { reasoning: false },
  3216. })
  3217. const result = ProviderTransform.variants(model)
  3218. expect(result).toEqual({})
  3219. })
  3220. test("deepseek returns empty object", () => {
  3221. const model = createMockModel({
  3222. id: "deepseek/deepseek-chat",
  3223. providerID: "deepseek",
  3224. api: {
  3225. id: "deepseek-chat",
  3226. url: "https://api.deepseek.com",
  3227. npm: "@ai-sdk/openai-compatible",
  3228. },
  3229. })
  3230. const result = ProviderTransform.variants(model)
  3231. expect(result).toEqual({})
  3232. })
  3233. test("minimax returns empty object", () => {
  3234. const model = createMockModel({
  3235. id: "minimax/minimax-model",
  3236. providerID: "minimax",
  3237. api: {
  3238. id: "minimax-model",
  3239. url: "https://api.minimax.com",
  3240. npm: "@ai-sdk/openai-compatible",
  3241. },
  3242. })
  3243. const result = ProviderTransform.variants(model)
  3244. expect(result).toEqual({})
  3245. })
  3246. test("minimax m3 using anthropic returns thinking toggles", () => {
  3247. const model = createMockModel({
  3248. id: "minimax/minimax-m3",
  3249. providerID: "minimax",
  3250. api: {
  3251. id: "MiniMax-M3",
  3252. url: "https://api.minimax.com/anthropic/v1",
  3253. npm: "@ai-sdk/anthropic",
  3254. },
  3255. })
  3256. const result = ProviderTransform.variants(model)
  3257. expect(result).toEqual({
  3258. none: { thinking: { type: "disabled" } },
  3259. thinking: { thinking: { type: "adaptive" } },
  3260. })
  3261. })
  3262. test("minimax m3 using openai-compatible returns thinking toggles", () => {
  3263. const model = createMockModel({
  3264. id: "minimax/minimax-m3",
  3265. providerID: "minimax",
  3266. api: {
  3267. id: "minimax-m3",
  3268. url: "https://api.minimax.com/v1",
  3269. npm: "@ai-sdk/openai-compatible",
  3270. },
  3271. })
  3272. expect(ProviderTransform.variants(model)).toEqual({
  3273. none: { thinking: { type: "disabled" } },
  3274. thinking: { thinking: { type: "adaptive" } },
  3275. })
  3276. })
  3277. test.each(["nvidia", "lilac"])("%s minimax m3 returns chat template thinking toggles", (providerID) => {
  3278. const model = createMockModel({
  3279. id: `${providerID}/minimaxai/minimax-m3`,
  3280. providerID,
  3281. api: {
  3282. id: "minimaxai/minimax-m3",
  3283. url: "https://api.example.com/v1",
  3284. npm: "@ai-sdk/openai-compatible",
  3285. },
  3286. })
  3287. expect(ProviderTransform.variants(model)).toEqual({
  3288. none: { chat_template_kwargs: { thinking_mode: "disabled" } },
  3289. thinking: { chat_template_kwargs: { thinking_mode: "enabled" } },
  3290. })
  3291. })
  3292. test("glm returns empty object", () => {
  3293. const model = createMockModel({
  3294. id: "glm/glm-4",
  3295. providerID: "glm",
  3296. api: {
  3297. id: "glm-4",
  3298. url: "https://api.glm.com",
  3299. npm: "@ai-sdk/openai-compatible",
  3300. },
  3301. })
  3302. const result = ProviderTransform.variants(model)
  3303. expect(result).toEqual({})
  3304. })
  3305. test("glm-5.2 returns native effort variants for openai-compatible providers", () => {
  3306. const model = createMockModel({
  3307. id: "zhipuai/glm-5.2",
  3308. providerID: "zhipuai",
  3309. api: {
  3310. id: "glm-5.2",
  3311. url: "https://open.bigmodel.cn/api/paas/v4",
  3312. npm: "@ai-sdk/openai-compatible",
  3313. },
  3314. })
  3315. expect(ProviderTransform.variants(model)).toEqual({
  3316. high: { reasoningEffort: "high" },
  3317. max: { reasoningEffort: "max" },
  3318. })
  3319. })
  3320. test("recognizes GLM-5.2 provider model IDs", () => {
  3321. for (const id of ["accounts/fireworks/models/glm-5p2", "zai-org-glm-5-2", "umans-glm-5.2"]) {
  3322. const model = createMockModel({
  3323. id: `test/${id}`,
  3324. api: {
  3325. id,
  3326. url: "https://api.test.com",
  3327. npm: "@ai-sdk/openai-compatible",
  3328. },
  3329. })
  3330. expect(ProviderTransform.variants(model)).toEqual({
  3331. high: { reasoningEffort: "high" },
  3332. max: { reasoningEffort: "max" },
  3333. })
  3334. }
  3335. })
  3336. test("recognizes GLM-5.2 from the API ID when the configured model ID is an alias", () => {
  3337. const model = createMockModel({
  3338. id: "custom/my-glm",
  3339. api: {
  3340. id: "accounts/fireworks/models/glm-5p2",
  3341. url: "https://api.fireworks.ai/inference/v1",
  3342. npm: "@ai-sdk/openai-compatible",
  3343. },
  3344. })
  3345. expect(ProviderTransform.variants(model)).toEqual({
  3346. high: { reasoningEffort: "high" },
  3347. max: { reasoningEffort: "max" },
  3348. })
  3349. })
  3350. test("glm-5.2 returns openrouter effort variants for openrouter", () => {
  3351. const model = createMockModel({
  3352. id: "openrouter/z-ai/glm-5.2",
  3353. providerID: "openrouter",
  3354. api: {
  3355. id: "z-ai/glm-5.2",
  3356. url: "https://openrouter.ai/api/v1",
  3357. npm: "@openrouter/ai-sdk-provider",
  3358. },
  3359. })
  3360. expect(ProviderTransform.variants(model)).toEqual({
  3361. high: { reasoning: { effort: "high" } },
  3362. xhigh: { reasoning: { effort: "xhigh" } },
  3363. })
  3364. })
  3365. test("glm-5.2 returns effort variants for anthropic-compatible providers", () => {
  3366. const model = createMockModel({
  3367. id: "zai-coding-plan/glm-5.2",
  3368. providerID: "zai-coding-plan",
  3369. api: {
  3370. id: "glm-5.2",
  3371. url: "https://api.z.ai/api/anthropic",
  3372. npm: "@ai-sdk/anthropic",
  3373. },
  3374. })
  3375. expect(ProviderTransform.variants(model)).toEqual({
  3376. high: { effort: "high" },
  3377. max: { effort: "max" },
  3378. })
  3379. })
  3380. test("glm-5.2 falls back to provider defaults for other packages", () => {
  3381. const model = createMockModel({
  3382. id: "test/glm-5.2",
  3383. api: {
  3384. id: "glm-5.2",
  3385. url: "https://api.test.com",
  3386. npm: "@ai-sdk/amazon-bedrock",
  3387. },
  3388. })
  3389. expect(ProviderTransform.variants(model)).toEqual({
  3390. low: { reasoningConfig: { type: "enabled", maxReasoningEffort: "low" } },
  3391. medium: { reasoningConfig: { type: "enabled", maxReasoningEffort: "medium" } },
  3392. high: { reasoningConfig: { type: "enabled", maxReasoningEffort: "high" } },
  3393. })
  3394. })
  3395. test("mistral models with reasoning support return variants", () => {
  3396. const model = createMockModel({
  3397. id: "mistral/mistral-small-latest",
  3398. providerID: "mistral",
  3399. api: {
  3400. id: "mistral-small-latest",
  3401. url: "https://api.mistral.com",
  3402. npm: "@ai-sdk/mistral",
  3403. },
  3404. capabilities: { reasoning: true },
  3405. })
  3406. const result = ProviderTransform.variants(model)
  3407. expect(result).toEqual({
  3408. high: { reasoningEffort: "high" },
  3409. })
  3410. })
  3411. test("mistral-medium-3.5 with reasoning returns variants", () => {
  3412. const model = createMockModel({
  3413. id: "mistral/mistral-medium-3.5",
  3414. providerID: "mistral",
  3415. api: {
  3416. id: "mistral-medium-3.5",
  3417. url: "https://api.mistral.com",
  3418. npm: "@ai-sdk/mistral",
  3419. },
  3420. capabilities: { reasoning: true },
  3421. })
  3422. const result = ProviderTransform.variants(model)
  3423. expect(result).toEqual({
  3424. high: { reasoningEffort: "high" },
  3425. })
  3426. })
  3427. test("mistral without reasoning returns empty object", () => {
  3428. const model = createMockModel({
  3429. id: "mistral/mistral-large",
  3430. providerID: "mistral",
  3431. api: {
  3432. id: "mistral-large-latest",
  3433. url: "https://api.mistral.com",
  3434. npm: "@ai-sdk/mistral",
  3435. },
  3436. capabilities: { reasoning: false },
  3437. })
  3438. const result = ProviderTransform.variants(model)
  3439. expect(result).toEqual({})
  3440. })
  3441. test("mistral large with reasoning returns empty object (only small supports reasoning)", () => {
  3442. const model = createMockModel({
  3443. id: "mistral/mistral-large",
  3444. providerID: "mistral",
  3445. api: {
  3446. id: "mistral-large-latest",
  3447. url: "https://api.mistral.com",
  3448. npm: "@ai-sdk/mistral",
  3449. },
  3450. capabilities: { reasoning: true },
  3451. })
  3452. const result = ProviderTransform.variants(model)
  3453. expect(result).toEqual({})
  3454. })
  3455. describe("@openrouter/ai-sdk-provider", () => {
  3456. test("returns widely supported efforts for other reasoning models", () => {
  3457. const model = createMockModel({
  3458. id: "openrouter/test-model",
  3459. providerID: "openrouter",
  3460. api: {
  3461. id: "test-model",
  3462. url: "https://openrouter.ai",
  3463. npm: "@openrouter/ai-sdk-provider",
  3464. },
  3465. })
  3466. const result = ProviderTransform.variants(model)
  3467. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  3468. expect(result.medium).toEqual({ reasoning: { effort: "medium" } })
  3469. })
  3470. test("gpt models return OPENAI_EFFORTS with reasoning", () => {
  3471. const model = createMockModel({
  3472. id: "openrouter/gpt-4",
  3473. providerID: "openrouter",
  3474. api: {
  3475. id: "gpt-4",
  3476. url: "https://openrouter.ai",
  3477. npm: "@openrouter/ai-sdk-provider",
  3478. },
  3479. })
  3480. const result = ProviderTransform.variants(model)
  3481. expect(Object.keys(result)).toEqual(["none", "minimal", "low", "medium", "high", "xhigh"])
  3482. expect(result.low).toEqual({ reasoning: { effort: "low" } })
  3483. expect(result.high).toEqual({ reasoning: { effort: "high" } })
  3484. })
  3485. for (const testCase of [
  3486. { id: "openai/o3-mini", efforts: ["none", "minimal", "low", "medium", "high", "xhigh"] },
  3487. { id: "openai/gpt-5.4", efforts: ["none", "low", "medium", "high", "xhigh"] },
  3488. { id: "openai/gpt-5-pro", efforts: ["high"] },
  3489. { id: "openai/gpt-5.5-pro", efforts: ["medium", "high", "xhigh"] },
  3490. { id: "openai/gpt-5.2-codex", efforts: ["low", "medium", "high", "xhigh"] },
  3491. { id: "openai/gpt-5.3-codex", efforts: ["none", "low", "medium", "high", "xhigh"] },
  3492. { id: "openai/gpt-5.3-codex-max", efforts: ["none", "low", "medium", "high", "xhigh"] },
  3493. { id: "openai/gpt-5-chat-latest", efforts: [] },
  3494. { id: "openai/gpt-5.2-chat-latest", efforts: ["medium"] },
  3495. ]) {
  3496. test(`${testCase.id} returns supported OpenAI reasoning efforts`, () => {
  3497. const result = ProviderTransform.variants(
  3498. createMockModel({
  3499. id: testCase.id,
  3500. providerID: "openrouter",
  3501. api: {
  3502. id: testCase.id,
  3503. url: "https://openrouter.ai",
  3504. npm: "@openrouter/ai-sdk-provider",
  3505. },
  3506. }),
  3507. )
  3508. expect(Object.keys(result)).toEqual(testCase.efforts)
  3509. })
  3510. }
  3511. test("gemini-3 returns widely supported efforts with reasoning", () => {
  3512. const model = createMockModel({
  3513. id: "openrouter/gemini-3-5-pro",
  3514. providerID: "openrouter",
  3515. api: {
  3516. id: "gemini-3-5-pro",
  3517. url: "https://openrouter.ai",
  3518. npm: "@openrouter/ai-sdk-provider",
  3519. },
  3520. })
  3521. const result = ProviderTransform.variants(model)
  3522. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  3523. })
  3524. test("grok-4 uses the provider's standard efforts", () => {
  3525. const model = createMockModel({
  3526. id: "openrouter/grok-4",
  3527. providerID: "openrouter",
  3528. api: {
  3529. id: "grok-4",
  3530. url: "https://openrouter.ai",
  3531. npm: "@openrouter/ai-sdk-provider",
  3532. },
  3533. })
  3534. const result = ProviderTransform.variants(model)
  3535. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  3536. expect(result.medium).toEqual({ reasoning: { effort: "medium" } })
  3537. })
  3538. test("grok-3-mini returns low and high with reasoning", () => {
  3539. const model = createMockModel({
  3540. id: "openrouter/grok-3-mini",
  3541. providerID: "openrouter",
  3542. api: {
  3543. id: "grok-3-mini",
  3544. url: "https://openrouter.ai",
  3545. npm: "@openrouter/ai-sdk-provider",
  3546. },
  3547. })
  3548. const result = ProviderTransform.variants(model)
  3549. expect(Object.keys(result)).toEqual(["low", "high"])
  3550. expect(result.low).toEqual({ reasoning: { effort: "low" } })
  3551. expect(result.high).toEqual({ reasoning: { effort: "high" } })
  3552. })
  3553. })
  3554. describe("@ai-sdk/gateway", () => {
  3555. test("configured anthropic aliases route by the API ID", () => {
  3556. const model = createMockModel({
  3557. id: "my-claude",
  3558. providerID: "gateway",
  3559. api: {
  3560. id: "anthropic/claude-sonnet-4-6",
  3561. url: "https://gateway.ai",
  3562. npm: "@ai-sdk/gateway",
  3563. },
  3564. })
  3565. const result = ProviderTransform.variants(model)
  3566. expect(Object.keys(result)).toEqual(["low", "medium", "high", "max"])
  3567. expect(result.high).toEqual({
  3568. thinking: {
  3569. type: "adaptive",
  3570. },
  3571. effort: "high",
  3572. })
  3573. })
  3574. test("configured google aliases route by the API ID", () => {
  3575. const model = createMockModel({
  3576. id: "my-gemini",
  3577. providerID: "gateway",
  3578. api: {
  3579. id: "google/gemini-2.5-pro",
  3580. url: "https://gateway.ai",
  3581. npm: "@ai-sdk/gateway",
  3582. },
  3583. })
  3584. expect(ProviderTransform.variants(model)).toEqual({
  3585. high: { thinkingConfig: { includeThoughts: true, thinkingBudget: 16_000 } },
  3586. max: { thinkingConfig: { includeThoughts: true, thinkingBudget: 32_768 } },
  3587. })
  3588. })
  3589. test("anthropic sonnet 4.6 models return adaptive thinking options", () => {
  3590. const model = createMockModel({
  3591. id: "anthropic/claude-sonnet-4-6",
  3592. providerID: "gateway",
  3593. api: {
  3594. id: "anthropic/claude-sonnet-4-6",
  3595. url: "https://gateway.ai",
  3596. npm: "@ai-sdk/gateway",
  3597. },
  3598. })
  3599. const result = ProviderTransform.variants(model)
  3600. expect(Object.keys(result)).toEqual(["low", "medium", "high", "max"])
  3601. expect(result.medium).toEqual({
  3602. thinking: {
  3603. type: "adaptive",
  3604. },
  3605. effort: "medium",
  3606. })
  3607. })
  3608. test("anthropic sonnet 4.6 dot-format models return adaptive thinking options", () => {
  3609. const model = createMockModel({
  3610. id: "anthropic/claude-sonnet-4-6",
  3611. providerID: "gateway",
  3612. api: {
  3613. id: "anthropic/claude-sonnet-4.6",
  3614. url: "https://gateway.ai",
  3615. npm: "@ai-sdk/gateway",
  3616. },
  3617. })
  3618. const result = ProviderTransform.variants(model)
  3619. expect(Object.keys(result)).toEqual(["low", "medium", "high", "max"])
  3620. expect(result.medium).toEqual({
  3621. thinking: {
  3622. type: "adaptive",
  3623. },
  3624. effort: "medium",
  3625. })
  3626. })
  3627. test("anthropic opus 4.6 dot-format models return adaptive thinking options", () => {
  3628. const model = createMockModel({
  3629. id: "anthropic/claude-opus-4-6",
  3630. providerID: "gateway",
  3631. api: {
  3632. id: "anthropic/claude-opus-4.6",
  3633. url: "https://gateway.ai",
  3634. npm: "@ai-sdk/gateway",
  3635. },
  3636. })
  3637. const result = ProviderTransform.variants(model)
  3638. expect(Object.keys(result)).toEqual(["low", "medium", "high", "max"])
  3639. expect(result.high).toEqual({
  3640. thinking: {
  3641. type: "adaptive",
  3642. },
  3643. effort: "high",
  3644. })
  3645. })
  3646. test("anthropic opus 4.7 models return adaptive thinking options with xhigh", () => {
  3647. const model = createMockModel({
  3648. id: "anthropic/claude-opus-4-7",
  3649. providerID: "gateway",
  3650. api: {
  3651. id: "anthropic/claude-opus-4-7",
  3652. url: "https://gateway.ai",
  3653. npm: "@ai-sdk/gateway",
  3654. },
  3655. })
  3656. const result = ProviderTransform.variants(model)
  3657. expect(Object.keys(result)).toEqual(["low", "medium", "high", "xhigh", "max"])
  3658. expect(result.xhigh).toEqual({
  3659. thinking: {
  3660. type: "adaptive",
  3661. display: "summarized",
  3662. },
  3663. effort: "xhigh",
  3664. })
  3665. expect(result.max).toEqual({
  3666. thinking: {
  3667. type: "adaptive",
  3668. display: "summarized",
  3669. },
  3670. effort: "max",
  3671. })
  3672. })
  3673. test("anthropic opus 4.7 dot-format models return adaptive thinking options with xhigh", () => {
  3674. const model = createMockModel({
  3675. id: "anthropic/claude-opus-4-7",
  3676. providerID: "gateway",
  3677. api: {
  3678. id: "anthropic/claude-opus-4.7",
  3679. url: "https://gateway.ai",
  3680. npm: "@ai-sdk/gateway",
  3681. },
  3682. })
  3683. const result = ProviderTransform.variants(model)
  3684. expect(Object.keys(result)).toEqual(["low", "medium", "high", "xhigh", "max"])
  3685. })
  3686. test("anthropic opus 4.8 forces display summarized for adaptive reasoning", () => {
  3687. const model = createMockModel({
  3688. id: "anthropic/claude-opus-4-8",
  3689. providerID: "gateway",
  3690. api: {
  3691. id: "anthropic/claude-opus-4-8",
  3692. url: "https://gateway.ai",
  3693. npm: "@ai-sdk/gateway",
  3694. },
  3695. })
  3696. const result = ProviderTransform.variants(model)
  3697. expect(Object.keys(result)).toEqual(["low", "medium", "high", "xhigh", "max"])
  3698. expect(result.high).toEqual({
  3699. thinking: {
  3700. type: "adaptive",
  3701. display: "summarized",
  3702. },
  3703. effort: "high",
  3704. })
  3705. })
  3706. test("anthropic sonnet 5 returns adaptive thinking options with xhigh", () => {
  3707. const model = createMockModel({
  3708. id: "anthropic/claude-sonnet-5",
  3709. providerID: "gateway",
  3710. api: {
  3711. id: "anthropic/claude-sonnet-5",
  3712. url: "https://gateway.ai",
  3713. npm: "@ai-sdk/gateway",
  3714. },
  3715. })
  3716. const result = ProviderTransform.variants(model)
  3717. expect(Object.keys(result)).toEqual(["low", "medium", "high", "xhigh", "max"])
  3718. expect(result.high).toEqual({
  3719. thinking: {
  3720. type: "adaptive",
  3721. display: "summarized",
  3722. },
  3723. effort: "high",
  3724. })
  3725. })
  3726. test("anthropic opus 4.6 omits display so it keeps the summarized default", () => {
  3727. const model = createMockModel({
  3728. id: "anthropic/claude-opus-4-6",
  3729. providerID: "gateway",
  3730. api: {
  3731. id: "anthropic/claude-opus-4-6",
  3732. url: "https://gateway.ai",
  3733. npm: "@ai-sdk/gateway",
  3734. },
  3735. })
  3736. const result = ProviderTransform.variants(model)
  3737. expect(Object.keys(result)).toEqual(["low", "medium", "high", "max"])
  3738. expect(result.high).toEqual({
  3739. thinking: {
  3740. type: "adaptive",
  3741. },
  3742. effort: "high",
  3743. })
  3744. })
  3745. test("anthropic models return anthropic thinking options", () => {
  3746. const model = createMockModel({
  3747. id: "anthropic/claude-sonnet-4",
  3748. providerID: "gateway",
  3749. api: {
  3750. id: "anthropic/claude-sonnet-4",
  3751. url: "https://gateway.ai",
  3752. npm: "@ai-sdk/gateway",
  3753. },
  3754. })
  3755. const result = ProviderTransform.variants(model)
  3756. expect(Object.keys(result)).toEqual(["high", "max"])
  3757. expect(result.high).toEqual({
  3758. thinking: {
  3759. type: "enabled",
  3760. budgetTokens: 16000,
  3761. },
  3762. })
  3763. expect(result.max).toEqual({
  3764. thinking: {
  3765. type: "enabled",
  3766. budgetTokens: 31999,
  3767. },
  3768. })
  3769. })
  3770. test("returns OPENAI_EFFORTS with reasoningEffort", () => {
  3771. const model = createMockModel({
  3772. id: "gateway/gateway-model",
  3773. providerID: "gateway",
  3774. api: {
  3775. id: "gateway-model",
  3776. url: "https://gateway.ai",
  3777. npm: "@ai-sdk/gateway",
  3778. },
  3779. })
  3780. const result = ProviderTransform.variants(model)
  3781. expect(Object.keys(result)).toEqual(["none", "minimal", "low", "medium", "high", "xhigh"])
  3782. expect(result.low).toEqual({ reasoningEffort: "low" })
  3783. expect(result.high).toEqual({ reasoningEffort: "high" })
  3784. })
  3785. for (const testCase of [
  3786. { id: "openai/gpt-5-5", efforts: ["none", "low", "medium", "high", "xhigh"] },
  3787. { id: "openai/gpt-5-pro", efforts: ["high"] },
  3788. { id: "openai/gpt-5-5-pro", efforts: ["medium", "high", "xhigh"] },
  3789. { id: "openai/gpt-5-2-codex", efforts: ["low", "medium", "high", "xhigh"] },
  3790. { id: "openai/gpt-5-3-codex", efforts: ["none", "low", "medium", "high", "xhigh"] },
  3791. { id: "openai/gpt-5-3-codex-max", efforts: ["none", "low", "medium", "high", "xhigh"] },
  3792. { id: "openai/gpt-5-chat-latest", efforts: [] },
  3793. { id: "openai/gpt-5-2-chat-latest", efforts: ["medium"] },
  3794. ]) {
  3795. test(`${testCase.id} returns supported OpenAI reasoning efforts`, () => {
  3796. const result = ProviderTransform.variants(
  3797. createMockModel({
  3798. id: testCase.id,
  3799. providerID: "gateway",
  3800. api: {
  3801. id: testCase.id,
  3802. url: "https://gateway.ai",
  3803. npm: "@ai-sdk/gateway",
  3804. },
  3805. }),
  3806. )
  3807. expect(Object.keys(result)).toEqual(testCase.efforts)
  3808. })
  3809. }
  3810. })
  3811. describe("@ai-sdk/github-copilot", () => {
  3812. test("standard models return low, medium, high", () => {
  3813. const model = createMockModel({
  3814. id: "gpt-4.5",
  3815. providerID: "github-copilot",
  3816. api: {
  3817. id: "gpt-4.5",
  3818. url: "https://api.githubcopilot.com",
  3819. npm: "@ai-sdk/github-copilot",
  3820. },
  3821. })
  3822. const result = ProviderTransform.variants(model)
  3823. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  3824. expect(result.low).toEqual({
  3825. reasoningEffort: "low",
  3826. reasoningSummary: "auto",
  3827. include: ["reasoning.encrypted_content"],
  3828. })
  3829. })
  3830. test("gpt-5.1-codex-max includes xhigh", () => {
  3831. const model = createMockModel({
  3832. id: "gpt-5.1-codex-max",
  3833. providerID: "github-copilot",
  3834. api: {
  3835. id: "gpt-5.1-codex-max",
  3836. url: "https://api.githubcopilot.com",
  3837. npm: "@ai-sdk/github-copilot",
  3838. },
  3839. })
  3840. const result = ProviderTransform.variants(model)
  3841. expect(Object.keys(result)).toEqual(["low", "medium", "high", "xhigh"])
  3842. })
  3843. test("gpt-5.1-codex-mini does not include xhigh", () => {
  3844. const model = createMockModel({
  3845. id: "gpt-5.1-codex-mini",
  3846. providerID: "github-copilot",
  3847. api: {
  3848. id: "gpt-5.1-codex-mini",
  3849. url: "https://api.githubcopilot.com",
  3850. npm: "@ai-sdk/github-copilot",
  3851. },
  3852. })
  3853. const result = ProviderTransform.variants(model)
  3854. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  3855. })
  3856. test("gpt-5.1-codex does not include xhigh", () => {
  3857. const model = createMockModel({
  3858. id: "gpt-5.1-codex",
  3859. providerID: "github-copilot",
  3860. api: {
  3861. id: "gpt-5.1-codex",
  3862. url: "https://api.githubcopilot.com",
  3863. npm: "@ai-sdk/github-copilot",
  3864. },
  3865. })
  3866. const result = ProviderTransform.variants(model)
  3867. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  3868. })
  3869. test("gpt-5.2 includes xhigh", () => {
  3870. const model = createMockModel({
  3871. id: "gpt-5.2",
  3872. providerID: "github-copilot",
  3873. api: {
  3874. id: "gpt-5.2",
  3875. url: "https://api.githubcopilot.com",
  3876. npm: "@ai-sdk/github-copilot",
  3877. },
  3878. })
  3879. const result = ProviderTransform.variants(model)
  3880. expect(Object.keys(result)).toEqual(["low", "medium", "high", "xhigh"])
  3881. expect(result.xhigh).toEqual({
  3882. reasoningEffort: "xhigh",
  3883. reasoningSummary: "auto",
  3884. include: ["reasoning.encrypted_content"],
  3885. })
  3886. })
  3887. test("gpt-5.2-codex includes xhigh", () => {
  3888. const model = createMockModel({
  3889. id: "gpt-5.2-codex",
  3890. providerID: "github-copilot",
  3891. api: {
  3892. id: "gpt-5.2-codex",
  3893. url: "https://api.githubcopilot.com",
  3894. npm: "@ai-sdk/github-copilot",
  3895. },
  3896. })
  3897. const result = ProviderTransform.variants(model)
  3898. expect(Object.keys(result)).toEqual(["low", "medium", "high", "xhigh"])
  3899. })
  3900. test("gpt-5.3-codex includes xhigh", () => {
  3901. const model = createMockModel({
  3902. id: "gpt-5.3-codex",
  3903. providerID: "github-copilot",
  3904. api: {
  3905. id: "gpt-5.3-codex",
  3906. url: "https://api.githubcopilot.com",
  3907. npm: "@ai-sdk/github-copilot",
  3908. },
  3909. })
  3910. const result = ProviderTransform.variants(model)
  3911. expect(Object.keys(result)).toEqual(["low", "medium", "high", "xhigh"])
  3912. })
  3913. test("gpt-5.4 includes xhigh", () => {
  3914. const model = createMockModel({
  3915. id: "gpt-5.4",
  3916. release_date: "2026-03-05",
  3917. providerID: "github-copilot",
  3918. api: {
  3919. id: "gpt-5.4",
  3920. url: "https://api.githubcopilot.com",
  3921. npm: "@ai-sdk/github-copilot",
  3922. },
  3923. })
  3924. const result = ProviderTransform.variants(model)
  3925. expect(Object.keys(result)).toEqual(["low", "medium", "high", "xhigh"])
  3926. })
  3927. })
  3928. describe("@ai-sdk/cerebras", () => {
  3929. test("returns WIDELY_SUPPORTED_EFFORTS with reasoningEffort", () => {
  3930. const model = createMockModel({
  3931. id: "cerebras/llama-4",
  3932. providerID: "cerebras",
  3933. api: {
  3934. id: "llama-4-sc",
  3935. url: "https://api.cerebras.ai",
  3936. npm: "@ai-sdk/cerebras",
  3937. },
  3938. })
  3939. const result = ProviderTransform.variants(model)
  3940. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  3941. expect(result.low).toEqual({ reasoningEffort: "low" })
  3942. expect(result.high).toEqual({ reasoningEffort: "high" })
  3943. })
  3944. })
  3945. describe("@ai-sdk/togetherai", () => {
  3946. test("returns WIDELY_SUPPORTED_EFFORTS with reasoningEffort", () => {
  3947. const model = createMockModel({
  3948. id: "togetherai/llama-4",
  3949. providerID: "togetherai",
  3950. api: {
  3951. id: "llama-4-sc",
  3952. url: "https://api.togetherai.com",
  3953. npm: "@ai-sdk/togetherai",
  3954. },
  3955. })
  3956. const result = ProviderTransform.variants(model)
  3957. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  3958. expect(result.low).toEqual({ reasoningEffort: "low" })
  3959. expect(result.high).toEqual({ reasoningEffort: "high" })
  3960. })
  3961. })
  3962. describe("@ai-sdk/xai", () => {
  3963. test("grok-4.5 uses standard reasoning efforts", () => {
  3964. const model = createMockModel({
  3965. id: "xai/grok-4.5",
  3966. providerID: "xai",
  3967. api: {
  3968. id: "grok-4.5",
  3969. url: "https://api.x.ai",
  3970. npm: "@ai-sdk/xai",
  3971. },
  3972. })
  3973. const result = ProviderTransform.variants(model)
  3974. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  3975. expect(result.medium).toEqual({ reasoningEffort: "medium" })
  3976. })
  3977. test("grok-3-mini returns low and high with reasoningEffort", () => {
  3978. const model = createMockModel({
  3979. id: "xai/grok-3-mini",
  3980. providerID: "xai",
  3981. api: {
  3982. id: "grok-3-mini",
  3983. url: "https://api.x.ai",
  3984. npm: "@ai-sdk/xai",
  3985. },
  3986. })
  3987. const result = ProviderTransform.variants(model)
  3988. expect(Object.keys(result)).toEqual(["low", "high"])
  3989. expect(result.low).toEqual({ reasoningEffort: "low" })
  3990. expect(result.high).toEqual({ reasoningEffort: "high" })
  3991. })
  3992. })
  3993. describe("@ai-sdk/deepinfra", () => {
  3994. test("returns WIDELY_SUPPORTED_EFFORTS with reasoningEffort", () => {
  3995. const model = createMockModel({
  3996. id: "deepinfra/llama-4",
  3997. providerID: "deepinfra",
  3998. api: {
  3999. id: "llama-4-sc",
  4000. url: "https://api.deepinfra.com",
  4001. npm: "@ai-sdk/deepinfra",
  4002. },
  4003. })
  4004. const result = ProviderTransform.variants(model)
  4005. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  4006. expect(result.low).toEqual({ reasoningEffort: "low" })
  4007. expect(result.high).toEqual({ reasoningEffort: "high" })
  4008. })
  4009. })
  4010. describe("@ai-sdk/openai-compatible", () => {
  4011. test("returns WIDELY_SUPPORTED_EFFORTS with reasoningEffort", () => {
  4012. const model = createMockModel({
  4013. id: "custom-provider/custom-model",
  4014. providerID: "custom-provider",
  4015. api: {
  4016. id: "custom-model",
  4017. url: "https://api.custom.com",
  4018. npm: "@ai-sdk/openai-compatible",
  4019. },
  4020. })
  4021. const result = ProviderTransform.variants(model)
  4022. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  4023. expect(result.low).toEqual({ reasoningEffort: "low" })
  4024. expect(result.high).toEqual({ reasoningEffort: "high" })
  4025. })
  4026. test("north-mini-code-1-0 returns only none and high", () => {
  4027. const model = createMockModel({
  4028. id: "cohere/north-mini-code-1-0",
  4029. providerID: "cohere",
  4030. api: {
  4031. id: "North-Mini-Code-1-0-latest",
  4032. url: "https://api.cohere.com/compatibility/v1",
  4033. npm: "@ai-sdk/openai-compatible",
  4034. },
  4035. })
  4036. const result = ProviderTransform.variants(model)
  4037. expect(result).toEqual({
  4038. none: { reasoningEffort: "none" },
  4039. high: { reasoningEffort: "high" },
  4040. })
  4041. })
  4042. })
  4043. describe("@ai-sdk/azure", () => {
  4044. test("o1-mini returns empty object", () => {
  4045. const model = createMockModel({
  4046. id: "o1-mini",
  4047. providerID: "azure",
  4048. api: {
  4049. id: "o1-mini",
  4050. url: "https://azure.com",
  4051. npm: "@ai-sdk/azure",
  4052. },
  4053. })
  4054. const result = ProviderTransform.variants(model)
  4055. expect(result).toEqual({})
  4056. })
  4057. test("standard azure models return custom efforts with reasoningSummary", () => {
  4058. const model = createMockModel({
  4059. id: "o1",
  4060. providerID: "azure",
  4061. api: {
  4062. id: "o1",
  4063. url: "https://azure.com",
  4064. npm: "@ai-sdk/azure",
  4065. },
  4066. })
  4067. const result = ProviderTransform.variants(model)
  4068. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  4069. expect(result.low).toEqual({
  4070. reasoningEffort: "low",
  4071. reasoningSummary: "auto",
  4072. include: ["reasoning.encrypted_content"],
  4073. })
  4074. })
  4075. test("gpt-5 adds minimal effort", () => {
  4076. const model = createMockModel({
  4077. id: "gpt-5",
  4078. providerID: "azure",
  4079. api: {
  4080. id: "gpt-5",
  4081. url: "https://azure.com",
  4082. npm: "@ai-sdk/azure",
  4083. },
  4084. })
  4085. const result = ProviderTransform.variants(model)
  4086. expect(Object.keys(result)).toEqual(["minimal", "low", "medium", "high"])
  4087. })
  4088. for (const testCase of [
  4089. { id: "gpt-5-1", efforts: ["none", "low", "medium", "high"] },
  4090. { id: "gpt-5-4", efforts: ["none", "low", "medium", "high", "xhigh"] },
  4091. { id: "gpt-5.4", efforts: ["none", "low", "medium", "high", "xhigh"] },
  4092. { id: "gpt-5-5", efforts: ["none", "low", "medium", "high", "xhigh"] },
  4093. ]) {
  4094. test(`${testCase.id} returns supported Azure reasoning efforts`, () => {
  4095. const result = ProviderTransform.variants(
  4096. createMockModel({
  4097. id: testCase.id,
  4098. providerID: "azure",
  4099. api: {
  4100. id: testCase.id,
  4101. url: "https://azure.com",
  4102. npm: "@ai-sdk/azure",
  4103. },
  4104. }),
  4105. )
  4106. expect(Object.keys(result)).toEqual(testCase.efforts)
  4107. })
  4108. }
  4109. })
  4110. describe("@ai-sdk/openai", () => {
  4111. test("gpt-5-pro returns only high effort", () => {
  4112. const model = createMockModel({
  4113. id: "gpt-5-pro",
  4114. providerID: "openai",
  4115. api: {
  4116. id: "gpt-5-pro",
  4117. url: "https://api.openai.com",
  4118. npm: "@ai-sdk/openai",
  4119. },
  4120. })
  4121. const result = ProviderTransform.variants(model)
  4122. expect(Object.keys(result)).toEqual(["high"])
  4123. })
  4124. test("standard openai models return custom efforts with reasoningSummary", () => {
  4125. const model = createMockModel({
  4126. id: "gpt-5",
  4127. providerID: "openai",
  4128. api: {
  4129. id: "gpt-5",
  4130. url: "https://api.openai.com",
  4131. npm: "@ai-sdk/openai",
  4132. },
  4133. release_date: "2024-06-01",
  4134. })
  4135. const result = ProviderTransform.variants(model)
  4136. expect(Object.keys(result)).toEqual(["minimal", "low", "medium", "high"])
  4137. expect(result.low).toEqual({
  4138. reasoningEffort: "low",
  4139. reasoningSummary: "auto",
  4140. include: ["reasoning.encrypted_content"],
  4141. })
  4142. })
  4143. test("models after 2025-11-13 include 'none' effort", () => {
  4144. const model = createMockModel({
  4145. id: "gpt-5-nano",
  4146. providerID: "openai",
  4147. api: {
  4148. id: "gpt-5-nano",
  4149. url: "https://api.openai.com",
  4150. npm: "@ai-sdk/openai",
  4151. },
  4152. release_date: "2025-11-14",
  4153. })
  4154. const result = ProviderTransform.variants(model)
  4155. expect(Object.keys(result)).toEqual(["none", "minimal", "low", "medium", "high"])
  4156. })
  4157. test("models after 2025-12-04 include 'xhigh' effort", () => {
  4158. const model = createMockModel({
  4159. id: "openai/gpt-5-reasoning",
  4160. providerID: "openai",
  4161. api: {
  4162. id: "gpt-5-reasoning",
  4163. url: "https://api.openai.com",
  4164. npm: "@ai-sdk/openai",
  4165. },
  4166. release_date: "2025-12-05",
  4167. })
  4168. const result = ProviderTransform.variants(model)
  4169. expect(Object.keys(result)).toEqual(["none", "minimal", "low", "medium", "high", "xhigh"])
  4170. })
  4171. for (const testCase of [
  4172. { id: "o1", releaseDate: "2024-12-17", efforts: ["low", "medium", "high"] },
  4173. { id: "o1-pro", releaseDate: "2025-03-19", efforts: ["low", "medium", "high"] },
  4174. { id: "o3", releaseDate: "2025-04-16", efforts: ["low", "medium", "high"] },
  4175. { id: "o3-mini", releaseDate: "2025-01-31", efforts: ["low", "medium", "high"] },
  4176. { id: "o3-pro", releaseDate: "2025-06-10", efforts: ["low", "medium", "high"] },
  4177. { id: "o4-mini", releaseDate: "2025-04-16", efforts: ["low", "medium", "high"] },
  4178. { id: "o3-deep-research", releaseDate: "2025-06-26", efforts: ["medium"] },
  4179. { id: "o4-mini-deep-research", releaseDate: "2025-06-26", efforts: ["medium"] },
  4180. { id: "gpt-5.1", releaseDate: "2025-11-13", efforts: ["none", "low", "medium", "high"] },
  4181. { id: "gpt-5.4", releaseDate: "2026-03-05", efforts: ["none", "low", "medium", "high", "xhigh"] },
  4182. {
  4183. id: "gpt-5.5",
  4184. modelID: "gpt-5-5",
  4185. releaseDate: "2026-04-23",
  4186. efforts: ["none", "low", "medium", "high", "xhigh"],
  4187. },
  4188. { id: "gpt-5.4-pro", releaseDate: "2026-03-05", efforts: ["medium", "high", "xhigh"] },
  4189. { id: "gpt-5.5-pro", releaseDate: "2026-04-23", efforts: ["medium", "high", "xhigh"] },
  4190. { id: "gpt-5-codex", releaseDate: "2025-09-23", efforts: ["low", "medium", "high"] },
  4191. { id: "gpt-5.1-codex", releaseDate: "2025-11-13", efforts: ["low", "medium", "high"] },
  4192. { id: "gpt-5.1-codex-max", releaseDate: "2025-11-13", efforts: ["low", "medium", "high", "xhigh"] },
  4193. { id: "gpt-5.2-codex", releaseDate: "2025-12-11", efforts: ["low", "medium", "high", "xhigh"] },
  4194. { id: "gpt-5.3-codex", releaseDate: "2026-01-22", efforts: ["none", "low", "medium", "high", "xhigh"] },
  4195. { id: "gpt-5.3-codex-max", releaseDate: "2026-01-22", efforts: ["none", "low", "medium", "high", "xhigh"] },
  4196. { id: "gpt-5-chat-latest", releaseDate: "2025-08-07", efforts: [] },
  4197. { id: "gpt-5.1-chat-latest", releaseDate: "2025-11-13", efforts: ["medium"] },
  4198. { id: "gpt-5.2-chat-latest", releaseDate: "2025-12-11", efforts: ["medium"] },
  4199. ]) {
  4200. test(`${testCase.id} returns supported reasoning efforts`, () => {
  4201. const result = ProviderTransform.variants(
  4202. createMockModel({
  4203. id: testCase.modelID ?? testCase.id,
  4204. providerID: "openai",
  4205. api: {
  4206. id: testCase.id,
  4207. url: "https://api.openai.com",
  4208. npm: "@ai-sdk/openai",
  4209. },
  4210. release_date: testCase.releaseDate,
  4211. }),
  4212. )
  4213. expect(Object.keys(result)).toEqual(testCase.efforts)
  4214. })
  4215. }
  4216. test("gpt-50 (lookalike) does not get gpt-5 family treatment", () => {
  4217. const model = createMockModel({
  4218. id: "gpt-50",
  4219. providerID: "openai",
  4220. api: {
  4221. id: "gpt-50",
  4222. url: "https://api.openai.com",
  4223. npm: "@ai-sdk/openai",
  4224. },
  4225. release_date: "2024-01-01",
  4226. })
  4227. const result = ProviderTransform.variants(model)
  4228. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  4229. })
  4230. })
  4231. describe("@ai-sdk/amazon-bedrock/mantle", () => {
  4232. test("gpt-5.5 returns OpenAI-style reasoning variants", () => {
  4233. const model = createMockModel({
  4234. id: "openai.gpt-5.5",
  4235. providerID: "amazon-bedrock",
  4236. api: {
  4237. id: "openai.gpt-5.5",
  4238. url: "https://bedrock-mantle.us-east-2.api.aws/openai/v1",
  4239. npm: "@ai-sdk/amazon-bedrock/mantle",
  4240. },
  4241. release_date: "2026-04-23",
  4242. })
  4243. const result = ProviderTransform.variants(model)
  4244. expect(Object.keys(result)).toEqual(["none", "low", "medium", "high", "xhigh"])
  4245. expect(result.medium).toEqual({
  4246. reasoningEffort: "medium",
  4247. reasoningSummary: "auto",
  4248. include: ["reasoning.encrypted_content"],
  4249. })
  4250. })
  4251. })
  4252. describe("@ai-sdk/anthropic", () => {
  4253. for (const testCase of [
  4254. {
  4255. name: "opus 4.5",
  4256. apiIds: ["claude-opus-4-5-20251101", "claude-opus-4.5-20251101"],
  4257. efforts: ["low", "medium", "high"],
  4258. expectedHigh: { effort: "high" },
  4259. },
  4260. {
  4261. name: "sonnet 4.6",
  4262. apiIds: ["claude-sonnet-4-6", "claude-sonnet-4.6"],
  4263. efforts: ["low", "medium", "high", "max"],
  4264. expectedHigh: { thinking: { type: "adaptive" }, effort: "high" },
  4265. },
  4266. {
  4267. name: "opus 4.6",
  4268. apiIds: ["claude-opus-4-6", "claude-opus-4.6"],
  4269. efforts: ["low", "medium", "high", "max"],
  4270. expectedHigh: { thinking: { type: "adaptive" }, effort: "high" },
  4271. },
  4272. {
  4273. name: "opus 4.7",
  4274. apiIds: ["claude-opus-4-7", "claude-opus-4.7"],
  4275. efforts: ["low", "medium", "high", "xhigh", "max"],
  4276. expectedHigh: { thinking: { type: "adaptive", display: "summarized" }, effort: "high" },
  4277. },
  4278. {
  4279. name: "opus 4.8",
  4280. apiIds: ["claude-opus-4-8", "claude-opus-4.8"],
  4281. efforts: ["low", "medium", "high", "xhigh", "max"],
  4282. expectedHigh: { thinking: { type: "adaptive", display: "summarized" }, effort: "high" },
  4283. },
  4284. {
  4285. name: "sonnet 5",
  4286. apiIds: ["claude-sonnet-5", "claude-sonnet-5-20260630"],
  4287. efforts: ["low", "medium", "high", "xhigh", "max"],
  4288. expectedHigh: { thinking: { type: "adaptive", display: "summarized" }, effort: "high" },
  4289. },
  4290. {
  4291. name: "fable 5",
  4292. apiIds: ["claude-fable-5"],
  4293. efforts: ["low", "medium", "high", "xhigh", "max"],
  4294. expectedHigh: { thinking: { type: "adaptive", display: "summarized" }, effort: "high" },
  4295. },
  4296. ]) {
  4297. for (const apiId of testCase.apiIds) {
  4298. test(`${testCase.name} ${apiId} returns supported reasoning efforts`, () => {
  4299. const result = ProviderTransform.variants(
  4300. createMockModel({
  4301. id: `anthropic/${apiId}`,
  4302. providerID: "anthropic",
  4303. api: {
  4304. id: apiId,
  4305. url: "https://api.anthropic.com",
  4306. npm: "@ai-sdk/anthropic",
  4307. },
  4308. }),
  4309. )
  4310. expect(Object.keys(result)).toEqual(testCase.efforts)
  4311. expect(result.high).toEqual(testCase.expectedHigh)
  4312. })
  4313. }
  4314. }
  4315. test("github copilot opus 4.7 returns only medium reasoning effort", () => {
  4316. const model = createMockModel({
  4317. id: "claude-opus-4.7",
  4318. providerID: "github-copilot",
  4319. api: {
  4320. id: "claude-opus-4.7",
  4321. url: "https://api.githubcopilot.com/v1",
  4322. npm: "@ai-sdk/anthropic",
  4323. },
  4324. })
  4325. const result = ProviderTransform.variants(model)
  4326. expect(result).toEqual({
  4327. medium: {
  4328. thinking: {
  4329. type: "adaptive",
  4330. display: "summarized",
  4331. },
  4332. effort: "medium",
  4333. },
  4334. })
  4335. })
  4336. test("returns high and max with thinking config", () => {
  4337. const model = createMockModel({
  4338. id: "anthropic/claude-4",
  4339. providerID: "anthropic",
  4340. api: {
  4341. id: "claude-4",
  4342. url: "https://api.anthropic.com",
  4343. npm: "@ai-sdk/anthropic",
  4344. },
  4345. })
  4346. const result = ProviderTransform.variants(model)
  4347. expect(Object.keys(result)).toEqual(["high", "max"])
  4348. expect(result.high).toEqual({
  4349. thinking: {
  4350. type: "enabled",
  4351. budgetTokens: 16000,
  4352. },
  4353. })
  4354. expect(result.max).toEqual({
  4355. thinking: {
  4356. type: "enabled",
  4357. budgetTokens: 31999,
  4358. },
  4359. })
  4360. })
  4361. })
  4362. describe("@ai-sdk/google-vertex/anthropic", () => {
  4363. test("opus 4.8 uses adaptive reasoning for Vertex model IDs", () => {
  4364. const result = ProviderTransform.variants(
  4365. createMockModel({
  4366. id: "google-vertex-anthropic/claude-opus-4-8@default",
  4367. providerID: "google-vertex-anthropic",
  4368. api: {
  4369. id: "claude-opus-4-8@default",
  4370. url: "https://us-central1-aiplatform.googleapis.com",
  4371. npm: "@ai-sdk/google-vertex/anthropic",
  4372. },
  4373. }),
  4374. )
  4375. expect(Object.keys(result)).toEqual(["low", "medium", "high", "xhigh", "max"])
  4376. expect(result.high).toEqual({
  4377. thinking: {
  4378. type: "adaptive",
  4379. display: "summarized",
  4380. },
  4381. effort: "high",
  4382. })
  4383. })
  4384. test("sonnet 5 uses adaptive reasoning for Vertex model IDs", () => {
  4385. const result = ProviderTransform.variants(
  4386. createMockModel({
  4387. id: "google-vertex-anthropic/claude-sonnet-5@default",
  4388. providerID: "google-vertex-anthropic",
  4389. api: {
  4390. id: "claude-sonnet-5@default",
  4391. url: "https://us-central1-aiplatform.googleapis.com",
  4392. npm: "@ai-sdk/google-vertex/anthropic",
  4393. },
  4394. }),
  4395. )
  4396. expect(Object.keys(result)).toEqual(["low", "medium", "high", "xhigh", "max"])
  4397. expect(result.high).toEqual({
  4398. thinking: {
  4399. type: "adaptive",
  4400. display: "summarized",
  4401. },
  4402. effort: "high",
  4403. })
  4404. })
  4405. })
  4406. describe("@ai-sdk/amazon-bedrock", () => {
  4407. test("anthropic sonnet 4.6 returns adaptive reasoning options", () => {
  4408. const model = createMockModel({
  4409. id: "bedrock/anthropic-claude-sonnet-4-6",
  4410. providerID: "bedrock",
  4411. api: {
  4412. id: "anthropic.claude-sonnet-4-6",
  4413. url: "https://bedrock.amazonaws.com",
  4414. npm: "@ai-sdk/amazon-bedrock",
  4415. },
  4416. })
  4417. const result = ProviderTransform.variants(model)
  4418. expect(Object.keys(result)).toEqual(["low", "medium", "high", "max"])
  4419. expect(result.max).toEqual({
  4420. reasoningConfig: {
  4421. type: "adaptive",
  4422. maxReasoningEffort: "max",
  4423. },
  4424. })
  4425. })
  4426. test("anthropic opus 4.7 returns adaptive reasoning options with xhigh", () => {
  4427. const model = createMockModel({
  4428. id: "bedrock/anthropic-claude-opus-4-7",
  4429. providerID: "bedrock",
  4430. api: {
  4431. id: "anthropic.claude-opus-4-7",
  4432. url: "https://bedrock.amazonaws.com",
  4433. npm: "@ai-sdk/amazon-bedrock",
  4434. },
  4435. })
  4436. const result = ProviderTransform.variants(model)
  4437. expect(Object.keys(result)).toEqual(["low", "medium", "high", "xhigh", "max"])
  4438. expect(result.xhigh).toEqual({
  4439. reasoningConfig: {
  4440. type: "adaptive",
  4441. maxReasoningEffort: "xhigh",
  4442. display: "summarized",
  4443. },
  4444. })
  4445. expect(result.max).toEqual({
  4446. reasoningConfig: {
  4447. type: "adaptive",
  4448. maxReasoningEffort: "max",
  4449. display: "summarized",
  4450. },
  4451. })
  4452. })
  4453. test("anthropic opus 4.8 returns adaptive reasoning options with xhigh", () => {
  4454. const result = ProviderTransform.variants(
  4455. createMockModel({
  4456. id: "bedrock/anthropic-claude-opus-4.8",
  4457. providerID: "bedrock",
  4458. api: {
  4459. id: "anthropic.claude-opus-4.8",
  4460. url: "https://bedrock.amazonaws.com",
  4461. npm: "@ai-sdk/amazon-bedrock",
  4462. },
  4463. }),
  4464. )
  4465. expect(Object.keys(result)).toEqual(["low", "medium", "high", "xhigh", "max"])
  4466. expect(result.high).toEqual({
  4467. reasoningConfig: {
  4468. type: "adaptive",
  4469. maxReasoningEffort: "high",
  4470. display: "summarized",
  4471. },
  4472. })
  4473. })
  4474. test("anthropic sonnet 5 returns adaptive reasoning options with xhigh", () => {
  4475. const result = ProviderTransform.variants(
  4476. createMockModel({
  4477. id: "bedrock/anthropic-claude-sonnet-5",
  4478. providerID: "bedrock",
  4479. api: {
  4480. id: "anthropic.claude-sonnet-5",
  4481. url: "https://bedrock.amazonaws.com",
  4482. npm: "@ai-sdk/amazon-bedrock",
  4483. },
  4484. }),
  4485. )
  4486. expect(Object.keys(result)).toEqual(["low", "medium", "high", "xhigh", "max"])
  4487. expect(result.high).toEqual({
  4488. reasoningConfig: {
  4489. type: "adaptive",
  4490. maxReasoningEffort: "high",
  4491. display: "summarized",
  4492. },
  4493. })
  4494. })
  4495. test("returns WIDELY_SUPPORTED_EFFORTS with reasoningConfig", () => {
  4496. const model = createMockModel({
  4497. id: "bedrock/llama-4",
  4498. providerID: "bedrock",
  4499. api: {
  4500. id: "llama-4-sc",
  4501. url: "https://bedrock.amazonaws.com",
  4502. npm: "@ai-sdk/amazon-bedrock",
  4503. },
  4504. })
  4505. const result = ProviderTransform.variants(model)
  4506. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  4507. expect(result.low).toEqual({
  4508. reasoningConfig: {
  4509. type: "enabled",
  4510. maxReasoningEffort: "low",
  4511. },
  4512. })
  4513. })
  4514. })
  4515. for (const provider of [
  4516. { name: "@ai-sdk/google", providerID: "google", url: "https://generativelanguage.googleapis.com" },
  4517. { name: "@ai-sdk/google-vertex", providerID: "google-vertex", url: "https://vertexai.googleapis.com" },
  4518. ]) {
  4519. describe(provider.name, () => {
  4520. for (const testCase of [
  4521. {
  4522. apiId: "gemini-2.5-pro",
  4523. efforts: ["high", "max"],
  4524. expectedHigh: { thinkingConfig: { includeThoughts: true, thinkingBudget: 16_000 } },
  4525. expectedMax: { thinkingConfig: { includeThoughts: true, thinkingBudget: 32_768 } },
  4526. },
  4527. {
  4528. apiId: "gemini-2.5-flash",
  4529. efforts: ["high", "max"],
  4530. expectedHigh: { thinkingConfig: { includeThoughts: true, thinkingBudget: 16_000 } },
  4531. expectedMax: { thinkingConfig: { includeThoughts: true, thinkingBudget: 24_576 } },
  4532. },
  4533. {
  4534. apiId: "gemini-3-pro-preview",
  4535. efforts: ["low", "medium", "high"],
  4536. expectedHigh: { thinkingConfig: { includeThoughts: true, thinkingLevel: "high" } },
  4537. },
  4538. {
  4539. apiId: "gemini-3.1-pro-preview",
  4540. efforts: ["low", "medium", "high"],
  4541. expectedHigh: { thinkingConfig: { includeThoughts: true, thinkingLevel: "high" } },
  4542. },
  4543. {
  4544. apiId: "gemini-3-flash-preview",
  4545. efforts: ["minimal", "low", "medium", "high"],
  4546. expectedHigh: { thinkingConfig: { includeThoughts: true, thinkingLevel: "high" } },
  4547. },
  4548. {
  4549. apiId: "gemini-3.1-flash-lite",
  4550. efforts: ["minimal", "low", "medium", "high"],
  4551. expectedHigh: { thinkingConfig: { includeThoughts: true, thinkingLevel: "high" } },
  4552. },
  4553. {
  4554. apiId: "gemini-3.1-flash-image-preview",
  4555. efforts: ["minimal", "high"],
  4556. expectedHigh: { thinkingConfig: { includeThoughts: true, thinkingLevel: "high" } },
  4557. },
  4558. {
  4559. apiId: "gemini-3-pro-image-preview",
  4560. efforts: ["high"],
  4561. expectedHigh: { thinkingConfig: { includeThoughts: true, thinkingLevel: "high" } },
  4562. },
  4563. ]) {
  4564. test(`${testCase.apiId} returns supported thinking controls`, () => {
  4565. const result = ProviderTransform.variants(
  4566. createMockModel({
  4567. id: `${provider.providerID}/${testCase.apiId}`,
  4568. providerID: provider.providerID,
  4569. api: {
  4570. id: testCase.apiId,
  4571. url: provider.url,
  4572. npm: provider.name,
  4573. },
  4574. }),
  4575. )
  4576. expect(Object.keys(result)).toEqual(testCase.efforts)
  4577. expect(result.high).toEqual(testCase.expectedHigh)
  4578. if (testCase.expectedMax) expect(result.max).toEqual(testCase.expectedMax)
  4579. })
  4580. }
  4581. })
  4582. }
  4583. describe("@ai-sdk/cohere", () => {
  4584. test("returns empty object", () => {
  4585. const model = createMockModel({
  4586. id: "cohere/command-r",
  4587. providerID: "cohere",
  4588. api: {
  4589. id: "command-r",
  4590. url: "https://api.cohere.com",
  4591. npm: "@ai-sdk/cohere",
  4592. },
  4593. })
  4594. const result = ProviderTransform.variants(model)
  4595. expect(result).toEqual({})
  4596. })
  4597. })
  4598. describe("@ai-sdk/groq", () => {
  4599. test("returns none and WIDELY_SUPPORTED_EFFORTS with thinkingLevel", () => {
  4600. const model = createMockModel({
  4601. id: "groq/llama-4",
  4602. providerID: "groq",
  4603. api: {
  4604. id: "llama-4-sc",
  4605. url: "https://api.groq.com",
  4606. npm: "@ai-sdk/groq",
  4607. },
  4608. })
  4609. const result = ProviderTransform.variants(model)
  4610. expect(Object.keys(result)).toEqual(["none", "low", "medium", "high"])
  4611. expect(result.none).toEqual({
  4612. reasoningEffort: "none",
  4613. })
  4614. expect(result.low).toEqual({
  4615. reasoningEffort: "low",
  4616. })
  4617. })
  4618. })
  4619. describe("@ai-sdk/perplexity", () => {
  4620. test("returns empty object", () => {
  4621. const model = createMockModel({
  4622. id: "perplexity/sonar-plus",
  4623. providerID: "perplexity",
  4624. api: {
  4625. id: "sonar-plus",
  4626. url: "https://api.perplexity.ai",
  4627. npm: "@ai-sdk/perplexity",
  4628. },
  4629. })
  4630. const result = ProviderTransform.variants(model)
  4631. expect(result).toEqual({})
  4632. })
  4633. })
  4634. describe("@jerome-benoit/sap-ai-provider-v2", () => {
  4635. const sapModel = (apiId: string, releaseDate = "2024-01-01") =>
  4636. createMockModel({
  4637. id: `sap-ai-core/${apiId}`,
  4638. providerID: "sap-ai-core",
  4639. api: {
  4640. id: apiId,
  4641. url: "https://api.ai.sap",
  4642. npm: "@jerome-benoit/sap-ai-provider-v2",
  4643. },
  4644. release_date: releaseDate,
  4645. })
  4646. for (const testCase of [
  4647. {
  4648. name: "sonnet 4.6",
  4649. apiIds: ["anthropic--claude-sonnet-4-6"],
  4650. efforts: ["low", "medium", "high", "max"],
  4651. thinking: { type: "adaptive" },
  4652. },
  4653. {
  4654. name: "opus 4.6",
  4655. apiIds: ["anthropic--claude-4.6-opus", "anthropic--claude-4-6-opus"],
  4656. efforts: ["low", "medium", "high", "max"],
  4657. thinking: { type: "adaptive" },
  4658. },
  4659. {
  4660. name: "opus 4.7",
  4661. apiIds: ["anthropic--claude-4.7-opus", "anthropic--claude-4-7-opus"],
  4662. efforts: ["low", "medium", "high", "xhigh", "max"],
  4663. thinking: { type: "adaptive", display: "summarized" },
  4664. },
  4665. {
  4666. name: "opus 4.8",
  4667. apiIds: ["anthropic--claude-4.8-opus", "anthropic--claude-4-8-opus"],
  4668. efforts: ["low", "medium", "high", "xhigh", "max"],
  4669. thinking: { type: "adaptive", display: "summarized" },
  4670. },
  4671. {
  4672. name: "sonnet 5",
  4673. apiIds: ["anthropic--claude-sonnet-5", "anthropic--claude-5-sonnet"],
  4674. efforts: ["low", "medium", "high", "xhigh", "max"],
  4675. thinking: { type: "adaptive", display: "summarized" },
  4676. },
  4677. ]) {
  4678. for (const apiId of testCase.apiIds) {
  4679. test(`${testCase.name} ${apiId} returns adaptive thinking variants under modelParams`, () => {
  4680. const result = ProviderTransform.variants(sapModel(apiId))
  4681. expect(Object.keys(result)).toEqual(testCase.efforts)
  4682. for (const effort of testCase.efforts) {
  4683. expect(result[effort]).toEqual({
  4684. modelParams: {
  4685. thinking: testCase.thinking,
  4686. output_config: { effort },
  4687. },
  4688. })
  4689. }
  4690. })
  4691. }
  4692. }
  4693. for (const apiId of ["anthropic--claude-sonnet-4", "anthropic--claude-4.5-opus"]) {
  4694. test(`${apiId} returns budget_tokens variants under modelParams`, () => {
  4695. const result = ProviderTransform.variants(sapModel(apiId))
  4696. expect(Object.keys(result)).toEqual(["high", "max"])
  4697. expect(result.high).toEqual({
  4698. modelParams: { thinking: { type: "enabled", budget_tokens: 16000 } },
  4699. })
  4700. expect(result.max).toEqual({
  4701. modelParams: { thinking: { type: "enabled", budget_tokens: 31999 } },
  4702. })
  4703. })
  4704. }
  4705. for (const testCase of [
  4706. { apiId: "gemini-2.5-pro", maxBudget: 32768 },
  4707. { apiId: "gemini-2.5-flash", maxBudget: 24576 },
  4708. ]) {
  4709. test(`${testCase.apiId} returns thinkingConfig variants under modelParams`, () => {
  4710. const result = ProviderTransform.variants(sapModel(testCase.apiId))
  4711. expect(Object.keys(result)).toEqual(["high", "max"])
  4712. expect(result.high).toEqual({
  4713. modelParams: { thinkingConfig: { includeThoughts: true, thinkingBudget: 16000 } },
  4714. })
  4715. expect(result.max).toEqual({
  4716. modelParams: { thinkingConfig: { includeThoughts: true, thinkingBudget: testCase.maxBudget } },
  4717. })
  4718. })
  4719. }
  4720. for (const testCase of [
  4721. { apiId: "gpt-5", releaseDate: "2025-08-07", efforts: ["minimal", "low", "medium", "high"] },
  4722. { apiId: "gpt-5-mini", releaseDate: "2025-08-07", efforts: ["minimal", "low", "medium", "high"] },
  4723. { apiId: "gpt-5-nano", releaseDate: "2025-08-07", efforts: ["minimal", "low", "medium", "high"] },
  4724. { apiId: "gpt-5.4", releaseDate: "2026-01-15", efforts: ["none", "low", "medium", "high", "xhigh"] },
  4725. { apiId: "azure-openai--o3-mini", releaseDate: "2024-01-01", efforts: ["low", "medium", "high"] },
  4726. ]) {
  4727. test(`${testCase.apiId} returns reasoning_effort variants under modelParams`, () => {
  4728. const result = ProviderTransform.variants(sapModel(testCase.apiId, testCase.releaseDate))
  4729. expect(Object.keys(result)).toEqual(testCase.efforts)
  4730. for (const effort of testCase.efforts) {
  4731. expect(result[effort]).toEqual({ modelParams: { reasoning_effort: effort } })
  4732. }
  4733. })
  4734. }
  4735. for (const apiId of [
  4736. "gemini-3.1-flash-lite",
  4737. "cohere--command-a-reasoning",
  4738. "sonar-deep-research",
  4739. "aws--llama-opus-4.7-fake",
  4740. ]) {
  4741. test(`${apiId} falls through to harmonized reasoning_effort fallback`, () => {
  4742. const result = ProviderTransform.variants(sapModel(apiId))
  4743. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  4744. for (const effort of ["low", "medium", "high"]) {
  4745. expect(result[effort]).toEqual({ modelParams: { reasoning_effort: effort } })
  4746. }
  4747. })
  4748. }
  4749. })
  4750. describe("ai-gateway-provider (cloudflare-ai-gateway)", () => {
  4751. const cfModel = (apiId: string, releaseDate = "2024-01-01") =>
  4752. createMockModel({
  4753. id: `cloudflare-ai-gateway/${apiId}`,
  4754. providerID: "cloudflare-ai-gateway",
  4755. api: {
  4756. id: apiId,
  4757. url: "https://gateway.ai.cloudflare.com/v1/compat",
  4758. npm: "ai-gateway-provider",
  4759. },
  4760. release_date: releaseDate,
  4761. })
  4762. for (const testCase of [
  4763. { id: "openai/gpt-5.4", efforts: ["none", "low", "medium", "high", "xhigh"] },
  4764. { id: "openai/gpt-5.2-codex", efforts: ["low", "medium", "high", "xhigh"] },
  4765. { id: "openai/gpt-5.3-codex", efforts: ["none", "low", "medium", "high", "xhigh"] },
  4766. { id: "openai/gpt-5-pro", efforts: ["high"] },
  4767. { id: "openai/gpt-5.2-pro", efforts: ["medium", "high", "xhigh"] },
  4768. { id: "openai/gpt-5-chat-latest", efforts: [] },
  4769. { id: "openai/gpt-5.2-chat-latest", efforts: ["medium"] },
  4770. ]) {
  4771. test(`${testCase.id} returns supported reasoning efforts`, () => {
  4772. const result = ProviderTransform.variants(cfModel(testCase.id, "2026-03-05"))
  4773. expect(Object.keys(result)).toEqual(testCase.efforts)
  4774. })
  4775. }
  4776. test("openai gpt-4o (no reasoning) returns empty", () => {
  4777. const model = cfModel("openai/gpt-4o")
  4778. model.capabilities.reasoning = false
  4779. const result = ProviderTransform.variants(model)
  4780. expect(result).toEqual({})
  4781. })
  4782. test("non-openai upstream falls back to widely-supported OAI efforts", () => {
  4783. const result = ProviderTransform.variants(cfModel("anthropic/claude-sonnet-4-6"))
  4784. expect(result).toEqual({
  4785. low: { reasoningEffort: "low" },
  4786. medium: { reasoningEffort: "medium" },
  4787. high: { reasoningEffort: "high" },
  4788. })
  4789. })
  4790. })
  4791. })
  4792. describe("ProviderTransform.smallOptions - gpt-5 chat/search", () => {
  4793. const createModel = (apiId: string) => {
  4794. const model = {
  4795. id: `openai/${apiId}`,
  4796. providerID: "openai",
  4797. api: {
  4798. id: apiId,
  4799. url: "https://api.openai.com",
  4800. npm: "@ai-sdk/openai",
  4801. },
  4802. capabilities: { reasoning: true },
  4803. limit: { output: 64_000 },
  4804. release_date: "2026-01-01",
  4805. } as any
  4806. model.variants = ProviderTransform.variants(model)
  4807. return model
  4808. }
  4809. for (const testCase of [
  4810. { id: "gpt-5-chat-latest", options: { store: false } },
  4811. {
  4812. id: "gpt-5.1-chat-latest",
  4813. options: {
  4814. store: false,
  4815. reasoningEffort: "medium",
  4816. reasoningSummary: "auto",
  4817. include: ["reasoning.encrypted_content"],
  4818. },
  4819. },
  4820. {
  4821. id: "gpt-5.2-chat-latest",
  4822. options: {
  4823. store: false,
  4824. reasoningEffort: "medium",
  4825. reasoningSummary: "auto",
  4826. include: ["reasoning.encrypted_content"],
  4827. },
  4828. },
  4829. {
  4830. id: "gpt-5-search-api",
  4831. options: {
  4832. store: false,
  4833. reasoningEffort: "none",
  4834. reasoningSummary: "auto",
  4835. include: ["reasoning.encrypted_content"],
  4836. },
  4837. },
  4838. ]) {
  4839. test(`${testCase.id} returns only supported small options`, () => {
  4840. expect(ProviderTransform.smallOptions(createModel(testCase.id))).toEqual(testCase.options)
  4841. })
  4842. }
  4843. })
  4844. test("ProviderTransform.smallOptions preserves the weakest OpenRouter reasoning effort", () => {
  4845. expect(
  4846. ProviderTransform.smallOptions({
  4847. providerID: "openrouter",
  4848. api: {
  4849. id: "google/gemini-3.5-flash",
  4850. npm: "@openrouter/ai-sdk-provider",
  4851. },
  4852. variants: {
  4853. low: { reasoning: { effort: "low" } },
  4854. medium: { reasoning: { effort: "medium" } },
  4855. high: { reasoning: { effort: "high" } },
  4856. },
  4857. } as any),
  4858. ).toEqual({ reasoning: { effort: "low" } })
  4859. })
  4860. describe("ProviderTransform.smallOptions - google thinking controls", () => {
  4861. const createGoogleModel = (apiId: string) => {
  4862. const model = {
  4863. id: `google/${apiId}`,
  4864. providerID: "google",
  4865. api: {
  4866. id: apiId,
  4867. url: "https://generativelanguage.googleapis.com",
  4868. npm: "@ai-sdk/google",
  4869. },
  4870. capabilities: { reasoning: true },
  4871. limit: { output: 64_000 },
  4872. } as any
  4873. model.variants = ProviderTransform.variants(model)
  4874. return model
  4875. }
  4876. for (const testCase of [
  4877. { id: "gemini-3-pro-preview", options: { thinkingConfig: { includeThoughts: true, thinkingLevel: "low" } } },
  4878. { id: "gemini-3-flash-preview", options: { thinkingConfig: { includeThoughts: true, thinkingLevel: "minimal" } } },
  4879. {
  4880. id: "gemini-3.1-flash-image-preview",
  4881. options: { thinkingConfig: { includeThoughts: true, thinkingLevel: "minimal" } },
  4882. },
  4883. { id: "gemini-3-pro-image-preview", options: { thinkingConfig: { includeThoughts: true, thinkingLevel: "high" } } },
  4884. { id: "gemini-2.5-pro", options: { thinkingConfig: { includeThoughts: true, thinkingBudget: 16000 } } },
  4885. { id: "gemini-2.5-flash", options: { thinkingConfig: { includeThoughts: true, thinkingBudget: 16000 } } },
  4886. ]) {
  4887. test(`${testCase.id} returns supported small thinking options`, () => {
  4888. expect(ProviderTransform.smallOptions(createGoogleModel(testCase.id))).toEqual(testCase.options)
  4889. })
  4890. }
  4891. test("uses the first configured variant when available", () => {
  4892. expect(
  4893. ProviderTransform.smallOptions({
  4894. ...createGoogleModel("gemini-2.5-pro"),
  4895. variants: {
  4896. high: { thinkingConfig: { includeThoughts: true, thinkingBudget: 16000 } },
  4897. max: { thinkingConfig: { includeThoughts: true, thinkingBudget: 32768 } },
  4898. },
  4899. }),
  4900. ).toEqual({ thinkingConfig: { includeThoughts: true, thinkingBudget: 16000 } })
  4901. })
  4902. test("does not synthesize thinking options when variants are empty", () => {
  4903. expect(ProviderTransform.smallOptions({ ...createGoogleModel("gemini-2.5-pro"), variants: {} })).toEqual({})
  4904. })
  4905. })
  4906. describe("ProviderTransform.providerOptions - ai-gateway-provider", () => {
  4907. const createModel = (overrides: Partial<any> = {}) =>
  4908. ({
  4909. id: "cloudflare-ai-gateway/openai/gpt-5.4",
  4910. providerID: "cloudflare-ai-gateway",
  4911. api: {
  4912. id: "openai/gpt-5.4",
  4913. url: "https://gateway.ai.cloudflare.com/v1/compat",
  4914. npm: "ai-gateway-provider",
  4915. },
  4916. capabilities: {
  4917. temperature: false,
  4918. reasoning: true,
  4919. attachment: true,
  4920. toolcall: true,
  4921. input: { text: true, audio: false, image: true, video: false, pdf: true },
  4922. output: { text: true, audio: false, image: false, video: false, pdf: false },
  4923. interleaved: false,
  4924. },
  4925. cost: { input: 1, output: 1, cache: { read: 0, write: 0 } },
  4926. limit: { context: 1_000_000, output: 128_000 },
  4927. status: "active",
  4928. options: {},
  4929. headers: {},
  4930. release_date: "2026-03-05",
  4931. ...overrides,
  4932. }) as any
  4933. test("routes options under openaiCompatible (the key @ai-sdk/openai-compatible reads)", () => {
  4934. // Regression: previously fell back to providerID="cloudflare-ai-gateway",
  4935. // which @ai-sdk/openai-compatible never reads, silently dropping reasoningEffort.
  4936. const result = ProviderTransform.providerOptions(createModel(), { reasoningEffort: "high" })
  4937. expect(result).toEqual({ openaiCompatible: { reasoningEffort: "high" } })
  4938. })
  4939. })
  4940. describe("ProviderTransform.options - kimi family adaptive thinking", () => {
  4941. const createModel = (overrides: Record<string, any> = {}) =>
  4942. ({
  4943. id: "moonshotai/kimi-k2-thinking",
  4944. providerID: "moonshotai",
  4945. api: {
  4946. id: "kimi-k2-thinking",
  4947. url: "https://api.moonshot.ai/anthropic",
  4948. npm: "@ai-sdk/anthropic",
  4949. },
  4950. name: "Kimi K2 Thinking",
  4951. capabilities: {
  4952. temperature: true,
  4953. reasoning: true,
  4954. attachment: false,
  4955. toolcall: true,
  4956. input: { text: true, audio: false, image: false, video: false, pdf: false },
  4957. output: { text: true, audio: false, image: false, video: false, pdf: false },
  4958. interleaved: false,
  4959. },
  4960. cost: { input: 0.001, output: 0.002, cache: { read: 0.0001, write: 0.0002 } },
  4961. limit: { context: 262144, output: 262144 },
  4962. status: "active",
  4963. options: {},
  4964. headers: {},
  4965. ...overrides,
  4966. }) as any
  4967. test("uses adaptive thinking with effort instead of budget tokens", () => {
  4968. const result = ProviderTransform.options({ model: createModel(), sessionID: "s1", providerOptions: {} })
  4969. expect(result.thinking).toEqual({ type: "adaptive", display: "summarized" })
  4970. expect(result.effort).toBe("high")
  4971. expect(JSON.stringify(result)).not.toContain("budgetTokens")
  4972. })
  4973. test("uses adaptive thinking through Google Vertex Anthropic", () => {
  4974. const model = createModel()
  4975. model.api.npm = "@ai-sdk/google-vertex/anthropic"
  4976. const result = ProviderTransform.options({ model, sessionID: "s1", providerOptions: {} })
  4977. expect(result.thinking).toEqual({ type: "adaptive", display: "summarized" })
  4978. expect(result.effort).toBe("high")
  4979. })
  4980. test("provides adaptive effort variants without models.dev metadata", () => {
  4981. expect(ProviderTransform.variants(createModel())).toEqual(
  4982. Object.fromEntries(
  4983. ["low", "medium", "high", "xhigh", "max"].map((effort) => [
  4984. effort,
  4985. { thinking: { type: "adaptive", display: "summarized" }, effort },
  4986. ]),
  4987. ),
  4988. )
  4989. const model = createModel()
  4990. model.api.npm = "@ai-sdk/openai-compatible"
  4991. expect(ProviderTransform.variants(model)).toEqual({})
  4992. })
  4993. test("does not enable thinking for kimi models without reasoning capability", () => {
  4994. const model = createModel()
  4995. model.capabilities.reasoning = false
  4996. const result = ProviderTransform.options({ model, sessionID: "s1", providerOptions: {} })
  4997. expect(result.thinking).toBeUndefined()
  4998. })
  4999. test("does not set thinking defaults for non-kimi anthropic models", () => {
  5000. const model = createModel({
  5001. id: "anthropic/claude-sonnet-4-5",
  5002. providerID: "anthropic",
  5003. api: {
  5004. id: "claude-sonnet-4-5",
  5005. url: "https://api.anthropic.com",
  5006. npm: "@ai-sdk/anthropic",
  5007. },
  5008. })
  5009. const result = ProviderTransform.options({ model, sessionID: "s1", providerOptions: {} })
  5010. expect(result.thinking).toBeUndefined()
  5011. expect(result.effort).toBeUndefined()
  5012. })
  5013. test("does not set adaptive thinking for kimi on openai-compatible", () => {
  5014. const model = createModel()
  5015. model.api = {
  5016. id: "kimi-k2-thinking",
  5017. url: "https://api.moonshot.ai/v1",
  5018. npm: "@ai-sdk/openai-compatible",
  5019. }
  5020. const result = ProviderTransform.options({ model, sessionID: "s1", providerOptions: {} })
  5021. expect(result.thinking).toBeUndefined()
  5022. })
  5023. })