refactor(agent): dedupe harness and command workflows

This commit is contained in:
Peter Steinberger
2026-02-16 14:52:09 +00:00
parent 04892ee230
commit f717a13039
204 changed files with 7366 additions and 11540 deletions

View File

@@ -40,6 +40,36 @@ const requireAgentDir = () => {
return agentDir;
};
function createLegacyProviderConfig(params: {
providerId: string;
api: string;
modelId?: string;
modelName?: string;
}) {
return {
models: {
providers: {
[params.providerId]: {
baseUrl: "https://old.example.com",
apiKey: "old-key",
api: params.api,
models: [
{
id: params.modelId ?? "old-model",
name: params.modelName ?? "Old",
reasoning: false,
input: ["text"],
cost: { input: 1, output: 2, cacheRead: 0, cacheWrite: 0 },
contextWindow: 1000,
maxTokens: 100,
},
],
},
},
},
};
}
describe("writeOAuthCredentials", () => {
const envSnapshot = captureEnv([
"OPENCLAW_STATE_DIR",
@@ -209,28 +239,12 @@ describe("applyMinimaxApiConfig", () => {
});
it("merges existing minimax provider models", () => {
const cfg = applyMinimaxApiConfig({
models: {
providers: {
minimax: {
baseUrl: "https://old.example.com",
apiKey: "old-key",
api: "openai-completions",
models: [
{
id: "old-model",
name: "Old",
reasoning: false,
input: ["text"],
cost: { input: 1, output: 2, cacheRead: 0, cacheWrite: 0 },
contextWindow: 1000,
maxTokens: 100,
},
],
},
},
},
});
const cfg = applyMinimaxApiConfig(
createLegacyProviderConfig({
providerId: "minimax",
api: "openai-completions",
}),
);
expect(cfg.models?.providers?.minimax?.baseUrl).toBe("https://api.minimax.io/anthropic");
expect(cfg.models?.providers?.minimax?.api).toBe("anthropic-messages");
expect(cfg.models?.providers?.minimax?.apiKey).toBe("old-key");
@@ -341,28 +355,12 @@ describe("applySyntheticConfig", () => {
});
it("merges existing synthetic provider models", () => {
const cfg = applySyntheticProviderConfig({
models: {
providers: {
synthetic: {
baseUrl: "https://old.example.com",
apiKey: "old-key",
api: "openai-completions",
models: [
{
id: "old-model",
name: "Old",
reasoning: false,
input: ["text"],
cost: { input: 1, output: 2, cacheRead: 0, cacheWrite: 0 },
contextWindow: 1000,
maxTokens: 100,
},
],
},
},
},
});
const cfg = applySyntheticProviderConfig(
createLegacyProviderConfig({
providerId: "synthetic",
api: "openai-completions",
}),
);
expect(cfg.models?.providers?.synthetic?.baseUrl).toBe("https://api.synthetic.new/anthropic");
expect(cfg.models?.providers?.synthetic?.api).toBe("anthropic-messages");
expect(cfg.models?.providers?.synthetic?.apiKey).toBe("old-key");
@@ -383,28 +381,14 @@ describe("applyXiaomiConfig", () => {
});
it("merges Xiaomi models and keeps existing provider overrides", () => {
const cfg = applyXiaomiProviderConfig({
models: {
providers: {
xiaomi: {
baseUrl: "https://old.example.com",
apiKey: "old-key",
api: "openai-completions",
models: [
{
id: "custom-model",
name: "Custom",
reasoning: false,
input: ["text"],
cost: { input: 1, output: 2, cacheRead: 0, cacheWrite: 0 },
contextWindow: 1000,
maxTokens: 100,
},
],
},
},
},
});
const cfg = applyXiaomiProviderConfig(
createLegacyProviderConfig({
providerId: "xiaomi",
api: "openai-completions",
modelId: "custom-model",
modelName: "Custom",
}),
);
expect(cfg.models?.providers?.xiaomi?.baseUrl).toBe("https://api.xiaomimimo.com/anthropic");
expect(cfg.models?.providers?.xiaomi?.api).toBe("anthropic-messages");
@@ -445,28 +429,14 @@ describe("applyXaiProviderConfig", () => {
});
it("merges xAI models and keeps existing provider overrides", () => {
const cfg = applyXaiProviderConfig({
models: {
providers: {
xai: {
baseUrl: "https://old.example.com",
apiKey: "old-key",
api: "anthropic-messages",
models: [
{
id: "custom-model",
name: "Custom",
reasoning: false,
input: ["text"],
cost: { input: 1, output: 2, cacheRead: 0, cacheWrite: 0 },
contextWindow: 1000,
maxTokens: 100,
},
],
},
},
},
});
const cfg = applyXaiProviderConfig(
createLegacyProviderConfig({
providerId: "xai",
api: "anthropic-messages",
modelId: "custom-model",
modelName: "Custom",
}),
);
expect(cfg.models?.providers?.xai?.baseUrl).toBe("https://api.x.ai/v1");
expect(cfg.models?.providers?.xai?.api).toBe("openai-completions");