replicas-engine 0.1.573 → 0.1.575
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 +88 -10
- package/package.json +1 -1
package/dist/src/index.js
CHANGED
|
@@ -785,10 +785,39 @@ function parsePosixEnvFile(content) {
|
|
|
785
785
|
|
|
786
786
|
// ../shared/src/git.ts
|
|
787
787
|
var GIT_CREDENTIAL_HELPER_FILENAME = ".git-credential-replicas";
|
|
788
|
+
var GITLAB_CREDENTIAL_REFRESH_PATH = "/git-credentials/gitlab/refresh";
|
|
788
789
|
function buildGitCredentialHelperScript(credentialsPath) {
|
|
789
790
|
return `#!/bin/sh
|
|
791
|
+
request=$(cat)
|
|
792
|
+
|
|
793
|
+
get_credential() {
|
|
794
|
+
printf '%s
|
|
795
|
+
' "$request" | git credential-store --file=${shellQuotePosix(credentialsPath)} get
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
refresh_gitlab_credential() {
|
|
799
|
+
[ -n "\${REPLICAS_ENGINE_SECRET:-}" ] || return 1
|
|
800
|
+
command -v curl >/dev/null 2>&1 || return 1
|
|
801
|
+
curl --silent --fail --connect-timeout 1 --max-time 5 -X POST -H "X-Replicas-Engine-Secret: $REPLICAS_ENGINE_SECRET" "http://127.0.0.1:\${REPLICAS_ENGINE_PORT:-3737}${GITLAB_CREDENTIAL_REFRESH_PATH}" >/dev/null 2>&1
|
|
802
|
+
}
|
|
803
|
+
|
|
790
804
|
if [ "$1" = "get" ]; then
|
|
791
|
-
|
|
805
|
+
credential=$(get_credential)
|
|
806
|
+
if printf '%s
|
|
807
|
+
%s
|
|
808
|
+
' "$request" "$credential" | grep -q '^username=oauth2$'; then
|
|
809
|
+
if refresh_gitlab_credential; then
|
|
810
|
+
refreshed_credential=$(get_credential)
|
|
811
|
+
if [ -n "$refreshed_credential" ]; then
|
|
812
|
+
credential=$refreshed_credential
|
|
813
|
+
fi
|
|
814
|
+
fi
|
|
815
|
+
fi
|
|
816
|
+
printf '%s
|
|
817
|
+
' "$credential"
|
|
818
|
+
elif [ "$1" = "erase" ] && printf '%s
|
|
819
|
+
' "$request" | grep -q '^username=oauth2$'; then
|
|
820
|
+
refresh_gitlab_credential || true
|
|
792
821
|
fi
|
|
793
822
|
exit 0
|
|
794
823
|
`;
|
|
@@ -5345,12 +5374,48 @@ function mergeCodexAspDisplayMessages(primary, supplemental) {
|
|
|
5345
5374
|
}
|
|
5346
5375
|
function parseCodexAspTranscript(transcript) {
|
|
5347
5376
|
const messages = [];
|
|
5348
|
-
const orderedItems = transcript.turns.map((turn, turnIndex) => ({ turn, turnIndex })).flatMap(({ turn, turnIndex }) => turn.items.map((item, itemIndex) => ({ item, turnIndex, itemIndex }))).sort((a, b) => {
|
|
5377
|
+
const orderedItems = transcript.turns.map((turn, turnIndex) => ({ turn, turnIndex })).flatMap(({ turn, turnIndex }) => turn.items.map((item, itemIndex) => ({ item, turn, turnIndex, itemIndex }))).sort((a, b) => {
|
|
5349
5378
|
const aSequence = a.item.sequence ?? Number.MAX_SAFE_INTEGER;
|
|
5350
5379
|
const bSequence = b.item.sequence ?? Number.MAX_SAFE_INTEGER;
|
|
5351
5380
|
return aSequence - bSequence || parseTimestampMs(a.item.timestamp) - parseTimestampMs(b.item.timestamp) || a.turnIndex - b.turnIndex || a.itemIndex - b.itemIndex;
|
|
5352
5381
|
});
|
|
5353
|
-
|
|
5382
|
+
const reasoningByTurnId = /* @__PURE__ */ new Map();
|
|
5383
|
+
for (const { item, turn } of orderedItems) {
|
|
5384
|
+
if (item.type !== "reasoning" || !item.text.trim()) continue;
|
|
5385
|
+
const reasoning = reasoningByTurnId.get(turn.id) ?? [];
|
|
5386
|
+
reasoning.push(item);
|
|
5387
|
+
reasoningByTurnId.set(turn.id, reasoning);
|
|
5388
|
+
}
|
|
5389
|
+
const emittedReasoningTurnIds = /* @__PURE__ */ new Set();
|
|
5390
|
+
const coalescedItems = orderedItems.flatMap((entry) => {
|
|
5391
|
+
if (entry.item.type !== "reasoning") return [entry];
|
|
5392
|
+
const reasoning = reasoningByTurnId.get(entry.turn.id);
|
|
5393
|
+
if (!reasoning || emittedReasoningTurnIds.has(entry.turn.id)) return [];
|
|
5394
|
+
emittedReasoningTurnIds.add(entry.turn.id);
|
|
5395
|
+
return [{
|
|
5396
|
+
...entry,
|
|
5397
|
+
item: {
|
|
5398
|
+
type: "reasoning",
|
|
5399
|
+
id: entry.turn.id,
|
|
5400
|
+
text: reasoning.map(({ text }) => text.trim()).join("\n\n"),
|
|
5401
|
+
timestamp: entry.turn.startedAt,
|
|
5402
|
+
status: reasoning.at(-1)?.status ?? "completed",
|
|
5403
|
+
sequence: entry.item.sequence
|
|
5404
|
+
}
|
|
5405
|
+
}];
|
|
5406
|
+
});
|
|
5407
|
+
for (const turn of transcript.turns) {
|
|
5408
|
+
const reasoningIndex = coalescedItems.findIndex(({ item, turn: itemTurn }) => itemTurn.id === turn.id && item.type === "reasoning");
|
|
5409
|
+
if (reasoningIndex === -1) continue;
|
|
5410
|
+
let finalAnswerIndex = coalescedItems.findIndex(({ item, turn: itemTurn }) => itemTurn.id === turn.id && item.type === "agentMessage" && item.phase === "final_answer");
|
|
5411
|
+
if (finalAnswerIndex === -1 && normalizeCodexAspTranscriptStatus(turn.status) !== "in_progress") {
|
|
5412
|
+
finalAnswerIndex = coalescedItems.findLastIndex(({ item, turn: itemTurn }) => itemTurn.id === turn.id && item.type === "agentMessage");
|
|
5413
|
+
}
|
|
5414
|
+
if (finalAnswerIndex === -1 || reasoningIndex < finalAnswerIndex) continue;
|
|
5415
|
+
const [reasoning] = coalescedItems.splice(reasoningIndex, 1);
|
|
5416
|
+
coalescedItems.splice(finalAnswerIndex, 0, reasoning);
|
|
5417
|
+
}
|
|
5418
|
+
for (const { item } of coalescedItems) {
|
|
5354
5419
|
const message = messageForItem(item);
|
|
5355
5420
|
if (message) {
|
|
5356
5421
|
messages.push(message);
|
|
@@ -5720,21 +5785,23 @@ var BaseRefreshManager = class {
|
|
|
5720
5785
|
}
|
|
5721
5786
|
async refreshOnce() {
|
|
5722
5787
|
if (this.getSkipReason()) {
|
|
5723
|
-
return;
|
|
5788
|
+
return createSuccessResult();
|
|
5724
5789
|
}
|
|
5725
5790
|
const config = this.getRuntimeConfig();
|
|
5726
|
-
if (!config) return;
|
|
5791
|
+
if (!config) return createSuccessResult();
|
|
5727
5792
|
this.health.lastAttemptAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
5728
5793
|
try {
|
|
5729
5794
|
await this.doRefresh(config);
|
|
5730
5795
|
this.health.lastSuccessAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
5731
5796
|
this.health.lastErrorAt = null;
|
|
5732
5797
|
this.health.lastErrorMessage = null;
|
|
5798
|
+
return createSuccessResult();
|
|
5733
5799
|
} catch (error) {
|
|
5734
5800
|
const message = error instanceof Error ? error.message : "Unknown error";
|
|
5735
5801
|
this.health.lastErrorAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
5736
5802
|
this.health.lastErrorMessage = message;
|
|
5737
5803
|
console.error(`[${this.managerName}] Failed to refresh credentials:`, error);
|
|
5804
|
+
return createErrorResult({ message });
|
|
5738
5805
|
}
|
|
5739
5806
|
}
|
|
5740
5807
|
};
|
|
@@ -10787,7 +10854,7 @@ var DEFAULT_CODEX_ARGS = ["app-server", "--listen", "stdio://"];
|
|
|
10787
10854
|
var MIN_CODEX_CLI_VERSION = "0.144.6";
|
|
10788
10855
|
var CODEX_UPGRADE_TIMEOUT_MS = 12e4;
|
|
10789
10856
|
var codexCliVersionEnsured = null;
|
|
10790
|
-
var ENGINE_PACKAGE_VERSION = "0.1.
|
|
10857
|
+
var ENGINE_PACKAGE_VERSION = "0.1.575";
|
|
10791
10858
|
var INITIALIZE_METHOD = "initialize";
|
|
10792
10859
|
var INITIALIZED_NOTIFICATION = "initialized";
|
|
10793
10860
|
var ACCOUNT_LOGIN_START_METHOD = "account/login/start";
|
|
@@ -11222,6 +11289,7 @@ function itemToTranscriptItem(item, timestamp, status) {
|
|
|
11222
11289
|
type: "agentMessage",
|
|
11223
11290
|
id: item.id,
|
|
11224
11291
|
text: item.text,
|
|
11292
|
+
phase: item.phase,
|
|
11225
11293
|
timestamp
|
|
11226
11294
|
};
|
|
11227
11295
|
}
|
|
@@ -18063,14 +18131,14 @@ data: ${JSON.stringify("Terminal session not found")}
|
|
|
18063
18131
|
});
|
|
18064
18132
|
app2.post("/codex/refresh-now", async (c) => {
|
|
18065
18133
|
try {
|
|
18066
|
-
await codexTokenManager.refreshOnce();
|
|
18067
|
-
|
|
18068
|
-
if (status.lastErrorAt && (!status.lastSuccessAt || status.lastErrorAt > status.lastSuccessAt)) {
|
|
18134
|
+
const result = await codexTokenManager.refreshOnce();
|
|
18135
|
+
if (!result.ok) {
|
|
18069
18136
|
return c.json(
|
|
18070
|
-
jsonError("Failed to refresh Codex credentials",
|
|
18137
|
+
jsonError("Failed to refresh Codex credentials", result.error.message),
|
|
18071
18138
|
502
|
|
18072
18139
|
);
|
|
18073
18140
|
}
|
|
18141
|
+
const status = codexTokenManager.getHealthStatus();
|
|
18074
18142
|
return c.json({ success: true, lastSuccessAt: status.lastSuccessAt });
|
|
18075
18143
|
} catch (error) {
|
|
18076
18144
|
return c.json(
|
|
@@ -18621,6 +18689,16 @@ app.get("/token-refresh/health", async (c) => {
|
|
|
18621
18689
|
infisical: infisicalTokenManager.getHealthStatus()
|
|
18622
18690
|
});
|
|
18623
18691
|
});
|
|
18692
|
+
app.post(GITLAB_CREDENTIAL_REFRESH_PATH, async (c) => {
|
|
18693
|
+
const result = await gitlabTokenManager.refreshOnce();
|
|
18694
|
+
if (!result.ok) {
|
|
18695
|
+
return c.json({
|
|
18696
|
+
error: "Failed to refresh GitLab credentials",
|
|
18697
|
+
details: result.error.message
|
|
18698
|
+
}, 502);
|
|
18699
|
+
}
|
|
18700
|
+
return c.body(null, 204);
|
|
18701
|
+
});
|
|
18624
18702
|
var repoFileService = new RepoFileService(gitService);
|
|
18625
18703
|
app.route("/", createV1Routes({ chatService, repoFileService }));
|
|
18626
18704
|
var port = ENGINE_ENV.REPLICAS_ENGINE_PORT;
|