@adea-ai/ui 0.65.1 → 0.66.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 +140 -35
- package/dist/NOTICE +125 -97
- package/dist/components/conversation/chat-composer.d.ts +61 -0
- package/dist/components/conversation/chat-composer.d.ts.map +1 -0
- package/dist/components/conversation/chat-composer.js +411 -0
- package/dist/components/conversation/chat-composer.js.map +1 -0
- package/dist/components/conversation/index.d.ts +1 -0
- package/dist/components/conversation/index.d.ts.map +1 -1
- package/dist/components/conversation/index.js +2 -1
- package/dist/components/layout/split-layout/split-layout.d.ts.map +1 -1
- package/dist/components/layout/split-layout/split-layout.js +2 -0
- package/dist/components/layout/split-layout/split-layout.js.map +1 -1
- package/dist/index.js +2 -1
- package/dist/r/conversation.json +5 -0
- package/dist/r/registry.json +5 -0
- package/dist/r/src/components/conversation/chat-composer.tsx +378 -0
- package/dist/r/src/components/conversation/index.ts +1 -0
- package/dist/r/src/components/layout/split-layout/split-layout.tsx +10 -0
- package/package.json +2 -1
- package/registry.json +5 -0
- package/src/components/conversation/chat-composer.tsx +378 -0
- package/src/components/conversation/index.ts +1 -0
- package/src/components/layout/split-layout/split-layout.tsx +10 -0
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Substantially translated from KiroCrew website/src/components/ChatInput.tsx
|
|
3
|
+
* at 283e136c0f902e965a535a7c9548c57c7504fed0.
|
|
4
|
+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
5
|
+
* Licensed under Apache-2.0; see LICENSE and NOTICE.
|
|
6
|
+
*/
|
|
7
|
+
import { ChevronsDownUp, ChevronsUpDown, MoreHorizontal, ArrowUp } from 'lucide-solid'
|
|
8
|
+
import { Show, createEffect, createSignal, on, onCleanup, onMount, type JSX } from 'solid-js'
|
|
9
|
+
import { Button } from '../ui/button/button'
|
|
10
|
+
import {
|
|
11
|
+
DropdownMenu,
|
|
12
|
+
DropdownMenuContent,
|
|
13
|
+
DropdownMenuItem,
|
|
14
|
+
DropdownMenuTrigger,
|
|
15
|
+
} from '../ui/dropdown-menu/dropdown-menu'
|
|
16
|
+
import { Spinner } from '../ui/spinner/spinner'
|
|
17
|
+
import { BusySendButton, type BusySendButtonProps, type BusySendMode } from './busy-send-button'
|
|
18
|
+
import { createComposerImeGuard } from './ime-guard'
|
|
19
|
+
|
|
20
|
+
export type ChatComposerControl = {
|
|
21
|
+
/** Focus this instance; false when it is unavailable or collapsed. */
|
|
22
|
+
focus: () => boolean
|
|
23
|
+
/** A typing intent, unlike merely navigating to a conversation. */
|
|
24
|
+
expandAndFocus: () => boolean
|
|
25
|
+
}
|
|
26
|
+
export type ChatComposerProps = {
|
|
27
|
+
value: string
|
|
28
|
+
onValueChange: (value: string) => void
|
|
29
|
+
/** The host owns attachments and delivery; text/action are captured at the gesture. */
|
|
30
|
+
onSubmit: (input: { text: string; action: 'send' | BusySendMode }) => void | Promise<void>
|
|
31
|
+
/** Host scope fence; changes discard local feedback, not the host draft. */
|
|
32
|
+
resetKey?: unknown
|
|
33
|
+
disabled?: boolean
|
|
34
|
+
readOnly?: boolean
|
|
35
|
+
/** A visible capability or connectivity reason. */
|
|
36
|
+
blockedReason?: string
|
|
37
|
+
placeholder?: string
|
|
38
|
+
inputLabel?: string
|
|
39
|
+
/** Opt-in and controlled: the library neither persists nor broadcasts it. */
|
|
40
|
+
collapse?: { value: boolean; onChange: (value: boolean) => void }
|
|
41
|
+
controlRef?: (control: ChatComposerControl | undefined) => void
|
|
42
|
+
/** Host payload eligibility by action; explicit false refuses even a nonempty draft. */
|
|
43
|
+
sendableActions?: Partial<Record<'send' | BusySendMode, boolean>>
|
|
44
|
+
busy?: Omit<BusySendButtonProps, 'onFire' | 'disabled' | 'alternateActionHint'>
|
|
45
|
+
knowledge?: JSX.Element
|
|
46
|
+
followUps?: JSX.Element
|
|
47
|
+
band?: JSX.Element
|
|
48
|
+
approval?: JSX.Element
|
|
49
|
+
notices?: JSX.Element
|
|
50
|
+
attachments?: JSX.Element
|
|
51
|
+
leadingActions?: JSX.Element
|
|
52
|
+
trailingActions?: JSX.Element
|
|
53
|
+
/** Host-contributed menu items; no upload, skill or permission services here. */
|
|
54
|
+
menuItems?: JSX.Element
|
|
55
|
+
context?: JSX.Element
|
|
56
|
+
/** Host derives this from the pending approval presentation, not UI policy. */
|
|
57
|
+
approvalFocus?: boolean
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Kiro's composer assembly: context/options, adjacent band, approval/notices,
|
|
62
|
+
* staged content, input/action groups and a context shelf. Reading collapse
|
|
63
|
+
* really unmounts the input and shelf and offers a labeled way back with draft
|
|
64
|
+
* preview. The host retains the only draft, identities, preferences and services.
|
|
65
|
+
*
|
|
66
|
+
* Kobalte owns the options menu. Scoped imperative typing intent replaces the
|
|
67
|
+
* donor global lookup/broadcast so a second composer cannot receive this draft
|
|
68
|
+
* or focus. No animation starts from hidden geometry, no global shortcut, and no
|
|
69
|
+
* runtime/permission/voice/optimizer authority is copied. More specific chips,
|
|
70
|
+
* approval decisions and staged-content semantics are supplied by their owners.
|
|
71
|
+
*/
|
|
72
|
+
export function ChatComposer(props: ChatComposerProps) {
|
|
73
|
+
const ime = createComposerImeGuard()
|
|
74
|
+
const [pending, setPending] = createSignal(false)
|
|
75
|
+
const [error, setError] = createSignal<string | null>(null)
|
|
76
|
+
let field: HTMLTextAreaElement | undefined
|
|
77
|
+
let restoreBar: HTMLButtonElement | undefined
|
|
78
|
+
let focusFrame: number | undefined
|
|
79
|
+
let focusTarget: 'input' | 'bar' | undefined
|
|
80
|
+
let selection:
|
|
81
|
+
| { start: number; end: number; direction: 'forward' | 'backward' | 'none' }
|
|
82
|
+
| undefined
|
|
83
|
+
let generation = 0
|
|
84
|
+
let active = true
|
|
85
|
+
const collapsed = () => props.collapse?.value === true
|
|
86
|
+
const unavailable = () => props.disabled || props.readOnly || !!props.blockedReason
|
|
87
|
+
const cancelFocus = () => {
|
|
88
|
+
if (focusFrame !== undefined) cancelAnimationFrame(focusFrame)
|
|
89
|
+
focusFrame = undefined
|
|
90
|
+
}
|
|
91
|
+
const requestFocus = (target: 'input' | 'bar') => {
|
|
92
|
+
cancelFocus()
|
|
93
|
+
focusTarget = target
|
|
94
|
+
focusFrame = requestAnimationFrame(() => {
|
|
95
|
+
focusFrame = undefined
|
|
96
|
+
if (!active || props.approvalFocus) return
|
|
97
|
+
if (target === 'bar' && collapsed()) restoreBar?.focus()
|
|
98
|
+
if (target === 'input' && !collapsed() && !props.disabled && field) {
|
|
99
|
+
field.focus()
|
|
100
|
+
if (selection)
|
|
101
|
+
field.setSelectionRange(
|
|
102
|
+
Math.min(selection.start, field.value.length),
|
|
103
|
+
Math.min(selection.end, field.value.length),
|
|
104
|
+
selection.direction
|
|
105
|
+
)
|
|
106
|
+
}
|
|
107
|
+
focusTarget = undefined
|
|
108
|
+
})
|
|
109
|
+
}
|
|
110
|
+
const changeCollapsed = (value: boolean) => {
|
|
111
|
+
if (!props.collapse || props.approvalFocus) return
|
|
112
|
+
if (value && field)
|
|
113
|
+
selection = {
|
|
114
|
+
start: field.selectionStart,
|
|
115
|
+
end: field.selectionEnd,
|
|
116
|
+
direction: field.selectionDirection,
|
|
117
|
+
}
|
|
118
|
+
props.collapse.onChange(value)
|
|
119
|
+
requestFocus(value ? 'bar' : 'input')
|
|
120
|
+
}
|
|
121
|
+
const control: ChatComposerControl = {
|
|
122
|
+
focus() {
|
|
123
|
+
if (collapsed() || props.approvalFocus || props.disabled || !field) return false
|
|
124
|
+
field.focus()
|
|
125
|
+
return true
|
|
126
|
+
},
|
|
127
|
+
expandAndFocus() {
|
|
128
|
+
if (props.approvalFocus || props.disabled) return false
|
|
129
|
+
if (collapsed()) changeCollapsed(false)
|
|
130
|
+
else requestFocus('input')
|
|
131
|
+
return true
|
|
132
|
+
},
|
|
133
|
+
}
|
|
134
|
+
onMount(() => props.controlRef?.(control))
|
|
135
|
+
createEffect(
|
|
136
|
+
on(
|
|
137
|
+
() => props.resetKey,
|
|
138
|
+
() => {
|
|
139
|
+
generation += 1
|
|
140
|
+
selection = undefined
|
|
141
|
+
cancelFocus()
|
|
142
|
+
focusTarget = undefined
|
|
143
|
+
setPending(false)
|
|
144
|
+
setError(null)
|
|
145
|
+
ime.onBlur()
|
|
146
|
+
},
|
|
147
|
+
{ defer: true }
|
|
148
|
+
)
|
|
149
|
+
)
|
|
150
|
+
onCleanup(() => {
|
|
151
|
+
active = false
|
|
152
|
+
generation += 1
|
|
153
|
+
cancelFocus()
|
|
154
|
+
props.controlRef?.(undefined)
|
|
155
|
+
})
|
|
156
|
+
const action = (): 'send' | BusySendMode => props.busy?.mode ?? 'send'
|
|
157
|
+
const canSend = (selected: 'send' | BusySendMode = action()) =>
|
|
158
|
+
!unavailable() &&
|
|
159
|
+
!pending() &&
|
|
160
|
+
(props.sendableActions?.[selected] ?? props.value.trim().length > 0) &&
|
|
161
|
+
!(selected !== 'send' && props.busy?.unavailable?.[selected])
|
|
162
|
+
const submit = async (selected: 'send' | BusySendMode = action()) => {
|
|
163
|
+
if (!canSend(selected)) return
|
|
164
|
+
const started = generation
|
|
165
|
+
const input = { text: props.value, action: selected }
|
|
166
|
+
setPending(true)
|
|
167
|
+
setError(null)
|
|
168
|
+
try {
|
|
169
|
+
await props.onSubmit(input)
|
|
170
|
+
} catch {
|
|
171
|
+
if (active && started === generation)
|
|
172
|
+
setError('Message not sent. Check your draft and retry when the connection recovers.')
|
|
173
|
+
} finally {
|
|
174
|
+
if (active && started === generation) setPending(false)
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
const preview = () => {
|
|
178
|
+
const first =
|
|
179
|
+
props.value
|
|
180
|
+
.split('\n')
|
|
181
|
+
.find((line) => line.trim().length > 0)
|
|
182
|
+
?.trim() ?? ''
|
|
183
|
+
return first.length > 120 ? `${first.slice(0, 120)}…` : first
|
|
184
|
+
}
|
|
185
|
+
return (
|
|
186
|
+
<div data-slot="chat-composer" class="mx-auto flex w-full max-w-4xl flex-col px-4 pb-1">
|
|
187
|
+
<Show when={!props.approvalFocus}>
|
|
188
|
+
<Show when={props.knowledge}>
|
|
189
|
+
<div data-slot="composer-knowledge">{props.knowledge}</div>
|
|
190
|
+
</Show>
|
|
191
|
+
<Show when={props.followUps}>
|
|
192
|
+
<div data-slot="composer-follow-ups">{props.followUps}</div>
|
|
193
|
+
</Show>
|
|
194
|
+
</Show>
|
|
195
|
+
<Show when={props.band}>
|
|
196
|
+
<div data-slot="composer-band">{props.band}</div>
|
|
197
|
+
</Show>
|
|
198
|
+
<div aria-hidden="true" class="h-1.5 shrink-0" />
|
|
199
|
+
<Show when={props.approval}>
|
|
200
|
+
<div data-slot="composer-approval">{props.approval}</div>
|
|
201
|
+
</Show>
|
|
202
|
+
<Show when={props.notices}>
|
|
203
|
+
<div data-slot="composer-notices">{props.notices}</div>
|
|
204
|
+
</Show>
|
|
205
|
+
<Show when={props.blockedReason}>
|
|
206
|
+
<p role="status" class="text-muted-foreground mb-1 text-xs">
|
|
207
|
+
{props.blockedReason}
|
|
208
|
+
</p>
|
|
209
|
+
</Show>
|
|
210
|
+
<Show when={error()}>
|
|
211
|
+
{(message) => (
|
|
212
|
+
<p role="alert" class="text-destructive mb-1 text-xs">
|
|
213
|
+
{message()}
|
|
214
|
+
</p>
|
|
215
|
+
)}
|
|
216
|
+
</Show>
|
|
217
|
+
<Show when={!props.approvalFocus}>
|
|
218
|
+
<Show
|
|
219
|
+
when={!collapsed()}
|
|
220
|
+
fallback={
|
|
221
|
+
<Button
|
|
222
|
+
ref={(element) => {
|
|
223
|
+
restoreBar = element
|
|
224
|
+
onCleanup(() => {
|
|
225
|
+
if (restoreBar === element) restoreBar = undefined
|
|
226
|
+
})
|
|
227
|
+
}}
|
|
228
|
+
type="button"
|
|
229
|
+
variant="outline"
|
|
230
|
+
size="sm"
|
|
231
|
+
class="w-full justify-start"
|
|
232
|
+
aria-expanded={false}
|
|
233
|
+
aria-label="Show the message input"
|
|
234
|
+
onClick={() => changeCollapsed(false)}
|
|
235
|
+
>
|
|
236
|
+
<ChevronsUpDown />
|
|
237
|
+
<span aria-hidden="true" class="shrink-0">
|
|
238
|
+
Show the message input
|
|
239
|
+
</span>
|
|
240
|
+
<Show when={preview()}>
|
|
241
|
+
<span aria-hidden="true" class="min-w-0 flex-1 truncate">
|
|
242
|
+
{preview()}
|
|
243
|
+
</span>
|
|
244
|
+
</Show>
|
|
245
|
+
</Button>
|
|
246
|
+
}
|
|
247
|
+
>
|
|
248
|
+
<form
|
|
249
|
+
data-slot="composer-input-box"
|
|
250
|
+
class="border-input bg-card flex flex-col overflow-hidden rounded-2xl border transition-colors focus-within:border-ring"
|
|
251
|
+
onSubmit={(event) => {
|
|
252
|
+
event.preventDefault()
|
|
253
|
+
void submit()
|
|
254
|
+
}}
|
|
255
|
+
>
|
|
256
|
+
<Show when={props.attachments}>
|
|
257
|
+
<div data-slot="composer-staged-content">{props.attachments}</div>
|
|
258
|
+
</Show>
|
|
259
|
+
<textarea
|
|
260
|
+
ref={(element) => {
|
|
261
|
+
field = element
|
|
262
|
+
onCleanup(() => {
|
|
263
|
+
if (field === element) field = undefined
|
|
264
|
+
})
|
|
265
|
+
}}
|
|
266
|
+
data-slot="composer-input"
|
|
267
|
+
aria-label={props.inputLabel ?? 'Message'}
|
|
268
|
+
class="field-sizing-content text-foreground placeholder:text-muted-foreground min-h-11 max-h-36 w-full resize-none border-0 bg-transparent px-4 py-3 text-sm outline-none disabled:opacity-50"
|
|
269
|
+
value={props.value}
|
|
270
|
+
onInput={(event) => props.onValueChange(event.currentTarget.value)}
|
|
271
|
+
disabled={props.disabled}
|
|
272
|
+
readOnly={props.readOnly || pending()}
|
|
273
|
+
placeholder={props.placeholder ?? 'Write a message…'}
|
|
274
|
+
rows={1}
|
|
275
|
+
onCompositionStart={ime.onCompositionStart}
|
|
276
|
+
onCompositionEnd={ime.onCompositionEnd}
|
|
277
|
+
onFocus={ime.onFocus}
|
|
278
|
+
onBlur={ime.onBlur}
|
|
279
|
+
onKeyDown={(event) => {
|
|
280
|
+
if (event.key === 'Escape' && error()) {
|
|
281
|
+
setError(null)
|
|
282
|
+
return
|
|
283
|
+
}
|
|
284
|
+
if (event.key !== 'Enter' || event.shiftKey || event.defaultPrevented) return
|
|
285
|
+
if (ime.claimEnter(event)) {
|
|
286
|
+
const selected =
|
|
287
|
+
props.busy && (event.metaKey || event.ctrlKey)
|
|
288
|
+
? props.busy.mode === 'steer'
|
|
289
|
+
? 'queue'
|
|
290
|
+
: 'steer'
|
|
291
|
+
: action()
|
|
292
|
+
void submit(selected)
|
|
293
|
+
}
|
|
294
|
+
}}
|
|
295
|
+
/>
|
|
296
|
+
<div
|
|
297
|
+
data-slot="composer-action-row"
|
|
298
|
+
class="flex items-center justify-between gap-2 px-2.5 pb-2 pt-0.5"
|
|
299
|
+
>
|
|
300
|
+
<div class="flex min-w-0 items-center gap-1">
|
|
301
|
+
<Show when={props.collapse || props.menuItems}>
|
|
302
|
+
<DropdownMenu placement="top-start">
|
|
303
|
+
<DropdownMenuTrigger
|
|
304
|
+
as={Button}
|
|
305
|
+
type="button"
|
|
306
|
+
variant="ghost"
|
|
307
|
+
size="icon-sm"
|
|
308
|
+
aria-label="Message input options"
|
|
309
|
+
>
|
|
310
|
+
<MoreHorizontal />
|
|
311
|
+
</DropdownMenuTrigger>
|
|
312
|
+
<DropdownMenuContent
|
|
313
|
+
onCloseAutoFocus={(event) => {
|
|
314
|
+
if (focusTarget) event.preventDefault()
|
|
315
|
+
}}
|
|
316
|
+
>
|
|
317
|
+
{props.menuItems}
|
|
318
|
+
<Show when={props.collapse}>
|
|
319
|
+
<DropdownMenuItem onSelect={() => changeCollapsed(true)}>
|
|
320
|
+
<ChevronsDownUp />
|
|
321
|
+
<div class="flex min-w-0 flex-col">
|
|
322
|
+
<span>Collapse the message input</span>
|
|
323
|
+
<span class="text-muted-foreground text-xs">
|
|
324
|
+
Make room to read; keep your draft
|
|
325
|
+
</span>
|
|
326
|
+
</div>
|
|
327
|
+
</DropdownMenuItem>
|
|
328
|
+
</Show>
|
|
329
|
+
</DropdownMenuContent>
|
|
330
|
+
</DropdownMenu>
|
|
331
|
+
</Show>
|
|
332
|
+
{props.leadingActions}
|
|
333
|
+
</div>
|
|
334
|
+
<div class="flex shrink-0 items-center gap-1">
|
|
335
|
+
{props.trailingActions}
|
|
336
|
+
<Show
|
|
337
|
+
when={props.busy}
|
|
338
|
+
fallback={
|
|
339
|
+
<Button
|
|
340
|
+
type="submit"
|
|
341
|
+
size="icon-sm"
|
|
342
|
+
disabled={!canSend()}
|
|
343
|
+
aria-label={pending() ? 'Sending message' : 'Send message'}
|
|
344
|
+
>
|
|
345
|
+
<Show when={pending()} fallback={<ArrowUp />}>
|
|
346
|
+
<Spinner size="sm" label={false} />
|
|
347
|
+
</Show>
|
|
348
|
+
</Button>
|
|
349
|
+
}
|
|
350
|
+
>
|
|
351
|
+
{(busy) => (
|
|
352
|
+
<BusySendButton
|
|
353
|
+
{...busy()}
|
|
354
|
+
alternateActionHint={
|
|
355
|
+
canSend(busy().mode === 'steer' ? 'queue' : 'steer')
|
|
356
|
+
? 'Ctrl/Cmd+Enter uses the other action'
|
|
357
|
+
: undefined
|
|
358
|
+
}
|
|
359
|
+
disabled={!canSend()}
|
|
360
|
+
onFire={() => {
|
|
361
|
+
void submit()
|
|
362
|
+
}}
|
|
363
|
+
/>
|
|
364
|
+
)}
|
|
365
|
+
</Show>
|
|
366
|
+
</div>
|
|
367
|
+
</div>
|
|
368
|
+
</form>
|
|
369
|
+
<Show when={props.context}>
|
|
370
|
+
<div data-slot="composer-context" class="flex min-w-0 items-center gap-2 pt-1">
|
|
371
|
+
{props.context}
|
|
372
|
+
</div>
|
|
373
|
+
</Show>
|
|
374
|
+
</Show>
|
|
375
|
+
</Show>
|
|
376
|
+
</div>
|
|
377
|
+
)
|
|
378
|
+
}
|
|
@@ -307,6 +307,16 @@ export function SplitLayout<L extends SplitLayoutLeaf>(props: SplitLayoutProps<L
|
|
|
307
307
|
sizes={[branch().ratio, 1 - branch().ratio]}
|
|
308
308
|
keyboardDelta={0.05}
|
|
309
309
|
onSizesChange={(sizes) => {
|
|
310
|
+
// Corvu also reports panel registration/unregistration while
|
|
311
|
+
// mounting or disposing a controller. Those incomplete or
|
|
312
|
+
// hidden-host sizes are not user resize intent.
|
|
313
|
+
if (!root?.isConnected || root.getClientRects().length === 0) return
|
|
314
|
+
if (
|
|
315
|
+
sizes.length !== 2 ||
|
|
316
|
+
sizes.some((size) => !Number.isFinite(size)) ||
|
|
317
|
+
Math.abs(sizes[0]! + sizes[1]! - 1) > 0.000001
|
|
318
|
+
)
|
|
319
|
+
return
|
|
310
320
|
if (sizes[0] !== undefined && Math.abs(sizes[0] - branch().ratio) > 0.000001)
|
|
311
321
|
props.onResize(id, sizes[0])
|
|
312
322
|
}}
|