Skip to content

Commit 5929cdd

Browse files
Paul Mulliganclaude
andcommitted
feat(docs): author all nine doc sections with live demo on home page
Getting Started, Configuration, Deployment (per-host guides), Plugins & Tools, RAG, Channels, API Reference, Migration Guides, FAQ. Roadmap items are marked planned and link their tracking issues. The home page embeds the real widget via the jsDelivr @1 channel. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent cc98cf1 commit 5929cdd

30 files changed

Lines changed: 1416 additions & 6 deletions

docs/plans/2026-06-11-docs-site-design.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ issues, rather than describing unshipped features as real.
2828
| Getting Started | What is Claudius; 5-minute embed quick start (CDN snippet); local development setup |
2929
| Configuration | Widget options (React props / `window.ClaudiusConfig` / `<claudius-chat>` attributes); worker env vars; proactive triggers; localization; theming; multi-client configs + CLI |
3030
| Deployment | Worker on Cloudflare (KV, D1 analytics, secrets); embed via CDN; self-hosted embed; per-host guides: static HTML, WordPress, Replit, React/Next.js |
31-
| Plugins & Tools | Extension points that exist today (system prompt, translations, CSS custom properties); roadmap: tool-use registry (#42), plugin/hook SDK (#46), v2 plugin SDK RFC (#79) |
32-
| RAG | Sources feature that exists today (`sources` in `ChatResponse`, `ChatSources` sidebar); roadmap: pluggable retriever + Vectorize (#43), inline citations (#47) |
33-
| Channels | Web channel today (script embed, web component, React); roadmap: Slack/Teams (#57), SMS/WhatsApp (#58) |
31+
| Plugins & Tools | Extension points that exist today (system prompt, translations, CSS custom properties); roadmap: tool-use registry (#51), plugin/hook SDK (#45), v2 plugin SDK RFC (#79) |
32+
| RAG | Sources feature that exists today (`sources` in `ChatResponse`, `ChatSources` sidebar); roadmap: pluggable retriever + Vectorize (#52), inline citations (#56) |
33+
| Channels | Web channel today (script embed, web component, React); roadmap: Slack/Teams (#62), SMS/WhatsApp (#63) |
3434
| API Reference | REST: `POST /api/chat` (request/response, error codes, 429 + `Retry-After` + `limitType`), `GET /api/health`; client retry behavior; Widget API: full `ChatWidgetProps` |
3535
| Migration Guides | 1.0→1.1 (embed filenames `claudius-embed.*``claudius.iife.js`/`claudius.css`, sessionStorage persistence); 1.1→1.2 (CDN channel); 1.2→1.3 (429 `limitType`); versioning policy |
3636
| FAQ | CORS errors, rate limits, CSP for jsDelivr, multiple widgets per page, model configuration, data/privacy (metadata-only analytics) |

docs/plans/2026-06-11-docs-site-implementation.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ src/content/docs/
7575
deployment/wordpress.md # embed via theme footer / code-snippets plugin
7676
deployment/replit.md # self-hosted files on Replit (pmds.info pattern)
7777
deployment/react.md # React component + Next.js (client component) usage
78-
plugins/index.md # extension points today (system prompt, translations, CSS vars, MockChatApiClient); planned: #42 tool registry, #46 middleware SDK, #79 v2 RFC
79-
rag/index.md # sources pipeline today (ChatResponse.sources, ChatSources sidebar, Source type); planned: #43 retriever + Vectorize, #47 inline citations
80-
channels/index.md # web channel today (script embed, <claudius-chat>, React); planned: #57 Slack/Teams, #58 SMS/WhatsApp
78+
plugins/index.md # extension points today (system prompt, translations, CSS vars, MockChatApiClient); planned: #51 tool registry, #45 middleware SDK, #79 v2 RFC
79+
rag/index.md # sources pipeline today (ChatResponse.sources, ChatSources sidebar, Source type); planned: #52 retriever + Vectorize, #56 inline citations
80+
channels/index.md # web channel today (script embed, <claudius-chat>, React); planned: #62 Slack/Teams, #63 SMS/WhatsApp
8181
api/rest.md # POST /api/chat (request/response JSON, error envelope, codes table incl. RATE_LIMITED + Retry-After + limitType), GET /api/health, client retry policy
8282
api/widget.md # ChatWidgetProps reference, ClaudiusConfig global, web component attrs, exports
8383
migration/index.md # semver + versioning policy, docs archive policy
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
/**
3+
* Loads the real Claudius widget from the version-pinned jsDelivr channel and
4+
* points it at the production worker, so docs visitors can chat immediately.
5+
*
6+
* Chat requests work once the worker's ALLOWED_ORIGIN list includes this
7+
* site's origin (the worker accepts a comma-separated list).
8+
*/
9+
---
10+
11+
<script is:inline>
12+
window.ClaudiusConfig = {
13+
apiUrl: "https://pmds-chat-worker.paul-130.workers.dev",
14+
title: "Claudius demo",
15+
subtitle: "Ask me anything",
16+
welcomeMessage:
17+
"Hi! I'm a live Claudius widget running on this page. Try me out.",
18+
theme: "auto",
19+
storageKeyPrefix: "claudius-docs:demo",
20+
};
21+
</script>
22+
<link
23+
rel="stylesheet"
24+
href="https://cdn.jsdelivr.net/gh/PMDevSolutions/Claudius@1/cdn/claudius.css"
25+
/>
26+
<script
27+
is:inline
28+
src="https://cdn.jsdelivr.net/gh/PMDevSolutions/Claudius@1/cdn/claudius.iife.js"
29+
></script>

docs/src/content/docs/api/rest.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
---
2+
title: REST API
3+
description: The worker's HTTP endpoints — request/response shapes, error codes, and rate limiting.
4+
sidebar:
5+
order: 1
6+
---
7+
8+
Base URL: your deployed worker, e.g.
9+
`https://claudius-chat-worker.<you>.workers.dev`. CORS restricts callers to
10+
the configured [`ALLOWED_ORIGIN`](/configuration/worker/) list (plus
11+
`http://localhost:*`). Allowed methods: `POST`, `OPTIONS`;
12+
allowed header: `Content-Type`.
13+
14+
## POST /api/chat
15+
16+
Send the conversation so far; receive the assistant's reply.
17+
18+
### Request
19+
20+
```json
21+
{
22+
"messages": [
23+
{ "role": "user", "content": "Hello" },
24+
{ "role": "assistant", "content": "Hi there!" },
25+
{ "role": "user", "content": "What are your hours?" }
26+
],
27+
"conversationId": "optional-opaque-id"
28+
}
29+
```
30+
31+
| Field | Type | Notes |
32+
|-------|------|-------|
33+
| `messages` | array, required | Full conversation history, oldest first. Max **100** messages; each `content` is truncated to **2,000** characters |
34+
| `messages[].role` | `"user" \| "assistant"` | Other roles are rejected |
35+
| `conversationId` | string, optional | Opaque id used only for [analytics](/deployment/worker/#analytics-with-d1-optional) correlation |
36+
37+
### Response `200`
38+
39+
```json
40+
{
41+
"reply": "We're available Monday through Friday, 9am to 5pm.",
42+
"sources": [
43+
{ "url": "https://example.com/contact", "title": "Contact", "type": "page" }
44+
]
45+
}
46+
```
47+
48+
`sources` is optional and reserved for retrieval-backed backends — the
49+
bundled worker returns only `reply` today (see [RAG](/rag/)).
50+
51+
### Errors
52+
53+
All errors share one envelope:
54+
55+
```json
56+
{ "error": "Human-readable message", "code": "MACHINE_CODE", "limitType": "minute" }
57+
```
58+
59+
| Status | `code` | When | Extra |
60+
|--------|--------|------|-------|
61+
| `400` | `VALIDATION_ERROR` | Empty/missing `messages`, more than 100 messages, invalid role | |
62+
| `429` | `RATE_LIMITED` | Per-IP limit exceeded (default 10/min, 50/hr) | `Retry-After` header (seconds); `limitType`: `"minute"` or `"hour"` |
63+
| `500` | `CONFIG_ERROR` | Worker misconfiguration (e.g. bad API key) | |
64+
| `503` | `SERVICE_ERROR` | Claude temporarily unavailable/overloaded | |
65+
| `500` | `UNKNOWN_ERROR` | Anything else | |
66+
67+
## GET /api/health
68+
69+
```json
70+
{ "ok": true }
71+
```
72+
73+
Use for uptime checks; it does not call Claude.
74+
75+
## Client retry behavior
76+
77+
The widget's built-in API client retries up to 2 times (3 attempts total):
78+
`429` waits for the server's `Retry-After`; `503` backs off exponentially
79+
(1 s, then 3 s). Sends are debounced (300 ms default). If you build your own
80+
client, mirroring this behavior plays well with the worker's limits.
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
---
2+
title: Widget API
3+
description: TypeScript surface of the widget package — components, types, and globals.
4+
sidebar:
5+
order: 2
6+
---
7+
8+
## Exports
9+
10+
```ts
11+
import { ChatWidget } from "claudius-chat-widget";
12+
import "claudius-chat-widget/style.css";
13+
```
14+
15+
### `<ChatWidget />`
16+
17+
```ts
18+
interface ChatWidgetProps {
19+
apiUrl: string;
20+
title?: string;
21+
subtitle?: string;
22+
welcomeMessage?: string;
23+
placeholder?: string;
24+
persistMessages?: boolean;
25+
storageKeyPrefix?: string;
26+
requestTimeoutMs?: number;
27+
theme?: "light" | "dark" | "auto";
28+
accentColor?: string;
29+
position?: "bottom-right" | "bottom-left" | "top-right" | "top-left";
30+
locale?: "en" | "es" | "fr" | "de";
31+
translations?: Partial<ClaudiusTranslations>;
32+
triggers?: Trigger[];
33+
}
34+
```
35+
36+
Defaults and semantics: [widget options reference](/configuration/widget/).
37+
38+
### `Trigger`
39+
40+
```ts
41+
type Trigger =
42+
| { on: "time"; seconds: number; matchUrl?: string | RegExp; action: TriggerAction }
43+
| { on: "scroll"; percent: number; matchUrl?: string | RegExp; action: TriggerAction }
44+
| { on: "exit-intent"; matchUrl?: string | RegExp; action: TriggerAction }
45+
| { on: "url"; pattern: string | RegExp; action: TriggerAction };
46+
47+
type TriggerAction = "open" | { greeting: string };
48+
```
49+
50+
### `ClaudiusTranslations`
51+
52+
All UI strings; see the [key table](/configuration/localization/#available-keys).
53+
`Partial<ClaudiusTranslations>` merges over the resolved locale.
54+
55+
## Globals (script embed)
56+
57+
| Global | Direction | Purpose |
58+
|--------|-----------|---------|
59+
| `window.ClaudiusConfig` | you → widget | Configuration object read at load; same keys as `ChatWidgetProps` |
60+
| `window.ClaudiusWidgetVersion` | widget → you | The bundle's release version (`"dev"` for local builds) |
61+
62+
## `<claudius-chat>` web component
63+
64+
Registered automatically when the embed bundle loads. Attributes (kebab-case
65+
scalar options only): `api-url` (required), `title`, `subtitle`,
66+
`welcome-message`, `placeholder`, `persist-messages`, `storage-key-prefix`,
67+
`request-timeout-ms`, `theme`, `accent-color`, `position`. Attribute changes
68+
re-render the widget.
69+
70+
## Message persistence
71+
72+
With `persistMessages` (default on), history is stored in `sessionStorage`
73+
under `<storageKeyPrefix>` — it survives page navigation and clears when the
74+
tab closes. Trigger dismissals are stored under
75+
`claudius:triggers:dismissed`.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
title: Channels
3+
description: Where Claudius can talk to your users — web today, messaging platforms planned.
4+
---
5+
6+
## Today: the web channel
7+
8+
Claudius ships one channel: an embeddable web widget, available three ways
9+
(all backed by the same worker):
10+
11+
| Surface | Best for | Guide |
12+
|---------|----------|-------|
13+
| Script embed (`window.ClaudiusConfig` + IIFE bundle) | Any website, CMSs, static sites | [Embed via CDN](/deployment/cdn/) |
14+
| `<claudius-chat>` web component | Markup-driven embedding without React | [Static sites guide](/deployment/static-sites/) |
15+
| `ChatWidget` React component | React and Next.js apps | [React guide](/deployment/react/) |
16+
17+
Multiple widgets can share one worker, and one page can host multiple widgets
18+
(give each a unique `storageKeyPrefix`).
19+
20+
## Planned channels
21+
22+
The worker core (validation, rate limiting, Claude integration, analytics) is
23+
channel-agnostic by design; messaging adapters are tracked for v2:
24+
25+
- **Slack and Microsoft Teams** adapters sharing the worker core —
26+
[#62](https://github.com/PMDevSolutions/Claudius/issues/62)
27+
- **SMS and WhatsApp** via Twilio —
28+
[#63](https://github.com/PMDevSolutions/Claudius/issues/63)
29+
30+
Neither is shipped yet. Watch the issues for design discussion and progress.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
title: Multi-client configs
3+
description: Manage one widget+worker pair per client with JSON configs and the CLI.
4+
sidebar:
5+
order: 6
6+
---
7+
8+
Agencies deploying Claudius for several clients keep one JSON config per
9+
client in `clients/`, validated against `clients/_schema.json`.
10+
11+
## CLI
12+
13+
```bash
14+
pnpm claudius init acme # scaffold clients/acme.json
15+
pnpm claudius validate acme # validate against the schema
16+
pnpm claudius snippet acme # generate the embed snippet(s)
17+
```
18+
19+
## Config structure
20+
21+
```json
22+
{
23+
"$schema": "./_schema.json",
24+
"name": "Acme Corp",
25+
"slug": "acme",
26+
"apiUrl": "https://acme-chat.example.workers.dev/api/chat",
27+
"allowedDomains": ["acme.example"],
28+
"widget": {
29+
"title": "Acme Support",
30+
"theme": "auto",
31+
"accentColor": "#aa0000",
32+
"position": "bottom-right"
33+
},
34+
"worker": {
35+
"model": "claude-haiku-4-5-20251001",
36+
"maxTokens": 1024,
37+
"rateLimitMinute": 10,
38+
"rateLimitHour": 50,
39+
"systemPrompt": "acme-system-prompt.md"
40+
}
41+
}
42+
```
43+
44+
| Field | Required | Description |
45+
|-------|----------|-------------|
46+
| `name` | Yes | Human-readable client name |
47+
| `slug` | Yes | URL-safe identifier; must match the filename |
48+
| `apiUrl` | Yes | The client's worker chat endpoint |
49+
| `allowedDomains` | Yes | Domains where the widget may be embedded |
50+
| `widget` | No | Appearance: `title`, `subtitle`, `welcomeMessage`, `placeholder`, `theme`, `position`, `accentColor` |
51+
| `worker` | No | `model`, `maxTokens` (1–8192), `rateLimitMinute`, `rateLimitHour`, `systemPrompt` (path to a markdown file) |
52+
53+
See `clients/example.json` and `clients/example-system-prompt.md` in the repo
54+
for a complete worked example. Referencing `_schema.json` from `$schema` gives
55+
IDE autocomplete and inline validation.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
title: Localization
3+
description: Bundled locales, automatic detection, and custom translations.
4+
sidebar:
5+
order: 4
6+
---
7+
8+
The widget ships English (`en`), Spanish (`es`), French (`fr`), and German
9+
(`de`) UI strings.
10+
11+
## Locale resolution
12+
13+
1. Explicit `locale` option, if set
14+
2. `<html lang>` attribute of the host page
15+
3. `navigator.language`
16+
4. Fallback: English
17+
18+
Region subtags are normalized (`fr-CA``fr`); unknown languages fall back to
19+
English.
20+
21+
```js
22+
window.ClaudiusConfig = {
23+
apiUrl: "...",
24+
locale: "de", // force German regardless of page/browser language
25+
};
26+
```
27+
28+
## Overriding individual strings
29+
30+
`translations` merges over the resolved locale, so you can override just the
31+
strings you care about:
32+
33+
```js
34+
window.ClaudiusConfig = {
35+
apiUrl: "...",
36+
locale: "es",
37+
translations: {
38+
title: "Soporte PMDS",
39+
welcomeMessage: "¡Hola! ¿En qué puedo ayudarte hoy?",
40+
},
41+
};
42+
```
43+
44+
## Available keys
45+
46+
| Group | Keys |
47+
|-------|------|
48+
| Window | `title`, `subtitle`, `welcomeMessage`, `closeChat`, `chatMessages`, `typingIndicator` |
49+
| Input | `placeholder`, `sendMessage`, `typeYourMessage` |
50+
| Toggle / bubble | `openChat`, `dismissGreeting` |
51+
| Errors | `errorGeneric`, `errorConnection`, `errorTimeout`, `errorRateLimitMinute`, `errorRateLimitHour`, `errorRetry` |
52+
53+
Note these localize the widget UI only. The AI's reply language follows the
54+
conversation and your [system prompt](/configuration/worker/#system-prompt)
55+
instruct the bot there if you want replies pinned to a language.

0 commit comments

Comments
 (0)