@vibe-lark/larkpal 0.1.64 → 0.1.66
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/main.mjs +54 -4
- package/package.json +1 -1
package/dist/main.mjs
CHANGED
|
@@ -3777,6 +3777,30 @@ function serializeChatRun(run) {
|
|
|
3777
3777
|
staleReason: run.staleReason
|
|
3778
3778
|
};
|
|
3779
3779
|
}
|
|
3780
|
+
function serializeRuntimeProcessInfo(processInfo, processManager) {
|
|
3781
|
+
return {
|
|
3782
|
+
...processInfo,
|
|
3783
|
+
startedAt: processInfo.startedAt.toISOString(),
|
|
3784
|
+
lastActiveAt: processInfo.lastActiveAt.toISOString(),
|
|
3785
|
+
busy: processManager.isSessionBusy?.(processInfo.sessionId) ?? processInfo.status === "running"
|
|
3786
|
+
};
|
|
3787
|
+
}
|
|
3788
|
+
function buildOrphanedRunDiagnostic(sessionId, processManager) {
|
|
3789
|
+
const processInfo = processManager.getProcessInfo(sessionId);
|
|
3790
|
+
const adapterBusy = processManager.isSessionBusy?.(sessionId) ?? processInfo?.status === "running";
|
|
3791
|
+
if (!processInfo && !adapterBusy) return null;
|
|
3792
|
+
return {
|
|
3793
|
+
runId: null,
|
|
3794
|
+
sessionId,
|
|
3795
|
+
status: adapterBusy ? "orphaned" : "inconsistent",
|
|
3796
|
+
finalStatus: adapterBusy ? "orphaned" : "inconsistent",
|
|
3797
|
+
reasonCode: "RUN_REGISTRY_MISSING",
|
|
3798
|
+
reason: "Runtime process exists or reports busy, but gateway chat run registry has no visible run for this session.",
|
|
3799
|
+
processStatus: processInfo?.status,
|
|
3800
|
+
adapterBusy,
|
|
3801
|
+
process: processInfo ? serializeRuntimeProcessInfo(processInfo, processManager) : void 0
|
|
3802
|
+
};
|
|
3803
|
+
}
|
|
3780
3804
|
function getRuntimeEventDedupeKey(event) {
|
|
3781
3805
|
const record = event;
|
|
3782
3806
|
const eventId = record.eventId;
|
|
@@ -3903,6 +3927,27 @@ async function reconcileRunWithAdapter(run, messageStore, processManager) {
|
|
|
3903
3927
|
if (!adapterBusy) staleReason = processInfo ? `runtime process is ${processInfo.status}` : "runtime adapter reports session is not busy";
|
|
3904
3928
|
else if (idleMs >= getStaleRunIdleMs()) staleReason = `run idle for ${Math.floor(idleMs / 1e3)}s`;
|
|
3905
3929
|
if (!staleReason) return;
|
|
3930
|
+
let cleanupRequired = false;
|
|
3931
|
+
if (!adapterBusy && (processInfo?.status === "running" || processInfo?.status === "starting")) {
|
|
3932
|
+
cleanupRequired = true;
|
|
3933
|
+
try {
|
|
3934
|
+
await processManager.stopProcess(run.sessionId);
|
|
3935
|
+
log$30.warn("[stream] stale run 已触发 runtime process 清理", {
|
|
3936
|
+
sessionId: run.sessionId,
|
|
3937
|
+
runId: run.runId,
|
|
3938
|
+
staleReason,
|
|
3939
|
+
processStatus: processInfo.status
|
|
3940
|
+
});
|
|
3941
|
+
} catch (err) {
|
|
3942
|
+
log$30.error("[stream] stale run 清理 runtime process 失败", {
|
|
3943
|
+
sessionId: run.sessionId,
|
|
3944
|
+
runId: run.runId,
|
|
3945
|
+
staleReason,
|
|
3946
|
+
processStatus: processInfo.status,
|
|
3947
|
+
error: err instanceof Error ? err.message : String(err)
|
|
3948
|
+
});
|
|
3949
|
+
}
|
|
3950
|
+
}
|
|
3906
3951
|
const error = `Chat run became stale: ${staleReason}`;
|
|
3907
3952
|
log$30.warn("[stream] activeRun 与 runtime 状态不一致,标记为 stale", {
|
|
3908
3953
|
sessionId: run.sessionId,
|
|
@@ -3910,7 +3955,8 @@ async function reconcileRunWithAdapter(run, messageStore, processManager) {
|
|
|
3910
3955
|
staleReason,
|
|
3911
3956
|
idleMs,
|
|
3912
3957
|
adapterBusy,
|
|
3913
|
-
processStatus: processInfo?.status
|
|
3958
|
+
processStatus: processInfo?.status,
|
|
3959
|
+
cleanupRequired
|
|
3914
3960
|
});
|
|
3915
3961
|
if (await markRunTerminal(run, messageStore, "failed", {
|
|
3916
3962
|
finalStatus: "stale",
|
|
@@ -4465,12 +4511,14 @@ function createChatRouter(config) {
|
|
|
4465
4511
|
openId: chatUser.openId
|
|
4466
4512
|
}) ? run : void 0;
|
|
4467
4513
|
if (visibleRun) await reconcileRunWithAdapter(visibleRun, messageStore, processManager);
|
|
4514
|
+
const runDiagnostic = visibleRun ? null : buildOrphanedRunDiagnostic(sessionId, processManager);
|
|
4468
4515
|
res.json({
|
|
4469
4516
|
messages: result.messages,
|
|
4470
4517
|
nextCursor: result.nextCursor,
|
|
4471
4518
|
sessionId,
|
|
4472
4519
|
activeRun: visibleRun?.status === "running" ? serializeChatRun(visibleRun) : null,
|
|
4473
|
-
latestRun: visibleRun ? serializeChatRun(visibleRun) :
|
|
4520
|
+
latestRun: visibleRun ? serializeChatRun(visibleRun) : runDiagnostic,
|
|
4521
|
+
runDiagnostic
|
|
4474
4522
|
});
|
|
4475
4523
|
} catch (err) {
|
|
4476
4524
|
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
@@ -4493,10 +4541,12 @@ function createChatRouter(config) {
|
|
|
4493
4541
|
tenantKey: chatUser.tenantKey,
|
|
4494
4542
|
openId: chatUser.openId
|
|
4495
4543
|
})) {
|
|
4544
|
+
const runDiagnostic = buildOrphanedRunDiagnostic(sessionId, processManager);
|
|
4496
4545
|
res.json({
|
|
4497
4546
|
sessionId,
|
|
4498
|
-
run:
|
|
4499
|
-
activeRun: null
|
|
4547
|
+
run: runDiagnostic,
|
|
4548
|
+
activeRun: null,
|
|
4549
|
+
runDiagnostic
|
|
4500
4550
|
});
|
|
4501
4551
|
return;
|
|
4502
4552
|
}
|