dhalsim 2.3.0 → 2.4.0

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/index.cjs CHANGED
@@ -16594,25 +16594,7 @@ ${states.join("\n\n")}
16594
16594
  };
16595
16595
 
16596
16596
  // src/subagents/prompts.ts
16597
- var GADGET_LIST_WITH_USER_ASSISTANCE = `## Available Gadgets
16598
- - ReportResult: **REQUIRED** - Call this to return your findings when task is complete
16599
- - Navigate: Go to a URL
16600
- - Click: Click an element (auto-waits for element to be actionable)
16601
- - Fill: Fill a form input
16602
- - FillForm: Fill multiple fields and submit
16603
- - Select: Select dropdown option
16604
- - Check: Toggle checkboxes
16605
- - GetFullPageContent: Read page text content
16606
- - Screenshot: Capture the page (use when you need to show visual results)
16607
- - DismissOverlays: Auto-dismiss cookie banners
16608
- - Scroll: Scroll the page
16609
- - WaitForElement: Wait for an element to appear
16610
- - Wait: General wait
16611
- - RequestUserAssistance: Ask user for help with CAPTCHAs, 2FA codes, or other human-only challenges`;
16612
- var GADGET_LIST_WITHOUT_USER_ASSISTANCE = `## Available Gadgets
16613
- - ReportResult: **REQUIRED** - Call this to return your findings when task is complete
16614
- - Navigate: Go to a URL
16615
- - Click: Click an element (auto-waits for element to be actionable)
16597
+ var GADGETS_CORE = `- Click: Click an element (auto-waits for element to be actionable)
16616
16598
  - Fill: Fill a form input
16617
16599
  - FillForm: Fill multiple fields and submit
16618
16600
  - Select: Select dropdown option
@@ -16623,8 +16605,44 @@ var GADGET_LIST_WITHOUT_USER_ASSISTANCE = `## Available Gadgets
16623
16605
  - Scroll: Scroll the page
16624
16606
  - WaitForElement: Wait for an element to appear
16625
16607
  - Wait: General wait`;
16608
+ function buildGadgetList(options) {
16609
+ const lines = ["## Available Gadgets", "- ReportResult: **REQUIRED** - Call this to return your findings when task is complete"];
16610
+ if (options.includeNavigation) {
16611
+ lines.push("- Navigate: Go to a URL");
16612
+ }
16613
+ lines.push(GADGETS_CORE);
16614
+ if (options.includeUserAssistance) {
16615
+ lines.push("- RequestUserAssistance: Ask user for help with CAPTCHAs, 2FA codes, or other human-only challenges");
16616
+ }
16617
+ return lines.join("\n");
16618
+ }
16626
16619
  function createDhalsimSystemPrompt(options) {
16627
- const gadgetList = options.includeUserAssistance ? GADGET_LIST_WITH_USER_ASSISTANCE : GADGET_LIST_WITHOUT_USER_ASSISTANCE;
16620
+ const includeNavigation = !options.disableNavigation;
16621
+ const gadgetList = buildGadgetList({
16622
+ includeNavigation,
16623
+ includeUserAssistance: options.includeUserAssistance
16624
+ });
16625
+ const criticalRules = includeNavigation ? `## CRITICAL Rules
16626
+ 1. You have ONE page (p1) already open. Use Navigate to go to URLs.
16627
+ 2. ONLY use selectors exactly as shown in <CurrentBrowserState>
16628
+ 3. NEVER guess selectors - use GetFullPageContent if you need more info
16629
+ 4. Focus on completing the task efficiently - avoid unnecessary actions
16630
+ 5. If a selector matches multiple elements, you'll get an error with a "suggestions" array containing valid selectors. USE ONE OF THESE SUGGESTIONS DIRECTLY - don't guess or modify them.
16631
+ 6. For batch extraction: GetFullPageContent returns ALL matches when a selector matches multiple elements (as "texts" array). Use this instead of querying each element separately.` : `## CRITICAL Rules
16632
+ 1. You have ONE page (p1) open at the target URL. You cannot navigate to other URLs.
16633
+ 2. ONLY use selectors exactly as shown in <CurrentBrowserState>
16634
+ 3. NEVER guess selectors - use GetFullPageContent if you need more info
16635
+ 4. Focus on completing the task efficiently - avoid unnecessary actions
16636
+ 5. If a selector matches multiple elements, you'll get an error with a "suggestions" array containing valid selectors. USE ONE OF THESE SUGGESTIONS DIRECTLY - don't guess or modify them.
16637
+ 6. For batch extraction: GetFullPageContent returns ALL matches when a selector matches multiple elements (as "texts" array). Use this instead of querying each element separately.`;
16638
+ const efficientPattern = includeNavigation ? `## Efficient Pattern
16639
+ On first call: Navigate and DismissOverlays are ALREADY done. Take action immediately.
16640
+ After any Navigate call: DismissOverlays, then interact with elements.
16641
+
16642
+ If an action doesn't produce expected results, use GetFullPageContent to diagnose before retrying.` : `## Efficient Pattern
16643
+ On first call: DismissOverlays is ALREADY done. Take action immediately.
16644
+
16645
+ If an action doesn't produce expected results, use GetFullPageContent to diagnose before retrying.`;
16628
16646
  return `You are a browser automation agent focused on completing a specific web task.
16629
16647
 
16630
16648
  ## Browser State (<CurrentBrowserState>)
@@ -16638,19 +16656,9 @@ This is your source of truth for what's on screen. It contains:
16638
16656
  - CHECKBOXES: Checkbox/radio inputs
16639
16657
  - MENUITEMS: Dropdown options (only visible when dropdown is open)
16640
16658
 
16641
- ## CRITICAL Rules
16642
- 1. You have ONE page (p1) already open. Use Navigate to go to URLs.
16643
- 2. ONLY use selectors exactly as shown in <CurrentBrowserState>
16644
- 3. NEVER guess selectors - use GetFullPageContent if you need more info
16645
- 4. Focus on completing the task efficiently - avoid unnecessary actions
16646
- 5. If a selector matches multiple elements, you'll get an error with a "suggestions" array containing valid selectors. USE ONE OF THESE SUGGESTIONS DIRECTLY - don't guess or modify them.
16647
- 6. For batch extraction: GetFullPageContent returns ALL matches when a selector matches multiple elements (as "texts" array). Use this instead of querying each element separately.
16659
+ ${criticalRules}
16648
16660
 
16649
- ## Efficient Pattern
16650
- On first call: Navigate and DismissOverlays are ALREADY done. Take action immediately.
16651
- After any Navigate call: DismissOverlays, then interact with elements.
16652
-
16653
- If an action doesn't produce expected results, use GetFullPageContent to diagnose before retrying.
16661
+ ${efficientPattern}
16654
16662
 
16655
16663
  ## Dropdown/Toggle Behavior
16656
16664
  Dropdowns are TOGGLES - clicking the same trigger twice will close it!
@@ -16701,10 +16709,8 @@ var ReportResult = class extends (0, import_llmist15.Gadget)({
16701
16709
  )
16702
16710
  })
16703
16711
  }) {
16704
- result = null;
16705
16712
  execute(params) {
16706
- this.result = params.result;
16707
- return "Result reported successfully.";
16713
+ throw new import_llmist15.TaskCompletionSignal(params.result);
16708
16714
  }
16709
16715
  };
16710
16716
  var Dhalsim = class extends (0, import_llmist15.Gadget)({
@@ -16721,7 +16727,8 @@ Use this for web research, data extraction, form filling, or any web-based task.
16721
16727
  headless: import_llmist15.z.boolean().optional().describe("Run browser in headless mode (default: true, configurable via CLI)"),
16722
16728
  timeoutMs: import_llmist15.z.number().optional().describe("Overall timeout in ms (default: 300000 = 5 min, 0 = disabled, configurable via CLI)"),
16723
16729
  disableCache: import_llmist15.z.boolean().optional().describe("Disable browser cache for lower memory usage (default: false, configurable via CLI)"),
16724
- navigationTimeoutMs: import_llmist15.z.number().optional().describe("Navigation timeout in ms (default: 60000, configurable via CLI)")
16730
+ navigationTimeoutMs: import_llmist15.z.number().optional().describe("Navigation timeout in ms (default: 60000, configurable via CLI)"),
16731
+ disableNavigation: import_llmist15.z.boolean().optional().describe("Disable Navigate gadget to restrict agent to the initial URL (default: false, configurable via CLI)")
16725
16732
  }),
16726
16733
  timeoutMs: 3e5
16727
16734
  // 5 minutes - web browsing can take time
@@ -16729,12 +16736,14 @@ Use this for web research, data extraction, form filling, or any web-based task.
16729
16736
  customSessionManager;
16730
16737
  customSystemPrompt;
16731
16738
  userAssistanceEnabled;
16739
+ navigationDisabled;
16732
16740
  customUserAssistanceCallback;
16733
16741
  constructor(options) {
16734
16742
  super();
16735
16743
  this.customSessionManager = options?.sessionManager;
16736
16744
  this.customSystemPrompt = options?.systemPrompt;
16737
16745
  this.userAssistanceEnabled = options?.userAssistance;
16746
+ this.navigationDisabled = options?.disableNavigation;
16738
16747
  this.customUserAssistanceCallback = options?.onUserAssistance;
16739
16748
  if (options?.timeoutMs !== void 0) {
16740
16749
  this.timeoutMs = options.timeoutMs === 0 ? void 0 : options.timeoutMs;
@@ -16765,8 +16774,13 @@ Use this for web research, data extraction, form filling, or any web-based task.
16765
16774
  subagentKey: "navigationTimeoutMs",
16766
16775
  defaultValue: 6e4
16767
16776
  });
16777
+ const disableNavigation = (0, import_llmist15.resolveValue)(ctx, "BrowseWeb", {
16778
+ runtime: params.disableNavigation,
16779
+ subagentKey: "disableNavigation",
16780
+ defaultValue: this.navigationDisabled ?? false
16781
+ });
16768
16782
  const userAssistanceEnabled = this.userAssistanceEnabled ?? (this.customUserAssistanceCallback !== void 0 || ctx?.requestHumanInput !== void 0);
16769
- logger13?.debug(`[BrowseWeb] User assistance enabled=${userAssistanceEnabled}`);
16783
+ logger13?.debug(`[BrowseWeb] User assistance enabled=${userAssistanceEnabled}, disableNavigation=${disableNavigation}`);
16770
16784
  const collectedMedia = [];
16771
16785
  const manager = this.customSessionManager ?? new BrowserSessionManager(logger13);
16772
16786
  const isOwnedManager = !this.customSessionManager;
@@ -16812,7 +16826,8 @@ Use this for web research, data extraction, form filling, or any web-based task.
16812
16826
  const gadgets = [
16813
16827
  reportResult,
16814
16828
  // First so it's prominent in the list
16815
- new Navigate(manager),
16829
+ // Conditionally include Navigate (excluded when disableNavigation is true)
16830
+ ...disableNavigation ? [] : [new Navigate(manager)],
16816
16831
  new Click(manager),
16817
16832
  new Fill(manager),
16818
16833
  new FillForm(manager),
@@ -16829,7 +16844,7 @@ Use this for web research, data extraction, form filling, or any web-based task.
16829
16844
  ];
16830
16845
  const { AgentBuilder, LLMist } = (0, import_llmist15.getHostExports)(ctx);
16831
16846
  const client = new LLMist();
16832
- const systemPrompt = this.customSystemPrompt ?? createDhalsimSystemPrompt({ includeUserAssistance: userAssistanceEnabled });
16847
+ const systemPrompt = this.customSystemPrompt ?? createDhalsimSystemPrompt({ includeUserAssistance: userAssistanceEnabled, disableNavigation });
16833
16848
  const builder = new AgentBuilder(client).withModel(model).withSystem(systemPrompt).withMaxIterations(maxIterations).withGadgets(...gadgets).withTrailingMessage((trailingCtx) => [
16834
16849
  pageStateScanner.getCachedState(),
16835
16850
  "",
@@ -16885,6 +16900,7 @@ Use this for web research, data extraction, form filling, or any web-based task.
16885
16900
  Task: ${task}`);
16886
16901
  logger13?.debug(`[BrowseWeb] Starting agent loop model=${model} maxIterations=${maxIterations}`);
16887
16902
  let finalResult = "";
16903
+ let reportedResult;
16888
16904
  for await (const event of agent.run()) {
16889
16905
  if (ctx?.signal?.aborted) {
16890
16906
  break;
@@ -16895,15 +16911,15 @@ Task: ${task}`);
16895
16911
  collectedMedia.push(media);
16896
16912
  }
16897
16913
  }
16898
- if (reportResult.result !== null) {
16899
- break;
16914
+ if (event.result.gadgetName === "ReportResult" && event.result.breaksLoop) {
16915
+ reportedResult = event.result.result;
16900
16916
  }
16901
16917
  } else if (event.type === "text") {
16902
16918
  finalResult = event.content;
16903
16919
  }
16904
16920
  }
16905
16921
  return {
16906
- result: reportResult.result || finalResult || "Task completed but no result text was generated.",
16922
+ result: reportedResult || finalResult || "Task completed but no result text was generated.",
16907
16923
  media: collectedMedia.length > 0 ? collectedMedia : void 0
16908
16924
  };
16909
16925
  } finally {