Skip to content
English

ReflectionLogReader ​

KIT · interface · 类型合同

Structural port: the App supplies its own FileLogReader, trusted scope and current authorization.

导入 ​

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

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

定义 ​

ts
interface ReflectionLogReader

字段结构 ​

字段类型必需说明
listRuns(query: { traceId?: string; cursor?: string; limit?: number; signal?: AbortSignal; }) => Promise<Page<{ path: string; manifest: Readonly<Record<string, unknown>>; }>>必需List runs the caller may inspect.
readEvents(query: { run: string; sources?: readonly ("app" | "core" | "client")[]; types?: readonly string[]; cursor?: string; limit?: number; signal?: AbortSignal; }) => Promise<Page<Record<string, unknown>>>必需Read the events of one run.

成员目录 ​

成员用途
listRunsList runs the caller may inspect.
readEventsRead the events of one run.

成员详情 ​

listRuns ​

List runs the caller may inspect.

ts
ReflectionLogReader.listRuns(query: { traceId?: string; cursor?: string; limit?: number; signal?: AbortSignal; }): Promise<Page<{ path: string; manifest: Readonly<Record<string, unknown>>; }>>

List runs the caller may inspect.

参数类型传递说明
query{ traceId?: string; cursor?: string; limit?: number; signal?: AbortSignal; }必需—
query 的字段
字段类型必需说明
traceIdstring | undefined可省略见类型定义及调用场景。
cursorstring | undefined可省略见类型定义及调用场景。
limitnumber | undefined可省略见类型定义及调用场景。
signalAbortSignal | undefined可省略见类型定义及调用场景。

返回: Promise<Page<{ path: string; manifest: Readonly<Record<string, unknown>>; }>>。

等待后的值: Page<{ path: string; manifest: Readonly<Record<string, unknown>>; }>。

返回值结构
字段类型必需说明
items{ path: string; manifest: Readonly<Record<string, unknown>>; }[]必需见类型定义及调用场景。
statusstring必需见类型定义及调用场景。
cursorstring | undefined可省略见类型定义及调用场景。
issues{ code: string; }[]必需见类型定义及调用场景。
issuesOmittednumber必需见类型定义及调用场景。
coverage{ exhausted: boolean; captureIncomplete?: boolean; }必需见类型定义及调用场景。

readEvents ​

Read the events of one run.

ts
ReflectionLogReader.readEvents(query: { run: string; sources?: readonly ("app" | "core" | "client")[]; types?: readonly string[]; cursor?: string; limit?: number; signal?: AbortSignal; }): Promise<Page<Record<string, unknown>>>

Read the events of one run.

参数类型传递说明
query{ run: string; sources?: readonly ("app" | "core" | "client")[]; types?: readonly string[]; cursor?: string; limit?: number; signal?: AbortSignal; }必需—
query 的字段
字段类型必需说明
runstring必需见类型定义及调用场景。
sourcesreadonly ("app" | "core" | "client")[] | undefined可省略见类型定义及调用场景。
typesreadonly string[] | undefined可省略见类型定义及调用场景。
cursorstring | undefined可省略见类型定义及调用场景。
limitnumber | undefined可省略见类型定义及调用场景。
signalAbortSignal | undefined可省略见类型定义及调用场景。

返回: Promise<Page<Record<string, unknown>>>。

等待后的值: Page<Record<string, unknown>>。

返回值结构
字段类型必需说明
itemsRecord<string, unknown>[]必需见类型定义及调用场景。
statusstring必需见类型定义及调用场景。
cursorstring | undefined可省略见类型定义及调用场景。
issues{ code: string; }[]必需见类型定义及调用场景。
issuesOmittednumber必需见类型定义及调用场景。
coverage{ exhausted: boolean; captureIncomplete?: boolean; }必需见类型定义及调用场景。

使用示例 ​

绑定复盘模型、证据源和授权 ​

入门 · Node.js

ts
import { defineReflection } from '@jangts/agent-core/kits/reflection';
import type { ReflectionSource } from '@jangts/agent-core/kits/reflection';
import type { ModelRunner, OperationContext } from '@jangts/agent-core';

export function review<App>(model: ModelRunner, source: ReflectionSource<App>,
  authorize: (question: string, context: OperationContext<App>) => Promise<void>) {
  return defineReflection({ model, source, authorize,
    maxCalls: 4, reserveCalls: 1, maxPages: 4, maxEvents: 64, maxEvidenceChars: 12000 });
}
js
import { defineReflection } from '@jangts/agent-core/kits/reflection';
export function review(model, source, authorize) {
    return defineReflection({ model, source, authorize,
        maxCalls: 4, reserveCalls: 1, maxPages: 4, maxEvents: 64, maxEvidenceChars: 12000 });
}

从日志 reader 构造同一种证据源 ​

配置 · Node.js

reader 的目录范围、关闭与保留期由 App 管理。适配后的 source 可传入同一个 defineReflection。

ts
import { defineReflectionLogSource } from '@jangts/agent-core/kits/reflection';
import type { ReflectionLogReader } from '@jangts/agent-core/kits/reflection';
import type { OperationContext } from '@jangts/agent-core';

export function logSource<App>(reader: ReflectionLogReader, traceId: string,
  authorize: (context: OperationContext<App>) => Promise<void>) {
  return defineReflectionLogSource({ reader, traceId, id: 'authorized-history', authorize });
}
js
import { defineReflectionLogSource } from '@jangts/agent-core/kits/reflection';
export function logSource(reader, traceId, authorize) {
    return defineReflectionLogSource({ reader, traceId, id: 'authorized-history', authorize });
}

相关策略源码 ​

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