@zhin.js/adapter-qq 1.1.15 → 1.1.17
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/CHANGELOG.md +47 -0
- package/README.md +6 -0
- package/agents/qq/messages.js +24 -0
- package/agents/qq/messages.ts +24 -0
- package/agents/qq/skills/qq/tools/add_role/index.js +2 -1
- package/agents/qq/skills/qq/tools/add_role/index.ts +2 -1
- package/agents/qq/skills/qq/tools/create_role/index.js +2 -1
- package/agents/qq/skills/qq/tools/create_role/index.ts +2 -1
- package/agents/qq/skills/qq/tools/remove_role/index.js +2 -1
- package/agents/qq/skills/qq/tools/remove_role/index.ts +2 -1
- package/commands/qq/endpoint/cancel/index.js +6 -5
- package/commands/qq/endpoint/cancel/index.ts +5 -5
- package/commands/qq/endpoint/definition.js +32 -30
- package/commands/qq/endpoint/definition.ts +36 -31
- package/lib/i18n.d.ts +1 -0
- package/lib/i18n.js +72 -0
- package/lib/qq-bind-flow.d.ts +2 -0
- package/lib/qq-bind-flow.js +2 -1
- package/lib/qq-bot-kind-prompt.d.ts +5 -6
- package/lib/qq-bot-kind-prompt.js +26 -26
- package/lib/qq-runtime-state.d.ts +6 -0
- package/middlewares/bot-kind-reply/index.js +6 -5
- package/middlewares/bot-kind-reply/index.ts +6 -5
- package/package.json +17 -17
- package/schema.json +59 -9
- package/src/i18n.ts +73 -0
- package/src/qq-bind-flow.ts +4 -1
- package/src/qq-bot-kind-prompt.ts +22 -37
- package/src/qq-runtime-state.ts +6 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,52 @@
|
|
|
1
1
|
# @zhin.js/adapter-qq
|
|
2
2
|
|
|
3
|
+
## 1.1.17
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [f67883e]
|
|
8
|
+
- Updated dependencies [e23cabc]
|
|
9
|
+
- Updated dependencies [4d728c0]
|
|
10
|
+
- Updated dependencies [eb8feeb]
|
|
11
|
+
- Updated dependencies [24a2b71]
|
|
12
|
+
- Updated dependencies [d0e1fac]
|
|
13
|
+
- Updated dependencies [1ca669a]
|
|
14
|
+
- Updated dependencies [3771f7a]
|
|
15
|
+
- Updated dependencies [4f96ad5]
|
|
16
|
+
- @zhin.js/core@1.1.52
|
|
17
|
+
- @zhin.js/adapter@1.1.24
|
|
18
|
+
- @zhin.js/tool@1.1.11
|
|
19
|
+
- @zhin.js/host-http@1.1.11
|
|
20
|
+
- @zhin.js/im-contract@1.1.8
|
|
21
|
+
|
|
22
|
+
## 1.1.16
|
|
23
|
+
|
|
24
|
+
### Patch Changes
|
|
25
|
+
|
|
26
|
+
- 53bc6a0: 适配器配置标签、端点命令和工具反馈支持中英文;复用当前操作语言,保持协议值、用户内容、身份、权限与发送链路不变。Sandbox 展示使用项目语言,QQ 绑定与交互状态保留完整会话身份。
|
|
27
|
+
- Updated dependencies [334e92d]
|
|
28
|
+
- Updated dependencies [f3b7c9f]
|
|
29
|
+
- Updated dependencies [658a5fb]
|
|
30
|
+
- Updated dependencies [144a17b]
|
|
31
|
+
- Updated dependencies [18296cf]
|
|
32
|
+
- Updated dependencies [08e64de]
|
|
33
|
+
- Updated dependencies [9cade30]
|
|
34
|
+
- Updated dependencies [53bc6a0]
|
|
35
|
+
- Updated dependencies [7595136]
|
|
36
|
+
- Updated dependencies [66b6404]
|
|
37
|
+
- Updated dependencies [adb4af2]
|
|
38
|
+
- Updated dependencies [69f9ef6]
|
|
39
|
+
- Updated dependencies [17d1301]
|
|
40
|
+
- @zhin.js/adapter@1.1.23
|
|
41
|
+
- @zhin.js/host-http@1.1.10
|
|
42
|
+
- @zhin.js/core@1.1.51
|
|
43
|
+
- @zhin.js/permission@1.1.9
|
|
44
|
+
- @zhin.js/tool@1.1.10
|
|
45
|
+
- @zhin.js/skill@1.1.10
|
|
46
|
+
- @zhin.js/im-contract@1.1.7
|
|
47
|
+
- @zhin.js/agent-feature@1.1.10
|
|
48
|
+
- @zhin.js/feature-kit@1.1.9
|
|
49
|
+
|
|
3
50
|
## 1.1.15
|
|
4
51
|
|
|
5
52
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -237,3 +237,9 @@ QQ 当前未实现 canonical `share` 的标题/描述/URL 消息卡片。适配
|
|
|
237
237
|
可选 `streamProxy: { port: 18443, serverName: "实际网关 hostname" }` 将 WSS 的 TCP 连接导向 `127.0.0.1:port`。需代理固定转发到相同官方网关的 443 端口;SDK 每次仍动态调用 `getWsUrl()`,hostname/443 不匹配会拒绝连接并只记录 hostname,不能自动绕过代理。原始 URL、HTTP Host、TLS SNI 保留,证书验证始终开启。不要填带 query 的 URL。
|
|
238
238
|
|
|
239
239
|
仅 WSS 入站、心跳和会话认证经过此代理;AppSecret 换 token、网关发现 HTTP、消息 API 和媒体上传仍直连。故障恢复由 `createEndpointLifecycle` 负责,SDK 内置重连关闭,避免双重重连。此入口用于受控网络验收,不提供全局代理或 TLS 验证绕过。
|
|
240
|
+
|
|
241
|
+
## 语言与绑定会话
|
|
242
|
+
|
|
243
|
+
Endpoint 管理命令和工具反馈使用当前操作语言。扫码绑定在开始时固定语言,后续二维码刷新、公域/私域选择和结果回复保持一致;`public` / `private` 是稳定的配置值,两种语言都可使用,中文别名只在中文流程中接受。
|
|
244
|
+
|
|
245
|
+
取消指引使用发起命令时的真实前缀及插件命名空间,不猜测调用方式。确认回复仅接受发起者所在的完整会话(Endpoint、会话、父容器、线程和发送者);其他成员或线程不会完成该绑定。
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { createMessages } from 'zhin.js/i18n';
|
|
3
|
+
export const messages = createMessages({
|
|
4
|
+
"operationFailed": {
|
|
5
|
+
"zh-CN": "操作失败",
|
|
6
|
+
"en": "Operation failed"
|
|
7
|
+
},
|
|
8
|
+
"roleAdded": {
|
|
9
|
+
"zh-CN": "已给成员添加角色",
|
|
10
|
+
"en": "Role added to the member"
|
|
11
|
+
},
|
|
12
|
+
"createFailed": {
|
|
13
|
+
"zh-CN": "创建失败",
|
|
14
|
+
"en": "Creation failed"
|
|
15
|
+
},
|
|
16
|
+
"namedRoleCreated": {
|
|
17
|
+
"zh-CN": "角色 \"{p0}\" 创建成功",
|
|
18
|
+
"en": "Role \"{p0}\" created"
|
|
19
|
+
},
|
|
20
|
+
"roleRemoved": {
|
|
21
|
+
"zh-CN": "已移除成员的角色",
|
|
22
|
+
"en": "Role removed from the member"
|
|
23
|
+
}
|
|
24
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { createMessages } from 'zhin.js/i18n';
|
|
2
|
+
|
|
3
|
+
export const messages = createMessages({
|
|
4
|
+
"operationFailed": {
|
|
5
|
+
"zh-CN": "操作失败",
|
|
6
|
+
"en": "Operation failed"
|
|
7
|
+
},
|
|
8
|
+
"roleAdded": {
|
|
9
|
+
"zh-CN": "已给成员添加角色",
|
|
10
|
+
"en": "Role added to the member"
|
|
11
|
+
},
|
|
12
|
+
"createFailed": {
|
|
13
|
+
"zh-CN": "创建失败",
|
|
14
|
+
"en": "Creation failed"
|
|
15
|
+
},
|
|
16
|
+
"namedRoleCreated": {
|
|
17
|
+
"zh-CN": "角色 \"{p0}\" 创建成功",
|
|
18
|
+
"en": "Role \"{p0}\" created"
|
|
19
|
+
},
|
|
20
|
+
"roleRemoved": {
|
|
21
|
+
"zh-CN": "已移除成员的角色",
|
|
22
|
+
"en": "Role removed from the member"
|
|
23
|
+
}
|
|
24
|
+
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { messages as t } from "../../../../messages.js";
|
|
2
3
|
import { defineAgentTool } from '@zhin.js/tool';
|
|
3
4
|
import { z } from 'zod';
|
|
4
5
|
import { platformPermission } from '@zhin.js/permission';
|
|
@@ -17,6 +18,6 @@ export default defineAgentTool({
|
|
|
17
18
|
async execute({ guild_id, channel_id, user_id, role_id }, context) {
|
|
18
19
|
const client = context.$client;
|
|
19
20
|
const success = await client.addMemberRole(guild_id, channel_id, user_id, role_id);
|
|
20
|
-
return { success, message: success ? '
|
|
21
|
+
return { success, message: success ? t(context.locale, 'roleAdded') : t(context.locale, 'operationFailed') };
|
|
21
22
|
},
|
|
22
23
|
});
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { messages as t } from "../../../../messages.js";
|
|
1
2
|
import { defineAgentTool } from '@zhin.js/tool';
|
|
2
3
|
import { z } from 'zod';
|
|
3
4
|
import { platformPermission } from '@zhin.js/permission';
|
|
@@ -17,6 +18,6 @@ export default defineAgentTool<{ guild_id: string; channel_id: string; user_id:
|
|
|
17
18
|
async execute({ guild_id, channel_id, user_id, role_id }: { guild_id: string; channel_id: string; user_id: string; role_id: string }, context) {
|
|
18
19
|
const client = context.$client;
|
|
19
20
|
const success = await client.addMemberRole(guild_id, channel_id, user_id, role_id);
|
|
20
|
-
return { success, message: success ? '
|
|
21
|
+
return { success, message: success ? t(context.locale, 'roleAdded') : t(context.locale, 'operationFailed') };
|
|
21
22
|
},
|
|
22
23
|
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { messages as t } from "../../../../messages.js";
|
|
2
3
|
import { defineAgentTool } from '@zhin.js/tool';
|
|
3
4
|
import { z } from 'zod';
|
|
4
5
|
import { platformPermission } from '@zhin.js/permission';
|
|
@@ -16,6 +17,6 @@ export default defineAgentTool({
|
|
|
16
17
|
async execute({ guild_id, name, color }, context) {
|
|
17
18
|
const client = context.$client;
|
|
18
19
|
const role = await client.createGuildRole(guild_id, name, color);
|
|
19
|
-
return { success: !!role, role, message: role ?
|
|
20
|
+
return { success: !!role, role, message: role ? t(context.locale, 'namedRoleCreated', { p0: name }) : t(context.locale, 'createFailed') };
|
|
20
21
|
},
|
|
21
22
|
});
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { messages as t } from "../../../../messages.js";
|
|
1
2
|
import { defineAgentTool } from '@zhin.js/tool';
|
|
2
3
|
import { z } from 'zod';
|
|
3
4
|
import { platformPermission } from '@zhin.js/permission';
|
|
@@ -16,6 +17,6 @@ export default defineAgentTool<{ guild_id: string; name: string; color?: number
|
|
|
16
17
|
async execute({ guild_id, name, color }: { guild_id: string; name: string; color?: number }, context) {
|
|
17
18
|
const client = context.$client;
|
|
18
19
|
const role = await client.createGuildRole(guild_id, name, color);
|
|
19
|
-
return { success: !!role, role, message: role ?
|
|
20
|
+
return { success: !!role, role, message: role ? t(context.locale, 'namedRoleCreated', { p0: name }) : t(context.locale, 'createFailed') };
|
|
20
21
|
},
|
|
21
22
|
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { messages as t } from "../../../../messages.js";
|
|
2
3
|
import { defineAgentTool } from '@zhin.js/tool';
|
|
3
4
|
import { z } from 'zod';
|
|
4
5
|
import { platformPermission } from '@zhin.js/permission';
|
|
@@ -17,6 +18,6 @@ export default defineAgentTool({
|
|
|
17
18
|
async execute({ guild_id, channel_id, user_id, role_id }, context) {
|
|
18
19
|
const client = context.$client;
|
|
19
20
|
const success = await client.removeMemberRole(guild_id, channel_id, user_id, role_id);
|
|
20
|
-
return { success, message: success ? '
|
|
21
|
+
return { success, message: success ? t(context.locale, 'roleRemoved') : t(context.locale, 'operationFailed') };
|
|
21
22
|
},
|
|
22
23
|
});
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { messages as t } from "../../../../messages.js";
|
|
1
2
|
import { defineAgentTool } from '@zhin.js/tool';
|
|
2
3
|
import { z } from 'zod';
|
|
3
4
|
import { platformPermission } from '@zhin.js/permission';
|
|
@@ -17,6 +18,6 @@ export default defineAgentTool<{ guild_id: string; channel_id: string; user_id:
|
|
|
17
18
|
async execute({ guild_id, channel_id, user_id, role_id }: { guild_id: string; channel_id: string; user_id: string; role_id: string }, context) {
|
|
18
19
|
const client = context.$client;
|
|
19
20
|
const success = await client.removeMemberRole(guild_id, channel_id, user_id, role_id);
|
|
20
|
-
return { success, message: success ? '
|
|
21
|
+
return { success, message: success ? t(context.locale, 'roleRemoved') : t(context.locale, 'operationFailed') };
|
|
21
22
|
},
|
|
22
23
|
});
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { endpointCommandForbidden } from 'zhin.js/adapter';
|
|
2
3
|
import { defineCommand } from 'zhin.js/command';
|
|
3
|
-
import { isQqEndpointOperator,
|
|
4
|
+
import { isQqEndpointOperator, qqRuntimeStateToken, runQqEndpointCancel, } from '../definition.js';
|
|
4
5
|
export default defineCommand({
|
|
5
|
-
description: '取消进行中的 QQ 扫码绑定或公域/私域选择',
|
|
6
|
-
execute({ config, input, use }) {
|
|
6
|
+
description: '取消进行中的 QQ 扫码绑定或公域/私域选择', descriptionI18n: { en: "Cancel an active QQ QR binding or public/private-domain selection" },
|
|
7
|
+
execute({ config, input, use, locale }) {
|
|
7
8
|
if (!isQqEndpointOperator(config, input))
|
|
8
|
-
return
|
|
9
|
-
return runQqEndpointCancel(use(qqRuntimeStateToken));
|
|
9
|
+
return endpointCommandForbidden('QQ', locale);
|
|
10
|
+
return runQqEndpointCancel(use(qqRuntimeStateToken), locale);
|
|
10
11
|
},
|
|
11
12
|
});
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
+
import { endpointCommandForbidden } from 'zhin.js/adapter';
|
|
1
2
|
import { defineCommand } from 'zhin.js/command';
|
|
2
3
|
import {
|
|
3
4
|
isQqEndpointOperator,
|
|
4
|
-
QQ_ENDPOINT_FORBIDDEN,
|
|
5
5
|
qqRuntimeStateToken,
|
|
6
6
|
runQqEndpointCancel,
|
|
7
7
|
} from '../definition.js';
|
|
8
8
|
|
|
9
9
|
export default defineCommand({
|
|
10
|
-
description: '取消进行中的 QQ 扫码绑定或公域/私域选择',
|
|
11
|
-
execute({ config, input, use }) {
|
|
12
|
-
if (!isQqEndpointOperator(config, input)) return
|
|
13
|
-
return runQqEndpointCancel(use(qqRuntimeStateToken));
|
|
10
|
+
description: '取消进行中的 QQ 扫码绑定或公域/私域选择', descriptionI18n: { en: "Cancel an active QQ QR binding or public/private-domain selection" },
|
|
11
|
+
execute({ config, input, use, locale }) {
|
|
12
|
+
if (!isQqEndpointOperator(config, input)) return endpointCommandForbidden('QQ', locale);
|
|
13
|
+
return runQqEndpointCancel(use(qqRuntimeStateToken), locale);
|
|
14
14
|
},
|
|
15
15
|
});
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { resolveLocale } from 'zhin.js/i18n';
|
|
3
|
+
import { messages as t } from "../../../lib/i18n.js";
|
|
2
4
|
/**
|
|
3
5
|
* `qq endpoint` 命令的业务逻辑(与命令定义文件分离,便于测试)。
|
|
4
6
|
* 通用部分(权限 / list / remove / 配置写回 / .env 持久化)已迁移到
|
|
@@ -8,7 +10,7 @@
|
|
|
8
10
|
*/
|
|
9
11
|
import { buildEndpointEnvKey, createEndpointCommands, endpointCommandForbidden, endpointConfigurationStoreToken, extractEndpointCommandReply, formatEndpointList, isEndpointOperator, removeEndpointById, } from 'zhin.js/adapter';
|
|
10
12
|
import { defineCommand } from 'zhin.js/command';
|
|
11
|
-
import {
|
|
13
|
+
import { qqBotKindPrompt, qqCommandSessionKey } from "../../../lib/qq-bot-kind-prompt.js";
|
|
12
14
|
import { startQqBindFlow } from "../../../lib/qq-bind-flow.js";
|
|
13
15
|
import { defaultQqEndpointIntentFields } from "../../../lib/qq-intents.js";
|
|
14
16
|
import { qqRuntimeStateToken, } from "../../../lib/qq-runtime-state.js";
|
|
@@ -28,20 +30,20 @@ export const QQ_ENDPOINT_FORBIDDEN = endpointCommandForbidden('QQ');
|
|
|
28
30
|
export function extractQqCommandReply(input) {
|
|
29
31
|
return extractEndpointCommandReply(input);
|
|
30
32
|
}
|
|
31
|
-
function busyFooter(state) {
|
|
33
|
+
function busyFooter(state, locale) {
|
|
32
34
|
if (state.bindFlow)
|
|
33
|
-
return '
|
|
35
|
+
return t(locale, 'bindingBusy') + (state.bindFlow.cancelCommand ? `\n${t(locale, 'cancelHint', { command: state.bindFlow.cancelCommand })}` : '');
|
|
34
36
|
if (state.pendingBotKind) {
|
|
35
|
-
return
|
|
37
|
+
return t(locale, 'kindBusy', { id: state.pendingBotKind.endpointId });
|
|
36
38
|
}
|
|
37
39
|
return undefined;
|
|
38
40
|
}
|
|
39
41
|
/** `qq endpoint list`:运行中的 endpoints(本 generation adapter create 注册)+ 配置里的 endpoints */
|
|
40
|
-
export async function runQqEndpointList(state, store) {
|
|
42
|
+
export async function runQqEndpointList(state, store, locale) {
|
|
41
43
|
return formatEndpointList(qqEndpointListSpec, {
|
|
42
44
|
running: state.endpoints.values(),
|
|
43
45
|
configured: await store.list('qq'),
|
|
44
|
-
footer: busyFooter(state),
|
|
46
|
+
footer: busyFooter(state, locale), locale,
|
|
45
47
|
});
|
|
46
48
|
}
|
|
47
49
|
const qqEndpointListSpec = {
|
|
@@ -50,6 +52,7 @@ const qqEndpointListSpec = {
|
|
|
50
52
|
describeEntry: (entry) => `appid: ${String(entry.appid)}`,
|
|
51
53
|
};
|
|
52
54
|
async function writeEndpointWithBotKind(pending, botKind, store) {
|
|
55
|
+
const locale = pending.locale;
|
|
53
56
|
const appidKey = buildEndpointEnvKey('qq', pending.endpointId, 'appid');
|
|
54
57
|
const secretKey = buildEndpointEnvKey('qq', pending.endpointId, 'secret');
|
|
55
58
|
const intentFields = defaultQqEndpointIntentFields(botKind);
|
|
@@ -67,9 +70,7 @@ async function writeEndpointWithBotKind(pending, botKind, store) {
|
|
|
67
70
|
[secretKey]: pending.appSecret,
|
|
68
71
|
},
|
|
69
72
|
});
|
|
70
|
-
return (
|
|
71
|
-
`intents: ${intentFields.intents.join(', ')}。\n` +
|
|
72
|
-
'⚠️ 需重启 zhin 后新 endpoint 才会生效。');
|
|
73
|
+
return t(locale, 'endpointSaved', { kind: intentFields.botKind, id: pending.endpointId, file: filePath, intents: intentFields.intents.join(', ') });
|
|
73
74
|
}
|
|
74
75
|
/**
|
|
75
76
|
* 完成 pending 的公域/私域选择:一次性写 .env + yaml。
|
|
@@ -84,9 +85,9 @@ export async function completeQqPendingBotKind(pending, botKind, store) {
|
|
|
84
85
|
* 后续状态(已扫码 / 成功 / 失败 / 过期刷新)通过 reply 推回当前会话。
|
|
85
86
|
* 扫码成功后凭据暂存内存并询问公域/私域;确认后一次性写 .env + yaml。
|
|
86
87
|
*/
|
|
87
|
-
export function runQqEndpointAdd(state, id, reply, store, input) {
|
|
88
|
+
export function runQqEndpointAdd(state, id, reply, store, input, locale = 'zh-CN', cancelCommand, commandHeads) {
|
|
88
89
|
if (state.bindFlow || state.pendingBotKind) {
|
|
89
|
-
return Promise.resolve(
|
|
90
|
+
return Promise.resolve(t(locale, 'existingFlow'));
|
|
90
91
|
}
|
|
91
92
|
const endpointId = id?.trim() || undefined;
|
|
92
93
|
const sessionKey = qqCommandSessionKey(input);
|
|
@@ -106,11 +107,11 @@ export function runQqEndpointAdd(state, id, reply, store, input) {
|
|
|
106
107
|
const stop = startQqBindFlow({
|
|
107
108
|
onQrDisplayed: (url) => {
|
|
108
109
|
// QQ 出站当前仅支持纯文本(富媒体未迁移),二维码只能发链接文本
|
|
109
|
-
settle(
|
|
110
|
+
settle(t(locale, 'scanLink', { url }));
|
|
110
111
|
},
|
|
111
112
|
onQrExpired: async () => {
|
|
112
113
|
try {
|
|
113
|
-
await reply('
|
|
114
|
+
await reply(t(locale, 'qrExpired'));
|
|
114
115
|
}
|
|
115
116
|
catch {
|
|
116
117
|
// same as settle follow-up: best-effort after command scope ends
|
|
@@ -127,45 +128,45 @@ export function runQqEndpointAdd(state, id, reply, store, input) {
|
|
|
127
128
|
endpointId: finalName,
|
|
128
129
|
appId,
|
|
129
130
|
appSecret,
|
|
130
|
-
sessionKey: '',
|
|
131
|
+
sessionKey: '', locale, cancelCommand,
|
|
131
132
|
}, 'public', store) +
|
|
132
|
-
'
|
|
133
|
+
t(locale, 'noInteractiveKind'));
|
|
133
134
|
return;
|
|
134
135
|
}
|
|
135
136
|
state.pendingBotKind = {
|
|
136
137
|
endpointId: finalName,
|
|
137
138
|
appId,
|
|
138
139
|
appSecret,
|
|
139
|
-
sessionKey,
|
|
140
|
+
sessionKey, locale, cancelCommand, commandHeads,
|
|
140
141
|
};
|
|
141
|
-
settle(
|
|
142
|
-
QQ_BOT_KIND_PROMPT);
|
|
142
|
+
settle(t(locale, 'scanned', { id: finalName, prompt: qqBotKindPrompt(locale, cancelCommand) }));
|
|
143
143
|
}
|
|
144
144
|
catch (error) {
|
|
145
|
-
settle(
|
|
145
|
+
settle(t(locale, 'writeFailed', { error: error instanceof Error ? error.message : String(error) }));
|
|
146
146
|
}
|
|
147
147
|
},
|
|
148
148
|
onFailure: (error) => {
|
|
149
149
|
state.bindFlow = null;
|
|
150
|
-
settle(
|
|
150
|
+
settle(t(locale, 'bindingFailed', { error: error.message }));
|
|
151
151
|
},
|
|
152
|
-
}, { source: 'zhin' });
|
|
153
|
-
state.bindFlow = { id: endpointId, stop };
|
|
152
|
+
}, { source: 'zhin', locale });
|
|
153
|
+
state.bindFlow = { id: endpointId, stop, locale, cancelCommand, commandHeads };
|
|
154
154
|
});
|
|
155
155
|
}
|
|
156
156
|
/** `qq endpoint cancel`:中止进行中的绑定或待选 botKind */
|
|
157
|
-
export function runQqEndpointCancel(state) {
|
|
157
|
+
export function runQqEndpointCancel(state, preference) {
|
|
158
|
+
const locale = resolveLocale(state.pendingBotKind?.locale ?? state.bindFlow?.locale ?? preference);
|
|
158
159
|
if (state.bindFlow) {
|
|
159
160
|
state.bindFlow.stop();
|
|
160
161
|
state.bindFlow = null;
|
|
161
|
-
return
|
|
162
|
+
return t(locale, 'cancelled');
|
|
162
163
|
}
|
|
163
164
|
if (state.pendingBotKind) {
|
|
164
165
|
const name = state.pendingBotKind.endpointId;
|
|
165
166
|
state.pendingBotKind = null;
|
|
166
|
-
return
|
|
167
|
+
return t(locale, 'pendingCancelled', { name });
|
|
167
168
|
}
|
|
168
|
-
return
|
|
169
|
+
return t(locale, 'noFlow');
|
|
169
170
|
}
|
|
170
171
|
/** `qq endpoint remove <id>`:从 zhin.config.yml 移除对应 endpoints 项 */
|
|
171
172
|
export async function runQqEndpointRemove(_state, id, store) {
|
|
@@ -178,11 +179,12 @@ export async function runQqEndpointRemove(_state, id, store) {
|
|
|
178
179
|
export const qqEndpointCommands = createEndpointCommands({
|
|
179
180
|
...qqEndpointListSpec,
|
|
180
181
|
fields: [
|
|
181
|
-
{ key: 'appid', required: true, env: true, description: 'QQ 机器人 appid' },
|
|
182
|
-
{ key: 'secret', required: true, env: true, description: 'QQ 机器人 secret' },
|
|
182
|
+
{ key: 'appid', required: true, env: true, description: 'QQ 机器人 appid', descriptionI18n: { en: "QQ bot app ID" } },
|
|
183
|
+
{ key: 'secret', required: true, env: true, description: 'QQ 机器人 secret', descriptionI18n: { en: "QQ bot secret" } },
|
|
183
184
|
],
|
|
184
185
|
running: (use) => use(qqRuntimeStateToken).endpoints.values(),
|
|
185
|
-
listFooter: (use) => busyFooter(use(qqRuntimeStateToken)),
|
|
186
|
+
listFooter: (use, locale) => busyFooter(use(qqRuntimeStateToken), locale),
|
|
187
|
+
addDescriptionI18n: { en: 'Bind a bot through mobile QQ, choose public/private, then save configuration; restart to apply' },
|
|
186
188
|
addDescription: '手机 QQ 扫码绑定机器人:确认公域/私域后一次性写入 .env 与 zhin.config.yml(重启生效)',
|
|
187
|
-
bindFlow: ({ id, reply, input, use }) => runQqEndpointAdd(use(qqRuntimeStateToken), id, reply, use(endpointConfigurationStoreToken), input),
|
|
189
|
+
bindFlow: ({ id, reply, input, use, locale, formatCommand }) => runQqEndpointAdd(use(qqRuntimeStateToken), id, reply, use(endpointConfigurationStoreToken), input, locale, formatCommand?.('qq endpoint cancel'), ['qq endpoint list', 'qq endpoint add', 'qq endpoint remove', 'qq endpoint cancel'].flatMap(path => { const head = formatCommand?.(path); return head ? [head] : []; })),
|
|
188
190
|
}, defineCommand);
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { resolveLocale, type Locale } from 'zhin.js/i18n';
|
|
2
|
+
import { messages as t } from '../../../src/i18n.js';
|
|
1
3
|
/**
|
|
2
4
|
* `qq endpoint` 命令的业务逻辑(与命令定义文件分离,便于测试)。
|
|
3
5
|
* 通用部分(权限 / list / remove / 配置写回 / .env 持久化)已迁移到
|
|
@@ -19,7 +21,7 @@ import {
|
|
|
19
21
|
type EndpointConfigurationStore,
|
|
20
22
|
} from 'zhin.js/adapter';
|
|
21
23
|
import { defineCommand } from 'zhin.js/command';
|
|
22
|
-
import {
|
|
24
|
+
import { qqBotKindPrompt, qqCommandSessionKey } from '../../../src/qq-bot-kind-prompt.js';
|
|
23
25
|
import { startQqBindFlow } from '../../../src/qq-bind-flow.js';
|
|
24
26
|
import { defaultQqEndpointIntentFields, type QqBotKind } from '../../../src/qq-intents.js';
|
|
25
27
|
import {
|
|
@@ -50,10 +52,10 @@ export function extractQqCommandReply(input: unknown): QqCommandReply {
|
|
|
50
52
|
return extractEndpointCommandReply(input);
|
|
51
53
|
}
|
|
52
54
|
|
|
53
|
-
function busyFooter(state: QqRuntimeState): string | undefined {
|
|
54
|
-
if (state.bindFlow) return '
|
|
55
|
+
function busyFooter(state: QqRuntimeState, locale?: Locale): string | undefined {
|
|
56
|
+
if (state.bindFlow) return t(locale, 'bindingBusy') + (state.bindFlow.cancelCommand ? `\n${t(locale, 'cancelHint', { command: state.bindFlow.cancelCommand })}` : '');
|
|
55
57
|
if (state.pendingBotKind) {
|
|
56
|
-
return
|
|
58
|
+
return t(locale, 'kindBusy', { id: state.pendingBotKind.endpointId });
|
|
57
59
|
}
|
|
58
60
|
return undefined;
|
|
59
61
|
}
|
|
@@ -62,11 +64,12 @@ function busyFooter(state: QqRuntimeState): string | undefined {
|
|
|
62
64
|
export async function runQqEndpointList(
|
|
63
65
|
state: QqRuntimeState,
|
|
64
66
|
store: EndpointConfigurationStore,
|
|
67
|
+
locale?: Locale,
|
|
65
68
|
): Promise<string> {
|
|
66
69
|
return formatEndpointList(qqEndpointListSpec, {
|
|
67
70
|
running: state.endpoints.values(),
|
|
68
71
|
configured: await store.list('qq'),
|
|
69
|
-
footer: busyFooter(state),
|
|
72
|
+
footer: busyFooter(state, locale), locale,
|
|
70
73
|
});
|
|
71
74
|
}
|
|
72
75
|
|
|
@@ -81,6 +84,7 @@ async function writeEndpointWithBotKind(
|
|
|
81
84
|
botKind: QqBotKind,
|
|
82
85
|
store: EndpointConfigurationStore,
|
|
83
86
|
): Promise<string> {
|
|
87
|
+
const locale = pending.locale;
|
|
84
88
|
const appidKey = buildEndpointEnvKey('qq', pending.endpointId, 'appid');
|
|
85
89
|
const secretKey = buildEndpointEnvKey('qq', pending.endpointId, 'secret');
|
|
86
90
|
const intentFields = defaultQqEndpointIntentFields(botKind);
|
|
@@ -98,11 +102,7 @@ async function writeEndpointWithBotKind(
|
|
|
98
102
|
[secretKey]: pending.appSecret,
|
|
99
103
|
},
|
|
100
104
|
});
|
|
101
|
-
return (
|
|
102
|
-
`✅ 已按 botKind=${intentFields.botKind} 将 endpoint「${pending.endpointId}」写入 .env 与 ${filePath}。\n` +
|
|
103
|
-
`intents: ${intentFields.intents.join(', ')}。\n` +
|
|
104
|
-
'⚠️ 需重启 zhin 后新 endpoint 才会生效。'
|
|
105
|
-
);
|
|
105
|
+
return t(locale, 'endpointSaved', { kind: intentFields.botKind, id: pending.endpointId, file: filePath, intents: intentFields.intents.join(', ') });
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
/**
|
|
@@ -129,10 +129,13 @@ export function runQqEndpointAdd(
|
|
|
129
129
|
reply: QqCommandReply,
|
|
130
130
|
store: EndpointConfigurationStore,
|
|
131
131
|
input?: unknown,
|
|
132
|
+
locale: Locale = 'zh-CN',
|
|
133
|
+
cancelCommand?: string,
|
|
134
|
+
commandHeads?: readonly string[],
|
|
132
135
|
): Promise<string> {
|
|
133
136
|
if (state.bindFlow || state.pendingBotKind) {
|
|
134
137
|
return Promise.resolve(
|
|
135
|
-
|
|
138
|
+
t(locale, 'existingFlow'),
|
|
136
139
|
);
|
|
137
140
|
}
|
|
138
141
|
const endpointId = id?.trim() || undefined;
|
|
@@ -155,12 +158,12 @@ export function runQqEndpointAdd(
|
|
|
155
158
|
onQrDisplayed: (url) => {
|
|
156
159
|
// QQ 出站当前仅支持纯文本(富媒体未迁移),二维码只能发链接文本
|
|
157
160
|
settle(
|
|
158
|
-
|
|
161
|
+
t(locale, 'scanLink', { url }),
|
|
159
162
|
);
|
|
160
163
|
},
|
|
161
164
|
onQrExpired: async () => {
|
|
162
165
|
try {
|
|
163
|
-
await reply('
|
|
166
|
+
await reply(t(locale, 'qrExpired'));
|
|
164
167
|
} catch {
|
|
165
168
|
// same as settle follow-up: best-effort after command scope ends
|
|
166
169
|
}
|
|
@@ -179,12 +182,12 @@ export function runQqEndpointAdd(
|
|
|
179
182
|
endpointId: finalName,
|
|
180
183
|
appId,
|
|
181
184
|
appSecret,
|
|
182
|
-
sessionKey: '',
|
|
185
|
+
sessionKey: '', locale, cancelCommand,
|
|
183
186
|
},
|
|
184
187
|
'public',
|
|
185
188
|
store,
|
|
186
189
|
) +
|
|
187
|
-
'
|
|
190
|
+
t(locale, 'noInteractiveKind'),
|
|
188
191
|
);
|
|
189
192
|
return;
|
|
190
193
|
}
|
|
@@ -193,40 +196,40 @@ export function runQqEndpointAdd(
|
|
|
193
196
|
endpointId: finalName,
|
|
194
197
|
appId,
|
|
195
198
|
appSecret,
|
|
196
|
-
sessionKey,
|
|
199
|
+
sessionKey, locale, cancelCommand, commandHeads,
|
|
197
200
|
};
|
|
198
201
|
settle(
|
|
199
|
-
|
|
200
|
-
QQ_BOT_KIND_PROMPT,
|
|
202
|
+
t(locale, 'scanned', { id: finalName, prompt: qqBotKindPrompt(locale, cancelCommand) }),
|
|
201
203
|
);
|
|
202
204
|
} catch (error) {
|
|
203
|
-
settle(
|
|
205
|
+
settle(t(locale, 'writeFailed', { error: error instanceof Error ? error.message : String(error) }));
|
|
204
206
|
}
|
|
205
207
|
},
|
|
206
208
|
onFailure: (error) => {
|
|
207
209
|
state.bindFlow = null;
|
|
208
|
-
settle(
|
|
210
|
+
settle(t(locale, 'bindingFailed', { error: error.message }));
|
|
209
211
|
},
|
|
210
212
|
},
|
|
211
|
-
{ source: 'zhin' },
|
|
213
|
+
{ source: 'zhin', locale },
|
|
212
214
|
);
|
|
213
|
-
state.bindFlow = { id: endpointId, stop };
|
|
215
|
+
state.bindFlow = { id: endpointId, stop, locale, cancelCommand, commandHeads };
|
|
214
216
|
});
|
|
215
217
|
}
|
|
216
218
|
|
|
217
219
|
/** `qq endpoint cancel`:中止进行中的绑定或待选 botKind */
|
|
218
|
-
export function runQqEndpointCancel(state: QqRuntimeState): string {
|
|
220
|
+
export function runQqEndpointCancel(state: QqRuntimeState, preference?: Locale): string {
|
|
221
|
+
const locale = resolveLocale(state.pendingBotKind?.locale ?? state.bindFlow?.locale ?? preference);
|
|
219
222
|
if (state.bindFlow) {
|
|
220
223
|
state.bindFlow.stop();
|
|
221
224
|
state.bindFlow = null;
|
|
222
|
-
return
|
|
225
|
+
return t(locale, 'cancelled');
|
|
223
226
|
}
|
|
224
227
|
if (state.pendingBotKind) {
|
|
225
228
|
const name = state.pendingBotKind.endpointId;
|
|
226
229
|
state.pendingBotKind = null;
|
|
227
|
-
return
|
|
230
|
+
return t(locale, 'pendingCancelled', { name });
|
|
228
231
|
}
|
|
229
|
-
return
|
|
232
|
+
return t(locale, 'noFlow');
|
|
230
233
|
}
|
|
231
234
|
|
|
232
235
|
/** `qq endpoint remove <id>`:从 zhin.config.yml 移除对应 endpoints 项 */
|
|
@@ -245,19 +248,21 @@ export async function runQqEndpointRemove(
|
|
|
245
248
|
export const qqEndpointCommands = createEndpointCommands({
|
|
246
249
|
...qqEndpointListSpec,
|
|
247
250
|
fields: [
|
|
248
|
-
{ key: 'appid', required: true, env: true, description: 'QQ 机器人 appid' },
|
|
249
|
-
{ key: 'secret', required: true, env: true, description: 'QQ 机器人 secret' },
|
|
251
|
+
{ key: 'appid', required: true, env: true, description: 'QQ 机器人 appid', descriptionI18n: { en: "QQ bot app ID" } },
|
|
252
|
+
{ key: 'secret', required: true, env: true, description: 'QQ 机器人 secret', descriptionI18n: { en: "QQ bot secret" } },
|
|
250
253
|
],
|
|
251
254
|
running: (use) => use(qqRuntimeStateToken).endpoints.values(),
|
|
252
|
-
listFooter: (use) => busyFooter(use(qqRuntimeStateToken)),
|
|
255
|
+
listFooter: (use, locale) => busyFooter(use(qqRuntimeStateToken), locale),
|
|
256
|
+
addDescriptionI18n: { en: 'Bind a bot through mobile QQ, choose public/private, then save configuration; restart to apply' },
|
|
253
257
|
addDescription:
|
|
254
258
|
'手机 QQ 扫码绑定机器人:确认公域/私域后一次性写入 .env 与 zhin.config.yml(重启生效)',
|
|
255
|
-
bindFlow: ({ id, reply, input, use }) =>
|
|
259
|
+
bindFlow: ({ id, reply, input, use, locale, formatCommand }) =>
|
|
256
260
|
runQqEndpointAdd(
|
|
257
261
|
use(qqRuntimeStateToken),
|
|
258
262
|
id,
|
|
259
263
|
reply,
|
|
260
264
|
use(endpointConfigurationStoreToken),
|
|
261
|
-
input,
|
|
265
|
+
input, locale, formatCommand?.('qq endpoint cancel'),
|
|
266
|
+
['qq endpoint list', 'qq endpoint add', 'qq endpoint remove', 'qq endpoint cancel'].flatMap(path => { const head = formatCommand?.(path); return head ? [head] : []; }),
|
|
262
267
|
),
|
|
263
268
|
}, defineCommand);
|
package/lib/i18n.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const messages: (locale: import("zhin.js").Locale | undefined, key: "bindTaskFailed" | "kindPrompt" | "cancelHint" | "bindingBusy" | "kindBusy" | "endpointSaved" | "existingFlow" | "scanLink" | "qrExpired" | "noInteractiveKind" | "scanned" | "writeFailed" | "bindingFailed" | "cancelled" | "pendingCancelled" | "noFlow" | "kindUnrecognized" | "configFailed", values?: import("zhin.js").MessageValues) => string;
|