/** * Circuit domain types: the document shape a host converts into a SimCircuit, * plus the catalog identity the engine resolves against. * * Scope is deliberately engine-only. A host's editor document carries more — * wire colours and waypoints, canvas annotations, per-component labels and * lock flags, palette/BOM/teaching metadata on catalog entries — and none of * it reaches a stamp, so none of it is modelled here. Publishing those fields * would freeze one host's editor and product schema into an engine package's * public API. Hosts keep their own richer document/catalog types and hand the * engine the subset below. */ export type Rotation = 0 | 90 | 180 | 270; export interface Position { x: number; y: number; } export declare const COMPONENT_KINDS: readonly ["breadboard", "voltage_source", "battery_pack", "bench_psu", "pulse_gen", "clock_gen", "signal_gen", "pulse_source", "clock", "resistor", "capacitor", "inductor", "led", "diode", "zener_diode", "schottky_diode", "switch", "ne555", "ic", "bjt_npn", "bjt_pnp", "nmos", "pmos", "bicolor_led", "rgb_led", "push_button", "spdt_switch", "push_dpdt", "potentiometer", "fuse", "trimmer", "ldr", "thermistor", "74ls00", "74ls04", "74ls08", "74ls32", "74ls86", "74ls161", "74ls173", "74ls189", "74ls157", "74ls153", "74ls245", "74ls283", "74hc595", "74hc165", "74hc14", "74hc138", "74ls47", "74hc74", "cd4017", "cd4511", "cd4060", "28c16", "28c256", "seg7_cc", "seg7_ca", "arduino_uno", "arduino_nano", "raspberry_pi_pico", "microbit", "dip_switch", "tvs_diode", "ptc_fuse", "ferrite_bead", "resistor_array", "lm358", "mcp6002", "lm386", "lm393", "tl431", "linear_reg", "lm317", "dcdc_converter", "relay", "uln2003", "uln2803", "buzzer", "speaker", "l293d", "tb6612", "dc_motor", "servo", "stepper", "max7219", "hd44780", "hcsr04", "coupled_inductor", "njfet", "pjfet", "scr", "triac", "opto_npn", "crystal", "analog_switch", "current_source"]; export type ComponentKind = typeof COMPONENT_KINDS[number]; /** EEPROM component kinds whose params.contents is JSON-revision-only (never live-replicated). */ export declare const EEPROM_KINDS: readonly ["28c16", "28c256"]; export declare function isEepromKind(kind: string): boolean; /** * RAM component kinds. Their optional `params.contents` is a POWER-ON PRELOAD * (coordinator ruling 2026-11-13), shaped like the EEPROMs' image: base64 of * one byte per word, address 0 first, each word in true sense (a 74LS189's * /O pins show its complement). * * - It is what the RAM holds when it powers up. With no contents the RAM * starts exactly as it did before the field existed. * - It is NOT non-volatile. A write changes the live contents only; when the * chip loses power they go, and the preload is back at the next power-up. * - Like an EEPROM's contents it changes only through a circuit revision; it * is never live-replicated. A reload that keeps the chip and its contents * keeps the live words; one that changes the contents starts from them. */ export declare const RAM_KINDS: readonly ["74ls189"]; export type RamKind = (typeof RAM_KINDS)[number]; export declare function isRamKind(kind: string): kind is RamKind; /** Words, and bits per word, of each RAM kind's `params.contents` image. */ export declare const RAM_CONTENTS_SHAPE: Readonly>; /** * The preload both engines load from a RAM's `params.contents`, or null for * none (absent or empty). It mirrors `eepromImageBytes` and never throws: * the value is read through `String()`, a byte past the last address is * dropped, an address the image does not reach keeps the blank word (all * ones, a 74LS189's 0xF), a byte wider than the word keeps its low bits, and * a value that is not base64 is a blank image. An editor checks a value with * {@link ramContentsError} before saving it. */ export declare function ramPreloadWords(kind: RamKind, contents: unknown): number[] | null; /** * Why `contents` is not a well-formed image for `kind`, or null when it is * (or is absent or empty, which is "no preload"): a base64 string of exactly * one byte per word, none wider than the word. Stricter than the engines' * {@link ramPreloadWords}, which loads whatever it is given. */ export declare function ramContentsError(kind: RamKind, contents: unknown): string | null; /** `words` (address 0 first, true sense) as a RAM's `params.contents`. Throws a RangeError on a count or a word the kind cannot hold. */ export declare function encodeRamContents(kind: RamKind, words: readonly number[]): string; /** * Electrical role of a pin, used by the AI assistant to reason about wiring * without inventing function from pin labels alone. Optional everywhere so * legacy catalog entries and instantiated component pins stay valid. */ export type PinFunction = "vcc" | "gnd" | "supply_pos" | "supply_neg" | "input" | "output" | "io" | "open_collector" | "open_drain" | "tri_state" | "analog_in" | "analog_out" | "clock" | "reset" | "enable" | "load" | "passive" | "anode" | "cathode" | "base" | "collector" | "emitter" | "gate" | "drain" | "source" | "wiper"; export interface Pin { id: string; label?: string; offset: Position; net_id?: string | null; function?: PinFunction | null; } export type ComponentParams = Record; export interface CircuitComponent { id: string; kind: ComponentKind; /** * Stable identity of the exact catalog entry used to create this instance. * `kind` selects simulator topology; `catalogUid` selects the physical/model * variant (for example 7805 vs AMS1117, or CR2032 vs 9 V battery). * Optional only for legacy/imported circuits; normal placement and migration * populate it and JSON/collaboration round-trips preserve it verbatim. */ catalogUid?: string; /** * Placement geometry. Kept in the engine's document shape (rather than * treated as host presentation) because board geometry is electrical here: * the MCU breakout resolver rotates a board's corners to decide which * breadboard holes an edge connector lands in — see circuit/arduino.ts. */ position: Position; rotation: Rotation; pins: Pin[]; params: ComponentParams; } export interface Wire { id: string; from_component: string; from_pin: string; to_component: string; to_pin: string; resistance: number; } export interface Net { id: string; pins: [string, string][]; } /** * Circuit-level environmental stimulus that applies to all sensor parts at once. * Moving stimulus here (instead of per-part params) makes it visible, editable, * and saved in one place — so a user can change ambient light for the whole * circuit without hunting for every LDR. */ export interface CircuitEnvironment { /** Ambient temperature in degrees Celsius. Read by temperature-sensitive parts (thermistor). */ temperatureC: number; /** Ambient illuminance in lux. Read by light-sensitive parts (LDR). */ lux: number; } /** * Default environment matches the historical per-part defaults (lux=100, tempC=25) * so circuits with no explicit environment behave identically to before migration. */ export declare const DEFAULT_ENVIRONMENT: CircuitEnvironment; export interface Circuit { id: string; name: string; components: CircuitComponent[]; wires: Wire[]; nets: Net[]; schema_version: number; /** Circuit-level environmental stimulus. Optional because pre-v2 saves lack it. */ environment?: CircuitEnvironment; netLabel?: Record; } /** * Structured operating-envelope source for the AI assistant and the * diagnostics/realism layers (Wave C: diagnostics engine; Waves D/E: * failure-mode and derating models). Every field is optional — passives carry * only what is relevant (e.g. tolerance), LEDs carry forward voltage, ICs * carry supply range and per-pin drive. The model uses this to pick parts, * choose values, and avoid driving outputs past their ratings. */ export interface ElectricalSpecs { /** Forward voltage drop for diodes/LEDs (volts). */ vf?: number; /** Maximum forward current for LEDs/diodes (amps). */ if_max?: number; /** Supply voltage range for ICs (volts). */ vcc_range?: { min: number; nominal: number; max: number; }; /** Typical whole-package quiescent supply current (amps). */ quiescent_current_a?: number; /** Maximum sourcing/sinking current per output pin (amps). */ io_max?: number; /** Logic family — e.g. "LS-TTL", "HC-CMOS", "CMOS 4000". */ logic_family?: string; /** Input voltage thresholds (volts) for digital inputs. v_t_plus/v_t_minus are * Schmitt-trigger hysteresis thresholds defined at vcc_range.nominal; the engine * scales them with the actual supply and holds state in the dead band. */ v_input?: { v_il_max?: number; v_ih_min?: number; v_t_plus?: number; v_t_minus?: number; }; /** Maximum collector/drain current for transistors (amps). */ i_c_max?: number; /** DC current gain (β) for BJTs at the nominal operating point. */ beta_typical?: number; /** Catalog/package power envelope (watts), before any ambient thermal derating. */ p_max?: number; /** * Package/body thermal reference consumed for exact supported catalog * identities. The engine integrates a one-pole temperature and ambient- * adjusted power allowance; electrical feedback and shutdown behavior remain * device-specific and must be disclosed by that model. */ thermal?: { /** Junction/body-to-ambient thermal resistance (°C/W). */ r_theta_ja_c_per_w: number; /** One-pole compact-model time constant (seconds). */ time_constant_s: number; /** Ambient range over which the catalog profile is intended to be used. */ ambient_range_c: { min: number; max: number; }; /** Continuous junction, film, or body-temperature ceiling (°C). */ continuous_temperature_max_c: number; /** Absolute junction, film, or body-temperature ceiling (°C). */ absolute_temperature_max_c: number; /** Package, PCB, or derivation condition behind r_theta_ja_c_per_w. */ r_theta_condition: string; /** Optional reversible protection thresholds for devices that claim it. */ shutdown?: { trip_c: number; restart_c: number; trip_is_assumed?: boolean; restart_is_assumed?: boolean; }; /** Human-readable limits or compact-model assumptions. */ assumptions: string[]; }; /** Maximum reverse/blocking voltage (volts) — rectifier and Schottky diodes. */ vr_max?: number; /** * Breakdown knee current (amps) for zener/TVS diodes — the current flowing * at the rated breakdown voltage. Used to derive Is_z for the breakdown stamp. * Catalog default: 5 mA. */ iz_knee?: number; /** Free-text spec the model can read when nothing structured fits. */ notes?: string; /** * Fractional tolerance on the part's principal value (resistance or capacitance). * 0.05 = ±5%, 0.1 = ±10%, 0.2 = ±20%. Used by the Monte Carlo runner to * perturb params.resistance / params.capacitance per run. */ value_tol?: number; /** * Fractional spread on the forward voltage (Vf). * 0.05 = ±5%. Used by the Monte Carlo runner to perturb params.vf * (and params.vf1/vf2 for bicolor, params.vf_r/vf_g/vf_b for RGB LEDs). */ vf_tol?: number; /** * Fractional spread on logic input thresholds (v_il_max, v_ih_min). * METADATA ONLY in v1: the engine reads thresholds from the catalog module-level * catalogByKind map — there is no per-instance override mechanism — so the * Monte Carlo runner does NOT vary thresholds yet. Populated for documentation * and future runner support. */ vth_tol?: number; /** * Catalog-declared propagation delay (nanoseconds) for logic parts. * The engine prefers this over the kind-prefix fallback map * (propagationDelayForKind in sim-engine.ts). */ prop_delay_ns?: number; /** * Per-path datasheet switching figures in nanoseconds (owner decision 3; * core/spec/w1-datasheet-delays.md): typical at 5 V and the datasheet's * standard load (HC parts: the 4.5 V column), or the maximum where no * typical is published. Read only by the core compiler * (src/core/compile/delays.ts); the classic engine keeps prop_delay_ns and * the family prefix. */ switching_ns?: Record; /** Where switching_ns came from (datasheet, typical or maximum, supply, load). Documentation only; never read. */ switching_source?: string; } /** One datasheet switching path in nanoseconds: a level path carries tplh/tphl, an enable tpzh/tpzl, a disable tphz/tplz. */ export interface SwitchingPathNs { tplh?: number; tphl?: number; tpzh?: number; tpzl?: number; tphz?: number; tplz?: number; } /** * Model identity for one catalog part — the ONLY catalog surface the engine * reads. * * WHY this is narrower than a host's catalog entry: a product catalog also * carries presentation and commerce metadata (display name, palette copy, * teaching text, purchasing/BOM data, tier gating). None of it reaches a * stamp, so none of it belongs in an engine package's public API — shipping * those fields would publish one host's product schema as though the solver * depended on it. Hosts keep their own richer entry type and inject it through * setPartLibrary(): extra properties are simply ignored here, because * TypeScript's excess-property check does not apply to a typed value passed * through a variable. * * Every field below is read by the engine: uid and kind select identity * (catalog-resolver), default_params feeds modelParam(), pin_layout drives * pin-function lookups (vcc/gnd discovery, open-collector gating), and * electrical_specs carries the operating envelope (logic thresholds, thermal * profile, tolerances). */ export interface PartDefinition { uid: string; kind: ComponentKind; default_params: ComponentParams; pin_layout: Pin[]; spice_model?: string | null; /** Structured electrical specs: thresholds, thermal profile, tolerances. */ electrical_specs?: ElectricalSpecs | null; } export interface PartCatalog { version: number; parts: PartDefinition[]; } export type AnalysisKind = "op" | "transient" | "ac"; export interface OperatingPointAnalysis { kind: "op"; } export interface TransientAnalysis { kind: "transient"; stop: number; step: number; start?: number; chunk_size?: number; } export interface ACAnalysis { kind: "ac"; start_frequency: number; stop_frequency: number; points_per_decade: number; variation: "dec" | "oct" | "lin"; } export type Analysis = OperatingPointAnalysis | TransientAnalysis | ACAnalysis; export interface SimulationRequest { circuit: Circuit; analysis: Analysis; probes: string[]; } export interface SimWarning { code: string; message: string; component_id?: string | null; } export interface OperatingPointResult { kind: "op"; node_voltages: Record; warnings: SimWarning[]; } export interface TransientResult { kind: "transient"; time: number[]; node_voltages: Record; warnings: SimWarning[]; } export type SimulationResult = OperatingPointResult | TransientResult;