Skip to content
中文

defineEvidenceProjection ​

KIT · function · Runtime value

Compile a projection that keeps only the sources a caller asked to see.

No selection retains the complete evidence; a selection narrows registered source-bearing results. Observations whose tool has no provider pass through untouched, so the projection can only ever remove sources it knows how to name.

Import ​

ts
import { defineEvidenceProjection } from '@jangts/agent-core/kits/evidence';
js
import { defineEvidenceProjection } from '@jangts/agent-core/kits/evidence';

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

Definition ​

Type parameters ​

Type parameterConstraintDefault type
Observation——
Source——

Call ​

ts
defineEvidenceProjection<Observation, Source>(definition: EvidenceProjectionDefinition<Observation, Source>): Readonly<{ project({ observations, sourceIds, }: { observations: Observation[]; sourceIds?: readonly string[]; }): Observation[]; }>

Compile a projection that keeps only the sources a caller asked to see.

No selection retains the complete evidence; a selection narrows registered source-bearing results. Observations whose tool has no provider pass through untouched, so the projection can only ever remove sources it knows how to name.

Type parameterConstraintDefault type
Observation——
Source——
ParameterTypePassingDescription
definitionEvidenceProjectionDefinition<Observation, Source>Required—
Fields of definition
FieldTypeRequiredDescription
providersReadonly<Record<string, EvidenceProjectionProvider<Observation, Source>>>RequiredRead-only. One provider per tool id; observations without a provider pass through unchanged.
sourceId(source: Source) => stringRequiredRead-only. Stable citation id for a source.
toolId((observation: Observation) => string) | undefinedOptionalRead-only. Selects the tool id of an observation; defaults to its toolId (or legacy tool) field.

Returns: Readonly<{ project({ observations, sourceIds, }: { observations: Observation[]; sourceIds?: readonly string[]; }): Observation[]; }>.

Return value structure
FieldTypeRequiredDescription
project({ observations, sourceIds, }: { observations: Observation[]; sourceIds?: readonly string[]; }) => Observation[]RequiredSee the type definition and usage context.

Examples ​

Check whether real material has been read ​

Beginner · Node.js

ts
import { Evidence } from '@jangts/agent-core/kits/evidence';
type Observation = { sourceId: string; read: boolean };
type Requirement = { id: string; kind: 'source-read'; sourceId: string };
const checklist = Evidence.defineEvidenceChecklist<Observation, Requirement>([
  { kind: 'source-read', description: '资料读取已成功', isSatisfied: (seen, need) => seen.read && seen.sourceId === need.sourceId },
]);
console.log(checklist.isComplete({ observations: [{ sourceId: 'manual', read: true }], requirements: [{ id: 'need-manual', kind: 'source-read', sourceId: 'manual' }] }));
js
import { Evidence } from '@jangts/agent-core/kits/evidence';
const checklist = Evidence.defineEvidenceChecklist([
    { kind: 'source-read', description: '资料读取已成功', isSatisfied: (seen, need) => seen.read && seen.sourceId === need.sourceId },
]);
console.log(checklist.isComplete({ observations: [{ sourceId: 'manual', read: true }], requirements: [{ id: 'need-manual', kind: 'source-read', sourceId: 'manual' }] }));

Return gaps from the same checklist, then limit the sources used for review ​

Configuration · Node.js

ts
import { Evidence } from '@jangts/agent-core/kits/evidence';
type Observation = { sourceId: string; read: boolean };
type Requirement = { id: string; kind: 'source-read'; sourceId: string };
const checklist = Evidence.defineEvidenceChecklist<Observation, Requirement>([
  { kind: 'source-read', description: '资料读取已成功', isSatisfied: (seen, need) => seen.read && seen.sourceId === need.sourceId },
]);
console.log(checklist.missing({ observations: [], requirements: [{ id: 'need-manual', kind: 'source-read', sourceId: 'manual' }] }));
type ToolObservation = { toolId: string; sources: { id: string; text: string }[] };
const projection = Evidence.defineEvidenceProjection<ToolObservation, { id: string; text: string }>({
  sourceId: source => source.id,
  providers: { search: { sources: row => row.sources, withSources: (row, sources) => ({ ...row, sources }) } },
});
console.log(projection.project({ observations: [{ toolId: 'search', sources: [{ id: 'manual', text: '使用指南' }, { id: 'faq', text: '常见问题' }] }], sourceIds: ['manual'] }));
js
import { Evidence } from '@jangts/agent-core/kits/evidence';
const checklist = Evidence.defineEvidenceChecklist([
    { kind: 'source-read', description: '资料读取已成功', isSatisfied: (seen, need) => seen.read && seen.sourceId === need.sourceId },
]);
console.log(checklist.missing({ observations: [], requirements: [{ id: 'need-manual', kind: 'source-read', sourceId: 'manual' }] }));
const projection = Evidence.defineEvidenceProjection({
    sourceId: source => source.id,
    providers: { search: { sources: row => row.sources, withSources: (row, sources) => ({ ...row, sources }) } },
});
console.log(projection.project({ observations: [{ toolId: 'search', sources: [{ id: 'manual', text: '使用指南' }, { id: 'faq', text: '常见问题' }] }], sourceIds: ['manual'] }));

API reference, usage examples and developer guides.