Skip to content
中文

defineKnowledgePublication ​

KIT · function · Runtime value

Compile a publication lifecycle over one App-owned atomic record.

Candidate preparation and publication share the same compiler and an App-owned atomic revision. propose compiles and validates a candidate but leaves published documents alone; publish re-verifies sources and the base revision before swapping, so a stale candidate can never overwrite newer content.

Import ​

ts
import { defineKnowledgePublication } from '@jangts/agent-core/kits/knowledge';
js
import { defineKnowledgePublication } from '@jangts/agent-core/kits/knowledge';

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

Definition ​

Type parameters ​

Type parameterConstraintDefault type
App——

Call ​

ts
defineKnowledgePublication<App>(options: KnowledgePublicationOptions<App>): KnowledgePublication<App>

Compile a publication lifecycle over one App-owned atomic record.

Candidate preparation and publication share the same compiler and an App-owned atomic revision. propose compiles and validates a candidate but leaves published documents alone; publish re-verifies sources and the base revision before swapping, so a stale candidate can never overwrite newer content.

Type parameterConstraintDefault type
App——
ParameterTypePassingDescription
optionsKnowledgePublicationOptions<App>Required—
Fields of options
FieldTypeRequiredDescription
storeKnowledgePublicationStoreRequiredRead-only. See the type definition and usage context.
requiredReadsreadonly KnowledgeRead[] | undefinedOptionalRead-only. Reads that must succeed against every compiled document set, proving sections still exist.
maxReadCharsnumber | undefinedOptionalRead-only. Per-read character budget applied by the catalog compiler.
maxCandidatesnumber | undefinedOptionalRead-only. Maximum pending candidates retained; defaults to 32 and must be a positive integer.
candidateRetentionMsnumber | undefinedOptionalRead-only. Candidate retention window; defaults to seven days.
now(() => number) | undefinedOptionalRead-only. Clock override for timestamps and expiry; defaults to Date.now.
authorize(operation: (typeof knowledgePublicationOperations)[number], context: OperationContext<App>) => MaybePromise<void>RequiredGuards one operation before any read or write.
verifySources(sources: readonly KnowledgeSourceReference[], context: OperationContext<App>) => MaybePromise<void>RequiredValidate real provenance/revisions/visibility. A model's source list is not a grant.

Returns: KnowledgePublication<App>.

Return value structure
FieldTypeRequiredDescription
read(context: OperationContext<App>) => Promise<KnowledgePublicationRecord>RequiredReturns the current record, with expired candidates already pruned.
propose(request: { revision: number; document: KnowledgeDocument; sources: readonly KnowledgeSourceReference[]; }, context: OperationContext<App>) => Promise<KnowledgePublicationRecord>RequiredAdds a candidate based on revision; fails when the record moved on.
publish(request: { revision: number; candidateId: string; }, context: OperationContext<App>) => Promise<KnowledgePublicationRecord>RequiredPublishes one candidate and removes it from the pending list.
reject(request: { revision: number; candidateId: string; }, context: OperationContext<App>) => Promise<KnowledgePublicationRecord>RequiredDiscards one candidate without touching the published documents.

Examples ​

Bind document storage and source authorization ​

Beginner · Node.js

ts
import { defineKnowledgePublication } from '@jangts/agent-core/kits/knowledge';
import type { KnowledgePublicationOptions } from '@jangts/agent-core/kits/knowledge';

export function publication<App>(store: KnowledgePublicationOptions<App>['store'],
  authorize: KnowledgePublicationOptions<App>['authorize'],
  verifySources: KnowledgePublicationOptions<App>['verifySources']) {
  return defineKnowledgePublication({ store, authorize, verifySources, maxReadChars: 12000 });
}
js
import { defineKnowledgePublication } from '@jangts/agent-core/kits/knowledge';
export function publication(store, authorize, verifySources) {
    return defineKnowledgePublication({ store, authorize, verifySources, maxReadChars: 12000 });
}

Publish an approved candidate document set ​

Configuration · Node.js

Call this after the App's real approval flow. Source changes, expired candidates, or version conflicts reject the commit.

ts
import type { KnowledgePublication } from '@jangts/agent-core/kits/knowledge';
import type { OperationContext } from '@jangts/agent-core';

export async function publish<App>(publication: KnowledgePublication<App>, candidateId: string,
  context: OperationContext<App>) {
  const record = await publication.read(context);
  return publication.publish({ revision: record.revision, candidateId }, context);
}
js
export async function publish(publication, candidateId, context) {
    const record = await publication.read(context);
    return publication.publish({ revision: record.revision, candidateId }, context);
}

API reference, usage examples and developer guides.