@ateam-ai-mobile/core 0.1.40 → 0.1.42

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/index.mjs CHANGED
@@ -1752,6 +1752,32 @@ function plainTextOf(content) {
1752
1752
  }).join("");
1753
1753
  }
1754
1754
 
1755
+ // src/chat/liveGoals.ts
1756
+ var MAX_TOOLS = 4;
1757
+ function foldGoals(prev, wire, liveMessage, liveSeq) {
1758
+ const g = wire && Array.isArray(wire.l) ? wire : null;
1759
+ if (g && g.l.length === 0) return void 0;
1760
+ const goals = g ? { l: g.l, c: g.c ?? null } : prev ? { l: prev.l, c: prev.c } : null;
1761
+ if (!goals) return void 0;
1762
+ const ids = goals.l.map((x) => x[0]).join("|");
1763
+ const tools = ids === prev?.ids ? { ...prev?.tools || {} } : {};
1764
+ const key = liveSeq != null ? `s${liveSeq}` : `m${liveMessage ?? ""}`;
1765
+ const fresh = key !== prev?.lastKey;
1766
+ if (fresh && goals.c && liveMessage && liveMessage.startsWith("\u2192 ")) {
1767
+ const tool = liveMessage.slice(2).trim();
1768
+ const list2 = tools[goals.c] || [];
1769
+ if (tool && list2[list2.length - 1] !== tool) tools[goals.c] = [...list2, tool].slice(-MAX_TOOLS);
1770
+ }
1771
+ return { ...goals, tools, lastKey: key, ids };
1772
+ }
1773
+ function goalRows(goals) {
1774
+ if (!goals?.l?.length) return [];
1775
+ return goals.l.map(([id, title, s]) => {
1776
+ const state = s === "d" ? "done" : id === goals.c ? "current" : "todo";
1777
+ return { id, title, state, tools: state === "current" ? goals.tools?.[id] || [] : [] };
1778
+ });
1779
+ }
1780
+
1755
1781
  // src/chat/store.ts
1756
1782
  function coreHeaders() {
1757
1783
  const token = getToken();
@@ -1787,7 +1813,8 @@ function extractLiveProgress(snap) {
1787
1813
  return {
1788
1814
  message: String(latest.message || ""),
1789
1815
  ...latest.step != null ? { step: latest.step } : {},
1790
- ...latest.total != null ? { total: latest.total } : {}
1816
+ ...latest.total != null ? { total: latest.total } : {},
1817
+ ...latest.seq != null ? { seq: latest.seq } : {}
1791
1818
  };
1792
1819
  }
1793
1820
  function extractCurrentTool(state) {
@@ -1816,6 +1843,7 @@ function snapshotToProgress(snap, rootJobId) {
1816
1843
  if (liveProgress) progress.liveProgress = liveProgress;
1817
1844
  if (typeof snap?.humanStatus === "string" && snap.humanStatus) progress.humanStatus = snap.humanStatus;
1818
1845
  if (snap?.humanLabels && typeof snap.humanLabels === "object") progress.humanLabels = snap.humanLabels;
1846
+ if (snap?.goals && Array.isArray(snap.goals.l)) progress.goalsWire = snap.goals;
1819
1847
  if (pq) {
1820
1848
  progress.pendingQuestion = {
1821
1849
  inputId: pq.correlation_id || pq.correlationId || pq.inputId || "",
@@ -1970,12 +1998,14 @@ var useChatStore = create4((set, get) => ({
1970
1998
  );
1971
1999
  const chainCreatedAt = typeof slim.createdAt === "number" ? slim.createdAt : typeof slim.lastUpdate === "number" ? slim.lastUpdate : Date.now();
1972
2000
  const chainLastUpdate = typeof slim.lastUpdate === "number" ? slim.lastUpdate : chainCreatedAt;
2001
+ const { goalsWire, ...progressRest } = progress;
1973
2002
  const jobProgress = {
1974
2003
  jobId: chainId,
1975
2004
  actorId: extractActorId(slim),
1976
2005
  status: "running",
1977
2006
  chainStartedAt: chainCreatedAt,
1978
- ...progress
2007
+ ...progressRest,
2008
+ goals: foldGoals(void 0, goalsWire, progress.liveProgress?.message, progress.liveProgress?.seq)
1979
2009
  };
1980
2010
  const goal = typeof slim.goal === "string" ? slim.goal : "";
1981
2011
  const userExists = finalMessages.some(
@@ -2175,7 +2205,9 @@ var useChatStore = create4((set, get) => ({
2175
2205
  set((s) => ({
2176
2206
  messages: s.messages.map((m) => {
2177
2207
  if (m.jobProgress?.jobId === jobId) {
2178
- const updated = { ...m.jobProgress, ...progress };
2208
+ const { goalsWire, ...rest } = progress;
2209
+ const updated = { ...m.jobProgress, ...rest };
2210
+ updated.goals = foldGoals(m.jobProgress.goals, goalsWire, progress.liveProgress?.message, progress.liveProgress?.seq);
2179
2211
  if (progress.status && progress.status !== "paused") {
2180
2212
  updated.pendingQuestion = void 0;
2181
2213
  }
@@ -2494,7 +2526,12 @@ function turnToMessages(turn) {
2494
2526
  function createSideChatStore(pageId) {
2495
2527
  return create5((set, get) => {
2496
2528
  const local = (m) => ({ ...m, local: true });
2497
- const patchJob = (jobId, p) => set((s) => ({ messages: s.messages.map((m) => m.jobProgress?.jobId === jobId ? { ...m, jobProgress: { ...m.jobProgress, ...p } } : m) }));
2529
+ const patchJob = (jobId, p) => {
2530
+ const { goalsWire, ...rest } = p;
2531
+ set((s) => ({
2532
+ messages: s.messages.map((m) => m.jobProgress?.jobId === jobId ? { ...m, jobProgress: { ...m.jobProgress, ...rest, goals: foldGoals(m.jobProgress.goals, goalsWire, p.liveProgress?.message, p.liveProgress?.seq) } } : m)
2533
+ }));
2534
+ };
2498
2535
  async function follow(jobId, chainId) {
2499
2536
  let ended = null;
2500
2537
  for (let i = 0; !ended; i++) {
@@ -2832,6 +2869,7 @@ export {
2832
2869
  getToken,
2833
2870
  getUser,
2834
2871
  getVoiceApiUrl,
2872
+ goalRows,
2835
2873
  initAdas,
2836
2874
  isAdasInitialized,
2837
2875
  isDevHost,