Skip to content

A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.

Accept structured browser tool outputs

Fei2411832b4c29b42a
diff --git a/ds-bot/src/host/browser/mount.js b/ds-bot/src/host/browser/mount.js
index fc2d5b2a..a9c76939 100644
--- a/ds-bot/src/host/browser/mount.js
+++ b/ds-bot/src/host/browser/mount.js
@@ -5,7 +5,19 @@ import { openBotBrowser } from './session.js'
import { gateScope } from './gate.js'
export const browserOutput = {
- schema: { type: 'string' },
+ schema: {
+ oneOf: [
+ { type: 'string' },
+ {
+ type: 'object',
+ properties: {
+ text: { type: 'string', required: true },
+ image: { type: 'string' },
+ },
+ additionalProperties: false,
+ },
+ ],
+ },
render(_args, value) {
if (value && typeof value === 'object') {
const blocks = [{ type: 'text', text: String(value.text ?? '') }]
@@ -18,9 +30,9 @@ export const browserOutput = {
/**
* @param {any} ctx
- * @param {{ toolDefs: any[], defineTool: Function, keyOf: (exec: any) => Promise<string|undefined>, profileRoot: string, downloadRoot?: string, headless: boolean, playwrightUrl?: string, executablePath?: string, actionTimeout?: number, authorize?: (exec: any, botId: string, action: any) => Promise<void>, complete?: Function }} options
+ * @param {{ toolDefs: any[], defineTool: Function, keyOf: (exec: any) => Promise<string|undefined>, profileRoot: string, downloadRoot?: string, headless: boolean, playwrightUrl?: string, executablePath?: string, actionTimeout?: number, authorize?: (exec: any, botId: string, action: any) => Promise<void>, complete?: Function, openSession?: typeof openBotBrowser }} options
*/
-export function mountBrowserPlugin(ctx, { toolDefs, defineTool, keyOf, profileRoot, downloadRoot, headless, playwrightUrl, executablePath, actionTimeout, authorize, complete, connect, getHold, onHold }) {
+export function mountBrowserPlugin(ctx, { toolDefs, defineTool, keyOf, profileRoot, downloadRoot, headless, playwrightUrl, executablePath, actionTimeout, authorize, complete, connect, getHold, onHold, openSession = openBotBrowser }) {
const sessions = new Map()
ctx.effect(() => async () => {
const open = [...sessions.values()]
@@ -39,7 +51,7 @@ export function mountBrowserPlugin(ctx, { toolDefs, defineTool, keyOf, profileRo
if (!botId) return 'Only Bots on the team have a browser.'
let session = sessions.get(botId)
if (spec.needsBrowser && session === undefined) {
- session = await openBotBrowser({
+ session = await openSession({
botId,
profileRoot,
downloadDir: join(downloadRoot ?? join(profileRoot, 'browser-downloads'), botId),
diff --git a/ds-bot/test/browser-plugin-output.test.js b/ds-bot/test/browser-plugin-output.test.js
new file mode 100644
index 00000000..9831bb17
--- /dev/null
+++ b/ds-bot/test/browser-plugin-output.test.js
@@ -0,0 +1,76 @@
+import assert from 'node:assert/strict'
+import { test } from 'node:test'
+import { Context } from '@deepseek-ai/cordis'
+import { ToolCallId } from '@deepseek-ai/dsh-llm'
+import SystemPrompt from '@deepseek-ai/dsh-system-prompt'
+import ToolRuntime, { defineTool } from '@deepseek-ai/dsh-tools'
+import { mountBrowserPlugin } from '../src/host/browser/mount.js'
+import { toolDefs as refsTools } from '../src/host/browser/refs.js'
+
+test('browser handoff and resume return valid DSH outputs and clear the Bot hold', async t => {
+ const ctx = new Context()
+ await ctx.plugin(SystemPrompt)
+ await ctx.plugin(ToolRuntime)
+ t.after(async () => ctx.fiber.dispose())
+
+ let hold = null
+ const plugin = inner => mountBrowserPlugin(inner, {
+ toolDefs: refsTools.filter(tool => ['browser_handoff', 'browser_resume', 'browser_screenshot'].includes(tool.name)),
+ defineTool,
+ keyOf: async () => 'bot-1',
+ profileRoot: '/tmp/browser-profiles',
+ headless: true,
+ openSession: async ({ getHold, onHold }) => ({
+ handoff(reason, note) {
+ const safeNote = String(note ?? '').slice(0, 300)
+ onHold({ by: 'bot', reason, note: safeNote })
+ return `Waiting for the user (${reason}). ${safeNote || 'Ask them to take over.'} Call browser_resume when they have finished.`
+ },
+ resume() {
+ if (getHold()?.by === 'user') throw new Error('The user has taken over this browser. Only the user can give it back.')
+ onHold(null)
+ return 'The browser is yours again.'
+ },
+ async shot() {
+ return { text: 'Screenshot of https://example.com/.', image: 'AAAA' }
+ },
+ async close() {},
+ }),
+ getHold: () => hold,
+ onHold: (botId, value) => { hold = value },
+ })
+ plugin.inject = ['tools']
+ await ctx.plugin(plugin)
+
+ const execute = (name, args) => ctx.tools.execute({
+ signal: new AbortController().signal,
+ callId: ToolCallId(name),
+ name,
+ arguments: args,
+ })
+
+ const handoff = await execute('browser_handoff', { reason: 'other', note: 'Please take over.' })
+ assert.equal(handoff.isError, false, handoff.error?.message)
+ assert.deepEqual(handoff.value, {
+ text: 'Waiting for the user (other). Please take over. Call browser_resume when they have finished.',
+ })
+ assert.deepEqual(handoff.content, [{
+ type: 'text',
+ text: 'Waiting for the user (other). Please take over. Call browser_resume when they have finished.',
+ }])
+ assert.deepEqual(hold, { by: 'bot', reason: 'other', note: 'Please take over.' })
+
+ const resume = await execute('browser_resume', {})
+ assert.equal(resume.isError, false, resume.error?.message)
+ assert.deepEqual(resume.value, { text: 'The browser is yours again.' })
+ assert.deepEqual(resume.content, [{ type: 'text', text: 'The browser is yours again.' }])
+ assert.equal(hold, null)
+
+ const screenshot = await execute('browser_screenshot', {})
+ assert.equal(screenshot.isError, false, screenshot.error?.message)
+ assert.deepEqual(screenshot.value, { text: 'Screenshot of https://example.com/.', image: 'AAAA' })
+ assert.deepEqual(screenshot.content, [
+ { type: 'text', text: 'Screenshot of https://example.com/.' },
+ { type: 'image', data: 'AAAA', mediaType: 'image/jpeg' },
+ ])
+})