@sema-agent/core
Version:
Stateless, task-oriented AI agent core
36 lines (35 loc) • 1.55 kB
TypeScript
import type { TSchema } from "typebox";
/** Port of 204 `Lqn` — derive the strict form of a whole schema (root must be `type:"object"`). */
export declare function deriveStrictSchema(schema: unknown): {
ok: true;
schema: Record<string, unknown>;
} | {
ok: false;
reason: string;
};
/** Exposed for callers that only need validity (no derivation). Runs the size guard first. */
export declare function validateJsonSchemaShape(schema: unknown): string | null;
export type CompiledOutputSchema =
/** The schema is not a valid JSON Schema (or too large) — callers must FAIL FAST, never run silently. */
{
error: string;
}
/** Strict derivation succeeded: `modelSchema` is the tightened form to hand the model. */
| {
modelSchema: TSchema;
strict: true;
}
/** Valid but outside the strict subset: serve the schema as-is; `fallbackReason` is the observable why. */
| {
modelSchema: TSchema;
strict: false;
fallbackReason: string;
};
/**
* Validate + strict-derive a structured-output schema (CC 2.1.205 semantics):
* invalid / oversized schema → `{error}` (the caller throws — no silent acceptance);
* in-subset schema → `{modelSchema: strictForm, strict:true}` (`additionalProperties:false` stamped);
* valid-but-unsupported schema → `{modelSchema: original, strict:false, fallbackReason}` (observable).
* A derivation CRASH also falls back non-strict (CC's inner try/catch), never fails the task.
*/
export declare function compileOutputSchema(schema: TSchema): CompiledOutputSchema;