exports.test.ts 3.2 KB

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