mirror of
https://github.com/legop3/MultiRoombaRover.git
synced 2026-11-14 18:58:49 -05:00
overseer v2 5 (real tools)
This commit is contained in:
@@ -8,6 +8,7 @@ const neatoSendHome = require('./neatoSendHome');
|
||||
const neatoLocate = require('./neatoLocate');
|
||||
const neatoClearErrors = require('./neatoClearErrors');
|
||||
const haSetEntity = require('./haSetEntity');
|
||||
const buttonBoxAddCount = require('./buttonBoxAddCount');
|
||||
|
||||
const TOOL_DEFINITIONS = [
|
||||
chatSay,
|
||||
@@ -20,37 +21,69 @@ const TOOL_DEFINITIONS = [
|
||||
neatoLocate,
|
||||
neatoClearErrors,
|
||||
haSetEntity,
|
||||
buttonBoxAddCount,
|
||||
];
|
||||
const TOOL_BY_ID = new Map(TOOL_DEFINITIONS.map((tool) => [tool.id, tool]));
|
||||
|
||||
function evaluateTools(context = {}) {
|
||||
const available = [];
|
||||
const availableIds = [];
|
||||
const blocked = [];
|
||||
TOOL_DEFINITIONS.forEach((tool) => {
|
||||
const result = typeof tool.availability === 'function' ? tool.availability(context) : { available: false, reason: 'unavailable' };
|
||||
if (result?.available) {
|
||||
available.push(tool.signature);
|
||||
availableIds.push(tool.id);
|
||||
return;
|
||||
}
|
||||
blocked.push({ tool: tool.signature, reason: result?.reason || 'unavailable' });
|
||||
blocked.push({ id: tool.id, tool: tool.signature, reason: result?.reason || 'unavailable' });
|
||||
});
|
||||
return { available, blocked };
|
||||
return { available, availableIds, blocked };
|
||||
}
|
||||
|
||||
async function executeToolAction(action = {}, context = {}) {
|
||||
const toolId = String(action?.tool || '').trim();
|
||||
const tool = TOOL_BY_ID.get(toolId);
|
||||
function buildOllamaTools(availableIds = []) {
|
||||
const allowed = new Set((availableIds || []).map((id) => String(id)));
|
||||
return TOOL_DEFINITIONS.filter((tool) => allowed.has(tool.id)).map((tool) => ({
|
||||
type: 'function',
|
||||
function: {
|
||||
name: tool.id,
|
||||
description: String(tool.description || tool.signature || tool.id),
|
||||
parameters: tool.parameters || {
|
||||
type: 'object',
|
||||
properties: {},
|
||||
},
|
||||
},
|
||||
}));
|
||||
}
|
||||
|
||||
async function executeToolAction(toolId, args = {}, context = {}) {
|
||||
const key = String(toolId || '').trim();
|
||||
if (!key) throw new Error('Missing tool id');
|
||||
const tool = TOOL_BY_ID.get(key);
|
||||
if (!tool) {
|
||||
throw new Error(`Unknown tool: ${toolId}`);
|
||||
throw new Error(`Unknown tool: ${key}`);
|
||||
}
|
||||
if (typeof tool.execute !== 'function') {
|
||||
throw new Error(`Tool ${toolId} is not executable`);
|
||||
throw new Error(`Tool ${key} is not executable`);
|
||||
}
|
||||
return tool.execute({ ...context, args: action?.args || {} });
|
||||
return tool.execute({ ...context, args: args || {} });
|
||||
}
|
||||
|
||||
function getToolById(toolId) {
|
||||
return TOOL_BY_ID.get(String(toolId || '').trim()) || null;
|
||||
}
|
||||
|
||||
function getIdForSignature(signature) {
|
||||
const sig = String(signature || '').trim();
|
||||
const match = TOOL_DEFINITIONS.find((tool) => tool.signature === sig);
|
||||
return match?.id || null;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
TOOL_DEFINITIONS,
|
||||
evaluateTools,
|
||||
buildOllamaTools,
|
||||
executeToolAction,
|
||||
getToolById,
|
||||
getIdForSignature,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user