replicas-engine 0.1.651 → 0.1.652

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.
@@ -782,6 +782,12 @@ function createAcceptedUserMessageEvent(message, messageId, timestamp, images) {
782
782
  }
783
783
  };
784
784
  }
785
+ function getCodexAspTurnResponse(turn) {
786
+ const finalAnswer = turn.items.find((item) => item.type === "agentMessage" && item.phase === "final_answer");
787
+ if (finalAnswer) return finalAnswer;
788
+ if (normalizeCodexAspTranscriptStatus(turn.status) === "in_progress") return null;
789
+ return turn.items.findLast((item) => item.type === "agentMessage") ?? null;
790
+ }
785
791
  function isCodexAspTranscript(value) {
786
792
  if (!isRecord(value)) return false;
787
793
  return typeof value.threadId === "string" && typeof value.updatedAt === "string" && Array.isArray(value.turns);
@@ -5397,10 +5403,11 @@ function parseCodexAspTranscript(transcript) {
5397
5403
  for (const turn of transcript.turns) {
5398
5404
  const reasoningIndex = coalescedItems.findIndex(({ item, turn: itemTurn }) => itemTurn.id === turn.id && item.type === "reasoning");
5399
5405
  if (reasoningIndex === -1) continue;
5400
- let finalAnswerIndex = coalescedItems.findIndex(({ item, turn: itemTurn }) => itemTurn.id === turn.id && item.type === "agentMessage" && item.phase === "final_answer");
5401
- if (finalAnswerIndex === -1 && normalizeCodexAspTranscriptStatus(turn.status) !== "in_progress") {
5402
- finalAnswerIndex = coalescedItems.findLastIndex(({ item, turn: itemTurn }) => itemTurn.id === turn.id && item.type === "agentMessage");
5403
- }
5406
+ const responseItem = getCodexAspTurnResponse({
5407
+ status: turn.status,
5408
+ items: coalescedItems.filter(({ turn: itemTurn }) => itemTurn.id === turn.id).map(({ item }) => item)
5409
+ });
5410
+ const finalAnswerIndex = responseItem ? coalescedItems.findIndex(({ item }) => item === responseItem) : -1;
5404
5411
  if (finalAnswerIndex === -1 || reasoningIndex < finalAnswerIndex) continue;
5405
5412
  const [reasoning] = coalescedItems.splice(reasoningIndex, 1);
5406
5413
  coalescedItems.splice(finalAnswerIndex, 0, reasoning);
@@ -5922,7 +5929,7 @@ var DEFAULT_CODEX_ARGS = [
5922
5929
  var MIN_CODEX_CLI_VERSION = "0.144.6";
5923
5930
  var CODEX_UPGRADE_TIMEOUT_MS = 12e4;
5924
5931
  var codexCliVersionEnsured = null;
5925
- var ENGINE_PACKAGE_VERSION = "0.1.651";
5932
+ var ENGINE_PACKAGE_VERSION = "0.1.652";
5926
5933
  var INITIALIZE_METHOD = "initialize";
5927
5934
  var INITIALIZED_NOTIFICATION = "initialized";
5928
5935
  var ACCOUNT_LOGIN_START_METHOD = "account/login/start";
@@ -6250,6 +6257,7 @@ export {
6250
6257
  normalizeCodexAspTranscriptStatus,
6251
6258
  imageContentToUserMessageImages,
6252
6259
  createAcceptedUserMessageEvent,
6260
+ getCodexAspTurnResponse,
6253
6261
  isCodexAspTranscript,
6254
6262
  isCodexAspTranscriptDelta,
6255
6263
  applyCodexAspTranscriptDelta,
@@ -7,7 +7,7 @@ import {
7
7
  isUnsafeMemoryOutput,
8
8
  putPresignedFile,
9
9
  recoverCompletedTurn
10
- } from "./chunk-CJKDLHFP.js";
10
+ } from "./chunk-XUQTF7P5.js";
11
11
 
12
12
  // src/headless-agent.ts
13
13
  import { createHash } from "crypto";
package/dist/src/index.js CHANGED
@@ -119,6 +119,7 @@ import {
119
119
  findPrMergeSignals,
120
120
  getChatHistoryPageWindow,
121
121
  getClaudeModelContextWindow,
122
+ getCodexAspTurnResponse,
122
123
  getDefaultAgentModel,
123
124
  getEventTimestampMs,
124
125
  getGoalCommand,
@@ -172,7 +173,7 @@ import {
172
173
  serializeCanvasContentResponse,
173
174
  shellQuotePosix,
174
175
  stripAgentDiagnosticErrors
175
- } from "./chunk-CJKDLHFP.js";
176
+ } from "./chunk-XUQTF7P5.js";
176
177
 
177
178
  // src/index.ts
178
179
  import { serve } from "@hono/node-server";
@@ -9181,16 +9182,11 @@ async function waitForChatCompletion(chatId, timeoutMs = DEFAULT_SUBAGENT_TIMEOU
9181
9182
  }
9182
9183
  throw new Error(`Subagent chat ${chatId} timed out after ${timeoutMs}ms`);
9183
9184
  }
9184
- async function getChatFinalResponse(chatId) {
9185
- const res = await engineFetch(`/chats/${chatId}/history`);
9186
- if (!res.ok) {
9187
- return "[Failed to retrieve subagent history]";
9188
- }
9189
- let history;
9190
- try {
9191
- history = await res.json();
9192
- } catch {
9193
- return "[Failed to parse subagent history (response may have been interrupted)]";
9185
+ function extractFinalResponse(history) {
9186
+ const turns = history.codexAspTranscript?.turns ?? [];
9187
+ for (let turnIndex = turns.length - 1; turnIndex >= 0; turnIndex--) {
9188
+ const response = getCodexAspTurnResponse(turns[turnIndex]);
9189
+ if (response?.text) return response.text;
9194
9190
  }
9195
9191
  const events = history.events || [];
9196
9192
  for (let i = events.length - 1; i >= 0; i--) {
@@ -9226,7 +9222,20 @@ async function getChatFinalResponse(chatId) {
9226
9222
  if (text) return text;
9227
9223
  }
9228
9224
  }
9229
- return "[No response from subagent]";
9225
+ return null;
9226
+ }
9227
+ async function getChatFinalResponse(chatId) {
9228
+ const res = await engineFetch(`/chats/${chatId}/history`);
9229
+ if (!res.ok) {
9230
+ return "[Failed to retrieve subagent history]";
9231
+ }
9232
+ let history;
9233
+ try {
9234
+ history = await res.json();
9235
+ } catch {
9236
+ return "[Failed to parse subagent history (response may have been interrupted)]";
9237
+ }
9238
+ return extractFinalResponse(history) ?? "[No response from subagent]";
9230
9239
  }
9231
9240
  function buildSpawnAgentTool(parentChatId, availability = {}, getAllowedProviders = () => monolithService.getRelaySubagentProviders()) {
9232
9241
  const codexAvailable = availability.codexAvailable ?? false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "replicas-engine",
3
- "version": "0.1.651",
3
+ "version": "0.1.652",
4
4
  "description": "Lightweight API server for Replicas workspaces",
5
5
  "type": "module",
6
6
  "main": "dist/src/index.js",