mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-17 04:50:51 +00:00
* Plugins: add inbound claim and Telegram interaction seams * Plugins: add Discord interaction surface * Chore: fix formatting after plugin rebase * fix(hooks): preserve observers after inbound claim * test(hooks): cover claimed inbound observer delivery * fix(plugins): harden typing lease refreshes * fix(discord): pass real auth to plugin interactions * fix(plugins): remove raw session binding runtime exposure * fix(plugins): tighten interactive callback handling * Plugins: gate conversation binding with approvals * Plugins: migrate legacy plugin binding records * Plugins/phone-control: update test command context * Plugins: migrate legacy binding ids * Plugins: migrate legacy codex session bindings * Discord: fix plugin interaction handling * Discord: support direct plugin conversation binds * Plugins: preserve Discord command bind targets * Tests: fix plugin binding and interactive fallout * Discord: stabilize directory lookup tests * Discord: route bound DMs to plugins * Discord: restore plugin bindings after restart * Telegram: persist detached plugin bindings * Plugins: limit binding APIs to Telegram and Discord * Plugins: harden bound conversation routing * Plugins: fix extension target imports * Plugins: fix Telegram runtime extension imports * Plugins: format rebased binding handlers * Discord: bind group DM interactions by channel --------- Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
80 lines
2.1 KiB
TypeScript
80 lines
2.1 KiB
TypeScript
import type { OpenClawConfig } from "../config/config.js";
|
|
import { STATE_DIR } from "../config/paths.js";
|
|
import { createSubsystemLogger } from "../logging/subsystem.js";
|
|
import type { PluginRegistry } from "./registry.js";
|
|
import type { OpenClawPluginServiceContext, PluginLogger } from "./types.js";
|
|
|
|
const log = createSubsystemLogger("plugins");
|
|
|
|
function createPluginLogger(): PluginLogger {
|
|
return {
|
|
info: (msg) => log.info(msg),
|
|
warn: (msg) => log.warn(msg),
|
|
error: (msg) => log.error(msg),
|
|
debug: (msg) => log.debug(msg),
|
|
};
|
|
}
|
|
|
|
function createServiceContext(params: {
|
|
config: OpenClawConfig;
|
|
workspaceDir?: string;
|
|
}): OpenClawPluginServiceContext {
|
|
return {
|
|
config: params.config,
|
|
workspaceDir: params.workspaceDir,
|
|
stateDir: STATE_DIR,
|
|
logger: createPluginLogger(),
|
|
};
|
|
}
|
|
|
|
export type PluginServicesHandle = {
|
|
stop: () => Promise<void>;
|
|
};
|
|
|
|
export async function startPluginServices(params: {
|
|
registry: PluginRegistry;
|
|
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)}`);
|
|
}
|
|
}
|
|
},
|
|
};
|
|
}
|