transform.test.ts 86 KB

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