github-copilot-models.test.ts 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. import { afterEach, expect, mock, test } from "bun:test"
  2. import { CopilotModels } from "@/plugin/github-copilot/models"
  3. import { CopilotAuthPlugin } from "@/plugin/github-copilot/copilot"
  4. const originalFetch = globalThis.fetch
  5. afterEach(() => {
  6. globalThis.fetch = originalFetch
  7. })
  8. test("preserves temperature support from existing provider models", async () => {
  9. globalThis.fetch = mock(() =>
  10. Promise.resolve(
  11. new Response(
  12. JSON.stringify({
  13. data: [
  14. {
  15. model_picker_enabled: true,
  16. id: "gpt-4o",
  17. name: "GPT-4o",
  18. version: "gpt-4o-2024-05-13",
  19. capabilities: {
  20. family: "gpt",
  21. limits: {
  22. max_context_window_tokens: 64000,
  23. max_output_tokens: 16384,
  24. max_prompt_tokens: 64000,
  25. },
  26. supports: {
  27. streaming: true,
  28. tool_calls: true,
  29. },
  30. },
  31. },
  32. {
  33. model_picker_enabled: true,
  34. id: "brand-new",
  35. name: "Brand New",
  36. version: "brand-new-2026-04-01",
  37. capabilities: {
  38. family: "test",
  39. limits: {
  40. max_context_window_tokens: 32000,
  41. max_output_tokens: 8192,
  42. max_prompt_tokens: 32000,
  43. },
  44. supports: {
  45. streaming: true,
  46. tool_calls: false,
  47. },
  48. },
  49. },
  50. ],
  51. }),
  52. { status: 200 },
  53. ),
  54. ),
  55. ) as unknown as typeof fetch
  56. const models = await CopilotModels.get(
  57. "https://api.githubcopilot.com",
  58. {},
  59. {
  60. "gpt-4o": {
  61. id: "gpt-4o",
  62. providerID: "github-copilot",
  63. api: {
  64. id: "gpt-4o",
  65. url: "https://api.githubcopilot.com",
  66. npm: "@ai-sdk/openai-compatible",
  67. },
  68. name: "GPT-4o",
  69. family: "gpt",
  70. capabilities: {
  71. temperature: true,
  72. reasoning: false,
  73. attachment: true,
  74. toolcall: true,
  75. input: {
  76. text: true,
  77. audio: false,
  78. image: true,
  79. video: false,
  80. pdf: false,
  81. },
  82. output: {
  83. text: true,
  84. audio: false,
  85. image: false,
  86. video: false,
  87. pdf: false,
  88. },
  89. interleaved: false,
  90. },
  91. cost: {
  92. input: 0,
  93. output: 0,
  94. cache: {
  95. read: 0,
  96. write: 0,
  97. },
  98. },
  99. limit: {
  100. context: 64000,
  101. output: 16384,
  102. },
  103. options: {},
  104. headers: {},
  105. release_date: "2024-05-13",
  106. variants: {},
  107. status: "active",
  108. },
  109. },
  110. )
  111. expect(models["gpt-4o"].capabilities.temperature).toBe(true)
  112. expect(models["brand-new"].capabilities.temperature).toBe(true)
  113. })
  114. test("remaps fallback oauth model urls to the enterprise host", async () => {
  115. globalThis.fetch = mock(() => Promise.reject(new Error("timeout"))) as unknown as typeof fetch
  116. const hooks = await CopilotAuthPlugin({
  117. client: {} as never,
  118. project: {} as never,
  119. directory: "",
  120. worktree: "",
  121. experimental_workspace: {
  122. register() {},
  123. },
  124. serverUrl: new URL("https://example.com"),
  125. $: {} as never,
  126. })
  127. const models = await hooks.provider!.models!(
  128. {
  129. id: "github-copilot",
  130. models: {
  131. claude: {
  132. id: "claude",
  133. providerID: "github-copilot",
  134. api: {
  135. id: "claude-sonnet-4.5",
  136. url: "https://api.githubcopilot.com/v1",
  137. npm: "@ai-sdk/anthropic",
  138. },
  139. },
  140. },
  141. } as never,
  142. {
  143. auth: {
  144. type: "oauth",
  145. refresh: "token",
  146. access: "token",
  147. expires: Date.now() + 60_000,
  148. enterpriseUrl: "ghe.example.com",
  149. } as never,
  150. },
  151. )
  152. expect(models.claude.api.url).toBe("https://copilot-api.ghe.example.com")
  153. expect(models.claude.api.npm).toBe("@ai-sdk/github-copilot")
  154. })