ChatCraft

ChatCraft AI Platform, Widget SDK & REST API Documentation

Complete engineering manual covering RAG document ingestion limits, recursive chunking hygiene, asynchronous Shadow DOM widget installation, Content-Security-Policy (CSP) headers, REST API endpoints, and production troubleshooting.

1. Platform Architecture & Request Lifecycle

How ChatCraft AI isolates knowledge bases, retrieves vector passages, and synthesizes grounded answers.

ChatCraft AI separates conversational customer support into two deterministic planes: an Asynchronous Ingestion Pipeline and a Low-Latency Runtime Retrieval Engine.

When you upload a PDF, Word manual, Markdown guide, or website URL in the Bot Studio, the ingestion pipeline strips non-content markup, normalizes UTF-8 whitespace, splits prose along recursive paragraph and sentence boundaries, and stores indexed vector chunks inside an isolated per-bot store (bot_<id>_kb.json or connected SQL/vector backend).

At query time, every visitor message passes through four sequential gates:

  1. Input Normalization & Rate Limiting: Request payload size, session history depth, and workspace quotas are validated before model invocation.
  2. Top-K Semantic Retrieval: The query is compared against the bot's indexed chunks to select the highest-scoring passages above the relevance cutoff.
  3. Sandboxed Prompt Assembly: Verified passages are injected inside <verified_context> tags alongside your bot's negative-constraint instructions and recent turn memory.
  4. Low-Temperature Generation: The configured inference model (Gemini Flash or BYOK provider) generates a grounded reply at deterministic temperature (0.1), returning both the answer text and source metadata.

2. 5-Minute Quickstart Guide

Create a workspace, ingest your first help center document, style the launcher, and deploy.

Follow these five steps to take a grounded assistant from raw documentation to a live website widget:

  1. Create a Bot Instance: Sign in to your ChatCraft Workspace and click New Chatbot. Select a visual preset or start with a blank theme.
  2. Ingest Verified Sources: Open the Knowledge tab. Upload text-searchable .pdf, .docx, .txt, or .md files (up to 10 MB per upload), add atomic Q&A pairs, or submit canonical documentation URLs for crawling.
  3. Configure Refusal Guardrails: Open the Rules tab. Verify that strict knowledge-base grounding is active and customize the fallback escalation message (for example, directing unverified account billing requests to support@yourdomain.com).
  4. Customize Brand Styling: In the Theme and Launcher tabs, set your primary hex accent, header gradient, corner radius (8px–24px), typography, and starter prompt chips while previewing changes live.
  5. Embed & Verify: Copy the single-line widget.js snippet from the Integrations tab and paste it immediately before </body> on your site.

3. Document Ingestion Formats, Quotas & Sanitization

Supported file extensions, parser behavior, table serialization, and pre-upload data hygiene.

Clean source material is the primary determinant of RAG retrieval precision. Review the parser behavior below before uploading enterprise documentation:

Source ChannelAccepted FormatsMax PayloadParser Behavior & Recommendations
Document Upload.pdf, .docx, .txt, .md, .csv, .json10 MB / fileExtracts text streams via pdf-parse and mammoth. Export PDFs directly from Word/Docs rather than scanning paper without OCR.
Website Crawlerhttps:// public HTML pages10s fetch timeoutStrips <script>, <style>, <nav>, and <footer> noise via Cheerio before chunking main <article> / <main> prose.
Atomic FAQ PairsStructured Question + Answer2 MB / fieldStored as single self-contained FAQ chunks (isFaq: true) so short high-value policies are never split mid-answer.
Database SnapshotPostgreSQL, MySQL, MongoDB200 rows / syncSerializes catalog or policy rows into structured key-value text chunks with source table provenance.

Pre-Upload Hygiene Checklist

  • Remove outdated policy versions before uploading revised manuals; re-uploading the same filename automatically replaces prior chunks from that source.
  • Never upload internal API secret keys, employee personal phone numbers, or unredacted customer PII into a public-facing chatbot's knowledge store.
  • Test how your prose splits prior to upload using our free RAG Chunking & Overlap Visualizer.

4. Universal Widget Embed & Content Security Policy (CSP)

Asynchronous loading, Shadow DOM style encapsulation, and security header allowlists.

The ChatCraft web widget mounts inside an encapsulated Shadow DOM container so host CSS resets (Tailwind preflight, Bootstrap, Shopify Dawn styles) never distort chat bubbles or typography, and widget styles never leak onto your host page.

<!-- Place immediately before closing </body> tag -->
<script
  async
  src="https://chatcraftstdo.com/widget.js"
  data-bot-id="bot_your_unique_id"
></script>

Content-Security-Policy (CSP) Configuration

If your production web application enforces strict HTTP Content-Security-Policy headers, add https://chatcraftstdo.com to script-src and connect-src:

Content-Security-Policy:
  default-src 'self';
  script-src 'self' https://chatcraftstdo.com;
  connect-src 'self' https://chatcraftstdo.com;
  img-src 'self' data: https:;
  style-src 'self' 'unsafe-inline' https://fonts.googleapis.com;
  font-src 'self' https://fonts.gstatic.com;

Because widget.js executes with the async attribute and defers DOM tree construction until network fetch completion, it adds zero render-blocking delay to Largest Contentful Paint (LCP).

5. Public & Workspace REST API Reference

HTTP endpoints for programmatic chat completions, widget configuration, and knowledge updates.

Developers on Pro and Agency plans can query trained bots or push documentation updates directly from CI/CD pipelines over HTTPS JSON endpoints.

Query a Trained Bot (POST /api/bots/:id/chat)

const res = await fetch('https://chatcraftstdo.com/api/bots/bot_ecommerce_store/chat', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    query: 'What is the domestic return window for unopened items?',
    history: [
      { role: 'assistant', content: 'Hello! How can I help with your order today?' }
    ],
    sessionId: 'sess_98a7bc12'
  })
});

const data = await res.json();
// Returns: { reply: "...", provider: "gemini", model: "...", sources: [...] }

Push Markdown Documentation from CI (POST /api/bots/:id/knowledge/text)

await fetch('https://chatcraftstdo.com/api/bots/YOUR_BOT_ID/knowledge/text', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    title: 'Release v2.4 Billing FAQ',
    source: 'docs/billing-faq.md',
    content: '## Annual Plan Upgrades\nWorkspace upgrades prorate unused monthly credit...'
  })
});

6. Production Troubleshooting & Accuracy Diagnostics

Resolving empty PDF extractions, crawler blocks, and over-eager refusal fallbacks.

Use the diagnostic table below when tuning a newly deployed assistant:

Symptom ObservedRoot Technical CauseResolution Step
Upload returns "Could not extract readable text"Source PDF is a flat raster scan without an embedded UTF-8 text layer.Run OCR conversion (Adobe Acrobat, Tesseract, or Google Drive Docs export) and re-upload as text-searchable PDF or Markdown.
Crawler fails on a target URLTarget host blocks automated fetches via WAF challenge or returns SPA empty HTML shell.Export the page content as Markdown/PDF or expose static server-rendered HTML on documentation routes.
Bot triggers refusal fallback on valid policy questionsPhrasing mismatch between terse policy bullets and conversational customer vocabulary.Add explicit atomic Q&A pairs in the Knowledge tab using customer phrasing, or inspect chunks in the Chunk Visualizer.
Bot answers too verboselySystem instructions lack conciseness bounds.Add "Keep answers under 120 words and use bullet points for multi-step instructions" using the Prompt Builder.