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
import { defineKnowledgePublication } from '@jangts/agent-core/kits/knowledge';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 parameter | Constraint | Default type |
|---|---|---|
App | — | — |
Call
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 parameter | Constraint | Default type |
|---|---|---|
App | — | — |
| Parameter | Type | Passing | Description |
|---|---|---|---|
options | KnowledgePublicationOptions<App> | Required | — |
Fields of options
| Field | Type | Required | Description |
|---|---|---|---|
store | KnowledgePublicationStore | Required | Read-only. See the type definition and usage context. |
requiredReads | readonly KnowledgeRead[] | undefined | Optional | Read-only. Reads that must succeed against every compiled document set, proving sections still exist. |
maxReadChars | number | undefined | Optional | Read-only. Per-read character budget applied by the catalog compiler. |
maxCandidates | number | undefined | Optional | Read-only. Maximum pending candidates retained; defaults to 32 and must be a positive integer. |
candidateRetentionMs | number | undefined | Optional | Read-only. Candidate retention window; defaults to seven days. |
now | (() => number) | undefined | Optional | Read-only. Clock override for timestamps and expiry; defaults to Date.now. |
authorize | (operation: (typeof knowledgePublicationOperations)[number], context: OperationContext<App>) => MaybePromise<void> | Required | Guards one operation before any read or write. |
verifySources | (sources: readonly KnowledgeSourceReference[], context: OperationContext<App>) => MaybePromise<void> | Required | Validate real provenance/revisions/visibility. A model's source list is not a grant. |
Returns: KnowledgePublication<App>.
Return value structure
| Field | Type | Required | Description |
|---|---|---|---|
read | (context: OperationContext<App>) => Promise<KnowledgePublicationRecord> | Required | Returns the current record, with expired candidates already pruned. |
propose | (request: { revision: number; document: KnowledgeDocument; sources: readonly KnowledgeSourceReference[]; }, context: OperationContext<App>) => Promise<KnowledgePublicationRecord> | Required | Adds a candidate based on revision; fails when the record moved on. |
publish | (request: { revision: number; candidateId: string; }, context: OperationContext<App>) => Promise<KnowledgePublicationRecord> | Required | Publishes one candidate and removes it from the pending list. |
reject | (request: { revision: number; candidateId: string; }, context: OperationContext<App>) => Promise<KnowledgePublicationRecord> | Required | Discards one candidate without touching the published documents. |
Examples
- Knowledge candidates: compilation checks and explicit publication: Candidate preparation and publication reuse the Knowledge compiler, and the real store commits official documents through CAS.
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);
}