Skip to content
Open
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 @@ -376,7 +376,7 @@ const sambaNovaSchema = apiModelIdProviderModelSchema.extend({
sambaNovaApiKey: z.string().optional(),
})

export const zaiApiLineSchema = z.enum(["international_coding", "international", "china_coding", "china"])
export const zaiApiLineSchema = z.enum(["international", "china"])

export type ZaiApiLine = z.infer<typeof zaiApiLineSchema>

Expand Down
8 changes: 3 additions & 5 deletions packages/types/src/providers/zai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,10 @@ export const mainlandZAiModels = {
export const ZAI_DEFAULT_TEMPERATURE = 0

export const zaiApiLineConfigs = {
international_coding: {
name: "International Coding Plan",
international: {
name: "International",
Copy link

Choose a reason for hiding this comment

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

Is the naming convention intentional where the enum uses lowercase 'international' and 'china' but the display names are 'International' and 'China'? Just confirming this is the desired pattern - it's consistent throughout, which is good.

baseUrl: "https://api.z.ai/api/coding/paas/v4",
isChina: false,
},
international: { name: "International Standard", baseUrl: "https://api.z.ai/api/paas/v4", isChina: false },
china_coding: { name: "China Coding Plan", baseUrl: "https://open.bigmodel.cn/api/coding/paas/v4", isChina: true },
china: { name: "China Standard", baseUrl: "https://open.bigmodel.cn/api/paas/v4", isChina: true },
china: { name: "China", baseUrl: "https://open.bigmodel.cn/api/coding/paas/v4", isChina: true },
} satisfies Record<ZaiApiLine, { name: string; baseUrl: string; isChina: boolean }>
40 changes: 35 additions & 5 deletions scripts/find-missing-translations.js
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure if it's necessary for this to handle keys with dots, I would think that would be a bad practice for translation keys.

Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,44 @@ function findKeys(obj, parentKey = "") {

// Get value at a dotted path in an object
function getValueAtPath(obj, path) {
const parts = path.split(".")
// Handle the case where keys might contain dots (like "glm-4.5")
// We need to be smarter about splitting the path
let current = obj
let remainingPath = path

while (remainingPath && current && typeof current === "object") {
let found = false

// Try to find the longest matching key first
for (const key of Object.keys(current)) {
Copy link

Choose a reason for hiding this comment

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

The comment indicates 'Try to find the longest matching key first,' but the code iterates over Object.keys(current) without sorting by key length. This may cause ambiguous matches when multiple keys (e.g. 'aaa' and 'aaa.b') exist. Consider sorting the keys in descending order by length to ensure the longest matching key is selected.

Suggested change
for (const key of Object.keys(current)) {
for (const key of Object.keys(current).sort((a, b) => b.length - a.length)) {

if (remainingPath === key) {
// Exact match - we're done
return current[key]
} else if (remainingPath.startsWith(key + ".")) {
// Key matches the start of remaining path
current = current[key]
remainingPath = remainingPath.slice(key.length + 1)
found = true
break
}
}

for (const part of parts) {
if (current === undefined || current === null) {
return undefined
if (!found) {
// No matching key found, try the old method as fallback
const dotIndex = remainingPath.indexOf(".")
if (dotIndex === -1) {
// No more dots, this should be the final key
return current[remainingPath]
} else {
const nextKey = remainingPath.slice(0, dotIndex)
if (current[nextKey] !== undefined) {
current = current[nextKey]
remainingPath = remainingPath.slice(dotIndex + 1)
} else {
return undefined
}
}
}
current = current[part]
}

return current
Expand Down
4 changes: 2 additions & 2 deletions src/api/providers/__tests__/zai.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe("ZAiHandler", () => {
new ZAiHandler({ zaiApiKey: "test-zai-api-key", zaiApiLine: "international" })
expect(OpenAI).toHaveBeenCalledWith(
expect.objectContaining({
baseURL: "https://api.z.ai/api/paas/v4",
baseURL: "https://api.z.ai/api/coding/paas/v4",
}),
)
})
Expand Down Expand Up @@ -81,7 +81,7 @@ describe("ZAiHandler", () => {
it("should use the correct China Z AI base URL", () => {
new ZAiHandler({ zaiApiKey: "test-zai-api-key", zaiApiLine: "china" })
expect(OpenAI).toHaveBeenCalledWith(
expect.objectContaining({ baseURL: "https://open.bigmodel.cn/api/paas/v4" }),
expect.objectContaining({ baseURL: "https://open.bigmodel.cn/api/coding/paas/v4" }),
)
})

Expand Down
4 changes: 2 additions & 2 deletions src/api/providers/zai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ import { BaseOpenAiCompatibleProvider } from "./base-openai-compatible-provider"

export class ZAiHandler extends BaseOpenAiCompatibleProvider<InternationalZAiModelId | MainlandZAiModelId> {
constructor(options: ApiHandlerOptions) {
const isChina = zaiApiLineConfigs[options.zaiApiLine ?? "international_coding"].isChina
const isChina = zaiApiLineConfigs[options.zaiApiLine ?? "international"].isChina
Copy link

Choose a reason for hiding this comment

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

Since this removes existing enum values ('international_coding' and 'china_coding'), users with existing configurations using these values might encounter runtime issues. Could we consider adding a migration handler here?

Suggested change
const isChina = zaiApiLineConfigs[options.zaiApiLine ?? "international"].isChina
const isChina = zaiApiLineConfigs[options.zaiApiLine ?? "international"].isChina ||
// Handle legacy values for backward compatibility
(options.zaiApiLine === "china_coding" ||
(options.zaiApiLine as any) === "international_coding" && false);

This would gracefully handle legacy configurations.

const models = isChina ? mainlandZAiModels : internationalZAiModels
const defaultModelId = isChina ? mainlandZAiDefaultModelId : internationalZAiDefaultModelId

super({
...options,
providerName: "Z AI",
baseURL: zaiApiLineConfigs[options.zaiApiLine ?? "international_coding"].baseUrl,
baseURL: zaiApiLineConfigs[options.zaiApiLine ?? "international"].baseUrl,
apiKey: options.zaiApiKey ?? "not-provided",
defaultProviderModelId: defaultModelId,
providerModels: models,
Expand Down
12 changes: 10 additions & 2 deletions webview-ui/src/components/settings/ModelInfoView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,20 @@ export const ModelInfoView = ({

const infoItems = shouldShowTierPricingTable ? baseInfoItems : [...baseInfoItems, ...priceInfoItems]

// Localize provider-specific model descriptions when available
const zaiDescKey = `settings:providers.zaiModels.${selectedModelId}.description`
const zaiLocalizedDesc = apiProvider === "zai" ? t(zaiDescKey) : undefined
const descriptionToUse =
apiProvider === "zai" && zaiLocalizedDesc && zaiLocalizedDesc !== zaiDescKey
? zaiLocalizedDesc
: modelInfo?.description

return (
<>
{modelInfo?.description && (
{descriptionToUse && (
<ModelDescriptionMarkdown
key="description"
markdown={modelInfo.description}
markdown={descriptionToUse}
isExpanded={isDescriptionExpanded}
setIsExpanded={setIsDescriptionExpanded}
/>
Expand Down
7 changes: 4 additions & 3 deletions webview-ui/src/components/settings/providers/ZAi.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,15 @@ export const ZAi = ({ apiConfiguration, setApiConfigurationField }: ZAiProps) =>
<div>
<label className="block font-medium mb-1">{t("settings:providers.zaiEntrypoint")}</label>
<VSCodeDropdown
value={apiConfiguration.zaiApiLine || zaiApiLineSchema.enum.international_coding}
value={apiConfiguration.zaiApiLine || zaiApiLineSchema.enum.international}
Copy link

Choose a reason for hiding this comment

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

Good job updating the default value here. This ensures the UI properly reflects the new simplified options.

onChange={handleInputChange("zaiApiLine")}
className={cn("w-full")}>
{zaiApiLineSchema.options.map((zaiApiLine) => {
const config = zaiApiLineConfigs[zaiApiLine]
const label = t(`settings:providers.zaiEntrypointOptions.${zaiApiLine}`)
return (
<VSCodeOption key={zaiApiLine} value={zaiApiLine} className="p-2">
{config.name} ({config.baseUrl})
{label} ({config.baseUrl})
</VSCodeOption>
)
})}
Expand All @@ -64,7 +65,7 @@ export const ZAi = ({ apiConfiguration, setApiConfigurationField }: ZAiProps) =>
{!apiConfiguration?.zaiApiKey && (
<VSCodeButtonLink
href={
zaiApiLineConfigs[apiConfiguration.zaiApiLine ?? "international_coding"].isChina
zaiApiLineConfigs[apiConfiguration.zaiApiLine ?? "international"].isChina
? "https://open.bigmodel.cn/console/overview"
: "https://z.ai/manage-apikey/apikey-list"
}
Expand Down
12 changes: 12 additions & 0 deletions webview-ui/src/i18n/locales/ca/settings.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions webview-ui/src/i18n/locales/de/settings.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions webview-ui/src/i18n/locales/en/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,18 @@
"getZaiApiKey": "Get Z AI API Key",
"zaiEntrypoint": "Z AI Entrypoint",
"zaiEntrypointDescription": "Please select the appropriate API entrypoint based on your location. If you are in China, choose open.bigmodel.cn. Otherwise, choose api.z.ai.",
"zaiEntrypointOptions": {
"international": "International",
"china": "China"
},
"zaiModels": {
"glm-4.5": {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Currently we save these descriptions in the types package and they are all in English, unless we want to change all of them I think it makes sense to keep them like that

"description": "GLM-4.5 is Zhipu's latest featured model. Its comprehensive capabilities in reasoning, coding, and agent reach the state-of-the-art (SOTA) level among open-source models, with a context length of up to 128k."
},
"glm-4.5-air": {
"description": "GLM-4.5-Air is the lightweight version of GLM-4.5. It balances performance and cost-effectiveness, and can flexibly switch to hybrid thinking models."
}
},
"geminiApiKey": "Gemini API Key",
"getGroqApiKey": "Get Groq API Key",
"groqApiKey": "Groq API Key",
Expand Down
12 changes: 12 additions & 0 deletions webview-ui/src/i18n/locales/es/settings.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions webview-ui/src/i18n/locales/fr/settings.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions webview-ui/src/i18n/locales/hi/settings.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions webview-ui/src/i18n/locales/id/settings.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions webview-ui/src/i18n/locales/it/settings.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions webview-ui/src/i18n/locales/ja/settings.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions webview-ui/src/i18n/locales/ko/settings.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions webview-ui/src/i18n/locales/nl/settings.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions webview-ui/src/i18n/locales/pl/settings.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading