Skip to content

Commit 64a9c3d

Browse files
Claudehotlong
andauthored
fix: Use kernel.getService() public API instead of private context property
Replace direct access to kernel.context (private property) with public kernel.getService() method. The protocol now probes for known services at runtime to build a fresh service map, ensuring metadata service is accessible when needed. Related to AI metadata visibility fix. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 37bbb2f commit 64a9c3d

File tree

1 file changed

+30
-6
lines changed

1 file changed

+30
-6
lines changed

packages/objectql/src/plugin.ts

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,39 @@ export class ObjectQLPlugin implements Plugin {
7373

7474
// Register Protocol Implementation
7575
// IMPORTANT: Use getKernel() to access services dynamically.
76-
// ctx.getServices() returns a snapshot at call time, but we need
77-
// live access to services that are registered after this plugin's init().
78-
// MetadataPlugin and AIServicePlugin register after ObjectQLPlugin,
79-
// so we must access kernel.context.getServices() at request time.
76+
// We pass callbacks that invoke kernel methods at request time, ensuring
77+
// we get live access to services registered after this plugin's init().
78+
// MetadataPlugin and AIServicePlugin register after ObjectQLPlugin.
8079
const kernel = ctx.getKernel();
8180
const protocolShim = new ObjectStackProtocolImplementation(
8281
this.ql,
83-
() => kernel.context?.getServices() ?? new Map(),
84-
() => kernel.context?.getService('feed') as any
82+
() => {
83+
try {
84+
// Get fresh services map at runtime by probing known service names
85+
const services = new Map<string, any>();
86+
const knownServices = ['data', 'metadata', 'ai', 'feed', 'cache', 'queue', 'manifest'];
87+
for (const name of knownServices) {
88+
try {
89+
const service = kernel.getService(name);
90+
if (service) {
91+
services.set(name, service);
92+
}
93+
} catch {
94+
// Service not available, skip
95+
}
96+
}
97+
return services;
98+
} catch {
99+
return new Map();
100+
}
101+
},
102+
() => {
103+
try {
104+
return kernel.getService('feed') as any;
105+
} catch {
106+
return undefined;
107+
}
108+
}
85109
);
86110

87111
ctx.registerService('protocol', protocolShim);

0 commit comments

Comments
 (0)