Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions changelog.d/563-share-with-friend-missing-tool.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Sharing a Bot with a friend on a Bot Social server that lacks `grant_bot_to_friend` now tries the REST route and, when that is missing too, says *Bot Social needs an update to share with a friend. Invite links still work.* instead of showing the raw `MCP error -32602: Tool grant_bot_to_friend not found` ([#563](https://github.com/ThinkFlowLab/FlyBot/issues/563)).
2 changes: 1 addition & 1 deletion docs/subsystems/social.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The social plugin talks to a [Bot Social](https://github.com/Birfy/bot-social) s

Bot Social plugin for chatting with friends' Bots (send middleware `social` with per-home approval) lives entirely under `plugins/social/`. Inbound friend messages arrive immediately; outbound drafts the server holds (`pending_approval`) are listed on `social/status` and approved in the open chat (`flybot.session.dock`). The social sidebar strip shows a badge and a one-line jump list. The same queue is also attached to a native shared room via `flybot.roomApprovals.setProvider`, so an invited owner sees “N to approve” in that room without auto-send.

Face-to-face rooms (#83, #92) also live here: the primary entry is the sidebar **+** menu (slot `flybot.new-chat.action` on the core new-chat picker, after New group chat; `label` / `hint` use the same `t()` map). **Face-to-face room** and **Add friend** are those rows (copying an invite and your own handle live inside Add friend); the social strip has no **+ Add** button. **Face-to-face room** opens the same screen (pick one or more local Bots, six-digit number, live waiting room that shows the code, **Enter chat**). The pick list and waiting roster draw each Bot with the host `BotAvatar` (team roster look for yours; a friend's Bot uses its published look or a handle-seeded look, plus any avatar face-room `members[]` carries). Waiting-room and picker Bots are a wrapping tile grid (avatar on top, name centered below; yours a tiny accent dot; waiting tiles use the server owner label, e.g. `Chief · BoxB`); **Leave** and **Enter chat** share a fixed footer while a long grid scrolls under the countdown. The plugin calls Bot Social REST (`POST /v1/face-rooms/join`, poll `GET /v1/face-rooms/{id}?after=`, start/leave/messages) with the stored connector token and hosts the result as a native room through `flybot.rooms` (`origin: 'face-to-face'`). Those face-room routes accept a connector token; owner settings do not (`GET`/`PATCH /v1/me` returns 403 `connector_token_rest_forbidden`). Peer text is fenced; `pending_approval` drafts of kind `face_room_message` use the in-chat Approve / Reject path. **Auto-send** for face rooms is one compact checkbox (tooltip) on the open room's overview, via MCP `whoami` (read) and `set_auto_approve { auto_approve_face_rooms }` (write; the owner's click requests and uses `confirm_code` in the same step); default off. A friend's Bot in the room card, waiting grid, **main sidebar row**, and core group overview uses the host `BotAvatar` (published look, optional member `avatar`, else a handle-seeded look). **Sharing → Copy invite link** creates a per-Bot grant when the friend accepts; **Share with a friend** (#500) lists current friends who do not have this Bot yet and grants it in one click (Bot Social `grant_bot_to_friend`, companion Birfy/bot-social#34) without an invite link; **People with access** lists who has that Bot, in which groups, and **Revoke**. There is no published toggle. Bringing my own Bot by number is an implicit room-scoped grant: if it has no identity yet, join registers it room-only (`add_home_member`) and revokes that identity (`remove_home_member`) when it leaves its last face room. Friends' Bots lists only Bots granted to me. Held replies show in the chat (owner Approve / Reject). **Remove this Bot** declines that grant on Bot Social (`decline_bot_grant`) so it leaves the owner's Manage access; an older server falls back to a local hide. The row drops immediately; room leave and a roster refresh continue in the background. A local hide is forgotten only after two consecutive successful `list_remote_bots` results without that handle, or an explicit re-share / `regranted` join. Hidden, gone, and home-level remotes stay out of `flybot.remote.publish` and the new-chat picker. Friends' Bots paints a cached roster immediately and refreshes in the background (keep-alive HTTP, parallel mount calls).
Face-to-face rooms (#83, #92) also live here: the primary entry is the sidebar **+** menu (slot `flybot.new-chat.action` on the core new-chat picker, after New group chat; `label` / `hint` use the same `t()` map). **Face-to-face room** and **Add friend** are those rows (copying an invite and your own handle live inside Add friend); the social strip has no **+ Add** button. **Face-to-face room** opens the same screen (pick one or more local Bots, six-digit number, live waiting room that shows the code, **Enter chat**). The pick list and waiting roster draw each Bot with the host `BotAvatar` (team roster look for yours; a friend's Bot uses its published look or a handle-seeded look, plus any avatar face-room `members[]` carries). Waiting-room and picker Bots are a wrapping tile grid (avatar on top, name centered below; yours a tiny accent dot; waiting tiles use the server owner label, e.g. `Chief · BoxB`); **Leave** and **Enter chat** share a fixed footer while a long grid scrolls under the countdown. The plugin calls Bot Social REST (`POST /v1/face-rooms/join`, poll `GET /v1/face-rooms/{id}?after=`, start/leave/messages) with the stored connector token and hosts the result as a native room through `flybot.rooms` (`origin: 'face-to-face'`). Those face-room routes accept a connector token; owner settings do not (`GET`/`PATCH /v1/me` returns 403 `connector_token_rest_forbidden`). Peer text is fenced; `pending_approval` drafts of kind `face_room_message` use the in-chat Approve / Reject path. **Auto-send** for face rooms is one compact checkbox (tooltip) on the open room's overview, via MCP `whoami` (read) and `set_auto_approve { auto_approve_face_rooms }` (write; the owner's click requests and uses `confirm_code` in the same step); default off. A friend's Bot in the room card, waiting grid, **main sidebar row**, and core group overview uses the host `BotAvatar` (published look, optional member `avatar`, else a handle-seeded look). **Sharing → Copy invite link** creates a per-Bot grant when the friend accepts; **Share with a friend** (#500) lists current friends who do not have this Bot yet and grants it in one click (Bot Social `grant_bot_to_friend`, companion Birfy/bot-social#34) without an invite link; a server without that tool tries the REST route `POST /v1/bots/:id/grants/to-friend` and, when it 404s too, says *Bot Social needs an update to share with a friend. Invite links still work.* instead of the raw MCP error (the production `MCP error -32602: Tool … not found` wording counts as an unknown tool, #563); **People with access** lists who has that Bot, in which groups, and **Revoke**. There is no published toggle. Bringing my own Bot by number is an implicit room-scoped grant: if it has no identity yet, join registers it room-only (`add_home_member`) and revokes that identity (`remove_home_member`) when it leaves its last face room. Friends' Bots lists only Bots granted to me. Held replies show in the chat (owner Approve / Reject). **Remove this Bot** declines that grant on Bot Social (`decline_bot_grant`) so it leaves the owner's Manage access; an older server falls back to a local hide. The row drops immediately; room leave and a roster refresh continue in the background. A local hide is forgotten only after two consecutive successful `list_remote_bots` results without that handle, or an explicit re-share / `regranted` join. Hidden, gone, and home-level remotes stay out of `flybot.remote.publish` and the new-chat picker. Friends' Bots paints a cached roster immediately and refreshes in the background (keep-alive HTTP, parallel mount calls).

## Owns

Expand Down
7 changes: 6 additions & 1 deletion plugins/social/src/mcp-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
const lib = parsed.protocol === 'http:' ? http : https
const agent = init.agent ?? agentFor(url)
const method = String(init.method ?? 'GET').toUpperCase()
const headers = { ...(init.headers ?? {}) }

Check warning on line 44 in plugins/social/src/mcp-client.js

View workflow job for this annotation

GitHub Actions / plugins (social)

unicorn(no-useless-fallback-in-spread)

Empty fallbacks in spreads are unnecessary
const signal = init.signal
return new Promise((resolve, reject) => {
const req = lib.request(parsed, { method, headers, agent }, (res) => {
Expand Down Expand Up @@ -76,7 +76,7 @@
const list = [...items]
if (list.length === 0) return []
const cap = Math.max(1, Math.min(limit || GRANT_CONCURRENCY, list.length))
const out = new Array(list.length)

Check warning on line 79 in plugins/social/src/mcp-client.js

View workflow job for this annotation

GitHub Actions / plugins (social)

unicorn(no-new-array)

Do not use `new Array(singleArgument)`.
let next = 0
async function worker() {
for (;;) {
Expand Down Expand Up @@ -157,7 +157,12 @@
const code = String(error?.code ?? '')
const blob = `${code} ${text}`
if (/grant_not_found/i.test(blob)) return false
return code === 'unknown' || /unknown tool|no tool|method not found|unrecognized tool/i.test(text)
if (code === 'unknown' || /unknown tool|no tool|method not found|unrecognized tool|no such tool/i.test(text)) return true
// #563: the production Bot Social answers a missing tool with JSON-RPC -32602 and
// "Tool <name> not found". Without this the raw MCP string reaches the UI and the REST
// fallback never runs.
if (/tool\s+['`"]?[\w.-]+['`"]?\s+(?:is\s+)?not found/i.test(text)) return true
return /-32602\b/.test(text) && /\btool\b/i.test(text) && /not found|no such/i.test(text)
}

export function isGrantNotFound(error) {
Expand Down
61 changes: 61 additions & 0 deletions plugins/social/test/social.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8406,6 +8406,67 @@ test('#500: share-with-friend surfaces a clear error when Bot Social lacks grant
assert.match(String(result.error?.message || result.error), /needs an update to share with a friend|Invite links still work/i)
})

test('#563: production "Tool <name> not found" (-32602) is unknown-tool and degrades to the unavailable message', async (t) => {
// The production Bot Social answers a missing tool with JSON-RPC -32602 and
// "Tool <name> not found"; the #500 fallback only knew "unknown tool"/"no tool".
assert.equal(isUnknownTool(Object.assign(new Error('MCP error -32602: Tool grant_bot_to_friend not found'), { code: 'mcp' })), true)
assert.equal(isUnknownTool(new Error('Tool list_x not found')), true)
assert.equal(isUnknownTool(new Error('MCP error -32602: relationship not found')), false, 'invalid params that are not a missing tool stay an error')
{
// The API: the MCP call reports the production wording, so the REST fallback must run and,
// when the route is absent as well (the mock answers 404), report `unavailable`.
const server = mockServer()
const baseFetch = server.fetch
server.fetch = async (url, init) => {
const body = init.body ? JSON.parse(init.body) : {}
if (body?.params?.name === 'grant_bot_to_friend') {
return new Response(JSON.stringify({
jsonrpc: '2.0', id: body.id,
result: { isError: true, content: [{ type: 'text', text: JSON.stringify({ code: 'mcp', message: 'MCP error -32602: Tool grant_bot_to_friend not found' }) }] },
}), { status: 200 })
}
return baseFetch(url, init)
}
const api = createSocialApi({ server: 'https://s', token: 'owner-token', fetch: server.fetch })
const result = await api.grantBotToFriend({ botId: 'm1', friendHome: '@bob.home' })
assert.equal(result.unavailable, true)
assert.equal(server.calls.some(c => c.name === 'REST POST /v1/bots/grants/to-friend'), true, 'the REST fallback runs before giving up')
}
{
// The handler: the user sees the actionable message, never the raw MCP string.
const { ctx, home, call, stop } = await team()
t.after(stop)
const server = mockServer()
server.tools.list_friends = () => ({
friends: [{ relationship_id: 'r1', status: 'active', peer: { handle: '@bob.home', owner_display_name: 'Bob' } }],
pending_incoming: [], pending_outgoing: [],
})
const baseFetch = server.fetch
server.fetch = async (url, init) => {
const body = init.body ? JSON.parse(init.body) : {}
if (body?.params?.name === 'grant_bot_to_friend') {
return new Response(JSON.stringify({
jsonrpc: '2.0', id: body.id,
result: { isError: true, content: [{ type: 'text', text: JSON.stringify({ code: 'mcp', message: 'MCP error -32602: Tool grant_bot_to_friend not found' }) }] },
}), { status: 200 })
}
return baseFetch(url, init)
}
const social = await startSocial(ctx.flybot, {
server: 'https://social.test', credentialsPath: join(home, 'flybot-social.json'),
fetch: server.fetch, inboxPollMs: 0,
})
t.after(() => social.dispose())
await settle()
const chief = ctx.flybot.bot.list().find(b => b.isMain) || ctx.flybot.bot.list()[0]
await call('flybot/social/create-invite', { botId: chief.id })
const result = await call('flybot/social/share-with-friend', { botId: chief.id, home: '@bob.home' })
assert.equal(result.ok, false)
assert.match(String(result.error?.message || result.error), /needs an update to share with a friend|Invite links still work/i)
assert.doesNotMatch(String(result.error?.message || result.error), /-32602|MCP error/i)
}
})

test('#500: Share with a friend lists candidates and shares on click', async () => {
const calls = []
const friends = [{ home: '@bob.home', name: 'Bob', ownerId: 'o-bob' }]
Expand Down
Loading