@agent-idle/cli 0.1.0 → 0.1.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/index.js +55 -8
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -170,7 +170,7 @@ function persistedConvexUrl() {
|
|
|
170
170
|
}
|
|
171
171
|
}
|
|
172
172
|
var BUILD_CONVEX_URL = "https://handsome-camel-783.convex.cloud";
|
|
173
|
-
var BUILD_AUTH_URL = "https://agent-idle
|
|
173
|
+
var BUILD_AUTH_URL = "https://agent-idle.com";
|
|
174
174
|
var LOCAL_CONVEX_URL = "http://127.0.0.1:3210";
|
|
175
175
|
function resolveConvexUrl() {
|
|
176
176
|
return process.env.CONVEX_URL ?? persistedConvexUrl() ?? BUILD_CONVEX_URL ?? LOCAL_CONVEX_URL;
|
|
@@ -412,6 +412,32 @@ function topicWord(prompt) {
|
|
|
412
412
|
return pool.reduce((best, w) => w.length > best.length ? w : best, "");
|
|
413
413
|
}
|
|
414
414
|
var ingestEvent = makeFunctionReference("events:ingestEvent");
|
|
415
|
+
var ingestEvents = makeFunctionReference("events:ingestEvents");
|
|
416
|
+
var FLUSH_CHUNK = 100;
|
|
417
|
+
function isPureRenewal(item) {
|
|
418
|
+
if (item.type !== "activity") return false;
|
|
419
|
+
const p = item.payload;
|
|
420
|
+
if (!p || typeof p !== "object") return false;
|
|
421
|
+
const keys = Object.keys(p);
|
|
422
|
+
return p.working === true && keys.every((k) => k === "working" || k === "action");
|
|
423
|
+
}
|
|
424
|
+
function coalesceRenewals(items) {
|
|
425
|
+
const keep = new Array(items.length).fill(true);
|
|
426
|
+
const lastRenewal = /* @__PURE__ */ new Map();
|
|
427
|
+
items.forEach((item, i) => {
|
|
428
|
+
if (isPureRenewal(item)) {
|
|
429
|
+
const prev = lastRenewal.get(item.sessionId);
|
|
430
|
+
const prevItem = prev === void 0 ? void 0 : items[prev];
|
|
431
|
+
if (prevItem && prevItem.payload?.action === item.payload?.action) {
|
|
432
|
+
keep[prev] = false;
|
|
433
|
+
}
|
|
434
|
+
lastRenewal.set(item.sessionId, i);
|
|
435
|
+
} else {
|
|
436
|
+
lastRenewal.delete(item.sessionId);
|
|
437
|
+
}
|
|
438
|
+
});
|
|
439
|
+
return items.filter((_, i) => keep[i]);
|
|
440
|
+
}
|
|
415
441
|
function classifyToolAction(toolName) {
|
|
416
442
|
switch (toolName) {
|
|
417
443
|
case "Bash":
|
|
@@ -794,13 +820,34 @@ function startDaemon() {
|
|
|
794
820
|
const client = new ConvexHttpClient(convexUrl);
|
|
795
821
|
client.setAuth(token);
|
|
796
822
|
const remaining = [];
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
823
|
+
const queue = coalesceRenewals(items);
|
|
824
|
+
let batchSupported = true;
|
|
825
|
+
for (let i = 0; i < queue.length; i += FLUSH_CHUNK) {
|
|
826
|
+
const chunk = queue.slice(i, i + FLUSH_CHUNK);
|
|
827
|
+
if (batchSupported) {
|
|
828
|
+
try {
|
|
829
|
+
const res = await client.mutation(ingestEvents, { events: chunk });
|
|
830
|
+
debug(` batch of ${chunk.length} \u2192`, res);
|
|
831
|
+
continue;
|
|
832
|
+
} catch (err) {
|
|
833
|
+
const msg = err?.message ?? String(err);
|
|
834
|
+
if (!/Could not find public function/i.test(msg)) {
|
|
835
|
+
remaining.push(...chunk);
|
|
836
|
+
debug(` batch of ${chunk.length} FAILED:`, msg);
|
|
837
|
+
continue;
|
|
838
|
+
}
|
|
839
|
+
batchSupported = false;
|
|
840
|
+
debug(" batch unsupported by backend \u2014 falling back to per-event");
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
for (const item of chunk) {
|
|
844
|
+
try {
|
|
845
|
+
const res = await client.mutation(ingestEvent, item);
|
|
846
|
+
debug(` ${item.type} session=${tag(item.sessionId)} \u2192`, res);
|
|
847
|
+
} catch (err) {
|
|
848
|
+
remaining.push(item);
|
|
849
|
+
debug(` ${item.type} session=${tag(item.sessionId)} FAILED:`, err?.message ?? err);
|
|
850
|
+
}
|
|
804
851
|
}
|
|
805
852
|
}
|
|
806
853
|
writeOutbox(remaining);
|