replicas-engine 0.1.159 → 0.1.160

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 +64 -6
  2. package/package.json +1 -1
package/dist/src/index.js CHANGED
@@ -285,7 +285,7 @@ function parseReplicasConfigString(content, filename) {
285
285
  }
286
286
 
287
287
  // ../shared/src/engine/environment.ts
288
- var DAYTONA_SNAPSHOT_ID = "11-05-2026-royal-york-v5";
288
+ var DAYTONA_SNAPSHOT_ID = "11-05-2026-royal-york-v6";
289
289
 
290
290
  // ../shared/src/engine/types.ts
291
291
  var DEFAULT_CHAT_TITLES = {
@@ -1914,7 +1914,7 @@ var previewService = new PreviewService();
1914
1914
 
1915
1915
  // src/services/chat/chat-service.ts
1916
1916
  import { existsSync as existsSync7 } from "fs";
1917
- import { mkdir as mkdir10, readFile as readFile8, rm, writeFile as writeFile8 } from "fs/promises";
1917
+ import { appendFile as appendFile5, mkdir as mkdir10, readFile as readFile8, rm, writeFile as writeFile8 } from "fs/promises";
1918
1918
  import { homedir as homedir9 } from "os";
1919
1919
  import { join as join12 } from "path";
1920
1920
  import { randomUUID as randomUUID4 } from "crypto";
@@ -4050,7 +4050,12 @@ var ENGINE_DIR2 = join12(homedir9(), ".replicas", "engine");
4050
4050
  var CHATS_FILE = join12(ENGINE_DIR2, "chats.json");
4051
4051
  var CLAUDE_HISTORY_DIR = join12(ENGINE_DIR2, "claude-histories");
4052
4052
  var RELAY_HISTORY_DIR = join12(ENGINE_DIR2, "relay-histories");
4053
+ var CHAT_SENDERS_DIR = join12(ENGINE_DIR2, "chat-senders");
4053
4054
  var CODEX_AUTH_PATH2 = join12(homedir9(), ".codex", "auth.json");
4055
+ function isChatMessageSender(value) {
4056
+ if (!isRecord3(value)) return false;
4057
+ return typeof value.senderUserId === "string" && typeof value.senderEmail === "string" && typeof value.recordedAt === "string";
4058
+ }
4054
4059
  function isCodexAvailable() {
4055
4060
  return existsSync7(CODEX_AUTH_PATH2) || Boolean(ENGINE_ENV.OPENAI_API_KEY);
4056
4061
  }
@@ -4072,6 +4077,7 @@ var ChatService = class {
4072
4077
  await mkdir10(ENGINE_DIR2, { recursive: true });
4073
4078
  await mkdir10(CLAUDE_HISTORY_DIR, { recursive: true });
4074
4079
  await mkdir10(RELAY_HISTORY_DIR, { recursive: true });
4080
+ await mkdir10(CHAT_SENDERS_DIR, { recursive: true });
4075
4081
  const persisted = await this.loadChats();
4076
4082
  for (const chat of persisted) {
4077
4083
  const runtime = this.createRuntimeChat(chat);
@@ -4139,13 +4145,24 @@ var ChatService = class {
4139
4145
  const result = await chat.provider.enqueueMessage(request);
4140
4146
  chat.pendingMessageIds.push(result.messageId);
4141
4147
  this.touch(chat);
4148
+ let recordedSender;
4149
+ if (request.senderUserId && request.senderEmail) {
4150
+ recordedSender = {
4151
+ senderUserId: request.senderUserId,
4152
+ senderEmail: request.senderEmail,
4153
+ ...request.senderDisplayName ? { senderDisplayName: request.senderDisplayName } : {},
4154
+ recordedAt: (/* @__PURE__ */ new Date()).toISOString()
4155
+ };
4156
+ await this.appendSender(chatId, recordedSender);
4157
+ }
4142
4158
  await this.publish({
4143
4159
  type: "chat.turn.accepted",
4144
4160
  payload: {
4145
4161
  chatId,
4146
4162
  messageId: result.messageId,
4147
4163
  queued: result.queued,
4148
- position: result.position
4164
+ position: result.position,
4165
+ ...recordedSender ? { sender: recordedSender } : {}
4149
4166
  }
4150
4167
  });
4151
4168
  return {
@@ -4154,6 +4171,39 @@ var ChatService = class {
4154
4171
  position: result.position
4155
4172
  };
4156
4173
  }
4174
+ senderFilePath(chatId) {
4175
+ return join12(CHAT_SENDERS_DIR, `${chatId}.jsonl`);
4176
+ }
4177
+ async appendSender(chatId, sender) {
4178
+ try {
4179
+ await appendFile5(this.senderFilePath(chatId), JSON.stringify(sender) + "\n", "utf-8");
4180
+ } catch (error) {
4181
+ console.error("[ChatService] Failed to append sender record:", error);
4182
+ }
4183
+ }
4184
+ async readSenders(chatId) {
4185
+ try {
4186
+ const content = await readFile8(this.senderFilePath(chatId), "utf-8");
4187
+ const lines = content.split("\n").filter((line) => line.trim().length > 0);
4188
+ const senders = [];
4189
+ for (const line of lines) {
4190
+ try {
4191
+ const parsed = JSON.parse(line);
4192
+ if (isChatMessageSender(parsed)) {
4193
+ senders.push(parsed);
4194
+ }
4195
+ } catch {
4196
+ }
4197
+ }
4198
+ return senders;
4199
+ } catch (error) {
4200
+ if (error && typeof error === "object" && "code" in error && error.code === "ENOENT") {
4201
+ return [];
4202
+ }
4203
+ console.error("[ChatService] Failed to read sender records:", error);
4204
+ return [];
4205
+ }
4206
+ }
4157
4207
  async interrupt(chatId) {
4158
4208
  const chat = this.requireChat(chatId);
4159
4209
  const result = await chat.provider.interrupt();
@@ -4210,13 +4260,18 @@ var ChatService = class {
4210
4260
  const dir = persisted.provider === "claude" ? CLAUDE_HISTORY_DIR : RELAY_HISTORY_DIR;
4211
4261
  await rm(join12(dir, `${persisted.id}.jsonl`), { force: true });
4212
4262
  }
4263
+ await rm(this.senderFilePath(persisted.id), { force: true });
4213
4264
  }
4214
4265
  async getChatHistory(chatId) {
4215
4266
  const chat = this.requireChat(chatId);
4216
- const history = await chat.provider.getHistory();
4267
+ const [history, senders] = await Promise.all([
4268
+ chat.provider.getHistory(),
4269
+ this.readSenders(chatId)
4270
+ ]);
4217
4271
  return {
4218
4272
  thread_id: history.thread_id,
4219
- events: history.events
4273
+ events: history.events,
4274
+ senders
4220
4275
  };
4221
4276
  }
4222
4277
  getProcessingCount() {
@@ -4891,7 +4946,10 @@ var sendMessageSchema = z2.object({
4891
4946
  })
4892
4947
  ])
4893
4948
  })).optional(),
4894
- thinkingLevel: z2.enum(["low", "medium", "high", "max"]).optional()
4949
+ thinkingLevel: z2.enum(["low", "medium", "high", "max"]).optional(),
4950
+ senderUserId: z2.string().optional(),
4951
+ senderEmail: z2.string().optional(),
4952
+ senderDisplayName: z2.string().optional()
4895
4953
  });
4896
4954
  function jsonError(message, details) {
4897
4955
  return { error: message, details };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "replicas-engine",
3
- "version": "0.1.159",
3
+ "version": "0.1.160",
4
4
  "description": "Lightweight API server for Replicas workspaces",
5
5
  "type": "module",
6
6
  "main": "dist/src/index.js",