Services: restore host lifecycle facade
This commit is contained in:
parent
ef7ae4c6db
commit
499b8ad972
BIN
src/extension-host/.DS_Store
vendored
BIN
src/extension-host/.DS_Store
vendored
Binary file not shown.
@ -19,7 +19,12 @@ import { startExtensionHostServices } from "./service-lifecycle.js";
|
||||
function createRegistry(services: OpenClawPluginService[]) {
|
||||
const registry = createEmptyPluginRegistry();
|
||||
for (const service of services) {
|
||||
registry.services.push({ pluginId: "plugin:test", service, source: "test" });
|
||||
registry.services.push({
|
||||
pluginId: "plugin:test",
|
||||
service,
|
||||
source: "test",
|
||||
rootDir: "/plugins/test-plugin",
|
||||
});
|
||||
}
|
||||
return registry;
|
||||
}
|
||||
@ -116,7 +121,9 @@ describe("startExtensionHostServices", () => {
|
||||
await handle.stop();
|
||||
|
||||
expect(mockedLogger.error).toHaveBeenCalledWith(
|
||||
expect.stringContaining("plugin service failed (service-start-fail):"),
|
||||
expect.stringContaining(
|
||||
"plugin service failed (service-start-fail, plugin=plugin:test, root=/plugins/test-plugin):",
|
||||
),
|
||||
);
|
||||
expect(mockedLogger.warn).toHaveBeenCalledWith(
|
||||
expect.stringContaining("plugin service stop failed (service-stop-fail):"),
|
||||
|
||||
@ -55,7 +55,11 @@ export async function startExtensionHostServices(params: {
|
||||
stop: service.stop ? () => service.stop?.(serviceContext) : undefined,
|
||||
});
|
||||
} catch (err) {
|
||||
log.error(`plugin service failed (${service.id}): ${String(err)}`);
|
||||
const error = err as Error;
|
||||
const stack = error?.stack?.trim();
|
||||
log.error(
|
||||
`plugin service failed (${service.id}, plugin=${entry.pluginId}, root=${entry.rootDir ?? "unknown"}): ${error?.message ?? String(err)}${stack ? `\n${stack}` : ""}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,6 +1,10 @@
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import type { ExtensionHostServicesHandle } from "../extension-host/contributions/service-lifecycle.js";
|
||||
import {
|
||||
startExtensionHostServices,
|
||||
type ExtensionHostServicesHandle,
|
||||
} from "../extension-host/contributions/service-lifecycle.js";
|
||||
import type { PluginRegistry } from "./registry.js";
|
||||
|
||||
export type PluginServicesHandle = ExtensionHostServicesHandle;
|
||||
|
||||
export async function startPluginServices(params: {
|
||||
@ -8,44 +12,5 @@ export async function startPluginServices(params: {
|
||||
config: OpenClawConfig;
|
||||
workspaceDir?: string;
|
||||
}): Promise<PluginServicesHandle> {
|
||||
const running: Array<{
|
||||
id: string;
|
||||
stop?: () => void | Promise<void>;
|
||||
}> = [];
|
||||
const serviceContext = createServiceContext({
|
||||
config: params.config,
|
||||
workspaceDir: params.workspaceDir,
|
||||
});
|
||||
|
||||
for (const entry of params.registry.services) {
|
||||
const service = entry.service;
|
||||
try {
|
||||
await service.start(serviceContext);
|
||||
running.push({
|
||||
id: service.id,
|
||||
stop: service.stop ? () => service.stop?.(serviceContext) : undefined,
|
||||
});
|
||||
} catch (err) {
|
||||
const error = err as Error;
|
||||
const stack = error?.stack?.trim();
|
||||
log.error(
|
||||
`plugin service failed (${service.id}, plugin=${entry.pluginId}, root=${entry.rootDir ?? "unknown"}): ${error?.message ?? String(err)}${stack ? `\n${stack}` : ""}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
stop: async () => {
|
||||
for (const entry of running.toReversed()) {
|
||||
if (!entry.stop) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
await entry.stop();
|
||||
} catch (err) {
|
||||
log.warn(`plugin service stop failed (${entry.id}): ${String(err)}`);
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
return startExtensionHostServices(params);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user