agent-ticketing 0.1.4 → 0.1.5
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/runner.js +35 -14
- package/package.json +1 -1
package/dist/runner.js
CHANGED
|
@@ -446,6 +446,10 @@ function repliesSince(messages) {
|
|
|
446
446
|
const fresh = messages.slice(lastAgent + 1).filter((m) => m.kind === "message" && m.author.type === "human");
|
|
447
447
|
return fresh.map((m) => m.body).join("\n\n");
|
|
448
448
|
}
|
|
449
|
+
// Live-step shipping cadence: min ms between ⚙ progress posts (each is a
|
|
450
|
+
// permanent thread row + an HTTP call, and Claude bursts tool calls) — but
|
|
451
|
+
// trailing-edge: the LATEST step always ships once the window opens.
|
|
452
|
+
const STEP_INTERVAL_MS = Math.max(2_000, Number(process.env.MAILBOX_STEP_INTERVAL_MS ?? "7000"));
|
|
449
453
|
const MAX_DELIVERABLES = 10; // server cap: attachments per message
|
|
450
454
|
const MAX_DELIVERABLE_BYTES = 25 * 1024 * 1024;
|
|
451
455
|
const MIME_BY_EXT = {
|
|
@@ -485,16 +489,40 @@ async function workTicket(ticket, ctx) {
|
|
|
485
489
|
(previous ? " (resumed)" : "") +
|
|
486
490
|
(attachmentPaths.length > 0 ? ` (${attachmentPaths.length} attachment(s) downloaded)` : ""));
|
|
487
491
|
// Live peek: steps from the session JSONL → throttled ⚙ entries on the ticket.
|
|
492
|
+
// Trailing-edge throttle: never more often than STEP_INTERVAL_MS, but the
|
|
493
|
+
// latest step is never lost — it ships when the window reopens.
|
|
488
494
|
let lastShipped = 0;
|
|
489
495
|
let lastLabel = "";
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
lastShipped = now;
|
|
496
|
+
let pending = null;
|
|
497
|
+
let pendingTimer = null;
|
|
498
|
+
const ship = (label) => {
|
|
499
|
+
lastShipped = Date.now();
|
|
495
500
|
lastLabel = label;
|
|
496
501
|
ctx.progress(label).catch(() => undefined); // heartbeat + visible step; best-effort
|
|
497
|
-
}
|
|
502
|
+
};
|
|
503
|
+
const onStep = (label) => {
|
|
504
|
+
if (label === lastLabel || label === pending)
|
|
505
|
+
return;
|
|
506
|
+
const wait = lastShipped + STEP_INTERVAL_MS - Date.now();
|
|
507
|
+
if (wait <= 0)
|
|
508
|
+
return ship(label);
|
|
509
|
+
pending = label;
|
|
510
|
+
if (!pendingTimer) {
|
|
511
|
+
pendingTimer = setTimeout(() => {
|
|
512
|
+
pendingTimer = null;
|
|
513
|
+
const p = pending;
|
|
514
|
+
pending = null;
|
|
515
|
+
if (p && p !== lastLabel)
|
|
516
|
+
ship(p);
|
|
517
|
+
}, wait);
|
|
518
|
+
}
|
|
519
|
+
};
|
|
520
|
+
const stopWatch0 = watchClaudeSession(sessionId, onStep);
|
|
521
|
+
const stopWatch = () => {
|
|
522
|
+
stopWatch0();
|
|
523
|
+
if (pendingTimer)
|
|
524
|
+
clearTimeout(pendingTimer);
|
|
525
|
+
};
|
|
498
526
|
const freshPrompt = promptFor(ticket, ctx.messages, attachmentPaths);
|
|
499
527
|
const resumePrompt = `The requester replied on the ticket you were working:\n\n${repliesSince(ctx.messages)}\n\n` +
|
|
500
528
|
`Continue the task. Reply with your final result (it is posted back as the ticket resolution), ` +
|
|
@@ -508,14 +536,7 @@ async function workTicket(ticket, ctx) {
|
|
|
508
536
|
stopWatch();
|
|
509
537
|
const freshId = crypto.randomUUID();
|
|
510
538
|
await ctx.progress(`previous session gone — fresh headless Claude Code session ${freshId}`);
|
|
511
|
-
const stopWatch2 = watchClaudeSession(freshId,
|
|
512
|
-
const now = Date.now();
|
|
513
|
-
if (label === lastLabel || now - lastShipped < 7_000)
|
|
514
|
-
return;
|
|
515
|
-
lastShipped = now;
|
|
516
|
-
lastLabel = label;
|
|
517
|
-
ctx.progress(label).catch(() => undefined);
|
|
518
|
-
});
|
|
539
|
+
const stopWatch2 = watchClaudeSession(freshId, onStep);
|
|
519
540
|
try {
|
|
520
541
|
outcome = await runClaude(freshPrompt, { newId: freshId }, ctx.signal);
|
|
521
542
|
}
|
package/package.json
CHANGED