documentation cleanse, sprints work and planning. remaining non EF DAL migration to EF
This commit is contained in:
@@ -21,6 +21,8 @@ using StellaOps.AdvisoryAI.WebService.Security;
|
||||
using StellaOps.Auth.ServerIntegration.Tenancy;
|
||||
using System.Collections.Immutable;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using static StellaOps.Localization.T;
|
||||
|
||||
@@ -166,6 +168,17 @@ public static class ChatEndpoints
|
||||
|
||||
if (!result.Success)
|
||||
{
|
||||
if (!result.GuardrailBlocked && !result.QuotaBlocked && !result.ToolAccessDenied)
|
||||
{
|
||||
logger.LogWarning(
|
||||
"Chat gateway runtime fallback activated for tenant {TenantId}, user {UserId}. Reason: {Reason}",
|
||||
tenantId,
|
||||
userId,
|
||||
result.Error ?? "processing_failed");
|
||||
|
||||
return Results.Ok(CreateDeterministicFallbackQueryResponse(request, result));
|
||||
}
|
||||
|
||||
var statusCode = result.GuardrailBlocked
|
||||
? StatusCodes.Status400BadRequest
|
||||
: result.QuotaBlocked
|
||||
@@ -858,6 +871,60 @@ public static class ChatEndpoints
|
||||
} : null
|
||||
};
|
||||
}
|
||||
|
||||
private static AdvisoryChatQueryResponse CreateDeterministicFallbackQueryResponse(
|
||||
AdvisoryChatQueryRequest request,
|
||||
AdvisoryChatServiceResult failedResult)
|
||||
{
|
||||
var diagnostics = failedResult.Diagnostics is null
|
||||
? null
|
||||
: new DiagnosticsResponse
|
||||
{
|
||||
IntentRoutingMs = failedResult.Diagnostics.IntentRoutingMs,
|
||||
EvidenceAssemblyMs = failedResult.Diagnostics.EvidenceAssemblyMs,
|
||||
InferenceMs = failedResult.Diagnostics.InferenceMs,
|
||||
TotalMs = failedResult.Diagnostics.TotalMs,
|
||||
PromptTokens = failedResult.Diagnostics.PromptTokens,
|
||||
CompletionTokens = failedResult.Diagnostics.CompletionTokens,
|
||||
};
|
||||
|
||||
var reason = string.IsNullOrWhiteSpace(failedResult.Error)
|
||||
? "chat runtime unavailable"
|
||||
: failedResult.Error.Trim();
|
||||
var normalizedQuery = request.Query?.Trim() ?? string.Empty;
|
||||
var fallbackId = BuildFallbackResponseId(normalizedQuery, reason);
|
||||
|
||||
return new AdvisoryChatQueryResponse
|
||||
{
|
||||
ResponseId = fallbackId,
|
||||
BundleId = null,
|
||||
Intent = (failedResult.Intent ?? AdvisoryChatIntent.General).ToString(),
|
||||
GeneratedAt = DateTimeOffset.UtcNow,
|
||||
Summary =
|
||||
$"Chat runtime is temporarily unavailable. For \"{normalizedQuery}\", start with unified search evidence, verify VEX status, and confirm active policy gates before acting.",
|
||||
Confidence = new ConfidenceResponse { Level = ConfidenceLevel.Low.ToString(), Score = 0.2d },
|
||||
EvidenceLinks = [],
|
||||
Mitigations = [],
|
||||
ProposedActions = [],
|
||||
FollowUp = new FollowUpResponse
|
||||
{
|
||||
SuggestedQueries = [normalizedQuery],
|
||||
NextSteps =
|
||||
[
|
||||
"Retry this chat query after runtime recovery.",
|
||||
"Use global search to review findings, VEX, and policy context now."
|
||||
]
|
||||
},
|
||||
Diagnostics = diagnostics,
|
||||
};
|
||||
}
|
||||
|
||||
private static string BuildFallbackResponseId(string query, string reason)
|
||||
{
|
||||
var bytes = SHA256.HashData(Encoding.UTF8.GetBytes($"{query}|{reason}"));
|
||||
var token = Convert.ToHexString(bytes.AsSpan(0, 8)).ToLowerInvariant();
|
||||
return $"fallback-{token}";
|
||||
}
|
||||
}
|
||||
|
||||
#region Request/Response DTOs
|
||||
|
||||
Reference in New Issue
Block a user