Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/fe/CLAUDE.md

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions apps/fe/bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions apps/fe/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"@hot-labs/near-connect": "0.12.0",
"@tanstack/react-query": "5.106.1",
"@xyflow/react": "12.12.1",
"border-beam": "1.4.1",
"class-variance-authority": "0.7.1",
"cn": "0.5.2",
"eventsource-parser": "4.1.3",
Expand Down
8 changes: 7 additions & 1 deletion apps/fe/src/modules/chat/components/ChatScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { dayLabel } from "@/modules/chat/data/thread"
import { Shown, TurnView } from "@/modules/chat/components/TurnView"
import { FirstChat, Centered, ThreadSkeleton } from "@/modules/chat/components/ChatStates"
import { onLiveDrawer } from "@/modules/graph/data/liveDrawer"
import { useMediaQuery } from "@/hooks/useMediaQuery"

/**
* Chat (design 4 · Chat, C1): the thread, what each run did, and the composer. `threadId` null
Expand All @@ -51,6 +52,7 @@ export function ChatScreen({ mindId, threadId }: { mindId: string; threadId: str

// The live view (C2, #17): beside the chat from 1280 px, remembered per device; a sheet below that.
const liveOpen = useLiveOpen()
const wide = useMediaQuery(MEDIA.xl, false)
const [liveSheet, setLiveSheet] = useState(false)
// Phones get it as a drawer from the bottom (Ancung, 10 Nov), tablets as a sheet from the right.
const [liveDrawer, setLiveDrawer] = useState(false)
Expand Down Expand Up @@ -371,7 +373,11 @@ export function ChatScreen({ mindId, threadId }: { mindId: string; threadId: str
liveOpen ? "opacity-100 delay-50" : "opacity-0"
)}
>
<LiveView mindId={mindId} active={activeHere ?? null} className="w-full p-5" />
{/* Only made on screens wide enough to show it (1280 px): below that the panel is hidden,
and it still fetched the history, laid out the graph and readied its entrance on
every chat page (Ancung, 11 Nov: no animating what a phone doesn't show). Phones and
tablets make it only when the drawer or sheet opens. */}
{wide && <LiveView mindId={mindId} active={activeHere ?? null} className="w-full p-5" />}
</div>
</aside>
<Drawer open={liveDrawer} onOpenChange={setLiveDrawer} showSwipeHandle>
Expand Down
9 changes: 8 additions & 1 deletion apps/fe/src/modules/chat/components/Composer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { Spinner } from "@/components/elements/Spinner"
import { Button } from "@/components/ui/button"
import { readPref, writePref } from "@/lib/storage"
import { MEDIA, matches } from "@/lib/media"
import { BorderBeam } from "border-beam"
import { useTheme } from "next-themes"

/**
* The message box (C1.1). Enter sends, Shift+Enter adds a line. While the Mind replies, the send
Expand Down Expand Up @@ -60,6 +62,7 @@ export function Composer({
}
const message = value.trim()
const canSend = !busy && !locked && message.length > 0
const { resolvedTheme } = useTheme()

function send() {
if (!canSend) return
Expand All @@ -82,7 +85,10 @@ export function Composer({
}}
className="flex w-full flex-col gap-2"
>
<div className="flex w-full items-end gap-2 rounded-[24px] border border-input bg-surface py-2 pr-2 pl-[18px] transition-[border-color,box-shadow] duration-150 ease-out focus-within:ring-2 focus-within:ring-focus focus-within:ring-offset-2 focus-within:ring-offset-background">
{/* A beam travels along the box's bottom edge only while the Mind replies (Ancung, 11 Nov),
like "Thinking...": off otherwise, so nothing moves while the owner types. */}
<BorderBeam size="line" colorVariant="mono" staticColors active={busy} theme={resolvedTheme === "light" ? "light" : "dark"} strength={1} brightness={1.8} className="composer-beam">
<div className="flex w-full items-end gap-2 rounded-[24px] border border-input bg-surface py-2 pr-2 pl-[18px] transition-[border-color,box-shadow] duration-150 ease-out focus-within:ring-2 focus-within:ring-focus focus-within:ring-offset-2 focus-within:ring-offset-background">
<label htmlFor="chat-message" className="sr-only">
Message {name}
</label>
Expand All @@ -108,6 +114,7 @@ export function Composer({
</Button>
)}
</div>
</BorderBeam>
<p className="text-center text-xs text-muted-foreground">{note}</p>
</form>
)
Expand Down
92 changes: 84 additions & 8 deletions apps/fe/src/modules/graph/components/MindGraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { setFlag } from "@/modules/onboarding/data/progress"
import { wheelPan, wheelPixels, wheelZoomFactor } from "@/modules/builder/hooks/useCanvasView"
import { APPS } from "@/modules/connections/data/apps"
import type { GraphLink, GraphNode } from "@/modules/graph/data/graph"
import { settle, stepSim, syncSim, type Sim } from "@/modules/graph/data/sim"
import { stepSim, syncSim, type Sim } from "@/modules/graph/data/sim"
import { MEDIA } from "@/lib/media"
import { clampZoom, framing, toWorld as worldAt, zoomAround } from "@/modules/graph/data/camera"
import { readColors, FILL } from "@/modules/graph/data/colors"
Expand Down Expand Up @@ -39,6 +39,11 @@ const KEPT = new Map<string, { sim: Sim; view: { x: number; y: number; k: number

/** How long a finished state keeps glowing (ms). */
const AFTERGLOW = { ok: 1600, error: 4000, denied: 4000 } as const
// The live view's entrance: from 1.35 times the frame's zoom out to it, over 700 ms, ease-out.
const ENTER_ZOOM = 1.35
const ENTER_MS = 700
/** How long a frame may spend settling a new layout, so the page never freezes for it. */
const SETTLE_BUDGET_MS = 6
// The magnet: bubbles within 120 screen px of the cursor move toward it, up to a third of the
// way when right under it, fading to nothing at the edge, at most 8 units.
const MAGNET_REACH = 120
Expand All @@ -59,14 +64,29 @@ export function MindGraph({ mindId, nodes, links, avatarSrc, selected, onSelect,
// not from the event's own time, which comes from the server's clock and can arrive late
// (Ancung, 10 Nov: a 1 s calendar call never lit up).
const seen = useRef(new Map<string, { key: string; at: number }>())
const view = useRef(KEPT.get(mindId)?.view ?? { x: 0, y: 0, k: 1, auto: true })
// The camera kept from the last chat, but always back on automatic framing: a zoom or a click on
// a bubble (which zooms to it) used to stick, so every chat opened after it was zoomed into the
// Mind (Ancung, 11 Nov). The layout itself is kept, so nothing replays.
const view = useRef({ ...(KEPT.get(mindId)?.view ?? { x: 0, y: 0, k: 1 }), auto: true })
// The node the camera is gliding to after a click (Axel, via Ancung, 10 Nov: zoom to it).
const focus = useRef<string | null>(null)
const lastSelected = useRef<string | null>(null)
// Frame the layout at once on the next draw, instead of easing toward it.
// Frame the layout at once on the next draw, instead of easing toward it. A page that finds a
// kept layout frames it at once too, without a glide.
const snap = useRef(false)
// Fit was pressed: glide to the frame until there.
const fitting = useRef(false)
// How many bubbles the camera last framed, so a change reframes it.
const framedCount = useRef(0)
// A layout to settle before it is drawn, a slice each frame (see SETTLE_BUDGET_MS).
const pendingSettle = useRef(false)
// The entrance zoom out: null when none, -1 waiting for the first frame, else when it started.
// Every chat page plays it over the kept layout (Ancung, 11 Nov: like stepping into the chat);
// the layout itself stays put, so nothing jiggles.
const entering = useRef<number | null>(KEPT.has(mindId) ? -1 : null)
// No layout kept for this Mind yet: its first real frame on this page gets the entrance, even if
// the very first graph held only the Mind.
const fresh = useRef(!KEPT.has(mindId))
const hover = useRef<string | null>(null)
// How far each bubble leans toward the cursor right now (drawn only), and whether one is dragged.
const magnet = useRef(new Map<string, { x: number; y: number }>())
Expand All @@ -89,12 +109,28 @@ export function MindGraph({ mindId, nodes, links, avatarSrc, selected, onSelect,
}
lastSelected.current = selected
const first = sim.current === null
const before = sim.current?.bodies.size ?? 0
sim.current = syncSim(sim.current, nodes, links, mind)
// The first graph of this Mind on this page shows settled and framed at once: no bounce, no
// zoom out (Ancung, 11 Nov). Later, only bubbles that are really new nudge it.
if (first && nodes.length > 1) {
settle(sim.current, new Map(nodes.map((n) => [n.id, n.kind])))
snap.current = true
// zoom out (Ancung, 11 Nov). So does a graph that grows by several bubbles at once: the first
// one often holds only the Mind, before its skills and history arrive, and they then piled in
// and bounced into place (Ancung, 11 Nov: "too much jiggle"). One or two new ones only nudge it.
const grew = sim.current.bodies.size - before
if ((first && nodes.length > 1) || grew >= 3) {
// Settled in slices by the draw loop (SETTLE_BUDGET_MS a frame), not here at once: 35
// bubbles took 23 to 58 ms on a laptop, so a phone would freeze for a few hundred. A graph
// that isn't on screen doesn't draw, so it doesn't settle either.
pendingSettle.current = true
// Frame it at once only while the graph is opening (nothing but the Mind before). Later, the
// camera glides to the new frame, and only if the owner hasn't moved it: snapping during a
// reply read as the graph zooming by itself (Ancung, 11 Nov).
// The very first graph of this Mind on the page comes in with a zoom out (ENTER_MS); a page
// that finds the layout kept, or one still opening, frames at once.
if (fresh.current) {
fresh.current = false
entering.current = -1
} else if (before <= 1 && entering.current === null) snap.current = true
else fitting.current = true
}
const now = performance.now()
for (const n of nodes) {
Expand Down Expand Up @@ -193,6 +229,28 @@ export function MindGraph({ mindId, nodes, links, avatarSrc, selected, onSelect,
}
const to = framing({ x0, y0, x1, y1 }, size)
const v = view.current
// The Mind alone is no frame: zooming to it is what stuck when a chat page opened before the
// other bubbles were back (Ancung, 11 Nov). Wait for them, keeping a pending snap.
if (bodies.length <= 1) return
// The entrance (Ancung, 11 Nov): start a little zoomed in on the frame's middle and ease out
// to it, fast at first and slowing at the end. Reduced motion frames at once.
if (entering.current !== null && !still.matches) {
const now = performance.now()
if (entering.current < 0) entering.current = now
const p = Math.min(1, (now - entering.current) / ENTER_MS)
const e = 1 - (1 - p) ** 4
const from = ENTER_ZOOM + (1 - ENTER_ZOOM) * e
// Scaling the frame about the panel's middle keeps the same spot in the middle.
v.k = to.k * from
v.x = to.x * from
v.y = to.y * from
if (p >= 1) entering.current = null
return
}
if (entering.current !== null) {
entering.current = null
snap.current = true
}
if (snap.current) {
snap.current = false
v.k = to.k
Expand Down Expand Up @@ -227,8 +285,26 @@ export function MindGraph({ mindId, nodes, links, avatarSrc, selected, onSelect,
const s = sim.current
if (!s) return
const kinds = new Map(data.current.nodes.map((n) => [n.id, n.kind]))
if (pendingSettle.current) {
const until = now + SETTLE_BUDGET_MS
let warm = true
while (warm && performance.now() < until) warm = stepSim(s, kinds)
// Not still yet: nothing drawn this frame, the rest next frame. Then it appears settled.
if (warm) {
ctx.setTransform(1, 0, 0, 1, 0, 0)
ctx.clearRect(0, 0, cv.width, cv.height)
return
}
pendingSettle.current = false
}
const moving = stepSim(s, kinds)
if (view.current.auto && (moving || snap.current || fitting.current || now < 1500)) fit()
// While the camera is automatic, a change in how many bubbles there are reframes it (gliding),
// so bubbles that come back one or two at a time are never left outside it.
if (view.current.auto && s.bodies.size !== framedCount.current && s.bodies.size > 1) {
framedCount.current = s.bodies.size
fitting.current = true
}
if (view.current.auto && (moving || snap.current || fitting.current || entering.current !== null || now < 1500)) fit()
// Glide to the picked node and zoom in a little; a jump with reduced motion.
const f = focus.current ? s.bodies.get(focus.current) : null
if (f) {
Expand Down
13 changes: 9 additions & 4 deletions apps/fe/src/modules/graph/data/sim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ export function syncSim(prev: Sim | null, nodes: GraphNode[], links: GraphLink[]
// reply set it bouncing again).
const seen = new Map(prev?.seen)
for (const b of prev?.bodies.values() ?? []) seen.set(b.id, { x: b.x, y: b.y })
return { bodies, links, alpha: !prev ? 1 : added ? Math.max(prev.alpha, 0.5) : prev.alpha, seen }
// A bubble or two joining only nudges it (0.25, was 0.5: Ancung, 11 Nov, the entrance read as
// too much jiggle); many at once are settled before drawing (MindGraph).
return { bodies, links, alpha: !prev ? 1 : added ? Math.max(prev.alpha, 0.25) : prev.alpha, seen }
}

/** Run the layout until it is still (or `max` ticks), so a first graph shows settled, without the bounce. */
Expand All @@ -77,6 +79,8 @@ export function stepSim(sim: Sim, kinds: Map<string, NodeKind>): boolean {
if (sim.alpha < 0.004) return false
const list = [...sim.bodies.values()]
const a = sim.alpha
// The Mind is always pinned; another pinned bubble is one being dragged.
const friction = list.filter((b) => b.pinned).length > 1 ? 0.86 : 0.74
// Every pair pushes apart, more when close.
for (let i = 0; i < list.length; i++) {
for (let j = i + 1; j < list.length; j++) {
Expand Down Expand Up @@ -128,9 +132,10 @@ export function stepSim(sim: Sim, kinds: Map<string, NodeKind>): boolean {
// A pull to the centre, and friction.
b.vx -= b.x * 0.0025 * a
b.vy -= b.y * 0.0025 * a
// A little less friction than a dead stop, so a pulled bubble sways back (Obsidian).
b.vx *= 0.86
b.vy *= 0.86
// While a bubble is dragged, a little less friction than a dead stop, so it sways back on
// release (Obsidian). Settling on its own, more, so it comes to rest without bouncing.
b.vx *= friction
b.vy *= friction
b.x += b.vx
b.y += b.vy
}
Expand Down
11 changes: 11 additions & 0 deletions apps/fe/src/styles/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -400,3 +400,14 @@
display: none;
}
}

/* The composer's beam (border-beam, Composer.tsx) has no colour of its own to set: its "mono" light
is tinted to the brand lime here, on the beam's own layers only so the text keeps its colour.
The bloom keeps the 6 px blur the library gives it (Ancung, 11 Nov). */
.composer-beam::before,
.composer-beam::after {
filter: sepia(1) saturate(6) hue-rotate(28deg) brightness(1.08);
}
.composer-beam [data-beam-bloom] {
filter: blur(6px) sepia(1) saturate(6) hue-rotate(28deg) brightness(1.08);
}
Loading