@contractspec/example.versioned-knowledge-base 1.56.1 → 1.58.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 +53 -48
- package/.turbo/turbo-prebuild.log +1 -0
- package/CHANGELOG.md +30 -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 +33 -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 -47
- 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/dist/operations/index.js
CHANGED
|
@@ -1,3 +1,258 @@
|
|
|
1
|
-
|
|
1
|
+
// @bun
|
|
2
|
+
// src/entities/models.ts
|
|
3
|
+
import { ScalarTypeEnum, defineSchemaModel } 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
|
+
});
|
|
2
69
|
|
|
3
|
-
|
|
70
|
+
// src/operations/kb.ts
|
|
71
|
+
import { defineCommand, defineQuery } from "@contractspec/lib.contracts";
|
|
72
|
+
import { ScalarTypeEnum as ScalarTypeEnum2, defineSchemaModel as defineSchemaModel2 } from "@contractspec/lib.schema";
|
|
73
|
+
var IngestSourceInput = defineSchemaModel2({
|
|
74
|
+
name: "KbIngestSourceInput",
|
|
75
|
+
description: "Ingest immutable source metadata referencing a stored file.",
|
|
76
|
+
fields: {
|
|
77
|
+
jurisdiction: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
|
|
78
|
+
authority: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
|
|
79
|
+
title: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
|
|
80
|
+
fetchedAt: { type: ScalarTypeEnum2.DateTime(), isOptional: false },
|
|
81
|
+
hash: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
|
|
82
|
+
fileId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false }
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
var UpsertRuleVersionInput = defineSchemaModel2({
|
|
86
|
+
name: "KbUpsertRuleVersionInput",
|
|
87
|
+
description: "Create a new draft rule version (immutable history).",
|
|
88
|
+
fields: {
|
|
89
|
+
ruleId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
|
|
90
|
+
content: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
|
|
91
|
+
sourceRefs: { type: SourceRefModel, isArray: true, isOptional: false }
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
var ApproveRuleVersionInput = defineSchemaModel2({
|
|
95
|
+
name: "KbApproveRuleVersionInput",
|
|
96
|
+
description: "Approve a rule version (human verification).",
|
|
97
|
+
fields: {
|
|
98
|
+
ruleVersionId: {
|
|
99
|
+
type: ScalarTypeEnum2.String_unsecure(),
|
|
100
|
+
isOptional: false
|
|
101
|
+
},
|
|
102
|
+
approver: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false }
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
var PublishSnapshotInput = defineSchemaModel2({
|
|
106
|
+
name: "KbPublishSnapshotInput",
|
|
107
|
+
description: "Publish a snapshot for a jurisdiction as-of a date.",
|
|
108
|
+
fields: {
|
|
109
|
+
jurisdiction: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
|
|
110
|
+
asOfDate: { type: ScalarTypeEnum2.DateTime(), isOptional: false }
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
var SearchKbInput = defineSchemaModel2({
|
|
114
|
+
name: "KbSearchInput",
|
|
115
|
+
description: "Search within a published snapshot.",
|
|
116
|
+
fields: {
|
|
117
|
+
snapshotId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
|
|
118
|
+
jurisdiction: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
|
|
119
|
+
query: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false }
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
var SearchKbResultItem = defineSchemaModel2({
|
|
123
|
+
name: "KbSearchResultItem",
|
|
124
|
+
description: "Search result referencing a specific rule version.",
|
|
125
|
+
fields: {
|
|
126
|
+
ruleVersionId: {
|
|
127
|
+
type: ScalarTypeEnum2.String_unsecure(),
|
|
128
|
+
isOptional: false
|
|
129
|
+
},
|
|
130
|
+
excerpt: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true }
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
var SearchKbOutput = defineSchemaModel2({
|
|
134
|
+
name: "KbSearchOutput",
|
|
135
|
+
description: "Search results constrained to snapshot + jurisdiction.",
|
|
136
|
+
fields: {
|
|
137
|
+
items: { type: SearchKbResultItem, isArray: true, isOptional: false }
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
var KbIngestSourceContract = defineCommand({
|
|
141
|
+
meta: {
|
|
142
|
+
key: "kb.ingestSource",
|
|
143
|
+
title: "Ingest Source",
|
|
144
|
+
version: "1.0.0",
|
|
145
|
+
stability: "experimental",
|
|
146
|
+
owners: ["@examples"],
|
|
147
|
+
tags: ["knowledge", "sources", "ingestion"],
|
|
148
|
+
description: "Ingest immutable source document metadata.",
|
|
149
|
+
goal: "Store traceable source documents for curated KB.",
|
|
150
|
+
context: "Called when an admin uploads/records authoritative sources."
|
|
151
|
+
},
|
|
152
|
+
io: {
|
|
153
|
+
input: IngestSourceInput,
|
|
154
|
+
output: SourceDocumentModel
|
|
155
|
+
},
|
|
156
|
+
policy: { auth: "user" }
|
|
157
|
+
});
|
|
158
|
+
var KbUpsertRuleVersionContract = defineCommand({
|
|
159
|
+
meta: {
|
|
160
|
+
key: "kb.upsertRuleVersion",
|
|
161
|
+
title: "Upsert Rule Version",
|
|
162
|
+
version: "1.0.0",
|
|
163
|
+
stability: "experimental",
|
|
164
|
+
owners: ["@examples"],
|
|
165
|
+
tags: ["knowledge", "rules", "versioning"],
|
|
166
|
+
description: "Create a new draft rule version with source references.",
|
|
167
|
+
goal: "Propose curated knowledge updates with traceability.",
|
|
168
|
+
context: "Automation or curators propose draft rule versions."
|
|
169
|
+
},
|
|
170
|
+
io: {
|
|
171
|
+
input: UpsertRuleVersionInput,
|
|
172
|
+
output: RuleVersionModel,
|
|
173
|
+
errors: {
|
|
174
|
+
SOURCE_REFS_REQUIRED: {
|
|
175
|
+
description: "Rule version must cite at least one sourceRef",
|
|
176
|
+
http: 400,
|
|
177
|
+
gqlCode: "SOURCE_REFS_REQUIRED",
|
|
178
|
+
when: "sourceRefs is empty"
|
|
179
|
+
},
|
|
180
|
+
RULE_NOT_FOUND: {
|
|
181
|
+
description: "Rule does not exist",
|
|
182
|
+
http: 404,
|
|
183
|
+
gqlCode: "RULE_NOT_FOUND",
|
|
184
|
+
when: "ruleId is unknown"
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
},
|
|
188
|
+
policy: { auth: "user" }
|
|
189
|
+
});
|
|
190
|
+
var KbApproveRuleVersionContract = defineCommand({
|
|
191
|
+
meta: {
|
|
192
|
+
key: "kb.approveRuleVersion",
|
|
193
|
+
title: "Approve Rule Version",
|
|
194
|
+
version: "1.0.0",
|
|
195
|
+
stability: "experimental",
|
|
196
|
+
owners: ["@examples"],
|
|
197
|
+
tags: ["knowledge", "rules", "approval"],
|
|
198
|
+
description: "Approve a draft rule version.",
|
|
199
|
+
goal: "Human verification step before publishing snapshots.",
|
|
200
|
+
context: "Curators/experts approve proposed KB changes."
|
|
201
|
+
},
|
|
202
|
+
io: {
|
|
203
|
+
input: ApproveRuleVersionInput,
|
|
204
|
+
output: RuleVersionModel
|
|
205
|
+
},
|
|
206
|
+
policy: { auth: "user" }
|
|
207
|
+
});
|
|
208
|
+
var KbPublishSnapshotContract = defineCommand({
|
|
209
|
+
meta: {
|
|
210
|
+
key: "kb.publishSnapshot",
|
|
211
|
+
title: "Publish Snapshot",
|
|
212
|
+
version: "1.0.0",
|
|
213
|
+
stability: "experimental",
|
|
214
|
+
owners: ["@examples"],
|
|
215
|
+
tags: ["knowledge", "snapshots", "publishing"],
|
|
216
|
+
description: "Publish a KB snapshot for a jurisdiction.",
|
|
217
|
+
goal: "Create a stable snapshot that assistant answers can cite.",
|
|
218
|
+
context: "Publishing happens after approvals; snapshot is referenced by answers."
|
|
219
|
+
},
|
|
220
|
+
io: {
|
|
221
|
+
input: PublishSnapshotInput,
|
|
222
|
+
output: KBSnapshotModel,
|
|
223
|
+
errors: {
|
|
224
|
+
NO_APPROVED_RULES: {
|
|
225
|
+
description: "No approved rule versions available to publish",
|
|
226
|
+
http: 409,
|
|
227
|
+
gqlCode: "NO_APPROVED_RULES",
|
|
228
|
+
when: "jurisdiction has zero approved rule versions"
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
},
|
|
232
|
+
policy: { auth: "user" }
|
|
233
|
+
});
|
|
234
|
+
var KbSearchContract = defineQuery({
|
|
235
|
+
meta: {
|
|
236
|
+
key: "kb.search",
|
|
237
|
+
title: "Search KB",
|
|
238
|
+
version: "1.0.0",
|
|
239
|
+
stability: "experimental",
|
|
240
|
+
owners: ["@examples"],
|
|
241
|
+
tags: ["knowledge", "search", "snapshots"],
|
|
242
|
+
description: "Search within a published KB snapshot.",
|
|
243
|
+
goal: "Provide scoped retrieval for assistant answers.",
|
|
244
|
+
context: "Assistant queries curated rules from a specific snapshot."
|
|
245
|
+
},
|
|
246
|
+
io: {
|
|
247
|
+
input: SearchKbInput,
|
|
248
|
+
output: SearchKbOutput
|
|
249
|
+
},
|
|
250
|
+
policy: { auth: "user" }
|
|
251
|
+
});
|
|
252
|
+
export {
|
|
253
|
+
KbUpsertRuleVersionContract,
|
|
254
|
+
KbSearchContract,
|
|
255
|
+
KbPublishSnapshotContract,
|
|
256
|
+
KbIngestSourceContract,
|
|
257
|
+
KbApproveRuleVersionContract
|
|
258
|
+
};
|