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/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": 46, "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": 53, "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
31 changes: 19 additions & 12 deletions flybot_workspace/static/settings/connected-tools.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// One-shot owner approvals. No execution is authorized by provider/model text.
// Kept separate from the settings layout so unrelated UI polish stays isolated.
// Activity and one-time decisions for the current account's connected tools.
const APPROVAL_STATUS = {
pending: '待确认', approved: '已允许', executing: '执行中', succeeded: '已完成',
denied: '已拒绝', failed: '执行失败', expired: '已过期', unknown: '结果未确认',
}

export async function mountToolApprovals(document, fetcher = globalThis.fetch, schedule = globalThis.setInterval) {
const keyCard = document.getElementById('composio-key-card')
if (!keyCard || (globalThis.location && globalThis.location.pathname !== '/settings/connectors')) return
Expand All @@ -8,9 +12,9 @@ export async function mountToolApprovals(document, fetcher = globalThis.fetch, s
section.className = 'composio-key-card'
const title = document.createElement('h2')
title.className = 'composio-key-title'
title.textContent = '智能体工具调用 · 逐次确认'
title.textContent = '应用工具调用'
const note = document.createElement('p')
note.textContent = '下方每次确认只允许这一项工具和这些参数执行一次(读取也需要确认)。外部工具可能发送消息、修改或删除数据;仅在核实完整参数后允许。拒绝或超时不会自动重试。'
note.textContent = '在私聊里,已授权的 GitHub 只读查询(如检查 PR 是否合并)会自动执行。修改数据、发送消息和其他工具调用需要确认。每次确认只允许所示工具和参数执行一次。'
const list = document.createElement('div')
list.setAttribute('aria-live', 'polite')
section.append(title, note, list)
Expand All @@ -25,23 +29,26 @@ export async function mountToolApprovals(document, fetcher = globalThis.fetch, s
const response = await fetcher('/v1/composio/approvals', {credentials: 'same-origin'})
if (!response.ok) return
const payload = await response.json()
const pending = (payload.items || []).slice(0, 10)
const raw = JSON.stringify(pending)
const calls = (payload.items || []).slice(0, 10)
const raw = JSON.stringify(calls)
if (raw === previous) return
const rows = pending.map(item => {
const rows = calls.map(item => {
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) : ''
label.textContent = item.name + ' · ' + item.status + task
const automatic = item.approval_mode === 'automatic_read'
const mode = automatic ? ' · 自动只读' : ''
label.textContent = item.name + mode + ' · ' + (APPROVAL_STATUS[item.status] ?? '状态未知') + task
const context = document.createElement('p')
context.textContent = '请求:' + item.prompt + '\n连接:' + (item.account ? item.account.toolkit + ' / ' + item.account.account_id : '连接已移除')
const prompt = item.prompt ? '请求:' + item.prompt + '\n' : ''
context.textContent = prompt + '连接:' + (item.account ? item.account.toolkit + ' / ' + item.account.account_id : '连接已移除')
const args = document.createElement('pre')
args.style.whiteSpace = 'pre-wrap'
args.style.overflowWrap = 'anywhere'
args.textContent = JSON.stringify(item.arguments, null, 2)
const status = document.createElement('p')
if (item.status === 'unknown' || item.status === 'executing') status.textContent = '执行结果不明;不要重试,请先到提供方核实。'
const actions = item.status === 'pending' ? [['deny', '拒绝'], ['approve', '允许此调用一次']] : []
if (item.status === 'unknown') status.textContent = '请先到应用核实执行结果。'
const actions = !automatic && item.status === 'pending' ? [['deny', '拒绝'], ['approve', '允许此调用一次']] : []
for (const [decision, text] of actions) {
const button = document.createElement('button')
button.type = 'button'
Expand All @@ -64,7 +71,7 @@ export async function mountToolApprovals(document, fetcher = globalThis.fetch, s
return row
})
list.replaceChildren(...rows)
if (!rows.length) list.textContent = '暂无待确认调用。请在私人聊天中请求智能体使用你授权的应用;群聊、定时任务和对外 API 尚未接通个人工具。'
if (!rows.length) list.textContent = '暂无工具调用记录。'
previous = raw
} catch { /* A polling failure grants nothing. */ }
finally { busy = false }
Expand Down
2 changes: 1 addition & 1 deletion flybot_workspace/static/settings/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1046,7 +1046,7 @@ <h2 id="composio-key-title" class="composio-key-title">Composio API key</h2>
<p id="connectors-empty" class="settings-card settings-empty" role="status" hidden>没有匹配的应用。</p>
<section class="composio-key-card" id="custom-mcp-card">
<h2>自定义 MCP 服务器 · 仅当前账号</h2>
<p>公开 HTTPS:443 Streamable HTTP;不支持本地命令、私网、重定向或 URL 查询参数。凭据仅加密保存在管理服务,不会交给 DS-Bot。每次工具调用(包括读取)都需要在上方逐次确认。</p>
<p>公开 HTTPS:443 Streamable HTTP;不支持本地命令、私网、重定向或 URL 查询参数。凭据仅加密保存在管理服务,不会交给 DS-Bot。自定义 MCP 的每次调用都需要在上方确认。</p>
<div id="custom-mcp-list" aria-live="polite"></div>
<form id="custom-mcp-form" autocomplete="off">
<label>名称 <input name="name" required maxlength="60"></label>
Expand Down
2 changes: 1 addition & 1 deletion runtime/flybot-image/native-ds-bot-overlay.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const files = {
],
'src/host/capabilities.js': [
'656fcc0b0fb7fd597dfd0f62bd49522d92becd4ed1c77dd53ba016f045614c89',
'321be0845446f49d8e0a8a2c6fc6acc95e178042b33a5c37e93aa7f2e6c079ca',
'bff22001141ec0ea02714a2e440575adf7d863a036eb91f487f3f7725046349c',
],
'src/host/channel.js': [
'34b2a23af48a7c90984cca4050d3187816a9873fd513005cfb4663a6b8a33cb8',
Expand Down
18 changes: 16 additions & 2 deletions runtime/flybot-image/native-ds-bot.patch
Original file line number Diff line number Diff line change
Expand Up @@ -1255,10 +1255,24 @@ index 9116437..1ee020e 100644
if (rt.isSwitchingPart?.(sessionId)) return false
const session = ctx.get('agents')?.get(sessionId)?.session
diff --git a/src/host/capabilities.js b/src/host/capabilities.js
index efe6323..85c65df 100644
index efe6323..e0e439e 100644
--- a/src/host/capabilities.js
+++ b/src/host/capabilities.js
@@ -397,7 +397,9 @@ export function install(rt) {
@@ -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) {
}
const desiredFor = (agent, bot) => {
const sessionId = agent.session.id
Expand Down
68 changes: 53 additions & 15 deletions runtime/flybot-workspace-web/features/connectors/connectors.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// B4 connectors in the user's own DS-Bot: the user's own Composio key and
// connections, user-configured remote MCP servers, and the one-shot owner
// approval for every tool call. Port of composio.py, connected_tools.py,
// approval for calls outside the verified read allowlist. Port of composio.py, connected_tools.py,
// composio_principals (personal scope) and custom_mcp.py. Keys and bearer
// tokens are sealed at rest; nothing here falls back to another key.
import { createHash, randomUUID } from 'node:crypto'
Expand All @@ -16,6 +16,28 @@ 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 newId = () => randomUUID().replaceAll('-', '')
const KEY_PURPOSE = 'flybot-workspace.composio.key'
const mcpPurpose = id => `flybot-workspace.mcp.${id}`
Expand All @@ -40,6 +62,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 (withArgs) view.arguments = JSON.parse(row.arguments)
if (row.result != null) view.result = row.result
return view
Expand Down Expand Up @@ -334,24 +357,36 @@ export function createConnectors({ dir, sealKey, identity, env = process.env, cl
}

const live = (row, now) => (row.status === 'pending' || row.status === 'approved') && row.expires > now
function expireCalls(draft, now) {
function expireCalls(draft, now, limit = MAX_CALLS_KEPT) {
for (const row of draft.calls) if ((row.status === 'pending' || row.status === 'approved') && row.expires <= now) row.status = 'expired'
if (draft.calls.length > MAX_CALLS_KEPT) draft.calls = draft.calls.slice(-MAX_CALLS_KEPT)
if (draft.calls.length <= limit) return
let toRemove = draft.calls.length - limit
draft.calls = draft.calls.filter(row => {
if (live(row, now) || (row.status === 'executing' && row.expires > now) || toRemove === 0) return true
toRemove -= 1
return false
})
}
function propose(name, args) {
function propose(name, args, { automaticReads = false } = {}) {
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 now = clock()
return store.update((draft) => {
expireCalls(draft, now)
// The same tool with the same arguments reuses its open proposal, so the
// agent can call again after the owner approved without a second prompt.
const open = draft.calls.find(row => row.name === name && row.arguments === argumentsText && live(row, now))
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.
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
const row = { id: newId(), name, kind: entry.kind, ref: entry.ref, version: entry.version, revision: entry.revision, arguments: argumentsText, status: 'pending', result: null, created: now, expires: now + APPROVAL_TTL }
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} : {}),
result: null, created: now, expires: now + APPROVAL_TTL }
draft.calls.push(row)
return row
})
Expand All @@ -377,7 +412,8 @@ export function createConnectors({ dir, sealKey, identity, env = process.env, cl
noQuery(query)
const st = store.update((draft) => { expireCalls(draft, now); return draft })
const key = secretKey()
const items = [...st.calls].sort((a, b) => b.created - a.created || a.id.localeCompare(b.id)).slice(0, 30).map((row) => {
const items = [...st.calls].sort((a, b) => Number(b.status === 'pending') - Number(a.status === 'pending') ||
b.created - a.created || a.id.localeCompare(b.id)).slice(0, 30).map((row) => {
const view = callView(row, true)
if (row.kind === 'composio') {
const account = st.connections.find(c => c.id === row.ref)
Expand All @@ -391,11 +427,12 @@ export function createConnectors({ dir, sealKey, identity, env = process.env, cl
})
return { items }
}
async function run(id) {
async function run(id, { automaticReads = false } = {}) {
// 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 Down Expand Up @@ -439,16 +476,17 @@ export function createConnectors({ dir, sealKey, identity, env = process.env, cl
return item ? { ...item } : null
})
}
// One agent tool call: propose, wait (bounded) for the owner's decision, run once.
async function callTool(name, args, { waitMs = 40_000, pollMs = 500 } = {}) {
// One agent tool call. Verified private reads 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 } = {}) {
if (!catalog.has(name)) await discover({ force: true })
let row = propose(name, args)
let row = propose(name, args, {automaticReads})
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)
if (row?.status === 'approved') row = await run(row.id, {automaticReads})
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.' }
return row.result ?? { error: 'tool_' + row.status, note: 'Await owner approval in Settings > App connectors; no implicit retry.' }
Expand Down
4 changes: 2 additions & 2 deletions runtime/flybot-workspace-web/features/connectors/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// B4 connectors feature: the user's own Composio key/connections, custom MCP
// servers and per-call owner approvals, executed in this user's DS-Bot and
// servers and owner approval rules, executed in this user's DS-Bot and
// exposed to it as the native MCP capability "ot-apps" (loopback, token path).
// Endpoints: connectors/<op> and connectors/v1 (legacy /v1/composio/* and
// /v1/mcp/servers* compat). /v1/composio/callback stays on the platform (it is
Expand Down Expand Up @@ -32,7 +32,7 @@ export default function connectors(host) {
pending = setTimeout(() => { pending = null; sync().then((done) => { if (done === false && !host.currentRuntime()?.mainBot) schedule(5000) }).catch(error => { host.log(`apps capability sync failed: ${String(error?.code ?? error?.message ?? 'error').slice(0, 80)}`); schedule(15000) }) }, delay)
pending.unref?.()
}
const apps = Object.freeze({ connectedToolkits: api.connectedToolkits, sync })
const apps = Object.freeze({ connectedToolkits: api.connectedToolkits, ownerPrivateToolUrl: tools.ownerPrivateToolUrl, sync })
const attach = runtime => {
if (!runtime?.rt) return
runtime.rt.flybotWorkspaceApps = apps
Expand Down
Loading
Loading