Skip to content
中文

CandidateSelectionDefinition ​

KIT · interface · Type contract

Declares the alternative-proposal envelope.

A value without the declared field is treated as a single implicit candidate.

Import ​

ts
import type { CandidateSelectionDefinition } from '@jangts/agent-core/kits/candidates';
js
/** @typedef {import('@jangts/agent-core/kits/candidates').CandidateSelectionDefinition} CandidateSelectionDefinition */

Other public entry points:@jangts/agent-core, @jangts/agent-core/types, @jangts/agent-core/structs, @jangts/agent-core/kits/candidates, @jangts/agent-core/kits.

Definition ​

ts
interface CandidateSelectionDefinition

Field structure ​

FieldTypeRequiredDescription
fieldstringRequiredRead-only. Reply field that carries the alternatives.
minCandidatesnumber | undefinedOptionalRead-only. Minimum number of distinct candidates once the envelope is present; defaults to 1.
maxCandidatesnumberRequiredRead-only. Maximum number of candidates; must be a safe integer not below the minimum.
errorBreakReason | undefinedOptionalRead-only. Rejection wording, either fixed, a pre-built error or a lazy factory.
tagsreadonly string[] | undefinedOptionalRead-only. Diagnostic tags attached to every rejection from this contract.

Examples ​

Accept a single proposal or up to three candidates ​

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

Add a lower bound and an application-stage constraint to the same parse ​

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

API reference, usage examples and developer guides.