@aginies/webuikit 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,75 @@
1
+ # @aginies/webuikit
2
+
3
+ React components and widgets that embed Aginies agents into any site: the hosted chat as a
4
+ bubble, an inline panel or a full page, plus the core primitives of the Aginies design
5
+ system. The package is public; rendering requires an activation token issued for your
6
+ deployment, and the platform only answers origins listed in its configuration.
7
+
8
+ ```bash
9
+ npm install @aginies/webuikit react react-dom
10
+ ```
11
+
12
+ ## Quick start
13
+
14
+ ```tsx
15
+ import { init, AginiesProvider, ChatWidget } from '@aginies/webuikit'
16
+ import '@aginies/webuikit/styles.css'
17
+
18
+ init({ baseUrl: 'https://app.your-aginies.example', token: 'agn_…', locale: 'tr' })
19
+
20
+ export function App() {
21
+ return (
22
+ <AginiesProvider>
23
+ <ChatWidget identifier='support' mode='bubble' />
24
+ </AginiesProvider>
25
+ )
26
+ }
27
+ ```
28
+
29
+ `init()` runs the activation handshake (`POST /api/ui/activate`) once. Until it succeeds
30
+ the provider renders its `fallback`; if the platform refuses the token or the origin,
31
+ nothing renders and one warning is logged.
32
+
33
+ ## Activation keys
34
+
35
+ Two kinds of token work with `init()`:
36
+
37
+ - **Tenant keys** (`agn_pk_…`) are created per tenant in the platform's admin console
38
+ (tenant page, "UI package keys"), each with its own list of allowed origins
39
+ (`https://www.example.com`, `https://*.example.com` or `*` for development), an
40
+ optional module list and an optional expiry. The key is publishable: it identifies the
41
+ tenant and unlocks nothing on its own. A successful activation returns a one-hour
42
+ session that the client sends as `Authorization: Bearer …` on every platform call and
43
+ renews on its own when it expires. Only the tenant's own chats can be reached through
44
+ it, and only the modules the key enables render; the rest render nothing and log one
45
+ warning. `client.getSession()` and `client.hasModule('chat')` expose both, and
46
+ `useModule('run')` does the same inside components.
47
+ - **The static key** from the platform's `UI_PACKAGE_ACTIVATION_KEY` works for origins
48
+ listed in `UI_PACKAGE_ALLOWED_ORIGINS`. No session is involved: those origins are
49
+ trusted by configuration. Meant for the platform's own sites and local development.
50
+
51
+ ## Platform configuration
52
+
53
+ | Variable | Purpose |
54
+ |---|---|
55
+ | `UI_PACKAGE_ACTIVATION_KEY` | The static activation token (optional when tenant keys are used). |
56
+ | `UI_PACKAGE_ALLOWED_ORIGINS` | Comma-separated origins trusted without a tenant key (CORS, cookies, frame-ancestors). `*` for local development. |
57
+ | `INTERNAL_API_SECRET` | Signs tenant sessions (already required by the platform). |
58
+
59
+ ## Components
60
+
61
+ - `ChatWidget` — `identifier`, `mode` (`bubble` | `inline` | `full`), `position`, `launcherLabel`, `theme` (`dark` | `light` | `auto`). Streams replies, renders them as Markdown (headings, emphasis, code, links, lists, quotes, tables; never raw HTML), renders structured replies (text, buttons, table, cards, pie, image), lets visitors attach up to five files of 10 MB, and handles password and e-mail protected chats. E-mail protection follows the platform's two-step flow: the address receives a six-digit code, which the widget verifies.
62
+ - `Markdown` — the same renderer on its own: `<Markdown text={reply} />`.
63
+ - `AgentRunner` — `workflowId`, `apiKey` (an `execute`-scoped key for that agent only; it is visible to the page), `fields` (form spec) and `onResult`. Posts the form as the agent's input, streams text and steps, shows the final output. `useAgentRun(workflowId, apiKey)` for a custom UI.
64
+ - `useChat(identifier)` — the same state for a custom UI: `messages`, `send`, `stop`, `busy`, `authNeed`, `authenticate`.
65
+ - `ApprovalPanel` — `workflowId`, `executionId` (from the resume link a "Human in the Loop" block sends), optional `contextId`, `onResumed`. Shows what the agent proposes, renders the approver's form the block author configured (string, number, boolean, JSON, select), validates it and resumes the run; queued resumes are reported as such. `useApproval(workflowId, executionId)` for a custom UI; the `approval` module must be enabled on the key.
66
+ - Observability (data-driven): `StatTiles`, `SuccessHeatmap` (per-agent success by day or hour, threshold-coloured), `RunTimeline` (steps on the run scale with tokens and cost), `CostBars` (cost by scenario, unit or channel).
67
+ - Core: `Button`, `Tag`, `Chip`, `Panel`, `Eyebrow`, `Stat`, `Field`, `Input`, `Textarea`, `Spinner`.
68
+ - `useChat(identifier)` — the widget's state for a custom UI: `messages`, `send(text, files)`, `stop`, `authenticate({ password })`, `requestCode(email)`, `verifyCode(email, code)`.
69
+ - `AginiesClient` — the underlying client (`activate`, `getChat`, `sendMessage` as an async generator, `getSession`, `hasModule`, `fetchRaw` with the session attached).
70
+
71
+ ## Theming
72
+
73
+ Styles come from `@aginies/tokens`: dark by default, `.light` / `[data-theme="light"]` on an
74
+ ancestor (or the widget's `theme` prop) for the light palette. Override `--signal`,
75
+ `--bg`, `--panel` and friends on a wrapper to whitelabel.