How to Import Data into PI Desktop: 3 Methods Explained

PI Desktop supports data import via clipboard paste, drag-and-drop operations, and the programmatic pasteFiles API, with all methods routing through the central composer-paste.ts handler to validate and sessionize your content.

The vastsa/PI-Desktop repository implements a unified import system that converts external files into chat sessions. Whether you are importing CSV datasets, JSON configurations, or images, the Electron main process validates, stores, and routes your data through a consistent pipeline defined in the main-process handlers.

Understanding the Import Architecture

All import pathways converge in apps/desktop/electron/main/composer-paste.ts. This module validates file size limits, restricts the number of simultaneous files, and writes validated content to a temporary pasted directory before creating a new session. The architecture ensures that UI gestures (paste, drag-and-drop) and programmatic calls receive identical treatment, maintaining consistent session state across the application.

Method 1: Paste Files from the Clipboard

The Paste menu item triggers the pasteFiles IPC handler in composer-paste.ts. The handler receives an array of ComposerPasteFile objects containing the file name, MIME type, and raw bytes.

Key validation steps:

  • Enforces maximum file size limits per file
  • Restricts the total number of files per paste operation
  • Writes valid files to a temporary persistence layer
  • Creates a new session containing the imported data

This method supports CSV, TSV, JSON, PNG, and other MIME types defined in the composer-paste.ts validation logic.

Method 2: Drag-and-Drop Import

Drag-and-drop operations are captured in apps/desktop/electron/main/composer-picker.ts. The drop zone handler extracts file metadata from the DragEvent and forwards the payload to the same pasteFiles routine used by the clipboard method.

The unified handling ensures that dragging a CSV onto the composer area produces identical session creation logic as using the Edit > Paste menu. The composer-picker.ts module acts as a UI adapter, converting native browser drag events into the internal ComposerPasteFile format expected by the main process.

Method 3: Programmatic Import via API

The renderer process can trigger imports through the api.pasteFiles endpoint defined in apps/desktop/src/lib/api.ts. This method requires a valid session ID and an array of file descriptors, allowing automated imports from React components or external scripts.

Import a CSV file from a React component:

import { api } from "../lib/api";

async function importCsv(file: File) {
  const bytes = await file.arrayBuffer();
  const sessionId = await api.createSession();
  await api.pasteFiles(sessionId, [
    {
      name: file.name,
      mimeType: file.type,
      bytes: new Uint8Array(bytes)
    }
  ]);
}

The api.createSession() call initializes a fresh chat context, while api.pasteFiles transmits the binary data to the main process via IPC.

Supported File Types and MCP Handling

According to the source code in composer-paste.ts, PI Desktop recognizes standard MIME types including text/csv, text/tab-separated-values, application/json, and image/png. When imported files contain Model Context Protocol (MCP) configuration blocks, the parser in apps/desktop/electron/main/mcp-control.ts intercepts the content to persist server entries individually before standard session creation proceeds.

The importer registry in apps/desktop/electron/main/importers/index.ts maintains backends for PI, Opencode, Claude, and Codex formats, ensuring specialized parsing logic applies to vendor-specific file structures.

Complete Import Examples

Drag-and-drop handler implementation:

function onDrop(event: DragEvent) {
  event.preventDefault();
  const files = Array.from(event.dataTransfer?.files ?? []);
  window.ipc.invoke("pasteFiles", { files });
}

Command-line import (using bundled scripts):

node scripts/e2e-import.mjs \
  --session $(pi-desktop create-session) \
  --file data/sample.csv

Key Source Files

File Path Responsibility
apps/desktop/electron/main/composer-paste.ts Validates, stores, and routes pasted files; enforces size and count limits
apps/desktop/src/lib/api.ts Exposes pasteFiles endpoint for renderer-side programmatic access
apps/desktop/electron/main/mcp-control.ts Parses MCP configuration blocks and persists server entries
apps/desktop/electron/main/importers/index.ts Registers importer backends for different formats (PI, Opencode, etc.)
apps/desktop/electron/main/composer-picker.ts Connects UI drop zones to the central paste logic

Summary

  • Unified pipeline: All import methods route through composer-paste.ts for consistent validation and session creation.
  • Three entry points: Clipboard paste, drag-and-drop (via composer-picker.ts), and the api.pasteFiles programmatic interface.
  • Format support: Native handling for CSV, TSV, JSON, and images, with specialized MCP parsing in mcp-control.ts.
  • Session creation: Every successful import automatically generates a new chat session containing the file content.
  • Validation: Built-in limits on file size and quantity prevent resource exhaustion during bulk operations.

Frequently Asked Questions

What file formats does PI Desktop support for import?

PI Desktop supports text/csv, text/tab-separated-values, application/json, and standard image formats like image/png. The validation logic in composer-paste.ts maintains the authoritative whitelist, while the importer registry in importers/index.ts provides specialized parsers for PI, Opencode, Claude, and Codex dialects.

How does PI Desktop handle large file imports?

The composer-paste.ts handler enforces size limits on individual files and restricts the total number of files per paste operation. Valid files are written to a temporary pasted folder before session creation, ensuring the main process memory remains stable during large imports.

Can I import data into an existing session?

The current implementation in api.ts and composer-paste.ts creates a new session for each import operation. The api.pasteFiles method requires a session ID parameter, but the standard UI flow always initializes fresh session state rather than appending to existing chat history.

Where does PI Desktop store imported files temporarily?

Imported files are written to a temporary pasted directory managed by the main process, as implemented in composer-paste.ts. This staging location persists the raw bytes until the new session is fully initialized, after which the content is integrated into the application's session storage model.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →