dewee-webchat 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +144 -2
- package/astro/DeweeChat.astro +21 -0
- package/dist/chunk-D4JM2FOB.js +1271 -0
- package/dist/chunk-WD6V3TAX.js +10 -0
- package/dist/dewee-webchat.js +258 -0
- package/dist/index.d.ts +161 -0
- package/dist/index.js +17 -0
- package/dist/protocol-CS8_4zC0.d.ts +71 -0
- package/dist/react.d.ts +26 -0
- package/dist/react.js +44 -0
- package/dist/server.d.ts +125 -0
- package/dist/server.js +632 -0
- package/dist/vue.d.ts +254 -0
- package/dist/vue.js +66 -0
- package/package.json +97 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 NextLevelBuilder
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,145 @@
|
|
|
1
|
-
#
|
|
1
|
+
# dewee-webchat
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Put your [Dewee](https://dewee.sh) agent on any website. A dependency-free chat widget that streams the
|
|
4
|
+
agent's **reasoning** and **tool calls**, plus a small backend handler that keeps your gateway token
|
|
5
|
+
off the browser.
|
|
6
|
+
|
|
7
|
+
**Playground:** [webchat.dewee.sh](https://webchat.dewee.sh) · **CDN:** [webchat-cdn.dewee.sh](https://webchat-cdn.dewee.sh) ·
|
|
8
|
+
**Source & examples:** [github.com/nextlevelbuilder/dewee-webchat](https://github.com/nextlevelbuilder/dewee-webchat)
|
|
9
|
+
|
|
10
|
+
```
|
|
11
|
+
browser <dewee-chat> ──HTTPS + SSE──▶ your backend /api/dewee/* ──WebSocket──▶ Dewee gateway
|
|
12
|
+
(visitor token only) (holds the gateway token) (agents, MCP, tools)
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## 1. Add the backend
|
|
16
|
+
|
|
17
|
+
The handler is a standard `(Request) => Promise<Response>`, so it runs on Cloudflare Workers, Next.js,
|
|
18
|
+
Astro, Bun, Deno and Node (via `toNodeHandler`).
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
// Next.js: app/api/dewee/[...path]/route.ts
|
|
22
|
+
import { createDeweeHandler, optionsFromEnv } from "dewee-webchat/server";
|
|
23
|
+
|
|
24
|
+
export const dynamic = "force-dynamic";
|
|
25
|
+
const handler = createDeweeHandler(optionsFromEnv(process.env));
|
|
26
|
+
export { handler as GET, handler as POST, handler as OPTIONS };
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
// Express
|
|
31
|
+
import { createDeweeHandler, optionsFromEnv, toNodeHandler } from "dewee-webchat/server";
|
|
32
|
+
app.all("/api/dewee/*path", toNodeHandler(createDeweeHandler(optionsFromEnv(process.env))));
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
// Cloudflare Workers
|
|
37
|
+
let dewee;
|
|
38
|
+
export default {
|
|
39
|
+
fetch(req, env) {
|
|
40
|
+
if (new URL(req.url).pathname.startsWith("/api/dewee/")) return (dewee ??= createDeweeHandler(optionsFromEnv(env)))(req);
|
|
41
|
+
return env.ASSETS.fetch(req);
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
PHP? Use the single-file backend in [`php/`](https://github.com/nextlevelbuilder/dewee-webchat/tree/main/php).
|
|
47
|
+
|
|
48
|
+
### Environment
|
|
49
|
+
|
|
50
|
+
| Variable | |
|
|
51
|
+
|---|---|
|
|
52
|
+
| `DEWEE_GATEWAY_URL` | Gateway runtime origin, e.g. `https://gateway.example.com` |
|
|
53
|
+
| `DEWEE_GATEWAY_TOKEN` | Operator API key (`operator.read,operator.write`) or gateway token. **Server only.** |
|
|
54
|
+
| `DEWEE_WEBCHAT_SECRET` | 32+ random chars to sign visitor sessions (`openssl rand -base64 32`) |
|
|
55
|
+
| `DEWEE_AGENTS` | Allowlist, comma separated (`support,sales`) or `*` |
|
|
56
|
+
| `DEWEE_DEFAULT_AGENT` | Optional; defaults to the first allowed agent |
|
|
57
|
+
| `DEWEE_ALLOWED_ORIGINS` | Extra origins for cross-origin embedding (same origin always works) |
|
|
58
|
+
| `TURNSTILE_SITE_KEY` / `TURNSTILE_SECRET_KEY` | Optional Cloudflare Turnstile check for new visitors |
|
|
59
|
+
|
|
60
|
+
Create a scoped key with the Dewee CLI: `dewee api-keys create --name "website chat" --scopes operator.read,operator.write`.
|
|
61
|
+
|
|
62
|
+
## 2. Add the widget
|
|
63
|
+
|
|
64
|
+
**Script tag** (no build step):
|
|
65
|
+
|
|
66
|
+
```html
|
|
67
|
+
<script
|
|
68
|
+
src="https://webchat-cdn.dewee.sh/dewee-webchat@0.1.1/dewee-webchat.js"
|
|
69
|
+
data-endpoint="/api/dewee"
|
|
70
|
+
data-title="Support"
|
|
71
|
+
data-suggestions="What do you do?|Pricing?"
|
|
72
|
+
defer
|
|
73
|
+
></script>
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
**React / Next.js**
|
|
77
|
+
|
|
78
|
+
```tsx
|
|
79
|
+
"use client";
|
|
80
|
+
import { DeweeChat } from "dewee-webchat/react";
|
|
81
|
+
|
|
82
|
+
<DeweeChat endpoint="/api/dewee" title="Support" suggestions={["Pricing?"]} showReasoning={false} onReply={(e) => console.log(e.detail)} />;
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
**Vue**
|
|
86
|
+
|
|
87
|
+
```vue
|
|
88
|
+
<script setup>
|
|
89
|
+
import { DeweeChat } from "dewee-webchat/vue";
|
|
90
|
+
</script>
|
|
91
|
+
<template><DeweeChat endpoint="/api/dewee" :show-tool-calls="false" @reply="onReply" /></template>
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
**Astro**
|
|
95
|
+
|
|
96
|
+
```astro
|
|
97
|
+
---
|
|
98
|
+
import DeweeChat from "dewee-webchat/astro";
|
|
99
|
+
---
|
|
100
|
+
<DeweeChat endpoint="/api/dewee" title="Support" />
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
**Anything else**: `import { mount } from "dewee-webchat"; mount({ endpoint: "/api/dewee" })`, or write
|
|
104
|
+
`<dewee-chat endpoint="/api/dewee"></dewee-chat>` after importing `dewee-webchat`.
|
|
105
|
+
|
|
106
|
+
## Options
|
|
107
|
+
|
|
108
|
+
Attributes use kebab-case (`show-reasoning="false"`), `data-*` on the script tag, camelCase as props.
|
|
109
|
+
|
|
110
|
+
| Option | Default | |
|
|
111
|
+
|---|---|---|
|
|
112
|
+
| `endpoint` | `/api/dewee` | Backend base URL |
|
|
113
|
+
| `agent` | backend default | Agent key |
|
|
114
|
+
| `title`, `subtitle`, `greeting`, `intro`, `placeholder` | | Texts |
|
|
115
|
+
| `suggestions` | | Quick replies (`a|b` or JSON array as attribute) |
|
|
116
|
+
| `avatar`, `launcherAvatar` | | Image URL; also use it on the launcher |
|
|
117
|
+
| `mode` | `floating` | `floating` (bubble + panel) or `inline` (fills its container) |
|
|
118
|
+
| `position` | `bottom-right` | or `bottom-left` |
|
|
119
|
+
| `theme` | `light` | `light`, `dark`, `auto` |
|
|
120
|
+
| `accentColor` | `#5446e8` | Any CSS color |
|
|
121
|
+
| `locale` | page language | `en`, `vi` |
|
|
122
|
+
| `showReasoning` | `true` | Stream the model's thinking |
|
|
123
|
+
| `showToolCalls` | `true` | Show tool calls with arguments and results |
|
|
124
|
+
| `allowAgentSwitch` | `true` | Agent picker when the backend allows several |
|
|
125
|
+
| `persist` | `true` | Keep the conversation across page loads |
|
|
126
|
+
| `open`, `hideBranding`, `width`, `height`, `zIndex` | | |
|
|
127
|
+
|
|
128
|
+
Methods: `open()`, `close()`, `toggle()`, `send(text)`, `stop()`, `newConversation()`, `configure(partial)`.
|
|
129
|
+
Events: `dewee:ready`, `dewee:open`, `dewee:close`, `dewee:send`, `dewee:reply`, `dewee:error`.
|
|
130
|
+
CSS variables: `--dw-accent`, `--dw-font`, `--dw-radius`, `--dw-width`, `--dw-height`, `--dw-z`.
|
|
131
|
+
|
|
132
|
+
## Security model
|
|
133
|
+
|
|
134
|
+
- The gateway token never leaves your server. Browsers get an HMAC-signed visitor id.
|
|
135
|
+
- Each visitor gets its own gateway user (`webchat-<id>`) and session keys, so history is private to them.
|
|
136
|
+
- Only allowlisted agents are reachable; origin allowlist, rate limits (20 messages/min per visitor, 10
|
|
137
|
+
new sessions/10 min per IP by default — pass `rateLimit` for a shared store), 4000-char messages,
|
|
138
|
+
optional Turnstile.
|
|
139
|
+
- "Bring your own gateway" (`allowClientCredentials`) is off by default; when on, internal hosts are refused.
|
|
140
|
+
|
|
141
|
+
The wire format is documented in [docs/http-contract.md](https://github.com/nextlevelbuilder/dewee-webchat/blob/main/docs/http-contract.md).
|
|
142
|
+
|
|
143
|
+
## License
|
|
144
|
+
|
|
145
|
+
MIT © NextLevelBuilder
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
---
|
|
2
|
+
// Astro component: <DeweeChat endpoint="/api/dewee" title="Support" showReasoning={false} />
|
|
3
|
+
import type { DeweeChatConfig } from "dewee-webchat";
|
|
4
|
+
|
|
5
|
+
type Props = Partial<DeweeChatConfig> & { class?: string };
|
|
6
|
+
const { class: className, ...config } = Astro.props;
|
|
7
|
+
const attrs: Record<string, string> = {};
|
|
8
|
+
for (const [key, value] of Object.entries(config)) {
|
|
9
|
+
if (value === undefined || value === null) continue;
|
|
10
|
+
const name = key.replace(/[A-Z]/g, (c) => "-" + c.toLowerCase());
|
|
11
|
+
attrs[name] = Array.isArray(value) ? JSON.stringify(value) : String(value);
|
|
12
|
+
}
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
<dewee-chat class={className} {...attrs}></dewee-chat>
|
|
16
|
+
|
|
17
|
+
<script>
|
|
18
|
+
// Explicit call: bundlers may tree-shake a bare side-effect import.
|
|
19
|
+
import { defineDeweeChat } from "dewee-webchat";
|
|
20
|
+
defineDeweeChat();
|
|
21
|
+
</script>
|