Skip to content
中文

KnowledgePublication ​

KIT · interface · Type contract

Compiled publication workflow.

Import ​

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

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

Definition ​

ts
interface KnowledgePublication<App>

Type parameters ​

Type parameterConstraintDefault type
App——

Field 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.

Member index ​

MemberPurpose
readReturns the current record, with expired candidates already pruned.
proposeAdds a candidate based on revision; fails when the record moved on.
publishPublishes one candidate and removes it from the pending list.
rejectDiscards one candidate without touching the published documents.

Member details ​

read ​

Returns the current record, with expired candidates already pruned.

ts
KnowledgePublication.read(context: OperationContext<App>): Promise<KnowledgePublicationRecord>

Returns the current record, with expired candidates already pruned.

ParameterTypePassingDescription
contextOperationContext<App>Required—
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<KnowledgePublicationRecord>.

Awaited value: KnowledgePublicationRecord.

Return value structure
FieldTypeRequiredDescription
revisionnumberRequiredRead-only. Monotonic record revision; every accepted mutation increments it.
publishedRevisionnumberRequiredRead-only. Revision number of the currently published document set.
documentsreadonly KnowledgeDocument[]RequiredRead-only. Published documents, in catalog order.
candidatesreadonly KnowledgeCandidate[]RequiredRead-only. Pending candidates; expired entries are removed before use.

propose ​

Adds a candidate based on revision; fails when the record moved on.

ts
KnowledgePublication.propose(request: { revision: number; document: KnowledgeDocument; sources: readonly KnowledgeSourceReference[]; }, context: OperationContext<App>): Promise<KnowledgePublicationRecord>

Adds a candidate based on revision; fails when the record moved on.

ParameterTypePassingDescription
request{ revision: number; document: KnowledgeDocument; sources: readonly KnowledgeSourceReference[]; }Required—
contextOperationContext<App>Required—
Fields of request
FieldTypeRequiredDescription
revisionnumberRequiredSee the type definition and usage context.
documentKnowledgeDocumentRequiredSee the type definition and usage context.
sourcesreadonly KnowledgeSourceReference[]RequiredSee the type definition and usage context.
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<KnowledgePublicationRecord>.

Awaited value: KnowledgePublicationRecord.

Return value structure
FieldTypeRequiredDescription
revisionnumberRequiredRead-only. Monotonic record revision; every accepted mutation increments it.
publishedRevisionnumberRequiredRead-only. Revision number of the currently published document set.
documentsreadonly KnowledgeDocument[]RequiredRead-only. Published documents, in catalog order.
candidatesreadonly KnowledgeCandidate[]RequiredRead-only. Pending candidates; expired entries are removed before use.

publish ​

Publishes one candidate and removes it from the pending list.

ts
KnowledgePublication.publish(request: { revision: number; candidateId: string; }, context: OperationContext<App>): Promise<KnowledgePublicationRecord>

Publishes one candidate and removes it from the pending list.

ParameterTypePassingDescription
request{ revision: number; candidateId: string; }Required—
contextOperationContext<App>Required—
Fields of request
FieldTypeRequiredDescription
revisionnumberRequiredSee the type definition and usage context.
candidateIdstringRequiredSee the type definition and usage context.
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<KnowledgePublicationRecord>.

Awaited value: KnowledgePublicationRecord.

Return value structure
FieldTypeRequiredDescription
revisionnumberRequiredRead-only. Monotonic record revision; every accepted mutation increments it.
publishedRevisionnumberRequiredRead-only. Revision number of the currently published document set.
documentsreadonly KnowledgeDocument[]RequiredRead-only. Published documents, in catalog order.
candidatesreadonly KnowledgeCandidate[]RequiredRead-only. Pending candidates; expired entries are removed before use.

reject ​

Discards one candidate without touching the published documents.

ts
KnowledgePublication.reject(request: { revision: number; candidateId: string; }, context: OperationContext<App>): Promise<KnowledgePublicationRecord>

Discards one candidate without touching the published documents.

ParameterTypePassingDescription
request{ revision: number; candidateId: string; }Required—
contextOperationContext<App>Required—
Fields of request
FieldTypeRequiredDescription
revisionnumberRequiredSee the type definition and usage context.
candidateIdstringRequiredSee the type definition and usage context.
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<KnowledgePublicationRecord>.

Awaited value: KnowledgePublicationRecord.

Return value structure
FieldTypeRequiredDescription
revisionnumberRequiredRead-only. Monotonic record revision; every accepted mutation increments it.
publishedRevisionnumberRequiredRead-only. Revision number of the currently published document set.
documentsreadonly KnowledgeDocument[]RequiredRead-only. Published documents, in catalog order.
candidatesreadonly KnowledgeCandidate[]RequiredRead-only. Pending candidates; expired entries are removed before use.

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.