@contractspec/example.versioned-knowledge-base 0.0.0-canary-20260113162409
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$colon$bundle.log +47 -0
- package/.turbo/turbo-build.log +48 -0
- package/CHANGELOG.md +302 -0
- package/LICENSE +21 -0
- package/README.md +35 -0
- package/dist/docs/index.d.ts +1 -0
- package/dist/docs/index.js +1 -0
- package/dist/docs/versioned-knowledge-base.docblock.d.ts +1 -0
- package/dist/docs/versioned-knowledge-base.docblock.js +31 -0
- package/dist/docs/versioned-knowledge-base.docblock.js.map +1 -0
- package/dist/entities/index.d.ts +2 -0
- package/dist/entities/index.js +3 -0
- package/dist/entities/models.d.ts +139 -0
- package/dist/entities/models.d.ts.map +1 -0
- package/dist/entities/models.js +151 -0
- package/dist/entities/models.js.map +1 -0
- package/dist/events.d.ts +63 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +124 -0
- package/dist/events.js.map +1 -0
- package/dist/example.d.ts +7 -0
- package/dist/example.d.ts.map +1 -0
- package/dist/example.js +49 -0
- package/dist/example.js.map +1 -0
- package/dist/handlers/index.d.ts +2 -0
- package/dist/handlers/index.js +3 -0
- package/dist/handlers/memory.handlers.d.ts +78 -0
- package/dist/handlers/memory.handlers.d.ts.map +1 -0
- package/dist/handlers/memory.handlers.js +103 -0
- package/dist/handlers/memory.handlers.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +11 -0
- package/dist/operations/index.d.ts +2 -0
- package/dist/operations/index.js +3 -0
- package/dist/operations/kb.d.ts +267 -0
- package/dist/operations/kb.d.ts.map +1 -0
- package/dist/operations/kb.js +256 -0
- package/dist/operations/kb.js.map +1 -0
- package/dist/versioned-knowledge-base.feature.d.ts +7 -0
- package/dist/versioned-knowledge-base.feature.d.ts.map +1 -0
- package/dist/versioned-knowledge-base.feature.js +70 -0
- package/dist/versioned-knowledge-base.feature.js.map +1 -0
- package/example.ts +1 -0
- package/package.json +71 -0
- package/src/docs/index.ts +1 -0
- package/src/docs/versioned-knowledge-base.docblock.ts +29 -0
- package/src/entities/index.ts +1 -0
- package/src/entities/models.ts +75 -0
- package/src/events.ts +102 -0
- package/src/example.ts +34 -0
- package/src/handlers/index.ts +1 -0
- package/src/handlers/memory.handlers.test.ts +81 -0
- package/src/handlers/memory.handlers.ts +216 -0
- package/src/index.ts +13 -0
- package/src/operations/index.ts +1 -0
- package/src/operations/kb.ts +201 -0
- package/src/versioned-knowledge-base.feature.ts +34 -0
- package/tsconfig.json +19 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/tsdown.config.js +17 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { defineCommand, defineQuery } from '@contractspec/lib.contracts';
|
|
2
|
+
import { ScalarTypeEnum, defineSchemaModel } from '@contractspec/lib.schema';
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
KBSnapshotModel,
|
|
6
|
+
RuleVersionModel,
|
|
7
|
+
SourceDocumentModel,
|
|
8
|
+
SourceRefModel,
|
|
9
|
+
} from '../entities/models';
|
|
10
|
+
|
|
11
|
+
const IngestSourceInput = defineSchemaModel({
|
|
12
|
+
name: 'KbIngestSourceInput',
|
|
13
|
+
description: 'Ingest immutable source metadata referencing a stored file.',
|
|
14
|
+
fields: {
|
|
15
|
+
jurisdiction: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
16
|
+
authority: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
17
|
+
title: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
18
|
+
fetchedAt: { type: ScalarTypeEnum.DateTime(), isOptional: false },
|
|
19
|
+
hash: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
20
|
+
fileId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const UpsertRuleVersionInput = defineSchemaModel({
|
|
25
|
+
name: 'KbUpsertRuleVersionInput',
|
|
26
|
+
description: 'Create a new draft rule version (immutable history).',
|
|
27
|
+
fields: {
|
|
28
|
+
ruleId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
29
|
+
content: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
30
|
+
sourceRefs: { type: SourceRefModel, isArray: true, isOptional: false },
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const ApproveRuleVersionInput = defineSchemaModel({
|
|
35
|
+
name: 'KbApproveRuleVersionInput',
|
|
36
|
+
description: 'Approve a rule version (human verification).',
|
|
37
|
+
fields: {
|
|
38
|
+
ruleVersionId: {
|
|
39
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
40
|
+
isOptional: false,
|
|
41
|
+
},
|
|
42
|
+
approver: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
const PublishSnapshotInput = defineSchemaModel({
|
|
47
|
+
name: 'KbPublishSnapshotInput',
|
|
48
|
+
description: 'Publish a snapshot for a jurisdiction as-of a date.',
|
|
49
|
+
fields: {
|
|
50
|
+
jurisdiction: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
51
|
+
asOfDate: { type: ScalarTypeEnum.DateTime(), isOptional: false },
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
const SearchKbInput = defineSchemaModel({
|
|
56
|
+
name: 'KbSearchInput',
|
|
57
|
+
description: 'Search within a published snapshot.',
|
|
58
|
+
fields: {
|
|
59
|
+
snapshotId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
60
|
+
jurisdiction: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
61
|
+
query: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
const SearchKbResultItem = defineSchemaModel({
|
|
66
|
+
name: 'KbSearchResultItem',
|
|
67
|
+
description: 'Search result referencing a specific rule version.',
|
|
68
|
+
fields: {
|
|
69
|
+
ruleVersionId: {
|
|
70
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
71
|
+
isOptional: false,
|
|
72
|
+
},
|
|
73
|
+
excerpt: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
const SearchKbOutput = defineSchemaModel({
|
|
78
|
+
name: 'KbSearchOutput',
|
|
79
|
+
description: 'Search results constrained to snapshot + jurisdiction.',
|
|
80
|
+
fields: {
|
|
81
|
+
items: { type: SearchKbResultItem, isArray: true, isOptional: false },
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
export const KbIngestSourceContract = defineCommand({
|
|
86
|
+
meta: {
|
|
87
|
+
key: 'kb.ingestSource',
|
|
88
|
+
title: 'Ingest Source',
|
|
89
|
+
version: '1.0.0',
|
|
90
|
+
stability: 'experimental',
|
|
91
|
+
owners: ['@examples'],
|
|
92
|
+
tags: ['knowledge', 'sources', 'ingestion'],
|
|
93
|
+
description: 'Ingest immutable source document metadata.',
|
|
94
|
+
goal: 'Store traceable source documents for curated KB.',
|
|
95
|
+
context: 'Called when an admin uploads/records authoritative sources.',
|
|
96
|
+
},
|
|
97
|
+
io: {
|
|
98
|
+
input: IngestSourceInput,
|
|
99
|
+
output: SourceDocumentModel,
|
|
100
|
+
},
|
|
101
|
+
policy: { auth: 'user' },
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
export const KbUpsertRuleVersionContract = defineCommand({
|
|
105
|
+
meta: {
|
|
106
|
+
key: 'kb.upsertRuleVersion',
|
|
107
|
+
title: 'Upsert Rule Version',
|
|
108
|
+
version: '1.0.0',
|
|
109
|
+
stability: 'experimental',
|
|
110
|
+
owners: ['@examples'],
|
|
111
|
+
tags: ['knowledge', 'rules', 'versioning'],
|
|
112
|
+
description: 'Create a new draft rule version with source references.',
|
|
113
|
+
goal: 'Propose curated knowledge updates with traceability.',
|
|
114
|
+
context: 'Automation or curators propose draft rule versions.',
|
|
115
|
+
},
|
|
116
|
+
io: {
|
|
117
|
+
input: UpsertRuleVersionInput,
|
|
118
|
+
output: RuleVersionModel,
|
|
119
|
+
errors: {
|
|
120
|
+
SOURCE_REFS_REQUIRED: {
|
|
121
|
+
description: 'Rule version must cite at least one sourceRef',
|
|
122
|
+
http: 400,
|
|
123
|
+
gqlCode: 'SOURCE_REFS_REQUIRED',
|
|
124
|
+
when: 'sourceRefs is empty',
|
|
125
|
+
},
|
|
126
|
+
RULE_NOT_FOUND: {
|
|
127
|
+
description: 'Rule does not exist',
|
|
128
|
+
http: 404,
|
|
129
|
+
gqlCode: 'RULE_NOT_FOUND',
|
|
130
|
+
when: 'ruleId is unknown',
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
policy: { auth: 'user' },
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
export const KbApproveRuleVersionContract = defineCommand({
|
|
138
|
+
meta: {
|
|
139
|
+
key: 'kb.approveRuleVersion',
|
|
140
|
+
title: 'Approve Rule Version',
|
|
141
|
+
version: '1.0.0',
|
|
142
|
+
stability: 'experimental',
|
|
143
|
+
owners: ['@examples'],
|
|
144
|
+
tags: ['knowledge', 'rules', 'approval'],
|
|
145
|
+
description: 'Approve a draft rule version.',
|
|
146
|
+
goal: 'Human verification step before publishing snapshots.',
|
|
147
|
+
context: 'Curators/experts approve proposed KB changes.',
|
|
148
|
+
},
|
|
149
|
+
io: {
|
|
150
|
+
input: ApproveRuleVersionInput,
|
|
151
|
+
output: RuleVersionModel,
|
|
152
|
+
},
|
|
153
|
+
policy: { auth: 'user' },
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
export const KbPublishSnapshotContract = defineCommand({
|
|
157
|
+
meta: {
|
|
158
|
+
key: 'kb.publishSnapshot',
|
|
159
|
+
title: 'Publish Snapshot',
|
|
160
|
+
version: '1.0.0',
|
|
161
|
+
stability: 'experimental',
|
|
162
|
+
owners: ['@examples'],
|
|
163
|
+
tags: ['knowledge', 'snapshots', 'publishing'],
|
|
164
|
+
description: 'Publish a KB snapshot for a jurisdiction.',
|
|
165
|
+
goal: 'Create a stable snapshot that assistant answers can cite.',
|
|
166
|
+
context:
|
|
167
|
+
'Publishing happens after approvals; snapshot is referenced by answers.',
|
|
168
|
+
},
|
|
169
|
+
io: {
|
|
170
|
+
input: PublishSnapshotInput,
|
|
171
|
+
output: KBSnapshotModel,
|
|
172
|
+
errors: {
|
|
173
|
+
NO_APPROVED_RULES: {
|
|
174
|
+
description: 'No approved rule versions available to publish',
|
|
175
|
+
http: 409,
|
|
176
|
+
gqlCode: 'NO_APPROVED_RULES',
|
|
177
|
+
when: 'jurisdiction has zero approved rule versions',
|
|
178
|
+
},
|
|
179
|
+
},
|
|
180
|
+
},
|
|
181
|
+
policy: { auth: 'user' },
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
export const KbSearchContract = defineQuery({
|
|
185
|
+
meta: {
|
|
186
|
+
key: 'kb.search',
|
|
187
|
+
title: 'Search KB',
|
|
188
|
+
version: '1.0.0',
|
|
189
|
+
stability: 'experimental',
|
|
190
|
+
owners: ['@examples'],
|
|
191
|
+
tags: ['knowledge', 'search', 'snapshots'],
|
|
192
|
+
description: 'Search within a published KB snapshot.',
|
|
193
|
+
goal: 'Provide scoped retrieval for assistant answers.',
|
|
194
|
+
context: 'Assistant queries curated rules from a specific snapshot.',
|
|
195
|
+
},
|
|
196
|
+
io: {
|
|
197
|
+
input: SearchKbInput,
|
|
198
|
+
output: SearchKbOutput,
|
|
199
|
+
},
|
|
200
|
+
policy: { auth: 'user' },
|
|
201
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { defineFeature } from '@contractspec/lib.contracts';
|
|
2
|
+
|
|
3
|
+
export const VersionedKnowledgeBaseFeature = defineFeature({
|
|
4
|
+
meta: {
|
|
5
|
+
key: 'versioned-knowledge-base',
|
|
6
|
+
version: '1.0.0',
|
|
7
|
+
title: 'Versioned Knowledge Base',
|
|
8
|
+
description:
|
|
9
|
+
'Curated KB with immutable sources, rule versions, and published snapshots.',
|
|
10
|
+
domain: 'knowledge',
|
|
11
|
+
owners: ['@examples'],
|
|
12
|
+
tags: ['knowledge', 'versioning', 'snapshots'],
|
|
13
|
+
stability: 'experimental',
|
|
14
|
+
},
|
|
15
|
+
operations: [
|
|
16
|
+
{ key: 'kb.ingestSource', version: '1.0.0' },
|
|
17
|
+
{ key: 'kb.upsertRuleVersion', version: '1.0.0' },
|
|
18
|
+
{ key: 'kb.approveRuleVersion', version: '1.0.0' },
|
|
19
|
+
{ key: 'kb.publishSnapshot', version: '1.0.0' },
|
|
20
|
+
{ key: 'kb.search', version: '1.0.0' },
|
|
21
|
+
],
|
|
22
|
+
events: [
|
|
23
|
+
{ key: 'kb.source.ingested', version: '1.0.0' },
|
|
24
|
+
{ key: 'kb.ruleVersion.created', version: '1.0.0' },
|
|
25
|
+
{ key: 'kb.ruleVersion.approved', version: '1.0.0' },
|
|
26
|
+
{ key: 'kb.snapshot.published', version: '1.0.0' },
|
|
27
|
+
],
|
|
28
|
+
presentations: [],
|
|
29
|
+
opToPresentation: [],
|
|
30
|
+
presentationsTargets: [],
|
|
31
|
+
capabilities: {
|
|
32
|
+
requires: [{ key: 'knowledge', version: '1.0.0' }],
|
|
33
|
+
},
|
|
34
|
+
});
|
package/tsconfig.json
ADDED