import { z } from 'zod';
import { getSource } from '../executor/wda.js';
import { getOrCreateSession } from '../utils/wda-session.js';
export const wdaSourceSchema = z.object({
bundle_id: z
.string()
.optional()
.describe('Bundle ID of app to activate for this session'),
port: z.number().optional().describe('WDA server port (default: 8100)'),
});
export type WdaSourceInput = z.infer<typeof wdaSourceSchema>;
export const wdaSourceTool = {
name: 'wda_source',
description:
'Get the UI hierarchy (accessibility tree) of the current screen as XML. Useful for understanding app structure and finding elements to interact with.',
inputSchema: wdaSourceSchema,
handler: async (input: WdaSourceInput) => {
const options = { port: input.port };
const sessionId = await getOrCreateSession(input.bundle_id, options);
const source = await getSource(sessionId, options);
return {
content: [
{
type: 'text' as const,
text: source,
},
],
};
},
};