graphlit-client 1.0.20260301002 → 1.0.20260301003

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/client.d.ts CHANGED
@@ -2683,6 +2683,15 @@ declare class Graphlit {
2683
2683
  * Build bare continuation messages from turn history (skip formatConversation).
2684
2684
  */
2685
2685
  private buildBareMessages;
2686
+ /**
2687
+ * Reconstruct TurnResult objects from persisted conversation messages.
2688
+ * Used when resuming a conversation so the stuck detector and turn counter
2689
+ * have full context from prior turns.
2690
+ *
2691
+ * Walks the message list identifying user→assistant pairs as logical turns.
2692
+ * Tool calls on assistant messages are extracted for stuck-pattern tracking.
2693
+ */
2694
+ private reconstructTurnResults;
2686
2695
  /**
2687
2696
  * Extract task_complete summary from intermediate messages.
2688
2697
  */
package/dist/client.js CHANGED
@@ -6051,13 +6051,18 @@ class Graphlit {
6051
6051
  }
6052
6052
  }
6053
6053
  else {
6054
- // Resume: load existing turns to initialize stuck detector
6054
+ // Resume: reconstruct TurnResults from conversation history so the
6055
+ // stuck detector has full context from prior turns.
6055
6056
  const convResponse = await this.getConversation(conversationId);
6056
6057
  const existingMessages = convResponse.conversation?.messages;
6057
6058
  if (existingMessages && existingMessages.length > 0) {
6058
- // Reconstruct turn results from conversation history for stuck detector
6059
- // This is a simplified reconstruction — we only need tool names and errors
6060
- stuckDetector.initializeFromHistory(turnResults);
6059
+ const resumedTurns = this.reconstructTurnResults(existingMessages);
6060
+ stuckDetector.initializeFromHistory(resumedTurns);
6061
+ // Carry forward the turn count and tool call total
6062
+ for (const rt of resumedTurns) {
6063
+ turnResults.push(rt);
6064
+ totalToolCalls += rt.toolCallCount;
6065
+ }
6061
6066
  }
6062
6067
  }
6063
6068
  // ── Phase 2: The Loop ──────────────────────────────────────────────
@@ -6461,6 +6466,65 @@ class Graphlit {
6461
6466
  });
6462
6467
  return messages;
6463
6468
  }
6469
+ /**
6470
+ * Reconstruct TurnResult objects from persisted conversation messages.
6471
+ * Used when resuming a conversation so the stuck detector and turn counter
6472
+ * have full context from prior turns.
6473
+ *
6474
+ * Walks the message list identifying user→assistant pairs as logical turns.
6475
+ * Tool calls on assistant messages are extracted for stuck-pattern tracking.
6476
+ */
6477
+ reconstructTurnResults(messages) {
6478
+ const results = [];
6479
+ let turnNumber = 0;
6480
+ for (let i = 0; i < messages.length; i++) {
6481
+ const msg = messages[i];
6482
+ if (msg.role !== Types.ConversationRoleTypes.User)
6483
+ continue;
6484
+ // Find the next assistant message after this user message
6485
+ let assistantMsg;
6486
+ for (let j = i + 1; j < messages.length; j++) {
6487
+ if (messages[j].role === Types.ConversationRoleTypes.Assistant) {
6488
+ assistantMsg = messages[j];
6489
+ break;
6490
+ }
6491
+ }
6492
+ if (!assistantMsg)
6493
+ continue;
6494
+ // Collect tool names from the assistant's tool calls
6495
+ const toolNames = [];
6496
+ if (assistantMsg.toolCalls) {
6497
+ for (const tc of assistantMsg.toolCalls) {
6498
+ if (tc?.name)
6499
+ toolNames.push(tc.name);
6500
+ }
6501
+ }
6502
+ // Check tool response messages for errors
6503
+ const toolErrors = [];
6504
+ for (let j = i + 1; j < messages.length; j++) {
6505
+ const respMsg = messages[j];
6506
+ if (respMsg.role === Types.ConversationRoleTypes.Tool) {
6507
+ if (respMsg.message?.startsWith("Error:")) {
6508
+ toolErrors.push(respMsg.message);
6509
+ }
6510
+ }
6511
+ else if (respMsg.role === Types.ConversationRoleTypes.User) {
6512
+ break; // Next turn
6513
+ }
6514
+ }
6515
+ results.push({
6516
+ turnNumber: turnNumber++,
6517
+ prompt: msg.message || "",
6518
+ responseText: assistantMsg.message || "",
6519
+ toolCalls: [...new Set(toolNames)].sort(),
6520
+ toolCallCount: toolNames.length,
6521
+ durationMs: 0, // Not available from persisted messages
6522
+ taskComplete: toolNames.includes("task_complete"),
6523
+ errors: toolErrors.length > 0 ? toolErrors : undefined,
6524
+ });
6525
+ }
6526
+ return results;
6527
+ }
6464
6528
  /**
6465
6529
  * Extract task_complete summary from intermediate messages.
6466
6530
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "graphlit-client",
3
- "version": "1.0.20260301002",
3
+ "version": "1.0.20260301003",
4
4
  "description": "Graphlit API Client for TypeScript",
5
5
  "type": "module",
6
6
  "main": "./dist/client.js",