-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi-types.ts
More file actions
42 lines (37 loc) · 1.07 KB
/
Copy pathapi-types.ts
File metadata and controls
42 lines (37 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import type { Invoice } from "./schema";
import type { Anomaly } from "./anomalies";
import type { ValidationIssue, TokenUsage } from "./anthropic";
/**
* The wire contract for POST /api/parse. The client and server both import
* these types, so a change to the response shape is a compile error on both
* sides — not a runtime surprise.
*/
export interface ParseSuccess {
ok: true;
invoice: Invoice;
anomalies: Anomaly[];
meta: {
fileName: string;
model: string;
usage: TokenUsage;
elapsedMs: number;
};
}
/** Stable machine-readable failure codes, each mapped to a distinct UI state. */
type ParseErrorCode =
| "rate_limited"
| "bad_request"
| "validation_failed"
| "no_data"
| "model_refused"
| "upstream_error";
export interface ParseError {
ok: false;
code: ParseErrorCode;
message: string;
/** Present only for validation_failed — the Zod issues to surface in the UI. */
issues?: ValidationIssue[];
/** Present only for rate_limited. */
retryAfterSeconds?: number;
}
export type ParseResponse = ParseSuccess | ParseError;