Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:AIPexStudio AIPex AIPex chat

From Leeroopedia
Knowledge Sources
Domains AI_Agent, Core
Last Updated 2026-10-24 12:00 GMT

Overview

Concrete async generator method that accepts user input with optional contexts and images, resolves session state, and yields a stream of AgentEvents for real-time consumption.

Description

The AIPex.chat method is the primary interaction entry point after agent creation. It accepts a text input string plus optional contexts (page content, files, bookmarks), images (for vision models), and a sessionId (to resume existing conversations). It resolves context IDs to Context objects, formats them into the prompt prefix, builds a multimodal user message when images are provided, and then delegates to the internal `runExecution` generator. The method handles both new session creation and session resumption, emitting `session_created` or `session_resumed` events before execution begins.

Usage

  • New conversation: call `chat(input)` without `sessionId` to start a fresh session.
  • Resume conversation: pass `options.sessionId` to continue an existing session.
  • With contexts: pass `options.contexts` as Context objects or context ID strings to enrich the prompt.
  • With images: pass `options.images` as base64 data with optional detail level for vision-capable models.

Code Reference

Source Location

  • Repository: AIPex
  • File: packages/core/src/agent/aipex.ts
  • Lines: L344-454

Signature

async *chat(
  input: string,
  options?: ChatOptions
): AsyncGenerator<AgentEvent>

interface ChatOptions {
  sessionId?: string;
  contexts?: Context[] | string[];
  images?: ImageInput[];
}

interface ImageInput {
  image: string;  // base64, URL, or file ID
  detail?: "auto" | "low" | "high";
}

Import

import { AIPex } from "@aipexstudio/aipex-core";
// chat is an instance method on AIPex

I/O Contract

Inputs

Name Type Required Description
input string Yes User message text
options.sessionId string No Resume existing session by ID
options.contexts string[] No Context objects or IDs to attach
options.images ImageInput[] No Images for vision models

Outputs

Name Type Description
yields AgentEvent Stream of events: session_created, session_resumed, contexts_attached, content_delta, tool_call_*, metrics_update, execution_complete, error

Usage Examples

Basic Chat

const agent = AIPex.create({ ... });

for await (const event of agent.chat("What's on this page?")) {
  if (event.type === "content_delta") {
    process.stdout.write(event.delta);
  }
  if (event.type === "execution_complete") {
    console.log("\nDone:", event.finalOutput);
  }
}

Resume Session with Context

for await (const event of agent.chat("Scroll down", {
  sessionId: "existing-session-id",
  contexts: ["current-page"],
})) {
  if (event.type === "session_resumed") {
    console.log(`Resumed session with ${event.itemCount} items`);
  }
}

Multimodal with Images

for await (const event of agent.chat("What's in this screenshot?", {
  images: [{ image: base64Data, detail: "high" }],
})) {
  if (event.type === "content_delta") {
    process.stdout.write(event.delta);
  }
}

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment