feat(plugin): fabric-channel tool (members / join / leave)
One tool, three actions backed by FabricClient channelMembers (GET
/channels/:id/members -> [{userId,bypass}]), joinChannel, and new
leaveChannel (POST /channels/:id/leave).
Verified: client-level smoke against the running guild — members
initial=[tester], after join echo2 present, after leave echo2 gone.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
44
src/tools.ts
44
src/tools.ts
@@ -199,4 +199,48 @@ export function registerFabricTools(
|
||||
}
|
||||
},
|
||||
}));
|
||||
|
||||
// fabric-channel: channel membership (one tool, three actions).
|
||||
api.registerTool((ctx: Ctx) => ({
|
||||
name: 'fabric-channel',
|
||||
description:
|
||||
'Channel membership. action: members (list channel member userIds) | ' +
|
||||
'join (this agent joins the channel) | leave (this agent leaves).',
|
||||
parameters: {
|
||||
type: 'object',
|
||||
additionalProperties: false,
|
||||
required: ['action', 'guildNodeId', 'channelId'],
|
||||
properties: {
|
||||
action: { type: 'string', enum: ['members', 'join', 'leave'] },
|
||||
guildNodeId: { type: 'string' },
|
||||
channelId: { type: 'string' },
|
||||
},
|
||||
},
|
||||
execute: async (p: {
|
||||
action: 'members' | 'join' | 'leave';
|
||||
guildNodeId: string;
|
||||
channelId: string;
|
||||
}) => {
|
||||
const agentId = ctx.agentId;
|
||||
if (!agentId) return { ok: false, error: 'no agent context' };
|
||||
const { guild, token } = await ctxGuild(agentId, p.guildNodeId);
|
||||
const ep = guild.endpoint;
|
||||
switch (p.action) {
|
||||
case 'members': {
|
||||
const members = await client.channelMembers(ep, token, p.channelId);
|
||||
return { ok: true, members };
|
||||
}
|
||||
case 'join': {
|
||||
await client.joinChannel(ep, token, p.channelId);
|
||||
return { ok: true, joined: true };
|
||||
}
|
||||
case 'leave': {
|
||||
await client.leaveChannel(ep, token, p.channelId);
|
||||
return { ok: true, left: true };
|
||||
}
|
||||
default:
|
||||
return { ok: false, error: `unknown action ${String(p.action)}` };
|
||||
}
|
||||
},
|
||||
}));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user