mirror of
https://github.com/samsonjs/Peekaboo.git
synced 2026-04-27 15:07:41 +00:00
Report version right in the tool
This commit is contained in:
parent
bda349ea29
commit
b029504f2f
1 changed files with 9 additions and 29 deletions
38
src/index.ts
38
src/index.ts
|
|
@ -34,8 +34,7 @@ const SERVER_VERSION = packageJson.version;
|
||||||
// Initialize the Swift CLI Path once
|
// Initialize the Swift CLI Path once
|
||||||
initializeSwiftCliPath(packageRootDir);
|
initializeSwiftCliPath(packageRootDir);
|
||||||
|
|
||||||
// Server-level state
|
// No longer need to track initial status display
|
||||||
let hasSentInitialStatus = false;
|
|
||||||
|
|
||||||
// Initialize logger
|
// Initialize logger
|
||||||
const baseLogLevel = (process.env.PEEKABOO_LOG_LEVEL || 'info').toLowerCase();
|
const baseLogLevel = (process.env.PEEKABOO_LOG_LEVEL || 'info').toLowerCase();
|
||||||
|
|
@ -143,21 +142,25 @@ const server = new Server(
|
||||||
|
|
||||||
// Set up request handlers
|
// Set up request handlers
|
||||||
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
||||||
|
// Generate server status string to append to tool descriptions
|
||||||
|
const serverStatus = generateServerStatusString(SERVER_VERSION);
|
||||||
|
const statusSuffix = `\n${serverStatus}`;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
tools: [
|
tools: [
|
||||||
{
|
{
|
||||||
name: 'image',
|
name: 'image',
|
||||||
description: 'Captures macOS screen content. Targets: entire screen (each display separately), a specific application window, or all windows of an application. Supports foreground/background capture. Captured image(s) can be saved to file(s) and/or returned directly as image data. Window shadows/frames are automatically excluded. Application identification uses intelligent fuzzy matching.',
|
description: 'Captures macOS screen content. Targets: entire screen (each display separately), a specific application window, or all windows of an application. Supports foreground/background capture. Captured image(s) can be saved to file(s) and/or returned directly as image data. Window shadows/frames are automatically excluded. Application identification uses intelligent fuzzy matching.' + statusSuffix,
|
||||||
inputSchema: zodToJsonSchema(imageToolSchema)
|
inputSchema: zodToJsonSchema(imageToolSchema)
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'analyze',
|
name: 'analyze',
|
||||||
description: 'Analyzes an image file using a configured AI model (local Ollama, cloud OpenAI, etc.) and returns a textual analysis/answer. Requires image path. AI provider selection and model defaults are governed by the server\'s `AI_PROVIDERS` environment variable and client overrides.',
|
description: 'Analyzes an image file using a configured AI model (local Ollama, cloud OpenAI, etc.) and returns a textual analysis/answer. Requires image path. AI provider selection and model defaults are governed by the server\'s `AI_PROVIDERS` environment variable and client overrides.' + statusSuffix,
|
||||||
inputSchema: zodToJsonSchema(analyzeToolSchema)
|
inputSchema: zodToJsonSchema(analyzeToolSchema)
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'list',
|
name: 'list',
|
||||||
description: 'Lists system items: all running applications, windows of a specific app, or server status. Allows specifying window details. App ID uses fuzzy matching.',
|
description: 'Lists system items: all running applications, windows of a specific app, or server status. Allows specifying window details. App ID uses fuzzy matching.' + statusSuffix,
|
||||||
inputSchema: zodToJsonSchema(listToolSchema)
|
inputSchema: zodToJsonSchema(listToolSchema)
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
@ -186,10 +189,6 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
||||||
case 'list': {
|
case 'list': {
|
||||||
const validatedArgs = listToolSchema.parse(args || {});
|
const validatedArgs = listToolSchema.parse(args || {});
|
||||||
response = await listToolHandler(validatedArgs, toolContext);
|
response = await listToolHandler(validatedArgs, toolContext);
|
||||||
// Do not augment status for peekaboo.list with item_type: "server_status"
|
|
||||||
if (validatedArgs.item_type === 'server_status') {
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
|
@ -197,29 +196,10 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
||||||
content: [{ type: 'text', text: `Unknown tool: ${name}` }],
|
content: [{ type: 'text', text: `Unknown tool: ${name}` }],
|
||||||
isError: true
|
isError: true
|
||||||
};
|
};
|
||||||
// Log error for unknown tool, but allow status augmentation if it somehow wasn't an error response initially
|
|
||||||
logger.error(`Unknown tool: ${name}`);
|
logger.error(`Unknown tool: ${name}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Augment successful tool responses with initial server status
|
return response;
|
||||||
if (response && !response.isError && !hasSentInitialStatus) {
|
|
||||||
const statusString = generateServerStatusString(SERVER_VERSION);
|
|
||||||
const statusContentItem = { type: 'text', text: statusString };
|
|
||||||
|
|
||||||
if (response.content && Array.isArray(response.content) && response.content.length > 0) {
|
|
||||||
// Check if first item is a text item
|
|
||||||
if (response.content[0].type === 'text') {
|
|
||||||
response.content[0].text += statusString; // Append to existing text item
|
|
||||||
} else {
|
|
||||||
response.content.unshift(statusContentItem); // Prepend as new text item
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
response.content = [statusContentItem]; // Create content array with status item
|
|
||||||
}
|
|
||||||
hasSentInitialStatus = true;
|
|
||||||
logger.info('Initial server status message appended to tool response.');
|
|
||||||
}
|
|
||||||
return response; // Return the (potentially augmented) response
|
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error({ error, toolName: name }, 'Tool execution failed');
|
logger.error({ error, toolName: name }, 'Tool execution failed');
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue