@efengx/openclaw-channel-dragon 0.5.12 → 0.5.14
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/components/channel/ChannelComponent.d.ts +1 -0
- package/dist/components/channel/ChannelComponent.js +43 -28
- package/dist/components/sync/SseComponent.js +6 -4
- package/dist/components/telemetry/TelemetryComponent.d.ts +1 -0
- package/dist/components/telemetry/TelemetryComponent.js +1 -1
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
|
@@ -11,6 +11,7 @@ export declare class ChannelComponent implements IComponent {
|
|
|
11
11
|
private options;
|
|
12
12
|
private telemetry;
|
|
13
13
|
private processedMessageIds;
|
|
14
|
+
private sessionQueues;
|
|
14
15
|
constructor(options: ChannelOptions, telemetry: TelemetryComponent);
|
|
15
16
|
start(): Promise<void>;
|
|
16
17
|
stop(): Promise<void>;
|
|
@@ -3,6 +3,7 @@ export class ChannelComponent {
|
|
|
3
3
|
options;
|
|
4
4
|
telemetry;
|
|
5
5
|
processedMessageIds = new Set();
|
|
6
|
+
sessionQueues = new Map();
|
|
6
7
|
constructor(options, telemetry) {
|
|
7
8
|
this.options = options;
|
|
8
9
|
this.telemetry = telemetry;
|
|
@@ -10,6 +11,7 @@ export class ChannelComponent {
|
|
|
10
11
|
async start() { }
|
|
11
12
|
async stop() { }
|
|
12
13
|
deliverToOpenClaw = async (content, sessionId = 'default', modelId, attachments, messageId) => {
|
|
14
|
+
const replyMsgId = messageId ? `dragon_msg_${messageId}` : `dragon_msg_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`;
|
|
13
15
|
if (messageId && this.processedMessageIds.has(messageId))
|
|
14
16
|
return;
|
|
15
17
|
if (messageId) {
|
|
@@ -25,37 +27,50 @@ export class ChannelComponent {
|
|
|
25
27
|
return;
|
|
26
28
|
const { accountId, agentId, cfg, logger } = this.options;
|
|
27
29
|
const sessionKey = `dragon:${agentId}:direct:${sessionId}`;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
30
|
+
const previous = this.sessionQueues.get(sessionKey) || Promise.resolve();
|
|
31
|
+
const current = previous
|
|
32
|
+
.catch(() => { })
|
|
33
|
+
.then(async () => {
|
|
34
|
+
logger?.info?.(`[Dragon Plugin] Sending to OpenClaw: "${content.substring(0, 50)}${content.length > 50 ? '...' : ''}" [Session: ${sessionId}]`);
|
|
35
|
+
await replyDispatcher({
|
|
36
|
+
ctx: {
|
|
37
|
+
Body: content,
|
|
38
|
+
From: sessionId === 'default' ? "workbench-user" : `workbench-user-${sessionId}`,
|
|
39
|
+
To: agentId,
|
|
40
|
+
ChatType: "direct",
|
|
41
|
+
Provider: channelId,
|
|
42
|
+
ChannelId: channelId,
|
|
43
|
+
AccountId: accountId,
|
|
44
|
+
SessionKey: sessionKey,
|
|
45
|
+
Timestamp: Date.now(),
|
|
46
|
+
Model: modelId,
|
|
47
|
+
Attachments: attachments,
|
|
48
|
+
},
|
|
49
|
+
cfg,
|
|
50
|
+
dispatcherOptions: {
|
|
51
|
+
deliver: async (payload) => {
|
|
52
|
+
const text = payload?.text || "";
|
|
53
|
+
if (!text && !payload?.tool_calls?.length)
|
|
54
|
+
return;
|
|
55
|
+
await this.telemetry.reportReply({
|
|
56
|
+
content: text,
|
|
57
|
+
sessionId,
|
|
58
|
+
tool_calls: payload?.tool_calls,
|
|
59
|
+
reasoning_content: payload?.reasoning_content,
|
|
60
|
+
source: "telemetry_deliver",
|
|
61
|
+
msgId: replyMsgId,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
56
64
|
}
|
|
65
|
+
});
|
|
66
|
+
})
|
|
67
|
+
.finally(() => {
|
|
68
|
+
if (this.sessionQueues.get(sessionKey) === current) {
|
|
69
|
+
this.sessionQueues.delete(sessionKey);
|
|
57
70
|
}
|
|
58
71
|
});
|
|
72
|
+
this.sessionQueues.set(sessionKey, current);
|
|
73
|
+
await current;
|
|
59
74
|
};
|
|
60
75
|
handleOutboundText = async (ctx) => {
|
|
61
76
|
const text = ctx?.text || "";
|
|
@@ -26,7 +26,7 @@ export class SseComponent {
|
|
|
26
26
|
const url = `${this.http.options.baseURL}/api/agents/events`;
|
|
27
27
|
logger?.info?.(`[Dragon Plugin] Connecting to Orchestrator SSE: ${url}`);
|
|
28
28
|
try {
|
|
29
|
-
// In Node 22, we might need a fetch-based SSE or a library,
|
|
29
|
+
// In Node 22, we might need a fetch-based SSE or a library,
|
|
30
30
|
// but for simplicity we'll use the same pattern as Bridge if possible.
|
|
31
31
|
// Actually, standard EventSource is not in Node globals yet.
|
|
32
32
|
// We'll use a simple fetch-based stream reader.
|
|
@@ -65,7 +65,9 @@ export class SseComponent {
|
|
|
65
65
|
if (line.startsWith("data: ")) {
|
|
66
66
|
try {
|
|
67
67
|
const data = JSON.parse(line.slice(6));
|
|
68
|
-
this.handleEvent(data)
|
|
68
|
+
void this.handleEvent(data).catch((err) => {
|
|
69
|
+
this.options.logger?.error?.(`[Dragon Plugin] SSE event handling failed: ${err?.message || err}`);
|
|
70
|
+
});
|
|
69
71
|
}
|
|
70
72
|
catch (e) { }
|
|
71
73
|
}
|
|
@@ -79,7 +81,7 @@ export class SseComponent {
|
|
|
79
81
|
}
|
|
80
82
|
}
|
|
81
83
|
}
|
|
82
|
-
handleEvent(data) {
|
|
84
|
+
async handleEvent(data) {
|
|
83
85
|
const { agentId, logger } = this.options;
|
|
84
86
|
// 1. Filter for events belonging to this agent
|
|
85
87
|
if (data.agentId && data.agentId !== agentId)
|
|
@@ -88,7 +90,7 @@ export class SseComponent {
|
|
|
88
90
|
if (data.type === 'WORKBENCH_MESSAGE') {
|
|
89
91
|
const { content, sessionId, attachments, id, msgId } = data.payload || {};
|
|
90
92
|
logger?.info?.(`[Dragon Plugin] [SSE] Received from Workbench: "${content?.substring(0, 50)}${content?.length > 50 ? '...' : ''}" [Session: ${sessionId}]`);
|
|
91
|
-
this.channel.deliverToOpenClaw(content, sessionId, undefined, attachments, msgId || id);
|
|
93
|
+
await this.channel.deliverToOpenClaw(content, sessionId, undefined, attachments, msgId || id);
|
|
92
94
|
}
|
|
93
95
|
else if (data.type === 'FETCH_HISTORY') {
|
|
94
96
|
const { sessionId } = data.payload || {};
|
|
@@ -24,7 +24,7 @@ export class TelemetryComponent {
|
|
|
24
24
|
}
|
|
25
25
|
this.lastReplies.set(key, { normalized, timestamp: now });
|
|
26
26
|
}
|
|
27
|
-
const msgId = crypto.randomUUID();
|
|
27
|
+
const msgId = payload.msgId || crypto.randomUUID();
|
|
28
28
|
await this.http.fetch(`/api/agents/${this.agentId}/messages/reply`, {
|
|
29
29
|
method: "POST",
|
|
30
30
|
headers: { "Content-Type": "application/json" },
|
package/openclaw.plugin.json
CHANGED