provider-google.test.ts 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import { describe, expect } from "bun:test"
  2. import { Effect } from "effect"
  3. import { ModelV2 } from "@opencode-ai/core/model"
  4. import { PluginV2 } from "@opencode-ai/core/plugin"
  5. import { PluginHost } from "@opencode-ai/core/plugin/host"
  6. import { GooglePlugin } from "@opencode-ai/core/plugin/provider/google"
  7. import { ProviderV2 } from "@opencode-ai/core/provider"
  8. import { testEffect } from "../lib/effect"
  9. import { PluginTestLayer } from "./fixture"
  10. const it = testEffect(PluginTestLayer)
  11. const addPlugin = Effect.fn(function* () {
  12. const plugin = yield* PluginV2.Service
  13. const host = yield* PluginHost.make()
  14. yield* plugin.add({ id: GooglePlugin.id, effect: GooglePlugin.effect(host) })
  15. })
  16. describe("GooglePlugin", () => {
  17. it.effect("creates a Google Generative AI SDK for @ai-sdk/google using the provider ID as SDK name", () =>
  18. Effect.gen(function* () {
  19. const plugin = yield* PluginV2.Service
  20. yield* addPlugin()
  21. const result = yield* plugin.trigger(
  22. "aisdk.sdk",
  23. {
  24. model: new ModelV2.Info({
  25. ...ModelV2.Info.empty(ProviderV2.ID.make("custom-google"), ModelV2.ID.make("gemini")),
  26. api: { id: ModelV2.ID.make("gemini"), type: "aisdk", package: "@ai-sdk/google" },
  27. }),
  28. package: "@ai-sdk/google",
  29. options: { name: "custom-google", apiKey: "test" },
  30. },
  31. {},
  32. )
  33. expect(result.sdk).toBeDefined()
  34. expect(result.sdk?.languageModel("gemini").provider).toBe("custom-google")
  35. }),
  36. )
  37. it.effect("ignores non-Google SDK packages", () =>
  38. Effect.gen(function* () {
  39. const plugin = yield* PluginV2.Service
  40. yield* addPlugin()
  41. const result = yield* plugin.trigger(
  42. "aisdk.sdk",
  43. {
  44. model: new ModelV2.Info({
  45. ...ModelV2.Info.empty(ProviderV2.ID.make("google"), ModelV2.ID.make("gemini")),
  46. api: { id: ModelV2.ID.make("gemini"), type: "aisdk", package: "@ai-sdk/google" },
  47. }),
  48. package: "@ai-sdk/google-vertex",
  49. options: { name: "google" },
  50. },
  51. {},
  52. )
  53. expect(result.sdk).toBeUndefined()
  54. }),
  55. )
  56. it.effect("uses default languageModel loading with provider ID parity", () =>
  57. Effect.gen(function* () {
  58. const plugin = yield* PluginV2.Service
  59. yield* addPlugin()
  60. const sdkEvent = yield* plugin.trigger(
  61. "aisdk.sdk",
  62. {
  63. model: new ModelV2.Info({
  64. ...ModelV2.Info.empty(ProviderV2.ID.make("custom-google"), ModelV2.ID.make("alias")),
  65. api: { id: ModelV2.ID.make("gemini-api"), type: "aisdk", package: "@ai-sdk/google" },
  66. }),
  67. package: "@ai-sdk/google",
  68. options: { name: "custom-google", apiKey: "test" },
  69. },
  70. {},
  71. )
  72. const result = yield* plugin.trigger(
  73. "aisdk.language",
  74. {
  75. model: sdkEvent.model,
  76. sdk: sdkEvent.sdk,
  77. options: sdkEvent.options,
  78. },
  79. {},
  80. )
  81. const language = result.language ?? result.sdk.languageModel(result.model.api.id)
  82. expect(language.modelId).toBe("gemini-api")
  83. expect(language.provider).toBe("custom-google")
  84. }),
  85. )
  86. })