fix(schedule): validate exact time-context marker shapes

This commit is contained in:
pku-xht
2026-08-07 20:55:58 +08:00
committed by Tianyi Cui
parent 081b2819e3
commit de3e0a5d1c
4 changed files with 177 additions and 16 deletions
+15 -7
View File
@@ -226,18 +226,26 @@ function isTimeContextReading(event: SessionEvent): boolean {
|| source.plugin !== 'time-context'
|| Object.keys(source).length !== 4
|| source.form !== 'snapshot') return false
const [block] = event.data.content
const blockValue: unknown = event.data.content[0]
const block = typeof blockValue === 'object' && blockValue !== null
? blockValue as Record<string, unknown>
: undefined
const sections: unknown = source.sections
const section: unknown = Array.isArray(sections) ? sections[0] : undefined
const sectionValue: unknown = Array.isArray(sections) ? sections[0] : undefined
const section = typeof sectionValue === 'object' && sectionValue !== null
? sectionValue as Record<string, unknown>
: undefined
return event.data.content.length === 1
&& block?.type === 'text'
&& block !== undefined
&& Object.keys(block).length === 2
&& block.type === 'text'
&& typeof block.text === 'string'
&& Array.isArray(sections)
&& sections.length === 1
&& typeof section === 'object'
&& section !== null
&& 'name' in section
&& section !== undefined
&& Object.keys(section).length === 2
&& section.name === 'time-context'
&& 'text' in section
&& typeof section.text === 'string'
&& section.text === block.text
}