import {z} from 'zod' export type GetApiApiSessionIdWebmcpToolsArgs = {id: string}; export type GetApiApiSessionIdWebmcpToolsOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const webMCPAnnotations = z.object({readOnly: z.boolean(), untrustedContent: z.boolean(), consequential: z.boolean(), autosubmit: z.boolean(), destructive: z.boolean().optional(), idempotent: z.boolean().optional(), openWorld: z.boolean().optional()}); export const webMCPFrame = z.object({id: z.string(), url: z.string(), isMainFrame: z.boolean()}); export const webMCPSource = z.object({provider: z.enum(["native", "polyfill"]), tabId: z.string(), pageUrl: z.string(), pageTitle: z.string(), frame: webMCPFrame}); export const webMCPTool = z.object({toolRef: z.string(), name: z.string(), title: z.string().optional(), description: z.string(), inputSchema: z.record(z.string(), z.unknown()).optional(), outputSchema: z.record(z.string(), z.unknown()).optional(), annotations: webMCPAnnotations, declarative: z.boolean(), backendNodeId: z.number().int().optional(), source: webMCPSource}); export const webMCPToolsResponse = z.object({tools: z.array(webMCPTool), nativeSupported: z.boolean(), truncated: z.boolean()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * List WebMCP tools * * GET /api/session/{id}/webmcp/tools */ export const getApiApiSessionIdWebmcpTools = async (args: GetApiApiSessionIdWebmcpToolsArgs, options?: GetApiApiSessionIdWebmcpToolsOptions) => { const {baseUrl = "https://api.hyperbrowser.ai", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (ApiKeyAuth !== undefined) headers.set("x-api-key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/api/session/${encodeURIComponent(String(args.id))}/webmcp/tools${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(webMCPToolsResponse, await res.json()) };