import type { AnyToolDefinition } from "./tools"; import type { Transition } from "./transitions"; import type { Node } from "./node"; import type { Executor } from "../executor/types"; import type { Pack } from "./pack"; import type { Instance } from "./instance"; import type { SystemPromptOptions } from "../runtime/system-prompt"; /** * Custom system prompt builder function type. * Allows applications to override the default system prompt generation. * @typeParam AppMessage - The application message type for structured outputs. */ export type SystemPromptBuilder = ( charter: Charter, node: Node, state: S, ancestors: Instance[], packStates: Record, options?: SystemPromptOptions ) => string; /** * Charter configuration for createCharter. * Charter is purely static - a registry for serialization and ref resolution. * @typeParam AppMessage - The application message type for structured outputs (defaults to unknown). */ export interface CharterConfig { name: string; /** Charter-level instructions applied to all nodes */ instructions?: string; /** Single executor for running nodes */ executor: Executor; /** Registered tools (for ref-based lookup, available to all nodes) */ tools?: Record; /** Registered transitions (for ref-based lookup) */ transitions?: Record>; /** * Registered nodes (for ref-based lookup). * Nodes must output AppMessage or have no output. * Uses `any` for state to allow nodes with different state types. */ nodes?: Record | Node>; /** Registered packs (reusable modules with state and tools) */ packs?: Pack[]; /** * Optional custom system prompt builder. * If provided, this function will be used instead of the default system prompt builder. */ buildSystemPrompt?: SystemPromptBuilder; } /** * Charter instance - static registry with single executor, tools, transitions, and nodes. * Charter has no state - state lives in NodeInstances. * @typeParam AppMessage - The application message type for structured outputs (defaults to unknown). */ export interface Charter { name: string; /** Charter-level instructions applied to all nodes */ instructions?: string; /** * Single executor for running nodes. * Uses `any` to break contravariance - allows Charter to be assignable to Charter. */ executor: Executor; /** Registered tools (available to all nodes via ref resolution) */ tools: Record; /** Registered transitions */ transitions: Record>; /** * Registered nodes. * Uses `any` for both type params to break contravariance in node tools/transitions. */ nodes: Record>; /** Registered packs */ packs: Pack[]; /** * Optional custom system prompt builder. * Uses `any` to break contravariance - the node parameter is contravariant. */ buildSystemPrompt?: SystemPromptBuilder; }