traderclaw-cli 1.0.52 → 1.0.53
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/openclaw-trader.mjs +65 -14
- package/package.json +1 -1
package/bin/openclaw-trader.mjs
CHANGED
|
@@ -1856,6 +1856,51 @@ async function loadWizardLlmCatalogAsync() {
|
|
|
1856
1856
|
}
|
|
1857
1857
|
}
|
|
1858
1858
|
|
|
1859
|
+
function buildProvidersFromMap(providerMap) {
|
|
1860
|
+
return providerIds
|
|
1861
|
+
.map((id) => {
|
|
1862
|
+
const rawModels = providerMap.get(id) || [];
|
|
1863
|
+
const sortedIds = sortModelsByPreference(
|
|
1864
|
+
id,
|
|
1865
|
+
rawModels.map((m) => m.id),
|
|
1866
|
+
);
|
|
1867
|
+
const byId = new Map(rawModels.map((m) => [m.id, m]));
|
|
1868
|
+
const limitedIds = sortedIds.slice(0, MAX_MODELS_PER_PROVIDER_SORT);
|
|
1869
|
+
const models = limitedIds.map((mid) => byId.get(mid)).filter(Boolean);
|
|
1870
|
+
return { id, models };
|
|
1871
|
+
})
|
|
1872
|
+
.filter((entry) => supportedProviders.has(entry.id))
|
|
1873
|
+
.filter((entry) => entry.models.length > 0);
|
|
1874
|
+
}
|
|
1875
|
+
|
|
1876
|
+
/** When `openclaw models list --all --json` returns models; used if per-provider calls yield nothing. */
|
|
1877
|
+
function mergeFlatCatalogIntoMap(providerMap) {
|
|
1878
|
+
const raw = execSync("openclaw models list --all --json", {
|
|
1879
|
+
encoding: "utf-8",
|
|
1880
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
1881
|
+
maxBuffer: 50 * 1024 * 1024,
|
|
1882
|
+
timeout: 45_000,
|
|
1883
|
+
env: NO_COLOR_ENV,
|
|
1884
|
+
});
|
|
1885
|
+
const parsed = extractJson(raw);
|
|
1886
|
+
if (!parsed) return;
|
|
1887
|
+
const models = Array.isArray(parsed?.models) ? parsed.models : [];
|
|
1888
|
+
for (const entry of models) {
|
|
1889
|
+
if (!entry || typeof entry.key !== "string") continue;
|
|
1890
|
+
const modelId = String(entry.key);
|
|
1891
|
+
const slash = modelId.indexOf("/");
|
|
1892
|
+
if (slash <= 0 || slash === modelId.length - 1) continue;
|
|
1893
|
+
const provider = modelId.slice(0, slash);
|
|
1894
|
+
if (!supportedProviders.has(provider)) continue;
|
|
1895
|
+
const existing = providerMap.get(provider) || [];
|
|
1896
|
+
existing.push({
|
|
1897
|
+
id: modelId,
|
|
1898
|
+
name: typeof entry.name === "string" && entry.name.trim() ? entry.name : modelId,
|
|
1899
|
+
});
|
|
1900
|
+
providerMap.set(provider, existing);
|
|
1901
|
+
}
|
|
1902
|
+
}
|
|
1903
|
+
|
|
1859
1904
|
try {
|
|
1860
1905
|
const t0 = Date.now();
|
|
1861
1906
|
const batches = await Promise.all(providerIds.map((p) => fetchModelsForProvider(p)));
|
|
@@ -1883,23 +1928,28 @@ async function loadWizardLlmCatalogAsync() {
|
|
|
1883
1928
|
}
|
|
1884
1929
|
}
|
|
1885
1930
|
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1931
|
+
let providers = buildProvidersFromMap(providerMap);
|
|
1932
|
+
let catalogStrategy = "parallel";
|
|
1933
|
+
|
|
1934
|
+
if (providers.length === 0) {
|
|
1935
|
+
catalogStrategy = "legacy_fallback";
|
|
1936
|
+
try {
|
|
1937
|
+
mergeFlatCatalogIntoMap(providerMap);
|
|
1938
|
+
providers = buildProvidersFromMap(providerMap);
|
|
1939
|
+
} catch (legacyErr) {
|
|
1940
|
+
console.error(
|
|
1941
|
+
`[traderclaw] loadWizardLlmCatalog legacy fallback failed: ${legacyErr instanceof Error ? legacyErr.message : String(legacyErr)}`,
|
|
1892
1942
|
);
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
const models = limitedIds.map((mid) => byId.get(mid)).filter(Boolean);
|
|
1896
|
-
return { id, models };
|
|
1897
|
-
})
|
|
1898
|
-
.filter((entry) => supportedProviders.has(entry.id))
|
|
1899
|
-
.filter((entry) => entry.models.length > 0);
|
|
1943
|
+
}
|
|
1944
|
+
}
|
|
1900
1945
|
|
|
1901
1946
|
if (providers.length === 0) {
|
|
1902
|
-
|
|
1947
|
+
const failedParallel = batches.filter((b) => b.error).length;
|
|
1948
|
+
const hint =
|
|
1949
|
+
failedParallel > 0
|
|
1950
|
+
? ` (${failedParallel}/${batches.length} per-provider openclaw calls failed — check OpenClaw version supports: openclaw models list --all --provider <id> --json)`
|
|
1951
|
+
: "";
|
|
1952
|
+
return { ...fallback, warning: `openclaw_model_catalog_empty${hint}` };
|
|
1903
1953
|
}
|
|
1904
1954
|
|
|
1905
1955
|
const elapsedMs = Date.now() - t0;
|
|
@@ -1908,6 +1958,7 @@ async function loadWizardLlmCatalogAsync() {
|
|
|
1908
1958
|
providers,
|
|
1909
1959
|
generatedAt: new Date().toISOString(),
|
|
1910
1960
|
catalogFetchMs: elapsedMs,
|
|
1961
|
+
catalogStrategy,
|
|
1911
1962
|
};
|
|
1912
1963
|
} catch (err) {
|
|
1913
1964
|
const detail = err?.message || String(err);
|
package/package.json
CHANGED