embed.js · Co-Pilot4 min read

In-App Co-Pilot & Product Guide

Embed a white-label Shadow-DOM co-pilot that reads your docs, sees the live screen, highlights elements, and guides users across pages.

  • Sync Markdown, FAQs, or llms.txt into a placement-sealed Knowledge Pack
  • Drop one <script> tag (embed.js) - persists across SPA navigations automatically
  • Strict white-label seal: third-party pl:* placements never leak Kami branding or internal docs
  1. 1

    Upload your product docs into a Knowledge Pack

    Push Markdown, docs, or llms.txt to your placement. Large documents are automatically chunked by ## headings and sealed strictly to this placement.

    cURLPOST /api/placement/v1/knowledge
    curl -X POST https://api.kami.bot/api/placement/v1/knowledge \
      -H "Authorization: Bearer $KAMI_PLACEMENT_KEY" \
      -H "Content-Type: application/json" \
      -d '{
        "name": "product-docs",
        "replace": true,
        "text": "# Billing\nPro costs $49/mo. Open Settings > Billing and click Upgrade."
      }'
  2. 2

    Add a thin server proxy (keeps kpl_ secret)

    Never put your kpl_ key in browser HTML. Expose a 15-line server route that forwards { senderId, text, uiSnapshot } to /api/placement/v1/turn and streams SSE straight back.

    TypeScriptapp/api/kami-support/route.ts (Next.js App Router)
    export async function POST(req: Request) {
      const { text, senderId, uiSnapshot } = await req.json();
    
      const upstream = await fetch("https://api.kami.bot/api/placement/v1/turn", {
        method: "POST",
        headers: {
          Authorization: `Bearer ${process.env.KAMI_PLACEMENT_KEY}`,
          "Content-Type": "application/json",
        },
        body: JSON.stringify({
          place: "dm",
          senderId,
          text,
          uiSnapshot,
          channel: "text",
          stream: true,
        }),
      });
    
      return new Response(upstream.body, {
        headers: {
          "Content-Type": "text/event-stream; charset=utf-8",
          "X-Accel-Buffering": "no",
        },
      });
    }
  3. 3

    Drop in embed.js & register confirmed actions

    One script tag mounts an isolated Shadow-DOM drawer, captures a privacy-safe uiSnapshot (never reads input values), renders spotlights & multi-step walkthroughs, and lets you register safe host actions.

    HTMLAny website or SPA (HTML)
    <script
      src="https://kami.bot/embed.js"
      data-endpoint="/api/kami-support"
      data-title="Ask Acme AI"
      data-subtitle="Live product guide"
      data-suggestions="How do I upgrade?|Invite my team"
      async
    ></script>
    
    <script>
      window.addEventListener("load", () => {
        window.KamiCopilot?.registerAction({
          verb: "open_billing",
          label: "Open Billing Settings",
          handler: () => { window.location.assign("/settings/billing"); },
        });
      });
    </script>
    Tag important UI buttons with data-kami-id="upgrade-btn" so spotlights and multi-step walkthroughs stay rock-solid even when CSS classes change.
  4. 4

    Native apps (React Native, Swift, Android, Quest)

    The protocol is pure JSON. Send uiSnapshot from any native screen and render validated action.uiActions (highlight, scroll_to, navigate, walkthrough, suggest_action) with your native UI primitives.

    JSONResponse excerpt (action.uiActions)
    {
      "response": "Pro is **$49/mo**. Let me show you where to upgrade.",
      "action": {
        "uiActions": [
          {
            "kind": "walkthrough",
            "id": "wt-upgrade",
            "title": "Upgrade to Pro",
            "steps": [
              { "route": "/settings/billing", "target": "upgrade-btn", "instruction": "Click Upgrade ($49/mo)" }
            ]
          }
        ]
      }
    }