diff --git a/index.mjs b/index.mjs index 1a42997..5e33814 100644 --- a/index.mjs +++ b/index.mjs @@ -243,7 +243,10 @@ export async function CrofaiPlugin() { // second pass, not plugin-returned model variants). config: async (config) => { config.provider = config.provider || {}; + // Preserve any pre-existing user config (whitelist, blacklist, options, etc.) + // before setting our provider definition fields. config.provider.crofai = { + ...config.provider.crofai, id: PROVIDER_ID, name: "CrofAI", npm: "@ai-sdk/openai-compatible", diff --git a/test/plugin.test.js b/test/plugin.test.js index 45df098..88c1ec9 100644 --- a/test/plugin.test.js +++ b/test/plugin.test.js @@ -60,6 +60,46 @@ describe("config hook", () => { assert.equal(cfg.provider.crofai.id, "crofai"); }); + it("preserves user-defined whitelist, blacklist, and options on the crofai provider", async () => { + const hooks = await CrofaiPlugin(); + const cfg = { + provider: { + crofai: { + whitelist: ["deepseek-v4-pro", "kimi-k2.6"], + blacklist: ["some-model-i-dont-want"], + options: { timeout: 300000 }, + }, + }, + }; + await hooks.config(cfg); + + const p = cfg.provider.crofai; + assert.deepEqual(p.whitelist, ["deepseek-v4-pro", "kimi-k2.6"], "whitelist should survive config hook"); + assert.deepEqual(p.blacklist, ["some-model-i-dont-want"], "blacklist should survive config hook"); + assert.deepEqual(p.options, { timeout: 300000 }, "options should survive config hook"); + // Core provider fields should still be set + assert.equal(p.id, "crofai"); + assert.equal(p.npm, "@ai-sdk/openai-compatible"); + }); + + it("allows overriding provider options while preserving whitelist", async () => { + const hooks = await CrofaiPlugin(); + const cfg = { + provider: { + crofai: { + whitelist: ["kimi-k2.6"], + }, + }, + }; + await hooks.config(cfg); + + assert.deepEqual( + cfg.provider.crofai.whitelist, + ["kimi-k2.6"], + "whitelist alone should survive the config hook", + ); + }); + it("injects all models from cache with full config data", async () => { const cachePath = getCachePath(); const cacheDir = join(cachePath, "..");