npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@assistant-ui/local-pdf-adapter

v0.0.1

Published

Local PDF attachment adapter for @assistant-ui/react

Downloads

90

Readme

Local PDF Attachment Adapter

A standalone PDF attachment adapter for @assistant-ui/react that provides native PDF text extraction support.

Features

  • 📄 PDF Text Extraction: Extracts text content from PDF documents for LLM consumption
  • 🌐 Cross-Platform: Works in both browser and Node.js environments
  • Performance Optimized: Configurable file size limits to prevent browser performance issues
  • 🔒 Security Conscious: Support for self-hosted PDF.js worker scripts
  • 🛡️ Error Handling: Comprehensive error handling for corrupted or invalid PDFs
  • 📦 Standalone: Can be used as a separate package without modifying assistant-ui core

Installation

npm install local-pdf-adapter

Dependencies

This package requires:

  • @assistant-ui/react (peer dependency)
  • pdfjs-dist (for browser environments)

For Node.js environments, also install:

npm install pdf-parse

Usage

Basic Usage

import { LocalPDFAttachmentAdapter } from 'local-pdf-adapter';
import { CompositeAttachmentAdapter } from '@assistant-ui/react';

const pdfAdapter = new LocalPDFAttachmentAdapter();

// Use with CompositeAttachmentAdapter
const attachmentAdapter = new CompositeAttachmentAdapter([
  pdfAdapter,
  // Add other adapters as needed
]);

// Use in your runtime
const runtime = useLocalRuntime({
  attachmentAdapter,
});

Advanced Configuration

const pdfAdapter = new LocalPDFAttachmentAdapter({
  maxFileSize: 20 * 1024 * 1024, // 20MB limit
  workerSrc: '/pdf.worker.min.mjs', // Self-hosted worker
});

Configuration Options

LocalPDFAttachmentAdapterConfig

| Option | Type | Default | Description | |--------|------|---------|-------------| | workerSrc | string | undefined | Custom URL for PDF.js worker script. If not provided, uses unpkg CDN | | maxFileSize | number | 10 * 1024 * 1024 (10MB) | Maximum file size in bytes |

Security Considerations

Self-Hosting the PDF.js Worker

By default, the PDF.js worker is loaded from the unpkg CDN. For production applications, consider self-hosting:

  1. Download the worker from PDF.js releases
  2. Serve it from your domain (e.g., in your public directory)
  3. Configure the adapter:
const pdfAdapter = new LocalPDFAttachmentAdapter({
  workerSrc: '/pdf.worker.min.mjs'
});

Content Security Policy (CSP)

If using the default CDN, add it to your Content Security Policy:

script-src https://unpkg.com/pdfjs-dist@*

Environment Support

Browser Environment

  • Uses pdfjs-dist for client-side PDF processing
  • Supports all modern browsers
  • Worker script handles heavy processing to avoid blocking UI

Node.js Environment

  • Uses pdf-parse for server-side PDF processing
  • Requires optional pdf-parse dependency
  • Faster processing for server applications

Error Handling

The adapter handles various error scenarios:

  • File size exceeded: Returns attachment with error status
  • Corrupted PDFs: Returns error message in attachment content
  • Network failures: Graceful fallback with error reporting
  • Invalid format: Clear error messages for unsupported files

Example Implementation

import { 
  LocalRuntime, 
  CompositeAttachmentAdapter,
  useLocalRuntime 
} from '@assistant-ui/react';
import { LocalPDFAttachmentAdapter } from 'local-pdf-adapter';

function ChatComponent() {
  const attachmentAdapter = new CompositeAttachmentAdapter([
    new LocalPDFAttachmentAdapter({
      maxFileSize: 5 * 1024 * 1024, // 5MB limit
      workerSrc: '/assets/pdf.worker.min.mjs' // Self-hosted
    }),
    // Add other adapters for images, text, etc.
  ]);

  const runtime = useLocalRuntime({
    attachmentAdapter,
  });

  return (
    <ThreadContainer runtime={runtime}>
      <Viewport>
        <ThreadWelcome />
        <ThreadMessages />
        <ThreadComposer />
      </Viewport>
    </ThreadContainer>
  );
}

Development

# Install dependencies
npm install

# Run tests
npm test

# Build the package
npm run build

# Watch mode for development
npm run dev

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.