fluxy-bot 0.5.3 → 0.5.4
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/package.json +1 -1
- package/supervisor/scheduler.ts +50 -6
package/package.json
CHANGED
package/supervisor/scheduler.ts
CHANGED
|
@@ -121,19 +121,45 @@ function triggerAgent(prompt: string, label: string) {
|
|
|
121
121
|
log.warn(`[scheduler] Failed to create conversation for ${label}: ${err.message}`);
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
+
console.log(`[scheduler] Sending prompt to agent: ${prompt}`);
|
|
125
|
+
console.log(`[scheduler] Using model: ${model}, convId: ${convId}`);
|
|
126
|
+
|
|
124
127
|
let fullResponse = '';
|
|
125
128
|
|
|
126
129
|
startFluxyAgentQuery(convId, prompt, model, (type, eventData) => {
|
|
130
|
+
console.log(`[scheduler] onMessage callback: type=${type}`);
|
|
131
|
+
|
|
132
|
+
if (type === 'bot:typing') {
|
|
133
|
+
console.log(`[scheduler] Agent started typing`);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (type === 'bot:token') {
|
|
137
|
+
// Log first 100 chars of accumulated tokens periodically
|
|
138
|
+
const token = eventData.token || '';
|
|
139
|
+
fullResponse += token; // accumulate from tokens too, in case bot:response doesn't fire
|
|
140
|
+
}
|
|
141
|
+
|
|
127
142
|
if (type === 'bot:response') {
|
|
143
|
+
console.log(`[scheduler] bot:response received, content length: ${(eventData.content || '').length}`);
|
|
144
|
+
console.log(`[scheduler] bot:response first 300 chars: ${(eventData.content || '').slice(0, 300)}`);
|
|
128
145
|
fullResponse = eventData.content || '';
|
|
129
146
|
}
|
|
130
147
|
|
|
131
148
|
if (type === 'bot:done') {
|
|
149
|
+
console.log(`[scheduler] bot:done — fullResponse length: ${fullResponse.length}`);
|
|
150
|
+
console.log(`[scheduler] bot:done — fullResponse first 500 chars: ${fullResponse.slice(0, 500)}`);
|
|
151
|
+
console.log(`[scheduler] bot:done — usedFileTools: ${eventData.usedFileTools}`);
|
|
152
|
+
|
|
132
153
|
// Extract <Message> blocks after agent turn completes
|
|
133
154
|
if (fullResponse) {
|
|
134
155
|
const messageRegex = /<Message(?:\s+([^>]*))?>(([\s\S]*?))<\/Message>/g;
|
|
156
|
+
const hasMessageTags = /<Message/.test(fullResponse);
|
|
157
|
+
console.log(`[scheduler] Contains <Message> tags: ${hasMessageTags}`);
|
|
158
|
+
|
|
135
159
|
let match;
|
|
160
|
+
let messageCount = 0;
|
|
136
161
|
while ((match = messageRegex.exec(fullResponse)) !== null) {
|
|
162
|
+
messageCount++;
|
|
137
163
|
const attrs = match[1] || '';
|
|
138
164
|
const messageContent = match[2].trim();
|
|
139
165
|
|
|
@@ -141,7 +167,8 @@ function triggerAgent(prompt: string, label: string) {
|
|
|
141
167
|
const titleMatch = attrs.match(/title="([^"]*)"/);
|
|
142
168
|
const priorityMatch = attrs.match(/priority="([^"]*)"/);
|
|
143
169
|
|
|
144
|
-
log
|
|
170
|
+
console.log(`[scheduler] Extracted message #${messageCount}: "${messageContent.slice(0, 100)}"`);
|
|
171
|
+
console.log(`[scheduler] Broadcasting bot:autonomous-message to WS clients`);
|
|
145
172
|
broadcastFluxy('bot:autonomous-message', {
|
|
146
173
|
content: messageContent,
|
|
147
174
|
source: label,
|
|
@@ -151,6 +178,7 @@ function triggerAgent(prompt: string, label: string) {
|
|
|
151
178
|
});
|
|
152
179
|
// TODO: push notification for PWA
|
|
153
180
|
}
|
|
181
|
+
console.log(`[scheduler] Total <Message> blocks extracted: ${messageCount}`);
|
|
154
182
|
|
|
155
183
|
// Strip <Message> blocks from stored response
|
|
156
184
|
const cleanedResponse = fullResponse.replace(/<Message(?:\s+[^>]*)?>[\s\S]*?<\/Message>/g, '').trim();
|
|
@@ -165,6 +193,8 @@ function triggerAgent(prompt: string, label: string) {
|
|
|
165
193
|
log.warn(`[scheduler] DB persist error: ${err.message}`);
|
|
166
194
|
});
|
|
167
195
|
}
|
|
196
|
+
} else {
|
|
197
|
+
console.log(`[scheduler] bot:done but fullResponse is EMPTY`);
|
|
168
198
|
}
|
|
169
199
|
|
|
170
200
|
log.info(`[scheduler] ${label} agent query complete`);
|
|
@@ -175,20 +205,28 @@ function triggerAgent(prompt: string, label: string) {
|
|
|
175
205
|
}
|
|
176
206
|
|
|
177
207
|
if (type === 'bot:error') {
|
|
208
|
+
console.log(`[scheduler] bot:error: ${JSON.stringify(eventData)}`);
|
|
178
209
|
log.warn(`[scheduler] ${label} agent error: ${eventData.error}`);
|
|
179
210
|
}
|
|
211
|
+
|
|
212
|
+
if (type === 'bot:tool') {
|
|
213
|
+
console.log(`[scheduler] Agent using tool: ${eventData.name}`);
|
|
214
|
+
}
|
|
180
215
|
});
|
|
181
216
|
})();
|
|
182
217
|
}
|
|
183
218
|
|
|
184
219
|
function tick() {
|
|
185
220
|
const now = Date.now();
|
|
221
|
+
console.log(`[scheduler] tick at ${new Date().toISOString()}`);
|
|
186
222
|
|
|
187
223
|
// ── Pulse check ──
|
|
188
224
|
const pulse = readPulseConfig();
|
|
225
|
+
console.log(`[scheduler] Pulse: enabled=${pulse.enabled}, interval=${pulse.intervalMinutes}min, quietHours=${isInQuietHours(pulse.quietHours)}`);
|
|
189
226
|
if (pulse.enabled && !isInQuietHours(pulse.quietHours)) {
|
|
190
227
|
const elapsed = now - lastPulseTime;
|
|
191
228
|
const intervalMs = pulse.intervalMinutes * 60 * 1000;
|
|
229
|
+
console.log(`[scheduler] Pulse elapsed: ${Math.round(elapsed / 1000)}s / ${pulse.intervalMinutes * 60}s`);
|
|
192
230
|
if (elapsed >= intervalMs) {
|
|
193
231
|
lastPulseTime = now;
|
|
194
232
|
triggerAgent('<PULSE/>', 'pulse');
|
|
@@ -197,13 +235,19 @@ function tick() {
|
|
|
197
235
|
|
|
198
236
|
// ── Cron check ──
|
|
199
237
|
const crons = readCronsConfig();
|
|
238
|
+
console.log(`[scheduler] Crons loaded: ${crons.length} entries`);
|
|
200
239
|
for (const cron of crons) {
|
|
201
|
-
if (!cron.enabled || !cron.id || !cron.schedule)
|
|
240
|
+
if (!cron.enabled || !cron.id || !cron.schedule) {
|
|
241
|
+
console.log(`[scheduler] Cron "${cron.id}" skipped: enabled=${cron.enabled}`);
|
|
242
|
+
continue;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
const matches = cronMatchesNow(cron.schedule);
|
|
246
|
+
const lastRun = lastCronRuns.get(cron.id) || 0;
|
|
247
|
+
const oneMinuteAgo = now - 60_000;
|
|
248
|
+
console.log(`[scheduler] Cron "${cron.id}" (${cron.schedule}): matches=${matches}, lastRun=${lastRun > 0 ? Math.round((now - lastRun) / 1000) + 's ago' : 'never'}, canFire=${lastRun < oneMinuteAgo}`);
|
|
202
249
|
|
|
203
|
-
if (
|
|
204
|
-
// Prevent double-firing within the same minute
|
|
205
|
-
const lastRun = lastCronRuns.get(cron.id) || 0;
|
|
206
|
-
const oneMinuteAgo = now - 60_000;
|
|
250
|
+
if (matches) {
|
|
207
251
|
if (lastRun < oneMinuteAgo) {
|
|
208
252
|
lastCronRuns.set(cron.id, now);
|
|
209
253
|
triggerAgent(`<CRON>${cron.id}</CRON>`, cron.id);
|