Skip to content
中文

KnowledgePublicationStore ​

KIT · interface · Type contract

Single-writer store for the publication record.

Import ​

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

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

Definition ​

ts
interface KnowledgePublicationStore

Field structure ​

FieldTypeRequiredDescription
load() => Promise<KnowledgePublicationRecord>RequiredReturns the current record; it must always be readable.
compareAndSwap(expectedRevision: number, next: KnowledgePublicationRecord) => Promise<boolean>RequiredAtomically replaces the record when the stored revision still equals expectedRevision.

Member index ​

MemberPurpose
loadReturns the current record; it must always be readable.
compareAndSwapAtomically replaces the record when the stored revision still equals expectedRevision.

Member details ​

load ​

Returns the current record; it must always be readable.

ts
KnowledgePublicationStore.load(): Promise<KnowledgePublicationRecord>

Returns the current record; it must always be readable.

No call parameters.

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.

compareAndSwap ​

Atomically replaces the record when the stored revision still equals expectedRevision.

ts
KnowledgePublicationStore.compareAndSwap(expectedRevision: number, next: KnowledgePublicationRecord): Promise<boolean>

Atomically replaces the record when the stored revision still equals expectedRevision.

ParameterTypePassingDescription
expectedRevisionnumberRequired—
nextKnowledgePublicationRecordRequired—
Fields of next
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.

Returns: Promise<boolean>.

Awaited value: boolean.

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.