Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions app/api/shape/route.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import { NextRequest, NextResponse } from "next/server";
import { shape } from "@/lib/shape";
import { reportShapeError } from "@/lib/monitoring";
import type { ShapeEngine, ShapeProfile } from "@/lib/types";

const VALID_PROFILES = ["narrative_segment_v0", "concept_blob_v0"];
const VALID_ENGINES = ["openai", "local"];

export async function POST(request: NextRequest) {
let engineForReport: ShapeEngine | "unknown" = "unknown";
let profileForReport: ShapeProfile | "unknown" | "default" = "unknown";
try {
const body = await request.json();
const text = body?.text;
Expand All @@ -30,17 +27,12 @@ export async function POST(request: NextRequest) {
engine && VALID_ENGINES.includes(engine)
? (engine as ShapeEngine)
: "openai";
engineForReport = engineOverride;
profileForReport = profileOverride ?? "default";

const result = await shape(text, profileOverride, engineOverride);
return NextResponse.json(result);
} catch (err: unknown) {
const message = err instanceof Error ? err.message : "Unknown error";
await reportShapeError(err, "POST /api/shape", {
engine: engineForReport,
profile: profileForReport,
});
console.error("[/api/shape]", err);
return NextResponse.json({ error: message }, { status: 500 });
}
}
9 changes: 2 additions & 7 deletions lib/engine.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { buildSystemPrompt } from "./prompt";
import { runLocalShape } from "./local-engine";
import { runOpenAIShapePrompt } from "./model";
import { reportShapeError } from "./monitoring";
import type { ShapeEngine, ShapeProfile } from "./types";

export async function runShapeEngine({
Expand All @@ -22,12 +21,8 @@ export async function runShapeEngine({

try {
return JSON.parse(raw);
} catch (err) {
await reportShapeError(err, "runShapeEngine.parseModelJson", {
engine,
profile,
raw_preview: raw.slice(0, 200),
});
} catch {
console.error("[engine] model returned invalid JSON");
throw new Error("Model returned invalid JSON");
}
}
68 changes: 0 additions & 68 deletions lib/monitoring.ts

This file was deleted.