feat: add guarded document workbench foundations
CI (SIAX Cloud) / integration (push) Skipped
CI (SIAX Cloud) / sonar (push) Skipped
masterplan-lock / check (push) Successful in 5s
Security Scan (SIAX Cloud) / security (push) Successful in 15s
CI (SIAX Cloud) / security (push) Successful in 16s
CI (SIAX Cloud) / sonar (pull_request) Skipped
masterplan-lock / check (pull_request) Successful in 7s
Security Scan (SIAX Cloud) / security (pull_request) Successful in 21s
CI (SIAX Cloud) / security (pull_request) Successful in 25s
CI (SIAX Cloud) / quality (push) Successful in 1m17s
CI (SIAX Cloud) / integration (pull_request) Successful in 54s
CI (SIAX Cloud) / quality (pull_request) Successful in 1m7s
CI (SIAX Cloud) / integration (push) Skipped
CI (SIAX Cloud) / sonar (push) Skipped
masterplan-lock / check (push) Successful in 5s
Security Scan (SIAX Cloud) / security (push) Successful in 15s
CI (SIAX Cloud) / security (push) Successful in 16s
CI (SIAX Cloud) / sonar (pull_request) Skipped
masterplan-lock / check (pull_request) Successful in 7s
Security Scan (SIAX Cloud) / security (pull_request) Successful in 21s
CI (SIAX Cloud) / security (pull_request) Successful in 25s
CI (SIAX Cloud) / quality (push) Successful in 1m17s
CI (SIAX Cloud) / integration (pull_request) Successful in 54s
CI (SIAX Cloud) / quality (pull_request) Successful in 1m7s
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
/**
|
||||
* Admission decision only. All policy, context and reservation values must be
|
||||
* obtained from trusted server-side stores; this function does not verify a
|
||||
* user identity, reserve credits, or call INF0 or a model provider.
|
||||
*/
|
||||
export interface ModelAdmissionRequest {
|
||||
tenantId: string;
|
||||
projectId: string;
|
||||
jobId: string;
|
||||
modelId: string;
|
||||
dataClass: string;
|
||||
maxInputTokens: number;
|
||||
maxOutputTokens: number;
|
||||
maximumCredits: number;
|
||||
}
|
||||
export interface ModelExecutionPolicy {
|
||||
tenantId: string;
|
||||
projectId: string;
|
||||
allowedModelIds: readonly string[];
|
||||
allowedDataClasses: readonly string[];
|
||||
/** Destination is determined from the operator's verified model registry. */
|
||||
destination: 'internal' | 'external';
|
||||
externalTransferAllowed: boolean;
|
||||
maxInputTokens: number;
|
||||
maxOutputTokens: number;
|
||||
}
|
||||
export interface ModelBudgetReservation {
|
||||
tenantId: string;
|
||||
projectId: string;
|
||||
jobId: string;
|
||||
status: 'reserved' | 'settled' | 'released';
|
||||
credits: number;
|
||||
}
|
||||
export type ModelAdmission = { allowed: true } | {
|
||||
allowed: false;
|
||||
reason: 'invalid_request' | 'scope_mismatch' | 'model_not_allowed' | 'data_class_not_allowed'
|
||||
| 'external_transfer_denied' | 'token_limit_exceeded' | 'reservation_required';
|
||||
};
|
||||
|
||||
export function admitModelExecution(
|
||||
request: ModelAdmissionRequest,
|
||||
policy: ModelExecutionPolicy,
|
||||
reservation: ModelBudgetReservation | undefined,
|
||||
): ModelAdmission {
|
||||
const names = [request.tenantId, request.projectId, request.jobId, request.modelId, request.dataClass, policy.tenantId, policy.projectId];
|
||||
if (!names.every((s) => typeof s === 'string' && s.trim())
|
||||
|| !Array.isArray(policy.allowedModelIds) || !Array.isArray(policy.allowedDataClasses)
|
||||
|| !['none', 'low', 'medium', 'high', 'restricted'].includes(request.dataClass)
|
||||
|| !['internal', 'external'].includes(policy.destination) || typeof policy.externalTransferAllowed !== 'boolean'
|
||||
|| ![request.maxInputTokens, request.maxOutputTokens, request.maximumCredits, policy.maxInputTokens, policy.maxOutputTokens]
|
||||
.every((n) => Number.isSafeInteger(n) && n > 0)) return { allowed: false, reason: 'invalid_request' };
|
||||
if (request.tenantId !== policy.tenantId || request.projectId !== policy.projectId) return { allowed: false, reason: 'scope_mismatch' };
|
||||
if (!policy.allowedModelIds.includes(request.modelId)) return { allowed: false, reason: 'model_not_allowed' };
|
||||
if (!policy.allowedDataClasses.includes(request.dataClass)) return { allowed: false, reason: 'data_class_not_allowed' };
|
||||
if (policy.destination === 'external' && (!policy.externalTransferAllowed || ['high', 'restricted'].includes(request.dataClass))) {
|
||||
return { allowed: false, reason: 'external_transfer_denied' };
|
||||
}
|
||||
if (request.maxInputTokens > policy.maxInputTokens || request.maxOutputTokens > policy.maxOutputTokens) {
|
||||
return { allowed: false, reason: 'token_limit_exceeded' };
|
||||
}
|
||||
if (!reservation || reservation.tenantId !== request.tenantId || reservation.projectId !== request.projectId
|
||||
|| reservation.jobId !== request.jobId || reservation.status !== 'reserved'
|
||||
|| !Number.isSafeInteger(reservation.credits) || reservation.credits < request.maximumCredits) {
|
||||
return { allowed: false, reason: 'reservation_required' };
|
||||
}
|
||||
return { allowed: true };
|
||||
}
|
||||
Reference in New Issue
Block a user