Skip to content

Commit f7639c6

Browse files
Copilothotlong
andcommitted
feat: apply Kernel Protocol Compliance (6.1) to UI and Browser plugins
- Add PluginCapabilityManifest with provides/requires declarations - Add latency tracking (responseTime) to healthCheck() in both plugins - Emit plugin.initialized, plugin.started, plugin.destroyed lifecycle events Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent becb4f2 commit f7639c6

2 files changed

Lines changed: 46 additions & 2 deletions

File tree

packages/browser/src/plugin.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ export class BrowserRuntimePlugin implements Plugin {
9191
context.registerService('browser-service-worker', this.serviceWorker);
9292
context.registerService('browser-worker', this.worker);
9393

94+
context.trigger('plugin.initialized', { plugin: this.name });
9495
context.logger.info('[BrowserRuntime] Initialized successfully');
9596
} catch (error: any) {
9697
context.logger.error('[BrowserRuntime] Initialization failed:', error);
@@ -102,6 +103,7 @@ export class BrowserRuntimePlugin implements Plugin {
102103
* Start plugin
103104
*/
104105
async start(context: PluginContext): Promise<void> {
106+
context.trigger('plugin.started', { plugin: this.name });
105107
context.logger.info('[BrowserRuntime] Started successfully');
106108

107109
// Set up API handlers
@@ -131,15 +133,21 @@ export class BrowserRuntimePlugin implements Plugin {
131133
* Health check
132134
*/
133135
async healthCheck(): Promise<PluginHealthReport> {
136+
const start = Date.now();
137+
134138
const isDbReady = !!this.database;
135139
const status = isDbReady ? 'healthy' : 'unhealthy';
136140
const message = isDbReady ? 'SQLite WASM ready' : 'Database not initialized';
141+
142+
const latency = Date.now() - start;
143+
137144
return {
138145
status,
139146
timestamp: new Date().toISOString(),
140147
message,
141148
metrics: {
142149
uptime: this.startedAt ? Date.now() - this.startedAt : 0,
150+
responseTime: latency,
143151
},
144152
checks: [
145153
{ name: 'browser-database', status: isDbReady ? 'passed' : 'failed', message },
@@ -153,7 +161,20 @@ export class BrowserRuntimePlugin implements Plugin {
153161
*/
154162
getManifest(): { capabilities: PluginCapabilityManifest; security: PluginSecurityManifest } {
155163
return {
156-
capabilities: {},
164+
capabilities: {
165+
provides: [{
166+
id: 'com.objectstack.service.browser',
167+
name: 'browser',
168+
version: { major: 0, minor: 1, patch: 0 },
169+
methods: [
170+
{ name: 'getDatabase', description: 'Get browser database instance', async: false },
171+
{ name: 'getStorage', description: 'Get OPFS storage instance', async: false },
172+
{ name: 'getServiceWorker', description: 'Get service worker manager', async: false },
173+
],
174+
stability: 'experimental',
175+
}],
176+
requires: [],
177+
},
157178
security: {
158179
pluginId: 'browser',
159180
trustLevel: 'trusted',
@@ -175,6 +196,7 @@ export class BrowserRuntimePlugin implements Plugin {
175196
*/
176197
async destroy(): Promise<void> {
177198
await this.stop();
199+
this.context?.trigger('plugin.destroyed', { plugin: this.name });
178200
this.context?.logger.info('[BrowserRuntime] Destroyed');
179201
}
180202

packages/ui/src/plugin.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ export class UIPlugin implements Plugin {
5757
// ObjectQL might not be available yet; will try again in start()
5858
}
5959

60+
context.trigger('plugin.initialized', { plugin: this.name });
6061
context.logger.info('[UI] Initialized successfully');
6162
};
6263

@@ -77,6 +78,7 @@ export class UIPlugin implements Plugin {
7778
await this.registerViewObject();
7879
}
7980

81+
context.trigger('plugin.started', { plugin: this.name });
8082
context.logger.info('[UI] Started successfully');
8183
}
8284

@@ -153,6 +155,8 @@ export class UIPlugin implements Plugin {
153155
* Health check
154156
*/
155157
async healthCheck(): Promise<PluginHealthReport> {
158+
const start = Date.now();
159+
156160
let checkStatus: 'healthy' | 'degraded' | 'unhealthy' = 'healthy';
157161
let message = 'UI service operational';
158162

@@ -161,12 +165,15 @@ export class UIPlugin implements Plugin {
161165
message = 'ObjectQL service not available';
162166
}
163167

168+
const latency = Date.now() - start;
169+
164170
return {
165171
status: checkStatus,
166172
timestamp: new Date().toISOString(),
167173
message,
168174
metrics: {
169175
uptime: this.startedAt ? Date.now() - this.startedAt : 0,
176+
responseTime: latency,
170177
},
171178
checks: [
172179
{
@@ -183,7 +190,21 @@ export class UIPlugin implements Plugin {
183190
*/
184191
getManifest(): { capabilities: PluginCapabilityManifest; security: PluginSecurityManifest } {
185192
return {
186-
capabilities: {},
193+
capabilities: {
194+
provides: [{
195+
id: 'com.objectstack.service.ui',
196+
name: 'ui',
197+
version: { major: 0, minor: 1, patch: 0 },
198+
methods: [
199+
{ name: 'saveView', description: 'Save a view definition', async: true },
200+
{ name: 'loadView', description: 'Load a view definition', async: true },
201+
{ name: 'listViews', description: 'List all views', async: true },
202+
{ name: 'deleteView', description: 'Delete a view', async: true },
203+
],
204+
stability: 'stable',
205+
}],
206+
requires: [],
207+
},
187208
security: {
188209
pluginId: 'ui',
189210
trustLevel: 'trusted',
@@ -209,6 +230,7 @@ export class UIPlugin implements Plugin {
209230
*/
210231
async destroy(): Promise<void> {
211232
this.objectql = undefined;
233+
this.context?.trigger('plugin.destroyed', { plugin: this.name });
212234
this.context?.logger.info('[UI] Destroyed');
213235
}
214236

0 commit comments

Comments
 (0)