@agentchatme/agent-core 0.0.1313 → 0.0.13131
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/README.md +8 -2
- package/dist/{chunk-27XDHOL3.js → chunk-M2X5WY7Q.js} +20 -2
- package/dist/chunk-M2X5WY7Q.js.map +1 -0
- package/dist/daemon-entry.d.ts +14 -5
- package/dist/daemon-entry.js +64 -28
- package/dist/daemon-entry.js.map +1 -1
- package/dist/index.d.ts +18 -8
- package/dist/index.js +43 -8
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-27XDHOL3.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
clearAlwaysOnOptOut,
|
|
21
21
|
clearAlwaysOnWanted,
|
|
22
22
|
clearCredentials,
|
|
23
|
+
clearForegroundTurn,
|
|
23
24
|
clearPending,
|
|
24
25
|
clearSessionActive,
|
|
25
26
|
contextOf,
|
|
@@ -33,6 +34,7 @@ import {
|
|
|
33
34
|
markAlwaysOnInstalledVersion,
|
|
34
35
|
markAlwaysOnOptOut,
|
|
35
36
|
markAlwaysOnWanted,
|
|
37
|
+
markForegroundTurn,
|
|
36
38
|
markSessionActive,
|
|
37
39
|
pendingPath,
|
|
38
40
|
readAlwaysOnInstalledVersion,
|
|
@@ -47,7 +49,7 @@ import {
|
|
|
47
49
|
syncPeek,
|
|
48
50
|
writeCredentials,
|
|
49
51
|
writePending
|
|
50
|
-
} from "./chunk-
|
|
52
|
+
} from "./chunk-M2X5WY7Q.js";
|
|
51
53
|
|
|
52
54
|
// src/identity/state.ts
|
|
53
55
|
var SESSION_TTL_MS = 48 * 60 * 60 * 1e3;
|
|
@@ -431,6 +433,7 @@ function renderDeclinedBlock(copy) {
|
|
|
431
433
|
var SESSION_START_PEEK_LIMIT = 100;
|
|
432
434
|
var STOP_PEEK_LIMIT = 50;
|
|
433
435
|
var DEFAULT_MAX_CONTINUATIONS = 5;
|
|
436
|
+
var FOREGROUND_TURN_TTL_SECONDS = 600;
|
|
434
437
|
function hooksDisabled() {
|
|
435
438
|
return process.env["AGENTCHAT_HOOKS_ENABLED"] === "0";
|
|
436
439
|
}
|
|
@@ -487,7 +490,6 @@ async function sessionStart(ctx, input) {
|
|
|
487
490
|
return none;
|
|
488
491
|
}
|
|
489
492
|
const cfg = { apiKey: identity.apiKey, apiBase: identity.apiBase };
|
|
490
|
-
await markSessionActive(cfg);
|
|
491
493
|
const h = alwaysOnHealth(ctx.home);
|
|
492
494
|
const alert = h.wanted && !h.healthy ? formatAlwaysOnDown(ctx.copy) : null;
|
|
493
495
|
const peeked = ackableRows(await syncPeek(cfg, { limit: SESSION_START_PEEK_LIMIT }));
|
|
@@ -511,9 +513,10 @@ async function userPrompt(ctx, input) {
|
|
|
511
513
|
if (hooksDisabled()) return;
|
|
512
514
|
const identity = resolveIdentity(ctx.home);
|
|
513
515
|
if (identity === null) return;
|
|
516
|
+
const cfg = { apiKey: identity.apiKey, apiBase: identity.apiBase };
|
|
517
|
+
await markForegroundTurn(cfg, input.sessionId, FOREGROUND_TURN_TTL_SECONDS);
|
|
514
518
|
const cursor = takePendingAck(ctx.home, input.sessionId);
|
|
515
519
|
if (cursor === null) return;
|
|
516
|
-
const cfg = { apiKey: identity.apiKey, apiBase: identity.apiBase };
|
|
517
520
|
try {
|
|
518
521
|
await syncAck(cfg, cursor);
|
|
519
522
|
} catch (err) {
|
|
@@ -527,43 +530,64 @@ async function userPrompt(ctx, input) {
|
|
|
527
530
|
async function stop(ctx, input) {
|
|
528
531
|
const none = { reason: null, commit: async () => {
|
|
529
532
|
} };
|
|
533
|
+
let cfg = null;
|
|
530
534
|
try {
|
|
531
535
|
if (hooksDisabled()) return none;
|
|
532
536
|
const identity = resolveIdentity(ctx.home);
|
|
533
537
|
if (identity === null) return none;
|
|
534
|
-
|
|
535
|
-
await
|
|
538
|
+
cfg = { apiKey: identity.apiKey, apiBase: identity.apiBase };
|
|
539
|
+
await markForegroundTurn(cfg, input.sessionId, FOREGROUND_TURN_TTL_SECONDS);
|
|
536
540
|
const cap = maxContinuations();
|
|
537
541
|
if (getContinuations(ctx.home, input.sessionId) >= cap) {
|
|
538
542
|
log.info(
|
|
539
543
|
`stop hook: continuation cap (${cap}) reached for ${input.sessionId}; leaving inbox queued`
|
|
540
544
|
);
|
|
545
|
+
await clearForegroundTurn(cfg, input.sessionId);
|
|
541
546
|
return none;
|
|
542
547
|
}
|
|
543
548
|
const peeked = ackableRows(await syncPeek(cfg, { limit: STOP_PEEK_LIMIT }));
|
|
544
|
-
if (peeked.length === 0)
|
|
549
|
+
if (peeked.length === 0) {
|
|
550
|
+
await clearForegroundTurn(cfg, input.sessionId);
|
|
551
|
+
return none;
|
|
552
|
+
}
|
|
545
553
|
const rows = await claimContiguousPrefix(cfg, peeked, `session:${input.sessionId}`);
|
|
546
|
-
if (rows.length === 0)
|
|
554
|
+
if (rows.length === 0) {
|
|
555
|
+
await clearForegroundTurn(cfg, input.sessionId);
|
|
556
|
+
return none;
|
|
557
|
+
}
|
|
547
558
|
recordContinuation(ctx.home, input.sessionId);
|
|
548
559
|
const handle = await resolveHandle(cfg, identity.handle);
|
|
549
560
|
const reason = formatStopPickup(handle, rows);
|
|
550
561
|
const cursor = lastDeliveryId(rows);
|
|
562
|
+
const claimedCfg = cfg;
|
|
551
563
|
return {
|
|
552
564
|
reason,
|
|
553
565
|
commit: async () => {
|
|
554
566
|
if (cursor === null) return;
|
|
555
567
|
try {
|
|
556
|
-
await syncAck(
|
|
568
|
+
await syncAck(claimedCfg, cursor);
|
|
557
569
|
} catch (err) {
|
|
558
570
|
log.warn(`stop ack failed (messages stay queued): ${String(err)}`);
|
|
559
571
|
}
|
|
560
572
|
}
|
|
561
573
|
};
|
|
562
574
|
} catch (err) {
|
|
575
|
+
if (cfg !== null) await clearForegroundTurn(cfg, input.sessionId);
|
|
563
576
|
log.warn(`stop hook degraded to no-op: ${String(err)}`);
|
|
564
577
|
return none;
|
|
565
578
|
}
|
|
566
579
|
}
|
|
580
|
+
async function sessionEnd(ctx, input) {
|
|
581
|
+
try {
|
|
582
|
+
if (hooksDisabled()) return;
|
|
583
|
+
const identity = resolveIdentity(ctx.home);
|
|
584
|
+
if (identity === null) return;
|
|
585
|
+
const cfg = { apiKey: identity.apiKey, apiBase: identity.apiBase };
|
|
586
|
+
await clearForegroundTurn(cfg, input.sessionId);
|
|
587
|
+
} catch (err) {
|
|
588
|
+
log.warn(`session-end hook degraded to no-op: ${String(err)}`);
|
|
589
|
+
}
|
|
590
|
+
}
|
|
567
591
|
|
|
568
592
|
// src/hooks/hook-input.ts
|
|
569
593
|
async function readHookInput(stream = process.stdin) {
|
|
@@ -633,6 +657,14 @@ function createHookRunners(context, dialect) {
|
|
|
633
657
|
} catch (err) {
|
|
634
658
|
log.warn(`stop hook degraded to no-op: ${String(err)}`);
|
|
635
659
|
}
|
|
660
|
+
},
|
|
661
|
+
async runSessionEnd() {
|
|
662
|
+
try {
|
|
663
|
+
const input = await readHookInput();
|
|
664
|
+
await sessionEnd(context(), input);
|
|
665
|
+
} catch (err) {
|
|
666
|
+
log.warn(`session-end hook degraded to no-op: ${String(err)}`);
|
|
667
|
+
}
|
|
636
668
|
}
|
|
637
669
|
};
|
|
638
670
|
}
|
|
@@ -1681,6 +1713,7 @@ export {
|
|
|
1681
1713
|
clearAlwaysOnOptOut,
|
|
1682
1714
|
clearAlwaysOnWanted,
|
|
1683
1715
|
clearCredentials,
|
|
1716
|
+
clearForegroundTurn,
|
|
1684
1717
|
clearOfferDeclined,
|
|
1685
1718
|
clearPending,
|
|
1686
1719
|
clearSessionActive,
|
|
@@ -1705,6 +1738,7 @@ export {
|
|
|
1705
1738
|
markAlwaysOnInstalledVersion,
|
|
1706
1739
|
markAlwaysOnOptOut,
|
|
1707
1740
|
markAlwaysOnWanted,
|
|
1741
|
+
markForegroundTurn,
|
|
1708
1742
|
markSessionActive,
|
|
1709
1743
|
offerDeclined,
|
|
1710
1744
|
pendingPath,
|
|
@@ -1732,6 +1766,7 @@ export {
|
|
|
1732
1766
|
serviceDefinitionCurrent,
|
|
1733
1767
|
serviceInstalled,
|
|
1734
1768
|
serviceStatus,
|
|
1769
|
+
sessionEnd,
|
|
1735
1770
|
sessionStart,
|
|
1736
1771
|
setPendingAck,
|
|
1737
1772
|
shouldOfferRegistration,
|