fix(codebuddy): dodge Tencent filter for CN, add usage tracking & normalize messages for INT

Neutralize CLI-agent system prompts that trigger CodeBuddy CN's content filter, add usage/quota tracking for codebuddy-intl sharing CN's logic, and normalize codebuddy-intl request messages to the shape it expects.
This commit is contained in:
Rafi Mahardika
2026-08-05 10:51:29 +07:00
committed by decolua
parent 41606a37a3
commit 9138c99391
5 changed files with 63 additions and 7 deletions

View File

@@ -43,17 +43,17 @@ function refillCadence(acc) {
return "Monthly";
}
export async function getCodeBuddyCnUsage(accessToken, apiKey, providerSpecificData, proxyOptions = null) {
async function getCodeBuddyUsage(providerId, accessToken, apiKey, providerSpecificData, proxyOptions = null) {
const token = accessToken || apiKey;
if (!token) {
return { message: "CodeBuddy CN credential not available." };
return { message: `CodeBuddy (${providerId}) credential not available.` };
}
try {
const response = await proxyAwareFetch(U(PROVIDER_ID).url, {
const response = await proxyAwareFetch(U(providerId).url, {
method: "POST",
headers: {
...(PROVIDERS[PROVIDER_ID]?.headers || {}),
...(PROVIDERS[providerId]?.headers || {}),
Authorization: `Bearer ${token}`,
"Content-Type": "application/json",
Accept: "application/json",
@@ -129,10 +129,18 @@ export async function getCodeBuddyCnUsage(accessToken, apiKey, providerSpecificD
});
const basePkg = refills[0] || accounts[0] || {};
const plan = basePkg.PackageName || basePkg.SubProductName || "CodeBuddy CN";
const plan = basePkg.PackageName || basePkg.SubProductName || "CodeBuddy";
return { plan, quotas };
} catch (error) {
return { message: `CodeBuddy CN error: ${error.message}` };
return { message: `CodeBuddy (${providerId}) error: ${error.message}` };
}
}
export async function getCodeBuddyCnUsage(accessToken, apiKey, providerSpecificData, proxyOptions = null) {
return getCodeBuddyUsage(PROVIDER_ID, accessToken, apiKey, providerSpecificData, proxyOptions);
}
export async function getCodeBuddyIntlUsage(accessToken, apiKey, providerSpecificData, proxyOptions = null) {
return getCodeBuddyUsage("codebuddy-intl", accessToken, apiKey, providerSpecificData, proxyOptions);
}