chore: preserve initial reconstruction prototype
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
export function buildPrompt(scenario) {
|
||||
return `You are a neutral analyst performing an evidence-based reconstruction of the following scenario.
|
||||
|
||||
Rules:
|
||||
1. Do NOT invent facts. Only include information present in the scenario or clearly implied.
|
||||
2. Distinguish carefully between:
|
||||
- Direct observations (you witnessed directly)
|
||||
- Reported claims (statements made by another person/entity)
|
||||
- Interpretations (your analysis of what something means)
|
||||
- Unsupported assumptions (things you are guessing without evidence)
|
||||
3. If information is unknown, place it under "openUncertainties" — never guess.
|
||||
4. Be precise, concise, and grounded in the text.
|
||||
|
||||
Scenario:
|
||||
${scenario}
|
||||
|
||||
Return valid JSON matching this structure exactly:
|
||||
{
|
||||
"observations": [{"id": "...", "description": "...", "confidence": "low|medium|high"}],
|
||||
"reportedClaims": [{"id": "...", "description": "...", "confidence": "low|medium|high", "attributedTo": "person/entity or null"}],
|
||||
"assumptions": [{"id": "...", "description": "...", "confidence": "low|medium|high"}],
|
||||
"entities": [{"id": "...", "description": "...", "confidence": "low|medium|high"}],
|
||||
"transitions": [{"id": "...", "description": "...", "confidence": "low|medium|high", "entity": "...", "previousState": "...", "currentState": "...", "explanationStatus": "..."}],
|
||||
"expectedButMissing": [{"id": "...", "description": "...", "confidence": "low|medium|high"}],
|
||||
"presentButUnexpected": [{"id": "...", "description": "...", "confidence": "low|medium|high"}],
|
||||
"contradictions": [{"id": "...", "description": "...", "confidence": "low|medium|high"}],
|
||||
"openUncertainties": [{"id": "...", "description": "...", "confidence": "low|medium|high"}]
|
||||
}
|
||||
|
||||
Return ONLY the JSON object. No markdown, no explanation, no preamble.`;
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
import { z } from "zod";
|
||||
|
||||
const confidenceEnum = z.enum(["low", "medium", "high"]);
|
||||
|
||||
const itemSchema = z.object({
|
||||
id: z.string().min(1),
|
||||
description: z.string().min(1),
|
||||
confidence: confidenceEnum,
|
||||
});
|
||||
|
||||
export const reconstructionSchema = z.object({
|
||||
observations: z.array(itemSchema),
|
||||
reportedClaims: z.array(
|
||||
itemSchema.extend({
|
||||
attributedTo: z.union([z.string().min(1), z.null()]).optional().nullable(),
|
||||
})
|
||||
),
|
||||
assumptions: z.array(itemSchema),
|
||||
entities: z.array(itemSchema),
|
||||
transitions: z.array(
|
||||
itemSchema.extend({
|
||||
entity: z.string().min(1),
|
||||
previousState: z.string().min(1),
|
||||
currentState: z.string().min(1),
|
||||
explanationStatus: z.string().min(1),
|
||||
})
|
||||
),
|
||||
expectedButMissing: z.array(itemSchema),
|
||||
presentButUnexpected: z.array(itemSchema),
|
||||
contradictions: z.array(itemSchema),
|
||||
openUncertainties: z.array(itemSchema),
|
||||
});
|
||||
|
||||
export const analyseResponseSchema = z.object({
|
||||
reconstruction: reconstructionSchema,
|
||||
modelName: z.string(),
|
||||
responseDurationMs: z.number(),
|
||||
validationStatus: z.enum(["valid", "partial", "invalid"]),
|
||||
rawResponse: z.string().optional(),
|
||||
errors: z.array(z.string()).optional(),
|
||||
});
|
||||
|
||||
export const healthResponseSchema = z.object({
|
||||
configPresent: z.boolean(),
|
||||
baseUrl: z.string().nullable(),
|
||||
model: z.string().nullable(),
|
||||
reachable: z.boolean(),
|
||||
error: z.string().nullable(),
|
||||
});
|
||||
|
||||
export function parseReconstruction(raw) {
|
||||
if (typeof raw === "string") {
|
||||
try {
|
||||
raw = JSON.parse(raw);
|
||||
} catch {
|
||||
throw new SyntaxError("Model response is not valid JSON");
|
||||
}
|
||||
}
|
||||
return reconstructionSchema.parse(raw);
|
||||
}
|
||||
Reference in New Issue
Block a user