@contractspec/example.versioned-knowledge-base 3.7.16 → 3.7.18

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.
Files changed (42) hide show
  1. package/.turbo/turbo-build.log +42 -42
  2. package/CHANGELOG.md +22 -0
  3. package/dist/browser/docs/index.js +3 -27
  4. package/dist/browser/docs/versioned-knowledge-base.docblock.js +3 -27
  5. package/dist/browser/entities/index.js +1 -74
  6. package/dist/browser/entities/models.js +1 -74
  7. package/dist/browser/events.js +1 -101
  8. package/dist/browser/example.js +1 -35
  9. package/dist/browser/handlers/index.js +1 -115
  10. package/dist/browser/handlers/memory.handlers.js +1 -115
  11. package/dist/browser/index.js +4 -617
  12. package/dist/browser/knowledge-snapshot-publication.migration.js +2 -44
  13. package/dist/browser/operations/index.js +1 -257
  14. package/dist/browser/operations/kb.js +1 -257
  15. package/dist/browser/versioned-knowledge-base.feature.js +1 -41
  16. package/dist/docs/index.js +3 -27
  17. package/dist/docs/versioned-knowledge-base.docblock.js +3 -27
  18. package/dist/entities/index.js +1 -74
  19. package/dist/entities/models.js +1 -74
  20. package/dist/events.js +1 -101
  21. package/dist/example.js +1 -35
  22. package/dist/handlers/index.js +1 -115
  23. package/dist/handlers/memory.handlers.js +1 -115
  24. package/dist/index.js +4 -617
  25. package/dist/knowledge-snapshot-publication.migration.js +2 -44
  26. package/dist/node/docs/index.js +3 -27
  27. package/dist/node/docs/versioned-knowledge-base.docblock.js +3 -27
  28. package/dist/node/entities/index.js +1 -74
  29. package/dist/node/entities/models.js +1 -74
  30. package/dist/node/events.js +1 -101
  31. package/dist/node/example.js +1 -35
  32. package/dist/node/handlers/index.js +1 -115
  33. package/dist/node/handlers/memory.handlers.js +1 -115
  34. package/dist/node/index.js +4 -617
  35. package/dist/node/knowledge-snapshot-publication.migration.js +2 -44
  36. package/dist/node/operations/index.js +1 -257
  37. package/dist/node/operations/kb.js +1 -257
  38. package/dist/node/versioned-knowledge-base.feature.js +1 -41
  39. package/dist/operations/index.js +1 -257
  40. package/dist/operations/kb.js +1 -257
  41. package/dist/versioned-knowledge-base.feature.js +1 -41
  42. package/package.json +7 -7
@@ -1,51 +1,9 @@
1
1
  // @bun
2
- // src/knowledge-snapshot-publication.migration.ts
3
- import {
4
- OwnersEnum,
5
- StabilityEnum,
6
- TagsEnum
7
- } from "@contractspec/lib.contracts-spec/ownership";
8
- var KnowledgeSnapshotPublicationMigration = {
9
- meta: {
10
- key: "versioned-knowledge-base.migration.snapshot-publication",
11
- version: "1.0.0",
12
- title: "Knowledge Snapshot Publication Migration",
13
- description: "Adds publication audit fields and validation checks for published knowledge snapshots.",
14
- domain: "knowledge",
15
- owners: [OwnersEnum.PlatformContent],
16
- tags: ["knowledge", "migration", "snapshots", TagsEnum.Hygiene],
17
- stability: StabilityEnum.Experimental
18
- },
19
- dependencies: ["versioned-knowledge-base.migration.bootstrap"],
20
- plan: {
21
- up: [
22
- {
23
- kind: "schema",
24
- description: "Create the published snapshot audit table.",
25
- sql: `
2
+ import{OwnersEnum as d,StabilityEnum as f,TagsEnum as j}from"@contractspec/lib.contracts-spec/ownership";var q={meta:{key:"versioned-knowledge-base.migration.snapshot-publication",version:"1.0.0",title:"Knowledge Snapshot Publication Migration",description:"Adds publication audit fields and validation checks for published knowledge snapshots.",domain:"knowledge",owners:[d.PlatformContent],tags:["knowledge","migration","snapshots",j.Hygiene],stability:f.Experimental},dependencies:["versioned-knowledge-base.migration.bootstrap"],plan:{up:[{kind:"schema",description:"Create the published snapshot audit table.",sql:`
26
3
  CREATE TABLE kb_snapshot_publications (
27
4
  snapshot_id TEXT PRIMARY KEY,
28
5
  published_by TEXT NOT NULL,
29
6
  published_at TIMESTAMPTZ NOT NULL,
30
7
  source_count INTEGER NOT NULL,
31
8
  rule_version_count INTEGER NOT NULL
32
- );`
33
- },
34
- {
35
- kind: "validation",
36
- description: "Ensure snapshots have at least one approved rule version.",
37
- assertion: "SELECT COUNT(*) = 0 FROM kb_snapshots WHERE array_length(included_rule_version_ids, 1) = 0"
38
- }
39
- ],
40
- down: [
41
- {
42
- kind: "schema",
43
- description: "Remove the snapshot publication audit table.",
44
- sql: "DROP TABLE IF EXISTS kb_snapshot_publications;"
45
- }
46
- ]
47
- }
48
- };
49
- export {
50
- KnowledgeSnapshotPublicationMigration
51
- };
9
+ );`},{kind:"validation",description:"Ensure snapshots have at least one approved rule version.",assertion:"SELECT COUNT(*) = 0 FROM kb_snapshots WHERE array_length(included_rule_version_ids, 1) = 0"}],down:[{kind:"schema",description:"Remove the snapshot publication audit table.",sql:"DROP TABLE IF EXISTS kb_snapshot_publications;"}]}};export{q as KnowledgeSnapshotPublicationMigration};
@@ -1,15 +1,4 @@
1
- // src/docs/versioned-knowledge-base.docblock.ts
2
- import { registerDocBlocks } from "@contractspec/lib.contracts-spec/docs";
3
- var docBlocks = [
4
- {
5
- id: "docs.examples.versioned-knowledge-base.goal",
6
- title: "Versioned Knowledge Base — Goal",
7
- summary: "Curated KB with immutable sources, versioned rules, and published snapshots referenced by answers.",
8
- kind: "goal",
9
- visibility: "public",
10
- route: "/docs/examples/versioned-knowledge-base/goal",
11
- tags: ["knowledge", "versioning", "snapshots", "traceability"],
12
- body: `## Why it matters
1
+ import{registerDocBlocks as f}from"@contractspec/lib.contracts-spec/docs";var h=[{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
13
2
  - Separates raw sources from curated knowledge.
14
3
  - Ensures assistant answers cite a published snapshot.
15
4
  - Makes change review and safe regeneration possible.
@@ -17,17 +6,7 @@ var docBlocks = [
17
6
  ## Core invariants
18
7
  - Sources are immutable and content-addressed (hash).
19
8
  - Rule versions must cite at least one source.
20
- - Snapshots include only approved rule versions.`
21
- },
22
- {
23
- id: "docs.examples.versioned-knowledge-base.reference",
24
- title: "Versioned Knowledge Base — Reference",
25
- summary: "Entities, contracts, and events for the versioned KB example.",
26
- kind: "reference",
27
- visibility: "public",
28
- route: "/docs/examples/versioned-knowledge-base",
29
- tags: ["knowledge", "reference"],
30
- body: `## Contracts
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
31
10
  - kb.ingestSource
32
11
  - kb.upsertRuleVersion
33
12
  - kb.approveRuleVersion
@@ -38,7 +17,4 @@ var docBlocks = [
38
17
  - kb.source.ingested
39
18
  - kb.ruleVersion.created
40
19
  - kb.ruleVersion.approved
41
- - kb.snapshot.published`
42
- }
43
- ];
44
- registerDocBlocks(docBlocks);
20
+ - kb.snapshot.published`}];f(h);
@@ -1,15 +1,4 @@
1
- // src/docs/versioned-knowledge-base.docblock.ts
2
- import { registerDocBlocks } from "@contractspec/lib.contracts-spec/docs";
3
- var docBlocks = [
4
- {
5
- id: "docs.examples.versioned-knowledge-base.goal",
6
- title: "Versioned Knowledge Base — Goal",
7
- summary: "Curated KB with immutable sources, versioned rules, and published snapshots referenced by answers.",
8
- kind: "goal",
9
- visibility: "public",
10
- route: "/docs/examples/versioned-knowledge-base/goal",
11
- tags: ["knowledge", "versioning", "snapshots", "traceability"],
12
- body: `## Why it matters
1
+ import{registerDocBlocks as f}from"@contractspec/lib.contracts-spec/docs";var h=[{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
13
2
  - Separates raw sources from curated knowledge.
14
3
  - Ensures assistant answers cite a published snapshot.
15
4
  - Makes change review and safe regeneration possible.
@@ -17,17 +6,7 @@ var docBlocks = [
17
6
  ## Core invariants
18
7
  - Sources are immutable and content-addressed (hash).
19
8
  - Rule versions must cite at least one source.
20
- - Snapshots include only approved rule versions.`
21
- },
22
- {
23
- id: "docs.examples.versioned-knowledge-base.reference",
24
- title: "Versioned Knowledge Base — Reference",
25
- summary: "Entities, contracts, and events for the versioned KB example.",
26
- kind: "reference",
27
- visibility: "public",
28
- route: "/docs/examples/versioned-knowledge-base",
29
- tags: ["knowledge", "reference"],
30
- body: `## Contracts
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
31
10
  - kb.ingestSource
32
11
  - kb.upsertRuleVersion
33
12
  - kb.approveRuleVersion
@@ -38,7 +17,4 @@ var docBlocks = [
38
17
  - kb.source.ingested
39
18
  - kb.ruleVersion.created
40
19
  - kb.ruleVersion.approved
41
- - kb.snapshot.published`
42
- }
43
- ];
44
- registerDocBlocks(docBlocks);
20
+ - kb.snapshot.published`}];f(h);
@@ -1,74 +1 @@
1
- // src/entities/models.ts
2
- import { defineSchemaModel, ScalarTypeEnum } from "@contractspec/lib.schema";
3
- var 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
- var SourceRefModel = defineSchemaModel({
17
- name: "SourceRef",
18
- description: "Reference to a source document used to justify a rule version.",
19
- fields: {
20
- sourceDocumentId: {
21
- type: ScalarTypeEnum.String_unsecure(),
22
- isOptional: false
23
- },
24
- excerpt: { type: ScalarTypeEnum.String_unsecure(), isOptional: true }
25
- }
26
- });
27
- var RuleModel = defineSchemaModel({
28
- name: "Rule",
29
- description: "Curated rule (stable identity) with topic + jurisdiction scope.",
30
- fields: {
31
- id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
32
- jurisdiction: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
33
- topicKey: { type: ScalarTypeEnum.String_unsecure(), isOptional: false }
34
- }
35
- });
36
- var 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.String_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 },
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
- var KBSnapshotModel = defineSchemaModel({
54
- name: "KBSnapshot",
55
- description: "Published KB snapshot (as-of) referencing approved rule versions.",
56
- fields: {
57
- id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
58
- jurisdiction: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
59
- asOfDate: { type: ScalarTypeEnum.DateTime(), isOptional: false },
60
- includedRuleVersionIds: {
61
- type: ScalarTypeEnum.String_unsecure(),
62
- isArray: true,
63
- isOptional: false
64
- },
65
- publishedAt: { type: ScalarTypeEnum.DateTime(), isOptional: false }
66
- }
67
- });
68
- export {
69
- SourceRefModel,
70
- SourceDocumentModel,
71
- RuleVersionModel,
72
- RuleModel,
73
- KBSnapshotModel
74
- };
1
+ import{defineSchemaModel as t,ScalarTypeEnum as e}from"@contractspec/lib.schema";var 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}}}),i=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}}}),r=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}}}),o=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.String_unsecure(),isOptional:!1},content:{type:e.String_unsecure(),isOptional:!1},sourceRefs:{type:i,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}}}),a=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{i as SourceRefModel,n as SourceDocumentModel,o as RuleVersionModel,r as RuleModel,a as KBSnapshotModel};
@@ -1,74 +1 @@
1
- // src/entities/models.ts
2
- import { defineSchemaModel, ScalarTypeEnum } from "@contractspec/lib.schema";
3
- var 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
- var SourceRefModel = defineSchemaModel({
17
- name: "SourceRef",
18
- description: "Reference to a source document used to justify a rule version.",
19
- fields: {
20
- sourceDocumentId: {
21
- type: ScalarTypeEnum.String_unsecure(),
22
- isOptional: false
23
- },
24
- excerpt: { type: ScalarTypeEnum.String_unsecure(), isOptional: true }
25
- }
26
- });
27
- var RuleModel = defineSchemaModel({
28
- name: "Rule",
29
- description: "Curated rule (stable identity) with topic + jurisdiction scope.",
30
- fields: {
31
- id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
32
- jurisdiction: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
33
- topicKey: { type: ScalarTypeEnum.String_unsecure(), isOptional: false }
34
- }
35
- });
36
- var 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.String_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 },
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
- var KBSnapshotModel = defineSchemaModel({
54
- name: "KBSnapshot",
55
- description: "Published KB snapshot (as-of) referencing approved rule versions.",
56
- fields: {
57
- id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
58
- jurisdiction: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
59
- asOfDate: { type: ScalarTypeEnum.DateTime(), isOptional: false },
60
- includedRuleVersionIds: {
61
- type: ScalarTypeEnum.String_unsecure(),
62
- isArray: true,
63
- isOptional: false
64
- },
65
- publishedAt: { type: ScalarTypeEnum.DateTime(), isOptional: false }
66
- }
67
- });
68
- export {
69
- SourceRefModel,
70
- SourceDocumentModel,
71
- RuleVersionModel,
72
- RuleModel,
73
- KBSnapshotModel
74
- };
1
+ import{defineSchemaModel as t,ScalarTypeEnum as e}from"@contractspec/lib.schema";var 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}}}),i=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}}}),r=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.String_unsecure(),isOptional:!1},content:{type:e.String_unsecure(),isOptional:!1},sourceRefs:{type:i,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{i as SourceRefModel,n as SourceDocumentModel,a as RuleVersionModel,r as RuleModel,o as KBSnapshotModel};
@@ -1,101 +1 @@
1
- // src/events.ts
2
- import { defineEvent } from "@contractspec/lib.contracts-spec";
3
- import { defineSchemaModel, ScalarTypeEnum } from "@contractspec/lib.schema";
4
- var KbSourceIngestedPayload = defineSchemaModel({
5
- name: "KbSourceIngestedPayload",
6
- description: "Emitted when a source document is ingested.",
7
- fields: {
8
- sourceDocumentId: {
9
- type: ScalarTypeEnum.String_unsecure(),
10
- isOptional: false
11
- },
12
- jurisdiction: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
13
- hash: { type: ScalarTypeEnum.String_unsecure(), isOptional: false }
14
- }
15
- });
16
- var KbSourceIngestedEvent = defineEvent({
17
- meta: {
18
- key: "kb.source.ingested",
19
- version: "1.0.0",
20
- description: "Source document ingested (immutable).",
21
- stability: "experimental",
22
- owners: ["@examples"],
23
- tags: ["knowledge"]
24
- },
25
- payload: KbSourceIngestedPayload
26
- });
27
- var KbRuleVersionCreatedPayload = defineSchemaModel({
28
- name: "KbRuleVersionCreatedPayload",
29
- description: "Emitted when a rule version draft is created.",
30
- fields: {
31
- ruleVersionId: {
32
- type: ScalarTypeEnum.String_unsecure(),
33
- isOptional: false
34
- },
35
- ruleId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
36
- jurisdiction: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
37
- status: { type: ScalarTypeEnum.String_unsecure(), isOptional: false }
38
- }
39
- });
40
- var KbRuleVersionCreatedEvent = defineEvent({
41
- meta: {
42
- key: "kb.ruleVersion.created",
43
- version: "1.0.0",
44
- description: "Rule version created (draft).",
45
- stability: "experimental",
46
- owners: ["@examples"],
47
- tags: ["knowledge"]
48
- },
49
- payload: KbRuleVersionCreatedPayload
50
- });
51
- var KbRuleVersionApprovedPayload = defineSchemaModel({
52
- name: "KbRuleVersionApprovedPayload",
53
- description: "Emitted when a rule version is approved.",
54
- fields: {
55
- ruleVersionId: {
56
- type: ScalarTypeEnum.String_unsecure(),
57
- isOptional: false
58
- },
59
- approver: { type: ScalarTypeEnum.String_unsecure(), isOptional: false }
60
- }
61
- });
62
- var KbRuleVersionApprovedEvent = defineEvent({
63
- meta: {
64
- key: "kb.ruleVersion.approved",
65
- version: "1.0.0",
66
- description: "Rule version approved (human verified).",
67
- stability: "experimental",
68
- owners: ["@examples"],
69
- tags: ["knowledge"]
70
- },
71
- payload: KbRuleVersionApprovedPayload
72
- });
73
- var KbSnapshotPublishedPayload = defineSchemaModel({
74
- name: "KbSnapshotPublishedPayload",
75
- description: "Emitted when a KB snapshot is published.",
76
- fields: {
77
- snapshotId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
78
- jurisdiction: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
79
- includedRuleVersionsCount: {
80
- type: ScalarTypeEnum.Int_unsecure(),
81
- isOptional: false
82
- }
83
- }
84
- });
85
- var KbSnapshotPublishedEvent = defineEvent({
86
- meta: {
87
- key: "kb.snapshot.published",
88
- version: "1.0.0",
89
- description: "KB snapshot published.",
90
- stability: "experimental",
91
- owners: ["@examples"],
92
- tags: ["knowledge"]
93
- },
94
- payload: KbSnapshotPublishedPayload
95
- });
96
- export {
97
- KbSourceIngestedEvent,
98
- KbSnapshotPublishedEvent,
99
- KbRuleVersionCreatedEvent,
100
- KbRuleVersionApprovedEvent
101
- };
1
+ import{defineEvent as k}from"@contractspec/lib.contracts-spec";import{defineSchemaModel as q,ScalarTypeEnum as j}from"@contractspec/lib.schema";var w=q({name:"KbSourceIngestedPayload",description:"Emitted when a source document is ingested.",fields:{sourceDocumentId:{type:j.String_unsecure(),isOptional:!1},jurisdiction:{type:j.String_unsecure(),isOptional:!1},hash:{type:j.String_unsecure(),isOptional:!1}}}),G=k({meta:{key:"kb.source.ingested",version:"1.0.0",description:"Source document ingested (immutable).",stability:"experimental",owners:["@examples"],tags:["knowledge"]},payload:w}),x=q({name:"KbRuleVersionCreatedPayload",description:"Emitted when a rule version draft is created.",fields:{ruleVersionId:{type:j.String_unsecure(),isOptional:!1},ruleId:{type:j.String_unsecure(),isOptional:!1},jurisdiction:{type:j.String_unsecure(),isOptional:!1},status:{type:j.String_unsecure(),isOptional:!1}}}),H=k({meta:{key:"kb.ruleVersion.created",version:"1.0.0",description:"Rule version created (draft).",stability:"experimental",owners:["@examples"],tags:["knowledge"]},payload:x}),z=q({name:"KbRuleVersionApprovedPayload",description:"Emitted when a rule version is approved.",fields:{ruleVersionId:{type:j.String_unsecure(),isOptional:!1},approver:{type:j.String_unsecure(),isOptional:!1}}}),J=k({meta:{key:"kb.ruleVersion.approved",version:"1.0.0",description:"Rule version approved (human verified).",stability:"experimental",owners:["@examples"],tags:["knowledge"]},payload:z}),B=q({name:"KbSnapshotPublishedPayload",description:"Emitted when a KB snapshot is published.",fields:{snapshotId:{type:j.String_unsecure(),isOptional:!1},jurisdiction:{type:j.String_unsecure(),isOptional:!1},includedRuleVersionsCount:{type:j.Int_unsecure(),isOptional:!1}}}),L=k({meta:{key:"kb.snapshot.published",version:"1.0.0",description:"KB snapshot published.",stability:"experimental",owners:["@examples"],tags:["knowledge"]},payload:B});export{G as KbSourceIngestedEvent,L as KbSnapshotPublishedEvent,H as KbRuleVersionCreatedEvent,J as KbRuleVersionApprovedEvent};
@@ -1,35 +1 @@
1
- // src/example.ts
2
- import { defineExample } from "@contractspec/lib.contracts-spec";
3
- var example = defineExample({
4
- meta: {
5
- key: "versioned-knowledge-base",
6
- version: "1.0.0",
7
- title: "Versioned Knowledge Base",
8
- description: "Curated KB with immutable sources, reviewable rule versions, and published snapshots.",
9
- kind: "knowledge",
10
- visibility: "public",
11
- stability: "experimental",
12
- owners: ["@platform.core"],
13
- tags: ["knowledge", "versioning", "snapshots"]
14
- },
15
- docs: {
16
- rootDocId: "docs.examples.versioned-knowledge-base"
17
- },
18
- entrypoints: {
19
- packageName: "@contractspec/example.versioned-knowledge-base",
20
- feature: "./feature",
21
- contracts: "./contracts",
22
- handlers: "./handlers",
23
- docs: "./docs"
24
- },
25
- surfaces: {
26
- templates: true,
27
- sandbox: { enabled: true, modes: ["markdown", "specs", "builder"] },
28
- studio: { enabled: true, installable: true },
29
- mcp: { enabled: true }
30
- }
31
- });
32
- var example_default = example;
33
- export {
34
- example_default as default
35
- };
1
+ import{defineExample as g}from"@contractspec/lib.contracts-spec";var h=g({meta:{key:"versioned-knowledge-base",version:"1.0.0",title:"Versioned Knowledge Base",description:"Curated KB with immutable sources, reviewable rule versions, and published snapshots.",kind:"knowledge",visibility:"public",stability:"experimental",owners:["@platform.core"],tags:["knowledge","versioning","snapshots"]},docs:{rootDocId:"docs.examples.versioned-knowledge-base"},entrypoints:{packageName:"@contractspec/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}}}),q=h;export{q as default};
@@ -1,115 +1 @@
1
- // src/handlers/memory.handlers.ts
2
- function createMemoryKbStore() {
3
- return {
4
- sources: new Map,
5
- rules: new Map,
6
- ruleVersions: new Map,
7
- snapshots: new Map,
8
- nextRuleVersionNumberByRuleId: new Map
9
- };
10
- }
11
- function stableId(prefix, value) {
12
- return `${prefix}_${value.replace(/[^a-zA-Z0-9_-]/g, "_")}`;
13
- }
14
- function createMemoryKbHandlers(store) {
15
- async function createRule(rule) {
16
- store.rules.set(rule.id, rule);
17
- return rule;
18
- }
19
- async function ingestSource(input) {
20
- const id = stableId("src", `${input.jurisdiction}_${input.hash}`);
21
- const doc = { id, ...input };
22
- store.sources.set(id, doc);
23
- return doc;
24
- }
25
- async function upsertRuleVersion(input) {
26
- if (!input.sourceRefs.length) {
27
- throw new Error("SOURCE_REFS_REQUIRED");
28
- }
29
- const rule = store.rules.get(input.ruleId);
30
- if (!rule) {
31
- throw new Error("RULE_NOT_FOUND");
32
- }
33
- const next = (store.nextRuleVersionNumberByRuleId.get(input.ruleId) ?? 0) + 1;
34
- const id = stableId("rv", `${input.ruleId}_${next}`);
35
- const ruleVersion = {
36
- id,
37
- ruleId: input.ruleId,
38
- jurisdiction: rule.jurisdiction,
39
- topicKey: rule.topicKey,
40
- version: next.toString(),
41
- content: input.content,
42
- sourceRefs: input.sourceRefs,
43
- status: "draft",
44
- createdAt: new Date,
45
- approvedAt: undefined,
46
- approvedBy: undefined
47
- };
48
- store.ruleVersions.set(id, ruleVersion);
49
- return ruleVersion;
50
- }
51
- async function approveRuleVersion(input) {
52
- const existing = store.ruleVersions.get(input.ruleVersionId);
53
- if (!existing) {
54
- throw new Error("RULE_VERSION_NOT_FOUND");
55
- }
56
- const approved = {
57
- ...existing,
58
- status: "approved",
59
- approvedBy: input.approver,
60
- approvedAt: new Date
61
- };
62
- store.ruleVersions.set(approved.id, approved);
63
- return approved;
64
- }
65
- async function publishSnapshot(input) {
66
- const approved = [...store.ruleVersions.values()].filter((rv) => rv.status === "approved" && rv.jurisdiction === input.jurisdiction);
67
- if (approved.length === 0) {
68
- throw new Error("NO_APPROVED_RULES");
69
- }
70
- const includedRuleVersionIds = approved.map((rv) => rv.id).sort();
71
- const id = stableId("snap", `${input.jurisdiction}_${input.asOfDate.toISOString().slice(0, 10)}_${includedRuleVersionIds.length}`);
72
- const snapshot = {
73
- id,
74
- jurisdiction: input.jurisdiction,
75
- asOfDate: input.asOfDate,
76
- includedRuleVersionIds,
77
- publishedAt: new Date
78
- };
79
- store.snapshots.set(id, snapshot);
80
- return snapshot;
81
- }
82
- async function search(input) {
83
- const snapshot = store.snapshots.get(input.snapshotId);
84
- if (!snapshot) {
85
- throw new Error("SNAPSHOT_NOT_FOUND");
86
- }
87
- if (snapshot.jurisdiction !== input.jurisdiction) {
88
- throw new Error("JURISDICTION_MISMATCH");
89
- }
90
- const q = input.query.toLowerCase();
91
- const tokens = q.split(/\s+/).map((t) => t.trim()).filter(Boolean);
92
- const items = snapshot.includedRuleVersionIds.map((id) => store.ruleVersions.get(id)).filter((rv) => Boolean(rv)).filter((rv) => {
93
- if (tokens.length === 0)
94
- return true;
95
- const hay = rv.content.toLowerCase();
96
- return tokens.every((token) => hay.includes(token));
97
- }).map((rv) => ({
98
- ruleVersionId: rv.id,
99
- excerpt: rv.content.slice(0, 120)
100
- }));
101
- return { items };
102
- }
103
- return {
104
- createRule,
105
- ingestSource,
106
- upsertRuleVersion,
107
- approveRuleVersion,
108
- publishSnapshot,
109
- search
110
- };
111
- }
112
- export {
113
- createMemoryKbStore,
114
- createMemoryKbHandlers
115
- };
1
+ function m(){return{sources:new Map,rules:new Map,ruleVersions:new Map,snapshots:new Map,nextRuleVersionNumberByRuleId:new Map}}function c(s,u){return`${s}_${u.replace(/[^a-zA-Z0-9_-]/g,"_")}`}function h(s){async function u(e){return s.rules.set(e.id,e),e}async function a(e){let r=c("src",`${e.jurisdiction}_${e.hash}`),n={id:r,...e};return s.sources.set(r,n),n}async function d(e){if(!e.sourceRefs.length)throw Error("SOURCE_REFS_REQUIRED");let r=s.rules.get(e.ruleId);if(!r)throw Error("RULE_NOT_FOUND");let n=(s.nextRuleVersionNumberByRuleId.get(e.ruleId)??0)+1,i=c("rv",`${e.ruleId}_${n}`),o={id:i,ruleId:e.ruleId,jurisdiction:r.jurisdiction,topicKey:r.topicKey,version:n.toString(),content:e.content,sourceRefs:e.sourceRefs,status:"draft",createdAt:new Date,approvedAt:void 0,approvedBy:void 0};return s.ruleVersions.set(i,o),o}async function l(e){let r=s.ruleVersions.get(e.ruleVersionId);if(!r)throw Error("RULE_VERSION_NOT_FOUND");let n={...r,status:"approved",approvedBy:e.approver,approvedAt:new Date};return s.ruleVersions.set(n.id,n),n}async function p(e){let r=[...s.ruleVersions.values()].filter((t)=>t.status==="approved"&&t.jurisdiction===e.jurisdiction);if(r.length===0)throw Error("NO_APPROVED_RULES");let n=r.map((t)=>t.id).sort(),i=c("snap",`${e.jurisdiction}_${e.asOfDate.toISOString().slice(0,10)}_${n.length}`),o={id:i,jurisdiction:e.jurisdiction,asOfDate:e.asOfDate,includedRuleVersionIds:n,publishedAt:new Date};return s.snapshots.set(i,o),o}async function g(e){let r=s.snapshots.get(e.snapshotId);if(!r)throw Error("SNAPSHOT_NOT_FOUND");if(r.jurisdiction!==e.jurisdiction)throw Error("JURISDICTION_MISMATCH");let i=e.query.toLowerCase().split(/\s+/).map((t)=>t.trim()).filter(Boolean);return{items:r.includedRuleVersionIds.map((t)=>s.ruleVersions.get(t)).filter((t)=>Boolean(t)).filter((t)=>{if(i.length===0)return!0;let f=t.content.toLowerCase();return i.every((R)=>f.includes(R))}).map((t)=>({ruleVersionId:t.id,excerpt:t.content.slice(0,120)}))}}return{createRule:u,ingestSource:a,upsertRuleVersion:d,approveRuleVersion:l,publishSnapshot:p,search:g}}export{m as createMemoryKbStore,h as createMemoryKbHandlers};