// Block contract for `@levelset/level-blocks`. // // A Block is the LCNC composition unit: a typed quadruple shared by the // visual editor, the LLM agent, and the compiler. // Four families differ only in the output type `O`: // // • Constraint blocks — O = Constraint // • Scoring blocks — O = Scorer // • Search blocks — O = Search | SearchTransformer // • Collector blocks — O = Collector (selection layer, not a solver // constraint — `toMiniZinc` emits an explanatory `% comment` fragment) // // Constraint variants are the *interchange format* between Constraint blocks // and Search; the ADT is the wire, the Block is the cable. import type { ZodType } from "zod"; import type { Collector, Constraint, Scorer, Search, SearchTransformer, } from "../level-core/types.ts"; /** Top-level MiniZinc text emitted for a single block — `constraint`, * `var`, `array`, etc. The compiler concatenates fragments and resolves * shared symbols (`active[t,d]`, `tasks_demanding[r]`, `DAYS`). */ export interface MiniZincFragment { readonly text: string; } /** Optional escape hatch for blocks where MiniZinc → FlatZinc loses * structure the underlying CP-SAT model can express directly. */ export interface CpSatFragment { readonly text: string; } export interface BlockDoc { readonly nl: string; readonly pseudocode: string; } export interface Block { readonly id: string; readonly schema: { readonly input: ZodType; readonly output: ZodType; }; apply(input: I): O; toMiniZinc(input: I): MiniZincFragment; toCpSat?(input: I): CpSatFragment; readonly doc: BlockDoc; } export type ConstraintBlock = Block; /** A policy/group block that expands one authored instance into several * ordinary engine constraints. */ export type MultiConstraintBlock = Block; export type ScoringBlock = Block; export type SearchBlock = Block; export type CollectorBlock = Block;