@efengx/openclaw-channel-dragon 0.3.2 → 0.3.5
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/index.js +40 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -177,16 +177,55 @@ async function startPolling(ctx) {
|
|
|
177
177
|
const dataStr = dataLines.join('\n');
|
|
178
178
|
try {
|
|
179
179
|
const evt = JSON.parse(dataStr);
|
|
180
|
-
if (!evt
|
|
180
|
+
if (!evt)
|
|
181
181
|
continue;
|
|
182
182
|
if (evt.type === 'WORKBENCH_MESSAGE') {
|
|
183
183
|
const sendTs = evt.payload?.ts || 0;
|
|
184
184
|
const latency = sendTs ? (Date.now() - sendTs) : 'unknown';
|
|
185
|
+
// Critical Log: Confirm receipt of SSE message
|
|
186
|
+
logger?.info?.(`dragon channel: [SSE] RECEIVED WORKBENCH_MESSAGE. agentId=${evt.agentId} (Current Config: ${agentId}), sessionId=${evt.payload?.sessionId}, latency=${latency}ms`);
|
|
187
|
+
if (evt.agentId !== agentId) {
|
|
188
|
+
logger?.warn?.(`dragon channel: [SSE] ID Mismatch! Event ID "${evt.agentId}" !== Config ID "${agentId}". Ignoring message.`);
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
185
191
|
logger?.info?.(`dragon channel: [DEBUG] Received WORKBENCH_MESSAGE via SSE. AgentID=${evt.agentId}, ContentLen=${evt.payload?.content?.length}, Latency=${latency}ms`);
|
|
186
192
|
logger?.info?.(`dragon channel: [DEBUG] Payload Content: "${evt.payload?.content?.substring(0, 500)}"`);
|
|
187
193
|
logger?.info?.(`dragon channel: [DEBUG] Current Account Config: ${JSON.stringify(account)}`);
|
|
188
194
|
await deliverToOpenClaw(String(evt?.payload?.content || ''), String(evt?.payload?.sessionId || 'default'), evt?.payload?.modelId, evt?.payload?.attachments);
|
|
189
195
|
}
|
|
196
|
+
else if (evt.type === 'FETCH_HISTORY') {
|
|
197
|
+
const { sessionId } = evt.payload;
|
|
198
|
+
logger?.info?.(`dragon channel: [DEBUG] Received FETCH_HISTORY for session ${sessionId}`);
|
|
199
|
+
try {
|
|
200
|
+
// Retrieve history from OpenClaw core via channelRuntime
|
|
201
|
+
// sessionKey format: dragon:agentId:direct:sessionId
|
|
202
|
+
const sessionKey = `dragon:${account.agentId}:direct:${sessionId}`;
|
|
203
|
+
// Standard OpenClaw 2026.4.12+ history retrieval API
|
|
204
|
+
const history = await ctx.channelRuntime?.history?.getMessages?.({
|
|
205
|
+
sessionKey,
|
|
206
|
+
limit: 50
|
|
207
|
+
}) || [];
|
|
208
|
+
logger?.info?.(`dragon channel: [DEBUG] Retrieved ${history.length} messages from OpenClaw core for sync.`);
|
|
209
|
+
// Post back to orchestrator
|
|
210
|
+
const syncUrl = `${orchestratorUrl}/api/agents/${account.agentId}/messages/sync-context`;
|
|
211
|
+
await fetch(syncUrl, {
|
|
212
|
+
method: "POST",
|
|
213
|
+
headers: { "Content-Type": "application/json" },
|
|
214
|
+
body: JSON.stringify({
|
|
215
|
+
sessionId,
|
|
216
|
+
messages: history.map((m) => ({
|
|
217
|
+
role: m.role || (m.from === 'workbench-user' ? 'user' : 'assistant'),
|
|
218
|
+
content: m.body || m.text || '',
|
|
219
|
+
ts: m.timestamp || Date.now()
|
|
220
|
+
}))
|
|
221
|
+
}),
|
|
222
|
+
});
|
|
223
|
+
logger?.info?.(`dragon channel: [DEBUG] Successfully synced ${history.length} messages back to orchestrator.`);
|
|
224
|
+
}
|
|
225
|
+
catch (e) {
|
|
226
|
+
logger?.error?.(`dragon channel: [ERROR] FETCH_HISTORY failed: ${e.message}`);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
190
229
|
}
|
|
191
230
|
catch (e) {
|
|
192
231
|
logger?.error?.(`dragon channel: failed to parse SSE data: ${e?.message || e}`, e?.stack);
|