provider-anthropic.test.ts 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import { describe, expect } from "bun:test"
  2. import { Effect } from "effect"
  3. import { PluginV2 } from "@opencode-ai/core/plugin"
  4. import { AnthropicPlugin } from "@opencode-ai/core/plugin/provider/anthropic"
  5. import { it, model, provider } from "./provider-helper"
  6. describe("AnthropicPlugin", () => {
  7. it.effect("applies legacy beta headers", () =>
  8. Effect.gen(function* () {
  9. const plugin = yield* PluginV2.Service
  10. yield* plugin.add(AnthropicPlugin)
  11. const result = yield* plugin.trigger(
  12. "provider.update",
  13. {},
  14. {
  15. provider: provider("anthropic", {
  16. options: { headers: { Existing: "1" }, body: {}, aisdk: { provider: {}, request: {} } },
  17. }),
  18. cancel: false,
  19. },
  20. )
  21. expect(result.provider.options.headers["anthropic-beta"]).toBe(
  22. "interleaved-thinking-2025-05-14,fine-grained-tool-streaming-2025-05-14",
  23. )
  24. expect(result.provider.options.headers.Existing).toBe("1")
  25. }),
  26. )
  27. it.effect("ignores non-Anthropic providers", () =>
  28. Effect.gen(function* () {
  29. const plugin = yield* PluginV2.Service
  30. yield* plugin.add(AnthropicPlugin)
  31. const result = yield* plugin.trigger("provider.update", {}, { provider: provider("openai"), cancel: false })
  32. expect(result.provider.options.headers["anthropic-beta"]).toBeUndefined()
  33. }),
  34. )
  35. it.effect("creates Anthropic SDKs with the model provider ID as the SDK name", () =>
  36. Effect.gen(function* () {
  37. const plugin = yield* PluginV2.Service
  38. const providers: string[] = []
  39. yield* plugin.add(AnthropicPlugin)
  40. yield* plugin.add({
  41. id: PluginV2.ID.make("anthropic-sdk-inspector"),
  42. effect: Effect.succeed({
  43. "aisdk.sdk": (evt) =>
  44. Effect.sync(() => {
  45. providers.push(evt.sdk.languageModel("claude-sonnet-4-5").provider)
  46. }),
  47. }),
  48. })
  49. yield* plugin.trigger(
  50. "aisdk.sdk",
  51. {
  52. model: model("custom-anthropic", "claude-sonnet-4-5"),
  53. package: "@ai-sdk/anthropic",
  54. options: { name: "custom-anthropic", apiKey: "test" },
  55. },
  56. {},
  57. )
  58. expect(providers).toEqual(["custom-anthropic"])
  59. }),
  60. )
  61. it.effect("uses the Anthropic provider ID as the SDK name for the bundled Anthropic provider", () =>
  62. Effect.gen(function* () {
  63. const plugin = yield* PluginV2.Service
  64. const providers: string[] = []
  65. yield* plugin.add(AnthropicPlugin)
  66. yield* plugin.add({
  67. id: PluginV2.ID.make("anthropic-sdk-inspector"),
  68. effect: Effect.succeed({
  69. "aisdk.sdk": (evt) =>
  70. Effect.sync(() => {
  71. providers.push(evt.sdk.languageModel("claude-sonnet-4-5").provider)
  72. }),
  73. }),
  74. })
  75. yield* plugin.trigger(
  76. "aisdk.sdk",
  77. {
  78. model: model("anthropic", "claude-sonnet-4-5"),
  79. package: "@ai-sdk/anthropic",
  80. options: { name: "anthropic", apiKey: "test" },
  81. },
  82. {},
  83. )
  84. expect(providers).toEqual(["anthropic"])
  85. }),
  86. )
  87. })