replicas-engine 0.1.1094 → 0.1.1095

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.
@@ -8,9 +8,9 @@ import {
8
8
  listRunningCodexModels,
9
9
  restartCodexAspHost,
10
10
  restartCodexAspHostIfRunning
11
- } from "./chunk-SDR2RVKV.js";
11
+ } from "./chunk-IJZVNH2K.js";
12
12
  import "./chunk-QU7RJJ5E.js";
13
- import "./chunk-5ZJEUCSE.js";
13
+ import "./chunk-4VVCCZZK.js";
14
14
  import "./chunk-B4M37E6B.js";
15
15
  import "./chunk-UZSNFLDQ.js";
16
16
  import "./chunk-PN6QVQJF.js";
@@ -240,7 +240,7 @@ function getCodexModelProvider(method) {
240
240
  if (method === "foundry") return "azure";
241
241
  return method === "ollama" || method === "openai-compatible" ? "replicas_openai_compatible" : "openai";
242
242
  }
243
- var ENGINE_PACKAGE_VERSION = "0.1.1094";
243
+ var ENGINE_PACKAGE_VERSION = "0.1.1095";
244
244
  var INITIALIZE_METHOD = "initialize";
245
245
  var INITIALIZED_NOTIFICATION = "initialized";
246
246
  var ACCOUNT_LOGIN_START_METHOD = "account/login/start";
@@ -14,7 +14,7 @@ import {
14
14
  import {
15
15
  AppServerProcess,
16
16
  buildCodexAgentEnv
17
- } from "./chunk-5ZJEUCSE.js";
17
+ } from "./chunk-4VVCCZZK.js";
18
18
  import {
19
19
  SUBPROCESS_MAX_BUFFER,
20
20
  execFileAsync
@@ -291,7 +291,7 @@ var CodexTokenManager = class extends BaseRefreshManager {
291
291
  await this.applyCredentialUpdate(++this.credentialGeneration, async () => {
292
292
  await this.applyCredentialsResponse(data);
293
293
  setAgentCredentialSnapshot("codex", data);
294
- const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-VZODH5FY.js");
294
+ const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-YAOSPHKC.js");
295
295
  await restartCodexAspHostIfRunning2();
296
296
  });
297
297
  await this.start(true);
@@ -312,7 +312,7 @@ var CodexTokenManager = class extends BaseRefreshManager {
312
312
  const accountChanged = ENGINE_ENV.REPLICAS_AGENT_CREDENTIALS.codex?.credentialId !== data.credentialId;
313
313
  await this.applyCredentialsResponse(data);
314
314
  if (restartOnChange && (accountChanged || CODEX_AUTH_ENV_KEYS.some((key, index) => process.env[key] !== previousEnv[index]))) {
315
- const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-VZODH5FY.js");
315
+ const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-YAOSPHKC.js");
316
316
  await restartCodexAspHostIfRunning2();
317
317
  }
318
318
  setAgentCredentialSnapshot("codex", data);
@@ -3,7 +3,7 @@ import { createRequire as __createRequire } from 'node:module';
3
3
  const require = __createRequire(import.meta.url);
4
4
  import {
5
5
  AspClient
6
- } from "./chunk-5ZJEUCSE.js";
6
+ } from "./chunk-4VVCCZZK.js";
7
7
  import {
8
8
  ASTER_BASE_URL,
9
9
  ASTER_PROVIDER,
@@ -13,11 +13,11 @@ import {
13
13
  recoverCompletedTurn,
14
14
  spawnMuseMsp,
15
15
  startMuseSession
16
- } from "./chunk-52XEVGOZ.js";
16
+ } from "./chunk-QCL7XPUC.js";
17
17
  import {
18
18
  AppServerProcess,
19
19
  buildCodexAgentEnv
20
- } from "./chunk-5ZJEUCSE.js";
20
+ } from "./chunk-4VVCCZZK.js";
21
21
  import "./chunk-B4M37E6B.js";
22
22
  import {
23
23
  AGENT,
package/dist/src/index.js CHANGED
@@ -64,7 +64,7 @@ import {
64
64
  spawnMuseMsp,
65
65
  startMuseSession,
66
66
  uuidV7
67
- } from "./chunk-52XEVGOZ.js";
67
+ } from "./chunk-QCL7XPUC.js";
68
68
  import {
69
69
  publishedPullRequestUrls
70
70
  } from "./chunk-FJGLCQ32.js";
@@ -130,7 +130,7 @@ import {
130
130
  timestampFromSeconds,
131
131
  upsertCredentialFileLines,
132
132
  writeSecureCredentialFile
133
- } from "./chunk-SDR2RVKV.js";
133
+ } from "./chunk-IJZVNH2K.js";
134
134
  import {
135
135
  ENGINE_ENV,
136
136
  monolithRequest,
@@ -142,7 +142,7 @@ import {
142
142
  } from "./chunk-QU7RJJ5E.js";
143
143
  import {
144
144
  getCodexModelProvider
145
- } from "./chunk-5ZJEUCSE.js";
145
+ } from "./chunk-4VVCCZZK.js";
146
146
  import {
147
147
  SUBPROCESS_MAX_BUFFER,
148
148
  execAsync,
@@ -59414,6 +59414,8 @@ var FINAL_MESSAGE_MAX = 6e3;
59414
59414
  var MAX_ACCEPTED_SEND_RESPONSES = 50;
59415
59415
  var MAX_REMOVED_MESSAGE_IDS = 6e3;
59416
59416
  var SUBAGENT_POLL_INTERVAL_MS = 2e3;
59417
+ var CHAT_IDLE_RELEASE_MS = 15 * 6e4;
59418
+ var CHILD_CHAT_IDLE_RELEASE_MS = 2 * 6e4;
59417
59419
  function createForkInfo(source, trigger, startedAt, reason) {
59418
59420
  return {
59419
59421
  source: { chatId: source.id, provider: source.provider, title: source.title },
@@ -59723,6 +59725,8 @@ var ChatService = class {
59723
59725
  try {
59724
59726
  await previousAcceptance?.catch(() => {
59725
59727
  });
59728
+ await chat.release;
59729
+ this.requireChat(chatId);
59726
59730
  seenBeforeSend = this.sideChatSeenBlocks.get(chatId);
59727
59731
  if (chat.persisted.fork && (chat.persisted.pendingForkHandoff || chat.persisted.fork.trigger === "side")) {
59728
59732
  request = {
@@ -59907,6 +59911,9 @@ var ChatService = class {
59907
59911
  if (!chat.provider.clearGoal) {
59908
59912
  return { interrupted: false, queue: [], goal: null };
59909
59913
  }
59914
+ this.cancelIdleRelease(chat);
59915
+ await chat.release;
59916
+ this.requireChat(chatId);
59910
59917
  const interruptResult = await chat.provider.interrupt((messageIds) => this.forgetPendingMessages(chat, messageIds));
59911
59918
  this.endTrackedTurn(chat);
59912
59919
  chat.hasActiveTurn = false;
@@ -59914,7 +59921,7 @@ var ChatService = class {
59914
59921
  chat.pendingMessageIds = [];
59915
59922
  chat.acceptedUserEvents.clear();
59916
59923
  chat.turnAnswer = null;
59917
- const goal = await chat.provider.clearGoal(chat.persisted.model);
59924
+ const goal = await chat.provider.clearGoal(chat.persisted.model).finally(() => this.scheduleIdleRelease(chat));
59918
59925
  this.touch(chat);
59919
59926
  await this.publish({
59920
59927
  type: "chat.interrupted",
@@ -60090,13 +60097,14 @@ var ChatService = class {
60090
60097
  target.slackActivity?.finish();
60091
60098
  target.slackActivity = null;
60092
60099
  target.slackActivityMessageIds.clear();
60093
- if (hasChatStarted(this.toSummary(target))) {
60100
+ const started = hasChatStarted(this.toSummary(target));
60101
+ if (started) {
60094
60102
  target.persisted.deletedAt = deletedAt;
60095
60103
  } else {
60096
60104
  this.chats.delete(id);
60097
- await target.provider.dispose?.();
60098
- await this.deleteHistoryFile(target.persisted);
60099
60105
  }
60106
+ await this.releaseAgentProcess(target);
60107
+ if (!started) await this.deleteHistoryFile(target.persisted);
60100
60108
  await this.publish({ type: "chat.deleted", payload: { chatId: id, chat: this.toSummary(target) } });
60101
60109
  }
60102
60110
  await this.persistAllChats();
@@ -60528,6 +60536,8 @@ var ChatService = class {
60528
60536
  turnRequest: null,
60529
60537
  turnAnswer: null,
60530
60538
  turnCompletion: null,
60539
+ idleReleaseTimer: null,
60540
+ release: null,
60531
60541
  errorNotificationTargets: /* @__PURE__ */ new Map(),
60532
60542
  activeErrorNotificationTargets: [],
60533
60543
  slackActivityMessageIds: /* @__PURE__ */ new Set(),
@@ -60710,6 +60720,31 @@ var ChatService = class {
60710
60720
  this.publish({ type: "chat.updated", payload: { chat: this.toSummary(chat) } }).catch(() => {
60711
60721
  });
60712
60722
  this.notifyWorkspaceAgentIdle();
60723
+ this.scheduleIdleRelease(chat);
60724
+ }
60725
+ // Idleness is re-checked when the timer fires: work that starts in between
60726
+ // ends with another processing stop, which schedules a fresh release.
60727
+ scheduleIdleRelease(chat) {
60728
+ this.cancelIdleRelease(chat);
60729
+ if (!chat.provider.dispose) return;
60730
+ chat.idleReleaseTimer = setTimeout(() => {
60731
+ chat.idleReleaseTimer = null;
60732
+ if (chat.persisted.deletedAt || chat.acceptingMessages > 0 || hasActiveChatTurn(chat) || hasActiveAgentWork(chat)) return;
60733
+ void this.releaseAgentProcess(chat);
60734
+ }, chat.persisted.parentChatId === null ? CHAT_IDLE_RELEASE_MS : CHILD_CHAT_IDLE_RELEASE_MS);
60735
+ chat.idleReleaseTimer.unref?.();
60736
+ }
60737
+ cancelIdleRelease(chat) {
60738
+ if (chat.idleReleaseTimer) clearTimeout(chat.idleReleaseTimer);
60739
+ chat.idleReleaseTimer = null;
60740
+ }
60741
+ /** Senders await `chat.release` so a new turn never starts against a session that is being torn down. */
60742
+ releaseAgentProcess(chat) {
60743
+ this.cancelIdleRelease(chat);
60744
+ chat.release ??= Promise.resolve().then(() => chat.provider.dispose?.()).catch((error) => console.error("[ChatService] Failed to release chat agent process:", { chatId: chat.persisted.id, error })).finally(() => {
60745
+ chat.release = null;
60746
+ });
60747
+ return chat.release;
60713
60748
  }
60714
60749
  endTrackedTurn(chat) {
60715
60750
  this.agentTokenUsageTracker.endTurn(chat.persisted.id);
@@ -60753,6 +60788,7 @@ var ChatService = class {
60753
60788
  const completion = this.publishAgentTurnCompleteWebhook(chat, completedAt, stillProcessing, forked ? null : exhaustion, responseComplete, chat.turnCompletion).catch((error) => console.error("[ChatService] Failed to report turn completion:", { chatId, error })).finally(() => {
60754
60789
  if (chat.turnCompletion === completion) chat.turnCompletion = null;
60755
60790
  this.notifyWorkspaceAgentIdle();
60791
+ this.scheduleIdleRelease(chat);
60756
60792
  });
60757
60793
  chat.turnCompletion = completion;
60758
60794
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "replicas-engine",
3
- "version": "0.1.1094",
3
+ "version": "0.1.1095",
4
4
  "description": "Lightweight API server for Replicas workspaces",
5
5
  "type": "module",
6
6
  "main": "dist/src/index.js",