botschat 0.1.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/LICENSE +201 -0
- package/README.md +213 -0
- package/migrations/0001_initial.sql +88 -0
- package/migrations/0002_rename_projects_to_channels.sql +53 -0
- package/migrations/0003_messages.sql +14 -0
- package/migrations/0004_jobs.sql +15 -0
- package/migrations/0005_deleted_cron_jobs.sql +6 -0
- package/migrations/0006_tasks_add_model.sql +2 -0
- package/migrations/0007_sessions.sql +25 -0
- package/migrations/0008_remove_openclaw_fields.sql +8 -0
- package/package.json +53 -0
- package/packages/api/package.json +17 -0
- package/packages/api/src/do/connection-do.ts +929 -0
- package/packages/api/src/env.ts +8 -0
- package/packages/api/src/index.ts +297 -0
- package/packages/api/src/routes/agents.ts +68 -0
- package/packages/api/src/routes/auth.ts +105 -0
- package/packages/api/src/routes/channels.ts +185 -0
- package/packages/api/src/routes/jobs.ts +65 -0
- package/packages/api/src/routes/models.ts +22 -0
- package/packages/api/src/routes/pairing.ts +76 -0
- package/packages/api/src/routes/projects.ts +177 -0
- package/packages/api/src/routes/sessions.ts +171 -0
- package/packages/api/src/routes/tasks.ts +375 -0
- package/packages/api/src/routes/upload.ts +52 -0
- package/packages/api/src/utils/auth.ts +101 -0
- package/packages/api/src/utils/id.ts +19 -0
- package/packages/api/tsconfig.json +18 -0
- package/packages/plugin/dist/index.d.ts +19 -0
- package/packages/plugin/dist/index.d.ts.map +1 -0
- package/packages/plugin/dist/index.js +17 -0
- package/packages/plugin/dist/index.js.map +1 -0
- package/packages/plugin/dist/src/accounts.d.ts +12 -0
- package/packages/plugin/dist/src/accounts.d.ts.map +1 -0
- package/packages/plugin/dist/src/accounts.js +103 -0
- package/packages/plugin/dist/src/accounts.js.map +1 -0
- package/packages/plugin/dist/src/channel.d.ts +206 -0
- package/packages/plugin/dist/src/channel.d.ts.map +1 -0
- package/packages/plugin/dist/src/channel.js +1248 -0
- package/packages/plugin/dist/src/channel.js.map +1 -0
- package/packages/plugin/dist/src/runtime.d.ts +3 -0
- package/packages/plugin/dist/src/runtime.d.ts.map +1 -0
- package/packages/plugin/dist/src/runtime.js +18 -0
- package/packages/plugin/dist/src/runtime.js.map +1 -0
- package/packages/plugin/dist/src/types.d.ts +179 -0
- package/packages/plugin/dist/src/types.d.ts.map +1 -0
- package/packages/plugin/dist/src/types.js +6 -0
- package/packages/plugin/dist/src/types.js.map +1 -0
- package/packages/plugin/dist/src/ws-client.d.ts +51 -0
- package/packages/plugin/dist/src/ws-client.d.ts.map +1 -0
- package/packages/plugin/dist/src/ws-client.js +170 -0
- package/packages/plugin/dist/src/ws-client.js.map +1 -0
- package/packages/plugin/openclaw.plugin.json +11 -0
- package/packages/plugin/package.json +39 -0
- package/packages/plugin/tsconfig.json +20 -0
- package/packages/web/dist/assets/index-C-wI8eHy.css +1 -0
- package/packages/web/dist/assets/index-CbPEKHLG.js +93 -0
- package/packages/web/dist/index.html +17 -0
- package/packages/web/index.html +16 -0
- package/packages/web/package.json +29 -0
- package/packages/web/postcss.config.js +6 -0
- package/packages/web/src/App.tsx +827 -0
- package/packages/web/src/api.ts +242 -0
- package/packages/web/src/components/ChatWindow.tsx +864 -0
- package/packages/web/src/components/CronDetail.tsx +943 -0
- package/packages/web/src/components/CronSidebar.tsx +123 -0
- package/packages/web/src/components/DebugLogPanel.tsx +258 -0
- package/packages/web/src/components/IconRail.tsx +163 -0
- package/packages/web/src/components/JobList.tsx +120 -0
- package/packages/web/src/components/LoginPage.tsx +178 -0
- package/packages/web/src/components/MessageContent.tsx +1082 -0
- package/packages/web/src/components/ModelSelect.tsx +87 -0
- package/packages/web/src/components/ScheduleEditor.tsx +403 -0
- package/packages/web/src/components/SessionTabs.tsx +246 -0
- package/packages/web/src/components/Sidebar.tsx +331 -0
- package/packages/web/src/components/TaskBar.tsx +413 -0
- package/packages/web/src/components/ThreadPanel.tsx +212 -0
- package/packages/web/src/debug-log.ts +58 -0
- package/packages/web/src/index.css +170 -0
- package/packages/web/src/main.tsx +10 -0
- package/packages/web/src/store.ts +492 -0
- package/packages/web/src/ws.ts +99 -0
- package/packages/web/tailwind.config.js +65 -0
- package/packages/web/tsconfig.json +18 -0
- package/packages/web/vite.config.ts +20 -0
- package/scripts/dev.sh +122 -0
- package/tsconfig.json +18 -0
- package/wrangler.toml +40 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
# BotsChat
|
|
2
|
+
|
|
3
|
+
A self-hosted chat interface for [OpenClaw](https://github.com/openclaw/openclaw) AI agents.
|
|
4
|
+
|
|
5
|
+
BotsChat gives you a modern, Slack-like web UI to interact with your OpenClaw agents — organize conversations into **Channels**, schedule **Background Tasks**, and monitor **Job** executions. Everything runs on your own infrastructure; your API keys and data never leave your machine.
|
|
6
|
+
|
|
7
|
+
## Architecture
|
|
8
|
+
|
|
9
|
+

|
|
10
|
+
|
|
11
|
+
OpenClaw runs your agents locally (with your API keys, data, and configs). The BotsChat plugin establishes an **outbound WebSocket** to the BotsChat server — no port forwarding, no tunnels. Your API keys and data never leave your machine; only chat messages travel through the relay.
|
|
12
|
+
|
|
13
|
+
You can run BotsChat locally on the same machine, or deploy it to Cloudflare for remote access (e.g. from your phone).
|
|
14
|
+
|
|
15
|
+
## Concepts
|
|
16
|
+
|
|
17
|
+
BotsChat introduces a few UI-level concepts that map to OpenClaw primitives:
|
|
18
|
+
|
|
19
|
+
| BotsChat | What it is | OpenClaw mapping |
|
|
20
|
+
|-------------------|---------------------------------------------------------|--------------------------|
|
|
21
|
+
| **Channel** | A workspace for one agent (e.g. "Research Bot") | Agent (`agentId`) |
|
|
22
|
+
| **Task** | A unit of work under a Channel | CronJob or Session |
|
|
23
|
+
| **Job** | One execution of a Background Task | CronRunLogEntry |
|
|
24
|
+
| **Session** | A conversation thread within a Task | Session |
|
|
25
|
+
| **Thread** | A branched sub-conversation from any message | Thread Session |
|
|
26
|
+
|
|
27
|
+
**Task types:**
|
|
28
|
+
|
|
29
|
+
- **Background Task** — runs on a cron schedule (e.g. "post a tweet every 6 hours"). Each run creates a Job with its own conversation session.
|
|
30
|
+
- **Ad Hoc Chat** — a regular conversation you start whenever you want.
|
|
31
|
+
|
|
32
|
+
## Getting Started
|
|
33
|
+
|
|
34
|
+
### Prerequisites
|
|
35
|
+
|
|
36
|
+
- [Node.js](https://nodejs.org/) 22+
|
|
37
|
+
- [Wrangler CLI](https://developers.cloudflare.com/workers/wrangler/install-and-update/)
|
|
38
|
+
- An [OpenClaw](https://github.com/openclaw/openclaw) instance
|
|
39
|
+
|
|
40
|
+
### Step 1: Clone and Install
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
git clone https://github.com/botschat-app/botsChat.git
|
|
44
|
+
cd botsChat
|
|
45
|
+
npm install
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Step 2: Deploy BotsChat Server
|
|
49
|
+
|
|
50
|
+
Choose one of the two options below:
|
|
51
|
+
|
|
52
|
+
#### Option A: Run Locally
|
|
53
|
+
|
|
54
|
+
Wrangler uses [Miniflare](https://miniflare.dev) under the hood, so D1, R2, and Durable Objects all run locally — **no Cloudflare account needed**.
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
# One-command startup: build web → migrate D1 → start server on 0.0.0.0:8787
|
|
58
|
+
./scripts/dev.sh
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Or step by step:
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
npm run build -w packages/web # Build the React frontend
|
|
65
|
+
npm run db:migrate # Apply D1 migrations (local)
|
|
66
|
+
npx wrangler dev --config wrangler.toml --ip 0.0.0.0 # Start on port 8787
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Open `http://localhost:8787` in your browser.
|
|
70
|
+
|
|
71
|
+
Other dev commands:
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
./scripts/dev.sh reset # Nuke local DB → re-migrate → start
|
|
75
|
+
./scripts/dev.sh migrate # Only run D1 migrations
|
|
76
|
+
./scripts/dev.sh build # Only build web frontend
|
|
77
|
+
./scripts/dev.sh sync # Sync plugin to remote OpenClaw host + restart gateway
|
|
78
|
+
./scripts/dev.sh logs # Tail remote gateway logs
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
#### Option B: Deploy to Cloudflare
|
|
82
|
+
|
|
83
|
+
For remote access (e.g. chatting with your agents from your phone), deploy to Cloudflare Workers. The free tier is more than enough for personal use.
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
# Create Cloudflare resources
|
|
87
|
+
wrangler d1 create botschat-db # Copy the database_id into wrangler.toml
|
|
88
|
+
wrangler r2 bucket create botschat-media
|
|
89
|
+
|
|
90
|
+
# Build & deploy
|
|
91
|
+
npm run build -w packages/web # Build the React frontend
|
|
92
|
+
npm run deploy # Deploy API + web + Durable Objects
|
|
93
|
+
npm run db:migrate:remote # Apply migrations to remote D1
|
|
94
|
+
wrangler secret put JWT_SECRET # Set a production JWT secret
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
| Service | Purpose | Free Tier |
|
|
98
|
+
|------------------|----------------------------------------|----------------------------------|
|
|
99
|
+
| Workers | API server (Hono) | 100K req/day |
|
|
100
|
+
| Durable Objects | WebSocket relay (ConnectionDO) | 1M req/mo, hibernation = free |
|
|
101
|
+
| D1 | Database (users, channels, tasks) | 5M reads/day, 100K writes/day |
|
|
102
|
+
| R2 | Media storage | 10GB, no egress fees |
|
|
103
|
+
|
|
104
|
+
### Step 3: Install the OpenClaw Plugin
|
|
105
|
+
|
|
106
|
+
After the BotsChat server is running, connect your OpenClaw instance to it.
|
|
107
|
+
|
|
108
|
+
**1. Install the plugin**
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
openclaw plugins install @botschat/openclaw-plugin
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
**2. Create a pairing token**
|
|
115
|
+
|
|
116
|
+
Open the BotsChat web UI, register an account, and generate a **pairing token** from the dashboard.
|
|
117
|
+
|
|
118
|
+
**3. Configure the connection**
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
# For local deployment, use http://localhost:8787 or your LAN IP
|
|
122
|
+
# For Cloudflare deployment, use your Workers URL
|
|
123
|
+
openclaw config set channels.botschat.cloudUrl <BOTSCHAT_URL>
|
|
124
|
+
openclaw config set channels.botschat.pairingToken <YOUR_PAIRING_TOKEN>
|
|
125
|
+
openclaw config set channels.botschat.enabled true
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
This writes the following to your `~/.openclaw/openclaw.json`:
|
|
129
|
+
|
|
130
|
+
```json
|
|
131
|
+
{
|
|
132
|
+
"channels": {
|
|
133
|
+
"botschat": {
|
|
134
|
+
"enabled": true,
|
|
135
|
+
"cloudUrl": "http://localhost:8787",
|
|
136
|
+
"pairingToken": "bc_pat_xxxxxxxxxxxxxxxx"
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
**4. Restart the gateway and verify**
|
|
143
|
+
|
|
144
|
+
```bash
|
|
145
|
+
openclaw gateway restart
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Check the gateway logs — you should see:
|
|
149
|
+
|
|
150
|
+
```
|
|
151
|
+
Authenticated with BotsChat cloud
|
|
152
|
+
Task scan complete
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
Open the BotsChat web UI in your browser, sign in, and start chatting with your agents.
|
|
156
|
+
|
|
157
|
+
### How It Works
|
|
158
|
+
|
|
159
|
+
1. When your OpenClaw gateway starts, the BotsChat plugin establishes an **outbound WebSocket** to `ws://<your-botschat-host>/api/gateway/<your-user-id>`.
|
|
160
|
+
2. This WebSocket stays connected (with automatic reconnection if it drops).
|
|
161
|
+
3. When you type a message in the web UI, it travels: **Browser → ConnectionDO → WebSocket → OpenClaw → Agent → response back through the same path**.
|
|
162
|
+
4. Your API keys, agent configs, and data never leave your machine — only chat messages travel through the relay.
|
|
163
|
+
|
|
164
|
+
## Plugin Reference
|
|
165
|
+
|
|
166
|
+
### Configuration
|
|
167
|
+
|
|
168
|
+
All config lives under `channels.botschat` in your `openclaw.json`:
|
|
169
|
+
|
|
170
|
+
| Key | Type | Required | Description |
|
|
171
|
+
|-----------------|---------|----------|------------------------------------------------------|
|
|
172
|
+
| `enabled` | boolean | no | Enable/disable the channel (default: true) |
|
|
173
|
+
| `cloudUrl` | string | yes | BotsChat server URL (e.g. `http://localhost:8787`) |
|
|
174
|
+
| `pairingToken` | string | yes | Your pairing token from the BotsChat dashboard |
|
|
175
|
+
| `name` | string | no | Display name for this connection |
|
|
176
|
+
|
|
177
|
+
### Message Protocol
|
|
178
|
+
|
|
179
|
+
The plugin uses a JSON-based WebSocket protocol:
|
|
180
|
+
|
|
181
|
+
| Direction | Message Types |
|
|
182
|
+
|--------------------|------------------------------------------------------------------|
|
|
183
|
+
| Cloud → Plugin | `user.message`, `user.action`, `user.command`, `task.schedule`, `task.delete`, `task.run`, `task.scan.request` |
|
|
184
|
+
| Plugin → Cloud | `agent.text`, `agent.media`, `agent.a2ui`, `agent.stream.*`, `job.update`, `job.output`, `task.scan.result`, `model.changed` |
|
|
185
|
+
|
|
186
|
+
### Uninstall
|
|
187
|
+
|
|
188
|
+
```bash
|
|
189
|
+
openclaw plugins disable botschat
|
|
190
|
+
# or remove entirely:
|
|
191
|
+
openclaw plugins remove botschat
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
---
|
|
195
|
+
|
|
196
|
+
## Development
|
|
197
|
+
|
|
198
|
+
### Build the plugin
|
|
199
|
+
|
|
200
|
+
```bash
|
|
201
|
+
npm run build:plugin
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
### Type-check everything
|
|
205
|
+
|
|
206
|
+
```bash
|
|
207
|
+
npm run typecheck
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
## License
|
|
212
|
+
|
|
213
|
+
Apache-2.0
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
-- BotsChat D1 Schema
|
|
2
|
+
-- Initial migration: users, projects, tasks, threads, skill usage, voice keywords
|
|
3
|
+
|
|
4
|
+
CREATE TABLE IF NOT EXISTS users (
|
|
5
|
+
id TEXT PRIMARY KEY,
|
|
6
|
+
email TEXT NOT NULL UNIQUE,
|
|
7
|
+
password_hash TEXT NOT NULL,
|
|
8
|
+
display_name TEXT,
|
|
9
|
+
settings_json TEXT DEFAULT '{}', -- voice keywords, STT API key, etc.
|
|
10
|
+
created_at INTEGER NOT NULL DEFAULT (unixepoch()),
|
|
11
|
+
updated_at INTEGER NOT NULL DEFAULT (unixepoch())
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
CREATE TABLE IF NOT EXISTS pairing_tokens (
|
|
15
|
+
id TEXT PRIMARY KEY,
|
|
16
|
+
user_id TEXT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
|
17
|
+
token TEXT NOT NULL UNIQUE, -- bc_pat_xxxxxxxx
|
|
18
|
+
label TEXT, -- user-assigned label
|
|
19
|
+
last_connected_at INTEGER,
|
|
20
|
+
created_at INTEGER NOT NULL DEFAULT (unixepoch())
|
|
21
|
+
);
|
|
22
|
+
CREATE INDEX IF NOT EXISTS idx_pairing_tokens_user ON pairing_tokens(user_id);
|
|
23
|
+
CREATE INDEX IF NOT EXISTS idx_pairing_tokens_token ON pairing_tokens(token);
|
|
24
|
+
|
|
25
|
+
CREATE TABLE IF NOT EXISTS projects (
|
|
26
|
+
id TEXT PRIMARY KEY,
|
|
27
|
+
user_id TEXT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
|
28
|
+
name TEXT NOT NULL,
|
|
29
|
+
description TEXT DEFAULT '',
|
|
30
|
+
openclaw_agent_id TEXT NOT NULL, -- maps to OpenClaw agent ID
|
|
31
|
+
system_prompt TEXT DEFAULT '',
|
|
32
|
+
created_at INTEGER NOT NULL DEFAULT (unixepoch()),
|
|
33
|
+
updated_at INTEGER NOT NULL DEFAULT (unixepoch())
|
|
34
|
+
);
|
|
35
|
+
CREATE INDEX IF NOT EXISTS idx_projects_user ON projects(user_id);
|
|
36
|
+
|
|
37
|
+
CREATE TABLE IF NOT EXISTS tasks (
|
|
38
|
+
id TEXT PRIMARY KEY,
|
|
39
|
+
project_id TEXT NOT NULL REFERENCES projects(id) ON DELETE CASCADE,
|
|
40
|
+
name TEXT NOT NULL,
|
|
41
|
+
kind TEXT NOT NULL CHECK (kind IN ('background', 'adhoc')),
|
|
42
|
+
openclaw_cron_job_id TEXT, -- for background tasks
|
|
43
|
+
schedule TEXT, -- cron expression or preset
|
|
44
|
+
instructions TEXT, -- agent instructions per run
|
|
45
|
+
session_key TEXT, -- for adhoc: the OpenClaw session key
|
|
46
|
+
enabled INTEGER NOT NULL DEFAULT 1,
|
|
47
|
+
created_at INTEGER NOT NULL DEFAULT (unixepoch()),
|
|
48
|
+
updated_at INTEGER NOT NULL DEFAULT (unixepoch())
|
|
49
|
+
);
|
|
50
|
+
CREATE INDEX IF NOT EXISTS idx_tasks_project ON tasks(project_id);
|
|
51
|
+
|
|
52
|
+
CREATE TABLE IF NOT EXISTS threads (
|
|
53
|
+
id TEXT PRIMARY KEY,
|
|
54
|
+
task_id TEXT NOT NULL REFERENCES tasks(id) ON DELETE CASCADE,
|
|
55
|
+
parent_message_id TEXT NOT NULL,
|
|
56
|
+
thread_session_key TEXT NOT NULL,
|
|
57
|
+
created_at INTEGER NOT NULL DEFAULT (unixepoch())
|
|
58
|
+
);
|
|
59
|
+
CREATE INDEX IF NOT EXISTS idx_threads_task ON threads(task_id);
|
|
60
|
+
|
|
61
|
+
CREATE TABLE IF NOT EXISTS skill_usage (
|
|
62
|
+
id TEXT PRIMARY KEY,
|
|
63
|
+
user_id TEXT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
|
64
|
+
project_id TEXT NOT NULL REFERENCES projects(id) ON DELETE CASCADE,
|
|
65
|
+
skill_name TEXT NOT NULL,
|
|
66
|
+
usage_count INTEGER NOT NULL DEFAULT 0,
|
|
67
|
+
last_used_at INTEGER NOT NULL DEFAULT (unixepoch()),
|
|
68
|
+
UNIQUE(user_id, project_id, skill_name)
|
|
69
|
+
);
|
|
70
|
+
CREATE INDEX IF NOT EXISTS idx_skill_usage_user_project ON skill_usage(user_id, project_id);
|
|
71
|
+
|
|
72
|
+
CREATE TABLE IF NOT EXISTS voice_keywords (
|
|
73
|
+
id TEXT PRIMARY KEY,
|
|
74
|
+
user_id TEXT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
|
75
|
+
keyword TEXT NOT NULL,
|
|
76
|
+
source TEXT NOT NULL CHECK (source IN ('manual', 'auto-learned')),
|
|
77
|
+
created_at INTEGER NOT NULL DEFAULT (unixepoch())
|
|
78
|
+
);
|
|
79
|
+
CREATE INDEX IF NOT EXISTS idx_voice_keywords_user ON voice_keywords(user_id);
|
|
80
|
+
|
|
81
|
+
-- FTS5 virtual table for chat history search (hashtag cross-reference)
|
|
82
|
+
-- Messages are synced from OpenClaw session transcripts on demand.
|
|
83
|
+
CREATE VIRTUAL TABLE IF NOT EXISTS chat_search USING fts5(
|
|
84
|
+
session_key,
|
|
85
|
+
sender,
|
|
86
|
+
content,
|
|
87
|
+
timestamp UNINDEXED
|
|
88
|
+
);
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
-- Rename projects → channels and project_id → channel_id
|
|
2
|
+
-- Full recreation since SQLite doesn't support ALTER COLUMN RENAME
|
|
3
|
+
|
|
4
|
+
-- Create channels table matching projects schema
|
|
5
|
+
CREATE TABLE IF NOT EXISTS channels (
|
|
6
|
+
id TEXT PRIMARY KEY,
|
|
7
|
+
user_id TEXT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
|
8
|
+
name TEXT NOT NULL,
|
|
9
|
+
description TEXT DEFAULT '',
|
|
10
|
+
openclaw_agent_id TEXT NOT NULL,
|
|
11
|
+
system_prompt TEXT DEFAULT '',
|
|
12
|
+
created_at INTEGER NOT NULL DEFAULT (unixepoch()),
|
|
13
|
+
updated_at INTEGER NOT NULL DEFAULT (unixepoch())
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
-- Drop old projects table if it still exists
|
|
17
|
+
DROP TABLE IF EXISTS projects;
|
|
18
|
+
|
|
19
|
+
-- Recreate tasks table with channel_id instead of project_id
|
|
20
|
+
DROP TABLE IF EXISTS tasks;
|
|
21
|
+
CREATE TABLE IF NOT EXISTS tasks (
|
|
22
|
+
id TEXT PRIMARY KEY,
|
|
23
|
+
channel_id TEXT NOT NULL REFERENCES channels(id) ON DELETE CASCADE,
|
|
24
|
+
name TEXT NOT NULL,
|
|
25
|
+
kind TEXT NOT NULL CHECK (kind IN ('background', 'adhoc')),
|
|
26
|
+
openclaw_cron_job_id TEXT,
|
|
27
|
+
schedule TEXT,
|
|
28
|
+
instructions TEXT,
|
|
29
|
+
session_key TEXT,
|
|
30
|
+
enabled INTEGER NOT NULL DEFAULT 1,
|
|
31
|
+
created_at INTEGER NOT NULL DEFAULT (unixepoch()),
|
|
32
|
+
updated_at INTEGER NOT NULL DEFAULT (unixepoch())
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
-- Recreate threads table with corrected references
|
|
36
|
+
DROP TABLE IF EXISTS threads;
|
|
37
|
+
CREATE TABLE IF NOT EXISTS threads (
|
|
38
|
+
id TEXT PRIMARY KEY,
|
|
39
|
+
task_id TEXT NOT NULL REFERENCES tasks(id) ON DELETE CASCADE,
|
|
40
|
+
parent_message_id TEXT NOT NULL,
|
|
41
|
+
thread_session_key TEXT NOT NULL,
|
|
42
|
+
created_at INTEGER NOT NULL DEFAULT (unixepoch())
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
-- Ensure indexes exist
|
|
46
|
+
CREATE INDEX IF NOT EXISTS idx_channels_user ON channels(user_id);
|
|
47
|
+
CREATE INDEX IF NOT EXISTS idx_tasks_channel ON tasks(channel_id);
|
|
48
|
+
CREATE INDEX IF NOT EXISTS idx_threads_task ON threads(task_id);
|
|
49
|
+
|
|
50
|
+
-- Cleanup old indexes
|
|
51
|
+
DROP INDEX IF EXISTS idx_projects_user;
|
|
52
|
+
DROP INDEX IF EXISTS idx_tasks_project;
|
|
53
|
+
DROP INDEX IF EXISTS idx_skill_usage_user_project;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
-- Messages table — persists chat messages for history
|
|
2
|
+
CREATE TABLE IF NOT EXISTS messages (
|
|
3
|
+
id TEXT PRIMARY KEY,
|
|
4
|
+
user_id TEXT NOT NULL,
|
|
5
|
+
session_key TEXT NOT NULL,
|
|
6
|
+
thread_id TEXT,
|
|
7
|
+
sender TEXT NOT NULL CHECK (sender IN ('user', 'agent')),
|
|
8
|
+
text TEXT NOT NULL DEFAULT '',
|
|
9
|
+
media_url TEXT,
|
|
10
|
+
a2ui TEXT,
|
|
11
|
+
created_at INTEGER NOT NULL DEFAULT (unixepoch())
|
|
12
|
+
);
|
|
13
|
+
CREATE INDEX IF NOT EXISTS idx_messages_session ON messages(session_key, created_at);
|
|
14
|
+
CREATE INDEX IF NOT EXISTS idx_messages_thread ON messages(thread_id, created_at);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
-- Jobs table — caches background task execution history from OpenClaw CronService
|
|
2
|
+
CREATE TABLE IF NOT EXISTS jobs (
|
|
3
|
+
id TEXT PRIMARY KEY,
|
|
4
|
+
task_id TEXT NOT NULL,
|
|
5
|
+
user_id TEXT NOT NULL,
|
|
6
|
+
session_key TEXT NOT NULL,
|
|
7
|
+
status TEXT NOT NULL CHECK (status IN ('running', 'ok', 'error', 'skipped')),
|
|
8
|
+
started_at INTEGER NOT NULL DEFAULT (unixepoch()),
|
|
9
|
+
finished_at INTEGER,
|
|
10
|
+
duration_ms INTEGER,
|
|
11
|
+
summary TEXT DEFAULT '',
|
|
12
|
+
created_at INTEGER NOT NULL DEFAULT (unixepoch())
|
|
13
|
+
);
|
|
14
|
+
CREATE INDEX IF NOT EXISTS idx_jobs_task ON jobs(task_id, started_at DESC);
|
|
15
|
+
CREATE INDEX IF NOT EXISTS idx_jobs_session ON jobs(session_key);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
-- Sessions table — multiple conversation sessions per channel.
|
|
2
|
+
-- Each session has its own session_key so messages are isolated.
|
|
3
|
+
CREATE TABLE IF NOT EXISTS sessions (
|
|
4
|
+
id TEXT PRIMARY KEY,
|
|
5
|
+
channel_id TEXT NOT NULL REFERENCES channels(id) ON DELETE CASCADE,
|
|
6
|
+
user_id TEXT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
|
7
|
+
name TEXT NOT NULL DEFAULT 'Default',
|
|
8
|
+
session_key TEXT NOT NULL UNIQUE,
|
|
9
|
+
created_at INTEGER NOT NULL DEFAULT (unixepoch()),
|
|
10
|
+
updated_at INTEGER NOT NULL DEFAULT (unixepoch())
|
|
11
|
+
);
|
|
12
|
+
CREATE INDEX IF NOT EXISTS idx_sessions_channel ON sessions(channel_id, created_at);
|
|
13
|
+
|
|
14
|
+
-- Migrate existing channels: create a "Default" session for each channel
|
|
15
|
+
-- using the adhoc task's session_key for backward compatibility.
|
|
16
|
+
INSERT OR IGNORE INTO sessions (id, channel_id, user_id, name, session_key)
|
|
17
|
+
SELECT
|
|
18
|
+
'ses_' || lower(hex(randomblob(8))),
|
|
19
|
+
ch.id,
|
|
20
|
+
ch.user_id,
|
|
21
|
+
'Default',
|
|
22
|
+
t.session_key
|
|
23
|
+
FROM channels ch
|
|
24
|
+
JOIN tasks t ON t.channel_id = ch.id AND t.kind = 'adhoc' AND t.session_key IS NOT NULL
|
|
25
|
+
GROUP BY ch.id;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
-- Remove OpenClaw-owned fields from the tasks table.
|
|
2
|
+
-- Schedule, instructions, and model belong to OpenClaw (stored in ~/.openclaw/cron/jobs.json)
|
|
3
|
+
-- and should not be duplicated in D1 to avoid sync issues.
|
|
4
|
+
-- These values now come to the frontend via WebSocket task.scan.result messages.
|
|
5
|
+
|
|
6
|
+
ALTER TABLE tasks DROP COLUMN schedule;
|
|
7
|
+
ALTER TABLE tasks DROP COLUMN instructions;
|
|
8
|
+
ALTER TABLE tasks DROP COLUMN model;
|