feat: 持久化运维审计日志
This commit is contained in:
+22
-10
@@ -42,11 +42,18 @@ export class AgentService {
|
||||
);
|
||||
}
|
||||
|
||||
async createInvocation(input: CreateAgentInvocationInput): Promise<AgentInvocation> {
|
||||
async createInvocation(
|
||||
input: CreateAgentInvocationInput,
|
||||
): Promise<AgentInvocation> {
|
||||
if (!allowedTypes.includes(input.type)) {
|
||||
throw new AppError('VALIDATION_FAILED', 'Unsupported agent invocation type', 400, {
|
||||
type: input.type,
|
||||
});
|
||||
throw new AppError(
|
||||
'VALIDATION_FAILED',
|
||||
'Unsupported agent invocation type',
|
||||
400,
|
||||
{
|
||||
type: input.type,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
const llmHealth = this.llmClient.healthSummary();
|
||||
@@ -74,7 +81,7 @@ export class AgentService {
|
||||
status: 'success',
|
||||
resultMarkdown: completion.text || mockResults[input.type],
|
||||
};
|
||||
this.recordInvocationAudit(invocation, 'llm', completion.model);
|
||||
await this.recordInvocationAudit(invocation, 'llm', completion.model);
|
||||
} catch (error) {
|
||||
invocation = {
|
||||
...baseInvocation,
|
||||
@@ -84,7 +91,7 @@ export class AgentService {
|
||||
? redactSensitive({ message: error.message }).message
|
||||
: 'LLM invocation failed',
|
||||
};
|
||||
this.recordInvocationAudit(invocation, 'llm_failed');
|
||||
await this.recordInvocationAudit(invocation, 'llm_failed');
|
||||
}
|
||||
} else {
|
||||
invocation = {
|
||||
@@ -92,25 +99,30 @@ export class AgentService {
|
||||
status: 'success',
|
||||
resultMarkdown: mockResults[input.type],
|
||||
};
|
||||
this.recordInvocationAudit(invocation, 'mock', undefined, llmHealth.message);
|
||||
await this.recordInvocationAudit(
|
||||
invocation,
|
||||
'mock',
|
||||
undefined,
|
||||
llmHealth.message,
|
||||
);
|
||||
}
|
||||
|
||||
this.invocations.unshift(invocation);
|
||||
return invocation;
|
||||
}
|
||||
|
||||
private recordInvocationAudit(
|
||||
private async recordInvocationAudit(
|
||||
invocation: AgentInvocation,
|
||||
mode: 'mock' | 'llm' | 'llm_failed',
|
||||
model?: string,
|
||||
reason?: string,
|
||||
): void {
|
||||
): Promise<void> {
|
||||
const action =
|
||||
invocation.status === 'failed'
|
||||
? 'AGENT_INVOCATION_FAILED'
|
||||
: 'AGENT_INVOCATION_CREATED';
|
||||
|
||||
this.auditService.record({
|
||||
await this.auditService.record({
|
||||
action,
|
||||
resourceType: 'agent_invocation',
|
||||
resourceId: invocation.id,
|
||||
|
||||
Reference in New Issue
Block a user