Skip to content
中文

ReflectionSource ​

KIT · interface · Type contract

App-owned evidence source, including its own authorization.

Import ​

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

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

Definition ​

ts
interface ReflectionSource<App>

Type parameters ​

Type parameterConstraintDefault type
App——

Field structure ​

FieldTypeRequiredDescription
idstringRequiredRead-only. See the type definition and usage context.
descriptionstringRequiredRead-only. See the type definition and usage context.
authorize(query: ReflectionQuery, context: OperationContext<App>) => MaybePromise<void>RequiredGuards one query; runs before any evidence is read.
query(query: ReflectionQuery, context: OperationContext<App>) => Promise<ReflectionPage>RequiredReturns one page; an invalid page shape aborts the reflection.

Member index ​

MemberPurpose
authorizeGuards one query; runs before any evidence is read.
queryReturns one page; an invalid page shape aborts the reflection.

Member details ​

authorize ​

Guards one query; runs before any evidence is read.

ts
ReflectionSource.authorize(query: ReflectionQuery, context: OperationContext<App>): MaybePromise<void>

Guards one query; runs before any evidence is read.

ParameterTypePassingDescription
queryReflectionQueryRequired—
contextOperationContext<App>Required—
Fields of query
FieldTypeRequiredDescription
runstring | undefinedOptionalRead-only. Run to inspect; omitted means the App chooses the scope.
typesreadonly string[] | undefinedOptionalRead-only. Evidence types to include; omitted means all types.
cursorstring | undefinedOptionalRead-only. Opaque continuation cursor from a previous page.
limitnumberRequiredRead-only. Maximum items requested; at least 1, clamped to the remaining evidence budget.
Fields of context
FieldTypeRequiredDescription
appunknown extends App ? App : Readonly<App>RequiredRead-only. See the type definition and usage context.
loggerSubFlowLog | undefinedOptionalRead-only. Explicit optional recorder for this operation; never inferred from diagnostics.
signalAbortSignalRequiredRead-only. Non-optional cancellation signal; never undefined once execution has started.
diagnosticsDiagnosticContext | undefinedOptionalRead-only. Diagnostic scope of the enclosing call, when recording is enabled.

Returns: MaybePromise<void>.

Awaited value: void.

query ​

Returns one page; an invalid page shape aborts the reflection.

ts
ReflectionSource.query(query: ReflectionQuery, context: OperationContext<App>): Promise<ReflectionPage>

Returns one page; an invalid page shape aborts the reflection.

ParameterTypePassingDescription
queryReflectionQueryRequired—
contextOperationContext<App>Required—
Fields of query
FieldTypeRequiredDescription
runstring | undefinedOptionalRead-only. Run to inspect; omitted means the App chooses the scope.
typesreadonly string[] | undefinedOptionalRead-only. Evidence types to include; omitted means all types.
cursorstring | undefinedOptionalRead-only. Opaque continuation cursor from a previous page.
limitnumberRequiredRead-only. Maximum items requested; at least 1, clamped to the remaining evidence budget.
Fields of context
FieldTypeRequiredDescription
appunknown extends App ? App : Readonly<App>RequiredRead-only. See the type definition and usage context.
loggerSubFlowLog | undefinedOptionalRead-only. Explicit optional recorder for this operation; never inferred from diagnostics.
signalAbortSignalRequiredRead-only. Non-optional cancellation signal; never undefined once execution has started.
diagnosticsDiagnosticContext | undefinedOptionalRead-only. Diagnostic scope of the enclosing call, when recording is enabled.

Returns: Promise<ReflectionPage>.

Awaited value: ReflectionPage.

Return value structure
FieldTypeRequiredDescription
itemsreadonly ReflectionEvidence[]RequiredRead-only. Items in source order.
cursorstring | undefinedOptionalRead-only. Continuation cursor; absent when the source has no further items.
coverage{ readonly consistency: "best-effort" | "snapshot"; readonly complete: boolean | null; readonly gaps: readonly string[]; }RequiredRead-only. See the type definition and usage context.

Examples ​

Bind the reflection model, evidence source, and authorization ​

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

Build the same kind of evidence source from a log reader ​

Configuration · Node.js

The reader's directory scope, shutdown, and retention are managed by the App. The adapted source can be passed into the same 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 });
}

API reference, usage examples and developer guides.