Knowledge candidates: compilation checks and explicit publication
Candidate preparation and publication reuse the Knowledge compiler, and the real store commits official documents through CAS.
propose checks the complete replaced document set and writes only the candidate. publish re-verifies authorization, sources, validity period, and publishedRevision, then atomically replaces the official set. reject deletes the candidate.
store.revision coordinates all writes, and publishedRevision marks changes to the official set. When body text or metadata changes, the document needs a new revision. Ordinary knowledge reads use documents, and candidates do not enter the fact catalog.
Progressive examples for the same business case
Bind document storage and source authorization
Beginner · Node.js
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 });
}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.
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);
}export async function publish(publication, candidateId, context) {
const record = await publication.read(context);
return publication.publish({ revision: record.revision, candidateId }, context);
}