refactor: zod tree-shaking; better error handling in agent steps

This commit is contained in:
Simon
2026-02-09 17:49:10 +08:00
parent 6fdb8d03f2
commit 6f0ff1fd33
12 changed files with 82 additions and 67 deletions

View File

@@ -1,3 +1,5 @@
import chalk from 'chalk'
export { normalizeResponse } from './autoFixer'
/**
@@ -85,3 +87,19 @@ export function uid() {
ids.push(id)
return id
}
/**
* Simple assertion function that throws an error if the condition is falsy
* @param condition - The condition to assert
* @param message - Optional error message
* @throws Error if condition is falsy
*/
export function assert(condition: unknown, message?: string, silent?: boolean): asserts condition {
if (!condition) {
const errorMessage = message ?? 'Assertion failed'
if (!silent) console.error(chalk.red(`❌ assert: ${errorMessage}`))
throw new Error(errorMessage)
}
}