replicas-engine 0.1.455 → 0.1.461
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 +60 -43
- package/package.json +1 -1
package/dist/src/index.js
CHANGED
|
@@ -543,7 +543,7 @@ var WORKSPACE_SIZES = ["small", "large"];
|
|
|
543
543
|
var INVALID_WORKSPACE_SIZE_ERROR = `Invalid size: must be one of ${WORKSPACE_SIZES.join(", ")}`;
|
|
544
544
|
|
|
545
545
|
// ../shared/src/e2b.ts
|
|
546
|
-
var E2B_TEMPLATE_NAME = "replicas-sandbox-2026-07-19-
|
|
546
|
+
var E2B_TEMPLATE_NAME = "replicas-sandbox-2026-07-19-v13";
|
|
547
547
|
|
|
548
548
|
// ../shared/src/runtime-env.ts
|
|
549
549
|
function shellQuotePosix(value) {
|
|
@@ -6774,6 +6774,15 @@ var CodingAgentManager = class {
|
|
|
6774
6774
|
};
|
|
6775
6775
|
|
|
6776
6776
|
// src/utils/agent-env.ts
|
|
6777
|
+
function resolveClaudeAuthMethodForMessage(env = ENGINE_ENV) {
|
|
6778
|
+
const method = env.REPLICAS_CLAUDE_AUTH_METHOD;
|
|
6779
|
+
if (method && method !== "none") {
|
|
6780
|
+
return method;
|
|
6781
|
+
}
|
|
6782
|
+
if (env.CLAUDE_CODE_USE_BEDROCK === "1") return "bedrock";
|
|
6783
|
+
if (env.ANTHROPIC_API_KEY) return "api_key";
|
|
6784
|
+
return "unknown";
|
|
6785
|
+
}
|
|
6777
6786
|
function buildClaudeAgentEnv(overrides) {
|
|
6778
6787
|
const env = { ...process.env };
|
|
6779
6788
|
if (overrides) {
|
|
@@ -7790,7 +7799,7 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
|
|
|
7790
7799
|
);
|
|
7791
7800
|
}
|
|
7792
7801
|
claudeAuthFailureMessage() {
|
|
7793
|
-
switch (
|
|
7802
|
+
switch (resolveClaudeAuthMethodForMessage()) {
|
|
7794
7803
|
case "oauth":
|
|
7795
7804
|
return "Claude Code OAuth authentication failed after refreshing credentials. Reconnect Claude Code in Settings \u2192 Agents and try again.";
|
|
7796
7805
|
case "api_key":
|
|
@@ -7803,14 +7812,6 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
|
|
|
7803
7812
|
return "Claude authentication failed after multiple attempts. Check your Claude, Anthropic API key, or Bedrock credentials in Settings \u2192 Agents and try again.";
|
|
7804
7813
|
}
|
|
7805
7814
|
}
|
|
7806
|
-
resolveClaudeAuthMethodForMessage() {
|
|
7807
|
-
if (ENGINE_ENV.REPLICAS_CLAUDE_AUTH_METHOD === "oauth" || ENGINE_ENV.REPLICAS_CLAUDE_AUTH_METHOD === "api_key" || ENGINE_ENV.REPLICAS_CLAUDE_AUTH_METHOD === "bedrock" || ENGINE_ENV.REPLICAS_CLAUDE_AUTH_METHOD === "foundry") {
|
|
7808
|
-
return ENGINE_ENV.REPLICAS_CLAUDE_AUTH_METHOD;
|
|
7809
|
-
}
|
|
7810
|
-
if (ENGINE_ENV.CLAUDE_CODE_USE_BEDROCK === "1" || ENGINE_ENV.AWS_ACCESS_KEY_ID || ENGINE_ENV.AWS_SECRET_ACCESS_KEY) return "bedrock";
|
|
7811
|
-
if (ENGINE_ENV.ANTHROPIC_API_KEY) return "api_key";
|
|
7812
|
-
return "unknown";
|
|
7813
|
-
}
|
|
7814
7815
|
async emitMidTurnExhaustedEvent(error) {
|
|
7815
7816
|
const detail = error instanceof Error ? error.message : String(error);
|
|
7816
7817
|
await this.emitTerminalErrorResult(
|
|
@@ -8604,7 +8605,7 @@ var DEFAULT_CODEX_ARGS = ["app-server", "--listen", "stdio://"];
|
|
|
8604
8605
|
var MIN_CODEX_CLI_VERSION = "0.144.0";
|
|
8605
8606
|
var CODEX_UPGRADE_TIMEOUT_MS = 12e4;
|
|
8606
8607
|
var codexCliVersionEnsured = null;
|
|
8607
|
-
var ENGINE_PACKAGE_VERSION = "0.1.
|
|
8608
|
+
var ENGINE_PACKAGE_VERSION = "0.1.461";
|
|
8608
8609
|
var INITIALIZE_METHOD = "initialize";
|
|
8609
8610
|
var INITIALIZED_NOTIFICATION = "initialized";
|
|
8610
8611
|
var ACCOUNT_LOGIN_START_METHOD = "account/login/start";
|
|
@@ -8847,24 +8848,32 @@ function buildCodexRateLimitsSnapshot(fields) {
|
|
|
8847
8848
|
var CodexQuotaStatusTracker = class {
|
|
8848
8849
|
lastEmittedQuotaState = "ok";
|
|
8849
8850
|
latestQuotaSnapshot = null;
|
|
8850
|
-
|
|
8851
|
-
|
|
8852
|
-
|
|
8853
|
-
|
|
8854
|
-
|
|
8855
|
-
|
|
8856
|
-
}
|
|
8857
|
-
prime(snapshot) {
|
|
8851
|
+
// OpenAI keeps `rate_limit_reached_type` set in snapshots even while requests
|
|
8852
|
+
// still succeed (the flag is sticky until an authoritative snapshot clears it),
|
|
8853
|
+
// so an out_of_credits reading on its own is not trustworthy. Record it here,
|
|
8854
|
+
// and only surface it via confirmOutOfCredits() once a turn actually fails
|
|
8855
|
+
// with a quota error.
|
|
8856
|
+
observe(snapshot) {
|
|
8858
8857
|
this.latestQuotaSnapshot = snapshot;
|
|
8859
|
-
|
|
8858
|
+
if (snapshot.state === "out_of_credits") return null;
|
|
8859
|
+
if (snapshot.state === this.lastEmittedQuotaState) return null;
|
|
8860
|
+
return this.emit(snapshot);
|
|
8861
|
+
}
|
|
8862
|
+
confirmOutOfCredits() {
|
|
8863
|
+
if (this.latestQuotaSnapshot?.state !== "out_of_credits") return null;
|
|
8864
|
+
return this.emit(this.latestQuotaSnapshot);
|
|
8865
|
+
}
|
|
8866
|
+
recordTurnSuccess() {
|
|
8867
|
+
if (this.lastEmittedQuotaState === "ok") return null;
|
|
8868
|
+
return this.emit({
|
|
8869
|
+
state: "ok",
|
|
8870
|
+
balance: this.latestQuotaSnapshot?.balance ?? null,
|
|
8871
|
+
rateLimitResetType: null,
|
|
8872
|
+
planType: this.latestQuotaSnapshot?.planType ?? null
|
|
8873
|
+
});
|
|
8860
8874
|
}
|
|
8861
|
-
|
|
8862
|
-
const stateChanged = snapshot.state !== this.lastEmittedQuotaState;
|
|
8863
|
-
if (!stateChanged && !force) {
|
|
8864
|
-
return null;
|
|
8865
|
-
}
|
|
8875
|
+
emit(snapshot) {
|
|
8866
8876
|
this.lastEmittedQuotaState = snapshot.state;
|
|
8867
|
-
this.quotaBlocked = snapshot.state === "out_of_credits";
|
|
8868
8877
|
this.latestQuotaSnapshot = snapshot;
|
|
8869
8878
|
const payload = {
|
|
8870
8879
|
state: snapshot.state,
|
|
@@ -8872,12 +8881,11 @@ var CodexQuotaStatusTracker = class {
|
|
|
8872
8881
|
rateLimitResetType: snapshot.rateLimitResetType,
|
|
8873
8882
|
planType: snapshot.planType
|
|
8874
8883
|
};
|
|
8875
|
-
|
|
8884
|
+
return {
|
|
8876
8885
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
8877
8886
|
type: CODEX_QUOTA_STATUS_EVENT_TYPE,
|
|
8878
8887
|
payload
|
|
8879
8888
|
};
|
|
8880
|
-
return event;
|
|
8881
8889
|
}
|
|
8882
8890
|
};
|
|
8883
8891
|
|
|
@@ -9145,6 +9153,18 @@ function aspGoalToChatGoal(goal) {
|
|
|
9145
9153
|
updatedAt: timestampFromSeconds(goal.updatedAt)
|
|
9146
9154
|
};
|
|
9147
9155
|
}
|
|
9156
|
+
function isQuotaTurnFailure(turn) {
|
|
9157
|
+
const info = turn.error?.codexErrorInfo;
|
|
9158
|
+
if (!info) return false;
|
|
9159
|
+
if (info === "usageLimitExceeded") return true;
|
|
9160
|
+
if (typeof info === "object") {
|
|
9161
|
+
return Object.values(info).some((detail) => isRecord4(detail) && detail.httpStatusCode === 429);
|
|
9162
|
+
}
|
|
9163
|
+
return false;
|
|
9164
|
+
}
|
|
9165
|
+
function isQuotaErrorMessage(error) {
|
|
9166
|
+
return error instanceof Error && /\b429\b|rate.?limit|usage.?limit|quota|out.of.credits|credits?.?(?:depleted|exhausted|remaining)/i.test(error.message);
|
|
9167
|
+
}
|
|
9148
9168
|
function formatTurnFailure(turn) {
|
|
9149
9169
|
const turnError = turn.error;
|
|
9150
9170
|
if (!turnError) {
|
|
@@ -9840,14 +9860,6 @@ var CodexAspManager = class extends CodingAgentManager {
|
|
|
9840
9860
|
}
|
|
9841
9861
|
async executeAspTurn(request, recordUserMessage, options = {}) {
|
|
9842
9862
|
const host = await getCodexAspHost();
|
|
9843
|
-
if (this.quotaStatus.blocked && this.quotaStatus.latestSnapshot) {
|
|
9844
|
-
await this.refreshQuotaSnapshot(host);
|
|
9845
|
-
if (this.quotaStatus.blocked && this.quotaStatus.latestSnapshot) {
|
|
9846
|
-
recordUserMessage(options.userMessagePayload);
|
|
9847
|
-
this.emitQuotaStatus(this.quotaStatus.latestSnapshot, true);
|
|
9848
|
-
return;
|
|
9849
|
-
}
|
|
9850
|
-
}
|
|
9851
9863
|
const developerInstructions = this.buildCombinedInstructions(request.customInstructions);
|
|
9852
9864
|
recordUserMessage(options.userMessagePayload);
|
|
9853
9865
|
const threadId = await this.ensureThread(host, request, developerInstructions);
|
|
@@ -9858,19 +9870,18 @@ var CodexAspManager = class extends CodingAgentManager {
|
|
|
9858
9870
|
try {
|
|
9859
9871
|
completedTurn = await runTurn(host, threadId);
|
|
9860
9872
|
} catch (error) {
|
|
9861
|
-
await this.
|
|
9862
|
-
if (this.quotaStatus.blocked) {
|
|
9873
|
+
if (isQuotaErrorMessage(error) && await this.confirmOutOfCredits(host)) {
|
|
9863
9874
|
return;
|
|
9864
9875
|
}
|
|
9865
9876
|
throw error;
|
|
9866
9877
|
}
|
|
9867
9878
|
if (completedTurn.status === "failed") {
|
|
9868
|
-
await this.
|
|
9869
|
-
if (this.quotaStatus.blocked) {
|
|
9879
|
+
if (isQuotaTurnFailure(completedTurn) && await this.confirmOutOfCredits(host)) {
|
|
9870
9880
|
return;
|
|
9871
9881
|
}
|
|
9872
9882
|
throw new Error(formatTurnFailure(completedTurn));
|
|
9873
9883
|
}
|
|
9884
|
+
this.emitQuotaEvent(this.quotaStatus.recordTurnSuccess());
|
|
9874
9885
|
}
|
|
9875
9886
|
async ensureThread(host, request, developerInstructions) {
|
|
9876
9887
|
await this.applySkillRegistries(host);
|
|
@@ -10694,7 +10705,7 @@ var CodexAspManager = class extends CodingAgentManager {
|
|
|
10694
10705
|
handleRateLimits(rateLimits) {
|
|
10695
10706
|
const snapshot = extractRateLimitsSnapshot(rateLimits);
|
|
10696
10707
|
if (snapshot) {
|
|
10697
|
-
this.
|
|
10708
|
+
this.emitQuotaEvent(this.quotaStatus.observe(snapshot));
|
|
10698
10709
|
}
|
|
10699
10710
|
}
|
|
10700
10711
|
async refreshQuotaSnapshot(host) {
|
|
@@ -10707,8 +10718,14 @@ var CodexAspManager = class extends CodingAgentManager {
|
|
|
10707
10718
|
} catch {
|
|
10708
10719
|
}
|
|
10709
10720
|
}
|
|
10710
|
-
|
|
10711
|
-
|
|
10721
|
+
async confirmOutOfCredits(host) {
|
|
10722
|
+
await this.refreshQuotaSnapshot(host);
|
|
10723
|
+
const event = this.quotaStatus.confirmOutOfCredits();
|
|
10724
|
+
if (!event) return false;
|
|
10725
|
+
this.emitQuotaEvent(event);
|
|
10726
|
+
return true;
|
|
10727
|
+
}
|
|
10728
|
+
emitQuotaEvent(event) {
|
|
10712
10729
|
if (!event) return;
|
|
10713
10730
|
this.trackHistoryEvent(event);
|
|
10714
10731
|
this.onEvent(event);
|