@efengx/openclaw-channel-dragon 0.3.1 → 0.3.3
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 +33 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -187,6 +187,39 @@ async function startPolling(ctx) {
|
|
|
187
187
|
logger?.info?.(`dragon channel: [DEBUG] Current Account Config: ${JSON.stringify(account)}`);
|
|
188
188
|
await deliverToOpenClaw(String(evt?.payload?.content || ''), String(evt?.payload?.sessionId || 'default'), evt?.payload?.modelId, evt?.payload?.attachments);
|
|
189
189
|
}
|
|
190
|
+
else if (evt.type === 'FETCH_HISTORY') {
|
|
191
|
+
const { sessionId } = evt.payload;
|
|
192
|
+
logger?.info?.(`dragon channel: [DEBUG] Received FETCH_HISTORY for session ${sessionId}`);
|
|
193
|
+
try {
|
|
194
|
+
// Retrieve history from OpenClaw core via channelRuntime
|
|
195
|
+
// sessionKey format: dragon:agentId:direct:sessionId
|
|
196
|
+
const sessionKey = `dragon:${account.agentId}:direct:${sessionId}`;
|
|
197
|
+
// Standard OpenClaw 2026.4.12+ history retrieval API
|
|
198
|
+
const history = await ctx.channelRuntime?.history?.getMessages?.({
|
|
199
|
+
sessionKey,
|
|
200
|
+
limit: 50
|
|
201
|
+
}) || [];
|
|
202
|
+
logger?.info?.(`dragon channel: [DEBUG] Retrieved ${history.length} messages from OpenClaw core for sync.`);
|
|
203
|
+
// Post back to orchestrator
|
|
204
|
+
const syncUrl = `${orchestratorUrl}/api/agents/${account.agentId}/messages/sync-context`;
|
|
205
|
+
await fetch(syncUrl, {
|
|
206
|
+
method: "POST",
|
|
207
|
+
headers: { "Content-Type": "application/json" },
|
|
208
|
+
body: JSON.stringify({
|
|
209
|
+
sessionId,
|
|
210
|
+
messages: history.map((m) => ({
|
|
211
|
+
role: m.role || (m.from === 'workbench-user' ? 'user' : 'assistant'),
|
|
212
|
+
content: m.body || m.text || '',
|
|
213
|
+
ts: m.timestamp || Date.now()
|
|
214
|
+
}))
|
|
215
|
+
}),
|
|
216
|
+
});
|
|
217
|
+
logger?.info?.(`dragon channel: [DEBUG] Successfully synced ${history.length} messages back to orchestrator.`);
|
|
218
|
+
}
|
|
219
|
+
catch (e) {
|
|
220
|
+
logger?.error?.(`dragon channel: [ERROR] FETCH_HISTORY failed: ${e.message}`);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
190
223
|
}
|
|
191
224
|
catch (e) {
|
|
192
225
|
logger?.error?.(`dragon channel: failed to parse SSE data: ${e?.message || e}`, e?.stack);
|