Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

## [Unreleased]

### 修复

- QQ 群聊策略新增群命令保护开关和所有者 OpenID 白名单,配合 Gateway 命令鉴权;保存配置时保留白名单和显式关闭状态。
- QQ 群聊支持仅所有者调用工具,复用所有者白名单并向 harness 透传 gateway 的回合级工具限制;新建 QQ 通道默认开启,旧通道保持原配置。 发布需配套升级包含该能力的 gateway 与 harness,并同步更新依赖锁文件。

## [1.0.3b1] - 2026-10-25

### 新增
Expand Down
3 changes: 3 additions & 0 deletions dashboard/src/api/types/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ export interface QQConfig extends BaseChannelConfig {
history_limit?: number;
history_ttl_seconds?: number;
clear_after_reply?: boolean;
owner_commands_only?: boolean;
owner_tools_only?: boolean;
owner_ids?: string[];
groups?: Record<string, Record<string, unknown>>;
};
}
Expand Down
8 changes: 8 additions & 0 deletions dashboard/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2664,6 +2664,14 @@
"qqQrSuccess": "QQ Bot bound successfully",
"qqQrFailed": "QQ Bot binding failed",
"qqGroupPolicyTitle": "Group chat policy",
"qqGroupContextEnabled": "Enable group message context",
"qqGroupOwnerCommandsOnly": "Only owners can use / commands in group chats",
"qqGroupOwnerCommandsOnlyDesc": "Only allowlisted members can use Octop commands such as /model, /new and /delete in groups. Normal chat is unaffected. Turning off group context keeps this protection enabled.",
"qqGroupOwnerToolsOnly": "Only owners can use tools in group chats",
"qqGroupOwnerToolsOnlyDesc": "Only allowlisted members can invoke agent tools; other members can still chat. Turning off group context keeps this restriction enabled.",
"qqGroupOwnerIds": "Owner allowlist",
"qqGroupOwnerIdsHelp": "Enter QQ group member IDs (not QQ numbers). Leaving this empty prevents all group members from using protected / commands and tools.",
"qqGroupOwnerIdsPlaceholder": "Enter a member ID and press Enter",
"qqGroupPolicyDescription": "Control which group messages the bot can use and when they start an agent reply.",
"qqGroupVisibility": "Visible group messages",
"qqGroupVisibilityAuto": "Auto",
Expand Down
8 changes: 8 additions & 0 deletions dashboard/src/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -2664,6 +2664,14 @@
"qqQrSuccess": "QQ 机器人绑定成功",
"qqQrFailed": "QQ 机器人绑定失败",
"qqGroupPolicyTitle": "群聊策略",
"qqGroupContextEnabled": "启用群消息上下文",
"qqGroupOwnerCommandsOnly": "仅所有者可在群聊中使用 / 命令",
"qqGroupOwnerCommandsOnlyDesc": "仅白名单成员可在群内使用 /model、/new、/delete 等 Octop 命令,普通聊天不受影响。关闭群消息上下文不会关闭此保护。",
"qqGroupOwnerToolsOnly": "仅所有者可在群聊中调用工具",
"qqGroupOwnerToolsOnlyDesc": "仅白名单成员可以调用专家工具,其他成员仍可聊天。关闭群消息上下文不会关闭此限制。",
"qqGroupOwnerIds": "所有者白名单",
"qqGroupOwnerIdsHelp": "请填写 QQ 群成员 ID(不是 QQ 号),留空则所有群成员都无法使用受保护的 / 命令和工具。",
"qqGroupOwnerIdsPlaceholder": "输入成员 ID,按回车添加",
"qqGroupPolicyDescription": "控制机器人能看到哪些群消息,以及什么时候启动专家回复。",
"qqGroupVisibility": "群消息可见范围",
"qqGroupVisibilityAuto": "自动适配",
Expand Down
132 changes: 132 additions & 0 deletions dashboard/src/pages/Agent/Channels/ChannelsPanel.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* - saving a new channel sends exactly one POST (no PATCH churn)
*/

import "@testing-library/jest-dom/vitest";
import { describe, it, expect, vi, beforeEach } from "vitest";
import { render, screen, waitFor } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
Expand Down Expand Up @@ -202,6 +203,137 @@ describe("<ChannelsPanel /> create-flow default", () => {
expectBefore(displaySettings, groupPolicy);
});

async function openQqEditDrawer(groupContext?: Record<string, unknown>) {
const row = { id: "qq-policy", kind: "qq", name: "qq", enabled: true };
api.mockImplementation(async (url, init) => {
if (init?.method === "PATCH") return row;
if (url.endsWith("/qq-policy")) {
return {
...row,
config: {
app_id: "offline-app",
secret: "offline-secret",
group_context: groupContext,
},
};
}
return [row];
});
render(<ChannelsPanel agentId="ag1" />);
await userEvent.click((await screen.findAllByText("channels.label_qq"))[0]);
}

it.each([undefined, true, false])(
"round-trips QQ command protection %s and the owner allowlist",
async (ownerOnly) => {
await openQqEditDrawer({
enabled: true,
owner_ids: ["owner-1"],
...(ownerOnly === undefined ? {} : { owner_commands_only: ownerOnly }),
});
const toggle = await screen.findByLabelText(
"channels.qqGroupOwnerCommandsOnly",
);
await waitFor(() => {
expect(toggle.getAttribute("aria-checked")).toBe(
String(ownerOnly ?? true),
);
expect(screen.getByText("owner-1")).toBeInTheDocument();
});
const owners = screen.getByRole("combobox", {
name: "channels.qqGroupOwnerIds",
});
if (ownerOnly === false) expect(owners).toBeDisabled();
else expect(owners).toBeEnabled();
await userEvent.click(
screen.getByRole("button", { name: "common.save" }),
);
await waitFor(() => {
const patch = api.mock.calls.find(
([, init]) => init?.method === "PATCH",
);
expect(patch).toBeDefined();
expect(
JSON.parse(String(patch![1]!.body)).config.group_context,
).toMatchObject({
enabled: true,
owner_commands_only: ownerOnly ?? true,
owner_ids: ["owner-1"],
});
});
},
);

it("keeps the shared allowlist enabled when only tool protection is on", async () => {
await openQqEditDrawer({
enabled: true,
owner_commands_only: false,
owner_tools_only: true,
owner_ids: ["owner-1"],
});
const owners = await screen.findByRole("combobox", {
name: "channels.qqGroupOwnerIds",
});
expect(owners).toBeEnabled();
await userEvent.click(
screen.getByLabelText("channels.qqGroupOwnerToolsOnly"),
);
expect(owners).toBeDisabled();
await userEvent.click(screen.getByRole("button", { name: "common.save" }));
await waitFor(() => {
const patch = api.mock.calls.find(([, init]) => init?.method === "PATCH");
expect(
JSON.parse(String(patch![1]!.body)).config.group_context,
).toMatchObject({
owner_commands_only: false,
owner_tools_only: false,
owner_ids: ["owner-1"],
});
});
});

it("enables tool protection for new QQ channels", async () => {
render(<ChannelsPanel agentId="ag1" />);
await userEvent.click((await screen.findAllByText("channels.label_qq"))[0]);
expect(
await screen.findByLabelText("channels.qqGroupOwnerToolsOnly"),
).toBeChecked();
});

it("hides QQ command controls while group context is off", async () => {
await openQqEditDrawer({ enabled: false, owner_ids: ["stored-owner"] });
expect(
screen.queryByLabelText("channels.qqGroupOwnerCommandsOnly"),
).not.toBeInTheDocument();
expect(
screen.queryByLabelText("channels.qqGroupOwnerToolsOnly"),
).not.toBeInTheDocument();
expect(
screen.queryByRole("combobox", { name: "channels.qqGroupOwnerIds" }),
).not.toBeInTheDocument();

await userEvent.click(
screen.getByLabelText("channels.qqGroupContextEnabled"),
);
const toggle = await screen.findByLabelText(
"channels.qqGroupOwnerCommandsOnly",
);
expect(toggle).toBeChecked();
expect(await screen.findByText("stored-owner")).toBeInTheDocument();
await userEvent.click(screen.getByRole("button", { name: "common.save" }));
await waitFor(() => {
const patch = api.mock.calls.find(([, init]) => init?.method === "PATCH");
expect(patch).toBeDefined();
expect(
JSON.parse(String(patch![1]!.body)).config.group_context,
).toMatchObject({
enabled: true,
owner_commands_only: true,
owner_ids: ["stored-owner"],
});
});
});

async function openTelegramCreateDrawer() {
render(<ChannelsPanel agentId="ag1" />);
// Telegram is collapsed behind "更多通道" until expanded.
Expand Down
7 changes: 6 additions & 1 deletion dashboard/src/pages/Agent/Channels/ChannelsPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,12 @@ export default function ChannelsPanel({ agentId }: ChannelsPanelProps) {
...DEFAULT_CHANNEL_DISPLAY_CONFIG,
...(kind === "discord" ? { allow_all_channels: true } : {}),
...(kind === "qq"
? { group_context: { ...DEFAULT_QQ_GROUP_CONTEXT_CONFIG } }
? {
group_context: {
...DEFAULT_QQ_GROUP_CONTEXT_CONFIG,
owner_tools_only: true,
},
}
: {}),
};
setDrawerInitialValues(defaults);
Expand Down
59 changes: 57 additions & 2 deletions dashboard/src/pages/Agent/Channels/components/ChannelDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,14 @@ function QqGroupContextPolicyFields({
["group_context", "activation"],
form,
);
const watchedOwnerCommandsOnly = Form.useWatch(
["group_context", "owner_commands_only"],
form,
);
const watchedOwnerToolsOnly = Form.useWatch(
["group_context", "owner_tools_only"],
form,
);
const policy = normalizeQqGroupContextConfig(
form.getFieldValue("group_context"),
);
Expand All @@ -318,6 +326,14 @@ function QqGroupContextPolicyFields({
policy.visibility) as QqGroupVisibility;
const activation = (watchedActivation ??
policy.activation) as QqGroupActivation;
const ownerCommandsOnly =
typeof watchedOwnerCommandsOnly === "boolean"
? watchedOwnerCommandsOnly
: policy.owner_commands_only;
const ownerToolsOnly =
typeof watchedOwnerToolsOnly === "boolean"
? watchedOwnerToolsOnly
: policy.owner_tools_only;

const updatePolicy = (patch: Partial<QqGroupContextConfig>) => {
form.setFieldValue("group_context", {
Expand All @@ -337,7 +353,11 @@ function QqGroupContextPolicyFields({

return (
<div className={styles.qqGroupPolicy}>
<div className={styles.qqGroupPolicyHeader}>
<div
className={`${styles.qqGroupPolicyHeader} ${
enabled ? "" : styles.qqGroupPolicyHeaderCollapsed
}`}
>
<div>
<div className={styles.qqGroupPolicyTitle}>
{t("channels.qqGroupPolicyTitle")}
Expand All @@ -351,7 +371,7 @@ function QqGroupContextPolicyFields({
valuePropName="checked"
noStyle
>
<Switch />
<Switch aria-label={t("channels.qqGroupContextEnabled")} />
</Form.Item>
</div>

Expand Down Expand Up @@ -420,9 +440,44 @@ function QqGroupContextPolicyFields({
</Form.Item>
</div>

<Form.Item
name={["group_context", "owner_commands_only"]}
label={t("channels.qqGroupOwnerCommandsOnly")}
tooltip={t("channels.qqGroupOwnerCommandsOnlyDesc")}
valuePropName="checked"
>
<Switch />
</Form.Item>
<Form.Item
name={["group_context", "owner_tools_only"]}
label={t("channels.qqGroupOwnerToolsOnly")}
tooltip={t("channels.qqGroupOwnerToolsOnlyDesc")}
valuePropName="checked"
>
<Switch />
</Form.Item>
<Form.Item
name={["group_context", "owner_ids"]}
label={t("channels.qqGroupOwnerIds")}
extra={
<div className={styles.qqGroupPolicyDescription}>
{t("channels.qqGroupOwnerIdsHelp")}
</div>
}
>
<Select
mode="tags"
open={false}
suffixIcon={null}
disabled={!ownerCommandsOnly && !ownerToolsOnly}
tokenSeparators={[",", ",", " ", "\n"]}
placeholder={t("channels.qqGroupOwnerIdsPlaceholder")}
/>
</Form.Item>
<Form.Item
name={["group_context", "clear_after_reply"]}
label={t("channels.qqGroupClearAfterReply")}
className={styles.qqGroupPolicyClearAfterReply}
tooltip={t("channels.qqGroupClearAfterReplyDesc")}
valuePropName="checked"
>
Expand Down
32 changes: 31 additions & 1 deletion dashboard/src/pages/Agent/Channels/components/constants.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { describe, expect, it } from "vitest";

import {
applyQqChannelSaveConfig,
DEFAULT_CHANNEL_DISPLAY_CONFIG,
DEFAULT_QQ_GROUP_CONTEXT_CONFIG,
normalizeQqGroupContextConfig,
partitionChannelKeys,
Expand Down Expand Up @@ -100,6 +99,37 @@ describe("normalizeQqGroupContextConfig", () => {
});
});

it("protects legacy group configs and preserves explicit opt-out", () => {
expect(normalizeQqGroupContextConfig({ enabled: false })).toMatchObject({
enabled: false,
owner_commands_only: true,
owner_tools_only: false,
owner_ids: [],
});
expect(
normalizeQqGroupContextConfig({ owner_commands_only: false }),
).toMatchObject({ owner_commands_only: false });
expect(
normalizeQqGroupContextConfig({ owner_tools_only: true }),
).toMatchObject({ owner_tools_only: true });
expect(
normalizeQqGroupContextConfig({ owner_tools_only: false }),
).toMatchObject({ owner_tools_only: false });
});

it("normalizes owner IDs without losing per-group authorization overrides", () => {
const groups = { "group-1": { owner_ids: ["group-owner"] } };
expect(
normalizeQqGroupContextConfig({
owner_ids: [" owner-1 ", "owner-2", "owner-1", "", 123],
groups,
}),
).toMatchObject({ owner_ids: ["owner-1", "owner-2"], groups });
expect(
normalizeQqGroupContextConfig({ owner_ids: "owner-1, owner-2\nowner-1" }),
).toMatchObject({ owner_ids: ["owner-1", "owner-2"] });
});

it("forces mention-only visibility to discard passive history", () => {
expect(
normalizeQqGroupContextConfig({
Expand Down
Loading
Loading