transform.test.ts 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799
  1. import { describe, expect, test } from "bun:test"
  2. import { ProviderTransform } from "../../src/provider/transform"
  3. const OUTPUT_TOKEN_MAX = 32000
  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 - gpt-5 textVerbosity", () => {
  97. const sessionID = "test-session-123"
  98. const createGpt5Model = (apiId: string) =>
  99. ({
  100. id: `openai/${apiId}`,
  101. providerID: "openai",
  102. api: {
  103. id: apiId,
  104. url: "https://api.openai.com",
  105. npm: "@ai-sdk/openai",
  106. },
  107. name: apiId,
  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: false },
  114. output: { text: true, audio: false, image: false, video: false, pdf: false },
  115. interleaved: false,
  116. },
  117. cost: { input: 0.03, output: 0.06, cache: { read: 0.001, write: 0.002 } },
  118. limit: { context: 128000, output: 4096 },
  119. status: "active",
  120. options: {},
  121. headers: {},
  122. }) as any
  123. test("gpt-5.2 should have textVerbosity set to low", () => {
  124. const model = createGpt5Model("gpt-5.2")
  125. const result = ProviderTransform.options({ model, sessionID, providerOptions: {} })
  126. expect(result.textVerbosity).toBe("low")
  127. })
  128. test("gpt-5.1 should have textVerbosity set to low", () => {
  129. const model = createGpt5Model("gpt-5.1")
  130. const result = ProviderTransform.options({ model, sessionID, providerOptions: {} })
  131. expect(result.textVerbosity).toBe("low")
  132. })
  133. test("gpt-5.2-chat-latest should NOT have textVerbosity set (only supports medium)", () => {
  134. const model = createGpt5Model("gpt-5.2-chat-latest")
  135. const result = ProviderTransform.options({ model, sessionID, providerOptions: {} })
  136. expect(result.textVerbosity).toBeUndefined()
  137. })
  138. test("gpt-5.1-chat-latest should NOT have textVerbosity set (only supports medium)", () => {
  139. const model = createGpt5Model("gpt-5.1-chat-latest")
  140. const result = ProviderTransform.options({ model, sessionID, providerOptions: {} })
  141. expect(result.textVerbosity).toBeUndefined()
  142. })
  143. test("gpt-5.2-chat should NOT have textVerbosity set", () => {
  144. const model = createGpt5Model("gpt-5.2-chat")
  145. const result = ProviderTransform.options({ model, sessionID, providerOptions: {} })
  146. expect(result.textVerbosity).toBeUndefined()
  147. })
  148. test("gpt-5-chat should NOT have textVerbosity set", () => {
  149. const model = createGpt5Model("gpt-5-chat")
  150. const result = ProviderTransform.options({ model, sessionID, providerOptions: {} })
  151. expect(result.textVerbosity).toBeUndefined()
  152. })
  153. test("gpt-5.2-codex should NOT have textVerbosity set (codex models excluded)", () => {
  154. const model = createGpt5Model("gpt-5.2-codex")
  155. const result = ProviderTransform.options({ model, sessionID, providerOptions: {} })
  156. expect(result.textVerbosity).toBeUndefined()
  157. })
  158. })
  159. describe("ProviderTransform.maxOutputTokens", () => {
  160. test("returns 32k when modelLimit > 32k", () => {
  161. const modelLimit = 100000
  162. const result = ProviderTransform.maxOutputTokens("@ai-sdk/openai", {}, modelLimit, OUTPUT_TOKEN_MAX)
  163. expect(result).toBe(OUTPUT_TOKEN_MAX)
  164. })
  165. test("returns modelLimit when modelLimit < 32k", () => {
  166. const modelLimit = 16000
  167. const result = ProviderTransform.maxOutputTokens("@ai-sdk/openai", {}, modelLimit, OUTPUT_TOKEN_MAX)
  168. expect(result).toBe(16000)
  169. })
  170. describe("azure", () => {
  171. test("returns 32k when modelLimit > 32k", () => {
  172. const modelLimit = 100000
  173. const result = ProviderTransform.maxOutputTokens("@ai-sdk/azure", {}, modelLimit, OUTPUT_TOKEN_MAX)
  174. expect(result).toBe(OUTPUT_TOKEN_MAX)
  175. })
  176. test("returns modelLimit when modelLimit < 32k", () => {
  177. const modelLimit = 16000
  178. const result = ProviderTransform.maxOutputTokens("@ai-sdk/azure", {}, modelLimit, OUTPUT_TOKEN_MAX)
  179. expect(result).toBe(16000)
  180. })
  181. })
  182. describe("bedrock", () => {
  183. test("returns 32k when modelLimit > 32k", () => {
  184. const modelLimit = 100000
  185. const result = ProviderTransform.maxOutputTokens("@ai-sdk/amazon-bedrock", {}, modelLimit, OUTPUT_TOKEN_MAX)
  186. expect(result).toBe(OUTPUT_TOKEN_MAX)
  187. })
  188. test("returns modelLimit when modelLimit < 32k", () => {
  189. const modelLimit = 16000
  190. const result = ProviderTransform.maxOutputTokens("@ai-sdk/amazon-bedrock", {}, modelLimit, OUTPUT_TOKEN_MAX)
  191. expect(result).toBe(16000)
  192. })
  193. })
  194. describe("anthropic without thinking options", () => {
  195. test("returns 32k when modelLimit > 32k", () => {
  196. const modelLimit = 100000
  197. const result = ProviderTransform.maxOutputTokens("@ai-sdk/anthropic", {}, modelLimit, OUTPUT_TOKEN_MAX)
  198. expect(result).toBe(OUTPUT_TOKEN_MAX)
  199. })
  200. test("returns modelLimit when modelLimit < 32k", () => {
  201. const modelLimit = 16000
  202. const result = ProviderTransform.maxOutputTokens("@ai-sdk/anthropic", {}, modelLimit, OUTPUT_TOKEN_MAX)
  203. expect(result).toBe(16000)
  204. })
  205. })
  206. describe("anthropic with thinking options", () => {
  207. test("returns 32k when budgetTokens + 32k <= modelLimit", () => {
  208. const modelLimit = 100000
  209. const options = {
  210. thinking: {
  211. type: "enabled",
  212. budgetTokens: 10000,
  213. },
  214. }
  215. const result = ProviderTransform.maxOutputTokens("@ai-sdk/anthropic", options, modelLimit, OUTPUT_TOKEN_MAX)
  216. expect(result).toBe(OUTPUT_TOKEN_MAX)
  217. })
  218. test("returns modelLimit - budgetTokens when budgetTokens + 32k > modelLimit", () => {
  219. const modelLimit = 50000
  220. const options = {
  221. thinking: {
  222. type: "enabled",
  223. budgetTokens: 30000,
  224. },
  225. }
  226. const result = ProviderTransform.maxOutputTokens("@ai-sdk/anthropic", options, modelLimit, OUTPUT_TOKEN_MAX)
  227. expect(result).toBe(20000)
  228. })
  229. test("returns 32k when thinking type is not enabled", () => {
  230. const modelLimit = 100000
  231. const options = {
  232. thinking: {
  233. type: "disabled",
  234. budgetTokens: 10000,
  235. },
  236. }
  237. const result = ProviderTransform.maxOutputTokens("@ai-sdk/anthropic", options, modelLimit, OUTPUT_TOKEN_MAX)
  238. expect(result).toBe(OUTPUT_TOKEN_MAX)
  239. })
  240. })
  241. })
  242. describe("ProviderTransform.schema - gemini array items", () => {
  243. test("adds missing items for array properties", () => {
  244. const geminiModel = {
  245. providerID: "google",
  246. api: {
  247. id: "gemini-3-pro",
  248. },
  249. } as any
  250. const schema = {
  251. type: "object",
  252. properties: {
  253. nodes: { type: "array" },
  254. edges: { type: "array", items: { type: "string" } },
  255. },
  256. } as any
  257. const result = ProviderTransform.schema(geminiModel, schema) as any
  258. expect(result.properties.nodes.items).toBeDefined()
  259. expect(result.properties.edges.items.type).toBe("string")
  260. })
  261. })
  262. describe("ProviderTransform.message - DeepSeek reasoning content", () => {
  263. test("DeepSeek with tool calls includes reasoning_content in providerOptions", () => {
  264. const msgs = [
  265. {
  266. role: "assistant",
  267. content: [
  268. { type: "reasoning", text: "Let me think about this..." },
  269. {
  270. type: "tool-call",
  271. toolCallId: "test",
  272. toolName: "bash",
  273. input: { command: "echo hello" },
  274. },
  275. ],
  276. },
  277. ] as any[]
  278. const result = ProviderTransform.message(
  279. msgs,
  280. {
  281. id: "deepseek/deepseek-chat",
  282. providerID: "deepseek",
  283. api: {
  284. id: "deepseek-chat",
  285. url: "https://api.deepseek.com",
  286. npm: "@ai-sdk/openai-compatible",
  287. },
  288. name: "DeepSeek Chat",
  289. capabilities: {
  290. temperature: true,
  291. reasoning: true,
  292. attachment: false,
  293. toolcall: true,
  294. input: { text: true, audio: false, image: false, video: false, pdf: false },
  295. output: { text: true, audio: false, image: false, video: false, pdf: false },
  296. interleaved: {
  297. field: "reasoning_content",
  298. },
  299. },
  300. cost: {
  301. input: 0.001,
  302. output: 0.002,
  303. cache: { read: 0.0001, write: 0.0002 },
  304. },
  305. limit: {
  306. context: 128000,
  307. output: 8192,
  308. },
  309. status: "active",
  310. options: {},
  311. headers: {},
  312. release_date: "2023-04-01",
  313. },
  314. {},
  315. )
  316. expect(result).toHaveLength(1)
  317. expect(result[0].content).toEqual([
  318. {
  319. type: "tool-call",
  320. toolCallId: "test",
  321. toolName: "bash",
  322. input: { command: "echo hello" },
  323. },
  324. ])
  325. expect(result[0].providerOptions?.openaiCompatible?.reasoning_content).toBe("Let me think about this...")
  326. })
  327. test("Non-DeepSeek providers leave reasoning content unchanged", () => {
  328. const msgs = [
  329. {
  330. role: "assistant",
  331. content: [
  332. { type: "reasoning", text: "Should not be processed" },
  333. { type: "text", text: "Answer" },
  334. ],
  335. },
  336. ] as any[]
  337. const result = ProviderTransform.message(
  338. msgs,
  339. {
  340. id: "openai/gpt-4",
  341. providerID: "openai",
  342. api: {
  343. id: "gpt-4",
  344. url: "https://api.openai.com",
  345. npm: "@ai-sdk/openai",
  346. },
  347. name: "GPT-4",
  348. capabilities: {
  349. temperature: true,
  350. reasoning: false,
  351. attachment: true,
  352. toolcall: true,
  353. input: { text: true, audio: false, image: true, video: false, pdf: false },
  354. output: { text: true, audio: false, image: false, video: false, pdf: false },
  355. interleaved: false,
  356. },
  357. cost: {
  358. input: 0.03,
  359. output: 0.06,
  360. cache: { read: 0.001, write: 0.002 },
  361. },
  362. limit: {
  363. context: 128000,
  364. output: 4096,
  365. },
  366. status: "active",
  367. options: {},
  368. headers: {},
  369. release_date: "2023-04-01",
  370. },
  371. {},
  372. )
  373. expect(result[0].content).toEqual([
  374. { type: "reasoning", text: "Should not be processed" },
  375. { type: "text", text: "Answer" },
  376. ])
  377. expect(result[0].providerOptions?.openaiCompatible?.reasoning_content).toBeUndefined()
  378. })
  379. })
  380. describe("ProviderTransform.message - empty image handling", () => {
  381. const mockModel = {
  382. id: "anthropic/claude-3-5-sonnet",
  383. providerID: "anthropic",
  384. api: {
  385. id: "claude-3-5-sonnet-20241022",
  386. url: "https://api.anthropic.com",
  387. npm: "@ai-sdk/anthropic",
  388. },
  389. name: "Claude 3.5 Sonnet",
  390. capabilities: {
  391. temperature: true,
  392. reasoning: false,
  393. attachment: true,
  394. toolcall: true,
  395. input: { text: true, audio: false, image: true, video: false, pdf: true },
  396. output: { text: true, audio: false, image: false, video: false, pdf: false },
  397. interleaved: false,
  398. },
  399. cost: {
  400. input: 0.003,
  401. output: 0.015,
  402. cache: { read: 0.0003, write: 0.00375 },
  403. },
  404. limit: {
  405. context: 200000,
  406. output: 8192,
  407. },
  408. status: "active",
  409. options: {},
  410. headers: {},
  411. } as any
  412. test("should replace empty base64 image with error text", () => {
  413. const msgs = [
  414. {
  415. role: "user",
  416. content: [
  417. { type: "text", text: "What is in this image?" },
  418. { type: "image", image: "data:image/png;base64," },
  419. ],
  420. },
  421. ] as any[]
  422. const result = ProviderTransform.message(msgs, mockModel, {})
  423. expect(result).toHaveLength(1)
  424. expect(result[0].content).toHaveLength(2)
  425. expect(result[0].content[0]).toEqual({ type: "text", text: "What is in this image?" })
  426. expect(result[0].content[1]).toEqual({
  427. type: "text",
  428. text: "ERROR: Image file is empty or corrupted. Please provide a valid image.",
  429. })
  430. })
  431. test("should keep valid base64 images unchanged", () => {
  432. const validBase64 =
  433. "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg=="
  434. const msgs = [
  435. {
  436. role: "user",
  437. content: [
  438. { type: "text", text: "What is in this image?" },
  439. { type: "image", image: `data:image/png;base64,${validBase64}` },
  440. ],
  441. },
  442. ] as any[]
  443. const result = ProviderTransform.message(msgs, mockModel, {})
  444. expect(result).toHaveLength(1)
  445. expect(result[0].content).toHaveLength(2)
  446. expect(result[0].content[0]).toEqual({ type: "text", text: "What is in this image?" })
  447. expect(result[0].content[1]).toEqual({ type: "image", image: `data:image/png;base64,${validBase64}` })
  448. })
  449. test("should handle mixed valid and empty images", () => {
  450. const validBase64 =
  451. "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg=="
  452. const msgs = [
  453. {
  454. role: "user",
  455. content: [
  456. { type: "text", text: "Compare these images" },
  457. { type: "image", image: `data:image/png;base64,${validBase64}` },
  458. { type: "image", image: "data:image/jpeg;base64," },
  459. ],
  460. },
  461. ] as any[]
  462. const result = ProviderTransform.message(msgs, mockModel, {})
  463. expect(result).toHaveLength(1)
  464. expect(result[0].content).toHaveLength(3)
  465. expect(result[0].content[0]).toEqual({ type: "text", text: "Compare these images" })
  466. expect(result[0].content[1]).toEqual({ type: "image", image: `data:image/png;base64,${validBase64}` })
  467. expect(result[0].content[2]).toEqual({
  468. type: "text",
  469. text: "ERROR: Image file is empty or corrupted. Please provide a valid image.",
  470. })
  471. })
  472. })
  473. describe("ProviderTransform.message - anthropic empty content filtering", () => {
  474. const anthropicModel = {
  475. id: "anthropic/claude-3-5-sonnet",
  476. providerID: "anthropic",
  477. api: {
  478. id: "claude-3-5-sonnet-20241022",
  479. url: "https://api.anthropic.com",
  480. npm: "@ai-sdk/anthropic",
  481. },
  482. name: "Claude 3.5 Sonnet",
  483. capabilities: {
  484. temperature: true,
  485. reasoning: false,
  486. attachment: true,
  487. toolcall: true,
  488. input: { text: true, audio: false, image: true, video: false, pdf: true },
  489. output: { text: true, audio: false, image: false, video: false, pdf: false },
  490. interleaved: false,
  491. },
  492. cost: {
  493. input: 0.003,
  494. output: 0.015,
  495. cache: { read: 0.0003, write: 0.00375 },
  496. },
  497. limit: {
  498. context: 200000,
  499. output: 8192,
  500. },
  501. status: "active",
  502. options: {},
  503. headers: {},
  504. } as any
  505. test("filters out messages with empty string content", () => {
  506. const msgs = [
  507. { role: "user", content: "Hello" },
  508. { role: "assistant", content: "" },
  509. { role: "user", content: "World" },
  510. ] as any[]
  511. const result = ProviderTransform.message(msgs, anthropicModel, {})
  512. expect(result).toHaveLength(2)
  513. expect(result[0].content).toBe("Hello")
  514. expect(result[1].content).toBe("World")
  515. })
  516. test("filters out empty text parts from array content", () => {
  517. const msgs = [
  518. {
  519. role: "assistant",
  520. content: [
  521. { type: "text", text: "" },
  522. { type: "text", text: "Hello" },
  523. { type: "text", text: "" },
  524. ],
  525. },
  526. ] as any[]
  527. const result = ProviderTransform.message(msgs, anthropicModel, {})
  528. expect(result).toHaveLength(1)
  529. expect(result[0].content).toHaveLength(1)
  530. expect(result[0].content[0]).toEqual({ type: "text", text: "Hello" })
  531. })
  532. test("filters out empty reasoning parts from array content", () => {
  533. const msgs = [
  534. {
  535. role: "assistant",
  536. content: [
  537. { type: "reasoning", text: "" },
  538. { type: "text", text: "Answer" },
  539. { type: "reasoning", text: "" },
  540. ],
  541. },
  542. ] as any[]
  543. const result = ProviderTransform.message(msgs, anthropicModel, {})
  544. expect(result).toHaveLength(1)
  545. expect(result[0].content).toHaveLength(1)
  546. expect(result[0].content[0]).toEqual({ type: "text", text: "Answer" })
  547. })
  548. test("removes entire message when all parts are empty", () => {
  549. const msgs = [
  550. { role: "user", content: "Hello" },
  551. {
  552. role: "assistant",
  553. content: [
  554. { type: "text", text: "" },
  555. { type: "reasoning", text: "" },
  556. ],
  557. },
  558. { role: "user", content: "World" },
  559. ] as any[]
  560. const result = ProviderTransform.message(msgs, anthropicModel, {})
  561. expect(result).toHaveLength(2)
  562. expect(result[0].content).toBe("Hello")
  563. expect(result[1].content).toBe("World")
  564. })
  565. test("keeps non-text/reasoning parts even if text parts are empty", () => {
  566. const msgs = [
  567. {
  568. role: "assistant",
  569. content: [
  570. { type: "text", text: "" },
  571. { type: "tool-call", toolCallId: "123", toolName: "bash", input: { command: "ls" } },
  572. ],
  573. },
  574. ] as any[]
  575. const result = ProviderTransform.message(msgs, anthropicModel, {})
  576. expect(result).toHaveLength(1)
  577. expect(result[0].content).toHaveLength(1)
  578. expect(result[0].content[0]).toEqual({
  579. type: "tool-call",
  580. toolCallId: "123",
  581. toolName: "bash",
  582. input: { command: "ls" },
  583. })
  584. })
  585. test("keeps messages with valid text alongside empty parts", () => {
  586. const msgs = [
  587. {
  588. role: "assistant",
  589. content: [
  590. { type: "reasoning", text: "Thinking..." },
  591. { type: "text", text: "" },
  592. { type: "text", text: "Result" },
  593. ],
  594. },
  595. ] as any[]
  596. const result = ProviderTransform.message(msgs, anthropicModel, {})
  597. expect(result).toHaveLength(1)
  598. expect(result[0].content).toHaveLength(2)
  599. expect(result[0].content[0]).toEqual({ type: "reasoning", text: "Thinking..." })
  600. expect(result[0].content[1]).toEqual({ type: "text", text: "Result" })
  601. })
  602. test("does not filter for non-anthropic providers", () => {
  603. const openaiModel = {
  604. ...anthropicModel,
  605. providerID: "openai",
  606. api: {
  607. id: "gpt-4",
  608. url: "https://api.openai.com",
  609. npm: "@ai-sdk/openai",
  610. },
  611. }
  612. const msgs = [
  613. { role: "assistant", content: "" },
  614. {
  615. role: "assistant",
  616. content: [{ type: "text", text: "" }],
  617. },
  618. ] as any[]
  619. const result = ProviderTransform.message(msgs, openaiModel, {})
  620. expect(result).toHaveLength(2)
  621. expect(result[0].content).toBe("")
  622. expect(result[1].content).toHaveLength(1)
  623. })
  624. })
  625. describe("ProviderTransform.message - strip openai metadata when store=false", () => {
  626. const openaiModel = {
  627. id: "openai/gpt-5",
  628. providerID: "openai",
  629. api: {
  630. id: "gpt-5",
  631. url: "https://api.openai.com",
  632. npm: "@ai-sdk/openai",
  633. },
  634. name: "GPT-5",
  635. capabilities: {
  636. temperature: true,
  637. reasoning: true,
  638. attachment: true,
  639. toolcall: true,
  640. input: { text: true, audio: false, image: true, video: false, pdf: false },
  641. output: { text: true, audio: false, image: false, video: false, pdf: false },
  642. interleaved: false,
  643. },
  644. cost: { input: 0.03, output: 0.06, cache: { read: 0.001, write: 0.002 } },
  645. limit: { context: 128000, output: 4096 },
  646. status: "active",
  647. options: {},
  648. headers: {},
  649. } as any
  650. test("preserves itemId and reasoningEncryptedContent when store=false", () => {
  651. const msgs = [
  652. {
  653. role: "assistant",
  654. content: [
  655. {
  656. type: "reasoning",
  657. text: "thinking...",
  658. providerOptions: {
  659. openai: {
  660. itemId: "rs_123",
  661. reasoningEncryptedContent: "encrypted",
  662. },
  663. },
  664. },
  665. {
  666. type: "text",
  667. text: "Hello",
  668. providerOptions: {
  669. openai: {
  670. itemId: "msg_456",
  671. },
  672. },
  673. },
  674. ],
  675. },
  676. ] as any[]
  677. const result = ProviderTransform.message(msgs, openaiModel, { store: false }) as any[]
  678. expect(result).toHaveLength(1)
  679. expect(result[0].content[0].providerOptions?.openai?.itemId).toBe("rs_123")
  680. expect(result[0].content[1].providerOptions?.openai?.itemId).toBe("msg_456")
  681. })
  682. test("preserves itemId and reasoningEncryptedContent when store=false even when not openai", () => {
  683. const zenModel = {
  684. ...openaiModel,
  685. providerID: "zen",
  686. }
  687. const msgs = [
  688. {
  689. role: "assistant",
  690. content: [
  691. {
  692. type: "reasoning",
  693. text: "thinking...",
  694. providerOptions: {
  695. openai: {
  696. itemId: "rs_123",
  697. reasoningEncryptedContent: "encrypted",
  698. },
  699. },
  700. },
  701. {
  702. type: "text",
  703. text: "Hello",
  704. providerOptions: {
  705. openai: {
  706. itemId: "msg_456",
  707. },
  708. },
  709. },
  710. ],
  711. },
  712. ] as any[]
  713. const result = ProviderTransform.message(msgs, zenModel, { store: false }) as any[]
  714. expect(result).toHaveLength(1)
  715. expect(result[0].content[0].providerOptions?.openai?.itemId).toBe("rs_123")
  716. expect(result[0].content[1].providerOptions?.openai?.itemId).toBe("msg_456")
  717. })
  718. test("preserves other openai options including itemId", () => {
  719. const msgs = [
  720. {
  721. role: "assistant",
  722. content: [
  723. {
  724. type: "text",
  725. text: "Hello",
  726. providerOptions: {
  727. openai: {
  728. itemId: "msg_123",
  729. otherOption: "value",
  730. },
  731. },
  732. },
  733. ],
  734. },
  735. ] as any[]
  736. const result = ProviderTransform.message(msgs, openaiModel, { store: false }) as any[]
  737. expect(result[0].content[0].providerOptions?.openai?.itemId).toBe("msg_123")
  738. expect(result[0].content[0].providerOptions?.openai?.otherOption).toBe("value")
  739. })
  740. test("preserves metadata for openai package when store is true", () => {
  741. const msgs = [
  742. {
  743. role: "assistant",
  744. content: [
  745. {
  746. type: "text",
  747. text: "Hello",
  748. providerOptions: {
  749. openai: {
  750. itemId: "msg_123",
  751. },
  752. },
  753. },
  754. ],
  755. },
  756. ] as any[]
  757. // openai package preserves itemId regardless of store value
  758. const result = ProviderTransform.message(msgs, openaiModel, { store: true }) as any[]
  759. expect(result[0].content[0].providerOptions?.openai?.itemId).toBe("msg_123")
  760. })
  761. test("preserves metadata for non-openai packages when store is false", () => {
  762. const anthropicModel = {
  763. ...openaiModel,
  764. providerID: "anthropic",
  765. api: {
  766. id: "claude-3",
  767. url: "https://api.anthropic.com",
  768. npm: "@ai-sdk/anthropic",
  769. },
  770. }
  771. const msgs = [
  772. {
  773. role: "assistant",
  774. content: [
  775. {
  776. type: "text",
  777. text: "Hello",
  778. providerOptions: {
  779. openai: {
  780. itemId: "msg_123",
  781. },
  782. },
  783. },
  784. ],
  785. },
  786. ] as any[]
  787. // store=false preserves metadata for non-openai packages
  788. const result = ProviderTransform.message(msgs, anthropicModel, { store: false }) as any[]
  789. expect(result[0].content[0].providerOptions?.openai?.itemId).toBe("msg_123")
  790. })
  791. test("preserves metadata using providerID key when store is false", () => {
  792. const opencodeModel = {
  793. ...openaiModel,
  794. providerID: "opencode",
  795. api: {
  796. id: "opencode-test",
  797. url: "https://api.opencode.ai",
  798. npm: "@ai-sdk/openai-compatible",
  799. },
  800. }
  801. const msgs = [
  802. {
  803. role: "assistant",
  804. content: [
  805. {
  806. type: "text",
  807. text: "Hello",
  808. providerOptions: {
  809. opencode: {
  810. itemId: "msg_123",
  811. otherOption: "value",
  812. },
  813. },
  814. },
  815. ],
  816. },
  817. ] as any[]
  818. const result = ProviderTransform.message(msgs, opencodeModel, { store: false }) as any[]
  819. expect(result[0].content[0].providerOptions?.opencode?.itemId).toBe("msg_123")
  820. expect(result[0].content[0].providerOptions?.opencode?.otherOption).toBe("value")
  821. })
  822. test("preserves itemId across all providerOptions keys", () => {
  823. const opencodeModel = {
  824. ...openaiModel,
  825. providerID: "opencode",
  826. api: {
  827. id: "opencode-test",
  828. url: "https://api.opencode.ai",
  829. npm: "@ai-sdk/openai-compatible",
  830. },
  831. }
  832. const msgs = [
  833. {
  834. role: "assistant",
  835. providerOptions: {
  836. openai: { itemId: "msg_root" },
  837. opencode: { itemId: "msg_opencode" },
  838. extra: { itemId: "msg_extra" },
  839. },
  840. content: [
  841. {
  842. type: "text",
  843. text: "Hello",
  844. providerOptions: {
  845. openai: { itemId: "msg_openai_part" },
  846. opencode: { itemId: "msg_opencode_part" },
  847. extra: { itemId: "msg_extra_part" },
  848. },
  849. },
  850. ],
  851. },
  852. ] as any[]
  853. const result = ProviderTransform.message(msgs, opencodeModel, { store: false }) as any[]
  854. expect(result[0].providerOptions?.openai?.itemId).toBe("msg_root")
  855. expect(result[0].providerOptions?.opencode?.itemId).toBe("msg_opencode")
  856. expect(result[0].providerOptions?.extra?.itemId).toBe("msg_extra")
  857. expect(result[0].content[0].providerOptions?.openai?.itemId).toBe("msg_openai_part")
  858. expect(result[0].content[0].providerOptions?.opencode?.itemId).toBe("msg_opencode_part")
  859. expect(result[0].content[0].providerOptions?.extra?.itemId).toBe("msg_extra_part")
  860. })
  861. test("does not strip metadata for non-openai packages when store is not false", () => {
  862. const anthropicModel = {
  863. ...openaiModel,
  864. providerID: "anthropic",
  865. api: {
  866. id: "claude-3",
  867. url: "https://api.anthropic.com",
  868. npm: "@ai-sdk/anthropic",
  869. },
  870. }
  871. const msgs = [
  872. {
  873. role: "assistant",
  874. content: [
  875. {
  876. type: "text",
  877. text: "Hello",
  878. providerOptions: {
  879. openai: {
  880. itemId: "msg_123",
  881. },
  882. },
  883. },
  884. ],
  885. },
  886. ] as any[]
  887. const result = ProviderTransform.message(msgs, anthropicModel, {}) as any[]
  888. expect(result[0].content[0].providerOptions?.openai?.itemId).toBe("msg_123")
  889. })
  890. })
  891. describe("ProviderTransform.message - providerOptions key remapping", () => {
  892. const createModel = (providerID: string, npm: string) =>
  893. ({
  894. id: `${providerID}/test-model`,
  895. providerID,
  896. api: {
  897. id: "test-model",
  898. url: "https://api.test.com",
  899. npm,
  900. },
  901. name: "Test Model",
  902. capabilities: {
  903. temperature: true,
  904. reasoning: false,
  905. attachment: true,
  906. toolcall: true,
  907. input: { text: true, audio: false, image: true, video: false, pdf: true },
  908. output: { text: true, audio: false, image: false, video: false, pdf: false },
  909. interleaved: false,
  910. },
  911. cost: { input: 0.001, output: 0.002, cache: { read: 0.0001, write: 0.0002 } },
  912. limit: { context: 128000, output: 8192 },
  913. status: "active",
  914. options: {},
  915. headers: {},
  916. }) as any
  917. test("azure keeps 'azure' key and does not remap to 'openai'", () => {
  918. const model = createModel("azure", "@ai-sdk/azure")
  919. const msgs = [
  920. {
  921. role: "user",
  922. content: "Hello",
  923. providerOptions: {
  924. azure: { someOption: "value" },
  925. },
  926. },
  927. ] as any[]
  928. const result = ProviderTransform.message(msgs, model, {})
  929. expect(result[0].providerOptions?.azure).toEqual({ someOption: "value" })
  930. expect(result[0].providerOptions?.openai).toBeUndefined()
  931. })
  932. test("openai with github-copilot npm remaps providerID to 'openai'", () => {
  933. const model = createModel("github-copilot", "@ai-sdk/github-copilot")
  934. const msgs = [
  935. {
  936. role: "user",
  937. content: "Hello",
  938. providerOptions: {
  939. "github-copilot": { someOption: "value" },
  940. },
  941. },
  942. ] as any[]
  943. const result = ProviderTransform.message(msgs, model, {})
  944. expect(result[0].providerOptions?.openai).toEqual({ someOption: "value" })
  945. expect(result[0].providerOptions?.["github-copilot"]).toBeUndefined()
  946. })
  947. test("bedrock remaps providerID to 'bedrock' key", () => {
  948. const model = createModel("my-bedrock", "@ai-sdk/amazon-bedrock")
  949. const msgs = [
  950. {
  951. role: "user",
  952. content: "Hello",
  953. providerOptions: {
  954. "my-bedrock": { someOption: "value" },
  955. },
  956. },
  957. ] as any[]
  958. const result = ProviderTransform.message(msgs, model, {})
  959. expect(result[0].providerOptions?.bedrock).toEqual({ someOption: "value" })
  960. expect(result[0].providerOptions?.["my-bedrock"]).toBeUndefined()
  961. })
  962. })
  963. describe("ProviderTransform.message - claude w/bedrock custom inference profile", () => {
  964. test("adds cachePoint", () => {
  965. const model = {
  966. id: "amazon-bedrock/custom-claude-sonnet-4.5",
  967. providerID: "amazon-bedrock",
  968. api: {
  969. id: "arn:aws:bedrock:xxx:yyy:application-inference-profile/zzz",
  970. url: "https://api.test.com",
  971. npm: "@ai-sdk/amazon-bedrock",
  972. },
  973. name: "Custom inference profile",
  974. capabilities: {},
  975. options: {},
  976. headers: {},
  977. } as any
  978. const msgs = [
  979. {
  980. role: "user",
  981. content: "Hello",
  982. },
  983. ] as any[]
  984. const result = ProviderTransform.message(msgs, model, {})
  985. expect(result[0].providerOptions?.bedrock).toEqual(
  986. expect.objectContaining({
  987. cachePoint: {
  988. type: "ephemeral",
  989. },
  990. }),
  991. )
  992. })
  993. })
  994. describe("ProviderTransform.variants", () => {
  995. const createMockModel = (overrides: Partial<any> = {}): any => ({
  996. id: "test/test-model",
  997. providerID: "test",
  998. api: {
  999. id: "test-model",
  1000. url: "https://api.test.com",
  1001. npm: "@ai-sdk/openai",
  1002. },
  1003. name: "Test Model",
  1004. capabilities: {
  1005. temperature: true,
  1006. reasoning: true,
  1007. attachment: true,
  1008. toolcall: true,
  1009. input: { text: true, audio: false, image: true, video: false, pdf: false },
  1010. output: { text: true, audio: false, image: false, video: false, pdf: false },
  1011. interleaved: false,
  1012. },
  1013. cost: {
  1014. input: 0.001,
  1015. output: 0.002,
  1016. cache: { read: 0.0001, write: 0.0002 },
  1017. },
  1018. limit: {
  1019. context: 200_000,
  1020. output: 64_000,
  1021. },
  1022. status: "active",
  1023. options: {},
  1024. headers: {},
  1025. release_date: "2024-01-01",
  1026. ...overrides,
  1027. })
  1028. test("returns empty object when model has no reasoning capabilities", () => {
  1029. const model = createMockModel({
  1030. capabilities: { reasoning: false },
  1031. })
  1032. const result = ProviderTransform.variants(model)
  1033. expect(result).toEqual({})
  1034. })
  1035. test("deepseek returns empty object", () => {
  1036. const model = createMockModel({
  1037. id: "deepseek/deepseek-chat",
  1038. providerID: "deepseek",
  1039. api: {
  1040. id: "deepseek-chat",
  1041. url: "https://api.deepseek.com",
  1042. npm: "@ai-sdk/openai-compatible",
  1043. },
  1044. })
  1045. const result = ProviderTransform.variants(model)
  1046. expect(result).toEqual({})
  1047. })
  1048. test("minimax returns empty object", () => {
  1049. const model = createMockModel({
  1050. id: "minimax/minimax-model",
  1051. providerID: "minimax",
  1052. api: {
  1053. id: "minimax-model",
  1054. url: "https://api.minimax.com",
  1055. npm: "@ai-sdk/openai-compatible",
  1056. },
  1057. })
  1058. const result = ProviderTransform.variants(model)
  1059. expect(result).toEqual({})
  1060. })
  1061. test("glm returns empty object", () => {
  1062. const model = createMockModel({
  1063. id: "glm/glm-4",
  1064. providerID: "glm",
  1065. api: {
  1066. id: "glm-4",
  1067. url: "https://api.glm.com",
  1068. npm: "@ai-sdk/openai-compatible",
  1069. },
  1070. })
  1071. const result = ProviderTransform.variants(model)
  1072. expect(result).toEqual({})
  1073. })
  1074. test("mistral returns empty object", () => {
  1075. const model = createMockModel({
  1076. id: "mistral/mistral-large",
  1077. providerID: "mistral",
  1078. api: {
  1079. id: "mistral-large-latest",
  1080. url: "https://api.mistral.com",
  1081. npm: "@ai-sdk/mistral",
  1082. },
  1083. })
  1084. const result = ProviderTransform.variants(model)
  1085. expect(result).toEqual({})
  1086. })
  1087. describe("@openrouter/ai-sdk-provider", () => {
  1088. test("returns empty object for non-qualifying models", () => {
  1089. const model = createMockModel({
  1090. id: "openrouter/test-model",
  1091. providerID: "openrouter",
  1092. api: {
  1093. id: "test-model",
  1094. url: "https://openrouter.ai",
  1095. npm: "@openrouter/ai-sdk-provider",
  1096. },
  1097. })
  1098. const result = ProviderTransform.variants(model)
  1099. expect(result).toEqual({})
  1100. })
  1101. test("gpt models return OPENAI_EFFORTS with reasoning", () => {
  1102. const model = createMockModel({
  1103. id: "openrouter/gpt-4",
  1104. providerID: "openrouter",
  1105. api: {
  1106. id: "gpt-4",
  1107. url: "https://openrouter.ai",
  1108. npm: "@openrouter/ai-sdk-provider",
  1109. },
  1110. })
  1111. const result = ProviderTransform.variants(model)
  1112. expect(Object.keys(result)).toEqual(["none", "minimal", "low", "medium", "high", "xhigh"])
  1113. expect(result.low).toEqual({ reasoning: { effort: "low" } })
  1114. expect(result.high).toEqual({ reasoning: { effort: "high" } })
  1115. })
  1116. test("gemini-3 returns OPENAI_EFFORTS with reasoning", () => {
  1117. const model = createMockModel({
  1118. id: "openrouter/gemini-3-5-pro",
  1119. providerID: "openrouter",
  1120. api: {
  1121. id: "gemini-3-5-pro",
  1122. url: "https://openrouter.ai",
  1123. npm: "@openrouter/ai-sdk-provider",
  1124. },
  1125. })
  1126. const result = ProviderTransform.variants(model)
  1127. expect(Object.keys(result)).toEqual(["none", "minimal", "low", "medium", "high", "xhigh"])
  1128. })
  1129. test("grok-4 returns empty object", () => {
  1130. const model = createMockModel({
  1131. id: "openrouter/grok-4",
  1132. providerID: "openrouter",
  1133. api: {
  1134. id: "grok-4",
  1135. url: "https://openrouter.ai",
  1136. npm: "@openrouter/ai-sdk-provider",
  1137. },
  1138. })
  1139. const result = ProviderTransform.variants(model)
  1140. expect(result).toEqual({})
  1141. })
  1142. test("grok-3-mini returns low and high with reasoning", () => {
  1143. const model = createMockModel({
  1144. id: "openrouter/grok-3-mini",
  1145. providerID: "openrouter",
  1146. api: {
  1147. id: "grok-3-mini",
  1148. url: "https://openrouter.ai",
  1149. npm: "@openrouter/ai-sdk-provider",
  1150. },
  1151. })
  1152. const result = ProviderTransform.variants(model)
  1153. expect(Object.keys(result)).toEqual(["low", "high"])
  1154. expect(result.low).toEqual({ reasoning: { effort: "low" } })
  1155. expect(result.high).toEqual({ reasoning: { effort: "high" } })
  1156. })
  1157. })
  1158. describe("@ai-sdk/gateway", () => {
  1159. test("returns OPENAI_EFFORTS with reasoningEffort", () => {
  1160. const model = createMockModel({
  1161. id: "gateway/gateway-model",
  1162. providerID: "gateway",
  1163. api: {
  1164. id: "gateway-model",
  1165. url: "https://gateway.ai",
  1166. npm: "@ai-sdk/gateway",
  1167. },
  1168. })
  1169. const result = ProviderTransform.variants(model)
  1170. expect(Object.keys(result)).toEqual(["none", "minimal", "low", "medium", "high", "xhigh"])
  1171. expect(result.low).toEqual({ reasoningEffort: "low" })
  1172. expect(result.high).toEqual({ reasoningEffort: "high" })
  1173. })
  1174. })
  1175. describe("@ai-sdk/github-copilot", () => {
  1176. test("standard models return low, medium, high", () => {
  1177. const model = createMockModel({
  1178. id: "gpt-4.5",
  1179. providerID: "github-copilot",
  1180. api: {
  1181. id: "gpt-4.5",
  1182. url: "https://api.githubcopilot.com",
  1183. npm: "@ai-sdk/github-copilot",
  1184. },
  1185. })
  1186. const result = ProviderTransform.variants(model)
  1187. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  1188. expect(result.low).toEqual({
  1189. reasoningEffort: "low",
  1190. reasoningSummary: "auto",
  1191. include: ["reasoning.encrypted_content"],
  1192. })
  1193. })
  1194. test("gpt-5.1-codex-max includes xhigh", () => {
  1195. const model = createMockModel({
  1196. id: "gpt-5.1-codex-max",
  1197. providerID: "github-copilot",
  1198. api: {
  1199. id: "gpt-5.1-codex-max",
  1200. url: "https://api.githubcopilot.com",
  1201. npm: "@ai-sdk/github-copilot",
  1202. },
  1203. })
  1204. const result = ProviderTransform.variants(model)
  1205. expect(Object.keys(result)).toEqual(["low", "medium", "high", "xhigh"])
  1206. })
  1207. test("gpt-5.1-codex-mini does not include xhigh", () => {
  1208. const model = createMockModel({
  1209. id: "gpt-5.1-codex-mini",
  1210. providerID: "github-copilot",
  1211. api: {
  1212. id: "gpt-5.1-codex-mini",
  1213. url: "https://api.githubcopilot.com",
  1214. npm: "@ai-sdk/github-copilot",
  1215. },
  1216. })
  1217. const result = ProviderTransform.variants(model)
  1218. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  1219. })
  1220. test("gpt-5.1-codex does not include xhigh", () => {
  1221. const model = createMockModel({
  1222. id: "gpt-5.1-codex",
  1223. providerID: "github-copilot",
  1224. api: {
  1225. id: "gpt-5.1-codex",
  1226. url: "https://api.githubcopilot.com",
  1227. npm: "@ai-sdk/github-copilot",
  1228. },
  1229. })
  1230. const result = ProviderTransform.variants(model)
  1231. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  1232. })
  1233. test("gpt-5.2 includes xhigh", () => {
  1234. const model = createMockModel({
  1235. id: "gpt-5.2",
  1236. providerID: "github-copilot",
  1237. api: {
  1238. id: "gpt-5.2",
  1239. url: "https://api.githubcopilot.com",
  1240. npm: "@ai-sdk/github-copilot",
  1241. },
  1242. })
  1243. const result = ProviderTransform.variants(model)
  1244. expect(Object.keys(result)).toEqual(["low", "medium", "high", "xhigh"])
  1245. expect(result.xhigh).toEqual({
  1246. reasoningEffort: "xhigh",
  1247. reasoningSummary: "auto",
  1248. include: ["reasoning.encrypted_content"],
  1249. })
  1250. })
  1251. test("gpt-5.2-codex includes xhigh", () => {
  1252. const model = createMockModel({
  1253. id: "gpt-5.2-codex",
  1254. providerID: "github-copilot",
  1255. api: {
  1256. id: "gpt-5.2-codex",
  1257. url: "https://api.githubcopilot.com",
  1258. npm: "@ai-sdk/github-copilot",
  1259. },
  1260. })
  1261. const result = ProviderTransform.variants(model)
  1262. expect(Object.keys(result)).toEqual(["low", "medium", "high", "xhigh"])
  1263. })
  1264. })
  1265. describe("@ai-sdk/cerebras", () => {
  1266. test("returns WIDELY_SUPPORTED_EFFORTS with reasoningEffort", () => {
  1267. const model = createMockModel({
  1268. id: "cerebras/llama-4",
  1269. providerID: "cerebras",
  1270. api: {
  1271. id: "llama-4-sc",
  1272. url: "https://api.cerebras.ai",
  1273. npm: "@ai-sdk/cerebras",
  1274. },
  1275. })
  1276. const result = ProviderTransform.variants(model)
  1277. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  1278. expect(result.low).toEqual({ reasoningEffort: "low" })
  1279. expect(result.high).toEqual({ reasoningEffort: "high" })
  1280. })
  1281. })
  1282. describe("@ai-sdk/togetherai", () => {
  1283. test("returns WIDELY_SUPPORTED_EFFORTS with reasoningEffort", () => {
  1284. const model = createMockModel({
  1285. id: "togetherai/llama-4",
  1286. providerID: "togetherai",
  1287. api: {
  1288. id: "llama-4-sc",
  1289. url: "https://api.togetherai.com",
  1290. npm: "@ai-sdk/togetherai",
  1291. },
  1292. })
  1293. const result = ProviderTransform.variants(model)
  1294. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  1295. expect(result.low).toEqual({ reasoningEffort: "low" })
  1296. expect(result.high).toEqual({ reasoningEffort: "high" })
  1297. })
  1298. })
  1299. describe("@ai-sdk/xai", () => {
  1300. test("grok-3 returns empty object", () => {
  1301. const model = createMockModel({
  1302. id: "xai/grok-3",
  1303. providerID: "xai",
  1304. api: {
  1305. id: "grok-3",
  1306. url: "https://api.x.ai",
  1307. npm: "@ai-sdk/xai",
  1308. },
  1309. })
  1310. const result = ProviderTransform.variants(model)
  1311. expect(result).toEqual({})
  1312. })
  1313. test("grok-3-mini returns low and high with reasoningEffort", () => {
  1314. const model = createMockModel({
  1315. id: "xai/grok-3-mini",
  1316. providerID: "xai",
  1317. api: {
  1318. id: "grok-3-mini",
  1319. url: "https://api.x.ai",
  1320. npm: "@ai-sdk/xai",
  1321. },
  1322. })
  1323. const result = ProviderTransform.variants(model)
  1324. expect(Object.keys(result)).toEqual(["low", "high"])
  1325. expect(result.low).toEqual({ reasoningEffort: "low" })
  1326. expect(result.high).toEqual({ reasoningEffort: "high" })
  1327. })
  1328. })
  1329. describe("@ai-sdk/deepinfra", () => {
  1330. test("returns WIDELY_SUPPORTED_EFFORTS with reasoningEffort", () => {
  1331. const model = createMockModel({
  1332. id: "deepinfra/llama-4",
  1333. providerID: "deepinfra",
  1334. api: {
  1335. id: "llama-4-sc",
  1336. url: "https://api.deepinfra.com",
  1337. npm: "@ai-sdk/deepinfra",
  1338. },
  1339. })
  1340. const result = ProviderTransform.variants(model)
  1341. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  1342. expect(result.low).toEqual({ reasoningEffort: "low" })
  1343. expect(result.high).toEqual({ reasoningEffort: "high" })
  1344. })
  1345. })
  1346. describe("@ai-sdk/openai-compatible", () => {
  1347. test("returns WIDELY_SUPPORTED_EFFORTS with reasoningEffort", () => {
  1348. const model = createMockModel({
  1349. id: "custom-provider/custom-model",
  1350. providerID: "custom-provider",
  1351. api: {
  1352. id: "custom-model",
  1353. url: "https://api.custom.com",
  1354. npm: "@ai-sdk/openai-compatible",
  1355. },
  1356. })
  1357. const result = ProviderTransform.variants(model)
  1358. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  1359. expect(result.low).toEqual({ reasoningEffort: "low" })
  1360. expect(result.high).toEqual({ reasoningEffort: "high" })
  1361. })
  1362. })
  1363. describe("@ai-sdk/azure", () => {
  1364. test("o1-mini returns empty object", () => {
  1365. const model = createMockModel({
  1366. id: "o1-mini",
  1367. providerID: "azure",
  1368. api: {
  1369. id: "o1-mini",
  1370. url: "https://azure.com",
  1371. npm: "@ai-sdk/azure",
  1372. },
  1373. })
  1374. const result = ProviderTransform.variants(model)
  1375. expect(result).toEqual({})
  1376. })
  1377. test("standard azure models return custom efforts with reasoningSummary", () => {
  1378. const model = createMockModel({
  1379. id: "o1",
  1380. providerID: "azure",
  1381. api: {
  1382. id: "o1",
  1383. url: "https://azure.com",
  1384. npm: "@ai-sdk/azure",
  1385. },
  1386. })
  1387. const result = ProviderTransform.variants(model)
  1388. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  1389. expect(result.low).toEqual({
  1390. reasoningEffort: "low",
  1391. reasoningSummary: "auto",
  1392. include: ["reasoning.encrypted_content"],
  1393. })
  1394. })
  1395. test("gpt-5 adds minimal effort", () => {
  1396. const model = createMockModel({
  1397. id: "gpt-5",
  1398. providerID: "azure",
  1399. api: {
  1400. id: "gpt-5",
  1401. url: "https://azure.com",
  1402. npm: "@ai-sdk/azure",
  1403. },
  1404. })
  1405. const result = ProviderTransform.variants(model)
  1406. expect(Object.keys(result)).toEqual(["minimal", "low", "medium", "high"])
  1407. })
  1408. })
  1409. describe("@ai-sdk/openai", () => {
  1410. test("gpt-5-pro returns empty object", () => {
  1411. const model = createMockModel({
  1412. id: "gpt-5-pro",
  1413. providerID: "openai",
  1414. api: {
  1415. id: "gpt-5-pro",
  1416. url: "https://api.openai.com",
  1417. npm: "@ai-sdk/openai",
  1418. },
  1419. })
  1420. const result = ProviderTransform.variants(model)
  1421. expect(result).toEqual({})
  1422. })
  1423. test("standard openai models return custom efforts with reasoningSummary", () => {
  1424. const model = createMockModel({
  1425. id: "gpt-5",
  1426. providerID: "openai",
  1427. api: {
  1428. id: "gpt-5",
  1429. url: "https://api.openai.com",
  1430. npm: "@ai-sdk/openai",
  1431. },
  1432. release_date: "2024-06-01",
  1433. })
  1434. const result = ProviderTransform.variants(model)
  1435. expect(Object.keys(result)).toEqual(["minimal", "low", "medium", "high"])
  1436. expect(result.low).toEqual({
  1437. reasoningEffort: "low",
  1438. reasoningSummary: "auto",
  1439. include: ["reasoning.encrypted_content"],
  1440. })
  1441. })
  1442. test("models after 2025-11-13 include 'none' effort", () => {
  1443. const model = createMockModel({
  1444. id: "gpt-5-nano",
  1445. providerID: "openai",
  1446. api: {
  1447. id: "gpt-5-nano",
  1448. url: "https://api.openai.com",
  1449. npm: "@ai-sdk/openai",
  1450. },
  1451. release_date: "2025-11-14",
  1452. })
  1453. const result = ProviderTransform.variants(model)
  1454. expect(Object.keys(result)).toEqual(["none", "minimal", "low", "medium", "high"])
  1455. })
  1456. test("models after 2025-12-04 include 'xhigh' effort", () => {
  1457. const model = createMockModel({
  1458. id: "openai/gpt-5-chat",
  1459. providerID: "openai",
  1460. api: {
  1461. id: "gpt-5-chat",
  1462. url: "https://api.openai.com",
  1463. npm: "@ai-sdk/openai",
  1464. },
  1465. release_date: "2025-12-05",
  1466. })
  1467. const result = ProviderTransform.variants(model)
  1468. expect(Object.keys(result)).toEqual(["none", "minimal", "low", "medium", "high", "xhigh"])
  1469. })
  1470. })
  1471. describe("@ai-sdk/anthropic", () => {
  1472. test("returns high and max with thinking config", () => {
  1473. const model = createMockModel({
  1474. id: "anthropic/claude-4",
  1475. providerID: "anthropic",
  1476. api: {
  1477. id: "claude-4",
  1478. url: "https://api.anthropic.com",
  1479. npm: "@ai-sdk/anthropic",
  1480. },
  1481. })
  1482. const result = ProviderTransform.variants(model)
  1483. expect(Object.keys(result)).toEqual(["high", "max"])
  1484. expect(result.high).toEqual({
  1485. thinking: {
  1486. type: "enabled",
  1487. budgetTokens: 16000,
  1488. },
  1489. })
  1490. expect(result.max).toEqual({
  1491. thinking: {
  1492. type: "enabled",
  1493. budgetTokens: 31999,
  1494. },
  1495. })
  1496. })
  1497. })
  1498. describe("@ai-sdk/amazon-bedrock", () => {
  1499. test("returns WIDELY_SUPPORTED_EFFORTS with reasoningConfig", () => {
  1500. const model = createMockModel({
  1501. id: "bedrock/llama-4",
  1502. providerID: "bedrock",
  1503. api: {
  1504. id: "llama-4-sc",
  1505. url: "https://bedrock.amazonaws.com",
  1506. npm: "@ai-sdk/amazon-bedrock",
  1507. },
  1508. })
  1509. const result = ProviderTransform.variants(model)
  1510. expect(Object.keys(result)).toEqual(["low", "medium", "high"])
  1511. expect(result.low).toEqual({
  1512. reasoningConfig: {
  1513. type: "enabled",
  1514. maxReasoningEffort: "low",
  1515. },
  1516. })
  1517. })
  1518. })
  1519. describe("@ai-sdk/google", () => {
  1520. test("gemini-2.5 returns high and max with thinkingConfig and thinkingBudget", () => {
  1521. const model = createMockModel({
  1522. id: "google/gemini-2.5-pro",
  1523. providerID: "google",
  1524. api: {
  1525. id: "gemini-2.5-pro",
  1526. url: "https://generativelanguage.googleapis.com",
  1527. npm: "@ai-sdk/google",
  1528. },
  1529. })
  1530. const result = ProviderTransform.variants(model)
  1531. expect(Object.keys(result)).toEqual(["high", "max"])
  1532. expect(result.high).toEqual({
  1533. thinkingConfig: {
  1534. includeThoughts: true,
  1535. thinkingBudget: 16000,
  1536. },
  1537. })
  1538. expect(result.max).toEqual({
  1539. thinkingConfig: {
  1540. includeThoughts: true,
  1541. thinkingBudget: 24576,
  1542. },
  1543. })
  1544. })
  1545. test("other gemini models return low and high with thinkingLevel", () => {
  1546. const model = createMockModel({
  1547. id: "google/gemini-2.0-pro",
  1548. providerID: "google",
  1549. api: {
  1550. id: "gemini-2.0-pro",
  1551. url: "https://generativelanguage.googleapis.com",
  1552. npm: "@ai-sdk/google",
  1553. },
  1554. })
  1555. const result = ProviderTransform.variants(model)
  1556. expect(Object.keys(result)).toEqual(["low", "high"])
  1557. expect(result.low).toEqual({
  1558. includeThoughts: true,
  1559. thinkingLevel: "low",
  1560. })
  1561. expect(result.high).toEqual({
  1562. includeThoughts: true,
  1563. thinkingLevel: "high",
  1564. })
  1565. })
  1566. })
  1567. describe("@ai-sdk/google-vertex", () => {
  1568. test("gemini-2.5 returns high and max with thinkingConfig and thinkingBudget", () => {
  1569. const model = createMockModel({
  1570. id: "google-vertex/gemini-2.5-pro",
  1571. providerID: "google-vertex",
  1572. api: {
  1573. id: "gemini-2.5-pro",
  1574. url: "https://vertexai.googleapis.com",
  1575. npm: "@ai-sdk/google-vertex",
  1576. },
  1577. })
  1578. const result = ProviderTransform.variants(model)
  1579. expect(Object.keys(result)).toEqual(["high", "max"])
  1580. })
  1581. test("other vertex models return low and high with thinkingLevel", () => {
  1582. const model = createMockModel({
  1583. id: "google-vertex/gemini-2.0-pro",
  1584. providerID: "google-vertex",
  1585. api: {
  1586. id: "gemini-2.0-pro",
  1587. url: "https://vertexai.googleapis.com",
  1588. npm: "@ai-sdk/google-vertex",
  1589. },
  1590. })
  1591. const result = ProviderTransform.variants(model)
  1592. expect(Object.keys(result)).toEqual(["low", "high"])
  1593. })
  1594. })
  1595. describe("@ai-sdk/cohere", () => {
  1596. test("returns empty object", () => {
  1597. const model = createMockModel({
  1598. id: "cohere/command-r",
  1599. providerID: "cohere",
  1600. api: {
  1601. id: "command-r",
  1602. url: "https://api.cohere.com",
  1603. npm: "@ai-sdk/cohere",
  1604. },
  1605. })
  1606. const result = ProviderTransform.variants(model)
  1607. expect(result).toEqual({})
  1608. })
  1609. })
  1610. describe("@ai-sdk/groq", () => {
  1611. test("returns none and WIDELY_SUPPORTED_EFFORTS with thinkingLevel", () => {
  1612. const model = createMockModel({
  1613. id: "groq/llama-4",
  1614. providerID: "groq",
  1615. api: {
  1616. id: "llama-4-sc",
  1617. url: "https://api.groq.com",
  1618. npm: "@ai-sdk/groq",
  1619. },
  1620. })
  1621. const result = ProviderTransform.variants(model)
  1622. expect(Object.keys(result)).toEqual(["none", "low", "medium", "high"])
  1623. expect(result.none).toEqual({
  1624. includeThoughts: true,
  1625. thinkingLevel: "none",
  1626. })
  1627. expect(result.low).toEqual({
  1628. includeThoughts: true,
  1629. thinkingLevel: "low",
  1630. })
  1631. })
  1632. })
  1633. describe("@ai-sdk/perplexity", () => {
  1634. test("returns empty object", () => {
  1635. const model = createMockModel({
  1636. id: "perplexity/sonar-plus",
  1637. providerID: "perplexity",
  1638. api: {
  1639. id: "sonar-plus",
  1640. url: "https://api.perplexity.ai",
  1641. npm: "@ai-sdk/perplexity",
  1642. },
  1643. })
  1644. const result = ProviderTransform.variants(model)
  1645. expect(result).toEqual({})
  1646. })
  1647. })
  1648. })