lunel-cli 0.1.26 → 0.1.28
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 +30 -5
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1225,7 +1225,17 @@ async function handleAiGetMessages(payload) {
|
|
|
1225
1225
|
console.log("[ai] getMessages called, sessionId:", id);
|
|
1226
1226
|
try {
|
|
1227
1227
|
const response = await opencodeClient.session.messages({ path: { id } });
|
|
1228
|
-
|
|
1228
|
+
const raw = requireData(response, "session.messages");
|
|
1229
|
+
// Transform SDK shape { info: { id, sessionID, role, ... }, parts: [...] }
|
|
1230
|
+
// into app shape { id, role, parts }
|
|
1231
|
+
const messages = raw.map((m) => ({
|
|
1232
|
+
id: m.info.id,
|
|
1233
|
+
role: m.info.role,
|
|
1234
|
+
parts: m.parts || [],
|
|
1235
|
+
time: m.info.time,
|
|
1236
|
+
}));
|
|
1237
|
+
console.log("[ai] getMessages returned", messages.length, "messages");
|
|
1238
|
+
return { messages };
|
|
1229
1239
|
}
|
|
1230
1240
|
catch (err) {
|
|
1231
1241
|
console.error("[ai] getMessages exception:", err.message);
|
|
@@ -1355,7 +1365,19 @@ async function handleAiPermissionReply(payload) {
|
|
|
1355
1365
|
async function subscribeToOpenCodeEvents(client) {
|
|
1356
1366
|
try {
|
|
1357
1367
|
const events = await client.event.subscribe();
|
|
1358
|
-
for await (const
|
|
1368
|
+
for await (const raw of events.stream) {
|
|
1369
|
+
// OpenCode SSE payload shapes vary across versions:
|
|
1370
|
+
// { type, properties, ... }
|
|
1371
|
+
// { payload: { type, properties, ... }, directory: "..." }
|
|
1372
|
+
const parsed = raw;
|
|
1373
|
+
const base = parsed?.payload && typeof parsed.payload === "object"
|
|
1374
|
+
? parsed.payload
|
|
1375
|
+
: parsed;
|
|
1376
|
+
if (!base || typeof base.type !== "string") {
|
|
1377
|
+
console.warn("[sse] Dropped malformed event:", JSON.stringify(parsed).substring(0, 200));
|
|
1378
|
+
continue;
|
|
1379
|
+
}
|
|
1380
|
+
console.log("[sse]", base.type);
|
|
1359
1381
|
if (dataChannel && dataChannel.readyState === WebSocket.OPEN) {
|
|
1360
1382
|
const msg = {
|
|
1361
1383
|
v: 1,
|
|
@@ -1363,16 +1385,19 @@ async function subscribeToOpenCodeEvents(client) {
|
|
|
1363
1385
|
ns: "ai",
|
|
1364
1386
|
action: "event",
|
|
1365
1387
|
payload: {
|
|
1366
|
-
type:
|
|
1367
|
-
properties:
|
|
1388
|
+
type: base.type,
|
|
1389
|
+
properties: base.properties || {},
|
|
1368
1390
|
},
|
|
1369
1391
|
};
|
|
1370
1392
|
dataChannel.send(JSON.stringify(msg));
|
|
1371
1393
|
}
|
|
1372
1394
|
}
|
|
1395
|
+
// Stream ended normally — reconnect
|
|
1396
|
+
console.log("[sse] Event stream ended, reconnecting...");
|
|
1397
|
+
setTimeout(() => subscribeToOpenCodeEvents(client), 1000);
|
|
1373
1398
|
}
|
|
1374
1399
|
catch (err) {
|
|
1375
|
-
console.error("
|
|
1400
|
+
console.error("[sse] Event stream error:", err.message);
|
|
1376
1401
|
setTimeout(() => subscribeToOpenCodeEvents(client), 3000);
|
|
1377
1402
|
}
|
|
1378
1403
|
}
|