aisdk-native.test.ts 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import { describe, expect, test } from "bun:test"
  2. import { AISDKNative } from "@opencode-ai/core/aisdk-native"
  3. describe("AISDKNative", () => {
  4. test("maps every Google thinking setting", () => {
  5. expect(
  6. AISDKNative.map("@ai-sdk/google", {
  7. cachedContent: "cachedContents/example",
  8. safetySettings: [{ category: "HARM_CATEGORY_HARASSMENT", threshold: "BLOCK_NONE" }],
  9. serviceTier: "flex",
  10. thinkingConfig: {
  11. thinkingBudget: 0,
  12. includeThoughts: false,
  13. thinkingLevel: "high",
  14. unknown: true,
  15. },
  16. }),
  17. ).toEqual({
  18. package: "@opencode-ai/ai/providers/google",
  19. settings: {
  20. providerOptions: {
  21. gemini: {
  22. cachedContent: "cachedContents/example",
  23. safetySettings: [{ category: "HARM_CATEGORY_HARASSMENT", threshold: "BLOCK_NONE" }],
  24. serviceTier: "flex",
  25. thinkingConfig: {
  26. thinkingBudget: 0,
  27. includeThoughts: false,
  28. thinkingLevel: "high",
  29. },
  30. },
  31. },
  32. },
  33. })
  34. })
  35. test("maps Google thinking settings independently", () => {
  36. for (const thinkingConfig of [{ thinkingBudget: -1 }, { includeThoughts: true }, { thinkingLevel: "medium" }]) {
  37. expect(AISDKNative.map("@ai-sdk/google", { thinkingConfig })).toMatchObject({
  38. settings: { providerOptions: { gemini: { thinkingConfig } } },
  39. })
  40. }
  41. })
  42. test("maps Google request options without thinking settings", () => {
  43. expect(
  44. AISDKNative.map("@ai-sdk/google", {
  45. cachedContent: "cachedContents/example",
  46. safetySettings: [{ category: "HARM_CATEGORY_HARASSMENT", threshold: "BLOCK_NONE" }],
  47. serviceTier: "future-tier",
  48. }),
  49. ).toMatchObject({
  50. settings: {
  51. providerOptions: {
  52. gemini: {
  53. cachedContent: "cachedContents/example",
  54. safetySettings: [{ category: "HARM_CATEGORY_HARASSMENT", threshold: "BLOCK_NONE" }],
  55. serviceTier: "future-tier",
  56. },
  57. },
  58. },
  59. })
  60. })
  61. test("maps supported xAI settings", () => {
  62. expect(
  63. AISDKNative.map("@ai-sdk/xai", {
  64. apiKey: "secret",
  65. baseURL: "https://xai.example/v1",
  66. reasoningEffort: "custom",
  67. store: true,
  68. promptCacheKey: "cache-key",
  69. }),
  70. ).toEqual({
  71. package: "@opencode-ai/ai/providers/xai",
  72. settings: {
  73. apiKey: "secret",
  74. baseURL: "https://xai.example/v1",
  75. providerOptions: {
  76. xai: {
  77. reasoningEffort: "custom",
  78. store: true,
  79. promptCacheKey: "cache-key",
  80. },
  81. },
  82. },
  83. })
  84. })
  85. test("omits invalid and unsupported xAI settings", () => {
  86. expect(
  87. AISDKNative.map("@ai-sdk/xai", {
  88. reasoningEffort: 10,
  89. store: "yes",
  90. include: ["unknown"],
  91. logprobs: true,
  92. topLogprobs: 8,
  93. previousResponseId: "response-id",
  94. searchParameters: { mode: "auto" },
  95. }),
  96. ).toEqual({
  97. package: "@opencode-ai/ai/providers/xai",
  98. settings: {},
  99. })
  100. })
  101. })