@umimoney/clawdbot-relay-plugin 0.1.6 → 0.1.8
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 +56 -16
- package/dist/index.d.ts +56 -16
- package/dist/index.js +73 -33
- package/dist/index.mjs +72 -29
- 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.8",
|
|
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,22 +96,62 @@ 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
|
-
|
|
105
|
+
interface ChannelPlugin {
|
|
106
|
+
id: string;
|
|
107
|
+
meta: {
|
|
108
|
+
id: string;
|
|
109
|
+
label: string;
|
|
110
|
+
description?: string;
|
|
111
|
+
};
|
|
112
|
+
capabilities: {
|
|
113
|
+
chatTypes: string[];
|
|
114
|
+
media: boolean;
|
|
115
|
+
};
|
|
116
|
+
outbound: {
|
|
117
|
+
deliveryMode: 'direct' | 'queued';
|
|
118
|
+
resolveTarget: (opts: {
|
|
119
|
+
to: string;
|
|
120
|
+
}) => {
|
|
121
|
+
ok: boolean;
|
|
122
|
+
to: string;
|
|
123
|
+
};
|
|
124
|
+
sendText: (opts: {
|
|
125
|
+
cfg: any;
|
|
126
|
+
to: string;
|
|
127
|
+
text: string;
|
|
128
|
+
}) => Promise<{
|
|
129
|
+
channel: string;
|
|
130
|
+
ok: boolean;
|
|
131
|
+
}>;
|
|
132
|
+
};
|
|
133
|
+
gateway: {
|
|
134
|
+
startAccount: (ctx: GatewayContext) => Promise<{
|
|
135
|
+
stop: () => void;
|
|
136
|
+
}>;
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
interface GatewayContext {
|
|
140
|
+
cfg: any;
|
|
141
|
+
runtime: {
|
|
142
|
+
inbound: (msg: InboundMessage) => void;
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
interface InboundMessage {
|
|
146
|
+
channel: string;
|
|
147
|
+
from: string;
|
|
148
|
+
text: string;
|
|
149
|
+
ts?: number;
|
|
150
|
+
metadata?: Record<string, any>;
|
|
151
|
+
}
|
|
152
|
+
declare const _default: {
|
|
153
|
+
id: string;
|
|
154
|
+
register(api: ClawdbotPluginApi): void;
|
|
155
|
+
};
|
|
116
156
|
|
|
117
|
-
export { type
|
|
157
|
+
export { type MessageHandler, type RelayConfig, type RelayMessage, type StateUpdate, UmiRelayClient, _default as default };
|
package/dist/index.d.ts
CHANGED
|
@@ -96,22 +96,62 @@ 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
|
-
|
|
105
|
+
interface ChannelPlugin {
|
|
106
|
+
id: string;
|
|
107
|
+
meta: {
|
|
108
|
+
id: string;
|
|
109
|
+
label: string;
|
|
110
|
+
description?: string;
|
|
111
|
+
};
|
|
112
|
+
capabilities: {
|
|
113
|
+
chatTypes: string[];
|
|
114
|
+
media: boolean;
|
|
115
|
+
};
|
|
116
|
+
outbound: {
|
|
117
|
+
deliveryMode: 'direct' | 'queued';
|
|
118
|
+
resolveTarget: (opts: {
|
|
119
|
+
to: string;
|
|
120
|
+
}) => {
|
|
121
|
+
ok: boolean;
|
|
122
|
+
to: string;
|
|
123
|
+
};
|
|
124
|
+
sendText: (opts: {
|
|
125
|
+
cfg: any;
|
|
126
|
+
to: string;
|
|
127
|
+
text: string;
|
|
128
|
+
}) => Promise<{
|
|
129
|
+
channel: string;
|
|
130
|
+
ok: boolean;
|
|
131
|
+
}>;
|
|
132
|
+
};
|
|
133
|
+
gateway: {
|
|
134
|
+
startAccount: (ctx: GatewayContext) => Promise<{
|
|
135
|
+
stop: () => void;
|
|
136
|
+
}>;
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
interface GatewayContext {
|
|
140
|
+
cfg: any;
|
|
141
|
+
runtime: {
|
|
142
|
+
inbound: (msg: InboundMessage) => void;
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
interface InboundMessage {
|
|
146
|
+
channel: string;
|
|
147
|
+
from: string;
|
|
148
|
+
text: string;
|
|
149
|
+
ts?: number;
|
|
150
|
+
metadata?: Record<string, any>;
|
|
151
|
+
}
|
|
152
|
+
declare const _default: {
|
|
153
|
+
id: string;
|
|
154
|
+
register(api: ClawdbotPluginApi): void;
|
|
155
|
+
};
|
|
116
156
|
|
|
117
|
-
export { type
|
|
157
|
+
export { type MessageHandler, type RelayConfig, type RelayMessage, type StateUpdate, UmiRelayClient, _default as default };
|
package/dist/index.js
CHANGED
|
@@ -31,9 +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
|
-
register: () => register
|
|
34
|
+
default: () => index_default
|
|
37
35
|
});
|
|
38
36
|
module.exports = __toCommonJS(index_exports);
|
|
39
37
|
var import_ws = __toESM(require("ws"));
|
|
@@ -273,40 +271,82 @@ var UmiRelayClient = class {
|
|
|
273
271
|
}
|
|
274
272
|
};
|
|
275
273
|
var relayClient = null;
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
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
|
+
outbound: {
|
|
286
|
+
deliveryMode: "direct",
|
|
287
|
+
resolveTarget: ({ to }) => ({ ok: true, to }),
|
|
288
|
+
sendText: async ({ cfg, to, text }) => {
|
|
289
|
+
if (relayClient?.isConnected) {
|
|
290
|
+
relayClient.sendMessage(text, { to });
|
|
291
|
+
return { channel: "umi-relay", ok: true };
|
|
292
|
+
}
|
|
293
|
+
return { channel: "umi-relay", ok: false };
|
|
294
|
+
}
|
|
295
|
+
},
|
|
296
|
+
gateway: {
|
|
297
|
+
startAccount: async (ctx) => {
|
|
298
|
+
const config = {
|
|
299
|
+
apiKey: ctx.cfg?.apiKey || process.env.UMI_API_KEY || "",
|
|
300
|
+
relayUrl: ctx.cfg?.relayUrl || "wss://ws.umi.app/ws/relay",
|
|
301
|
+
agentVersion: ctx.cfg?.agentVersion || "1.0.0",
|
|
302
|
+
capabilities: ctx.cfg?.capabilities || ["chat"],
|
|
303
|
+
autoReconnect: ctx.cfg?.autoReconnect ?? true
|
|
304
|
+
};
|
|
305
|
+
if (!config.apiKey) {
|
|
306
|
+
console.error("[UmiRelay] No API key provided. Set UMI_API_KEY or pass apiKey in config.");
|
|
307
|
+
return { stop: () => {
|
|
308
|
+
} };
|
|
309
|
+
}
|
|
310
|
+
relayClient = new UmiRelayClient(config);
|
|
311
|
+
relayClient.onMessage((message) => {
|
|
312
|
+
if (message.type === "platform:message") {
|
|
313
|
+
ctx.runtime.inbound({
|
|
314
|
+
channel: "umi-relay",
|
|
315
|
+
from: message.userId || "unknown",
|
|
316
|
+
text: message.content,
|
|
317
|
+
ts: message.timestamp,
|
|
318
|
+
metadata: {
|
|
319
|
+
userId: message.userId,
|
|
320
|
+
agentId: message.agentId
|
|
321
|
+
}
|
|
322
|
+
});
|
|
286
323
|
}
|
|
287
324
|
});
|
|
325
|
+
try {
|
|
326
|
+
await relayClient.connect();
|
|
327
|
+
console.log("[UmiRelay] Connected to relay");
|
|
328
|
+
} catch (error) {
|
|
329
|
+
console.error("[UmiRelay] Failed to connect:", error);
|
|
330
|
+
}
|
|
331
|
+
return {
|
|
332
|
+
stop: () => {
|
|
333
|
+
if (relayClient) {
|
|
334
|
+
relayClient.disconnect();
|
|
335
|
+
relayClient = null;
|
|
336
|
+
}
|
|
337
|
+
console.log("[UmiRelay] Disconnected");
|
|
338
|
+
}
|
|
339
|
+
};
|
|
288
340
|
}
|
|
289
|
-
});
|
|
290
|
-
ctx.registerSend("umi", (response) => {
|
|
291
|
-
if (relayClient?.isConnected) {
|
|
292
|
-
relayClient.sendMessage(response.text || response.content, response.metadata);
|
|
293
|
-
}
|
|
294
|
-
});
|
|
295
|
-
await relayClient.connect();
|
|
296
|
-
console.log("[UmiRelay] Plugin activated");
|
|
297
|
-
}
|
|
298
|
-
function deactivate() {
|
|
299
|
-
if (relayClient) {
|
|
300
|
-
relayClient.disconnect();
|
|
301
|
-
relayClient = null;
|
|
302
341
|
}
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
342
|
+
};
|
|
343
|
+
var index_default = {
|
|
344
|
+
id: "umi-relay",
|
|
345
|
+
register(api) {
|
|
346
|
+
api.registerChannel({ plugin: umiRelayChannel });
|
|
347
|
+
}
|
|
348
|
+
};
|
|
306
349
|
// Annotate the CommonJS export names for ESM import in node:
|
|
307
350
|
0 && (module.exports = {
|
|
308
|
-
UmiRelayClient
|
|
309
|
-
activate,
|
|
310
|
-
deactivate,
|
|
311
|
-
register
|
|
351
|
+
UmiRelayClient
|
|
312
352
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -236,39 +236,82 @@ var UmiRelayClient = class {
|
|
|
236
236
|
}
|
|
237
237
|
};
|
|
238
238
|
var relayClient = null;
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
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
|
+
outbound: {
|
|
251
|
+
deliveryMode: "direct",
|
|
252
|
+
resolveTarget: ({ to }) => ({ ok: true, to }),
|
|
253
|
+
sendText: async ({ cfg, to, text }) => {
|
|
254
|
+
if (relayClient?.isConnected) {
|
|
255
|
+
relayClient.sendMessage(text, { to });
|
|
256
|
+
return { channel: "umi-relay", ok: true };
|
|
257
|
+
}
|
|
258
|
+
return { channel: "umi-relay", ok: false };
|
|
259
|
+
}
|
|
260
|
+
},
|
|
261
|
+
gateway: {
|
|
262
|
+
startAccount: async (ctx) => {
|
|
263
|
+
const config = {
|
|
264
|
+
apiKey: ctx.cfg?.apiKey || process.env.UMI_API_KEY || "",
|
|
265
|
+
relayUrl: ctx.cfg?.relayUrl || "wss://ws.umi.app/ws/relay",
|
|
266
|
+
agentVersion: ctx.cfg?.agentVersion || "1.0.0",
|
|
267
|
+
capabilities: ctx.cfg?.capabilities || ["chat"],
|
|
268
|
+
autoReconnect: ctx.cfg?.autoReconnect ?? true
|
|
269
|
+
};
|
|
270
|
+
if (!config.apiKey) {
|
|
271
|
+
console.error("[UmiRelay] No API key provided. Set UMI_API_KEY or pass apiKey in config.");
|
|
272
|
+
return { stop: () => {
|
|
273
|
+
} };
|
|
274
|
+
}
|
|
275
|
+
relayClient = new UmiRelayClient(config);
|
|
276
|
+
relayClient.onMessage((message) => {
|
|
277
|
+
if (message.type === "platform:message") {
|
|
278
|
+
ctx.runtime.inbound({
|
|
279
|
+
channel: "umi-relay",
|
|
280
|
+
from: message.userId || "unknown",
|
|
281
|
+
text: message.content,
|
|
282
|
+
ts: message.timestamp,
|
|
283
|
+
metadata: {
|
|
284
|
+
userId: message.userId,
|
|
285
|
+
agentId: message.agentId
|
|
286
|
+
}
|
|
287
|
+
});
|
|
249
288
|
}
|
|
250
289
|
});
|
|
290
|
+
try {
|
|
291
|
+
await relayClient.connect();
|
|
292
|
+
console.log("[UmiRelay] Connected to relay");
|
|
293
|
+
} catch (error) {
|
|
294
|
+
console.error("[UmiRelay] Failed to connect:", error);
|
|
295
|
+
}
|
|
296
|
+
return {
|
|
297
|
+
stop: () => {
|
|
298
|
+
if (relayClient) {
|
|
299
|
+
relayClient.disconnect();
|
|
300
|
+
relayClient = null;
|
|
301
|
+
}
|
|
302
|
+
console.log("[UmiRelay] Disconnected");
|
|
303
|
+
}
|
|
304
|
+
};
|
|
251
305
|
}
|
|
252
|
-
});
|
|
253
|
-
ctx.registerSend("umi", (response) => {
|
|
254
|
-
if (relayClient?.isConnected) {
|
|
255
|
-
relayClient.sendMessage(response.text || response.content, response.metadata);
|
|
256
|
-
}
|
|
257
|
-
});
|
|
258
|
-
await relayClient.connect();
|
|
259
|
-
console.log("[UmiRelay] Plugin activated");
|
|
260
|
-
}
|
|
261
|
-
function deactivate() {
|
|
262
|
-
if (relayClient) {
|
|
263
|
-
relayClient.disconnect();
|
|
264
|
-
relayClient = null;
|
|
265
306
|
}
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
307
|
+
};
|
|
308
|
+
var index_default = {
|
|
309
|
+
id: "umi-relay",
|
|
310
|
+
register(api) {
|
|
311
|
+
api.registerChannel({ plugin: umiRelayChannel });
|
|
312
|
+
}
|
|
313
|
+
};
|
|
269
314
|
export {
|
|
270
315
|
UmiRelayClient,
|
|
271
|
-
|
|
272
|
-
deactivate,
|
|
273
|
-
register
|
|
316
|
+
index_default as default
|
|
274
317
|
};
|