Spaces:
Sleeping
Sleeping
fix: normalize auditor policy feedback
Browse files- lib/agent/nodes/auditor.ts +18 -1
lib/agent/nodes/auditor.ts
CHANGED
|
@@ -6,6 +6,20 @@ import { chatComplete } from "../llm";
|
|
| 6 |
import { extractJSON, loadPolicy } from "../utils";
|
| 7 |
import { ResearchState, AuditResult, appendReasoning } from "../state";
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
/**
|
| 10 |
* Compares the current plan against POLICY.md.
|
| 11 |
* Sets `auditResult` with verdict + structured feedback.
|
|
@@ -64,8 +78,11 @@ ${JSON.stringify(state.plan, null, 2)}
|
|
| 64 |
throw new Error(`Auditor produced non-JSON output: ${rawThought.slice(0, 300)}`);
|
| 65 |
}
|
| 66 |
|
|
|
|
| 67 |
const auditResult = AuditResult.parse({
|
| 68 |
-
...
|
|
|
|
|
|
|
| 69 |
auditedAt: new Date().toISOString(),
|
| 70 |
});
|
| 71 |
|
|
|
|
| 6 |
import { extractJSON, loadPolicy } from "../utils";
|
| 7 |
import { ResearchState, AuditResult, appendReasoning } from "../state";
|
| 8 |
|
| 9 |
+
function normalizeStringArray(value: unknown): string[] {
|
| 10 |
+
if (!Array.isArray(value)) return [];
|
| 11 |
+
return value.map((item) => {
|
| 12 |
+
if (typeof item === "string") return item;
|
| 13 |
+
if (item && typeof item === "object") {
|
| 14 |
+
const obj = item as Record<string, unknown>;
|
| 15 |
+
if (typeof obj.reason === "string") return obj.reason;
|
| 16 |
+
if (typeof obj.message === "string") return obj.message;
|
| 17 |
+
return JSON.stringify(obj);
|
| 18 |
+
}
|
| 19 |
+
return String(item);
|
| 20 |
+
});
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
/**
|
| 24 |
* Compares the current plan against POLICY.md.
|
| 25 |
* Sets `auditResult` with verdict + structured feedback.
|
|
|
|
| 78 |
throw new Error(`Auditor produced non-JSON output: ${rawThought.slice(0, 300)}`);
|
| 79 |
}
|
| 80 |
|
| 81 |
+
const base = parsed as Record<string, unknown>;
|
| 82 |
const auditResult = AuditResult.parse({
|
| 83 |
+
...base,
|
| 84 |
+
policyViolations: normalizeStringArray(base.policyViolations),
|
| 85 |
+
suggestions: normalizeStringArray(base.suggestions),
|
| 86 |
auditedAt: new Date().toISOString(),
|
| 87 |
});
|
| 88 |
|