@umimoney/clawdbot-relay-plugin 0.1.7 → 0.1.9
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/dist/clawdbot.plugin.json +1 -1
- package/dist/index.d.mts +73 -19
- package/dist/index.d.ts +73 -19
- package/dist/index.js +93 -50
- package/dist/index.mjs +92 -45
- package/package.json +1 -1
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"$schema": "https://clawdbot.dev/schemas/plugin.json",
|
|
3
3
|
"id": "umi-relay",
|
|
4
4
|
"name": "UMI Relay",
|
|
5
|
-
"version": "0.1.
|
|
5
|
+
"version": "0.1.9",
|
|
6
6
|
"description": "Connect to UMI relay server for real-time chat visibility in UMI web UI",
|
|
7
7
|
"type": "channel",
|
|
8
8
|
"main": "index.js",
|
package/dist/index.d.mts
CHANGED
|
@@ -96,25 +96,79 @@ declare class UmiRelayClient {
|
|
|
96
96
|
private scheduleReconnect;
|
|
97
97
|
private generateId;
|
|
98
98
|
}
|
|
99
|
-
interface
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
text: string;
|
|
103
|
-
metadata?: any;
|
|
99
|
+
interface ClawdbotPluginApi {
|
|
100
|
+
registerChannel: (opts: {
|
|
101
|
+
plugin: ChannelPlugin;
|
|
104
102
|
}) => void;
|
|
105
|
-
|
|
103
|
+
runtime: any;
|
|
106
104
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
105
|
+
interface AccountInfo {
|
|
106
|
+
accountId: string;
|
|
107
|
+
enabled: boolean;
|
|
108
|
+
configured: boolean;
|
|
109
|
+
}
|
|
110
|
+
interface ChannelPlugin {
|
|
111
|
+
id: string;
|
|
112
|
+
meta: {
|
|
113
|
+
id: string;
|
|
114
|
+
label: string;
|
|
115
|
+
description?: string;
|
|
116
|
+
};
|
|
117
|
+
capabilities: {
|
|
118
|
+
chatTypes: string[];
|
|
119
|
+
media: boolean;
|
|
120
|
+
};
|
|
121
|
+
configSchema: {
|
|
122
|
+
type: string;
|
|
123
|
+
properties: Record<string, any>;
|
|
124
|
+
additionalProperties: boolean;
|
|
125
|
+
};
|
|
126
|
+
config: {
|
|
127
|
+
listAccountIds: (cfg: any) => string[];
|
|
128
|
+
resolveAccount: (cfg: any, accountId: string) => AccountInfo;
|
|
129
|
+
defaultAccountId: (cfg: any) => string;
|
|
130
|
+
isConfigured: (account: AccountInfo) => boolean;
|
|
131
|
+
describeAccount: (account: AccountInfo) => AccountInfo;
|
|
132
|
+
};
|
|
133
|
+
outbound: {
|
|
134
|
+
deliveryMode: 'direct' | 'queued';
|
|
135
|
+
resolveTarget: (opts: {
|
|
136
|
+
to: string;
|
|
137
|
+
}) => {
|
|
138
|
+
ok: boolean;
|
|
139
|
+
to: string;
|
|
140
|
+
};
|
|
141
|
+
sendText: (opts: {
|
|
142
|
+
cfg: any;
|
|
143
|
+
to: string;
|
|
144
|
+
text: string;
|
|
145
|
+
}) => Promise<{
|
|
146
|
+
channel: string;
|
|
147
|
+
ok: boolean;
|
|
148
|
+
}>;
|
|
149
|
+
};
|
|
150
|
+
gateway: {
|
|
151
|
+
startAccount: (ctx: GatewayContext) => Promise<{
|
|
152
|
+
stop: () => void;
|
|
153
|
+
}>;
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
interface GatewayContext {
|
|
157
|
+
cfg: any;
|
|
158
|
+
runtime: {
|
|
159
|
+
inbound: (msg: InboundMessage) => void;
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
interface InboundMessage {
|
|
163
|
+
channel: string;
|
|
164
|
+
from: string;
|
|
165
|
+
text: string;
|
|
166
|
+
ts?: number;
|
|
167
|
+
metadata?: Record<string, any>;
|
|
168
|
+
}
|
|
169
|
+
declare const _default: {
|
|
170
|
+
id: string;
|
|
171
|
+
register(api: ClawdbotPluginApi): void;
|
|
172
|
+
};
|
|
119
173
|
|
|
120
|
-
export { type
|
|
174
|
+
export { type MessageHandler, type RelayConfig, type RelayMessage, type StateUpdate, UmiRelayClient, _default as default };
|
package/dist/index.d.ts
CHANGED
|
@@ -96,25 +96,79 @@ declare class UmiRelayClient {
|
|
|
96
96
|
private scheduleReconnect;
|
|
97
97
|
private generateId;
|
|
98
98
|
}
|
|
99
|
-
interface
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
text: string;
|
|
103
|
-
metadata?: any;
|
|
99
|
+
interface ClawdbotPluginApi {
|
|
100
|
+
registerChannel: (opts: {
|
|
101
|
+
plugin: ChannelPlugin;
|
|
104
102
|
}) => void;
|
|
105
|
-
|
|
103
|
+
runtime: any;
|
|
106
104
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
105
|
+
interface AccountInfo {
|
|
106
|
+
accountId: string;
|
|
107
|
+
enabled: boolean;
|
|
108
|
+
configured: boolean;
|
|
109
|
+
}
|
|
110
|
+
interface ChannelPlugin {
|
|
111
|
+
id: string;
|
|
112
|
+
meta: {
|
|
113
|
+
id: string;
|
|
114
|
+
label: string;
|
|
115
|
+
description?: string;
|
|
116
|
+
};
|
|
117
|
+
capabilities: {
|
|
118
|
+
chatTypes: string[];
|
|
119
|
+
media: boolean;
|
|
120
|
+
};
|
|
121
|
+
configSchema: {
|
|
122
|
+
type: string;
|
|
123
|
+
properties: Record<string, any>;
|
|
124
|
+
additionalProperties: boolean;
|
|
125
|
+
};
|
|
126
|
+
config: {
|
|
127
|
+
listAccountIds: (cfg: any) => string[];
|
|
128
|
+
resolveAccount: (cfg: any, accountId: string) => AccountInfo;
|
|
129
|
+
defaultAccountId: (cfg: any) => string;
|
|
130
|
+
isConfigured: (account: AccountInfo) => boolean;
|
|
131
|
+
describeAccount: (account: AccountInfo) => AccountInfo;
|
|
132
|
+
};
|
|
133
|
+
outbound: {
|
|
134
|
+
deliveryMode: 'direct' | 'queued';
|
|
135
|
+
resolveTarget: (opts: {
|
|
136
|
+
to: string;
|
|
137
|
+
}) => {
|
|
138
|
+
ok: boolean;
|
|
139
|
+
to: string;
|
|
140
|
+
};
|
|
141
|
+
sendText: (opts: {
|
|
142
|
+
cfg: any;
|
|
143
|
+
to: string;
|
|
144
|
+
text: string;
|
|
145
|
+
}) => Promise<{
|
|
146
|
+
channel: string;
|
|
147
|
+
ok: boolean;
|
|
148
|
+
}>;
|
|
149
|
+
};
|
|
150
|
+
gateway: {
|
|
151
|
+
startAccount: (ctx: GatewayContext) => Promise<{
|
|
152
|
+
stop: () => void;
|
|
153
|
+
}>;
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
interface GatewayContext {
|
|
157
|
+
cfg: any;
|
|
158
|
+
runtime: {
|
|
159
|
+
inbound: (msg: InboundMessage) => void;
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
interface InboundMessage {
|
|
163
|
+
channel: string;
|
|
164
|
+
from: string;
|
|
165
|
+
text: string;
|
|
166
|
+
ts?: number;
|
|
167
|
+
metadata?: Record<string, any>;
|
|
168
|
+
}
|
|
169
|
+
declare const _default: {
|
|
170
|
+
id: string;
|
|
171
|
+
register(api: ClawdbotPluginApi): void;
|
|
172
|
+
};
|
|
119
173
|
|
|
120
|
-
export { type
|
|
174
|
+
export { type MessageHandler, type RelayConfig, type RelayMessage, type StateUpdate, UmiRelayClient, _default as default };
|
package/dist/index.js
CHANGED
|
@@ -31,10 +31,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
33
|
UmiRelayClient: () => UmiRelayClient,
|
|
34
|
-
|
|
35
|
-
deactivate: () => deactivate,
|
|
36
|
-
id: () => id,
|
|
37
|
-
register: () => register
|
|
34
|
+
default: () => index_default
|
|
38
35
|
});
|
|
39
36
|
module.exports = __toCommonJS(index_exports);
|
|
40
37
|
var import_ws = __toESM(require("ws"));
|
|
@@ -274,56 +271,102 @@ var UmiRelayClient = class {
|
|
|
274
271
|
}
|
|
275
272
|
};
|
|
276
273
|
var relayClient = null;
|
|
277
|
-
var
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
274
|
+
var umiRelayChannel = {
|
|
275
|
+
id: "umi-relay",
|
|
276
|
+
meta: {
|
|
277
|
+
id: "umi-relay",
|
|
278
|
+
label: "UMI Relay",
|
|
279
|
+
description: "Connect to UMI relay server for real-time chat"
|
|
280
|
+
},
|
|
281
|
+
capabilities: {
|
|
282
|
+
chatTypes: ["direct"],
|
|
283
|
+
media: false
|
|
284
|
+
},
|
|
285
|
+
configSchema: {
|
|
286
|
+
type: "object",
|
|
287
|
+
properties: {},
|
|
288
|
+
additionalProperties: false
|
|
289
|
+
},
|
|
290
|
+
config: {
|
|
291
|
+
listAccountIds: () => ["default"],
|
|
292
|
+
resolveAccount: (cfg, accountId) => ({
|
|
293
|
+
accountId: accountId || "default",
|
|
294
|
+
enabled: true,
|
|
295
|
+
configured: true
|
|
296
|
+
}),
|
|
297
|
+
defaultAccountId: () => "default",
|
|
298
|
+
isConfigured: () => true,
|
|
299
|
+
describeAccount: (account) => ({
|
|
300
|
+
accountId: account.accountId,
|
|
301
|
+
enabled: account.enabled,
|
|
302
|
+
configured: account.configured
|
|
303
|
+
})
|
|
304
|
+
},
|
|
305
|
+
outbound: {
|
|
306
|
+
deliveryMode: "direct",
|
|
307
|
+
resolveTarget: ({ to }) => ({ ok: true, to }),
|
|
308
|
+
sendText: async ({ cfg, to, text }) => {
|
|
309
|
+
if (relayClient?.isConnected) {
|
|
310
|
+
relayClient.sendMessage(text, { to });
|
|
311
|
+
return { channel: "umi-relay", ok: true };
|
|
312
|
+
}
|
|
313
|
+
return { channel: "umi-relay", ok: false };
|
|
314
|
+
}
|
|
315
|
+
},
|
|
316
|
+
gateway: {
|
|
317
|
+
startAccount: async (ctx) => {
|
|
318
|
+
const config = {
|
|
319
|
+
apiKey: ctx.cfg?.apiKey || process.env.UMI_API_KEY || "",
|
|
320
|
+
relayUrl: ctx.cfg?.relayUrl || "wss://ws.umi.app/ws/relay",
|
|
321
|
+
agentVersion: ctx.cfg?.agentVersion || "1.0.0",
|
|
322
|
+
capabilities: ctx.cfg?.capabilities || ["chat"],
|
|
323
|
+
autoReconnect: ctx.cfg?.autoReconnect ?? true
|
|
324
|
+
};
|
|
325
|
+
if (!config.apiKey) {
|
|
326
|
+
console.error("[UmiRelay] No API key provided. Set UMI_API_KEY or pass apiKey in config.");
|
|
327
|
+
return { stop: () => {
|
|
328
|
+
} };
|
|
329
|
+
}
|
|
330
|
+
relayClient = new UmiRelayClient(config);
|
|
331
|
+
relayClient.onMessage((message) => {
|
|
332
|
+
if (message.type === "platform:message") {
|
|
333
|
+
ctx.runtime.inbound({
|
|
334
|
+
channel: "umi-relay",
|
|
335
|
+
from: message.userId || "unknown",
|
|
336
|
+
text: message.content,
|
|
337
|
+
ts: message.timestamp,
|
|
338
|
+
metadata: {
|
|
339
|
+
userId: message.userId,
|
|
340
|
+
agentId: message.agentId
|
|
341
|
+
}
|
|
342
|
+
});
|
|
299
343
|
}
|
|
300
344
|
});
|
|
345
|
+
try {
|
|
346
|
+
await relayClient.connect();
|
|
347
|
+
console.log("[UmiRelay] Connected to relay");
|
|
348
|
+
} catch (error) {
|
|
349
|
+
console.error("[UmiRelay] Failed to connect:", error);
|
|
350
|
+
}
|
|
351
|
+
return {
|
|
352
|
+
stop: () => {
|
|
353
|
+
if (relayClient) {
|
|
354
|
+
relayClient.disconnect();
|
|
355
|
+
relayClient = null;
|
|
356
|
+
}
|
|
357
|
+
console.log("[UmiRelay] Disconnected");
|
|
358
|
+
}
|
|
359
|
+
};
|
|
301
360
|
}
|
|
302
|
-
});
|
|
303
|
-
ctx.registerSend("umi", (response) => {
|
|
304
|
-
if (relayClient?.isConnected) {
|
|
305
|
-
relayClient.sendMessage(response.text || response.content, response.metadata);
|
|
306
|
-
}
|
|
307
|
-
});
|
|
308
|
-
relayClient.connect().then(() => {
|
|
309
|
-
console.log("[UmiRelay] Plugin activated and connected");
|
|
310
|
-
}).catch((error) => {
|
|
311
|
-
console.error("[UmiRelay] Failed to connect:", error);
|
|
312
|
-
});
|
|
313
|
-
}
|
|
314
|
-
function deactivate() {
|
|
315
|
-
if (relayClient) {
|
|
316
|
-
relayClient.disconnect();
|
|
317
|
-
relayClient = null;
|
|
318
361
|
}
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
362
|
+
};
|
|
363
|
+
var index_default = {
|
|
364
|
+
id: "umi-relay",
|
|
365
|
+
register(api) {
|
|
366
|
+
api.registerChannel({ plugin: umiRelayChannel });
|
|
367
|
+
}
|
|
368
|
+
};
|
|
322
369
|
// Annotate the CommonJS export names for ESM import in node:
|
|
323
370
|
0 && (module.exports = {
|
|
324
|
-
UmiRelayClient
|
|
325
|
-
activate,
|
|
326
|
-
deactivate,
|
|
327
|
-
id,
|
|
328
|
-
register
|
|
371
|
+
UmiRelayClient
|
|
329
372
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -236,55 +236,102 @@ var UmiRelayClient = class {
|
|
|
236
236
|
}
|
|
237
237
|
};
|
|
238
238
|
var relayClient = null;
|
|
239
|
-
var
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
239
|
+
var umiRelayChannel = {
|
|
240
|
+
id: "umi-relay",
|
|
241
|
+
meta: {
|
|
242
|
+
id: "umi-relay",
|
|
243
|
+
label: "UMI Relay",
|
|
244
|
+
description: "Connect to UMI relay server for real-time chat"
|
|
245
|
+
},
|
|
246
|
+
capabilities: {
|
|
247
|
+
chatTypes: ["direct"],
|
|
248
|
+
media: false
|
|
249
|
+
},
|
|
250
|
+
configSchema: {
|
|
251
|
+
type: "object",
|
|
252
|
+
properties: {},
|
|
253
|
+
additionalProperties: false
|
|
254
|
+
},
|
|
255
|
+
config: {
|
|
256
|
+
listAccountIds: () => ["default"],
|
|
257
|
+
resolveAccount: (cfg, accountId) => ({
|
|
258
|
+
accountId: accountId || "default",
|
|
259
|
+
enabled: true,
|
|
260
|
+
configured: true
|
|
261
|
+
}),
|
|
262
|
+
defaultAccountId: () => "default",
|
|
263
|
+
isConfigured: () => true,
|
|
264
|
+
describeAccount: (account) => ({
|
|
265
|
+
accountId: account.accountId,
|
|
266
|
+
enabled: account.enabled,
|
|
267
|
+
configured: account.configured
|
|
268
|
+
})
|
|
269
|
+
},
|
|
270
|
+
outbound: {
|
|
271
|
+
deliveryMode: "direct",
|
|
272
|
+
resolveTarget: ({ to }) => ({ ok: true, to }),
|
|
273
|
+
sendText: async ({ cfg, to, text }) => {
|
|
274
|
+
if (relayClient?.isConnected) {
|
|
275
|
+
relayClient.sendMessage(text, { to });
|
|
276
|
+
return { channel: "umi-relay", ok: true };
|
|
277
|
+
}
|
|
278
|
+
return { channel: "umi-relay", ok: false };
|
|
279
|
+
}
|
|
280
|
+
},
|
|
281
|
+
gateway: {
|
|
282
|
+
startAccount: async (ctx) => {
|
|
283
|
+
const config = {
|
|
284
|
+
apiKey: ctx.cfg?.apiKey || process.env.UMI_API_KEY || "",
|
|
285
|
+
relayUrl: ctx.cfg?.relayUrl || "wss://ws.umi.app/ws/relay",
|
|
286
|
+
agentVersion: ctx.cfg?.agentVersion || "1.0.0",
|
|
287
|
+
capabilities: ctx.cfg?.capabilities || ["chat"],
|
|
288
|
+
autoReconnect: ctx.cfg?.autoReconnect ?? true
|
|
289
|
+
};
|
|
290
|
+
if (!config.apiKey) {
|
|
291
|
+
console.error("[UmiRelay] No API key provided. Set UMI_API_KEY or pass apiKey in config.");
|
|
292
|
+
return { stop: () => {
|
|
293
|
+
} };
|
|
294
|
+
}
|
|
295
|
+
relayClient = new UmiRelayClient(config);
|
|
296
|
+
relayClient.onMessage((message) => {
|
|
297
|
+
if (message.type === "platform:message") {
|
|
298
|
+
ctx.runtime.inbound({
|
|
299
|
+
channel: "umi-relay",
|
|
300
|
+
from: message.userId || "unknown",
|
|
301
|
+
text: message.content,
|
|
302
|
+
ts: message.timestamp,
|
|
303
|
+
metadata: {
|
|
304
|
+
userId: message.userId,
|
|
305
|
+
agentId: message.agentId
|
|
306
|
+
}
|
|
307
|
+
});
|
|
261
308
|
}
|
|
262
309
|
});
|
|
310
|
+
try {
|
|
311
|
+
await relayClient.connect();
|
|
312
|
+
console.log("[UmiRelay] Connected to relay");
|
|
313
|
+
} catch (error) {
|
|
314
|
+
console.error("[UmiRelay] Failed to connect:", error);
|
|
315
|
+
}
|
|
316
|
+
return {
|
|
317
|
+
stop: () => {
|
|
318
|
+
if (relayClient) {
|
|
319
|
+
relayClient.disconnect();
|
|
320
|
+
relayClient = null;
|
|
321
|
+
}
|
|
322
|
+
console.log("[UmiRelay] Disconnected");
|
|
323
|
+
}
|
|
324
|
+
};
|
|
263
325
|
}
|
|
264
|
-
});
|
|
265
|
-
ctx.registerSend("umi", (response) => {
|
|
266
|
-
if (relayClient?.isConnected) {
|
|
267
|
-
relayClient.sendMessage(response.text || response.content, response.metadata);
|
|
268
|
-
}
|
|
269
|
-
});
|
|
270
|
-
relayClient.connect().then(() => {
|
|
271
|
-
console.log("[UmiRelay] Plugin activated and connected");
|
|
272
|
-
}).catch((error) => {
|
|
273
|
-
console.error("[UmiRelay] Failed to connect:", error);
|
|
274
|
-
});
|
|
275
|
-
}
|
|
276
|
-
function deactivate() {
|
|
277
|
-
if (relayClient) {
|
|
278
|
-
relayClient.disconnect();
|
|
279
|
-
relayClient = null;
|
|
280
326
|
}
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
327
|
+
};
|
|
328
|
+
var index_default = {
|
|
329
|
+
id: "umi-relay",
|
|
330
|
+
register(api) {
|
|
331
|
+
api.registerChannel({ plugin: umiRelayChannel });
|
|
332
|
+
}
|
|
333
|
+
};
|
|
284
334
|
export {
|
|
285
335
|
UmiRelayClient,
|
|
286
|
-
|
|
287
|
-
deactivate,
|
|
288
|
-
id,
|
|
289
|
-
register
|
|
336
|
+
index_default as default
|
|
290
337
|
};
|