exports.test.ts 3.6 KB

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