provider-perplexity.test.ts 3.4 KB

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