replicas-engine 0.1.465 → 0.1.467
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.
- package/dist/src/index.js +61 -8
- package/package.json +1 -1
package/dist/src/index.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
// src/index.ts
|
|
4
4
|
import { serve } from "@hono/node-server";
|
|
5
5
|
import { Hono as Hono2 } from "hono";
|
|
6
|
+
import { existsSync as existsSync11 } from "fs";
|
|
6
7
|
|
|
7
8
|
// ../shared/src/type-guards.ts
|
|
8
9
|
function isRecord(value) {
|
|
@@ -44,6 +45,7 @@ function createErrorResult(error) {
|
|
|
44
45
|
|
|
45
46
|
// ../shared/src/agent.ts
|
|
46
47
|
var VALID_AGENT_PROVIDERS = ["claude", "codex", "cursor", "opencode", "pi", "relay"];
|
|
48
|
+
var VALID_RELAY_SUBAGENT_PROVIDERS = VALID_AGENT_PROVIDERS;
|
|
47
49
|
var VALID_CODING_AGENT_PROVIDERS = VALID_AGENT_PROVIDERS.filter(
|
|
48
50
|
(provider) => provider !== "relay"
|
|
49
51
|
);
|
|
@@ -568,11 +570,19 @@ var SANDBOX_LIFECYCLE = {
|
|
|
568
570
|
AUTO_DELETE_MINUTES: -1,
|
|
569
571
|
SSH_TOKEN_EXPIRATION_MINUTES: 3 * 60
|
|
570
572
|
};
|
|
573
|
+
var SANDBOX_PATHS = {
|
|
574
|
+
HOME_DIR: "/home/user",
|
|
575
|
+
WORKSPACES_DIR: "/home/user/workspaces",
|
|
576
|
+
REPLICAS_DIR: "/home/user/.replicas",
|
|
577
|
+
ENGINE_INIT_GATE: "/home/user/.replicas/engine-init-gate",
|
|
578
|
+
REPLICAS_CANVAS_DIR: "/home/user/.replicas/canvas",
|
|
579
|
+
REPLICAS_RUNTIME_ENV_FILE: "/home/user/.replicas/runtime-env.sh"
|
|
580
|
+
};
|
|
571
581
|
var WORKSPACE_SIZES = ["small", "large"];
|
|
572
582
|
var INVALID_WORKSPACE_SIZE_ERROR = `Invalid size: must be one of ${WORKSPACE_SIZES.join(", ")}`;
|
|
573
583
|
|
|
574
584
|
// ../shared/src/e2b.ts
|
|
575
|
-
var E2B_TEMPLATE_NAME = "replicas-sandbox-2026-07-19-
|
|
585
|
+
var E2B_TEMPLATE_NAME = "replicas-sandbox-2026-07-19-v19";
|
|
576
586
|
|
|
577
587
|
// ../shared/src/runtime-env.ts
|
|
578
588
|
function shellQuotePosix(value) {
|
|
@@ -2517,6 +2527,7 @@ var EMPTY_AGENT_DEFAULT_SETTINGS = {
|
|
|
2517
2527
|
goal_mode: null,
|
|
2518
2528
|
fast_mode: null
|
|
2519
2529
|
};
|
|
2530
|
+
var DEFAULT_RELAY_SUBAGENT_PROVIDERS = [...VALID_RELAY_SUBAGENT_PROVIDERS];
|
|
2520
2531
|
var DEFAULT_USER_PREFERENCES = {
|
|
2521
2532
|
default_agent: "codex",
|
|
2522
2533
|
default_model: null,
|
|
@@ -4633,7 +4644,8 @@ function loadEngineEnv() {
|
|
|
4633
4644
|
REPLICAS_DISABLE_GH_PR_MERGE: readEnv("REPLICAS_DISABLE_GH_PR_MERGE")?.toLowerCase() === "true",
|
|
4634
4645
|
REPLICAS_ENV_SYSTEM_PROMPT: readEnv("REPLICAS_ENV_SYSTEM_PROMPT"),
|
|
4635
4646
|
REPLICAS_ENV_START_HOOK: readEnv("REPLICAS_ENV_START_HOOK"),
|
|
4636
|
-
REPLICAS_DISABLE_AUTO_START_HOOKS: readEnv("REPLICAS_DISABLE_AUTO_START_HOOKS")?.toLowerCase() === "true"
|
|
4647
|
+
REPLICAS_DISABLE_AUTO_START_HOOKS: readEnv("REPLICAS_DISABLE_AUTO_START_HOOKS")?.toLowerCase() === "true",
|
|
4648
|
+
REPLICAS_ENGINE_DEFER_INITIALIZATION: readEnv("REPLICAS_ENGINE_DEFER_INITIALIZATION")?.toLowerCase() === "true"
|
|
4637
4649
|
};
|
|
4638
4650
|
if (!IS_WARMING_MODE && !env.WORKSPACE_ID) {
|
|
4639
4651
|
console.error("WORKSPACE_ID is not set \u2014 this is required in normal (non-warming) mode");
|
|
@@ -4773,6 +4785,18 @@ async function monolithRequest(path6, init = {}) {
|
|
|
4773
4785
|
});
|
|
4774
4786
|
}
|
|
4775
4787
|
var MonolithService = class {
|
|
4788
|
+
async getRelaySubagentProviders() {
|
|
4789
|
+
try {
|
|
4790
|
+
const response = await monolithRequest("/v1/engine/relay-subagent-providers", { method: "GET" });
|
|
4791
|
+
if (!response.ok) {
|
|
4792
|
+
return null;
|
|
4793
|
+
}
|
|
4794
|
+
const body = await response.json();
|
|
4795
|
+
return isRecord(body) && Array.isArray(body.providers) && body.providers.every((provider) => typeof provider === "string" && isValidAgentProvider(provider)) ? body.providers : null;
|
|
4796
|
+
} catch {
|
|
4797
|
+
return null;
|
|
4798
|
+
}
|
|
4799
|
+
}
|
|
4776
4800
|
async sendEvent(event) {
|
|
4777
4801
|
if (!ENGINE_ENV.WORKSPACE_ID) {
|
|
4778
4802
|
return;
|
|
@@ -9761,7 +9785,7 @@ var DEFAULT_CODEX_ARGS = ["app-server", "--listen", "stdio://"];
|
|
|
9761
9785
|
var MIN_CODEX_CLI_VERSION = "0.144.6";
|
|
9762
9786
|
var CODEX_UPGRADE_TIMEOUT_MS = 12e4;
|
|
9763
9787
|
var codexCliVersionEnsured = null;
|
|
9764
|
-
var ENGINE_PACKAGE_VERSION = "0.1.
|
|
9788
|
+
var ENGINE_PACKAGE_VERSION = "0.1.467";
|
|
9765
9789
|
var INITIALIZE_METHOD = "initialize";
|
|
9766
9790
|
var INITIALIZED_NOTIFICATION = "initialized";
|
|
9767
9791
|
var ACCOUNT_LOGIN_START_METHOD = "account/login/start";
|
|
@@ -13173,6 +13197,9 @@ import { createSdkMcpServer, tool } from "@anthropic-ai/claude-agent-sdk";
|
|
|
13173
13197
|
import { z as z3 } from "zod";
|
|
13174
13198
|
|
|
13175
13199
|
// src/managers/relay-providers.ts
|
|
13200
|
+
function isRelaySubagentProviderAllowed(provider, allowedProviders) {
|
|
13201
|
+
return allowedProviders.includes(provider);
|
|
13202
|
+
}
|
|
13176
13203
|
function getAvailableRelayProviders(availability) {
|
|
13177
13204
|
const codexAvailable = availability.codexAvailable ?? false;
|
|
13178
13205
|
const cursorAvailable = availability.cursorAvailable ?? false;
|
|
@@ -13277,7 +13304,7 @@ async function getChatFinalResponse(chatId) {
|
|
|
13277
13304
|
}
|
|
13278
13305
|
return "[No response from subagent]";
|
|
13279
13306
|
}
|
|
13280
|
-
function buildSpawnAgentTool(parentChatId, availability = {}) {
|
|
13307
|
+
function buildSpawnAgentTool(parentChatId, availability = {}, getAllowedProviders = () => monolithService.getRelaySubagentProviders()) {
|
|
13281
13308
|
const codexAvailable = availability.codexAvailable ?? false;
|
|
13282
13309
|
const cursorAvailable = availability.cursorAvailable ?? false;
|
|
13283
13310
|
const opencodeAvailable = availability.opencodeAvailable ?? false;
|
|
@@ -13316,9 +13343,23 @@ You will also receive the chatId so you can send follow-up messages or clean up
|
|
|
13316
13343
|
},
|
|
13317
13344
|
async (args) => {
|
|
13318
13345
|
try {
|
|
13346
|
+
const provider = args.provider;
|
|
13347
|
+
const allowedProviders = await getAllowedProviders();
|
|
13348
|
+
if (!allowedProviders) {
|
|
13349
|
+
return {
|
|
13350
|
+
content: [{ type: "text", text: "Unable to verify Relay subagent settings. Please try again." }],
|
|
13351
|
+
isError: true
|
|
13352
|
+
};
|
|
13353
|
+
}
|
|
13354
|
+
if (!isRelaySubagentProviderAllowed(provider, allowedProviders)) {
|
|
13355
|
+
return {
|
|
13356
|
+
content: [{ type: "text", text: `Relay is not allowed to use ${provider} as a subagent.` }],
|
|
13357
|
+
isError: true
|
|
13358
|
+
};
|
|
13359
|
+
}
|
|
13319
13360
|
const createBody = {
|
|
13320
|
-
provider
|
|
13321
|
-
title: args.title || `Subagent (${
|
|
13361
|
+
provider,
|
|
13362
|
+
title: args.title || `Subagent (${provider})`
|
|
13322
13363
|
};
|
|
13323
13364
|
if (parentChatId) {
|
|
13324
13365
|
createBody.parentChatId = parentChatId;
|
|
@@ -13435,11 +13476,11 @@ var deleteAgentTool = tool(
|
|
|
13435
13476
|
}
|
|
13436
13477
|
}
|
|
13437
13478
|
);
|
|
13438
|
-
function createRelayMcpServer(parentChatId, availability = {}) {
|
|
13479
|
+
function createRelayMcpServer(parentChatId, availability = {}, getAllowedProviders) {
|
|
13439
13480
|
return createSdkMcpServer({
|
|
13440
13481
|
name: "relay-subagent-tools",
|
|
13441
13482
|
version: "1.0.0",
|
|
13442
|
-
tools: [buildSpawnAgentTool(parentChatId, availability), messageAgentTool, deleteAgentTool]
|
|
13483
|
+
tools: [buildSpawnAgentTool(parentChatId, availability, getAllowedProviders), messageAgentTool, deleteAgentTool]
|
|
13443
13484
|
});
|
|
13444
13485
|
}
|
|
13445
13486
|
|
|
@@ -16715,6 +16756,7 @@ var heartbeatService = new HeartbeatService();
|
|
|
16715
16756
|
// src/index.ts
|
|
16716
16757
|
var startupStartedAt = performance.now();
|
|
16717
16758
|
var startupTimings = {};
|
|
16759
|
+
var ENGINE_INIT_GATE_TIMEOUT_MS = 35 * 60 * 1e3;
|
|
16718
16760
|
var resolveEngineReady = () => {
|
|
16719
16761
|
};
|
|
16720
16762
|
var engineReadyPromise = new Promise((resolve4) => {
|
|
@@ -16731,6 +16773,16 @@ async function timeStartupStep(name, fn) {
|
|
|
16731
16773
|
};
|
|
16732
16774
|
}
|
|
16733
16775
|
}
|
|
16776
|
+
async function waitForInitializationGate() {
|
|
16777
|
+
if (!ENGINE_ENV.REPLICAS_ENGINE_DEFER_INITIALIZATION) return;
|
|
16778
|
+
const deadline = Date.now() + ENGINE_INIT_GATE_TIMEOUT_MS;
|
|
16779
|
+
while (!existsSync11(SANDBOX_PATHS.ENGINE_INIT_GATE)) {
|
|
16780
|
+
if (Date.now() >= deadline) {
|
|
16781
|
+
throw new Error("Timed out waiting for deferred engine initialization gate");
|
|
16782
|
+
}
|
|
16783
|
+
await new Promise((resolve4) => setTimeout(resolve4, 25));
|
|
16784
|
+
}
|
|
16785
|
+
}
|
|
16734
16786
|
await timeStartupStep("engine_logger_initialize", () => engineLogger.initialize());
|
|
16735
16787
|
process.on("uncaughtException", (error) => {
|
|
16736
16788
|
console.error("[FATAL] Uncaught exception:", error);
|
|
@@ -16974,6 +17026,7 @@ serve(
|
|
|
16974
17026
|
} else {
|
|
16975
17027
|
console.log(`Replicas Engine running on port ${info.port}`);
|
|
16976
17028
|
}
|
|
17029
|
+
await timeStartupStep("wait_for_initialization_gate", waitForInitializationGate);
|
|
16977
17030
|
const gitResult = await timeStartupStep("git_initialize", () => gitService.initializeGitRepository());
|
|
16978
17031
|
if (!gitResult.success && gitResult.error) {
|
|
16979
17032
|
console.warn(`Git initialization warning: ${gitResult.error}`);
|