feat(oc-plugin): add MACP ACP runtime backend
This commit is contained in:
73
plugins/macp/src/index.ts
Normal file
73
plugins/macp/src/index.ts
Normal file
@@ -0,0 +1,73 @@
|
||||
import path from 'node:path';
|
||||
|
||||
import {
|
||||
registerAcpRuntimeBackend,
|
||||
unregisterAcpRuntimeBackend,
|
||||
} from '/home/jarvis/.npm-global/lib/node_modules/openclaw/dist/plugin-sdk/acp-runtime.js';
|
||||
import type { OpenClawPluginApi } from '/home/jarvis/.npm-global/lib/node_modules/openclaw/dist/plugin-sdk/index.js';
|
||||
import type {
|
||||
OpenClawPluginService,
|
||||
OpenClawPluginServiceContext,
|
||||
} from '/home/jarvis/.npm-global/lib/node_modules/openclaw/dist/plugin-sdk/src/plugins/types.js';
|
||||
|
||||
import { MacpRuntime } from './macp-runtime.js';
|
||||
|
||||
type PluginConfig = {
|
||||
defaultModel?: string;
|
||||
systemPrompt?: string;
|
||||
timeoutMs?: number;
|
||||
logDir?: string;
|
||||
};
|
||||
|
||||
function resolveConfig(pluginConfig?: Record<string, unknown>, stateDir?: string) {
|
||||
const config = (pluginConfig ?? {}) as PluginConfig;
|
||||
return {
|
||||
defaultModel: config.defaultModel?.trim() || 'openai/gpt-5-mini',
|
||||
systemPrompt: config.systemPrompt ?? '',
|
||||
timeoutMs:
|
||||
typeof config.timeoutMs === 'number' &&
|
||||
Number.isFinite(config.timeoutMs) &&
|
||||
config.timeoutMs > 0
|
||||
? config.timeoutMs
|
||||
: 300_000,
|
||||
stateDir: config.logDir?.trim() ? path.resolve(config.logDir) : (stateDir ?? process.cwd()),
|
||||
};
|
||||
}
|
||||
|
||||
function createMacpRuntimeService(pluginConfig?: Record<string, unknown>): OpenClawPluginService {
|
||||
let runtime: MacpRuntime | null = null;
|
||||
|
||||
return {
|
||||
id: 'macp-runtime',
|
||||
async start(ctx: OpenClawPluginServiceContext) {
|
||||
const resolved = resolveConfig(pluginConfig, ctx.stateDir);
|
||||
runtime = new MacpRuntime({
|
||||
...resolved,
|
||||
logger: ctx.logger,
|
||||
});
|
||||
registerAcpRuntimeBackend({
|
||||
id: 'macp',
|
||||
runtime,
|
||||
healthy: () => runtime !== null,
|
||||
});
|
||||
ctx.logger.info(
|
||||
`macp runtime backend registered (defaultModel: ${resolved.defaultModel}, timeoutMs: ${resolved.timeoutMs})`,
|
||||
);
|
||||
},
|
||||
async stop(_ctx: OpenClawPluginServiceContext) {
|
||||
unregisterAcpRuntimeBackend('macp');
|
||||
runtime = null;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
const plugin = {
|
||||
id: 'macp',
|
||||
name: 'MACP Runtime',
|
||||
description: 'ACP runtime backend that dispatches Pi oneshot sessions through MACP.',
|
||||
register(api: OpenClawPluginApi) {
|
||||
api.registerService(createMacpRuntimeService(api.pluginConfig));
|
||||
},
|
||||
};
|
||||
|
||||
export default plugin;
|
||||
Reference in New Issue
Block a user