@@ -131,7 +131,7 @@ export class HttpDispatcher {
131131 * Standard: /metadata/:type/:name
132132 * Fallback for backward compat: /metadata (all objects), /metadata/:objectName (get object)
133133 */
134- async handleMetadata ( path : string , context : HttpProtocolContext ) : Promise < HttpDispatcherResult > {
134+ async handleMetadata ( path : string , context : HttpProtocolContext , method ?: string , body ?: any ) : Promise < HttpDispatcherResult > {
135135 const broker = this . ensureBroker ( ) ;
136136 const parts = path . replace ( / ^ \/ + / , '' ) . split ( '/' ) . filter ( Boolean ) ;
137137
@@ -142,9 +142,34 @@ export class HttpDispatcher {
142142 return { handled : true , response : this . success ( { types : [ 'objects' , 'apps' , 'plugins' ] } ) } ;
143143 }
144144
145- // GET /metadata/:type/:name
145+ // /metadata/:type/:name
146146 if ( parts . length === 2 ) {
147147 const [ type , name ] = parts ;
148+
149+ // PUT /metadata/:type/:name (Save)
150+ if ( method === 'PUT' && body ) {
151+ // Try to get the protocol service directly
152+ const protocol = this . kernel ?. context ?. getService ? this . kernel . context . getService ( 'protocol' ) : null ;
153+
154+ if ( protocol && typeof protocol . saveMetaItem === 'function' ) {
155+ try {
156+ const result = await protocol . saveMetaItem ( { type, name, item : body } ) ;
157+ return { handled : true , response : this . success ( result ) } ;
158+ } catch ( e : any ) {
159+ return { handled : true , response : this . error ( e . message , 400 ) } ;
160+ }
161+ }
162+
163+ // Fallback to broker if protocol not available (legacy)
164+ try {
165+ const data = await broker . call ( 'metadata.saveItem' , { type, name, item : body } , { request : context . request } ) ;
166+ return { handled : true , response : this . success ( data ) } ;
167+ } catch ( e : any ) {
168+ // If broker doesn't support it either
169+ return { handled : true , response : this . error ( e . message || 'Save not supported' , 501 ) } ;
170+ }
171+ }
172+
148173 try {
149174 // Try specific calls based on type
150175 if ( type === 'objects' ) {
0 commit comments