refactor: rename openclaw -> clawhubadapter, add ClawHub search/install, fix agent interrupt

- Rename internal/plugins/openclaw/ -> internal/plugins/clawhubadapter/
- Add RegistryDispatcher with 5 sub-registries (Tool, Provider, Channel, Stage, Cap)
- Add clawhubadapter_search tool for ClawHub marketplace search
- Add clawhub: prefix support for installing from ClawHub (ZIP/tgz auto-detect)
- Add CallProvider RPC and provider/call routing
- Fix QQ interrupt: check interceptCh before/after each tool execution
This commit is contained in:
2026-07-21 22:47:14 +08:00
parent 906d117bdd
commit 76a4619ed5
15 changed files with 758 additions and 186 deletions

View File

@ -0,0 +1,106 @@
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
terminal: false
});
const tools = [
{
name: 'echo',
description: 'Echo back the input text',
inputSchema: {
type: 'object',
properties: {
text: { type: 'string', description: 'Text to echo' }
},
required: ['text']
}
},
{
name: 'add',
description: 'Add two numbers',
inputSchema: {
type: 'object',
properties: {
a: { type: 'number', description: 'First number' },
b: { type: 'number', description: 'Second number' }
},
required: ['a', 'b']
}
},
{
name: 'ping',
description: 'Health check',
inputSchema: {
type: 'object',
properties: {}
}
}
];
rl.on('line', (line) => {
let req;
try {
req = JSON.parse(line);
} catch (e) {
sendError(null, -32700, 'Parse error');
return;
}
const id = req.id;
const method = req.method;
if (method === 'ping') {
sendResult(id, { status: 'ok' });
return;
}
if (method === 'tools/list') {
sendResult(id, { tools });
return;
}
if (method === 'tools/call') {
const params = req.params || {};
const toolName = params.name;
const args = params.arguments || {};
const tool = tools.find(t => t.name === toolName);
if (!tool) {
sendError(id, -32601, `Tool not found: ${toolName}`);
return;
}
let result;
switch (toolName) {
case 'echo':
result = { content: [{ type: 'text', text: `Echo: ${args.text || ''}` }] };
break;
case 'add':
const sum = (Number(args.a) || 0) + (Number(args.b) || 0);
result = { content: [{ type: 'text', text: `${sum}` }] };
break;
default:
sendError(id, -32601, `Not implemented: ${toolName}`);
return;
}
sendResult(id, result);
return;
}
sendError(id, -32601, `Method not found: ${method}`);
});
function sendResult(id, result) {
const resp = { jsonrpc: '2.0', id, result };
process.stdout.write(JSON.stringify(resp) + '\n');
}
function sendError(id, code, message) {
const resp = { jsonrpc: '2.0', id, error: { code, message } };
process.stdout.write(JSON.stringify(resp) + '\n');
}
// Sidecar is ready - no startup message needed

View File

@ -0,0 +1,33 @@
module.exports = {
default: {
id: 'oc-pkg',
name: 'OC Package',
version: '2.0.0',
description: 'Test plugin discovered via package.json extensions',
register(api) {
api.registerTool({
name: 'add',
description: 'Add two numbers',
parameters: {
type: 'object',
properties: {
a: { type: 'number', description: 'First number' },
b: { type: 'number', description: 'Second number' },
},
required: ['a', 'b'],
},
execute(id, params) {
return String(params.a + params.b);
},
});
api.registerTool({
name: 'info',
description: 'Return plugin info',
execute(id, params) {
return JSON.stringify({ id: this.id, name: this.name, version: this.version });
},
});
},
},
};

View File

@ -0,0 +1,8 @@
{
"name": "oc-pkg",
"version": "2.0.0",
"description": "OC plugin with package.json entry discovery",
"openclaw": {
"extensions": ["lib/entry.js"]
}
}

View File

@ -0,0 +1,31 @@
module.exports = {
default: {
id: 'oc-simple',
name: 'OC Simple',
version: '1.0.0',
description: 'Simple test plugin for OpenClaw simulator',
register(api) {
api.registerTool({
name: 'greet',
description: 'Greet someone',
parameters: {
type: 'object',
properties: {
name: { type: 'string', description: 'Name to greet' },
},
required: ['name'],
},
execute(id, params) {
return `Hello, ${params.name}!`;
},
});
api.registerTool({
name: 'ping',
description: 'Health check ping',
execute(id, params) {
return 'pong';
},
});
},
},
};

View File

@ -0,0 +1,6 @@
{
"name": "oc-simple",
"version": "1.0.0",
"entry": "index.js",
"description": "Simple OpenClaw test plugin"
}