PRD-38.4: SDK Foundation

Version: 1.0 Status: 🟡 Planned Priority: HIGH - Platform Expansion Author: Automatos AI Platform Team Last Updated: 2026-01-27 Dependencies: PRD-38.1, PRD-38.2, PRD-38.3, PRD-32 (Widget Integration System) Timeline: Weeks 8-10


Executive Summary

Extract the widget system into a standalone, embeddable SDK that customers can add to their websites and applications. This transforms Automatos from a standalone platform into an embeddable AI service.

The Vision

Customer Website                        Automatos Cloud
─────────────────                       ───────────────
┌─────────────────────┐                 ┌─────────────────────┐
│                     │                 │                     │
│  <script src=       │    ◀──────▶    │  Widget API         │
│   "automatos.js">   │    Secure       │  - Chat             │
│                     │    WebSocket    │  - RAG              │
│  ┌───────────────┐  │    + REST       │  - NL2SQL           │
│  │ Automatos     │  │                 │  - 863+ Tools       │
│  │ Chat Widget   │  │                 │  - Agents           │
│  │               │  │                 │  - Memory           │
│  └───────────────┘  │                 │                     │
│                     │                 └─────────────────────┘
└─────────────────────┘

Key Deliverables

Deliverable
Description

@automatos-ai/core

Core SDK - API client, auth, types

@automatos-ai/react

React components for widgets

@automatos-ai/vanilla

Vanilla JS for script tag embedding

cdn.automatos.app/widget.js

CDN-hosted script loader

Documentation Site

Developer documentation and playground


1) Goals & Success Metrics

Goals

ID
Goal
Description

G1

Easy Integration

< 5 lines of code to embed

G2

Framework Agnostic

Works with React, Vue, vanilla JS, WordPress

G3

Small Bundle

< 50KB gzipped per widget

G4

Secure

API key auth, tenant isolation

G5

Performant

< 500ms load time from CDN

Success Metrics

Metric
Target
Measurement

Script tag integration time

< 15 minutes

User testing

Bundle size (chat widget)

< 50KB gzipped

Build output

CDN load time

< 500ms (p95)

Cloudflare analytics

First message latency

< 2s

Performance monitoring

Documentation coverage

100% of widgets

Doc review


2) Repository Structure

New Repository: automatos-widgets


3) Package Specifications

3.1 @automatos-ai/core

Purpose: Core SDK with API client, authentication, and shared utilities.

Installation:

Usage:

API:

3.2 @automatos-ai/react

Purpose: React components and hooks for embedding widgets.

Installation:

Usage:

Components:

ChatWidget Props:

3.3 @automatos-ai/vanilla

Purpose: Vanilla JavaScript for script tag embedding (no framework required).

CDN Usage:

Script Tag Attributes:

⚠️ Security Warning: API Keys in Client-Side HTML

CRITICAL: Embedding data-automatos-api-key directly in HTML exposes keys to:

  • End users via browser DevTools (View Source, Network tab)

  • Web crawlers and scrapers

  • Browser extensions with page access

  • Any JavaScript on the page

This approach should ONLY be used with "public" client-side keys that have:

  1. Restricted Permissions: Only allow non-sensitive operations

  2. Strict Domain Binding: Key only works from specific origins

  3. Aggressive Rate Limiting: Prevent abuse

For production deployments, use a server-mediated flow instead of exposing API keys:

Benefits of server-mediated approach:

  • API key never exposed to client

  • Tokens are short-lived (1 hour default)

  • Tokens are scoped to specific user and permissions

  • Revocation is immediate (vs API key rotation)

  • Audit trail of token issuance

Documentation must clearly state:

  • Public keys = limited permissions + domain binding + rate limiting

  • Server tokens = recommended for production

  • Examples should show both approaches with security tradeoffs

Implementation:


4) API Endpoints

Widget API (Backend)

Headers:

Streaming Response:


5) Security

API Key Management

Security Measures

Measure
Implementation

API Key Auth

SHA-256 hashed, rotatable

Domain Restriction

CORS origin validation

Rate Limiting

Per-key limits (Redis)

Tenant Isolation

All queries scoped to workspace

Input Validation

Zod schemas on all inputs

Output Sanitization

XSS prevention

CSP Headers

Strict Content-Security-Policy

CORS Configuration


6) CDN & Distribution

Cloudflare Setup

Build Configuration:

Versioning Strategy


7) Implementation Plan

Week 8: Core Package + API

Day
Task

1

Set up monorepo with Turborepo

2

Implement @automatos-ai/core API client

3

Add authentication and streaming

4

Backend: Widget API endpoints

5

Testing and documentation

Week 9: React Package

Day
Task

1

AutomatosProvider and hooks

2

ChatWidget component

3

DataWidget, DocumentWidget

4

Theming system

5

Testing with Next.js example

Week 10: Vanilla Package + CDN

Day
Task

1

Vanilla JS loader

2

Script tag auto-initialization

3

Build pipeline for CDN

4

Deploy to Cloudflare

5

Documentation site launch


8) Files to Create

In automatos-widgets repo:

In main automatos-ai repo:


9) Example Integrations

Next.js Integration

WordPress Integration

Plain HTML Integration


10) Testing Checklist

Core Package

React Package

Vanilla Package

Security


11) Success Criteria

Phase 4 is complete when:


12) References


Document Version: 1.0 Created: 2026-01-27 Estimated Implementation: 3 weeks

Last updated