@cryptiklemur/lattice 5.13.0 → 5.13.1

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.
@@ -380,6 +380,7 @@ function pushToExistingStream(session, options) {
380
380
  session.clientId = clientId;
381
381
  session.turnStartTime = Date.now();
382
382
  session.turnDoneSent = false;
383
+ session.sawNewTurnContent = false;
383
384
  session.activeToolBlocks = {};
384
385
  const prompt = resolvePromptText(text);
385
386
  const userMsg = buildSDKUserMessage(prompt, attachments, sessionId);
@@ -675,6 +676,7 @@ export function startChatStream(options) {
675
676
  ended: false,
676
677
  accumulatedText: "",
677
678
  specId: options.specId,
679
+ sawNewTurnContent: false,
678
680
  analyzer: new ContextAnalyzer(function (msg) {
679
681
  const ss = sessionStreams.get(sessionId);
680
682
  if (ss)
@@ -693,16 +695,27 @@ export function startChatStream(options) {
693
695
  catch (initErr) {
694
696
  log.chat("Session %s SDK initialization FAILED: %O", sessionId, initErr);
695
697
  }
696
- log.chat("Session %s pushing first message to queue", sessionId);
697
- mq.push(firstMsg);
698
+ if (!shouldResume) {
699
+ log.chat("Session %s pushing first message to queue", sessionId);
700
+ mq.push(firstMsg);
701
+ }
698
702
  try {
699
703
  log.chat("Session %s entering stream loop", sessionId);
700
704
  let msgCount = 0;
705
+ let replayDone = !shouldResume;
701
706
  for await (const msg of stream) {
702
707
  msgCount++;
703
- if (msgCount <= 3 || msg.type === "result") {
708
+ if (msgCount <= 5 || msg.type === "result") {
704
709
  log.chat("Session %s msg #%d type=%s", sessionId, msgCount, msg.type);
705
710
  }
711
+ if (!replayDone && msg.type === "result") {
712
+ replayDone = true;
713
+ log.chat("Session %s replay complete at msg #%d, waiting for connection settle", sessionId, msgCount);
714
+ await new Promise(function (resolve) { setTimeout(resolve, 200); });
715
+ log.chat("Session %s pushing first message after replay", sessionId);
716
+ mq.push(firstMsg);
717
+ continue;
718
+ }
706
719
  processMessage(sessionStream, msg);
707
720
  }
708
721
  log.chat("Session %s stream ended normally after %d messages", sessionId, msgCount);
@@ -715,6 +728,7 @@ export function startChatStream(options) {
715
728
  }
716
729
  else if (errMsg.includes("Sent before connected")) {
717
730
  log.chat("Session %s SDK WebSocket race condition: %s", sessionId, errMsg);
731
+ sendTo(sessionStream.clientId, { type: "chat:error", message: "Connection failed. Please try again." });
718
732
  }
719
733
  else {
720
734
  console.error("[lattice] SDK stream error: " + errMsg);
@@ -822,6 +836,7 @@ function processMessage(ss, msg) {
822
836
  const partial = msg;
823
837
  const evt = partial.event;
824
838
  if (evt.type === "content_block_start") {
839
+ ss.sawNewTurnContent = true;
825
840
  const block = evt.content_block;
826
841
  const idx = evt.index;
827
842
  if (block.type === "tool_use" && block.id && block.name) {
@@ -952,6 +967,10 @@ function processMessage(ss, msg) {
952
967
  return;
953
968
  }
954
969
  if (msg.type === "result") {
970
+ if (!ss.sawNewTurnContent) {
971
+ log.chat("Session %s ignoring replayed result (no new turn content seen)", sessionId);
972
+ return;
973
+ }
955
974
  const resultMsg = msg;
956
975
  const dur = Date.now() - ss.turnStartTime;
957
976
  const cost = resultMsg.total_cost_usd || 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cryptiklemur/lattice",
3
- "version": "5.13.0",
3
+ "version": "5.13.1",
4
4
  "description": "Multi-machine agentic dashboard for Claude Code. Monitor sessions, manage MCP servers and skills, orchestrate across mesh-networked nodes.",
5
5
  "license": "MIT",
6
6
  "author": "Aaron Scherer <me@aaronscherer.me>",