feat: add stepIndex to history events

This commit is contained in:
Simon
2026-01-21 16:59:22 +08:00
parent 6944bedf85
commit 81807e17ca
4 changed files with 14 additions and 9 deletions

View File

@@ -263,6 +263,7 @@ export class PageAgentCore extends EventTarget {
this.history.push({
type: 'step',
stepIndex: step,
reflection,
action,
usage: result.usage,

View File

@@ -35,6 +35,7 @@ export interface MacroToolResult {
*/
export interface AgentStep {
type: 'step'
stepIndex: number
reflection: Partial<AgentReflection>
action: {
name: string

View File

@@ -563,9 +563,8 @@ export class Panel {
// 2. Render each history event
const history = this.#agent.history
for (let i = 0; i < history.length; i++) {
const event = history[i]
items.push(...this.#createHistoryCards(event, i + 1))
for (const event of history) {
items.push(...this.#createHistoryCards(event))
}
this.#historySection.innerHTML = items.join('')
@@ -577,14 +576,17 @@ export class Panel {
}
/** Create cards for a history event */
#createHistoryCards(event: PanelAgentAdapter['history'][number], stepNumber: number): string[] {
#createHistoryCards(event: PanelAgentAdapter['history'][number]): string[] {
const cards: string[] = []
const time = formatTime(this.#config.language ?? 'en-US')
const meta = this.#i18n.t('ui.panel.step', {
number: stepNumber.toString(),
const meta =
event.type === 'step' && event.stepIndex !== undefined
? this.#i18n.t('ui.panel.step', {
number: (event.stepIndex + 1).toString(),
time,
duration: '',
})
: time
if (event.type === 'step') {
// Reflection card

View File

@@ -34,6 +34,7 @@ export interface PanelAgentAdapter extends EventTarget {
/** History of agent events */
readonly history: readonly {
type: 'step' | 'observation' | 'user_takeover' | 'error'
stepIndex?: number
/** For 'step' type */
reflection?: {
evaluation_previous_goal?: string