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