Skip to content
English

defineEvidenceProjection ​

KIT · function · 运行时值

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.

导入 ​

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

其他公开入口:@jangts/agent-core、@jangts/agent-core/types、@jangts/agent-core/kits/evidence、@jangts/agent-core/kits。

定义 ​

泛型参数 ​

类型参数约束默认类型
Observation——
Source——

调用 ​

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.

类型参数约束默认类型
Observation——
Source——
参数类型传递说明
definitionEvidenceProjectionDefinition<Observation, Source>必需—
definition 的字段
字段类型必需说明
providersReadonly<Record<string, EvidenceProjectionProvider<Observation, Source>>>必需只读。One provider per tool id; observations without a provider pass through unchanged.
sourceId(source: Source) => string必需只读。Stable citation id for a source.
toolId((observation: Observation) => string) | undefined可省略只读。Selects the tool id of an observation; defaults to its toolId (or legacy tool) field.

返回: Readonly<{ project({ observations, sourceIds, }: { observations: Observation[]; sourceIds?: readonly string[]; }): Observation[]; }>。

返回值结构
字段类型必需说明
project({ observations, sourceIds, }: { observations: Observation[]; sourceIds?: readonly string[]; }) => Observation[]必需见类型定义及调用场景。

使用示例 ​

检查真实资料是否已读取 ​

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

相同清单返回缺口,再限定审查所用来源 ​

配置 · 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'] }));

相关策略源码 ​

相关定义 ​

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