///
import { b as WebMCPToolResponse } from '../shared/vue-webmcp.BUJ4eDiy.mjs';
/**
* A test double for `document.modelContext`.
*
* `installModelContextStub()` is written to be self-contained: it refers to
* nothing outside its own body, so `MODEL_CONTEXT_INIT_SCRIPT` can be its
* source as a string for Playwright's `addInitScript` or Puppeteer's
* `evaluateOnNewDocument`. Keep it that way when editing.
*/
interface StubTool {
name: string;
title?: string;
description: string;
inputSchema?: object;
annotations?: {
readOnlyHint?: boolean;
untrustedContentHint?: boolean;
};
execute: (args: unknown, options?: {
signal: AbortSignal;
}) => unknown;
}
interface StubRegisteredTool {
name: string;
title: string;
description: string;
inputSchema?: object;
annotations?: StubTool['annotations'];
window: unknown;
origin: string;
}
interface ModelContextStub extends EventTarget {
/** Every currently registered tool, by name. */
tools: Map;
registerTool(tool: StubTool, options?: {
signal?: AbortSignal;
exposedTo?: readonly string[];
}): Promise;
getTools(options?: {
fromOrigins?: readonly string[];
}): Promise;
/** Accepts an object (spec) or a JSON string (older Chrome); resolves with the result as JSON text. */
executeTool(tool: {
name: string;
}, args?: object | string, options?: {
signal?: AbortSignal;
}): Promise;
/** Sorted registered names. Not part of the spec. */
names(): string[];
/**
* Call a tool the way an agent would and get its result back as the value
* `execute` produced; through `useWebMCPTool` that is the normalized
* `{ content, isError }`. Not part of the spec.
*/
call(name: string, args?: object, options?: {
signal?: AbortSignal;
}): Promise;
}
interface StubHost {
document?: object;
window?: unknown;
location?: {
origin: string;
};
}
/**
* Installs a stub `document.modelContext` on `host` (`globalThis` by default)
* and returns it. Registrations are recorded, the `AbortSignal` that
* unregisters is honoured, `getTools()` / `executeTool()` / `toolchange`
* behave as the spec describes, and `names()` / `call()` are there for tests.
*/
declare function installModelContextStub(host?: StubHost): ModelContextStub;
/** Removes a stub installed by `installModelContextStub()`. */
declare function uninstallModelContextStub(host?: StubHost): void;
/**
* `installModelContextStub` as a script, for Playwright's
* `context.addInitScript(MODEL_CONTEXT_INIT_SCRIPT)` or Puppeteer's
* `page.evaluateOnNewDocument(MODEL_CONTEXT_INIT_SCRIPT)`, so the stub is in
* place before any page script runs. The page can then reach it as
* `document.modelContext` and its `names()` / `call()` helpers.
*
* The string is the function's source as published. Import it from Node
* (a Playwright fixture, a vitest setup file); a bundler that re-transforms
* this package with name-keeping helpers (`__name`) would leave those in
* the string, which a page without them cannot run.
*/
declare const MODEL_CONTEXT_INIT_SCRIPT: string;
export { MODEL_CONTEXT_INIT_SCRIPT, installModelContextStub, uninstallModelContextStub };
export type { ModelContextStub, StubRegisteredTool, StubTool };