@vinaverse/client 0.1.0-alpha.2 → 0.1.0-alpha.3

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.
@@ -1550,6 +1550,7 @@ function persistable(item) {
1550
1550
 
1551
1551
  // src/conversation/store.ts
1552
1552
  var MAX_TEXT = 2e3;
1553
+ var TURN_INPUTS = 50;
1553
1554
  var PERSIST_DELAY = 500;
1554
1555
  var PERSIST_VERSION = 1;
1555
1556
  var NO_ITEMS = [];
@@ -1580,6 +1581,8 @@ var ConversationStore = class {
1580
1581
  /** Proposals whose tenant decision threw: shown as recoverable, the person may decide again. */
1581
1582
  decisionErrors = /* @__PURE__ */ new Set();
1582
1583
  system = [];
1584
+ /** The person's text that started each recent turn, by `turn_id` (`turn.started` echoes its `client_event_id`). */
1585
+ turnInputs = /* @__PURE__ */ new Map();
1583
1586
  /** Numbers system rows that carry no id of their own. */
1584
1587
  systemSeq = 0;
1585
1588
  history = NO_ITEMS;
@@ -1809,6 +1812,24 @@ var ConversationStore = class {
1809
1812
  this.sent.delete(key);
1810
1813
  return this.send(sent.text);
1811
1814
  }
1815
+ /**
1816
+ * Send again the person's text whose turn failed before any reply (a `turn_failed` row with `data.retry`), as a new
1817
+ * message (the person's action). Once per row: its `retry` turns false. Returns the new id, or null when the row
1818
+ * allows no retry.
1819
+ */
1820
+ retryTurn(key) {
1821
+ const at = this.system.findIndex(
1822
+ (s) => s.item.key === key && s.item.event === "turn_failed"
1823
+ );
1824
+ const entry = this.system[at];
1825
+ if (entry?.item.data.retry !== true) return null;
1826
+ const text = this.turnText(String(entry.item.data.turn ?? ""));
1827
+ if (text === void 0) return null;
1828
+ this.system = this.system.map(
1829
+ (s, i) => i === at ? { ...s, item: { ...s.item, data: { ...s.item.data, retry: false } } } : s
1830
+ );
1831
+ return this.send(text);
1832
+ }
1812
1833
  /** After the conversation continued on another device: continue it here (the person's choice). */
1813
1834
  continueHere() {
1814
1835
  return this.resumeWith("continue_here");
@@ -1981,6 +2002,17 @@ var ConversationStore = class {
1981
2002
  code: str2(frame.code)
1982
2003
  });
1983
2004
  return;
2005
+ case "turn.started": {
2006
+ const turn = str2(frame.turn_id);
2007
+ const input = str2(frame.client_event_id);
2008
+ if (turn === null || input === null) return;
2009
+ this.turnInputs.set(turn, input);
2010
+ if (this.turnInputs.size > TURN_INPUTS) {
2011
+ const oldest = this.turnInputs.keys().next().value;
2012
+ if (oldest !== void 0) this.turnInputs.delete(oldest);
2013
+ }
2014
+ return;
2015
+ }
1984
2016
  case "turn.failed": {
1985
2017
  const turn = str2(frame.turn_id) ?? "";
1986
2018
  if (this.engine.state().messages.some((m) => m.key === `a:${turn}`))
@@ -1989,7 +2021,9 @@ var ConversationStore = class {
1989
2021
  add(`failed:${turn}`, "turn_failed", {
1990
2022
  code: str2(frame.code),
1991
2023
  message: str2(frame.message),
1992
- retryable: frame.retryable === true
2024
+ retryable: frame.retryable === true,
2025
+ retry: frame.retryable === true && this.turnText(turn) !== void 0,
2026
+ turn
1993
2027
  });
1994
2028
  return;
1995
2029
  }
@@ -1997,6 +2031,13 @@ var ConversationStore = class {
1997
2031
  return;
1998
2032
  }
1999
2033
  }
2034
+ /** The person's text that started a turn, while its message is on screen. */
2035
+ turnText(turn) {
2036
+ const input = this.turnInputs.get(turn);
2037
+ if (input === void 0) return void 0;
2038
+ const message = this.engine.state().messages.find((m) => m.key === input && m.role === "person");
2039
+ return message?.text || void 0;
2040
+ }
2000
2041
  /**
2001
2042
  * A resumed session's transcript replaced the messages, and a chat transcript carries text only: the engine drops
2002
2043
  * the cards it drew, and draws the pending ones again at the end. Each card on screen is anchored just after the
@@ -2098,6 +2139,7 @@ var ConversationStore = class {
2098
2139
  const avatarUrl = this.info?.agent?.avatar_url ?? null;
2099
2140
  const view = {
2100
2141
  status,
2142
+ conversationId: s.conversationId,
2101
2143
  banner: banner(status, next),
2102
2144
  next,
2103
2145
  agent: sameAgent(prev?.agent, name, avatarUrl) ? prev.agent : { name, avatarUrl },