@vibe-lark/larkpal 0.1.66 → 0.1.68

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 +37 -3
  2. package/package.json +1 -1
package/dist/main.mjs CHANGED
@@ -3774,6 +3774,7 @@ function serializeChatRun(run) {
3774
3774
  lastToolName: run.lastToolName,
3775
3775
  idleSeconds,
3776
3776
  adapterBusy: run.status === "running" ? run.adapterBusy : false,
3777
+ processStatus: run.processStatus,
3777
3778
  staleReason: run.staleReason
3778
3779
  };
3779
3780
  }
@@ -3917,15 +3918,45 @@ async function markRunTerminal(run, messageStore, status, params) {
3917
3918
  await appendRunStatusMessage(run, messageStore);
3918
3919
  return true;
3919
3920
  }
3921
+ async function cleanupTerminalRunProcess(run, processManager, reason) {
3922
+ if (run.status === "running") return;
3923
+ const processInfo = processManager.getProcessInfo(run.sessionId);
3924
+ const adapterBusy = processManager.isSessionBusy?.(run.sessionId) ?? processInfo?.status === "running";
3925
+ run.adapterBusy = adapterBusy;
3926
+ run.processStatus = processInfo?.status;
3927
+ if (adapterBusy || processInfo?.status !== "running" && processInfo?.status !== "starting") return;
3928
+ try {
3929
+ await processManager.stopProcess(run.sessionId);
3930
+ run.processStatus = processManager.getProcessInfo(run.sessionId)?.status ?? "stopped";
3931
+ log$30.info("[stream] terminal run 已清理 runtime process", {
3932
+ sessionId: run.sessionId,
3933
+ runId: run.runId,
3934
+ reason,
3935
+ processStatus: processInfo.status
3936
+ });
3937
+ } catch (err) {
3938
+ log$30.error("[stream] terminal run 清理 runtime process 失败", {
3939
+ sessionId: run.sessionId,
3940
+ runId: run.runId,
3941
+ reason,
3942
+ processStatus: processInfo.status,
3943
+ error: err instanceof Error ? err.message : String(err)
3944
+ });
3945
+ }
3946
+ }
3920
3947
  async function reconcileRunWithAdapter(run, messageStore, processManager) {
3921
3948
  if (run.status !== "running") return;
3922
3949
  const processInfo = processManager.getProcessInfo(run.sessionId);
3923
3950
  const adapterBusy = processManager.isSessionBusy?.(run.sessionId) ?? processInfo?.status === "running";
3924
3951
  run.adapterBusy = adapterBusy;
3952
+ run.processStatus = processInfo?.status;
3925
3953
  const idleMs = Date.now() - run.lastEventAt;
3926
3954
  let staleReason;
3927
- if (!adapterBusy) staleReason = processInfo ? `runtime process is ${processInfo.status}` : "runtime adapter reports session is not busy";
3928
- else if (idleMs >= getStaleRunIdleMs()) staleReason = `run idle for ${Math.floor(idleMs / 1e3)}s`;
3955
+ if (!adapterBusy) {
3956
+ if (!processInfo) staleReason = "runtime adapter reports session is not busy";
3957
+ else if (processInfo.status === "stopped" || processInfo.status === "crashed" || processInfo.status === "stopping") staleReason = `runtime process is ${processInfo.status}`;
3958
+ else if (idleMs >= getStaleRunIdleMs()) staleReason = `run idle for ${Math.floor(idleMs / 1e3)}s while runtime process is ${processInfo.status}`;
3959
+ } else if (idleMs >= getStaleRunIdleMs()) staleReason = `run idle for ${Math.floor(idleMs / 1e3)}s`;
3929
3960
  if (!staleReason) return;
3930
3961
  let cleanupRequired = false;
3931
3962
  if (!adapterBusy && (processInfo?.status === "running" || processInfo?.status === "starting")) {
@@ -4313,6 +4344,7 @@ function createChatRouter(config) {
4313
4344
  const finalText = run.text.trim() ? run.text : result.result || "";
4314
4345
  run.text = finalText;
4315
4346
  await markRunTerminal(run, messageStore, result.isError ? "failed" : "completed", { finalStatus: result.subtype });
4347
+ await cleanupTerminalRunProcess(run, processManager, "result");
4316
4348
  await queueRunMessage(run, messageStore, {
4317
4349
  sessionId,
4318
4350
  role: "assistant",
@@ -4397,6 +4429,7 @@ function createChatRouter(config) {
4397
4429
  finalStatus: "error",
4398
4430
  error: error.message
4399
4431
  });
4432
+ await cleanupTerminalRunProcess(run, processManager, "error");
4400
4433
  broadcastRunEvent(run, "error", {
4401
4434
  runId: run.runId,
4402
4435
  message: error.message
@@ -4468,13 +4501,14 @@ function createChatRouter(config) {
4468
4501
  finalStatus: "error",
4469
4502
  error: errorMessage
4470
4503
  });
4504
+ await cleanupTerminalRunProcess(run, processManager, "missing-result");
4471
4505
  broadcastRunEvent(run, "error", {
4472
4506
  runId: run.runId,
4473
4507
  message: errorMessage
4474
4508
  });
4475
4509
  clearInterval(heartbeatTimer);
4476
4510
  endRunClients(run);
4477
- }
4511
+ } else await cleanupTerminalRunProcess(run, processManager, "execute-returned");
4478
4512
  } catch (err) {
4479
4513
  const errorMessage = err instanceof Error ? err.message : String(err);
4480
4514
  log$30.error("[stream] executePrompt 异常", {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vibe-lark/larkpal",
3
- "version": "0.1.66",
3
+ "version": "0.1.68",
4
4
  "description": "LarkPal - Lark/Feishu bot service",
5
5
  "type": "module",
6
6
  "main": "./dist/main.mjs",