fix: stop adding auto as Qoder model fallback
This commit is contained in:
Generated
+2
-2
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "pi-provider-qoder",
|
"name": "pi-provider-qoder",
|
||||||
"version": "0.2.5",
|
"version": "0.2.7",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "pi-provider-qoder",
|
"name": "pi-provider-qoder",
|
||||||
"version": "0.2.5",
|
"version": "0.2.7",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@biomejs/biome": "2.4.2",
|
"@biomejs/biome": "2.4.2",
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "pi-provider-qoder",
|
"name": "pi-provider-qoder",
|
||||||
"version": "0.2.6",
|
"version": "0.2.7",
|
||||||
"description": "Pi extension for Qoder AI — with OAuth authentication, COSY signatures and WAF bypass",
|
"description": "Pi extension for Qoder AI — with OAuth authentication, COSY signatures and WAF bypass",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
|||||||
@@ -0,0 +1,59 @@
|
|||||||
|
import { existsSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
||||||
|
import { homedir } from "node:os";
|
||||||
|
import { join } from "node:path";
|
||||||
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||||
|
import { getCachedModels, updateQoderModelsCache } from "../models.js";
|
||||||
|
|
||||||
|
const CACHE_PATH = join(homedir(), ".pi", "agent", "qoder-models-cache.json");
|
||||||
|
let originalCache: string | undefined;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
originalCache = existsSync(CACHE_PATH) ? readFileSync(CACHE_PATH, "utf8") : undefined;
|
||||||
|
rmSync(CACHE_PATH, { force: true });
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
vi.unstubAllGlobals();
|
||||||
|
if (originalCache === undefined) rmSync(CACHE_PATH, { force: true });
|
||||||
|
else writeFileSync(CACHE_PATH, originalCache, "utf8");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("Qoder model cache", () => {
|
||||||
|
it("keeps only enabled service models without adding auto as a fallback", async () => {
|
||||||
|
vi.stubGlobal(
|
||||||
|
"fetch",
|
||||||
|
vi.fn().mockResolvedValue({
|
||||||
|
ok: true,
|
||||||
|
json: () =>
|
||||||
|
Promise.resolve({
|
||||||
|
chat: [
|
||||||
|
{ key: "auto", enable: false, display_name: "Auto" },
|
||||||
|
{ key: "ultimate", enable: true, display_name: "Ultimate", is_reasoning: true },
|
||||||
|
{ key: "lite", enable: true, display_name: "Lite" },
|
||||||
|
{ key: "performance", enable: false, display_name: "Performance" },
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
await updateQoderModelsCache("access-token", "user-id", "Test User", "test@example.com", "global");
|
||||||
|
|
||||||
|
const cache = JSON.parse(readFileSync(CACHE_PATH, "utf8"));
|
||||||
|
expect(cache.models.map((model: { id: string }) => model.id)).toEqual(["ultimate", "lite"]);
|
||||||
|
expect(cache.models.some((model: { id: string }) => model.id === "auto")).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("filters auto from a legacy fallback cache when the service did not enable it", () => {
|
||||||
|
writeFileSync(
|
||||||
|
CACHE_PATH,
|
||||||
|
JSON.stringify({
|
||||||
|
updatedAt: Date.now(),
|
||||||
|
models: [{ id: "auto" }, { id: "ultimate" }],
|
||||||
|
configs: { ultimate: { key: "ultimate", enable: true } },
|
||||||
|
}),
|
||||||
|
"utf8",
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(getCachedModels("global").map((model) => model.id)).toEqual(["ultimate"]);
|
||||||
|
});
|
||||||
|
});
|
||||||
+5
-17
@@ -345,6 +345,11 @@ export function getCachedModels(mode?: string): QoderModelDef[] {
|
|||||||
try {
|
try {
|
||||||
const data = JSON.parse(readFileSync(cachePath, "utf8"));
|
const data = JSON.parse(readFileSync(cachePath, "utf8"));
|
||||||
if (data && Array.isArray(data.models)) {
|
if (data && Array.isArray(data.models)) {
|
||||||
|
// Older releases injected `auto` without a corresponding service config.
|
||||||
|
// Keep an explicitly enabled service model, but drop the legacy fallback.
|
||||||
|
if (data.configs && typeof data.configs === "object" && !data.configs.auto) {
|
||||||
|
return data.models.filter((model: QoderModelDef) => model.id !== "auto");
|
||||||
|
}
|
||||||
return data.models;
|
return data.models;
|
||||||
}
|
}
|
||||||
} catch {}
|
} catch {}
|
||||||
@@ -504,23 +509,6 @@ export async function updateQoderModelsCache(
|
|||||||
|
|
||||||
if (newModels.length === 0) return;
|
if (newModels.length === 0) return;
|
||||||
|
|
||||||
// Ensure auto is present
|
|
||||||
if (!newModels.some((m) => m.id === "auto")) {
|
|
||||||
newModels.unshift({
|
|
||||||
id: "auto",
|
|
||||||
name: isQoderCNMode(mode) ? "Auto · Qoder CN" : "Qoder Auto",
|
|
||||||
api: "qoder-api",
|
|
||||||
provider: isQoderCNMode(mode) ? "qoder-cn" : "qoder",
|
|
||||||
baseUrl: getQoderBaseUrl(mode),
|
|
||||||
reasoning: true,
|
|
||||||
supportsEffort: false,
|
|
||||||
input: ["text", "image"],
|
|
||||||
cost: ZERO_COST,
|
|
||||||
contextWindow: 180000,
|
|
||||||
maxTokens: 32768,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const cacheData = {
|
const cacheData = {
|
||||||
updatedAt: Date.now(),
|
updatedAt: Date.now(),
|
||||||
models: newModels,
|
models: newModels,
|
||||||
|
|||||||
Reference in New Issue
Block a user