- port retrieval, validation, and eval improvements relevant to os - align prompts and dimensions with the flat single-agent model - replace the old eval suite with the focused core scenarios Generated with Codex
92 lines
2.7 KiB
TypeScript
92 lines
2.7 KiB
TypeScript
import { tool } from 'ai';
|
|
import { z } from 'zod';
|
|
import { DimensionService } from '@/services/database/dimensionService';
|
|
import { getSQLiteClient } from '@/services/database/sqlite-client';
|
|
|
|
export const getDimensionTool = tool({
|
|
description: 'Get dimension details: description and node count.',
|
|
inputSchema: z.object({
|
|
name: z.string().describe('The exact name of the dimension to retrieve')
|
|
}),
|
|
execute: async ({ name }) => {
|
|
console.log('📁 GetDimension tool called for:', name);
|
|
try {
|
|
const trimmedName = name.trim();
|
|
if (!trimmedName) {
|
|
return {
|
|
success: false,
|
|
error: 'Dimension name is required',
|
|
data: null
|
|
};
|
|
}
|
|
|
|
// Get dimension details from service
|
|
const dimension = await DimensionService.getDimensionByName(trimmedName);
|
|
|
|
// Get node count for this dimension
|
|
const sqlite = getSQLiteClient();
|
|
const countResult = sqlite.query(`
|
|
SELECT COUNT(*) AS count
|
|
FROM node_dimensions
|
|
WHERE dimension = ?
|
|
`, [trimmedName]);
|
|
|
|
const nodeCount = countResult.rows.length > 0
|
|
? Number((countResult.rows[0] as { count: number }).count)
|
|
: 0;
|
|
|
|
if (!dimension) {
|
|
// Dimension might exist in node_dimensions but not in dimensions table
|
|
if (nodeCount > 0) {
|
|
return {
|
|
success: true,
|
|
data: {
|
|
name: trimmedName,
|
|
description: null,
|
|
nodeCount,
|
|
exists: true,
|
|
hasMetadata: false
|
|
},
|
|
message: `Dimension "${trimmedName}" exists with ${nodeCount} nodes but has no metadata (description/priority not set).`
|
|
};
|
|
}
|
|
|
|
return {
|
|
success: false,
|
|
error: `Dimension "${trimmedName}" not found`,
|
|
data: null
|
|
};
|
|
}
|
|
|
|
const result = {
|
|
name: dimension.name,
|
|
description: dimension.description,
|
|
nodeCount,
|
|
updatedAt: dimension.updated_at,
|
|
exists: true,
|
|
hasMetadata: true
|
|
};
|
|
|
|
// Build descriptive message
|
|
const parts: string[] = [];
|
|
parts.push(`Dimension: ${result.name}`);
|
|
parts.push(`Nodes: ${result.nodeCount}`);
|
|
if (result.description) parts.push(`Description: ${result.description}`);
|
|
parts.push(`Last updated: ${result.updatedAt}`);
|
|
|
|
return {
|
|
success: true,
|
|
data: result,
|
|
message: parts.join('\n')
|
|
};
|
|
} catch (error) {
|
|
console.error('GetDimension tool error:', error);
|
|
return {
|
|
success: false,
|
|
error: error instanceof Error ? error.message : 'Failed to get dimension',
|
|
data: null
|
|
};
|
|
}
|
|
}
|
|
});
|