@debbl/relay 0.0.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/README.md +101 -0
- package/README.zh.md +101 -0
- package/bin/relay.mjs +3 -0
- package/dist/index.d.mts +1 -0
- package/dist/index.mjs +1360 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +79 -0
package/README.md
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# relay
|
|
2
|
+
|
|
3
|
+
[English](./README.md) | [简体中文](./README.zh.md)
|
|
4
|
+
|
|
5
|
+
A Feishu bot that forwards chat messages to Codex and returns results in chat.
|
|
6
|
+
|
|
7
|
+
## Prerequisites
|
|
8
|
+
|
|
9
|
+
1. Node.js 20+ and `pnpm`.
|
|
10
|
+
2. `codex` CLI installed and logged in (`codex login`).
|
|
11
|
+
3. Feishu app with bot capability enabled [create-bot](https://open.feishu.cn/document/develop-an-echo-bot/introduction).
|
|
12
|
+
4. Feishu event subscription enabled for `im.message.receive_v1`.
|
|
13
|
+
5. Feishu bot permissions:
|
|
14
|
+
- P2P messages to bot.
|
|
15
|
+
- Group messages `@` bot (or all group messages if you prefer).
|
|
16
|
+
|
|
17
|
+
## Configuration
|
|
18
|
+
|
|
19
|
+
Relay reads configuration only from `~/.relay/config.json`.
|
|
20
|
+
|
|
21
|
+
Run `pnpm dev` once to auto-generate a template file (the process exits after creation), then edit:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
~/.relay/config.json
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Config fields:
|
|
28
|
+
|
|
29
|
+
```json
|
|
30
|
+
{
|
|
31
|
+
"locale": "en",
|
|
32
|
+
"env": {
|
|
33
|
+
"BASE_DOMAIN": "https://open.feishu.cn",
|
|
34
|
+
"APP_ID": "your_app_id",
|
|
35
|
+
"APP_SECRET": "your_app_secret",
|
|
36
|
+
"BOT_OPEN_ID": "ou_xxx",
|
|
37
|
+
"CODEX_BIN": "codex",
|
|
38
|
+
"CODEX_TIMEOUT_MS": null
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
- Required fields (inside `env`): `BASE_DOMAIN`, `APP_ID`, `APP_SECRET`.
|
|
44
|
+
- Optional fields:
|
|
45
|
+
- `locale` (root level, supported values: `en`, `zh`; default: `en`; unsupported value falls back to `en` with a warning).
|
|
46
|
+
- `BOT_OPEN_ID` (empty or missing means disabled).
|
|
47
|
+
- `CODEX_BIN` (default: `codex`).
|
|
48
|
+
- `CODEX_TIMEOUT_MS` (default: no timeout; if set, must be a positive integer).
|
|
49
|
+
|
|
50
|
+
## Run
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
pnpm install
|
|
54
|
+
pnpm dev
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## How To Use In Feishu
|
|
58
|
+
|
|
59
|
+
### Message flow
|
|
60
|
+
|
|
61
|
+
1. Send a text message to the bot.
|
|
62
|
+
2. Bot replies immediately with a processing echo:
|
|
63
|
+
- `已收到,正在处理任务: <task preview>`
|
|
64
|
+
3. Bot sends final Codex result when done.
|
|
65
|
+
4. After `/new`, the first normal prompt triggers one extra model call to auto-generate a session title.
|
|
66
|
+
|
|
67
|
+
### P2P chat
|
|
68
|
+
|
|
69
|
+
- Any text message is handled.
|
|
70
|
+
|
|
71
|
+
### Group chat
|
|
72
|
+
|
|
73
|
+
- Bot only handles messages that `@` the bot.
|
|
74
|
+
- Session is isolated by `group + sender` (different users in same group do not share context).
|
|
75
|
+
|
|
76
|
+
### Commands
|
|
77
|
+
|
|
78
|
+
- `/help` show help.
|
|
79
|
+
- `/new [default|plan]` create a new conversation (default mode if omitted).
|
|
80
|
+
- `/mode <default|plan>` switch mode for current conversation.
|
|
81
|
+
- `/status` show current thread info.
|
|
82
|
+
- `/projects` show current fixed workspace root.
|
|
83
|
+
- `/reset` clear current conversation.
|
|
84
|
+
|
|
85
|
+
## Notes
|
|
86
|
+
|
|
87
|
+
- Sessions are in-memory only; restarting the process resets session mapping.
|
|
88
|
+
- Codex runtime still stores its own threads under `~/.codex/sessions`.
|
|
89
|
+
- Relay fixes workspace root to the process startup directory (`process.cwd()`).
|
|
90
|
+
- Ensure process user can read/write `~/.codex/sessions`.
|
|
91
|
+
- `.env.local` is no longer used for runtime config.
|
|
92
|
+
|
|
93
|
+
## Quality checks
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
pnpm i18n:extract
|
|
97
|
+
pnpm i18n:compile
|
|
98
|
+
pnpm lint
|
|
99
|
+
pnpm typecheck
|
|
100
|
+
pnpm test
|
|
101
|
+
```
|
package/README.zh.md
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# relay
|
|
2
|
+
|
|
3
|
+
[English](./README.md) | [简体中文](./README.zh.md)
|
|
4
|
+
|
|
5
|
+
一个将飞书聊天消息转发给 Codex,并将结果回传到聊天中的机器人。
|
|
6
|
+
|
|
7
|
+
## 前置条件
|
|
8
|
+
|
|
9
|
+
1. Node.js 20+ 和 `pnpm`。
|
|
10
|
+
2. 已安装并登录 `codex` CLI(`codex login`)。
|
|
11
|
+
3. 已创建并启用机器人能力的飞书应用 [创建机器人](https://open.feishu.cn/document/develop-an-echo-bot/introduction)。
|
|
12
|
+
4. 已开启飞书事件订阅 `im.message.receive_v1`。
|
|
13
|
+
5. 飞书机器人权限:
|
|
14
|
+
- 与机器人单聊(P2P)消息。
|
|
15
|
+
- 群聊中 `@` 机器人消息(或按需放开为全部群消息)。
|
|
16
|
+
|
|
17
|
+
## 配置
|
|
18
|
+
|
|
19
|
+
Relay 仅从 `~/.relay/config.json` 读取配置。
|
|
20
|
+
|
|
21
|
+
先运行一次 `pnpm dev` 自动生成模板文件(生成后进程会退出),然后编辑:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
~/.relay/config.json
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
配置字段:
|
|
28
|
+
|
|
29
|
+
```json
|
|
30
|
+
{
|
|
31
|
+
"locale": "en",
|
|
32
|
+
"env": {
|
|
33
|
+
"BASE_DOMAIN": "https://open.feishu.cn",
|
|
34
|
+
"APP_ID": "your_app_id",
|
|
35
|
+
"APP_SECRET": "your_app_secret",
|
|
36
|
+
"BOT_OPEN_ID": "ou_xxx",
|
|
37
|
+
"CODEX_BIN": "codex",
|
|
38
|
+
"CODEX_TIMEOUT_MS": null
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
- 必填字段(放在 `env` 内):`BASE_DOMAIN`、`APP_ID`、`APP_SECRET`。
|
|
44
|
+
- 可选字段:
|
|
45
|
+
- `locale`(放在根级,支持:`en`、`zh`;默认:`en`;如果值不支持会告警并回退到 `en`)。
|
|
46
|
+
- `BOT_OPEN_ID`(为空或缺失表示禁用)。
|
|
47
|
+
- `CODEX_BIN`(默认:`codex`)。
|
|
48
|
+
- `CODEX_TIMEOUT_MS`(默认:不超时;如果设置,必须为正整数)。
|
|
49
|
+
|
|
50
|
+
## 运行
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
pnpm install
|
|
54
|
+
pnpm dev
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## 在飞书中使用
|
|
58
|
+
|
|
59
|
+
### 消息流程
|
|
60
|
+
|
|
61
|
+
1. 给机器人发送一条文本消息。
|
|
62
|
+
2. 机器人会先立即回复处理中回显:
|
|
63
|
+
- `已收到,正在处理任务: <task preview>`
|
|
64
|
+
3. Codex 处理完成后,机器人发送最终结果。
|
|
65
|
+
4. 执行 `/new` 后,首条普通提示词会额外触发一次模型调用,用于自动生成会话标题。
|
|
66
|
+
|
|
67
|
+
### 单聊(P2P)
|
|
68
|
+
|
|
69
|
+
- 任意文本消息都会被处理。
|
|
70
|
+
|
|
71
|
+
### 群聊
|
|
72
|
+
|
|
73
|
+
- 机器人只处理 `@` 机器人的消息。
|
|
74
|
+
- 会话按 `群 + 发送者` 隔离(同一群内不同用户不会共享上下文)。
|
|
75
|
+
|
|
76
|
+
### 命令
|
|
77
|
+
|
|
78
|
+
- `/help` 显示帮助。
|
|
79
|
+
- `/new [default|plan]` 新建会话(省略参数时为 default 模式)。
|
|
80
|
+
- `/mode <default|plan>` 切换当前会话模式。
|
|
81
|
+
- `/status` 显示当前线程信息。
|
|
82
|
+
- `/projects` 显示当前固定工作区根目录。
|
|
83
|
+
- `/reset` 清空当前会话。
|
|
84
|
+
|
|
85
|
+
## 说明
|
|
86
|
+
|
|
87
|
+
- 会话映射仅保存在内存中;重启进程后会重置。
|
|
88
|
+
- Codex 运行时仍会把自己的线程存到 `~/.codex/sessions`。
|
|
89
|
+
- Relay 将工作区根目录固定为进程启动目录(`process.cwd()`)。
|
|
90
|
+
- 请确保进程用户对 `~/.codex/sessions` 有读写权限。
|
|
91
|
+
- 运行时不再使用 `.env.local`。
|
|
92
|
+
|
|
93
|
+
## 质量检查
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
pnpm i18n:extract
|
|
97
|
+
pnpm i18n:compile
|
|
98
|
+
pnpm lint
|
|
99
|
+
pnpm typecheck
|
|
100
|
+
pnpm test
|
|
101
|
+
```
|
package/bin/relay.mjs
ADDED
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|