provider-google.test.ts 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import { describe, expect } from "bun:test"
  2. import { Effect, Layer } from "effect"
  3. import { AISDK } from "@opencode-ai/core/aisdk"
  4. import { ModelV2 } from "@opencode-ai/core/model"
  5. import { PluginV2 } from "@opencode-ai/core/plugin"
  6. import { GooglePlugin } from "@opencode-ai/core/plugin/provider/google"
  7. import { testEffect } from "../lib/effect"
  8. import { it, model } from "./provider-helper"
  9. const itWithAISDK = testEffect(AISDK.layer.pipe(Layer.provideMerge(PluginV2.defaultLayer)))
  10. describe("GooglePlugin", () => {
  11. it.effect("creates a Google Generative AI SDK for @ai-sdk/google using the provider ID as SDK name", () =>
  12. Effect.gen(function* () {
  13. const plugin = yield* PluginV2.Service
  14. yield* plugin.add(GooglePlugin)
  15. const result = yield* plugin.trigger(
  16. "aisdk.sdk",
  17. {
  18. model: model("custom-google", "gemini"),
  19. package: "@ai-sdk/google",
  20. options: { name: "custom-google", apiKey: "test" },
  21. },
  22. {},
  23. )
  24. expect(result.sdk).toBeDefined()
  25. expect(result.sdk?.languageModel("gemini").provider).toBe("custom-google")
  26. }),
  27. )
  28. it.effect("ignores non-Google SDK packages", () =>
  29. Effect.gen(function* () {
  30. const plugin = yield* PluginV2.Service
  31. yield* plugin.add(GooglePlugin)
  32. const result = yield* plugin.trigger(
  33. "aisdk.sdk",
  34. { model: model("google", "gemini"), package: "@ai-sdk/google-vertex", options: { name: "google" } },
  35. {},
  36. )
  37. expect(result.sdk).toBeUndefined()
  38. }),
  39. )
  40. itWithAISDK.effect("uses default languageModel loading with provider ID parity", () =>
  41. Effect.gen(function* () {
  42. const plugin = yield* PluginV2.Service
  43. const aisdk = yield* AISDK.Service
  44. yield* plugin.add(GooglePlugin)
  45. const language = yield* aisdk.language(
  46. model("custom-google", "alias", {
  47. apiID: ModelV2.ID.make("gemini-api"),
  48. endpoint: {
  49. type: "aisdk",
  50. package: "@ai-sdk/google",
  51. },
  52. options: {
  53. headers: {},
  54. body: {},
  55. aisdk: {
  56. provider: { apiKey: "test" },
  57. request: {},
  58. },
  59. },
  60. }),
  61. )
  62. expect(language.modelId).toBe("gemini-api")
  63. expect(language.provider).toBe("custom-google")
  64. }),
  65. )
  66. })