mirror of
https://github.com/samsonjs/Peekaboo.git
synced 2026-04-27 15:07:41 +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;
|
const { logger } = context;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Determine the effective item_type
|
logger.debug({ input }, "Processing peekaboo.list tool call");
|
||||||
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");
|
|
||||||
|
|
||||||
// Handle server_status directly without calling Swift CLI
|
// 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
|
// Get package version and root directory
|
||||||
const __filename = fileURLToPath(import.meta.url);
|
const __filename = fileURLToPath(import.meta.url);
|
||||||
const __dirname = path.dirname(__filename);
|
const __dirname = path.dirname(__filename);
|
||||||
|
|
@ -118,7 +111,7 @@ export async function listToolHandler(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build Swift CLI arguments
|
// Build Swift CLI arguments
|
||||||
const args = buildSwiftCliArgs(new_input);
|
const args = buildSwiftCliArgs(input);
|
||||||
|
|
||||||
// Execute Swift CLI
|
// Execute Swift CLI
|
||||||
const swiftResponse = await executeSwiftCli(args, logger);
|
const swiftResponse = await executeSwiftCli(args, logger);
|
||||||
|
|
@ -157,15 +150,17 @@ export async function listToolHandler(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process the response based on item type
|
// 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(
|
return handleApplicationsList(
|
||||||
swiftResponse.data as ApplicationListData,
|
swiftResponse.data as ApplicationListData,
|
||||||
swiftResponse,
|
swiftResponse,
|
||||||
);
|
);
|
||||||
} else if (new_input.item_type === "application_windows") {
|
} else if (effective_item_type === "application_windows") {
|
||||||
return handleWindowsList(
|
return handleWindowsList(
|
||||||
swiftResponse.data as WindowListData,
|
swiftResponse.data as WindowListData,
|
||||||
new_input,
|
input,
|
||||||
swiftResponse,
|
swiftResponse,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -350,19 +345,23 @@ async function handleServerStatus(
|
||||||
|
|
||||||
export function buildSwiftCliArgs(input: ListToolInput): string[] {
|
export function buildSwiftCliArgs(input: ListToolInput): string[] {
|
||||||
const args = ["list"];
|
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");
|
args.push("apps");
|
||||||
} else if (input.item_type === "application_windows") {
|
} else if (itemType === "application_windows") {
|
||||||
args.push("windows");
|
args.push("windows");
|
||||||
args.push("--app", input.app as string);
|
if (input.app) {
|
||||||
|
args.push("--app", input.app);
|
||||||
|
}
|
||||||
if (
|
if (
|
||||||
input.include_window_details &&
|
input.include_window_details &&
|
||||||
input.include_window_details.length > 0
|
input.include_window_details.length > 0
|
||||||
) {
|
) {
|
||||||
args.push("--include-details", input.include_window_details.join(","));
|
args.push("--include-details", input.include_window_details.join(","));
|
||||||
}
|
}
|
||||||
|
} else if (itemType === "server_status") {
|
||||||
|
args.push("server_status");
|
||||||
}
|
}
|
||||||
|
|
||||||
return args;
|
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" +
|
"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.",
|
"Defaults to `'data'` if `path` is not given.",
|
||||||
),
|
),
|
||||||
capture_focus: z.enum(["background", "foreground"])
|
capture_focus: z.preprocess(
|
||||||
.optional()
|
(val) => (val === "" || val === null ? undefined : val),
|
||||||
.default("background")
|
z.enum(["background", "foreground"])
|
||||||
.describe(
|
.optional()
|
||||||
"Optional. Focus behavior.\n" +
|
.default("background")
|
||||||
"`'background'` (default): Captures without altering window focus.\n" +
|
.describe(
|
||||||
"`'foreground'`: Brings the target window(s) to the front before capture.",
|
"Optional. Focus behavior. 'background' (default): capture without altering window focus. " +
|
||||||
),
|
"'foreground': bring target to front before capture."
|
||||||
|
)
|
||||||
|
),
|
||||||
})
|
})
|
||||||
.describe(
|
.describe(
|
||||||
"Captures screen content and optionally analyzes it. " +
|
"Captures screen content and optionally analyzes it. " +
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue