Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/types/src/provider-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ const sambaNovaSchema = apiModelIdProviderModelSchema.extend({
sambaNovaApiKey: z.string().optional(),
})

export const zaiApiLineSchema = z.enum(["international_coding", "china_coding"])
export const zaiApiLineSchema = z.enum(["international_coding", "china_coding", "international_api", "china_api"])

export type ZaiApiLine = z.infer<typeof zaiApiLineSchema>

Expand Down
14 changes: 12 additions & 2 deletions packages/types/src/providers/zai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,23 @@ export const ZAI_DEFAULT_TEMPERATURE = 0.6

export const zaiApiLineConfigs = {
international_coding: {
name: "International",
name: "International Coding",
baseUrl: "https://api.z.ai/api/coding/paas/v4",
isChina: false,
},
china_coding: {
name: "China",
name: "China Coding",
baseUrl: "https://open.bigmodel.cn/api/coding/paas/v4",
isChina: true,
},
international_api: {
name: "International API",
baseUrl: "https://api.z.ai/api/paas/v4",
isChina: false,
},
china_api: {
name: "China API",
baseUrl: "https://open.bigmodel.cn/api/paas/v4",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The China API endpoint uses paas in the URL path, but the original issue #9879 specifies pass (without the second 'a'). The issue states the endpoint should be https://open.bigmodel.cn/api/pass/v4. This discrepancy could cause the endpoint to fail if pass is the correct path. Please verify the correct URL with Z.ai's API documentation.

Fix it with Roo Code or mention @roomote and request a fix.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The correct endpoint uses paas

isChina: true,
},
} satisfies Record<ZaiApiLine, { name: string; baseUrl: string; isChina: boolean }>
78 changes: 78 additions & 0 deletions src/api/providers/__tests__/zai.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,84 @@ describe("ZAiHandler", () => {
})
})

describe("International API", () => {
beforeEach(() => {
handler = new ZAiHandler({ zaiApiKey: "test-zai-api-key", zaiApiLine: "international_api" })
})

it("should use the correct international API base URL", () => {
new ZAiHandler({ zaiApiKey: "test-zai-api-key", zaiApiLine: "international_api" })
expect(OpenAI).toHaveBeenCalledWith(
expect.objectContaining({
baseURL: "https://api.z.ai/api/paas/v4",
}),
)
})

it("should use the provided API key for international API", () => {
const zaiApiKey = "test-zai-api-key"
new ZAiHandler({ zaiApiKey, zaiApiLine: "international_api" })
expect(OpenAI).toHaveBeenCalledWith(expect.objectContaining({ apiKey: zaiApiKey }))
})

it("should return international default model when no model is specified", () => {
const model = handler.getModel()
expect(model.id).toBe(internationalZAiDefaultModelId)
expect(model.info).toEqual(internationalZAiModels[internationalZAiDefaultModelId])
})

it("should return specified international model when valid model is provided", () => {
const testModelId: InternationalZAiModelId = "glm-4.5-air"
const handlerWithModel = new ZAiHandler({
apiModelId: testModelId,
zaiApiKey: "test-zai-api-key",
zaiApiLine: "international_api",
})
const model = handlerWithModel.getModel()
expect(model.id).toBe(testModelId)
expect(model.info).toEqual(internationalZAiModels[testModelId])
})
})

describe("China API", () => {
beforeEach(() => {
handler = new ZAiHandler({ zaiApiKey: "test-zai-api-key", zaiApiLine: "china_api" })
})

it("should use the correct China API base URL", () => {
new ZAiHandler({ zaiApiKey: "test-zai-api-key", zaiApiLine: "china_api" })
expect(OpenAI).toHaveBeenCalledWith(
expect.objectContaining({
baseURL: "https://open.bigmodel.cn/api/paas/v4",
}),
)
})

it("should use the provided API key for China API", () => {
const zaiApiKey = "test-zai-api-key"
new ZAiHandler({ zaiApiKey, zaiApiLine: "china_api" })
expect(OpenAI).toHaveBeenCalledWith(expect.objectContaining({ apiKey: zaiApiKey }))
})

it("should return China default model when no model is specified", () => {
const model = handler.getModel()
expect(model.id).toBe(mainlandZAiDefaultModelId)
expect(model.info).toEqual(mainlandZAiModels[mainlandZAiDefaultModelId])
})

it("should return specified China model when valid model is provided", () => {
const testModelId: MainlandZAiModelId = "glm-4.5-air"
const handlerWithModel = new ZAiHandler({
apiModelId: testModelId,
zaiApiKey: "test-zai-api-key",
zaiApiLine: "china_api",
})
const model = handlerWithModel.getModel()
expect(model.id).toBe(testModelId)
expect(model.info).toEqual(mainlandZAiModels[testModelId])
})
})

describe("Default behavior", () => {
it("should default to international when no zaiApiLine is specified", () => {
const handlerDefault = new ZAiHandler({ zaiApiKey: "test-zai-api-key" })
Expand Down
Loading