meshy-node 0.6.2 → 0.6.4

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/main.cjs CHANGED
@@ -55874,16 +55874,147 @@ var fs8 = __toESM(require("fs"), 1);
55874
55874
  var os4 = __toESM(require("os"), 1);
55875
55875
  var path7 = __toESM(require("path"), 1);
55876
55876
 
55877
- // ../../packages/core/src/agents/copilot-transcript-events.ts
55877
+ // ../../packages/core/src/agents/codex-transcript-events.ts
55878
55878
  function isRecord2(value) {
55879
55879
  return typeof value === "object" && value !== null;
55880
55880
  }
55881
+ function buildAssistantTextEvent(text, timestamp = (/* @__PURE__ */ new Date()).toISOString()) {
55882
+ return {
55883
+ type: "assistant",
55884
+ message: {
55885
+ role: "assistant",
55886
+ content: [{ type: "text", text }]
55887
+ },
55888
+ timestamp
55889
+ };
55890
+ }
55891
+ function buildAssistantThinkingEvent(thinking, timestamp = (/* @__PURE__ */ new Date()).toISOString()) {
55892
+ return {
55893
+ type: "assistant",
55894
+ message: {
55895
+ role: "assistant",
55896
+ content: [{ type: "thinking", thinking }]
55897
+ },
55898
+ timestamp
55899
+ };
55900
+ }
55901
+ function buildAssistantToolUseEvent(id, name2, input, timestamp = (/* @__PURE__ */ new Date()).toISOString()) {
55902
+ return {
55903
+ type: "assistant",
55904
+ message: {
55905
+ role: "assistant",
55906
+ content: [{ type: "tool_use", id, name: name2, input }]
55907
+ },
55908
+ timestamp
55909
+ };
55910
+ }
55911
+ function extractCodexReasoningText(item) {
55912
+ if (typeof item.text === "string") {
55913
+ return item.text.trim();
55914
+ }
55915
+ if (Array.isArray(item.summary)) {
55916
+ return item.summary.map((entry) => {
55917
+ if (typeof entry === "string") return entry.trim();
55918
+ if (isRecord2(entry) && typeof entry.text === "string") {
55919
+ return entry.text.trim();
55920
+ }
55921
+ return "";
55922
+ }).filter(Boolean).join("\n\n");
55923
+ }
55924
+ return "";
55925
+ }
55926
+ function parseCodexToolInput(value) {
55927
+ if (isRecord2(value)) return value;
55928
+ if (typeof value !== "string") return {};
55929
+ const trimmed = value.trim();
55930
+ if (!trimmed) return {};
55931
+ try {
55932
+ const parsed = JSON.parse(trimmed);
55933
+ if (isRecord2(parsed)) return parsed;
55934
+ } catch {
55935
+ }
55936
+ return { arguments: trimmed };
55937
+ }
55938
+ function getToolCallId(payload) {
55939
+ for (const key of ["call_id", "id", "tool_call_id"]) {
55940
+ const value = payload[key];
55941
+ if (typeof value === "string" && value.trim()) {
55942
+ return value.trim();
55943
+ }
55944
+ }
55945
+ return "";
55946
+ }
55947
+ function getToolName(payload) {
55948
+ for (const key of ["name", "tool_name"]) {
55949
+ const value = payload[key];
55950
+ if (typeof value === "string" && value.trim()) {
55951
+ return value.trim();
55952
+ }
55953
+ }
55954
+ return "tool";
55955
+ }
55956
+ function getToolOutput(payload) {
55957
+ for (const key of ["output", "content", "result"]) {
55958
+ const value = payload[key];
55959
+ if (typeof value === "string" && value.trim()) {
55960
+ return value.trim();
55961
+ }
55962
+ }
55963
+ return "";
55964
+ }
55965
+ function convertCodexTranscriptPayload(payload, timestamp = (/* @__PURE__ */ new Date()).toISOString()) {
55966
+ if (payload.type === "user_message" && typeof payload.message === "string" && payload.message.trim()) {
55967
+ return [buildTaskUserLogEvent([{ type: "text", text: payload.message.trim() }], timestamp)];
55968
+ }
55969
+ if (payload.type === "agent_message" && typeof payload.message === "string" && payload.message.trim()) {
55970
+ return [buildAssistantTextEvent(payload.message.trim(), timestamp)];
55971
+ }
55972
+ if (payload.type === "agent_message" && typeof payload.text === "string" && payload.text.trim()) {
55973
+ return [buildAssistantTextEvent(payload.text.trim(), timestamp)];
55974
+ }
55975
+ if (payload.type === "agent_reasoning" || payload.type === "reasoning") {
55976
+ const reasoning = extractCodexReasoningText(payload);
55977
+ return reasoning ? [buildAssistantThinkingEvent(reasoning, timestamp)] : [];
55978
+ }
55979
+ if (payload.type === "function_call" || payload.type === "tool_call") {
55980
+ const callId = getToolCallId(payload);
55981
+ if (!callId) return [];
55982
+ return [buildAssistantToolUseEvent(
55983
+ callId,
55984
+ getToolName(payload),
55985
+ parseCodexToolInput(payload.arguments ?? payload.input),
55986
+ timestamp
55987
+ )];
55988
+ }
55989
+ if (payload.type === "function_call_output" || payload.type === "tool_call_output") {
55990
+ const callId = getToolCallId(payload);
55991
+ const output = getToolOutput(payload);
55992
+ if (!callId || !output) return [];
55993
+ return [buildTaskUserLogEvent([{ type: "tool_result", toolUseId: callId, content: output }], timestamp)];
55994
+ }
55995
+ return [];
55996
+ }
55997
+ function convertCodexTranscriptEvent(event) {
55998
+ const timestamp = typeof event.timestamp === "string" ? event.timestamp : (/* @__PURE__ */ new Date()).toISOString();
55999
+ if ((event.type === "event_msg" || event.type === "response_item") && isRecord2(event.payload)) {
56000
+ return convertCodexTranscriptPayload(event.payload, timestamp);
56001
+ }
56002
+ if (event.type === "item.completed" && isRecord2(event.item)) {
56003
+ return convertCodexTranscriptPayload(event.item, timestamp);
56004
+ }
56005
+ return [];
56006
+ }
56007
+
56008
+ // ../../packages/core/src/agents/copilot-transcript-events.ts
56009
+ function isRecord3(value) {
56010
+ return typeof value === "object" && value !== null;
56011
+ }
55881
56012
  function extractStringContent(value) {
55882
56013
  if (typeof value === "string") return value.trim();
55883
56014
  if (!Array.isArray(value)) return "";
55884
56015
  return value.map((part) => {
55885
56016
  if (typeof part === "string") return part.trim();
55886
- if (isRecord2(part)) {
56017
+ if (isRecord3(part)) {
55887
56018
  if (typeof part.text === "string") return part.text.trim();
55888
56019
  if (typeof part.content === "string") return part.content.trim();
55889
56020
  }
@@ -55901,9 +56032,9 @@ function buildAssistantContentEvent(content, timestamp) {
55901
56032
  };
55902
56033
  }
55903
56034
  function extractCopilotEventText(event) {
55904
- const data = isRecord2(event.data) ? event.data : void 0;
55905
- const message = isRecord2(event.message) ? event.message : void 0;
55906
- const dataMessage = isRecord2(data?.message) ? data.message : void 0;
56035
+ const data = isRecord3(event.data) ? event.data : void 0;
56036
+ const message = isRecord3(event.message) ? event.message : void 0;
56037
+ const dataMessage = isRecord3(data?.message) ? data.message : void 0;
55907
56038
  return extractStringContent(data?.content) || extractStringContent(data?.text) || extractStringContent(dataMessage?.content) || extractStringContent(dataMessage?.text) || extractStringContent(event.content) || extractStringContent(event.text) || extractStringContent(message?.content) || extractStringContent(message?.text);
55908
56039
  }
55909
56040
  function getStringField(record2, field) {
@@ -55911,14 +56042,14 @@ function getStringField(record2, field) {
55911
56042
  return typeof value === "string" ? value.trim() : "";
55912
56043
  }
55913
56044
  function normalizeCopilotToolInput(value) {
55914
- if (isRecord2(value)) return value;
56045
+ if (isRecord3(value)) return value;
55915
56046
  if (typeof value === "string" && value.trim()) {
55916
56047
  return { arguments: value.trim() };
55917
56048
  }
55918
56049
  return {};
55919
56050
  }
55920
56051
  function extractCopilotAssistantContent(event) {
55921
- const data = isRecord2(event.data) ? event.data : void 0;
56052
+ const data = isRecord3(event.data) ? event.data : void 0;
55922
56053
  const content = [];
55923
56054
  const reasoning = extractStringContent(data?.reasoningText) || extractStringContent(data?.reasoning);
55924
56055
  const text = extractCopilotEventText(event);
@@ -55930,7 +56061,7 @@ function extractCopilotAssistantContent(event) {
55930
56061
  }
55931
56062
  if (Array.isArray(data?.toolRequests)) {
55932
56063
  for (const request of data.toolRequests) {
55933
- if (!isRecord2(request)) continue;
56064
+ if (!isRecord3(request)) continue;
55934
56065
  const id = getStringField(request, "toolCallId") || getStringField(request, "id") || getStringField(request, "callId");
55935
56066
  const name2 = getStringField(request, "name") || getStringField(request, "toolName");
55936
56067
  if (!id || !name2) continue;
@@ -55945,8 +56076,8 @@ function extractCopilotAssistantContent(event) {
55945
56076
  return content;
55946
56077
  }
55947
56078
  function extractCopilotToolResult(event) {
55948
- const data = isRecord2(event.data) ? event.data : void 0;
55949
- const result = isRecord2(data?.result) ? data.result : void 0;
56079
+ const data = isRecord3(event.data) ? event.data : void 0;
56080
+ const result = isRecord3(data?.result) ? data.result : void 0;
55950
56081
  const toolUseId = getStringField(data, "toolCallId") || getStringField(data, "toolUseId") || getStringField(data, "id");
55951
56082
  const content = extractStringContent(result?.content) || extractStringContent(result?.detailedContent) || extractStringContent(data?.result) || extractStringContent(data?.content) || extractStringContent(data?.output);
55952
56083
  if (!toolUseId || !content) {
@@ -55986,7 +56117,7 @@ function convertCopilotTranscriptEvent(event, opts = {}) {
55986
56117
  }
55987
56118
 
55988
56119
  // ../../packages/core/src/agents/native-session-history.ts
55989
- function isRecord3(value) {
56120
+ function isRecord4(value) {
55990
56121
  return typeof value === "object" && value !== null;
55991
56122
  }
55992
56123
  function readJsonLines(filePath) {
@@ -56000,7 +56131,7 @@ function readJsonLines(filePath) {
56000
56131
  return content.split(/\r?\n/).map((line) => line.trim()).filter(Boolean).flatMap((line) => {
56001
56132
  try {
56002
56133
  const parsed = JSON.parse(line);
56003
- return isRecord3(parsed) ? [parsed] : [];
56134
+ return isRecord4(parsed) ? [parsed] : [];
56004
56135
  } catch {
56005
56136
  return [];
56006
56137
  }
@@ -56073,41 +56204,6 @@ function findFirstMatchingFile(rootDir, predicate) {
56073
56204
  }
56074
56205
  return null;
56075
56206
  }
56076
- function buildAssistantTextEvent(text, timestamp) {
56077
- return {
56078
- type: "assistant",
56079
- message: {
56080
- role: "assistant",
56081
- content: [{ type: "text", text }]
56082
- },
56083
- ...timestamp ? { timestamp } : {}
56084
- };
56085
- }
56086
- function buildAssistantThinkingEvent(thinking, timestamp) {
56087
- return {
56088
- type: "assistant",
56089
- message: {
56090
- role: "assistant",
56091
- content: [{ type: "thinking", thinking }]
56092
- },
56093
- ...timestamp ? { timestamp } : {}
56094
- };
56095
- }
56096
- function extractCodexReasoningText(item) {
56097
- if (typeof item.text === "string") {
56098
- return item.text.trim();
56099
- }
56100
- if (Array.isArray(item.summary)) {
56101
- return item.summary.map((entry) => {
56102
- if (typeof entry === "string") return entry.trim();
56103
- if (isRecord3(entry) && typeof entry.text === "string") {
56104
- return entry.text.trim();
56105
- }
56106
- return "";
56107
- }).filter(Boolean).join("\n\n");
56108
- }
56109
- return "";
56110
- }
56111
56207
  function truncateSummary(text, maxLength = 96) {
56112
56208
  const normalized = text.replace(/\s+/g, " ").trim();
56113
56209
  if (!normalized) {
@@ -56126,7 +56222,7 @@ function extractTextFromClaudeMessageContent(content) {
56126
56222
  return "";
56127
56223
  }
56128
56224
  for (const part of content) {
56129
- if (!isRecord3(part)) continue;
56225
+ if (!isRecord4(part)) continue;
56130
56226
  if (typeof part.text === "string" && part.text.trim()) {
56131
56227
  return truncateSummary(part.text);
56132
56228
  }
@@ -56168,7 +56264,7 @@ function findClaudeSessionSummary(entries, sessionId) {
56168
56264
  if (!cwd && typeof entry.cwd === "string" && entry.cwd.trim()) {
56169
56265
  cwd = entry.cwd.trim();
56170
56266
  }
56171
- if (summary || entry.type !== "user" || !isRecord3(entry.message)) {
56267
+ if (summary || entry.type !== "user" || !isRecord4(entry.message)) {
56172
56268
  continue;
56173
56269
  }
56174
56270
  const candidate = extractTextFromClaudeMessageContent(entry.message.content);
@@ -56187,6 +56283,63 @@ function findClaudeSessionSummary(entries, sessionId) {
56187
56283
  updatedAt
56188
56284
  };
56189
56285
  }
56286
+ function getClaudeMessageContent(entry) {
56287
+ const message = entry.message;
56288
+ if (!isRecord4(message) || !Array.isArray(message.content)) {
56289
+ return [];
56290
+ }
56291
+ return message.content.filter(isRecord4);
56292
+ }
56293
+ function isClaudeToolResultEvent(entry) {
56294
+ if (!entry || entry.type !== "user") {
56295
+ return false;
56296
+ }
56297
+ const content = getClaudeMessageContent(entry);
56298
+ return content.length > 0 && content.every((block) => block.type === "tool_result");
56299
+ }
56300
+ function isClaudeTextOnlyUserEvent(entry) {
56301
+ if (entry.type !== "user") {
56302
+ return false;
56303
+ }
56304
+ const content = getClaudeMessageContent(entry);
56305
+ return content.length > 0 && content.every((block) => block.type === "text" && typeof block.text === "string");
56306
+ }
56307
+ function convertClaudeGeneratedPrompt(entry) {
56308
+ const content = getClaudeMessageContent(entry);
56309
+ const prompt = content.map((block) => typeof block.text === "string" ? block.text : "").filter(Boolean).join("\n\n").trim();
56310
+ if (!prompt) {
56311
+ return null;
56312
+ }
56313
+ const id = typeof entry.uuid === "string" && entry.uuid.trim() ? entry.uuid.trim() : typeof entry.parentUuid === "string" && entry.parentUuid.trim() ? `${entry.parentUuid.trim()}-generated-prompt` : `generated-prompt-${prompt.slice(0, 24)}`;
56314
+ return {
56315
+ ...entry,
56316
+ type: "assistant",
56317
+ message: {
56318
+ role: "assistant",
56319
+ content: [{
56320
+ type: "tool_use",
56321
+ id,
56322
+ name: "AgentPrompt",
56323
+ input: { prompt }
56324
+ }]
56325
+ }
56326
+ };
56327
+ }
56328
+ function normalizeClaudeSessionLogs(entries) {
56329
+ const byUuid = /* @__PURE__ */ new Map();
56330
+ for (const entry of entries) {
56331
+ if (typeof entry.uuid === "string" && entry.uuid.trim()) {
56332
+ byUuid.set(entry.uuid.trim(), entry);
56333
+ }
56334
+ }
56335
+ return entries.map((entry) => {
56336
+ const parent = typeof entry.parentUuid === "string" ? byUuid.get(entry.parentUuid) : void 0;
56337
+ if (isClaudeTextOnlyUserEvent(entry) && isClaudeToolResultEvent(parent)) {
56338
+ return convertClaudeGeneratedPrompt(entry) ?? entry;
56339
+ }
56340
+ return entry;
56341
+ });
56342
+ }
56190
56343
  function loadCodexSessionIndex() {
56191
56344
  const indexPath = path7.join(getNativeHomeDir(), ".codex", "session_index.jsonl");
56192
56345
  const index = /* @__PURE__ */ new Map();
@@ -56210,7 +56363,7 @@ function findCodexSessionSummary(entries, filePath, sessionIndex) {
56210
56363
  if (typeof entry.timestamp === "string") {
56211
56364
  updatedAt = entry.timestamp;
56212
56365
  }
56213
- if (entry.type === "session_meta" && isRecord3(entry.payload)) {
56366
+ if (entry.type === "session_meta" && isRecord4(entry.payload)) {
56214
56367
  if (typeof entry.payload.id === "string" && entry.payload.id.trim()) {
56215
56368
  sessionId = entry.payload.id.trim();
56216
56369
  }
@@ -56219,7 +56372,7 @@ function findCodexSessionSummary(entries, filePath, sessionIndex) {
56219
56372
  }
56220
56373
  continue;
56221
56374
  }
56222
- if (!summary && entry.type === "event_msg" && isRecord3(entry.payload) && entry.payload.type === "user_message") {
56375
+ if (!summary && entry.type === "event_msg" && isRecord4(entry.payload) && entry.payload.type === "user_message") {
56223
56376
  if (typeof entry.payload.message === "string" && entry.payload.message.trim()) {
56224
56377
  summary = truncateSummary(entry.payload.message);
56225
56378
  }
@@ -56252,9 +56405,9 @@ function loadClaudeSessionHistory(sessionId) {
56252
56405
  if (entry.type !== "user" && entry.type !== "assistant" || entry.isMeta === true || entry.isSidechain === true) {
56253
56406
  return false;
56254
56407
  }
56255
- return isRecord3(entry.message);
56408
+ return isRecord4(entry.message);
56256
56409
  });
56257
- return { logs, sourcePath: sessionFile };
56410
+ return { logs: normalizeClaudeSessionLogs(logs), sourcePath: sessionFile };
56258
56411
  }
56259
56412
  function loadCodexSessionHistory(sessionId) {
56260
56413
  const sessionsDir = path7.join(getNativeHomeDir(), ".codex", "sessions");
@@ -56262,26 +56415,7 @@ function loadCodexSessionHistory(sessionId) {
56262
56415
  if (!sessionFile) {
56263
56416
  return { logs: [], sourcePath: null };
56264
56417
  }
56265
- const logs = readJsonLines(sessionFile).flatMap((entry) => {
56266
- if (entry.type !== "event_msg" || !isRecord3(entry.payload)) {
56267
- return [];
56268
- }
56269
- const timestamp = typeof entry.timestamp === "string" ? entry.timestamp : void 0;
56270
- const payload = entry.payload;
56271
- if (payload.type === "user_message" && typeof payload.message === "string" && payload.message.trim()) {
56272
- return [buildTaskUserLogEvent([{ type: "text", text: payload.message.trim() }], timestamp)];
56273
- }
56274
- if (payload.type === "agent_message" && typeof payload.message === "string" && payload.message.trim()) {
56275
- return [buildAssistantTextEvent(payload.message.trim(), timestamp)];
56276
- }
56277
- if (payload.type === "agent_reasoning") {
56278
- const reasoning = extractCodexReasoningText(payload);
56279
- if (reasoning) {
56280
- return [buildAssistantThinkingEvent(reasoning, timestamp)];
56281
- }
56282
- }
56283
- return [];
56284
- });
56418
+ const logs = readJsonLines(sessionFile).flatMap(convertCodexTranscriptEvent);
56285
56419
  return { logs, sourcePath: sessionFile };
56286
56420
  }
56287
56421
  function findCopilotSessionDir(sessionId) {
@@ -57026,6 +57160,9 @@ function getClaudeStreamError(event) {
57026
57160
  }
57027
57161
  return null;
57028
57162
  }
57163
+ function shouldSkipClaudeTranscriptEvent(event) {
57164
+ return event.isMeta === true || event.isSidechain === true || event.type === "attachment" || event.type === "last-prompt";
57165
+ }
57029
57166
  var ClaudeCodeEngine = class extends ExecutionEngine {
57030
57167
  sessions = /* @__PURE__ */ new Map();
57031
57168
  /** Rebuild in-memory sessions map from persisted task payloads. */
@@ -57082,6 +57219,9 @@ var ClaudeCodeEngine = class extends ExecutionEngine {
57082
57219
  try {
57083
57220
  const event = JSON.parse(line);
57084
57221
  streamError = getClaudeStreamError(event) ?? streamError;
57222
+ if (shouldSkipClaudeTranscriptEvent(event)) {
57223
+ return;
57224
+ }
57085
57225
  if (event.type === "system" && event.subtype === "init" && typeof event.session_id === "string") {
57086
57226
  this.sessions.set(task.id, {
57087
57227
  sessionId: event.session_id,
@@ -57208,6 +57348,9 @@ var ClaudeCodeEngine = class extends ExecutionEngine {
57208
57348
  try {
57209
57349
  const event = JSON.parse(line);
57210
57350
  streamError = getClaudeStreamError(event) ?? streamError;
57351
+ if (shouldSkipClaudeTranscriptEvent(event)) {
57352
+ return;
57353
+ }
57211
57354
  if (event.type === "system" && event.subtype === "init" && typeof event.session_id === "string") {
57212
57355
  this.sessions.set(taskId, {
57213
57356
  sessionId: event.session_id,
@@ -57347,40 +57490,25 @@ var ClaudeCodeEngine = class extends ExecutionEngine {
57347
57490
  var fs11 = __toESM(require("fs"), 1);
57348
57491
  var path10 = __toESM(require("path"), 1);
57349
57492
  var import_node_child_process5 = require("child_process");
57350
- function buildAssistantEvent(text, timestamp = (/* @__PURE__ */ new Date()).toISOString()) {
57351
- return {
57352
- type: "assistant",
57353
- message: {
57354
- role: "assistant",
57355
- content: [{ type: "text", text }]
57356
- },
57357
- timestamp
57358
- };
57359
- }
57360
- function buildAssistantThinkingEvent2(thinking, timestamp = (/* @__PURE__ */ new Date()).toISOString()) {
57361
- return {
57362
- type: "assistant",
57363
- message: {
57364
- role: "assistant",
57365
- content: [{ type: "thinking", thinking }]
57366
- },
57367
- timestamp
57368
- };
57493
+ var CODEX_SESSION_MIRROR_INTERVAL_MS = 500;
57494
+ function isRecord5(value) {
57495
+ return typeof value === "object" && value !== null;
57369
57496
  }
57370
- function extractCodexReasoningText2(item) {
57371
- if (typeof item.text === "string") {
57372
- return item.text.trim();
57497
+ function stableStringify(value) {
57498
+ if (Array.isArray(value)) {
57499
+ return `[${value.map((entry) => stableStringify(entry)).join(",")}]`;
57373
57500
  }
57374
- if (Array.isArray(item.summary)) {
57375
- return item.summary.map((entry) => {
57376
- if (typeof entry === "string") return entry.trim();
57377
- if (typeof entry === "object" && entry !== null && typeof entry.text === "string") {
57378
- return String(entry.text).trim();
57379
- }
57380
- return "";
57381
- }).filter(Boolean).join("\n\n");
57501
+ if (!isRecord5(value)) {
57502
+ return JSON.stringify(value);
57382
57503
  }
57383
- return "";
57504
+ return `{${Object.entries(value).filter(([, entryValue]) => entryValue !== void 0).sort(([leftKey], [rightKey]) => leftKey.localeCompare(rightKey)).map(([key, entryValue]) => `${JSON.stringify(key)}:${stableStringify(entryValue)}`).join(",")}}`;
57505
+ }
57506
+ function transcriptEventSignature(event) {
57507
+ const message = event.message;
57508
+ if ((event.type === "assistant" || event.type === "user") && isRecord5(message) && Array.isArray(message.content)) {
57509
+ return `${event.type}:${stableStringify(message.content)}`;
57510
+ }
57511
+ return stableStringify(event);
57384
57512
  }
57385
57513
  function sanitizeFilename(filename) {
57386
57514
  return filename.replace(/[^a-zA-Z0-9._-]/g, "-");
@@ -57418,6 +57546,8 @@ function buildCodexModeArgs(mode) {
57418
57546
  }
57419
57547
  var CodexEngine = class extends ExecutionEngine {
57420
57548
  sessions = /* @__PURE__ */ new Map();
57549
+ nativeSessionMirrors = /* @__PURE__ */ new Map();
57550
+ emittedTranscriptSignatures = /* @__PURE__ */ new Map();
57421
57551
  /** Rebuild in-memory sessions map from persisted task payloads. */
57422
57552
  init() {
57423
57553
  const { tasks } = this.taskEngine.listTasks();
@@ -57474,6 +57604,7 @@ var CodexEngine = class extends ExecutionEngine {
57474
57604
  const model = typeof current?.payload.model === "string" ? current.payload.model : void 0;
57475
57605
  const mode = current?.payload.mode;
57476
57606
  const userEvent = buildTaskUserLogEvent(content);
57607
+ this.markTranscriptEventEmitted(taskId, userEvent);
57477
57608
  this.appendLog(taskId, userEvent);
57478
57609
  this.emitOutput(taskId, userEvent);
57479
57610
  const { prompt, imagePaths } = this.prepareAssets(taskId, content);
@@ -57518,11 +57649,7 @@ var CodexEngine = class extends ExecutionEngine {
57518
57649
  if (!line.trim()) return;
57519
57650
  try {
57520
57651
  const event = JSON.parse(line);
57521
- const converted = this.handleEvent(taskId, title, cwd, event);
57522
- if (converted) {
57523
- this.emitOutput(taskId, converted);
57524
- this.appendLog(taskId, converted);
57525
- }
57652
+ this.emitConvertedEvents(taskId, this.handleEvent(taskId, title, cwd, event));
57526
57653
  } catch {
57527
57654
  }
57528
57655
  };
@@ -57542,10 +57669,12 @@ var CodexEngine = class extends ExecutionEngine {
57542
57669
  processLine(buffer);
57543
57670
  }
57544
57671
  if (this.shouldSkipProcessOutcome(activeProcess)) {
57672
+ this.stopNativeSessionMirror(taskId);
57545
57673
  this.releaseProcess(activeProcess);
57546
57674
  return;
57547
57675
  }
57548
57676
  try {
57677
+ this.flushNativeSessionMirror(taskId);
57549
57678
  if (code === 0) {
57550
57679
  this.logger.info(isFollowUp ? "Codex follow-up completed" : "Codex task completed successfully", {
57551
57680
  taskId,
@@ -57568,11 +57697,13 @@ var CodexEngine = class extends ExecutionEngine {
57568
57697
  reason: err instanceof Error ? err.message : String(err)
57569
57698
  });
57570
57699
  } finally {
57700
+ this.stopNativeSessionMirror(taskId);
57571
57701
  this.releaseProcess(activeProcess);
57572
57702
  }
57573
57703
  });
57574
57704
  proc.on("error", (err) => {
57575
57705
  if (this.shouldSkipProcessOutcome(activeProcess)) {
57706
+ this.stopNativeSessionMirror(taskId);
57576
57707
  this.releaseProcess(activeProcess);
57577
57708
  return;
57578
57709
  }
@@ -57588,10 +57719,69 @@ var CodexEngine = class extends ExecutionEngine {
57588
57719
  reason: reportErr instanceof Error ? reportErr.message : String(reportErr)
57589
57720
  });
57590
57721
  } finally {
57722
+ this.stopNativeSessionMirror(taskId);
57591
57723
  this.releaseProcess(activeProcess);
57592
57724
  }
57593
57725
  });
57594
57726
  }
57727
+ emitConvertedEvents(taskId, events) {
57728
+ if (events.length === 0) return;
57729
+ const emitted = this.getEmittedTranscriptSignatures(taskId);
57730
+ for (const event of events) {
57731
+ const signature = transcriptEventSignature(event);
57732
+ if (emitted.has(signature)) {
57733
+ continue;
57734
+ }
57735
+ emitted.add(signature);
57736
+ this.emitOutput(taskId, event);
57737
+ this.appendLog(taskId, event);
57738
+ }
57739
+ }
57740
+ getEmittedTranscriptSignatures(taskId) {
57741
+ let emitted = this.emittedTranscriptSignatures.get(taskId);
57742
+ if (emitted) return emitted;
57743
+ emitted = /* @__PURE__ */ new Set();
57744
+ const logPath = this.getLogPath(taskId);
57745
+ if (fs11.existsSync(logPath)) {
57746
+ for (const line of fs11.readFileSync(logPath, "utf-8").split(/\r?\n/)) {
57747
+ if (!line.trim()) continue;
57748
+ try {
57749
+ emitted.add(transcriptEventSignature(JSON.parse(line)));
57750
+ } catch {
57751
+ }
57752
+ }
57753
+ }
57754
+ this.emittedTranscriptSignatures.set(taskId, emitted);
57755
+ return emitted;
57756
+ }
57757
+ markTranscriptEventEmitted(taskId, event) {
57758
+ this.getEmittedTranscriptSignatures(taskId).add(transcriptEventSignature(event));
57759
+ }
57760
+ startNativeSessionMirror(taskId, sessionId) {
57761
+ this.stopNativeSessionMirror(taskId);
57762
+ const mirror = {
57763
+ sessionId,
57764
+ timer: setInterval(() => this.flushNativeSessionMirror(taskId), CODEX_SESSION_MIRROR_INTERVAL_MS)
57765
+ };
57766
+ mirror.timer.unref?.();
57767
+ this.nativeSessionMirrors.set(taskId, mirror);
57768
+ this.flushNativeSessionMirror(taskId);
57769
+ }
57770
+ stopNativeSessionMirror(taskId) {
57771
+ const mirror = this.nativeSessionMirrors.get(taskId);
57772
+ if (!mirror) return;
57773
+ clearInterval(mirror.timer);
57774
+ this.nativeSessionMirrors.delete(taskId);
57775
+ }
57776
+ flushNativeSessionMirror(taskId) {
57777
+ const mirror = this.nativeSessionMirrors.get(taskId);
57778
+ if (!mirror) return;
57779
+ try {
57780
+ const { logs } = loadNativeSessionHistory({ agent: "codex", sessionId: mirror.sessionId });
57781
+ this.emitConvertedEvents(taskId, logs);
57782
+ } catch {
57783
+ }
57784
+ }
57595
57785
  /** Translate a Codex JSON event into a Meshy transcript event. */
57596
57786
  handleEvent(taskId, title, cwd, event) {
57597
57787
  if (event.type === "thread.started" && typeof event.thread_id === "string") {
@@ -57603,22 +57793,11 @@ var CodexEngine = class extends ExecutionEngine {
57603
57793
  this.persistSession(taskId, event.thread_id, cwd);
57604
57794
  this.appendLog(taskId, event);
57605
57795
  this.emitOutput(taskId, event);
57796
+ this.startNativeSessionMirror(taskId, event.thread_id);
57606
57797
  this.logger.info("Codex session established", { taskId, sessionId: event.thread_id });
57607
- return null;
57608
- }
57609
- if (event.type === "item.completed") {
57610
- const item = event.item;
57611
- if (item?.type === "agent_message" && typeof item.text === "string" && item.text.trim()) {
57612
- return buildAssistantEvent(item.text);
57613
- }
57614
- if (item?.type === "reasoning" || item?.type === "agent_reasoning") {
57615
- const reasoning = extractCodexReasoningText2(item);
57616
- if (reasoning) {
57617
- return buildAssistantThinkingEvent2(reasoning);
57618
- }
57619
- }
57798
+ return [];
57620
57799
  }
57621
- return null;
57800
+ return convertCodexTranscriptEvent(event);
57622
57801
  }
57623
57802
  /** Write image attachments to disk and return the text prompt + file paths. */
57624
57803
  prepareAssets(taskId, content) {
@@ -57694,7 +57873,7 @@ var CodexEngine = class extends ExecutionEngine {
57694
57873
  var fs12 = __toESM(require("fs"), 1);
57695
57874
  var path11 = __toESM(require("path"), 1);
57696
57875
  var import_node_child_process6 = require("child_process");
57697
- function isRecord4(value) {
57876
+ function isRecord6(value) {
57698
57877
  return typeof value === "object" && value !== null;
57699
57878
  }
57700
57879
  function contentToPrompt(content) {
@@ -57732,7 +57911,7 @@ function inferExtension2(mediaType) {
57732
57911
  return normalized.replace(/[^a-z0-9]/g, "") || "bin";
57733
57912
  }
57734
57913
  function extractSessionId(event) {
57735
- const data = isRecord4(event.data) ? event.data : void 0;
57914
+ const data = isRecord6(event.data) ? event.data : void 0;
57736
57915
  const direct = event.session_id ?? event.sessionId ?? event.conversation_id ?? event.conversationId ?? data?.sessionId ?? data?.session_id ?? data?.conversationId ?? data?.conversation_id;
57737
57916
  if (typeof direct === "string" && direct.trim()) return direct.trim();
57738
57917
  const type = typeof event.type === "string" ? event.type.toLowerCase() : "";
@@ -59765,13 +59944,13 @@ function cleanDevBoxInfo(devbox) {
59765
59944
  }
59766
59945
  function normalizeMcpDevBoxList(value) {
59767
59946
  const normalized = normalizeMcpValue(value);
59768
- const record2 = isRecord5(normalized) ? normalized : {};
59947
+ const record2 = isRecord7(normalized) ? normalized : {};
59769
59948
  const list = Array.isArray(normalized) ? normalized : Array.isArray(record2.devboxes) ? record2.devboxes : Array.isArray(record2.value) ? record2.value : [];
59770
59949
  return list.map((item) => normalizeDevBoxResource(item, void 0)).filter((item) => Boolean(item.name));
59771
59950
  }
59772
59951
  function normalizeDevBoxResource(value, fallback) {
59773
59952
  const record2 = normalizeRecord(value);
59774
- const additional = isRecord5(record2.additionalProperties) ? record2.additionalProperties : {};
59953
+ const additional = isRecord7(record2.additionalProperties) ? record2.additionalProperties : {};
59775
59954
  const fromUri = parseDevBoxUri(readString(record2, "uri"));
59776
59955
  const status = readString(record2, "status") ?? readString(record2, "powerState") ?? readString(record2, "lastStatus") ?? fallback?.lastStatus;
59777
59956
  const name2 = readString(record2, "name") ?? fromUri?.name ?? fallback?.name ?? "";
@@ -59825,7 +60004,7 @@ function parseDevCenterEndpoint(hostname4) {
59825
60004
  }
59826
60005
  function normalizeRecord(value) {
59827
60006
  const normalized = normalizeMcpValue(value);
59828
- return isRecord5(normalized) ? normalized : {};
60007
+ return isRecord7(normalized) ? normalized : {};
59829
60008
  }
59830
60009
  function normalizeMcpValue(value) {
59831
60010
  if (Array.isArray(value)) return value;
@@ -59860,7 +60039,7 @@ function tryParseJson(text) {
59860
60039
  return null;
59861
60040
  }
59862
60041
  }
59863
- function isRecord5(value) {
60042
+ function isRecord7(value) {
59864
60043
  return Boolean(value && typeof value === "object" && !Array.isArray(value));
59865
60044
  }
59866
60045
  function readString(record2, key) {
@@ -61089,7 +61268,7 @@ function upgradeRuntimeAgentForDeps(deps, agent) {
61089
61268
 
61090
61269
  // ../../packages/api/src/node/runtime-restart-request.ts
61091
61270
  function parseRuntimeRestartRequest(value) {
61092
- const body = isRecord6(value) ? value : {};
61271
+ const body = isRecord8(value) ? value : {};
61093
61272
  const startArgs = parseRuntimeRestartStartArgs(body.startArgs);
61094
61273
  return {
61095
61274
  reason: body.reason === "update" ? "update" : "restart",
@@ -61098,7 +61277,7 @@ function parseRuntimeRestartRequest(value) {
61098
61277
  }
61099
61278
  function parseRuntimeRestartStartArgs(value) {
61100
61279
  if (value === void 0) return void 0;
61101
- if (!isRecord6(value)) {
61280
+ if (!isRecord8(value)) {
61102
61281
  throw new MeshyError("VALIDATION_ERROR", "Runtime restart startArgs must be an object", 400);
61103
61282
  }
61104
61283
  const startArgs = {};
@@ -61135,7 +61314,7 @@ function parseOptionalString(value, key) {
61135
61314
  const trimmed = value.trim();
61136
61315
  return trimmed || void 0;
61137
61316
  }
61138
- function isRecord6(value) {
61317
+ function isRecord8(value) {
61139
61318
  return Boolean(value && typeof value === "object" && !Array.isArray(value));
61140
61319
  }
61141
61320
 
@@ -61618,7 +61797,7 @@ function toLegacyWorkerControl2(message) {
61618
61797
  }
61619
61798
 
61620
61799
  // ../../packages/api/src/tasks/task-route-utils.ts
61621
- function isRecord7(value) {
61800
+ function isRecord9(value) {
61622
61801
  return typeof value === "object" && value !== null;
61623
61802
  }
61624
61803
  function restoreTaskState(taskEngine, task) {
@@ -61685,7 +61864,7 @@ function normalizeStructuredValue(value) {
61685
61864
  if (Array.isArray(value)) {
61686
61865
  return value.map((entry) => normalizeStructuredValue(entry));
61687
61866
  }
61688
- if (!isRecord7(value)) {
61867
+ if (!isRecord9(value)) {
61689
61868
  return value;
61690
61869
  }
61691
61870
  return Object.fromEntries(
@@ -61694,20 +61873,20 @@ function normalizeStructuredValue(value) {
61694
61873
  }
61695
61874
  function getTranscriptEventSignature(event) {
61696
61875
  if (event.type === "user") {
61697
- const signature = getTaskUserMessageSignature(isRecord7(event.message) ? event.message.content : event.message) ?? getTaskUserMessageSignature(event.content);
61876
+ const signature = getTaskUserMessageSignature(isRecord9(event.message) ? event.message.content : event.message) ?? getTaskUserMessageSignature(event.content);
61698
61877
  return signature ? `user:${signature}` : null;
61699
61878
  }
61700
61879
  if (event.type === "assistant") {
61701
61880
  if (typeof event.message === "string") {
61702
61881
  return `assistant:${JSON.stringify(event.message)}`;
61703
61882
  }
61704
- if (isRecord7(event.message) && "content" in event.message) {
61883
+ if (isRecord9(event.message) && "content" in event.message) {
61705
61884
  return `assistant:${JSON.stringify(normalizeStructuredValue(event.message.content))}`;
61706
61885
  }
61707
61886
  if (Array.isArray(event.content)) {
61708
61887
  return `assistant:${JSON.stringify(normalizeStructuredValue(event.content))}`;
61709
61888
  }
61710
- if (isRecord7(event.message)) {
61889
+ if (isRecord9(event.message)) {
61711
61890
  return `assistant:${JSON.stringify(normalizeStructuredValue(event.message))}`;
61712
61891
  }
61713
61892
  }