provider-google.test.ts 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. apiID: ModelV2.ID.make("gemini-api"),
  51. endpoint: {
  52. type: "aisdk",
  53. package: "@ai-sdk/google",
  54. },
  55. options: {
  56. headers: {},
  57. body: {},
  58. aisdk: {
  59. provider: { apiKey: "test" },
  60. request: {},
  61. },
  62. },
  63. }),
  64. )
  65. expect(language.modelId).toBe("gemini-api")
  66. expect(language.provider).toBe("custom-google")
  67. }),
  68. )
  69. })