feat: loadable openclaw channel plugin v1 (agent=account)

Rewritten against the real openclaw v2026.5.7 plugin SDK (generic
third-party channel path): createChannelPluginBase + createChatChannelPlugin
with required capabilities, minimal ChannelSetupAdapter, agent=account
config resolution, attached outbound -> Fabric POST, inbound socket per
account -> runtime.channel.turn (wakeup->admission). Compat notes mark
SDK-coupled seams for future openclaw upgrades. Verified: builds clean,
installs, 'openclaw channels list' -> Fabric installed/configured/enabled.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
h z
2026-05-15 17:54:32 +01:00
parent 7fed6d07f6
commit ece77ff2c7
8 changed files with 412 additions and 159 deletions

68
dist/fabric/index.js vendored
View File

@@ -1,40 +1,62 @@
import path from 'node:path';
import os from 'node:os';
import { defineChannelPluginEntry } from 'openclaw/plugin-sdk/channel-core';
// Fabric channel plugin entry.
// COMPAT NOTE (openclaw v2026.5.7): defineChannelPluginEntry signature
// { id, name, description, plugin, setRuntime?, registerFull? }. setRuntime
// receives the PluginRuntime (has channel.turn kernel); registerFull receives
// the OpenClawPluginApi for runtime startup (transport + tools).
import { defineChannelPluginEntry } from 'openclaw/plugin-sdk/core';
import { fabricChannelPlugin } from './src/channel.js';
import { FabricInbound } from './src/inbound.js';
import { listEnabledFabricAccounts } from './src/accounts.js';
import { registerFabricTools } from './src/tools.js';
import { FabricClient } from './src/fabric-client.js';
import { IdentityRegistry } from './src/identity.js';
import { FabricInbound } from './src/inbound.js';
import { buildFabricChannelPlugin } from './src/channel.js';
import { registerFabricTools } from './src/tools.js';
function centerApiBase(api) {
const section = api.config?.channels?.['fabric'];
return section?.centerApiBase ?? 'http://localhost:7001/api';
}
import path from 'node:path';
import os from 'node:os';
let runtimeRef = null;
let inbound = null;
export { fabricChannelPlugin } from './src/channel.js';
export default defineChannelPluginEntry({
id: 'fabric',
name: 'Fabric',
description: 'Fabric channel plugin — OpenClaw agents speak in Fabric guilds',
// Channel object: config/security/outbound. Visible turn replies flow
// through the inbound channel-turn delivery adapter; outbound.sendText
// covers proactive sends via the shared message tool.
plugin: buildFabricChannelPlugin(async () => ({ messageId: undefined })),
// registerFull: runtime pieces (transport, tools). Guarded so the long-lived
// Fabric connections start once per gateway process.
registerFull(api) {
const cfg = (api.pluginConfig ?? {});
const identityFilePath = cfg.identityFilePath ?? path.join(os.homedir(), '.openclaw', 'fabric-identity.json');
const client = new FabricClient(centerApiBase(api));
const identity = new IdentityRegistry(identityFilePath);
plugin: fabricChannelPlugin,
setRuntime(runtime) {
runtimeRef = runtime;
},
registerFull(apiRaw) {
// COMPAT: access the subset we use through a loose view so SDK type
// drift in unrelated api members doesn't break the build.
const api = apiRaw;
const cfg = (api.config ?? {});
const centerApiBase = cfg.channels?.fabric?.centerApiBase ?? 'http://localhost:7001/api';
const idFile = api.pluginConfig?.identityFilePath ??
path.join(os.homedir(), '.openclaw', 'fabric-identity.json');
// tools operate against a default Center; per-account keys come from config
const client = new FabricClient(centerApiBase);
const identity = new IdentityRegistry(idFile);
registerFabricTools({ registerTool: (d) => api.registerTool(d), logger: api.logger }, client, identity);
api.on('gateway_start', () => {
const _G = globalThis;
if (_G._fabricInboundStarted)
return;
_G._fabricInboundStarted = true;
inbound = new FabricInbound(api.runtime, client, identity, api.logger);
const accounts = listEnabledFabricAccounts(cfg).map((a) => ({
agentId: a.accountId,
fabricApiKey: a.fabricApiKey,
}));
// also include any tool-registered identities
for (const e of identity.list()) {
if (!accounts.some((x) => x.agentId === e.agentId)) {
accounts.push({ agentId: e.agentId, fabricApiKey: e.fabricApiKey });
}
}
if (!runtimeRef) {
api.logger.warn('fabric: runtime not set; inbound disabled');
return;
}
inbound = new FabricInbound(runtimeRef, client, identity, api.logger, accounts);
void inbound.start();
api.logger.info('fabric: inbound transport started');
api.logger.info(`fabric: inbound started for ${accounts.length} account(s)`);
});
api.on('gateway_stop', () => {
inbound?.stop();