Skip to content

Commit 3049770

Browse files
docs: add widget YAML config and /communities endpoint
- Schema reference: add widget section (title, initial_message, placeholder, suggested_questions) - Widget deployment: document two-layer config (YAML defaults + JS overrides), add widgetInstructions - Quick start: add widget to example config.yaml, simplify widget deploy step - API reference: add GET /communities endpoint
1 parent 453842c commit 3049770

4 files changed

Lines changed: 142 additions & 24 deletions

File tree

docs/osa/api-reference.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,37 @@ Response:
6262
}
6363
```
6464

65+
### List Communities
66+
67+
Get all available communities and their widget configuration.
68+
69+
```
70+
GET /communities
71+
```
72+
73+
Response:
74+
```json
75+
[
76+
{
77+
"id": "hed",
78+
"name": "HED (Hierarchical Event Descriptors)",
79+
"description": "Event annotation standard for neuroimaging research",
80+
"status": "available",
81+
"widget": {
82+
"title": "HED Assistant",
83+
"initial_message": "Hi! I'm the HED Assistant...",
84+
"placeholder": "Ask about HED...",
85+
"suggested_questions": [
86+
"What is HED and how is it used?",
87+
"How do I annotate an event with HED tags?"
88+
]
89+
}
90+
}
91+
]
92+
```
93+
94+
This endpoint is public (no authentication required) and is used by the widget to load display configuration from the community YAML configs.
95+
6596
### Chat
6697

6798
Send a message and receive a streaming response.

docs/osa/deployment/widget.md

Lines changed: 52 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,33 @@ Add two script tags to your HTML:
1717

1818
The widget appears as a chat bubble in the bottom-right corner of the page.
1919

20+
## How Configuration Works
21+
22+
Widget configuration uses a two-layer approach:
23+
24+
1. **YAML defaults** (community-level): Title, greeting, placeholder, and suggested questions are defined in each community's `config.yaml` under the `widget` section. These are served by the `GET /communities` API endpoint.
25+
2. **JavaScript overrides** (page-level): Embedders can override any field via `setConfig()`. Any value set in JavaScript takes precedence over the YAML defaults.
26+
27+
This means most embedders only need to set `communityId`; the widget fetches its display configuration from the API automatically.
28+
2029
## Configuration Options
2130

31+
### Display Options (from YAML defaults)
32+
33+
These fields are typically configured in the community's `config.yaml` and loaded automatically. You can override them per-page via `setConfig()`:
34+
2235
| Option | Type | Default | Description |
2336
|--------|------|---------|-------------|
2437
| `communityId` | string | `'hed'` | Which community assistant to use |
25-
| `title` | string | `'HED Assistant'` | Widget header title |
26-
| `initialMessage` | string | HED greeting | First message shown to user |
27-
| `placeholder` | string | `'Ask about HED...'` | Input placeholder text |
28-
| `suggestedQuestions` | string[] | HED questions | Clickable suggestion buttons |
38+
| `title` | string | From YAML or community name | Widget header title |
39+
| `initialMessage` | string | From YAML | First message shown to user |
40+
| `placeholder` | string | From YAML or `'Ask a question...'` | Input placeholder text |
41+
| `suggestedQuestions` | string[] | From YAML | Clickable suggestion buttons |
42+
43+
### Behavior Options
44+
45+
| Option | Type | Default | Description |
46+
|--------|------|---------|-------------|
2947
| `apiEndpoint` | string | Auto-detected | Backend API URL |
3048
| `storageKey` | string | Auto-derived | localStorage key for chat history |
3149
| `turnstileSiteKey` | string | `null` | Cloudflare Turnstile site key |
@@ -37,10 +55,11 @@ The widget appears as a chat bubble in the bottom-right corner of the page.
3755
| `pageContextStorageKey` | string | `'osa-page-context-enabled'` | localStorage key for page context preference |
3856
| `pageContextLabel` | string | `'Share page URL...'` | Label text for the page context checkbox |
3957
| `fullscreen` | boolean | `false` | Open chat in fullscreen mode |
58+
| `widgetInstructions` | string | `null` | Per-page context hint sent to the assistant (max 2000 chars) |
4059

4160
### Minimal Configuration
4261

43-
Only `communityId` is required. Everything else has sensible defaults:
62+
Only `communityId` is required. The widget fetches display settings (title, greeting, placeholder, suggested questions) from the `/communities` API automatically:
4463

4564
```html
4665
<script src="https://osa-demo.pages.dev/osa-chat-widget.js"></script>
@@ -51,6 +70,22 @@ Only `communityId` is required. Everything else has sensible defaults:
5170
</script>
5271
```
5372

73+
### Per-Page Customization
74+
75+
Use `widgetInstructions` to give the assistant context about the specific page where the widget is embedded. This is sent to the backend as part of the page context and helps the assistant provide more relevant answers:
76+
77+
```html
78+
<script src="https://osa-demo.pages.dev/osa-chat-widget.js"></script>
79+
<script>
80+
OSAChatWidget.setConfig({
81+
communityId: 'hed',
82+
widgetInstructions: 'The user is on the HED online validation tools page. Focus on helping with validation errors and tool usage.'
83+
});
84+
</script>
85+
```
86+
87+
This is useful when the same community assistant is embedded across multiple pages (e.g., documentation, tools, tutorials) and you want the assistant to adapt its responses to the page context.
88+
5489
### Full Configuration
5590

5691
```html
@@ -67,6 +102,7 @@ Only `communityId` is required. Everything else has sensible defaults:
67102
'Validate my HED string',
68103
'What tools are available?'
69104
],
105+
widgetInstructions: 'User is on the annotation guide page.',
70106
showExperimentalBadge: false,
71107
allowPageContext: true,
72108
pageContextDefaultEnabled: true
@@ -142,26 +178,30 @@ When configured, users must complete a Turnstile challenge before sending messag
142178

143179
## API Endpoints
144180

145-
The widget communicates with two backend endpoints:
181+
The widget communicates with the following backend endpoints:
146182

147183
| Endpoint | Method | Description |
148184
|----------|--------|-------------|
185+
| `/communities` | GET | Fetch available communities and widget config |
149186
| `/{communityId}/ask` | POST | Send a question, get a response |
150187
| `/health` | GET | Check backend status |
151188

189+
On load, the widget fetches `/communities` to get display configuration (title, greeting, placeholder, suggested questions) for all available communities. This eliminates the need to hardcode these values in JavaScript.
190+
152191
### Request Format
153192

154193
```json
155194
{
156195
"question": "What is HED?",
157196
"page_context": {
158197
"url": "https://hedtags.org/docs/getting-started",
159-
"title": "Getting Started - HED"
198+
"title": "Getting Started - HED",
199+
"widget_instructions": "User is on the getting started page."
160200
}
161201
}
162202
```
163203

164-
The `cf_turnstile_response` field is also sent by the widget when Turnstile is configured, but this is consumed by the Cloudflare Worker proxy, not the backend API.
204+
The `widget_instructions` field is optional and only sent when configured via `setConfig({ widgetInstructions: '...' })`. The `cf_turnstile_response` field is also sent by the widget when Turnstile is configured, but this is consumed by the Cloudflare Worker proxy, not the backend API.
165205

166206
### Response Format
167207

@@ -193,14 +233,12 @@ To host the widget yourself:
193233

194234
## Demo Page
195235

196-
The demo page at [osa-demo.pages.dev](https://osa-demo.pages.dev) showcases all available community assistants with URL-based routing:
236+
The demo page at [osa-demo.pages.dev](https://osa-demo.pages.dev) dynamically loads all available communities from the `/communities` API and showcases them with URL-based routing:
197237

198-
- `/` - Landing page with community cards
199-
- `/hed` - HED assistant demo
200-
- `/bids` - BIDS assistant demo
201-
- `/eeglab` - EEGLAB assistant demo
238+
- `/` - Landing page with community cards (populated from API)
239+
- `/{communityId}` - Community-specific assistant demo (e.g., `/hed`, `/bids`, `/eeglab`)
202240

203-
Each community page auto-configures the widget with the appropriate settings.
241+
Each community page auto-configures the widget using the YAML-defined defaults. New communities added to the registry appear on the demo page automatically without frontend changes.
204242

205243
## Troubleshooting
206244

docs/osa/registry/quick-start.md

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,16 @@ github:
6767
- org/my-tool
6868
- org/my-tool-plugins
6969

70+
# Widget display configuration (optional)
71+
widget:
72+
title: My Tool Assistant
73+
initial_message: "Hi! I can help with My Tool. What would you like to know?"
74+
placeholder: Ask about My Tool...
75+
suggested_questions:
76+
- How do I get started with My Tool?
77+
- What are the configuration options?
78+
- How do I use the API?
79+
7080
# Paper search and citation tracking
7181
citations:
7282
queries:
@@ -129,26 +139,29 @@ uv run osa sync all --community my-tool
129139

130140
## Step 6: Deploy the Widget (Optional)
131141

132-
Add the chat widget to your community's website:
142+
Add the chat widget to your community's website. If you configured the `widget` section in your `config.yaml`, only `communityId` is needed; the widget fetches display settings from the API automatically:
133143

134144
```html
135145
<script src="https://osa-demo.pages.dev/osa-chat-widget.js"></script>
146+
<script>
147+
OSAChatWidget.setConfig({
148+
communityId: 'my-tool'
149+
});
150+
</script>
151+
```
152+
153+
You can optionally add per-page context to help the assistant understand the current page:
154+
155+
```html
136156
<script>
137157
OSAChatWidget.setConfig({
138158
communityId: 'my-tool',
139-
title: 'My Tool Assistant',
140-
initialMessage: 'Hi! I can help with My Tool. What would you like to know?',
141-
placeholder: 'Ask about My Tool...',
142-
suggestedQuestions: [
143-
'How do I get started?',
144-
'What are the configuration options?',
145-
'How do I use the API?'
146-
]
159+
widgetInstructions: 'The user is on the installation guide page.'
147160
});
148161
</script>
149162
```
150163

151-
See the [Widget Deployment Guide](../deployment/widget.md) for more options.
164+
See the [Widget Deployment Guide](../deployment/widget.md) for all configuration options.
152165

153166
## What You Get
154167

docs/osa/registry/schema-reference.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Complete reference for the community `config.yaml` file format.
1616
| `github` | object | No | `null` | GitHub sync configuration |
1717
| `citations` | object | No | `null` | Paper/citation search config |
1818
| `discourse` | list | No | `[]` | Discourse forum configs |
19+
| `widget` | object | No | `null` | Widget display configuration (title, greeting, suggestions) |
1920
| `extensions` | object | No | `null` | Extension points (plugins, MCP) |
2021

2122
## `id`
@@ -205,6 +206,33 @@ extensions:
205206
url: https://mcp.my-tool.org
206207
```
207208

209+
## `widget`
210+
211+
Widget display configuration for the embedded chat widget. These values provide defaults that the widget loads from the `/communities` API endpoint, so embedders only need to set `communityId` in their JavaScript.
212+
213+
| Field | Type | Required | Default | Description |
214+
|-------|------|----------|---------|-------------|
215+
| `title` | string | No | Community `name` | Widget header title (max 100 chars) |
216+
| `initial_message` | string | No | `null` | Greeting message shown when chat opens (max 1000 chars) |
217+
| `placeholder` | string | No | `"Ask a question..."` | Input field placeholder text (max 200 chars) |
218+
| `suggested_questions` | list[string] | No | `[]` | Clickable suggestion buttons (max 10) |
219+
220+
```yaml
221+
widget:
222+
title: HED Assistant
223+
initial_message: "Hi! I'm the HED Assistant. I can help with HED annotation, validation, and related tools."
224+
placeholder: Ask about HED...
225+
suggested_questions:
226+
- What is HED and how is it used?
227+
- How do I annotate an event with HED tags?
228+
- What tools are available for working with HED?
229+
- Explain this HED validation error.
230+
```
231+
232+
When the widget is embedded on a page, it fetches community defaults from `GET /communities` and applies them automatically. Embedders can still override any field via `setConfig()` in JavaScript; see the [Widget Deployment Guide](../deployment/widget.md).
233+
234+
If `widget` is omitted, the widget falls back to generic defaults (title = community name, placeholder = "Ask a question...").
235+
208236
## `enable_page_context`
209237

210238
When `true` (default), the assistant includes a `fetch_current_page` tool that retrieves content from the web page where the widget is embedded. This allows the assistant to provide contextually relevant answers based on what the user is currently reading.
@@ -254,6 +282,14 @@ citations:
254282
dois:
255283
- "10.1016/j.neuroimage.2021.118766"
256284
285+
widget:
286+
title: HED Assistant
287+
initial_message: "Hi! I'm the HED Assistant. I can help with HED annotations."
288+
placeholder: Ask about HED...
289+
suggested_questions:
290+
- What is HED and how is it used?
291+
- How do I annotate an event with HED tags?
292+
257293
discourse:
258294
- url: https://neurostars.org
259295
tags:

0 commit comments

Comments
 (0)