intellibrix v1.0.0
    Preparing search index...

    Class representing a brick that sets up an Express server. It extends from the intellibrix!Brick class.

    Access all of Express's functionality through the ExpressBrick.express property.

    const brick = new ExpressBrick({
    port: 3000,
    routes: [
    {
    path: '/',
    method: 'get',
    handler: (req, res) => {
    res.status(200).send('Hello World')
    }
    },
    {
    path: '/echo',
    method: 'post',
    handler: (req, res) => {
    res.status(200).json(req.body)
    }
    }
    ]
    })

    Hierarchy

    • Brick
      • default
    Index
    • Creates a new ExpressBrick.

      Parameters

      • options: ExpressBrickOptions = ...

        The options for the ExpressBrick.

        Interface for the options of ExpressBrick. It extends from BrickOptions and adds properties specific to ExpressBrick.

        • OptionalbuiltinMiddleware?: { json: boolean; urlencoded: boolean }

          An object specifying whether to use built-in middleware functions.

          • json: boolean

            Whether to use the built-in JSON middleware.

          • urlencoded: boolean

            Whether to use the built-in URL-encoded middleware.

        • Optionaldatabase?: KeyValueStore

          The key-value store of the Brick instance. Defaults to an in-memory store.

        • Optionalhost?: string

          The host on which the Express server will listen.

        • Optionalid?: string

          The unique identifier of the Brick instance. If not provided, a random UUID will be generated.

        • Optionalintelligence?: Intelligence

          The Intelligence of the Brick instance. This is used to manage the AI capabilities of the Brick.

        • OptionallogJSON?: boolean

          A boolean indicating whether the logs should be in JSON format.

        • OptionallogLevel?: Level

          The log level of the Brick instance. This determines the level of detail of the logs.

        • Optionalmiddleware?: RequestHandler<ParamsDictionary, any, any, ParsedQs, Record<string, any>>[]

          An array of middleware functions to use in the Express application.

        • Optionalname?: string

          The name of the Brick instance. If not provided, the id will be used as the name.

        • OptionalpinoOptions?: LoggerOptions<never>

          The options for the pino logger used by the Brick instance.

        • Optionalport?: number

          The port on which the Express server will listen.

        • Optionalroutes?: { handler: (req: Request, res: Response) => void; method: string; path: string }[]

          An array of routes that the Express server will handle.

        • Optionalstructure?: Structure

          The parent Structure of the Brick, if any.

      Returns default

      Supports all BrickOptions as well as ExpressBrickOptions.

    ai?: Intelligence

    The intelligence of the Brick instance. This is used to manage the AI capabilities of the Brick.

    db: KeyValueStore

    The key-value store of the Brick instance.

    events: EventEmitter

    The event emitter of the Brick instance. This is used to emit events that occur in the Brick, such as the running of a program.

    express: Application

    The Express application instance.

    id: string

    The unique identifier of the Brick instance.

    log: Logger

    The logger used by the Brick instance. This is used to log information about the operation of the Brick.

    name: string

    The name of the Brick instance.

    server?: Server<typeof IncomingMessage, typeof ServerResponse>

    The HTTP server instance.

    structure?: Structure

    The parent Structure of the Brick instance, if any.

    usage: UsageAccumulator

    Accumulates token usage/cost across every ask() call on this Brick. Starts as a .child() of this.ai.usage when an Intelligence is configured (so totals also roll up there), or standalone otherwise. Rebound as a .child() of the parent Structure's usage when added to one via Structure.add().

    • get programs(): { [key: string]: Program }

      Returns the private map of programs.

      Returns { [key: string]: Program }

    • Runs a prompt through this Brick's ai, offering its programs (via Brick.tools) plus any tools attached via Brick.use.

      Parameters

      • prompt: string
      • Optionaloptions: AskOptions

      Returns Promise<AskResult>

    • Removes a program from the private map of programs by its name.

      Parameters

      • name: string

        The name of the program to remove.

      Returns void

    • Toggles the keep alive flag of the Brick instance, which will prevent the Node process from exiting

      Parameters

      • on: boolean

        A boolean indicating whether to turn the keep alive flag on or off.

      Returns void

      This is useful if you don't have a server or something else keeping the Node process alive.

    • Adds a program to the private map of programs.

      Parameters

      • program: Program

        The program to add.

      Returns void

    • Runs a program by its name with a given payload.

      Parameters

      • name: string

        The name of the program to run.

      • payload: any

        The payload to pass to the program.

      Returns Promise<any>

      The result of the program.

    • Schedules a Task to run on a given schedule. This is a wrapper around the cron package.

      Parameters

      • task: Task

        The Task to schedule.

      Returns Task

      The scheduled task.

      The task will run on the schedule provided, and will run the method provided with the Brick instance as the first argument.

      An error if the task already exists.

    • Returns a Task by its name.

      Parameters

      • name: string

      Returns Task | undefined

    • Exposes every registered program as a ToolDefinition, each execute calling this.run(program.name, input).

      Returns ToolDefinition[]

    • Every tool this Brick offers: its programs (via Brick.tools) plus anything attached via Brick.use.

      Returns ToolDefinition[]

    • Unschedules a task by its name.

      Parameters

      • name: string

        The name of the task to unschedule.

      Returns void

      An error if the task does not exist.

    • Attaches external tool arrays (e.g. MCP-sourced tools) to this Brick, included whenever ask() builds its tool list.

      Parameters

      • ...toolsets: ToolDefinition[][]

      Returns this