Skip to content

Commit 1f7550e

Browse files
Claudehotlong
andauthored
Fix broker shim to query MetadataService for runtime-registered metadata
The broker shim was only querying SchemaRegistry, which doesn't contain agents/tools registered at runtime via metadataService.register(). Changes: - Merge types from both SchemaRegistry and MetadataService.registry - Query MetadataService.list() for metadata items alongside SchemaRegistry - Deduplicate items by name when merging from both sources This ensures that agents and tools registered by AIServicePlugin during the start() phase are visible to Studio's sidebar. Agent-Logs-Url: https://github.com/objectstack-ai/framework/sessions/6dbd64f2-446d-4992-9adb-659a1283ec1b Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 4610c03 commit 1f7550e

1 file changed

Lines changed: 42 additions & 3 deletions

File tree

apps/studio/src/lib/create-broker-shim.ts

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,23 @@ export function createBrokerShim(kernel: any): BrokerShim {
178178
}
179179

180180
if (service === 'metadata') {
181+
// Get MetadataService for runtime-registered metadata (agents, tools, etc.)
182+
const metadataService = kernel.context?.getService('metadata');
183+
181184
if (method === 'types') {
182-
return { types: SchemaRegistry.getRegisteredTypes() };
185+
// Combine types from both SchemaRegistry (static) and MetadataService (runtime)
186+
const schemaTypes = SchemaRegistry.getRegisteredTypes();
187+
188+
// MetadataService exposes types through its internal registry
189+
// Access via the manager's registry property if available
190+
let runtimeTypes: string[] = [];
191+
if (metadataService && (metadataService as any).registry) {
192+
runtimeTypes = Array.from((metadataService as any).registry.keys());
193+
}
194+
195+
// Merge and deduplicate
196+
const allTypes = Array.from(new Set([...schemaTypes, ...runtimeTypes]));
197+
return { types: allTypes };
183198
}
184199
if (method === 'objects') {
185200
const packageId = params.packageId;
@@ -206,9 +221,33 @@ export function createBrokerShim(kernel: any): BrokerShim {
206221
}
207222
return def || null;
208223
}
209-
// Generic metadata type: metadata.<type> → SchemaRegistry.listItems(type, packageId?)
224+
// Generic metadata type: metadata.<type> → check both SchemaRegistry and MetadataService
210225
const packageId = params.packageId;
211-
const items = SchemaRegistry.listItems(method, packageId);
226+
227+
// Try SchemaRegistry first (static metadata from packages)
228+
let items = SchemaRegistry.listItems(method, packageId);
229+
230+
// Also check MetadataService for runtime-registered metadata (agents, tools, etc.)
231+
if (metadataService && typeof metadataService.list === 'function') {
232+
try {
233+
const runtimeItems = await metadataService.list(method);
234+
if (runtimeItems && runtimeItems.length > 0) {
235+
// Merge items, avoiding duplicates by name
236+
const itemMap = new Map();
237+
items.forEach((item: any) => itemMap.set(item.name, item));
238+
runtimeItems.forEach((item: any) => {
239+
if (item && typeof item === 'object' && 'name' in item) {
240+
itemMap.set(item.name, item);
241+
}
242+
});
243+
items = Array.from(itemMap.values());
244+
}
245+
} catch (err) {
246+
// MetadataService.list might fail for unknown types, that's OK
247+
console.debug(`[BrokerShim] MetadataService.list('${method}') failed:`, err);
248+
}
249+
}
250+
212251
if (items && items.length > 0) {
213252
return { type: method, items };
214253
}

0 commit comments

Comments
 (0)