@mobius-os/mobius 0.2.3 → 0.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mobius-os/mobius",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "type": "module",
5
5
  "description": "Mobius terminal client. Reuses Mobius frontend TypeScript types and jsonl entry shapes.",
6
6
  "bin": {
@@ -35,7 +35,7 @@ interface TerminalSize {
35
35
  isTty: boolean
36
36
  }
37
37
 
38
- const VERSION = '0.2.1'
38
+ const VERSION = '0.2.4'
39
39
  const WELCOME_ROWS = 12
40
40
  const CHROME_ROWS = 11
41
41
 
@@ -118,13 +118,30 @@ export function useChat({ client, ready, resumeSessionId }: ChatApi): ChatContro
118
118
  const appendEntries = useCallback((newOnes: AnyEntry[]) => {
119
119
  if (!newOnes.length) return
120
120
  setEntries(prev => {
121
- const stamped = newOnes.map(e => ({ ...e, __id: e.__id ?? nextId() }))
122
- return [...prev, ...stamped]
121
+ // De-duplicate by uuid so a live jsonl_entry that also appears in a
122
+ // reconnect's history replay is never shown twice.
123
+ const seen = new Set<string>()
124
+ for (const e of prev) { const k = entryKey(e); if (k) seen.add(k) }
125
+ const stamped: AnyEntry[] = []
126
+ for (const e of newOnes) {
127
+ const k = entryKey(e)
128
+ if (k && seen.has(k)) continue
129
+ if (k) seen.add(k)
130
+ stamped.push({ ...e, __id: e.__id ?? nextId() })
131
+ }
132
+ return stamped.length ? [...prev, ...stamped] : prev
123
133
  })
124
134
  }, [])
125
135
 
126
136
  const setHistory = useCallback((list: AnyEntry[]) => {
127
- setEntries(list.map(e => ({ ...e, __id: e.__id ?? nextId() })))
137
+ const seen = new Set<string>()
138
+ const out: AnyEntry[] = []
139
+ for (const e of list) {
140
+ const k = entryKey(e)
141
+ if (k) { if (seen.has(k)) continue; seen.add(k) }
142
+ out.push({ ...e, __id: e.__id ?? nextId() })
143
+ }
144
+ setEntries(out)
128
145
  }, [])
129
146
 
130
147
  // ── SSE connection ────────────────────────────────────────────────────────
@@ -136,6 +153,14 @@ export function useChat({ client, ready, resumeSessionId }: ChatApi): ChatContro
136
153
  const conn = new SseConnection(url, {
137
154
  onHistoryEntries: (es, _done) => {
138
155
  if (es.length) setHistory(es)
156
+ // A reconnect replays the session tail. If our optimistic placeholder is
157
+ // now backed by its real entry, retire it so the user's input isn't shown
158
+ // twice (once as the entry, once as the placeholder). The live jsonl_entry
159
+ // path already clears pendingUser, but a dropped SSE stream (reverse-proxy
160
+ // idle timeout) can deliver the message only via this history replay — and
161
+ // if the whole turn finished while disconnected, no live entry ever comes
162
+ // to clear it, leaving the duplication on screen until the next send.
163
+ setPendingUser(prev => (prev !== null && es.some(e => entryMatchesPendingUser(e, prev)) ? null : prev))
139
164
  },
140
165
  onEntry: (entry) => {
141
166
  if (process.env.MOBIUS_TUI_DEBUG) console.error('[onEntry]', entry?.type, (entry?.message?.content?.[0]?.text ?? '').slice(0, 40))
@@ -317,7 +342,10 @@ export function useChat({ client, ready, resumeSessionId }: ChatApi): ChatContro
317
342
 
318
343
  const send = useCallback(async (text: string) => {
319
344
  const body = text.trim()
320
- if (!body || sending) return
345
+ // Guard on the ref (synchronous truth) as well as the state so a stale
346
+ // closure can't dispatch the same message twice (two distinct reqIds → two
347
+ // user entries on the server).
348
+ if (!body || sending || sendingRef.current) return
321
349
  setError(null)
322
350
  setPendingUser(body)
323
351
  statusEpochRef.current += 1