mirror of
https://github.com/DayuanJiang/next-ai-draw-io.git
synced 2026-10-11 03:59:58 +08:00
feat(settings): link to each provider's key page and clean up base URLs
- A "Get API key" link next to the API Key field for the 19 providers that have a key page (from env.example and the providers' docs). 17 answered 200 to curl; OpenAI's is behind a Cloudflare challenge and DeepSeek's behind a regional block, both checked in Chrome - Base URLs drop spaces, trailing slashes and a pasted endpoint path (/chat/completions, /completions, /messages, /responses), which the SDK would otherwise append a second time and get a 404. getAIModel does this for the chat and the Test button; the field does it on blur and shows the URL requests go to
This commit is contained in:
@@ -65,3 +65,34 @@ test("the Test button checks all models at once and shows each result", async ({
|
||||
"model-ok",
|
||||
])
|
||||
})
|
||||
|
||||
test("the key link and the base URL cleanup", async ({ page }) => {
|
||||
await page.addInitScript((config) => {
|
||||
localStorage.setItem(
|
||||
"next-ai-draw-io-model-configs",
|
||||
JSON.stringify(config),
|
||||
)
|
||||
}, CONFIG)
|
||||
await page.goto("/", { waitUntil: "networkidle" })
|
||||
await getIframe(page).waitFor({ state: "visible", timeout: 30000 })
|
||||
await page.locator("button:has(svg.lucide-bot)").first().click()
|
||||
await page.getByText("Configure Models...").click()
|
||||
const dialog = page.locator('[role="dialog"]')
|
||||
await dialog.getByText("GLM (Zhipu)").first().click()
|
||||
|
||||
await expect(
|
||||
dialog.getByRole("link", { name: "Get API key" }),
|
||||
).toHaveAttribute(
|
||||
"href",
|
||||
"https://open.bigmodel.cn/usercenter/proj-mgmt/apikeys",
|
||||
)
|
||||
const baseUrl = dialog.locator("#base-url")
|
||||
await baseUrl.fill("https://proxy.example.com/v4/chat/completions/")
|
||||
await baseUrl.blur()
|
||||
await expect(baseUrl).toHaveValue("https://proxy.example.com/v4")
|
||||
await expect(
|
||||
dialog.getByText(
|
||||
"Requests go to https://proxy.example.com/v4/chat/completions",
|
||||
),
|
||||
).toBeVisible()
|
||||
})
|
||||
|
||||
@@ -332,6 +332,21 @@ describe("Atlas Cloud provider", () => {
|
||||
includeUsage: true,
|
||||
})
|
||||
})
|
||||
|
||||
it("drops an endpoint path pasted along with the base URL", () => {
|
||||
getAIModel({
|
||||
provider: "atlascloud",
|
||||
apiKey: "client-atlas-key",
|
||||
baseUrl: "https://proxy.example.com/v1/chat/completions/",
|
||||
modelId: "deepseek-ai/deepseek-v4-pro",
|
||||
})
|
||||
|
||||
expect(createCompatibleMock).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
baseURL: "https://proxy.example.com/v1",
|
||||
}),
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("Kimi provider uses createDeepSeek for reasoning_content support", () => {
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
import { describe, expect, it } from "vitest"
|
||||
import { chatRequestUrl, normalizeBaseUrl } from "@/lib/types/model-config"
|
||||
|
||||
describe("normalizeBaseUrl", () => {
|
||||
it("drops spaces, trailing slashes and a pasted endpoint path", () => {
|
||||
expect(normalizeBaseUrl(" https://api.x.com/v1/ ")).toBe(
|
||||
"https://api.x.com/v1",
|
||||
)
|
||||
expect(normalizeBaseUrl("https://api.x.com/v1/chat/completions")).toBe(
|
||||
"https://api.x.com/v1",
|
||||
)
|
||||
expect(
|
||||
normalizeBaseUrl("https://api.x.com/anthropic/v1/messages/"),
|
||||
).toBe("https://api.x.com/anthropic/v1")
|
||||
})
|
||||
|
||||
it("keeps provider paths such as /api/paas/v4 and /api/v3", () => {
|
||||
expect(normalizeBaseUrl("https://open.bigmodel.cn/api/paas/v4")).toBe(
|
||||
"https://open.bigmodel.cn/api/paas/v4",
|
||||
)
|
||||
expect(
|
||||
normalizeBaseUrl("https://ark.cn-beijing.volces.com/api/v3"),
|
||||
).toBe("https://ark.cn-beijing.volces.com/api/v3")
|
||||
})
|
||||
})
|
||||
|
||||
describe("chatRequestUrl", () => {
|
||||
it("shows the endpoint the SDK will call", () => {
|
||||
expect(chatRequestUrl("glm", "https://api.x.com/v1/")).toBe(
|
||||
"https://api.x.com/v1/chat/completions",
|
||||
)
|
||||
expect(
|
||||
chatRequestUrl("anthropic", "https://proxy.example.com/v1"),
|
||||
).toBe("https://proxy.example.com/v1/messages")
|
||||
})
|
||||
|
||||
it("stays out of the way for SDKs that build their own paths", () => {
|
||||
expect(chatRequestUrl("google", "https://x.example.com")).toBeNull()
|
||||
expect(chatRequestUrl("minimax", "https://x.example.com")).toBeNull()
|
||||
expect(chatRequestUrl("glm", " ")).toBeNull()
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user