Issue
CORE · interface · 类型合同
One validation problem, locatable by code and, when available, by field path.
导入
ts
import type { Issue } from '@jangts/agent-core';js
/** @typedef {import('@jangts/agent-core').Issue} Issue */其他公开入口:@jangts/agent-core、@jangts/agent-core/types、@jangts/agent-core/structs。
定义
ts
interface Issue字段结构
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
code | string | 必需 | 只读。Stable machine-readable reason code; the primary key for programmatic handling. |
message | string | 必需 | 只读。Human-readable description; not guaranteed stable for matching. |
path | readonly (string | number)[] | undefined | 可省略 | 只读。Path of the offending field inside the checked value, outermost segment first. |
checkId | string | undefined | 可省略 | 只读。Registered check that produced the issue, when the check belongs to a catalog. |
使用示例
- 尝试预算与错误归属:将尝试次数、数据无效和流程合同错误分别表达,不把所有失败都转成成功正文。
只给两次业务尝试
入门 · Node.js
ts
import { AttemptBudget } from '@jangts/agent-core/engine';
const attempts = new AttemptBudget(2);
while (attempts.take()) console.log('attempt', attempts.used);
console.log(attempts.available); // falsejs
import { AttemptBudget } from '@jangts/agent-core/engine';
const attempts = new AttemptBudget(2);
while (attempts.take())
console.log('attempt', attempts.used);
console.log(attempts.available); // false明确额度不足与数据无效
配置 · Node.js
ts
import { BudgetError, ValidationError, getErrorInfo } from '@jangts/agent-core';
function requireAnswer(answer: string) {
if (!answer.trim()) throw new ValidationError([{ code: 'ANSWER_EMPTY', message: '回答不能为空' }]);
return answer;
}
try { requireAnswer(''); }
catch (error) { console.log(getErrorInfo(error)); }
const exhausted = new BudgetError('本次业务的尝试额度已用尽');
console.log(getErrorInfo(exhausted));js
import { BudgetError, ValidationError, getErrorInfo } from '@jangts/agent-core';
function requireAnswer(answer) {
if (!answer.trim())
throw new ValidationError([{ code: 'ANSWER_EMPTY', message: '回答不能为空' }]);
return answer;
}
try {
requireAnswer('');
}
catch (error) {
console.log(getErrorInfo(error));
}
const exhausted = new BudgetError('本次业务的尝试额度已用尽');
console.log(getErrorInfo(exhausted));