@lssm/example.versioned-knowledge-base 0.0.0-canary-20251213172311
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +23 -0
- package/CHANGELOG.md +9 -0
- package/README.md +24 -0
- package/dist/contracts/index.js +1 -0
- package/dist/contracts/kb.js +1 -0
- package/dist/docs/index.js +1 -0
- package/dist/docs/versioned-knowledge-base.docblock.js +20 -0
- package/dist/entities/index.js +1 -0
- package/dist/entities/models.js +1 -0
- package/dist/events.js +1 -0
- package/dist/example.js +1 -0
- package/dist/feature.js +1 -0
- package/dist/handlers/index.js +1 -0
- package/dist/handlers/memory.handlers.js +1 -0
- package/dist/index.js +1 -0
- package/example.ts +1 -0
- package/package.json +64 -0
- package/src/contracts/index.ts +3 -0
- package/src/contracts/kb.ts +191 -0
- package/src/docs/index.ts +3 -0
- package/src/docs/versioned-knowledge-base.docblock.ts +31 -0
- package/src/entities/index.ts +3 -0
- package/src/entities/models.ts +70 -0
- package/src/events.ts +72 -0
- package/src/example.ts +29 -0
- package/src/feature.ts +35 -0
- package/src/handlers/index.ts +3 -0
- package/src/handlers/memory.handlers.test.ts +79 -0
- package/src/handlers/memory.handlers.ts +206 -0
- package/src/index.ts +15 -0
- package/tsconfig.json +11 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/tsdown.config.js +9 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
$ bun build:bundle && bun build:types
|
|
2
|
+
$ tsdown
|
|
3
|
+
[34mℹ[39m tsdown [2mv0.17.0[22m powered by rolldown [2mv1.0.0-beta.53[22m
|
|
4
|
+
[34mℹ[39m config file: [4m/home/runner/work/contractspec/contractspec/packages/examples/versioned-knowledge-base/tsdown.config.js[24m
|
|
5
|
+
[34mℹ[39m entry: [34msrc/events.ts, src/example.ts, src/feature.ts, src/index.ts, src/contracts/index.ts, src/contracts/kb.ts, src/docs/index.ts, src/docs/versioned-knowledge-base.docblock.ts, src/entities/index.ts, src/entities/models.ts, src/handlers/index.ts, src/handlers/memory.handlers.ts[39m
|
|
6
|
+
[34mℹ[39m target: [34mesnext[39m
|
|
7
|
+
[34mℹ[39m tsconfig: [34mtsconfig.json[39m
|
|
8
|
+
[34mℹ[39m Build start
|
|
9
|
+
[34mℹ[39m [2mdist/[22m[1mcontracts/kb.js[22m [2m4.35 kB[22m [2m│ gzip: 1.33 kB[22m
|
|
10
|
+
[34mℹ[39m [2mdist/[22m[1mhandlers/memory.handlers.js[22m [2m2.16 kB[22m [2m│ gzip: 0.91 kB[22m
|
|
11
|
+
[34mℹ[39m [2mdist/[22m[1mentities/models.js[22m [2m2.13 kB[22m [2m│ gzip: 0.59 kB[22m
|
|
12
|
+
[34mℹ[39m [2mdist/[22m[1mevents.js[22m [2m1.72 kB[22m [2m│ gzip: 0.49 kB[22m
|
|
13
|
+
[34mℹ[39m [2mdist/[22m[1mdocs/versioned-knowledge-base.docblock.js[22m [2m1.28 kB[22m [2m│ gzip: 0.59 kB[22m
|
|
14
|
+
[34mℹ[39m [2mdist/[22m[1mindex.js[22m [2m1.21 kB[22m [2m│ gzip: 0.42 kB[22m
|
|
15
|
+
[34mℹ[39m [2mdist/[22m[1mfeature.js[22m [2m0.81 kB[22m [2m│ gzip: 0.37 kB[22m
|
|
16
|
+
[34mℹ[39m [2mdist/[22m[1mexample.js[22m [2m0.61 kB[22m [2m│ gzip: 0.36 kB[22m
|
|
17
|
+
[34mℹ[39m [2mdist/[22m[1mcontracts/index.js[22m [2m0.33 kB[22m [2m│ gzip: 0.16 kB[22m
|
|
18
|
+
[34mℹ[39m [2mdist/[22m[1mentities/index.js[22m [2m0.24 kB[22m [2m│ gzip: 0.14 kB[22m
|
|
19
|
+
[34mℹ[39m [2mdist/[22m[1mhandlers/index.js[22m [2m0.15 kB[22m [2m│ gzip: 0.10 kB[22m
|
|
20
|
+
[34mℹ[39m [2mdist/[22m[1mdocs/index.js[22m [2m0.05 kB[22m [2m│ gzip: 0.07 kB[22m
|
|
21
|
+
[34mℹ[39m 12 files, total: 15.02 kB
|
|
22
|
+
[32m✔[39m Build complete in [32m66ms[39m
|
|
23
|
+
$ tsc --noEmit
|
package/CHANGELOG.md
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# `@lssm/example.versioned-knowledge-base`
|
|
2
|
+
|
|
3
|
+
Spec-first example demonstrating a **curated, versioned knowledge base**:
|
|
4
|
+
|
|
5
|
+
- Raw **source documents** are immutable and referenced by hash.
|
|
6
|
+
- Curated **rules** are versioned, reviewable, and must cite sources.
|
|
7
|
+
- Published **KB snapshots** contain only **approved** rule versions.
|
|
8
|
+
- Assistant answers reference a **snapshot id** for traceability.
|
|
9
|
+
|
|
10
|
+
## Contracts
|
|
11
|
+
|
|
12
|
+
- `kb.ingestSource(docMeta, fileRef) -> SourceDocument`
|
|
13
|
+
- `kb.upsertRuleVersion(ruleId, content, sourceRefs) -> RuleVersion (draft)`
|
|
14
|
+
- `kb.approveRuleVersion(ruleVersionId, approver) -> RuleVersion (approved)`
|
|
15
|
+
- `kb.publishSnapshot(jurisdiction, asOfDate) -> KBSnapshot`
|
|
16
|
+
- `kb.search(snapshotId, query) -> results (ruleVersionIds + citations)`
|
|
17
|
+
|
|
18
|
+
## Running tests
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
bun test
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{KbApproveRuleVersionContract as e,KbIngestSourceContract as t,KbPublishSnapshotContract as n,KbSearchContract as r,KbUpsertRuleVersionContract as i}from"./kb.js";export{e as KbApproveRuleVersionContract,t as KbIngestSourceContract,n as KbPublishSnapshotContract,r as KbSearchContract,i as KbUpsertRuleVersionContract};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{KBSnapshotModel as e,RuleVersionModel as t,SourceDocumentModel as n,SourceRefModel as r}from"../entities/models.js";import{defineCommand as i,defineQuery as a}from"@lssm/lib.contracts";import{ScalarTypeEnum as o,defineSchemaModel as s}from"@lssm/lib.schema";const c=s({name:`KbIngestSourceInput`,description:`Ingest immutable source metadata referencing a stored file.`,fields:{jurisdiction:{type:o.String_unsecure(),isOptional:!1},authority:{type:o.String_unsecure(),isOptional:!1},title:{type:o.String_unsecure(),isOptional:!1},fetchedAt:{type:o.DateTime(),isOptional:!1},hash:{type:o.String_unsecure(),isOptional:!1},fileId:{type:o.String_unsecure(),isOptional:!1}}}),l=s({name:`KbUpsertRuleVersionInput`,description:`Create a new draft rule version (immutable history).`,fields:{ruleId:{type:o.String_unsecure(),isOptional:!1},content:{type:o.String_unsecure(),isOptional:!1},sourceRefs:{type:r,isArray:!0,isOptional:!1}}}),u=s({name:`KbApproveRuleVersionInput`,description:`Approve a rule version (human verification).`,fields:{ruleVersionId:{type:o.String_unsecure(),isOptional:!1},approver:{type:o.String_unsecure(),isOptional:!1}}}),d=s({name:`KbPublishSnapshotInput`,description:`Publish a snapshot for a jurisdiction as-of a date.`,fields:{jurisdiction:{type:o.String_unsecure(),isOptional:!1},asOfDate:{type:o.DateTime(),isOptional:!1}}}),f=s({name:`KbSearchInput`,description:`Search within a published snapshot.`,fields:{snapshotId:{type:o.String_unsecure(),isOptional:!1},jurisdiction:{type:o.String_unsecure(),isOptional:!1},query:{type:o.String_unsecure(),isOptional:!1}}}),p=s({name:`KbSearchOutput`,description:`Search results constrained to snapshot + jurisdiction.`,fields:{items:{type:s({name:`KbSearchResultItem`,description:`Search result referencing a specific rule version.`,fields:{ruleVersionId:{type:o.String_unsecure(),isOptional:!1},excerpt:{type:o.String_unsecure(),isOptional:!0}}}),isArray:!0,isOptional:!1}}}),m=i({meta:{name:`kb.ingestSource`,version:1,stability:`experimental`,owners:[`examples`],tags:[`knowledge`,`sources`,`ingestion`],description:`Ingest immutable source document metadata.`,goal:`Store traceable source documents for curated KB.`,context:`Called when an admin uploads/records authoritative sources.`},io:{input:c,output:n},policy:{auth:`user`}}),h=i({meta:{name:`kb.upsertRuleVersion`,version:1,stability:`experimental`,owners:[`examples`],tags:[`knowledge`,`rules`,`versioning`],description:`Create a new draft rule version with source references.`,goal:`Propose curated knowledge updates with traceability.`,context:`Automation or curators propose draft rule versions.`},io:{input:l,output:t,errors:{SOURCE_REFS_REQUIRED:{description:`Rule version must cite at least one sourceRef`,http:400,gqlCode:`SOURCE_REFS_REQUIRED`,when:`sourceRefs is empty`},RULE_NOT_FOUND:{description:`Rule does not exist`,http:404,gqlCode:`RULE_NOT_FOUND`,when:`ruleId is unknown`}}},policy:{auth:`user`}}),g=i({meta:{name:`kb.approveRuleVersion`,version:1,stability:`experimental`,owners:[`examples`],tags:[`knowledge`,`rules`,`approval`],description:`Approve a draft rule version.`,goal:`Human verification step before publishing snapshots.`,context:`Curators/experts approve proposed KB changes.`},io:{input:u,output:t},policy:{auth:`user`}}),_=i({meta:{name:`kb.publishSnapshot`,version:1,stability:`experimental`,owners:[`examples`],tags:[`knowledge`,`snapshots`,`publishing`],description:`Publish a KB snapshot for a jurisdiction.`,goal:`Create a stable snapshot that assistant answers can cite.`,context:`Publishing happens after approvals; snapshot is referenced by answers.`},io:{input:d,output:e,errors:{NO_APPROVED_RULES:{description:`No approved rule versions available to publish`,http:409,gqlCode:`NO_APPROVED_RULES`,when:`jurisdiction has zero approved rule versions`}}},policy:{auth:`user`}}),v=a({meta:{name:`kb.search`,version:1,stability:`experimental`,owners:[`examples`],tags:[`knowledge`,`search`,`snapshots`],description:`Search within a published KB snapshot.`,goal:`Provide scoped retrieval for assistant answers.`,context:`Assistant queries curated rules from a specific snapshot.`},io:{input:f,output:p},policy:{auth:`user`}});export{g as KbApproveRuleVersionContract,m as KbIngestSourceContract,_ as KbPublishSnapshotContract,v as KbSearchContract,h as KbUpsertRuleVersionContract};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./versioned-knowledge-base.docblock.js";
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import{registerDocBlocks as e}from"@lssm/lib.contracts/docs";e([{id:`docs.examples.versioned-knowledge-base.goal`,title:`Versioned Knowledge Base — Goal`,summary:`Curated KB with immutable sources, versioned rules, and published snapshots referenced by answers.`,kind:`goal`,visibility:`public`,route:`/docs/examples/versioned-knowledge-base/goal`,tags:[`knowledge`,`versioning`,`snapshots`,`traceability`],body:`## Why it matters
|
|
2
|
+
- Separates raw sources from curated knowledge.
|
|
3
|
+
- Ensures assistant answers cite a published snapshot.
|
|
4
|
+
- Makes change review and safe regeneration possible.
|
|
5
|
+
|
|
6
|
+
## Core invariants
|
|
7
|
+
- Sources are immutable and content-addressed (hash).
|
|
8
|
+
- Rule versions must cite at least one source.
|
|
9
|
+
- Snapshots include only approved rule versions.`},{id:`docs.examples.versioned-knowledge-base.reference`,title:`Versioned Knowledge Base — Reference`,summary:`Entities, contracts, and events for the versioned KB example.`,kind:`reference`,visibility:`public`,route:`/docs/examples/versioned-knowledge-base`,tags:[`knowledge`,`reference`],body:`## Contracts
|
|
10
|
+
- kb.ingestSource
|
|
11
|
+
- kb.upsertRuleVersion
|
|
12
|
+
- kb.approveRuleVersion
|
|
13
|
+
- kb.publishSnapshot
|
|
14
|
+
- kb.search
|
|
15
|
+
|
|
16
|
+
## Events
|
|
17
|
+
- kb.source.ingested
|
|
18
|
+
- kb.ruleVersion.created
|
|
19
|
+
- kb.ruleVersion.approved
|
|
20
|
+
- kb.snapshot.published`}]);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{KBSnapshotModel as e,RuleModel as t,RuleVersionModel as n,SourceDocumentModel as r,SourceRefModel as i}from"./models.js";export{e as KBSnapshotModel,t as RuleModel,n as RuleVersionModel,r as SourceDocumentModel,i as SourceRefModel};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{ScalarTypeEnum as e,defineSchemaModel as t}from"@lssm/lib.schema";const n=t({name:`SourceDocument`,description:`Immutable raw source document metadata referencing a stored file.`,fields:{id:{type:e.String_unsecure(),isOptional:!1},jurisdiction:{type:e.String_unsecure(),isOptional:!1},authority:{type:e.String_unsecure(),isOptional:!1},title:{type:e.String_unsecure(),isOptional:!1},fetchedAt:{type:e.DateTime(),isOptional:!1},hash:{type:e.String_unsecure(),isOptional:!1},fileId:{type:e.String_unsecure(),isOptional:!1}}}),r=t({name:`SourceRef`,description:`Reference to a source document used to justify a rule version.`,fields:{sourceDocumentId:{type:e.String_unsecure(),isOptional:!1},excerpt:{type:e.String_unsecure(),isOptional:!0}}}),i=t({name:`Rule`,description:`Curated rule (stable identity) with topic + jurisdiction scope.`,fields:{id:{type:e.String_unsecure(),isOptional:!1},jurisdiction:{type:e.String_unsecure(),isOptional:!1},topicKey:{type:e.String_unsecure(),isOptional:!1}}}),a=t({name:`RuleVersion`,description:`A versioned rule content with source references and approval status.`,fields:{id:{type:e.String_unsecure(),isOptional:!1},ruleId:{type:e.String_unsecure(),isOptional:!1},jurisdiction:{type:e.String_unsecure(),isOptional:!1},topicKey:{type:e.String_unsecure(),isOptional:!1},version:{type:e.Int_unsecure(),isOptional:!1},content:{type:e.String_unsecure(),isOptional:!1},sourceRefs:{type:r,isArray:!0,isOptional:!1},status:{type:e.String_unsecure(),isOptional:!1},approvedBy:{type:e.String_unsecure(),isOptional:!0},approvedAt:{type:e.DateTime(),isOptional:!0},createdAt:{type:e.DateTime(),isOptional:!1}}}),o=t({name:`KBSnapshot`,description:`Published KB snapshot (as-of) referencing approved rule versions.`,fields:{id:{type:e.String_unsecure(),isOptional:!1},jurisdiction:{type:e.String_unsecure(),isOptional:!1},asOfDate:{type:e.DateTime(),isOptional:!1},includedRuleVersionIds:{type:e.String_unsecure(),isArray:!0,isOptional:!1},publishedAt:{type:e.DateTime(),isOptional:!1}}});export{o as KBSnapshotModel,i as RuleModel,a as RuleVersionModel,n as SourceDocumentModel,r as SourceRefModel};
|
package/dist/events.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{defineEvent as e,defineSchemaModel as t}from"@lssm/lib.contracts";import{ScalarTypeEnum as n}from"@lssm/lib.schema";const r=e({name:`kb.source.ingested`,version:1,description:`Source document ingested (immutable).`,payload:t({name:`KbSourceIngestedPayload`,description:`Emitted when a source document is ingested.`,fields:{sourceDocumentId:{type:n.String_unsecure(),isOptional:!1},jurisdiction:{type:n.String_unsecure(),isOptional:!1},hash:{type:n.String_unsecure(),isOptional:!1}}})}),i=e({name:`kb.ruleVersion.created`,version:1,description:`Rule version created (draft).`,payload:t({name:`KbRuleVersionCreatedPayload`,description:`Emitted when a rule version draft is created.`,fields:{ruleVersionId:{type:n.String_unsecure(),isOptional:!1},ruleId:{type:n.String_unsecure(),isOptional:!1},jurisdiction:{type:n.String_unsecure(),isOptional:!1},status:{type:n.String_unsecure(),isOptional:!1}}})}),a=e({name:`kb.ruleVersion.approved`,version:1,description:`Rule version approved (human verified).`,payload:t({name:`KbRuleVersionApprovedPayload`,description:`Emitted when a rule version is approved.`,fields:{ruleVersionId:{type:n.String_unsecure(),isOptional:!1},approver:{type:n.String_unsecure(),isOptional:!1}}})}),o=e({name:`kb.snapshot.published`,version:1,description:`KB snapshot published.`,payload:t({name:`KbSnapshotPublishedPayload`,description:`Emitted when a KB snapshot is published.`,fields:{snapshotId:{type:n.String_unsecure(),isOptional:!1},jurisdiction:{type:n.String_unsecure(),isOptional:!1},includedRuleVersionsCount:{type:n.Int_unsecure(),isOptional:!1}}})});export{a as KbRuleVersionApprovedEvent,i as KbRuleVersionCreatedEvent,o as KbSnapshotPublishedEvent,r as KbSourceIngestedEvent};
|
package/dist/example.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e={id:`versioned-knowledge-base`,title:`Versioned Knowledge Base`,summary:`Curated KB with immutable sources, reviewable rule versions, and published snapshots.`,tags:[`knowledge`,`versioning`,`snapshots`],kind:`knowledge`,visibility:`public`,docs:{rootDocId:`docs.examples.versioned-knowledge-base`},entrypoints:{packageName:`@lssm/example.versioned-knowledge-base`,feature:`./feature`,contracts:`./contracts`,handlers:`./handlers`,docs:`./docs`},surfaces:{templates:!0,sandbox:{enabled:!0,modes:[`markdown`,`specs`,`builder`]},studio:{enabled:!0,installable:!0},mcp:{enabled:!0}}};export{e as default};
|
package/dist/feature.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e={meta:{key:`versioned-knowledge-base`,title:`Versioned Knowledge Base`,description:`Curated KB with immutable sources, rule versions, and published snapshots.`,domain:`knowledge`,owners:[`examples`],tags:[`knowledge`,`versioning`,`snapshots`],stability:`experimental`},operations:[{name:`kb.ingestSource`,version:1},{name:`kb.upsertRuleVersion`,version:1},{name:`kb.approveRuleVersion`,version:1},{name:`kb.publishSnapshot`,version:1},{name:`kb.search`,version:1}],events:[{name:`kb.source.ingested`,version:1},{name:`kb.ruleVersion.created`,version:1},{name:`kb.ruleVersion.approved`,version:1},{name:`kb.snapshot.published`,version:1}],presentations:[],opToPresentation:[],presentationsTargets:[],capabilities:{requires:[{key:`knowledge`,version:1}]}};export{e as VersionedKnowledgeBaseFeature};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createMemoryKbHandlers as e,createMemoryKbStore as t}from"./memory.handlers.js";export{e as createMemoryKbHandlers,t as createMemoryKbStore};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function e(){return{sources:new Map,rules:new Map,ruleVersions:new Map,snapshots:new Map,nextRuleVersionNumberByRuleId:new Map}}function t(e,t){return`${e}_${t.replace(/[^a-zA-Z0-9_-]/g,`_`)}`}function n(e){async function n(t){return e.rules.set(t.id,t),t}async function r(n){let r=t(`src`,`${n.jurisdiction}_${n.hash}`),i={id:r,...n};return e.sources.set(r,i),i}async function i(n){if(!n.sourceRefs.length)throw Error(`SOURCE_REFS_REQUIRED`);let r=e.rules.get(n.ruleId);if(!r)throw Error(`RULE_NOT_FOUND`);let i=(e.nextRuleVersionNumberByRuleId.get(n.ruleId)??0)+1;e.nextRuleVersionNumberByRuleId.set(n.ruleId,i);let a=t(`rv`,`${n.ruleId}_${i}`),o={id:a,ruleId:n.ruleId,jurisdiction:r.jurisdiction,topicKey:r.topicKey,version:i,content:n.content,sourceRefs:n.sourceRefs,status:`draft`,createdAt:new Date,approvedAt:void 0,approvedBy:void 0};return e.ruleVersions.set(a,o),o}async function a(t){let n=e.ruleVersions.get(t.ruleVersionId);if(!n)throw Error(`RULE_VERSION_NOT_FOUND`);let r={...n,status:`approved`,approvedBy:t.approver,approvedAt:new Date};return e.ruleVersions.set(r.id,r),r}async function o(n){let r=[...e.ruleVersions.values()].filter(e=>e.status===`approved`&&e.jurisdiction===n.jurisdiction);if(r.length===0)throw Error(`NO_APPROVED_RULES`);let i=r.map(e=>e.id).sort(),a=t(`snap`,`${n.jurisdiction}_${n.asOfDate.toISOString().slice(0,10)}_${i.length}`),o={id:a,jurisdiction:n.jurisdiction,asOfDate:n.asOfDate,includedRuleVersionIds:i,publishedAt:new Date};return e.snapshots.set(a,o),o}async function s(t){let n=e.snapshots.get(t.snapshotId);if(!n)throw Error(`SNAPSHOT_NOT_FOUND`);if(n.jurisdiction!==t.jurisdiction)throw Error(`JURISDICTION_MISMATCH`);let r=t.query.toLowerCase().split(/\s+/).map(e=>e.trim()).filter(Boolean);return{items:n.includedRuleVersionIds.map(t=>e.ruleVersions.get(t)).filter(e=>!!e).filter(e=>{if(r.length===0)return!0;let t=e.content.toLowerCase();return r.every(e=>t.includes(e))}).map(e=>({ruleVersionId:e.id,excerpt:e.content.slice(0,120)}))}}return{createRule:n,ingestSource:r,upsertRuleVersion:i,approveRuleVersion:a,publishSnapshot:o,search:s}}export{n as createMemoryKbHandlers,e as createMemoryKbStore};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{KbRuleVersionApprovedEvent as e,KbRuleVersionCreatedEvent as t,KbSnapshotPublishedEvent as n,KbSourceIngestedEvent as r}from"./events.js";import i from"./example.js";import{VersionedKnowledgeBaseFeature as a}from"./feature.js";import{KBSnapshotModel as o,RuleModel as s,RuleVersionModel as c,SourceDocumentModel as l,SourceRefModel as u}from"./entities/models.js";import"./entities/index.js";import{KbApproveRuleVersionContract as d,KbIngestSourceContract as f,KbPublishSnapshotContract as p,KbSearchContract as m,KbUpsertRuleVersionContract as h}from"./contracts/kb.js";import"./contracts/index.js";import{createMemoryKbHandlers as g,createMemoryKbStore as _}from"./handlers/memory.handlers.js";import"./docs/index.js";export{o as KBSnapshotModel,d as KbApproveRuleVersionContract,f as KbIngestSourceContract,p as KbPublishSnapshotContract,e as KbRuleVersionApprovedEvent,t as KbRuleVersionCreatedEvent,m as KbSearchContract,n as KbSnapshotPublishedEvent,r as KbSourceIngestedEvent,h as KbUpsertRuleVersionContract,s as RuleModel,c as RuleVersionModel,l as SourceDocumentModel,u as SourceRefModel,a as VersionedKnowledgeBaseFeature,g as createMemoryKbHandlers,_ as createMemoryKbStore,i as example};
|
package/example.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './src/example';
|
package/package.json
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lssm/example.versioned-knowledge-base",
|
|
3
|
+
"version": "0.0.0-canary-20251213172311",
|
|
4
|
+
"description": "Example: curated, versioned knowledge base with immutable sources, rule versions, and published snapshots.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": "./src/index.ts",
|
|
11
|
+
"./contracts": "./src/contracts/index.ts",
|
|
12
|
+
"./contracts/kb": "./src/contracts/kb.ts",
|
|
13
|
+
"./docs": "./src/docs/index.ts",
|
|
14
|
+
"./docs/versioned-knowledge-base.docblock": "./src/docs/versioned-knowledge-base.docblock.ts",
|
|
15
|
+
"./entities": "./src/entities/index.ts",
|
|
16
|
+
"./entities/models": "./src/entities/models.ts",
|
|
17
|
+
"./events": "./src/events.ts",
|
|
18
|
+
"./example": "./src/example.ts",
|
|
19
|
+
"./feature": "./src/feature.ts",
|
|
20
|
+
"./handlers": "./src/handlers/index.ts",
|
|
21
|
+
"./handlers/memory.handlers": "./src/handlers/memory.handlers.ts",
|
|
22
|
+
"./*": "./*"
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "bun build:bundle && bun build:types",
|
|
26
|
+
"build:bundle": "tsdown",
|
|
27
|
+
"build:types": "tsc --noEmit",
|
|
28
|
+
"dev": "bun build:bundle --watch",
|
|
29
|
+
"clean": "rimraf dist .turbo",
|
|
30
|
+
"lint": "bun lint:fix",
|
|
31
|
+
"lint:fix": "eslint src --fix",
|
|
32
|
+
"lint:check": "eslint src",
|
|
33
|
+
"test": "bun test"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@lssm/lib.contracts": "workspace:*",
|
|
37
|
+
"@lssm/lib.schema": "workspace:*",
|
|
38
|
+
"zod": "^4.1.13"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@lssm/tool.tsdown": "workspace:*",
|
|
42
|
+
"@lssm/tool.typescript": "workspace:*",
|
|
43
|
+
"tsdown": "^0.17.0",
|
|
44
|
+
"typescript": "^5.9.3"
|
|
45
|
+
},
|
|
46
|
+
"publishConfig": {
|
|
47
|
+
"access": "public",
|
|
48
|
+
"exports": {
|
|
49
|
+
".": "./dist/index.js",
|
|
50
|
+
"./contracts": "./dist/contracts/index.js",
|
|
51
|
+
"./contracts/kb": "./dist/contracts/kb.js",
|
|
52
|
+
"./docs": "./dist/docs/index.js",
|
|
53
|
+
"./docs/versioned-knowledge-base.docblock": "./dist/docs/versioned-knowledge-base.docblock.js",
|
|
54
|
+
"./entities": "./dist/entities/index.js",
|
|
55
|
+
"./entities/models": "./dist/entities/models.js",
|
|
56
|
+
"./events": "./dist/events.js",
|
|
57
|
+
"./example": "./dist/example.js",
|
|
58
|
+
"./feature": "./dist/feature.js",
|
|
59
|
+
"./handlers": "./dist/handlers/index.js",
|
|
60
|
+
"./handlers/memory.handlers": "./dist/handlers/memory.handlers.js",
|
|
61
|
+
"./*": "./*"
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { defineCommand, defineQuery } from '@lssm/lib.contracts';
|
|
2
|
+
import { ScalarTypeEnum, defineSchemaModel } from '@lssm/lib.schema';
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
KBSnapshotModel,
|
|
6
|
+
RuleVersionModel,
|
|
7
|
+
SourceDocumentModel,
|
|
8
|
+
SourceRefModel,
|
|
9
|
+
} from '../entities/models';
|
|
10
|
+
|
|
11
|
+
const IngestSourceInput = defineSchemaModel({
|
|
12
|
+
name: 'KbIngestSourceInput',
|
|
13
|
+
description: 'Ingest immutable source metadata referencing a stored file.',
|
|
14
|
+
fields: {
|
|
15
|
+
jurisdiction: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
16
|
+
authority: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
17
|
+
title: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
18
|
+
fetchedAt: { type: ScalarTypeEnum.DateTime(), isOptional: false },
|
|
19
|
+
hash: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
20
|
+
fileId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const UpsertRuleVersionInput = defineSchemaModel({
|
|
25
|
+
name: 'KbUpsertRuleVersionInput',
|
|
26
|
+
description: 'Create a new draft rule version (immutable history).',
|
|
27
|
+
fields: {
|
|
28
|
+
ruleId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
29
|
+
content: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
30
|
+
sourceRefs: { type: SourceRefModel, isArray: true, isOptional: false },
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const ApproveRuleVersionInput = defineSchemaModel({
|
|
35
|
+
name: 'KbApproveRuleVersionInput',
|
|
36
|
+
description: 'Approve a rule version (human verification).',
|
|
37
|
+
fields: {
|
|
38
|
+
ruleVersionId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
39
|
+
approver: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const PublishSnapshotInput = defineSchemaModel({
|
|
44
|
+
name: 'KbPublishSnapshotInput',
|
|
45
|
+
description: 'Publish a snapshot for a jurisdiction as-of a date.',
|
|
46
|
+
fields: {
|
|
47
|
+
jurisdiction: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
48
|
+
asOfDate: { type: ScalarTypeEnum.DateTime(), isOptional: false },
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const SearchKbInput = defineSchemaModel({
|
|
53
|
+
name: 'KbSearchInput',
|
|
54
|
+
description: 'Search within a published snapshot.',
|
|
55
|
+
fields: {
|
|
56
|
+
snapshotId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
57
|
+
jurisdiction: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
58
|
+
query: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
const SearchKbResultItem = defineSchemaModel({
|
|
63
|
+
name: 'KbSearchResultItem',
|
|
64
|
+
description: 'Search result referencing a specific rule version.',
|
|
65
|
+
fields: {
|
|
66
|
+
ruleVersionId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
67
|
+
excerpt: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
const SearchKbOutput = defineSchemaModel({
|
|
72
|
+
name: 'KbSearchOutput',
|
|
73
|
+
description: 'Search results constrained to snapshot + jurisdiction.',
|
|
74
|
+
fields: {
|
|
75
|
+
items: { type: SearchKbResultItem, isArray: true, isOptional: false },
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
export const KbIngestSourceContract = defineCommand({
|
|
80
|
+
meta: {
|
|
81
|
+
name: 'kb.ingestSource',
|
|
82
|
+
version: 1,
|
|
83
|
+
stability: 'experimental',
|
|
84
|
+
owners: ['examples'],
|
|
85
|
+
tags: ['knowledge', 'sources', 'ingestion'],
|
|
86
|
+
description: 'Ingest immutable source document metadata.',
|
|
87
|
+
goal: 'Store traceable source documents for curated KB.',
|
|
88
|
+
context: 'Called when an admin uploads/records authoritative sources.',
|
|
89
|
+
},
|
|
90
|
+
io: {
|
|
91
|
+
input: IngestSourceInput,
|
|
92
|
+
output: SourceDocumentModel,
|
|
93
|
+
},
|
|
94
|
+
policy: { auth: 'user' },
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
export const KbUpsertRuleVersionContract = defineCommand({
|
|
98
|
+
meta: {
|
|
99
|
+
name: 'kb.upsertRuleVersion',
|
|
100
|
+
version: 1,
|
|
101
|
+
stability: 'experimental',
|
|
102
|
+
owners: ['examples'],
|
|
103
|
+
tags: ['knowledge', 'rules', 'versioning'],
|
|
104
|
+
description: 'Create a new draft rule version with source references.',
|
|
105
|
+
goal: 'Propose curated knowledge updates with traceability.',
|
|
106
|
+
context: 'Automation or curators propose draft rule versions.',
|
|
107
|
+
},
|
|
108
|
+
io: {
|
|
109
|
+
input: UpsertRuleVersionInput,
|
|
110
|
+
output: RuleVersionModel,
|
|
111
|
+
errors: {
|
|
112
|
+
SOURCE_REFS_REQUIRED: {
|
|
113
|
+
description: 'Rule version must cite at least one sourceRef',
|
|
114
|
+
http: 400,
|
|
115
|
+
gqlCode: 'SOURCE_REFS_REQUIRED',
|
|
116
|
+
when: 'sourceRefs is empty',
|
|
117
|
+
},
|
|
118
|
+
RULE_NOT_FOUND: {
|
|
119
|
+
description: 'Rule does not exist',
|
|
120
|
+
http: 404,
|
|
121
|
+
gqlCode: 'RULE_NOT_FOUND',
|
|
122
|
+
when: 'ruleId is unknown',
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
policy: { auth: 'user' },
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
export const KbApproveRuleVersionContract = defineCommand({
|
|
130
|
+
meta: {
|
|
131
|
+
name: 'kb.approveRuleVersion',
|
|
132
|
+
version: 1,
|
|
133
|
+
stability: 'experimental',
|
|
134
|
+
owners: ['examples'],
|
|
135
|
+
tags: ['knowledge', 'rules', 'approval'],
|
|
136
|
+
description: 'Approve a draft rule version.',
|
|
137
|
+
goal: 'Human verification step before publishing snapshots.',
|
|
138
|
+
context: 'Curators/experts approve proposed KB changes.',
|
|
139
|
+
},
|
|
140
|
+
io: {
|
|
141
|
+
input: ApproveRuleVersionInput,
|
|
142
|
+
output: RuleVersionModel,
|
|
143
|
+
},
|
|
144
|
+
policy: { auth: 'user' },
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
export const KbPublishSnapshotContract = defineCommand({
|
|
148
|
+
meta: {
|
|
149
|
+
name: 'kb.publishSnapshot',
|
|
150
|
+
version: 1,
|
|
151
|
+
stability: 'experimental',
|
|
152
|
+
owners: ['examples'],
|
|
153
|
+
tags: ['knowledge', 'snapshots', 'publishing'],
|
|
154
|
+
description: 'Publish a KB snapshot for a jurisdiction.',
|
|
155
|
+
goal: 'Create a stable snapshot that assistant answers can cite.',
|
|
156
|
+
context: 'Publishing happens after approvals; snapshot is referenced by answers.',
|
|
157
|
+
},
|
|
158
|
+
io: {
|
|
159
|
+
input: PublishSnapshotInput,
|
|
160
|
+
output: KBSnapshotModel,
|
|
161
|
+
errors: {
|
|
162
|
+
NO_APPROVED_RULES: {
|
|
163
|
+
description: 'No approved rule versions available to publish',
|
|
164
|
+
http: 409,
|
|
165
|
+
gqlCode: 'NO_APPROVED_RULES',
|
|
166
|
+
when: 'jurisdiction has zero approved rule versions',
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
},
|
|
170
|
+
policy: { auth: 'user' },
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
export const KbSearchContract = defineQuery({
|
|
174
|
+
meta: {
|
|
175
|
+
name: 'kb.search',
|
|
176
|
+
version: 1,
|
|
177
|
+
stability: 'experimental',
|
|
178
|
+
owners: ['examples'],
|
|
179
|
+
tags: ['knowledge', 'search', 'snapshots'],
|
|
180
|
+
description: 'Search within a published KB snapshot.',
|
|
181
|
+
goal: 'Provide scoped retrieval for assistant answers.',
|
|
182
|
+
context: 'Assistant queries curated rules from a specific snapshot.',
|
|
183
|
+
},
|
|
184
|
+
io: {
|
|
185
|
+
input: SearchKbInput,
|
|
186
|
+
output: SearchKbOutput,
|
|
187
|
+
},
|
|
188
|
+
policy: { auth: 'user' },
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { DocBlock } from '@lssm/lib.contracts/docs';
|
|
2
|
+
import { registerDocBlocks } from '@lssm/lib.contracts/docs';
|
|
3
|
+
|
|
4
|
+
const docBlocks: DocBlock[] = [
|
|
5
|
+
{
|
|
6
|
+
id: 'docs.examples.versioned-knowledge-base.goal',
|
|
7
|
+
title: 'Versioned Knowledge Base — Goal',
|
|
8
|
+
summary:
|
|
9
|
+
'Curated KB with immutable sources, versioned rules, and published snapshots referenced by answers.',
|
|
10
|
+
kind: 'goal',
|
|
11
|
+
visibility: 'public',
|
|
12
|
+
route: '/docs/examples/versioned-knowledge-base/goal',
|
|
13
|
+
tags: ['knowledge', 'versioning', 'snapshots', 'traceability'],
|
|
14
|
+
body: `## Why it matters
|
|
15
|
+
- Separates raw sources from curated knowledge.\n- Ensures assistant answers cite a published snapshot.\n- Makes change review and safe regeneration possible.\n\n## Core invariants\n- Sources are immutable and content-addressed (hash).\n- Rule versions must cite at least one source.\n- Snapshots include only approved rule versions.`,
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
id: 'docs.examples.versioned-knowledge-base.reference',
|
|
19
|
+
title: 'Versioned Knowledge Base — Reference',
|
|
20
|
+
summary: 'Entities, contracts, and events for the versioned KB example.',
|
|
21
|
+
kind: 'reference',
|
|
22
|
+
visibility: 'public',
|
|
23
|
+
route: '/docs/examples/versioned-knowledge-base',
|
|
24
|
+
tags: ['knowledge', 'reference'],
|
|
25
|
+
body: `## Contracts\n- kb.ingestSource\n- kb.upsertRuleVersion\n- kb.approveRuleVersion\n- kb.publishSnapshot\n- kb.search\n\n## Events\n- kb.source.ingested\n- kb.ruleVersion.created\n- kb.ruleVersion.approved\n- kb.snapshot.published`,
|
|
26
|
+
},
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
registerDocBlocks(docBlocks);
|
|
30
|
+
|
|
31
|
+
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { ScalarTypeEnum, defineSchemaModel } from '@lssm/lib.schema';
|
|
2
|
+
|
|
3
|
+
export const SourceDocumentModel = defineSchemaModel({
|
|
4
|
+
name: 'SourceDocument',
|
|
5
|
+
description: 'Immutable raw source document metadata referencing a stored file.',
|
|
6
|
+
fields: {
|
|
7
|
+
id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
8
|
+
jurisdiction: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
9
|
+
authority: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
10
|
+
title: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
11
|
+
fetchedAt: { type: ScalarTypeEnum.DateTime(), isOptional: false },
|
|
12
|
+
hash: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
13
|
+
fileId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
export const SourceRefModel = defineSchemaModel({
|
|
18
|
+
name: 'SourceRef',
|
|
19
|
+
description: 'Reference to a source document used to justify a rule version.',
|
|
20
|
+
fields: {
|
|
21
|
+
sourceDocumentId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
22
|
+
excerpt: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
export const RuleModel = defineSchemaModel({
|
|
27
|
+
name: 'Rule',
|
|
28
|
+
description: 'Curated rule (stable identity) with topic + jurisdiction scope.',
|
|
29
|
+
fields: {
|
|
30
|
+
id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
31
|
+
jurisdiction: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
32
|
+
topicKey: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
export const RuleVersionModel = defineSchemaModel({
|
|
37
|
+
name: 'RuleVersion',
|
|
38
|
+
description: 'A versioned rule content with source references and approval status.',
|
|
39
|
+
fields: {
|
|
40
|
+
id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
41
|
+
ruleId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
42
|
+
jurisdiction: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
43
|
+
topicKey: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
44
|
+
version: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
|
|
45
|
+
content: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
46
|
+
sourceRefs: { type: SourceRefModel, isArray: true, isOptional: false },
|
|
47
|
+
status: { type: ScalarTypeEnum.String_unsecure(), isOptional: false }, // draft|approved|rejected
|
|
48
|
+
approvedBy: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
49
|
+
approvedAt: { type: ScalarTypeEnum.DateTime(), isOptional: true },
|
|
50
|
+
createdAt: { type: ScalarTypeEnum.DateTime(), isOptional: false },
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
export const KBSnapshotModel = defineSchemaModel({
|
|
55
|
+
name: 'KBSnapshot',
|
|
56
|
+
description: 'Published KB snapshot (as-of) referencing approved rule versions.',
|
|
57
|
+
fields: {
|
|
58
|
+
id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
59
|
+
jurisdiction: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
60
|
+
asOfDate: { type: ScalarTypeEnum.DateTime(), isOptional: false },
|
|
61
|
+
includedRuleVersionIds: {
|
|
62
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
63
|
+
isArray: true,
|
|
64
|
+
isOptional: false,
|
|
65
|
+
},
|
|
66
|
+
publishedAt: { type: ScalarTypeEnum.DateTime(), isOptional: false },
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
|
package/src/events.ts
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { defineEvent, defineSchemaModel } from '@lssm/lib.contracts';
|
|
2
|
+
import { ScalarTypeEnum } from '@lssm/lib.schema';
|
|
3
|
+
|
|
4
|
+
const KbSourceIngestedPayload = defineSchemaModel({
|
|
5
|
+
name: 'KbSourceIngestedPayload',
|
|
6
|
+
description: 'Emitted when a source document is ingested.',
|
|
7
|
+
fields: {
|
|
8
|
+
sourceDocumentId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
9
|
+
jurisdiction: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
10
|
+
hash: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
export const KbSourceIngestedEvent = defineEvent({
|
|
15
|
+
name: 'kb.source.ingested',
|
|
16
|
+
version: 1,
|
|
17
|
+
description: 'Source document ingested (immutable).',
|
|
18
|
+
payload: KbSourceIngestedPayload,
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const KbRuleVersionCreatedPayload = defineSchemaModel({
|
|
22
|
+
name: 'KbRuleVersionCreatedPayload',
|
|
23
|
+
description: 'Emitted when a rule version draft is created.',
|
|
24
|
+
fields: {
|
|
25
|
+
ruleVersionId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
26
|
+
ruleId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
27
|
+
jurisdiction: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
28
|
+
status: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
export const KbRuleVersionCreatedEvent = defineEvent({
|
|
33
|
+
name: 'kb.ruleVersion.created',
|
|
34
|
+
version: 1,
|
|
35
|
+
description: 'Rule version created (draft).',
|
|
36
|
+
payload: KbRuleVersionCreatedPayload,
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const KbRuleVersionApprovedPayload = defineSchemaModel({
|
|
40
|
+
name: 'KbRuleVersionApprovedPayload',
|
|
41
|
+
description: 'Emitted when a rule version is approved.',
|
|
42
|
+
fields: {
|
|
43
|
+
ruleVersionId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
44
|
+
approver: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
export const KbRuleVersionApprovedEvent = defineEvent({
|
|
49
|
+
name: 'kb.ruleVersion.approved',
|
|
50
|
+
version: 1,
|
|
51
|
+
description: 'Rule version approved (human verified).',
|
|
52
|
+
payload: KbRuleVersionApprovedPayload,
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
const KbSnapshotPublishedPayload = defineSchemaModel({
|
|
56
|
+
name: 'KbSnapshotPublishedPayload',
|
|
57
|
+
description: 'Emitted when a KB snapshot is published.',
|
|
58
|
+
fields: {
|
|
59
|
+
snapshotId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
60
|
+
jurisdiction: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
61
|
+
includedRuleVersionsCount: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
export const KbSnapshotPublishedEvent = defineEvent({
|
|
66
|
+
name: 'kb.snapshot.published',
|
|
67
|
+
version: 1,
|
|
68
|
+
description: 'KB snapshot published.',
|
|
69
|
+
payload: KbSnapshotPublishedPayload,
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
|
package/src/example.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const example = {
|
|
2
|
+
id: 'versioned-knowledge-base',
|
|
3
|
+
title: 'Versioned Knowledge Base',
|
|
4
|
+
summary:
|
|
5
|
+
'Curated KB with immutable sources, reviewable rule versions, and published snapshots.',
|
|
6
|
+
tags: ['knowledge', 'versioning', 'snapshots'],
|
|
7
|
+
kind: 'knowledge',
|
|
8
|
+
visibility: 'public',
|
|
9
|
+
docs: {
|
|
10
|
+
rootDocId: 'docs.examples.versioned-knowledge-base',
|
|
11
|
+
},
|
|
12
|
+
entrypoints: {
|
|
13
|
+
packageName: '@lssm/example.versioned-knowledge-base',
|
|
14
|
+
feature: './feature',
|
|
15
|
+
contracts: './contracts',
|
|
16
|
+
handlers: './handlers',
|
|
17
|
+
docs: './docs',
|
|
18
|
+
},
|
|
19
|
+
surfaces: {
|
|
20
|
+
templates: true,
|
|
21
|
+
sandbox: { enabled: true, modes: ['markdown', 'specs', 'builder'] },
|
|
22
|
+
studio: { enabled: true, installable: true },
|
|
23
|
+
mcp: { enabled: true },
|
|
24
|
+
},
|
|
25
|
+
} as const;
|
|
26
|
+
|
|
27
|
+
export default example;
|
|
28
|
+
|
|
29
|
+
|