refactor: standardize runtime guard patterns with lodash-es (#154)

* refactor(ui): replace runtime type guards with lodash-es predicates

* refactor(runtime): migrate typeof checks to lodash-es in core modules

* refactor(ipc): standardize runtime guards with lodash-es

* test(refactor): align runtime guard checks with lodash-es

* docs(agents): add lodash-es runtime guard skill summary
This commit is contained in:
vin authored and GitHub committed 2026-04-12 11:41:56 +08:00
1 parent 0223e8d807
commit bc35b96b5d
33 files changed
+303 -208

No files matched your search

+3 -2
View File
@@ -1,4 +1,5 @@
import modelSpecsJson from './model-specs';
import { isNumber } from 'lodash-es';
type ModelSpec = {
max_output_tokens?: number;
@@ -24,7 +25,7 @@ export function resolveModelAlias(modelId: string): string {
export function getMaxOutputTokens(modelId: string): number {
const resolved = resolveModelAlias(modelId);
const fromSpec = SPECS.models[resolved]?.max_output_tokens;
if (typeof fromSpec === 'number' && Number.isFinite(fromSpec) && fromSpec > 0) {
if (isNumber(fromSpec) && Number.isFinite(fromSpec) && fromSpec > 0) {
return Math.floor(fromSpec);
}
return DEFAULT_MAX_OUTPUT_TOKENS;
@@ -33,7 +34,7 @@ export function getMaxOutputTokens(modelId: string): number {
export function getThinkingBudget(modelId: string): number {
const resolved = resolveModelAlias(modelId);
const fromSpec = SPECS.models[resolved]?.thinking_budget;
if (typeof fromSpec === 'number' && Number.isFinite(fromSpec) && fromSpec >= 0) {
if (isNumber(fromSpec) && Number.isFinite(fromSpec) && fromSpec >= 0) {
return Math.floor(fromSpec);
}
return DEFAULT_THINKING_BUDGET;