@hyperframes/studio 0.9.52 → 0.9.53
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/assets/{hyperframes-player-D7LhzIg1.js → hyperframes-player-z7r-N5fm.js} +2 -2
- package/dist/assets/{index-CQ7o0CBU.js → index-2QPHxCxy.js} +1 -1
- package/dist/assets/{index-D3WxJaqm.js → index-Dpo7Q_9-.js} +160 -160
- package/dist/assets/index-Dv67Vrl6.js +74 -0
- package/dist/assets/{pausedVideoDecoder-BVUmBgn0.js → pausedVideoDecoder-BarDYEAf.js} +1 -1
- package/dist/chunk-USW3YBOG.js +70 -0
- package/dist/index.d.ts +6 -5
- package/dist/index.html +1 -1
- package/dist/index.js +45 -77
- package/dist/keys.d.ts +72 -1
- package/dist/keys.js +5 -4
- package/package.json +9 -9
- package/src/captions/keyboard.ts +1 -1
- package/src/components/RightPanelTabs.test.tsx +1 -1
- package/src/components/StudioHeader.dom.test.tsx +1 -1
- package/src/components/TimelineHistoryButtons.dom.test.tsx +1 -1
- package/src/components/TimelineToolbar.tsx +1 -1
- package/src/components/editor/SnapToolbar.tsx +1 -1
- package/src/components/editor/useDomEditNudge.ts +1 -1
- package/src/components/panels/SlideshowPanel.tsx +1 -1
- package/src/components/renders/RenderQueue.test.tsx +1 -1
- package/src/components/ui/Button.test.tsx +1 -1
- package/src/components/ui/Menu.test.tsx +1 -1
- package/src/components/ui/valueControls.test.tsx +1 -1
- package/src/hooks/appHotkeysDispatch.ts +1 -1
- package/src/hooks/linkShortcuts.ts +1 -1
- package/src/hooks/useAutomationSelectionKeyboard.ts +1 -1
- package/src/hooks/useKeyframeKeyboard.ts +1 -1
- package/src/index.ts +2 -2
- package/src/keys.test.ts +5 -7
- package/src/keys.ts +1 -6
- package/src/player/components/ShortcutsPanel.tsx +1 -1
- package/src/player/components/studioCombo.test.ts +1 -1
- package/src/player/components/studioShortcuts.ts +1 -1
- package/src/player/lib/playbackShortcuts.ts +3 -28
- package/src/utils/studioHelpers.ts +1 -1
- package/src/utils/studioPendingEdits.ts +1 -1
- package/src/utils/timelineDiscovery.ts +1 -1
- package/src/utils/typingTarget.test.ts +1 -1
- package/src/webmcp/polyfill.transport.test.ts +13 -3
- package/src/webmcp/types.ts +3 -3
- package/src/webmcp/useStudioAgentTools.polyfill.test.tsx +89 -121
- package/src/webmcp/useStudioAgentTools.test.tsx +2 -2
- package/src/webmcp/useStudioAgentTools.ts +2 -3
- package/dist/assets/index-BX3KHhGX.js +0 -71
- package/dist/chunk-5ZHKYODQ.js +0 -149
- package/dist/keys-B163OjLN.d.ts +0 -87
- package/src/player/components/studioCombo.ts +0 -108
- package/src/utils/typingTarget.ts +0 -56
|
@@ -39,7 +39,7 @@ import { useAudioMetersVisible } from "../utils/audioMeterVisibility";
|
|
|
39
39
|
import { LinkedSelectionToggle } from "./LinkedSelectionToggle";
|
|
40
40
|
import { useProjectHasAudio } from "../utils/audioMeterMath";
|
|
41
41
|
import { canAddBeatAt, addBeatAtCompositionTime } from "../utils/beatEditActions";
|
|
42
|
-
import { isTypingTarget } from "
|
|
42
|
+
import { isTypingTarget } from "@hyperframes/core/typing-target";
|
|
43
43
|
import { keyHint, matchesKey, useStudioKeys } from "../player/components/studioShortcuts";
|
|
44
44
|
import type { TimelineProps } from "../player/components/TimelineTypes";
|
|
45
45
|
|
|
@@ -3,7 +3,7 @@ import { memo, useCallback, useEffect, useRef, useState } from "react";
|
|
|
3
3
|
import { MagnetStraight, GridFour, Path, Ruler, FrameCorners } from "@phosphor-icons/react";
|
|
4
4
|
import { usePlayerStore } from "../../player/store/playerStore";
|
|
5
5
|
import { usePreviewOverlayContext } from "./PreviewOverlayProvider";
|
|
6
|
-
import { ownsPlainKeys } from "
|
|
6
|
+
import { ownsPlainKeys } from "@hyperframes/core/typing-target";
|
|
7
7
|
import { keyHint, matchesKey, useStudioKeys } from "../../player/components/studioShortcuts";
|
|
8
8
|
|
|
9
9
|
// fallow-ignore-next-line complexity
|
|
@@ -8,7 +8,7 @@ import { trackPreviewEditResult } from "../../utils/previewFeatureUsage";
|
|
|
8
8
|
*/
|
|
9
9
|
import { useCallback, useEffect, useRef, type RefObject } from "react";
|
|
10
10
|
import { useMountEffect } from "../../hooks/useMountEffect";
|
|
11
|
-
import { ownsPlainKeys } from "
|
|
11
|
+
import { ownsPlainKeys } from "@hyperframes/core/typing-target";
|
|
12
12
|
import { acquireCanvasNudgeKeys } from "../../utils/canvasNudgeGate";
|
|
13
13
|
import {
|
|
14
14
|
addStudioPendingEditFlushListener,
|
|
@@ -21,7 +21,7 @@ import { usePlayerStore } from "../../player";
|
|
|
21
21
|
import { useDomEditSelectionContext } from "../../contexts/DomEditContext";
|
|
22
22
|
import { useFileManagerContext } from "../../contexts/FileManagerContext";
|
|
23
23
|
import { generateId } from "../../utils/generateId";
|
|
24
|
-
import { isTypingTarget } from "
|
|
24
|
+
import { isTypingTarget } from "@hyperframes/core/typing-target";
|
|
25
25
|
import {
|
|
26
26
|
SectionHeader,
|
|
27
27
|
SlideList,
|
|
@@ -6,7 +6,7 @@ import { afterEach, beforeEach, describe, expect, it, vi, type Mock } from "vite
|
|
|
6
6
|
import { RenderQueue, type StartRenderHandler } from "./RenderQueue";
|
|
7
7
|
import { getPersistedRenderSettings } from "./renderSettings";
|
|
8
8
|
import { buttonBase, buttonSizes, buttonVariants, cn } from "../ui";
|
|
9
|
-
import { isTypingTarget } from "
|
|
9
|
+
import { isTypingTarget } from "@hyperframes/core/typing-target";
|
|
10
10
|
import { shouldIgnorePlaybackShortcutTarget } from "../../player/lib/playbackShortcuts";
|
|
11
11
|
import type { FfmpegStatus } from "./useFfmpegStatus";
|
|
12
12
|
|
|
@@ -14,7 +14,7 @@ import { Button, type ButtonSize, type ButtonVariant } from "./Button";
|
|
|
14
14
|
import { IconButton } from "./IconButton";
|
|
15
15
|
import { Tab, Tabs, TabsList } from "./Tabs";
|
|
16
16
|
import { cleanupMounted, mountHost } from "./mountHost.testHelpers";
|
|
17
|
-
import { isTypingTarget } from "
|
|
17
|
+
import { isTypingTarget } from "@hyperframes/core/typing-target";
|
|
18
18
|
import { shouldIgnorePlaybackShortcutTarget } from "../../player/lib/playbackShortcuts";
|
|
19
19
|
|
|
20
20
|
const VARIANTS: ButtonVariant[] = ["primary", "secondary", "danger", "ghost"];
|
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
MenuSeparator,
|
|
17
17
|
} from "./Menu";
|
|
18
18
|
import { Popover } from "./Popover";
|
|
19
|
-
import { isTypingTarget } from "
|
|
19
|
+
import { isTypingTarget } from "@hyperframes/core/typing-target";
|
|
20
20
|
import { shouldIgnorePlaybackShortcutTarget } from "../../player/lib/playbackShortcuts";
|
|
21
21
|
import { cleanupMounted, mountHost as render } from "./mountHost.testHelpers";
|
|
22
22
|
|
|
@@ -17,7 +17,7 @@ import { NumberField } from "./NumberField";
|
|
|
17
17
|
import { Select } from "./Select";
|
|
18
18
|
import { Slider } from "./Slider";
|
|
19
19
|
import { Toggle } from "./Toggle";
|
|
20
|
-
import { isTypingTarget } from "
|
|
20
|
+
import { isTypingTarget } from "@hyperframes/core/typing-target";
|
|
21
21
|
import { shouldIgnorePlaybackShortcutTarget } from "../../player/lib/playbackShortcuts";
|
|
22
22
|
import { __resetDesignInputThrottle, trackDesignInput } from "../../utils/designInputTracking";
|
|
23
23
|
import { cleanupMounted, mountHost as render } from "./mountHost.testHelpers";
|
|
@@ -3,7 +3,7 @@ import { usePlayerStore } from "../player";
|
|
|
3
3
|
import type { TimelineElement } from "../player";
|
|
4
4
|
import type { DomEditSelection } from "../components/editor/domEditing";
|
|
5
5
|
import { useDockLayoutStore } from "../components/dock/dockLayoutStore";
|
|
6
|
-
import { isTypingTarget, ownsPlainKeys } from "
|
|
6
|
+
import { isTypingTarget, ownsPlainKeys } from "@hyperframes/core/typing-target";
|
|
7
7
|
import { isEditableTarget } from "../utils/timelineDiscovery";
|
|
8
8
|
import { shouldIgnoreHistoryShortcut } from "../utils/studioHelpers";
|
|
9
9
|
import { canSplitElement } from "../utils/timelineElementSplit";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { usePlayerStore } from "../player";
|
|
2
2
|
import type { TimelineEditCallbacks } from "../player/components/timelineCallbacks";
|
|
3
3
|
import { resolveLinkMenuItems } from "../player/components/clipMenuLinkItems";
|
|
4
|
-
import { isTypingTarget } from "
|
|
4
|
+
import { isTypingTarget } from "@hyperframes/core/typing-target";
|
|
5
5
|
import { keyHint, matchesKey } from "../player/components/studioShortcuts";
|
|
6
6
|
|
|
7
7
|
export interface LinkShortcutCallbacks {
|
|
@@ -31,7 +31,7 @@ import {
|
|
|
31
31
|
type HfAutomationLane,
|
|
32
32
|
} from "@hyperframes/core/audio-automation";
|
|
33
33
|
import { clampNumber } from "../utils/studioHelpers";
|
|
34
|
-
import { isTypingTarget } from "
|
|
34
|
+
import { isTypingTarget } from "@hyperframes/core/typing-target";
|
|
35
35
|
import { matchesKey } from "../player/components/studioShortcuts";
|
|
36
36
|
import type { AutomationSelection } from "../player/store/automationSelectionSlice";
|
|
37
37
|
import type {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useEffect, useCallback } from "react";
|
|
2
2
|
import { matchesKey } from "../player/components/studioShortcuts";
|
|
3
|
-
import { isTypingTarget } from "
|
|
3
|
+
import { isTypingTarget } from "@hyperframes/core/typing-target";
|
|
4
4
|
|
|
5
5
|
interface KeyframeKeyboardOptions {
|
|
6
6
|
enabled: boolean;
|
package/src/index.ts
CHANGED
|
@@ -14,8 +14,8 @@ export {
|
|
|
14
14
|
studioKeyClash,
|
|
15
15
|
useStudioKeys,
|
|
16
16
|
} from "./player/components/studioShortcuts";
|
|
17
|
-
export { formatCombo, matchCombo, parseCombo } from "
|
|
18
|
-
export type { Combo } from "
|
|
17
|
+
export { formatCombo, matchCombo, parseCombo } from "@hyperframes/core/key-combo";
|
|
18
|
+
export type { Combo } from "@hyperframes/core/key-combo";
|
|
19
19
|
export type { StudioKeyAction, StudioKeys } from "./player/components/studioShortcuts";
|
|
20
20
|
export { ShortcutsButton } from "./player/components/ShortcutsPanel";
|
|
21
21
|
export { dispatchLinkShortcut } from "./hooks/linkShortcuts";
|
package/src/keys.test.ts
CHANGED
|
@@ -31,15 +31,13 @@ function importGraph(entry: string): { files: string[]; packages: string[] } {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
describe("@hyperframes/studio/keys", () => {
|
|
34
|
-
it("imports only the key helpers:
|
|
34
|
+
it("imports only the key helpers: core's import-free matcher and no editor module", () => {
|
|
35
35
|
expect(importGraph("keys.ts")).toEqual({
|
|
36
|
-
files: [
|
|
37
|
-
|
|
38
|
-
"player/components/studioCombo.ts",
|
|
39
|
-
"player/components/studioKeyDefaults.ts",
|
|
40
|
-
],
|
|
41
|
-
packages: [],
|
|
36
|
+
files: ["keys.ts", "player/components/studioKeyDefaults.ts"],
|
|
37
|
+
packages: ["@hyperframes/core/key-combo"],
|
|
42
38
|
});
|
|
39
|
+
const matcher = readFileSync(join(src, "../../core/src/keyCombo.ts"), "utf8");
|
|
40
|
+
expect(ts.preProcessFile(matcher).importedFiles).toEqual([]);
|
|
43
41
|
});
|
|
44
42
|
|
|
45
43
|
it("is a published subpath sharing the defaults the root entry exports", async () => {
|
package/src/keys.ts
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
export {
|
|
2
|
-
matchCombo,
|
|
3
|
-
parseCombo,
|
|
4
|
-
type Combo,
|
|
5
|
-
type ComboEvent,
|
|
6
|
-
} from "./player/components/studioCombo";
|
|
1
|
+
export { matchCombo, parseCombo, type Combo, type ComboEvent } from "@hyperframes/core/key-combo";
|
|
7
2
|
export {
|
|
8
3
|
DEFAULT_STUDIO_KEYS,
|
|
9
4
|
type StudioKeyAction,
|
|
@@ -5,7 +5,7 @@ import { flatActive, flatIdle } from "../../components/timelineToolbarStyles";
|
|
|
5
5
|
import { usePlayerStore } from "../store/playerStore";
|
|
6
6
|
import { useCompositionFps } from "../../utils/linkedClipPreferences";
|
|
7
7
|
import { matchesKey, useShortcutSections, type ShortcutSection } from "./studioShortcuts";
|
|
8
|
-
import { isTypingTarget } from "
|
|
8
|
+
import { isTypingTarget } from "@hyperframes/core/typing-target";
|
|
9
9
|
|
|
10
10
|
interface ShortcutsPanelProps {
|
|
11
11
|
disabled: boolean;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @vitest-environment happy-dom
|
|
2
2
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
3
|
-
import { formatCombo, matchCombo, parseCombo } from "
|
|
3
|
+
import { formatCombo, matchCombo, parseCombo } from "@hyperframes/core/key-combo";
|
|
4
4
|
import {
|
|
5
5
|
getStudioKey,
|
|
6
6
|
getStudioKeys,
|
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
* is active and the user is navigating caption segments).
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import {
|
|
10
|
-
import type { ComboEvent } from "
|
|
9
|
+
import { shouldIgnorePlaybackShortcutTarget } from "@hyperframes/core/typing-target";
|
|
10
|
+
import type { ComboEvent } from "@hyperframes/core/key-combo";
|
|
11
11
|
import { matchesKey } from "../components/studioShortcuts";
|
|
12
12
|
import { usePlayerStore } from "../store/playerStore";
|
|
13
13
|
|
|
@@ -18,32 +18,7 @@ const FRAME_STEP_ACTIONS = [
|
|
|
18
18
|
"frameForwardTen",
|
|
19
19
|
] as const;
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
"button",
|
|
23
|
-
"a[href]",
|
|
24
|
-
"[role='button']",
|
|
25
|
-
"[role='checkbox']",
|
|
26
|
-
"[role='menuitem']",
|
|
27
|
-
// Base UI's menu radio item is a `<div>`, so `button` above no longer catches it.
|
|
28
|
-
"[role='menuitemradio']",
|
|
29
|
-
"[role='radio']",
|
|
30
|
-
"[role='spinbutton']",
|
|
31
|
-
].join(",");
|
|
32
|
-
|
|
33
|
-
export function shouldIgnorePlaybackShortcutTarget(target: EventTarget | null): boolean {
|
|
34
|
-
// Anything the user is typing into owns its keys outright, editable elements
|
|
35
|
-
// included: a letter claimed here never reaches the text. So does a native player.
|
|
36
|
-
if (ownsPlainKeys(target)) return true;
|
|
37
|
-
if (!target || typeof target !== "object") return false;
|
|
38
|
-
const candidate = target as { closest?: unknown };
|
|
39
|
-
if (typeof candidate.closest !== "function") return false;
|
|
40
|
-
return (
|
|
41
|
-
(candidate.closest as (selector: string) => Element | null).call(
|
|
42
|
-
target,
|
|
43
|
-
PLAYBACK_SHORTCUT_IGNORED_SELECTOR,
|
|
44
|
-
) !== null
|
|
45
|
-
);
|
|
46
|
-
}
|
|
21
|
+
export { shouldIgnorePlaybackShortcutTarget };
|
|
47
22
|
|
|
48
23
|
const MODAL_DIALOG_SELECTOR = "[role=dialog][aria-modal=true]";
|
|
49
24
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { buildProjectApiPath } from "./projectRouting";
|
|
2
|
-
import { isTypingTarget } from "
|
|
2
|
+
import { isTypingTarget } from "@hyperframes/core/typing-target";
|
|
3
3
|
import type { TimelineElement } from "../player/store/playerStore";
|
|
4
4
|
import type { DomEditSelection } from "../components/editor/domEditing";
|
|
5
5
|
import type { TimelineAssetKind } from "./timelineAssetDrop";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { StudioFileConflictError, type StudioSaveDrainResult } from "./studioSaveDiagnostics";
|
|
2
|
-
import { isTypingTarget } from "
|
|
2
|
+
import { isTypingTarget } from "@hyperframes/core/typing-target";
|
|
3
3
|
|
|
4
4
|
const STUDIO_FLUSH_PENDING_EDITS_EVENT = "hf-studio-flush-pending-edits";
|
|
5
5
|
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
// Compatibility name for downstream imports. The typing decision itself has
|
|
2
2
|
// one owner; new Studio callers import `isTypingTarget` directly.
|
|
3
|
-
export { isTypingTarget as isEditableTarget } from "
|
|
3
|
+
export { isTypingTarget as isEditableTarget } from "@hyperframes/core/typing-target";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// @vitest-environment happy-dom
|
|
2
2
|
|
|
3
3
|
import { afterEach, describe, expect, it } from "vitest";
|
|
4
|
-
import { isTypingTarget, ownsPlainKeys } from "
|
|
4
|
+
import { isTypingTarget, ownsPlainKeys } from "@hyperframes/core/typing-target";
|
|
5
5
|
import { isEditableTarget } from "./timelineDiscovery";
|
|
6
6
|
|
|
7
7
|
afterEach(() => {
|
|
@@ -1,24 +1,34 @@
|
|
|
1
1
|
// @vitest-environment jsdom
|
|
2
2
|
/**
|
|
3
3
|
* Loads the REAL `@mcp-b/global` through Studio's loader, inside a page that is
|
|
4
|
-
* framed by another site, and checks that neither of the package's
|
|
5
|
-
* transports answers anyone but Studio's own page.
|
|
4
|
+
* framed by another site, and checks that neither of the package's MCP
|
|
5
|
+
* message transports answers anyone but Studio's own page. The W3C polyfill's
|
|
6
|
+
* frame protocol is not exercised here: the fake framer is not `window.top`.
|
|
6
7
|
*/
|
|
7
8
|
import { afterAll, expect, it, vi } from "vitest";
|
|
8
9
|
|
|
9
10
|
vi.mock("../telemetry/client", () => ({ trackEvent: vi.fn() }));
|
|
10
11
|
|
|
11
|
-
|
|
12
|
+
// A top-level window: the polyfill walks `parent` until it reaches itself.
|
|
13
|
+
const framer = {
|
|
14
|
+
postMessage: vi.fn(),
|
|
15
|
+
get parent(): object {
|
|
16
|
+
return framer;
|
|
17
|
+
},
|
|
18
|
+
};
|
|
12
19
|
const ownParent = Object.getOwnPropertyDescriptor(window, "parent");
|
|
13
20
|
afterAll(() => {
|
|
14
21
|
if (ownParent) Object.defineProperty(window, "parent", ownParent);
|
|
15
22
|
else Reflect.deleteProperty(window, "parent");
|
|
23
|
+
Reflect.deleteProperty(window, "isSecureContext");
|
|
16
24
|
});
|
|
17
25
|
|
|
18
26
|
const settle = () => new Promise((resolve) => setTimeout(resolve, 20));
|
|
19
27
|
|
|
20
28
|
it("answers no MCP client but Studio's own page when another site frames Studio", async () => {
|
|
21
29
|
Object.defineProperty(window, "parent", { value: framer, configurable: true });
|
|
30
|
+
// jsdom leaves this undefined and the polyfill installs only in a secure context.
|
|
31
|
+
Object.defineProperty(window, "isSecureContext", { value: true, configurable: true });
|
|
22
32
|
const ownMessages = vi.spyOn(window, "postMessage");
|
|
23
33
|
const { loadModelContextPolyfill } = await import("./polyfill");
|
|
24
34
|
|
package/src/webmcp/types.ts
CHANGED
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
* Only the surface Studio registers against is declared. `getTools` and
|
|
15
15
|
* `executeTool` are the consumer side; Studio registers, it does not call.
|
|
16
16
|
*
|
|
17
|
-
* These stay hand-written rather than imported from
|
|
18
|
-
*
|
|
17
|
+
* These stay hand-written rather than imported from `webmcp-types`, which
|
|
18
|
+
* the polyfill pulls in. That package's `registerTool` is overloaded to
|
|
19
19
|
* infer argument types from a literal `inputSchema`, which is useful when you
|
|
20
20
|
* register one tool inline and actively hostile when you register a uniform
|
|
21
21
|
* list of them, as `registerStudioTools` does. Narrower is the safe operation
|
|
@@ -59,7 +59,7 @@ export interface ModelContextTool {
|
|
|
59
59
|
* instead. See `toolResult.ts`.
|
|
60
60
|
*
|
|
61
61
|
* `options` is optional here although the spec always passes it: the
|
|
62
|
-
* `@mcp-b/global` polyfill
|
|
62
|
+
* `@mcp-b/global` polyfill before 6.0 called `execute(input)` with no
|
|
63
63
|
* second argument, so a Studio handler must not depend on receiving one.
|
|
64
64
|
*/
|
|
65
65
|
execute: (input: object, options?: ToolExecuteCallbackOptions) => Promise<unknown>;
|
|
@@ -3,24 +3,24 @@
|
|
|
3
3
|
* Drives the write tools through the REAL `@mcp-b/global` package rather than
|
|
4
4
|
* a fake `document.modelContext`.
|
|
5
5
|
*
|
|
6
|
-
* The package
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* of 'undefined'" while the read tools kept working. This file proves the fix
|
|
13
|
-
* against the code that ships in the polyfill chunk. The spec-shaped call and
|
|
14
|
-
* the abort path live in `useStudioAgentTools.test.tsx`; the polyfill cannot
|
|
15
|
-
* exercise them because it drops the caller's signal before the handler.
|
|
16
|
-
*
|
|
17
|
-
* A native-looking `modelContext` is installed BEFORE the import so the bridge
|
|
18
|
-
* wraps it and mirrors every registration into it, which is how both paths get
|
|
19
|
-
* covered from one setup. Its own file because the import is a one-shot side
|
|
20
|
-
* effect that the sibling suite's fake would otherwise have to fight.
|
|
6
|
+
* The package installs the W3C polyfill and wraps it in an in-page MCP server
|
|
7
|
+
* that an out-of-browser agent reaches over the tab transport. This file
|
|
8
|
+
* proves a write tool saves when an MCP `tools/call` drives it through that
|
|
9
|
+
* chain, against the code that ships in the polyfill chunk. Its own file
|
|
10
|
+
* because the import is a one-shot side effect that the sibling suite's fake
|
|
11
|
+
* would otherwise have to fight.
|
|
21
12
|
*/
|
|
22
13
|
import { act } from "react";
|
|
23
|
-
import {
|
|
14
|
+
import {
|
|
15
|
+
afterAll,
|
|
16
|
+
afterEach,
|
|
17
|
+
beforeAll,
|
|
18
|
+
describe,
|
|
19
|
+
expect,
|
|
20
|
+
it,
|
|
21
|
+
vi,
|
|
22
|
+
type MockInstance,
|
|
23
|
+
} from "vitest";
|
|
24
24
|
import { mountReactHarness } from "../hooks/domSelectionTestHarness";
|
|
25
25
|
import { mintElementHandle } from "./handles";
|
|
26
26
|
import { useStudioAgentTools, type StudioAgentToolsDeps } from "./useStudioAgentTools";
|
|
@@ -30,71 +30,37 @@ vi.mock("../telemetry/client", () => ({ trackEvent: vi.fn() }));
|
|
|
30
30
|
|
|
31
31
|
Reflect.set(globalThis, "IS_REACT_ACT_ENVIRONMENT", true);
|
|
32
32
|
|
|
33
|
-
/** What a browser's own `registerTool` receives from the bridge. */
|
|
34
|
-
interface MirroredTool {
|
|
35
|
-
name: string;
|
|
36
|
-
description: string;
|
|
37
|
-
execute: (input: object, options?: { signal?: AbortSignal }) => Promise<unknown>;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/** What `getTools()` returns and `executeTool()` accepts. */
|
|
41
|
-
interface RegisteredTool {
|
|
42
|
-
name: string;
|
|
43
|
-
description: string;
|
|
44
|
-
window: Window;
|
|
45
|
-
origin: string;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/** The bridge's registry entry, as the reporter of the bug drove it. */
|
|
49
|
-
interface BridgeToolEntry {
|
|
50
|
-
item: { name: string };
|
|
51
|
-
execute: (input: object, signal?: AbortSignal) => Promise<unknown>;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
33
|
interface BridgeModelContext {
|
|
55
|
-
|
|
56
|
-
getTools(): Promise<
|
|
57
|
-
executeTool(
|
|
58
|
-
tool: RegisteredTool,
|
|
59
|
-
inputArguments: string,
|
|
60
|
-
options?: { signal?: AbortSignal },
|
|
61
|
-
): Promise<string | null>;
|
|
34
|
+
listTools(): { name: string }[];
|
|
35
|
+
getTools(): Promise<{ name: string }[]>;
|
|
62
36
|
}
|
|
63
37
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
},
|
|
70
|
-
// The bridge delegates `getTools()` to the native context when there is one,
|
|
71
|
-
// and its own `executeTool` then insists on a full `RegisteredTool`.
|
|
72
|
-
getTools: async (): Promise<RegisteredTool[]> =>
|
|
73
|
-
mirrored.map((tool) => ({
|
|
74
|
-
name: tool.name,
|
|
75
|
-
description: tool.description,
|
|
76
|
-
window,
|
|
77
|
-
origin: window.location.origin,
|
|
78
|
-
})),
|
|
79
|
-
};
|
|
38
|
+
interface JsonRpcResponse {
|
|
39
|
+
id: number;
|
|
40
|
+
result?: { structuredContent?: unknown; content?: { type: string; text?: string }[] };
|
|
41
|
+
error?: unknown;
|
|
42
|
+
}
|
|
80
43
|
|
|
81
44
|
let cleanup: (() => void) | null = null;
|
|
82
45
|
|
|
83
46
|
beforeAll(async () => {
|
|
84
|
-
//
|
|
85
|
-
Object.defineProperty(
|
|
86
|
-
value: fakeNative,
|
|
87
|
-
configurable: true,
|
|
88
|
-
writable: true,
|
|
89
|
-
});
|
|
47
|
+
// jsdom leaves this undefined and the polyfill installs only in a secure context.
|
|
48
|
+
Object.defineProperty(window, "isSecureContext", { value: true, configurable: true });
|
|
90
49
|
await import("@mcp-b/global");
|
|
91
|
-
expect(
|
|
50
|
+
expect(typeof bridge().listTools).toBe("function");
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
afterAll(async () => {
|
|
54
|
+
// Close the server so its deferred tools-changed event doesn't fire after jsdom is torn down.
|
|
55
|
+
const { cleanupWebModelContext } = await import("@mcp-b/global");
|
|
56
|
+
cleanupWebModelContext();
|
|
57
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
58
|
+
Reflect.deleteProperty(window, "isSecureContext");
|
|
92
59
|
});
|
|
93
60
|
|
|
94
61
|
afterEach(async () => {
|
|
95
62
|
cleanup?.();
|
|
96
63
|
cleanup = null;
|
|
97
|
-
mirrored.length = 0;
|
|
98
64
|
// The polyfill watches the document with a MutationObserver that reads jsdom
|
|
99
65
|
// globals. Empty the document and let the observer settle now, while those
|
|
100
66
|
// globals still exist, instead of when vitest closes the window.
|
|
@@ -112,28 +78,14 @@ function bridge(): BridgeModelContext {
|
|
|
112
78
|
/** Registration is async, so wait for the whole tool set to land. */
|
|
113
79
|
async function waitForTools(count: number): Promise<void> {
|
|
114
80
|
const deadline = Date.now() + 5_000;
|
|
115
|
-
while (bridge().
|
|
81
|
+
while (bridge().listTools().length !== count || (await bridge().getTools()).length !== count) {
|
|
116
82
|
if (Date.now() > deadline) {
|
|
117
|
-
throw new Error(
|
|
118
|
-
`expected ${count} tools, saw ${bridge().tools.size} in the bridge and ${mirrored.length} mirrored`,
|
|
119
|
-
);
|
|
83
|
+
throw new Error(`expected ${count} tools, saw ${bridge().listTools().length} in the bridge`);
|
|
120
84
|
}
|
|
121
85
|
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
122
86
|
}
|
|
123
87
|
}
|
|
124
88
|
|
|
125
|
-
function bridgeEntry(name: string): BridgeToolEntry {
|
|
126
|
-
const entry = [...bridge().tools.values()].find((candidate) => candidate.item.name === name);
|
|
127
|
-
if (!entry) throw new Error(`expected ${name} in the bridge registry`);
|
|
128
|
-
return entry;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
function mirroredTool(name: string): MirroredTool {
|
|
132
|
-
const tool = mirrored.find((candidate) => candidate.name === name);
|
|
133
|
-
if (!tool) throw new Error(`expected ${name} to be mirrored into the native context`);
|
|
134
|
-
return tool;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
89
|
/** Mount Studio's tools against a preview whose `#agent` element can be edited. */
|
|
138
90
|
async function mountEditableAgent() {
|
|
139
91
|
const doc = previewDoc('<h1 id="agent">Agent</h1>');
|
|
@@ -170,49 +122,65 @@ async function mountEditableAgent() {
|
|
|
170
122
|
return { agent, handle, setText };
|
|
171
123
|
}
|
|
172
124
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
// Chromium's `executeTool` extension, which the bridge also implements.
|
|
185
|
-
const descriptor = (await bridge().getTools()).find((tool) => tool.name === "studio_set_text");
|
|
186
|
-
if (!descriptor) throw new Error("expected studio_set_text in getTools()");
|
|
187
|
-
const viaExecuteTool = await bridge().executeTool(
|
|
188
|
-
descriptor,
|
|
189
|
-
JSON.stringify({ handle, text: "Through executeTool" }),
|
|
190
|
-
{ signal: new AbortController().signal },
|
|
191
|
-
);
|
|
192
|
-
expect(JSON.parse(viaExecuteTool ?? "null")).toMatchObject({ ok: true, stage: "saved" });
|
|
125
|
+
/** Post one JSON-RPC message to the in-page server the way the tab client does. */
|
|
126
|
+
function postToServer(payload: object): void {
|
|
127
|
+
window.dispatchEvent(
|
|
128
|
+
new MessageEvent("message", {
|
|
129
|
+
data: { channel: "mcp-default", type: "mcp", direction: "client-to-server", payload },
|
|
130
|
+
origin: window.location.origin,
|
|
131
|
+
source: window,
|
|
132
|
+
}),
|
|
133
|
+
);
|
|
134
|
+
}
|
|
193
135
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
136
|
+
/** The server answers through `window.postMessage`; wait for the reply to `id`. */
|
|
137
|
+
async function replyTo(sent: MockInstance, id: number): Promise<JsonRpcResponse> {
|
|
138
|
+
const deadline = Date.now() + 5_000;
|
|
139
|
+
for (;;) {
|
|
140
|
+
for (const [message] of sent.mock.calls) {
|
|
141
|
+
const payload = (message as { payload?: unknown } | undefined)?.payload;
|
|
142
|
+
if (typeof payload === "object" && payload !== null && Reflect.get(payload, "id") === id) {
|
|
143
|
+
return payload as JsonRpcResponse;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
if (Date.now() > deadline) throw new Error(`no MCP reply to request ${id}`);
|
|
147
|
+
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
148
|
+
}
|
|
149
|
+
}
|
|
201
150
|
|
|
202
|
-
|
|
151
|
+
describe("useStudioAgentTools through @mcp-b/global", () => {
|
|
152
|
+
it("saves through studio_set_text when an MCP client calls it", async () => {
|
|
203
153
|
const { agent, handle, setText } = await mountEditableAgent();
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
154
|
+
const sent = vi.spyOn(window, "postMessage");
|
|
155
|
+
|
|
156
|
+
postToServer({
|
|
157
|
+
jsonrpc: "2.0",
|
|
158
|
+
id: 1,
|
|
159
|
+
method: "initialize",
|
|
160
|
+
params: {
|
|
161
|
+
protocolVersion: "2025-06-18",
|
|
162
|
+
capabilities: {},
|
|
163
|
+
clientInfo: { name: "studio-test", version: "1.0.0" },
|
|
164
|
+
},
|
|
165
|
+
});
|
|
166
|
+
expect((await replyTo(sent, 1)).error).toBeUndefined();
|
|
167
|
+
postToServer({ jsonrpc: "2.0", method: "notifications/initialized" });
|
|
168
|
+
|
|
169
|
+
postToServer({
|
|
170
|
+
jsonrpc: "2.0",
|
|
171
|
+
id: 2,
|
|
172
|
+
method: "tools/call",
|
|
173
|
+
params: { name: "studio_set_text", arguments: { handle, text: "Through MCP" } },
|
|
174
|
+
});
|
|
175
|
+
const reply = await replyTo(sent, 2);
|
|
176
|
+
sent.mockRestore();
|
|
177
|
+
|
|
178
|
+
const text = reply.result?.content?.[0]?.text;
|
|
179
|
+
const result = reply.result?.structuredContent ?? JSON.parse(text ?? "null");
|
|
212
180
|
expect(result).toMatchObject({ ok: true, stage: "saved", changed: true });
|
|
213
181
|
expect(setText).toHaveBeenCalledWith(
|
|
214
182
|
expect.objectContaining({ element: agent }),
|
|
215
|
-
"Through
|
|
183
|
+
"Through MCP",
|
|
216
184
|
"self",
|
|
217
185
|
);
|
|
218
186
|
});
|
|
@@ -26,7 +26,7 @@ async function executeRegistered<T>(
|
|
|
26
26
|
return (await tool.execute(input, { signal })) as T;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
/** The call shape `@mcp-b/global`
|
|
29
|
+
/** The call shape `@mcp-b/global` used before 6.0: the input and nothing else. */
|
|
30
30
|
async function executeRegisteredWithoutOptions<T>(
|
|
31
31
|
registered: ModelContextTool[],
|
|
32
32
|
name: string,
|
|
@@ -362,7 +362,7 @@ describe("useStudioAgentTools", () => {
|
|
|
362
362
|
});
|
|
363
363
|
|
|
364
364
|
it("runs every write tool when execute is called with the input alone", async () => {
|
|
365
|
-
// `@mcp-b/global`
|
|
365
|
+
// `@mcp-b/global` before 6.0 invoked `execute(input)` with no options object, both from
|
|
366
366
|
// its in-page server and from the descriptor it mirrors into a native
|
|
367
367
|
// `document.modelContext`. Handlers that destructured `{ signal }` threw a
|
|
368
368
|
// TypeError before running, which `runToolBody` reports as `internal`.
|
|
@@ -117,9 +117,8 @@ export function buildStudioTools(depsRef: {
|
|
|
117
117
|
/**
|
|
118
118
|
* `execute` for a tool whose handler takes the caller's abort signal.
|
|
119
119
|
*
|
|
120
|
-
* The spec shape is `execute(input, { signal })`, but `@mcp-b/global`
|
|
121
|
-
*
|
|
122
|
-
* registered `execute` with the input ALONE, both from its in-page
|
|
120
|
+
* The spec shape is `execute(input, { signal })`, but `@mcp-b/global` before
|
|
121
|
+
* 6.0 invoked a registered `execute` with the input ALONE, both from its in-page
|
|
123
122
|
* `BrowserMcpServer` wrapper and from the descriptor it mirrors into a native
|
|
124
123
|
* `document.modelContext`. A handler that destructures its second argument
|
|
125
124
|
* throws before it runs, so every write tool failed with "Cannot destructure
|