@40rty/ams-cli 0.2.1 → 0.2.2
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 +1 -1
- package/templates/package/src/shell.tsx +118 -42
package/package.json
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import {useEffect, useState} from 'react';
|
|
1
2
|
import {
|
|
2
3
|
SpacefrontCanvas,
|
|
3
4
|
renderInline,
|
|
@@ -9,7 +10,12 @@ import {
|
|
|
9
10
|
useThreadRows,
|
|
10
11
|
} from '@40rty/ams-sdk';
|
|
11
12
|
|
|
12
|
-
/**
|
|
13
|
+
/**
|
|
14
|
+
* The page: a header, the canvas the agent composes onto, and the AMS island —
|
|
15
|
+
* the floating composer every 40rty spacefront is recognised by. Its shape is
|
|
16
|
+
* fixed (grip, latest answer, field, round send stamp, suggestion chips, a pill
|
|
17
|
+
* when folded); its look comes from the brand tokens in `styles.css`.
|
|
18
|
+
*/
|
|
13
19
|
export function Shell() {
|
|
14
20
|
const session = useFourtySession();
|
|
15
21
|
const [draft, setDraft] = useComposerDraft();
|
|
@@ -18,9 +24,34 @@ export function Shell() {
|
|
|
18
24
|
const goHome = useGoHome();
|
|
19
25
|
const {cart} = useCart();
|
|
20
26
|
const chips = session.suggestions ? session.suggestions.actions : [];
|
|
27
|
+
const latest = rows.length > 0 ? rows[rows.length - 1] : undefined;
|
|
28
|
+
|
|
29
|
+
const [threadOpen, setThreadOpen] = useState(false);
|
|
30
|
+
const [folded, setFolded] = useState(false);
|
|
31
|
+
|
|
32
|
+
// Folds to the pill while the visitor scrolls down the canvas, back on scroll up.
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
let last = window.scrollY;
|
|
35
|
+
const onScroll = () => {
|
|
36
|
+
const y = window.scrollY;
|
|
37
|
+
if (Math.abs(y - last) > 24) {
|
|
38
|
+
setFolded(y > last && y > 120);
|
|
39
|
+
last = y;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
window.addEventListener('scroll', onScroll, {passive: true});
|
|
43
|
+
return () => window.removeEventListener('scroll', onScroll);
|
|
44
|
+
}, []);
|
|
45
|
+
|
|
46
|
+
const send = (text: string) => {
|
|
47
|
+
if (text.trim() === '') return;
|
|
48
|
+
session.sendMessage(text);
|
|
49
|
+
setDraft('');
|
|
50
|
+
setFolded(false);
|
|
51
|
+
};
|
|
21
52
|
|
|
22
53
|
return (
|
|
23
|
-
<div className="
|
|
54
|
+
<div className="min-h-screen bg-paper text-ink antialiased">
|
|
24
55
|
<header className="sticky top-0 z-40 flex h-16 items-center justify-between border-b border-ink/10 bg-paper/90 px-6 backdrop-blur md:px-10">
|
|
25
56
|
<button type="button" className="font-semibold" onClick={goHome}>
|
|
26
57
|
__LABEL__
|
|
@@ -30,51 +61,96 @@ export function Shell() {
|
|
|
30
61
|
</a>
|
|
31
62
|
</header>
|
|
32
63
|
|
|
33
|
-
<
|
|
34
|
-
<
|
|
35
|
-
|
|
36
|
-
</main>
|
|
64
|
+
<main className="min-w-0 pb-56">
|
|
65
|
+
<SpacefrontCanvas />
|
|
66
|
+
</main>
|
|
37
67
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
68
|
+
<div className="pointer-events-none fixed inset-x-0 bottom-4 z-40 flex justify-center px-4">
|
|
69
|
+
{folded ? (
|
|
70
|
+
<button
|
|
71
|
+
type="button"
|
|
72
|
+
className="pointer-events-auto h-10 w-28 rounded-[20px] bg-ink text-paper text-sm font-semibold shadow-lg"
|
|
73
|
+
onClick={() => setFolded(false)}
|
|
74
|
+
>
|
|
75
|
+
Ask
|
|
76
|
+
</button>
|
|
77
|
+
) : (
|
|
78
|
+
<div className="pointer-events-auto grid w-full max-w-[640px] gap-2">
|
|
79
|
+
{chips.length > 0 && (
|
|
80
|
+
<div className="flex flex-wrap justify-center gap-2">
|
|
81
|
+
{chips.map((chip) => (
|
|
82
|
+
<button
|
|
83
|
+
key={chip.id}
|
|
84
|
+
type="button"
|
|
85
|
+
className="rounded-full border border-ink/20 bg-paper px-3 py-1 text-sm hover:border-accent"
|
|
86
|
+
onClick={() => selectChip(chip)}
|
|
87
|
+
>
|
|
88
|
+
{chip.label}
|
|
89
|
+
</button>
|
|
90
|
+
))}
|
|
45
91
|
</div>
|
|
46
|
-
)
|
|
47
|
-
{session.error && <p className="text-accent">{session.error}</p>}
|
|
48
|
-
</div>
|
|
92
|
+
)}
|
|
49
93
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
94
|
+
<div className="overflow-hidden rounded-2xl bg-paper text-ink shadow-[0_0_0_1px_rgb(var(--color-ink)/.14),0_6px_16px_-4px_rgb(var(--color-ink)/.26),0_20px_44px_-12px_rgb(var(--color-ink)/.36)]">
|
|
95
|
+
<button
|
|
96
|
+
type="button"
|
|
97
|
+
aria-label="Fold the assistant"
|
|
98
|
+
className="flex w-full justify-center py-2"
|
|
99
|
+
onClick={() => setFolded(true)}
|
|
100
|
+
>
|
|
101
|
+
<span className="h-1 w-8 rounded-full bg-ink/40" />
|
|
54
102
|
</button>
|
|
55
|
-
))}
|
|
56
|
-
</div>
|
|
57
103
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
104
|
+
<div className={`px-4 text-sm ${threadOpen ? 'grid max-h-64 gap-3 overflow-y-auto pb-2' : ''}`} aria-live="polite">
|
|
105
|
+
{session.error ? (
|
|
106
|
+
<p className="text-accent">{session.error}</p>
|
|
107
|
+
) : session.isRunning ? (
|
|
108
|
+
<p className="animate-pulse text-ink/50">Pulling that together…</p>
|
|
109
|
+
) : threadOpen ? (
|
|
110
|
+
rows.map((row) => (
|
|
111
|
+
<div key={row.key} className="grid gap-1">
|
|
112
|
+
<p className="text-ink/60">{row.visitorText}</p>
|
|
113
|
+
<p>{renderInline(row.prose, row.key)}</p>
|
|
114
|
+
</div>
|
|
115
|
+
))
|
|
116
|
+
) : isEmpty ? (
|
|
117
|
+
<p className="text-ink/60">Tell us what you’re looking for.</p>
|
|
118
|
+
) : (
|
|
119
|
+
latest && (
|
|
120
|
+
<button type="button" className="line-clamp-2 text-left text-ink/70" onClick={() => setThreadOpen(true)}>
|
|
121
|
+
{renderInline(latest.prose, latest.key)}
|
|
122
|
+
</button>
|
|
123
|
+
)
|
|
124
|
+
)}
|
|
125
|
+
</div>
|
|
126
|
+
|
|
127
|
+
<form
|
|
128
|
+
className="flex items-center gap-2 px-3 pb-3 pt-2"
|
|
129
|
+
onSubmit={(event) => {
|
|
130
|
+
event.preventDefault();
|
|
131
|
+
send(draft);
|
|
132
|
+
}}
|
|
133
|
+
>
|
|
134
|
+
<input
|
|
135
|
+
className="min-w-0 flex-1 bg-transparent px-3 py-2 outline-none"
|
|
136
|
+
aria-label="Ask"
|
|
137
|
+
placeholder="Ask anything…"
|
|
138
|
+
value={draft}
|
|
139
|
+
onChange={(event) => setDraft(event.target.value)}
|
|
140
|
+
onFocus={() => setThreadOpen(false)}
|
|
141
|
+
/>
|
|
142
|
+
<button
|
|
143
|
+
type="submit"
|
|
144
|
+
aria-label="Send"
|
|
145
|
+
className="grid h-[34px] w-[34px] shrink-0 place-items-center rounded-full bg-ink text-paper disabled:opacity-40"
|
|
146
|
+
disabled={session.isRunning || draft.trim() === ''}
|
|
147
|
+
>
|
|
148
|
+
↑
|
|
149
|
+
</button>
|
|
150
|
+
</form>
|
|
151
|
+
</div>
|
|
152
|
+
</div>
|
|
153
|
+
)}
|
|
78
154
|
</div>
|
|
79
155
|
</div>
|
|
80
156
|
);
|