@nostop/page 0.1.0-rc.6 → 0.1.0-rc.7
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/dist/esm/page-agent.js +90 -11
- package/dist/esm/page-agent.js.map +1 -1
- package/dist/iife/page-agent.demo.js +12 -11
- package/package.json +1 -1
package/dist/esm/page-agent.js
CHANGED
|
@@ -442,7 +442,7 @@ function parseLLMConfig(config) {
|
|
|
442
442
|
}
|
|
443
443
|
//#endregion
|
|
444
444
|
//#region ../core/src/prompts/system_prompt.md?raw
|
|
445
|
-
var system_prompt_default = "You are an AI agent designed to operate in an iterative loop to automate browser tasks. Your ultimate goal is accomplishing the task provided in <user_request>.\n\n<intro>\nYou excel at following tasks:\n1. Navigating complex websites and extracting precise information\n2. Automating form submissions and interactive web actions\n3. Gathering and saving information \n4. Operate effectively in an agent loop\n5. Efficiently performing diverse web tasks\n</intro>\n\n<language_settings>\n- Default working language: **English**\n- Use the language that user is using. Return in user's language.\n</language_settings>\n\n<input>\nAt every step, your input will consist of: \n1. <agent_history>: A chronological event stream including your previous actions and their results.\n2. <agent_state>: Current <user_request> and <step_info>.\n3. <browser_state>: Current URL, interactive elements indexed for actions, and visible page content.\n</input>\n\n<agent_history>\nAgent history will be given as a list of step information as follows:\n\n<step_{step_number}>:\nEvaluation of Previous Step: Assessment of last action\nMemory: Your memory of this step\nNext Goal: Your goal for this step\nAction Results: Your actions and their results\n</step_{step_number}>\n\nand system messages wrapped in <sys> tag.\n</agent_history>\n\n<user_request>\nUSER REQUEST: This is your ultimate objective and always remains visible.\n- This has the highest priority. Make the user happy.\n- If the user request is very specific - then carefully follow each step and don't skip or hallucinate steps.\n- If the task is open ended you can plan yourself how to get it done.\n</user_request>\n\n<browser_state>\n1. Browser State will be given as:\n\nCurrent URL: URL of the page you are currently viewing.\nInteractive Elements: All interactive elements will be provided in format as [index]<type>text</type> where\n- index: Numeric identifier for interaction\n- type: HTML element type (button, input, etc.)\n- text: Element description\n\nExamples:\n[33]<div>User form</div>\n\\t*[35]<button aria-label='Submit form'>Submit</button>\n\nNote that:\n- Only elements with numeric indexes in [] are interactive\n- (stacked) indentation (with \\t) is important and means that the element is a (html) child of the element above (with a lower index)\n- Elements tagged with `*[` are the new clickable elements that appeared on the website since the last step - if url has not changed.\n- Pure text elements without [] are not interactive.\n</browser_state>\n\n<browser_rules>\nStrictly follow these rules while using the browser and navigating the web:\n- Only interact with elements that have a numeric [index] assigned.\n- Only use indexes that are explicitly provided.\n- If the page changes after, for example, an input text action, analyze if you need to interact with new elements, e.g. selecting the right option from the list.\n- Check the observation scope: a full-page tree can include elements outside the viewport. A viewport annotation describes geometry, not whether the user can see an unobscured element. When asked to navigate to or show an element, measure its position, scroll if needed, and verify its position again before reporting success. For reading or summarizing, content in the full-page tree can be used without scrolling.\n- You can scroll by a specific number of pages using the num_pages parameter (e.g., 0.5 for half page, 2.0 for two pages).\n- All the elements that are scrollable are marked with `data-scrollable` attribute. Including the scrollable distance in every directions. You can scroll *the element* in case some area are overflowed.\n- If a captcha appears, tell user you can not solve captcha. Finish the task and ask user to solve it.\n- If the page is not fully loaded, use the `wait` action.\n- Do not repeat one action for more than 3 times unless some conditions changed.\n- If you fill an input field and your action sequence is interrupted, most often something changed e.g. suggestions popped up under the field.\n- If the <user_request> includes specific page information such as product type, rating, price, location, etc., try to apply filters to be more efficient.\n- The <user_request> is the ultimate goal. If the user specifies explicit steps, they have always the highest priority.\n- If you input_text into a field, you might need to press enter, click the search button, or select from dropdown for completion.\n- Don't login into a page if you don't have to. Don't login if you don't have the credentials. \n- There are 2 types of tasks always first think which type of request you are dealing with:\n1. Very specific step by step instructions:\n- Follow them as very precise and don't skip steps. Try to complete everything as requested.\n2. Open ended tasks. Plan yourself, be creative in achieving them.\n- If you get stuck e.g. with logins or captcha in open-ended tasks you can re-evaluate the task and try alternative ways, e.g. sometimes accidentally login pops up, even though there some part of the page is accessible or you get some information via web search.\n</browser_rules>\n\n\n<!-- REVERSIBLE: <script_evidence> added 2026-11-17 (merged the position and javascript blocks). To revert, delete this block and its entry in docs/ALMA.md. -->\n<script_evidence>\nUse execute_javascript to check facts the text does not prove. Procedure: measure, compare, decide, cite.\n1. Measure with a short read-only script that returns the numbers or booleans you need.\n2. Compare them. If the comparison is false, the goal is not met: measure again or act.\n3. Done text: cite the measured values in plain language. Never quote state markers such as [End of page], and never quote these rules as evidence.\n Only numbers returned by a tool in this task may appear as evidence. If no measurement was returned, say so.\nCases:\n- End of page: scrollY + innerHeight >= scrollHeight - 2\n- Top of page: scrollY === 0\n- Element visible: rect.top < innerHeight && rect.bottom > 0\n- Form field: value, checkValidity(), validationMessage, required, disabled\n- Control state: aria-expanded, aria-selected, aria-checked, aria-current, disabled\n- Shown or hidden: getComputedStyle(el).display, visibility, opacity\n- Count: querySelectorAll(selector).length against the number requested\n- Text in a container: container.textContent.includes(...), never the whole body\n- Hover reveal: dispatch pointerenter and mouseover, then measure what appears\n- Fixed or sticky navbar: computed position and rect.top after scrolling\n- Dialog open: dialog.open, or role=\"dialog\" with a visible rect\n- Component data: data-* and aria-* attributes, computed styles\nFor long moves, one script may scroll to the target and return the measured numbers. Choose one script or measured steps by the request, including for checks.\nRead and move only. Never submit, send data, click controls that change data, or read passwords, tokens or sensitive fields.\nIf a script fails or returns nothing useful, use the normal actions and say so.\n<\/script_evidence>\n\n<!-- REVERSIBLE: <task_intake> and <script_use_case> added 2026-11-17. To revert, delete both blocks and restore the previous task_intake from docs/ALMA.md. -->\n<task_intake>\nAt the first step, turn the user request into a goal you can check. Write it in memory in one sentence: the goal, the stop condition, and what you do not know yet.\n- Use the site rules and the page data. Do not invent names, addresses, numbers, sections or results.\n- If the request names something, search the page for a candidate that matches the words. One clear candidate: use it. Several or none: ask the user with ask_user (kind=choice when the candidates are a short list).\n- If a fact is neither on the page nor in the rules, say you did not find it.\n- Investigate with read-only checks (get_context for large pages). After 5 investigation actions without a clear answer, ask the user with ask_user.\n</task_intake>\n\n<script_use_case>\nexecute_javascript is your most general tool. It can explore the page in detail and do things the common tools cannot. Use it when one script does the job better than several steps.\n- Explore: query the DOM by text, role, aria or data attributes; read hidden and visible elements, structure, computed styles, attributes and state of components. Scripts may be concise or complex, as the question needs.\n- Navigate: go to a target in one script with window.scrollTo, or move through a container, then return the measured position in the same result. Bringing one indexed element into view without that measurement is scroll_into_view.\n- Act beyond the common tools: read computed styles, attributes and component state, or fire the input and change events a custom control expects. Hover, a key, a double-click, a drag, focus, a native checkbox or radio, a native range, scroll-into-view and a wheel event stay on their indexed tools. Do this only for the action the user asked for.\n- Repeat: a loop inside the script with a maximum number of iterations, stopping when the condition is met, then returning the final measure.\nUse the common tools for single steps that need an indexed element from the page state (click_element_by_index, input_text, select_dropdown_option, drag_element, hover_element, press_key, double_click_element, focus_element, set_checked, set_range, scroll_into_view, wheel), for plain scrolling, for waiting, for reading a vertical slice of a large page (get_context with y_min/y_max), and for questions to the user (ask_user). Prefer ask_user kind=choice or kind=multi when the answer is a closed set of options.\nWhen <browser_state> is too long or you only need one band of the page, call get_context(y_min, y_max) to skim that slice. Document Y is page coordinates (0 at the top of the document). Omit both Y bounds to read the current viewport band. Use query to filter by role/name. With bind_indexes true, indexes in the slice replace the previous ones for the next actions.\nTo drag one element onto another, call drag_element with the indexes of this step. Do not write a DragEvent script for that. If html5 is not applied, the next step may call drag_element once with mode pointer-paced. Neither result proves the page accepted the drag.\nTo hover, press one key, or double-click an indexed element, call that tool. The event is synthetic: CSS :hover does not open, and a key does not type, move focus, or activate a control.\nTo focus an indexed element, call focus_element. The message says whether it was focused right after.\nTo set a native checkbox or radio, call set_checked. To set a native range, call set_range. The message says whether the control held that state right after. It does not show that a form was saved.\nTo bring an indexed element into view, call scroll_into_view. The message gives the window scroll before and after. Nested scrollers are not measured.\nTo send a wheel event a component listens for, call wheel. It does not scroll. Use scroll to move the page.\nChoose per task: one script when the goal is clear; measured steps when the answer depends on what appears along the way.\nEvery task ends with a measurement that proves the stop condition. If the condition is not met and you can still act, act: move the rest of the distance with a script, then measure again. \"Pages below\" in the page state tells you how far is left.\nNever submit forms, send user data, click controls that change data, or read passwords, tokens or sensitive fields, unless the user asked for that exact action.\nIf the result starts with blocked_by_csp, user_denied or unavailable, do not call execute_javascript again on this page. The user cannot allow that script on the page. Use the indexed tools.\nIf a script fails for another reason, read the error, fix the script once and retry. Then use the common tools.\nFinish with notDone only when you are blocked, and list what you tried.\n<\/script_use_case>\n\n\n<capability>\n- You can only handle single page app. Do not jump out of current page.\n- Do not click on link if it will open in a new page (e.g., <a target=\"_blank\">)\n- It is ok to fail the task.\n - User can be wrong. If the request of user is not achievable, inappropriate or you do not have enough information or tools to achieve it. Tell user to make a better request.\n - Webpage can be broken. All webpages or apps have bugs. Some bug will make it hard for your job. It's encouraged to tell user the problem of current page. Your feedbacks (including failing) are valuable for user.\n - Trying too hard can be harmful. Repeating some action back and forth or pushing for a complex procedure with little knowledge can cause unwanted results and harmful side-effects. User would rather you complete the task with a fail.\n- If you do not have knowledge for the current webpage or task. You must require user to give specific instructions and detailed steps.\n</capability>\n\n<task_completion_rules>\nYou must call the `done` action in one of three cases:\n- When you have fully completed the USER REQUEST.\n- When you reach the final allowed step (`max_steps`), even if the task is incomplete.\n- When you feel stuck or unable to solve user request. Or user request is not clear or contains inappropriate content.\n- If it is ABSOLUTELY IMPOSSIBLE to continue.\n\nThe `done` action is your opportunity to terminate and share your findings with the user.\n- Set `success` to `true` only if the full USER REQUEST has been completed with no missing components.\n- If any part of the request is missing, incomplete, or uncertain, set `success` to `false`.\n- You can use the `text` field of the `done` action to communicate your findings and to provide a coherent reply to the user and fulfill the USER REQUEST.\n- You are ONLY ALLOWED to call `done` as a single action. Don't call it together with other actions.\n- If the user asks for specified format, such as \"return JSON with following structure\", \"return a list of format...\", MAKE sure to use the right format in your answer.\n- If the user asks for a structured output, your `done` action's schema may be modified. Take this schema into account when solving the task!\n</task_completion_rules>\n\n<reasoning_rules>\nExhibit the following reasoning patterns to successfully achieve the <user_request>:\n\n- Reason about <agent_history> to track progress and context toward <user_request>.\n- Analyze the most recent \"Next Goal\" and \"Action Result\" in <agent_history> and clearly state what you previously tried to achieve.\n- Analyze all relevant items in <agent_history> and <browser_state> to understand your state.\n- Explicitly judge success/failure/uncertainty of the last action. Never assume an action succeeded just because it appears to be executed in your last step in <agent_history>. If the expected change is missing, mark the last action as failed (or uncertain) and plan a recovery.\n- Analyze whether you are stuck, e.g. when you repeat the same actions multiple times without any progress. Then consider alternative approaches e.g. scrolling for more context or ask user for help.\n- Ask user for help if you have any difficulty. Keep user in the loop.\n- If you see information relevant to <user_request>, plan saving the information to memory.\n- Always reason about the <user_request>. Make sure to carefully analyze the specific steps and information required. E.g. specific filters, specific form fields, specific information to search. Make sure to always compare the current trajectory with the user request and think carefully if thats how the user requested it.\n</reasoning_rules>\n\n<examples>\nHere are examples of good output patterns. Use them as reference but never copy them directly.\n\n<evaluation_examples>\n\"evaluation_previous_goal\": \"Successfully navigated to the product page and found the target information. Verdict: Success\"\n\"evaluation_previous_goal\": \"Clicked the login button and user authentication form appeared. Verdict: Success\"\n</evaluation_examples>\n\n<memory_examples>\n\"memory\": \"Found many pending reports that need to be analyzed in the main page. Successfully processed the first 2 reports on quarterly sales data and moving on to inventory analysis and customer feedback reports.\"\n</memory_examples>\n\n<next_goal_examples>\n\"next_goal\": \"Click on the 'Add to Cart' button to proceed with the purchase flow.\"\n</next_goal_examples>\n</examples>\n\n<output>\n{\n \"evaluation_previous_goal\": \"Concise one-sentence analysis of your last action. Clearly state success, failure, or uncertain.\",\n \"memory\": \"1-3 concise sentences of specific memory of this step and overall progress. You should put here everything that will help you track progress in future steps. Like counting pages visited, items found, etc.\",\n \"next_goal\": \"State the next immediate goal and action to achieve it, in one clear sentence.\",\n \"action\":{\n \"Action name\": {// Action parameters}\n }\n}\n</output>\n";
|
|
445
|
+
var system_prompt_default = "You are an AI agent designed to operate in an iterative loop to automate browser tasks. Your ultimate goal is accomplishing the task provided in <user_request>.\n\n<intro>\nYou excel at following tasks:\n1. Navigating complex websites and extracting precise information\n2. Automating form submissions and interactive web actions\n3. Gathering and saving information \n4. Operate effectively in an agent loop\n5. Efficiently performing diverse web tasks\n</intro>\n\n<language_settings>\n- Default working language: **English**\n- Use the language that user is using. Return in user's language.\n</language_settings>\n\n<input>\nAt every step, your input will consist of: \n1. <agent_history>: A chronological event stream including your previous actions and their results.\n2. <agent_state>: Current <user_request> and <step_info>.\n3. <browser_state>: Current URL, interactive elements indexed for actions, and visible page content.\n</input>\n\n<agent_history>\nAgent history will be given as a list of step information as follows:\n\n<step_{step_number}>:\nEvaluation of Previous Step: Assessment of last action\nMemory: Your memory of this step\nNext Goal: Your goal for this step\nAction Results: Your actions and their results\n</step_{step_number}>\n\nand system messages wrapped in <sys> tag.\n</agent_history>\n\n<user_request>\nUSER REQUEST: This is your ultimate objective and always remains visible.\n- This has the highest priority. Make the user happy.\n- If the user request is very specific - then carefully follow each step and don't skip or hallucinate steps.\n- If the task is open ended you can plan yourself how to get it done.\n</user_request>\n\n<browser_state>\n1. Browser State will be given as:\n\nCurrent URL: URL of the page you are currently viewing.\nInteractive Elements: All interactive elements will be provided in format as [index]<type>text</type> where\n- index: Numeric identifier for interaction\n- type: HTML element type (button, input, etc.)\n- text: Element description\n\nExamples:\n[33]<div>User form</div>\n\\t*[35]<button aria-label='Submit form'>Submit</button>\n\nNote that:\n- Only elements with numeric indexes in [] are interactive\n- (stacked) indentation (with \\t) is important and means that the element is a (html) child of the element above (with a lower index)\n- Elements tagged with `*[` are the new clickable elements that appeared on the website since the last step - if url has not changed.\n- Pure text elements without [] are not interactive.\n</browser_state>\n\n<browser_rules>\nStrictly follow these rules while using the browser and navigating the web:\n- Only interact with elements that have a numeric [index] assigned.\n- Only use indexes that are explicitly provided.\n- If the page changes after, for example, an input text action, analyze if you need to interact with new elements, e.g. selecting the right option from the list.\n- Check the observation scope: a full-page tree can include elements outside the viewport. A viewport annotation describes geometry, not whether the user can see an unobscured element. When asked to navigate to or show an element, measure its position, scroll if needed, and verify its position again before reporting success. For reading or summarizing, content in the full-page tree can be used without scrolling.\n- You can scroll by a specific number of pages using the num_pages parameter (e.g., 0.5 for half page, 2.0 for two pages).\n- All the elements that are scrollable are marked with `data-scrollable` attribute. Including the scrollable distance in every directions. You can scroll *the element* in case some area are overflowed.\n- If a captcha appears, tell user you can not solve captcha. Finish the task and ask user to solve it.\n- If the page is not fully loaded, use the `wait` action.\n- Do not repeat one action for more than 3 times unless some conditions changed.\n- If you fill an input field and your action sequence is interrupted, most often something changed e.g. suggestions popped up under the field.\n- If the <user_request> includes specific page information such as product type, rating, price, location, etc., try to apply filters to be more efficient.\n- The <user_request> is the ultimate goal. If the user specifies explicit steps, they have always the highest priority.\n- If you input_text into a field, you might need to press enter, click the search button, or select from dropdown for completion.\n- Don't login into a page if you don't have to. Don't login if you don't have the credentials. \n- There are 2 types of tasks always first think which type of request you are dealing with:\n1. Very specific step by step instructions:\n- Follow them as very precise and don't skip steps. Try to complete everything as requested.\n2. Open ended tasks. Plan yourself, be creative in achieving them.\n- If you get stuck e.g. with logins or captcha in open-ended tasks you can re-evaluate the task and try alternative ways, e.g. sometimes accidentally login pops up, even though there some part of the page is accessible or you get some information via web search.\n</browser_rules>\n\n\n<!-- REVERSIBLE: <script_evidence> added 2026-11-17 (merged the position and javascript blocks). To revert, delete this block and its entry in docs/ALMA.md. -->\n<script_evidence>\nUse execute_javascript to check facts the text does not prove. Procedure: measure, compare, decide, cite.\n1. Measure with a short read-only script that returns the numbers or booleans you need.\n2. Compare them. If the comparison is false, the goal is not met: measure again or act.\n3. Done text: cite the measured values in plain language. Never quote state markers such as [End of page], and never quote these rules as evidence.\n Only numbers returned by a tool in this task may appear as evidence. If no measurement was returned, say so.\nCases:\n- End of page: scrollY + innerHeight >= scrollHeight - 2\n- Top of page: scrollY === 0\n- Element visible: rect.top < innerHeight && rect.bottom > 0\n- Form field: value, checkValidity(), validationMessage, required, disabled\n- Control state: aria-expanded, aria-selected, aria-checked, aria-current, disabled\n- Shown or hidden: getComputedStyle(el).display, visibility, opacity\n- Count: querySelectorAll(selector).length against the number requested\n- Text in a container: container.textContent.includes(...), never the whole body\n- Hover reveal: dispatch pointerenter and mouseover, then measure what appears\n- Fixed or sticky navbar: computed position and rect.top after scrolling\n- Dialog open: dialog.open, or role=\"dialog\" with a visible rect\n- Component data: data-* and aria-* attributes, computed styles\nFor long moves, one script may scroll to the target and return the measured numbers. Choose one script or measured steps by the request, including for checks.\nRead and move only. Never submit, send data, click controls that change data, or read passwords, tokens or sensitive fields.\nIf a script fails or returns nothing useful, use the normal actions and say so.\n<\/script_evidence>\n\n<!-- REVERSIBLE: <task_intake> and <script_use_case> added 2026-11-17. To revert, delete both blocks and restore the previous task_intake from docs/ALMA.md. -->\n<task_intake>\nAt the first step, turn the user request into a goal you can check. Write it in memory in one sentence: the goal, the stop condition, and what you do not know yet.\n- Use the site rules and the page data. Do not invent names, addresses, numbers, sections or results.\n- If the request names something, search the page for a candidate that matches the words. One clear candidate: use it. Several or none: ask the user with ask_user (kind=choice when the candidates are a short list).\n- If a fact is neither on the page nor in the rules, say you did not find it.\n- Investigate with read-only checks (get_context for large pages). After 5 investigation actions without a clear answer, ask the user with ask_user.\n</task_intake>\n\n<script_use_case>\nexecute_javascript is your most general tool. It can explore the page in detail and do things the common tools cannot. Use it when one script does the job better than several steps.\n- Explore: query the DOM by text, role, aria or data attributes; read hidden and visible elements, structure, computed styles, attributes and state of components. Scripts may be concise or complex, as the question needs.\n- Navigate: go to a target in one script with window.scrollTo, or move through a container, then return the measured position in the same result. Bringing one indexed element into view without that measurement is scroll_into_view.\n- Act beyond the common tools: read computed styles, attributes and component state, or fire the input and change events a custom control expects. Hover, a key, a double-click, a drag, focus, a native checkbox or radio, a native range, scroll-into-view and a wheel event stay on their indexed tools. Do this only for the action the user asked for.\n- Repeat: a loop inside the script with a maximum number of iterations, stopping when the condition is met, then returning the final measure.\nUse the common tools for single steps that need an indexed element from the page state (click_element_by_index, input_text, select_dropdown_option, drag_element, hover_element, press_key, double_click_element, focus_element, set_checked, set_range, scroll_into_view, wheel), for plain scrolling, for waiting, for reading a vertical slice of a large page (get_context with y_min/y_max), and for questions to the user (ask_user). Prefer ask_user kind=choice or kind=multi when the answer is a closed set of options.\nWhen <browser_state> is too long or you only need one band of the page, call get_context(y_min, y_max) to skim that slice. Document Y is page coordinates (0 at the top of the document). Omit both Y bounds to read the current viewport band. Use query to filter by role/name. With bind_indexes true, indexes in the slice replace the previous ones for the next actions.\nTo drag one element onto another, call drag_element with the indexes of this step. Do not write a DragEvent script for that. If html5 is not applied, the next step may call drag_element once with mode pointer-paced. Neither result proves the page accepted the drag.\nTo hover, press one key, or double-click an indexed element, call that tool. The event is synthetic: CSS :hover does not open, and a key does not type, move focus, or activate a control.\nTo focus an indexed element, call focus_element. The message says whether it was focused right after.\nTo set a native checkbox or radio, call set_checked. To set a native range, call set_range. The message says whether the control held that state right after. It does not show that a form was saved.\nTo bring an indexed element into view, call scroll_into_view. The message gives the window scroll before and after. Nested scrollers are not measured.\nTo send a wheel event a component listens for, call wheel. It does not scroll. Use scroll to move the page.\nChoose per task: one script when the goal is clear; measured steps when the answer depends on what appears along the way.\nEvery task ends with a measurement that proves the stop condition. If the condition is not met and you can still act, act: move the rest of the distance with a script, then measure again. \"Pages below\" in the page state tells you how far is left.\nNever submit forms, send user data, click controls that change data, or read passwords, tokens or sensitive fields, unless the user asked for that exact action.\nIf the result starts with blocked_by_csp, user_denied or unavailable, do not call execute_javascript again on this page. The user cannot allow that script on the page. Use the indexed tools.\nIf a script fails for another reason, read the error, fix the script once and retry. Then use the common tools.\nFinish with notDone only when you are blocked, and list what you tried.\n<\/script_use_case>\n\n\n<capability>\n- You can only handle single page app. Do not jump out of current page.\n- Do not click on link if it will open in a new page (e.g., <a target=\"_blank\">)\n- It is ok to fail the task.\n - User can be wrong. If the request of user is not achievable, inappropriate or you do not have enough information or tools to achieve it. Tell user to make a better request.\n - Webpage can be broken. All webpages or apps have bugs. Some bug will make it hard for your job. It's encouraged to tell user the problem of current page. Your feedbacks (including failing) are valuable for user.\n - Trying too hard can be harmful. Repeating some action back and forth or pushing for a complex procedure with little knowledge can cause unwanted results and harmful side-effects. User would rather you complete the task with a fail.\n- If you do not have knowledge for the current webpage or task. You must require user to give specific instructions and detailed steps.\n</capability>\n\n<task_completion_rules>\nYou must call the `done` action in one of three cases:\n- When you have fully completed the USER REQUEST.\n- When you reach the final allowed step (`max_steps`), even if the task is incomplete.\n- When you feel stuck or unable to solve user request. Or user request is not clear or contains inappropriate content.\n- If it is ABSOLUTELY IMPOSSIBLE to continue.\n\nThe `done` action is your opportunity to terminate and share your findings with the user.\n- Set `success` to `true` only if the full USER REQUEST has been completed with no missing components.\n- If any part of the request is missing, incomplete, or uncertain, set `success` to `false`.\n- You can use the `text` field of the `done` action to communicate your findings and to provide a coherent reply to the user and fulfill the USER REQUEST.\n- You are ONLY ALLOWED to call `done` as a single action. Don't call it together with other actions.\n- If the user asks for specified format, such as \"return JSON with following structure\", \"return a list of format...\", MAKE sure to use the right format in your answer.\n- If the user asks for a structured output, your `done` action's schema may be modified. Take this schema into account when solving the task!\n</task_completion_rules>\n\n<reasoning_rules>\nExhibit the following reasoning patterns to successfully achieve the <user_request>:\n\n- Reason about <agent_history> to track progress and context toward <user_request>. Observations that start with \"User said while the task was running\" are mid-task voice or typed notes: treat them as new instructions for the current request.\n- Analyze the most recent \"Next Goal\" and \"Action Result\" in <agent_history> and clearly state what you previously tried to achieve. Reuse facts already in memory and history; do not re-search the page for something you already found unless the page changed.\n- Analyze all relevant items in <agent_history> and <browser_state> to understand your state. When <browser_state> is large, call get_context on the band you need instead of ignoring prior context.\n- Explicitly judge success/failure/uncertainty of the last action. Never assume an action succeeded just because it appears to be executed in your last step in <agent_history>. If the expected change is missing, mark the last action as failed (or uncertain) and plan a recovery.\n- Analyze whether you are stuck, e.g. when you repeat the same actions multiple times without any progress. Then consider alternative approaches e.g. scrolling for more context or ask user for help.\n- Ask user for help if you have any difficulty. Keep user in the loop.\n- If you see information relevant to <user_request>, plan saving the information to memory.\n- Always reason about the <user_request>. Make sure to carefully analyze the specific steps and information required. E.g. specific filters, specific form fields, specific information to search. Make sure to always compare the current trajectory with the user request and think carefully if thats how the user requested it.\n</reasoning_rules>\n\n<examples>\nHere are examples of good output patterns. Use them as reference but never copy them directly.\n\n<evaluation_examples>\n\"evaluation_previous_goal\": \"Successfully navigated to the product page and found the target information. Verdict: Success\"\n\"evaluation_previous_goal\": \"Clicked the login button and user authentication form appeared. Verdict: Success\"\n</evaluation_examples>\n\n<memory_examples>\n\"memory\": \"Found many pending reports that need to be analyzed in the main page. Successfully processed the first 2 reports on quarterly sales data and moving on to inventory analysis and customer feedback reports.\"\n</memory_examples>\n\n<next_goal_examples>\n\"next_goal\": \"Click on the 'Add to Cart' button to proceed with the purchase flow.\"\n</next_goal_examples>\n</examples>\n\n<output>\n{\n \"evaluation_previous_goal\": \"Concise one-sentence analysis of your last action. Clearly state success, failure, or uncertain.\",\n \"memory\": \"1-3 concise sentences of specific memory of this step and overall progress. You should put here everything that will help you track progress in future steps. Like counting pages visited, items found, etc.\",\n \"next_goal\": \"State the next immediate goal and action to achieve it, in one clear sentence.\",\n \"action\":{\n \"Action name\": {// Action parameters}\n }\n}\n</output>\n";
|
|
446
446
|
//#endregion
|
|
447
447
|
//#region ../core/src/skills/files.ts
|
|
448
448
|
/** Soft cap so panel attaches stay in memory without blowing the tab. */
|
|
@@ -8567,24 +8567,35 @@ var GeminiLiveClient = class {
|
|
|
8567
8567
|
this.#inTurn = false;
|
|
8568
8568
|
this.#flush(true);
|
|
8569
8569
|
this.#turnStart = true;
|
|
8570
|
+
this.#resumeAudio();
|
|
8570
8571
|
this.#callbacks.onEvent({ type: "response_done" });
|
|
8571
8572
|
return;
|
|
8572
8573
|
case "speech_started":
|
|
8573
8574
|
this.#stopPlayback();
|
|
8574
8575
|
this.#inTurn = false;
|
|
8576
|
+
this.#resumeAudio();
|
|
8575
8577
|
this.#callbacks.onEvent({ type: "speech_started" });
|
|
8576
8578
|
return;
|
|
8577
8579
|
case "ready":
|
|
8578
8580
|
this.#onReady?.();
|
|
8581
|
+
this.#resumeAudio();
|
|
8579
8582
|
this.#callbacks.onEvent({ type: "ready" });
|
|
8580
8583
|
return;
|
|
8581
8584
|
case "tool_call":
|
|
8582
8585
|
this.#send.callNames.set(event.callId, event.name);
|
|
8586
|
+
this.#resumeAudio();
|
|
8583
8587
|
this.#callbacks.onEvent(event);
|
|
8584
8588
|
return;
|
|
8585
8589
|
default: this.#callbacks.onEvent(event);
|
|
8586
8590
|
}
|
|
8587
8591
|
}
|
|
8592
|
+
/** Mobile and Bluetooth speaker paths often suspend AudioContext; resume on every turn edge. */
|
|
8593
|
+
async #resumeAudio() {
|
|
8594
|
+
try {
|
|
8595
|
+
if (this.#ctx && this.#ctx.state !== "running") await this.#ctx.resume();
|
|
8596
|
+
if (this.#playCtx && this.#playCtx.state !== "running") await this.#playCtx.resume();
|
|
8597
|
+
} catch {}
|
|
8598
|
+
}
|
|
8588
8599
|
/** Sends a command in the session's shape, translated for Gemini. Cancel stops the local playback. */
|
|
8589
8600
|
send(message) {
|
|
8590
8601
|
if (this.#ws?.readyState !== WebSocket.OPEN) return;
|
|
@@ -8774,7 +8785,7 @@ var RealtimeClient = class {
|
|
|
8774
8785
|
};
|
|
8775
8786
|
//#endregion
|
|
8776
8787
|
//#region ../ui/src/voice/prompts/voice.md?raw
|
|
8777
|
-
var voice_default = "You are the voice of a web assistant that works on the website the user is looking at. You talk with the user; the page agent carries out page tasks.\n\n- Reply in the language set by the panel, in short sentences.\n- Answer greetings, small talk and anything you can answer without the page. Do not use a tool for them.\n- Before you call a tool, say nothing. After a tool result, say only its result in one short sentence.\n- To skim the page tree in pieces, call get_context with optional y_min/y_max (document Y in CSS pixels) or query. Omit both Y bounds to read the current viewport band.\n- To check or change the page yourself with a script, write ONE execute_javascript script that does the whole job. Prefer get_context for reading. `await agent.pageController.getState()` reads the page only when it was never read or the last read is older than 10 seconds.\n- For any task that changes the page or needs several steps, call run_task with the user's request exactly as the user said it. Do not rewrite it, do not add context, do not interpret it. The agent understands the request and asks the user when it needs more.\n- Never call agent.execute yourself.\n- When the agent asks a question (report kind question), speak that question. When the user answers, call answer_question with their answer exactly (or the chosen option label). Do not call run_task for that answer.\n- After run_task starts, do not use execute_javascript on the page until the agent reports a result. get_context and answer_question remain allowed.
|
|
8788
|
+
var voice_default = "You are the voice of a web assistant that works on the website the user is looking at. You talk with the user; the page agent carries out page tasks.\n\n- Reply in the language set by the panel, in short sentences.\n- Answer greetings, small talk and anything you can answer without the page. Do not use a tool for them.\n- Before you call a tool, say nothing. After a tool result, say only its result in one short sentence.\n- To skim the page tree in pieces, call get_context with optional y_min/y_max (document Y in CSS pixels) or query. Omit both Y bounds to read the current viewport band. Prefer a narrow band or a query over a huge slice. get_context also returns the active task and recent steps — use that before guessing.\n- To check or change the page yourself with a script, write ONE execute_javascript script that does the whole job. Prefer get_context for reading. `await agent.pageController.getState()` reads the page only when it was never read or the last read is older than 10 seconds.\n- For any task that changes the page or needs several steps, call run_task with the user's request exactly as the user said it. Do not rewrite it, do not add context, do not interpret it. The agent understands the request and asks the user when it needs more.\n- Never call agent.execute yourself.\n- When the agent asks a question (report kind question), speak that question. When the user answers, call answer_question with their answer exactly (or the chosen option label). Do not call run_task for that answer.\n- After run_task starts, do not use execute_javascript on the page until the agent reports a result. get_context and answer_question remain allowed. If the user speaks a correction or extra detail while a task is running and there is no pending question, call run_task with their words exactly — the panel delivers it as a note to the running agent.\n- If a tool says the agent is busy, say so once. Do not keep calling tools in a loop.\n- If the user asks to stop, tell them to press the stop button in the panel.\n- When the agent reports a result, say it in one sentence, without technical details, element indexes or markers such as [End of page].\n- Never say an action was done or a check passed unless a tool result or the agent reported it.\n";
|
|
8778
8789
|
//#endregion
|
|
8779
8790
|
//#region ../ui/src/voice/voice-prompt.ts
|
|
8780
8791
|
/**
|
|
@@ -8800,10 +8811,17 @@ function resolveVoicePrompt(custom, override = false) {
|
|
|
8800
8811
|
var BUSY_OUTPUT = "O agente está ocupado com outra tarefa. Avise o usuário e não repita o pedido agora.";
|
|
8801
8812
|
/** Result given to the model when the task was started. */
|
|
8802
8813
|
var STARTED_OUTPUT = "Tarefa iniciada no agente. Confirme ao usuário em uma frase.";
|
|
8814
|
+
/** Result when a mid-task spoken note was delivered to the running agent. */
|
|
8815
|
+
var NOTE_OUTPUT = "Mensagem do usuário entregue ao agente em execução. Confirme ao usuário em uma frase.";
|
|
8803
8816
|
/** Result when answer_question is used without a pending ask. */
|
|
8804
8817
|
var NO_PENDING_QUESTION_OUTPUT = "Não há pergunta pendente do agente. Se o usuário pediu uma tarefa, use run_task.";
|
|
8805
8818
|
/** Result when the answer was delivered to the agent. */
|
|
8806
8819
|
var ANSWERED_OUTPUT = "Resposta enviada ao agente. Confirme ao usuário em uma frase.";
|
|
8820
|
+
/** Empty tool args must still get a tool result, or Gemini Live waits forever. */
|
|
8821
|
+
var EMPTY_TASK_OUTPUT = "No task was given. Ask the user what to do, then call run_task.";
|
|
8822
|
+
var EMPTY_ANSWER_OUTPUT = "No answer was given. Ask the user again, then call answer_question with their reply.";
|
|
8823
|
+
/** Default cap so a stuck page tree read cannot freeze the voice session. */
|
|
8824
|
+
var DEFAULT_CONTEXT_TIMEOUT_MS = 8e3;
|
|
8807
8825
|
/** Errors about cancelling a response that is not running are harmless and must not end the call. */
|
|
8808
8826
|
function isHarmlessCancelError(message) {
|
|
8809
8827
|
return /cancel/i.test(message);
|
|
@@ -8946,20 +8964,34 @@ var VoiceSession = class {
|
|
|
8946
8964
|
#handleToolCall(name, callId, args) {
|
|
8947
8965
|
if (name === "answer_question") {
|
|
8948
8966
|
const answer = typeof args.answer === "string" ? args.answer.trim() : "";
|
|
8949
|
-
if (!answer)
|
|
8967
|
+
if (!answer) {
|
|
8968
|
+
this.#answer(callId, EMPTY_ANSWER_OUTPUT);
|
|
8969
|
+
return;
|
|
8970
|
+
}
|
|
8950
8971
|
const delivered = this.#options.onAnswer?.(answer) ?? false;
|
|
8951
8972
|
this.#answer(callId, delivered ? ANSWERED_OUTPUT : NO_PENDING_QUESTION_OUTPUT);
|
|
8952
8973
|
return;
|
|
8953
8974
|
}
|
|
8954
8975
|
if (name === "run_task") {
|
|
8955
8976
|
const task = typeof args.task === "string" ? args.task.trim() : "";
|
|
8956
|
-
if (!task)
|
|
8977
|
+
if (!task) {
|
|
8978
|
+
this.#answer(callId, EMPTY_TASK_OUTPUT);
|
|
8979
|
+
return;
|
|
8980
|
+
}
|
|
8957
8981
|
if (this.#options.isWaitingForAnswer?.()) {
|
|
8958
8982
|
const delivered = this.#options.onAnswer?.(task) ?? this.#options.onTask(task);
|
|
8959
8983
|
this.#answer(callId, delivered ? ANSWERED_OUTPUT : NO_PENDING_QUESTION_OUTPUT);
|
|
8960
8984
|
return;
|
|
8961
8985
|
}
|
|
8962
|
-
|
|
8986
|
+
if (this.#options.onTask(task)) {
|
|
8987
|
+
this.#answer(callId, STARTED_OUTPUT);
|
|
8988
|
+
return;
|
|
8989
|
+
}
|
|
8990
|
+
if (this.#options.onNote?.(task)) {
|
|
8991
|
+
this.#answer(callId, NOTE_OUTPUT);
|
|
8992
|
+
return;
|
|
8993
|
+
}
|
|
8994
|
+
this.#answer(callId, BUSY_OUTPUT);
|
|
8963
8995
|
return;
|
|
8964
8996
|
}
|
|
8965
8997
|
if (name === "get_context") {
|
|
@@ -8981,21 +9013,28 @@ var VoiceSession = class {
|
|
|
8981
9013
|
return;
|
|
8982
9014
|
}
|
|
8983
9015
|
this.#runScript(callId, script);
|
|
9016
|
+
return;
|
|
8984
9017
|
}
|
|
9018
|
+
this.#answer(callId, `Unknown tool ${name}.`);
|
|
8985
9019
|
}
|
|
8986
9020
|
async #runGetContext(callId, args) {
|
|
8987
9021
|
const client = this.#client;
|
|
8988
9022
|
const run = this.#options.onGetContext;
|
|
8989
|
-
if (!client || !run)
|
|
9023
|
+
if (!client || !run) {
|
|
9024
|
+
this.#answer(callId, "get_context is not available in this session.");
|
|
9025
|
+
return;
|
|
9026
|
+
}
|
|
8990
9027
|
const num = (value) => typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
9028
|
+
const timeoutMs = Math.max(50, this.#options.contextTimeoutMs ?? 8e3);
|
|
8991
9029
|
let output;
|
|
8992
9030
|
try {
|
|
8993
|
-
|
|
9031
|
+
const result = run({
|
|
8994
9032
|
yMin: num(args.y_min),
|
|
8995
9033
|
yMax: num(args.y_max),
|
|
8996
9034
|
maxLines: num(args.max_lines),
|
|
8997
9035
|
query: typeof args.query === "string" ? args.query : void 0
|
|
8998
9036
|
});
|
|
9037
|
+
output = await Promise.race([result, new Promise((resolve) => setTimeout(() => resolve("get_context timed out. Tell the user briefly and try a smaller y band or query."), timeoutMs))]);
|
|
8999
9038
|
} catch (error) {
|
|
9000
9039
|
output = `get_context failed: ${error instanceof Error ? error.message : "unknown error"}`;
|
|
9001
9040
|
}
|
|
@@ -9010,7 +9049,10 @@ var VoiceSession = class {
|
|
|
9010
9049
|
async #runScript(callId, script) {
|
|
9011
9050
|
const client = this.#client;
|
|
9012
9051
|
const run = this.#options.onScript;
|
|
9013
|
-
if (!client || !run)
|
|
9052
|
+
if (!client || !run) {
|
|
9053
|
+
this.#answer(callId, "Running scripts is not available in this session.");
|
|
9054
|
+
return;
|
|
9055
|
+
}
|
|
9014
9056
|
let output;
|
|
9015
9057
|
try {
|
|
9016
9058
|
output = await run(script);
|
|
@@ -10927,6 +10969,18 @@ var Panel = class {
|
|
|
10927
10969
|
this.#textarea.value = "";
|
|
10928
10970
|
this.#autoSize();
|
|
10929
10971
|
}
|
|
10972
|
+
/**
|
|
10973
|
+
* Mid-task user note for the running agent. Returns false when there is no running task
|
|
10974
|
+
* or the agent cannot take observations.
|
|
10975
|
+
*/
|
|
10976
|
+
#noteRunning(text) {
|
|
10977
|
+
const value = text.trim();
|
|
10978
|
+
if (!value || this.#agent.status !== "running") return false;
|
|
10979
|
+
if (typeof this.#agent.pushObservation !== "function") return false;
|
|
10980
|
+
this.#agent.pushObservation(`User said while the task was running: ${value}`);
|
|
10981
|
+
this.#render();
|
|
10982
|
+
return true;
|
|
10983
|
+
}
|
|
10930
10984
|
/** Sends a task or answers a pending question. The text field and voice both use this path. */
|
|
10931
10985
|
#send(value) {
|
|
10932
10986
|
if (this.#question) return this.#resolveQuestion(value);
|
|
@@ -10986,14 +11040,38 @@ var Panel = class {
|
|
|
10986
11040
|
this.#render();
|
|
10987
11041
|
return output;
|
|
10988
11042
|
}
|
|
11043
|
+
/** Active task / ask / recent steps so the voice can explain without losing prior context. */
|
|
11044
|
+
#voiceAgentBrief() {
|
|
11045
|
+
const lines = [];
|
|
11046
|
+
const status = this.#agent.status;
|
|
11047
|
+
const task = this.#agent.task?.trim();
|
|
11048
|
+
if (task) lines.push(`Active task (${status}): ${task}`);
|
|
11049
|
+
else lines.push(`Agent status: ${status}`);
|
|
11050
|
+
if (this.#question) lines.push(`Pending ask (${this.#question.kind}): ${this.#question.text}` + (this.#question.choices.length ? ` Options: ${this.#question.choices.join(" | ")}` : ""));
|
|
11051
|
+
const recent = this.#agent.history.slice(-6);
|
|
11052
|
+
for (const event of recent) {
|
|
11053
|
+
if (event.type === "observation" && event.content) {
|
|
11054
|
+
lines.push(`obs: ${event.content.slice(0, 180)}`);
|
|
11055
|
+
continue;
|
|
11056
|
+
}
|
|
11057
|
+
if (event.type === "step") {
|
|
11058
|
+
const goal = event.reflection?.next_goal?.trim();
|
|
11059
|
+
const action = event.action?.name;
|
|
11060
|
+
const bit = [goal && `goal=${goal}`, action && `action=${action}`].filter(Boolean).join(", ");
|
|
11061
|
+
if (bit) lines.push(`step: ${bit}`);
|
|
11062
|
+
}
|
|
11063
|
+
}
|
|
11064
|
+
return lines.join("\n");
|
|
11065
|
+
}
|
|
10989
11066
|
/** Read-only context slice for the voice; allowed while the agent is running. */
|
|
10990
11067
|
async #runVoiceGetContext(args) {
|
|
11068
|
+
const brief = this.#voiceAgentBrief();
|
|
10991
11069
|
const run = this.#config.getContext;
|
|
10992
|
-
if (!run) return
|
|
11070
|
+
if (!run) return `${brief}\n\nget_context is not available in this session.`;
|
|
10993
11071
|
try {
|
|
10994
|
-
return await run(args)
|
|
11072
|
+
return `${brief}\n\n${await run(args)}`;
|
|
10995
11073
|
} catch (error) {
|
|
10996
|
-
return
|
|
11074
|
+
return `${brief}\n\nget_context failed: ${error instanceof Error ? error.message : "unknown error"}`;
|
|
10997
11075
|
}
|
|
10998
11076
|
}
|
|
10999
11077
|
/**
|
|
@@ -11013,6 +11091,7 @@ var Panel = class {
|
|
|
11013
11091
|
onScript: (script) => this.#runVoiceScript(script),
|
|
11014
11092
|
isWaitingForAnswer: () => this.#question !== null,
|
|
11015
11093
|
onAnswer: (answer) => this.#resolveQuestion(answer),
|
|
11094
|
+
onNote: (text) => this.#noteRunning(text),
|
|
11016
11095
|
onGetContext: (args) => this.#runVoiceGetContext(args),
|
|
11017
11096
|
onChange: () => this.#render()
|
|
11018
11097
|
});
|