@vibe-lark/larkpal 0.1.82 → 0.1.83

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.
Files changed (2) hide show
  1. package/dist/main.mjs +22 -4
  2. package/package.json +1 -1
package/dist/main.mjs CHANGED
@@ -4473,10 +4473,13 @@ async function reconcileRunWithAdapter(run, messageStore, processManager) {
4473
4473
  } else if (idleMs >= getStaleRunIdleMs()) staleReason = `run idle for ${Math.floor(idleMs / 1e3)}s`;
4474
4474
  if (!staleReason) return;
4475
4475
  let cleanupRequired = false;
4476
- if (!adapterBusy && (processInfo?.status === "running" || processInfo?.status === "starting")) {
4476
+ if (processInfo?.status === "running" || processInfo?.status === "starting") {
4477
4477
  cleanupRequired = true;
4478
4478
  try {
4479
4479
  await processManager.stopProcess(run.sessionId);
4480
+ const stoppedInfo = processManager.getProcessInfo(run.sessionId);
4481
+ run.adapterBusy = processManager.isSessionBusy?.(run.sessionId) ?? false;
4482
+ run.processStatus = stoppedInfo?.status ?? "stopped";
4480
4483
  log$30.warn("[stream] stale run 已触发 runtime process 清理", {
4481
4484
  sessionId: run.sessionId,
4482
4485
  runId: run.runId,
@@ -4516,6 +4519,16 @@ async function reconcileRunWithAdapter(run, messageStore, processManager) {
4516
4519
  endRunClients(run);
4517
4520
  }
4518
4521
  }
4522
+ async function reconcileActiveChatRuns(messageStore, processManager, sessionIds) {
4523
+ const targetSessionIds = sessionIds ? new Set(sessionIds) : void 0;
4524
+ const tasks = [];
4525
+ for (const run of chatRunsBySession.values()) {
4526
+ if (run.status !== "running") continue;
4527
+ if (targetSessionIds && !targetSessionIds.has(run.sessionId)) continue;
4528
+ tasks.push(reconcileRunWithAdapter(run, messageStore, processManager));
4529
+ }
4530
+ await Promise.all(tasks);
4531
+ }
4519
4532
  function buildRuntimeEventMessageMetadata(event, runtimeConfig) {
4520
4533
  return {
4521
4534
  runtimeEventType: event.type,
@@ -8503,6 +8516,7 @@ function createStatusRouter(config) {
8503
8516
  const sessionsDir = getWorkspaceChatsRoot(config?.workspaceRoot ?? resolveWorkspaceRoot("/workspace"));
8504
8517
  const processManager = config?.processManager;
8505
8518
  const messageStore = config?.messageStore;
8519
+ const reconcileActiveRuns = config?.reconcileActiveRuns;
8506
8520
  router.get("/sessions", async (req, res) => {
8507
8521
  logger$2.info("list sessions request", {
8508
8522
  method: req.method,
@@ -8603,7 +8617,7 @@ function createStatusRouter(config) {
8603
8617
  try {
8604
8618
  const uptimeSeconds = process.uptime();
8605
8619
  const memory = process.memoryUsage();
8606
- const { processes, diagnostics } = processManager ? await serializeRuntimeProcesses(processManager, messageStore) : {
8620
+ const { processes, diagnostics } = processManager ? await serializeRuntimeProcesses(processManager, messageStore, reconcileActiveRuns) : {
8607
8621
  processes: [],
8608
8622
  diagnostics: []
8609
8623
  };
@@ -8660,9 +8674,11 @@ function createStatusRouter(config) {
8660
8674
  });
8661
8675
  return router;
8662
8676
  }
8663
- async function serializeRuntimeProcesses(processManager, messageStore) {
8677
+ async function serializeRuntimeProcesses(processManager, messageStore, reconcileActiveRuns) {
8664
8678
  const processes = [];
8665
8679
  const diagnostics = [];
8680
+ const processSnapshot = processManager.getAllProcessInfo();
8681
+ if (reconcileActiveRuns) await reconcileActiveRuns(processSnapshot.map((processInfo) => processInfo.sessionId));
8666
8682
  for (const processInfo of processManager.getAllProcessInfo()) {
8667
8683
  const busy = processManager.isSessionBusy?.(processInfo.sessionId) ?? processInfo.status === "running";
8668
8684
  const terminalRunStatus = messageStore ? await getLatestTerminalRunStatus(messageStore, processInfo.sessionId) : null;
@@ -8695,6 +8711,7 @@ async function serializeRuntimeProcesses(processManager, messageStore) {
8695
8711
  });
8696
8712
  continue;
8697
8713
  }
8714
+ if (terminalRunStatus && !busy && (processInfo.status === "stopped" || processInfo.status === "crashed" || processInfo.status === "stopping")) continue;
8698
8715
  processes.push(serializeRuntimeProcess(processInfo, processManager));
8699
8716
  }
8700
8717
  return {
@@ -8801,7 +8818,8 @@ function registerRoutes(app, processManager, scheduledTaskManager, appCredential
8801
8818
  app.use("/api", createStatusRouter({
8802
8819
  workspaceRoot,
8803
8820
  processManager,
8804
- messageStore
8821
+ messageStore,
8822
+ reconcileActiveRuns: processManager && messageStore ? (sessionIds) => reconcileActiveChatRuns(messageStore, processManager, sessionIds) : void 0
8805
8823
  }));
8806
8824
  app.use("/hooks", createHooksRouter());
8807
8825
  app.use("/api/mcp", createMcpCallbackRouter());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vibe-lark/larkpal",
3
- "version": "0.1.82",
3
+ "version": "0.1.83",
4
4
  "description": "LarkPal - Lark/Feishu bot service",
5
5
  "type": "module",
6
6
  "main": "./dist/main.mjs",