reifyui 0.13.3 → 0.13.5

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": "reifyui",
3
- "version": "0.13.3",
3
+ "version": "0.13.5",
4
4
  "description": "The open-source rendering & interaction layer for agentic applications. Stream and render any agent's output as polished, application-native UI — model-agnostic, framework-agnostic, design-system-native. The foundation for building generative-UI and agent products.",
5
5
  "keywords": [
6
6
  "react",
@@ -91,6 +91,9 @@ export function ChatPanel(props) {
91
91
  const [draft, setDraft] = useState('');
92
92
  const [busy, setBusy] = useState(false);
93
93
  const [connecting, setConnecting] = useState(false);
94
+ // A turn this tab started but can no longer hear: its stream broke after the gateway accepted
95
+ // it. Its messages come from history until it settles.
96
+ const [dropped, setDropped] = useState(false);
94
97
  const [histLoading, setHistLoading] = useState(true);
95
98
  const [staged, setStaged] = useState([]); // files picked, not yet sent
96
99
  const [attachErr, setAttachErr] = useState('');
@@ -182,12 +185,25 @@ export function ChatPanel(props) {
182
185
  }
183
186
  pendingRef.current = null;
184
187
  setConnecting(false);
188
+ if (out.dropped) {
189
+ // The turn is running and this tab lost its stream. Never resend: that starts a second
190
+ // turn behind the first (a game played twice at once, a deck written twice). The message
191
+ // stays as sent, the answer stays "running", and history fills it in below.
192
+ setDropped(true);
193
+ return;
194
+ }
185
195
  updateLastAsst((a) => (a.status === 'running' ? { ...a, status: 'done' } : a));
186
196
  api.current.onChanged?.();
187
- } catch {
188
- dropRunningAsst();
189
- pendingRef.current = { text, files };
190
- setConnecting(true);
197
+ } catch (e) {
198
+ // A refused turn is an answer, not a gateway still coming up: a wall, a bad request, a
199
+ // session busy with another turn. Say so on the message and leave it there; resending
200
+ // every twenty seconds is what filled a pane with "connecting" over a game that was
201
+ // playing fine (2026-09-22).
202
+ updateLastAsst((a) => ({
203
+ ...a,
204
+ blocks: a.blocks.length ? a.blocks : withText([], (e && e.message) || 'The turn could not be started.'),
205
+ status: 'failed',
206
+ }));
191
207
  } finally {
192
208
  setBusy(false);
193
209
  }
@@ -272,6 +288,24 @@ export function ChatPanel(props) {
272
288
  return () => window.clearInterval(iv);
273
289
  }, [connecting, busy, deliver]);
274
290
 
291
+ // A turn this tab started and lost the stream of: poll its history until the turn settles,
292
+ // then one last reload for the final answer and whatever it changed.
293
+ useEffect(() => {
294
+ if (!dropped) return undefined;
295
+ let dead = false;
296
+ const tick = () => Promise.resolve(api.current.loadHistory(sessionId)).then((hist) => {
297
+ if (dead || !hist?.length) return;
298
+ const last = hist[hist.length - 1];
299
+ const settled = !(last.role === 'assistant' && last.status === 'running')
300
+ && !externalBusy;
301
+ setMessages(hist);
302
+ if (settled) { setDropped(false); api.current.onChanged?.(); }
303
+ }).catch(() => {});
304
+ const iv = window.setInterval(tick, POLL_MS);
305
+ return () => { dead = true; window.clearInterval(iv); };
306
+ // eslint-disable-next-line react-hooks/exhaustive-deps
307
+ }, [dropped, externalBusy, sessionId]);
308
+
275
309
  // A turn may be running that this tab did not start. While that is true and nothing local is
276
310
  // streaming, poll history so its messages appear; when it ends, reload once so the final answer
277
311
  // and whatever it changed land here without a refresh.
@@ -380,6 +414,7 @@ export function ChatPanel(props) {
380
414
  {title ? <span className="uic-chat-title" title={title}>{title}</span> : null}
381
415
  {headerRight}
382
416
  {connecting ? <span className="uic-chat-conn">{connectingLabel}</span> : null}
417
+ {dropped ? <span className="uic-chat-conn">{workingLabel}</span> : null}
383
418
  </div>
384
419
 
385
420
  <div className="uic-chat-body" ref={bodyRef} onScroll={onBodyScroll} role="log" aria-live="polite">
@@ -49,6 +49,7 @@ function kindOf(name, mime = '') {
49
49
  if (mime.startsWith('audio/') || ['mp3', 'wav', 'ogg', 'm4a', 'flac'].includes(e)) return 'audio';
50
50
  if (e === 'csv' || e === 'tsv') return 'csv';
51
51
  if (e === 'md' || e === 'markdown') return 'markdown';
52
+ if (e === 'html' || e === 'htm') return 'html'; // the page itself, or its source: the header switches
52
53
  if (SHEET.has(e)) return 'sheet';
53
54
  if (OFFICE.has(e)) return 'office';
54
55
  if (mime.startsWith('text/') || LANG[e] || /^(txt|log|env|conf|cfg|gitignore)$/.test(e)) return 'code';
@@ -98,6 +99,9 @@ export function FilePreview({
98
99
  const { url, name } = file || {};
99
100
  const [st, setSt] = useState({ kind: 'loading' });
100
101
  const [tab, setTab] = useState(0);
102
+ // An HTML file opens as the page it is; Source shows what was written. The choice lives in the
103
+ // header, beside the name, so it reads as a property of the file being looked at.
104
+ const [view, setView] = useState('preview');
101
105
 
102
106
  useEffect(() => {
103
107
  if (!url) return undefined;
@@ -105,6 +109,7 @@ export function FilePreview({
105
109
  let obj;
106
110
  setSt({ kind: 'loading' });
107
111
  setTab(0);
112
+ setView('preview');
108
113
  const get = fetchFile || ((u) => fetch(u, { cache: 'no-store' }));
109
114
 
110
115
  (async () => {
@@ -142,7 +147,7 @@ export function FilePreview({
142
147
  }
143
148
  return;
144
149
  }
145
- if (kind === 'csv' || kind === 'markdown' || kind === 'code') {
150
+ if (kind === 'csv' || kind === 'markdown' || kind === 'code' || kind === 'html') {
146
151
  const text = await res.text();
147
152
  if (!alive) return;
148
153
  if (kind === 'csv') setSt({ kind: 'csv', rows: delimitedToRows(text, extOf(name) === 'tsv' ? '\t' : ',') });
@@ -164,6 +169,14 @@ export function FilePreview({
164
169
  <header className="uic-fp-head">
165
170
  <span className="uic-fp-ic"><FileTypeIcon name={name} size={20} /></span>
166
171
  <span className="uic-fp-name" title={name}>{name}</span>
172
+ {st.kind === 'html' && (
173
+ <div className="uic-fp-seg" role="tablist" aria-label="Show the page or its source">
174
+ {[['preview', 'Preview'], ['source', 'Source']].map(([id, label]) => (
175
+ <button key={id} type="button" role="tab" aria-selected={view === id}
176
+ className={'uic-fp-seg-btn' + (view === id ? ' is-on' : '')} onClick={() => setView(id)}>{label}</button>
177
+ ))}
178
+ </div>
179
+ )}
167
180
  <button type="button" className="uic-fp-btn" aria-label={`Download ${name}`} title="Download"
168
181
  onClick={download}><IcDownload /></button>
169
182
  {onClose && (
@@ -184,6 +197,12 @@ export function FilePreview({
184
197
  </div>
185
198
  )}
186
199
  {st.kind === 'code' && <CodeBlock code={st.text || ''} lang={LANG[extOf(name)] || 'plaintext'} />}
200
+ {st.kind === 'html' && view === 'source' && <CodeBlock code={st.text || ''} lang="xml" />}
201
+ {st.kind === 'html' && view === 'preview' && (
202
+ // The page runs in its own origin with scripts only: a mockup's own script and styles
203
+ // work, and nothing in it can read the host page, its cookies or its storage.
204
+ <iframe className="uic-fp-frame" title={name} sandbox="allow-scripts" srcDoc={st.text || ''} />
205
+ )}
187
206
  {st.kind === 'csv' && <Grid rows={st.rows} />}
188
207
  {st.kind === 'sheet' && st.sheets && (
189
208
  <div className="uic-fp-xlsx">
@@ -202,17 +202,22 @@ export async function streamTurn({ sessionId, harnessId, input, instructions, ha
202
202
  hid = h.id;
203
203
  }
204
204
  const existing = sessionId ? String(sessionId) : '';
205
- const res = await fetch(`${CONFIG.base}/responses`, {
206
- method: 'POST',
207
- cache: 'no-store',
208
- headers: { 'content-type': 'application/json', accept: 'text/event-stream' },
209
- body: JSON.stringify({
210
- input,
211
- ...(instructions ? { instructions } : {}),
212
- metadata: { harness_id: hid, ...(existing ? { session_id: existing } : {}) },
213
- stream: true,
214
- }),
215
- });
205
+ let res;
206
+ try {
207
+ res = await fetch(`${CONFIG.base}/responses`, {
208
+ method: 'POST',
209
+ cache: 'no-store',
210
+ headers: { 'content-type': 'application/json', accept: 'text/event-stream' },
211
+ body: JSON.stringify({
212
+ input,
213
+ ...(instructions ? { instructions } : {}),
214
+ metadata: { harness_id: hid, ...(existing ? { session_id: existing } : {}) },
215
+ stream: true,
216
+ }),
217
+ });
218
+ } catch {
219
+ return { connecting: true }; // nothing reached the gateway (down, or restarting): safe to send again
220
+ }
216
221
  if (res.status === 503) return { connecting: true };
217
222
  if (!res.ok || !res.body) {
218
223
  const t = await res.text().catch(() => '');
@@ -225,13 +230,21 @@ export async function streamTurn({ sessionId, harnessId, input, instructions, ha
225
230
  ...handlers,
226
231
  onError: (msg) => { sawError = true; handlers.onError?.(msg); },
227
232
  });
228
- await readSSEStream(res.body, (data) => {
229
- let evt;
230
- try { evt = JSON.parse(data); } catch { return; } // malformed frame
231
- const found = sessionIdOf(evt);
232
- if (found && found !== sid) { sid = found; handlers.onSession?.(found); }
233
- d.dispatch(evt);
234
- });
233
+ try {
234
+ await readSSEStream(res.body, (data) => {
235
+ let evt;
236
+ try { evt = JSON.parse(data); } catch { return; } // malformed frame
237
+ const found = sessionIdOf(evt);
238
+ if (found && found !== sid) { sid = found; handlers.onSession?.(found); }
239
+ d.dispatch(evt);
240
+ });
241
+ } catch {
242
+ // The gateway ACCEPTED the turn (200) and the stream broke afterwards: a console rollout
243
+ // that stopped the old slot, a proxy timeout, a network blink. The turn is running without
244
+ // this stream, so sending the message again would start a second one; the caller attaches
245
+ // to the one that exists instead (its history, polled until it settles).
246
+ return { ok: false, dropped: true, sessionId: sid };
247
+ }
235
248
  return { ok: !sawError, sessionId: sid };
236
249
  }
237
250
 
package/styles/file.css CHANGED
@@ -74,6 +74,10 @@
74
74
  display: inline-flex; align-items: center; justify-content: center;
75
75
  }
76
76
  .uic-fp-btn:hover { background: var(--uic-brand-faint, #EFF3FF); color: var(--uic-ink, #111317); }
77
+ /* the Preview | Source switch of an HTML file, a segmented control in the header */
78
+ .uic-fp-seg { flex: 0 0 auto; display: inline-flex; gap: 2px; padding: 2px; border-radius: 8px; background: var(--uic-surface-2, #F7F8FA); border: 1px solid var(--uic-line, #DDDFE6); }
79
+ .uic-fp-seg-btn { height: 24px; padding: 0 10px; border: 0; border-radius: 6px; background: transparent; color: var(--uic-mute, #5B5D66); font: inherit; font-size: 12px; font-weight: 600; cursor: pointer; }
80
+ .uic-fp-seg-btn.is-on { background: var(--uic-surface, #FFFFFF); color: var(--uic-ink, #111317); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08); }
77
81
 
78
82
  .uic-fp-body { flex: 1; min-height: 0; overflow: auto; }
79
83
  .uic-fp-pad { padding: 18px; }