model-request.test.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { describe, expect, test } from "bun:test"
  2. import { ModelRequest } from "@opencode-ai/core/model-request"
  3. describe("ModelRequest", () => {
  4. test("partitions AI SDK model and models.dev mode options", () => {
  5. expect(
  6. ModelRequest.normalizeAiSdkOptions("@ai-sdk/openai", {
  7. maxOutputTokens: 4096,
  8. temperature: 0.2,
  9. reasoningEffort: "high",
  10. serviceTier: "priority",
  11. custom_extension: { enabled: true },
  12. }),
  13. ).toEqual({
  14. generation: { maxTokens: 4096, temperature: 0.2 },
  15. options: { reasoningEffort: "high", serviceTier: "priority" },
  16. body: { custom_extension: { enabled: true } },
  17. })
  18. })
  19. test("keeps unknown-provider options as compatibility fields", () => {
  20. expect(ModelRequest.normalizeAiSdkOptions(undefined, { temperature: 0.2, reasoningEffort: "high" })).toEqual({
  21. generation: { temperature: 0.2 },
  22. options: {},
  23. body: { reasoningEffort: "high" },
  24. })
  25. })
  26. test("does not consult inherited package-name properties", () => {
  27. expect(ModelRequest.normalizeAiSdkOptions("__proto__", { reasoningEffort: "high" })).toEqual({
  28. generation: {},
  29. options: {},
  30. body: { reasoningEffort: "high" },
  31. })
  32. })
  33. test("normalizes models.dev wire aliases owned by native protocols", () => {
  34. expect(ModelRequest.normalizeAiSdkOptions("@ai-sdk/openai", { service_tier: "priority" })).toEqual({
  35. generation: {},
  36. options: { serviceTier: "priority" },
  37. body: {},
  38. })
  39. })
  40. })