lunel-cli 0.1.21 → 0.1.23
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 -10
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1171,40 +1171,53 @@ async function handleHttpRequest(payload) {
|
|
|
1171
1171
|
// ============================================================================
|
|
1172
1172
|
// AI Handlers (OpenCode SDK)
|
|
1173
1173
|
// ============================================================================
|
|
1174
|
+
function requireData(response, label) {
|
|
1175
|
+
if (!response.data) {
|
|
1176
|
+
const errMsg = response.error
|
|
1177
|
+
? (typeof response.error === "string" ? response.error : JSON.stringify(response.error))
|
|
1178
|
+
: `${label} returned no data`;
|
|
1179
|
+
throw new Error(errMsg);
|
|
1180
|
+
}
|
|
1181
|
+
return response.data;
|
|
1182
|
+
}
|
|
1174
1183
|
async function handleAiCreateSession(payload) {
|
|
1175
1184
|
const title = payload.title || undefined;
|
|
1176
1185
|
const response = await opencodeClient.session.create({ body: { title } });
|
|
1177
|
-
return { session: response.
|
|
1186
|
+
return { session: requireData(response, "session.create") };
|
|
1178
1187
|
}
|
|
1179
1188
|
async function handleAiListSessions() {
|
|
1180
1189
|
const response = await opencodeClient.session.list();
|
|
1181
|
-
return { sessions: response.
|
|
1190
|
+
return { sessions: requireData(response, "session.list") };
|
|
1182
1191
|
}
|
|
1183
1192
|
async function handleAiGetSession(payload) {
|
|
1184
1193
|
const id = payload.id;
|
|
1185
1194
|
const response = await opencodeClient.session.get({ path: { id } });
|
|
1186
|
-
return { session: response.
|
|
1195
|
+
return { session: requireData(response, "session.get") };
|
|
1187
1196
|
}
|
|
1188
1197
|
async function handleAiDeleteSession(payload) {
|
|
1189
1198
|
const id = payload.id;
|
|
1190
|
-
await opencodeClient.session.delete({ path: { id } });
|
|
1199
|
+
const response = await opencodeClient.session.delete({ path: { id } });
|
|
1200
|
+
if (response.error)
|
|
1201
|
+
throw new Error(JSON.stringify(response.error));
|
|
1191
1202
|
return {};
|
|
1192
1203
|
}
|
|
1193
1204
|
async function handleAiGetMessages(payload) {
|
|
1194
1205
|
const id = payload.id;
|
|
1195
1206
|
const response = await opencodeClient.session.messages({ path: { id } });
|
|
1196
|
-
return { messages: response.
|
|
1207
|
+
return { messages: requireData(response, "session.messages") };
|
|
1197
1208
|
}
|
|
1198
1209
|
async function handleAiPrompt(payload) {
|
|
1199
1210
|
const sessionId = payload.sessionId;
|
|
1200
1211
|
const text = payload.text;
|
|
1201
1212
|
const model = payload.model;
|
|
1213
|
+
const agent = payload.agent;
|
|
1202
1214
|
// Fire and forget — results stream via SSE events forwarded on data channel
|
|
1203
1215
|
opencodeClient.session.prompt({
|
|
1204
1216
|
path: { id: sessionId },
|
|
1205
1217
|
body: {
|
|
1206
1218
|
parts: [{ type: "text", text }],
|
|
1207
1219
|
...(model ? { model } : {}),
|
|
1220
|
+
...(agent ? { agent } : {}),
|
|
1208
1221
|
},
|
|
1209
1222
|
}).catch((err) => {
|
|
1210
1223
|
if (dataChannel && dataChannel.readyState === WebSocket.OPEN) {
|
|
@@ -1229,11 +1242,12 @@ async function handleAiAbort(payload) {
|
|
|
1229
1242
|
}
|
|
1230
1243
|
async function handleAiAgents() {
|
|
1231
1244
|
const response = await opencodeClient.app.agents();
|
|
1232
|
-
return { agents: response.
|
|
1245
|
+
return { agents: requireData(response, "app.agents") };
|
|
1233
1246
|
}
|
|
1234
1247
|
async function handleAiProviders() {
|
|
1235
1248
|
const response = await opencodeClient.config.providers();
|
|
1236
|
-
|
|
1249
|
+
const data = requireData(response, "config.providers");
|
|
1250
|
+
return { providers: data.providers, default: data.default };
|
|
1237
1251
|
}
|
|
1238
1252
|
async function handleAiSetAuth(payload) {
|
|
1239
1253
|
const providerId = payload.providerId;
|
|
@@ -1252,7 +1266,7 @@ async function handleAiCommand(payload) {
|
|
|
1252
1266
|
path: { id: sessionId },
|
|
1253
1267
|
body: { command, arguments: args },
|
|
1254
1268
|
});
|
|
1255
|
-
return { result: response.data };
|
|
1269
|
+
return { result: response.data ?? null };
|
|
1256
1270
|
}
|
|
1257
1271
|
async function handleAiRevert(payload) {
|
|
1258
1272
|
const sessionId = payload.sessionId;
|
|
@@ -1271,15 +1285,24 @@ async function handleAiUnrevert(payload) {
|
|
|
1271
1285
|
async function handleAiShare(payload) {
|
|
1272
1286
|
const sessionId = payload.sessionId;
|
|
1273
1287
|
const response = await opencodeClient.session.share({ path: { id: sessionId } });
|
|
1274
|
-
return { share: response.
|
|
1288
|
+
return { share: requireData(response, "session.share") };
|
|
1275
1289
|
}
|
|
1276
1290
|
async function handleAiPermissionReply(payload) {
|
|
1277
1291
|
const permissionId = payload.permissionId;
|
|
1278
1292
|
const sessionId = payload.sessionId;
|
|
1293
|
+
const response = payload.response;
|
|
1279
1294
|
const approved = payload.approved;
|
|
1295
|
+
// Support new "once" | "always" | "reject" format, fallback to legacy boolean
|
|
1296
|
+
let permResponse;
|
|
1297
|
+
if (response === "once" || response === "always" || response === "reject") {
|
|
1298
|
+
permResponse = response;
|
|
1299
|
+
}
|
|
1300
|
+
else {
|
|
1301
|
+
permResponse = approved ? "once" : "reject";
|
|
1302
|
+
}
|
|
1280
1303
|
await opencodeClient.postSessionIdPermissionsPermissionId({
|
|
1281
1304
|
path: { id: sessionId, permissionID: permissionId },
|
|
1282
|
-
body: { response:
|
|
1305
|
+
body: { response: permResponse },
|
|
1283
1306
|
});
|
|
1284
1307
|
return {};
|
|
1285
1308
|
}
|