@jay-framework/webmcp-plugin 0.12.0 → 0.14.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.
@@ -311,7 +311,7 @@ function interactionKey(automation) {
311
311
  ).join("|");
312
312
  }
313
313
  const init = makeJayInit().withClient(() => {
314
- setTimeout(() => {
314
+ const setup = () => {
315
315
  const automation = window.__jay?.automation;
316
316
  if (automation) {
317
317
  const cleanup = setupWebMCP(automation);
@@ -319,7 +319,12 @@ const init = makeJayInit().withClient(() => {
319
319
  } else {
320
320
  console.warn("[WebMCP] window.__jay.automation not available — skipping");
321
321
  }
322
- }, 0);
322
+ };
323
+ if (window.__jay?.automation) {
324
+ setup();
325
+ } else {
326
+ window.addEventListener("jay:automation-ready", setup, { once: true });
327
+ }
323
328
  });
324
329
  export {
325
330
  init,
package/dist/index.d.ts CHANGED
@@ -4,17 +4,10 @@ import { AutomationAPI } from '@jay-framework/runtime-automation';
4
4
  /**
5
5
  * WebMCP plugin init — client-only.
6
6
  *
7
- * Uses setTimeout(0) to defer setup until after the current task completes:
8
- * 1. All plugin client inits (each `await`ed, creating microtasks)
9
- * 2. Page component is created and mounted
10
- * 3. wrapWithAutomation() is called
11
- * 4. window.__jay.automation is set
12
- *
13
- * Why setTimeout and not queueMicrotask:
14
- * Plugin inits are `await`ed in the generated script. `await undefined` yields
15
- * to the microtask queue, so a queueMicrotask callback runs BEFORE the rest of
16
- * the script (component creation, automation setup). setTimeout(0) schedules on
17
- * the macrotask queue, which runs after all synchronous code and microtasks.
7
+ * Listens for the 'jay:automation-ready' event dispatched by the generated
8
+ * client script after window.__jay.automation is set. This avoids the race
9
+ * condition where a setTimeout(0) could fire during another plugin's async
10
+ * init, before automation is available.
18
11
  */
19
12
  declare const init: _jay_framework_fullstack_component.JayInit<void>;
20
13
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jay-framework/webmcp-plugin",
3
- "version": "0.12.0",
3
+ "version": "0.14.0",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "description": "WebMCP plugin for jay-stack — automatically exposes page interactions as WebMCP tools, resources, and prompts",
@@ -28,12 +28,12 @@
28
28
  "test:watch": "vitest"
29
29
  },
30
30
  "dependencies": {
31
- "@jay-framework/fullstack-component": "^0.12.0",
32
- "@jay-framework/runtime-automation": "^0.12.0"
31
+ "@jay-framework/fullstack-component": "^0.14.0",
32
+ "@jay-framework/runtime-automation": "^0.14.0"
33
33
  },
34
34
  "devDependencies": {
35
- "@jay-framework/compiler-jay-stack": "^0.12.0",
36
- "@jay-framework/dev-environment": "^0.12.0",
35
+ "@jay-framework/compiler-jay-stack": "^0.14.0",
36
+ "@jay-framework/dev-environment": "^0.14.0",
37
37
  "@types/node": "^20.11.5",
38
38
  "rimraf": "^5.0.5",
39
39
  "tsup": "^8.0.1",