CandidateSelectionDefinition
KIT · interface · 类型合同
Declares the alternative-proposal envelope.
A value without the declared field is treated as a single implicit candidate.
导入
ts
import type { CandidateSelectionDefinition } from '@jangts/agent-core/kits/candidates';js
/** @typedef {import('@jangts/agent-core/kits/candidates').CandidateSelectionDefinition} CandidateSelectionDefinition */其他公开入口:@jangts/agent-core、@jangts/agent-core/types、@jangts/agent-core/structs、@jangts/agent-core/kits/candidates、@jangts/agent-core/kits。
定义
ts
interface CandidateSelectionDefinition字段结构
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
field | string | 必需 | 只读。Reply field that carries the alternatives. |
minCandidates | number | undefined | 可省略 | 只读。Minimum number of distinct candidates once the envelope is present; defaults to 1. |
maxCandidates | number | 必需 | 只读。Maximum number of candidates; must be a safe integer not below the minimum. |
error | BreakReason | undefined | 可省略 | 只读。Rejection wording, either fixed, a pre-built error or a lazy factory. |
tags | readonly string[] | undefined | 可省略 | 只读。Diagnostic tags attached to every rejection from this contract. |
使用示例
- Candidates:有界候选封套:同一结果可以是单项提议或候选清单;候选权限与数量由应用控制。
接受单一提议或最多三个候选
入门 · Node.js
ts
import { Candidates } from '@jangts/agent-core/kits/candidates';
const selection = Candidates.defineCandidateSelection({ field: 'candidates', maxCandidates: 3 });
console.log(selection.parse({ value: { action: 'read' }, allowed: true }));
console.log(selection.parse({ value: { candidates: [{ action: 'read' }, { action: 'reply' }] }, allowed: true }));js
import { Candidates } from '@jangts/agent-core/kits/candidates';
const selection = Candidates.defineCandidateSelection({ field: 'candidates', maxCandidates: 3 });
console.log(selection.parse({ value: { action: 'read' }, allowed: true }));
console.log(selection.parse({ value: { candidates: [{ action: 'read' }, { action: 'reply' }] }, allowed: true }));相同 parse 增加下界和应用阶段约束
配置 · Node.js
ts
import { Candidates } from '@jangts/agent-core/kits/candidates';
const selection = Candidates.defineCandidateSelection({ field: 'candidates', minCandidates: 2, maxCandidates: 3, error: '当前阶段不接受这份候选' });
const taskAccepted = true;
try {
selection.parse({ value: { candidates: [{ action: 'read' }, { action: 'reply' }] }, allowed: !taskAccepted });
} catch (error) { console.log((error as Error).message); }js
import { Candidates } from '@jangts/agent-core/kits/candidates';
const selection = Candidates.defineCandidateSelection({ field: 'candidates', minCandidates: 2, maxCandidates: 3, error: '当前阶段不接受这份候选' });
const taskAccepted = true;
try {
selection.parse({ value: { candidates: [{ action: 'read' }, { action: 'reply' }] }, allowed: !taskAccepted });
}
catch (error) {
console.log(error.message);
}