mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-09 15:42:56 +00:00
fix(agents): centralize live model limit parsing
This commit is contained in:
@@ -92,6 +92,16 @@ describe("shouldExcludeProviderFromDefaultHighSignalLiveSweep", () => {
|
||||
});
|
||||
|
||||
describe("resolveHighSignalLiveModelLimit", () => {
|
||||
it("accepts signed decimal max model limits", () => {
|
||||
expect(
|
||||
resolveHighSignalLiveModelLimit({
|
||||
rawMaxModels: "+3",
|
||||
useExplicitModels: false,
|
||||
defaultLimit: 5,
|
||||
}),
|
||||
).toBe(3);
|
||||
});
|
||||
|
||||
it("does not coerce partial max model limits", () => {
|
||||
expect(
|
||||
resolveHighSignalLiveModelLimit({
|
||||
@@ -101,4 +111,14 @@ describe("resolveHighSignalLiveModelLimit", () => {
|
||||
}),
|
||||
).toBe(0);
|
||||
});
|
||||
|
||||
it("does not coerce non-decimal max model limits", () => {
|
||||
expect(
|
||||
resolveHighSignalLiveModelLimit({
|
||||
rawMaxModels: "0x3",
|
||||
useExplicitModels: false,
|
||||
defaultLimit: 5,
|
||||
}),
|
||||
).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { OpenClawConfig } from "../config/types.openclaw.js";
|
||||
import { resolveProviderModernModelRef } from "../plugins/provider-runtime.js";
|
||||
import { parseStrictNonNegativeInteger } from "../shared/number-coercion.js";
|
||||
import { normalizeLowercaseStringOrEmpty } from "../shared/string-coerce.js";
|
||||
import { liveProvidersShareOwningPlugin } from "./live-provider-owner.js";
|
||||
import { normalizeProviderId } from "./provider-id.js";
|
||||
@@ -414,8 +415,7 @@ export function resolveHighSignalLiveModelLimit(params: {
|
||||
}): number {
|
||||
const trimmed = params.rawMaxModels?.trim();
|
||||
if (trimmed) {
|
||||
const parsed = /^\d+$/.test(trimmed) ? Number(trimmed) : Number.NaN;
|
||||
return Number.isSafeInteger(parsed) ? Math.max(0, parsed) : 0;
|
||||
return parseStrictNonNegativeInteger(trimmed) ?? 0;
|
||||
}
|
||||
if (params.useExplicitModels) {
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user