refactor(providers): derive simple providers from manifests (#114331)

This commit is contained in:
Peter Steinberger
2026-07-27 01:29:53 -04:00
committed by GitHub
parent ccd6845e4d
commit dc8fdb1756
29 changed files with 409 additions and 412 deletions
+10 -11
View File
@@ -1,11 +1,12 @@
import { readFileSync } from "node:fs";
import type { StreamFn } from "openclaw/plugin-sdk/agent-core";
import type { Context, Model } from "openclaw/plugin-sdk/llm";
import { registerSingleProviderPlugin } from "openclaw/plugin-sdk/plugin-test-runtime";
import { buildManifestModelProviderConfig } from "openclaw/plugin-sdk/provider-catalog-shared";
import { buildOpenAICompletionsParams } from "openclaw/plugin-sdk/provider-transport-runtime";
import { describe, expect, it } from "vitest";
import plugin from "./index.js";
import { buildCohereProvider, COHERE_LIVE_MODEL_DISCOVERY } from "./provider-catalog.js";
import manifest from "./openclaw.plugin.json" with { type: "json" };
import { COHERE_LIVE_MODEL_DISCOVERY } from "./provider-catalog.js";
import { createCohereCompletionsWrapper } from "./stream.js";
const COHERE_COMMAND_A_PLUS_MODEL_ID = "command-a-plus-05-2026";
@@ -13,11 +14,11 @@ const COHERE_COMMAND_A_REASONING_MODEL_ID = "command-a-reasoning-08-2025";
const COHERE_COMMAND_A_VISION_MODEL_ID = "command-a-vision-07-2025";
const COHERE_NORTH_MINI_CODE_MODEL_ID = "north-mini-code-1-0";
function readManifest() {
return JSON.parse(readFileSync(new URL("./openclaw.plugin.json", import.meta.url), "utf8")) as {
providerAuthChoices?: Array<{ choiceId?: string; optionKey?: string; cliFlag?: string }>;
setup?: { providers?: Array<{ id?: string; envVars?: string[] }> };
};
function buildCohereProvider() {
return buildManifestModelProviderConfig({
providerId: "cohere",
catalog: manifest.modelCatalog.providers.cohere,
});
}
function requireCohereModel(modelId = COHERE_COMMAND_A_PLUS_MODEL_ID): Model<"openai-completions"> {
@@ -78,16 +79,14 @@ describe("Cohere provider plugin", () => {
kind: "api_key",
wizard: { choiceId: "cohere-api-key" },
});
expect(readManifest().providerAuthChoices).toEqual([
expect(manifest.providerAuthChoices).toEqual([
expect.objectContaining({
choiceId: "cohere-api-key",
optionKey: "cohereApiKey",
cliFlag: "--cohere-api-key",
}),
]);
expect(readManifest().setup?.providers).toEqual([
{ id: "cohere", envVars: ["COHERE_API_KEY"] },
]);
expect(manifest.setup.providers).toEqual([{ id: "cohere", envVars: ["COHERE_API_KEY"] }]);
});
it("exposes the static Cohere catalog", () => {
+5 -21
View File
@@ -1,36 +1,20 @@
import { defineSingleProviderPluginEntry } from "openclaw/plugin-sdk/provider-entry";
import { isModernCohereModelId } from "./models.js";
import { applyCohereConfig, COHERE_DEFAULT_MODEL_REF } from "./onboard.js";
import { buildCohereProvider, COHERE_LIVE_MODEL_DISCOVERY } from "./provider-catalog.js";
import { applyCohereConfig } from "./onboard.js";
import manifest from "./openclaw.plugin.json" with { type: "json" };
import { COHERE_LIVE_MODEL_DISCOVERY } from "./provider-catalog.js";
import { createCohereCompletionsWrapper } from "./stream.js";
export default defineSingleProviderPluginEntry({
id: "cohere",
name: "Cohere Provider",
description: "Cohere provider plugin",
manifest,
provider: {
label: "Cohere",
docsPath: "/providers/cohere",
auth: [
{
methodId: "api-key",
label: "Cohere API key",
hint: "OpenAI-compatible inference",
optionKey: "cohereApiKey",
flagName: "--cohere-api-key",
envVar: "COHERE_API_KEY",
promptMessage: "Enter Cohere API key",
defaultModel: COHERE_DEFAULT_MODEL_REF,
applyConfig: (cfg) => applyCohereConfig(cfg),
wizard: {
groupLabel: "Cohere",
groupHint: "OpenAI-compatible inference",
},
},
],
manifestAuth: { applyConfig: applyCohereConfig },
catalog: {
buildProvider: buildCohereProvider,
buildStaticProvider: buildCohereProvider,
liveModelDiscovery: COHERE_LIVE_MODEL_DISCOVERY,
},
wrapStreamFn: (ctx) => createCohereCompletionsWrapper(ctx.streamFn),
+2 -1
View File
@@ -2,9 +2,10 @@ import type { OpenClawConfig } from "openclaw/plugin-sdk/config-contracts";
import { resolveAgentModelPrimaryValue } from "openclaw/plugin-sdk/provider-onboard";
import { describe, expect, it } from "vitest";
import { buildCohereCatalogModels, COHERE_BASE_URL } from "./models.js";
import { applyCohereConfig, COHERE_DEFAULT_MODEL_REF } from "./onboard.js";
import { applyCohereConfig } from "./onboard.js";
import manifest from "./openclaw.plugin.json" with { type: "json" };
const COHERE_DEFAULT_MODEL_REF = `cohere/${manifest.modelCatalog.providers.cohere.defaultModel}`;
const COHERE_DEFAULT_MODEL_ID = "command-a-plus-05-2026";
const COHERE_COMMAND_A_REASONING_MODEL_ID = "command-a-reasoning-08-2025";
const COHERE_COMMAND_A_VISION_MODEL_ID = "command-a-vision-07-2025";
+1 -1
View File
@@ -6,7 +6,7 @@ import {
import { buildCohereCatalogModels, COHERE_BASE_URL } from "./models.js";
import manifest from "./openclaw.plugin.json" with { type: "json" };
export const COHERE_DEFAULT_MODEL_REF = readManifestProviderDefaultModelRef(manifest, "cohere")!;
const COHERE_DEFAULT_MODEL_REF = readManifestProviderDefaultModelRef(manifest, "cohere")!;
const coherePresetAppliers = createModelCatalogPresetAppliers({
primaryModelRef: COHERE_DEFAULT_MODEL_REF,
+1 -10
View File
@@ -1,6 +1,5 @@
import type { OpenAICompatibleModelDiscoveryOptions } from "openclaw/plugin-sdk/provider-catalog-live-runtime";
import type { ModelProviderConfig } from "openclaw/plugin-sdk/provider-model-shared";
import { buildCohereCatalogModels, COHERE_BASE_URL } from "./models.js";
import { COHERE_BASE_URL } from "./models.js";
export const COHERE_LIVE_MODEL_DISCOVERY: OpenAICompatibleModelDiscoveryOptions = {
endpointUrl: {
@@ -25,11 +24,3 @@ export const COHERE_LIVE_MODEL_DISCOVERY: OpenAICompatibleModelDiscoveryOptions
});
},
};
export function buildCohereProvider(): ModelProviderConfig {
return {
baseUrl: COHERE_BASE_URL,
api: "openai-completions",
models: buildCohereCatalogModels(),
};
}