aicq-chat-plugin 2.6.5 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/extension.js DELETED
@@ -1,204 +0,0 @@
1
- /**
2
- * AICQ Chat Plugin — OpenClaw Extension Entry Point
3
- *
4
- * This is the lightweight entry point loaded by `openclaw plugins install`.
5
- * It does NOT require native dependencies (better-sqlite3) which need C++ compilation.
6
- *
7
- * The actual chat server runs as a **sidecar** process (node index.js) on port 6109.
8
- * This extension registers the plugin and proxies tool calls to the sidecar.
9
- *
10
- * OpenClaw expects `register()` and `activate()` exports from extension modules.
11
- *
12
- * NOTE: This file intentionally avoids process.env access to pass OpenClaw's
13
- * security scanner (which flags env access + network send as a dangerous pattern).
14
- * Configuration comes from OpenClaw's config system via activate(config).
15
- */
16
- const http = require('http');
17
- const path = require('path');
18
-
19
- // Default port — can be overridden via activate(config)
20
- const DEFAULT_SIDECAR_PORT = 6109;
21
- const SIDECAR_HOST = '127.0.0.1';
22
-
23
- // Active port — set by activate() or falls back to default
24
- let sidecarPort = DEFAULT_SIDECAR_PORT;
25
-
26
- // ── Helper: proxy a gateway call to the sidecar ──────────────────────
27
- function proxyToSidecar(method, kwargs) {
28
- return new Promise((resolve, _reject) => {
29
- const postData = JSON.stringify({ method, kwargs });
30
- const req = http.request(
31
- {
32
- hostname: SIDECAR_HOST,
33
- port: sidecarPort,
34
- path: '/api/gateway',
35
- method: 'POST',
36
- headers: {
37
- 'Content-Type': 'application/json',
38
- 'Content-Length': Buffer.byteLength(postData),
39
- },
40
- timeout: 15000,
41
- },
42
- (res) => {
43
- let body = '';
44
- res.on('data', (chunk) => { body += chunk; });
45
- res.on('end', () => {
46
- try {
47
- resolve(JSON.parse(body));
48
- } catch (e) {
49
- resolve({ error: `Sidecar returned non-JSON: ${body.substring(0, 200)}` });
50
- }
51
- });
52
- }
53
- );
54
- req.on('error', (e) => {
55
- resolve({ error: `Sidecar not reachable: ${e.message}. Is the AICQ sidecar running on port ${sidecarPort}?` });
56
- });
57
- req.on('timeout', () => {
58
- req.destroy();
59
- resolve({ error: 'Sidecar request timed out' });
60
- });
61
- req.write(postData);
62
- req.end();
63
- });
64
- }
65
-
66
- // ── Tool handler: dispatch tool calls to sidecar ─────────────────────
67
- async function handleTool(toolName, params) {
68
- switch (toolName) {
69
- case 'chat-friend': {
70
- const { action, friend_code, friend_id } = params || {};
71
- switch (action) {
72
- case 'list':
73
- return proxyToSidecar('aicq.friends.list', {});
74
- case 'add':
75
- return proxyToSidecar('aicq.friends.add', { temp_number: friend_code });
76
- case 'remove':
77
- return proxyToSidecar('aicq.friends.remove', { friend_id });
78
- case 'requests':
79
- return proxyToSidecar('aicq.friends.requests', {});
80
- case 'accept':
81
- return proxyToSidecar('aicq.friends.acceptRequest', { request_id: friend_id });
82
- case 'reject':
83
- return proxyToSidecar('aicq.friends.rejectRequest', { request_id: friend_id });
84
- default:
85
- return { error: `Unknown friend action: ${action}` };
86
- }
87
- }
88
- case 'chat-send':
89
- return proxyToSidecar('aicq.chat.send', {
90
- targetId: (params || {}).targetId,
91
- content: (params || {}).content,
92
- isGroup: (params || {}).isGroup || false,
93
- });
94
- case 'chat-export-key':
95
- return proxyToSidecar('aicq.identity.info', {});
96
- default:
97
- return { error: `Unknown tool: ${toolName}` };
98
- }
99
- }
100
-
101
- // ── Gateway handler: proxy any gateway method to sidecar ─────────────
102
- async function handleGateway(method, kwargs) {
103
- return proxyToSidecar(method, kwargs || {});
104
- }
105
-
106
- // ── register() — called by OpenClaw when the plugin is discovered ────
107
- // Returns the plugin manifest (tools, sidecar config, etc.)
108
- function register() {
109
- return {
110
- id: 'aicq-chat',
111
- name: 'AICQ Encrypted Chat',
112
- version: '2.6.0',
113
- description: 'End-to-end encrypted chat plugin for OpenClaw agents',
114
-
115
- // Sidecar configuration — OpenClaw starts this process automatically
116
- sidecar: {
117
- command: 'node',
118
- args: [path.join(__dirname, 'index.js')],
119
- port: DEFAULT_SIDECAR_PORT,
120
- },
121
-
122
- // Tool definitions for OpenClaw agent use
123
- tools: {
124
- 'chat-friend': {
125
- description: 'Manage AICQ friends — list, add by friend code, remove, view requests, accept/reject requests',
126
- parameters: {
127
- type: 'object',
128
- properties: {
129
- action: {
130
- type: 'string',
131
- enum: ['list', 'add', 'remove', 'requests', 'accept', 'reject'],
132
- description: 'The friend management action to perform',
133
- },
134
- friend_code: {
135
- type: 'string',
136
- description: 'Friend code or temp number for adding a friend',
137
- },
138
- friend_id: {
139
- type: 'string',
140
- description: 'Friend ID for remove/accept/reject actions',
141
- },
142
- },
143
- required: ['action'],
144
- },
145
- },
146
- 'chat-send': {
147
- description: 'Send an encrypted message to a friend or group via AICQ',
148
- parameters: {
149
- type: 'object',
150
- properties: {
151
- targetId: {
152
- type: 'string',
153
- description: 'The friend ID or group ID to send the message to',
154
- },
155
- content: {
156
- type: 'string',
157
- description: 'The message content to send',
158
- },
159
- isGroup: {
160
- type: 'boolean',
161
- description: 'Whether the target is a group (default: false)',
162
- },
163
- },
164
- required: ['targetId', 'content'],
165
- },
166
- },
167
- 'chat-export-key': {
168
- description: 'Export your AICQ identity public key and fingerprint for sharing',
169
- parameters: {
170
- type: 'object',
171
- properties: {
172
- format: {
173
- type: 'string',
174
- enum: ['json', 'qr'],
175
- description: 'Output format: json for key data, qr for QR code image (default: json)',
176
- },
177
- },
178
- },
179
- },
180
- },
181
- };
182
- }
183
-
184
- // ── activate() — called by OpenClaw when the plugin is enabled ───────
185
- // Receives config from openclaw.json and returns handlers.
186
- // Port can be configured via the "port" field in configSchema.
187
- function activate(config) {
188
- // Read port from OpenClaw config (defined in configSchema)
189
- if (config && config.port) {
190
- sidecarPort = config.port;
191
- }
192
- return {
193
- handleTool,
194
- handleGateway,
195
- };
196
- }
197
-
198
- // ── Exports ──────────────────────────────────────────────────────────
199
- module.exports = {
200
- register,
201
- activate,
202
- handleTool,
203
- handleGateway,
204
- };