/** * BuilderBase — immutable fluent builder foundation for adk-fluent-ts. * * Every builder method returns a new instance (immutable clone pattern). * Call `.build()` to produce a native @google/adk object. * * This is the TypeScript equivalent of Python's `BuilderBase` in `_base.py`. * Key differences from the Python version: * - Immutable: every setter clones instead of copy-on-write with freeze/fork * - Explicit methods: no Proxy or __getattr__ — all setters are generated or hand-written * - Method-based operators: .then(), .parallel(), .times() instead of >>, |, * */ import type { CallbackFn, StatePredicate, UntilSpec } from "./types.js"; import type { VisualizeOptions } from "../visualize/index.js"; import { Signal, SignalPredicate, type ReactorHandler, type RuleSpec, type RuleSpecOptions } from "../namespaces/reactor.js"; export declare function registerWorkflow(name: string, ctor: any): void; /** * Abstract base class for all fluent builders. * * Subclasses must implement: * - `build()`: produce the native ADK object * - `_clone()`: produce a shallow copy of this builder */ export declare abstract class BuilderBase { /** Key-value configuration (name, model, instruction, etc.) */ protected _config: Map; /** Callback lists (before_agent, after_model, etc.) */ protected _callbacks: Map; /** List-typed fields (sub_agents, tools, etc.) */ protected _lists: Map; constructor(name: string, extras?: Record); /** Produce the native @google/adk object. */ abstract build(): TBuild; /** * Create a shallow clone of this builder with independent config/callback/list maps. * Subclasses should override to copy any additional instance state. */ protected _clone(): this; /** Set a config key, returning a new builder. */ protected _setConfig(key: string, value: unknown): this; /** * Append to a callback list, returning a new builder. * * Accepts ``unknown`` so that generated builders can pass through values * whose type the emitter could not narrow. The cast is safe at runtime * because the value is only invoked when ``.build()`` is called. */ protected _addCallback(key: string, fn: CallbackFn | unknown): this; /** Append to a list field, returning a new builder. */ protected _addToList(key: string, item: unknown): this; /** Replace a list field entirely, returning a new builder. */ protected _setList(key: string, items: unknown[]): this; /** * Build a plain config object from this builder's state. * * Used by generated builders that don't have a corresponding * `@google/adk` class to construct directly. Returns a tagged * config object: ``{ _type: typeName, ...config, ...lists, ...callbacks }``. * * Sub-builders inside list fields are recursively built. */ protected _buildConfig(typeName: string): Record; /** Apply any registered ``.native()`` post-build hooks. */ protected _applyNativeHooks(result: T): T; /** * Sequential composition: `a.then(b)` — equivalent to Python's `a >> b`. * * Returns a Pipeline that runs this builder first, then `other`. * If `this` is already a Pipeline, appends `other` as a new step. */ then(other: BuilderBase | ((...args: unknown[]) => unknown)): BuilderBase; /** * Parallel composition: `a.parallel(b)` — equivalent to Python's `a | b`. * * Returns a FanOut that runs this and `other` concurrently. * If `this` is already a FanOut, appends `other` as a new branch. */ parallel(other: BuilderBase): BuilderBase; /** * Loop composition: `a.times(3)` — equivalent to Python's `a * 3`. * * Repeats this builder's workflow N times. */ times(iterations: number): BuilderBase; /** * Conditional loop: `a.timesUntil(pred, { max: 5 })`. * Equivalent to Python's `a * until(pred, max=5)`. */ timesUntil(predicate: StatePredicate | UntilSpec, opts?: { max?: number; }): BuilderBase; /** * Fallback chain: `a.fallback(b)` — equivalent to Python's `a // b`. * * Tries this builder first. If it fails, falls back to `other`. */ fallback(other: BuilderBase): BuilderBase; /** * Structured output: `agent.outputAs(schema)` — equivalent to Python's `agent @ Schema`. * * Forces the LLM to respond with structured output matching the schema. */ outputAs(schema: unknown): this; /** Return the builder's configured name. */ get name(): string; /** Return a snapshot of the current config for debugging. */ inspect(): Record; /** * Escape hatch: modify the native ADK object after build(). * `fn` receives the raw object for direct manipulation. */ native(fn: (obj: TBuild) => void): this; /** Debug mode: log builder operations to stderr. */ debug(enabled?: boolean): this; /** * Render this builder's topology as a string. * * Builds the agent and dispatches to the requested format. The * default `"ascii"` format produces a `tree`-style listing suitable * for terminal output and `.explain()`-style introspection. * * console.log(pipeline.visualize()); // ascii * console.log(pipeline.visualize({ format: "mermaid" })); // mermaid * console.log(pipeline.visualize({ format: "markdown" })); // anatomy */ visualize(opts?: VisualizeOptions): string; /** Store the agent's text response in state[key] after execution. */ writes(key: string): this; /** Inject state[key] values into this agent's prompt. */ reads(...keys: string[]): this; /** * Attach a declarative reactor rule to this builder. * * When ``R.compile()`` walks this tree it turns every attached * ``RuleSpec`` into a live ``ReactorRule``. If ``handler`` is omitted * the default coerces the builder itself (``.askAsync()``) into a * handler so the rule re-invokes the agent with a short description * of the triggering signal change. * * ``predicate`` accepts either a bare ``Signal`` (promoted to * ``signal.changed``) or a ``SignalPredicate``. */ on(predicate: SignalPredicate | Signal, handler?: ReactorHandler, opts?: RuleSpecOptions): this; /** * Default reactor handler: fire-and-forget run of this builder. * Subclasses that know how to invoke themselves (e.g. Agent) override. */ protected _defaultReactorHandler(): ReactorHandler; /** * Read-only view of reactor rules attached via ``.on()``. Useful for * tests and introspection. */ get _reactor_rules(): readonly RuleSpec[]; toString(): string; get [Symbol.toStringTag](): string; } /** * Helper to resolve a builder-or-built value. * If the item is a BuilderBase, calls .build(). Otherwise returns as-is. */ export declare function autoBuild(item: BuilderBase | T): T; //# sourceMappingURL=builder-base.d.ts.map