@lambforge/agent-chat 0.0.0-stage → 0.0.2
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 +81 -2
- package/dist/agent-chat.js +280 -0
- package/dist/agent-chat.js.map +7 -0
- package/dist/auto.d.ts +1 -0
- package/dist/element.d.ts +142 -0
- package/dist/index.cjs +4122 -0
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.mjs +4136 -0
- package/dist/index.mjs.map +7 -0
- package/dist/markdown.d.ts +3 -0
- package/dist/store/chat-actions.d.ts +121 -0
- package/dist/store/chat-effects.d.ts +44 -0
- package/dist/store/chat-reducer.d.ts +2 -0
- package/dist/store/chat-state.d.ts +31 -0
- package/dist/store/chat-store.d.ts +18 -0
- package/dist/store/index.d.ts +5 -0
- package/dist/strings.d.ts +20 -0
- package/dist/styles.d.ts +2 -0
- package/dist/turnstile.d.ts +12 -0
- package/package.json +55 -4
package/README.md
CHANGED
|
@@ -1,3 +1,82 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @lambforge/agent-chat
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A chat with your [Lambforge](https://lambforge.com) agent on any site: one
|
|
4
|
+
script tag, or the `<lambforge-agent-chat>` web component in any framework.
|
|
5
|
+
|
|
6
|
+
## One script tag (anonymous visitors)
|
|
7
|
+
|
|
8
|
+
Publish the agent in the dashboard, create a **publishable** agent key
|
|
9
|
+
(`lfp_...`, safe in HTML) for your site, then:
|
|
10
|
+
|
|
11
|
+
```html
|
|
12
|
+
<script
|
|
13
|
+
src="https://cdn.jsdelivr.net/npm/@lambforge/agent-chat/dist/agent-chat.js"
|
|
14
|
+
data-key="lfp_..."
|
|
15
|
+
data-agent="Support"
|
|
16
|
+
></script>
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
A chat button appears in the corner. Visitors pass a Cloudflare Turnstile
|
|
20
|
+
bot check once per session (hosted by Lambforge, or your own widget with
|
|
21
|
+
`data-turnstile-sitekey` - its hostname must be one of the key's sites).
|
|
22
|
+
|
|
23
|
+
## Your signed-in users
|
|
24
|
+
|
|
25
|
+
Your server mints a session per user with `@lambforge/agents` (a secret
|
|
26
|
+
`lfk_` key) and answers `{ token, expiresAt }`:
|
|
27
|
+
|
|
28
|
+
```html
|
|
29
|
+
<script src="https://cdn.jsdelivr.net/npm/@lambforge/agent-chat/dist/agent-chat.js"></script>
|
|
30
|
+
<lambforge-agent-chat token-url="/agent-token" agent="Accountant"></lambforge-agent-chat>
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## In an app (npm)
|
|
34
|
+
|
|
35
|
+
```sh
|
|
36
|
+
npm install @lambforge/agent-chat @lambforge/agents rxjs
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
import '@lambforge/agent-chat'; // registers <lambforge-agent-chat>
|
|
41
|
+
import { AgentClient } from '@lambforge/agents';
|
|
42
|
+
|
|
43
|
+
const chat = document.querySelector('lambforge-agent-chat')!;
|
|
44
|
+
chat.client = new AgentClient({ getToken: () => fetch('/agent-token').then((r) => r.json()) });
|
|
45
|
+
chat.addEventListener('answer', (e) => console.log(e.detail.text));
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Server-side rendering (Next.js, Nuxt, Angular SSR): import it in the
|
|
49
|
+
browser only (`useEffect(() => { import('@lambforge/agent-chat') }, [])`) -
|
|
50
|
+
defining a custom element needs `window`.
|
|
51
|
+
|
|
52
|
+
## Options
|
|
53
|
+
|
|
54
|
+
| Attribute | |
|
|
55
|
+
|---|---|
|
|
56
|
+
| `publishable-key` / `token-url` | the session (or the `.client` / `.getToken` properties) |
|
|
57
|
+
| `agent` | the agent to start with (id or name) |
|
|
58
|
+
| `agents` | only these agents (comma list); a picker when more than one |
|
|
59
|
+
| `mode` | `drawer` (default), `inline`, `fullscreen` |
|
|
60
|
+
| `position` | `bottom-right` (default), `bottom-left` |
|
|
61
|
+
| `open` | the drawer starts open |
|
|
62
|
+
| `theme` | `light` (default), `dark` |
|
|
63
|
+
| `locale` | `en`, `bg` (default: the page's `lang`); `.strings` overrides any text |
|
|
64
|
+
| `title` | the header (default: the agent's name) |
|
|
65
|
+
|
|
66
|
+
With the script tag the same settings are `data-*` attributes
|
|
67
|
+
(`data-key`, `data-token-url`, `data-agent`, `data-mode`, ...).
|
|
68
|
+
|
|
69
|
+
Events: `open-change` `{ open }`, `answer` `{ text, agent, conversationId }`,
|
|
70
|
+
`error` `{ code }`.
|
|
71
|
+
|
|
72
|
+
Look: CSS variables `--lf-chat-accent`, `--lf-chat-bg`, `--lf-chat-fg`,
|
|
73
|
+
`--lf-chat-radius`, `--lf-chat-font`, `--lf-chat-width`, ... and
|
|
74
|
+
`::part(launcher | panel | header | messages | message | composer | send ...)`;
|
|
75
|
+
the `launcher` slot replaces the button's icon. Editors that read
|
|
76
|
+
`@customElement` JSDoc (web-component-analyzer, lit-plugin) autocomplete
|
|
77
|
+
all of them.
|
|
78
|
+
|
|
79
|
+
Answers render a safe markdown subset (paragraphs, lists, code, bold,
|
|
80
|
+
italics, http(s) links); an answer can never inject HTML.
|
|
81
|
+
|
|
82
|
+
License: MIT
|