exports.test.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import { describe, expect, test } from "bun:test"
  2. import { AIError, ImageInput, LanguageModel, LLM, LLMClient, Provider } from "@opencode-ai/ai"
  3. import { Route, Protocol, WebSocketTransport } from "@opencode-ai/ai/route"
  4. import { Provider as ProviderSubpath } from "@opencode-ai/ai/provider"
  5. import {
  6. CloudflareAIGateway,
  7. CloudflareWorkersAI,
  8. OpenAI,
  9. OpenAICompatible,
  10. OpenRouter,
  11. XAI,
  12. } from "@opencode-ai/ai/providers"
  13. import {
  14. OpenAIChat,
  15. OpenAICompatibleChat,
  16. OpenAICompatibleResponses,
  17. OpenAIResponses,
  18. OpenResponses,
  19. OpenResponsesChannel,
  20. } from "@opencode-ai/ai/protocols"
  21. import * as AnthropicMessages from "@opencode-ai/ai/protocols/anthropic-messages"
  22. import { TestLLM } from "@opencode-ai/ai/testing"
  23. describe("public exports", () => {
  24. test("root exposes app-facing runtime APIs", () => {
  25. expect(LLM.request).toBeFunction()
  26. expect(LLMClient.Service).toBeFunction()
  27. expect(LLMClient.layer).toBeDefined()
  28. expect(AIError).toBeFunction()
  29. expect(LanguageModel.make).toBeFunction()
  30. expect(ImageInput.bytes).toBeFunction()
  31. expect(Provider.make).toBeFunction()
  32. expect(ProviderSubpath.make).toBe(Provider.make)
  33. expect(TestLLM.layer).toBeFunction()
  34. })
  35. test("route barrel exposes route-authoring APIs", () => {
  36. expect(Route.make).toBeFunction()
  37. expect(Protocol.make).toBeFunction()
  38. expect(WebSocketTransport.makeDirect).toBeFunction()
  39. })
  40. test("provider barrels expose user-facing facades", async () => {
  41. const { OpenAICompatibleResponses } = await import("@opencode-ai/ai/providers")
  42. expect(OpenAI.model).toBeFunction()
  43. expect(OpenAI.provider.responses).toBe(OpenAI.responses)
  44. expect(OpenAI.configure({ apiKey: "fixture" }).responses).toBeFunction()
  45. expect(OpenAICompatible.deepseek.model).toBeFunction()
  46. expect(
  47. OpenAICompatibleResponses.configure({ baseURL: "https://responses.test/v1" }).model("fixture").route.id,
  48. ).toBe("openai-compatible-responses")
  49. expect(CloudflareAIGateway.configure).toBeFunction()
  50. expect(CloudflareAIGateway.configure({ accountId: "fixture", gatewayApiKey: "fixture" }).model).toBeFunction()
  51. expect(CloudflareWorkersAI.configure).toBeFunction()
  52. expect(CloudflareWorkersAI.configure({ accountId: "fixture", apiKey: "fixture" }).model).toBeFunction()
  53. expect(OpenRouter.model).toBeFunction()
  54. expect(XAI.model).toBeFunction()
  55. expect(XAI.provider.responses).toBe(XAI.responses)
  56. expect(XAI.provider.chat).toBe(XAI.chat)
  57. expect(XAI.configure({ apiKey: "fixture" }).responses("grok-4.3").route.id).toBe("openai-responses")
  58. expect(XAI.configure({ apiKey: "fixture" }).chat("grok-4.3").route.id).toBe("openai-compatible-chat")
  59. })
  60. test("protocol barrels expose supported low-level routes", () => {
  61. expect(OpenAIChat.route.id).toBe("openai-chat")
  62. expect(OpenAICompatibleChat.route.id).toBe("openai-compatible-chat")
  63. expect(OpenResponses.protocol.id).toBe("open-responses")
  64. expect(OpenResponsesChannel.transport).toBeFunction()
  65. expect(OpenAICompatibleResponses.route.id).toBe("openai-compatible-responses")
  66. expect(OpenAICompatibleResponses.route.protocol).toBe("open-responses")
  67. expect(OpenAIResponses.route.id).toBe("openai-responses")
  68. expect(AnthropicMessages.route.id).toBe("anthropic-messages")
  69. })
  70. })