transform.test.ts 45 KB

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