1
0

provider-mistral.test.ts 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 { MistralPlugin } from "@opencode-ai/core/plugin/provider/mistral"
  6. import { fakeSelectorSdk, it, model } from "./provider-helper"
  7. describe("MistralPlugin", () => {
  8. it.effect("creates a Mistral SDK for @ai-sdk/mistral", () =>
  9. Effect.gen(function* () {
  10. const plugin = yield* PluginV2.Service
  11. yield* plugin.add(MistralPlugin)
  12. const result = yield* plugin.trigger(
  13. "aisdk.sdk",
  14. { model: model("mistral", "mistral-large"), package: "@ai-sdk/mistral", options: { name: "mistral" } },
  15. {},
  16. )
  17. expect(result.sdk).toBeDefined()
  18. }),
  19. )
  20. it.effect("ignores non-Mistral SDK packages", () =>
  21. Effect.gen(function* () {
  22. const plugin = yield* PluginV2.Service
  23. yield* plugin.add(MistralPlugin)
  24. const result = yield* plugin.trigger(
  25. "aisdk.sdk",
  26. {
  27. model: model("mistral", "mistral-large"),
  28. package: "@ai-sdk/openai-compatible",
  29. options: { name: "mistral" },
  30. },
  31. {},
  32. )
  33. expect(result.sdk).toBeUndefined()
  34. }),
  35. )
  36. it.effect("matches the old bundled Mistral SDK provider name for the bundled provider ID", () =>
  37. Effect.gen(function* () {
  38. const plugin = yield* PluginV2.Service
  39. const providers: string[] = []
  40. yield* plugin.add(MistralPlugin)
  41. yield* plugin.add({
  42. id: PluginV2.ID.make("mistral-sdk-inspector"),
  43. effect: Effect.succeed({
  44. "aisdk.sdk": (evt) =>
  45. Effect.sync(() => {
  46. providers.push(evt.sdk.languageModel("mistral-large").provider)
  47. }),
  48. }),
  49. })
  50. const result = yield* plugin.trigger(
  51. "aisdk.sdk",
  52. { model: model("mistral", "mistral-large"), package: "@ai-sdk/mistral", options: { name: "mistral" } },
  53. {},
  54. )
  55. expect(result.sdk).toBeDefined()
  56. expect(providers).toEqual(["mistral.chat"])
  57. }),
  58. )
  59. it.effect("matches the old bundled Mistral SDK provider name for custom provider IDs", () =>
  60. Effect.gen(function* () {
  61. const plugin = yield* PluginV2.Service
  62. const providers: string[] = []
  63. yield* plugin.add(MistralPlugin)
  64. yield* plugin.add({
  65. id: PluginV2.ID.make("mistral-sdk-inspector"),
  66. effect: Effect.succeed({
  67. "aisdk.sdk": (evt) =>
  68. Effect.sync(() => {
  69. providers.push(evt.sdk.languageModel("mistral-large").provider)
  70. }),
  71. }),
  72. })
  73. yield* plugin.trigger(
  74. "aisdk.sdk",
  75. {
  76. model: model("custom-mistral", "mistral-large"),
  77. package: "@ai-sdk/mistral",
  78. options: { name: "custom-mistral" },
  79. },
  80. {},
  81. )
  82. expect(providers).toEqual(["mistral.chat"])
  83. }),
  84. )
  85. it.effect("leaves Mistral language selection on the default sdk.languageModel(api.id) path", () =>
  86. Effect.gen(function* () {
  87. const plugin = yield* PluginV2.Service
  88. const calls: string[] = []
  89. const sdk = fakeSelectorSdk(calls)
  90. yield* plugin.add(MistralPlugin)
  91. const result = yield* plugin.trigger(
  92. "aisdk.language",
  93. { model: model("mistral", "alias", { api: { id: ModelV2.ID.make("mistral-large") } }), sdk, options: {} },
  94. {},
  95. )
  96. const language = result.language ?? sdk.languageModel(result.model.api.id)
  97. expect(calls).toEqual(["languageModel:mistral-large"])
  98. expect(language).toBeDefined()
  99. }),
  100. )
  101. })