import { defineTool } from 'libllmorbiter'; import * as db from '../db/company.js'; import { TOOL_DESCRIPTIONS, TOOL_PARAMETER_DESCRIPTIONS } from './prompts.js'; /** * Creates the apisuggestionsorissues tool allowing the agent to report * missing API endpoints, bugs, or general issues into the company history table. * These reports are then visible to triage agents or administrators. * * @param {{ googleAuthId: number, companyId?: number }} ctx */ export function createApiSuggestionsOrIssuesTool({ googleAuthId, companyId }) { return defineTool({ name: 'apisuggestionsorissues', description: TOOL_DESCRIPTIONS.apisuggestionsorissues, strict: false, parameters: { type: 'object', additionalProperties: false, required: ['text'], properties: { text: { type: 'string', description: TOOL_PARAMETER_DESCRIPTIONS.apisuggestionsorissues.text, }, type: { type: ['string', 'null'], enum: ['missing_api', 'bug', 'suggestion', 'issue', 'other', null], description: TOOL_PARAMETER_DESCRIPTIONS.apisuggestionsorissues.type, }, title: { type: ['string', 'null'], description: TOOL_PARAMETER_DESCRIPTIONS.apisuggestionsorissues.title, }, }, }, invoke: async ({ text, type, title }) => { const trimmedText = typeof text === 'string' ? text.trim() : ''; if (!trimmedText) { throw new Error('text is required'); } const prefixParts = []; if (type) prefixParts.push(`[${type.toUpperCase()}]`); if (title) prefixParts.push(title.trim()); const formatted = prefixParts.length > 0 ? `${prefixParts.join(' ')}\n${trimmedText}` : trimmedText; const entry = await db.addCompanyHistory(googleAuthId, { text: formatted }); return { success: true, message: 'Recorded in company history for triage agent review', entry, }; }, }); }