Merge branch 'main' of https://github.com/alibaba/page-agent
This commit is contained in:
@@ -344,7 +344,7 @@ export class PageAgentCore extends EventTarget {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
await waitFor(0.4) // @TODO: configurable
|
await waitFor(this.config.stepDelay ?? 0.4)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -512,7 +512,8 @@ export class PageAgentCore extends EventTarget {
|
|||||||
// Accumulated wait time warning
|
// Accumulated wait time warning
|
||||||
if (this.#states.totalWaitTime >= 3) {
|
if (this.#states.totalWaitTime >= 3) {
|
||||||
this.pushObservation(
|
this.pushObservation(
|
||||||
`You have waited ${this.#states.totalWaitTime} seconds accumulatively. DO NOT wait any longer unless you have a good reason.`
|
`You have waited ${this.#states.totalWaitTime} seconds accumulatively. ` +
|
||||||
|
`DO NOT wait any longer unless you have a good reason.`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -528,7 +529,8 @@ export class PageAgentCore extends EventTarget {
|
|||||||
const remaining = this.config.maxSteps - step
|
const remaining = this.config.maxSteps - step
|
||||||
if (remaining === 5) {
|
if (remaining === 5) {
|
||||||
this.pushObservation(
|
this.pushObservation(
|
||||||
`⚠️ Only ${remaining} steps remaining. Consider wrapping up or calling done with partial results.`
|
`⚠️ Only ${remaining} steps remaining. ` +
|
||||||
|
`Consider wrapping up or calling done with partial results.`
|
||||||
)
|
)
|
||||||
} else if (remaining === 2) {
|
} else if (remaining === 2) {
|
||||||
this.pushObservation(
|
this.pushObservation(
|
||||||
|
|||||||
@@ -152,6 +152,12 @@ export interface AgentConfig extends LLMConfig {
|
|||||||
* @experimental Use with caution - incorrect prompts may break agent behavior.
|
* @experimental Use with caution - incorrect prompts may break agent behavior.
|
||||||
*/
|
*/
|
||||||
customSystemPrompt?: string
|
customSystemPrompt?: string
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delay between steps in seconds.
|
||||||
|
* @default 0.4
|
||||||
|
*/
|
||||||
|
stepDelay?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -213,14 +213,18 @@ export async function selectOptionElement(selectElement: HTMLSelectElement, opti
|
|||||||
await waitFor(0.1) // Wait to ensure change event processing completes
|
await waitFor(0.1) // Wait to ensure change event processing completes
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface ScrollableElement extends HTMLElement {
|
||||||
|
scrollIntoViewIfNeeded?: (centerIfNeeded?: boolean) => void
|
||||||
|
}
|
||||||
|
|
||||||
export async function scrollIntoViewIfNeeded(element: HTMLElement) {
|
export async function scrollIntoViewIfNeeded(element: HTMLElement) {
|
||||||
const el = element as any
|
const el = element as ScrollableElement
|
||||||
if (el.scrollIntoViewIfNeeded) {
|
if (typeof el.scrollIntoViewIfNeeded === 'function') {
|
||||||
el.scrollIntoViewIfNeeded()
|
el.scrollIntoViewIfNeeded()
|
||||||
// await waitFor(0.5) // Animation playback
|
// await waitFor(0.5) // Animation playback
|
||||||
} else {
|
} else {
|
||||||
// @todo visibility check
|
// @todo visibility check
|
||||||
el.scrollIntoView({ behavior: 'auto', block: 'center', inline: 'nearest' })
|
element.scrollIntoView({ behavior: 'auto', block: 'center', inline: 'nearest' })
|
||||||
// await waitFor(0.5) // Animation playback
|
// await waitFor(0.5) // Animation playback
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user