@contractspec/example.versioned-knowledge-base 1.57.0 → 1.59.0
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 +52 -52
- package/.turbo/turbo-prebuild.log +1 -0
- package/CHANGELOG.md +25 -0
- package/dist/browser/docs/index.js +44 -0
- package/dist/browser/docs/versioned-knowledge-base.docblock.js +44 -0
- package/dist/browser/entities/index.js +74 -0
- package/dist/browser/entities/models.js +74 -0
- package/dist/browser/events.js +101 -0
- package/dist/browser/example.js +35 -0
- package/dist/browser/handlers/index.js +115 -0
- package/dist/browser/handlers/memory.handlers.js +115 -0
- package/dist/browser/index.js +586 -0
- package/dist/browser/operations/index.js +257 -0
- package/dist/browser/operations/kb.js +257 -0
- package/dist/browser/versioned-knowledge-base.feature.js +36 -0
- package/dist/docs/index.d.ts +2 -1
- package/dist/docs/index.d.ts.map +1 -0
- package/dist/docs/index.js +45 -1
- package/dist/docs/versioned-knowledge-base.docblock.d.ts +2 -1
- package/dist/docs/versioned-knowledge-base.docblock.d.ts.map +1 -0
- package/dist/docs/versioned-knowledge-base.docblock.js +42 -28
- package/dist/entities/index.d.ts +2 -2
- package/dist/entities/index.d.ts.map +1 -0
- package/dist/entities/index.js +75 -3
- package/dist/entities/models.d.ts +127 -132
- package/dist/entities/models.d.ts.map +1 -1
- package/dist/entities/models.js +69 -145
- package/dist/events.d.ts +52 -58
- package/dist/events.d.ts.map +1 -1
- package/dist/events.js +92 -114
- package/dist/example.d.ts +2 -6
- package/dist/example.d.ts.map +1 -1
- package/dist/example.js +34 -46
- package/dist/handlers/index.d.ts +2 -2
- package/dist/handlers/index.d.ts.map +1 -0
- package/dist/handlers/index.js +116 -3
- package/dist/handlers/memory.handlers.d.ts +62 -64
- package/dist/handlers/memory.handlers.d.ts.map +1 -1
- package/dist/handlers/memory.handlers.js +110 -97
- package/dist/handlers/memory.handlers.test.d.ts +2 -0
- package/dist/handlers/memory.handlers.test.d.ts.map +1 -0
- package/dist/index.d.ts +13 -9
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +587 -11
- package/dist/node/docs/index.js +44 -0
- package/dist/node/docs/versioned-knowledge-base.docblock.js +44 -0
- package/dist/node/entities/index.js +74 -0
- package/dist/node/entities/models.js +74 -0
- package/dist/node/events.js +101 -0
- package/dist/node/example.js +35 -0
- package/dist/node/handlers/index.js +115 -0
- package/dist/node/handlers/memory.handlers.js +115 -0
- package/dist/node/index.js +586 -0
- package/dist/node/operations/index.js +257 -0
- package/dist/node/operations/kb.js +257 -0
- package/dist/node/versioned-knowledge-base.feature.js +36 -0
- package/dist/operations/index.d.ts +2 -2
- package/dist/operations/index.d.ts.map +1 -0
- package/dist/operations/index.js +257 -2
- package/dist/operations/kb.d.ts +252 -258
- package/dist/operations/kb.d.ts.map +1 -1
- package/dist/operations/kb.js +246 -244
- package/dist/versioned-knowledge-base.feature.d.ts +1 -6
- package/dist/versioned-knowledge-base.feature.d.ts.map +1 -1
- package/dist/versioned-knowledge-base.feature.js +35 -68
- package/package.json +141 -38
- package/tsdown.config.js +1 -2
- package/.turbo/turbo-build$colon$bundle.log +0 -52
- package/dist/docs/versioned-knowledge-base.docblock.js.map +0 -1
- package/dist/entities/models.js.map +0 -1
- package/dist/events.js.map +0 -1
- package/dist/example.js.map +0 -1
- package/dist/handlers/memory.handlers.js.map +0 -1
- package/dist/operations/kb.js.map +0 -1
- package/dist/versioned-knowledge-base.feature.js.map +0 -1
- package/tsconfig.tsbuildinfo +0 -1
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
$ bun
|
|
2
|
-
$
|
|
3
|
-
$
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
[34mℹ[39m target: [34mesnext[39m
|
|
8
|
-
[34mℹ[39m tsconfig: [34mtsconfig.json[39m
|
|
9
|
-
[34mℹ[39m Build start
|
|
10
|
-
[34mℹ[39m [2mdist/[22m[1moperations/kb.js[22m [2m6.46 kB[22m [2m│ gzip: 1.58 kB[22m
|
|
11
|
-
[34mℹ[39m [2mdist/[22m[1mhandlers/memory.handlers.js[22m [2m3.45 kB[22m [2m│ gzip: 1.20 kB[22m
|
|
12
|
-
[34mℹ[39m [2mdist/[22m[1mentities/models.js[22m [2m3.39 kB[22m [2m│ gzip: 0.67 kB[22m
|
|
13
|
-
[34mℹ[39m [2mdist/[22m[1mevents.js[22m [2m3.15 kB[22m [2m│ gzip: 0.67 kB[22m
|
|
14
|
-
[34mℹ[39m [2mdist/[22m[1mdocs/versioned-knowledge-base.docblock.js[22m [2m1.52 kB[22m [2m│ gzip: 0.66 kB[22m
|
|
15
|
-
[34mℹ[39m [2mdist/[22m[1mversioned-knowledge-base.feature.js[22m [2m1.34 kB[22m [2m│ gzip: 0.50 kB[22m
|
|
16
|
-
[34mℹ[39m [2mdist/[22m[1mindex.js[22m [2m1.14 kB[22m [2m│ gzip: 0.34 kB[22m
|
|
17
|
-
[34mℹ[39m [2mdist/[22m[1mexample.js[22m [2m1.03 kB[22m [2m│ gzip: 0.53 kB[22m
|
|
18
|
-
[34mℹ[39m [2mdist/[22m[1moperations/index.js[22m [2m0.29 kB[22m [2m│ gzip: 0.13 kB[22m
|
|
19
|
-
[34mℹ[39m [2mdist/[22m[1mentities/index.js[22m [2m0.21 kB[22m [2m│ gzip: 0.11 kB[22m
|
|
20
|
-
[34mℹ[39m [2mdist/[22m[1mhandlers/index.js[22m [2m0.14 kB[22m [2m│ gzip: 0.09 kB[22m
|
|
21
|
-
[34mℹ[39m [2mdist/[22m[1mdocs/index.js[22m [2m0.05 kB[22m [2m│ gzip: 0.07 kB[22m
|
|
22
|
-
[34mℹ[39m [2mdist/[22moperations/kb.js.map [2m9.51 kB[22m [2m│ gzip: 2.10 kB[22m
|
|
23
|
-
[34mℹ[39m [2mdist/[22mhandlers/memory.handlers.js.map [2m8.44 kB[22m [2m│ gzip: 2.43 kB[22m
|
|
24
|
-
[34mℹ[39m [2mdist/[22mentities/models.js.map [2m5.09 kB[22m [2m│ gzip: 1.00 kB[22m
|
|
25
|
-
[34mℹ[39m [2mdist/[22mevents.js.map [2m4.72 kB[22m [2m│ gzip: 0.98 kB[22m
|
|
26
|
-
[34mℹ[39m [2mdist/[22mdocs/versioned-knowledge-base.docblock.js.map [2m2.02 kB[22m [2m│ gzip: 0.84 kB[22m
|
|
27
|
-
[34mℹ[39m [2mdist/[22mversioned-knowledge-base.feature.js.map [2m1.94 kB[22m [2m│ gzip: 0.73 kB[22m
|
|
28
|
-
[34mℹ[39m [2mdist/[22mexample.js.map [2m1.52 kB[22m [2m│ gzip: 0.73 kB[22m
|
|
29
|
-
[34mℹ[39m [2mdist/[22mhandlers/memory.handlers.d.ts.map [2m1.28 kB[22m [2m│ gzip: 0.46 kB[22m
|
|
30
|
-
[34mℹ[39m [2mdist/[22moperations/kb.d.ts.map [2m0.74 kB[22m [2m│ gzip: 0.25 kB[22m
|
|
31
|
-
[34mℹ[39m [2mdist/[22mentities/models.d.ts.map [2m0.43 kB[22m [2m│ gzip: 0.20 kB[22m
|
|
32
|
-
[34mℹ[39m [2mdist/[22mevents.d.ts.map [2m0.40 kB[22m [2m│ gzip: 0.18 kB[22m
|
|
33
|
-
[34mℹ[39m [2mdist/[22mversioned-knowledge-base.feature.d.ts.map [2m0.18 kB[22m [2m│ gzip: 0.14 kB[22m
|
|
34
|
-
[34mℹ[39m [2mdist/[22mexample.d.ts.map [2m0.13 kB[22m [2m│ gzip: 0.13 kB[22m
|
|
35
|
-
[34mℹ[39m [2mdist/[22m[32m[1moperations/kb.d.ts[22m[39m [2m7.68 kB[22m [2m│ gzip: 0.62 kB[22m
|
|
36
|
-
[34mℹ[39m [2mdist/[22m[32m[1mentities/models.d.ts[22m[39m [2m3.84 kB[22m [2m│ gzip: 0.51 kB[22m
|
|
37
|
-
[34mℹ[39m [2mdist/[22m[32m[1mevents.d.ts[22m[39m [2m2.14 kB[22m [2m│ gzip: 0.39 kB[22m
|
|
38
|
-
[34mℹ[39m [2mdist/[22m[32m[1mhandlers/memory.handlers.d.ts[22m[39m [2m1.94 kB[22m [2m│ gzip: 0.61 kB[22m
|
|
39
|
-
[34mℹ[39m [2mdist/[22m[32m[1mindex.d.ts[22m[39m [2m1.18 kB[22m [2m│ gzip: 0.35 kB[22m
|
|
40
|
-
[34mℹ[39m [2mdist/[22m[32m[1mversioned-knowledge-base.feature.d.ts[22m[39m [2m0.34 kB[22m [2m│ gzip: 0.20 kB[22m
|
|
41
|
-
[34mℹ[39m [2mdist/[22m[32m[1moperations/index.d.ts[22m[39m [2m0.29 kB[22m [2m│ gzip: 0.13 kB[22m
|
|
42
|
-
[34mℹ[39m [2mdist/[22m[32m[1mexample.d.ts[22m[39m [2m0.25 kB[22m [2m│ gzip: 0.17 kB[22m
|
|
43
|
-
[34mℹ[39m [2mdist/[22m[32m[1mentities/index.d.ts[22m[39m [2m0.21 kB[22m [2m│ gzip: 0.11 kB[22m
|
|
44
|
-
[34mℹ[39m [2mdist/[22m[32m[1mhandlers/index.d.ts[22m[39m [2m0.20 kB[22m [2m│ gzip: 0.10 kB[22m
|
|
45
|
-
[34mℹ[39m [2mdist/[22m[32m[1mdocs/index.d.ts[22m[39m [2m0.01 kB[22m [2m│ gzip: 0.03 kB[22m
|
|
46
|
-
[33m[PLUGIN_TIMINGS] Warning:[0m Your build spent significant time in plugins. Here is a breakdown:
|
|
47
|
-
[34mℹ[39m [2mdist/[22m[32m[1mdocs/versioned-knowledge-base.docblock.d.ts[22m[39m [2m0.01 kB[22m [2m│ gzip: 0.03 kB[22m
|
|
48
|
-
- tsdown:external (71%)
|
|
49
|
-
[34mℹ[39m 37 files, total: 76.66 kB
|
|
50
|
-
- rolldown-plugin-dts:generate (27%)
|
|
51
|
-
See https://rolldown.rs/options/checks#plugintimings for more details.
|
|
1
|
+
$ contractspec-bun-build prebuild
|
|
2
|
+
$ bun run prebuild && bun run build:bundle && bun run build:types
|
|
3
|
+
$ contractspec-bun-build prebuild
|
|
4
|
+
$ contractspec-bun-build transpile
|
|
5
|
+
[contractspec-bun-build] transpile target=bun root=src entries=12
|
|
6
|
+
Bundled 12 modules in 30ms
|
|
52
7
|
|
|
53
|
-
|
|
8
|
+
docs/index.js 1.51 KB (entry point)
|
|
9
|
+
./index.js 20.10 KB (entry point)
|
|
10
|
+
operations/index.js 9.55 KB (entry point)
|
|
11
|
+
operations/kb.js 9.55 KB (entry point)
|
|
12
|
+
./versioned-knowledge-base.feature.js 1.22 KB (entry point)
|
|
13
|
+
docs/versioned-knowledge-base.docblock.js 1.51 KB (entry point)
|
|
14
|
+
entities/index.js 3.22 KB (entry point)
|
|
15
|
+
entities/models.js 3.22 KB (entry point)
|
|
16
|
+
./events.js 3.17 KB (entry point)
|
|
17
|
+
./example.js 1.0 KB (entry point)
|
|
18
|
+
handlers/index.js 3.56 KB (entry point)
|
|
19
|
+
handlers/memory.handlers.js 3.56 KB (entry point)
|
|
20
|
+
|
|
21
|
+
[contractspec-bun-build] transpile target=node root=src entries=12
|
|
22
|
+
Bundled 12 modules in 27ms
|
|
23
|
+
|
|
24
|
+
docs/index.js 1.50 KB (entry point)
|
|
25
|
+
./index.js 20.1 KB (entry point)
|
|
26
|
+
operations/index.js 9.54 KB (entry point)
|
|
27
|
+
operations/kb.js 9.54 KB (entry point)
|
|
28
|
+
./versioned-knowledge-base.feature.js 1.21 KB (entry point)
|
|
29
|
+
docs/versioned-knowledge-base.docblock.js 1.50 KB (entry point)
|
|
30
|
+
entities/index.js 3.22 KB (entry point)
|
|
31
|
+
entities/models.js 3.22 KB (entry point)
|
|
32
|
+
./events.js 3.16 KB (entry point)
|
|
33
|
+
./example.js 1.0 KB (entry point)
|
|
34
|
+
handlers/index.js 3.55 KB (entry point)
|
|
35
|
+
handlers/memory.handlers.js 3.55 KB (entry point)
|
|
36
|
+
|
|
37
|
+
[contractspec-bun-build] transpile target=browser root=src entries=12
|
|
38
|
+
Bundled 12 modules in 37ms
|
|
39
|
+
|
|
40
|
+
docs/index.js 1.50 KB (entry point)
|
|
41
|
+
./index.js 20.1 KB (entry point)
|
|
42
|
+
operations/index.js 9.54 KB (entry point)
|
|
43
|
+
operations/kb.js 9.54 KB (entry point)
|
|
44
|
+
./versioned-knowledge-base.feature.js 1.21 KB (entry point)
|
|
45
|
+
docs/versioned-knowledge-base.docblock.js 1.50 KB (entry point)
|
|
46
|
+
entities/index.js 3.22 KB (entry point)
|
|
47
|
+
entities/models.js 3.22 KB (entry point)
|
|
48
|
+
./events.js 3.16 KB (entry point)
|
|
49
|
+
./example.js 1.0 KB (entry point)
|
|
50
|
+
handlers/index.js 3.55 KB (entry point)
|
|
51
|
+
handlers/memory.handlers.js 3.55 KB (entry point)
|
|
52
|
+
|
|
53
|
+
$ contractspec-bun-build types
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
$ contractspec-bun-build prebuild
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
# @contractspec/example.versioned-knowledge-base
|
|
2
2
|
|
|
3
|
+
## 1.59.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 1a0cf44: fix: publishConfig not supported by bun
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [1a0cf44]
|
|
12
|
+
- @contractspec/lib.contracts@1.59.0
|
|
13
|
+
- @contractspec/lib.schema@1.59.0
|
|
14
|
+
|
|
15
|
+
## 1.58.0
|
|
16
|
+
|
|
17
|
+
### Minor Changes
|
|
18
|
+
|
|
19
|
+
- d1f0fd0: chore: Migrate non-app package builds from tsdown to shared Bun tooling, add `@contractspec/tool.bun`, and standardize `prebuild`/`build`/`typecheck` with platform-aware exports and `tsc` declaration emission into `dist`.
|
|
20
|
+
|
|
21
|
+
### Patch Changes
|
|
22
|
+
|
|
23
|
+
- Updated dependencies [d1f0fd0]
|
|
24
|
+
- Updated dependencies [4355a9e]
|
|
25
|
+
- @contractspec/lib.contracts@1.58.0
|
|
26
|
+
- @contractspec/lib.schema@1.58.0
|
|
27
|
+
|
|
3
28
|
## 1.57.0
|
|
4
29
|
|
|
5
30
|
### Minor Changes
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// src/docs/versioned-knowledge-base.docblock.ts
|
|
2
|
+
import { registerDocBlocks } from "@contractspec/lib.contracts/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
|
|
13
|
+
- Separates raw sources from curated knowledge.
|
|
14
|
+
- Ensures assistant answers cite a published snapshot.
|
|
15
|
+
- Makes change review and safe regeneration possible.
|
|
16
|
+
|
|
17
|
+
## Core invariants
|
|
18
|
+
- Sources are immutable and content-addressed (hash).
|
|
19
|
+
- 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
|
|
31
|
+
- kb.ingestSource
|
|
32
|
+
- kb.upsertRuleVersion
|
|
33
|
+
- kb.approveRuleVersion
|
|
34
|
+
- kb.publishSnapshot
|
|
35
|
+
- kb.search
|
|
36
|
+
|
|
37
|
+
## Events
|
|
38
|
+
- kb.source.ingested
|
|
39
|
+
- kb.ruleVersion.created
|
|
40
|
+
- kb.ruleVersion.approved
|
|
41
|
+
- kb.snapshot.published`
|
|
42
|
+
}
|
|
43
|
+
];
|
|
44
|
+
registerDocBlocks(docBlocks);
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// src/docs/versioned-knowledge-base.docblock.ts
|
|
2
|
+
import { registerDocBlocks } from "@contractspec/lib.contracts/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
|
|
13
|
+
- Separates raw sources from curated knowledge.
|
|
14
|
+
- Ensures assistant answers cite a published snapshot.
|
|
15
|
+
- Makes change review and safe regeneration possible.
|
|
16
|
+
|
|
17
|
+
## Core invariants
|
|
18
|
+
- Sources are immutable and content-addressed (hash).
|
|
19
|
+
- 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
|
|
31
|
+
- kb.ingestSource
|
|
32
|
+
- kb.upsertRuleVersion
|
|
33
|
+
- kb.approveRuleVersion
|
|
34
|
+
- kb.publishSnapshot
|
|
35
|
+
- kb.search
|
|
36
|
+
|
|
37
|
+
## Events
|
|
38
|
+
- kb.source.ingested
|
|
39
|
+
- kb.ruleVersion.created
|
|
40
|
+
- kb.ruleVersion.approved
|
|
41
|
+
- kb.snapshot.published`
|
|
42
|
+
}
|
|
43
|
+
];
|
|
44
|
+
registerDocBlocks(docBlocks);
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// src/entities/models.ts
|
|
2
|
+
import { ScalarTypeEnum, defineSchemaModel } 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
|
+
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// src/entities/models.ts
|
|
2
|
+
import { ScalarTypeEnum, defineSchemaModel } 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
|
+
};
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
// src/events.ts
|
|
2
|
+
import { defineEvent, defineSchemaModel } from "@contractspec/lib.contracts";
|
|
3
|
+
import { 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
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// src/example.ts
|
|
2
|
+
import { defineExample } from "@contractspec/lib.contracts";
|
|
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
|
+
};
|
|
@@ -0,0 +1,115 @@
|
|
|
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
|
+
};
|