Files
MultiRoombaRover/server/src/services/overseerControlService/tools/index.js
T
legop3 52c171c256
Container image / image (push) Failing after 53s
activity control tool yay and overseer god mode
2026-10-24 12:38:22 -04:00

98 lines
2.9 KiB
JavaScript

const memoryRead = require('./memoryRead');
const memoryWrite = require('./memoryWrite');
const memoryNoteUpsert = require('./memoryNoteUpsert');
const memoryNoteDelete = require('./memoryNoteDelete');
const memoryEventAdd = require('./memoryEventAdd');
const liftUp = require('./liftUp');
const liftDown = require('./liftDown');
const neatoStart = require('./neatoStart');
const neatoSendHome = require('./neatoSendHome');
// const neatoLocate = require('./neatoLocate');
const neatoClearErrors = require('./neatoClearErrors');
const haSetEntity = require('./haSetEntity');
const haSetLightColor = require('./haSetLightColor');
const buttonBoxAddCount = require('./buttonBoxAddCount');
const activityAct = require('./activityAct');
const TOOL_DEFINITIONS = [
memoryRead,
memoryWrite,
memoryNoteUpsert,
memoryNoteDelete,
memoryEventAdd,
liftUp,
liftDown,
neatoStart,
neatoSendHome,
// neatoLocate,
neatoClearErrors,
haSetEntity,
haSetLightColor,
buttonBoxAddCount,
activityAct,
];
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({ id: tool.id, tool: tool.signature, reason: result?.reason || 'unavailable' });
});
return { available, availableIds, blocked };
}
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: ${key}`);
}
if (typeof tool.execute !== 'function') {
throw new Error(`Tool ${key} is not executable`);
}
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,
};