From 3cd5b9a8d7a83588269b26bd2fa1fbb75c8c73b2 Mon Sep 17 00:00:00 2001 From: ancung Date: Thu, 12 Nov 2026 22:25:41 +0700 Subject: [PATCH 1/4] feat(fe): words for a cross-chain quote step (#273) The engine's crosschain_quote (#278) had no words in the FE, so its step row fell back to "Using a tool". It now reads "Getting a cross-chain quote", then "Got a cross-chain quote" with what would arrive where ("9.97 USDC on Base"), adding "signed by NEAR Intents" only when the engine checked the quote's signature. Tests: typecheck, eslint, vitest 276/276 (new expectations in chat-steps for a signed and an unsigned quote). Co-Authored-By: Claude Opus 5.5 --- apps/fe/src/modules/runs/data/steps.ts | 8 ++++++++ apps/fe/src/modules/runs/data/tools.ts | 2 ++ apps/fe/tests/chat-steps.test.ts | 4 ++++ 3 files changed, 14 insertions(+) diff --git a/apps/fe/src/modules/runs/data/steps.ts b/apps/fe/src/modules/runs/data/steps.ts index 94f6687a..44bb1f34 100644 --- a/apps/fe/src/modules/runs/data/steps.ts +++ b/apps/fe/src/modules/runs/data/steps.ts @@ -58,6 +58,14 @@ function summary(step: ToolStep): string | null { } case "split_amount": return count(r.shares, "share", "shares") + // A cross-chain preview (#273): what would arrive, where. "Signed by NEAR Intents" only when the engine checked it. + case "crosschain_quote": { + const to = r.to as { amount?: string; token?: string; chain?: string } | undefined + if (!to?.amount) return null + const chain = to.chain ? to.chain.charAt(0).toUpperCase() + to.chain.slice(1) : null + const signed = (r.proof as { signedBy1Click?: boolean } | undefined)?.signedBy1Click === true + return `${to.amount} ${to.token ?? ""} on ${chain ?? "the other chain"}${signed ? ", signed by NEAR Intents" : ""}`.replace(/\s+/g, " ") + } case "near_check_transfer": return r.coversAmount === true ? "Paid in full" : r.status === "succeeded" ? "Paid, but not the full amount" : r.status === "failed" ? "Not paid" : null case "near_view_account": diff --git a/apps/fe/src/modules/runs/data/tools.ts b/apps/fe/src/modules/runs/data/tools.ts index 09d0fbe9..6b3f0c9c 100644 --- a/apps/fe/src/modules/runs/data/tools.ts +++ b/apps/fe/src/modules/runs/data/tools.ts @@ -75,6 +75,8 @@ export const TOOLS: Record = { // The skills for the five tracks (#194, #211). Reading or looking up: searching. get_quotes: { doing: "Asking sellers for prices", done: "Compared prices", orb: "searching", node: "Price quotes" }, near_check_transfer: { doing: "Checking for a payment", done: "Checked for a payment", orb: "searching", node: "Transfer check" }, + // A stablecoin payment to another chain, previewed through NEAR Intents (#273): a dry quote, nothing is sent. + crosschain_quote: { doing: "Getting a cross-chain quote", done: "Got a cross-chain quote", orb: "searching", node: "Cross-chain quote", about: "Asks NEAR Intents what a stablecoin payment to another chain would deliver. A preview only: nothing is sent." }, googledrive_find_files: { doing: "Looking in your Google Drive", done: "Looked in your Google Drive", orb: "searching", node: "Drive search" }, googledocs_read_document: { doing: "Reading a Google Doc", done: "Read a Google Doc", orb: "searching", node: "Read a Doc" }, googlesheets_find_spreadsheets: { doing: "Looking for a spreadsheet", done: "Found your spreadsheets", orb: "searching", node: "Find sheets" }, diff --git a/apps/fe/tests/chat-steps.test.ts b/apps/fe/tests/chat-steps.test.ts index 33f83a69..5b0d1b85 100644 --- a/apps/fe/tests/chat-steps.test.ts +++ b/apps/fe/tests/chat-steps.test.ts @@ -116,6 +116,10 @@ describe("step words for the track skills (#211)", () => { expect(done("get_quotes", { quotes: [{ priceNear: "1" }, { priceNear: "0.8" }], cheapestOnYourList: { priceNear: "0.8" } })).toMatchObject({ label: "Compared prices", detail: "2 sellers, best 0.8 NEAR" }) expect(done("split_amount", { shares: [{}, {}, {}] })).toMatchObject({ label: "Worked out the shares", detail: "3 shares" }) expect(done("near_check_transfer", { status: "succeeded", coversAmount: true }).detail).toBe("Paid in full") + // A cross-chain preview (#273) says what would arrive where, and "signed" only when the engine checked it. + const quote = { status: "quote_only", to: { chain: "base", token: "USDC", amount: "9.97", recipient: "0xabc", minAmount: "9.87" }, proof: { signedBy1Click: true } } + expect(done("crosschain_quote", quote)).toMatchObject({ label: "Got a cross-chain quote", detail: "9.97 USDC on Base, signed by NEAR Intents" }) + expect(done("crosschain_quote", { ...quote, proof: { signedBy1Click: false } }).detail).toBe("9.97 USDC on Base") }) }) From c3fb23261941dd6e251557c794c1108d490c3692 Mon Sep 17 00:00:00 2001 From: ancung Date: Thu, 12 Nov 2026 22:25:41 +0700 Subject: [PATCH 2/4] fix(fe): Builder pinch follow-ups from Axel's review (#274) - Any new press, a mouse one too, forgets the last pinch, so a click on empty canvas after a pinch closes the settings again. - A pinch starts from the view on screen, not where an easing zoom was heading, so it no longer jumps once. - The second finger and the pinch's moves stop at the canvas, so they don't reach the card under them. - A finger lifted outside the canvas is still let go (pointerup on the window), so no stale touch starts a pinch later. Tests: typecheck, eslint, vitest 276/276. Not checked on a phone. Co-Authored-By: Claude Opus 5.5 --- apps/fe/CLAUDE.md | 4 ++-- .../fe/src/modules/builder/hooks/useCanvasView.ts | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/apps/fe/CLAUDE.md b/apps/fe/CLAUDE.md index 13e4725d..df70aace 100644 --- a/apps/fe/CLAUDE.md +++ b/apps/fe/CLAUDE.md @@ -81,7 +81,7 @@ New Mind (`/minds/new`, `NewMindFlow`): needs a session (else back to `/`) and h Chat (`/minds/[mindId]/chat` and `/chat/[threadId]`, `src/modules/chat`, design "4 · Chat" C1): - `ChatRunProvider` (in the Mind layout) holds the one run in progress per Mind, so the stream survives the move from `/chat` to `/chat/{threadId}` once `run.started` gives the new thread its id (`router.replace`). Until that move lands, `/chat` keeps showing the run it started (`ActiveRun.newThread`, newer than the page), even after the reply finished; a later "New chat" page doesn't show it (Ancung, 9 Nov: the empty first-chat screen flashed between the reply and the move). Approve/decline resumes go through it too, so the live view and the Approvals badge can read the same run. - `api.ts` posts chat and approve/decline and reads the SSE answer with `eventsource-parser`; an error before the stream starts throws `ApiError` from the JSON body. Both send the browser's `timeZone` (`ownerTimeZone`, #112), so the engine's `get_time` uses the owner's clock (it was never sent before 9 Nov, so every run was UTC). Not fixed by this: a model that schedules without calling `get_time` can still write `+00:00` (seen 9 Nov, raised with Axel); the approval card shows the time on the owner's clock, so it shows. -- `runs/data/events.ts` `foldRun` turns one run's §3 events into what the chat shows (text, tool steps, TEE badge, error; thinking a model sends as text, up to a closing ``, becomes a thought row, Ancung, 11 Nov); the same fold serves a live stream and `GET /runs/{runId}`. A paused run's stream still ends with `run.finished` and `run.verified` and the backend keeps it `awaiting_approval`, so only new work after the pause (step, text, another tool) counts as resumed; a resumed run with no result for the tool was declined (`engine/test/engine.test.ts`: decline never writes a `tool.result`). `send_payment` refusals come as `policy_denied` / `wallet_frozen`, as the event status or the result's own status. A `tool.called` with `approvedBy: "rule"` (#167) marks its step `approvedByRule`: the step row says "Approved by your rule" and a sent payment's receipt says it went without asking. A result that is really a failure, Mastra's `{ error: true, message }` (the arguments failed validation, nothing ran) or a tool's own `status: "refused"` (a Sheets change refused, #245), is an error step (it read "Changed cells ✓" before, 11 Nov). A `send_payment` result whose own status is `failed` (a try-out's demo limit, OutLayer erroring) is an error step and shows "not sent", never "Sent" (11 Nov). An approval that comes after a resume (a split bill's next person) starts a new pause: approvals from the earlier pause that never ran are declined, the new one waits with its card (11 Nov; before, it read "you declined" and had no card). +- `runs/data/events.ts` `foldRun` turns one run's §3 events into what the chat shows (text, tool steps, TEE badge, error; thinking a model sends as text, up to a closing ``, becomes a thought row, Ancung, 11 Nov); the same fold serves a live stream and `GET /runs/{runId}`. A paused run's stream still ends with `run.finished` and `run.verified` and the backend keeps it `awaiting_approval`, so only new work after the pause (step, text, another tool) counts as resumed; a resumed run with no result for the tool was declined (`engine/test/engine.test.ts`: decline never writes a `tool.result`). `send_payment` refusals come as `policy_denied` / `wallet_frozen`, as the event status or the result's own status. A cross-chain quote (`crosschain_quote`, #273, #278: a dry NEAR Intents quote, nothing is sent) reads "Got a cross-chain quote" with what would arrive where ("9.97 USDC on Base"), adding "signed by NEAR Intents" only when the result's `proof.signedBy1Click` is true. A `tool.called` with `approvedBy: "rule"` (#167) marks its step `approvedByRule`: the step row says "Approved by your rule" and a sent payment's receipt says it went without asking. A result that is really a failure, Mastra's `{ error: true, message }` (the arguments failed validation, nothing ran) or a tool's own `status: "refused"` (a Sheets change refused, #245), is an error step (it read "Changed cells ✓" before, 11 Nov). A `send_payment` result whose own status is `failed` (a try-out's demo limit, OutLayer erroring) is an error step and shows "not sent", never "Sent" (11 Nov). An approval that comes after a resume (a split bill's next person) starts a new pause: approvals from the earlier pause that never ran are declined, the new one waits with its card (11 Nov; before, it read "you declined" and had no card). - `useThread` reads `…/messages` (pages of whole runs, "Show earlier messages") and each run's events, and pairs them per run. - Cards: a receipt for a sent payment (limit from the stored policy, NearBlocks testnet link `testnet.nearblocks.io/txns/{hash}`, the explorer docs.near.org lists for testnet), a red card for a refused one (which limit, read against the policy; never a tx link), an approval card answered in place (decided 9 Nov with Ancung; the design sent "Review and approve" to Approvals): the same checks as Approvals and Approve only when nothing would refuse it, otherwise a button to the fix. Frozen wallets show a banner and a different composer note. - 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. @@ -178,7 +178,7 @@ Builder (`/minds/[mindId]/autopilot/new` and `/autopilot/[workflowId]`, `src/mod - Each kind of block has its own colour on its icon tile, in the palette, on the canvas and in its settings (`TONE` in `data/tone.ts`, through `KIND_META` in `data/blocks.ts`): Start neutral (`muted`), Ask the Mind's own (`node-mind`, inverse), Use a tool blue (`info`), If or else amber (`warning`), all from the design's B1.0, and Call a website purple (`node-app`; grey in the design, Ancung asked for every kind to differ, 9 Nov). Green and red stay for Test run results, lime stays the one brand accent. - Full screen, and asks before you leave (Ancung, 9 Nov): the Builder has no sidebar (route group `(focus)`). Changes are saved only with Save; with unsaved changes (header "Unsaved changes"), `hooks/useLeaveGuard.ts` asks first: the back arrow and the browser's Back button open "You have unsaved changes" with two buttons, Discard changes on the left and Save on the right (Keep editing instead of Save when something blocks saving); X, Esc or a click outside keep editing (Ancung, 10 Nov: three buttons were too many), and closing the tab, reloading or typing another address get the browser's own "Leave site?" (`beforeunload`). Back is caught the way cia-web's `useDraftGuard` does it: while there are changes one extra history entry (`#unsaved`) sits on top, `popstate` puts it back and asks, and leaving goes back two, or to Autopilot when the Builder was the first page this tab loaded (`loadedFirst` in `src/lib/historyNav.ts`), so it never steps out of HelloNear. `beforeunload` is listened to only while there are changes (MDN: the listener can keep a page out of the back-forward cache). This replaced keeping drafts on the device (Ancung asked for plain saving). Not checked in a browser yet. - Canvas like n8n (Ancung, 9 Nov; shortcuts read from docs.n8n.io/build/keyboard-shortcuts, the simple ones): the block column sits in a pan-and-zoom frame (`hooks/useCanvasView.ts`, a CSS transform, so the blocks stay normal DOM for clicks and drag and drop). The view is written to the DOM once per frame, never through React state, so moving doesn't re-render the Builder; the wheel and the buttons ease toward the target, dragging follows the pointer 1:1, and reduced motion jumps. Zoom is gentle: about 18% per mouse notch (`wheelZoomFactor`, capped so a fast wheel can't jump), line-based wheels are turned into pixels (`wheelPixels`); the dotted grid doubles whenever its dots would sit closer than 14 px on screen and fades a little when zoomed out (`gridOf`; zoomed far out the dots shimmered) (Ancung, 9 Nov: the first version stuttered and was too sensitive). Scroll or two fingers pan, Shift + scroll pans sideways (`wheelPan`, whether the browser sends it as deltaX or deltaY); Ctrl/Cmd + scroll or a pinch zooms around the pointer (25% to 200%); dragging empty canvas, Space + drag or the middle button pans. Controls at the bottom left (`canvas/ZoomControls.tsx`, one step is `ZOOM_STEP`): zoom out, the level (click for 100%), zoom in, Fit, shortcuts. Keys (`hooks/useEditorShortcuts.ts`, listed in `ShortcutsDialog`): + and -, 0 (100%), 1 (fit), Ctrl/Cmd + S (save), Ctrl/Cmd + Enter (test run), Ctrl/Cmd + Z and Shift + Z (undo and redo, `hooks/useHistory.ts`: up to 50 drafts, typing within a second counts once), Up and Down (pick a block), Delete (delete it), Esc (close the settings), [ (fold the Blocks panel to icons, remembered in `hellonear.builder.palette` by `hooks/usePaletteFold.ts`; it folds like the app's sidebar in `AppShell`: the width slides 240 <-> 72 px, ease-in-out 200 ms, and the full list crossfades with the icon rail, both clipped so no scrollbar shows; below 1024 px the list always sits open on top), ] (close or open the settings), ? (the list). Letters and arrows wait while you type; Save and Test run work anywhere. The settings panel shows only for a picked block and closes with X, Esc or a click on empty canvas. Not checked in a browser yet. -- Phones and tablets below 1024 px (design B1 mobile, B1.5, B1.8; Ancung, 9 Nov: the stacked desktop columns looked messy): no Blocks panel; the canvas fills the screen with zoom controls upright at the top right (+, -, fit); a round + sits between blocks (`canvas/TapSpot.tsx`) and the Add card opens "Add a block" (`AddBlockSheet.tsx`, a bottom sheet saying where it goes, "After Use a tool, before the If", with If or else off and why when it can't go there); a picked block's settings open in a bottom sheet with Done (`panels/SettingsFrame.tsx`; nothing is picked on open there); an "Add a block" button that is always there (`PhoneBar.tsx`) (it adds at the end, before the If; Ancung, 10 Nov: with an If the Add card is gone and the + was easy to miss), then Test run and Save, sit across the bottom. "Add a block" is a drawer you can swipe down (`Drawer`, like the live view on phones). One finger on empty canvas pans; two fingers pinch to zoom around the point between them and move the view with it, anywhere on the canvas, cards included (`pinchView` in `useCanvasView.ts`, touch pointers listened to in the capture phase; a pinch never counts as a tap that closes the settings; Ancung, 12 Nov: it only had the + and - buttons). Not checked on a phone yet. Money blocks refused on drop (B1.4) don't apply: the palette has no money blocks. +- Phones and tablets below 1024 px (design B1 mobile, B1.5, B1.8; Ancung, 9 Nov: the stacked desktop columns looked messy): no Blocks panel; the canvas fills the screen with zoom controls upright at the top right (+, -, fit); a round + sits between blocks (`canvas/TapSpot.tsx`) and the Add card opens "Add a block" (`AddBlockSheet.tsx`, a bottom sheet saying where it goes, "After Use a tool, before the If", with If or else off and why when it can't go there); a picked block's settings open in a bottom sheet with Done (`panels/SettingsFrame.tsx`; nothing is picked on open there); an "Add a block" button that is always there (`PhoneBar.tsx`) (it adds at the end, before the If; Ancung, 10 Nov: with an If the Add card is gone and the + was easy to miss), then Test run and Save, sit across the bottom. "Add a block" is a drawer you can swipe down (`Drawer`, like the live view on phones). One finger on empty canvas pans; two fingers pinch to zoom around the point between them and move the view with it, anywhere on the canvas, cards included (`pinchView` in `useCanvasView.ts`, touch pointers listened to in the capture phase; a pinch never counts as a tap that closes the settings; Ancung, 12 Nov: it only had the + and - buttons). After Axel's notes on #274: any new press, a mouse one too, forgets the last pinch; a pinch starts from the view on screen, not where an easing zoom was heading; the second finger and the pinch's moves don't reach the card under them; and a finger lifted outside the canvas is still let go (a `pointerup` on the window). Not checked on a phone yet. Money blocks refused on drop (B1.4) don't apply: the palette has no money blocks. - Proven 9 Nov in Chrome (try-out Mind against the hosted API): opening Morning balance check, changing its If to under 1 NEAR, Save, Run now worked; a Calendar digest (Read the calendar, then Ask with the events put in) ran and listed the sample calendar's events in Jakarta time; the engine's refusal of two asking endings, before the FE checked it. Stage 1: New job, a weekly-or-daily Start and one Ask step, Save, back in Autopilot with the job selected, Run now from Running to Worked with the Mind's note in Jakarta time. - Read steps for the track apps (#211; Ancung, 11 Nov): Read a Google Sheet (a sheet link, saved as its id by `sheetIdOf`, and optional cells like Sheet1!A1:D20), Read a Google Doc (a doc link) and Search Notion (words in the title), in `data/tools.ts`. Their rows, text and pages can go into an Ask step's prompt; a Doc's title can feed an If. Only reading: writing (a new Doc, a row, a Notion page, a Slack post) needs the owner's approval, which a job can't give. A tool arg can be `optional` (left out of the canvas when empty) and carry a `hint`, and a tool can turn what was typed into what it takes (`toArgs`). An Ask step can already use any of the Mind's skills that need no approval; these blocks make the reading explicit. Not checked with a real connected account. - Read steps for #252's tools (Ancung, 11 Nov): Read a Notion database (a database link, saved as its id by `notionIdOf`), Find free time (no fields: the engine's tool takes numbers and a job's arguments are text, so it runs with its defaults, gaps of an hour or more from 09:00 to 18:00) and List Zoom meetings. Their rows, slots and meetings can go into an Ask step's prompt. Not checked with a real connected account. diff --git a/apps/fe/src/modules/builder/hooks/useCanvasView.ts b/apps/fe/src/modules/builder/hooks/useCanvasView.ts index dfcd2f05..3f8423e7 100644 --- a/apps/fe/src/modules/builder/hooks/useCanvasView.ts +++ b/apps/fe/src/modules/builder/hooks/useCanvasView.ts @@ -218,15 +218,20 @@ export function useCanvasView() { return { d: Math.hypot(b.x - a.x, b.y - a.y) || 1, x: (a.x + b.x) / 2, y: (a.y + b.y) / 2 } } const down = (e: PointerEvent) => { + // Any new press starts fresh, a mouse one too (a touchscreen laptop: a click after a pinch + // still closes the settings; Axel, #274). + if (e.pointerType !== "touch" || touches.current.size === 0) pinched.current = false if (e.pointerType !== "touch") return - if (touches.current.size === 0) pinched.current = false touches.current.set(e.pointerId, local(e)) if (touches.current.size === 2) { // A one-finger pan becomes the pinch. pan.current = null setPanning(false) pinched.current = true - pinch.current = { view: { ...target.current }, ...between() } + // From where the view is on screen, not where an easing zoom was heading, so it doesn't jump (Axel, #274). + pinch.current = { view: { ...current.current }, ...between() } + // The second finger is the pinch's, not a press on the card under it (Axel, #274). + e.stopPropagation() } } const move = (e: PointerEvent) => { @@ -235,6 +240,7 @@ export function useCanvasView() { const p = pinch.current if (p && touches.current.size >= 2) { e.preventDefault() + e.stopPropagation() go(pinchView(p.view, p, between()), true) } } @@ -246,7 +252,12 @@ export function useCanvasView() { f.addEventListener("pointermove", move, true) f.addEventListener("pointerup", up, true) f.addEventListener("pointercancel", up, true) + // A finger lifted outside the canvas still ends there, so no stale touch starts a "pinch" later (Axel, #274). + window.addEventListener("pointerup", up) + window.addEventListener("pointercancel", up) return () => { + window.removeEventListener("pointerup", up) + window.removeEventListener("pointercancel", up) f.removeEventListener("pointerdown", down, true) f.removeEventListener("pointermove", move, true) f.removeEventListener("pointerup", up, true) From 2de4fc515b638db45b2aef5eac45c87a5e05be8a Mon Sep 17 00:00:00 2001 From: ancung Date: Thu, 12 Nov 2026 22:29:39 +0700 Subject: [PATCH 3/4] fix(fe): a cross-chain quote's step line fits a phone "9.97 USDC on Base, signed by NEAR Intents" was cut off on a phone's line (about 343 px). The step now reads "Got a cross-chain quote 9.97 USDC on Base"; the Mind states the quote's proof in its reply (#278), and the opened step still shows it. Tests: typecheck, vitest tests/chat-steps.test.ts 16/16. Co-Authored-By: Claude Opus 5.5 --- apps/fe/CLAUDE.md | 2 +- apps/fe/src/modules/runs/data/steps.ts | 8 ++++---- apps/fe/tests/chat-steps.test.ts | 5 ++--- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/apps/fe/CLAUDE.md b/apps/fe/CLAUDE.md index df70aace..2ca50586 100644 --- a/apps/fe/CLAUDE.md +++ b/apps/fe/CLAUDE.md @@ -81,7 +81,7 @@ New Mind (`/minds/new`, `NewMindFlow`): needs a session (else back to `/`) and h Chat (`/minds/[mindId]/chat` and `/chat/[threadId]`, `src/modules/chat`, design "4 · Chat" C1): - `ChatRunProvider` (in the Mind layout) holds the one run in progress per Mind, so the stream survives the move from `/chat` to `/chat/{threadId}` once `run.started` gives the new thread its id (`router.replace`). Until that move lands, `/chat` keeps showing the run it started (`ActiveRun.newThread`, newer than the page), even after the reply finished; a later "New chat" page doesn't show it (Ancung, 9 Nov: the empty first-chat screen flashed between the reply and the move). Approve/decline resumes go through it too, so the live view and the Approvals badge can read the same run. - `api.ts` posts chat and approve/decline and reads the SSE answer with `eventsource-parser`; an error before the stream starts throws `ApiError` from the JSON body. Both send the browser's `timeZone` (`ownerTimeZone`, #112), so the engine's `get_time` uses the owner's clock (it was never sent before 9 Nov, so every run was UTC). Not fixed by this: a model that schedules without calling `get_time` can still write `+00:00` (seen 9 Nov, raised with Axel); the approval card shows the time on the owner's clock, so it shows. -- `runs/data/events.ts` `foldRun` turns one run's §3 events into what the chat shows (text, tool steps, TEE badge, error; thinking a model sends as text, up to a closing ``, becomes a thought row, Ancung, 11 Nov); the same fold serves a live stream and `GET /runs/{runId}`. A paused run's stream still ends with `run.finished` and `run.verified` and the backend keeps it `awaiting_approval`, so only new work after the pause (step, text, another tool) counts as resumed; a resumed run with no result for the tool was declined (`engine/test/engine.test.ts`: decline never writes a `tool.result`). `send_payment` refusals come as `policy_denied` / `wallet_frozen`, as the event status or the result's own status. A cross-chain quote (`crosschain_quote`, #273, #278: a dry NEAR Intents quote, nothing is sent) reads "Got a cross-chain quote" with what would arrive where ("9.97 USDC on Base"), adding "signed by NEAR Intents" only when the result's `proof.signedBy1Click` is true. A `tool.called` with `approvedBy: "rule"` (#167) marks its step `approvedByRule`: the step row says "Approved by your rule" and a sent payment's receipt says it went without asking. A result that is really a failure, Mastra's `{ error: true, message }` (the arguments failed validation, nothing ran) or a tool's own `status: "refused"` (a Sheets change refused, #245), is an error step (it read "Changed cells ✓" before, 11 Nov). A `send_payment` result whose own status is `failed` (a try-out's demo limit, OutLayer erroring) is an error step and shows "not sent", never "Sent" (11 Nov). An approval that comes after a resume (a split bill's next person) starts a new pause: approvals from the earlier pause that never ran are declined, the new one waits with its card (11 Nov; before, it read "you declined" and had no card). +- `runs/data/events.ts` `foldRun` turns one run's §3 events into what the chat shows (text, tool steps, TEE badge, error; thinking a model sends as text, up to a closing ``, becomes a thought row, Ancung, 11 Nov); the same fold serves a live stream and `GET /runs/{runId}`. A paused run's stream still ends with `run.finished` and `run.verified` and the backend keeps it `awaiting_approval`, so only new work after the pause (step, text, another tool) counts as resumed; a resumed run with no result for the tool was declined (`engine/test/engine.test.ts`: decline never writes a `tool.result`). `send_payment` refusals come as `policy_denied` / `wallet_frozen`, as the event status or the result's own status. A cross-chain quote (`crosschain_quote`, #273, #278: a dry NEAR Intents quote, nothing is sent) reads "Got a cross-chain quote" with what would arrive where ("9.97 USDC on Base"; Ancung, 12 Nov: "signed by NEAR Intents" was cut off on a phone, and the Mind states the proof in its reply, #278). A `tool.called` with `approvedBy: "rule"` (#167) marks its step `approvedByRule`: the step row says "Approved by your rule" and a sent payment's receipt says it went without asking. A result that is really a failure, Mastra's `{ error: true, message }` (the arguments failed validation, nothing ran) or a tool's own `status: "refused"` (a Sheets change refused, #245), is an error step (it read "Changed cells ✓" before, 11 Nov). A `send_payment` result whose own status is `failed` (a try-out's demo limit, OutLayer erroring) is an error step and shows "not sent", never "Sent" (11 Nov). An approval that comes after a resume (a split bill's next person) starts a new pause: approvals from the earlier pause that never ran are declined, the new one waits with its card (11 Nov; before, it read "you declined" and had no card). - `useThread` reads `…/messages` (pages of whole runs, "Show earlier messages") and each run's events, and pairs them per run. - Cards: a receipt for a sent payment (limit from the stored policy, NearBlocks testnet link `testnet.nearblocks.io/txns/{hash}`, the explorer docs.near.org lists for testnet), a red card for a refused one (which limit, read against the policy; never a tx link), an approval card answered in place (decided 9 Nov with Ancung; the design sent "Review and approve" to Approvals): the same checks as Approvals and Approve only when nothing would refuse it, otherwise a button to the fix. Frozen wallets show a banner and a different composer note. - 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. diff --git a/apps/fe/src/modules/runs/data/steps.ts b/apps/fe/src/modules/runs/data/steps.ts index 44bb1f34..fb8637f2 100644 --- a/apps/fe/src/modules/runs/data/steps.ts +++ b/apps/fe/src/modules/runs/data/steps.ts @@ -58,13 +58,13 @@ function summary(step: ToolStep): string | null { } case "split_amount": return count(r.shares, "share", "shares") - // A cross-chain preview (#273): what would arrive, where. "Signed by NEAR Intents" only when the engine checked it. + // A cross-chain preview (#273): what would arrive, where. Kept short to fit a phone's line; the + // Mind states the quote's proof in its reply (#278) and the opened step shows it. case "crosschain_quote": { const to = r.to as { amount?: string; token?: string; chain?: string } | undefined if (!to?.amount) return null - const chain = to.chain ? to.chain.charAt(0).toUpperCase() + to.chain.slice(1) : null - const signed = (r.proof as { signedBy1Click?: boolean } | undefined)?.signedBy1Click === true - return `${to.amount} ${to.token ?? ""} on ${chain ?? "the other chain"}${signed ? ", signed by NEAR Intents" : ""}`.replace(/\s+/g, " ") + const chain = to.chain ? to.chain.charAt(0).toUpperCase() + to.chain.slice(1) : "the other chain" + return [to.amount, to.token, "on", chain].filter(Boolean).join(" ") } case "near_check_transfer": return r.coversAmount === true ? "Paid in full" : r.status === "succeeded" ? "Paid, but not the full amount" : r.status === "failed" ? "Not paid" : null diff --git a/apps/fe/tests/chat-steps.test.ts b/apps/fe/tests/chat-steps.test.ts index 5b0d1b85..8a14ab93 100644 --- a/apps/fe/tests/chat-steps.test.ts +++ b/apps/fe/tests/chat-steps.test.ts @@ -116,10 +116,9 @@ describe("step words for the track skills (#211)", () => { expect(done("get_quotes", { quotes: [{ priceNear: "1" }, { priceNear: "0.8" }], cheapestOnYourList: { priceNear: "0.8" } })).toMatchObject({ label: "Compared prices", detail: "2 sellers, best 0.8 NEAR" }) expect(done("split_amount", { shares: [{}, {}, {}] })).toMatchObject({ label: "Worked out the shares", detail: "3 shares" }) expect(done("near_check_transfer", { status: "succeeded", coversAmount: true }).detail).toBe("Paid in full") - // A cross-chain preview (#273) says what would arrive where, and "signed" only when the engine checked it. + // A cross-chain preview (#273) says what would arrive where, short enough for a phone's line. const quote = { status: "quote_only", to: { chain: "base", token: "USDC", amount: "9.97", recipient: "0xabc", minAmount: "9.87" }, proof: { signedBy1Click: true } } - expect(done("crosschain_quote", quote)).toMatchObject({ label: "Got a cross-chain quote", detail: "9.97 USDC on Base, signed by NEAR Intents" }) - expect(done("crosschain_quote", { ...quote, proof: { signedBy1Click: false } }).detail).toBe("9.97 USDC on Base") + expect(done("crosschain_quote", quote)).toMatchObject({ label: "Got a cross-chain quote", detail: "9.97 USDC on Base" }) }) }) From 7c9a6391506c1b6b66569d06c0c212760ae303e7 Mon Sep 17 00:00:00 2001 From: ancung Date: Thu, 12 Nov 2026 23:12:45 +0700 Subject: [PATCH 4/4] fix(fe): a cross-chain quote names its chain and trims the amount MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Axel checked #282 with a real 1Click quote: the step read "49.984601 USDC on Arb", since to.chain is 1Click's chain id. Ids now map to names (Arbitrum, Solana, BNB Chain, …; CHAIN_NAMES, from Axel's list), an unknown id shows as it is, and the amount is cut, never rounded up, to two decimals (shortAmount: 49.984601 -> 49.98, 0.004512 -> 0.0045): "49.98 USDC on Arbitrum". Tests: typecheck, eslint, vitest tests/chat-steps.test.ts 16/16 (new expectations for chain names and amounts). Co-Authored-By: Claude Opus 5.5 --- apps/fe/CLAUDE.md | 2 +- apps/fe/src/modules/runs/data/steps.ts | 25 +++++++++++++++++++++++-- apps/fe/tests/chat-steps.test.ts | 9 +++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/apps/fe/CLAUDE.md b/apps/fe/CLAUDE.md index 2ca50586..8b71f2d6 100644 --- a/apps/fe/CLAUDE.md +++ b/apps/fe/CLAUDE.md @@ -81,7 +81,7 @@ New Mind (`/minds/new`, `NewMindFlow`): needs a session (else back to `/`) and h Chat (`/minds/[mindId]/chat` and `/chat/[threadId]`, `src/modules/chat`, design "4 · Chat" C1): - `ChatRunProvider` (in the Mind layout) holds the one run in progress per Mind, so the stream survives the move from `/chat` to `/chat/{threadId}` once `run.started` gives the new thread its id (`router.replace`). Until that move lands, `/chat` keeps showing the run it started (`ActiveRun.newThread`, newer than the page), even after the reply finished; a later "New chat" page doesn't show it (Ancung, 9 Nov: the empty first-chat screen flashed between the reply and the move). Approve/decline resumes go through it too, so the live view and the Approvals badge can read the same run. - `api.ts` posts chat and approve/decline and reads the SSE answer with `eventsource-parser`; an error before the stream starts throws `ApiError` from the JSON body. Both send the browser's `timeZone` (`ownerTimeZone`, #112), so the engine's `get_time` uses the owner's clock (it was never sent before 9 Nov, so every run was UTC). Not fixed by this: a model that schedules without calling `get_time` can still write `+00:00` (seen 9 Nov, raised with Axel); the approval card shows the time on the owner's clock, so it shows. -- `runs/data/events.ts` `foldRun` turns one run's §3 events into what the chat shows (text, tool steps, TEE badge, error; thinking a model sends as text, up to a closing ``, becomes a thought row, Ancung, 11 Nov); the same fold serves a live stream and `GET /runs/{runId}`. A paused run's stream still ends with `run.finished` and `run.verified` and the backend keeps it `awaiting_approval`, so only new work after the pause (step, text, another tool) counts as resumed; a resumed run with no result for the tool was declined (`engine/test/engine.test.ts`: decline never writes a `tool.result`). `send_payment` refusals come as `policy_denied` / `wallet_frozen`, as the event status or the result's own status. A cross-chain quote (`crosschain_quote`, #273, #278: a dry NEAR Intents quote, nothing is sent) reads "Got a cross-chain quote" with what would arrive where ("9.97 USDC on Base"; Ancung, 12 Nov: "signed by NEAR Intents" was cut off on a phone, and the Mind states the proof in its reply, #278). A `tool.called` with `approvedBy: "rule"` (#167) marks its step `approvedByRule`: the step row says "Approved by your rule" and a sent payment's receipt says it went without asking. A result that is really a failure, Mastra's `{ error: true, message }` (the arguments failed validation, nothing ran) or a tool's own `status: "refused"` (a Sheets change refused, #245), is an error step (it read "Changed cells ✓" before, 11 Nov). A `send_payment` result whose own status is `failed` (a try-out's demo limit, OutLayer erroring) is an error step and shows "not sent", never "Sent" (11 Nov). An approval that comes after a resume (a split bill's next person) starts a new pause: approvals from the earlier pause that never ran are declined, the new one waits with its card (11 Nov; before, it read "you declined" and had no card). +- `runs/data/events.ts` `foldRun` turns one run's §3 events into what the chat shows (text, tool steps, TEE badge, error; thinking a model sends as text, up to a closing ``, becomes a thought row, Ancung, 11 Nov); the same fold serves a live stream and `GET /runs/{runId}`. A paused run's stream still ends with `run.finished` and `run.verified` and the backend keeps it `awaiting_approval`, so only new work after the pause (step, text, another tool) counts as resumed; a resumed run with no result for the tool was declined (`engine/test/engine.test.ts`: decline never writes a `tool.result`). `send_payment` refusals come as `policy_denied` / `wallet_frozen`, as the event status or the result's own status. A cross-chain quote (`crosschain_quote`, #273, #278: a dry NEAR Intents quote, nothing is sent) reads "Got a cross-chain quote" with what would arrive where ("49.98 USDC on Arbitrum": 1Click's chain ids named by `CHAIN_NAMES`, an unknown id shown as it is, and the amount cut to two decimals by `shortAmount`, Axel on #282; Ancung, 12 Nov: "signed by NEAR Intents" was cut off on a phone, and the Mind states the proof in its reply, #278). A `tool.called` with `approvedBy: "rule"` (#167) marks its step `approvedByRule`: the step row says "Approved by your rule" and a sent payment's receipt says it went without asking. A result that is really a failure, Mastra's `{ error: true, message }` (the arguments failed validation, nothing ran) or a tool's own `status: "refused"` (a Sheets change refused, #245), is an error step (it read "Changed cells ✓" before, 11 Nov). A `send_payment` result whose own status is `failed` (a try-out's demo limit, OutLayer erroring) is an error step and shows "not sent", never "Sent" (11 Nov). An approval that comes after a resume (a split bill's next person) starts a new pause: approvals from the earlier pause that never ran are declined, the new one waits with its card (11 Nov; before, it read "you declined" and had no card). - `useThread` reads `…/messages` (pages of whole runs, "Show earlier messages") and each run's events, and pairs them per run. - Cards: a receipt for a sent payment (limit from the stored policy, NearBlocks testnet link `testnet.nearblocks.io/txns/{hash}`, the explorer docs.near.org lists for testnet), a red card for a refused one (which limit, read against the policy; never a tx link), an approval card answered in place (decided 9 Nov with Ancung; the design sent "Review and approve" to Approvals): the same checks as Approvals and Approve only when nothing would refuse it, otherwise a button to the fix. Frozen wallets show a banner and a different composer note. - 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. diff --git a/apps/fe/src/modules/runs/data/steps.ts b/apps/fe/src/modules/runs/data/steps.ts index fb8637f2..f11ceedd 100644 --- a/apps/fe/src/modules/runs/data/steps.ts +++ b/apps/fe/src/modules/runs/data/steps.ts @@ -25,6 +25,27 @@ export function stepOrb(step: Pick): StepOrb { return TOOLS[step.tool]?.orb ?? "working" } +/** + * 1Click's chain ids in people's words (Axel, #282: "on Arb" read like a code). An id not listed + * shows as it is. + */ +export const CHAIN_NAMES: Record = { + eth: "Ethereum", arb: "Arbitrum", base: "Base", sol: "Solana", pol: "Polygon", bsc: "BNB Chain", op: "Optimism", + avax: "Avalanche", tron: "Tron", ton: "TON", sui: "Sui", aptos: "Aptos", stellar: "Stellar", gnosis: "Gnosis", + scroll: "Scroll", monad: "Monad", xlayer: "X Layer", hypercore: "Hyperliquid", +} + +/** A token amount cut (never rounded up) to two decimals, or to its first figures when smaller: "49.984601" -> "49.98", "0.004512" -> "0.0045". */ +export function shortAmount(amount: string): string { + const m = amount.match(/^(\d+)(?:\.(\d+))?$/) + if (!m) return amount + const [, whole, frac = ""] = m + const two = frac.slice(0, 2).replace(/0+$/, "") + if (whole !== "0" || !frac) return two ? `${whole}.${two}` : whole + const lead = frac.search(/[1-9]/) + return lead < 0 ? "0" : `0.${frac.slice(0, Math.max(2, lead + 2))}` +} + export type StepText = { label: string; detail: string | null; tone: "doing" | "done" | "failed" | "stopped" } export function stepText(step: ToolStep): StepText { @@ -63,8 +84,8 @@ function summary(step: ToolStep): string | null { case "crosschain_quote": { const to = r.to as { amount?: string; token?: string; chain?: string } | undefined if (!to?.amount) return null - const chain = to.chain ? to.chain.charAt(0).toUpperCase() + to.chain.slice(1) : "the other chain" - return [to.amount, to.token, "on", chain].filter(Boolean).join(" ") + const chain = to.chain ? (CHAIN_NAMES[to.chain] ?? to.chain) : "the other chain" + return [shortAmount(to.amount), to.token, "on", chain].filter(Boolean).join(" ") } case "near_check_transfer": return r.coversAmount === true ? "Paid in full" : r.status === "succeeded" ? "Paid, but not the full amount" : r.status === "failed" ? "Not paid" : null diff --git a/apps/fe/tests/chat-steps.test.ts b/apps/fe/tests/chat-steps.test.ts index 8a14ab93..5e483473 100644 --- a/apps/fe/tests/chat-steps.test.ts +++ b/apps/fe/tests/chat-steps.test.ts @@ -119,6 +119,15 @@ describe("step words for the track skills (#211)", () => { // A cross-chain preview (#273) says what would arrive where, short enough for a phone's line. const quote = { status: "quote_only", to: { chain: "base", token: "USDC", amount: "9.97", recipient: "0xabc", minAmount: "9.87" }, proof: { signedBy1Click: true } } expect(done("crosschain_quote", quote)).toMatchObject({ label: "Got a cross-chain quote", detail: "9.97 USDC on Base" }) + // 1Click's chain ids become names, unknown ones stay as they are, and the amount is cut to two decimals (Axel, #282). + expect(done("crosschain_quote", { ...quote, to: { ...quote.to, chain: "arb", amount: "49.984601" } }).detail).toBe("49.98 USDC on Arbitrum") + expect(done("crosschain_quote", { ...quote, to: { ...quote.to, chain: "bsc", amount: "12" } }).detail).toBe("12 USDC on BNB Chain") + expect(done("crosschain_quote", { ...quote, to: { ...quote.to, chain: "zksync" } }).detail).toBe("9.97 USDC on zksync") + const { shortAmount } = await import("@/modules/runs/data/steps") + expect(shortAmount("49.984601")).toBe("49.98") + expect(shortAmount("10.000000")).toBe("10") + expect(shortAmount("0.004512")).toBe("0.0045") + expect(shortAmount("0.000000")).toBe("0") }) })