Skip to main content
AI Actions provides high-level, ready-to-use AI operations for SuperDoc. Run natural-language commands like find, replace, track changes, and insert comments without building custom AI workflows. Works with OpenAI, Anthropic, or custom providers.

Quick start

import { SuperDoc } from 'superdoc';
import { AIActions, HttpProviderConfig } from '@superdoc-dev/ai';

const superdoc = new SuperDoc({ /* editor config */ });

const providerConfig: HttpProviderConfig = {
  type: 'http',
  url: '/api/ai/complete', // Your backend endpoint
  headers: {
    'Authorization': `Bearer ${userAuthToken}`, // Your user's session token
  },
};

const ai = new AIActions(superdoc, {
  user: { displayName: 'RedlineBot', userId: 'ai-assistant' },
  provider: providerConfig,
});

await ai.waitUntilReady();

// Use AI actions
await ai.action.find('GDPR clause');
await ai.action.replace('Rewrite as bullet points');
await ai.action.insertTrackedChange('Add legal disclaimer');

What it is

AI Actions is SuperDoc’s high-level AI offering. It provides pre-built operations for common document automation tasks:
  • AI-powered search, rewrites, and summaries
  • Tracked changes and comments created by an AI assistant
  • Bulk edits and repetitive automation
  • Multi-provider support (OpenAI, Anthropic, custom)
For low-level control and custom AI workflows, AI Builder is coming soon.

Capabilities

  • Natural-language operations - Find, replace, highlight, and manipulate content using plain English
  • Tracked changes & comments - AI-generated edits attributed to your configured AI user
  • Summaries & completions - Generate summaries or free-form content with streaming support
  • Provider-agnostic - Works with OpenAI, Anthropic, custom HTTP gateways, or custom providers
  • Lifecycle hooks - Real-time callbacks for streaming, errors, and readiness

Lifecycle & readiness

const ai = new AIActions(superdoc, { user, provider });

await ai.waitUntilReady();

if (!ai.getIsReady()) {
  // surface UI state, retry later
}
Each action internally calls waitUntilReady, so explicit checks are only required when guarding UI or retry flows.

Error handling

try {
  await ai.action.replace('Make the GDPR clause bullet pointed');
} catch (error) {
  if (/not ready/i.test((error as Error).message)) {
    await ai.waitUntilReady();
  } else {
    console.error('[AIActions] replace failed', error);
  }
}
Enable verbose logging by setting enableLogging: true. The package will emit parsing and traversal issues to console.error.

Documentation

  • Configuration - Provider setup and configuration options
  • Methods - Instance methods and AI actions
  • Hooks - Lifecycle and streaming callbacks