This commit is contained in:
seb
2026-10-08 12:44:53 +02:00
parent 79a1b72292
commit e2e7f8d566
11 changed files with 172 additions and 21 deletions

View File

@@ -0,0 +1,46 @@
import { defineTool } from 'libllmorbiter';
/**
* 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:
'Navigate the user to a frontend route. Use this when the user says "show me the article" or asks to see, open, or view a specific page or entity (e.g. an article detail page, orders, quotes, deliveries, or customer). Refer to the User Perspective Route Construction Matrix for valid route patterns.',
strict: false,
parameters: {
type: 'object',
additionalProperties: false,
required: ['route'],
properties: {
route: {
type: 'string',
description: 'Target frontend route path according to the Route Construction Matrix (e.g. "/artikel/ART-10042", "/kategorien/elektronik/kabel", "/auftrag/1001").',
},
},
},
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}`,
};
},
});
}