Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/aipoch/open-science/llms.txt

Use this file to discover all available pages before exploring further.

window.api.acp is the primary interface for controlling the AI agent runtime. It manages the agent subprocess lifecycle, session multiplexing, prompt streaming, and the permission approval flow. All state changes are broadcast to the renderer via push events; imperative calls return the latest AcpStateSnapshot once they complete.

Methods

getState()

Returns the current runtime state snapshot without triggering any side effects. Returns: Promise<AcpStateSnapshot>

connect(request?)

Spawns the agent subprocess and establishes the ACP connection. Safe to call multiple times — subsequent calls while already connected return the current snapshot.
request
AcpConnectRequest
Optional connection parameters.
Returns: Promise<AcpStateSnapshot>

disconnect()

Tears down all active sessions and shuts down the agent subprocess. Returns: Promise<AcpStateSnapshot>

createSession(request?)

Creates a new agent session with MCP servers injected for notebook and artifact access.
request
AcpCreateSessionRequest
Optional session creation parameters.
Returns: Promise<AcpCreateSessionResponse>
sessionId
string
required
Unique identifier for the newly created session.
cwd
string
Resolved working directory for the session.

resumeSession(request)

Reattaches to a previously persisted session by ID, restoring the agent’s context.
request
AcpResumeSessionRequest
required
Returns: Promise<AcpCreateSessionResponse>

sendPrompt(request)

Activates an artifact run, sends the user prompt to the agent, and streams events until the agent emits a stop event. The call resolves with the final AcpStateSnapshot once the turn completes.
request
AcpPromptRequest
required
Returns: Promise<AcpStateSnapshot>
Subscribe to onEvent before calling sendPrompt to receive streaming events (thoughts, tool calls, artifacts) as the agent processes the prompt.

cancel(request)

Cancels the in-flight prompt for the given session. The agent’s current run is interrupted and the session returns to an idle state.
request
AcpCancelPromptRequest
required
Returns: Promise<AcpStateSnapshot>

deleteSession(request)

Deletes the session and cancels any pending permission requests associated with it.
request
AcpDeleteSessionRequest
required
Returns: Promise<AcpStateSnapshot>

respondToPermission(response)

Resolves a pending permission request with a selected option or a cancellation.
response
AcpPermissionResponse
required
Returns: Promise<AcpStateSnapshot>

Event listeners

onState(listener)

Fired after every state change. The callback receives the complete, up-to-date AcpStateSnapshot — not a diff. Suitable for driving all reactive UI that depends on connection status, session lists, or prompt-in-flight flags.
listener
(snapshot: AcpStateSnapshot) => void
required
Called with the full current snapshot on every state change.
Returns: () => void — call this function to unsubscribe.

onEvent(listener)

Fired for each individual event emitted by the agent during a prompt run. Use this to update the chat transcript, activity feed, and artifact previews incrementally.
listener
(event: AcpRuntimeEvent) => void
required
Called with each individual runtime event.
Returns: () => void — call this function to unsubscribe.

onPermissionRequest(listener)

Fired when the agent requests a new permission approval from the user. Display the options from AcpPermissionRequest.options and call respondToPermission with the result.
listener
(request: AcpPermissionRequest) => void
required
Called when a new permission approval is needed.
Returns: () => void — call this function to unsubscribe.

Type reference

AcpStateSnapshot

The full runtime state delivered by onState and returned by all imperative methods.
status
AcpConnectionStatus
required
Current connection status: 'idle' | 'connecting' | 'connected' | 'error' | 'closed'
cwd
string
required
Working directory of the agent subprocess.
sessionId
string
The most recently active session ID.
sessionIds
string[]
required
All currently live session IDs.
error
string
Error message when status is 'error'.
events
AcpRuntimeEvent[]
required
Accumulated runtime events for the current connection lifetime.
pendingPermissions
AcpPermissionRequest[]
required
Permission requests that have not yet been resolved.
promptInFlight
boolean
required
true when any session has a prompt currently being processed.
promptInFlightSessionIds
string[]
required
Session IDs that are actively processing a prompt.

AcpRuntimeEvent

A single event emitted by the agent during a prompt run.
id
string
required
Unique event identifier.
timestamp
number
required
Unix epoch milliseconds.
kind
AcpRuntimeEventKind
required
Classifies the event. See the AcpRuntimeEventKind table below.
level
AcpRuntimeEventLevel
required
Severity: 'info' | 'warning' | 'error'
sessionId
string
Session that produced this event.
messageId
string
Message ID this event belongs to.
role
'assistant' | 'user'
Role of the speaker for message events.
text
string
Text content for message, thought, system, and error events.
title
string
Display title for tool, plan, and permission events.
status
string
Lifecycle status string (e.g., 'in_progress', 'completed').
toolCallId
string
Identifier tying tool events to their originating call.
artifacts
ArtifactFile[]
Files produced during an artifact event.
runId
string
Artifact run ID for bridging runtime runs to renderer messages.
artifactClaimId
string
Claim ID used with artifacts.finalizeRunArtifacts().
terminalOutput
string
Bash stdout/stderr when terminal output is streamed.
terminalExitCode
number | null
Exit code of a terminal command.

AcpRuntimeEventKind values

ValueDescription
'system'Internal runtime lifecycle messages
'message'Assistant or user message content
'thought'Agent reasoning / chain-of-thought text
'tool'Tool call lifecycle (start, result, error)
'plan'High-level task plan emitted before execution
'permission'Permission request lifecycle
'artifact'File produced by the agent
'error'Runtime or tool error
'stop'Signals the end of a prompt turn
'raw'Unprocessed protocol message

AcpPermissionRequest

requestId
string
required
Unique ID for this permission request.
sessionId
string
required
Session that raised this request.
toolCallId
string
required
Tool call that triggered the permission check.
title
string
required
Human-readable description of what is being requested.
status
string
Current status of the request (e.g., 'pending').
options
AcpPermissionOption[]
required
Available choices to present to the user. Each option has optionId, name, and kind.

Usage example

import { useEffect, useState } from 'react'
import type { AcpStateSnapshot, AcpRuntimeEvent } from '../../../../shared/acp'

async function startAgentSession(projectName: string) {
  // 1. Connect the agent subprocess
  await window.api.acp.connect()

  // 2. Subscribe to state changes before creating a session
  const unsubState = window.api.acp.onState((snapshot: AcpStateSnapshot) => {
    console.log('Connection status:', snapshot.status)
    console.log('Prompt in flight:', snapshot.promptInFlight)
  })

  // 3. Subscribe to individual events for live transcript updates
  const unsubEvents = window.api.acp.onEvent((event: AcpRuntimeEvent) => {
    if (event.kind === 'message') {
      console.log('Agent message:', event.text)
    }
    if (event.kind === 'artifact') {
      console.log('Artifact produced:', event.artifacts)
    }
    if (event.kind === 'stop') {
      console.log('Turn complete')
    }
  })

  // 4. Subscribe to permission requests
  const unsubPermissions = window.api.acp.onPermissionRequest((request) => {
    // Present request.options to the user, then:
    window.api.acp.respondToPermission({
      requestId: request.requestId,
      optionId: request.options[0].optionId
    })
  })

  // 5. Create a session scoped to the project
  const { sessionId } = await window.api.acp.createSession({ projectName })

  // 6. Send a prompt
  await window.api.acp.sendPrompt({
    sessionId,
    text: 'Analyse the dataset and produce a summary plot.'
  })

  // 7. Cleanup
  return () => {
    unsubState()
    unsubEvents()
    unsubPermissions()
  }
}

Build docs developers (and LLMs) love