mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-07 22:51:23 +00:00
fix: stabilize model catalog and pi discovery auth storage compatibility
This commit is contained in:
@@ -67,6 +67,14 @@ export function __setModelCatalogImportForTest(loader?: () => Promise<PiSdkModul
|
||||
importPiSdk = loader ?? defaultImportPiSdk;
|
||||
}
|
||||
|
||||
function createAuthStorage(AuthStorageLike: unknown, path: string) {
|
||||
const withFactory = AuthStorageLike as { create?: (path: string) => unknown };
|
||||
if (typeof withFactory.create === "function") {
|
||||
return withFactory.create(path);
|
||||
}
|
||||
return new (AuthStorageLike as { new (path: string): unknown })(path);
|
||||
}
|
||||
|
||||
export async function loadModelCatalog(params?: {
|
||||
config?: OpenClawConfig;
|
||||
useCache?: boolean;
|
||||
@@ -101,12 +109,17 @@ export async function loadModelCatalog(params?: {
|
||||
const piSdk = await importPiSdk();
|
||||
const agentDir = resolveOpenClawAgentDir();
|
||||
const { join } = await import("node:path");
|
||||
const authStorage = new piSdk.AuthStorage(join(agentDir, "auth.json"));
|
||||
const registry = new piSdk.ModelRegistry(authStorage, join(agentDir, "models.json")) as
|
||||
| {
|
||||
getAll: () => Array<DiscoveredModel>;
|
||||
}
|
||||
| Array<DiscoveredModel>;
|
||||
const authStorage = createAuthStorage(piSdk.AuthStorage, join(agentDir, "auth.json"));
|
||||
const registry = new (piSdk.ModelRegistry as unknown as {
|
||||
new (
|
||||
authStorage: unknown,
|
||||
modelsFile: string,
|
||||
):
|
||||
| Array<DiscoveredModel>
|
||||
| {
|
||||
getAll: () => Array<DiscoveredModel>;
|
||||
};
|
||||
})(authStorage, join(agentDir, "models.json"));
|
||||
const entries = Array.isArray(registry) ? registry : registry.getAll();
|
||||
for (const entry of entries) {
|
||||
const id = String(entry?.id ?? "").trim();
|
||||
|
||||
Reference in New Issue
Block a user