Skip to content

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

Normalize show_view blueprints for provider array encoding

klarkxy761a88250807
diff --git a/ds-bot/src/host/tools.js b/ds-bot/src/host/tools.js
index ac23af62..d04985a5 100644
--- a/ds-bot/src/host/tools.js
+++ b/ds-bot/src/host/tools.js
@@ -7,7 +7,7 @@ import { within } from './folders.js'
import { absoluteLinks } from './links.js'
import { unquote } from './text.js'
import { mentionSpans } from '../shared/mentions.js'
-import { validateView, VIEW_BYTE_LIMIT, viewBytes } from '../shared/views.js'
+import { normalizeView, validateView, VIEW_BYTE_LIMIT, viewBytes } from '../shared/views.js'
export const output = { schema: { type: 'string' }, render: (_args, value) => [{ type: 'text', text: String(value) }] }
export const GROUP_REF = { type: 'string', required: true, description: 'Exact group chat name from list_bots' }
@@ -619,12 +619,13 @@ export function install(rt) {
const id = exec.agent?.id
if (rt.groupOwners.has(id)) return 'View cards only work in your own chat. In a group, ask in your message instead.'
if (!rt.chatOwners.has(id)) return `Only Bots on the team can use show_view. Use ${BLOCKING_QUESTION_TOOL} if it is available in this session, or ask the user in your reply.`
+ const view = normalizeView(args.view)
let bytes
- try { bytes = viewBytes(args.title, args.view) } catch { return 'The view is not JSON data.' }
+ try { bytes = viewBytes(args.title, view) } catch { return 'The view is not JSON data.' }
if (bytes > VIEW_BYTE_LIMIT) return `The view is ${bytes} bytes; the limit is ${VIEW_BYTE_LIMIT}.`
const title = String(args.title ?? '').trim()
if (title === '') return 'Give the view a title.'
- const checked = validateView(args.view)
+ const checked = validateView(view)
if (!checked.ok) return checked.error
if (!checked.interactive && args.await_reply === true) return 'This view has nothing to submit; call show_view with await_reply: false.'
const awaitReply = args.await_reply ?? checked.interactive
@@ -637,7 +638,7 @@ export function install(rt) {
id: randomUUID(),
...(exec.callId && !hidden ? { callId: exec.callId } : {}),
title,
- view: args.view,
+ view,
askedAt: Date.now(),
}
await rt.save()
diff --git a/ds-bot/src/shared/views.js b/ds-bot/src/shared/views.js
index 87e67e89..cfb49d7a 100644
--- a/ds-bot/src/shared/views.js
+++ b/ds-bot/src/shared/views.js
@@ -39,6 +39,24 @@ export function viewBytes(title, view) {
return new TextEncoder().encode(`${JSON.stringify(view) ?? ''}${title ?? ''}`).length
}
+// Some providers serialize nested arrays as `{ item: [...] }` (XML-style) and
+// numbers as strings. Normalize the blueprint before validation so a model is
+// not asked to retry a call whose only fault is the provider's encoding.
+// Arrays are unwrapped; metric.value and progress.percent accept a numeric
+// string. Returns a new object; the input is not mutated.
+export function normalizeView(value) {
+ if (Array.isArray(value)) return value.map(normalizeView)
+ if (!isRecord(value)) return value
+ const keys = Object.keys(value)
+ if (keys.length === 1 && keys[0] === 'item' && Array.isArray(value.item)) return value.item.map(normalizeView)
+ const out = {}
+ for (const key of keys) out[key] = normalizeView(value[key])
+ for (const field of ['value', 'percent']) {
+ if (typeof out[field] === 'string' && out[field].trim() !== '' && !Number.isNaN(Number(out[field]))) out[field] = Number(out[field])
+ }
+ return out
+}
+
export function validateView(view) {
const ctx = { ids: new Set(), nodes: 0, interactive: false }
const error = checkNode(view, 'view', 1, ctx)
diff --git a/ds-bot/test/views.test.js b/ds-bot/test/views.test.js
index 8eca67bc..0d9c47d9 100644
--- a/ds-bot/test/views.test.js
+++ b/ds-bot/test/views.test.js
@@ -1,6 +1,6 @@
import assert from 'node:assert/strict'
import { test } from 'node:test'
-import { validateView, validateViewAnswer, VIEW_BYTE_LIMIT, viewBytes, viewSummary } from '../src/shared/views.js'
+import { normalizeView, validateView, validateViewAnswer, VIEW_BYTE_LIMIT, viewBytes, viewSummary } from '../src/shared/views.js'
const text = (value = 'hello') => ({ type: 'text', text: value })
const metric = (label = '进度', value = '70%') => ({ type: 'metric', label, value })
@@ -27,6 +27,22 @@ test('validateView accepts every component and reports whether the card can be s
assert.equal(validateView({ type: 'progress', percent: 100 }).ok, true)
})
+test('normalizeView unwraps XML-style arrays and coerces numeric strings', () => {
+ // Providers may serialize nested arrays as { item: [...] } and numbers as strings.
+ const wrapped = { type: 'stack', children: { item: [text(), { type: 'options', id: 'env', options: { item: [{ label: 'staging' }, { label: 'prod' }] } }] } }
+ const unwrapped = normalizeView(wrapped)
+ assert.ok(Array.isArray(unwrapped.children), 'children unwraps to an array')
+ assert.ok(Array.isArray(unwrapped.children[1].options), 'nested options unwrap to an array')
+ assert.deepEqual(validateView(unwrapped), { ok: true, interactive: true })
+ // Numeric strings land only on the numeric fields, never on labels or text.
+ assert.deepEqual(normalizeView({ type: 'progress', label: '70', percent: '70' }), { type: 'progress', label: '70', percent: 70 })
+ assert.deepEqual(normalizeView({ type: 'metric', label: '70', value: '70' }), { type: 'metric', label: '70', value: 70 })
+ assert.deepEqual(normalizeView(text('70')), text('70'), 'text stays a string')
+ assert.deepEqual(normalizeView(metric('进度', '70%')), metric('进度', '70%'), 'non-numeric string stays a string')
+ // Input is not mutated.
+ assert.equal(Array.isArray(wrapped.children), false)
+})
+
test('validateView rejects an unknown component with the path and the catalog', () => {
const view = stack(text(), metric(), { type: 'chart', data: [1] })
assert.equal(validateView(view).error, 'view.children[2].type: unknown component "chart"; allowed: stack, text, metric, table, options, confirm, form, progress')