lazy-gravity 0.6.0 → 0.6.2
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/bot/index.js +62 -17
- package/dist/bot/telegramMessageHandler.js +3 -0
- package/dist/services/cdpService.js +962 -105
- package/dist/services/responseMonitor.js +235 -48
- package/package.json +1 -1
package/dist/bot/index.js
CHANGED
|
@@ -184,13 +184,19 @@ async function sendPromptToAntigravity(bridge, message, prompt, cdp, modeService
|
|
|
184
184
|
const enqueueGeneral = createSerialTaskQueueForTest('general', monitorTraceId);
|
|
185
185
|
const enqueueResponse = createSerialTaskQueueForTest('response', monitorTraceId);
|
|
186
186
|
const enqueueActivity = createSerialTaskQueueForTest('activity', monitorTraceId);
|
|
187
|
+
const logDeliveryError = (scope, error) => {
|
|
188
|
+
const messageText = error instanceof Error ? error.message : String(error);
|
|
189
|
+
logger_1.logger.warn(`[DiscordDelivery:${monitorTraceId}] ${scope} failed: ${messageText}`);
|
|
190
|
+
};
|
|
187
191
|
const sendEmbed = (title, description, color, fields, footerText) => enqueueGeneral(async () => {
|
|
188
192
|
if (!channel)
|
|
189
193
|
return;
|
|
190
194
|
if (outputFormat === 'plain') {
|
|
191
195
|
const chunks = (0, plainTextFormatter_1.formatAsPlainText)({ title, description, fields, footerText });
|
|
192
196
|
for (const chunk of chunks) {
|
|
193
|
-
await channel.send({ content: chunk }).catch(() => {
|
|
197
|
+
await channel.send({ content: chunk }).catch((error) => {
|
|
198
|
+
logDeliveryError('sendEmbed/plain/send', error);
|
|
199
|
+
});
|
|
194
200
|
}
|
|
195
201
|
return;
|
|
196
202
|
}
|
|
@@ -205,7 +211,9 @@ async function sendPromptToAntigravity(bridge, message, prompt, cdp, modeService
|
|
|
205
211
|
if (footerText) {
|
|
206
212
|
embed.setFooter({ text: footerText });
|
|
207
213
|
}
|
|
208
|
-
await channel.send({ embeds: [embed] }).catch(() => {
|
|
214
|
+
await channel.send({ embeds: [embed] }).catch((error) => {
|
|
215
|
+
logDeliveryError('sendEmbed/embed/send', error);
|
|
216
|
+
});
|
|
209
217
|
}, 'send-embed');
|
|
210
218
|
const shouldTryGeneratedImages = (inputPrompt, responseText) => {
|
|
211
219
|
const prompt = (inputPrompt || '').toLowerCase();
|
|
@@ -238,7 +246,9 @@ async function sendPromptToAntigravity(bridge, message, prompt, cdp, modeService
|
|
|
238
246
|
await channel.send({
|
|
239
247
|
content: (0, i18n_1.t)(`🖼️ Detected generated images (${files.length})`),
|
|
240
248
|
files,
|
|
241
|
-
}).catch(() => {
|
|
249
|
+
}).catch((error) => {
|
|
250
|
+
logDeliveryError('sendGeneratedImages/send', error);
|
|
251
|
+
});
|
|
242
252
|
}, 'send-generated-images');
|
|
243
253
|
};
|
|
244
254
|
const tryEmergencyExtractText = async () => {
|
|
@@ -322,7 +332,9 @@ async function sendPromptToAntigravity(bridge, message, prompt, cdp, modeService
|
|
|
322
332
|
// Apply default model preference on CDP connect
|
|
323
333
|
const defaultModelResult = await (0, defaultModelApplicator_1.applyDefaultModel)(cdp, modelService);
|
|
324
334
|
if (defaultModelResult.stale && defaultModelResult.staleMessage && channel) {
|
|
325
|
-
await channel.send(defaultModelResult.staleMessage).catch(() => {
|
|
335
|
+
await channel.send(defaultModelResult.staleMessage).catch((error) => {
|
|
336
|
+
logDeliveryError('defaultModelResult/send', error);
|
|
337
|
+
});
|
|
326
338
|
}
|
|
327
339
|
const localMode = modeService.getCurrentMode();
|
|
328
340
|
const modeName = modeService_1.MODE_UI_NAMES[localMode] || localMode;
|
|
@@ -383,11 +395,18 @@ async function sendPromptToAntigravity(bridge, message, prompt, cdp, modeService
|
|
|
383
395
|
lastLiveResponseKey = renderKey;
|
|
384
396
|
for (let i = 0; i < plainChunks.length; i++) {
|
|
385
397
|
if (!liveResponseMessages[i]) {
|
|
386
|
-
liveResponseMessages[i] = await channel.send({ content: plainChunks[i] }).catch(() =>
|
|
398
|
+
liveResponseMessages[i] = await channel.send({ content: plainChunks[i] }).catch((error) => {
|
|
399
|
+
logDeliveryError('liveResponse/plain/send', error);
|
|
400
|
+
return null;
|
|
401
|
+
});
|
|
387
402
|
continue;
|
|
388
403
|
}
|
|
389
|
-
await liveResponseMessages[i].edit({ content: plainChunks[i] }).catch(async () => {
|
|
390
|
-
|
|
404
|
+
await liveResponseMessages[i].edit({ content: plainChunks[i] }).catch(async (error) => {
|
|
405
|
+
logDeliveryError('liveResponse/plain/edit', error);
|
|
406
|
+
liveResponseMessages[i] = await channel.send({ content: plainChunks[i] }).catch((sendError) => {
|
|
407
|
+
logDeliveryError('liveResponse/plain/resend', sendError);
|
|
408
|
+
return null;
|
|
409
|
+
});
|
|
391
410
|
});
|
|
392
411
|
}
|
|
393
412
|
while (liveResponseMessages.length > plainChunks.length) {
|
|
@@ -412,11 +431,18 @@ async function sendPromptToAntigravity(bridge, message, prompt, cdp, modeService
|
|
|
412
431
|
.setFooter({ text: footerText })
|
|
413
432
|
.setTimestamp();
|
|
414
433
|
if (!liveResponseMessages[i]) {
|
|
415
|
-
liveResponseMessages[i] = await channel.send({ embeds: [embed] }).catch(() =>
|
|
434
|
+
liveResponseMessages[i] = await channel.send({ embeds: [embed] }).catch((error) => {
|
|
435
|
+
logDeliveryError('liveResponse/embed/send', error);
|
|
436
|
+
return null;
|
|
437
|
+
});
|
|
416
438
|
continue;
|
|
417
439
|
}
|
|
418
|
-
await liveResponseMessages[i].edit({ embeds: [embed] }).catch(async () => {
|
|
419
|
-
|
|
440
|
+
await liveResponseMessages[i].edit({ embeds: [embed] }).catch(async (error) => {
|
|
441
|
+
logDeliveryError('liveResponse/embed/edit', error);
|
|
442
|
+
liveResponseMessages[i] = await channel.send({ embeds: [embed] }).catch((sendError) => {
|
|
443
|
+
logDeliveryError('liveResponse/embed/resend', sendError);
|
|
444
|
+
return null;
|
|
445
|
+
});
|
|
420
446
|
});
|
|
421
447
|
}
|
|
422
448
|
// Delete excess messages if page count decreased
|
|
@@ -444,11 +470,18 @@ async function sendPromptToAntigravity(bridge, message, prompt, cdp, modeService
|
|
|
444
470
|
lastLiveActivityKey = renderKey;
|
|
445
471
|
for (let i = 0; i < plainChunks.length; i++) {
|
|
446
472
|
if (!liveActivityMessages[i]) {
|
|
447
|
-
liveActivityMessages[i] = await channel.send({ content: plainChunks[i] }).catch(() =>
|
|
473
|
+
liveActivityMessages[i] = await channel.send({ content: plainChunks[i] }).catch((error) => {
|
|
474
|
+
logDeliveryError('liveActivity/plain/send', error);
|
|
475
|
+
return null;
|
|
476
|
+
});
|
|
448
477
|
continue;
|
|
449
478
|
}
|
|
450
|
-
await liveActivityMessages[i].edit({ content: plainChunks[i] }).catch(async () => {
|
|
451
|
-
|
|
479
|
+
await liveActivityMessages[i].edit({ content: plainChunks[i] }).catch(async (error) => {
|
|
480
|
+
logDeliveryError('liveActivity/plain/edit', error);
|
|
481
|
+
liveActivityMessages[i] = await channel.send({ content: plainChunks[i] }).catch((sendError) => {
|
|
482
|
+
logDeliveryError('liveActivity/plain/resend', sendError);
|
|
483
|
+
return null;
|
|
484
|
+
});
|
|
452
485
|
});
|
|
453
486
|
}
|
|
454
487
|
while (liveActivityMessages.length > plainChunks.length) {
|
|
@@ -473,11 +506,18 @@ async function sendPromptToAntigravity(bridge, message, prompt, cdp, modeService
|
|
|
473
506
|
.setFooter({ text: footerText })
|
|
474
507
|
.setTimestamp();
|
|
475
508
|
if (!liveActivityMessages[i]) {
|
|
476
|
-
liveActivityMessages[i] = await channel.send({ embeds: [embed] }).catch(() =>
|
|
509
|
+
liveActivityMessages[i] = await channel.send({ embeds: [embed] }).catch((error) => {
|
|
510
|
+
logDeliveryError('liveActivity/embed/send', error);
|
|
511
|
+
return null;
|
|
512
|
+
});
|
|
477
513
|
continue;
|
|
478
514
|
}
|
|
479
|
-
await liveActivityMessages[i].edit({ embeds: [embed] }).catch(async () => {
|
|
480
|
-
|
|
515
|
+
await liveActivityMessages[i].edit({ embeds: [embed] }).catch(async (error) => {
|
|
516
|
+
logDeliveryError('liveActivity/embed/edit', error);
|
|
517
|
+
liveActivityMessages[i] = await channel.send({ embeds: [embed] }).catch((sendError) => {
|
|
518
|
+
logDeliveryError('liveActivity/embed/resend', sendError);
|
|
519
|
+
return null;
|
|
520
|
+
});
|
|
481
521
|
});
|
|
482
522
|
}
|
|
483
523
|
while (liveActivityMessages.length > descriptions.length) {
|
|
@@ -488,6 +528,7 @@ async function sendPromptToAntigravity(bridge, message, prompt, cdp, modeService
|
|
|
488
528
|
}
|
|
489
529
|
}, `upsert-activity:${opts?.source ?? 'unknown'}`);
|
|
490
530
|
try {
|
|
531
|
+
const baseline = await (0, responseMonitor_1.captureResponseMonitorBaseline)(cdp);
|
|
491
532
|
logger_1.logger.prompt(prompt);
|
|
492
533
|
let injectResult;
|
|
493
534
|
if (inboundImages.length > 0) {
|
|
@@ -516,6 +557,8 @@ async function sendPromptToAntigravity(bridge, message, prompt, cdp, modeService
|
|
|
516
557
|
maxDurationMs: options?.responseTimeoutMs,
|
|
517
558
|
stopGoneConfirmCount: 3,
|
|
518
559
|
extractionMode: options?.extractionMode,
|
|
560
|
+
initialBaselineText: baseline.text,
|
|
561
|
+
initialSeenProcessLogKeys: baseline.processLogKeys,
|
|
519
562
|
onPhaseChange: (_phase, _text) => {
|
|
520
563
|
// Phase transitions are already logged inside ResponseMonitor.setPhase()
|
|
521
564
|
},
|
|
@@ -578,7 +621,9 @@ async function sendPromptToAntigravity(bridge, message, prompt, cdp, modeService
|
|
|
578
621
|
try {
|
|
579
622
|
const modelsPayload = await (0, modelsUi_1.buildModelsUI)(cdp, () => bridge.quota.fetchQuota());
|
|
580
623
|
if (modelsPayload && channel) {
|
|
581
|
-
await channel.send({ ...modelsPayload })
|
|
624
|
+
await channel.send({ ...modelsPayload }).catch((error) => {
|
|
625
|
+
logDeliveryError('quota/modelsPayload/send', error);
|
|
626
|
+
});
|
|
582
627
|
}
|
|
583
628
|
}
|
|
584
629
|
catch (e) {
|
|
@@ -155,6 +155,7 @@ function createTelegramMessageHandler(deps) {
|
|
|
155
155
|
}
|
|
156
156
|
// Determine the prompt text — use default for image-only messages
|
|
157
157
|
const effectivePrompt = promptText || 'Please review the attached images and respond accordingly.';
|
|
158
|
+
const baseline = await (0, responseMonitor_1.captureResponseMonitorBaseline)(cdp);
|
|
158
159
|
// Inject prompt (with or without images) into Antigravity
|
|
159
160
|
logger_1.logger.prompt(effectivePrompt);
|
|
160
161
|
let injectResult;
|
|
@@ -208,6 +209,8 @@ function createTelegramMessageHandler(deps) {
|
|
|
208
209
|
maxDurationMs: TIMEOUT_MS,
|
|
209
210
|
stopGoneConfirmCount: 3,
|
|
210
211
|
extractionMode: deps.extractionMode,
|
|
212
|
+
initialBaselineText: baseline.text,
|
|
213
|
+
initialSeenProcessLogKeys: baseline.processLogKeys,
|
|
211
214
|
onProcessLog: (logText) => {
|
|
212
215
|
if (logText && logText.trim().length > 0) {
|
|
213
216
|
lastActivityLogText = processLogBuffer.append(logText);
|