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
76 changes: 38 additions & 38 deletions docs/inventory/visible-controls.json

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions flybot_workspace/static/chat/app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3527,7 +3527,7 @@ export function mount(document, {fetcher = globalThis.fetch.bind(globalThis)} =

async function settleReplyProgress(watch, {terminal = true} = {}) {
watch.terminal ||= terminal;
if (replyWatch === watch) approvalNotice.stop();
if (terminal && replyWatch === watch) approvalNotice.stop();
globalThis.clearTimeout(watch.receiptTimer);
if (watch.posting) {
if (!await acceptPostingReply(watch)) scheduleReplyProgress(watch, 1200);
Expand All @@ -3548,11 +3548,15 @@ export function mount(document, {fetcher = globalThis.fetch.bind(globalThis)} =
const snapshot = result?.status === 200 ? result.body : null;
if (snapshot?.state === 'pending' || snapshot?.state === 'running') {
watch.failures = 0;
const hasRevision = Number.isSafeInteger(snapshot.revision);
if (snapshot.state === 'running' && !hasRevision && snapshot.text === '' && watch.snapshot) {
// The saved reply can still be running while live progress is unavailable.
snapshot.text = watch.snapshot.text;
}
observeReplyProgress(watch, snapshot);
const changed = Number.isSafeInteger(snapshot.revision) && snapshot.revision !== watch.revision;
const changed = hasRevision && snapshot.revision !== watch.revision;
if (changed) watch.revision = snapshot.revision;
const unchangedDelay = Number.isSafeInteger(snapshot.revision) ? 100 : 400;
scheduleReplyProgress(watch, changed ? 50 : unchangedDelay);
scheduleReplyProgress(watch, changed ? 50 : 750);
return;
}
if (['succeeded','failed','cancelled'].includes(snapshot?.state)) return settleReplyProgress(watch);
Expand Down
40 changes: 30 additions & 10 deletions runtime/flybot-image/ds-bot-bridge.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -255,15 +255,16 @@ export async function prepareNativeChat(rt, botId, savedSessionId) {

// Join progress to the native request echo and durable turn. The settled display
// items remain the source of truth for the returned reply.
export function runTurn(rt, ctx, botId, text, requestId, timeoutMs = 170000, files = [], { onProgress, onPhase, sessionId, signal, managedGroup = false } = {}) {
export function runTurn(rt, ctx, botId, text, requestId, timeoutMs = 170000, files = [], { onProgress, onPhase, sessionId, signal, managedGroup = false, interactive = false } = {}) {
if (signal?.aborted) return Promise.reject(signal.reason)
if (typeof requestId !== 'string' || !requestId) return Promise.reject(new Error('DS-Bot request identifier is required'))
if (sessionId !== undefined && !ownsLiveChat(rt, botId, sessionId)) return Promise.reject(new Error('Mapped native chat is no longer active'))
sessionId ??= rt.chatOf(botId)
const admissionOnly = interactive && !managedGroup
return new Promise((resolve, reject) => {
const progress = turnProgress(onProgress)
let observedTurn, observedSession, boundTurn, boundSession, attempt, lastAgent
let stopping
let stopping, stopDeadline, stopTimer
let revision = 0
let phase = 'preparing'
function emitPhase(next) {
Expand All @@ -286,23 +287,36 @@ export function runTurn(rt, ctx, botId, text, requestId, timeoutMs = 170000, fil
else listener?.dispose?.()
} catch {}
}
const complete = () => error ? reject(error) : resolve(value)
if (stopping) void stopping.then(complete, complete)
const complete = () => {
clearTimeout(stopTimer)
if (error) reject(error)
else resolve(value)
}
if (stopping) void (stopDeadline ? Promise.race([stopping, stopDeadline]) : stopping).then(complete, complete)
else complete()
}
const timer = setTimeout(() => finish(new Error('DS-Bot turn timed out')), timeoutMs)
const timer = setTimeout(() => finish(admissionOnly && signal?.aborted ? signal.reason : new Error('DS-Bot turn timed out')), timeoutMs)
const emptyReply = () => Object.assign(new Error('DS-Bot turn ended without a reply'), {code:'agents/empty-reply'})
function cancelNative() {
if (settled || stopping || !boundSession || boundTurn === undefined) return
const session = boundSession, turn = boundTurn
if (admissionOnly) {
// Native cancellation should emit its terminal event. Bound cleanup if the
// runtime can no longer resolve or settle a turn that the user has stopped.
stopDeadline = new Promise(done => { stopTimer = setTimeout(done, 30_000) })
void stopDeadline.then(() => finish(signal.reason))
}
stopping = Promise.resolve().then(() => rt.resolveAgent(sessionId)).then(agent => {
// Do not stop another turn even if it now owns the same Bot or Session.
if (settled || boundSession !== session || agent?.session !== session || boundTurn !== turn ||
rt.live?.get(sessionId)?.turn !== turn || !ownsLiveChat(rt, botId, sessionId)) return
rt.live?.get(sessionId)?.turn !== turn || !ownsLiveChat(rt, botId, sessionId)) {
if (admissionOnly) finish(signal.reason)
return
}
const children = rt.stopSubagents?.(sessionId)
agent.cancel({kind:'user'})
return children
}).catch(() => {})
}).catch(() => { if (admissionOnly) finish(signal.reason) })
}
signal?.addEventListener('abort', cancelNative, {once:true})
function discardAttempt() {
Expand All @@ -324,14 +338,18 @@ export function runTurn(rt, ctx, botId, text, requestId, timeoutMs = 170000, fil
const turn = event.data?.turn
if (event.type === 'turn/start' && Number.isSafeInteger(turn)) {
if (session === observedSession && turn <= observedTurn) return
if (boundTurn !== undefined && turn !== boundTurn) resetTurn()
if (boundTurn !== undefined && turn !== boundTurn) {
if (admissionOnly) { finish(signal?.aborted ? signal.reason : emptyReply()); return }
resetTurn()
}
observedTurn = turn
observedSession = session
return
}
if (event.type === 'user/message' && event.data?.source?.rpcId === requestId) {
boundSession = session
boundTurn = session === observedSession ? observedTurn : undefined
if (admissionOnly && boundTurn !== undefined) clearTimeout(timer)
if (signal?.aborted) cancelNative()
return
}
Expand All @@ -358,7 +376,7 @@ export function runTurn(rt, ctx, botId, text, requestId, timeoutMs = 170000, fil
if (signal?.aborted) { finish(signal.reason); return }
const reason = event.data?.reason
const disposed = reason?.kind === 'aborted' && reason.reason?.kind === 'disposed'
if (managedGroup && disposed) { finish(emptyReply()); return }
if ((managedGroup || admissionOnly) && disposed) { finish(emptyReply()); return }
const reply = parts.join('\n\n').trim()
if (reply) finish(null, { text: reply, sessionId, turnId: event.data?.turnId ?? event.turnId ?? null })
else if (event.data?.error || (managedGroup && reason && reason.kind !== 'completed')) finish(new Error('DS-Bot turn failed'))
Expand Down Expand Up @@ -390,8 +408,10 @@ export function runTurn(rt, ctx, botId, text, requestId, timeoutMs = 170000, fil
emitPhase('thinking')
}
}, { global: true }))
}
if (admissionOnly || progress || typeof onPhase === 'function') {
listeners.push(ctx.on('agent/disposed', ({ agent }) => {
if (managedGroup && boundSession && agent?.id === sessionId && agent.session === boundSession && !settled) {
if ((managedGroup || admissionOnly) && boundSession && agent?.id === sessionId && agent.session === boundSession && !settled) {
finish(signal?.aborted ? signal.reason : emptyReply())
} else if (agent === lastAgent && !settled) {
resetTurn()
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 @@ -15,15 +15,15 @@ const files = {
],
'src/host/tools.js': [
'a5c743b7c75c96498775808f029a5f15c7e08dbe6eaf33089d29b3c2a9ffb382',
'852dafff886dd8625d98152afe85432b8a22648d3627df5b61eddba4cea8c510',
'73846995fff9590d7d059166c8c9de14b27dea5477cfd5b37099800a0e3b96b7',
],
'src/host/roster.js': [
'20461d2d4aeae6ca373e3431a5802317d1130468e1940d22032189134429f984',
'31c4ec4f68067b79ef2d4fc967e254e15b5854cbc1928eed831c725030dd77aa',
],
'src/host/prompt.js': [
'b15fd1dd8b046589533540b45388e6573e84fdf51bb09aa48a97e694c1e83c21',
'ebf5a93da2ef5941e0417f4018635350cb251212c9eb9384671f2ef9a7bbc2b8',
'21d63cfed3a498fbb47661ee2d7b09dd947b7bd27a2e8ffc1e6b77587f08a2c5',
],
'client.js': [
'98713d86c6cbf85adab1d0a2d303140778d9ed85fb2220abdadfab377a5f539f',
Expand Down
36 changes: 28 additions & 8 deletions runtime/flybot-image/native-ds-bot.patch
Original file line number Diff line number Diff line change
Expand Up @@ -2064,9 +2064,10 @@ diff --git a/src/host/groups.js b/src/host/groups.js
if (running !== undefined) {
if (extra.failed !== undefined) {
diff --git a/src/host/tools.js b/src/host/tools.js
index 0b9ee2b..b9e79a2 100644
--- a/src/host/tools.js
+++ b/src/host/tools.js
@@ -477,7 +477,13 @@
@@ -477,7 +477,13 @@ export function install(rt) {
const served = new Set((await rt.catalog()).filter(entry => entry.needsKey !== true && rt.isLocalAgentRef?.(entry.ref) !== true).map(entry => entry.ref))
const fallback = [state.prefs.defaultBotModel, creator?.model].find(ref => ref && served.has(ref))
const model = args.model || fallback
Expand All @@ -2081,7 +2082,7 @@ diff --git a/src/host/tools.js b/src/host/tools.js
return `Created ${bot.name}${workDir ? `, working in ${workDir}` : ''}. It is greeting the user now.`
} catch (error) {
return `Could not create the Bot: ${error.message}`
@@ -631,9 +637,9 @@
@@ -631,9 +637,9 @@ export function install(rt) {

rt.teamTools.push(defineTool({
name: 'create_group',
Expand All @@ -2093,7 +2094,7 @@ diff --git a/src/host/tools.js b/src/host/tools.js
name: { type: 'string', description: 'Group name; defaults to the member names' },
notice: { type: 'string', description: 'Shared instructions every member reads before speaking in this group; at most 2000 characters' },
admin: { type: 'string', description: 'Member who leads the group; defaults to you' },
@@ -647,6 +653,15 @@
@@ -647,6 +653,15 @@ export function install(rt) {
if (!rt.isMain(self)) return 'Only a Main Bot can create group chats. Ask a Main Bot instead.'
const { bots, unknown } = resolveBots(args.members)
if (unknown.length > 0) return `No Bot named ${unknown.join(', ')}. Team: ${teamNames()}`
Expand All @@ -2109,16 +2110,22 @@ diff --git a/src/host/tools.js b/src/host/tools.js
const admin = args.admin ? rt.findBot(args.admin) : rt.botOf(self)
if (admin === undefined) return `No Bot named ${args.admin}. Team: ${teamNames()}`
const members = [...new Set([self, ...bots.map(bot => bot.id), admin.id])]
@@ -1189,12 +1204,16 @@
@@ -1189,12 +1204,20 @@ export function install(rt) {
const filterBotAssembly = (agent, held) => {
if (held.filtered === true || typeof agent.ctx?.on !== 'function') return
const filterTools = agent.ctx.on('llm/stream', function filterBuiltinTools(options, next) {
+ // The LLM service waterfall is shared. A specialist's restrictions must
+ // never drop tools from the Chief's concurrent or following model call.
+ if (options.sessionId !== agent.session?.id) return next()
+ const offered = options.tools
+ if (!Array.isArray(offered)) return next()
const hidden = rt.hiddenBuiltinTools(agent.session?.id)
if (!options.tools?.some(tool => hidden.has(tool.name))) return next()
return agent.ctx.llm.stream({ ...options, tools: options.tools.filter(tool => !hidden.has(tool.name)) })
- if (!options.tools?.some(tool => hidden.has(tool.name))) return next()
- return agent.ctx.llm.stream({ ...options, tools: options.tools.filter(tool => !hidden.has(tool.name)) })
+ const setup = rt.flybotWorkspaceTeam?.setupTools(agent.session?.id)
+ const canUseSetup = setup && [...setup].every(name => offered.some(tool => tool.name === name && !hidden.has(name)))
+ const tools = offered.filter(tool => !hidden.has(tool.name) && (!canUseSetup || setup.has(tool.name)))
+ return tools.length === offered.length ? next() : agent.ctx.llm.stream({ ...options, tools })
})
if (typeof filterTools === 'function') held.disposers.push(filterTools)
- const dispose = agent.ctx.on('system-prompt/assemble', async (_assembly, _context, next) => {
Expand All @@ -2127,6 +2134,17 @@ diff --git a/src/host/tools.js b/src/host/tools.js
const assembled = await next()
const hidden = new Set([...HIDDEN_TOOLS, ...rt.hiddenBuiltinTools(agent.session?.id)])
// DSH 0.2.2 adds the tool list after this waterfall (#814), so only an
@@ -1362,6 +1385,10 @@ export function install(rt) {
// goal made there is blocked.
ctx.tools.guard((exec) => {
if (!rt.isBotSession(exec.agent?.id)) return undefined
+ const setup = rt.flybotWorkspaceTeam?.setupTools(exec.agent?.session?.id ?? exec.agent?.id)
+ if (setup && exec.name !== 'run_code' && !setup.has(exec.name)) {
+ return 'Finish the requested team setup first using list_bots, create_bot, and create_group. Use the native tools instead of inspecting files or settings.'
+ }
if (exec.name === BLOCKING_QUESTION_TOOL) return `Bots cannot use ${BLOCKING_QUESTION_TOOL}. Ask with ask_user in your own chat, or ask in your reply.`
if (rt.taskOwners?.has(exec.agent?.id)) {
if (exec.name === 'browser_handoff') return 'Background tasks cannot hand the browser to the user. Report back to your own chat so it can ask the user to take over.'
diff --git a/src/host/roster.js b/src/host/roster.js
--- a/src/host/roster.js
+++ b/src/host/roster.js
Expand All @@ -2148,9 +2166,10 @@ diff --git a/src/host/roster.js b/src/host/roster.js
if (main) state.mainBotIds.push(id)
const creator = rt.botOf(createdBy)
diff --git a/src/host/prompt.js b/src/host/prompt.js
index 0c42154..cde287f 100644
--- a/src/host/prompt.js
+++ b/src/host/prompt.js
@@ -51,12 +51,19 @@
@@ -51,12 +51,20 @@ export function install(rt) {
const bot = rt.botOf(self)
if (bot !== undefined) {
const main = rt.isMainForTurn?.(id) ?? rt.isMain(self)
Expand All @@ -2164,7 +2183,8 @@ diff --git a/src/host/prompt.js b/src/host/prompt.js
+ ...(workspace ? [
+ '',
+ '## FlyBot personal workspace',
+ 'When the user asks you to create or assemble a team, use list_bots to reuse existing specialists, call create_bot for missing roles, and call create_group with their exact names. Use DS Bot tool discovery if these tools are not listed directly. You can do this from the current conversation.',
+ 'When the user asks to assemble a team, start by calling list_bots. Reuse suitable members, call create_bot for missing roles, then call create_group with their exact names. The tool list for this request is authoritative even if a previous reply said a tool was missing. Use DS Bot tool discovery only if the current request presents tools through run_code.',
+ ...(workspace.setupPending ? ['The current user explicitly requested team setup. Create the team before starting repository or project work. Use the native tools directly and report actual results from their calls.'] : []),
+ 'FlyBot shared groups include only the Bots you list. Include yourself only if the user asks. Supply the name and members, plus a notice if requested. Leave admin, reply mode, and section to group settings. After the tools confirm creation, name the actual Bots and link to the group using the returned link.',
+ ] : []),
].join('\n')
Expand Down
2 changes: 1 addition & 1 deletion runtime/flybot-image/plugin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export function apply(ctx, config = {}) {
bridge.requireModel(botId)
const turn = () => runTurn(rt, ctx, botId, text, requestId, undefined, parts, {
sessionId, onProgress: options.onProgress, onPhase: options.onPhase, signal: options.signal,
managedGroup: options.managedGroup,
managedGroup: options.managedGroup, interactive: options.interactive,
})
return options.personalTeamScope && rt.flybotWorkspaceTeam
? rt.flybotWorkspaceTeam.run({botId,sessionId,requestId,scope:options.personalTeamScope}, turn)
Expand Down
Loading
Loading