@opengeni/core 2.10.0-canary.0 → 2.10.0-canary.2
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/dist/application/external-workspace-members.d.ts +16 -0
- package/dist/application/host-mcp-resolvers.d.ts +13 -0
- package/dist/application/new-session-drafts.d.ts +4 -2
- package/dist/chunk-5WZYFL45.js +266 -0
- package/dist/chunk-5WZYFL45.js.map +1 -0
- package/dist/domain/file-owner.d.ts +8 -0
- package/dist/domain/knowledge-files.d.ts +20 -0
- package/dist/domain/knowledge-messages.d.ts +39 -0
- package/dist/domain/knowledge-messages.test.d.ts +1 -0
- package/dist/domain/knowledge-search.d.ts +80 -0
- package/dist/domain/knowledge-search.test.d.ts +1 -0
- package/dist/domain/knowledge.d.ts +9 -0
- package/dist/domain/pr-review.d.ts +2 -2
- package/dist/domain/resources.d.ts +2 -2
- package/dist/domain/scheduled-tasks.d.ts +12 -2
- package/dist/domain/sessions.d.ts +6 -2
- package/dist/domain/skills.d.ts +16 -0
- package/dist/index.d.ts +6 -4
- package/dist/index.js +3948 -3939
- package/dist/index.js.map +1 -1
- package/dist/remote-mcp-credentials.d.ts +16 -1
- package/dist/remote-mcp-credentials.js +7 -215
- package/dist/remote-mcp-credentials.js.map +1 -1
- package/package.json +12 -12
- package/src/application/external-workspace-members.ts +89 -0
- package/src/application/host-mcp-resolvers.ts +85 -0
- package/src/application/new-session-drafts.ts +37 -3
- package/src/domain/file-owner.ts +52 -0
- package/src/domain/host-mcp-task-admission.ts +27 -17
- package/src/domain/knowledge-files.ts +39 -0
- package/src/domain/knowledge-messages.test.ts +91 -0
- package/src/domain/knowledge-messages.ts +105 -0
- package/src/domain/knowledge-search.test.ts +45 -0
- package/src/domain/knowledge-search.ts +55 -0
- package/src/domain/knowledge.ts +133 -0
- package/src/domain/product-integration-skill.gen.ts +7 -7
- package/src/domain/resources.ts +36 -25
- package/src/domain/scheduled-tasks.ts +362 -139
- package/src/domain/sessions.ts +117 -20
- package/src/domain/skills.ts +8 -0
- package/src/index.ts +9 -4
- package/src/remote-mcp-credentials.ts +76 -8
- package/dist/domain/company-brain-governed-writes.d.ts +0 -79
- package/dist/domain/governed-learning-activation.d.ts +0 -16
- package/dist/domain/governed-learning-evaluator.d.ts +0 -6
- package/dist/domain/remember.d.ts +0 -72
- package/src/domain/company-brain-governed-writes.ts +0 -346
- package/src/domain/governed-learning-activation.ts +0 -44
- package/src/domain/governed-learning-evaluator.ts +0 -49
- package/src/domain/remember.ts +0 -577
|
@@ -1,346 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
CompanyBrainLearningPolicyRouteReceipt,
|
|
3
|
-
CompanyBrainGovernedWriteAttempt,
|
|
4
|
-
CompanyBrainGovernedWriteReceipt,
|
|
5
|
-
CompanyBrainGovernedWriteRequest,
|
|
6
|
-
resolveWorkspaceLearningPolicyEffectiveMode,
|
|
7
|
-
type CompanyBrainGovernedWriteReceipt as CompanyBrainGovernedWriteReceiptType,
|
|
8
|
-
type CompanyBrainLearningPolicyRouteReceipt as CompanyBrainLearningPolicyRouteReceiptType,
|
|
9
|
-
type CompanyBrainLearningStepFailure,
|
|
10
|
-
type GovernedLearningActivationDestination,
|
|
11
|
-
type GovernedLearningActivationReceipt,
|
|
12
|
-
type GovernedLearningDecisionReceipt,
|
|
13
|
-
type WorkspaceLearningPolicySnapshot,
|
|
14
|
-
} from "@opengeni/contracts";
|
|
15
|
-
import {
|
|
16
|
-
type Database,
|
|
17
|
-
GovernedLearningActivationAuthorityError,
|
|
18
|
-
GovernedLearningActivationConflictError,
|
|
19
|
-
GovernedLearningActivationInvalidOperationError,
|
|
20
|
-
GovernedLearningEvaluationAuthorityError,
|
|
21
|
-
GovernedLearningEvaluationConflictError,
|
|
22
|
-
activateGovernedLearningDecision,
|
|
23
|
-
evaluateGovernedLearningProposal,
|
|
24
|
-
getOrCreateWorkspaceLearningPolicySnapshot,
|
|
25
|
-
writeCompanyBrainGovernedProposal,
|
|
26
|
-
} from "@opengeni/db";
|
|
27
|
-
import { createHash } from "node:crypto";
|
|
28
|
-
import {
|
|
29
|
-
publishGovernedLearningEventToSlack,
|
|
30
|
-
type GovernedLearningSlackPublicationResult,
|
|
31
|
-
} from "./governed-learning-slack-publication";
|
|
32
|
-
|
|
33
|
-
export type CompanyBrainGovernedWriteInput = {
|
|
34
|
-
attempt: unknown;
|
|
35
|
-
request: unknown;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
export type CompanyBrainGovernedWriteRouterOptions = {
|
|
39
|
-
db: Database;
|
|
40
|
-
authority?: typeof writeCompanyBrainGovernedProposal;
|
|
41
|
-
learningPolicySnapshot?: typeof getOrCreateWorkspaceLearningPolicySnapshot;
|
|
42
|
-
/** Governed-learning evaluator (migration 0268). Defaults to the DB capability. */
|
|
43
|
-
evaluate?: typeof evaluateGovernedLearningProposal;
|
|
44
|
-
/** Governed-learning activation controller (migration 0269). Defaults to the DB capability. */
|
|
45
|
-
activate?: typeof activateGovernedLearningDecision;
|
|
46
|
-
/**
|
|
47
|
-
* Destinations the router may activate automatically from a final eligible
|
|
48
|
-
* decision. Defaults to Skills and instruction policy. Both still pass
|
|
49
|
-
* through the evaluator and destination-owned activation lifecycle.
|
|
50
|
-
*/
|
|
51
|
-
automaticDestinations?: ReadonlyArray<GovernedLearningActivationDestination>;
|
|
52
|
-
/**
|
|
53
|
-
* Optional post-activation notification sink (Slack publication outbox).
|
|
54
|
-
* Notification is never authority: failures are swallowed after the
|
|
55
|
-
* activation receipt is durable and never change the route receipt.
|
|
56
|
-
*/
|
|
57
|
-
notifyActivation?: (input: {
|
|
58
|
-
db: Database;
|
|
59
|
-
receipt: GovernedLearningActivationReceipt;
|
|
60
|
-
sessionId: string;
|
|
61
|
-
attemptId: string;
|
|
62
|
-
}) => Promise<GovernedLearningSlackPublicationResult>;
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
export const DEFAULT_AUTOMATIC_LEARNING_DESTINATIONS: ReadonlyArray<GovernedLearningActivationDestination> =
|
|
66
|
-
["preference", "instruction_policy"];
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Start a non-authoritative post-activation notification without making the
|
|
70
|
-
* durable activation receipt wait for its settlement. The callback is invoked
|
|
71
|
-
* synchronously so immediate enqueue work begins before the router returns;
|
|
72
|
-
* both synchronous throws and later promise rejections are contained.
|
|
73
|
-
*
|
|
74
|
-
* Exact retries intentionally dispatch again: the publication sink owns an
|
|
75
|
-
* activation-receipt idempotency key, while the activation receipt remains the
|
|
76
|
-
* caller-facing source of truth even if notification delivery stalls forever.
|
|
77
|
-
*/
|
|
78
|
-
export function dispatchBestEffortGovernedLearningNotification(
|
|
79
|
-
notify: () => Promise<unknown>,
|
|
80
|
-
): void {
|
|
81
|
-
try {
|
|
82
|
-
void notify().catch(() => undefined);
|
|
83
|
-
} catch {
|
|
84
|
-
// Notification is best-effort; the durable activation receipt already exists.
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Transport-neutral facade for explicit governed Company Brain proposals.
|
|
90
|
-
* It intentionally exposes no generic remember call, selector, activation,
|
|
91
|
-
* rollback token, or personal/organization destination.
|
|
92
|
-
*/
|
|
93
|
-
export function createCompanyBrainGovernedWriteRouter(
|
|
94
|
-
options: CompanyBrainGovernedWriteRouterOptions,
|
|
95
|
-
): {
|
|
96
|
-
write: (input: CompanyBrainGovernedWriteInput) => Promise<CompanyBrainGovernedWriteReceiptType>;
|
|
97
|
-
} {
|
|
98
|
-
const authority = options.authority ?? writeCompanyBrainGovernedProposal;
|
|
99
|
-
return {
|
|
100
|
-
async write(input) {
|
|
101
|
-
const attempt = CompanyBrainGovernedWriteAttempt.parse(input.attempt);
|
|
102
|
-
const request = CompanyBrainGovernedWriteRequest.parse(input.request);
|
|
103
|
-
const result = await authority(options.db, { attempt, request });
|
|
104
|
-
return CompanyBrainGovernedWriteReceipt.parse(result);
|
|
105
|
-
},
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Deterministic UUIDv5-shaped operation id derived from the caller's proposal
|
|
111
|
-
* operation id, so an exact retry of the same write converges on the same
|
|
112
|
-
* evaluator/activation receipts instead of conflicting.
|
|
113
|
-
*/
|
|
114
|
-
export function derivedGovernedLearningOperationId(
|
|
115
|
-
operationId: string,
|
|
116
|
-
stage: "evaluation" | "activation",
|
|
117
|
-
): string {
|
|
118
|
-
const bytes = Buffer.from(
|
|
119
|
-
createHash("sha256")
|
|
120
|
-
.update(`company-brain-governed-learning:v1:${operationId}:${stage}`, "utf8")
|
|
121
|
-
.digest("hex")
|
|
122
|
-
.slice(0, 32),
|
|
123
|
-
"hex",
|
|
124
|
-
);
|
|
125
|
-
bytes[6] = (bytes[6]! & 0x0f) | 0x50;
|
|
126
|
-
bytes[8] = (bytes[8]! & 0x3f) | 0x80;
|
|
127
|
-
const hex = bytes.toString("hex");
|
|
128
|
-
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
function classifyLearningFailure(
|
|
132
|
-
stage: CompanyBrainLearningStepFailure["stage"],
|
|
133
|
-
error: unknown,
|
|
134
|
-
): CompanyBrainLearningStepFailure {
|
|
135
|
-
if (
|
|
136
|
-
error instanceof GovernedLearningEvaluationAuthorityError ||
|
|
137
|
-
error instanceof GovernedLearningActivationAuthorityError
|
|
138
|
-
) {
|
|
139
|
-
return { stage, code: "authority" };
|
|
140
|
-
}
|
|
141
|
-
if (
|
|
142
|
-
error instanceof GovernedLearningEvaluationConflictError ||
|
|
143
|
-
error instanceof GovernedLearningActivationConflictError
|
|
144
|
-
) {
|
|
145
|
-
return { stage, code: "conflict" };
|
|
146
|
-
}
|
|
147
|
-
if (error instanceof GovernedLearningActivationInvalidOperationError) {
|
|
148
|
-
return { stage, code: "invalid_operation" };
|
|
149
|
-
}
|
|
150
|
-
return { stage, code: "unavailable" };
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* Resolve one derived Company Brain write from the immutable policy snapshot
|
|
155
|
-
* frozen for the exact accepted attempt. The evidence identity is the policy
|
|
156
|
-
* source identity; callers cannot select another override key to widen the
|
|
157
|
-
* decision.
|
|
158
|
-
*
|
|
159
|
-
* After the proposal commits, a Ways-of-working proposal (instruction policy or
|
|
160
|
-
* preference, i.e. one that materialized a `knowledge_change_proposals` row) is
|
|
161
|
-
* evaluated by the governed-learning evaluator against the same accepted
|
|
162
|
-
* snapshot. `suggest` records the content-free decision receipt only. Under
|
|
163
|
-
* `automatic`, a final `automaticEligible` receipt is handed to the activation
|
|
164
|
-
* controller, which revalidates current authority and applies the change only
|
|
165
|
-
* through the destination-owned lifecycle. Eligible Skills and instruction
|
|
166
|
-
* policies may activate automatically. Evaluation or activation failure
|
|
167
|
-
* never rolls back the durable proposal; it is reported as a bounded
|
|
168
|
-
* `learningFailure` and the proposal remains for human review.
|
|
169
|
-
*/
|
|
170
|
-
export function createCompanyBrainLearningPolicyRouter(
|
|
171
|
-
options: CompanyBrainGovernedWriteRouterOptions,
|
|
172
|
-
): {
|
|
173
|
-
write: (
|
|
174
|
-
input: CompanyBrainGovernedWriteInput,
|
|
175
|
-
) => Promise<CompanyBrainLearningPolicyRouteReceiptType>;
|
|
176
|
-
} {
|
|
177
|
-
const authority = options.authority ?? writeCompanyBrainGovernedProposal;
|
|
178
|
-
const evaluate = options.evaluate ?? evaluateGovernedLearningProposal;
|
|
179
|
-
const activate = options.activate ?? activateGovernedLearningDecision;
|
|
180
|
-
const notifyActivation =
|
|
181
|
-
options.notifyActivation ??
|
|
182
|
-
(async ({ db, receipt, sessionId, attemptId }) =>
|
|
183
|
-
publishGovernedLearningEventToSlack(db, {
|
|
184
|
-
kind: "activated",
|
|
185
|
-
receipt,
|
|
186
|
-
sessionId,
|
|
187
|
-
attemptId,
|
|
188
|
-
}));
|
|
189
|
-
const automaticDestinations = new Set(
|
|
190
|
-
options.automaticDestinations ?? DEFAULT_AUTOMATIC_LEARNING_DESTINATIONS,
|
|
191
|
-
);
|
|
192
|
-
const snapshotAuthority =
|
|
193
|
-
options.learningPolicySnapshot ?? getOrCreateWorkspaceLearningPolicySnapshot;
|
|
194
|
-
return {
|
|
195
|
-
async write(input) {
|
|
196
|
-
const attempt = CompanyBrainGovernedWriteAttempt.parse(input.attempt);
|
|
197
|
-
const request = CompanyBrainGovernedWriteRequest.parse(input.request);
|
|
198
|
-
const policySnapshot: WorkspaceLearningPolicySnapshot = await snapshotAuthority(options.db, {
|
|
199
|
-
accountId: attempt.accountId,
|
|
200
|
-
workspaceId: attempt.workspaceId,
|
|
201
|
-
sessionId: attempt.sessionId,
|
|
202
|
-
turnId: attempt.turnId,
|
|
203
|
-
attemptId: attempt.attemptId,
|
|
204
|
-
executionGeneration: attempt.executionGeneration,
|
|
205
|
-
});
|
|
206
|
-
const taskNotePromotion =
|
|
207
|
-
request.kind === "promote_task_note_knowledge" ||
|
|
208
|
-
request.kind === "promote_task_note_instruction_policy" ||
|
|
209
|
-
request.kind === "promote_task_note_preference";
|
|
210
|
-
const effectivePolicy = resolveWorkspaceLearningPolicyEffectiveMode(policySnapshot, {
|
|
211
|
-
kind: taskNotePromotion ? "task-note" : "scoped-knowledge-evidence",
|
|
212
|
-
id: taskNotePromotion ? request.noteId : request.evidenceId,
|
|
213
|
-
});
|
|
214
|
-
if (effectivePolicy.mode === "off") {
|
|
215
|
-
return CompanyBrainLearningPolicyRouteReceipt.parse({
|
|
216
|
-
operationId: request.operationId,
|
|
217
|
-
workspaceId: attempt.workspaceId,
|
|
218
|
-
effectivePolicy,
|
|
219
|
-
decision: "blocked",
|
|
220
|
-
write: null,
|
|
221
|
-
learning: null,
|
|
222
|
-
learningFailure: null,
|
|
223
|
-
activation: {
|
|
224
|
-
requested: false,
|
|
225
|
-
activated: false,
|
|
226
|
-
boundary: "policy_off",
|
|
227
|
-
},
|
|
228
|
-
});
|
|
229
|
-
}
|
|
230
|
-
const result = await authority(options.db, { attempt, request });
|
|
231
|
-
const write = CompanyBrainGovernedWriteReceipt.parse(result);
|
|
232
|
-
const automatic = effectivePolicy.mode === "automatic";
|
|
233
|
-
const proposalOnly = CompanyBrainLearningPolicyRouteReceipt.parse({
|
|
234
|
-
operationId: request.operationId,
|
|
235
|
-
workspaceId: attempt.workspaceId,
|
|
236
|
-
effectivePolicy,
|
|
237
|
-
decision: automatic ? "activation_requested" : "proposal_created",
|
|
238
|
-
write,
|
|
239
|
-
learning: null,
|
|
240
|
-
learningFailure: null,
|
|
241
|
-
activation: {
|
|
242
|
-
requested: automatic,
|
|
243
|
-
activated: false,
|
|
244
|
-
boundary: automatic ? "destination_authority" : "human_review",
|
|
245
|
-
},
|
|
246
|
-
});
|
|
247
|
-
// Knowledge destinations create no change proposal and are never
|
|
248
|
-
// evaluated; the human Knowledge review lifecycle owns them.
|
|
249
|
-
if (write.knowledgeChangeProposalId === null) return proposalOnly;
|
|
250
|
-
|
|
251
|
-
let decision: GovernedLearningDecisionReceipt;
|
|
252
|
-
try {
|
|
253
|
-
decision = await evaluate(options.db, {
|
|
254
|
-
attempt: {
|
|
255
|
-
workspaceId: attempt.workspaceId,
|
|
256
|
-
subjectId: result.initiatingHumanSubjectId,
|
|
257
|
-
sessionId: attempt.sessionId,
|
|
258
|
-
turnId: attempt.turnId,
|
|
259
|
-
attemptId: attempt.attemptId,
|
|
260
|
-
executionGeneration: attempt.executionGeneration,
|
|
261
|
-
},
|
|
262
|
-
request: {
|
|
263
|
-
operationId: derivedGovernedLearningOperationId(request.operationId, "evaluation"),
|
|
264
|
-
policySnapshotId: policySnapshot.id,
|
|
265
|
-
proposalId: write.knowledgeChangeProposalId,
|
|
266
|
-
claimId: write.claimId,
|
|
267
|
-
evidenceId: write.evidenceId,
|
|
268
|
-
},
|
|
269
|
-
});
|
|
270
|
-
} catch (error) {
|
|
271
|
-
return CompanyBrainLearningPolicyRouteReceipt.parse({
|
|
272
|
-
...proposalOnly,
|
|
273
|
-
learningFailure: classifyLearningFailure("evaluation", error),
|
|
274
|
-
});
|
|
275
|
-
}
|
|
276
|
-
const learning = {
|
|
277
|
-
receiptId: decision.id,
|
|
278
|
-
outcome: decision.outcome,
|
|
279
|
-
automaticEligible: decision.automaticEligible,
|
|
280
|
-
reasons: decision.reasons,
|
|
281
|
-
};
|
|
282
|
-
const destinationAllowsAutomatic =
|
|
283
|
-
write.destination !== "knowledge" && automaticDestinations.has(write.destination);
|
|
284
|
-
if (!automatic || !decision.automaticEligible || !destinationAllowsAutomatic) {
|
|
285
|
-
return CompanyBrainLearningPolicyRouteReceipt.parse({
|
|
286
|
-
...proposalOnly,
|
|
287
|
-
learning,
|
|
288
|
-
activation: {
|
|
289
|
-
requested: automatic,
|
|
290
|
-
activated: false,
|
|
291
|
-
boundary: !automatic
|
|
292
|
-
? "human_review"
|
|
293
|
-
: !decision.automaticEligible
|
|
294
|
-
? "not_eligible"
|
|
295
|
-
: "human_activation_required",
|
|
296
|
-
},
|
|
297
|
-
});
|
|
298
|
-
}
|
|
299
|
-
let activation: GovernedLearningActivationReceipt;
|
|
300
|
-
try {
|
|
301
|
-
activation = await activate(options.db, {
|
|
302
|
-
caller: {
|
|
303
|
-
workspaceId: attempt.workspaceId,
|
|
304
|
-
subjectId: result.initiatingHumanSubjectId,
|
|
305
|
-
},
|
|
306
|
-
request: {
|
|
307
|
-
operationId: derivedGovernedLearningOperationId(request.operationId, "activation"),
|
|
308
|
-
decisionReceiptId: decision.id,
|
|
309
|
-
},
|
|
310
|
-
});
|
|
311
|
-
} catch (error) {
|
|
312
|
-
return CompanyBrainLearningPolicyRouteReceipt.parse({
|
|
313
|
-
...proposalOnly,
|
|
314
|
-
learning,
|
|
315
|
-
learningFailure: classifyLearningFailure("activation", error),
|
|
316
|
-
});
|
|
317
|
-
}
|
|
318
|
-
dispatchBestEffortGovernedLearningNotification(() =>
|
|
319
|
-
notifyActivation({
|
|
320
|
-
db: options.db,
|
|
321
|
-
receipt: activation,
|
|
322
|
-
sessionId: attempt.sessionId,
|
|
323
|
-
attemptId: attempt.attemptId,
|
|
324
|
-
}),
|
|
325
|
-
);
|
|
326
|
-
return CompanyBrainLearningPolicyRouteReceipt.parse({
|
|
327
|
-
operationId: request.operationId,
|
|
328
|
-
workspaceId: attempt.workspaceId,
|
|
329
|
-
effectivePolicy,
|
|
330
|
-
decision: "activated",
|
|
331
|
-
write,
|
|
332
|
-
learning,
|
|
333
|
-
learningFailure: null,
|
|
334
|
-
activation: {
|
|
335
|
-
requested: true,
|
|
336
|
-
activated: true,
|
|
337
|
-
boundary: "activated",
|
|
338
|
-
receiptId: activation.id,
|
|
339
|
-
destination: activation.destination,
|
|
340
|
-
destinationRevisionId: activation.destinationRevisionId,
|
|
341
|
-
effectiveAt: activation.effectiveAt,
|
|
342
|
-
},
|
|
343
|
-
});
|
|
344
|
-
},
|
|
345
|
-
};
|
|
346
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
GovernedLearningActivationCaller,
|
|
3
|
-
ActivateGovernedLearningDecisionRequest,
|
|
4
|
-
UndoGovernedLearningActivationRequest,
|
|
5
|
-
type GovernedLearningActivationReceipt,
|
|
6
|
-
type GovernedLearningActivationUndoReceipt,
|
|
7
|
-
} from "@opengeni/contracts";
|
|
8
|
-
import {
|
|
9
|
-
activateGovernedLearningDecision,
|
|
10
|
-
undoGovernedLearningActivation,
|
|
11
|
-
type Database,
|
|
12
|
-
} from "@opengeni/db";
|
|
13
|
-
|
|
14
|
-
export function createGovernedLearningActivationController(options: {
|
|
15
|
-
db: Database;
|
|
16
|
-
activate?: typeof activateGovernedLearningDecision;
|
|
17
|
-
undo?: typeof undoGovernedLearningActivation;
|
|
18
|
-
}): {
|
|
19
|
-
activate(input: {
|
|
20
|
-
caller: unknown;
|
|
21
|
-
request: unknown;
|
|
22
|
-
}): Promise<GovernedLearningActivationReceipt>;
|
|
23
|
-
undo(input: {
|
|
24
|
-
caller: unknown;
|
|
25
|
-
request: unknown;
|
|
26
|
-
}): Promise<GovernedLearningActivationUndoReceipt>;
|
|
27
|
-
} {
|
|
28
|
-
const activate = options.activate ?? activateGovernedLearningDecision;
|
|
29
|
-
const undo = options.undo ?? undoGovernedLearningActivation;
|
|
30
|
-
return {
|
|
31
|
-
async activate(input) {
|
|
32
|
-
return await activate(options.db, {
|
|
33
|
-
caller: GovernedLearningActivationCaller.parse(input.caller),
|
|
34
|
-
request: ActivateGovernedLearningDecisionRequest.parse(input.request),
|
|
35
|
-
});
|
|
36
|
-
},
|
|
37
|
-
async undo(input) {
|
|
38
|
-
return await undo(options.db, {
|
|
39
|
-
caller: GovernedLearningActivationCaller.parse(input.caller),
|
|
40
|
-
request: UndoGovernedLearningActivationRequest.parse(input.request),
|
|
41
|
-
});
|
|
42
|
-
},
|
|
43
|
-
};
|
|
44
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
GOVERNED_LEARNING_AUTOMATIC_CONFIDENCE_FLOOR_BPS,
|
|
3
|
-
GovernedLearningDecision,
|
|
4
|
-
GovernedLearningDecisionFacts,
|
|
5
|
-
type GovernedLearningDecision as GovernedLearningDecisionType,
|
|
6
|
-
type GovernedLearningDecisionFacts as GovernedLearningDecisionFactsType,
|
|
7
|
-
type GovernedLearningDecisionReason,
|
|
8
|
-
} from "@opengeni/contracts";
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Pure, closed evaluator mirrored by the 0268 database authority. It never
|
|
12
|
-
* receives source content and cannot activate a destination authority.
|
|
13
|
-
*/
|
|
14
|
-
export function deriveGovernedLearningDecision(
|
|
15
|
-
input: GovernedLearningDecisionFactsType,
|
|
16
|
-
): GovernedLearningDecisionType {
|
|
17
|
-
const facts = GovernedLearningDecisionFacts.parse(input);
|
|
18
|
-
const reasons: GovernedLearningDecisionReason[] = [];
|
|
19
|
-
|
|
20
|
-
if (facts.effectiveMode === "off") reasons.push("policy_off");
|
|
21
|
-
if (facts.revoked) reasons.push("evidence_revoked");
|
|
22
|
-
if (facts.stale) reasons.push("proposal_stale");
|
|
23
|
-
if (facts.conflictCount > 0) reasons.push("evidence_conflict");
|
|
24
|
-
if (facts.confidenceBps < GOVERNED_LEARNING_AUTOMATIC_CONFIDENCE_FLOOR_BPS) {
|
|
25
|
-
reasons.push("confidence_below_floor");
|
|
26
|
-
}
|
|
27
|
-
if (facts.effectiveMode === "suggest") reasons.push("policy_suggest");
|
|
28
|
-
if (facts.effectiveMode === "automatic") reasons.push("policy_automatic");
|
|
29
|
-
|
|
30
|
-
const outcome =
|
|
31
|
-
facts.effectiveMode === "off"
|
|
32
|
-
? "off"
|
|
33
|
-
: facts.revoked
|
|
34
|
-
? "revoked"
|
|
35
|
-
: facts.stale
|
|
36
|
-
? "stale"
|
|
37
|
-
: facts.conflictCount > 0
|
|
38
|
-
? "conflict"
|
|
39
|
-
: facts.confidenceBps < GOVERNED_LEARNING_AUTOMATIC_CONFIDENCE_FLOOR_BPS
|
|
40
|
-
? "confidence"
|
|
41
|
-
: facts.effectiveMode;
|
|
42
|
-
|
|
43
|
-
return GovernedLearningDecision.parse({
|
|
44
|
-
outcome,
|
|
45
|
-
reasons,
|
|
46
|
-
automaticEligible: outcome === "automatic",
|
|
47
|
-
confidenceFloorBps: GOVERNED_LEARNING_AUTOMATIC_CONFIDENCE_FLOOR_BPS,
|
|
48
|
-
});
|
|
49
|
-
}
|