Commit Graph

5184 Commits

Author SHA1 Message Date
Adrià Arrufat
9ac2c03a7e tools: unify eval and extract tool dispatching
- Add `callEvalLike` to consolidate tools returning `EvalResult`.
- Update `Agent` and `MCP` to use the new helper.
- Route failed data commands to stderr in `CommandExecutor`.
- Update CSS selector guidance in `script.zig`.
2026-05-14 11:14:11 +02:00
Adrià Arrufat
faba86cf82 docs(browser.tools): clarify extract tool schema and examples 2026-05-14 10:48:13 +02:00
Adrià Arrufat
688924e7a1 agent: add eval_js support to CommandExecutor
Implements execution for the .eval_js command and adds a helper to
correctly map JavaScript execution errors to the failed state.
2026-05-14 10:37:51 +02:00
Adrià Arrufat
3d8621561a tools: add extract tool for structured data
Adds the `extract` tool for lifting structured data via JSON schemas.
Updates the command system to support recording and replaying
extraction steps in PandaScript.
2026-05-14 10:32:59 +02:00
Adrià Arrufat
819d2f9884 verifier: change VerifyResult to a tagged union
Replaces the struct-based result with a tagged union to represent
verification outcomes more idiomatically. Updates callers in Agent
and MCP tools to handle the new union type.
2026-05-14 09:39:12 +02:00
Adrià Arrufat
d6d4feeaa5 Merge branch 'main' into agent 2026-05-14 09:24:12 +02:00
Adrià Arrufat
eb863e0b16 script: unify tool call conversion to use json values 2026-05-14 09:23:54 +02:00
Adrià Arrufat
001fbb97d0 Recorder: make init fallible and Agent.recorder optional 2026-05-14 08:59:47 +02:00
Adrià Arrufat
f35a80682b refactor: simplify CommandExecutor and switch MCP to extractSchema
- Remove `extractText` from browser tools and `ToolExecutor`
- Update MCP `extract` step to use `extractSchema` instead of a selector
- Remove `allocator` and `execute` method from `CommandExecutor`
2026-05-14 08:41:09 +02:00
Adrià Arrufat
ad862862c2 test: consolidate Command parsing and round-trip tests 2026-05-14 07:48:45 +02:00
Karl Seguin
143bffdfec Merge pull request #2450 from navidemad/fix-bug7-form-idl
forms: add enctype + 5 submitter form-* IDL accessors
2026-05-14 13:44:57 +08:00
Adrià Arrufat
1400a0a62b Merge branch 'main' into agent 2026-05-14 07:41:04 +02:00
Karl Seguin
80a09fc0fd zig fmt 2026-05-14 13:19:17 +08:00
Karl Seguin
14b4449628 use format to write String value 2026-05-14 11:03:12 +08:00
Karl Seguin
373916873f Merge pull request #2442 from lightpanda-io/worker_message_buffer
CI fixes, callback timing correctness
2026-05-14 08:56:36 +08:00
Karl Seguin
96ac9a49ea Update src/browser/webapi/Worker.zig
Co-authored-by: Navid EMAD <navid.emad@yespark.fr>
2026-05-14 08:33:32 +08:00
Karl Seguin
bcafa175cb make Event worker-safe 2026-05-14 07:11:33 +08:00
Navid EMAD
f0cce42757 forms: route Frame.submitForm through Form.normalizeMethod/normalizeEnctype
The submitForm encoding path was the last duplicate of the "limited to
only known values" canonicalization the previous commit consolidated for
the IDL getters. Now it consumes the same Form.normalizeMethod /
Form.normalizeEnctype helpers, so a single function owns the canonical
mapping (`""` / unknown -> spec default, recognized values pass through
unchanged).

Side effect of routing through the helper: the
`log.warn(.not_implemented, "FormData.encoding", ...)` branch falls out.
After commit 4b693db4 added `text/plain`, the only attribute values that
still reach the urlencoded fallback are spec-invalid ones, which per
HTML §4.10.21.5 silently canonicalize to
`application/x-www-form-urlencoded`. The warning was firing for valid
spec behavior — Chrome doesn't log either.

Behavior-preserving on all observable surfaces: full suite 639/639 green;
existing form-submission integration tests (multipart, urlencoded,
text/plain, GET-ignores-enctype) all pass unchanged.
2026-05-13 18:14:10 +02:00
Navid EMAD
4b693db480 forms: support enctype=text/plain in form submission
Closing the divergence introduced by the new IDL accessors: `submitter.formEnctype`
(and `form.enctype`) now return "text/plain" for that attribute value per WHATWG
HTML §4.10.21.5, but `Frame.submitForm` previously fell back to urlencoded with
a `.not_implemented` log when it saw the same value on the submission path.

Implement the spec's text/plain encoding algorithm (HTML §4.10.21.8):

  - FormData.EncType gains a `.plaintext` variant.
  - FormData.plaintextEncode writes "name=value CRLF" per entry, no URL-encoding,
    no escaping — the spec accepts that text/plain is a lossy, human-readable
    encoding (values containing "=" or CRLF produce an ambiguous wire format
    by design).
  - Frame.submitForm recognizes "text/plain" before the urlencoded fallback and
    sets the Content-Type header to "text/plain; charset=<form-charset>", per
    spec step 21.4.

Two new Zig unit tests cover encoding output (`FormData: plaintext write`,
`FormData: plaintext empty body`). Full suite 639/639 green.

This is bundled with the IDL accessor commits because returning "text/plain"
from the IDL while the submission silently re-encodes as urlencoded is a
spec-internal inconsistency the IDL change itself introduces. Reviewers who'd
prefer to land just the read-only accessors first should feel free to ask for
a split — this commit is self-contained and reverts cleanly.
2026-05-13 18:08:54 +02:00
Navid EMAD
cedfdba0d7 forms: extract normalizeMethod / normalizeEnctype helpers
The "limited to only known values" canonicalization (per WHATWG HTML
§2.2.2) was duplicated five times: Form.getMethod + Form.getEnctype +
{Button,Input}.{getFormMethod,getFormEnctype}. Each callsite differed
only in the missing-value default ("" for submitter overrides, "get" /
"application/x-www-form-urlencoded" for the form-side).

Extract into two pub helpers on Form.zig taking the attribute slice +
the missing-value default. The five callers collapse to one-liners.

Behavior-preserving: existing form.html / button.html / input-attrs.html
fixtures all pass unchanged; full suite 637/637 green.

Net: -36 LOC.
2026-05-13 17:58:55 +02:00
Navid EMAD
2fdc82aa05 forms: add enctype + 5 submitter form-* IDL accessors
Six form-submission IDL accessors were missing from the JsApi blocks of
HTMLFormElement, HTMLButtonElement, and HTMLInputElement, so reads
produced undefined instead of the spec-mandated string/boolean. The
content-attribute path (clicking a submit button honoring formaction /
formmethod / formenctype) was wired up in #2279; this commit adds the
matching IDL-property accessors per WHATWG HTML §4.10.18.6 and §4.10.21.5.

- Form.enctype: limited to known values, missing+invalid both default to
  application/x-www-form-urlencoded (mirrors getMethod's shape).
- Button/Input formAction: returns frame.url when missing/empty, else the
  resolved URL (mirrors Form.getAction).
- Button/Input formEnctype, formMethod: limited to known values with no
  missing-value default ("" when missing, canonical invalid-value default
  application/x-www-form-urlencoded / get when invalid).
- Button/Input formTarget: plain reflection, defaults to "".
- Button/Input formNoValidate: boolean reflection of formnovalidate.

Closes #2449
2026-05-13 17:49:19 +02:00
Adrià Arrufat
70edee7063 lightpanda: close session before notification deinit 2026-05-13 17:49:00 +02:00
Adrià Arrufat
a0b6b656c3 Merge branch 'main' into agent 2026-05-13 17:43:33 +02:00
Karl Seguin
5595f7d298 Merge pull request #2448 from lightpanda-io/script_load_error_handling
Don't process scripts that failed to load
2026-05-13 23:19:40 +08:00
Pierre Tachoire
198c4e5a0f Merge pull request #2444 from lightpanda-io/useless-code
cdp: remove dead code
2026-05-13 15:36:16 +02:00
Pierre Tachoire
ffc2baa733 Merge pull request #2431 from lightpanda-io/cdp-double-frame-navigated-event
fix(cdp): remove duplicate Page.frameNavigated and fix context regist…
2026-05-13 15:17:27 +02:00
Adrià Arrufat
5316dffeb7 Merge branch 'main' into agent 2026-05-13 14:58:47 +02:00
Karl Seguin
7750bc94f6 Apply suggestions from code review
Remove no-longer needed setTimeouts in test now that messages are queued. 

Runner also checks ready_queue when determining doneness.

Co-authored-by: Navid EMAD <design.navid@gmail.com>
2026-05-13 20:57:59 +08:00
Karl Seguin
2326071036 Don't [try] to process scripts that failed to load
At some point recently, we started to process scripts that fail to load (e.g.
404). This stops such scripts from [trying] to be evaluated, and executes the
onerror handler in all script loading paths.
2026-05-13 20:48:08 +08:00
Adrià Arrufat
71824087e9 refactor: improve tool error logging and outcome handling
Adds debug logging for browser tool action and parsing errors.
Introduces a helper to deduplicate evaluation result handling in MCP.
2026-05-13 14:41:45 +02:00
Pierre Tachoire
12971a2420 Merge pull request #2445 from lightpanda-io/reset-bc-arena
cdp: reset browser context arena when bc is removed
2026-05-13 14:35:38 +02:00
Adrià Arrufat
38c74ab3b3 browser: extract formatJsError helper in tools.zig 2026-05-13 14:35:31 +02:00
Adrià Arrufat
48b8c4fb8c script: simplify formatHealReplacement 2026-05-13 14:34:12 +02:00
Adrià Arrufat
c009b291cb agent: correctly report JS errors in eval tool
Routes the eval tool through callEval instead of callValue. This
ensures JavaScript execution errors are flagged with is_error=true,
allowing the model to self-correct.
2026-05-13 14:33:11 +02:00
Adrià Arrufat
6538a34f56 browser: separate operational and JS errors in eval
Changes `EvalResult` to a union and uses Zig errors for operational
failures, distinguishing them from JavaScript execution errors.
Also removes redundant `stringifyJson` in favor of standard library.
2026-05-13 14:27:28 +02:00
Pierre Tachoire
5d73d82bf6 cdp: call context created w/ correct is_default_context value
Co-authored-by: Navid EMAD <navid.emad@yespark.fr>
2026-05-13 14:11:53 +02:00
Adrià Arrufat
635546bf85 Recorder: simplify initialization and file opening 2026-05-13 14:03:18 +02:00
Adrià Arrufat
fb06e282c2 agent: simplify promptNumberedChoice API\ 2026-05-13 13:29:26 +02:00
Adrià Arrufat
b2454a9190 chore: add license headers to source files 2026-05-13 13:20:36 +02:00
Adrià Arrufat
b4b533d2be agent: derive Action enum from tool_defs and clean up Verifier
- Derives the `Action` enum in `src/browser/tools.zig` from `tool_defs` to prevent manual maintenance and potential drift.
- Refactors `verifyElementValue` in `src/script/Verifier.zig` to use a `Check` struct for its parameters.
- Reorganizes and cleans up imports in `src/agent/Agent.zig`.
2026-05-13 13:18:30 +02:00
Adrià Arrufat
f35c4219c9 refactor: improve error handling and rename Self to Agent
- Replace `unreachable` with explicit error returns in Agent and Executor.
- Add `EvalResult.err` helper in `tools.zig` to simplify error paths.
- Improve error propagation in `SlashCommand` and `Recorder`.
- Rename `Self` to `Agent` for better clarity in function signatures.
2026-05-13 13:15:44 +02:00
Adrià Arrufat
6478853e93 agent: simplify zig syntax and arena usage 2026-05-13 13:01:30 +02:00
Adrià Arrufat
c374f8b04e browser: unify element identification with ActionTarget
Introduces an `ActionTarget` union to handle selectors and backend node
IDs consistently. This simplifies the `formatActionResult` function and
ensures the identification method is preserved within `NodeAndPage`
during element resolution.
2026-05-13 12:54:18 +02:00
Adrià Arrufat
cc59dd64b9 script: make ScriptIterator.next fallible 2026-05-13 12:40:07 +02:00
Pierre Tachoire
8432cfbfba cdp: return error in case of missing event's frame
Instead of using the root_frame
2026-05-13 12:29:11 +02:00
Adrià Arrufat
18890ea695 spinner: reset state on thread spawn failure 2026-05-13 12:25:32 +02:00
Adrià Arrufat
9f5814a431 agent: add errdefers for cleanup in ToolExecutor.init 2026-05-13 12:23:39 +02:00
Adrià Arrufat
457c565df3 agent: move ai_client check earlier in runHealTurn
Ensures the function fails fast if no AI client is available before
performing other operations.
2026-05-13 12:22:10 +02:00
Adrià Arrufat
96fce3c56f refactor: unify tool UI and browser action finalization
- Add `beginTool` and `endTool` to `Terminal` to encapsulate spinner logic.
- Consolidate navigation awaiting and context tagging in browser tools
  via a new `finalizeAction` helper.
2026-05-13 12:10:07 +02:00
Karl Seguin
e895ce81e3 Merge pull request #2437 from lightpanda-io/window_frameElement
Add window.frameElement
2026-05-13 18:00:08 +08:00