Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
12 changes: 7 additions & 5 deletions docs/developers/qwen-serve-protocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -794,19 +794,21 @@ Runtime actions are strict-gated `POST` requests to
worker owned by the resolved workspace.

Pairing management is available only for instances configured with the
`pairing` sender policy:
`pairing` sender policy or group policy:

- `GET .../channels/:name/pairing-requests`
- `POST .../channels/:name/pairing-requests/approve` with `{ "code": "..." }`
- `GET .../channels/:name/pairing-approvals`
- `DELETE .../channels/:name/pairing-approvals` with
`{ "senderId": "..." }`
either `{ "senderId": "..." }` or `{ "groupId": "..." }`

All pairing routes require a bearer token and use `Cache-Control: no-store`.
Requests, approvals, and revocations are scoped to the selected Channel
instance and workspace. The approvals snapshot contains sender IDs because the
allowlist does not persist sender display names. Revoking an unknown sender
returns `404 channel_pairing_approval_not_found`.
instance and workspace. Pending requests include a typed user or group subject;
group requests also retain the sender who initiated the request. Approval
snapshots contain `senderIds` and `groupIds` because allowlists do not persist
display names. Revoking an unknown user or group returns
`404 channel_pairing_approval_not_found`.

### Channel delivery and Notify

Expand Down
25 changes: 19 additions & 6 deletions docs/users/features/channels/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Channels are configured under the `channels` key in `settings.json`. Each channe
| `approvalMode` | No | Tool approval mode for channel sessions. Unattended webhook tasks require `yolo`; the setting applies to every session on the channel |
| `instructions` | No | Custom instructions prepended to the first message of each session |
| `webhooks` | No | Webhook sources and delivery targets for daemon-managed channels. See [Webhook-triggered tasks](#webhook-triggered-tasks) |
| `groupPolicy` | No | Group chat access: `disabled` (default), `allowlist`, or `open`. See [Group Chats](#group-chats) |
| `groupPolicy` | No | Group chat access: `disabled` (default), `allowlist`, `pairing`, or `open`. See [Group Chats](#group-chats) |
| `dmPolicy` | No | Private/DM access: `open` (default) or `disabled` (silently drop all DMs). Useful for group-only bots |
| `groupHistoryLimit` | No | Opt-in group history backfill. `0` or omitted disables it. A positive number persists that many authorized, unmentioned group messages for the next bot mention/reply. |
| `groups` | No | Per-group settings. Keys are group chat IDs or `"*"` for defaults. See [Group Chats](#group-chats) |
Expand Down Expand Up @@ -206,16 +206,29 @@ Run these from the channel's workspace directory (or pass `--cwd <dir>`) — pai

## Group Chats

By default, the bot only works in direct messages. To enable group chat support, set `groupPolicy` to `"allowlist"` or `"open"`.
By default, the bot only works in direct messages. To enable group chat support, set `groupPolicy` to `"allowlist"`, `"pairing"`, or `"open"`.

### Group Policy

Controls whether the bot participates in group chats at all:

- **`disabled`** (default) — The bot ignores all group messages. Safest option.
- **`allowlist`** — The bot only responds in groups explicitly listed in `groups` by chat ID. The `"*"` key provides default settings but does **not** act as a wildcard allow.
- **`pairing`** — A deliberate mention or reply from an unknown group creates one pairing request for the group. Once approved, every member can use the bot in that group; `senderPolicy` continues to control direct messages.
- **`open`** — The bot responds in all groups it's added to. Use with caution.

Approve a group with the same CLI command used for user pairing. The pending
request identifies the group and the member who initiated it:

```bash
qwen channel pairing approve my-channel <CODE>
```

Group approvals are stored by stable chat ID in the channel's workspace scope.
An unmentioned message never creates a group pairing request, even when a group
sets `requireMention` to `false`; after approval, the configured mention policy
applies normally.

### Mention Gating

In groups, the bot requires an `@mention` or a reply to one of its messages by default. This prevents the bot from responding to every message in a group chat.
Expand Down Expand Up @@ -262,18 +275,18 @@ By default, Qwen ignores unmentioned group messages and does not store them as s

- Omitted or `0` disables backfill.
- Group-level `groupHistoryLimit` overrides the channel-level value.
- Only messages from authorized senders are persisted.
- Only messages from authorized senders, or members of an approved paired group, are persisted.
- Messages rejected by `groupPolicy` or group allowlist are not persisted.
- Pending group history is stored as local JSONL under `~/.qwen/channels/<channel-name>-group-history.jsonl` or `$QWEN_HOME/channels/<channel-name>-group-history.jsonl`.
- Cached messages are injected as untrusted context on the next real trigger and are not written as standalone session turns.

### How group messages are evaluated

```
1. groupPolicy — is this group allowed? (no → ignore)
2. dmPolicy — is this DM allowed? (disabled → ignore)
1. groupPolicy — is this group disabled, listed, paired, or open? (no → ignore/pairing flow)
2. dmPolicy — is this DM allowed? (disabled → ignore)
3. requireMention — was the bot mentioned/replied to? (no → ignore)
4. senderPolicy — is this sender approved? (no → pairing flow)
4. senderPolicy — is this sender approved? (skipped for a paired group; otherwise no → user pairing flow)
5. Route to session
```

Expand Down
19 changes: 12 additions & 7 deletions packages/channels/base/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ Everything between `handleInbound()` and `sendMessage()` is handled by the base
| `ChannelPlugin` | Plugin factory interface (what you export) |
| `Envelope` | Normalized inbound message format |
| `SenderPolicy` | `'allowlist' \| 'pairing' \| 'open'` |
| `GroupPolicy` | `'disabled' \| 'allowlist' \| 'open'` |
| `GroupPolicy` | `'disabled' \| 'allowlist' \| 'pairing' \| 'open'` |
| `SessionScope` | `'user' \| 'thread' \| 'single'` |
| `GroupConfig` | Per-group settings (e.g. `requireMention`) |
| `SessionTarget` | Maps a session back to its channel/sender/chat |
Expand Down Expand Up @@ -278,19 +278,20 @@ constructor(policy: SenderPolicy, allowedUsers?: string[], pairingStore?: Pairin
### GroupGate

```typescript
constructor(policy?: GroupPolicy, groups?: Record<string, GroupConfig>)
constructor(policy?: GroupPolicy, groups?: Record<string, GroupConfig>, pairingStore?: PairingStore)
```

| Method | Description |
| ----------------- | ---------------------------------------------------------------------------------------------- |
| `check(envelope)` | Returns `{ allowed: boolean, reason?: 'disabled' \| 'not_allowlisted' \| 'mention_required' }` |
| Method | Description |
| ----------------- | -------------------------------------------------------------- |
| `check(envelope)` | Returns the group policy decision and an optional pairing code |

**Policy behavior:**

| Policy | Behavior |
| ----------- | ---------------------------------------- |
| `disabled` | All group messages rejected |
| `allowlist` | Only groups listed in config are allowed |
| `pairing` | A group must be approved once by chat ID |
| `open` | All groups allowed |

When `requireMention` is `true` (default), group messages are only processed if the bot is @mentioned or the message is a reply to the bot.
Expand All @@ -301,16 +302,20 @@ When `requireMention` is `true` (default), group messages are only processed if
constructor(channelName: string, workspaceCwd?: string)
```

Persists pairing state to `{channelName}-pairing.json` and `{channelName}-allowlist.json`. With `workspaceCwd` (what `ChannelBase` passes — the channel's `cwd`), the files live under the workspace-scoped directory `~/.qwen/channels/<workspace-scope>/` so two workspaces reusing the same channel name never share pairing requests or allowlist entries. Without it, the legacy global `~/.qwen/channels/` layout is used. The first time a given (workspace, channel) pair is constructed, existing legacy global files are copied in once (grandfathering) so already-approved senders stay approved; a per-channel `<channel>.migrated` sentinel in the scope directory marks that decision, after which legacy files are never consulted again for that channel. Channel names are URI-encoded in file names, so a name containing path separators cannot escape the scope directory. `revoke(senderId)` removes the sender only from this store's allowlist and never mutates the legacy global baseline.
Persists pending pairing state to `{channelName}-pairing.json`, user approvals to `{channelName}-allowlist.json`, and group approvals to `{channelName}-groups.json`. With `workspaceCwd` (what `ChannelBase` passes — the channel's `cwd`), the files live under the workspace-scoped directory `~/.qwen/channels/<workspace-scope>/` so two workspaces reusing the same channel name never share pairing requests or allowlist entries. Without it, the legacy global `~/.qwen/channels/` layout is used. The first time a given (workspace, channel) pair is constructed, existing legacy global files are copied in once (grandfathering) so already-approved senders stay approved; a per-channel `<channel>.migrated` sentinel in the scope directory marks that decision, after which legacy files are never consulted again for that channel. Channel names are URI-encoded in file names, so a name containing path separators cannot escape the scope directory. `revoke(senderId)` removes the sender only from this store's allowlist and never mutates the legacy global baseline.

| Method | Description |
| ------------------------------------- | --------------------------------------------------------------------------------------------------------- |
| `createRequest(senderId, senderName)` | Generate an 8-char pairing code (or return existing). Returns `null` if 3 pending requests already exist. |
| `approve(code)` | Approve a pairing request, adds sender to allowlist. Returns the request or `null`. |
| `createGroupRequest(...)` | Generate a request keyed by stable group ID and record its initiating sender. |
| `approve(code)` | Approve a user or group request and update its corresponding allowlist. |
| `isApproved(senderId)` | Check if sender is in the approved allowlist |
| `isGroupApproved(groupId)` | Check if a group is approved |
| `listPending()` | Get active (non-expired) pending requests |
| `getAllowlist()` | Get approved sender IDs |
| `getGroupAllowlist()` | Get approved group IDs |
| `revoke(senderId)` | Remove an approved sender. Returns whether the sender was present. |
| `revokeGroup(groupId)` | Remove an approved group. Returns whether the group was present. |

## Envelope

Expand Down
Loading
Loading