Skip to content
Closed
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
12 changes: 10 additions & 2 deletions apps/desktop/src/plugins/hermes-bots/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -11091,6 +11091,12 @@ function defaultScheduleState() {
return { freq: 'daily', time: '9:0', weekday: '1', monthday: '1', intervalN: '2', intervalUnit: 'h', onceN: '30', onceUnit: 'm', repeatN: '', raw: '' }
}

function routineDialogBotLabel(bot, metaByName) {
const owner = typeof bot === 'string' ? { name: bot } : bot

return displayName(owner, botRosterMeta(owner, metaByName))
}

function CreateRoutineDialog({ bot, open, onClose }) {
const [name, setName] = useState('')
const [instruction, setInstruction] = useState('')
Expand All @@ -11104,7 +11110,9 @@ function CreateRoutineDialog({ bot, open, onClose }) {
const [busy, setBusy] = useState(false)
const [error, setError] = useState(null)
const activeProfile = useValue(host.state.profile)
const allMeta = useValue($botMeta)
const profile = typeof bot === 'string' ? bot : bot?.name
const botLabel = routineDialogBotLabel(bot, allMeta)
const schedule = composeSchedule(sched)

const reset = () => {
Expand Down Expand Up @@ -11177,7 +11185,7 @@ function CreateRoutineDialog({ bot, open, onClose }) {
children: [
jsx(DialogTitle, { children: 'New Cronjob' }),
jsx(DialogDescription, {
children: `A recurring task ${displayName(typeof bot === 'string' ? { name: bot } : bot, botRosterMeta(bot, $botMeta.get()))} runs on a schedule. Runs land in its own chat history.`
children: `A recurring task ${botLabel} runs on a schedule. Runs land in its own chat history.`
})
]
}),
Expand Down Expand Up @@ -11207,7 +11215,7 @@ function CreateRoutineDialog({ bot, open, onClose }) {
'Send results to',
pickerSelect(target, setTarget, [
{ id: 'history', label: 'Run history only' },
{ id: 'bot-chat', label: `${displayName({ name: bot }, $botMeta.get()[bot])}\u2019s chat (bot responds)` }
{ id: 'bot-chat', label: `${botLabel}\u2019s chat (bot responds)` }
])
),
jsxs('label', {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import test from 'node:test'
import vm from 'node:vm'

// #93572: RoutinesPane.openCreate() stores resolveRoutineOwner()'s result as
// CreateRoutineDialog's bot prop. The dialog wrapped that owner again and
// passed the resulting {name: <object>} shape to displayName(), which called
// string methods on the object and crashed the whole pane. Keep one normalized
// owner shape for both display and metadata lookup.

const pluginSource = readFileSync(new URL('../plugin.js', import.meta.url), 'utf8')

function load() {
const values = new Map()
const atom = initial => {
const slot = { get: () => values.get(slot), set: value => values.set(slot, value) }
values.set(slot, initial)
return slot
}
const context = {
atom,
PALETTE_AREA: 'palette',
COMPOSER_AREAS: { middleware: 'middleware' },
document: { getElementById: () => null, createElement: () => ({}), head: { appendChild: () => undefined } },
host: { state: { profile: { listen: () => undefined } } }
}
const source = pluginSource
.replace(/^import\s+\*\s+as\s+sdk\s+from '@hermes\/plugin-sdk'\r?\n/m, '')
.replace(/^import\s+\{[\s\S]*?\}\s+from '@hermes\/plugin-sdk'\r?\n/m, '')
.replace(/^const \{ McpTab, ToolsetConfigPanel \} = sdk\r?\n/m, '')
.replace(/^import .* from 'react'\r?\n/m, '')
.replace(/^import .* from 'react\/jsx-runtime'\r?\n/m, '')
.replace('export default {', 'globalThis.plugin = {')
.concat(`
globalThis.__api = { routineDialogBotLabel };
`)
vm.runInNewContext(source, context, { filename: 'plugin.js' })
return context.__api
}

test('regression #93572: a roster-owner object composes the label without throwing', () => {
const { routineDialogBotLabel } = load()
assert.equal(routineDialogBotLabel({ name: 'blog-writer' }, {}), 'Blog Writer')
})

test('string owners keep their configured title through the normalized metadata lookup', () => {
const { routineDialogBotLabel } = load()
const metaByName = { 'blog-writer': { title: 'The Blog Writer' } }
assert.equal(routineDialogBotLabel('blog-writer', metaByName), 'The Blog Writer')
})

test('roster-object owners keep their configured title through the same metadata lookup', () => {
const { routineDialogBotLabel } = load()
const metaByName = { 'blog-writer': { title: 'The Blog Writer' } }
assert.equal(routineDialogBotLabel({ name: 'blog-writer' }, metaByName), 'The Blog Writer')
})

test('a remote roster-object owner never throws when its route cannot resolve', () => {
const { routineDialogBotLabel } = load()
const owner = { name: 'worker', remoteSource: true, sourceScoped: true, connectionId: 'gone' }
const label = routineDialogBotLabel(owner, {})
assert.equal(typeof label, 'string')
assert.ok(label.length > 0)
})
Loading