replicas-engine 0.1.566 → 0.1.568

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/src/index.js +74 -27
  2. package/package.json +1 -1
package/dist/src/index.js CHANGED
@@ -2793,8 +2793,11 @@ var DEFAULT_RELAY_SUBAGENT_PROVIDERS = [...VALID_RELAY_SUBAGENT_PROVIDERS];
2793
2793
  var DEFAULT_USER_PREFERENCES = {
2794
2794
  default_agent: "codex",
2795
2795
  default_model: null,
2796
+ claude_models: null,
2797
+ codex_models: null,
2796
2798
  cursor_models: null,
2797
2799
  openrouter_models: null,
2800
+ relay_models: null,
2798
2801
  close_workspace_on_pr_close: true,
2799
2802
  close_workspace_on_pr_merge: true,
2800
2803
  default_environment_id: null,
@@ -4257,8 +4260,9 @@ function parseOpencodeEvents(events) {
4257
4260
  if (event.type === "event_msg" && event.payload.type === "user_message") {
4258
4261
  const message = event.payload.message;
4259
4262
  if (typeof message === "string" && message.trim()) {
4263
+ const messageId = event.payload[USER_MESSAGE_ID_PAYLOAD_KEY];
4260
4264
  messages.push({
4261
- id: `opencode-user-${event.timestamp}-${messages.length}`,
4265
+ id: typeof messageId === "string" ? messageId : `opencode-user-${event.timestamp}`,
4262
4266
  type: "user",
4263
4267
  content: message,
4264
4268
  timestamp: event.timestamp
@@ -4270,7 +4274,7 @@ function parseOpencodeEvents(events) {
4270
4274
  const error = assistantError(event.payload.info);
4271
4275
  if (error) {
4272
4276
  messages.push({
4273
- id: `opencode-error-${event.timestamp}-${messages.length}`,
4277
+ id: `opencode-${event.type}-${event.timestamp}`,
4274
4278
  type: "error",
4275
4279
  message: error,
4276
4280
  timestamp: event.timestamp
@@ -4281,7 +4285,7 @@ function parseOpencodeEvents(events) {
4281
4285
  if (event.type === "opencode-error") {
4282
4286
  const message = typeof event.payload.message === "string" ? event.payload.message : "Opencode run failed";
4283
4287
  messages.push({
4284
- id: `opencode-error-${event.timestamp}-${messages.length}`,
4288
+ id: `opencode-${event.type}-${event.timestamp}`,
4285
4289
  type: "error",
4286
4290
  message,
4287
4291
  timestamp: event.timestamp
@@ -4292,7 +4296,7 @@ function parseOpencodeEvents(events) {
4292
4296
  const tool2 = typeof event.payload.tool === "string" ? event.payload.tool : "tool";
4293
4297
  const input = event.payload.input ?? event.payload.arguments;
4294
4298
  const callId = typeof event.payload.callID === "string" ? event.payload.callID : null;
4295
- const id2 = callId ? `opencode-${callId}` : `opencode-${event.timestamp}-${messages.length}`;
4299
+ const id2 = callId ? `opencode-${callId}` : `opencode-${event.type}-${event.timestamp}`;
4296
4300
  upsertDisplayMessage(messages, createCallDisplayMessage({
4297
4301
  id: id2,
4298
4302
  server: "opencode",
@@ -4305,7 +4309,7 @@ function parseOpencodeEvents(events) {
4305
4309
  }
4306
4310
  const part = partFromEvent(event);
4307
4311
  if (!part) continue;
4308
- let id = `opencode-${event.timestamp}-${messages.length}`;
4312
+ let id = `opencode-${event.type}-${event.timestamp}`;
4309
4313
  if (typeof part.callID === "string") id = `opencode-${part.callID}`;
4310
4314
  else if (typeof part.id === "string") id = `opencode-${part.id}`;
4311
4315
  const time = isRecord(part.time) ? part.time : null;
@@ -5249,38 +5253,81 @@ function stableString(value) {
5249
5253
  return String(value);
5250
5254
  }
5251
5255
  }
5252
- function duplicateMessage(a, b) {
5253
- if (a.id === b.id) return true;
5254
- if (a.type !== b.type || !nearTimestamp(a.timestamp, b.timestamp)) {
5255
- return false;
5256
+ function duplicateKey(message) {
5257
+ if (message.type === "user" || message.type === "agent" || message.type === "reasoning") {
5258
+ return JSON.stringify([message.type, message.content]);
5256
5259
  }
5257
- if (a.type === "user" && b.type === "user") return a.content === b.content;
5258
- if (a.type === "agent" && b.type === "agent") return a.content === b.content;
5259
- if (a.type === "reasoning" && b.type === "reasoning") return a.content === b.content;
5260
- if (a.type === "command" && b.type === "command") return a.command === b.command;
5261
- if (a.type === "web_search" && b.type === "web_search") return a.query === b.query;
5262
- if (a.type === "subagent" && b.type === "subagent") {
5263
- return a.description === b.description && a.prompt === b.prompt && a.subagentType === b.subagentType && a.model === b.model;
5260
+ if (message.type === "command") return JSON.stringify([message.type, message.command]);
5261
+ if (message.type === "web_search") return JSON.stringify([message.type, message.query]);
5262
+ if (message.type === "subagent") {
5263
+ return JSON.stringify([
5264
+ message.type,
5265
+ message.description,
5266
+ message.prompt,
5267
+ message.subagentType,
5268
+ message.model
5269
+ ]);
5264
5270
  }
5265
- if (a.type === "todo_list" && b.type === "todo_list") {
5266
- return stableString(a.items) === stableString(b.items);
5271
+ if (message.type === "todo_list") {
5272
+ return JSON.stringify([message.type, stableString(message.items)]);
5267
5273
  }
5268
- if (a.type === "patch" && b.type === "patch") {
5269
- return stableString(a.operations) === stableString(b.operations);
5274
+ if (message.type === "patch") {
5275
+ return JSON.stringify([message.type, stableString(message.operations)]);
5270
5276
  }
5271
- if (a.type === "tool_call" && b.type === "tool_call") {
5272
- return a.server === b.server && a.tool === b.tool && stableString(a.input) === stableString(b.input);
5277
+ if (message.type === "tool_call") {
5278
+ return JSON.stringify([
5279
+ message.type,
5280
+ message.server,
5281
+ message.tool,
5282
+ stableString(message.input)
5283
+ ]);
5273
5284
  }
5274
- return false;
5285
+ return null;
5286
+ }
5287
+ function duplicateBucketKey(message, bucketOffset = 0) {
5288
+ const key = duplicateKey(message);
5289
+ if (key === null) return null;
5290
+ const bucket = Math.floor(parseTimestampMs(message.timestamp) / DUPLICATE_WINDOW_MS) + bucketOffset;
5291
+ return JSON.stringify([bucket, key]);
5275
5292
  }
5276
5293
  function mergeCodexAspDisplayMessages(primary, supplemental) {
5277
5294
  const merged = [...primary];
5295
+ const firstIndexById = /* @__PURE__ */ new Map();
5296
+ const indexesByDuplicateBucket = /* @__PURE__ */ new Map();
5297
+ const indexMessage = (message, index) => {
5298
+ if (!firstIndexById.has(message.id)) firstIndexById.set(message.id, index);
5299
+ const key = duplicateBucketKey(message);
5300
+ if (key === null) return;
5301
+ const indexes = indexesByDuplicateBucket.get(key) ?? /* @__PURE__ */ new Set();
5302
+ indexes.add(index);
5303
+ indexesByDuplicateBucket.set(key, indexes);
5304
+ };
5305
+ const unindexMessage = (message, index) => {
5306
+ const key = duplicateBucketKey(message);
5307
+ if (key === null) return;
5308
+ const indexes = indexesByDuplicateBucket.get(key);
5309
+ indexes?.delete(index);
5310
+ if (indexes?.size === 0) indexesByDuplicateBucket.delete(key);
5311
+ };
5312
+ merged.forEach(indexMessage);
5278
5313
  for (const message of supplemental) {
5279
- const duplicateIndex = merged.findIndex((existing) => duplicateMessage(existing, message));
5280
- if (duplicateIndex === -1) {
5281
- merged.push(message);
5314
+ let duplicateIndex = firstIndexById.get(message.id);
5315
+ if (duplicateIndex === void 0) {
5316
+ for (let bucketOffset = -1; bucketOffset <= 1; bucketOffset += 1) {
5317
+ const key = duplicateBucketKey(message, bucketOffset);
5318
+ for (const index of (key === null ? void 0 : indexesByDuplicateBucket.get(key)) ?? []) {
5319
+ if (nearTimestamp(merged[index].timestamp, message.timestamp) && (duplicateIndex === void 0 || index < duplicateIndex)) {
5320
+ duplicateIndex = index;
5321
+ }
5322
+ }
5323
+ }
5324
+ }
5325
+ if (duplicateIndex === void 0) {
5326
+ indexMessage(message, merged.push(message) - 1);
5282
5327
  } else if (message.type === "user") {
5328
+ unindexMessage(merged[duplicateIndex], duplicateIndex);
5283
5329
  merged[duplicateIndex] = { ...merged[duplicateIndex], timestamp: message.timestamp };
5330
+ indexMessage(merged[duplicateIndex], duplicateIndex);
5284
5331
  }
5285
5332
  }
5286
5333
  return merged.map((message, index) => ({ message, index })).sort((a, b) => parseTimestampMs(a.message.timestamp) - parseTimestampMs(b.message.timestamp) || a.index - b.index).map(({ message }) => message);
@@ -10729,7 +10776,7 @@ var DEFAULT_CODEX_ARGS = ["app-server", "--listen", "stdio://"];
10729
10776
  var MIN_CODEX_CLI_VERSION = "0.144.6";
10730
10777
  var CODEX_UPGRADE_TIMEOUT_MS = 12e4;
10731
10778
  var codexCliVersionEnsured = null;
10732
- var ENGINE_PACKAGE_VERSION = "0.1.566";
10779
+ var ENGINE_PACKAGE_VERSION = "0.1.568";
10733
10780
  var INITIALIZE_METHOD = "initialize";
10734
10781
  var INITIALIZED_NOTIFICATION = "initialized";
10735
10782
  var ACCOUNT_LOGIN_START_METHOD = "account/login/start";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "replicas-engine",
3
- "version": "0.1.566",
3
+ "version": "0.1.568",
4
4
  "description": "Lightweight API server for Replicas workspaces",
5
5
  "type": "module",
6
6
  "main": "dist/src/index.js",