RecoveryResult
KIT · type · Type contract
Outcome of one recovery handler, or of the whole chain.
Import
ts
import type { RecoveryResult } from '@jangts/agent-core/kits/policies';js
/** @typedef {import('@jangts/agent-core/kits/policies').RecoveryResult} RecoveryResult */Other public entry points:@jangts/agent-core, @jangts/agent-core/types, @jangts/agent-core/structs, @jangts/agent-core/kits/policies, @jangts/agent-core/kits.
Definition
Type: RecoveryResult<Value>
Type parameters
| Type parameter | Constraint | Default type |
|---|---|---|
Value | — | — |
Union branch structure
Optional shapes of RecoveryResult: choose one shape; required fields for each branch are listed separately.
Branch 1
| Field | Type | Required | Description |
|---|---|---|---|
handled | false | Required | Read-only. See the type definition and usage context. |
Branch 2
| Field | Type | Required | Description |
|---|---|---|---|
handled | true | Required | Read-only. See the type definition and usage context. |
value | Value | Required | Read-only. See the type definition and usage context. |
Examples
- Answering Flow: item-by-item generation, review, and local repair: Preserve coverage relationships over a split question batch and repair failing items without regenerating the ones that passed.
- Policies: all matches and the first recovery: A policy set collects every matching reason; a recovery chain selects the first explicitly handled result in order.
First handle one question that has a source
Beginner · Node.js
The offline example uses already-read body text directly to show the flow contract; when switching to model generation, the same generate port still applies.
ts
import { Answering } from '@jangts/agent-core/kits/answering';
const flow = Answering.defineAnswerFlow<{ source: string }, string, {}>({
maxItems: 4, maxRepairs: 0, reviewPolicy: 'off', canInvoke: () => true,
async generate({ items }) { return new Map(items.map(item => [item.id, item.data.source])); },
check: ({ value }) => ({ status: value.trim() ? 'passed' : 'failed', issues: [] }),
fallback: () => ({ handled: false }),
});
const result = await flow.run({ inputIds: ['question-1'], items: [{ id: 'explain', inputIds: ['question-1'], sourceStatus: 'ready', data: { source: '普通对象可以实现节点合同。' } }] }, { app: {}, signal: new AbortController().signal });
console.log(result[0].status, result[0].value);js
import { Answering } from '@jangts/agent-core/kits/answering';
const flow = Answering.defineAnswerFlow({
maxItems: 4, maxRepairs: 0, reviewPolicy: 'off', canInvoke: () => true,
async generate({ items }) { return new Map(items.map(item => [item.id, item.data.source])); },
check: ({ value }) => ({ status: value.trim() ? 'passed' : 'failed', issues: [] }),
fallback: () => ({ handled: false }),
});
const result = await flow.run({ inputIds: ['question-1'], items: [{ id: 'explain', inputIds: ['question-1'], sourceStatus: 'ready', data: { source: '普通对象可以实现节点合同。' } }] }, { app: {}, signal: new AbortController().signal });
console.log(result[0].status, result[0].value);Keep run unchanged and add review plus one local repair
Configuration · Node.js
The example triggers one real local repair with an empty draft; production review should rely on real evidence instead of substituting string equality for semantic review.
ts
import { Answering } from '@jangts/agent-core/kits/answering';
const flow = Answering.defineAnswerFlow<{ source: string }, string, {}>({
maxItems: 4, maxRepairs: 1, reviewPolicy: 'required', canInvoke: () => true,
async generate({ items, repairs }) { return new Map(items.map(item => [item.id, repairs?.has(item.id) ? item.data.source : ''])); },
check: ({ value }) => ({ status: value.trim() ? 'passed' : 'failed', issues: value.trim() ? [] : [{ code: 'EMPTY', message: '需要非空回答' }] }),
async review({ items }) { return new Map(items.map(({ item, value }) => [item.id, { status: value === item.data.source ? 'passed' as const : 'failed' as const, issues: [] }])); },
fallback: () => ({ handled: true, value: '当前资料不足,暂时无法回答。' }),
});
const result = await flow.run({ inputIds: ['question-1'], items: [{ id: 'explain', inputIds: ['question-1'], sourceStatus: 'ready', data: { source: '普通对象可以实现节点合同。' } }] }, { app: {}, signal: new AbortController().signal });
console.log(result[0].status, result[0].checks);js
import { Answering } from '@jangts/agent-core/kits/answering';
const flow = Answering.defineAnswerFlow({
maxItems: 4, maxRepairs: 1, reviewPolicy: 'required', canInvoke: () => true,
async generate({ items, repairs }) { return new Map(items.map(item => [item.id, repairs?.has(item.id) ? item.data.source : ''])); },
check: ({ value }) => ({ status: value.trim() ? 'passed' : 'failed', issues: value.trim() ? [] : [{ code: 'EMPTY', message: '需要非空回答' }] }),
async review({ items }) { return new Map(items.map(({ item, value }) => [item.id, { status: value === item.data.source ? 'passed' : 'failed', issues: [] }])); },
fallback: () => ({ handled: true, value: '当前资料不足,暂时无法回答。' }),
});
const result = await flow.run({ inputIds: ['question-1'], items: [{ id: 'explain', inputIds: ['question-1'], sourceStatus: 'ready', data: { source: '普通对象可以实现节点合同。' } }] }, { app: {}, signal: new AbortController().signal });
console.log(result[0].status, result[0].checks);