@tinyweb_dev/agent-framework-chat-ui 0.1.1 → 0.3.0
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/components/Composer.d.ts +38 -0
- package/dist/components/Composer.d.ts.map +1 -0
- package/dist/components/Header.d.ts +7 -0
- package/dist/components/Header.d.ts.map +1 -0
- package/dist/components/Hero.d.ts +6 -0
- package/dist/components/Hero.d.ts.map +1 -0
- package/dist/components/RealtimeCallOverlay.d.ts +68 -0
- package/dist/components/RealtimeCallOverlay.d.ts.map +1 -0
- package/dist/components/RealtimeOrb.d.ts +21 -0
- package/dist/components/RealtimeOrb.d.ts.map +1 -0
- package/{src/components/Sidebar.tsx → dist/components/Sidebar.d.ts} +5 -9
- package/dist/components/Sidebar.d.ts.map +1 -0
- package/dist/components/TinywebChat.d.ts +3 -0
- package/dist/components/TinywebChat.d.ts.map +1 -0
- package/dist/components/Transcript.d.ts +20 -0
- package/dist/components/Transcript.d.ts.map +1 -0
- package/dist/components/WireOrbEffect.d.ts +17 -0
- package/dist/components/WireOrbEffect.d.ts.map +1 -0
- package/dist/components/condense/CondensePill.d.ts +11 -0
- package/dist/components/condense/CondensePill.d.ts.map +1 -0
- package/dist/components/messages/AssistantMessage.d.ts +10 -0
- package/dist/components/messages/AssistantMessage.d.ts.map +1 -0
- package/dist/components/messages/ErrorMessage.d.ts +7 -0
- package/dist/components/messages/ErrorMessage.d.ts.map +1 -0
- package/dist/components/messages/ToolMessage.d.ts +17 -0
- package/dist/components/messages/ToolMessage.d.ts.map +1 -0
- package/dist/components/messages/UserMessage.d.ts +7 -0
- package/dist/components/messages/UserMessage.d.ts.map +1 -0
- package/dist/components/tool/ExecRenderer.d.ts +14 -0
- package/dist/components/tool/ExecRenderer.d.ts.map +1 -0
- package/dist/components/tool/ImageRenderer.d.ts +16 -0
- package/dist/components/tool/ImageRenderer.d.ts.map +1 -0
- package/dist/components/tool/JsonRenderer.d.ts +11 -0
- package/dist/components/tool/JsonRenderer.d.ts.map +1 -0
- package/dist/components/tool/ToolCard.d.ts +29 -0
- package/dist/components/tool/ToolCard.d.ts.map +1 -0
- package/dist/components/tool/builtinRenderers.d.ts +9 -0
- package/dist/components/tool/builtinRenderers.d.ts.map +1 -0
- package/dist/hooks/useAgentChat.d.ts +46 -0
- package/dist/hooks/useAgentChat.d.ts.map +1 -0
- package/dist/hooks/useAnchorLatestUser.d.ts +15 -0
- package/dist/hooks/useAnchorLatestUser.d.ts.map +1 -0
- package/dist/hooks/useInitialScrollToEnd.d.ts +15 -0
- package/dist/hooks/useInitialScrollToEnd.d.ts.map +1 -0
- package/dist/hooks/useNdjsonStream.d.ts +11 -0
- package/dist/hooks/useNdjsonStream.d.ts.map +1 -0
- package/dist/hooks/useRealtimeCall.d.ts +112 -0
- package/dist/hooks/useRealtimeCall.d.ts.map +1 -0
- package/dist/index.cjs +3160 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3126 -0
- package/dist/index.js.map +1 -0
- package/dist/markdown/render.d.ts +2 -0
- package/dist/markdown/render.d.ts.map +1 -0
- package/dist/types.d.ts +257 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/util/attachments.d.ts +28 -0
- package/dist/util/attachments.d.ts.map +1 -0
- package/dist/util/escape.d.ts +2 -0
- package/dist/util/escape.d.ts.map +1 -0
- package/dist/util/theme.d.ts +13 -0
- package/dist/util/theme.d.ts.map +1 -0
- package/dist/util/tool-detect.d.ts +26 -0
- package/dist/util/tool-detect.d.ts.map +1 -0
- package/dist/util/tool-labels.d.ts +11 -0
- package/dist/util/tool-labels.d.ts.map +1 -0
- package/package.json +14 -14
- package/src/components/Composer.tsx +0 -267
- package/src/components/Header.tsx +0 -16
- package/src/components/Hero.tsx +0 -16
- package/src/components/RealtimeCallOverlay.tsx +0 -894
- package/src/components/RealtimeOrb.tsx +0 -388
- package/src/components/TinywebChat.tsx +0 -95
- package/src/components/Transcript.tsx +0 -146
- package/src/components/WireOrbEffect.tsx +0 -556
- package/src/components/condense/CondensePill.tsx +0 -77
- package/src/components/messages/AssistantMessage.tsx +0 -15
- package/src/components/messages/ErrorMessage.tsx +0 -12
- package/src/components/messages/ToolMessage.tsx +0 -49
- package/src/components/messages/UserMessage.tsx +0 -37
- package/src/components/tool/ExecRenderer.tsx +0 -71
- package/src/components/tool/ImageRenderer.tsx +0 -47
- package/src/components/tool/JsonRenderer.tsx +0 -24
- package/src/components/tool/ToolCard.tsx +0 -65
- package/src/components/tool/builtinRenderers.tsx +0 -456
- package/src/hooks/useAgentChat.ts +0 -454
- package/src/hooks/useAnchorLatestUser.ts +0 -99
- package/src/hooks/useInitialScrollToEnd.ts +0 -41
- package/src/hooks/useNdjsonStream.ts +0 -71
- package/src/hooks/useRealtimeCall.ts +0 -452
- package/src/index.ts +0 -45
- package/src/markdown/render.ts +0 -121
- package/src/types.ts +0 -241
- package/src/util/attachments.ts +0 -87
- package/src/util/escape.ts +0 -16
- package/src/util/theme.ts +0 -40
- package/src/util/tool-detect.ts +0 -65
- package/src/util/tool-labels.ts +0 -34
- /package/{src → dist}/styles.css +0 -0
|
@@ -1,267 +0,0 @@
|
|
|
1
|
-
import { useEffect, useRef, useState, type ChangeEvent, type ClipboardEvent, type DragEvent, type KeyboardEvent } from "react"
|
|
2
|
-
import type { AttachmentLimits, ImageAttachment } from "../types"
|
|
3
|
-
import { convertFile, revokePreview, DEFAULT_IMAGE_MIMES } from "../util/attachments"
|
|
4
|
-
|
|
5
|
-
export type ComposerProps = {
|
|
6
|
-
onSend: (prompt: string, options?: { images?: ReadonlyArray<ImageAttachment> }) => void
|
|
7
|
-
disabled?: boolean
|
|
8
|
-
placeholder?: string
|
|
9
|
-
attachmentLimits?: AttachmentLimits
|
|
10
|
-
/**
|
|
11
|
-
* When true the send button morphs into a stop button. Used while an
|
|
12
|
-
* agent turn is streaming so the user can force-abort a runaway tool
|
|
13
|
-
* loop. Clicking the stop button invokes [`onStop`](Composer.tsx:1)
|
|
14
|
-
* instead of [`onSend`](Composer.tsx:1).
|
|
15
|
-
*/
|
|
16
|
-
busy?: boolean
|
|
17
|
-
/** Force-stops the in-flight agent turn. Required when `busy === true`. */
|
|
18
|
-
onStop?: () => void
|
|
19
|
-
/**
|
|
20
|
-
* Optional click handler for the realtime Call button. When set the
|
|
21
|
-
* Composer renders a phone icon to the left of the textarea so the
|
|
22
|
-
* user can launch a voice call. When undefined the button is hidden.
|
|
23
|
-
* Wired by `<TinywebChat />` only when its `realtime` prop is set —
|
|
24
|
-
* see plan 0014 §9.
|
|
25
|
-
*/
|
|
26
|
-
onStartCall?: () => void
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Composer textarea + send button + image attachment strip.
|
|
31
|
-
*
|
|
32
|
-
* Image entry points:
|
|
33
|
-
* - paperclip button → hidden `<input type="file" accept="image/*" multiple>`
|
|
34
|
-
* - paste (Ctrl/⌘+V) of image blobs from clipboard
|
|
35
|
-
* - drag-and-drop image files onto the composer
|
|
36
|
-
*
|
|
37
|
-
* Enter sends; Shift+Enter inserts a newline.
|
|
38
|
-
*/
|
|
39
|
-
export const Composer = (props: ComposerProps) => {
|
|
40
|
-
const [value, setValue] = useState("")
|
|
41
|
-
const [images, setImages] = useState<ImageAttachment[]>([])
|
|
42
|
-
const [error, setError] = useState<string | null>(null)
|
|
43
|
-
const [dragOver, setDragOver] = useState(false)
|
|
44
|
-
const fileInputRef = useRef<HTMLInputElement | null>(null)
|
|
45
|
-
const textareaRef = useRef<HTMLTextAreaElement | null>(null)
|
|
46
|
-
|
|
47
|
-
// Revoke object URLs on unmount to avoid memory leaks.
|
|
48
|
-
useEffect(
|
|
49
|
-
() => () => {
|
|
50
|
-
images.forEach(revokePreview)
|
|
51
|
-
},
|
|
52
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
53
|
-
[],
|
|
54
|
-
)
|
|
55
|
-
|
|
56
|
-
const limits = props.attachmentLimits
|
|
57
|
-
|
|
58
|
-
const addFiles = async (files: FileList | File[]) => {
|
|
59
|
-
setError(null)
|
|
60
|
-
let next = images
|
|
61
|
-
for (const file of Array.from(files)) {
|
|
62
|
-
const r = await convertFile(file, next, limits)
|
|
63
|
-
if (!r.ok) {
|
|
64
|
-
setError(r.error.message)
|
|
65
|
-
break
|
|
66
|
-
}
|
|
67
|
-
next = next.concat(r.image)
|
|
68
|
-
}
|
|
69
|
-
setImages(next)
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const removeAt = (idx: number) => {
|
|
73
|
-
const removed = images[idx]
|
|
74
|
-
if (removed) revokePreview(removed)
|
|
75
|
-
setImages(images.filter((_, i) => i !== idx))
|
|
76
|
-
setError(null)
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const submit = () => {
|
|
80
|
-
const text = value.trim()
|
|
81
|
-
if ((!text && images.length === 0) || props.disabled) return
|
|
82
|
-
const out = images
|
|
83
|
-
setValue("")
|
|
84
|
-
setImages([])
|
|
85
|
-
setError(null)
|
|
86
|
-
props.onSend(text, out.length > 0 ? { images: out } : undefined)
|
|
87
|
-
// Keep focus on the textarea so the user can keep typing the next
|
|
88
|
-
// message without re-clicking. Refocus on the next animation frame
|
|
89
|
-
// so React has finished committing the cleared value first.
|
|
90
|
-
const raf = (globalThis as { requestAnimationFrame?: typeof requestAnimationFrame }).requestAnimationFrame
|
|
91
|
-
if (raf) raf(() => textareaRef.current?.focus())
|
|
92
|
-
else textareaRef.current?.focus()
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
const onKeyDown = (e: KeyboardEvent<HTMLTextAreaElement>) => {
|
|
96
|
-
if (e.key !== "Enter" || e.shiftKey) return
|
|
97
|
-
e.preventDefault()
|
|
98
|
-
submit()
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
const onPaste = (e: ClipboardEvent<HTMLTextAreaElement>) => {
|
|
102
|
-
const items = e.clipboardData?.items
|
|
103
|
-
if (!items) return
|
|
104
|
-
const files: File[] = []
|
|
105
|
-
for (let i = 0; i < items.length; i++) {
|
|
106
|
-
const it = items[i]
|
|
107
|
-
if (it && it.kind === "file") {
|
|
108
|
-
const f = it.getAsFile()
|
|
109
|
-
if (f && DEFAULT_IMAGE_MIMES.includes(f.type as (typeof DEFAULT_IMAGE_MIMES)[number])) files.push(f)
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
if (files.length > 0) {
|
|
113
|
-
e.preventDefault()
|
|
114
|
-
void addFiles(files)
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
const onDrop = (e: DragEvent<HTMLDivElement>) => {
|
|
119
|
-
e.preventDefault()
|
|
120
|
-
setDragOver(false)
|
|
121
|
-
const files = e.dataTransfer?.files
|
|
122
|
-
if (files && files.length > 0) void addFiles(files)
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
const onPickFiles = (e: ChangeEvent<HTMLInputElement>) => {
|
|
126
|
-
const files = e.target.files
|
|
127
|
-
if (files && files.length > 0) void addFiles(files)
|
|
128
|
-
e.target.value = ""
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
return (
|
|
132
|
-
<div
|
|
133
|
-
className={`composer${dragOver ? " composer-drop" : ""}`}
|
|
134
|
-
onDragEnter={(e) => {
|
|
135
|
-
e.preventDefault()
|
|
136
|
-
setDragOver(true)
|
|
137
|
-
}}
|
|
138
|
-
onDragOver={(e) => e.preventDefault()}
|
|
139
|
-
onDragLeave={(e) => {
|
|
140
|
-
if (e.currentTarget === e.target) setDragOver(false)
|
|
141
|
-
}}
|
|
142
|
-
onDrop={onDrop}
|
|
143
|
-
>
|
|
144
|
-
{images.length > 0 && (
|
|
145
|
-
<div className="composer-attachments" data-testid="tinyweb-composer-attachments">
|
|
146
|
-
{images.map((img, i) => (
|
|
147
|
-
<div key={i} className="composer-thumb">
|
|
148
|
-
{img.previewUrl ? (
|
|
149
|
-
// eslint-disable-next-line @next/next/no-img-element
|
|
150
|
-
<img src={img.previewUrl} alt={img.filename ?? `image ${i + 1}`} />
|
|
151
|
-
) : (
|
|
152
|
-
<span className="composer-thumb-fallback">{img.filename ?? "image"}</span>
|
|
153
|
-
)}
|
|
154
|
-
<button
|
|
155
|
-
type="button"
|
|
156
|
-
className="composer-thumb-remove"
|
|
157
|
-
aria-label="Remove image"
|
|
158
|
-
onClick={() => removeAt(i)}
|
|
159
|
-
>
|
|
160
|
-
×
|
|
161
|
-
</button>
|
|
162
|
-
</div>
|
|
163
|
-
))}
|
|
164
|
-
</div>
|
|
165
|
-
)}
|
|
166
|
-
{error && (
|
|
167
|
-
<div className="composer-error" role="alert">
|
|
168
|
-
{error}
|
|
169
|
-
</div>
|
|
170
|
-
)}
|
|
171
|
-
<div className="composer-inner">
|
|
172
|
-
<button
|
|
173
|
-
type="button"
|
|
174
|
-
className="attach-btn"
|
|
175
|
-
aria-label="Attach image"
|
|
176
|
-
disabled={props.disabled}
|
|
177
|
-
onClick={() => fileInputRef.current?.click()}
|
|
178
|
-
data-testid="tinyweb-composer-attach"
|
|
179
|
-
>
|
|
180
|
-
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={2} strokeLinecap="round" strokeLinejoin="round">
|
|
181
|
-
<path d="m21.44 11.05-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48" />
|
|
182
|
-
</svg>
|
|
183
|
-
</button>
|
|
184
|
-
{props.onStartCall && (
|
|
185
|
-
<button
|
|
186
|
-
type="button"
|
|
187
|
-
className="call-btn"
|
|
188
|
-
aria-label="Start voice call"
|
|
189
|
-
title="Start voice call"
|
|
190
|
-
disabled={props.disabled || props.busy}
|
|
191
|
-
onClick={props.onStartCall}
|
|
192
|
-
data-testid="tinyweb-composer-call"
|
|
193
|
-
>
|
|
194
|
-
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={2} strokeLinecap="round" strokeLinejoin="round">
|
|
195
|
-
<path d="M22 16.92v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07 19.5 19.5 0 0 1-6-6 19.79 19.79 0 0 1-3.07-8.67A2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72c.13.96.37 1.9.72 2.81a2 2 0 0 1-.45 2.11L8.09 9.91a16 16 0 0 0 6 6l1.27-1.27a2 2 0 0 1 2.11-.45c.91.35 1.85.59 2.81.72A2 2 0 0 1 22 16.92Z" />
|
|
196
|
-
</svg>
|
|
197
|
-
</button>
|
|
198
|
-
)}
|
|
199
|
-
<input
|
|
200
|
-
ref={fileInputRef}
|
|
201
|
-
type="file"
|
|
202
|
-
accept="image/*"
|
|
203
|
-
multiple
|
|
204
|
-
style={{ display: "none" }}
|
|
205
|
-
onChange={onPickFiles}
|
|
206
|
-
data-testid="tinyweb-composer-file"
|
|
207
|
-
/>
|
|
208
|
-
<textarea
|
|
209
|
-
ref={textareaRef}
|
|
210
|
-
rows={1}
|
|
211
|
-
placeholder={props.placeholder ?? "Ask me anything…"}
|
|
212
|
-
value={value}
|
|
213
|
-
// Intentionally NOT disabled when `busy`: disabling a focused
|
|
214
|
-
// element forces the browser to move focus to <body>, which
|
|
215
|
-
// breaks the type → enter → keep typing flow. The parent still
|
|
216
|
-
// queues the next submit (or shows the stop button) instead.
|
|
217
|
-
disabled={props.disabled}
|
|
218
|
-
onChange={(e) => setValue(e.target.value)}
|
|
219
|
-
onKeyDown={onKeyDown}
|
|
220
|
-
onPaste={onPaste}
|
|
221
|
-
data-testid="tinyweb-composer-input"
|
|
222
|
-
/>
|
|
223
|
-
{props.busy && props.onStop ? (
|
|
224
|
-
<button
|
|
225
|
-
type="button"
|
|
226
|
-
className="send-btn stop-btn"
|
|
227
|
-
aria-label="Stop"
|
|
228
|
-
title="Stop generating"
|
|
229
|
-
onClick={props.onStop}
|
|
230
|
-
data-testid="tinyweb-composer-stop"
|
|
231
|
-
>
|
|
232
|
-
<svg
|
|
233
|
-
viewBox="0 0 24 24"
|
|
234
|
-
fill="currentColor"
|
|
235
|
-
stroke="currentColor"
|
|
236
|
-
strokeWidth={1}
|
|
237
|
-
strokeLinejoin="round"
|
|
238
|
-
>
|
|
239
|
-
<rect x="6" y="6" width="12" height="12" rx="2" />
|
|
240
|
-
</svg>
|
|
241
|
-
</button>
|
|
242
|
-
) : (
|
|
243
|
-
<button
|
|
244
|
-
type="button"
|
|
245
|
-
className="send-btn"
|
|
246
|
-
aria-label="Send"
|
|
247
|
-
disabled={props.disabled || (!value.trim() && images.length === 0)}
|
|
248
|
-
onClick={submit}
|
|
249
|
-
data-testid="tinyweb-composer-send"
|
|
250
|
-
>
|
|
251
|
-
<svg
|
|
252
|
-
viewBox="0 0 24 24"
|
|
253
|
-
fill="none"
|
|
254
|
-
stroke="currentColor"
|
|
255
|
-
strokeWidth={2.2}
|
|
256
|
-
strokeLinecap="round"
|
|
257
|
-
strokeLinejoin="round"
|
|
258
|
-
>
|
|
259
|
-
<path d="M22 2 11 13" />
|
|
260
|
-
<path d="M22 2 15 22l-4-9-9-4 20-7Z" />
|
|
261
|
-
</svg>
|
|
262
|
-
</button>
|
|
263
|
-
)}
|
|
264
|
-
</div>
|
|
265
|
-
</div>
|
|
266
|
-
)
|
|
267
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { ReactNode } from "react"
|
|
2
|
-
|
|
3
|
-
export type HeaderProps = {
|
|
4
|
-
title: string
|
|
5
|
-
right?: ReactNode
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export const Header = (props: HeaderProps) => (
|
|
9
|
-
<header className="header">
|
|
10
|
-
<div className="brand">
|
|
11
|
-
<div className="brand-mark" aria-hidden="true" />
|
|
12
|
-
<h1>{props.title}</h1>
|
|
13
|
-
</div>
|
|
14
|
-
{props.right}
|
|
15
|
-
</header>
|
|
16
|
-
)
|
package/src/components/Hero.tsx
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { WireOrbEffect } from "./WireOrbEffect"
|
|
2
|
-
|
|
3
|
-
export type HeroProps = {
|
|
4
|
-
title?: string
|
|
5
|
-
subtitle?: string
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export const Hero = (props: HeroProps) => (
|
|
9
|
-
<div className="hero">
|
|
10
|
-
<div className="hero-orb" aria-hidden="true">
|
|
11
|
-
<WireOrbEffect state="idle" />
|
|
12
|
-
</div>
|
|
13
|
-
<h2 className="hero-title">{props.title ?? "Good to see you."}</h2>
|
|
14
|
-
<p className="hero-sub">{props.subtitle ?? "Ask me anything."}</p>
|
|
15
|
-
</div>
|
|
16
|
-
)
|