mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 05:10:44 +00:00
fix(minimax): respect usage base url
This commit is contained in:
@@ -25,6 +25,7 @@ Docs: https://docs.openclaw.ai
|
||||
|
||||
- Telegram: inherit the process DNS result order for Bot API transport and downgrade recovered sticky IPv4 fallback promotions to debug logs, while keeping pinned-IP escalation warnings visible. Fixes #75904. Thanks @highfly-hi and @neeravmakwana.
|
||||
- Web search/MiniMax: allow `MINIMAX_OAUTH_TOKEN` to satisfy MiniMax Search credentials, so OAuth-authorized MiniMax Token Plan setups do not need a separate web-search key. Fixes #65768. Thanks @kikibrian and @zhouhe-xydt.
|
||||
- Providers/MiniMax: derive Coding Plan usage polling from the configured MiniMax base URL, so global setups no longer query the CN usage host. Fixes #65054. Thanks @sixone74 and @Yanhu007.
|
||||
- Subagents: honor `sessions_spawn` with `expectsCompletionMessage: false` by skipping parent completion handoff delivery while still running child cleanup. Fixes #75848. Thanks @alfredjbclaw.
|
||||
- Gateway/logging: keep deferred channel startup logs on the subsystem logger, so Slack, Discord, Telegram, and voice-call startup messages keep timestamped prefixes. Thanks @vincentkoc.
|
||||
- Replies/typing: keep typing alive for queued follow-up messages that are genuinely waiting behind an active run, instead of making chat surfaces look idle while work is queued. Fixes #65685. Thanks @papag00se.
|
||||
|
||||
@@ -39,6 +39,9 @@ title: "Usage tracking"
|
||||
`minimax`, `minimax-cn`, and `minimax-portal` as the same MiniMax quota
|
||||
surface, prefers stored MiniMax OAuth when present, and otherwise falls back
|
||||
to `MINIMAX_CODE_PLAN_KEY`, `MINIMAX_CODING_API_KEY`, or `MINIMAX_API_KEY`.
|
||||
Usage polling derives the Coding Plan host from `models.providers.minimax-portal.baseUrl`
|
||||
or `models.providers.minimax.baseUrl` when configured, and otherwise uses the
|
||||
MiniMax CN host.
|
||||
MiniMax's raw `usage_percent` / `usagePercent` fields mean **remaining**
|
||||
quota, so OpenClaw inverts them before display; count-based fields win when
|
||||
present.
|
||||
|
||||
@@ -423,7 +423,8 @@ See [MiniMax Search](/tools/minimax-search) for full web search configuration an
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="Coding Plan usage details">
|
||||
- Coding Plan usage API: `https://api.minimaxi.com/v1/api/openplatform/coding_plan/remains` (requires a coding plan key).
|
||||
- Coding Plan usage API: `https://api.minimaxi.com/v1/token_plan/remains` or `https://api.minimax.io/v1/token_plan/remains` (requires a coding plan key).
|
||||
- Usage polling derives the host from `models.providers.minimax-portal.baseUrl` or `models.providers.minimax.baseUrl` when configured, so global setups using `https://api.minimax.io/anthropic` poll `api.minimax.io`. Missing or malformed base URLs keep the CN fallback for compatibility.
|
||||
- OpenClaw normalizes MiniMax coding-plan usage to the same `% left` display used by other providers. MiniMax's raw `usage_percent` / `usagePercent` fields are remaining quota, not consumed quota, so OpenClaw inverts them. Count-based fields win when present.
|
||||
- When the API returns `model_remains`, OpenClaw prefers the chat-model entry, derives the window label from `start_time` / `end_time` when needed, and includes the selected model name in the plan label so coding-plan windows are easier to distinguish.
|
||||
- Usage snapshots treat `minimax`, `minimax-cn`, and `minimax-portal` as the same MiniMax quota surface, and prefer stored MiniMax OAuth before falling back to Coding Plan key env vars.
|
||||
|
||||
@@ -276,6 +276,49 @@ describe("minimax provider hooks", () => {
|
||||
expect(resolveApiKeyFromConfigAndStore).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("uses the configured MiniMax base URL for usage snapshots", async () => {
|
||||
const { providers } = await registerProviderPlugin({
|
||||
plugin: minimaxProviderPlugin,
|
||||
id: "minimax",
|
||||
name: "MiniMax Provider",
|
||||
});
|
||||
const apiProvider = requireRegisteredProvider(providers, "minimax");
|
||||
const fetchFn = vi.fn(async (input: string | URL | Request) => {
|
||||
const url =
|
||||
typeof input === "string" ? input : input instanceof URL ? input.toString() : input.url;
|
||||
expect(url).toBe("https://api.minimax.io/v1/token_plan/remains");
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
data: {
|
||||
current_interval_total_count: 100,
|
||||
current_interval_usage_count: 98,
|
||||
},
|
||||
}),
|
||||
{ status: 200, headers: { "Content-Type": "application/json" } },
|
||||
);
|
||||
});
|
||||
|
||||
const result = await apiProvider.fetchUsageSnapshot?.({
|
||||
provider: "minimax",
|
||||
config: {
|
||||
models: {
|
||||
providers: {
|
||||
minimax: {
|
||||
baseUrl: "https://api.minimax.io/anthropic",
|
||||
models: [],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
env: {},
|
||||
token: "key",
|
||||
timeoutMs: 5000,
|
||||
fetchFn: fetchFn as typeof fetch,
|
||||
} as never);
|
||||
|
||||
expect(result?.windows).toEqual([{ label: "5h", usedPercent: 2, resetAt: undefined }]);
|
||||
});
|
||||
|
||||
it("writes api and authHeader into the MiniMax portal OAuth config patch", async () => {
|
||||
const { providers } = await registerProviderPlugin({
|
||||
plugin: minimaxProviderPlugin,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime";
|
||||
import type {
|
||||
OpenClawPluginApi,
|
||||
OpenClawConfig,
|
||||
ProviderAuthContext,
|
||||
ProviderAuthResult,
|
||||
ProviderCatalogContext,
|
||||
@@ -68,6 +69,14 @@ function portalModelRef(modelId: string): string {
|
||||
return `${PORTAL_PROVIDER_ID}/${modelId}`;
|
||||
}
|
||||
|
||||
function getProviderBaseUrl(cfg: OpenClawConfig, providerId: string): string | undefined {
|
||||
return normalizeOptionalString(cfg.models?.providers?.[providerId]?.baseUrl);
|
||||
}
|
||||
|
||||
function resolveMinimaxUsageBaseUrl(cfg: OpenClawConfig): string | undefined {
|
||||
return getProviderBaseUrl(cfg, PORTAL_PROVIDER_ID) ?? getProviderBaseUrl(cfg, API_PROVIDER_ID);
|
||||
}
|
||||
|
||||
function buildPortalProviderCatalog(params: { baseUrl: string; apiKey: string }) {
|
||||
return {
|
||||
...buildMinimaxPortalProvider(),
|
||||
@@ -255,7 +264,9 @@ export function registerMinimaxProviders(api: OpenClawPluginApi) {
|
||||
...MINIMAX_PROVIDER_HOOKS,
|
||||
isModernModelRef: ({ modelId }) => isMiniMaxModernModelId(modelId),
|
||||
fetchUsageSnapshot: async (ctx) =>
|
||||
await fetchMinimaxUsage(ctx.token, ctx.timeoutMs, ctx.fetchFn),
|
||||
await fetchMinimaxUsage(ctx.token, ctx.timeoutMs, ctx.fetchFn, {
|
||||
baseUrl: resolveMinimaxUsageBaseUrl(ctx.config),
|
||||
}),
|
||||
});
|
||||
|
||||
api.registerProvider({
|
||||
|
||||
@@ -22,6 +22,42 @@ async function expectMinimaxUsageResult(params: {
|
||||
}
|
||||
|
||||
describe("fetchMinimaxUsage", () => {
|
||||
it.each([
|
||||
{
|
||||
name: "uses the CN usage endpoint by default",
|
||||
baseUrl: undefined,
|
||||
expectedUrl: "https://api.minimaxi.com/v1/token_plan/remains",
|
||||
},
|
||||
{
|
||||
name: "derives the global usage endpoint from an Anthropic-compatible base URL",
|
||||
baseUrl: "https://api.minimax.io/anthropic",
|
||||
expectedUrl: "https://api.minimax.io/v1/token_plan/remains",
|
||||
},
|
||||
{
|
||||
name: "derives the usage endpoint from a configured origin",
|
||||
baseUrl: "https://api.minimaxi.com",
|
||||
expectedUrl: "https://api.minimaxi.com/v1/token_plan/remains",
|
||||
},
|
||||
{
|
||||
name: "falls back to CN when the configured base URL is malformed",
|
||||
baseUrl: "not a url",
|
||||
expectedUrl: "https://api.minimaxi.com/v1/token_plan/remains",
|
||||
},
|
||||
])("$name", async ({ baseUrl, expectedUrl }) => {
|
||||
const mockFetch = createProviderUsageFetch(async (url) => {
|
||||
expect(url).toBe(expectedUrl);
|
||||
return makeResponse(200, {
|
||||
data: {
|
||||
current_interval_total_count: 100,
|
||||
current_interval_usage_count: 98,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
const result = await fetchMinimaxUsage("key", 5000, mockFetch, { baseUrl });
|
||||
expect(result.windows).toEqual([{ label: "5h", usedPercent: 2, resetAt: undefined }]);
|
||||
});
|
||||
|
||||
it.each([
|
||||
{
|
||||
name: "returns HTTP errors for failed requests",
|
||||
|
||||
@@ -19,6 +19,13 @@ type MinimaxUsageResponse = {
|
||||
[key: string]: unknown;
|
||||
};
|
||||
|
||||
type FetchMinimaxUsageOptions = {
|
||||
baseUrl?: string;
|
||||
};
|
||||
|
||||
const DEFAULT_MINIMAX_USAGE_ORIGIN = "https://api.minimaxi.com";
|
||||
const MINIMAX_USAGE_PATH = "/v1/token_plan/remains";
|
||||
|
||||
const RESET_KEYS = [
|
||||
"reset_at",
|
||||
"resetAt",
|
||||
@@ -137,7 +144,7 @@ const REMAINING_KEYS = [
|
||||
"prompts_left",
|
||||
"promptsLeft",
|
||||
"left",
|
||||
// MiniMax `/coding_plan/remains` misnames these: values are remaining quota, not consumed.
|
||||
// MiniMax usage endpoints misname these: values are remaining quota, not consumed.
|
||||
// See https://github.com/MiniMax-AI/MiniMax-M2/issues/99
|
||||
"current_interval_usage_count",
|
||||
"currentIntervalUsageCount",
|
||||
@@ -366,13 +373,32 @@ function pickChatModelRemains(modelRemains: unknown[]): Record<string, unknown>
|
||||
});
|
||||
}
|
||||
|
||||
function resolveMinimaxUsageUrl(baseUrl?: string): string {
|
||||
const trimmed = baseUrl?.trim();
|
||||
if (!trimmed) {
|
||||
return `${DEFAULT_MINIMAX_USAGE_ORIGIN}${MINIMAX_USAGE_PATH}`;
|
||||
}
|
||||
|
||||
try {
|
||||
const parsed = new URL(trimmed);
|
||||
if (parsed.protocol === "http:" || parsed.protocol === "https:") {
|
||||
return `${parsed.origin}${MINIMAX_USAGE_PATH}`;
|
||||
}
|
||||
} catch {
|
||||
// Fall through to the stable CN default for malformed config values.
|
||||
}
|
||||
|
||||
return `${DEFAULT_MINIMAX_USAGE_ORIGIN}${MINIMAX_USAGE_PATH}`;
|
||||
}
|
||||
|
||||
export async function fetchMinimaxUsage(
|
||||
apiKey: string,
|
||||
timeoutMs: number,
|
||||
fetchFn: typeof fetch,
|
||||
options?: FetchMinimaxUsageOptions,
|
||||
): Promise<ProviderUsageSnapshot> {
|
||||
const res = await fetchJson(
|
||||
"https://api.minimaxi.com/v1/api/openplatform/coding_plan/remains",
|
||||
resolveMinimaxUsageUrl(options?.baseUrl),
|
||||
{
|
||||
method: "GET",
|
||||
headers: {
|
||||
|
||||
Reference in New Issue
Block a user