@sjawhar/pi-envoy 16.50.0 → 16.51.1
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/envoy.js +43 -19
- package/package.json +1 -1
package/dist/envoy.js
CHANGED
|
@@ -42775,7 +42775,7 @@ var import_nats2 = __toESM(require_mod4(), 1);
|
|
|
42775
42775
|
|
|
42776
42776
|
// package.json
|
|
42777
42777
|
var name = "@sjawhar/pi-envoy";
|
|
42778
|
-
var version2 = "16.
|
|
42778
|
+
var version2 = "16.51.1";
|
|
42779
42779
|
var package_default = {
|
|
42780
42780
|
name,
|
|
42781
42781
|
version: version2,
|
|
@@ -48511,6 +48511,7 @@ function envoyExtension(pi) {
|
|
|
48511
48511
|
checks: 0
|
|
48512
48512
|
};
|
|
48513
48513
|
let awarenessGeneration = 0;
|
|
48514
|
+
let armingPersonInput;
|
|
48514
48515
|
let askCheckInFlight = false;
|
|
48515
48516
|
let settledDuringCheck;
|
|
48516
48517
|
const takeSettledDuringCheck = () => {
|
|
@@ -48805,13 +48806,14 @@ function envoyExtension(pi) {
|
|
|
48805
48806
|
});
|
|
48806
48807
|
}
|
|
48807
48808
|
});
|
|
48808
|
-
const showReplayCard = (session, content, envelope, deliverAs = "card") => {
|
|
48809
|
+
const showReplayCard = async (session, content, envelope, deliverAs = "card", beforeHandOff) => {
|
|
48809
48810
|
const parsed = ClaimIdentitySchema.safeParse(envelope);
|
|
48810
48811
|
const identity = parsed.success ? parsed.data : undefined;
|
|
48811
48812
|
const claim = delivered.claim(identity);
|
|
48812
48813
|
if (claim === undefined && identity !== undefined && (delivered.pending(identity) || unwritten.waitsOnCard(identity))) {
|
|
48813
48814
|
return "queued";
|
|
48814
48815
|
}
|
|
48816
|
+
await beforeHandOff?.();
|
|
48815
48817
|
const outcome = unwritten.sendCard(session, content, deliverAs, identity, claim);
|
|
48816
48818
|
return outcome === "closed" ? "failed" : outcome;
|
|
48817
48819
|
};
|
|
@@ -48960,6 +48962,10 @@ function envoyExtension(pi) {
|
|
|
48960
48962
|
});
|
|
48961
48963
|
});
|
|
48962
48964
|
};
|
|
48965
|
+
const isHumanDispatchCard = (rendered) => {
|
|
48966
|
+
const actor = rendered.dispatchActor;
|
|
48967
|
+
return actor?.kind === "user" && actor.act === undefined;
|
|
48968
|
+
};
|
|
48963
48969
|
const acceptedUserTurn = (rendered, acceptedSessionID) => acceptUserTurn({
|
|
48964
48970
|
actorId: acceptedSessionID,
|
|
48965
48971
|
dispatch: () => timedDispatchClient(USER_TURN_ACCEPT_TIMEOUT_MS, () => acceptedSessionID),
|
|
@@ -49144,6 +49150,14 @@ ${REPLAYED_BTW_NOTE}`, "inert", identity, claim);
|
|
|
49144
49150
|
const shown = shownPictures(sessionID);
|
|
49145
49151
|
if (accepted === undefined) {
|
|
49146
49152
|
const card = await withDeliveredPictures(rendered.content, rendered.pictures ?? [], () => timedDispatchClient(DELIVERY_PICTURES_TIMEOUT_MS, () => session), true, shown);
|
|
49153
|
+
if (isHumanDispatchCard(rendered)) {
|
|
49154
|
+
let destination = cardSession();
|
|
49155
|
+
await armAskAwarenessForPersonInput(activeSessionContext, destination);
|
|
49156
|
+
while (cardSession() !== destination) {
|
|
49157
|
+
destination = cardSession();
|
|
49158
|
+
await armAskAwarenessForPersonInput(activeSessionContext, destination);
|
|
49159
|
+
}
|
|
49160
|
+
}
|
|
49147
49161
|
const outcome = unwritten.sendCard(cardSession(), card.content, rendered.delivery?.mode === "aside" ? "aside" : "card", identity, claim);
|
|
49148
49162
|
if (outcome !== "closed")
|
|
49149
49163
|
markPicturesShown(shownPictures(sessionID), card.shown);
|
|
@@ -49398,7 +49412,7 @@ ${REPLAYED_BTW_NOTE}`, "inert", identity, claim);
|
|
|
49398
49412
|
return showReplayCard(addressed, `${shown}
|
|
49399
49413
|
${REPLAYED_BTW_NOTE}`, frame.envelope, "inert");
|
|
49400
49414
|
}
|
|
49401
|
-
return showReplayCard(addressed, shown, frame.envelope);
|
|
49415
|
+
return showReplayCard(addressed, shown, frame.envelope, "card", isHumanDispatchCard(rendered) ? () => armAskAwarenessForPersonInput(activeSessionContext, addressed) : undefined);
|
|
49402
49416
|
};
|
|
49403
49417
|
const transcriptSessionID = () => {
|
|
49404
49418
|
const host = hostSessionID();
|
|
@@ -49418,7 +49432,7 @@ ${REPLAYED_BTW_NOTE}`, frame.envelope, "inert");
|
|
|
49418
49432
|
followedSubjects,
|
|
49419
49433
|
deliver: showReplayed,
|
|
49420
49434
|
showFailureNotice: async (notice) => {
|
|
49421
|
-
const outcome = showReplayCard(sessionID, envoyNoticeText(failureNoticeFields(notice)), notice.envelope, btwEvents.has(notice.eventId) ? "inert" : "card");
|
|
49435
|
+
const outcome = await showReplayCard(sessionID, envoyNoticeText(failureNoticeFields(notice)), notice.envelope, btwEvents.has(notice.eventId) ? "inert" : "card");
|
|
49422
49436
|
if (outcome === "failed")
|
|
49423
49437
|
throw new Error("the session it names is closed");
|
|
49424
49438
|
return outcome;
|
|
@@ -50515,21 +50529,9 @@ ${REPLAYED_BTW_NOTE}`, frame.envelope, "inert");
|
|
|
50515
50529
|
});
|
|
50516
50530
|
}
|
|
50517
50531
|
pi.on("before_agent_start", async (event, context) => {
|
|
50518
|
-
|
|
50519
|
-
if (id === "" || event.prompt.trim() === "" || !context.hasUI || sideTurn(context) === undefined || legionManaged(id)) {
|
|
50520
|
-
return;
|
|
50521
|
-
}
|
|
50522
|
-
if (await isSubagent(context))
|
|
50532
|
+
if (event.prompt.trim() === "")
|
|
50523
50533
|
return;
|
|
50524
|
-
|
|
50525
|
-
abortSelfCheck("a new user turn superseded the self-check");
|
|
50526
|
-
try {
|
|
50527
|
-
const open = await queryOpenAsks(id);
|
|
50528
|
-
if (open !== null)
|
|
50529
|
-
armAskAwareness(id, open.as_of);
|
|
50530
|
-
} catch (error) {
|
|
50531
|
-
warnAskAvailability(context, error);
|
|
50532
|
-
}
|
|
50534
|
+
await armAskAwarenessForPersonInput(context);
|
|
50533
50535
|
return;
|
|
50534
50536
|
});
|
|
50535
50537
|
pi.on("agent_start", async (_event, context) => {
|
|
@@ -50546,6 +50548,28 @@ ${REPLAYED_BTW_NOTE}`, frame.envelope, "inert");
|
|
|
50546
50548
|
checks: 0
|
|
50547
50549
|
};
|
|
50548
50550
|
}
|
|
50551
|
+
async function armAskAwarenessForPersonInput(context, expectedSession) {
|
|
50552
|
+
const id = context?.sessionManager.getSessionId() ?? "";
|
|
50553
|
+
if (context === undefined || id === "" || expectedSession !== undefined && id !== expectedSession || !context.hasUI || sideTurn(context) === undefined || legionManaged(id)) {
|
|
50554
|
+
return;
|
|
50555
|
+
}
|
|
50556
|
+
if (await isSubagent(context))
|
|
50557
|
+
return;
|
|
50558
|
+
const generation = ++awarenessGeneration;
|
|
50559
|
+
abortSelfCheck("a new person turn superseded the self-check");
|
|
50560
|
+
armingPersonInput = { session: id, generation };
|
|
50561
|
+
try {
|
|
50562
|
+
const open = await queryOpenAsks(id);
|
|
50563
|
+
if (open !== null && generation === awarenessGeneration && context.sessionManager.getSessionId() === id) {
|
|
50564
|
+
armAskAwareness(id, open.as_of);
|
|
50565
|
+
}
|
|
50566
|
+
} catch (error) {
|
|
50567
|
+
warnAskAvailability(context, error);
|
|
50568
|
+
} finally {
|
|
50569
|
+
if (armingPersonInput?.generation === generation)
|
|
50570
|
+
armingPersonInput = undefined;
|
|
50571
|
+
}
|
|
50572
|
+
}
|
|
50549
50573
|
pi.on("agent_end", async (event, context) => {
|
|
50550
50574
|
cardWake.agentEnd(context);
|
|
50551
50575
|
const id = context.sessionManager.getSessionId();
|
|
@@ -50585,7 +50609,7 @@ ${REPLAYED_BTW_NOTE}`, frame.envelope, "inert");
|
|
|
50585
50609
|
}
|
|
50586
50610
|
}
|
|
50587
50611
|
function checkOwed(id) {
|
|
50588
|
-
return !(shuttingDown || legionManaged(id) || askAwareness.session_id !== id || askAwareness.period === 0 || !askAwareness.check_due || askAwareness.checks >= ASK_CHECKS_PER_PERIOD || askAwareness.baseline_as_of === null);
|
|
50612
|
+
return !(shuttingDown || armingPersonInput !== undefined && armingPersonInput.session === id && armingPersonInput.generation === awarenessGeneration || legionManaged(id) || askAwareness.session_id !== id || askAwareness.period === 0 || !askAwareness.check_due || askAwareness.checks >= ASK_CHECKS_PER_PERIOD || askAwareness.baseline_as_of === null);
|
|
50589
50613
|
}
|
|
50590
50614
|
async function checkAtSettle(id, settle) {
|
|
50591
50615
|
const { context, ask, seenRun, generation } = settle;
|