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({ this.history.push({
type: 'step', type: 'step',
stepIndex: step,
reflection, reflection,
action, action,
usage: result.usage, usage: result.usage,

View File

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

View File

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

View File

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