mirror of
https://github.com/samsonjs/Peekaboo.git
synced 2026-04-26 14:57:47 +00:00
more lenient tool handling
This commit is contained in:
parent
bc834f977a
commit
b8fd8870dd
2 changed files with 26 additions and 25 deletions
|
|
@ -94,17 +94,10 @@ export async function listToolHandler(
|
|||
const { logger } = context;
|
||||
|
||||
try {
|
||||
// Determine the effective item_type
|
||||
let effective_item_type = input.item_type;
|
||||
if (!effective_item_type) {
|
||||
effective_item_type = input.app ? "application_windows" : "running_applications";
|
||||
}
|
||||
|
||||
const new_input = { ...input, item_type: effective_item_type };
|
||||
logger.debug({ input: new_input }, "Processing peekaboo.list tool call");
|
||||
logger.debug({ input }, "Processing peekaboo.list tool call");
|
||||
|
||||
// Handle server_status directly without calling Swift CLI
|
||||
if (new_input.item_type === "server_status") {
|
||||
if (input.item_type === "server_status") {
|
||||
// Get package version and root directory
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
|
|
@ -118,7 +111,7 @@ export async function listToolHandler(
|
|||
}
|
||||
|
||||
// Build Swift CLI arguments
|
||||
const args = buildSwiftCliArgs(new_input);
|
||||
const args = buildSwiftCliArgs(input);
|
||||
|
||||
// Execute Swift CLI
|
||||
const swiftResponse = await executeSwiftCli(args, logger);
|
||||
|
|
@ -157,15 +150,17 @@ export async function listToolHandler(
|
|||
}
|
||||
|
||||
// Process the response based on item type
|
||||
if (new_input.item_type === "running_applications") {
|
||||
const effective_item_type = input.item_type || (input.app ? "application_windows" : "running_applications");
|
||||
|
||||
if (effective_item_type === "running_applications") {
|
||||
return handleApplicationsList(
|
||||
swiftResponse.data as ApplicationListData,
|
||||
swiftResponse,
|
||||
);
|
||||
} else if (new_input.item_type === "application_windows") {
|
||||
} else if (effective_item_type === "application_windows") {
|
||||
return handleWindowsList(
|
||||
swiftResponse.data as WindowListData,
|
||||
new_input,
|
||||
input,
|
||||
swiftResponse,
|
||||
);
|
||||
}
|
||||
|
|
@ -350,19 +345,23 @@ async function handleServerStatus(
|
|||
|
||||
export function buildSwiftCliArgs(input: ListToolInput): string[] {
|
||||
const args = ["list"];
|
||||
const itemType = input.item_type || (input.app ? "application_windows" : "running_applications");
|
||||
|
||||
if (input.item_type === "running_applications") {
|
||||
if (itemType === "running_applications") {
|
||||
args.push("apps");
|
||||
} else if (input.item_type === "application_windows") {
|
||||
} else if (itemType === "application_windows") {
|
||||
args.push("windows");
|
||||
args.push("--app", input.app as string);
|
||||
|
||||
if (input.app) {
|
||||
args.push("--app", input.app);
|
||||
}
|
||||
if (
|
||||
input.include_window_details &&
|
||||
input.include_window_details.length > 0
|
||||
) {
|
||||
args.push("--include-details", input.include_window_details.join(","));
|
||||
}
|
||||
} else if (itemType === "server_status") {
|
||||
args.push("server_status");
|
||||
}
|
||||
|
||||
return args;
|
||||
|
|
|
|||
|
|
@ -143,14 +143,16 @@ export const imageToolSchema = z.object({
|
|||
"If `path` is also provided when `format` is `'data'`, the image is saved (as PNG) AND Base64 data is returned.\n" +
|
||||
"Defaults to `'data'` if `path` is not given.",
|
||||
),
|
||||
capture_focus: z.enum(["background", "foreground"])
|
||||
.optional()
|
||||
.default("background")
|
||||
.describe(
|
||||
"Optional. Focus behavior.\n" +
|
||||
"`'background'` (default): Captures without altering window focus.\n" +
|
||||
"`'foreground'`: Brings the target window(s) to the front before capture.",
|
||||
),
|
||||
capture_focus: z.preprocess(
|
||||
(val) => (val === "" || val === null ? undefined : val),
|
||||
z.enum(["background", "foreground"])
|
||||
.optional()
|
||||
.default("background")
|
||||
.describe(
|
||||
"Optional. Focus behavior. 'background' (default): capture without altering window focus. " +
|
||||
"'foreground': bring target to front before capture."
|
||||
)
|
||||
),
|
||||
})
|
||||
.describe(
|
||||
"Captures screen content and optionally analyzes it. " +
|
||||
|
|
|
|||
Loading…
Reference in a new issue