@lssm/example.versioned-knowledge-base 0.0.0-canary-20251213172311 → 0.0.0-canary-20251215220103
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 +2 -2
- package/CHANGELOG.md +3 -3
- package/README.md +1 -0
- package/package.json +2 -2
- package/src/contracts/index.ts +0 -2
- package/src/contracts/kb.ts +10 -5
- package/src/docs/index.ts +0 -2
- package/src/docs/versioned-knowledge-base.docblock.ts +0 -2
- package/src/entities/index.ts +0 -2
- package/src/entities/models.ts +12 -7
- package/src/events.ts +16 -6
- package/src/example.ts +0 -2
- package/src/feature.ts +0 -2
- package/src/handlers/index.ts +0 -2
- package/src/handlers/memory.handlers.test.ts +5 -3
- package/src/handlers/memory.handlers.ts +25 -14
- package/src/index.ts +0 -2
- package/tsconfig.json +1 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/tsdown.config.js +1 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
$ bun build:bundle && bun build:types
|
|
2
2
|
$ tsdown
|
|
3
|
-
[34mℹ[39m tsdown [2mv0.17.
|
|
3
|
+
[34mℹ[39m tsdown [2mv0.17.4[22m powered by rolldown [2mv1.0.0-beta.53[22m
|
|
4
4
|
[34mℹ[39m config file: [4m/home/runner/work/contractspec/contractspec/packages/examples/versioned-knowledge-base/tsdown.config.js[24m
|
|
5
5
|
[34mℹ[39m entry: [34msrc/events.ts, src/example.ts, src/feature.ts, src/index.ts, src/contracts/index.ts, src/contracts/kb.ts, src/docs/index.ts, src/docs/versioned-knowledge-base.docblock.ts, src/entities/index.ts, src/entities/models.ts, src/handlers/index.ts, src/handlers/memory.handlers.ts[39m
|
|
6
6
|
[34mℹ[39m target: [34mesnext[39m
|
|
@@ -19,5 +19,5 @@ $ tsdown
|
|
|
19
19
|
[34mℹ[39m [2mdist/[22m[1mhandlers/index.js[22m [2m0.15 kB[22m [2m│ gzip: 0.10 kB[22m
|
|
20
20
|
[34mℹ[39m [2mdist/[22m[1mdocs/index.js[22m [2m0.05 kB[22m [2m│ gzip: 0.07 kB[22m
|
|
21
21
|
[34mℹ[39m 12 files, total: 15.02 kB
|
|
22
|
-
[32m✔[39m Build complete in [
|
|
22
|
+
[32m✔[39m Build complete in [32m77ms[39m
|
|
23
23
|
$ tsc --noEmit
|
package/CHANGELOG.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# @lssm/example.versioned-knowledge-base
|
|
2
2
|
|
|
3
|
-
## 0.0.0-canary-
|
|
3
|
+
## 0.0.0-canary-20251215220103
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
7
|
- Updated dependencies [3086383]
|
|
8
|
-
- @lssm/lib.contracts@0.0.0-canary-
|
|
9
|
-
- @lssm/lib.schema@0.0.0-canary-
|
|
8
|
+
- @lssm/lib.contracts@0.0.0-canary-20251215220103
|
|
9
|
+
- @lssm/lib.schema@0.0.0-canary-20251215220103
|
package/README.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lssm/example.versioned-knowledge-base",
|
|
3
|
-
"version": "0.0.0-canary-
|
|
3
|
+
"version": "0.0.0-canary-20251215220103",
|
|
4
4
|
"description": "Example: curated, versioned knowledge base with immutable sources, rule versions, and published snapshots.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@lssm/tool.tsdown": "workspace:*",
|
|
42
42
|
"@lssm/tool.typescript": "workspace:*",
|
|
43
|
-
"tsdown": "^0.17.
|
|
43
|
+
"tsdown": "^0.17.4",
|
|
44
44
|
"typescript": "^5.9.3"
|
|
45
45
|
},
|
|
46
46
|
"publishConfig": {
|
package/src/contracts/index.ts
CHANGED
package/src/contracts/kb.ts
CHANGED
|
@@ -35,7 +35,10 @@ const ApproveRuleVersionInput = defineSchemaModel({
|
|
|
35
35
|
name: 'KbApproveRuleVersionInput',
|
|
36
36
|
description: 'Approve a rule version (human verification).',
|
|
37
37
|
fields: {
|
|
38
|
-
ruleVersionId: {
|
|
38
|
+
ruleVersionId: {
|
|
39
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
40
|
+
isOptional: false,
|
|
41
|
+
},
|
|
39
42
|
approver: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
40
43
|
},
|
|
41
44
|
});
|
|
@@ -63,7 +66,10 @@ const SearchKbResultItem = defineSchemaModel({
|
|
|
63
66
|
name: 'KbSearchResultItem',
|
|
64
67
|
description: 'Search result referencing a specific rule version.',
|
|
65
68
|
fields: {
|
|
66
|
-
ruleVersionId: {
|
|
69
|
+
ruleVersionId: {
|
|
70
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
71
|
+
isOptional: false,
|
|
72
|
+
},
|
|
67
73
|
excerpt: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
68
74
|
},
|
|
69
75
|
});
|
|
@@ -153,7 +159,8 @@ export const KbPublishSnapshotContract = defineCommand({
|
|
|
153
159
|
tags: ['knowledge', 'snapshots', 'publishing'],
|
|
154
160
|
description: 'Publish a KB snapshot for a jurisdiction.',
|
|
155
161
|
goal: 'Create a stable snapshot that assistant answers can cite.',
|
|
156
|
-
context:
|
|
162
|
+
context:
|
|
163
|
+
'Publishing happens after approvals; snapshot is referenced by answers.',
|
|
157
164
|
},
|
|
158
165
|
io: {
|
|
159
166
|
input: PublishSnapshotInput,
|
|
@@ -187,5 +194,3 @@ export const KbSearchContract = defineQuery({
|
|
|
187
194
|
},
|
|
188
195
|
policy: { auth: 'user' },
|
|
189
196
|
});
|
|
190
|
-
|
|
191
|
-
|
package/src/docs/index.ts
CHANGED
package/src/entities/index.ts
CHANGED
package/src/entities/models.ts
CHANGED
|
@@ -2,7 +2,8 @@ import { ScalarTypeEnum, defineSchemaModel } from '@lssm/lib.schema';
|
|
|
2
2
|
|
|
3
3
|
export const SourceDocumentModel = defineSchemaModel({
|
|
4
4
|
name: 'SourceDocument',
|
|
5
|
-
description:
|
|
5
|
+
description:
|
|
6
|
+
'Immutable raw source document metadata referencing a stored file.',
|
|
6
7
|
fields: {
|
|
7
8
|
id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
8
9
|
jurisdiction: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
@@ -18,14 +19,18 @@ export const SourceRefModel = defineSchemaModel({
|
|
|
18
19
|
name: 'SourceRef',
|
|
19
20
|
description: 'Reference to a source document used to justify a rule version.',
|
|
20
21
|
fields: {
|
|
21
|
-
sourceDocumentId: {
|
|
22
|
+
sourceDocumentId: {
|
|
23
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
24
|
+
isOptional: false,
|
|
25
|
+
},
|
|
22
26
|
excerpt: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
23
27
|
},
|
|
24
28
|
});
|
|
25
29
|
|
|
26
30
|
export const RuleModel = defineSchemaModel({
|
|
27
31
|
name: 'Rule',
|
|
28
|
-
description:
|
|
32
|
+
description:
|
|
33
|
+
'Curated rule (stable identity) with topic + jurisdiction scope.',
|
|
29
34
|
fields: {
|
|
30
35
|
id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
31
36
|
jurisdiction: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
@@ -35,7 +40,8 @@ export const RuleModel = defineSchemaModel({
|
|
|
35
40
|
|
|
36
41
|
export const RuleVersionModel = defineSchemaModel({
|
|
37
42
|
name: 'RuleVersion',
|
|
38
|
-
description:
|
|
43
|
+
description:
|
|
44
|
+
'A versioned rule content with source references and approval status.',
|
|
39
45
|
fields: {
|
|
40
46
|
id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
41
47
|
ruleId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
@@ -53,7 +59,8 @@ export const RuleVersionModel = defineSchemaModel({
|
|
|
53
59
|
|
|
54
60
|
export const KBSnapshotModel = defineSchemaModel({
|
|
55
61
|
name: 'KBSnapshot',
|
|
56
|
-
description:
|
|
62
|
+
description:
|
|
63
|
+
'Published KB snapshot (as-of) referencing approved rule versions.',
|
|
57
64
|
fields: {
|
|
58
65
|
id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
59
66
|
jurisdiction: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
@@ -66,5 +73,3 @@ export const KBSnapshotModel = defineSchemaModel({
|
|
|
66
73
|
publishedAt: { type: ScalarTypeEnum.DateTime(), isOptional: false },
|
|
67
74
|
},
|
|
68
75
|
});
|
|
69
|
-
|
|
70
|
-
|
package/src/events.ts
CHANGED
|
@@ -5,7 +5,10 @@ const KbSourceIngestedPayload = defineSchemaModel({
|
|
|
5
5
|
name: 'KbSourceIngestedPayload',
|
|
6
6
|
description: 'Emitted when a source document is ingested.',
|
|
7
7
|
fields: {
|
|
8
|
-
sourceDocumentId: {
|
|
8
|
+
sourceDocumentId: {
|
|
9
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
10
|
+
isOptional: false,
|
|
11
|
+
},
|
|
9
12
|
jurisdiction: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
10
13
|
hash: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
11
14
|
},
|
|
@@ -22,7 +25,10 @@ const KbRuleVersionCreatedPayload = defineSchemaModel({
|
|
|
22
25
|
name: 'KbRuleVersionCreatedPayload',
|
|
23
26
|
description: 'Emitted when a rule version draft is created.',
|
|
24
27
|
fields: {
|
|
25
|
-
ruleVersionId: {
|
|
28
|
+
ruleVersionId: {
|
|
29
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
30
|
+
isOptional: false,
|
|
31
|
+
},
|
|
26
32
|
ruleId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
27
33
|
jurisdiction: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
28
34
|
status: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
@@ -40,7 +46,10 @@ const KbRuleVersionApprovedPayload = defineSchemaModel({
|
|
|
40
46
|
name: 'KbRuleVersionApprovedPayload',
|
|
41
47
|
description: 'Emitted when a rule version is approved.',
|
|
42
48
|
fields: {
|
|
43
|
-
ruleVersionId: {
|
|
49
|
+
ruleVersionId: {
|
|
50
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
51
|
+
isOptional: false,
|
|
52
|
+
},
|
|
44
53
|
approver: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
45
54
|
},
|
|
46
55
|
});
|
|
@@ -58,7 +67,10 @@ const KbSnapshotPublishedPayload = defineSchemaModel({
|
|
|
58
67
|
fields: {
|
|
59
68
|
snapshotId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
60
69
|
jurisdiction: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
61
|
-
includedRuleVersionsCount: {
|
|
70
|
+
includedRuleVersionsCount: {
|
|
71
|
+
type: ScalarTypeEnum.Int_unsecure(),
|
|
72
|
+
isOptional: false,
|
|
73
|
+
},
|
|
62
74
|
},
|
|
63
75
|
});
|
|
64
76
|
|
|
@@ -68,5 +80,3 @@ export const KbSnapshotPublishedEvent = defineEvent({
|
|
|
68
80
|
description: 'KB snapshot published.',
|
|
69
81
|
payload: KbSnapshotPublishedPayload,
|
|
70
82
|
});
|
|
71
|
-
|
|
72
|
-
|
package/src/example.ts
CHANGED
package/src/feature.ts
CHANGED
package/src/handlers/index.ts
CHANGED
|
@@ -51,7 +51,11 @@ describe('@lssm/example.versioned-knowledge-base memory handlers', () => {
|
|
|
51
51
|
const store = createMemoryKbStore();
|
|
52
52
|
const kb = createMemoryKbHandlers(store);
|
|
53
53
|
|
|
54
|
-
await kb.createRule({
|
|
54
|
+
await kb.createRule({
|
|
55
|
+
id: 'rule_eu',
|
|
56
|
+
jurisdiction: 'EU',
|
|
57
|
+
topicKey: 'topic',
|
|
58
|
+
});
|
|
55
59
|
const euDraft = await kb.upsertRuleVersion({
|
|
56
60
|
ruleId: 'rule_eu',
|
|
57
61
|
content: 'This is about reporting obligations',
|
|
@@ -75,5 +79,3 @@ describe('@lssm/example.versioned-knowledge-base memory handlers', () => {
|
|
|
75
79
|
expect(ok.items.map((i) => i.ruleVersionId)).toEqual([euDraft.id]);
|
|
76
80
|
});
|
|
77
81
|
});
|
|
78
|
-
|
|
79
|
-
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
interface SourceRef {
|
|
2
|
+
sourceDocumentId: string;
|
|
3
|
+
excerpt?: string;
|
|
4
|
+
}
|
|
5
|
+
interface SourceDocument {
|
|
3
6
|
id: string;
|
|
4
7
|
jurisdiction: string;
|
|
5
8
|
authority: string;
|
|
@@ -7,9 +10,13 @@ type SourceDocument = {
|
|
|
7
10
|
fetchedAt: Date;
|
|
8
11
|
hash: string;
|
|
9
12
|
fileId: string;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
+
}
|
|
14
|
+
interface Rule {
|
|
15
|
+
id: string;
|
|
16
|
+
jurisdiction: string;
|
|
17
|
+
topicKey: string;
|
|
18
|
+
}
|
|
19
|
+
interface RuleVersion {
|
|
13
20
|
id: string;
|
|
14
21
|
ruleId: string;
|
|
15
22
|
jurisdiction: string;
|
|
@@ -21,14 +28,14 @@ type RuleVersion = {
|
|
|
21
28
|
approvedBy?: string;
|
|
22
29
|
approvedAt?: Date;
|
|
23
30
|
createdAt: Date;
|
|
24
|
-
}
|
|
25
|
-
|
|
31
|
+
}
|
|
32
|
+
interface KBSnapshot {
|
|
26
33
|
id: string;
|
|
27
34
|
jurisdiction: string;
|
|
28
35
|
asOfDate: Date;
|
|
29
36
|
includedRuleVersionIds: string[];
|
|
30
37
|
publishedAt: Date;
|
|
31
|
-
}
|
|
38
|
+
}
|
|
32
39
|
|
|
33
40
|
export interface MemoryKbStore {
|
|
34
41
|
sources: Map<string, SourceDocument>;
|
|
@@ -68,7 +75,7 @@ export interface MemoryKbHandlers {
|
|
|
68
75
|
snapshotId: string;
|
|
69
76
|
jurisdiction: string;
|
|
70
77
|
query: string;
|
|
71
|
-
}): Promise<{ items:
|
|
78
|
+
}): Promise<{ items: { ruleVersionId: string; excerpt?: string }[] }>;
|
|
72
79
|
}
|
|
73
80
|
|
|
74
81
|
function stableId(prefix: string, value: string): string {
|
|
@@ -171,7 +178,7 @@ export function createMemoryKbHandlers(store: MemoryKbStore): MemoryKbHandlers {
|
|
|
171
178
|
snapshotId: string;
|
|
172
179
|
jurisdiction: string;
|
|
173
180
|
query: string;
|
|
174
|
-
}): Promise<{ items:
|
|
181
|
+
}): Promise<{ items: { ruleVersionId: string; excerpt?: string }[] }> {
|
|
175
182
|
const snapshot = store.snapshots.get(input.snapshotId);
|
|
176
183
|
if (!snapshot) {
|
|
177
184
|
throw new Error('SNAPSHOT_NOT_FOUND');
|
|
@@ -180,7 +187,10 @@ export function createMemoryKbHandlers(store: MemoryKbStore): MemoryKbHandlers {
|
|
|
180
187
|
throw new Error('JURISDICTION_MISMATCH');
|
|
181
188
|
}
|
|
182
189
|
const q = input.query.toLowerCase();
|
|
183
|
-
const tokens = q
|
|
190
|
+
const tokens = q
|
|
191
|
+
.split(/\s+/)
|
|
192
|
+
.map((t) => t.trim())
|
|
193
|
+
.filter(Boolean);
|
|
184
194
|
const items = snapshot.includedRuleVersionIds
|
|
185
195
|
.map((id) => store.ruleVersions.get(id))
|
|
186
196
|
.filter((rv): rv is RuleVersion => Boolean(rv))
|
|
@@ -189,7 +199,10 @@ export function createMemoryKbHandlers(store: MemoryKbStore): MemoryKbHandlers {
|
|
|
189
199
|
const hay = rv.content.toLowerCase();
|
|
190
200
|
return tokens.every((token) => hay.includes(token));
|
|
191
201
|
})
|
|
192
|
-
.map((rv) => ({
|
|
202
|
+
.map((rv) => ({
|
|
203
|
+
ruleVersionId: rv.id,
|
|
204
|
+
excerpt: rv.content.slice(0, 120),
|
|
205
|
+
}));
|
|
193
206
|
return { items };
|
|
194
207
|
}
|
|
195
208
|
|
|
@@ -202,5 +215,3 @@ export function createMemoryKbHandlers(store: MemoryKbStore): MemoryKbHandlers {
|
|
|
202
215
|
search,
|
|
203
216
|
};
|
|
204
217
|
}
|
|
205
|
-
|
|
206
|
-
|
package/src/index.ts
CHANGED
package/tsconfig.json
CHANGED