provider-google.test.ts 2.3 KB

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