mirror of
https://github.com/morluto/rea.git
synced 2026-11-15 19:23:24 +00:00
refactor(artifacts): consolidate inventory into inspection
This commit is contained in:
1 parent
a66e43a99d
commit
0fe96d92df
28 files changed
+375
-280
No files matched your search
@@ -4,6 +4,7 @@ import type { AnalysisOperationPort } from "../application/AnalysisProvider.js";
|
||||
import type { BinarySessionPort } from "../application/BinarySession.js";
|
||||
import type { PromptCompletionKind } from "../contracts/promptContracts.js";
|
||||
import { artifactInventoryResultSchema } from "../domain/artifactGraph.js";
|
||||
import { artifactInspectionResultSchema } from "../domain/artifactInspection.js";
|
||||
import { processCaptureSchema } from "../domain/processCapture.js";
|
||||
|
||||
const documentListSchema = z.array(z.string().min(1));
|
||||
@@ -145,10 +146,21 @@ const evidenceValues = (
|
||||
if (kind === "evidence") return [evidence.evidence_id];
|
||||
if (kind === "capture")
|
||||
return isProcessCaptureEvidence(evidence) ? [evidence.evidence_id] : [];
|
||||
if (evidence.operation !== "inventory_artifact") return [];
|
||||
const inventory = artifactInventoryResultSchema.safeParse(
|
||||
evidence.normalized_result,
|
||||
);
|
||||
const inventoryResult =
|
||||
evidence.operation === "inventory_artifact"
|
||||
? evidence.normalized_result
|
||||
: evidence.operation === "inspect_artifact"
|
||||
? (() => {
|
||||
const inspection = artifactInspectionResultSchema.safeParse(
|
||||
evidence.normalized_result,
|
||||
);
|
||||
return inspection.success
|
||||
? inspection.data.substeps[0]?.evidence.normalized_result
|
||||
: undefined;
|
||||
})()
|
||||
: undefined;
|
||||
if (inventoryResult === undefined) return [];
|
||||
const inventory = artifactInventoryResultSchema.safeParse(inventoryResult);
|
||||
if (!inventory.success) return [];
|
||||
if (kind === "manifest") return [inventory.data.manifest.manifest_id];
|
||||
return inventory.data.occurrences.map(({ occurrence_id: id }) => id);
|
||||
|
||||
@@ -24,7 +24,7 @@ export const registerArtifactComparisonTool = (
|
||||
toolRegistrationOptions(contract),
|
||||
async (input, context) => {
|
||||
const expected = {
|
||||
operation: "inventory_artifact",
|
||||
operation: ["inspect_artifact", "inventory_artifact"],
|
||||
predicate: "rea.analysis/v2",
|
||||
};
|
||||
const left = resolveSessionEvidenceIds(
|
||||
|
||||
@@ -13,9 +13,16 @@ type EvidenceAuthorityResult = Result<Evidence[], EvidenceIntegrityError>;
|
||||
export const resolveSessionEvidenceIds = (
|
||||
session: BinarySessionPort,
|
||||
evidenceIds: readonly string[],
|
||||
expected: { readonly operation: string; readonly predicate: string },
|
||||
expected: {
|
||||
readonly operation: string | readonly string[];
|
||||
readonly predicate: string;
|
||||
},
|
||||
): EvidenceAuthorityResult => {
|
||||
const records: Evidence[] = [];
|
||||
const expectedOperations = Array.isArray(expected.operation)
|
||||
? expected.operation
|
||||
: [expected.operation];
|
||||
const expectedOperationLabel = expectedOperations.join(" or ");
|
||||
for (const evidenceId of evidenceIds) {
|
||||
const record = session.evidenceById(evidenceId);
|
||||
if (record === undefined)
|
||||
@@ -23,16 +30,16 @@ export const resolveSessionEvidenceIds = (
|
||||
new EvidenceReferenceError(
|
||||
evidenceId,
|
||||
"missing",
|
||||
expected.operation,
|
||||
expectedOperationLabel,
|
||||
null,
|
||||
),
|
||||
);
|
||||
if (record.operation !== expected.operation)
|
||||
if (!expectedOperations.includes(record.operation))
|
||||
return err(
|
||||
new EvidenceReferenceError(
|
||||
evidenceId,
|
||||
"wrong_operation",
|
||||
expected.operation,
|
||||
expectedOperationLabel,
|
||||
record.operation,
|
||||
),
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user