page-agent 1.5.5 → 1.5.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -49,8 +49,8 @@ Fastest way to try PageAgent with our free Demo LLM:
49
49
 
50
50
  | Mirrors | URL |
51
51
  | ------- | ---------------------------------------------------------------------------------- |
52
- | Global | https://cdn.jsdelivr.net/npm/page-agent@1.5.5/dist/iife/page-agent.demo.js |
53
- | China | https://registry.npmmirror.com/page-agent/1.5.5/files/dist/iife/page-agent.demo.js |
52
+ | Global | https://cdn.jsdelivr.net/npm/page-agent@1.5.6/dist/iife/page-agent.demo.js |
53
+ | China | https://registry.npmmirror.com/page-agent/1.5.6/files/dist/iife/page-agent.demo.js |
54
54
 
55
55
  > **⚠️ For technical evaluation only.** This demo CDN uses our free [testing LLM API](https://alibaba.github.io/page-agent/docs/features/models#free-testing-api). By using it, you agree to its [terms](https://github.com/alibaba/page-agent/blob/main/docs/terms-and-privacy.md).
56
56
 
@@ -244,7 +244,7 @@ ${s}
244
244
 
245
245
  ${c}
246
246
 
247
- ${d}`,g=o.pixels_below>4&&n!==-1?`... ${o.pixels_below} pixels below (${o.pages_below.toFixed(1)} pages) - scroll to see more ...`:"[End of page]";return{url:e,title:t,header:h,content:r,footer:g}}async updateTree(){this.dispatchEvent(new Event("beforeUpdate")),this.lastTimeUpdate=Date.now(),this.mask&&(this.mask.wrapper.style.pointerEvents="none"),cleanUpHighlights();const e=[...this.config.interactiveBlacklist||[],...document.querySelectorAll("[data-page-agent-not-interactive]").values()];return this.flatTree=getFlatTree({...this.config,interactiveBlacklist:e}),this.simplifiedHTML=flatTreeToString(this.flatTree,this.config.includeAttributes),this.selectorMap.clear(),this.selectorMap=getSelectorMap(this.flatTree),this.elementTextMap.clear(),this.elementTextMap=getElementTextMap(this.simplifiedHTML),this.isIndexed=!0,this.mask&&(this.mask.wrapper.style.pointerEvents="auto"),this.dispatchEvent(new Event("afterUpdate")),this.simplifiedHTML}async cleanUpHighlights(){cleanUpHighlights()}assertIndexed(){if(!this.isIndexed)throw new Error("DOM tree not indexed yet. Can not perform actions on elements.")}async clickElement(e){try{this.assertIndexed();const t=getElementByIndex(this.selectorMap,e),o=this.elementTextMap.get(e);return await clickElement(t),t instanceof HTMLAnchorElement&&t.target==="_blank"?{success:!0,message:`✅ Clicked element (${o??e}). ⚠️ Link opened in a new tab.`}:{success:!0,message:`✅ Clicked element (${o??e}).`}}catch(t){return{success:!1,message:`❌ Failed to click element: ${t}`}}}async inputText(e,t){try{this.assertIndexed();const o=getElementByIndex(this.selectorMap,e),n=this.elementTextMap.get(e);return await inputTextElement(o,t),{success:!0,message:`✅ Input text (${t}) into element (${n??e}).`}}catch(o){return{success:!1,message:`❌ Failed to input text: ${o}`}}}async selectOption(e,t){try{this.assertIndexed();const o=getElementByIndex(this.selectorMap,e),n=this.elementTextMap.get(e);return await selectOptionElement(o,t),{success:!0,message:`✅ Selected option (${t}) in element (${n??e}).`}}catch(o){return{success:!1,message:`❌ Failed to select option: ${o}`}}}async scroll(e){try{const{down:t,numPages:o,pixels:n,index:r}=e;this.assertIndexed();const i=n??o*(t?1:-1)*window.innerHeight,s=r!==void 0?getElementByIndex(this.selectorMap,r):null;return{success:!0,message:await scrollVertically(t,i,s)}}catch(t){return{success:!1,message:`❌ Failed to scroll: ${t}`}}}async scrollHorizontally(e){try{const{right:t,pixels:o,index:n}=e;this.assertIndexed();const r=o*(t?1:-1),i=n!==void 0?getElementByIndex(this.selectorMap,n):null;return{success:!0,message:await scrollHorizontally(t,r,i)}}catch(t){return{success:!1,message:`❌ Failed to scroll horizontally: ${t}`}}}async executeJavascript(script){try{const asyncFunction=eval(`(async () => { ${script} })`),result=await asyncFunction();return{success:!0,message:`✅ Executed JavaScript. Result: ${result}`}}catch(e){return{success:!1,message:`❌ Error executing JavaScript: ${e}`}}}async showMask(){await this.maskReady,this.mask?.show()}async hideMask(){await this.maskReady,this.mask?.hide()}dispose(){cleanUpHighlights(),this.flatTree=null,this.selectorMap.clear(),this.elementTextMap.clear(),this.simplifiedHTML="<EMPTY>",this.isIndexed=!1,this.mask?.dispose(),this.mask=null}};a(_PageController,"PageController");let PageController=_PageController;const enUS={ui:{panel:{ready:"Ready",thinking:"Thinking...",taskInput:"Enter new task, describe steps in detail, press Enter to submit",userAnswerPrompt:"Please answer the question above, press Enter to submit",taskTerminated:"Task terminated",taskCompleted:"Task completed",userAnswer:"User answer: {{input}}",question:"Question: {{question}}",waitingPlaceholder:"Waiting for task to start...",stop:"Stop",close:"Close",expand:"Expand history",collapse:"Collapse history",step:"Step {{number}}"},tools:{clicking:"Clicking element [{{index}}]...",inputting:"Inputting text to element [{{index}}]...",selecting:'Selecting option "{{text}}"...',scrolling:"Scrolling page...",waiting:"Waiting {{seconds}} seconds...",askingUser:"Asking user...",done:"Task done",clicked:"🖱️ Clicked element [{{index}}]",inputted:'⌨️ Inputted text "{{text}}"',selected:'☑️ Selected option "{{text}}"',scrolled:"🛞 Page scrolled",waited:"⌛️ Wait completed",executing:"Executing {{toolName}}...",resultSuccess:"success",resultFailure:"failed",resultError:"error"},errors:{elementNotFound:"No interactive element found at index {{index}}",taskRequired:"Task description is required",executionFailed:"Task execution failed",notInputElement:"Element is not an input or textarea",notSelectElement:"Element is not a select element",optionNotFound:'Option "{{text}}" not found'}}},zhCN={ui:{panel:{ready:"准备就绪",thinking:"正在思考...",taskInput:"输入新任务,详细描述步骤,回车提交",userAnswerPrompt:"请回答上面问题,回车提交",taskTerminated:"任务已终止",taskCompleted:"任务结束",userAnswer:"用户回答: {{input}}",question:"询问: {{question}}",waitingPlaceholder:"等待任务开始...",stop:"终止",close:"关闭",expand:"展开历史",collapse:"收起历史",step:"步骤 {{number}}"},tools:{clicking:"正在点击元素 [{{index}}]...",inputting:"正在输入文本到元素 [{{index}}]...",selecting:'正在选择选项 "{{text}}"...',scrolling:"正在滚动页面...",waiting:"等待 {{seconds}} 秒...",askingUser:"正在询问用户...",done:"结束任务",clicked:"🖱️ 已点击元素 [{{index}}]",inputted:'⌨️ 已输入文本 "{{text}}"',selected:'☑️ 已选择选项 "{{text}}"',scrolled:"🛞 页面滚动完成",waited:"⌛️ 等待完成",executing:"正在执行 {{toolName}}...",resultSuccess:"成功",resultFailure:"失败",resultError:"错误"},errors:{elementNotFound:"未找到索引为 {{index}} 的交互元素",taskRequired:"任务描述不能为空",executionFailed:"任务执行失败",notInputElement:"元素不是输入框或文本域",notSelectElement:"元素不是选择框",optionNotFound:'未找到选项 "{{text}}"'}}},locales={"en-US":enUS,"zh-CN":zhCN},dt=class dt{language;translations;constructor(t="en-US"){this.language=t in locales?t:"en-US",this.translations=locales[this.language]}t(t,o){const n=this.getNestedValue(this.translations,t);return n?o?this.interpolate(n,o):n:(console.warn(`Translation key "${t}" not found for language "${this.language}"`),t)}getNestedValue(t,o){return o.split(".").reduce((n,r)=>n?.[r],t)}interpolate(t,o){return t.replace(/\{\{(\w+)\}\}/g,(n,r)=>o[r]!=null?o[r].toString():n)}getLanguage(){return this.language}};a(dt,"I18n");let I18n=dt;function truncate(e,t){return e.length>t?e.substring(0,t)+"...":e}a(truncate,"truncate");function escapeHtml(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;")}a(escapeHtml,"escapeHtml");const wrapper$1="_wrapper_gtdpc_1",background="_background_gtdpc_39",header="_header_gtdpc_99",pulse="_pulse_gtdpc_1",retryPulse="_retryPulse_gtdpc_1",statusTextFadeOut="_statusTextFadeOut_gtdpc_1",statusTextFadeIn="_statusTextFadeIn_gtdpc_1",statusSection="_statusSection_gtdpc_121",indicator="_indicator_gtdpc_128",thinking="_thinking_gtdpc_137",tool_executing="_tool_executing_gtdpc_142",retry="_retry_gtdpc_147",completed="_completed_gtdpc_153",input="_input_gtdpc_154",output="_output_gtdpc_155",error="_error_gtdpc_160",statusText="_statusText_gtdpc_166",fadeOut="_fadeOut_gtdpc_178",fadeIn="_fadeIn_gtdpc_182",controls="_controls_gtdpc_188",controlButton="_controlButton_gtdpc_193",stopButton="_stopButton_gtdpc_212",historySectionWrapper="_historySectionWrapper_gtdpc_246",shimmer="_shimmer_gtdpc_1",celebrate="_celebrate_gtdpc_1",expanded="_expanded_gtdpc_278",historySection="_historySection_gtdpc_246",historyItem="_historyItem_gtdpc_297",observation="_observation_gtdpc_355",question="_question_gtdpc_360",doneSuccess="_doneSuccess_gtdpc_366",historyContent="_historyContent_gtdpc_402",statusIcon="_statusIcon_gtdpc_403",doneError="_doneError_gtdpc_412",reflectionLines="_reflectionLines_gtdpc_462",historyMeta="_historyMeta_gtdpc_469",inputSectionWrapper="_inputSectionWrapper_gtdpc_539",hidden="_hidden_gtdpc_562",inputSection="_inputSection_gtdpc_539",taskInput="_taskInput_gtdpc_573",styles$1={wrapper:wrapper$1,"mask-running":"_mask-running_gtdpc_1",background,header,pulse,retryPulse,statusTextFadeOut,statusTextFadeIn,statusSection,indicator,thinking,tool_executing,retry,completed,input,output,error,statusText,fadeOut,fadeIn,controls,controlButton,stopButton,historySectionWrapper,shimmer,celebrate,expanded,historySection,historyItem,observation,question,doneSuccess,historyContent,statusIcon,doneError,reflectionLines,historyMeta,inputSectionWrapper,hidden,inputSection,taskInput};function createCard({icon:e,content:t,meta:o,type:n}){const r=n?styles$1[n]:"",i=Array.isArray(t)?`<div class="${styles$1.reflectionLines}">${t.join("")}</div>`:`<span>${escapeHtml(t)}</span>`;return`
247
+ ${d}`,g=o.pixels_below>4&&n!==-1?`... ${o.pixels_below} pixels below (${o.pages_below.toFixed(1)} pages) - scroll to see more ...`:"[End of page]";return{url:e,title:t,header:h,content:r,footer:g}}async updateTree(){this.dispatchEvent(new Event("beforeUpdate")),this.lastTimeUpdate=Date.now(),this.mask&&(this.mask.wrapper.style.pointerEvents="none"),cleanUpHighlights();const e=[...this.config.interactiveBlacklist||[],...document.querySelectorAll("[data-page-agent-not-interactive]").values()];return this.flatTree=getFlatTree({...this.config,interactiveBlacklist:e}),this.simplifiedHTML=flatTreeToString(this.flatTree,this.config.includeAttributes),this.selectorMap.clear(),this.selectorMap=getSelectorMap(this.flatTree),this.elementTextMap.clear(),this.elementTextMap=getElementTextMap(this.simplifiedHTML),this.isIndexed=!0,this.mask&&(this.mask.wrapper.style.pointerEvents="auto"),this.dispatchEvent(new Event("afterUpdate")),this.simplifiedHTML}async cleanUpHighlights(){cleanUpHighlights()}assertIndexed(){if(!this.isIndexed)throw new Error("DOM tree not indexed yet. Can not perform actions on elements.")}async clickElement(e){try{this.assertIndexed();const t=getElementByIndex(this.selectorMap,e),o=this.elementTextMap.get(e);return await clickElement(t),t instanceof HTMLAnchorElement&&t.target==="_blank"?{success:!0,message:`✅ Clicked element (${o??e}). ⚠️ Link opened in a new tab.`}:{success:!0,message:`✅ Clicked element (${o??e}).`}}catch(t){return{success:!1,message:`❌ Failed to click element: ${t}`}}}async inputText(e,t){try{this.assertIndexed();const o=getElementByIndex(this.selectorMap,e),n=this.elementTextMap.get(e);return await inputTextElement(o,t),{success:!0,message:`✅ Input text (${t}) into element (${n??e}).`}}catch(o){return{success:!1,message:`❌ Failed to input text: ${o}`}}}async selectOption(e,t){try{this.assertIndexed();const o=getElementByIndex(this.selectorMap,e),n=this.elementTextMap.get(e);return await selectOptionElement(o,t),{success:!0,message:`✅ Selected option (${t}) in element (${n??e}).`}}catch(o){return{success:!1,message:`❌ Failed to select option: ${o}`}}}async scroll(e){try{const{down:t,numPages:o,pixels:n,index:r}=e;this.assertIndexed();const i=n??o*(t?1:-1)*window.innerHeight,s=r!==void 0?getElementByIndex(this.selectorMap,r):null;return{success:!0,message:await scrollVertically(t,i,s)}}catch(t){return{success:!1,message:`❌ Failed to scroll: ${t}`}}}async scrollHorizontally(e){try{const{right:t,pixels:o,index:n}=e;this.assertIndexed();const r=o*(t?1:-1),i=n!==void 0?getElementByIndex(this.selectorMap,n):null;return{success:!0,message:await scrollHorizontally(t,r,i)}}catch(t){return{success:!1,message:`❌ Failed to scroll horizontally: ${t}`}}}async executeJavascript(script){try{const asyncFunction=eval(`(async () => { ${script} })`),result=await asyncFunction();return{success:!0,message:`✅ Executed JavaScript. Result: ${result}`}}catch(e){return{success:!1,message:`❌ Error executing JavaScript: ${e}`}}}async showMask(){await this.maskReady,this.mask?.show()}async hideMask(){await this.maskReady,this.mask?.hide()}dispose(){cleanUpHighlights(),this.flatTree=null,this.selectorMap.clear(),this.elementTextMap.clear(),this.simplifiedHTML="<EMPTY>",this.isIndexed=!1,this.mask?.dispose(),this.mask=null}};a(_PageController,"PageController");let PageController=_PageController;const enUS={ui:{panel:{ready:"Ready",thinking:"Thinking...",taskInput:"Enter new task, describe steps in detail, press Enter to submit",userAnswerPrompt:"Please answer the question above, press Enter to submit",taskTerminated:"Task terminated",taskCompleted:"Task completed",userAnswer:"User answer: {{input}}",question:"Question: {{question}}",waitingPlaceholder:"Waiting for task to start...",stop:"Stop",close:"Close",expand:"Expand history",collapse:"Collapse history",step:"Step {{number}}"},tools:{clicking:"Clicking element [{{index}}]...",inputting:"Inputting text to element [{{index}}]...",selecting:'Selecting option "{{text}}"...',scrolling:"Scrolling page...",waiting:"Waiting {{seconds}} seconds...",askingUser:"Asking user...",done:"Task done",clicked:"🖱️ Clicked element [{{index}}]",inputted:'⌨️ Inputted text "{{text}}"',selected:'☑️ Selected option "{{text}}"',scrolled:"🛞 Page scrolled",waited:"⌛️ Wait completed",executing:"Executing {{toolName}}...",resultSuccess:"success",resultFailure:"failed",resultError:"error"},errors:{elementNotFound:"No interactive element found at index {{index}}",taskRequired:"Task description is required",executionFailed:"Task execution failed",notInputElement:"Element is not an input or textarea",notSelectElement:"Element is not a select element",optionNotFound:'Option "{{text}}" not found'}}},zhCN={ui:{panel:{ready:"准备就绪",thinking:"正在思考...",taskInput:"输入新任务,详细描述步骤,回车提交",userAnswerPrompt:"请回答上面问题,回车提交",taskTerminated:"任务已终止",taskCompleted:"任务结束",userAnswer:"用户回答: {{input}}",question:"询问: {{question}}",waitingPlaceholder:"等待任务开始...",stop:"终止",close:"关闭",expand:"展开历史",collapse:"收起历史",step:"步骤 {{number}}"},tools:{clicking:"正在点击元素 [{{index}}]...",inputting:"正在输入文本到元素 [{{index}}]...",selecting:'正在选择选项 "{{text}}"...',scrolling:"正在滚动页面...",waiting:"等待 {{seconds}} 秒...",askingUser:"正在询问用户...",done:"结束任务",clicked:"🖱️ 已点击元素 [{{index}}]",inputted:'⌨️ 已输入文本 "{{text}}"',selected:'☑️ 已选择选项 "{{text}}"',scrolled:"🛞 页面滚动完成",waited:"⌛️ 等待完成",executing:"正在执行 {{toolName}}...",resultSuccess:"成功",resultFailure:"失败",resultError:"错误"},errors:{elementNotFound:"未找到索引为 {{index}} 的交互元素",taskRequired:"任务描述不能为空",executionFailed:"任务执行失败",notInputElement:"元素不是输入框或文本域",notSelectElement:"元素不是选择框",optionNotFound:'未找到选项 "{{text}}"'}}},locales={"en-US":enUS,"zh-CN":zhCN},dt=class dt{language;translations;constructor(t="en-US"){this.language=t in locales?t:"en-US",this.translations=locales[this.language]}t(t,o){const n=this.getNestedValue(this.translations,t);return n?o?this.interpolate(n,o):n:(console.warn(`Translation key "${t}" not found for language "${this.language}"`),t)}getNestedValue(t,o){return o.split(".").reduce((n,r)=>n?.[r],t)}interpolate(t,o){return t.replace(/\{\{(\w+)\}\}/g,(n,r)=>o[r]!=null?o[r].toString():n)}getLanguage(){return this.language}};a(dt,"I18n");let I18n=dt;function truncate(e,t){return e.length>t?e.substring(0,t)+"...":e}a(truncate,"truncate");function escapeHtml(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;")}a(escapeHtml,"escapeHtml");const wrapper$1="_wrapper_gtdpc_1",background="_background_gtdpc_39",header="_header_gtdpc_99",pulse="_pulse_gtdpc_1",retryPulse="_retryPulse_gtdpc_1",statusTextFadeOut="_statusTextFadeOut_gtdpc_1",statusTextFadeIn="_statusTextFadeIn_gtdpc_1",statusSection="_statusSection_gtdpc_121",indicator="_indicator_gtdpc_128",thinking="_thinking_gtdpc_137",tool_executing="_tool_executing_gtdpc_142",retry="_retry_gtdpc_147",completed="_completed_gtdpc_153",input="_input_gtdpc_154",output="_output_gtdpc_155",error="_error_gtdpc_160",statusText="_statusText_gtdpc_166",fadeOut="_fadeOut_gtdpc_178",fadeIn="_fadeIn_gtdpc_182",controls="_controls_gtdpc_188",controlButton="_controlButton_gtdpc_193",stopButton="_stopButton_gtdpc_212",historySectionWrapper="_historySectionWrapper_gtdpc_246",shimmer="_shimmer_gtdpc_1",celebrate="_celebrate_gtdpc_1",expanded="_expanded_gtdpc_278",historySection="_historySection_gtdpc_246",historyItem="_historyItem_gtdpc_297",observation="_observation_gtdpc_355",question="_question_gtdpc_360",doneSuccess="_doneSuccess_gtdpc_366",historyContent="_historyContent_gtdpc_402",statusIcon="_statusIcon_gtdpc_403",doneError="_doneError_gtdpc_412",reflectionLines="_reflectionLines_gtdpc_462",historyMeta="_historyMeta_gtdpc_469",inputSectionWrapper="_inputSectionWrapper_gtdpc_539",hidden="_hidden_gtdpc_562",inputSection="_inputSection_gtdpc_539",taskInput="_taskInput_gtdpc_573",styles$1={wrapper:wrapper$1,"mask-running":"_mask-running_gtdpc_1",background,header,pulse,retryPulse,statusTextFadeOut,statusTextFadeIn,statusSection,indicator,thinking,tool_executing,retry,completed,input,output,error,statusText,fadeOut,fadeIn,controls,controlButton,stopButton,historySectionWrapper,shimmer,celebrate,expanded,historySection,historyItem,observation,question,doneSuccess,historyContent,statusIcon,doneError,reflectionLines,historyMeta,inputSectionWrapper,hidden,inputSection,taskInput};function createCard({icon:e,content:t,meta:o,type:n}){const r=n?styles$1[n]:"",i=Array.isArray(t)?`<div class="${styles$1.reflectionLines}">${t.map(s=>`<span>${escapeHtml(s)}</span>`).join("")}</div>`:`<span>${escapeHtml(t)}</span>`;return`
248
248
  <div class="${styles$1.historyItem} ${r}">
249
249
  <div class="${styles$1.historyContent}">
250
250
  <span class="${styles$1.statusIcon}">${e}</span>
@@ -252,7 +252,7 @@ ${d}`,g=o.pixels_below>4&&n!==-1?`... ${o.pixels_below} pixels below (${o.pages_
252
252
  </div>
253
253
  ${o?`<div class="${styles$1.historyMeta}">${o}</div>`:""}
254
254
  </div>
255
- `}a(createCard,"createCard");function createReflectionLines(e){const t=[];return e.evaluation_previous_goal&&t.push(`<div>🔍 ${escapeHtml(e.evaluation_previous_goal)}</div>`),e.memory&&t.push(`<div>💾 ${escapeHtml(e.memory)}</div>`),e.next_goal&&t.push(`<div>🎯 ${escapeHtml(e.next_goal)}</div>`),t}a(createReflectionLines,"createReflectionLines");const pt=class pt{constructor(t,o={}){Z(this,_);Z(this,ne);Z(this,je);Z(this,ie);Z(this,ye);Z(this,Ce);Z(this,be);Z(this,Re);Z(this,we);Z(this,B);Z(this,Ge);Z(this,$e,!1);Z(this,j);Z(this,xe,null);Z(this,ve,!1);Z(this,Ze,null);Z(this,Q,null);Z(this,Be,!1);Z(this,He,a(()=>b(this,_,Ot).call(this),"#onStatusChange"));Z(this,Je,a(()=>b(this,_,Ct).call(this),"#onHistoryChange"));Z(this,Ye,a(t=>b(this,_,Rt).call(this,t.detail),"#onActivity"));Z(this,qe,a(()=>this.dispose(),"#onAgentDispose"));S(this,B,t),S(this,Ge,o),S(this,j,new I18n(o.language??"en-US")),p(this,B).onAskUser=n=>b(this,_,Zt).call(this,n),S(this,ne,b(this,_,Dt).call(this)),S(this,je,p(this,ne).querySelector(`.${styles$1.indicator}`)),S(this,ie,p(this,ne).querySelector(`.${styles$1.statusText}`)),S(this,ye,p(this,ne).querySelector(`.${styles$1.historySection}`)),S(this,Ce,p(this,ne).querySelector(`.${styles$1.expandButton}`)),S(this,be,p(this,ne).querySelector(`.${styles$1.stopButton}`)),S(this,Re,p(this,ne).querySelector(`.${styles$1.inputSectionWrapper}`)),S(this,we,p(this,ne).querySelector(`.${styles$1.taskInput}`)),p(this,B).addEventListener("statuschange",p(this,He)),p(this,B).addEventListener("historychange",p(this,Je)),p(this,B).addEventListener("activity",p(this,Ye)),p(this,B).addEventListener("dispose",p(this,qe)),b(this,_,Ut).call(this),b(this,_,jt).call(this),b(this,_,tt).call(this),this.hide()}get wrapper(){return p(this,ne)}show(){this.wrapper.style.display="block",this.wrapper.offsetHeight,this.wrapper.style.opacity="1",this.wrapper.style.transform="translateX(-50%) translateY(0)"}hide(){this.wrapper.style.opacity="0",this.wrapper.style.transform="translateX(-50%) translateY(20px)",this.wrapper.style.display="none"}reset(){p(this,ie).textContent=p(this,j).t("ui.panel.ready"),b(this,_,Fe).call(this,"thinking"),b(this,_,kt).call(this),b(this,_,it).call(this),S(this,ve,!1),S(this,xe,null),b(this,_,tt).call(this)}expand(){b(this,_,ot).call(this)}collapse(){b(this,_,it).call(this)}dispose(){p(this,B).removeEventListener("statuschange",p(this,He)),p(this,B).removeEventListener("historychange",p(this,Je)),p(this,B).removeEventListener("activity",p(this,Ye)),p(this,B).removeEventListener("dispose",p(this,qe)),S(this,ve,!1),b(this,_,Bt).call(this),this.wrapper.remove()}};ne=new WeakMap,je=new WeakMap,ie=new WeakMap,ye=new WeakMap,Ce=new WeakMap,be=new WeakMap,Re=new WeakMap,we=new WeakMap,B=new WeakMap,Ge=new WeakMap,$e=new WeakMap,j=new WeakMap,xe=new WeakMap,ve=new WeakMap,Ze=new WeakMap,Q=new WeakMap,Be=new WeakMap,He=new WeakMap,Je=new WeakMap,Ye=new WeakMap,qe=new WeakMap,_=new WeakSet,Ot=a(function(){const t=p(this,B).status,o=t==="running"||t==="idle"?"thinking":t;b(this,_,Fe).call(this,o),t==="running"?(p(this,be).textContent="■",p(this,be).title=p(this,j).t("ui.panel.stop")):(p(this,be).textContent="X",p(this,be).title=p(this,j).t("ui.panel.close")),t==="running"&&(this.show(),b(this,_,bt).call(this)),(t==="completed"||t==="error")&&(p(this,$e)||b(this,_,ot).call(this),b(this,_,Ft).call(this)&&b(this,_,tt).call(this))},"#handleStatusChange"),Ct=a(function(){b(this,_,kt).call(this)},"#handleHistoryChange"),Rt=a(function(t){switch(t.type){case"thinking":S(this,Q,p(this,j).t("ui.panel.thinking")),b(this,_,Fe).call(this,"thinking");break;case"executing":S(this,Q,b(this,_,yt).call(this,t.tool,t.input)),b(this,_,Fe).call(this,"executing");break;case"executed":S(this,Q,truncate(t.output,50));break;case"retrying":S(this,Q,`Retrying (${t.attempt}/${t.maxAttempts})`),b(this,_,Fe).call(this,"retrying");break;case"error":S(this,Q,truncate(t.message,50)),b(this,_,Fe).call(this,"error");break}},"#handleActivity"),Zt=a(function(t){return new Promise(o=>{S(this,ve,!0),S(this,xe,o),p(this,$e)||b(this,_,ot).call(this);const n=document.createElement("div");n.innerHTML=createCard({icon:"❓",content:`Question: ${t}`,type:"question"});const r=n.firstElementChild;r.setAttribute("data-temp-card","true"),p(this,ye).appendChild(r),b(this,_,vt).call(this),b(this,_,tt).call(this,p(this,j).t("ui.panel.userAnswerPrompt"))})},"#askUser"),yt=a(function(t,o){const n=o;switch(t){case"click_element_by_index":return p(this,j).t("ui.tools.clicking",{index:n.index});case"input_text":return p(this,j).t("ui.tools.inputting",{index:n.index});case"select_dropdown_option":return p(this,j).t("ui.tools.selecting",{text:n.text});case"scroll":return p(this,j).t("ui.tools.scrolling");case"wait":return p(this,j).t("ui.tools.waiting",{seconds:n.seconds});case"ask_user":return p(this,j).t("ui.tools.askingUser");case"done":return p(this,j).t("ui.tools.done");default:return p(this,j).t("ui.tools.executing",{toolName:t})}},"#getToolExecutingText"),Nt=a(function(){p(this,B).status==="running"?p(this,B).stop():p(this,B).dispose()},"#handleActionButton"),Lt=a(function(){const t=p(this,we).value.trim();t&&(b(this,_,bt).call(this),p(this,ve)?b(this,_,Mt).call(this,t):p(this,B).execute(t))},"#submitTask"),Mt=a(function(t){Array.from(p(this,ye).children).forEach(o=>{o.getAttribute("data-temp-card")==="true"&&o.remove()}),S(this,ve,!1),p(this,xe)&&(p(this,xe).call(this,t),S(this,xe,null))},"#handleUserAnswer"),tt=a(function(t){p(this,we).value="",p(this,we).placeholder=t||p(this,j).t("ui.panel.taskInput"),p(this,Re).classList.remove(styles$1.hidden),setTimeout(()=>{p(this,we).focus()},100)},"#showInputArea"),bt=a(function(){p(this,Re).classList.add(styles$1.hidden)},"#hideInputArea"),Ft=a(function(){if(p(this,ve)||p(this,B).history.length===0)return!0;const o=p(this,B).status;return o==="completed"||o==="error"?p(this,Ge).promptForNextTask??!0:!1},"#shouldShowInputArea"),Dt=a(function(){const t=document.createElement("div");return t.id="page-agent-runtime_agent-panel",t.className=styles$1.wrapper,t.setAttribute("data-browser-use-ignore","true"),t.setAttribute("data-page-agent-ignore","true"),t.innerHTML=`
255
+ `}a(createCard,"createCard");function createReflectionLines(e){const t=[];return e.evaluation_previous_goal&&t.push(`🔍 ${e.evaluation_previous_goal}`),e.memory&&t.push(`💾 ${e.memory}`),e.next_goal&&t.push(`🎯 ${e.next_goal}`),t}a(createReflectionLines,"createReflectionLines");const pt=class pt{constructor(t,o={}){Z(this,_);Z(this,ne);Z(this,je);Z(this,ie);Z(this,ye);Z(this,Ce);Z(this,be);Z(this,Re);Z(this,we);Z(this,B);Z(this,Ge);Z(this,$e,!1);Z(this,j);Z(this,xe,null);Z(this,ve,!1);Z(this,Ze,null);Z(this,Q,null);Z(this,Be,!1);Z(this,He,a(()=>b(this,_,Ot).call(this),"#onStatusChange"));Z(this,Je,a(()=>b(this,_,Ct).call(this),"#onHistoryChange"));Z(this,Ye,a(t=>b(this,_,Rt).call(this,t.detail),"#onActivity"));Z(this,qe,a(()=>this.dispose(),"#onAgentDispose"));S(this,B,t),S(this,Ge,o),S(this,j,new I18n(o.language??"en-US")),p(this,B).onAskUser=n=>b(this,_,Zt).call(this,n),S(this,ne,b(this,_,Dt).call(this)),S(this,je,p(this,ne).querySelector(`.${styles$1.indicator}`)),S(this,ie,p(this,ne).querySelector(`.${styles$1.statusText}`)),S(this,ye,p(this,ne).querySelector(`.${styles$1.historySection}`)),S(this,Ce,p(this,ne).querySelector(`.${styles$1.expandButton}`)),S(this,be,p(this,ne).querySelector(`.${styles$1.stopButton}`)),S(this,Re,p(this,ne).querySelector(`.${styles$1.inputSectionWrapper}`)),S(this,we,p(this,ne).querySelector(`.${styles$1.taskInput}`)),p(this,B).addEventListener("statuschange",p(this,He)),p(this,B).addEventListener("historychange",p(this,Je)),p(this,B).addEventListener("activity",p(this,Ye)),p(this,B).addEventListener("dispose",p(this,qe)),b(this,_,Ut).call(this),b(this,_,jt).call(this),b(this,_,tt).call(this),this.hide()}get wrapper(){return p(this,ne)}show(){this.wrapper.style.display="block",this.wrapper.offsetHeight,this.wrapper.style.opacity="1",this.wrapper.style.transform="translateX(-50%) translateY(0)"}hide(){this.wrapper.style.opacity="0",this.wrapper.style.transform="translateX(-50%) translateY(20px)",this.wrapper.style.display="none"}reset(){p(this,ie).textContent=p(this,j).t("ui.panel.ready"),b(this,_,Fe).call(this,"thinking"),b(this,_,kt).call(this),b(this,_,it).call(this),S(this,ve,!1),S(this,xe,null),b(this,_,tt).call(this)}expand(){b(this,_,ot).call(this)}collapse(){b(this,_,it).call(this)}dispose(){p(this,B).removeEventListener("statuschange",p(this,He)),p(this,B).removeEventListener("historychange",p(this,Je)),p(this,B).removeEventListener("activity",p(this,Ye)),p(this,B).removeEventListener("dispose",p(this,qe)),S(this,ve,!1),b(this,_,Bt).call(this),this.wrapper.remove()}};ne=new WeakMap,je=new WeakMap,ie=new WeakMap,ye=new WeakMap,Ce=new WeakMap,be=new WeakMap,Re=new WeakMap,we=new WeakMap,B=new WeakMap,Ge=new WeakMap,$e=new WeakMap,j=new WeakMap,xe=new WeakMap,ve=new WeakMap,Ze=new WeakMap,Q=new WeakMap,Be=new WeakMap,He=new WeakMap,Je=new WeakMap,Ye=new WeakMap,qe=new WeakMap,_=new WeakSet,Ot=a(function(){const t=p(this,B).status,o=t==="running"||t==="idle"?"thinking":t;b(this,_,Fe).call(this,o),t==="running"?(p(this,be).textContent="■",p(this,be).title=p(this,j).t("ui.panel.stop")):(p(this,be).textContent="X",p(this,be).title=p(this,j).t("ui.panel.close")),t==="running"&&(this.show(),b(this,_,bt).call(this)),(t==="completed"||t==="error")&&(p(this,$e)||b(this,_,ot).call(this),b(this,_,Ft).call(this)&&b(this,_,tt).call(this))},"#handleStatusChange"),Ct=a(function(){b(this,_,kt).call(this)},"#handleHistoryChange"),Rt=a(function(t){switch(t.type){case"thinking":S(this,Q,p(this,j).t("ui.panel.thinking")),b(this,_,Fe).call(this,"thinking");break;case"executing":S(this,Q,b(this,_,yt).call(this,t.tool,t.input)),b(this,_,Fe).call(this,"executing");break;case"executed":S(this,Q,truncate(t.output,50));break;case"retrying":S(this,Q,`Retrying (${t.attempt}/${t.maxAttempts})`),b(this,_,Fe).call(this,"retrying");break;case"error":S(this,Q,truncate(t.message,50)),b(this,_,Fe).call(this,"error");break}},"#handleActivity"),Zt=a(function(t){return new Promise(o=>{S(this,ve,!0),S(this,xe,o),p(this,$e)||b(this,_,ot).call(this);const n=document.createElement("div");n.innerHTML=createCard({icon:"❓",content:`Question: ${t}`,type:"question"});const r=n.firstElementChild;r.setAttribute("data-temp-card","true"),p(this,ye).appendChild(r),b(this,_,vt).call(this),b(this,_,tt).call(this,p(this,j).t("ui.panel.userAnswerPrompt"))})},"#askUser"),yt=a(function(t,o){const n=o;switch(t){case"click_element_by_index":return p(this,j).t("ui.tools.clicking",{index:n.index});case"input_text":return p(this,j).t("ui.tools.inputting",{index:n.index});case"select_dropdown_option":return p(this,j).t("ui.tools.selecting",{text:n.text});case"scroll":return p(this,j).t("ui.tools.scrolling");case"wait":return p(this,j).t("ui.tools.waiting",{seconds:n.seconds});case"ask_user":return p(this,j).t("ui.tools.askingUser");case"done":return p(this,j).t("ui.tools.done");default:return p(this,j).t("ui.tools.executing",{toolName:t})}},"#getToolExecutingText"),Nt=a(function(){p(this,B).status==="running"?p(this,B).stop():p(this,B).dispose()},"#handleActionButton"),Lt=a(function(){const t=p(this,we).value.trim();t&&(b(this,_,bt).call(this),p(this,ve)?b(this,_,Mt).call(this,t):p(this,B).execute(t))},"#submitTask"),Mt=a(function(t){Array.from(p(this,ye).children).forEach(o=>{o.getAttribute("data-temp-card")==="true"&&o.remove()}),S(this,ve,!1),p(this,xe)&&(p(this,xe).call(this,t),S(this,xe,null))},"#handleUserAnswer"),tt=a(function(t){p(this,we).value="",p(this,we).placeholder=t||p(this,j).t("ui.panel.taskInput"),p(this,Re).classList.remove(styles$1.hidden),setTimeout(()=>{p(this,we).focus()},100)},"#showInputArea"),bt=a(function(){p(this,Re).classList.add(styles$1.hidden)},"#hideInputArea"),Ft=a(function(){if(p(this,ve)||p(this,B).history.length===0)return!0;const o=p(this,B).status;return o==="completed"||o==="error"?p(this,Ge).promptForNextTask??!0:!1},"#shouldShowInputArea"),Dt=a(function(){const t=document.createElement("div");return t.id="page-agent-runtime_agent-panel",t.className=styles$1.wrapper,t.setAttribute("data-browser-use-ignore","true"),t.setAttribute("data-page-agent-ignore","true"),t.innerHTML=`
256
256
  <div class="${styles$1.background}"></div>
257
257
  <div class="${styles$1.historySectionWrapper}">
258
258
  <div class="${styles$1.historySection}">
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "page-agent",
3
3
  "private": false,
4
- "version": "1.5.5",
4
+ "version": "1.5.6",
5
5
  "type": "module",
6
6
  "main": "./dist/esm/page-agent.js",
7
7
  "module": "./dist/esm/page-agent.js",
@@ -44,10 +44,10 @@
44
44
  "postpublish": "node -e \"['README.md','LICENSE'].forEach(f=>{try{require('fs').unlinkSync(f)}catch{}})\""
45
45
  },
46
46
  "dependencies": {
47
- "@page-agent/core": "1.5.5",
48
- "@page-agent/llms": "1.5.5",
49
- "@page-agent/page-controller": "1.5.5",
50
- "@page-agent/ui": "1.5.5",
47
+ "@page-agent/core": "1.5.6",
48
+ "@page-agent/llms": "1.5.6",
49
+ "@page-agent/page-controller": "1.5.6",
50
+ "@page-agent/ui": "1.5.6",
51
51
  "chalk": "^5.6.2"
52
52
  },
53
53
  "peerDependencies": {