UNPKG

@autobe/agent

Version:

AI backend server code generator

181 lines (180 loc) 7.83 kB
import { IMicroAgenticaHistoryJson } from "@agentica/core"; import { AutoBeEventSource, AutoBePreliminaryAcquisition, AutoBePreliminaryKind, AutoBePreliminaryRewriteEvent } from "@autobe/interface"; import { IJsonSchemaApplication, ILlmApplication, IValidation } from "@typia/interface"; import { AutoBeContext } from "../../context/AutoBeContext"; import { AutoBeState } from "../../context/AutoBeState"; import { IAutoBePreliminaryRequest } from "./structures/AutoBePreliminaryRequest"; import { IAutoBeOrchestrateResult } from "./structures/IAutoBeOrchestrateResult"; import { IAutoBePreliminaryCollection } from "./structures/IAutoBePreliminaryCollection"; /** * RAG controller for incremental context loading. * * Manages LLM's incremental data requests via function calling, preventing * duplicates and auto-resolving dependencies. * * - `all`: globally available data (from state) * - `local`: currently loaded data (agent context) * - Auto-complements prerequisites, $ref dependencies, and neighbors * * @author Samchon */ export declare class AutoBePreliminaryController<Kind extends AutoBePreliminaryKind> { private readonly source; private readonly source_id; private readonly kinds; private readonly argumentTypeNames; private readonly dispatch; private readonly all; private readonly local; private readonly config; private readonly state; private analysisPageOffset; private previousWrites; private completed; /** * Initializes controller with data collections and auto-complements * dependencies. * * @param props Constructor configuration including kinds, state, and initial * data. */ constructor(props: AutoBePreliminaryController.IProps<Kind>); /** * Validates request for duplicates and non-existent items. * * @param input LLM's function calling request to validate. * @returns Validation result with errors if duplicates or non-existent items * found. */ validate(input: IAutoBePreliminaryRequest<Kind>): IValidation<IAutoBePreliminaryRequest<Kind>>; /** * Generates dynamic system prompts with `LOADED`/`AVAILABLE` lists. * * @returns Assistant and system messages with loaded/available item lists. */ getHistories(): IMicroAgenticaHistoryJson[]; /** * Returns the orchestration source that created this controller. * * @returns Source event type (e.g., `"realizeWrite"`, `"interfaceSchema"`). */ getSource(): Exclude<AutoBeEventSource, "facade" | "preliminaryAcquire">; /** * Returns data types enabled for this controller. * * @returns Array of enabled kinds (e.g., `["databaseSchemas", * "interfaceSchemas"]`). */ getKinds(): Kind[]; /** * Returns configuration (e.g., database schema format: `"ast"` | `"text"`). * * @returns Controller configuration object. */ getConfig(): AutoBePreliminaryController.IConfig<Kind>; /** * Returns function calling type names available in LLM application. * * @returns Array of request type names from `oneOf` union. */ getArgumentTypeNames(): string[]; /** * Returns all globally available data from state. * * @returns Complete dataset that can be requested. */ getAll(): Pick<IAutoBePreliminaryCollection, Kind>; /** * Returns currently loaded data in agent context. * * @returns Subset of data already provided to LLM. */ getLocal(): Pick<IAutoBePreliminaryCollection, Kind>; /** * Extracts acquisition metadata from the currently loaded preliminary data. * * Transforms the local preliminary collection into a normalized acquisition * structure that is suitable for event tracking, including only metadata such * as filenames, schema names, and operation identifiers rather than full * objects. * * @returns Acquisition metadata derived from currently loaded data, * normalized for event tracking. */ getAcquisition(): Pick<AutoBePreliminaryAcquisition, Kind>; /** * Returns the current AutoBe state. * * @returns Current pipeline state containing all phase histories. */ getState(): AutoBeState; /** Returns current page offset for analysis section metadata pagination. */ getAnalysisPageOffset(): number; getPreviousWrite(): Record<string, unknown> | null; /** Advances analysis section metadata page by PAGE_SIZE. */ advanceAnalysisPage(): void; /** * Dynamically adjusts LLM application schema at runtime. * * Removes `getPreviousXXX` types from union/oneOf when no previous iteration * exists. Mutates application's `anyOf`/`oneOf` array, `$defs`, and * `discriminator` mapping. Also erases corresponding `kinds` from * controller's `all`/`local` collections. * * @param application LLM application to modify (mutated in-place) */ fixApplication(application: ILlmApplication, enumerable?: boolean): ILlmApplication; /** * Runs RAG loop for incremental context loading. * * Repeats until process returns non-null value or exceeds the maximum number * of iterations (`AutoBeConfigConstant.RAG_LIMIT`). Each iteration: LLM * requests data → `orchestratePreliminary` adds to `local` → next iteration * with updated context. * * When RAG_LIMIT is exhausted, throws `AutoBePreliminaryExhaustedError` which * can be caught alongside `AutoBeTimeoutError` for force-pass. * * @param ctx AutoBe context for `conversate` and state access. * @param process Callback that runs LLM `conversate` and returns result. * @returns Final value when process returns non-null or throws after * exceeding `AutoBeConfigConstant.RAG_LIMIT` retries. */ orchestrate<T>(ctx: AutoBeContext, process: (out: (result: AutoBeContext.IResult) => (value: T | null) => IAutoBeOrchestrateResult<T>) => Promise<IAutoBeOrchestrateResult<T>>): Promise<T | never>; } export declare namespace AutoBePreliminaryController { /** Constructor props for `AutoBePreliminaryController`. */ interface IProps<Kind extends AutoBePreliminaryKind> { /** Orchestration source creating this controller. */ source: Exclude<AutoBeEventSource, "facade" | "preliminaryAcquire">; /** LLM application schema for function calling validation. */ application: IJsonSchemaApplication; dispatch: (event: AutoBePreliminaryRewriteEvent) => void; /** * Data types to enable (e.g., `["databaseSchemas", * "interfaceOperations"]`). */ kinds: Kind[]; /** Current AutoBe state containing generated artifacts. */ state: AutoBeState; /** Override globally available data (defaults to state). */ all?: Partial<Pick<IAutoBePreliminaryCollection, Kind>>; /** Initial loaded data for agent context. */ local?: Partial<Pick<IAutoBePreliminaryCollection, Kind>>; /** Controller configuration options. */ config?: Partial<IConfig<Kind>>; } /** Result from orchestration process callback. */ interface IProcessResult<T> { /** Returned value if task completed, `undefined` if needs more context. */ value: T | undefined; /** Conversation histories including function calling. */ histories: IMicroAgenticaHistoryJson[]; } /** Controller configuration options. */ interface IConfig<Kind extends AutoBePreliminaryKind> { /** Database schema format: `"ast"` (JSON) or `"text"` (Database DSL). */ database: Kind extends "databaseSchemas" | "previousDatabaseSchemas" ? "ast" | "text" : never; databaseProperty: boolean; } }