reifyui 0.3.0 → 0.4.1
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/README.md +59 -10
- package/dist/index.d.ts +93 -22
- package/dist/slides.cjs +737 -0
- package/dist/slides.cjs.map +1 -0
- package/dist/slides.d.ts +128 -0
- package/dist/slides.js +705 -0
- package/dist/slides.js.map +1 -0
- package/package.json +10 -3
- package/src/auth/AuthForm.jsx +187 -0
- package/src/auth/GoogleButton.jsx +80 -0
- package/src/auth/client.js +177 -0
- package/src/components/ChatMessages.jsx +194 -0
- package/src/components/CodeBlock.jsx +120 -0
- package/src/components/Composer.jsx +75 -0
- package/src/components/Dialog.jsx +312 -0
- package/src/components/TaskList.jsx +193 -0
- package/src/components/ToolSteps.jsx +84 -0
- package/src/components/icons.jsx +33 -0
- package/src/components/resizable.jsx +84 -0
- package/src/components/toolMeta.js +91 -0
- package/src/index.d.ts +234 -0
- package/src/index.js +35 -0
- package/src/sheet/SheetGrid.jsx +633 -0
- package/src/slides/Editor.jsx +246 -0
- package/src/slides/Presentation.jsx +79 -0
- package/src/slides/SlideView.jsx +97 -0
- package/src/slides/elements.jsx +178 -0
- package/src/slides/index.d.ts +128 -0
- package/src/slides/index.js +10 -0
- package/src/state/blocks.js +37 -0
- package/src/state/conversationStore.js +55 -0
- package/src/stream/responses.js +122 -0
- package/styles/slides.css +38 -0
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
// Dialog — in-app replacements for window.alert / window.confirm / window.prompt.
|
|
2
|
+
//
|
|
3
|
+
// Agentic surfaces ask the user things constantly: confirm a destructive tool call, name a
|
|
4
|
+
// workspace, acknowledge a failure. Native browser popups block the event loop, cannot be
|
|
5
|
+
// styled, and look like a security warning rather than part of your product. This gives the
|
|
6
|
+
// same call-site ergonomics — an awaited call that returns a value — without any of that.
|
|
7
|
+
//
|
|
8
|
+
// Usage:
|
|
9
|
+
// 1. Mount <DialogHost> once, wrapping your app.
|
|
10
|
+
// 2. Anywhere underneath:
|
|
11
|
+
//
|
|
12
|
+
// const { confirm, prompt, alert } = useDialog();
|
|
13
|
+
//
|
|
14
|
+
// if (await confirm({ title: 'Delete task', message: 'This cannot be undone.',
|
|
15
|
+
// destructive: true, confirmLabel: 'Delete' })) { … }
|
|
16
|
+
//
|
|
17
|
+
// const name = await prompt({ title: 'New workspace', label: 'Name',
|
|
18
|
+
// validate: (v) => v.length < 40 ? null : 'Too long' });
|
|
19
|
+
// // string, or null when cancelled
|
|
20
|
+
//
|
|
21
|
+
// await alert({ title: 'Run failed', message: err, variant: 'error' });
|
|
22
|
+
//
|
|
23
|
+
// Dialogs stack rather than replace: a second caller layers on top instead of trampling the
|
|
24
|
+
// first, because two independent code paths asking at once is normal in a streaming UI.
|
|
25
|
+
//
|
|
26
|
+
// Styling is one stylesheet away — import 'reifyui/styles/dialog.css' — and every colour is a
|
|
27
|
+
// themeable variable, so it inherits the host app's palette.
|
|
28
|
+
import {
|
|
29
|
+
createContext, useCallback, useContext, useEffect,
|
|
30
|
+
useId, useMemo, useRef, useState,
|
|
31
|
+
} from 'react';
|
|
32
|
+
import { createPortal } from 'react-dom';
|
|
33
|
+
|
|
34
|
+
const DialogCtx = createContext(null);
|
|
35
|
+
|
|
36
|
+
const LABELS = {
|
|
37
|
+
en: { confirm: 'Confirm', cancel: 'Cancel', ok: 'OK', create: 'Create', required: 'Please enter a value' },
|
|
38
|
+
zh: { confirm: '确认', cancel: '取消', ok: '好的', create: '创建', required: '请输入内容' },
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
let _idSeq = 0;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Mount once near the root. `locale` picks a built-in label set ('en' | 'zh'); `labels`
|
|
45
|
+
* overrides individual strings for any other language.
|
|
46
|
+
*/
|
|
47
|
+
export function DialogHost({ children, locale = 'en', labels }) {
|
|
48
|
+
const [stack, setStack] = useState([]);
|
|
49
|
+
const t = useMemo(
|
|
50
|
+
() => ({ ...(LABELS[locale] || LABELS.en), ...(labels || {}) }),
|
|
51
|
+
[locale, labels],
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
const open = useCallback((spec) => new Promise((resolve) => {
|
|
55
|
+
setStack((s) => [...s, { id: `dlg_${++_idSeq}`, spec, resolve }]);
|
|
56
|
+
}), []);
|
|
57
|
+
|
|
58
|
+
const close = useCallback((id, value) => {
|
|
59
|
+
setStack((s) => {
|
|
60
|
+
const target = s.find((d) => d.id === id);
|
|
61
|
+
if (target) target.resolve(value);
|
|
62
|
+
return s.filter((d) => d.id !== id);
|
|
63
|
+
});
|
|
64
|
+
}, []);
|
|
65
|
+
|
|
66
|
+
const ctx = useMemo(() => ({
|
|
67
|
+
confirm: (opts) => open({ kind: 'confirm', ...opts }),
|
|
68
|
+
prompt: (opts) => open({ kind: 'prompt', ...opts }),
|
|
69
|
+
alert: (opts) => open({ kind: 'alert', ...opts }),
|
|
70
|
+
create: (opts) => open({ kind: 'create', ...opts }),
|
|
71
|
+
labels: t,
|
|
72
|
+
}), [open, t]);
|
|
73
|
+
|
|
74
|
+
return (
|
|
75
|
+
<DialogCtx.Provider value={ctx}>
|
|
76
|
+
{children}
|
|
77
|
+
{stack.length > 0 && typeof document !== 'undefined' && createPortal(
|
|
78
|
+
<div className="rui-dlg-root" role="presentation">
|
|
79
|
+
{stack.map((d, i) => (
|
|
80
|
+
<DialogShell key={d.id} dialog={d} isTop={i === stack.length - 1} onClose={close} t={t} />
|
|
81
|
+
))}
|
|
82
|
+
</div>,
|
|
83
|
+
document.body,
|
|
84
|
+
)}
|
|
85
|
+
</DialogCtx.Provider>
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function useDialog() {
|
|
90
|
+
const ctx = useContext(DialogCtx);
|
|
91
|
+
// Fail loudly rather than silently no-op: a confirm() that always resolves false would skip
|
|
92
|
+
// the user's decision entirely, which is worse than a crash in development.
|
|
93
|
+
if (!ctx) throw new Error('useDialog() called outside <DialogHost>');
|
|
94
|
+
return ctx;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// A cancelled prompt/create yields null (no value); a cancelled confirm/alert yields false.
|
|
98
|
+
const cancelValue = (kind) => ((kind === 'prompt' || kind === 'create') ? null : false);
|
|
99
|
+
|
|
100
|
+
function DialogShell({ dialog, isTop, onClose, t }) {
|
|
101
|
+
const { id, spec } = dialog;
|
|
102
|
+
const ref = useRef(null);
|
|
103
|
+
const titleId = useId();
|
|
104
|
+
|
|
105
|
+
useEffect(() => {
|
|
106
|
+
if (!isTop) return undefined;
|
|
107
|
+
const onKey = (e) => {
|
|
108
|
+
if (e.key !== 'Escape') return;
|
|
109
|
+
e.preventDefault();
|
|
110
|
+
onClose(id, cancelValue(spec.kind));
|
|
111
|
+
};
|
|
112
|
+
document.addEventListener('keydown', onKey);
|
|
113
|
+
return () => document.removeEventListener('keydown', onKey);
|
|
114
|
+
}, [id, isTop, onClose, spec.kind]);
|
|
115
|
+
|
|
116
|
+
// Focus the field if there is one, else the primary action — so Enter does the obvious thing.
|
|
117
|
+
useEffect(() => {
|
|
118
|
+
if (!isTop || !ref.current) return;
|
|
119
|
+
const el = ref.current.querySelector('input, textarea')
|
|
120
|
+
|| ref.current.querySelector('.rui-dlg-primary')
|
|
121
|
+
|| ref.current.querySelector('button');
|
|
122
|
+
el?.focus();
|
|
123
|
+
}, [isTop]);
|
|
124
|
+
|
|
125
|
+
const onBackdrop = (e) => {
|
|
126
|
+
if (e.target === e.currentTarget && isTop) onClose(id, cancelValue(spec.kind));
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
const done = (v) => onClose(id, v);
|
|
130
|
+
|
|
131
|
+
return (
|
|
132
|
+
<div className="rui-dlg-backdrop" onClick={onBackdrop}>
|
|
133
|
+
<div
|
|
134
|
+
ref={ref}
|
|
135
|
+
role="dialog"
|
|
136
|
+
aria-modal="true"
|
|
137
|
+
aria-labelledby={spec.title ? titleId : undefined}
|
|
138
|
+
className={`rui-dlg-card${spec.kind === 'create' ? ' is-wide' : ''}`}
|
|
139
|
+
>
|
|
140
|
+
{spec.kind === 'alert' && <AlertBody spec={spec} onClose={done} t={t} titleId={titleId} />}
|
|
141
|
+
{spec.kind === 'confirm' && <ConfirmBody spec={spec} onClose={done} t={t} titleId={titleId} />}
|
|
142
|
+
{spec.kind === 'prompt' && <PromptBody spec={spec} onClose={done} t={t} titleId={titleId} />}
|
|
143
|
+
{spec.kind === 'create' && <CreateBody spec={spec} onClose={done} t={t} titleId={titleId} />}
|
|
144
|
+
</div>
|
|
145
|
+
</div>
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function Header({ title, variant, titleId }) {
|
|
150
|
+
if (!title) return null;
|
|
151
|
+
return (
|
|
152
|
+
<div className={`rui-dlg-h${variant ? ` is-${variant}` : ''}`}>
|
|
153
|
+
<div className="rui-dlg-title" id={titleId}>{title}</div>
|
|
154
|
+
</div>
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const Footer = ({ children }) => <div className="rui-dlg-f">{children}</div>;
|
|
159
|
+
|
|
160
|
+
function AlertBody({ spec, onClose, t, titleId }) {
|
|
161
|
+
return (
|
|
162
|
+
<>
|
|
163
|
+
<Header title={spec.title} variant={spec.variant} titleId={titleId} />
|
|
164
|
+
<div className="rui-dlg-b">
|
|
165
|
+
{spec.message ? <div className="rui-dlg-msg">{spec.message}</div> : null}
|
|
166
|
+
</div>
|
|
167
|
+
<Footer>
|
|
168
|
+
<button type="button" className="rui-dlg-btn rui-dlg-primary" onClick={() => onClose(true)}>
|
|
169
|
+
{spec.confirmLabel || t.ok}
|
|
170
|
+
</button>
|
|
171
|
+
</Footer>
|
|
172
|
+
</>
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function ConfirmBody({ spec, onClose, t, titleId }) {
|
|
177
|
+
const destructive = !!spec.destructive;
|
|
178
|
+
return (
|
|
179
|
+
<>
|
|
180
|
+
<Header title={spec.title} variant={destructive ? 'destructive' : spec.variant} titleId={titleId} />
|
|
181
|
+
<div className="rui-dlg-b">
|
|
182
|
+
{spec.message ? <div className="rui-dlg-msg">{spec.message}</div> : null}
|
|
183
|
+
</div>
|
|
184
|
+
<Footer>
|
|
185
|
+
<button type="button" className="rui-dlg-btn rui-dlg-secondary" onClick={() => onClose(false)}>
|
|
186
|
+
{spec.cancelLabel || t.cancel}
|
|
187
|
+
</button>
|
|
188
|
+
<button
|
|
189
|
+
type="button"
|
|
190
|
+
className={`rui-dlg-btn rui-dlg-primary${destructive ? ' is-destructive' : ''}`}
|
|
191
|
+
onClick={() => onClose(true)}
|
|
192
|
+
>
|
|
193
|
+
{spec.confirmLabel || t.confirm}
|
|
194
|
+
</button>
|
|
195
|
+
</Footer>
|
|
196
|
+
</>
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function PromptBody({ spec, onClose, t, titleId }) {
|
|
201
|
+
const [value, setValue] = useState(spec.defaultValue ?? '');
|
|
202
|
+
const [err, setErr] = useState(null);
|
|
203
|
+
const inputId = useId();
|
|
204
|
+
const Field = spec.multiline ? 'textarea' : 'input';
|
|
205
|
+
|
|
206
|
+
const submit = () => {
|
|
207
|
+
const invalid = spec.validate?.(value);
|
|
208
|
+
if (invalid) { setErr(String(invalid)); return; }
|
|
209
|
+
if (spec.required !== false && !String(value).trim()) { setErr(t.required); return; }
|
|
210
|
+
onClose(String(value));
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
return (
|
|
214
|
+
<>
|
|
215
|
+
<Header title={spec.title} variant={spec.variant} titleId={titleId} />
|
|
216
|
+
<div className="rui-dlg-b">
|
|
217
|
+
{spec.message ? <div className="rui-dlg-msg">{spec.message}</div> : null}
|
|
218
|
+
{spec.label ? <label className="rui-dlg-label" htmlFor={inputId}>{spec.label}</label> : null}
|
|
219
|
+
<Field
|
|
220
|
+
id={inputId}
|
|
221
|
+
className={`rui-dlg-input${err ? ' is-err' : ''}`}
|
|
222
|
+
type={spec.multiline ? undefined : (spec.inputType || 'text')}
|
|
223
|
+
rows={spec.multiline ? (spec.rows || 4) : undefined}
|
|
224
|
+
value={value}
|
|
225
|
+
placeholder={spec.placeholder || ''}
|
|
226
|
+
onChange={(e) => { setValue(e.target.value); if (err) setErr(null); }}
|
|
227
|
+
onKeyDown={(e) => {
|
|
228
|
+
if (e.key === 'Enter' && !e.shiftKey && !spec.multiline) { e.preventDefault(); submit(); }
|
|
229
|
+
}}
|
|
230
|
+
autoComplete="off"
|
|
231
|
+
spellCheck="false"
|
|
232
|
+
/>
|
|
233
|
+
{err ? <div className="rui-dlg-err">{err}</div> : null}
|
|
234
|
+
{!err && spec.help ? <div className="rui-dlg-help">{spec.help}</div> : null}
|
|
235
|
+
</div>
|
|
236
|
+
<Footer>
|
|
237
|
+
<button type="button" className="rui-dlg-btn rui-dlg-secondary" onClick={() => onClose(null)}>
|
|
238
|
+
{spec.cancelLabel || t.cancel}
|
|
239
|
+
</button>
|
|
240
|
+
<button type="button" className="rui-dlg-btn rui-dlg-primary" onClick={submit}>
|
|
241
|
+
{spec.confirmLabel || t.confirm}
|
|
242
|
+
</button>
|
|
243
|
+
</Footer>
|
|
244
|
+
</>
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// Pick-a-type-then-name, for "New …" flows where the thing being created has variants. The
|
|
249
|
+
// caller supplies `types: [{ kind, label, color, icon }]`, so this stays icon-library agnostic.
|
|
250
|
+
// Resolves to { kind, name } or null.
|
|
251
|
+
function CreateBody({ spec, onClose, t, titleId }) {
|
|
252
|
+
const types = spec.types || [];
|
|
253
|
+
const [kind, setKind] = useState(spec.defaultKind || types[0]?.kind || '');
|
|
254
|
+
const [value, setValue] = useState(spec.defaultValue ?? '');
|
|
255
|
+
const [err, setErr] = useState(null);
|
|
256
|
+
const inputId = useId();
|
|
257
|
+
const sel = types.find((x) => x.kind === kind) || types[0] || {};
|
|
258
|
+
|
|
259
|
+
const submit = () => {
|
|
260
|
+
if (spec.required !== false && !String(value).trim()) { setErr(t.required); return; }
|
|
261
|
+
onClose({ kind, name: String(value).trim() });
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
return (
|
|
265
|
+
<>
|
|
266
|
+
<Header title={spec.title} titleId={titleId} />
|
|
267
|
+
<div className="rui-dlg-b">
|
|
268
|
+
{types.length > 0 ? (
|
|
269
|
+
<div className="rui-dlg-typegrid">
|
|
270
|
+
{types.map((ty) => (
|
|
271
|
+
<button
|
|
272
|
+
key={ty.kind}
|
|
273
|
+
type="button"
|
|
274
|
+
className={`rui-dlg-type${ty.kind === kind ? ' is-on' : ''}`}
|
|
275
|
+
onClick={() => setKind(ty.kind)}
|
|
276
|
+
>
|
|
277
|
+
{ty.icon ? (
|
|
278
|
+
<span className="rui-dlg-type-ic" style={ty.color ? { color: ty.color, background: `${ty.color}1f` } : undefined}>
|
|
279
|
+
{ty.icon}
|
|
280
|
+
</span>
|
|
281
|
+
) : null}
|
|
282
|
+
<span className="rui-dlg-type-lbl">{ty.label}</span>
|
|
283
|
+
</button>
|
|
284
|
+
))}
|
|
285
|
+
</div>
|
|
286
|
+
) : null}
|
|
287
|
+
<label className="rui-dlg-label" htmlFor={inputId}>
|
|
288
|
+
{spec.label || `${sel.label || 'Item'} name`}
|
|
289
|
+
</label>
|
|
290
|
+
<input
|
|
291
|
+
id={inputId}
|
|
292
|
+
className={`rui-dlg-input${err ? ' is-err' : ''}`}
|
|
293
|
+
value={value}
|
|
294
|
+
placeholder={spec.placeholder || 'Untitled'}
|
|
295
|
+
onChange={(e) => { setValue(e.target.value); if (err) setErr(null); }}
|
|
296
|
+
onKeyDown={(e) => { if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); submit(); } }}
|
|
297
|
+
autoComplete="off"
|
|
298
|
+
spellCheck="false"
|
|
299
|
+
/>
|
|
300
|
+
{err ? <div className="rui-dlg-err">{err}</div> : null}
|
|
301
|
+
</div>
|
|
302
|
+
<Footer>
|
|
303
|
+
<button type="button" className="rui-dlg-btn rui-dlg-secondary" onClick={() => onClose(null)}>
|
|
304
|
+
{spec.cancelLabel || t.cancel}
|
|
305
|
+
</button>
|
|
306
|
+
<button type="button" className="rui-dlg-btn rui-dlg-primary" onClick={submit}>
|
|
307
|
+
{spec.confirmLabel || t.create}
|
|
308
|
+
</button>
|
|
309
|
+
</Footer>
|
|
310
|
+
</>
|
|
311
|
+
);
|
|
312
|
+
}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
// TaskList — the master list beside an agent conversation: one row per run/session, with
|
|
2
|
+
// live status, text filter, status filter, cursor pagination on scroll, and optional delete.
|
|
3
|
+
//
|
|
4
|
+
// Transport-agnostic, like everything else here. The consumer supplies `fetchPage`, which
|
|
5
|
+
// returns `{ items, cursor }` for a given cursor ('' = first page). ReifyUI never decides how
|
|
6
|
+
// you authenticate or where your API lives; it only decides how the result looks and behaves.
|
|
7
|
+
//
|
|
8
|
+
// Pagination model: the FIRST page is refetched on `refreshNonce` so live runs stay current,
|
|
9
|
+
// while older pages accumulate in a tail. Merging de-duplicates by id, so a run that moves
|
|
10
|
+
// between pages while you scroll cannot appear twice.
|
|
11
|
+
//
|
|
12
|
+
// Slots:
|
|
13
|
+
// header node rendered above the filter row (e.g. a harness selector)
|
|
14
|
+
// onNew when provided, renders the "New task" action
|
|
15
|
+
// onDelete when provided, each row gets a delete affordance (confirm is the consumer's job
|
|
16
|
+
// if it wants one — this only calls back)
|
|
17
|
+
// renderMeta (item) => node, replaces the default right-hand status/time cell
|
|
18
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
19
|
+
|
|
20
|
+
const STATUS_GROUPS = {
|
|
21
|
+
all: () => true,
|
|
22
|
+
working: (s) => ['running', 'starting', 'queued', 'in_progress'].includes(s),
|
|
23
|
+
done: (s) => ['done', 'completed'].includes(s),
|
|
24
|
+
failed: (s) => ['failed', 'cancelled', 'incomplete', 'error'].includes(s),
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/** Coarse bucket for the status dot — keeps colour logic in one place. */
|
|
28
|
+
export function taskStatusGroup(status) {
|
|
29
|
+
const s = String(status || '').toLowerCase();
|
|
30
|
+
for (const k of ['working', 'done', 'failed']) if (STATUS_GROUPS[k](s)) return k;
|
|
31
|
+
return 'idle';
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function relTime(ts) {
|
|
35
|
+
const n = Number(ts) || 0;
|
|
36
|
+
if (!n) return '';
|
|
37
|
+
// Accept seconds or milliseconds — callers differ and a 1000x error is a silent wrong label.
|
|
38
|
+
const ms = n > 1e12 ? n : n * 1000;
|
|
39
|
+
const d = Math.max(0, Date.now() - ms) / 1000;
|
|
40
|
+
if (d < 60) return 'just now';
|
|
41
|
+
if (d < 3600) return `${Math.floor(d / 60)}m ago`;
|
|
42
|
+
if (d < 86400) return `${Math.floor(d / 3600)}h ago`;
|
|
43
|
+
return `${Math.floor(d / 86400)}d ago`;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function TaskList({
|
|
47
|
+
fetchPage,
|
|
48
|
+
selected,
|
|
49
|
+
onSelect,
|
|
50
|
+
onNew,
|
|
51
|
+
onDelete,
|
|
52
|
+
header,
|
|
53
|
+
renderMeta,
|
|
54
|
+
refreshNonce = 0,
|
|
55
|
+
emptyLabel = 'No tasks yet',
|
|
56
|
+
newLabel = 'New task',
|
|
57
|
+
idKey = 'id',
|
|
58
|
+
titleKey = 'title',
|
|
59
|
+
statusKey = 'status',
|
|
60
|
+
timeKey = 'updated_at',
|
|
61
|
+
}) {
|
|
62
|
+
const [head, setHead] = useState(null); // null = loading, [] = loaded-empty
|
|
63
|
+
const [tail, setTail] = useState([]);
|
|
64
|
+
const [cursor, setCursor] = useState('');
|
|
65
|
+
const [loadingMore, setLoadingMore] = useState(false);
|
|
66
|
+
const [q, setQ] = useState('');
|
|
67
|
+
const [statusFilter, setStatusFilter] = useState('all');
|
|
68
|
+
const alive = useRef(true);
|
|
69
|
+
|
|
70
|
+
useEffect(() => () => { alive.current = false; }, []);
|
|
71
|
+
|
|
72
|
+
// First page — refetched whenever the consumer bumps refreshNonce (poll, SSE, post-send).
|
|
73
|
+
useEffect(() => {
|
|
74
|
+
let ok = true;
|
|
75
|
+
Promise.resolve(fetchPage(''))
|
|
76
|
+
.then((r) => {
|
|
77
|
+
if (!ok) return;
|
|
78
|
+
setHead(Array.isArray(r?.items) ? r.items : []);
|
|
79
|
+
setCursor(r?.cursor || '');
|
|
80
|
+
})
|
|
81
|
+
.catch(() => { if (ok) setHead((p) => p ?? []); }); // keep what we had; don't blank the list
|
|
82
|
+
return () => { ok = false; };
|
|
83
|
+
}, [fetchPage, refreshNonce]);
|
|
84
|
+
|
|
85
|
+
const loadMore = useCallback(() => {
|
|
86
|
+
if (!cursor || loadingMore) return;
|
|
87
|
+
setLoadingMore(true);
|
|
88
|
+
Promise.resolve(fetchPage(cursor))
|
|
89
|
+
.then((r) => {
|
|
90
|
+
if (!alive.current) return;
|
|
91
|
+
if (Array.isArray(r?.items)) setTail((t) => [...t, ...r.items]);
|
|
92
|
+
setCursor(r?.cursor || '');
|
|
93
|
+
})
|
|
94
|
+
.catch(() => { /* keep the cursor so the next scroll retries */ })
|
|
95
|
+
.finally(() => { if (alive.current) setLoadingMore(false); });
|
|
96
|
+
}, [cursor, loadingMore, fetchPage]);
|
|
97
|
+
|
|
98
|
+
const items = useMemo(() => {
|
|
99
|
+
const h = head || [];
|
|
100
|
+
const seen = new Set(h.map((x) => x?.[idKey]));
|
|
101
|
+
return [...h, ...tail.filter((t) => !seen.has(t?.[idKey]))];
|
|
102
|
+
}, [head, tail, idKey]);
|
|
103
|
+
|
|
104
|
+
const shown = useMemo(() => {
|
|
105
|
+
const needle = q.trim().toLowerCase();
|
|
106
|
+
const pass = STATUS_GROUPS[statusFilter] || STATUS_GROUPS.all;
|
|
107
|
+
return items.filter((it) => {
|
|
108
|
+
if (!pass(String(it?.[statusKey] || '').toLowerCase())) return false;
|
|
109
|
+
if (!needle) return true;
|
|
110
|
+
return String(it?.[titleKey] || '').toLowerCase().includes(needle);
|
|
111
|
+
});
|
|
112
|
+
}, [items, q, statusFilter, statusKey, titleKey]);
|
|
113
|
+
|
|
114
|
+
const onScroll = (e) => {
|
|
115
|
+
const el = e.currentTarget;
|
|
116
|
+
if (el.scrollTop + el.clientHeight > el.scrollHeight - 140) loadMore();
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
return (
|
|
120
|
+
<div className="rui-tasks">
|
|
121
|
+
{header ? <div className="rui-tasks-header">{header}</div> : null}
|
|
122
|
+
{onNew ? (
|
|
123
|
+
<button type="button" className="rui-tasks-new" onClick={onNew}>+ {newLabel}</button>
|
|
124
|
+
) : null}
|
|
125
|
+
|
|
126
|
+
<div className="rui-tasks-filters">
|
|
127
|
+
<input
|
|
128
|
+
className="rui-tasks-search"
|
|
129
|
+
value={q}
|
|
130
|
+
placeholder="Filter tasks…"
|
|
131
|
+
onChange={(e) => setQ(e.target.value)}
|
|
132
|
+
aria-label="Filter tasks"
|
|
133
|
+
/>
|
|
134
|
+
<select
|
|
135
|
+
className="rui-tasks-status"
|
|
136
|
+
value={statusFilter}
|
|
137
|
+
onChange={(e) => setStatusFilter(e.target.value)}
|
|
138
|
+
aria-label="Filter by status"
|
|
139
|
+
>
|
|
140
|
+
<option value="all">All</option>
|
|
141
|
+
<option value="working">Working</option>
|
|
142
|
+
<option value="done">Done</option>
|
|
143
|
+
<option value="failed">Failed</option>
|
|
144
|
+
</select>
|
|
145
|
+
</div>
|
|
146
|
+
|
|
147
|
+
<div className="rui-tasks-list" onScroll={onScroll}>
|
|
148
|
+
{head === null ? (
|
|
149
|
+
<div className="rui-tasks-empty">Loading…</div>
|
|
150
|
+
) : shown.length === 0 ? (
|
|
151
|
+
<div className="rui-tasks-empty">{items.length ? 'No matching tasks' : emptyLabel}</div>
|
|
152
|
+
) : (
|
|
153
|
+
shown.map((it) => {
|
|
154
|
+
const id = it?.[idKey];
|
|
155
|
+
const group = taskStatusGroup(it?.[statusKey]);
|
|
156
|
+
return (
|
|
157
|
+
<div
|
|
158
|
+
key={id}
|
|
159
|
+
className={`rui-task${id === selected ? ' is-selected' : ''}`}
|
|
160
|
+
onClick={() => onSelect?.(id)}
|
|
161
|
+
role="button"
|
|
162
|
+
tabIndex={0}
|
|
163
|
+
onKeyDown={(e) => { if (e.key === 'Enter' || e.key === ' ') onSelect?.(id); }}
|
|
164
|
+
>
|
|
165
|
+
<div className="rui-task-main">
|
|
166
|
+
<div className="rui-task-title">{it?.[titleKey] || 'Untitled task'}</div>
|
|
167
|
+
<div className="rui-task-meta">
|
|
168
|
+
{renderMeta ? renderMeta(it) : (
|
|
169
|
+
<>
|
|
170
|
+
<span className={`rui-task-dot is-${group}`} />
|
|
171
|
+
<span className="rui-task-status">{it?.[statusKey] || ''}</span>
|
|
172
|
+
{it?.[timeKey] ? <span className="rui-task-time">{relTime(it[timeKey])}</span> : null}
|
|
173
|
+
</>
|
|
174
|
+
)}
|
|
175
|
+
</div>
|
|
176
|
+
</div>
|
|
177
|
+
{onDelete ? (
|
|
178
|
+
<button
|
|
179
|
+
type="button"
|
|
180
|
+
className="rui-task-del"
|
|
181
|
+
aria-label="Delete task"
|
|
182
|
+
onClick={(e) => { e.stopPropagation(); onDelete(it); }}
|
|
183
|
+
>×</button>
|
|
184
|
+
) : null}
|
|
185
|
+
</div>
|
|
186
|
+
);
|
|
187
|
+
})
|
|
188
|
+
)}
|
|
189
|
+
{loadingMore ? <div className="rui-tasks-empty">Loading more…</div> : null}
|
|
190
|
+
</div>
|
|
191
|
+
</div>
|
|
192
|
+
);
|
|
193
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// Activity timeline — extracted from HarnessRouter's workbench.
|
|
2
|
+
// ToolGroup: a collapsible group whose summary is a natural-language recap ("Ran 5 commands,
|
|
3
|
+
// wrote a file"); open while the turn runs, auto-collapses when it concludes. Each ToolRow
|
|
4
|
+
// carries a typed icon + friendly label (+ filename chip) and expands to its Request / Result.
|
|
5
|
+
//
|
|
6
|
+
// Override slot: renderStep(step, idx) replaces the default ToolRow for a step (return
|
|
7
|
+
// undefined to fall through to the default).
|
|
8
|
+
import React, { useEffect, useState } from 'react';
|
|
9
|
+
import { Chevron, IcThink, IcCheck } from './icons.jsx';
|
|
10
|
+
import { toolMeta, summarizeSteps, prettyJson } from './toolMeta.js';
|
|
11
|
+
|
|
12
|
+
// Takes a single `props` object (destructured inside) so TSX consumers don't infer every slot
|
|
13
|
+
// as required.
|
|
14
|
+
export function ToolGroup(props) {
|
|
15
|
+
const {
|
|
16
|
+
reasoning, steps, running,
|
|
17
|
+
workingLabel = 'Working…', thinkingLabel = 'Thinking', doneLabel = 'Done', thoughtLabel = 'Thought process',
|
|
18
|
+
renderStep,
|
|
19
|
+
} = props;
|
|
20
|
+
// Open while the turn runs; auto-collapse to a one-line recap once it concludes.
|
|
21
|
+
const [open, setOpen] = useState(running);
|
|
22
|
+
useEffect(() => { setOpen(running); }, [running]);
|
|
23
|
+
if (!reasoning && steps.length === 0) return null;
|
|
24
|
+
const summary = running ? workingLabel : (steps.length ? summarizeSteps(steps) : thoughtLabel);
|
|
25
|
+
return (
|
|
26
|
+
<div className={'wbx-acts' + (open ? ' open' : '')}>
|
|
27
|
+
<button className="wbx-acts-sum" onClick={() => setOpen((v) => !v)}>
|
|
28
|
+
<Chevron dir={open ? 'down' : 'right'} size={13} /><span>{summary}</span>
|
|
29
|
+
</button>
|
|
30
|
+
{open && (
|
|
31
|
+
<div className="wbx-acts-body">
|
|
32
|
+
{reasoning && (
|
|
33
|
+
<div className="wbx-act"><span className="wbx-act-ic-t thinking"><IcThink /></span>
|
|
34
|
+
<div className="wbx-act-main"><div className="wbx-act-k">{thinkingLabel}</div>
|
|
35
|
+
<div className="wbx-act-v">{reasoning}</div></div></div>
|
|
36
|
+
)}
|
|
37
|
+
{steps.map((s, j) => {
|
|
38
|
+
if (renderStep) {
|
|
39
|
+
const el = renderStep(s, j);
|
|
40
|
+
if (el !== undefined) return <React.Fragment key={j}>{el}</React.Fragment>;
|
|
41
|
+
}
|
|
42
|
+
return <ToolRow key={j} step={s} />;
|
|
43
|
+
})}
|
|
44
|
+
{!running && (
|
|
45
|
+
<div className="wbx-act"><span className="wbx-act-ic-t done"><IcCheck /></span>
|
|
46
|
+
<div className="wbx-act-main"><div className="wbx-act-k">{doneLabel}</div></div></div>
|
|
47
|
+
)}
|
|
48
|
+
</div>
|
|
49
|
+
)}
|
|
50
|
+
</div>
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function ToolRow(props) {
|
|
55
|
+
const { step, requestLabel = 'Request', resultLabel = 'Result' } = props;
|
|
56
|
+
const [open, setOpen] = useState(false);
|
|
57
|
+
const meta = toolMeta(step.name, step.args);
|
|
58
|
+
const Icon = meta.Icon;
|
|
59
|
+
const hasDetail = !!(step.args && step.args !== '{}') || step.result !== undefined;
|
|
60
|
+
return (
|
|
61
|
+
<div className="wbx-act">
|
|
62
|
+
<span className="wbx-act-ic-t"><Icon /></span>
|
|
63
|
+
<div className="wbx-act-main">
|
|
64
|
+
<button className={'wbx-act-row' + (open ? ' open' : '')} disabled={!hasDetail} onClick={() => setOpen((v) => !v)}>
|
|
65
|
+
<span className="wbx-act-k">{meta.label}</span>
|
|
66
|
+
{meta.chip && <span className="wbx-act-chip">{meta.chip}</span>}
|
|
67
|
+
{hasDetail && <span className="wbx-act-exp"><Chevron dir={open ? 'down' : 'right'} size={12} /></span>}
|
|
68
|
+
</button>
|
|
69
|
+
{open && (
|
|
70
|
+
<div className="wbx-act-detail">
|
|
71
|
+
{step.args && step.args !== '{}' && (
|
|
72
|
+
<div className="wbx-act-block"><div className="wbx-act-block-h">{requestLabel}</div>
|
|
73
|
+
<pre className="wbx-act-pre">{prettyJson(step.args)}</pre></div>
|
|
74
|
+
)}
|
|
75
|
+
{step.result !== undefined && (
|
|
76
|
+
<div className="wbx-act-block"><div className="wbx-act-block-h">{resultLabel}</div>
|
|
77
|
+
<pre className="wbx-act-pre">{String(step.result).slice(0, 4000)}</pre></div>
|
|
78
|
+
)}
|
|
79
|
+
</div>
|
|
80
|
+
)}
|
|
81
|
+
</div>
|
|
82
|
+
</div>
|
|
83
|
+
);
|
|
84
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Line-glyph icon set for the conversational surface (16-17px, currentColor stroke) —
|
|
2
|
+
// extracted verbatim from HarnessRouter's workbench. Dependency-free (inline SVG only).
|
|
3
|
+
import React from 'react';
|
|
4
|
+
|
|
5
|
+
export function Svg({ children, s = 16 }) {
|
|
6
|
+
return (
|
|
7
|
+
<svg width={s} height={s} viewBox="0 0 24 24" fill="none" stroke="currentColor"
|
|
8
|
+
strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round">{children}</svg>
|
|
9
|
+
);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function Chevron({ dir, size = 16 }) {
|
|
13
|
+
const d = dir === 'left' ? 'M15 18l-6-6 6-6' : dir === 'right' ? 'M9 18l6-6-6-6' : 'M6 9l6 6 6-6';
|
|
14
|
+
return (
|
|
15
|
+
<svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor"
|
|
16
|
+
strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d={d} /></svg>
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// ── tool-step icons (activity timeline) ──
|
|
21
|
+
export const IcTool = () => <Svg s={17}><path d="M14.7 6.3a4 4 0 0 1-5.4 5.4L4 17v3h3l5.3-5.3a4 4 0 0 1 5.4-5.4l-2.3 2.3-1.7-1.7 2.3-2.3a4 4 0 0 0-1.6 0Z" /></Svg>;
|
|
22
|
+
export const IcPlug = () => <Svg s={17}><path d="M9 2v6M15 2v6M6 8h12v3a6 6 0 0 1-12 0z" /><path d="M12 17v5" /></Svg>;
|
|
23
|
+
export const IcSkill = () => <Svg s={17}><path d="M9 18h6M10 22h4" /><path d="M12 2a7 7 0 0 0-4 12.7c.6.5 1 1.3 1 2.1V18h6v-1.2c0-.8.4-1.6 1-2.1A7 7 0 0 0 12 2z" /></Svg>;
|
|
24
|
+
export const IcTerminal = () => <Svg s={17}><rect x="3" y="4" width="18" height="16" rx="2" /><path d="M7 9l3 3-3 3M13 15h4" /></Svg>;
|
|
25
|
+
export const IcDoc = () => <Svg s={17}><path d="M14 3H6a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V9z" /><path d="M14 3v6h6M8 13h8M8 17h6" /></Svg>;
|
|
26
|
+
export const IcList = () => <Svg s={17}><path d="M8 6h12M8 12h12M8 18h12M3.5 6h.01M3.5 12h.01M3.5 18h.01" /></Svg>;
|
|
27
|
+
export const IcGlobe = () => <Svg s={17}><circle cx="12" cy="12" r="9" /><path d="M3 12h18M12 3a15 15 0 0 1 0 18a15 15 0 0 1 0-18z" /></Svg>;
|
|
28
|
+
export const IcSearch = () => <Svg s={17}><circle cx="11" cy="11" r="7" /><path d="m21 21-4.3-4.3" /></Svg>;
|
|
29
|
+
export const IcScroll = () => <Svg s={17}><path d="M6 3h10a2 2 0 0 1 2 2v12a3 3 0 0 0 3 3H8a2 2 0 0 1-2-2V3z" /><path d="M6 3a2 2 0 0 0-2 2v2h2M10 8h6M10 12h6" /></Svg>;
|
|
30
|
+
export const IcSpawn = () => <Svg s={17}><circle cx="6" cy="6" r="3" /><circle cx="18" cy="18" r="3" /><path d="M6 9v3a3 3 0 0 0 3 3h6" /></Svg>;
|
|
31
|
+
export const IcCheck = () => <Svg s={17}><circle cx="12" cy="12" r="9" /><path d="m9 12 2 2 4-4" /></Svg>;
|
|
32
|
+
export const IcThink = () => <Svg s={16}><path d="M9.5 2a5.5 5.5 0 0 0-3 10.1V15a2 2 0 0 0 2 2h3a2 2 0 0 0 2-2v-2.9A5.5 5.5 0 0 0 9.5 2zM9 20h4M10 22h2" /></Svg>;
|
|
33
|
+
export const IcSend = () => <Svg s={16}><path d="M12 19V5" /><path d="M5 12l7-7 7 7" /></Svg>;
|