Skip to content

Commit 59a84d9

Browse files
author
linyuan.yang
committed
整理 sendmessage sendfile
1 parent 329a014 commit 59a84d9

4 files changed

Lines changed: 19 additions & 16 deletions

File tree

‎packages/channel.base/src/index.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export { ChannelSessionHandler, ToolCallStatus } from './ChannelSessionHandler';
22
export {
33
ChannelPlugin, ChannelPluginContext, ChannelMessageArgs, InitSessionContext, ChannelSessionInfo,
44
IChannelService, ProcessAIHandler,
5+
ChannelCapability,
56
ConfigFieldType, ConfigField,
67
} from './ChannelPlugin';
78
export { AbstractChatProvider } from './AbstractChatProvider';

‎packages/sbot/prompts/tools/channel/list.txt‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
Discover channels, sessions, and users known to this bot. Reads from the bot's local config / database — no platform API permission required.
22

33
- type="channel": list all configured channels (id, type, name, caps). channel_id is ignored.
4-
- type="session": list sessions in channel_id; defaults to all channels. Entries with current="1" are on the same channel as the current conversation — prefer them when names collide.
4+
- type="session": list sessions in channel_id; defaults to all channels.
55
- type="user": list users in channel_id; defaults to all channels.
66
- type="session_and_user": list both sessions and users (under the same channel_id / name_pattern filter) in a single call. Use when you don't yet know whether to address a session or a user.
77

8+
current="1" on a <session>/<user> means the entry lives on the same channel that THIS conversation is happening on — e.g. if the user is talking to you via Lark right now, every Lark session/user gets current="1". When the user mentions a name without specifying which channel and the name exists on multiple channels, prefer the current="1" entry — it's almost always what they meant.
9+
810
caps (only on <channel>) is a comma-separated capability set. Tokens:
911
text — channel_send_message works on sessions of this channel
1012
file — channel_send_file works on sessions of this channel

‎packages/sbot/src/Channel/ChannelManager.ts‎

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ChannelPlugin, ChannelPluginContext, IChannelService, ChannelSessionInfo } from "channel.base";
1+
import { ChannelPlugin, ChannelPluginContext, IChannelService, ChannelSessionInfo, ChannelCapability } from "channel.base";
22
import { ChannelUserRow, database, type ChannelSessionRow } from "../Core/Database";
33
import { NowDate } from "scorpio.ai";
44
import { Op } from "sequelize";
@@ -267,17 +267,16 @@ export class ChannelManager {
267267
}
268268

269269
/**
270-
* 返回某 channel 当前 service 的发送能力 token 列表(text / file / text_user / file_user)。
271-
* 未启动或类型未知返回空数组。
270+
* 返回某 channel 当前 service 的发送能力。未启动或类型未知返回空数组。
272271
*/
273-
getChannelCapabilities(channelId: string): string[] {
272+
getChannelCapabilities(channelId: string): ChannelCapability[] {
274273
const service = this.services.get(channelId);
275274
if (!service) return [];
276-
const caps: string[] = [];
277-
if (service.sendTextToSession) caps.push('text');
278-
if (service.sendFileToSession) caps.push('file');
279-
if (service.sendTextToUser) caps.push('text_user');
280-
if (service.sendFileToUser) caps.push('file_user');
275+
const caps: ChannelCapability[] = [];
276+
if (service.sendTextToSession) caps.push(ChannelCapability.Text);
277+
if (service.sendFileToSession) caps.push(ChannelCapability.File);
278+
if (service.sendTextToUser) caps.push(ChannelCapability.TextUser);
279+
if (service.sendFileToUser) caps.push(ChannelCapability.FileUser);
281280
return caps;
282281
}
283282

‎packages/sbot/src/Tools/Channel/list.ts‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,13 @@ async function buildSessionsBlock(scope: string, queryChannelId: string | undefi
3535
return `<sessions channel_id="${scope}" count="${filtered.length}" total="${sessions.length}">\n${lines.join('\n')}\n</sessions>`;
3636
}
3737

38-
async function buildUsersBlock(scope: string, queryChannelId: string | undefined, matcher: (s: string) => boolean): Promise<string> {
38+
async function buildUsersBlock(scope: string, queryChannelId: string | undefined, matcher: (s: string) => boolean, currentChannelId?: string): Promise<string> {
3939
const users = await channelDataService.listChannelUsers(queryChannelId);
4040
const filtered = users.filter(u => matcher(u.userName ?? ''));
41-
const lines = filtered.map(u =>
42-
` <user id="${u.id}" channel_id="${u.channelId}" user_id="${u.userId}" name="${escapeAttr(u.userName ?? '')}" />`
43-
);
41+
const lines = filtered.map(u => {
42+
const currentAttr = currentChannelId && u.channelId === currentChannelId ? ' current="1"' : '';
43+
return ` <user id="${u.id}"${currentAttr} channel_id="${u.channelId}" user_id="${u.userId}" name="${escapeAttr(u.userName ?? '')}" />`;
44+
});
4445
return `<users channel_id="${scope}" count="${filtered.length}" total="${users.length}">\n${lines.join('\n')}\n</users>`;
4546
}
4647

@@ -77,12 +78,12 @@ export function createChannelListTool(currentChannelId?: string): StructuredTool
7778
return createSuccessResult(createTextContent(await buildSessionsBlock(scope, queryChannelId, matcher, currentChannelId)));
7879
}
7980
if (type === ChannelListType.User) {
80-
return createSuccessResult(createTextContent(await buildUsersBlock(scope, queryChannelId, matcher)));
81+
return createSuccessResult(createTextContent(await buildUsersBlock(scope, queryChannelId, matcher, currentChannelId)));
8182
}
8283
// ChannelListType.SessionAndUser
8384
const [sessionsBlock, usersBlock] = await Promise.all([
8485
buildSessionsBlock(scope, queryChannelId, matcher, currentChannelId),
85-
buildUsersBlock(scope, queryChannelId, matcher),
86+
buildUsersBlock(scope, queryChannelId, matcher, currentChannelId),
8687
]);
8788
return createSuccessResult(createTextContent(`${sessionsBlock}\n${usersBlock}`));
8889
} catch (e: any) {

0 commit comments

Comments
 (0)