Repository navigation
Add ToolActivatedEvent and ToolCancelEvent - #7
Merged
Merged
Conversation
beaufortfrancois
marked this pull request as draft
October 1, 2026 09:21
Base automatically changed from
fbeaufort/remove-origin-keyed-requirement
to
main
October 2, 2026 06:29
Contributor
|
PR prepared before transition to the |
2 tasks done
Follow webmachinelearning/webmcp#245: define the ToolActivatedEvent and ToolCancelEvent interfaces, add the ontoolactivated and ontoolcancel handlers to ModelContext, and dispatch the events at the ModelContext of the document that owns the tool. Bump webmcp-types to 0.1.10 for the declarations. Follow webmachinelearning/webmcp#371 (draft f2f2ae2) for timing: toolactivated fires after the execute callback is invoked, so listeners observe its synchronous effects. If the callback detaches its document, DOM's inner invoke skips the listeners. toolcancel fires when a caller aborts a callback that has started and not settled. All pinned IDL checks, the ToolActivatedEvent tests, and executeTool-abort's caller-abort case now pass. Record the remaining expected failures: isTrusted is false for script-dispatched events, blank.html frames have no polyfill, and aborting before dispatch skips the callback. Validation: 253 browser tests and packed consumer checks pass. WPT in Chrome Canary 159.0.8153.0: 70 files, 190 subtests, zero unexpected results.
beaufortfrancois
force-pushed
the
fbeaufort/tool-lifecycle-events
branch
from
November 10, 2026 09:46
3562689 to
670c319
Compare
beaufortfrancois
marked this pull request as ready for review
November 10, 2026 10:18
Collaborator
Author
|
@MiguelsPizza Please review |
MiguelsPizza
approved these changes
Nov 11, 2026
| // The draft fires toolactivated after invoking the callback, so listeners observe its | ||
| // synchronous effects. If the callback detached this document, DOM's inner invoke skips | ||
| // every listener because the context's relevant global is no longer fully active. | ||
| // Listener exceptions are reported, not thrown. |
Collaborator
There was a problem hiding this comment.
Good comment thanks for explaining!
Collaborator
|
LGTM with license fix |
Collaborator
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements webmachinelearning/webmcp#245, with the event timing from webmachinelearning/webmcp#371.
Rebased onto
main(after #12). #9 is based on this branch and needs a rebase.Changes
ToolActivatedEventandToolCancelEvent(src/events.ts) and install them as globals alongsideModelContext.ontoolactivatedandontoolcanceltoModelContext, sharing the existing event handler code withontoolchange.toolactivatedat theModelContextof the document that owns the tool, right after theexecutecallback is invoked (webmcp#371). If the callback detaches that document, DOM's inner invoke skips the listeners, with no extra check.toolcancelwhen a caller aborts a callback that has started and not settled.webmcp-typesto^0.1.10, which declares the new interfaces.callback,toolactivated, rejection, signal abort,toolcancel);toolactivatedafter the callback detaches its document.Revisions
eada13b(the pin onmain). Lifecycle event timing followsf2f2ae2(webmcp#371). The other draft changes sinceeada13b(#345, #347, #254) are not reviewed here.fe52996(unchanged).[email protected].Results
Browser tests: 253 passed (Playwright Chromium, Firefox, WebKit, plus native Chromium).
pnpm test:packagepassed.WPT in Chrome Canary 159.0.8153.0: 70 files, 190 subtests, zero unexpected results.
Files: 44 OK, 25 expected timeouts, 1 expected error.
Firefox WPT could not be validated locally:
netReset);Firefox and Safari results come from CI.
Newly passing:
idlharnessexpectations deleted);tool-activated-event(expectations deleted);ToolCancelEventconstructor and synthetic-event cases;imperative/executeTool-abort: "caller abort propagates…" and "already-aborted … synchronously rejects".Expected failures
imperative/executeTool-events:isTrusted, which cannot be true for script-dispatched events./common/blank.htmlframes, which do not load the polyfill.executeTool():imperative/executeTool-abort, "promise remains rejected…" (TIMEOUT), andtool-cancel-event, "ontoolcancel is invoked…" (TIMEOUT). The polyfill rejects before dispatching to the callback (the existing "Timing" limitation), so the callback never starts and notoolcancelfires.Excluded
Declarative forms and CSS states remain unimplemented. Crashtests and non-testharness files are outside the suite.
This is not full conformance.