fix(core): change emitActivity to #emitActivity

This commit is contained in:
Simon
2026-01-29 21:15:24 +08:00
parent 5cfaa292d3
commit 8a03391c95
2 changed files with 7 additions and 14 deletions

View File

@@ -95,7 +95,7 @@ export class PageAgentCore extends EventTarget {
// Listen to LLM retry events // Listen to LLM retry events
this.#llm.addEventListener('retry', (e) => { this.#llm.addEventListener('retry', (e) => {
const { attempt, maxAttempts } = (e as CustomEvent).detail const { attempt, maxAttempts } = (e as CustomEvent).detail
this.emitActivity({ type: 'retrying', attempt, maxAttempts }) this.#emitActivity({ type: 'retrying', attempt, maxAttempts })
// Also push to history for panel rendering // Also push to history for panel rendering
this.history.push({ this.history.push({
type: 'retry', type: 'retry',
@@ -109,7 +109,7 @@ export class PageAgentCore extends EventTarget {
const error = (e as CustomEvent).detail.error as Error | InvokeError const error = (e as CustomEvent).detail.error as Error | InvokeError
if ((error as any)?.rawError?.name === 'AbortError') return if ((error as any)?.rawError?.name === 'AbortError') return
const message = String(error) const message = String(error)
this.emitActivity({ type: 'error', message }) this.#emitActivity({ type: 'error', message })
// Also push to history for panel rendering // Also push to history for panel rendering
this.history.push({ this.history.push({
type: 'error', type: 'error',
@@ -153,7 +153,7 @@ export class PageAgentCore extends EventTarget {
* Emit activity event - for transient UI feedback * Emit activity event - for transient UI feedback
* @param activity - Current agent activity * @param activity - Current agent activity
*/ */
emitActivity(activity: AgentActivity): void { #emitActivity(activity: AgentActivity): void {
this.dispatchEvent(new CustomEvent('activity', { detail: activity })) this.dispatchEvent(new CustomEvent('activity', { detail: activity }))
} }
@@ -224,7 +224,7 @@ export class PageAgentCore extends EventTarget {
// Thinking // Thinking
console.log(chalk.blue('Thinking...')) console.log(chalk.blue('Thinking...'))
this.emitActivity({ type: 'thinking' }) this.#emitActivity({ type: 'thinking' })
// invoke LLM // invoke LLM
@@ -303,7 +303,7 @@ export class PageAgentCore extends EventTarget {
} catch (error: unknown) { } catch (error: unknown) {
console.error('Task failed', error) console.error('Task failed', error)
const errorMessage = String(error) const errorMessage = String(error)
this.emitActivity({ type: 'error', message: errorMessage }) this.#emitActivity({ type: 'error', message: errorMessage })
this.#onDone(false) this.#onDone(false)
const result: ExecutionResult = { const result: ExecutionResult = {
success: false, success: false,
@@ -376,7 +376,7 @@ export class PageAgentCore extends EventTarget {
console.log(chalk.blue.bold(`Executing tool: ${toolName}`), toolInput) console.log(chalk.blue.bold(`Executing tool: ${toolName}`), toolInput)
// Emit executing activity // Emit executing activity
this.emitActivity({ type: 'executing', tool: toolName, input: toolInput }) this.#emitActivity({ type: 'executing', tool: toolName, input: toolInput })
const startTime = Date.now() const startTime = Date.now()
@@ -387,7 +387,7 @@ export class PageAgentCore extends EventTarget {
console.log(chalk.green.bold(`Tool (${toolName}) executed for ${duration}ms`), result) console.log(chalk.green.bold(`Tool (${toolName}) executed for ${duration}ms`), result)
// Emit executed activity // Emit executed activity
this.emitActivity({ this.#emitActivity({
type: 'executed', type: 'executed',
tool: toolName, tool: toolName,
input: toolInput, input: toolInput,

View File

@@ -385,13 +385,6 @@ const result = await agent.execute('Fill in the form with test data')`}
? '向历史流推送一个观察事件,会在下一步时被 LLM 看到' ? '向历史流推送一个观察事件,会在下一步时被 LLM 看到'
: 'Push an observation to history stream, will be seen by LLM in next step', : 'Push an observation to history stream, will be seen by LLM in next step',
}, },
{
name: 'emitActivity(activity: AgentActivity)',
type: 'void',
description: isZh
? '发出活动事件用于 UI 反馈'
: 'Emit activity event for UI feedback',
},
{ {
name: 'dispose(reason?: string)', name: 'dispose(reason?: string)',
type: 'void', type: 'void',