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
6 changes: 3 additions & 3 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ a Tauri 2 shell (planned). Status: Phase 0, pre-alpha. See
| `crates/rupok-ink` | Pen input pipeline, wasm-safe | `StrokeBuilder` (wet ink), `filter::OneEuro2`, `pressure::PressureCurve`, `simplify`, `codec::{encode_points, decode_points}` (point codec v1), `MIN_WIDTH_RATIO`, `point_radius`, `math` (handwritten maths → LaTeX), `write` (text + LaTeX → timed handwriting strokes) |
| `crates/rupok-core` | Lesson document on Loro | `Lesson` (`doc.rs`: all mutations), model types (`model.rs`: `ItemData`, `StrokeData`, `ObjectData`, `PageSpec`…), `Scene` (`scene.rs`: R*-tree hit-test, eraser, lasso), `DOC_FORMAT` |
| `crates/rupok-format` | `.rpk` package and Smart Object bundles (Apache-2.0) | `Package::{read, write, from_lesson, add_asset, content_markdown}`, `readable` (derived `README.md`/`content.md`/`content.json`), `ObjectBundle::{from_single_html, from_files, from_dir, validate}`, `LIBS`, `safe_path`, `FORMAT_VERSION`, `MIMETYPE`, `media` (embed allowlist, `parse_link`, `embed_url`, `prepare`), `model3d` (3D viewer object) |
| `crates/rupok-live` | Live agent bridge shared by the board and `rupok mcp --live` | `protocol.rs` (WebSocket protocol v1: channels, ports, origin/host checks), `op.rs` (`Op`), `apply.rs` (`apply`: one attributed commit per agent op), `attribution.rs`, `sync` |
| `crates/rupok-live` | Live agent bridge shared by the board and `rupok mcp --live` | `protocol.rs` (WebSocket protocol v1: channels, ports, origin/host checks), `op.rs` (`Op`), `apply.rs` (`apply`: one attributed commit per agent op), `fit.rs` (agent text fitted inside the page), `progress.rs` (`show_progress` working cards), `attribution.rs`, `sync` |
| `crates/rupok-render` | wgpu ink renderer | `InkRenderer` (SDF capsules, chunk culling, cached dry layer, wet layer), `Camera`, `Gpu::headless`, `ink.wgsl` |
| `crates/rupok-wasm` | Board engine and wasm-bindgen API | `engine.rs` (`Engine`: tools, gestures, selection), `lib.rs` (`Board` JS API), `replay.rs`, `shapes.rs` |
| `crates/rupok-cli` | `rupok` binary: CLI and MCP server | `cli.rs` (clap), `ops.rs` (shared operations), `mcp.rs` + `tools.rs` (15 MCP tools), `workspace.rs` (path sandbox), `spec.rs`, `live/` (`LiveHub`: loopback WebSocket, pairing, Loro mirror) + `mcp_live.rs` (live tools; docs/ai-agents.md), `chat/` (`rupok agent`: ACP client relaying the in-app chat) + `mcp_http.rs` (MCP over loopback HTTP for it) |
| `crates/rupok-cli` | `rupok` binary: CLI and MCP server | `cli.rs` (clap), `ops.rs` (shared operations), `mcp.rs` + `tools.rs` (15 MCP tools), `workspace.rs` (path sandbox), `spec.rs`, `live/` (`LiveHub`: loopback WebSocket, pairing, Loro mirror) + `mcp_live.rs` + `mcp_progress.rs` (live tools; docs/ai-agents.md), `chat/` (`rupok agent`: ACP client relaying the in-app chat) + `mcp_http.rs` (MCP over loopback HTTP for it) |
| `bench/` | Performance harness and budgets | `cargo run -p rupok-bench --release [-- --check]` |
| `apps/board` | SolidJS board UI (Vite) | `controller.ts`, `objects.ts` (Smart Object host), `media/` + `components/Media*.tsx` (YouTube, video, audio, web embeds), `pdf.ts`, `storage.ts`, `live.ts` + `snapshot.ts` + `components/LivePanel.tsx` (Connect AI), `chat.ts` + `components/ChatPanel.tsx` + `markdown.ts` (AI chat), `components/` |
| `apps/board` | SolidJS board UI (Vite) | `controller.ts`, `objects.ts` (Smart Object host), `media/` + `components/Media*.tsx` (YouTube, video, audio, web embeds), `pdf.ts`, `storage.ts`, `live.ts` + `snapshot.ts` + `components/LivePanel.tsx` (Connect AI), `chat.ts` + `components/ChatPanel.tsx` + `markdown.ts` (AI chat), `aiAction/` (AI in action: working cards, class mode, live solve, students ask), `components/` |
| `packages/object-sdk` | In-object SDK, `window.rupok` (Apache-2.0) | `sdk.js` (ES2019 IIFE), `index.d.ts`, `test/` |
| `spec/` | Normative specs (Apache-2.0) | `rupok-format.md`, `smart-object.md` |
| `examples/objects/` | Validated example Smart Objects | checked by `crates/rupok-format/tests/examples.rs` |
Expand Down
5 changes: 5 additions & 0 deletions apps/board/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import { overlayRole } from "./overlay/role";
import { registerSettingsOpener } from "./components/ToText";
import LivePanel from "./components/LivePanel";
import ChatPanel from "./components/ChatPanel";
import AiActionLayer from "./aiAction/AiActionLayer";
import { initAiAction } from "./aiAction";
import VoiceLayer from "./voice/VoiceLayer";
import { LibraryRoot } from "./components/Library";
import { UpgradeHost } from "./components/Billing";
Expand Down Expand Up @@ -111,6 +113,7 @@ export default function App() {
setReady(true);
startUpdateChecks(); // desktop: new release; web: offline service worker, new build
void import("./solve").then((m) => m.initSolve()); // Solve this: AI handwriting, preview, reveal
initAiAction(controller); // AI in action: working cards, class mode, live solve, students ask
startLibrary(controller); // the Library home and saving lessons to their files (before files below arrive)
// Back from a payment page (?billing=…) or sent by the pricing page (?upgrade=pro).
const billingParams = takeBillingParams();
Expand Down Expand Up @@ -179,6 +182,8 @@ export default function App() {
<LivePanel />
{/* AI chat with the teacher's own agent (chat.ts, `rupok agent`). */}
<ChatPanel />
{/* AI in action: working cards, Undo toasts, students' own layer (aiAction/). */}
<AiActionLayer />
<VoiceLayer />
<LibraryRoot />
<UpdateNotice />
Expand Down
251 changes: 251 additions & 0 deletions apps/board/src/aiAction/AiActionLayer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,251 @@
// The "AI in action" layer over the board: working cards where results will
// land, the sparkle when they do, the class-mode Undo toast and destructive
// confirmations, and the students' "Ask AI" box and own layer.

import { For, Show, createEffect, createSignal, on, onCleanup } from "solid-js";
import { camera, isView, mode, pageIndex } from "../state";
import { controller } from "../controller";
import { liveHasChat } from "../live";
import { renderMarkdown } from "../markdown";
import { Icon } from "../components/Icon";
import { cancelCard, removeCard, retryCard } from "./progress";
import { aiToast, cards, confirmReq, setAiToast, sparkle, type Card } from "./state";
import { askOpen, asksLeft, clearStudentLayer, setAskOpen, studentAsk, studentLayer, studentsMayAsk } from "./student";
import "./aiAction.css";

/** Slide px → screen px on the board. */
function screen(r: { x: number; y: number; w: number; h: number }) {
const [cx, cy, z] = camera();
return { left: (r.x - cx) * z, top: (r.y - cy) * z, width: r.w * z, height: r.h * z };
}

const KIND_ICON: Record<Card["kind"], string> = { object: "smartink", handwriting: "pen", text: "text", shape: "rect", other: "smartink" };

function Preview(props: { html: string }) {
let frame!: HTMLIFrameElement;
// Re-render when the agent sends a new partial object (debounced a little).
let t: number | undefined;
createEffect(on(() => props.html, (h) => {
clearTimeout(t);
t = window.setTimeout(() => { if (frame) frame.srcdoc = controller.objects.wrap(h); }, 150);
}));
onCleanup(() => clearTimeout(t));
return (
<div class="aia-preview" aria-label="Live preview">
<iframe ref={frame} title="Live preview" sandbox="allow-scripts" referrerpolicy="no-referrer" tabindex={-1} />
<span class="aia-preview-tag">Live preview</span>
</div>
);
}

function ProgressCard(props: { card: Card }) {
const c = () => props.card;
const box = () => {
const s = screen(c().rect);
// Readable even when the target is small (a line of handwriting).
const minW = mode() === "teach" ? 460 : 340, minH = mode() === "teach" ? 150 : 112;
return { ...s, width: Math.max(s.width, minW), height: Math.max(s.height, minH) };
};
const big = () => box().height > 280 && box().width > 480;
return (
<div
class="aia-card"
classList={{ big: big(), landing: c().state === "landing", failed: c().state === "failed", done: c().state === "done", [`k-${c().kind}`]: true }}
style={{ left: `${box().left}px`, top: `${box().top}px`, width: `${box().width}px`, height: `${box().height}px` }}
role="status"
aria-live="polite"
data-card={c().id}
>
<svg class="aia-outline" aria-hidden="true"><rect x="1.5" y="1.5" rx="18" ry="18" /></svg>
<div class="aia-body">
<div class="aia-head">
<span class="aia-agent"><Icon name={KIND_ICON[c().kind] as any} size={16} />{c().agent}</span>
<Show when={c().title}><span class="aia-title">{c().title}</span></Show>
<button class="aia-x" onClick={() => cancelCard(c().id)} aria-label="Cancel" title="Stop"><Icon name="close" size={16} /></button>
</div>
<div class="aia-step">
<Show when={c().state === "working"}><span class="aia-dots" aria-hidden="true"><i /><i /><i /></span></Show>
<span>{c().state === "failed" ? "Not quite yet" : c().step}</span>
</div>
<Show when={c().state === "failed"}>
<p class="aia-error">{c().error ?? "It did not work this time."}</p>
<div class="aia-row">
<button class="aia-btn solid" onClick={() => retryCard(c().id)}>Try again</button>
<button class="aia-btn" onClick={() => removeCard(c().id)}>Dismiss</button>
</div>
</Show>
<Show when={c().state === "working" && c().error}>
<p class="aia-note">{c().error}</p>
</Show>
<Show when={big() && c().plan.length}>
<ul class="aia-plan">
<For each={c().plan}>
{(e) => <li classList={{ done: e.status === "completed", now: e.status === "in_progress" }}><span class="aia-tick" aria-hidden="true" />{e.content}</li>}
</For>
</ul>
</Show>
<Show when={big() && c().preview}><Preview html={c().preview!} /></Show>
<Show when={c().percent != null}>
<div class="aia-bar" role="progressbar" aria-valuenow={c().percent} aria-valuemin={0} aria-valuemax={100}><span style={{ width: `${c().percent}%` }} /></div>
</Show>
</div>
</div>
);
}

/** Cards working on another page: a chip that shows it. */
function Elsewhere(props: { card: Card }) {
return (
<button class="aia-elsewhere" onClick={() => { controller.board.goto_page(props.card.page - 1); controller.sync(true); }}>
<span class="aia-dots" aria-hidden="true"><i /><i /><i /></span>
{props.card.agent}: {props.card.step} <b>Page {props.card.page} →</b>
</button>
);
}

function Sparkle() {
const [shown, setShown] = createSignal<{ left: number; top: number; n: number } | null>(null);
let t: number | undefined;
createEffect(on(sparkle, (s) => {
if (!s || s.page !== pageIndex() + 1) return;
const p = screen({ x: s.x, y: s.y, w: 0, h: 0 });
setShown({ left: p.left, top: p.top, n: s.n });
clearTimeout(t);
t = window.setTimeout(() => setShown(null), 1100);
}, { defer: true }));
onCleanup(() => clearTimeout(t));
return (
<Show when={shown()} keyed>
{(s) => (
<div class="aia-sparkle" style={{ left: `${s.left}px`, top: `${s.top}px` }} aria-hidden="true">
<span class="ring" />
<For each={[0, 1, 2, 3, 4, 5, 6, 7]}>{(i) => <span class="star" style={{ "--a": `${i * 45 + 20}deg` } as any} />}</For>
</div>
)}
</Show>
);
}

function Toast() {
// Every toast goes by itself after a while (Undo stays on the AI button).
let t: number | undefined;
createEffect(on(aiToast, (x) => {
clearTimeout(t);
if (x) t = window.setTimeout(() => setAiToast((cur) => (cur?.id === x.id ? null : cur)), 7000);
}));
onCleanup(() => clearTimeout(t));
return (
<Show when={aiToast() && !isView() ? aiToast() : null} keyed>
{(t) => (
<div class="aia-toast" role="status">
<span class="aia-toast-dot" aria-hidden="true" />
<span><b>{t.agent}</b> {t.label}</span>
<Show when={t.undo}><button class="aia-btn solid" onClick={() => t.undo?.()}>Undo</button></Show>
<button class="aia-x" onClick={() => setAiToast(null)} aria-label="Dismiss"><Icon name="close" size={16} /></button>
</div>
)}
</Show>
);
}

function Confirm() {
return (
<Show when={confirmReq()} keyed>
{(r) => (
<div class="aia-confirm surface" role="alertdialog" aria-label="The AI asks to make a change">
<p class="aia-confirm-q"><b>{r.agent}</b> wants to {r.label}.</p>
<Show when={r.detail}><p class="aia-confirm-d">{r.detail}</p></Show>
<div class="aia-row">
<button class="aia-btn solid" onClick={() => r.answer(true)}>Allow</button>
<button class="aia-btn" onClick={() => r.answer(false)}>Don't allow</button>
</div>
</div>
)}
</Show>
);
}

function StudentLayer() {
return (
<For each={studentLayer().filter((i) => i.page === pageIndex() + 1)}>
{(it) => {
const box = () => screen(it.rect);
return (
<div class="aia-mine" style={{ left: `${box().left}px`, top: `${box().top}px`, width: `${box().width}px`, height: `${box().height}px` }}>
<span class="aia-mine-tag">Only you see this</span>
<Show when={it.kind === "object"} fallback={<div class="aia-mine-text" innerHTML={renderMarkdown((it.lines ?? []).join("\n\n"))} />}>
<iframe title={it.title} sandbox="allow-scripts" referrerpolicy="no-referrer" srcdoc={controller.objects.wrap(it.html ?? "")} />
</Show>
</div>
);
}}
</For>
);
}

function StudentAsk() {
const [q, setQ] = createSignal("");
const [msg, setMsg] = createSignal<string | null>(null);
const left = () => asksLeft();
const send = (e?: Event) => {
e?.preventDefault();
const r = studentAsk(q());
if (r === "sent") { setQ(""); setMsg("Asked! Watch the board."); setAskOpen(false); }
else if (r === "limit") setMsg(`That's all your asks for now. More in ${left().resetMin} min.`);
else if (r === "noagent") setMsg(null);
};
return (
<Show when={studentsMayAsk()}>
<div class="aia-ask">
<Show when={askOpen()} fallback={
<button class="aia-ask-chip surface" onClick={() => { setMsg(null); setAskOpen(true); }}>
<Icon name="smartink" size={18} /> Ask AI to show me
<span class="aia-ask-left" title="Asks left in the next 10 minutes">{left().left}/{left().limit}</span>
</button>
}>
<form class="aia-ask-box surface" onSubmit={send}>
<div class="aia-ask-head">
<b>What should the AI show you?</b>
<button type="button" class="aia-x" onClick={() => setAskOpen(false)} aria-label="Close"><Icon name="close" size={16} /></button>
</div>
<Show when={liveHasChat()} fallback={
<p class="aia-ask-help">
No AI is connected to this board. Ask your teacher to connect Rupok's AI, or open Rupok on your own
computer with your own AI assistant and ask it there.
</p>
}>
<input class="aia-ask-input" value={q()} onInput={(e) => setQ(e.currentTarget.value)} maxlength={300}
placeholder="e.g. a 3D model of a water molecule" aria-label="Your question" autofocus />
<div class="aia-row">
<button class="aia-btn solid" type="submit" disabled={!q().trim() || left().left <= 0}>Show me</button>
<span class="aia-ask-left">{left().left} of {left().limit} asks left</span>
<Show when={studentLayer().length}><button type="button" class="aia-btn" onClick={clearStudentLayer}>Clear mine</button></Show>
</div>
</Show>
<Show when={msg()}><p class="aia-ask-help" role="status">{msg()}</p></Show>
</form>
</Show>
</div>
</Show>
);
}

export default function AiActionLayer() {
const here = () => cards.list.filter((c) => c.page === pageIndex() + 1);
const away = () => cards.list.filter((c) => c.page !== pageIndex() + 1 && c.state === "working").slice(-1);
return (
<>
<div class="aia-layer" classList={{ teach: mode() === "teach" }}>
<For each={here()}>{(c) => <ProgressCard card={c} />}</For>
<Show when={isView()}><StudentLayer /></Show>
<Sparkle />
</div>
<div class="aia-float" classList={{ teach: mode() === "teach" }}>
<For each={away()}>{(c) => <Elsewhere card={c} />}</For>
<Toast />
</div>
<Confirm />
<StudentAsk />
</>
);
}
Loading
Loading