Skip to content
English

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

字段结构 ​

字段类型必需说明
fieldstring必需只读。Reply field that carries the alternatives.
minCandidatesnumber | undefined可省略只读。Minimum number of distinct candidates once the envelope is present; defaults to 1.
maxCandidatesnumber必需只读。Maximum number of candidates; must be a safe integer not below the minimum.
errorBreakReason | undefined可省略只读。Rejection wording, either fixed, a pre-built error or a lazy factory.
tagsreadonly string[] | undefined可省略只读。Diagnostic tags attached to every rejection from this contract.

使用示例 ​

接受单一提议或最多三个候选 ​

入门 · 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);
}

相关策略源码 ​

相关定义 ​

接口参考、使用示例与开发指南。