@contractspec/example.kb-update-pipeline 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 +55 -0
- package/.turbo/turbo-build.log +56 -0
- package/CHANGELOG.md +342 -0
- package/LICENSE +21 -0
- package/README.md +28 -0
- package/dist/docs/index.d.ts +1 -0
- package/dist/docs/index.js +1 -0
- package/dist/docs/kb-update-pipeline.docblock.d.ts +1 -0
- package/dist/docs/kb-update-pipeline.docblock.js +31 -0
- package/dist/docs/kb-update-pipeline.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 +61 -0
- package/dist/entities/models.d.ts.map +1 -0
- package/dist/entities/models.js +74 -0
- package/dist/entities/models.js.map +1 -0
- package/dist/events.d.ts +74 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +150 -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 +50 -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 +68 -0
- package/dist/handlers/memory.handlers.d.ts.map +1 -0
- package/dist/handlers/memory.handlers.js +93 -0
- package/dist/handlers/memory.handlers.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +12 -0
- package/dist/kb-update-pipeline.feature.d.ts +7 -0
- package/dist/kb-update-pipeline.feature.d.ts.map +1 -0
- package/dist/kb-update-pipeline.feature.js +142 -0
- package/dist/kb-update-pipeline.feature.js.map +1 -0
- package/dist/operations/index.d.ts +2 -0
- package/dist/operations/index.js +3 -0
- package/dist/operations/pipeline.d.ts +137 -0
- package/dist/operations/pipeline.d.ts.map +1 -0
- package/dist/operations/pipeline.js +183 -0
- package/dist/operations/pipeline.js.map +1 -0
- package/dist/presentations.d.ts +9 -0
- package/dist/presentations.d.ts.map +1 -0
- package/dist/presentations.js +71 -0
- package/dist/presentations.js.map +1 -0
- package/dist/tests/operations.test-spec.d.ts +9 -0
- package/dist/tests/operations.test-spec.d.ts.map +1 -0
- package/dist/tests/operations.test-spec.js +94 -0
- package/dist/tests/operations.test-spec.js.map +1 -0
- package/example.ts +1 -0
- package/package.json +74 -0
- package/src/docs/index.ts +1 -0
- package/src/docs/kb-update-pipeline.docblock.ts +30 -0
- package/src/entities/index.ts +1 -0
- package/src/entities/models.ts +53 -0
- package/src/events.ts +134 -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 +186 -0
- package/src/index.ts +15 -0
- package/src/kb-update-pipeline.feature.ts +59 -0
- package/src/operations/index.ts +1 -0
- package/src/operations/pipeline.ts +159 -0
- package/src/presentations.ts +68 -0
- package/src/tests/operations.test-spec.ts +82 -0
- package/tsconfig.json +19 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/tsdown.config.js +17 -0
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
interface ChangeCandidate {
|
|
2
|
+
id: string;
|
|
3
|
+
sourceDocumentId: string;
|
|
4
|
+
detectedAt: Date;
|
|
5
|
+
diffSummary: string;
|
|
6
|
+
riskLevel: 'low' | 'medium' | 'high';
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
interface ReviewTask {
|
|
10
|
+
id: string;
|
|
11
|
+
changeCandidateId: string;
|
|
12
|
+
status: 'open' | 'decided';
|
|
13
|
+
assignedRole: 'curator' | 'expert';
|
|
14
|
+
decision?: 'approve' | 'reject';
|
|
15
|
+
decidedAt?: Date;
|
|
16
|
+
decidedBy?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface PipelineMemoryStore {
|
|
20
|
+
candidates: Map<string, ChangeCandidate>;
|
|
21
|
+
reviewTasks: Map<string, ReviewTask>;
|
|
22
|
+
proposedRuleVersionIdsByCandidate: Map<string, string[]>;
|
|
23
|
+
approvedRuleVersionIds: Set<string>;
|
|
24
|
+
notifications: {
|
|
25
|
+
kind: 'kb.review.requested';
|
|
26
|
+
reviewTaskId: string;
|
|
27
|
+
changeCandidateId: string;
|
|
28
|
+
assignedRole: 'curator' | 'expert';
|
|
29
|
+
createdAt: Date;
|
|
30
|
+
}[];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function createPipelineMemoryStore(): PipelineMemoryStore {
|
|
34
|
+
return {
|
|
35
|
+
candidates: new Map(),
|
|
36
|
+
reviewTasks: new Map(),
|
|
37
|
+
proposedRuleVersionIdsByCandidate: new Map(),
|
|
38
|
+
approvedRuleVersionIds: new Set(),
|
|
39
|
+
notifications: [],
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function stableId(prefix: string, value: string): string {
|
|
44
|
+
return `${prefix}_${value.replace(/[^a-zA-Z0-9_-]/g, '_')}`;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface PipelineMemoryHandlers {
|
|
48
|
+
runWatch(input: {
|
|
49
|
+
jurisdiction: string;
|
|
50
|
+
}): Promise<{ candidates: ChangeCandidate[] }>;
|
|
51
|
+
createReviewTask(input: { changeCandidateId: string }): Promise<ReviewTask>;
|
|
52
|
+
proposeRulePatch(input: {
|
|
53
|
+
changeCandidateId: string;
|
|
54
|
+
proposedRuleVersionIds: string[];
|
|
55
|
+
}): Promise<{ proposedRuleVersionIds: string[] }>;
|
|
56
|
+
markRuleVersionApproved(input: {
|
|
57
|
+
ruleVersionId: string;
|
|
58
|
+
}): Promise<{ ruleVersionId: string }>;
|
|
59
|
+
submitDecision(input: {
|
|
60
|
+
reviewTaskId: string;
|
|
61
|
+
decision: 'approve' | 'reject';
|
|
62
|
+
decidedBy: string;
|
|
63
|
+
decidedByRole: 'curator' | 'expert';
|
|
64
|
+
}): Promise<ReviewTask>;
|
|
65
|
+
publishIfReady(input: {
|
|
66
|
+
jurisdiction: string;
|
|
67
|
+
}): Promise<{ published: boolean; reason?: string }>;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function createPipelineMemoryHandlers(
|
|
71
|
+
store: PipelineMemoryStore
|
|
72
|
+
): PipelineMemoryHandlers {
|
|
73
|
+
async function runWatch(input: { jurisdiction: string }) {
|
|
74
|
+
// demo: always returns empty unless caller pre-seeds candidates
|
|
75
|
+
const candidates = [...store.candidates.values()].filter(
|
|
76
|
+
(c) => c.sourceDocumentId.startsWith(`${input.jurisdiction}_`) || true
|
|
77
|
+
);
|
|
78
|
+
return { candidates };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async function createReviewTask(input: { changeCandidateId: string }) {
|
|
82
|
+
const candidate = store.candidates.get(input.changeCandidateId);
|
|
83
|
+
if (!candidate) throw new Error('CHANGE_CANDIDATE_NOT_FOUND');
|
|
84
|
+
const assignedRole = candidate.riskLevel === 'high' ? 'expert' : 'curator';
|
|
85
|
+
const id = stableId('review', input.changeCandidateId);
|
|
86
|
+
const task: ReviewTask = {
|
|
87
|
+
id,
|
|
88
|
+
changeCandidateId: input.changeCandidateId,
|
|
89
|
+
status: 'open',
|
|
90
|
+
assignedRole,
|
|
91
|
+
decision: undefined,
|
|
92
|
+
decidedAt: undefined,
|
|
93
|
+
decidedBy: undefined,
|
|
94
|
+
};
|
|
95
|
+
store.reviewTasks.set(id, task);
|
|
96
|
+
store.notifications.push({
|
|
97
|
+
kind: 'kb.review.requested',
|
|
98
|
+
reviewTaskId: id,
|
|
99
|
+
changeCandidateId: input.changeCandidateId,
|
|
100
|
+
assignedRole,
|
|
101
|
+
createdAt: new Date(),
|
|
102
|
+
});
|
|
103
|
+
return task;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
async function proposeRulePatch(input: {
|
|
107
|
+
changeCandidateId: string;
|
|
108
|
+
proposedRuleVersionIds: string[];
|
|
109
|
+
}): Promise<{ proposedRuleVersionIds: string[] }> {
|
|
110
|
+
if (!store.candidates.has(input.changeCandidateId)) {
|
|
111
|
+
throw new Error('CHANGE_CANDIDATE_NOT_FOUND');
|
|
112
|
+
}
|
|
113
|
+
store.proposedRuleVersionIdsByCandidate.set(input.changeCandidateId, [
|
|
114
|
+
...input.proposedRuleVersionIds,
|
|
115
|
+
]);
|
|
116
|
+
return { proposedRuleVersionIds: [...input.proposedRuleVersionIds] };
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
async function markRuleVersionApproved(input: {
|
|
120
|
+
ruleVersionId: string;
|
|
121
|
+
}): Promise<{ ruleVersionId: string }> {
|
|
122
|
+
store.approvedRuleVersionIds.add(input.ruleVersionId);
|
|
123
|
+
return { ruleVersionId: input.ruleVersionId };
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
async function submitDecision(input: {
|
|
127
|
+
reviewTaskId: string;
|
|
128
|
+
decision: 'approve' | 'reject';
|
|
129
|
+
decidedBy: string;
|
|
130
|
+
decidedByRole: 'curator' | 'expert';
|
|
131
|
+
}) {
|
|
132
|
+
const task = store.reviewTasks.get(input.reviewTaskId);
|
|
133
|
+
if (!task) throw new Error('REVIEW_TASK_NOT_FOUND');
|
|
134
|
+
const candidate = store.candidates.get(task.changeCandidateId);
|
|
135
|
+
if (!candidate) throw new Error('CHANGE_CANDIDATE_NOT_FOUND');
|
|
136
|
+
if (candidate.riskLevel === 'high' && input.decision === 'approve') {
|
|
137
|
+
if (input.decidedByRole !== 'expert') throw new Error('FORBIDDEN_ROLE');
|
|
138
|
+
}
|
|
139
|
+
const decided: ReviewTask = {
|
|
140
|
+
...task,
|
|
141
|
+
status: 'decided',
|
|
142
|
+
decision: input.decision,
|
|
143
|
+
decidedAt: new Date(),
|
|
144
|
+
decidedBy: input.decidedBy,
|
|
145
|
+
};
|
|
146
|
+
store.reviewTasks.set(decided.id, decided);
|
|
147
|
+
return decided;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
async function publishIfReady(_input: { jurisdiction: string }) {
|
|
151
|
+
const openTasks = [...store.reviewTasks.values()].filter(
|
|
152
|
+
(t) => t.status !== 'decided'
|
|
153
|
+
);
|
|
154
|
+
if (openTasks.length) {
|
|
155
|
+
throw new Error('NOT_READY');
|
|
156
|
+
}
|
|
157
|
+
const rejected = [...store.reviewTasks.values()].some(
|
|
158
|
+
(t) => t.decision === 'reject'
|
|
159
|
+
);
|
|
160
|
+
if (rejected) return { published: false, reason: 'REJECTED' };
|
|
161
|
+
|
|
162
|
+
// Ensure every proposed rule version is approved before publishing.
|
|
163
|
+
for (const task of store.reviewTasks.values()) {
|
|
164
|
+
if (task.decision !== 'approve') continue;
|
|
165
|
+
const proposed =
|
|
166
|
+
store.proposedRuleVersionIdsByCandidate.get(task.changeCandidateId) ??
|
|
167
|
+
[];
|
|
168
|
+
const unapproved = proposed.filter(
|
|
169
|
+
(id) => !store.approvedRuleVersionIds.has(id)
|
|
170
|
+
);
|
|
171
|
+
if (unapproved.length) {
|
|
172
|
+
throw new Error('NOT_READY');
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return { published: true };
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return {
|
|
179
|
+
runWatch,
|
|
180
|
+
createReviewTask,
|
|
181
|
+
proposeRulePatch,
|
|
182
|
+
markRuleVersionApproved,
|
|
183
|
+
submitDecision,
|
|
184
|
+
publishIfReady,
|
|
185
|
+
};
|
|
186
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* KB Update Pipeline Example
|
|
3
|
+
*
|
|
4
|
+
* Automation proposes KB updates; humans verify; everything audited and notified.
|
|
5
|
+
*/
|
|
6
|
+
export * from './entities';
|
|
7
|
+
export * from './operations';
|
|
8
|
+
export * from './events';
|
|
9
|
+
export * from './handlers';
|
|
10
|
+
export * from './kb-update-pipeline.feature';
|
|
11
|
+
export { default as example } from './example';
|
|
12
|
+
|
|
13
|
+
export * from './presentations';
|
|
14
|
+
|
|
15
|
+
import './docs';
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { defineFeature } from '@contractspec/lib.contracts';
|
|
2
|
+
|
|
3
|
+
export const KbUpdatePipelineFeature = defineFeature({
|
|
4
|
+
meta: {
|
|
5
|
+
key: 'kb-update-pipeline',
|
|
6
|
+
version: '1.0.0',
|
|
7
|
+
title: 'KB Update Pipeline (HITL)',
|
|
8
|
+
description:
|
|
9
|
+
'Automation proposes KB patches; humans verify; publishing is blocked until approvals are complete.',
|
|
10
|
+
domain: 'knowledge',
|
|
11
|
+
owners: ['@examples'],
|
|
12
|
+
tags: ['knowledge', 'pipeline', 'hitl', 'audit', 'notifications'],
|
|
13
|
+
stability: 'experimental',
|
|
14
|
+
},
|
|
15
|
+
operations: [
|
|
16
|
+
{ key: 'kbPipeline.runWatch', version: '1.0.0' },
|
|
17
|
+
{ key: 'kbPipeline.createReviewTask', version: '1.0.0' },
|
|
18
|
+
{ key: 'kbPipeline.submitDecision', version: '1.0.0' },
|
|
19
|
+
{ key: 'kbPipeline.publishIfReady', version: '1.0.0' },
|
|
20
|
+
],
|
|
21
|
+
events: [
|
|
22
|
+
{ key: 'kb.change.detected', version: '1.0.0' },
|
|
23
|
+
{ key: 'kb.change.summarized', version: '1.0.0' },
|
|
24
|
+
{ key: 'kb.patch.proposed', version: '1.0.0' },
|
|
25
|
+
{ key: 'kb.review.requested', version: '1.0.0' },
|
|
26
|
+
{ key: 'kb.review.decided', version: '1.0.0' },
|
|
27
|
+
],
|
|
28
|
+
presentations: [
|
|
29
|
+
{ key: 'kb.dashboard', version: '1.0.0' },
|
|
30
|
+
{ key: 'kb.review.list', version: '1.0.0' },
|
|
31
|
+
{ key: 'kb.review.form', version: '1.0.0' },
|
|
32
|
+
],
|
|
33
|
+
opToPresentation: [
|
|
34
|
+
{
|
|
35
|
+
op: { key: 'kbPipeline.runWatch', version: '1.0.0' },
|
|
36
|
+
pres: { key: 'kb.dashboard', version: '1.0.0' },
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
op: { key: 'kbPipeline.createReviewTask', version: '1.0.0' },
|
|
40
|
+
pres: { key: 'kb.review.list', version: '1.0.0' },
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
op: { key: 'kbPipeline.submitDecision', version: '1.0.0' },
|
|
44
|
+
pres: { key: 'kb.review.form', version: '1.0.0' },
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
presentationsTargets: [
|
|
48
|
+
{ key: 'kb.dashboard', version: '1.0.0', targets: ['react', 'markdown'] },
|
|
49
|
+
{ key: 'kb.review.list', version: '1.0.0', targets: ['react', 'markdown'] },
|
|
50
|
+
{ key: 'kb.review.form', version: '1.0.0', targets: ['react'] },
|
|
51
|
+
],
|
|
52
|
+
capabilities: {
|
|
53
|
+
requires: [
|
|
54
|
+
{ key: 'identity', version: '1.0.0' },
|
|
55
|
+
{ key: 'notifications', version: '1.0.0' },
|
|
56
|
+
{ key: 'audit-trail', version: '1.0.0' },
|
|
57
|
+
],
|
|
58
|
+
},
|
|
59
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './pipeline';
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { defineCommand } from '@contractspec/lib.contracts';
|
|
2
|
+
import { ScalarTypeEnum, defineSchemaModel } from '@contractspec/lib.schema';
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
ChangeCandidateModel,
|
|
6
|
+
ReviewDecisionEnum,
|
|
7
|
+
ReviewTaskModel,
|
|
8
|
+
} from '../entities/models';
|
|
9
|
+
|
|
10
|
+
const RunWatchInput = defineSchemaModel({
|
|
11
|
+
name: 'KbPipelineRunWatchInput',
|
|
12
|
+
description: 'Trigger a watch cycle for KB sources (demo).',
|
|
13
|
+
fields: {
|
|
14
|
+
jurisdiction: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
const RunWatchOutput = defineSchemaModel({
|
|
19
|
+
name: 'KbPipelineRunWatchOutput',
|
|
20
|
+
description: 'Output containing detected changes.',
|
|
21
|
+
fields: {
|
|
22
|
+
candidates: {
|
|
23
|
+
type: ChangeCandidateModel,
|
|
24
|
+
isArray: true,
|
|
25
|
+
isOptional: false,
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const CreateReviewTaskInput = defineSchemaModel({
|
|
31
|
+
name: 'KbPipelineCreateReviewTaskInput',
|
|
32
|
+
description: 'Create a review task for a change candidate.',
|
|
33
|
+
fields: {
|
|
34
|
+
changeCandidateId: {
|
|
35
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
36
|
+
isOptional: false,
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const SubmitDecisionInput = defineSchemaModel({
|
|
42
|
+
name: 'KbPipelineSubmitDecisionInput',
|
|
43
|
+
description: 'Submit a decision for a review task.',
|
|
44
|
+
fields: {
|
|
45
|
+
reviewTaskId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
46
|
+
decision: { type: ReviewDecisionEnum, isOptional: false },
|
|
47
|
+
decidedBy: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
48
|
+
decidedByRole: {
|
|
49
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
50
|
+
isOptional: false,
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
const PublishIfReadyInput = defineSchemaModel({
|
|
56
|
+
name: 'KbPipelinePublishIfReadyInput',
|
|
57
|
+
description:
|
|
58
|
+
'Publish snapshot if approvals are satisfied for a jurisdiction.',
|
|
59
|
+
fields: {
|
|
60
|
+
jurisdiction: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
const PublishIfReadyOutput = defineSchemaModel({
|
|
65
|
+
name: 'KbPipelinePublishIfReadyOutput',
|
|
66
|
+
description: 'Output for publish-if-ready operation.',
|
|
67
|
+
fields: {
|
|
68
|
+
published: { type: ScalarTypeEnum.Boolean(), isOptional: false },
|
|
69
|
+
reason: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
export const KbPipelineRunWatchContract = defineCommand({
|
|
74
|
+
meta: {
|
|
75
|
+
key: 'kbPipeline.runWatch',
|
|
76
|
+
version: '1.0.0',
|
|
77
|
+
stability: 'experimental',
|
|
78
|
+
owners: ['@examples'],
|
|
79
|
+
tags: ['knowledge', 'pipeline', 'jobs'],
|
|
80
|
+
description: 'Detect source changes and create change candidates.',
|
|
81
|
+
goal: 'Automate discovery of updates needing review.',
|
|
82
|
+
context: 'Scheduled job or manual trigger in demos.',
|
|
83
|
+
},
|
|
84
|
+
io: { input: RunWatchInput, output: RunWatchOutput },
|
|
85
|
+
policy: { auth: 'user' },
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
export const KbPipelineCreateReviewTaskContract = defineCommand({
|
|
89
|
+
meta: {
|
|
90
|
+
key: 'kbPipeline.createReviewTask',
|
|
91
|
+
version: '1.0.0',
|
|
92
|
+
stability: 'experimental',
|
|
93
|
+
owners: ['@examples'],
|
|
94
|
+
tags: ['knowledge', 'pipeline', 'hitl'],
|
|
95
|
+
description: 'Create a review task for a detected change.',
|
|
96
|
+
goal: 'Route work to human verifiers.',
|
|
97
|
+
context: 'Called after change detection or manual selection.',
|
|
98
|
+
},
|
|
99
|
+
io: { input: CreateReviewTaskInput, output: ReviewTaskModel },
|
|
100
|
+
policy: { auth: 'user' },
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
export const KbPipelineSubmitDecisionContract = defineCommand({
|
|
104
|
+
meta: {
|
|
105
|
+
key: 'kbPipeline.submitDecision',
|
|
106
|
+
version: '1.0.0',
|
|
107
|
+
stability: 'experimental',
|
|
108
|
+
owners: ['@examples'],
|
|
109
|
+
tags: ['knowledge', 'pipeline', 'hitl', 'rbac'],
|
|
110
|
+
description: 'Submit approve/reject decision for a review task.',
|
|
111
|
+
goal: 'Ensure humans verify before publishing.',
|
|
112
|
+
context: 'Curator/expert reviews and decides.',
|
|
113
|
+
},
|
|
114
|
+
io: {
|
|
115
|
+
input: SubmitDecisionInput,
|
|
116
|
+
output: ReviewTaskModel,
|
|
117
|
+
errors: {
|
|
118
|
+
FORBIDDEN_ROLE: {
|
|
119
|
+
description: 'Role not allowed to approve the given risk level',
|
|
120
|
+
http: 403,
|
|
121
|
+
gqlCode: 'FORBIDDEN_ROLE',
|
|
122
|
+
when: 'curator attempts to approve a high-risk change',
|
|
123
|
+
},
|
|
124
|
+
REVIEW_TASK_NOT_FOUND: {
|
|
125
|
+
description: 'Review task not found',
|
|
126
|
+
http: 404,
|
|
127
|
+
gqlCode: 'REVIEW_TASK_NOT_FOUND',
|
|
128
|
+
when: 'reviewTaskId is invalid',
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
policy: { auth: 'user' },
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
export const KbPipelinePublishIfReadyContract = defineCommand({
|
|
136
|
+
meta: {
|
|
137
|
+
key: 'kbPipeline.publishIfReady',
|
|
138
|
+
version: '1.0.0',
|
|
139
|
+
stability: 'experimental',
|
|
140
|
+
owners: ['@examples'],
|
|
141
|
+
tags: ['knowledge', 'pipeline', 'publishing'],
|
|
142
|
+
description: 'Publish snapshot if ready (all approvals satisfied).',
|
|
143
|
+
goal: 'Prevent publishing until all required approvals exist.',
|
|
144
|
+
context: 'Called by job or UI to attempt publish.',
|
|
145
|
+
},
|
|
146
|
+
io: {
|
|
147
|
+
input: PublishIfReadyInput,
|
|
148
|
+
output: PublishIfReadyOutput,
|
|
149
|
+
errors: {
|
|
150
|
+
NOT_READY: {
|
|
151
|
+
description: 'Publishing is blocked because approvals are incomplete',
|
|
152
|
+
http: 409,
|
|
153
|
+
gqlCode: 'NOT_READY',
|
|
154
|
+
when: 'there are open review tasks or unapproved rule versions',
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
policy: { auth: 'user' },
|
|
159
|
+
});
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { definePresentation, StabilityEnum } from '@contractspec/lib.contracts';
|
|
2
|
+
import { ChangeCandidateModel, ReviewTaskModel } from './entities/models';
|
|
3
|
+
|
|
4
|
+
export const KbDashboardPresentation = definePresentation({
|
|
5
|
+
meta: {
|
|
6
|
+
key: 'kb.dashboard',
|
|
7
|
+
version: '1.0.0',
|
|
8
|
+
title: 'KB Update Dashboard',
|
|
9
|
+
description: 'Overview of KB change candidates and review tasks.',
|
|
10
|
+
domain: 'knowledge',
|
|
11
|
+
owners: ['@examples'],
|
|
12
|
+
tags: ['dashboard', 'knowledge'],
|
|
13
|
+
stability: StabilityEnum.Experimental,
|
|
14
|
+
goal: 'Visualize status',
|
|
15
|
+
context: 'Dashboard',
|
|
16
|
+
},
|
|
17
|
+
source: {
|
|
18
|
+
type: 'component',
|
|
19
|
+
framework: 'react',
|
|
20
|
+
componentKey: 'KbDashboard',
|
|
21
|
+
props: ChangeCandidateModel, // Simplified props mapping for example
|
|
22
|
+
},
|
|
23
|
+
targets: ['react', 'markdown'],
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
export const KbReviewListPresentation = definePresentation({
|
|
27
|
+
meta: {
|
|
28
|
+
key: 'kb.review.list',
|
|
29
|
+
version: '1.0.0',
|
|
30
|
+
title: 'Review Tasks',
|
|
31
|
+
description: 'List of pending review tasks for the current user.',
|
|
32
|
+
domain: 'knowledge',
|
|
33
|
+
owners: ['@examples'],
|
|
34
|
+
tags: ['list', 'review'],
|
|
35
|
+
stability: StabilityEnum.Experimental,
|
|
36
|
+
goal: 'List tasks',
|
|
37
|
+
context: 'Inbox',
|
|
38
|
+
},
|
|
39
|
+
source: {
|
|
40
|
+
type: 'component',
|
|
41
|
+
framework: 'react',
|
|
42
|
+
componentKey: 'ReviewTaskList',
|
|
43
|
+
props: ReviewTaskModel,
|
|
44
|
+
},
|
|
45
|
+
targets: ['react', 'markdown'],
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
export const KbReviewFormPresentation = definePresentation({
|
|
49
|
+
meta: {
|
|
50
|
+
key: 'kb.review.form',
|
|
51
|
+
version: '1.0.0',
|
|
52
|
+
title: 'Review Change',
|
|
53
|
+
description: 'Form to approve or reject a KB change candidate.',
|
|
54
|
+
domain: 'knowledge',
|
|
55
|
+
owners: ['@examples'],
|
|
56
|
+
tags: ['form', 'review'],
|
|
57
|
+
stability: StabilityEnum.Experimental,
|
|
58
|
+
goal: 'Review',
|
|
59
|
+
context: 'Detail',
|
|
60
|
+
},
|
|
61
|
+
source: {
|
|
62
|
+
type: 'component',
|
|
63
|
+
framework: 'react',
|
|
64
|
+
componentKey: 'ReviewDecisionForm',
|
|
65
|
+
props: ReviewTaskModel,
|
|
66
|
+
},
|
|
67
|
+
targets: ['react'],
|
|
68
|
+
});
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { defineTestSpec } from '@contractspec/lib.contracts';
|
|
2
|
+
|
|
3
|
+
export const RunWatchTest = defineTestSpec({
|
|
4
|
+
meta: {
|
|
5
|
+
key: 'kbPipeline.runWatch.test',
|
|
6
|
+
version: '1.0.0',
|
|
7
|
+
stability: 'experimental',
|
|
8
|
+
owners: ['@example.kb-update-pipeline'],
|
|
9
|
+
description: 'Test for run watch operation',
|
|
10
|
+
tags: ['test'],
|
|
11
|
+
},
|
|
12
|
+
target: {
|
|
13
|
+
type: 'operation',
|
|
14
|
+
operation: { key: 'kbPipeline.runWatch', version: '1.0.0' },
|
|
15
|
+
},
|
|
16
|
+
scenarios: [
|
|
17
|
+
{
|
|
18
|
+
key: 'success',
|
|
19
|
+
when: { operation: { key: 'kbPipeline.runWatch' } },
|
|
20
|
+
then: [{ type: 'expectOutput', match: {} }],
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
key: 'error',
|
|
24
|
+
when: { operation: { key: 'kbPipeline.runWatch' } },
|
|
25
|
+
then: [{ type: 'expectError' }],
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
export const CreateReviewTaskTest = defineTestSpec({
|
|
31
|
+
meta: {
|
|
32
|
+
key: 'kbPipeline.createReviewTask.test',
|
|
33
|
+
version: '1.0.0',
|
|
34
|
+
stability: 'experimental',
|
|
35
|
+
owners: ['@example.kb-update-pipeline'],
|
|
36
|
+
description: 'Test for creating review task',
|
|
37
|
+
tags: ['test'],
|
|
38
|
+
},
|
|
39
|
+
target: {
|
|
40
|
+
type: 'operation',
|
|
41
|
+
operation: { key: 'kbPipeline.createReviewTask', version: '1.0.0' },
|
|
42
|
+
},
|
|
43
|
+
scenarios: [
|
|
44
|
+
{
|
|
45
|
+
key: 'success',
|
|
46
|
+
when: { operation: { key: 'kbPipeline.createReviewTask' } },
|
|
47
|
+
then: [{ type: 'expectOutput', match: {} }],
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
key: 'error',
|
|
51
|
+
when: { operation: { key: 'kbPipeline.createReviewTask' } },
|
|
52
|
+
then: [{ type: 'expectError' }],
|
|
53
|
+
},
|
|
54
|
+
],
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
export const SubmitDecisionTest = defineTestSpec({
|
|
58
|
+
meta: {
|
|
59
|
+
key: 'kbPipeline.submitDecision.test',
|
|
60
|
+
version: '1.0.0',
|
|
61
|
+
stability: 'experimental',
|
|
62
|
+
owners: ['@example.kb-update-pipeline'],
|
|
63
|
+
description: 'Test for submitting decision',
|
|
64
|
+
tags: ['test'],
|
|
65
|
+
},
|
|
66
|
+
target: {
|
|
67
|
+
type: 'operation',
|
|
68
|
+
operation: { key: 'kbPipeline.submitDecision', version: '1.0.0' },
|
|
69
|
+
},
|
|
70
|
+
scenarios: [
|
|
71
|
+
{
|
|
72
|
+
key: 'success',
|
|
73
|
+
when: { operation: { key: 'kbPipeline.submitDecision' } },
|
|
74
|
+
then: [{ type: 'expectOutput', match: {} }],
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
key: 'error',
|
|
78
|
+
when: { operation: { key: 'kbPipeline.submitDecision' } },
|
|
79
|
+
then: [{ type: 'expectError' }],
|
|
80
|
+
},
|
|
81
|
+
],
|
|
82
|
+
});
|
package/tsconfig.json
ADDED