47 lines
1.5 KiB
JavaScript
47 lines
1.5 KiB
JavaScript
import { defineTool } from 'libllmorbiter';
|
|
import { TOOL_DESCRIPTIONS, TOOL_PARAMETER_DESCRIPTIONS } from './prompts.js';
|
|
|
|
/**
|
|
* Creates the set-user-route tool.
|
|
* Sends the user to a specific frontend route (e.g. when the user says "show me the article",
|
|
* "open quote 1001", "go to orders", etc.).
|
|
*
|
|
* @param {{ onRoute?: (route: string) => void }} [options]
|
|
*/
|
|
export function createSetUserRouteTool({ onRoute } = {}) {
|
|
return defineTool({
|
|
name: 'set-user-route',
|
|
description: TOOL_DESCRIPTIONS.set_user_route,
|
|
strict: false,
|
|
parameters: {
|
|
type: 'object',
|
|
additionalProperties: false,
|
|
required: ['route'],
|
|
properties: {
|
|
route: {
|
|
type: 'string',
|
|
description: TOOL_PARAMETER_DESCRIPTIONS.set_user_route.route,
|
|
},
|
|
},
|
|
},
|
|
invoke: async ({ route }) => {
|
|
const trimmedRoute = typeof route === 'string' ? route.trim() : '';
|
|
if (!trimmedRoute) {
|
|
throw new Error('route is required');
|
|
}
|
|
if (typeof onRoute === 'function') {
|
|
try {
|
|
onRoute(trimmedRoute);
|
|
} catch (err) {
|
|
console.error('set-user-route onRoute callback error:', err);
|
|
}
|
|
}
|
|
return {
|
|
success: true,
|
|
route: trimmedRoute,
|
|
message: `Navigated user to ${trimmedRoute}`,
|
|
};
|
|
},
|
|
});
|
|
}
|