replicas-engine 0.1.826 → 0.1.827

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.
@@ -5,11 +5,11 @@ import {
5
5
  getCodexAspHost,
6
6
  restartCodexAspHost,
7
7
  restartCodexAspHostIfRunning
8
- } from "./chunk-JWG2DEIU.js";
9
- import "./chunk-JES6TTMW.js";
10
- import "./chunk-FZ73DSR2.js";
8
+ } from "./chunk-HQFWCOI3.js";
9
+ import "./chunk-C3MWT2WD.js";
10
+ import "./chunk-YMTLQI4E.js";
11
11
  import "./chunk-UZSNFLDQ.js";
12
- import "./chunk-COJQBVQN.js";
12
+ import "./chunk-5XK2ECRO.js";
13
13
  import "./chunk-VEQXQN22.js";
14
14
  export {
15
15
  getCodexAspHost,
@@ -797,6 +797,27 @@ var CONTEXT_USAGE_EVENT_TYPE = "context-usage";
797
797
  // ../shared/src/engine/v1.ts
798
798
  import { z as z3 } from "zod";
799
799
  var MERGED_MESSAGE_SEPARATOR = "\n\n<!-- replicas:merged -->\n\n";
800
+ function isChatScopedEngineEvent(event) {
801
+ return event.type.startsWith("chat.");
802
+ }
803
+ function getChatScopedEngineEventChatId(event) {
804
+ return event.type === "chat.created" || event.type === "chat.updated" ? event.payload.chat.id : event.payload.chatId;
805
+ }
806
+ var CHAT_STREAM_RESYNC_EVENT_TYPE = "chat.stream.resync";
807
+ function isChatStreamEvent(value) {
808
+ return isRecord(value) && typeof value.id === "string" && typeof value.ts === "string" && typeof value.type === "string" && value.type.startsWith("chat.") && isRecord(value.payload);
809
+ }
810
+ var ENGINE_CHAT_EVENTS_PUSH_MAX_EVENTS = 500;
811
+ var chatScopedEngineEventSchema = z3.custom(
812
+ (value) => isChatStreamEvent(value) && value.type !== CHAT_STREAM_RESYNC_EVENT_TYPE
813
+ );
814
+ var engineChatEventsPushRequestSchema = z3.object({
815
+ epoch: z3.string().min(1).max(64),
816
+ events: z3.array(z3.object({
817
+ seq: z3.number().int().positive(),
818
+ event: chatScopedEngineEventSchema
819
+ })).max(ENGINE_CHAT_EVENTS_PUSH_MAX_EVENTS)
820
+ });
800
821
  var ENGINE_HEALTH_WAIT_HEADER = "X-Replicas-Health-Wait";
801
822
  var ENGINE_HEALTH_WAIT_QUERY_PARAM = "wait_ms";
802
823
  var ENGINE_HEALTH_MAX_WAIT_MS = 2e3;
@@ -4962,11 +4983,13 @@ function parseClaudeEvents(events, parentToolUseId) {
4962
4983
  const messageKey = messageId || event.timestamp;
4963
4984
  const streamRefs = messageId ? partialIndexes.get(messageId) : void 0;
4964
4985
  if (messageId) {
4965
- completedStreamIds.add(messageId);
4966
4986
  if (liveStreamId !== null && liveStreamId !== messageId) {
4967
4987
  supersededStreamIds.add(liveStreamId);
4968
4988
  }
4969
- liveStreamId = null;
4989
+ if (contentBlocks.some((block) => block.type === "text" && block.text)) {
4990
+ completedStreamIds.add(messageId);
4991
+ liveStreamId = null;
4992
+ }
4970
4993
  }
4971
4994
  const thinkingBlocks = contentBlocks.flatMap(
4972
4995
  (block) => block.type === "thinking" && typeof block.thinking === "string" ? [block.thinking] : []
@@ -7721,6 +7744,9 @@ export {
7721
7744
  coerceChatGoalPayload,
7722
7745
  CONTEXT_USAGE_EVENT_TYPE,
7723
7746
  MERGED_MESSAGE_SEPARATOR,
7747
+ isChatScopedEngineEvent,
7748
+ getChatScopedEngineEventChatId,
7749
+ ENGINE_CHAT_EVENTS_PUSH_MAX_EVENTS,
7724
7750
  ENGINE_HEALTH_WAIT_HEADER,
7725
7751
  ENGINE_HEALTH_WAIT_QUERY_PARAM,
7726
7752
  ENGINE_HEALTH_MAX_WAIT_MS,
@@ -15,7 +15,7 @@ import {
15
15
  isValidRelayBaseProvider,
16
16
  parsePosixEnvFile,
17
17
  readReplicasRuntimeEnv
18
- } from "./chunk-COJQBVQN.js";
18
+ } from "./chunk-5XK2ECRO.js";
19
19
 
20
20
  // src/engine-env.ts
21
21
  import { readFileSync as readFileSync2 } from "fs";
@@ -5,18 +5,18 @@ import {
5
5
  ENGINE_ENV,
6
6
  monolithRequest,
7
7
  setAgentCredentialSnapshot
8
- } from "./chunk-JES6TTMW.js";
8
+ } from "./chunk-C3MWT2WD.js";
9
9
  import {
10
10
  AppServerProcess,
11
11
  buildCodexAgentEnv
12
- } from "./chunk-FZ73DSR2.js";
12
+ } from "./chunk-YMTLQI4E.js";
13
13
  import {
14
14
  CODEX_AUTH_ENV_KEYS,
15
15
  CODEX_AUTH_ENV_KEYS_BY_METHOD,
16
16
  codexAuthEnvFromResponse,
17
17
  createErrorResult,
18
18
  createSuccessResult
19
- } from "./chunk-COJQBVQN.js";
19
+ } from "./chunk-5XK2ECRO.js";
20
20
 
21
21
  // src/managers/codex-token-manager.ts
22
22
  import { promises as fs } from "fs";
@@ -232,7 +232,7 @@ var CodexTokenManager = class extends BaseRefreshManager {
232
232
  const data = await response.json();
233
233
  await this.applyCredentialsResponse(data);
234
234
  if (restartOnChange && CODEX_AUTH_ENV_KEYS.some((key, index) => process.env[key] !== previousEnv[index])) {
235
- const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-7CTVWTXX.js");
235
+ const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-OGXCZYKE.js");
236
236
  await restartCodexAspHostIfRunning2();
237
237
  }
238
238
  if (data.scope) {
@@ -3,7 +3,7 @@ import { createRequire as __createRequire } from 'node:module';
3
3
  const require = __createRequire(import.meta.url);
4
4
  import {
5
5
  shouldRefreshPullRequests
6
- } from "./chunk-COJQBVQN.js";
6
+ } from "./chunk-5XK2ECRO.js";
7
7
 
8
8
  // src/services/post-tool-pr-notifier.ts
9
9
  async function notifyPostToolUse(toolName, toolInput) {
@@ -3,12 +3,12 @@ import { createRequire as __createRequire } from 'node:module';
3
3
  const require = __createRequire(import.meta.url);
4
4
  import {
5
5
  monolithRequest
6
- } from "./chunk-JES6TTMW.js";
6
+ } from "./chunk-C3MWT2WD.js";
7
7
  import {
8
8
  extractCommandProtectionCommandText,
9
9
  findGitCommitSignals,
10
10
  findPrMergeSignals
11
- } from "./chunk-COJQBVQN.js";
11
+ } from "./chunk-5XK2ECRO.js";
12
12
 
13
13
  // src/services/command-protection-service.ts
14
14
  var DEFAULT_COMMAND_PROTECTION_BLOCK_MESSAGE = "Blocked by Replicas command protection.";
@@ -4,7 +4,7 @@ const require = __createRequire(import.meta.url);
4
4
  import {
5
5
  HOOK_EXEC_MAX_BUFFER_BYTES,
6
6
  isVersionBelow
7
- } from "./chunk-COJQBVQN.js";
7
+ } from "./chunk-5XK2ECRO.js";
8
8
 
9
9
  // src/utils/codex-agent-env.ts
10
10
  function buildCodexAgentEnv(source = process.env) {
@@ -241,7 +241,7 @@ var DEFAULT_CODEX_ARGS = [
241
241
  var MIN_CODEX_CLI_VERSION = "0.153.3";
242
242
  var CODEX_UPGRADE_TIMEOUT_MS = 12e4;
243
243
  var codexCliVersionEnsured = null;
244
- var ENGINE_PACKAGE_VERSION = "0.1.826";
244
+ var ENGINE_PACKAGE_VERSION = "0.1.827";
245
245
  var INITIALIZE_METHOD = "initialize";
246
246
  var INITIALIZED_NOTIFICATION = "initialized";
247
247
  var ACCOUNT_LOGIN_START_METHOD = "account/login/start";
@@ -3,12 +3,12 @@ import { createRequire as __createRequire } from 'node:module';
3
3
  const require = __createRequire(import.meta.url);
4
4
  import {
5
5
  evaluateCommandProtection
6
- } from "./chunk-YIJRPEJ5.js";
7
- import "./chunk-JES6TTMW.js";
6
+ } from "./chunk-ULXOFMGF.js";
7
+ import "./chunk-C3MWT2WD.js";
8
8
  import {
9
9
  isRecord
10
10
  } from "./chunk-UZSNFLDQ.js";
11
- import "./chunk-COJQBVQN.js";
11
+ import "./chunk-5XK2ECRO.js";
12
12
  import "./chunk-VEQXQN22.js";
13
13
 
14
14
  // src/command-protection-hook.ts
@@ -3,13 +3,13 @@ import { createRequire as __createRequire } from 'node:module';
3
3
  const require = __createRequire(import.meta.url);
4
4
  import {
5
5
  evaluateCommandProtection
6
- } from "./chunk-YIJRPEJ5.js";
6
+ } from "./chunk-ULXOFMGF.js";
7
7
  import {
8
8
  notifyPostToolUse
9
- } from "./chunk-A7G2VQHN.js";
10
- import "./chunk-JES6TTMW.js";
9
+ } from "./chunk-HUXYXVH3.js";
10
+ import "./chunk-C3MWT2WD.js";
11
11
  import "./chunk-UZSNFLDQ.js";
12
- import "./chunk-COJQBVQN.js";
12
+ import "./chunk-5XK2ECRO.js";
13
13
  import "./chunk-VEQXQN22.js";
14
14
 
15
15
  // src/deepseek-command-protection-plugin.ts
@@ -8,12 +8,12 @@ import {
8
8
  import {
9
9
  AppServerProcess,
10
10
  buildCodexAgentEnv
11
- } from "./chunk-FZ73DSR2.js";
11
+ } from "./chunk-YMTLQI4E.js";
12
12
  import {
13
13
  AGENT,
14
14
  getMemoryOutputSafetyViolation,
15
15
  headlessAgentRequestSchema
16
- } from "./chunk-COJQBVQN.js";
16
+ } from "./chunk-5XK2ECRO.js";
17
17
  import "./chunk-VEQXQN22.js";
18
18
 
19
19
  // src/headless-agent.ts
package/dist/src/index.js CHANGED
@@ -91,7 +91,7 @@ import {
91
91
  evaluateCommandProtection,
92
92
  extractToolCommand,
93
93
  reportCommandProtectionBlock
94
- } from "./chunk-YIJRPEJ5.js";
94
+ } from "./chunk-ULXOFMGF.js";
95
95
  import {
96
96
  ACCOUNT_RATE_LIMITS_UPDATED_METHOD,
97
97
  AGENT_MESSAGE_DELTA_METHOD,
@@ -131,20 +131,20 @@ import {
131
131
  recordCredentialFallback,
132
132
  recordExhaustedCredential,
133
133
  restartCodexAspHost
134
- } from "./chunk-JWG2DEIU.js";
134
+ } from "./chunk-HQFWCOI3.js";
135
135
  import {
136
136
  ENGINE_ENV,
137
137
  IS_WARMING_MODE,
138
138
  monolithRequest,
139
139
  monolithService,
140
140
  setAgentCredentialSnapshot
141
- } from "./chunk-JES6TTMW.js";
141
+ } from "./chunk-C3MWT2WD.js";
142
142
  import {
143
143
  AspClient,
144
144
  SUBPROCESS_MAX_BUFFER,
145
145
  execAsync,
146
146
  execFileAsync
147
- } from "./chunk-FZ73DSR2.js";
147
+ } from "./chunk-YMTLQI4E.js";
148
148
  import {
149
149
  isRecord as isRecord2
150
150
  } from "./chunk-UZSNFLDQ.js";
@@ -200,6 +200,7 @@ import {
200
200
  DEFAULT_RELAY_BASE_PROVIDER,
201
201
  DEFAULT_START_HOOK_TIMEOUT_MS,
202
202
  DESKTOP_STREAM_PORT,
203
+ ENGINE_CHAT_EVENTS_PUSH_MAX_EVENTS,
203
204
  ENGINE_HEALTH_MAX_WAIT_MS,
204
205
  ENGINE_HEALTH_WAIT_HEADER,
205
206
  ENGINE_HEALTH_WAIT_QUERY_PARAM,
@@ -272,6 +273,7 @@ import {
272
273
  getChatExecutionProvider,
273
274
  getChatHistoryPageSenders,
274
275
  getChatHistoryPageWindow,
276
+ getChatScopedEngineEventChatId,
275
277
  getChatTranscriptHistorySize,
276
278
  getClaudeModelContextWindow,
277
279
  getClaudePartialMessageStreamId,
@@ -297,6 +299,7 @@ import {
297
299
  isAuthenticationErrorText,
298
300
  isCanvasTextKind,
299
301
  isChatMessageSender,
302
+ isChatScopedEngineEvent,
300
303
  isClaudeAuthErrorText,
301
304
  isClaudeResultError,
302
305
  isCodexAspTranscript,
@@ -349,7 +352,7 @@ import {
349
352
  spawnRelaySubagentRequestSchema,
350
353
  stripAgentDiagnosticErrors,
351
354
  withTimeout
352
- } from "./chunk-COJQBVQN.js";
355
+ } from "./chunk-5XK2ECRO.js";
353
356
  import {
354
357
  __commonJS,
355
358
  __export,
@@ -8542,7 +8545,7 @@ var require_dist2 = __commonJS({
8542
8545
  import { serve } from "@hono/node-server";
8543
8546
  import { Hono as Hono2 } from "hono";
8544
8547
  import { existsSync as existsSync20 } from "fs";
8545
- import { randomUUID as randomUUID15 } from "crypto";
8548
+ import { randomUUID as randomUUID16 } from "crypto";
8546
8549
  import { connect } from "net";
8547
8550
 
8548
8551
  // src/managers/github-token-manager.ts
@@ -64779,6 +64782,72 @@ var HeartbeatService = class _HeartbeatService {
64779
64782
  };
64780
64783
  var heartbeatService = new HeartbeatService();
64781
64784
 
64785
+ // src/services/chat-event-publisher.ts
64786
+ import { randomUUID as randomUUID15 } from "crypto";
64787
+ var FLUSH_DELAY_MS = 100;
64788
+ var REQUEST_TIMEOUT_MS = 1e4;
64789
+ var MAX_QUEUE = 1e4;
64790
+ var INITIAL_BACKOFF_MS = 1e3;
64791
+ var MAX_BACKOFF_MS = 3e4;
64792
+ var ChatEventPublisher = class {
64793
+ epoch = randomUUID15();
64794
+ seqByChat = /* @__PURE__ */ new Map();
64795
+ queue = [];
64796
+ timer = null;
64797
+ flushing = false;
64798
+ backoffMs = INITIAL_BACKOFF_MS;
64799
+ unsupported = false;
64800
+ start() {
64801
+ if (IS_WARMING_MODE || !ENGINE_ENV.REPLICAS_WORKSPACE_ID) return;
64802
+ eventService.subscribe((event) => this.enqueue(event));
64803
+ }
64804
+ enqueue(event) {
64805
+ if (this.unsupported || !isChatScopedEngineEvent(event)) return;
64806
+ const chatId = getChatScopedEngineEventChatId(event);
64807
+ const seq = (this.seqByChat.get(chatId) ?? 0) + 1;
64808
+ this.seqByChat.set(chatId, seq);
64809
+ this.queue.push({ seq, event });
64810
+ if (this.queue.length > MAX_QUEUE) this.queue.splice(0, this.queue.length - MAX_QUEUE);
64811
+ this.schedule(FLUSH_DELAY_MS);
64812
+ }
64813
+ schedule(delayMs) {
64814
+ if (this.timer || this.flushing) return;
64815
+ this.timer = setTimeout(() => {
64816
+ this.timer = null;
64817
+ void this.flush();
64818
+ }, delayMs);
64819
+ this.timer.unref?.();
64820
+ }
64821
+ async flush() {
64822
+ if (this.flushing || this.queue.length === 0) return;
64823
+ this.flushing = true;
64824
+ const batch = this.queue.slice(0, ENGINE_CHAT_EVENTS_PUSH_MAX_EVENTS);
64825
+ try {
64826
+ const body = { epoch: this.epoch, events: batch };
64827
+ const response = await monolithRequest("/v1/engine/chat-events", { body, signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS) });
64828
+ if (response.status === 404) {
64829
+ this.unsupported = true;
64830
+ this.queue = [];
64831
+ return;
64832
+ }
64833
+ if (!response.ok) throw new Error(`chat events push returned ${response.status}`);
64834
+ const lastSentIndex = this.queue.indexOf(batch[batch.length - 1]);
64835
+ this.queue.splice(0, lastSentIndex + 1);
64836
+ this.backoffMs = INITIAL_BACKOFF_MS;
64837
+ } catch (error) {
64838
+ console.warn("[ChatEventPublisher] Push failed:", error instanceof Error ? error.message : error);
64839
+ this.flushing = false;
64840
+ this.schedule(this.backoffMs);
64841
+ this.backoffMs = Math.min(this.backoffMs * 2, MAX_BACKOFF_MS);
64842
+ return;
64843
+ } finally {
64844
+ this.flushing = false;
64845
+ }
64846
+ if (this.queue.length > 0) this.schedule(0);
64847
+ }
64848
+ };
64849
+ var chatEventPublisher = new ChatEventPublisher();
64850
+
64782
64851
  // src/services/workspace-sdk-service.ts
64783
64852
  import { cp, mkdir as mkdir23 } from "fs/promises";
64784
64853
  import { dirname as dirname20, resolve as resolve6 } from "path";
@@ -64990,7 +65059,7 @@ function startStatusBroadcaster() {
64990
65059
  if (serialized !== previousRepoStatus) {
64991
65060
  previousRepoStatus = serialized;
64992
65061
  eventService.publish({
64993
- id: randomUUID15(),
65062
+ id: randomUUID16(),
64994
65063
  ts: (/* @__PURE__ */ new Date()).toISOString(),
64995
65064
  type: "repo.status.changed",
64996
65065
  payload: { repos }
@@ -65011,7 +65080,7 @@ function startStatusBroadcaster() {
65011
65080
  if (engineStatusJson !== previousEngineStatus) {
65012
65081
  previousEngineStatus = engineStatusJson;
65013
65082
  eventService.publish({
65014
- id: randomUUID15(),
65083
+ id: randomUUID16(),
65015
65084
  ts: (/* @__PURE__ */ new Date()).toISOString(),
65016
65085
  type: "engine.status.changed",
65017
65086
  payload: { status: engineStatus }
@@ -65030,7 +65099,7 @@ function startStatusBroadcaster() {
65030
65099
  previousHookStatus = hookSnapshot;
65031
65100
  if (!lastHooksRunning && hooksRunning) {
65032
65101
  eventService.publish({
65033
- id: randomUUID15(),
65102
+ id: randomUUID16(),
65034
65103
  ts: (/* @__PURE__ */ new Date()).toISOString(),
65035
65104
  type: "hooks.started",
65036
65105
  payload: { running: true, completed: false }
@@ -65039,7 +65108,7 @@ function startStatusBroadcaster() {
65039
65108
  }
65040
65109
  if (hooksRunning) {
65041
65110
  eventService.publish({
65042
- id: randomUUID15(),
65111
+ id: randomUUID16(),
65043
65112
  ts: (/* @__PURE__ */ new Date()).toISOString(),
65044
65113
  type: "hooks.progress",
65045
65114
  payload: { running: true, completed: false }
@@ -65048,7 +65117,7 @@ function startStatusBroadcaster() {
65048
65117
  }
65049
65118
  if (lastHooksRunning && !hooksRunning && hooksCompleted && !hooksFailed) {
65050
65119
  eventService.publish({
65051
- id: randomUUID15(),
65120
+ id: randomUUID16(),
65052
65121
  ts: (/* @__PURE__ */ new Date()).toISOString(),
65053
65122
  type: "hooks.completed",
65054
65123
  payload: { running: false, completed: true }
@@ -65057,7 +65126,7 @@ function startStatusBroadcaster() {
65057
65126
  }
65058
65127
  if (lastHooksRunning && !hooksRunning && hooksFailed) {
65059
65128
  eventService.publish({
65060
- id: randomUUID15(),
65129
+ id: randomUUID16(),
65061
65130
  ts: (/* @__PURE__ */ new Date()).toISOString(),
65062
65131
  type: "hooks.failed",
65063
65132
  payload: { running: false, completed: hooksCompleted }
@@ -65065,7 +65134,7 @@ function startStatusBroadcaster() {
65065
65134
  });
65066
65135
  }
65067
65136
  eventService.publish({
65068
- id: randomUUID15(),
65137
+ id: randomUUID16(),
65069
65138
  ts: (/* @__PURE__ */ new Date()).toISOString(),
65070
65139
  type: "hooks.status",
65071
65140
  payload: {
@@ -65112,6 +65181,7 @@ serve(
65112
65181
  resolveEngineReady();
65113
65182
  void registerDesktopPreview();
65114
65183
  heartbeatService.start(bootTimeMs);
65184
+ chatEventPublisher.start();
65115
65185
  if (!IS_WARMING_MODE) {
65116
65186
  await gitlabTokenManager.start();
65117
65187
  await claudeTokenManager.start();
@@ -65120,20 +65190,20 @@ serve(
65120
65190
  }
65121
65191
  const repos = await gitService.listRepos();
65122
65192
  await eventService.publish({
65123
- id: randomUUID15(),
65193
+ id: randomUUID16(),
65124
65194
  ts: (/* @__PURE__ */ new Date()).toISOString(),
65125
65195
  type: "repo.discovered",
65126
65196
  payload: { repos }
65127
65197
  });
65128
65198
  const repoStatuses = await gitService.listRepos();
65129
65199
  await eventService.publish({
65130
- id: randomUUID15(),
65200
+ id: randomUUID16(),
65131
65201
  ts: (/* @__PURE__ */ new Date()).toISOString(),
65132
65202
  type: "repo.status.changed",
65133
65203
  payload: { repos: repoStatuses }
65134
65204
  });
65135
65205
  await eventService.publish({
65136
- id: randomUUID15(),
65206
+ id: randomUUID16(),
65137
65207
  ts: (/* @__PURE__ */ new Date()).toISOString(),
65138
65208
  type: "engine.ready",
65139
65209
  payload: { version: "v1" }
@@ -3,11 +3,11 @@ import { createRequire as __createRequire } from 'node:module';
3
3
  const require = __createRequire(import.meta.url);
4
4
  import {
5
5
  notifyPostToolUse
6
- } from "./chunk-A7G2VQHN.js";
6
+ } from "./chunk-HUXYXVH3.js";
7
7
  import {
8
8
  isRecord
9
9
  } from "./chunk-UZSNFLDQ.js";
10
- import "./chunk-COJQBVQN.js";
10
+ import "./chunk-5XK2ECRO.js";
11
11
  import "./chunk-VEQXQN22.js";
12
12
 
13
13
  // src/post-tool-pr-hook.ts
@@ -7,7 +7,7 @@ import {
7
7
  import {
8
8
  messageRelaySubagentRequestSchema,
9
9
  spawnRelaySubagentRequestSchema
10
- } from "./chunk-COJQBVQN.js";
10
+ } from "./chunk-5XK2ECRO.js";
11
11
  import "./chunk-VEQXQN22.js";
12
12
 
13
13
  // src/relay-mcp.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "replicas-engine",
3
- "version": "0.1.826",
3
+ "version": "0.1.827",
4
4
  "description": "Lightweight API server for Replicas workspaces",
5
5
  "type": "module",
6
6
  "main": "dist/src/index.js",