replicas-engine 0.1.443 → 0.1.444

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 +41 -11
  2. package/package.json +1 -1
package/dist/src/index.js CHANGED
@@ -521,7 +521,7 @@ var WORKSPACE_SIZES = ["small", "large"];
521
521
  var INVALID_WORKSPACE_SIZE_ERROR = `Invalid size: must be one of ${WORKSPACE_SIZES.join(", ")}`;
522
522
 
523
523
  // ../shared/src/e2b.ts
524
- var E2B_TEMPLATE_NAME = "replicas-sandbox-2026-07-16-v3";
524
+ var E2B_TEMPLATE_NAME = "replicas-sandbox-2026-07-16-v4";
525
525
 
526
526
  // ../shared/src/runtime-env.ts
527
527
  function shellQuotePosix(value) {
@@ -8592,7 +8592,7 @@ var DEFAULT_CODEX_ARGS = ["app-server", "--listen", "stdio://"];
8592
8592
  var MIN_CODEX_CLI_VERSION = "0.144.0";
8593
8593
  var CODEX_UPGRADE_TIMEOUT_MS = 12e4;
8594
8594
  var codexCliVersionEnsured = null;
8595
- var ENGINE_PACKAGE_VERSION = "0.1.443";
8595
+ var ENGINE_PACKAGE_VERSION = "0.1.444";
8596
8596
  var INITIALIZE_METHOD = "initialize";
8597
8597
  var INITIALIZED_NOTIFICATION = "initialized";
8598
8598
  var ACCOUNT_LOGIN_START_METHOD = "account/login/start";
@@ -8817,9 +8817,10 @@ async function restartCodexAspHost() {
8817
8817
 
8818
8818
  // src/utils/codex-quota.ts
8819
8819
  function buildCodexRateLimitsSnapshot(fields) {
8820
+ if (fields.authMethod !== "oauth") return null;
8820
8821
  if (fields.unlimited === true) return null;
8821
8822
  let state = "ok";
8822
- if (fields.hasCredits === false) {
8823
+ if (fields.rateLimitResetType?.endsWith("_credits_depleted")) {
8823
8824
  state = "out_of_credits";
8824
8825
  } else if (fields.rateLimitResetType !== null) {
8825
8826
  state = "rate_limited";
@@ -8901,8 +8902,8 @@ function toReasoningEffort(thinkingLevel) {
8901
8902
  function extractRateLimitsSnapshot(rateLimits) {
8902
8903
  const credits = rateLimits.credits;
8903
8904
  return buildCodexRateLimitsSnapshot({
8905
+ authMethod: ENGINE_ENV.REPLICAS_CODEX_AUTH_METHOD ?? "none",
8904
8906
  unlimited: credits?.unlimited ?? null,
8905
- hasCredits: credits?.hasCredits ?? null,
8906
8907
  balance: credits?.balance ?? null,
8907
8908
  rateLimitResetType: rateLimits.rateLimitReachedType || null,
8908
8909
  planType: rateLimits.planType
@@ -14162,11 +14163,12 @@ import { existsSync as existsSync9 } from "fs";
14162
14163
  import { spawn as spawn5 } from "node-pty";
14163
14164
  var MAX_REPLAY_CHARS = 1024 * 1024;
14164
14165
  var MAX_TERMINAL_SESSIONS = 8;
14166
+ var MAX_PENDING_INPUT = 64;
14165
14167
  var TerminalService = class {
14166
14168
  sessions = /* @__PURE__ */ new Map();
14167
14169
  nextTitleNumber = 1;
14168
14170
  list() {
14169
- return [...this.sessions.values()].map(({ pty: _pty, replay: _replay, subscribers: _subscribers, ...session }) => session);
14171
+ return [...this.sessions.values()].map((session) => this.publicSession(session));
14170
14172
  }
14171
14173
  create(cwd, cols, rows) {
14172
14174
  if (this.sessions.size >= MAX_TERMINAL_SESSIONS) {
@@ -14195,7 +14197,10 @@ var TerminalService = class {
14195
14197
  exited: false,
14196
14198
  pty,
14197
14199
  replay: "",
14198
- subscribers: /* @__PURE__ */ new Set()
14200
+ subscribers: /* @__PURE__ */ new Set(),
14201
+ inputGeneration: -1,
14202
+ nextInputSequence: 0,
14203
+ pendingInput: /* @__PURE__ */ new Map()
14199
14204
  };
14200
14205
  this.sessions.set(id, session);
14201
14206
  pty.onData((data) => {
@@ -14213,10 +14218,25 @@ var TerminalService = class {
14213
14218
  });
14214
14219
  return createSuccessResult(this.publicSession(session));
14215
14220
  }
14216
- write(id, data) {
14221
+ write(id, data, generation, sequence) {
14217
14222
  const session = this.sessions.get(id);
14218
14223
  if (!session || session.exited) return false;
14219
- session.pty.write(data);
14224
+ if (generation < session.inputGeneration) return true;
14225
+ if (generation > session.inputGeneration) {
14226
+ session.inputGeneration = generation;
14227
+ session.nextInputSequence = 0;
14228
+ session.pendingInput.clear();
14229
+ }
14230
+ if (sequence < session.nextInputSequence) return true;
14231
+ session.pendingInput.set(sequence, data);
14232
+ if (session.pendingInput.size > MAX_PENDING_INPUT) {
14233
+ session.nextInputSequence = Math.min(...session.pendingInput.keys());
14234
+ }
14235
+ let pendingInput;
14236
+ while ((pendingInput = session.pendingInput.get(session.nextInputSequence)) !== void 0) {
14237
+ session.pty.write(pendingInput);
14238
+ session.pendingInput.delete(session.nextInputSequence++);
14239
+ }
14220
14240
  return true;
14221
14241
  }
14222
14242
  resize(id, cols, rows) {
@@ -14242,7 +14262,15 @@ var TerminalService = class {
14242
14262
  return true;
14243
14263
  }
14244
14264
  publicSession(session) {
14245
- const { pty: _pty, replay: _replay, subscribers: _subscribers, ...value } = session;
14265
+ const {
14266
+ pty: _pty,
14267
+ replay: _replay,
14268
+ subscribers: _subscribers,
14269
+ inputGeneration: _inputGeneration,
14270
+ nextInputSequence: _nextInputSequence,
14271
+ pendingInput: _pendingInput,
14272
+ ...value
14273
+ } = session;
14246
14274
  return value;
14247
14275
  }
14248
14276
  };
@@ -14268,7 +14296,9 @@ var terminalSizeSchema = z2.object({
14268
14296
  rows: z2.number().int().min(1).max(200)
14269
14297
  });
14270
14298
  var writeTerminalSessionSchema = z2.object({
14271
- data: z2.string().max(64 * 1024)
14299
+ data: z2.string().max(64 * 1024),
14300
+ generation: z2.number().int().nonnegative(),
14301
+ sequence: z2.number().int().nonnegative()
14272
14302
  });
14273
14303
  var sendMessageSchema = z2.object({
14274
14304
  message: z2.string().min(1),
@@ -14656,7 +14686,7 @@ function createV1Routes(deps) {
14656
14686
  });
14657
14687
  app2.post("/terminal/sessions/:id/input", async (c) => {
14658
14688
  const body = writeTerminalSessionSchema.parse(await c.req.json());
14659
- if (!terminalService.write(c.req.param("id"), body.data)) {
14689
+ if (!terminalService.write(c.req.param("id"), body.data, body.generation, body.sequence)) {
14660
14690
  return c.json(jsonError("Terminal session not found or exited"), 404);
14661
14691
  }
14662
14692
  return c.body(null, 204);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "replicas-engine",
3
- "version": "0.1.443",
3
+ "version": "0.1.444",
4
4
  "description": "Lightweight API server for Replicas workspaces",
5
5
  "type": "module",
6
6
  "main": "dist/src/index.js",