feat!: Refine lifecycle hooks; fix abortSignal

- add `stop` method. agent can be reused after stopped
- agent can not be reused after disposed
- extension DO NOT exposes `dispose` anymore. only `stop`.
- update panel for new `stop` method
- fix MultiPageAgent dispose event
- better handling abortSignal
This commit is contained in:
Simon
2026-02-13 17:57:12 +08:00
parent 4dc332a32c
commit dffcb53db9
13 changed files with 80 additions and 68 deletions

View File

@@ -12,6 +12,7 @@ const enUS = {
question: 'Question: {{question}}',
waitingPlaceholder: 'Waiting for task to start...',
stop: 'Stop',
close: 'Close',
expand: 'Expand history',
collapse: 'Collapse history',
step: 'Step {{number}} · {{time}}{{duration}}',
@@ -59,6 +60,7 @@ const zhCN = {
question: '询问: {{question}}',
waitingPlaceholder: '等待任务开始...',
stop: '终止',
close: '关闭',
expand: '展开历史',
collapse: '收起历史',
step: '步骤 {{number}} · {{time}}{{duration}}',

View File

@@ -33,7 +33,7 @@ export class Panel {
#statusText: HTMLElement
#historySection: HTMLElement
#expandButton: HTMLElement
#stopButton: HTMLElement
#actionButton: HTMLElement
#inputSection: HTMLElement
#taskInput: HTMLInputElement
@@ -76,7 +76,7 @@ export class Panel {
this.#statusText = this.#wrapper.querySelector(`.${styles.statusText}`)!
this.#historySection = this.#wrapper.querySelector(`.${styles.historySection}`)!
this.#expandButton = this.#wrapper.querySelector(`.${styles.expandButton}`)!
this.#stopButton = this.#wrapper.querySelector(`.${styles.stopButton}`)!
this.#actionButton = this.#wrapper.querySelector(`.${styles.stopButton}`)!
this.#inputSection = this.#wrapper.querySelector(`.${styles.inputSectionWrapper}`)!
this.#taskInput = this.#wrapper.querySelector(`.${styles.taskInput}`)!
@@ -105,6 +105,15 @@ export class Panel {
status === 'running' ? 'thinking' : status === 'idle' ? 'thinking' : status
this.#updateStatusIndicator(indicatorType)
// Morph action button: running = stop (■), not running = close (X)
if (status === 'running') {
this.#actionButton.textContent = '■'
this.#actionButton.title = this.#i18n.t('ui.panel.stop')
} else {
this.#actionButton.textContent = 'X'
this.#actionButton.title = this.#i18n.t('ui.panel.close')
}
// Show/hide based on status
if (status === 'running') {
this.show()
@@ -266,10 +275,14 @@ export class Panel {
}
/**
* Stop Agent
* Action button handler: stop when running, close (dispose) when idle
*/
#stopAgent(): void {
this.#agent.dispose()
#handleActionButton(): void {
if (this.#agent.status === 'running') {
this.#agent.stop()
} else {
this.#agent.dispose()
}
}
/**
@@ -383,7 +396,7 @@ export class Panel {
<button class="${styles.controlButton} ${styles.expandButton}" title="${this.#i18n.t('ui.panel.expand')}">
</button>
<button class="${styles.controlButton} ${styles.stopButton}" title="${this.#i18n.t('ui.panel.stop')}">
<button class="${styles.controlButton} ${styles.stopButton}" title="${this.#i18n.t('ui.panel.close')}">
X
</button>
</div>
@@ -420,10 +433,10 @@ export class Panel {
this.#toggle()
})
// Stop button
this.#stopButton.addEventListener('click', (e) => {
// Action button (stop / close)
this.#actionButton.addEventListener('click', (e) => {
e.stopPropagation()
this.#stopAgent()
this.#handleActionButton()
})
// Submit on Enter key in input field

View File

@@ -68,6 +68,9 @@ export interface PanelAgentAdapter extends EventTarget {
/** Execute a task */
execute(task: string): Promise<unknown>
/** Dispose the agent */
/** Stop the current task (agent remains reusable) */
stop(): void
/** Dispose the agent (terminal, cannot be reused) */
dispose(): void
}