u
This commit is contained in:
46
src/tools/set-user-route.js
Normal file
46
src/tools/set-user-route.js
Normal 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}`,
|
||||
};
|
||||
},
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user