molta 1.0.0 → 1.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.en.md +119 -0
- package/README.md +27 -16
- package/package.json +5 -4
package/README.en.md
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
<h1 align="center">Molta</h1>
|
|
2
|
+
<h3 align="center">✨ Use MoltBot anywhere 🚀</h3>
|
|
3
|
+
<p align="center"><a href="./README.md">中文</a></p>
|
|
4
|
+
|
|
5
|
+
Molta is a lightweight HTTP gateway that forwards OpenAI-style `v1/chat/completions` requests to a local MoltBot (ClawdBot) gateway over WebSocket and returns compatible responses, so you can use MoltBot in existing clients.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
- OpenAI-style endpoints: `/v1/chat/completions`, `/v1/models`
|
|
9
|
+
- Built-in auth: Bearer token via `TOKEN`
|
|
10
|
+
- Streaming responses (SSE)
|
|
11
|
+
- Session reuse + quick new-session command
|
|
12
|
+
|
|
13
|
+
## Quick Start
|
|
14
|
+
> Requires Node.js 20+ (for local dev or npm install)
|
|
15
|
+
|
|
16
|
+
### Option A: Install from npm
|
|
17
|
+
```bash
|
|
18
|
+
npm i -g molta
|
|
19
|
+
molta
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### Option B: Run with Docker
|
|
23
|
+
```bash
|
|
24
|
+
docker run --rm -p 8090:8090 \
|
|
25
|
+
-e TOKEN="<Your token>" \
|
|
26
|
+
-e CLAWD_TOKEN="<Your Clawd Token>" \
|
|
27
|
+
-e CLAWD_HOST="<Clawd host>" \
|
|
28
|
+
-e CLAWD_PORT=<Clawd port> \
|
|
29
|
+
ghcr.io/ve-ria/molta:latest
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Option C: Local development (Yarn 4.12.2)
|
|
33
|
+
```bash
|
|
34
|
+
yarn install
|
|
35
|
+
yarn dev
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Default listening address: `http://127.0.0.1:8090`.
|
|
39
|
+
|
|
40
|
+
## Environment Variables
|
|
41
|
+
Molta reads `.env` in the current directory and validates it (see `schema.json`).
|
|
42
|
+
|
|
43
|
+
Required:
|
|
44
|
+
- `TOKEN`: HTTP auth token
|
|
45
|
+
- `CLAWD_TOKEN`: Clawd gateway auth token
|
|
46
|
+
|
|
47
|
+
Optional:
|
|
48
|
+
- `HOST`: bind host, default `localhost`
|
|
49
|
+
- `PORT`: bind port, default `8090`
|
|
50
|
+
- `CLAWD_HOST`: Clawd gateway host, default `localhost`
|
|
51
|
+
- Both Molta and Clawd in Docker: use Clawd container name or IP
|
|
52
|
+
- Molta in Docker, Clawd on host: use `host.docker.internal`
|
|
53
|
+
- Both on host: use `localhost`
|
|
54
|
+
- `CLAWD_PORT`: Clawd gateway port, default `18789`
|
|
55
|
+
|
|
56
|
+
Example:
|
|
57
|
+
```bash
|
|
58
|
+
TOKEN="<Your token>"
|
|
59
|
+
HOST="127.0.0.1"
|
|
60
|
+
PORT=8090
|
|
61
|
+
CLAWD_HOST="127.0.0.1"
|
|
62
|
+
CLAWD_PORT=18789
|
|
63
|
+
CLAWD_TOKEN="<Your Clawd Token>"
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## API
|
|
67
|
+
### List models
|
|
68
|
+
`GET /v1/models`
|
|
69
|
+
|
|
70
|
+
Example response (`created` is current time):
|
|
71
|
+
```json
|
|
72
|
+
{
|
|
73
|
+
"object": "list",
|
|
74
|
+
"data": [
|
|
75
|
+
{
|
|
76
|
+
"id": "molta",
|
|
77
|
+
"object": "model",
|
|
78
|
+
"created": "2025-01-01T00:00:00.000Z",
|
|
79
|
+
"owned_by": "molta"
|
|
80
|
+
}
|
|
81
|
+
]
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Chat completions
|
|
86
|
+
`POST /v1/chat/completions`
|
|
87
|
+
|
|
88
|
+
Request body (OpenAI-compatible):
|
|
89
|
+
```json
|
|
90
|
+
{
|
|
91
|
+
"model": "molta",
|
|
92
|
+
"messages": [
|
|
93
|
+
{ "role": "user", "content": "Hello" }
|
|
94
|
+
],
|
|
95
|
+
"stream": false
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Auth:
|
|
100
|
+
```
|
|
101
|
+
Authorization: Bearer <TOKEN>
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Streaming: set `stream=true` to receive SSE.
|
|
105
|
+
|
|
106
|
+
## Sessions
|
|
107
|
+
- Session ID is derived from `user` or `id` (falls back to `http`)
|
|
108
|
+
- Send `/clawd-new` or `clawd-new` to force a new session
|
|
109
|
+
|
|
110
|
+
## Run & Build (dev)
|
|
111
|
+
```bash
|
|
112
|
+
yarn build
|
|
113
|
+
yarn start
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## Project Layout
|
|
117
|
+
- `src/router/chat/completions.ts`: main API logic
|
|
118
|
+
- `src/services/gateway.ts`: Clawd gateway WebSocket client
|
|
119
|
+
- `schema.json`: env validation schema
|
package/README.md
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
<h1 align="center">Molta</h1>
|
|
2
2
|
<h3 align="center">✨ 在任意地方使用 MoltBot 🚀</h3>
|
|
3
|
+
<p align="center"><a href="./README.en.md">English</a></p>
|
|
3
4
|
|
|
4
|
-
Molta 是一个轻量的 HTTP 网关:将类 OpenAI 的 `v1/chat/completions` 请求转发到本地
|
|
5
|
+
Molta 是一个轻量的 HTTP 网关:将类 OpenAI 的 `v1/chat/completions` 请求转发到本地 MoltBot(ClawdBot) 网关(WebSocket),并返回兼容响应,方便你在现有客户端中直接使用 MoltBot(ClawdBot)。
|
|
5
6
|
|
|
6
7
|
## 特性
|
|
7
8
|
- OpenAI 风格接口:`/v1/chat/completions`、`/v1/models`
|
|
@@ -10,8 +11,25 @@ Molta 是一个轻量的 HTTP 网关:将类 OpenAI 的 `v1/chat/completions`
|
|
|
10
11
|
- 会话复用与快速创建新会话指令
|
|
11
12
|
|
|
12
13
|
## 快速开始
|
|
13
|
-
> 需要 Node.js 20
|
|
14
|
+
> 需要 Node.js 20+(本地开发或 npm 安装时)
|
|
14
15
|
|
|
16
|
+
### 方式 A:从 npm 安装
|
|
17
|
+
```bash
|
|
18
|
+
npm i -g molta
|
|
19
|
+
molta
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### 方式 B:Docker 运行
|
|
23
|
+
```bash
|
|
24
|
+
docker run --rm -p 8090:8090 \
|
|
25
|
+
-e TOKEN="<Your token>" \
|
|
26
|
+
-e CLAWD_TOKEN="<Your Clawd Token>" \
|
|
27
|
+
-e CLAWD_HOST="<Clawd host>" \
|
|
28
|
+
-e CLAWD_PORT=<Clawd port> \
|
|
29
|
+
ghcr.io/ve-ria/molta:latest
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### 方式 C:本地开发(Yarn 4.12.0)
|
|
15
33
|
```bash
|
|
16
34
|
yarn install
|
|
17
35
|
yarn dev
|
|
@@ -20,7 +38,7 @@ yarn dev
|
|
|
20
38
|
启动后默认监听 `http://127.0.0.1:8090`。
|
|
21
39
|
|
|
22
40
|
## 环境变量
|
|
23
|
-
|
|
41
|
+
项目会读取当前目录的 `.env` 并校验(见 `schema.json`)。
|
|
24
42
|
|
|
25
43
|
必填:
|
|
26
44
|
- `TOKEN`:HTTP 接口鉴权 Token
|
|
@@ -29,12 +47,11 @@ yarn dev
|
|
|
29
47
|
可选:
|
|
30
48
|
- `HOST`:监听地址,默认 `localhost`
|
|
31
49
|
- `PORT`:监听端口,默认 `8090`
|
|
32
|
-
- `CLAWD_HOST`:Clawd 网关地址,默认 `localhost
|
|
33
|
-
-
|
|
34
|
-
-
|
|
35
|
-
-
|
|
50
|
+
- `CLAWD_HOST`:Clawd 网关地址,默认 `localhost`
|
|
51
|
+
- Molta 与 Clawd 都在 Docker:填 Clawd 容器名或容器 IP
|
|
52
|
+
- Molta 在 Docker、Clawd 在本机:填 `host.docker.internal`
|
|
53
|
+
- Molta 与 Clawd 都在本机:填 `localhost`
|
|
36
54
|
- `CLAWD_PORT`:Clawd 网关端口,默认 `18789`
|
|
37
|
-
- `CLAWD_AGENT_ID`:预留字段(当前实现中未使用)
|
|
38
55
|
|
|
39
56
|
示例:
|
|
40
57
|
```bash
|
|
@@ -71,7 +88,7 @@ CLAWD_TOKEN="<Your Clawd Token>"
|
|
|
71
88
|
请求体(兼容 OpenAI):
|
|
72
89
|
```json
|
|
73
90
|
{
|
|
74
|
-
"model": "
|
|
91
|
+
"model": "molta",
|
|
75
92
|
"messages": [
|
|
76
93
|
{ "role": "user", "content": "你好" }
|
|
77
94
|
],
|
|
@@ -90,18 +107,12 @@ Authorization: Bearer <TOKEN>
|
|
|
90
107
|
- 会话 ID 基于 `user` 或 `id` 字段生成;未提供则使用 `http`。
|
|
91
108
|
- 发送 `/clawd-new` 或 `clawd-new` 可强制创建新会话。
|
|
92
109
|
|
|
93
|
-
##
|
|
110
|
+
## 运行与构建(开发者)
|
|
94
111
|
```bash
|
|
95
112
|
yarn build
|
|
96
113
|
yarn start
|
|
97
114
|
```
|
|
98
115
|
|
|
99
|
-
安装并启动:
|
|
100
|
-
```bash
|
|
101
|
-
npm i -g molta
|
|
102
|
-
molta
|
|
103
|
-
```
|
|
104
|
-
|
|
105
116
|
## 目录结构
|
|
106
117
|
- `src/router/chat/completions.ts`:主接口逻辑
|
|
107
118
|
- `src/services/gateway.ts`:Clawd 网关 WebSocket 客户端
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "molta",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Use MoltBot anywhere",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"packageManager": "yarn@4.12.0",
|
|
@@ -15,9 +15,7 @@
|
|
|
15
15
|
"prepublishOnly": "yarn build && node scripts/add-shebang.cjs",
|
|
16
16
|
"start": "node dist/index.js"
|
|
17
17
|
},
|
|
18
|
-
"bin":
|
|
19
|
-
"molta": "dist/index.js"
|
|
20
|
-
},
|
|
18
|
+
"bin": "dist/index.js",
|
|
21
19
|
"files": [
|
|
22
20
|
"dist",
|
|
23
21
|
"schema.json"
|
|
@@ -25,10 +23,13 @@
|
|
|
25
23
|
"dependencies": {
|
|
26
24
|
"@elysiajs/node": "^1.4.3",
|
|
27
25
|
"@elysiajs/openapi": "^1.4.14",
|
|
26
|
+
"@sinclair/typebox": "^0.34.48",
|
|
28
27
|
"ajv": "^8.17.1",
|
|
29
28
|
"dotenv": "^17.2.3",
|
|
30
29
|
"elysia": "^1.4.22",
|
|
30
|
+
"file-type": "^21.3.0",
|
|
31
31
|
"js-yaml": "^4.1.1",
|
|
32
|
+
"openapi-types": "^12.1.3",
|
|
32
33
|
"supports-color": "^10.2.2",
|
|
33
34
|
"typescript": "^5.9.3"
|
|
34
35
|
},
|