@cms.ai/brand_brain 0.0.1
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 +95 -0
- package/dist/index.cjs +1748 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +395 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +395 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +1741 -0
- package/dist/index.mjs.map +1 -0
- package/dist/react/index.cjs +1789 -0
- package/dist/react/index.cjs.map +1 -0
- package/dist/react/index.d.cts +387 -0
- package/dist/react/index.d.cts.map +1 -0
- package/dist/react/index.d.mts +387 -0
- package/dist/react/index.d.mts.map +1 -0
- package/dist/react/index.mjs +1788 -0
- package/dist/react/index.mjs.map +1 -0
- package/package.json +80 -0
- package/src/GuideClient.ts +239 -0
- package/src/analytics.test.ts +25 -0
- package/src/analytics.ts +36 -0
- package/src/api.ts +26 -0
- package/src/chat-stream.test.ts +55 -0
- package/src/chat-stream.ts +130 -0
- package/src/index.ts +2 -0
- package/src/react/index.ts +2 -0
- package/src/react/useGuide.ts +101 -0
- package/src/types.ts +316 -0
package/README.md
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# @cms.ai/brand_brain
|
|
2
|
+
|
|
3
|
+
Client-side SDK for building **CMS.ai Brand Brain (Guide)** experiences directly into your own website UI — your own chat, your own layout — instead of the drop-in overlay. It handles the visitor session, streaming chat across every guide skill, conversation history, and lead capture, all against your branded CMS.ai host.
|
|
4
|
+
|
|
5
|
+
Framework-agnostic core + an optional React binding.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @cms.ai/brand_brain
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Quick start (vanilla JS/TS)
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { initGuide } from "@cms.ai/brand_brain";
|
|
17
|
+
|
|
18
|
+
const guide = await initGuide({
|
|
19
|
+
baseUrl: "https://guide.yourcompany.com", // your branded CMS.ai host
|
|
20
|
+
slug: "default", // which guide to load
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
// Stream a reply into your own UI:
|
|
24
|
+
for await (const event of guide.ask("How does pricing work?")) {
|
|
25
|
+
if (event.type === "text") {
|
|
26
|
+
appendToChatBubble(event.delta); // your render fn
|
|
27
|
+
} else if (event.type === "gate") {
|
|
28
|
+
// The guide is asking for an email before continuing.
|
|
29
|
+
await guide.submitGate("visitor@acme.com");
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
> **`baseUrl` must be your branded CMS.ai host on your own root domain** (e.g. `guide.yourcompany.com`, the CNAME we provision). That keeps the visitor cookies same-site, so identity + analytics work in every browser without any third-party-cookie caveats.
|
|
35
|
+
|
|
36
|
+
## Quick start (React)
|
|
37
|
+
|
|
38
|
+
```tsx
|
|
39
|
+
import { useGuide } from "@cms.ai/brand_brain/react";
|
|
40
|
+
|
|
41
|
+
function Chat() {
|
|
42
|
+
const { messages, ask, isStreaming, isReady } = useGuide({
|
|
43
|
+
baseUrl: "https://guide.yourcompany.com",
|
|
44
|
+
slug: "default",
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<div>
|
|
49
|
+
{messages.map((m) => (
|
|
50
|
+
<p key={m.id} data-role={m.role}>
|
|
51
|
+
{m.content}
|
|
52
|
+
</p>
|
|
53
|
+
))}
|
|
54
|
+
<button disabled={!isReady || isStreaming} onClick={() => ask("What can you help me with?")}>
|
|
55
|
+
Ask
|
|
56
|
+
</button>
|
|
57
|
+
</div>
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## The `ask()` event stream
|
|
63
|
+
|
|
64
|
+
`ask()` returns an async iterator of `GuideStreamEvent`s. The common case is `text`; `skill` carries every structured deliverable (documents, recommendations, how-to steps, diagnose questions, business cases, solution designs, …), discriminated by its `name`.
|
|
65
|
+
|
|
66
|
+
| `event.type` | Meaning |
|
|
67
|
+
| ---------------------------------------- | ------------------------------------------------------------------------------ |
|
|
68
|
+
| `run-started` / `run-finished` | Turn lifecycle |
|
|
69
|
+
| `message-start` / `text` / `message-end` | The streamed chat reply (`text.delta` is the token chunk) |
|
|
70
|
+
| `skill` | A structured skill payload — `{ name, value }`, where `name` is a `GuideEvent` |
|
|
71
|
+
| `gate` | The guide needs an email before continuing — call `guide.submitGate(email)` |
|
|
72
|
+
| `error` | A run or skill error — `{ message, code? }` |
|
|
73
|
+
|
|
74
|
+
Skill routing is automatic (the server picks the skill from the message). Force one with `guide.ask(text, { forcedSkill: SkillResponseType.HowTo })`.
|
|
75
|
+
|
|
76
|
+
## API
|
|
77
|
+
|
|
78
|
+
`initGuide(config)` → `GuideClient`. Config: `baseUrl`, `slug`, optional `domain` (defaults to `window.location.hostname`), `consent` (`"auto"` | `{ functional?, analytical? }` | `false`), `trackLoad` (default `true`), `fetch`.
|
|
79
|
+
|
|
80
|
+
`GuideClient`:
|
|
81
|
+
|
|
82
|
+
- `guide` — resolved metadata (`id`, `accountId`, `theme`, `customization`, …)
|
|
83
|
+
- `ask(message, { forcedSkill?, signal? })` — stream a reply (see above)
|
|
84
|
+
- `messages` / `reset()` — in-memory conversation history
|
|
85
|
+
- `setConsent({ functional?, analytical? })` / `getStatus()`
|
|
86
|
+
- `submitGate(email, options?)` — capture a lead (magic link when verification is required)
|
|
87
|
+
- `track(eventType, properties?)` / `trackPageView(url?)` — analytics (call `trackPageView` on SPA route changes)
|
|
88
|
+
- `endSession()` — end the visit (call on `pagehide`)
|
|
89
|
+
- `conversations` — `getOrCreate()`, `list()`, `get(id, { cursor?, limit? })`, `delete(id)`
|
|
90
|
+
- `skills` — `listHistory()`, `get(id)`, `update(id, data)`, `selectDraft(id)`, `markShared(id)`, `importShared(id)`
|
|
91
|
+
|
|
92
|
+
## Notes
|
|
93
|
+
|
|
94
|
+
- The SDK calls the existing public CMS.ai API — it introduces no new endpoints.
|
|
95
|
+
- `@navless/*` internals are bundled in; the published package has no `@navless/*` runtime dependencies. `react` / `react-dom` are optional peers used only by `@cms.ai/brand_brain/react`.
|