mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-03 15:44:06 +00:00
* refactor: extract agent core package Introduce packages/agent-core as the OpenClaw-owned home for reusable agent loop, harness, session, prompt, and runtime dependency contracts. * refactor: extract shared llm runtime Move provider model registries, stream wrappers, OAuth helpers, and LLM utilities into src/llm with plugin-sdk barrels instead of depending on the old embedded runtime layout. * refactor: remove pi runtime internals Rename remaining Pi-shaped agent surfaces to OpenClaw agent runtime names, delete obsolete Pi docs and package graph checks, and add the third-party notice for incorporated code. * refactor: tighten agent session runtime Make agent-core/runtime dependencies explicit, consolidate compaction and session transcript helpers, and move model/session helpers behind OpenClaw-owned contracts. * refactor: remove static model and pi auth paths Drop static model catalogs and Pi auth bridges, move model/provider facts to manifest-owned runtime contracts, and harden internal embedded-agent utilities. * refactor: remove legacy provider compat paths * docs: remove agent parity notes * fix: skip provider wildcard metadata parsing * refactor: share session extension sdk loading * refactor: inline acpx proxy error formatter * refactor: fold edit recovery into edit tool * fix: accept extension batch separator * test: align startup provider plugin expectations * fix: restore provider-scoped release discovery * test: align static asset packaging expectations * fix: run static provider catalogs during scoped discovery * fix: add provider entry catalogs for scoped live discovery * fix: load lightweight provider catalog entries * fix: refresh provider-scoped plugin metadata * fix: keep provider catalog entries on release live path * fix: keep static manifest models in release live checks * fix: harden release model discovery * fix: reduce OpenAI live cache probe reasoning * fix: disable OpenAI cache probe reasoning * ci: extend OpenAI gateway live timeout * fix: extend live gateway model budget * fix: stabilize release validation regressions * fix: honor provider aliases in model rows * fix: stabilize release validation lanes * fix: stabilize release memory qa * ci: stabilize release validation lanes * ci: prefer ipv4 for live docker node calls * fix: restore shared tool-call stream wrapper * ci: remove legacy pi test shard alias * fix: clean up embedded agent test drift * fix: stabilize runtime alias status * fix: clean up embedded agent ci drift * fix: restore release ci invariants * fix: clean up post-rebase runtime drift * fix: restore release ci checks * fix: restore release ci after rebase * fix: remove stale pi runtime path * test: align compaction runtime expectations * test: update plugin prerelease expectations * fix: handle claude live tool approvals * fix: stabilize release validation gates * fix: finish agent runtime import * test: finish post-rebase agent runtime mocks * fix: keep codex compaction native * fix: stabilize codex app-server hook tests * test: isolate codex diagnostic active run * test: remove codex diagnostic completion race # Conflicts: # extensions/codex/src/app-server/run-attempt.test.ts * ci: fix full release manifest performance run id * refactor: narrow llm plugin sdk boundary * chore: drop generated google boundary stamps * fix: repair rebase fallout * fix: clean up rebased runtime references * fix: decode codex jwt payloads as base64url * fix: preserve shipped pi runtime alias * fix: add scoped sdk virtual modules * fix: decode llm codex oauth jwt as base64url * fix: avoid stale vertex adc negative cache * fix: harden tool arg decoding and codeql path * fix: keep vertex adc negative checks live * refactor: consolidate codex jwt and edit helpers * fix: await codex oauth node runtime imports * fix: preserve sdk tool and notice contracts * fix: preserve shipped compat config boundaries * fix: align codex oauth callback host * fix: terminate agent-core loop streams on failure * fix: keep codex oauth callback alive during fallback * ci: include session tools in critical codeql scans * fix: keep Cloudflare Anthropic provider auth header * docs: redirect legacy pi runtime pages * fix: honor bundled web provider compat discovery * fix: protect session output spill files * fix: keep legacy agent dir env blocked * fix: contain auto-discovered skill symlinks * fix: harden agent core sdk proxy surfaces * fix: restore approval reaction sdk compat * fix: keep live docker runs bounded * fix: keep codex oauth redirect host aligned * fix: resolve post-rebase agent runtime drift * fix: redact anthropic oauth parse failures * fix: preserve responses strict tool shaping * fix: repair agent runtime rebase cleanup * docs: redirect retired parity pages * fix: bound auto-discovered resources to roots * fix: repair post-rebase agent test drift * fix: preserve bundled provider allowlist migration * fix: preserve manifest-owned provider aliases * fix: declare photon image dependency * fix: keep provider headers out of proxy body * fix: preserve shipped env aliases * fix: refresh control ui i18n generated state * fix: quote read fallback paths * fix: preview edits through configured backend * test: satisfy core test typecheck * fix: preserve ZAI usage auth fallback * test: repair codex diagnostic test * fix: repair agent runtime rebase drift * test: finish embedded runner import rename * fix: repair agent runtime rebase integrations * test: align compaction oauth fallback expectations * fix: allow sdk-auth session models * fix: update doctor tool schema import * fix: preserve bedrock plugin region * fix: stream harmony-like prose immediately * ci: include session runtime in codeql shards * fix: repair latest rebase integrations * fix: honor explicit codex websocket transport * fix: keep openai-compatible credentials provider-scoped * fix: refresh sdk api baseline after rebase * fix: route cli runtime aliases through openclaw harness * test: rename stale harness mock expectation * test: rename embedded agent overflow calls * test: clean embedded auth test wording * test: use openclaw stream types in deepinfra cache test * fix: refresh sdk api baseline on latest main * fix: honor bundled discovery compat allowlists * fix: refresh sdk api baseline after latest rebase * fix: remove stale rebase imports * test: rename stale model catalog mock * test: mock renamed doctor runtime modules * fix: map canonical kimi env auth * fix: use internal model registry in bench script * fix: migrate deepinfra provider catalog entry * fix: enforce builtin tool suppression * fix: route compaction auth and proxy payloads safely * refactor: prune unused llm registry leftovers * test: update codex hooks session import * test: fix model picker ci coverage * test: align model picker auth mock types
409 lines
13 KiB
TypeScript
409 lines
13 KiB
TypeScript
import { readFileSync } from "node:fs";
|
|
import { resolve } from "node:path";
|
|
import type { StreamFn } from "openclaw/plugin-sdk/agent-core";
|
|
import type { Context, Model } from "openclaw/plugin-sdk/llm";
|
|
import {
|
|
registerProviderPlugin,
|
|
requireRegisteredProvider,
|
|
} from "openclaw/plugin-sdk/plugin-test-runtime";
|
|
import { describe, expect, it, vi } from "vitest";
|
|
import { registerMinimaxProviders } from "./provider-registration.js";
|
|
import { createMiniMaxWebSearchProvider } from "./src/minimax-web-search-provider.js";
|
|
|
|
vi.mock("./oauth.runtime.js", () => ({
|
|
loginMiniMaxPortalOAuth: vi.fn(async () => ({
|
|
access: "minimax-oauth-access-token",
|
|
refresh: "minimax-oauth-refresh-token",
|
|
expires: Date.now() + 60_000,
|
|
resourceUrl: "https://api.minimax.io/anthropic",
|
|
})),
|
|
}));
|
|
|
|
const minimaxProviderPlugin = {
|
|
register(api: Parameters<typeof registerMinimaxProviders>[0]) {
|
|
registerMinimaxProviders(api);
|
|
api.registerWebSearchProvider(createMiniMaxWebSearchProvider());
|
|
},
|
|
};
|
|
|
|
describe("minimax provider hooks", () => {
|
|
it("declares CN provider auth aliases in the manifest", () => {
|
|
const pluginJson = JSON.parse(
|
|
readFileSync(resolve(import.meta.dirname, "openclaw.plugin.json"), "utf-8"),
|
|
);
|
|
|
|
expect(pluginJson.providerAuthAliases).toEqual({
|
|
"minimax-cn": "minimax",
|
|
"minimax-portal-cn": "minimax-portal",
|
|
});
|
|
});
|
|
|
|
it("keeps native reasoning mode for MiniMax transports", async () => {
|
|
const { providers } = await registerProviderPlugin({
|
|
plugin: minimaxProviderPlugin,
|
|
id: "minimax",
|
|
name: "MiniMax Provider",
|
|
});
|
|
const apiProvider = requireRegisteredProvider(providers, "minimax");
|
|
const portalProvider = requireRegisteredProvider(providers, "minimax-portal");
|
|
|
|
expect(apiProvider.hookAliases).toContain("minimax-cn");
|
|
expect(
|
|
apiProvider.resolveReasoningOutputMode?.({
|
|
provider: "minimax",
|
|
modelApi: "anthropic-messages",
|
|
modelId: "MiniMax-M2.7",
|
|
} as never),
|
|
).toBe("native");
|
|
|
|
expect(portalProvider.hookAliases).toContain("minimax-portal-cn");
|
|
expect(
|
|
portalProvider.resolveReasoningOutputMode?.({
|
|
provider: "minimax-portal",
|
|
modelApi: "anthropic-messages",
|
|
modelId: "MiniMax-M2.7",
|
|
} as never),
|
|
).toBe("native");
|
|
});
|
|
|
|
it("keeps MiniMax auth setup metadata aligned across regions", async () => {
|
|
const { providers } = await registerProviderPlugin({
|
|
plugin: minimaxProviderPlugin,
|
|
id: "minimax",
|
|
name: "MiniMax Provider",
|
|
});
|
|
const apiProvider = requireRegisteredProvider(providers, "minimax");
|
|
const portalProvider = requireRegisteredProvider(providers, "minimax-portal");
|
|
|
|
expect(
|
|
apiProvider.auth.map((method) => ({
|
|
id: method.id,
|
|
label: method.label,
|
|
hint: method.hint,
|
|
choiceId: method.wizard?.choiceId,
|
|
groupId: method.wizard?.groupId,
|
|
groupHint: method.wizard?.groupHint,
|
|
})),
|
|
).toEqual([
|
|
{
|
|
id: "api-global",
|
|
label: "MiniMax API key (Global)",
|
|
hint: "Global endpoint - api.minimax.io",
|
|
choiceId: "minimax-global-api",
|
|
groupId: "minimax",
|
|
groupHint: "M2.7 (recommended)",
|
|
},
|
|
{
|
|
id: "api-cn",
|
|
label: "MiniMax API key (CN)",
|
|
hint: "CN endpoint - api.minimaxi.com",
|
|
choiceId: "minimax-cn-api",
|
|
groupId: "minimax",
|
|
groupHint: "M2.7 (recommended)",
|
|
},
|
|
]);
|
|
|
|
expect(
|
|
portalProvider.auth.map((method) => ({
|
|
id: method.id,
|
|
label: method.label,
|
|
hint: method.hint,
|
|
choiceId: method.wizard?.choiceId,
|
|
groupId: method.wizard?.groupId,
|
|
groupHint: method.wizard?.groupHint,
|
|
})),
|
|
).toEqual([
|
|
{
|
|
id: "oauth",
|
|
label: "MiniMax OAuth (Global)",
|
|
hint: "Global endpoint - api.minimax.io",
|
|
choiceId: "minimax-global-oauth",
|
|
groupId: "minimax",
|
|
groupHint: "M2.7 (recommended)",
|
|
},
|
|
{
|
|
id: "oauth-cn",
|
|
label: "MiniMax OAuth (CN)",
|
|
hint: "CN endpoint - api.minimaxi.com",
|
|
choiceId: "minimax-cn-oauth",
|
|
groupId: "minimax",
|
|
groupHint: "M2.7 (recommended)",
|
|
},
|
|
]);
|
|
});
|
|
|
|
it("owns replay policy for Anthropic and OpenAI-compatible MiniMax transports", async () => {
|
|
const { providers } = await registerProviderPlugin({
|
|
plugin: minimaxProviderPlugin,
|
|
id: "minimax",
|
|
name: "MiniMax Provider",
|
|
});
|
|
const apiProvider = requireRegisteredProvider(providers, "minimax");
|
|
const portalProvider = requireRegisteredProvider(providers, "minimax-portal");
|
|
|
|
expect(
|
|
apiProvider.buildReplayPolicy?.({
|
|
provider: "minimax",
|
|
modelApi: "anthropic-messages",
|
|
modelId: "MiniMax-M2.7",
|
|
} as never),
|
|
).toEqual({
|
|
sanitizeMode: "full",
|
|
sanitizeToolCallIds: true,
|
|
toolCallIdMode: "strict",
|
|
preserveSignatures: true,
|
|
repairToolUseResultPairing: true,
|
|
validateAnthropicTurns: true,
|
|
allowSyntheticToolResults: true,
|
|
});
|
|
|
|
expect(
|
|
portalProvider.buildReplayPolicy?.({
|
|
provider: "minimax-portal",
|
|
modelApi: "openai-completions",
|
|
modelId: "MiniMax-M2.7",
|
|
} as never),
|
|
).toEqual({
|
|
sanitizeToolCallIds: true,
|
|
toolCallIdMode: "strict",
|
|
applyAssistantFirstOrderingFix: true,
|
|
validateGeminiTurns: true,
|
|
validateAnthropicTurns: true,
|
|
dropReasoningFromHistory: true,
|
|
});
|
|
});
|
|
|
|
it("keeps M2.7 on the Anthropic Messages route used by the empty-history guard", async () => {
|
|
const { providers } = await registerProviderPlugin({
|
|
plugin: minimaxProviderPlugin,
|
|
id: "minimax",
|
|
name: "MiniMax Provider",
|
|
});
|
|
const apiProvider = requireRegisteredProvider(providers, "minimax");
|
|
|
|
const catalog = await apiProvider.catalog?.run({
|
|
env: {},
|
|
config: {},
|
|
resolveProviderApiKey: (providerId?: string) => ({
|
|
apiKey: providerId === "minimax" ? "sk-minimax-test" : undefined,
|
|
}),
|
|
} as never);
|
|
|
|
const provider = catalog && "provider" in catalog ? catalog.provider : undefined;
|
|
expect(provider?.api).toBe("anthropic-messages");
|
|
expect(provider?.authHeader).toBe(true);
|
|
expect(provider?.baseUrl).toBe("https://api.minimax.io/anthropic");
|
|
const model = provider?.models.find((entry: { id?: string }) => entry.id === "MiniMax-M2.7");
|
|
expect(model?.id).toBe("MiniMax-M2.7");
|
|
expect(model?.input).toEqual(["text"]);
|
|
expect(model?.name).toBe("MiniMax M2.7");
|
|
expect(model?.reasoning).toBe(true);
|
|
});
|
|
|
|
it("owns fast-mode stream wrapping for MiniMax transports", async () => {
|
|
const { providers } = await registerProviderPlugin({
|
|
plugin: minimaxProviderPlugin,
|
|
id: "minimax",
|
|
name: "MiniMax Provider",
|
|
});
|
|
const apiProvider = requireRegisteredProvider(providers, "minimax");
|
|
const portalProvider = requireRegisteredProvider(providers, "minimax-portal");
|
|
|
|
let resolvedApiModelId = "";
|
|
const captureApiModel: StreamFn = (model) => {
|
|
resolvedApiModelId = model.id ?? "";
|
|
return {} as ReturnType<StreamFn>;
|
|
};
|
|
const wrappedApiStream = apiProvider.wrapStreamFn?.({
|
|
provider: "minimax",
|
|
modelId: "MiniMax-M2.7",
|
|
extraParams: { fastMode: true },
|
|
streamFn: captureApiModel,
|
|
} as never);
|
|
|
|
void wrappedApiStream?.(
|
|
{
|
|
api: "anthropic-messages",
|
|
provider: "minimax",
|
|
id: "MiniMax-M2.7",
|
|
} as Model<"anthropic-messages">,
|
|
{ messages: [] } as Context,
|
|
{},
|
|
);
|
|
|
|
let resolvedPortalModelId = "";
|
|
const capturePortalModel: StreamFn = (model) => {
|
|
resolvedPortalModelId = model.id ?? "";
|
|
return {} as ReturnType<StreamFn>;
|
|
};
|
|
const wrappedPortalStream = portalProvider.wrapStreamFn?.({
|
|
provider: "minimax-portal",
|
|
modelId: "MiniMax-M2.7",
|
|
extraParams: { fastMode: true },
|
|
streamFn: capturePortalModel,
|
|
} as never);
|
|
|
|
void wrappedPortalStream?.(
|
|
{
|
|
api: "anthropic-messages",
|
|
provider: "minimax-portal",
|
|
id: "MiniMax-M2.7",
|
|
} as Model<"anthropic-messages">,
|
|
{ messages: [] } as Context,
|
|
{},
|
|
);
|
|
|
|
expect(resolvedApiModelId).toBe("MiniMax-M2.7-highspeed");
|
|
expect(resolvedPortalModelId).toBe("MiniMax-M2.7-highspeed");
|
|
});
|
|
|
|
it("shares the provider hook bundle across MiniMax variants", async () => {
|
|
const { providers } = await registerProviderPlugin({
|
|
plugin: minimaxProviderPlugin,
|
|
id: "minimax",
|
|
name: "MiniMax Provider",
|
|
});
|
|
const apiProvider = requireRegisteredProvider(providers, "minimax");
|
|
const portalProvider = requireRegisteredProvider(providers, "minimax-portal");
|
|
|
|
expect(apiProvider.buildReplayPolicy).toBe(portalProvider.buildReplayPolicy);
|
|
expect(apiProvider.wrapStreamFn).toBe(portalProvider.wrapStreamFn);
|
|
expect(apiProvider.resolveReasoningOutputMode).toBe(portalProvider.resolveReasoningOutputMode);
|
|
});
|
|
|
|
it("registers the bundled MiniMax web search provider", () => {
|
|
const webSearchProviders: unknown[] = [];
|
|
|
|
minimaxProviderPlugin.register({
|
|
registerProvider() {},
|
|
registerMediaUnderstandingProvider() {},
|
|
registerImageGenerationProvider() {},
|
|
registerMusicGenerationProvider() {},
|
|
registerVideoGenerationProvider() {},
|
|
registerSpeechProvider() {},
|
|
registerWebSearchProvider(provider: unknown) {
|
|
webSearchProviders.push(provider);
|
|
},
|
|
} as never);
|
|
|
|
expect(webSearchProviders).toHaveLength(1);
|
|
const provider = webSearchProviders[0] as
|
|
| {
|
|
id?: unknown;
|
|
label?: unknown;
|
|
onboardingScopes?: unknown;
|
|
envVars?: unknown;
|
|
}
|
|
| undefined;
|
|
expect(provider?.id).toBe("minimax");
|
|
expect(provider?.label).toBe("MiniMax Search");
|
|
expect(provider?.onboardingScopes).toEqual(["text-inference"]);
|
|
expect(provider?.envVars).toEqual([
|
|
"MINIMAX_CODE_PLAN_KEY",
|
|
"MINIMAX_CODING_API_KEY",
|
|
"MINIMAX_OAUTH_TOKEN",
|
|
"MINIMAX_API_KEY",
|
|
]);
|
|
});
|
|
|
|
it("prefers minimax-portal oauth when resolving MiniMax usage auth", async () => {
|
|
const { providers } = await registerProviderPlugin({
|
|
plugin: minimaxProviderPlugin,
|
|
id: "minimax",
|
|
name: "MiniMax Provider",
|
|
});
|
|
const apiProvider = requireRegisteredProvider(providers, "minimax");
|
|
const resolveOAuthToken = vi.fn(async (params?: { provider?: string }) =>
|
|
params?.provider === "minimax-portal" ? { token: "portal-oauth-token" } : null,
|
|
);
|
|
const resolveApiKeyFromConfigAndStore = vi.fn(() => undefined);
|
|
|
|
await expect(
|
|
apiProvider.resolveUsageAuth?.({
|
|
provider: "minimax",
|
|
config: {},
|
|
env: {},
|
|
resolveOAuthToken,
|
|
resolveApiKeyFromConfigAndStore,
|
|
} as never),
|
|
).resolves.toEqual({ token: "portal-oauth-token" });
|
|
|
|
expect(resolveOAuthToken).toHaveBeenCalledWith({ provider: "minimax-portal" });
|
|
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,
|
|
id: "minimax",
|
|
name: "MiniMax Provider",
|
|
});
|
|
const portalProvider = requireRegisteredProvider(providers, "minimax-portal");
|
|
const oauthMethod = portalProvider.auth.find((method) => method.id === "oauth");
|
|
|
|
if (!oauthMethod) {
|
|
throw new Error("expected minimax portal oauth auth method");
|
|
}
|
|
|
|
const result = await oauthMethod.run({
|
|
prompter: {
|
|
progress() {
|
|
return { stop() {} };
|
|
},
|
|
note: vi.fn(async () => undefined),
|
|
},
|
|
openUrl: vi.fn(async () => undefined),
|
|
} as never);
|
|
|
|
expect(result?.configPatch?.models?.providers?.["minimax-portal"]).toEqual({
|
|
baseUrl: "https://api.minimax.io/anthropic",
|
|
api: "anthropic-messages",
|
|
authHeader: true,
|
|
models: [],
|
|
});
|
|
});
|
|
});
|