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
2 changes: 1 addition & 1 deletion docs/CONNECTED_TOOLS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Related #10, #6, #11. Status: implemented, with **synthetic/mock** tests only.
No real Composio key, real model or live provider mutation has been used to
verify this. CI passing is not Teamily parity or real-vendor verification.

Connected app tools run in the user's own DS-Bot. The FlyBot connectors feature exposes the native `ot-apps` capability and handles the owner's one-time approvals. See [the native tool server](../runtime/flybot-workspace-web/features/connectors/tool-server.js).
Connected app tools run in the user's own DS-Bot through the native `ot-apps` capability. Where that capability is mounted, GitHub tools discovered through the user's active Composio connection run automatically within the account's granted permissions. This applies to both reads and writes in private and group chats. Other connected app tools continue to use one-time owner approval. Settings shows the execution history. See [the native tool server](../runtime/flybot-workspace-web/features/connectors/tool-server.js).

## Historical management task protocol

Expand Down
2 changes: 1 addition & 1 deletion docs/inventory/visible-controls.json
Original file line number Diff line number Diff line change
Expand Up @@ -2547,7 +2547,7 @@
{"source": "flybot_workspace/static/settings/app.mjs", "line": 657, "construction": "const confirm = document.createElement('button');", "execution_profile": "settings", "verification": "unverified dynamic construction site; conditional instances require execution"},
{"source": "flybot_workspace/static/settings/app.mjs", "line": 865, "construction": "const button = document.createElement('button');", "execution_profile": "settings", "verification": "unverified dynamic construction site; conditional instances require execution"},
{"source": "flybot_workspace/static/settings/app.mjs", "line": 1019, "construction": "const remove = document.createElement('button');", "execution_profile": "settings", "verification": "unverified dynamic construction site; conditional instances require execution"},
{"source": "flybot_workspace/static/settings/connected-tools.mjs", "line": 53, "construction": "const button = document.createElement('button')", "execution_profile": "settings", "verification": "unverified dynamic construction site; conditional instances require execution"},
{"source": "flybot_workspace/static/settings/connected-tools.mjs", "line": 55, "construction": "const button = document.createElement('button')", "execution_profile": "settings", "verification": "unverified dynamic construction site; conditional instances require execution"},
{"source": "flybot_workspace/static/settings/custom-mcp.mjs", "line": 23, "construction": "const remove = document.createElement('button')", "execution_profile": "settings", "verification": "unverified dynamic construction site; conditional instances require execution"},
{"source": "flybot_workspace/static/shell/app.mjs", "line": 261, "construction": "link = doc.createElement('a');", "execution_profile": "shell", "verification": "unverified dynamic construction site; conditional instances require execution"},
{"source": "flybot_workspace/static/shell/app.mjs", "line": 437, "construction": "const skip = document.createElement('a');", "execution_profile": "shell", "verification": "unverified dynamic construction site; conditional instances require execution"},
Expand Down
10 changes: 6 additions & 4 deletions flybot_workspace/static/settings/connected-tools.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const APPROVAL_STATUS = {
pending: '待确认', approved: '已允许', executing: '执行中', succeeded: '已完成',
denied: '已拒绝', failed: '执行失败', expired: '已过期', unknown: '结果未确认',
}
const AUTOMATIC_MODES = new Map([['automatic', '自动执行'], ['automatic_read', '自动只读']])

export async function mountToolApprovals(document, fetcher = globalThis.fetch, schedule = globalThis.setInterval) {
const keyCard = document.getElementById('composio-key-card')
Expand All @@ -14,7 +15,7 @@ export async function mountToolApprovals(document, fetcher = globalThis.fetch, s
title.className = 'composio-key-title'
title.textContent = '应用工具调用'
const note = document.createElement('p')
note.textContent = '在私聊里,已授权的 GitHub 只读查询(如检查 PR 是否合并)会自动执行。修改数据、发送消息和其他工具调用需要确认。每次确认只允许所示工具和参数执行一次。'
note.textContent = '在支持 GitHub 工具的对话中,账号已授权的 GitHub 读取和写入操作会自动执行。其他应用的工具调用需逐次确认,每次只允许所示工具和参数执行一次。'
const list = document.createElement('div')
list.setAttribute('aria-live', 'polite')
section.append(title, note, list)
Expand All @@ -36,9 +37,10 @@ export async function mountToolApprovals(document, fetcher = globalThis.fetch, s
const row = document.createElement('div')
const label = document.createElement('strong')
const task = typeof item.task_id === 'string' && item.task_id ? ' · 任务 ' + item.task_id.slice(0, 8) : ''
const automatic = item.approval_mode === 'automatic_read'
const mode = automatic ? ' · 自动只读' : ''
label.textContent = item.name + mode + ' · ' + (APPROVAL_STATUS[item.status] ?? '状态未知') + task
const automatic = AUTOMATIC_MODES.get(item.approval_mode)
const mode = automatic ? ' · ' + automatic : ''
const state = automatic && ['pending', 'approved'].includes(item.status) ? '待执行' : APPROVAL_STATUS[item.status]
label.textContent = item.name + mode + ' · ' + (state ?? '状态未知') + task
const context = document.createElement('p')
const prompt = item.prompt ? '请求:' + item.prompt + '\n' : ''
context.textContent = prompt + '连接:' + (item.account ? item.account.toolkit + ' / ' + item.account.account_id : '连接已移除')
Expand Down
4 changes: 2 additions & 2 deletions runtime/flybot-image/native-ds-bot-overlay.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const patch = fileURLToPath(new URL('./native-ds-bot.patch', import.meta.url))
const files = {
'src/host/connectors/index.js': [
'1b5da94a41a8bb5f849e7f54eaab23f9da3aaa1ee27111e1c33f79f5ef9a2b24',
'aae09738660a91ebdf8a64645bc6f16174bea715989e7638c170c6cc2d080bd8',
'687519fce1fe28d6932e244d1970d044c143e3f68529982508f593076a9d7390',
],
'src/host/tools.js': [
'a5c743b7c75c96498775808f029a5f15c7e08dbe6eaf33089d29b3c2a9ffb382',
Expand Down Expand Up @@ -55,7 +55,7 @@ const files = {
],
'src/host/capabilities.js': [
'656fcc0b0fb7fd597dfd0f62bd49522d92becd4ed1c77dd53ba016f045614c89',
'bff22001141ec0ea02714a2e440575adf7d863a036eb91f487f3f7725046349c',
'321be0845446f49d8e0a8a2c6fc6acc95e178042b33a5c37e93aa7f2e6c079ca',
],
'src/host/channel.js': [
'34b2a23af48a7c90984cca4050d3187816a9873fd513005cfb4663a6b8a33cb8',
Expand Down
28 changes: 7 additions & 21 deletions runtime/flybot-image/native-ds-bot.patch
Original file line number Diff line number Diff line change
Expand Up @@ -1258,21 +1258,7 @@ diff --git a/src/host/capabilities.js b/src/host/capabilities.js
index efe6323..e0e439e 100644
--- a/src/host/capabilities.js
+++ b/src/host/capabilities.js
@@ -336,6 +336,13 @@ export function install(rt) {
let config
try {
config = configFor(item, bot.id)
+ // Never pass the private read endpoint to a group or detached task.
+ if (name === 'ot-apps' && config.transport === 'streamable-http'
+ && rt.chatOwners?.get(sessionId) === bot.id
+ && rt.groupOwners?.has(sessionId) === false && rt.taskOwners?.has(sessionId) === false) {
+ const url = await rt.flybotWorkspaceApps?.ownerPrivateToolUrl?.(config.url)
+ if (url) config.url = url
+ }
} catch (error) {
await drop()
statusSet(bot.id, name, sessionId, { state: 'error', error: rt.redactSecrets(error.message).slice(0, 300) })
@@ -397,7 +404,9 @@ export function install(rt) {
@@ -397,7 +397,9 @@ export function install(rt) {
}
const desiredFor = (agent, bot) => {
const sessionId = agent.session.id
Expand Down Expand Up @@ -2221,8 +2207,8 @@ diff --git a/src/host/connectors/index.js b/src/host/connectors/index.js
+ const visible = new Set(attached ? (agent?.ctx?.tools?.schemas?.(agent) ?? []).map(tool => tool.name) : [])
+ return new Map(rows.map(({ slug, tools }) => [slug, tools.map(publicAppTool).filter(name => visible.has(name))]))
+ }
+ const describeComposio = tools => tools.length
+ ? `connected through FlyBot (Composio); ${tools.length} app tools available in this chat, including ${tools.slice(0, 5).join(', ')}. Calls require owner approval in /settings/connectors.`
+ const describeComposio = (slug, tools) => tools.length
+ ? `connected through FlyBot (Composio); ${tools.length} app tools available in this chat, including ${tools.slice(0, 5).join(', ')}. ${slug === 'github' ? 'Calls run automatically within the authorized GitHub permissions.' : 'Calls require owner approval in /settings/connectors.'}`
+ : 'connected through FlyBot (Composio); no app tools are currently mounted in this chat. Check /settings/connectors.'
+
const requestsOf = (botId) => {
Expand All @@ -2248,13 +2234,13 @@ diff --git a/src/host/connectors/index.js b/src/host/connectors/index.js
const connected = entry.id === 'mail' ? mailHasAccounts() : (statuses.get(entry.id)?.state === undefined && mounts.has(entry.id)) || hasCredential(entry.id)
const usable = !offFor(entry.id).includes(bot.id)
+ const tools = apps.get(entry.id)
+ if (tools && (tools.length || !connected || !usable)) return `- ${entry.name} (${entry.id}) — ${describeComposio(tools)}`
+ if (tools && (tools.length || !connected || !usable)) return `- ${entry.name} (${entry.id}) — ${describeComposio(entry.id, tools)}`
return `- ${entry.name} (${entry.id}) — ${entry.about} — ${connected ? 'connected' : 'not connected'}${usable ? '' : '; turned off for you'}`
})
- return ['Connectors:', ...lines].join('\n')
+ const native = new Set(rows.map(entry => entry.id))
+ for (const [slug, tools] of apps) {
+ if (!native.has(slug)) lines.push(`- ${slug} — ${describeComposio(tools)}`)
+ if (!native.has(slug)) lines.push(`- ${slug} — ${describeComposio(slug, tools)}`)
+ }
+ return lines.length ? ['Connectors:', ...lines].join('\n') : 'No connectors are set up.'
},
Expand All @@ -2273,9 +2259,9 @@ diff --git a/src/host/connectors/index.js b/src/host/connectors/index.js
const connected = id === 'mail' ? mailHasAccounts() : hasCredential(id)
const signIn = statuses.get(id)?.state === 'needs-sign-in'
- if (connected && !signIn && !offFor(id).includes(bot.id)) return `${entry.name} is already connected; use its tools (mcp__${id}__*).`
+ if (appTools?.length) return `${entry?.name ?? id} is ${describeComposio(appTools)}`
+ if (appTools?.length) return `${entry?.name ?? id} is ${describeComposio(id, appTools)}`
+ if (entry && connected && !signIn && !offFor(id).includes(bot.id)) return `${entry.name} is already connected; use its tools (mcp__${id}__*).`
+ if (appTools) return `${entry?.name ?? id} is ${describeComposio(appTools)}`
+ if (appTools) return `${entry?.name ?? id} is ${describeComposio(id, appTools)}`
+ if (entry === undefined) return `No connector named ${id}.`
if (offFor(id).includes(bot.id)) return `${entry.name} is turned off for you. The user can turn it on in your details.`
if (rt.taskOwners?.has(agentId)) return 'Background tasks cannot show connector cards. Finish or report back to your own chat so it can ask the user.'
Expand Down
1 change: 1 addition & 0 deletions runtime/flybot-image/test/native-open-parts.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ test('native connector tools use the mounted Composio connection without asking
const args = {id:'github',purpose:'Inspect a repository'}
const result = String(await list.execute({},exec))
assert.match(result,/GitHub \(github\).*connected through FlyBot \(Composio\).*mcp__ot-apps__GITHUB_LIST_REPOS/)
assert.match(result,/run automatically within the authorized GitHub permissions/)
assert.doesNotMatch(result,/GITHUB_CREATE_ISSUE/)
assert.match(String(await request.execute(args,exec)),/connected through FlyBot \(Composio\)/)
assert.equal(rt.state.connectorRequests?.writer?.length ?? 0,0)
Expand Down
65 changes: 28 additions & 37 deletions runtime/flybot-workspace-web/features/connectors/connectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,7 @@ const MAX_ARGS = 12000
const MAX_RESULT = 10000
const MAX_CALLS_KEPT = 100
const APPROVAL_TTL = 300
const AUTOMATIC_READ = 'automatic_read'
// Each entry is a known read in Composio's GitHub toolkit. Tool descriptions,
// name prefixes, and hints from custom MCP servers do not grant execution.
// https://docs.composio.dev/toolkits/github
// https://docs.github.com/en/rest/pulls/pulls#check-if-a-pull-request-has-been-merged
const GITHUB_READS = new Set([
'GITHUB_CHECK_IF_PULL_REQUEST_HAS_BEEN_MERGED',
'GITHUB_CHECK_IF_PULL_REQUEST_MERGED',
'GITHUB_GET_A_PULL_REQUEST',
'GITHUB_LIST_PULL_REQUESTS',
'GITHUB_GET_A_REPOSITORY',
'GITHUB_GET_REPOS',
'GITHUB_LIST_REPOS',
'GITHUB_LIST_REPOSITORIES',
'GITHUB_LIST_REPOSITORIES_FOR_THE_AUTHENTICATED_USER',
'GITHUB_LIST_REPOSITORIES_FOR_A_USER',
'GITHUB_GET_AN_ISSUE',
'GITHUB_LIST_REPOSITORY_ISSUES',
'GITHUB_GET_A_RELEASE',
'GITHUB_GET_A_RELEASE_BY_TAG_NAME',
'GITHUB_LIST_RELEASES',
])
const AUTOMATIC = 'automatic'
const newId = () => randomUUID().replaceAll('-', '')
const KEY_PURPOSE = 'flybot-workspace.composio.key'
const mcpPurpose = id => `flybot-workspace.mcp.${id}`
Expand All @@ -62,7 +41,7 @@ const keyView = row => (row ? { configured: true, key_hint: row.key_hint, revisi
const serverView = row => ({ id: row.id, name: row.name, origin: row.origin, revision: row.revision, created: row.created, updated: row.updated })
const callView = (row, withArgs = false) => {
const view = { id: row.id, task_id: null, name: row.name, status: row.status, created: row.created, expires: row.expires }
if (row.approval_mode === AUTOMATIC_READ) view.approval_mode = AUTOMATIC_READ
if (row.approval_mode === AUTOMATIC || row.approval_mode === 'automatic_read') view.approval_mode = row.approval_mode
if (withArgs) view.arguments = JSON.parse(row.arguments)
if (row.result != null) view.result = row.result
return view
Expand Down Expand Up @@ -367,25 +346,31 @@ export function createConnectors({ dir, sealKey, identity, env = process.env, cl
return false
})
}
function propose(name, args, { automaticReads = false } = {}) {
function propose(name, args) {
const entry = catalog.get(name)
if (!entry) fail(403, 'tool_not_discovered', 'Tool is not connected for this account')
if (!isObject(args)) fail(400, 'invalid', 'arguments must be an object')
const argumentsText = JSON.stringify(sortKeys(args))
if (Buffer.byteLength(argumentsText) > MAX_ARGS) fail(413, 'invalid', 'Tool arguments exceed bound')
const automatic = automaticReads === true && entry.kind === 'composio' && entry.toolkit === 'github' && GITHUB_READS.has(name)
const automatic = entry.kind === 'composio' && entry.toolkit === 'github'
const now = clock()
return store.update((draft) => {
expireCalls(draft, now, MAX_CALLS_KEPT - 1)
// Allow the same account, tool and arguments to resume an approval.
// A private automatic receipt cannot be claimed by another context.
// Reuse the exact receipt, including an in-flight GitHub operation, to avoid a duplicate write.
const open = draft.calls.find(row => row.name === name && row.arguments === argumentsText &&
row.kind === entry.kind && row.ref === entry.ref && row.version === entry.version && row.revision === entry.revision &&
(row.approval_mode === AUTOMATIC_READ) === automatic && live(row, now))
if (open) return open
(live(row, now) || (automatic && row.status === 'executing' && row.expires > now)))
if (open) {
// An old pending receipt may proceed only when the Bot calls it again.
if (automatic && open.status === 'pending') {
open.status = 'approved'
open.approval_mode = AUTOMATIC
}
return open
}
if (draft.calls.length >= MAX_CALLS_KEPT) fail(429, 'quota', 'Too many active connected-tool calls')
const row = { id: newId(), name, kind: entry.kind, ref: entry.ref, version: entry.version, revision: entry.revision, arguments: argumentsText,
status: automatic ? 'approved' : 'pending', ...(automatic ? {approval_mode: AUTOMATIC_READ} : {}),
status: automatic ? 'approved' : 'pending', ...(automatic ? {approval_mode: AUTOMATIC} : {}),
result: null, created: now, expires: now + APPROVAL_TTL }
draft.calls.push(row)
return row
Expand Down Expand Up @@ -427,12 +412,11 @@ export function createConnectors({ dir, sealKey, identity, env = process.env, cl
})
return { items }
}
async function run(id, { automaticReads = false } = {}) {
async function run(id) {
// Consume the approval before any network I/O; 'executing' is terminal.
let claimed = false
const row = store.update((draft) => {
const item = draft.calls.find(c => c.id === id)
if (item?.approval_mode === AUTOMATIC_READ && automaticReads !== true) return null
if (!item || item.status !== 'approved' || item.expires <= clock()) return item ? { ...item } : null
item.status = 'executing'
claimed = true
Expand All @@ -443,11 +427,17 @@ export function createConnectors({ dir, sealKey, identity, env = process.env, cl
try {
const st = state()
if (row.kind === 'composio') {
const account = st.connections.find(c => c.id === row.ref && c.status === 'ACTIVE')
const activeAccount = snapshot => snapshot.connections.find(c => c.id === row.ref && c.status === 'ACTIVE')
const account = activeAccount(st)
const key = secretKey()
if (!account || !key || st.composio?.revision !== row.revision) throw new Fault(409, 'connection_changed', 'Connection or key changed; call blocked')
const c = new composio.Client(key, transport)
const remote = await c.getAccount(account.account_id)
const latest = state()
if (latest.composio?.revision !== row.revision || latest.composio?.key_sealed !== st.composio.key_sealed ||
activeAccount(latest)?.account_id !== account.account_id) {
throw new Fault(409, 'connection_changed', 'Connection or key changed; call blocked')
}
if (remote.status !== 'ACTIVE' || ![undefined, null, '', userRef()].includes(remote.user_id)) {
status = 'failed'; result = { error: 'connection_not_active' }
} else {
Expand Down Expand Up @@ -476,19 +466,20 @@ export function createConnectors({ dir, sealKey, identity, env = process.env, cl
return item ? { ...item } : null
})
}
// One agent tool call. Verified private reads are ready to run immediately.
// One agent tool call. Connected GitHub tools are ready to run immediately.
// Other tools wait for a bounded period on a one-shot owner decision.
async function callTool(name, args, { automaticReads = false, waitMs = 40_000, pollMs = 500 } = {}) {
async function callTool(name, args, { waitMs = 40_000, pollMs = 500 } = {}) {
if (!catalog.has(name)) await discover({ force: true })
let row = propose(name, args, {automaticReads})
let row = propose(name, args)
const deadline = Date.now() + waitMs
while (row && row.status === 'pending' && Date.now() < deadline) {
await sleep(pollMs)
row = state().calls.find(c => c.id === row.id)
}
if (row?.status === 'approved') row = await run(row.id, {automaticReads})
if (row?.status === 'approved') row = await run(row.id)
if (!row) return { error: 'tool_unavailable' }
if (row.status === 'pending') return { error: 'tool_pending', approval_id: row.id, note: 'Waiting for the owner to approve in Settings > App connectors; call again with the same arguments after approval. No implicit retry.' }
if (row.status === 'executing') return { error: 'tool_executing', note: 'The matching call is already running. Do not repeat it.' }
return row.result ?? { error: 'tool_' + row.status, note: 'Await owner approval in Settings > App connectors; no implicit retry.' }
}

Expand Down
Loading
Loading