qidao-openclaw-plugin 1.2.2 → 1.2.5
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/package.json +1 -1
- package/src/auth-cli.js +27 -0
- package/src/index.js +39 -6
package/package.json
CHANGED
package/src/auth-cli.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 栖岛聊天认证 CLI 命令
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export function registerAuthCommand(api) {
|
|
6
|
+
api.registerCli(
|
|
7
|
+
({ program }) => {
|
|
8
|
+
program
|
|
9
|
+
.command('qidao-auth')
|
|
10
|
+
.description('栖岛聊天二维码认证')
|
|
11
|
+
.action(async () => {
|
|
12
|
+
console.log('🔐 开始栖岛聊天认证流程...');
|
|
13
|
+
console.log('');
|
|
14
|
+
console.log('请使用以下步骤完成认证:');
|
|
15
|
+
console.log('1. 访问栖岛官方网站');
|
|
16
|
+
console.log('2. 扫描二维码登录');
|
|
17
|
+
console.log('3. 获取您的 chatId');
|
|
18
|
+
console.log('');
|
|
19
|
+
console.log('然后运行:');
|
|
20
|
+
console.log(' openclaw config set channels.qidao.chatId <您的chatId>');
|
|
21
|
+
console.log(' openclaw config set channels.qidao.enabled true');
|
|
22
|
+
console.log(' openclaw gateway restart');
|
|
23
|
+
});
|
|
24
|
+
},
|
|
25
|
+
{ commands: ['qidao-auth'] }
|
|
26
|
+
);
|
|
27
|
+
}
|
package/src/index.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import { QidaoChannel } from './qidao-channel.js';
|
|
6
|
+
import { registerAuthCommand } from './auth-cli.js';
|
|
6
7
|
|
|
7
8
|
let connection = null;
|
|
8
9
|
|
|
@@ -28,7 +29,7 @@ const qidaoChannel = {
|
|
|
28
29
|
|
|
29
30
|
return {
|
|
30
31
|
accountId: 'default',
|
|
31
|
-
enabled: qidaoConfig.enabled
|
|
32
|
+
enabled: qidaoConfig.enabled !== false,
|
|
32
33
|
chatId: qidaoConfig.chatId,
|
|
33
34
|
userId: qidaoConfig.userId,
|
|
34
35
|
serverUrl: qidaoConfig.serverUrl ?? 'wss://oc.qidao.chat/ws',
|
|
@@ -37,18 +38,48 @@ const qidaoChannel = {
|
|
|
37
38
|
},
|
|
38
39
|
|
|
39
40
|
onboarding: {
|
|
41
|
+
getStatus: async ({ cfg }) => {
|
|
42
|
+
const qidaoConfig = cfg.channels?.qidao ?? {};
|
|
43
|
+
const configured = Boolean(qidaoConfig.chatId);
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
channel: 'qidao',
|
|
47
|
+
configured,
|
|
48
|
+
statusLines: [`栖岛聊天: ${configured ? `已配置 (chatId: ${qidaoConfig.chatId})` : '未配置'}`],
|
|
49
|
+
selectionHint: configured ? '已配置' : '需要配置',
|
|
50
|
+
};
|
|
51
|
+
},
|
|
52
|
+
|
|
40
53
|
configure: async ({ cfg, prompter }) => {
|
|
41
54
|
const qidaoConfig = cfg.channels?.qidao ?? {};
|
|
42
55
|
|
|
56
|
+
// 如果已经有 chatId,询问是否重新认证
|
|
57
|
+
if (qidaoConfig.chatId) {
|
|
58
|
+
const reauth = await prompter.confirm({
|
|
59
|
+
message: `已配置 chatId: ${qidaoConfig.chatId},是否重新配置?`,
|
|
60
|
+
default: false,
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
if (!reauth) {
|
|
64
|
+
return { cfg, accountId: 'default' };
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// 提示用户
|
|
69
|
+
console.log('');
|
|
70
|
+
console.log('栖岛聊天需要通过扫码获取 chatId');
|
|
71
|
+
console.log('请访问栖岛官方网站完成认证后,输入获取到的 chatId');
|
|
72
|
+
console.log('');
|
|
73
|
+
|
|
43
74
|
const chatId = await prompter.text({
|
|
44
75
|
message: '请输入栖岛 Chat ID:',
|
|
45
76
|
default: qidaoConfig.chatId?.toString() || '',
|
|
46
77
|
});
|
|
47
78
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
79
|
+
if (!chatId || chatId.trim() === '') {
|
|
80
|
+
console.log('未输入 chatId,取消配置');
|
|
81
|
+
return { cfg };
|
|
82
|
+
}
|
|
52
83
|
|
|
53
84
|
const serverUrl = await prompter.text({
|
|
54
85
|
message: '请输入服务器地址:',
|
|
@@ -62,7 +93,6 @@ const qidaoChannel = {
|
|
|
62
93
|
qidao: {
|
|
63
94
|
enabled: true,
|
|
64
95
|
chatId: parseInt(chatId),
|
|
65
|
-
userId: userId ? parseInt(userId) : undefined,
|
|
66
96
|
serverUrl,
|
|
67
97
|
},
|
|
68
98
|
},
|
|
@@ -99,6 +129,9 @@ export default function register(api) {
|
|
|
99
129
|
|
|
100
130
|
api.registerChannel({ plugin: qidaoChannel });
|
|
101
131
|
|
|
132
|
+
// 注册认证命令
|
|
133
|
+
registerAuthCommand(api);
|
|
134
|
+
|
|
102
135
|
setImmediate(async () => {
|
|
103
136
|
try {
|
|
104
137
|
const cfg = api.getGatewayConfig?.() || {};
|