@@ -28,6 +28,8 @@ import { ErrorCode } from '@infrastructure/errors/error.registry';
2828import { InvokeManager } from './invoke/invoke.impl' ;
2929import { Semver } from './utils/semver' ;
3030
31+ type JsonObject = Record < string , unknown > ;
32+
3133export type ToolManagerDeps = {
3234 pluginRepo : PluginRepoPort ;
3335 pluginRuntimeManager : PluginRuntimeManagerPort ;
@@ -41,6 +43,72 @@ export type PluginToolRunPayloadType = {
4143 childId ?: string ;
4244} ;
4345
46+ function isJsonObject ( value : unknown ) : value is JsonObject {
47+ return typeof value === 'object' && value !== null && ! Array . isArray ( value ) ;
48+ }
49+
50+ function getDescriptionFallback ( description : unknown ) : string | undefined {
51+ if ( typeof description === 'string' && description . length > 0 ) {
52+ return description ;
53+ }
54+
55+ if ( ! isJsonObject ( description ) ) {
56+ return undefined ;
57+ }
58+
59+ const en = description . en ;
60+ return typeof en === 'string' && en . length > 0 ? en : undefined ;
61+ }
62+
63+ function normalizeInputSchemaToolParams ( inputSchema : unknown ) : unknown {
64+ if ( ! isJsonObject ( inputSchema ) || ! isJsonObject ( inputSchema . properties ) ) {
65+ return inputSchema ;
66+ }
67+
68+ const properties = Object . fromEntries (
69+ Object . entries ( inputSchema . properties ) . map ( ( [ key , property ] ) => {
70+ if ( ! isJsonObject ( property ) ) {
71+ return [ key , property ] ;
72+ }
73+
74+ const normalizedProperty = { ...property } ;
75+ const hasToolDescription =
76+ typeof normalizedProperty . toolDescription === 'string' &&
77+ normalizedProperty . toolDescription . length > 0 ;
78+ const hasIsToolParams = normalizedProperty . isToolParams !== undefined ;
79+
80+ if ( hasIsToolParams ) {
81+ if ( ! hasToolDescription ) {
82+ const fallback = getDescriptionFallback ( normalizedProperty . description ) ;
83+ if ( fallback !== undefined ) {
84+ normalizedProperty . toolDescription = fallback ;
85+ }
86+ }
87+
88+ return [ key , normalizedProperty ] ;
89+ }
90+
91+ if ( hasToolDescription ) {
92+ normalizedProperty . isToolParams = true ;
93+ return [ key , normalizedProperty ] ;
94+ }
95+
96+ const fallback = getDescriptionFallback ( normalizedProperty . description ) ;
97+ if ( fallback !== undefined ) {
98+ normalizedProperty . toolDescription = fallback ;
99+ }
100+ normalizedProperty . isToolParams = false ;
101+
102+ return [ key , normalizedProperty ] ;
103+ } )
104+ ) ;
105+
106+ return {
107+ ...inputSchema ,
108+ properties
109+ } ;
110+ }
111+
44112export class ToolManager implements ToolManagerPort {
45113 private static instance : ToolManager ;
46114 private constructor ( private deps : ToolManagerDeps ) { }
@@ -61,6 +129,11 @@ export class ToolManager implements ToolManagerPort {
61129 } ) : ToolDetailType {
62130 return {
63131 ...tool ,
132+ inputSchema : normalizeInputSchemaToolParams ( tool . inputSchema ) ,
133+ children : tool . children ?. map ( ( child ) => ( {
134+ ...child ,
135+ inputSchema : normalizeInputSchemaToolParams ( child . inputSchema )
136+ } ) ) ,
64137 source,
65138 isToolset : Boolean ( tool . children ?. length ) ,
66139 isLatestVersion
0 commit comments