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
1 change: 1 addition & 0 deletions apps/fe/CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ Chat (`/minds/[mindId]/chat` and `/chat/[threadId]`, `src/modules/chat`, design
- Approval cards for things other than payments say what is being approved, from the tool's own arguments (`data/approvalDetails.ts`, `ApprovalDetailLines`, chat and Approvals): an event's title and time, a meeting's time, guests, whether it gets a Meet link, that it is added to the owner's Google Calendar, and that Google emails each guest an invite in the owner's name (`googlecalendar_create_meeting`, #97), a moved event's old and new time as From and To, saying nobody is emailed (`googlecalendar_move_event`, #247; the old time is what the Mind listed, and the engine refuses the move if the event has moved since), an email's subject and recipients (`mail_send`), "Email me" with its subject, only to the owner's own Gmail (`mail_send_to_owner`, in chat since #225), and for the track skills' apps (#211) a new Doc's title, text added at the end of an existing Doc with that Doc's title, length and the text (`googledocs_append_text`, #247), a Sheets row's values, a Notion page or row, a Notion row change (each property old → new, #247, same words as the backend's Telegram card), a Slack message with its channel, a Zoom meeting's topic, time on the owner's clock, length and "Nobody is invited" (`zoom_create_meeting`, #246), and what a Mind sells for how much (`sell_offer`). Times are shown on the owner's clock. The answer toast names the thing ("Declining the meeting", "Scheduled a meeting"), not the tool's progress words.
- Streaming follows design/CLAUDE.md: steady reveal by whole words at the pace the text arrives (Ancung, 12 Nov: still choppy). Measured on the hosted demo: the model sends about 45 characters a second in bursts every 0.5 s, and the old fixed 220 a second showed each burst at once, then waited, so words came in clumps half a second apart. Now the reply plays the text as it stood a short delay ago, joined evenly between bursts (`playoutLength`), the delay a little longer than the usual gap between bursts, 120 to 700 ms, a pause for a tool not counted (`playoutDelay`); once the stream ends, the rest shows within 0.8 s, at least 220 characters a second. The reply is rendered block by block (`splitBlocks`: blank lines, never inside a code fence), each block memoised, so only the last one is parsed again while streaming, like Vercel's Streamdown, and the reveal can update every frame; with a 200 ms per-word fade (all at once with reduced motion), rendered as Markdown from the first word; a "**" or "`" that is still open is closed for now (`closeOpenMarks`) so the symbols never show (Ancung, 9 Nov). The Markdown components are made once per streaming state (`markdownParts`, `useMemo`): defined inline they were new functions every frame, React remounted the whole reply as it grew, every word restarted its fade and a streaming reply showed only its list bullets (Ancung, 10 Nov; hidden locally while the dev proxy held the stream back). Where the view sits (decided 9 Nov with Ancung, like Claude, instead of the design's follow-the-bottom): an old thread opens at its end; a message sent glides its turn to the top of the view (24 px below it, 60 px on phones to clear the round Live view button too, `pinGap`; the last turn's min-height leaves the same room, so scrolling to the very end lands where pinning did instead of under the top fade; Ancung, 10 Nov) (the last turn gets a min-height of the view) and the reply grows below without the view chasing it; "Latest" shows whenever there is more below. The scroll area runs to the bottom of the screen and the composer floats over it, so the scrollbar reaches the bottom like Claude's (Ancung, 10 Nov); the text fades out under the header (24 px) and into the composer through overlays in the page colour that stop short of the scrollbar (Ancung, 9 Nov, like Gemini; a mask used to do it and hid the scrollbar's ends), and the content keeps room for the composer (its height is measured); the chat header has no divider line, and the content has the same room at both ends so nothing is faded at the start or the end. Only sending moves the view: answering an approval keeps the turn's room below it (`ActiveRun.pinned`) and starts from the events already shown, so nothing shrinks and the view stays put (Ancung, 9 Nov). The TEE badge shows under each verified reply only, not in the chat header as in the design: verification is per run, and a header badge read like it covered the whole chat. The Mind's replies and the typing dots have no bubble, only the small avatar and name above (also 9 Nov). A reply is one block under that avatar in the order it happened (`RunView.parts`): what the Mind said, the card it needed (approval, then receipt or refusal), then what it said after; the avatar shows even when the Mind goes straight to a tool. A short thread starts at the top, not pinned to the bottom as in the design, and a chat from today has no "Today" label: day labels only show where the day changes or at the top of an older thread (decided 9 Nov with Ancung), reading Today, Yesterday, or the day spelled out ("Monday, 2 Nov", the year only when it isn't this one; Ancung, 11 Nov: the short "Mon" from Recent chats read like a code there).
- The Mind's work shows inside its reply, in order (decided 9 Nov with Ancung, instead of relying on the live view): a row per tool (`runs/components/ReplySteps.tsx` `StepRow`, words in `runs/data/tools.ts` and `runs/data/steps.ts`): "Checking the balance..." with a spinner and shimmer while it runs, then "Checked the balance 4.79 NEAR"; a row per stretch of reasoning (`ThoughtRow`, from `reasoning.delta`, GLM only): "Thinking..." then "Thought for 4s". Finished rows open to show what went in and came back as plain "Name: value" lines (no code font, per the UI rules). Once the reply is done, its step and thought rows fold into one line above it, "Worked for 20s, used 4 steps" (`StepsSummary`, `summaryLabel`), that opens to show them in order; approvals, receipts and refusals stay in place (Ancung, 9 Nov, like Claude). "Worked for" is `RunView.workMs`: first event to last, leaving out the gap where a paused run waited for the owner's approval (thinking time alone hid where a 20 s wait went). Each finished tool row shows how long it took (`stepDuration`, from `tool.called` to its result); a running row and the "Thinking..." dots count seconds from 3 s on (`Elapsed`, this device's clock). Typing dots only show when nothing else does, reading "Thinking..." for the whole wait (not "Sending...": in a payments app that reads like money moving). Thought rows show the "Thinking..." orb while live and no icon once done (Ancung, 11 Nov: one "Thinking..." had an orb and one did not), and opened details sit level with the row as plain muted text, no box. No "·" separators in these rows (Ancung). Reduced motion keeps a fading pulse instead of movement (`typing-dot`, `text-shimmer` in `globals.css`).
- A reply that could not come (`FailedReply` in `TurnView.tsx`) links "Check the status" (`STATUS_URL` in `src/lib/config.ts`, a new tab) when a service may be down: a 5xx or a run that broke partway (`mayBeOutage` in `chat/data/thread.ts`), not for sign-in, guest limits, an empty reply or the owner's own connection (#304). Links in replies already open in a new tab (`ReplyText`).
- Under a finished reply (Ancung, 10 Nov, like Claude): Copy reply (`CopyButton` in `src/components/elements`, a check for 1.5 s), and on the newest turn only, Ask again, which sends the same message as a new turn (the backend can't replace a reply yet, so the old one stays). Fenced code blocks sit in a box with their language and a Copy button (`CodeBlock` in `ReplyText.tsx`; code stays mono there, per the UI rules); inline code keeps its chip.
- Switching chats while the Mind replies: `ChatRunProvider` lives in the Mind layout, so the stream keeps going on another chat of the same Mind and is still live when you come back; the chat being answered shows the chat's thinking orb in Recent chats instead of its time, and its title shimmers, like "Thinking..." (`useActiveRun`; Ancung, 10 Nov: first a green dot). One run per Mind, so the other chat waits to send. Leaving the Mind or reloading drops the stream here, but the backend finishes the run and the chat shows it when reopened (read from the code, not checked in a browser).
- A Recent chats title too long for its row runs like a ticker while the row is hovered or focused (`MarqueeTitle` in `ChatRow`, Web Animations): after 0.1 s it moves left at 28 px a second and loops, two copies 32 px apart so there is no seam, both edges fading; leaving glides it in 350 ms to the nearer start before "…" comes back. One that fits never moves; reduced motion keeps it still (Ancung, 11 Nov: a loop, not back and forth, and slower).
Expand Down
3 changes: 3 additions & 0 deletions apps/fe/src/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ export const NETWORK_ID = "testnet" as const

/** Testnet RPC, for reading the owner's own balance (docs.near.org lists it for testnet; checked 9 Nov). */
export const NEAR_RPC_URL = "https://rpc.testnet.near.org"

/** The public status page (apps/status, #303): whether HelloNear and the services it runs on answer. */
export const STATUS_URL = "https://status.hellonear.xyz"
26 changes: 18 additions & 8 deletions apps/fe/src/modules/chat/components/TurnView.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
"use client"

import { CircleXIcon, RotateCcwIcon } from "lucide-react"
import { CircleXIcon, ExternalLinkIcon, RotateCcwIcon } from "lucide-react"
import { MindAvatar } from "@/components/elements/MindAvatar"
import { CopyButton } from "@/components/elements/CopyButton"
import { Badge } from "@/components/ui/badge"
import { Button } from "@/components/ui/button"
import { STATUS_URL } from "@/lib/config"
import { clockTime } from "@/lib/format"
import { paymentOf, type ReplyPart, type RunView, type ToolStep } from "@/modules/runs/data/events"
import { ReplyText } from "@/modules/runs/components/ReplyText"
Expand All @@ -14,7 +15,7 @@ import { StepRow, StepsSummary, ThoughtRow } from "@/modules/runs/components/Rep
import { summaryLabel } from "@/modules/runs/data/steps"
import { Working } from "@/modules/runs/components/Working"
import type { ApiWallet } from "@/modules/wallet/api"
import { failureText } from "@/modules/chat/data/thread"
import { failureText, mayBeOutage } from "@/modules/chat/data/thread"

/** `read`: the run's events are in, so an empty reply is known to be empty, not still loading. */
export type Shown = { key: string; message: string | null; createdAt: string; view: RunView; live: boolean; failed: unknown; read: boolean }
Expand Down Expand Up @@ -191,12 +192,21 @@ function FailedReply({ name, error, canRetry, onRetry }: { name: string; error:
<CircleXIcon className="mt-0.5 size-4 shrink-0 text-danger" />
{failureText(name, error)}
</p>
{canRetry && (
<Button variant="outline" size="sm" onClick={onRetry}>
<RotateCcwIcon />
Try again
</Button>
)}
<div className="flex flex-wrap items-center gap-2">
{canRetry && (
<Button variant="outline" size="sm" onClick={onRetry}>
<RotateCcwIcon />
Try again
</Button>
)}
{/* #304: when a service may be down, say where to check it. A new tab, so the chat stays. */}
{mayBeOutage(error) && (
<Button variant="ghost" size="sm" nativeButton={false} render={<a href={STATUS_URL} target="_blank" rel="noopener noreferrer" />}>
Check the status
<ExternalLinkIcon />
</Button>
)}
</div>
</div>
)
}
Expand Down
11 changes: 11 additions & 0 deletions apps/fe/src/modules/chat/data/thread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@ function longDay(iso: string, now: Date): string {
return `${weekday}, ${rest}`
}

/**
* A failure that may be an outage on our side or a provider's (#304): the backend or engine answered 5xx, or the
* run broke partway. Those cards link to the status page; a sign-in, a limit or a dropped connection on the
* owner's side don't.
*/
export function mayBeOutage(error: unknown): boolean {
if (error instanceof ApiError) return error.status >= 500
// "no_reply" means the model wrote nothing, not that a service failed.
return typeof error === "string" && error !== "no_reply"
}

export function failureText(name: string, error: unknown): string {
if (error instanceof ApiError) {
if (error.code === "demo_run_limit") return `That's all the messages a guest gets. Connect a wallet to keep chatting with ${name}.`
Expand Down
14 changes: 13 additions & 1 deletion apps/fe/tests/chat-screen.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from "vitest"
import { ApiError } from "@/lib/api"
import { dayLabel, failureText } from "@/modules/chat/data/thread"
import { dayLabel, failureText, mayBeOutage } from "@/modules/chat/data/thread"
import { refusalReasons } from "@/modules/wallet/data/checks"

describe("refusalReasons", () => {
Expand Down Expand Up @@ -44,3 +44,15 @@ describe("no reply", () => {
expect(failureText("Omaga", "no_reply")).toBe("Omaga thought about it but didn't write a reply. Try asking again.")
})
})

describe("mayBeOutage (#304)", () => {
it("links the status page for a 5xx or a run that broke partway, not for the owner's own side", async () => {
const { ApiError } = await import("@/lib/api")
expect(mayBeOutage(new ApiError(503, "engine_unavailable", {}))).toBe(true)
expect(mayBeOutage("engine_stream_interrupted")).toBe(true)
expect(mayBeOutage(new ApiError(401, "unauthorized", {}))).toBe(false)
expect(mayBeOutage(new ApiError(429, "demo_run_limit", {}))).toBe(false)
expect(mayBeOutage("no_reply")).toBe(false)
expect(mayBeOutage(new TypeError("Failed to fetch"))).toBe(false)
})
})
2 changes: 2 additions & 0 deletions apps/status/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
tsconfig.tsbuildinfo
.vercel
.env*
2 changes: 0 additions & 2 deletions apps/status/app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ a { color: inherit; }

.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 32px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; font-size: 22px; font-weight: 600; letter-spacing: -0.3px; }
.ghost { border: 1px solid var(--border); border-radius: 999px; padding: 8px 14px; text-decoration: none; font-size: 14px; background: var(--card); white-space: nowrap; }
.ghost:hover { border-color: var(--muted); }

.banner { border-radius: 16px; padding: 20px 22px; margin-bottom: 32px; border: 1px solid transparent; }
.banner h1 { margin: 0; font-size: 20px; letter-spacing: -0.2px; }
Expand Down
10 changes: 5 additions & 5 deletions apps/status/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ export default async function Page() {
HelloNear <span className="muted">Status</span>
</span>
</a>
<a className="ghost" href="https://app.hellonear.xyz">
Open the app
</a>
</header>
{status ? <Board status={status} /> : <Unreachable />}
<footer className="foot">
Expand Down Expand Up @@ -57,7 +54,7 @@ function Board({ status }: { status: Status }) {
<li key={s.id}>
{/* The impact line says what breaks when a service is down; a slow one still works. */}
<strong>{s.name}</strong> {s.status === "down" ? "is down" : "is answering slowly"}
{s.detail ? ` (${s.detail})` : ""}.{s.status === "down" ? ` ${s.impact}` : " It still works."}
{s.detail ? ` (${trimDot(s.detail)})` : ""}.{s.status === "down" ? ` ${s.impact}` : " It still works."}
</li>
))}
</ul>
Expand All @@ -82,6 +79,9 @@ function Board({ status }: { status: Status }) {
);
}

// The backend writes details as sentences; the page adds its own full stop.
const trimDot = (s: string) => s.replace(/[.\s]+$/, "");

const clock = (iso: string) => new Date(iso).toLocaleTimeString("en-GB", { hour: "2-digit", minute: "2-digit", timeZone: "UTC" });

function PastIncidents({ status }: { status: Status }) {
Expand All @@ -104,7 +104,7 @@ function PastIncidents({ status }: { status: Status }) {
<strong>{x.end ? "Resolved" : "Ongoing"}</strong>
{" - "}
{x.end ? `From ${clock(x.start)} to ${clock(x.end)}` : `Since ${clock(x.start)}`} ({duration(x.minutes)}).
{x.detail ? ` ${x.detail}.` : ""}
{x.detail ? ` ${trimDot(x.detail)}.` : ""}
</p>
</div>
))
Expand Down
Loading
Loading