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
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ a Tauri 2 shell (planned). Status: Phase 0, pre-alpha. See
| `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) |
| `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), `voice/` (dictation; `board.ts` + `VoiceBoard.tsx`: Voice on the board), `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
24 changes: 24 additions & 0 deletions apps/board/scripts/gen-icons.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,23 @@ function body(name) {
return null;
}

// Composed icons: a Solar icon made smaller in the top-left corner, with a
// mark drawn in the free bottom-right corner (same stroke as the variant).
// voiceText: the Voice text tool (src/voice/board.ts), a mic with a T.
const COMPOSE = {
voiceText: { base: "microphone", mark: "M14.5 15H21.5M18 15V21.5" },
};
const STROKED = new Set(["linear", "line-duotone", "broken"]);

function compose({ base, mark }, v) {
const k = 0.74;
let b = body(`${base}-${v}`);
// Keep the stroke width the eye expects after scaling down.
if (STROKED.has(v)) b = b.replace(/stroke-width="1\.5"/g, `stroke-width="${(1.5 / k).toFixed(2)}"`);
const w = STROKED.has(v) ? 1.5 : 2;
return `<g transform="translate(0.4 0.2) scale(${k})">${b}</g><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-width="${w}" d="${mark}"/>`;
}

const out = {};
const missing = [];
for (const [logical, candidates] of Object.entries(MAP)) {
Expand All @@ -103,6 +120,13 @@ for (const [logical, candidates] of Object.entries(MAP)) {
}
out[logical] = Object.fromEntries(VARIANTS.map((v) => [v, body(`${base}-${v}`)]));
}
for (const [logical, spec] of Object.entries(COMPOSE)) {
if (!VARIANTS.every((v) => body(`${spec.base}-${v}`))) {
missing.push(logical);
continue;
}
out[logical] = Object.fromEntries(VARIANTS.map((v) => [v, compose(spec, v)]));
}
if (missing.length) {
console.error("missing icons:", missing.join(", "));
process.exit(1);
Expand Down
3 changes: 3 additions & 0 deletions apps/board/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { registerSettingsOpener } from "./components/ToText";
import LivePanel from "./components/LivePanel";
import ChatPanel from "./components/ChatPanel";
import VoiceLayer from "./voice/VoiceLayer";
import VoiceBoard from "./voice/VoiceBoard";
import { LibraryRoot } from "./components/Library";
import { UpgradeHost } from "./components/Billing";
import { openUpgrade, refreshBilling, takeBillingParams } from "./cloud/billing";
Expand Down Expand Up @@ -163,6 +164,8 @@ export default function App() {
<div class="input-layer" classList={{ interact: tool() === "interact" }} ref={input} style={{ cursor: cursorFor(tool()) }} />
<div class="eraser-cursor" ref={eraser} style={{ display: "none", width: `${sizes().eraser ?? 64}px`, height: `${sizes().eraser ?? 64}px` }} />
<GestureLayer onSettings={openSettings} />
{/* Voice text: speak, and the words go on the board (voice/board.ts). */}
<Show when={ready()}><VoiceBoard /></Show>
</div>
<Show when={ready()}>
<TopBar onObject={() => setObjectDialog(true)} onSettings={() => openSettings()} />
Expand Down
15 changes: 10 additions & 5 deletions apps/board/src/components/Dock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { MarkerOpacity, SizeControl, StylePicker } from "./InkOptions";
import { StampIcon, StampsPanel } from "./Stamps";
import { brushInfo, brushOf } from "../brushes";
import { celebrate, currentStamp } from "../stamps";
import { dockClickConsumed, dockPress, dockRelease, pickVoiceTool, voiceListening } from "../voice/board";

const META = new Map(TOOLBAR_ITEMS.map((t) => [t.id, t]));
const INK_TOOLS: Tool[] = ["pen", "highlighter", "rect", "ellipse", "line", "arrow", "shape"];
Expand All @@ -62,14 +63,14 @@ type Group = "ink" | "colors" | "create" | "point" | "context" | "history" | "na
type Kind = "tool" | "colors" | "shapes" | "smartink" | "undo" | "redo" | "pager" | "replay" | "exit" | "context" | "more";
interface Entry { key: string; kind: Kind; group: Group; id?: ToolbarItem }
const GROUP: Partial<Record<ToolbarItem, Group>> = {
pen: "ink", highlighter: "ink", eraser: "ink", smartink: "create", text: "create", stamp: "create",
pen: "ink", highlighter: "ink", eraser: "ink", smartink: "create", text: "create", voice: "create", stamp: "create",
lasso: "point", laser: "point", hand: "point", interact: "point", undo: "history", redo: "history", pager: "nav", replay: "nav", exit: "exit",
};

/** On a phone, what moves into ⋯ first when the dock is too long for the
* screen ("colors:N" keeps N recent colours). Pen, eraser, the pager and ⋯
* always stay; exit and undo go last (on the narrowest phones in Teach). */
const PHONE_DROP = ["redo", "hand", "laser", "stamp", "colors:2", "lasso", "colors:1", "smartink", "interact", "replay", "text", "shapes", "highlighter", "colors:0", "exit", "undo"];
const PHONE_DROP = ["redo", "hand", "laser", "voice", "stamp", "colors:2", "lasso", "colors:1", "smartink", "interact", "replay", "text", "shapes", "highlighter", "colors:0", "exit", "undo"];
/** Phone dock metrics (Dock.css): 44px cells with no gap; a 1px separator with 1.5px margins. */
const PHONE_CELL = 44, PHONE_SEP = 4;

Expand Down Expand Up @@ -527,14 +528,18 @@ export default function Dock(props: { onSettings?: (section?: string) => void })
ref={btn}
class="tool"
data-tour={p.id === "pen" ? "pen" : undefined}
classList={{ on: on(), "has-options": options }}
title={tipOf(p.id, p.id === "stamp" ? " · tap again for all stamps" : options ? " · tap again for styles, colours and sizes" : "")}
classList={{ on: on(), "has-options": options, listening: p.id === "voice" && voiceListening() }}
title={tipOf(p.id, p.id === "stamp" ? " · tap again for all stamps" : p.id === "voice" ? " · tap the page and speak; hold to talk" : options ? " · tap again for styles, colours and sizes" : "")}
aria-label={labelOf(p.id)}
aria-pressed={on()}
aria-haspopup={options ? "dialog" : undefined}
onPointerDown={options ? lp.onPointerDown : undefined}
onPointerDown={options ? lp.onPointerDown : p.id === "voice" ? dockPress : undefined}
onPointerUp={p.id === "voice" ? dockRelease : undefined}
onPointerCancel={p.id === "voice" ? dockRelease : undefined}
onClick={() => {
if (lp.consumed()) return;
// Voice text (voice/board.ts): a hold was push-to-talk, a tap picks the tool.
if (p.id === "voice") { if (!dockClickConsumed()) { setPop(null); pickVoiceTool(); } return; }
if (options && on()) toggle(p.id as Pop["kind"], btn);
else {
setPop(null);
Expand Down
6 changes: 3 additions & 3 deletions apps/board/src/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,16 +311,16 @@ export class Controller {

setTool(t: Tool) {
// Student view: only panning and using Smart Objects.
if (isView() && t !== "interact") t = "hand";
if (isView() && t !== "interact" && t !== "voice") t = "hand";
// Leaving "use objects": take keyboard focus back from any object iframe so
// shortcuts and the clicker reach the board again.
if (t !== "interact" && document.activeElement instanceof HTMLIFrameElement) document.activeElement.blur();
setTool(t);
if (t === "interact" || t === "text" || t === "stamp") {
if (t === "interact" || t === "text" || t === "stamp" || t === "voice") {
// A just-placed object stays selected in "use objects" so it can be
// resized right away; the text tool starts fresh.
this.board.set_tool("lasso");
if (t === "text" || t === "stamp") this.board.select_json("[]");
if (t === "text" || t === "stamp" || t === "voice") this.board.select_json("[]");
} else {
this.board.set_tool(t === "shape" ? shapeToolName() : t);
}
Expand Down
4 changes: 2 additions & 2 deletions apps/board/src/icons.generated.ts

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions apps/board/src/live.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,19 @@ const LABELS: Record<string, string> = {
set_page_design: "changed the page design", set_branding: "changed the branding",
replace_items_with_text: "turned ink into text", step_object: "stepped a Smart Object",
write_handwriting: "is writing on the board", add_media: "added media", add_model: "added a 3D model",
start_voice_text: "turned on voice text", stop_voice_text: "finished voice text",
};
export const opLabel = (op: any) => LABELS[op?.op] ?? "is working";

/** Break an agent's `add_text` lines at its box width `w`, as the board will
* show them (text items keep explicit line breaks; see voice/wrap.ts). */
async function wrapForBoard(op: any): Promise<any> {
const { boardMeasure, loadBoardFont, wrapText, WRAP_SLACK } = await import("./voice/wrap");
const size = typeof op.size === "number" && op.size > 0 ? op.size : 32;
await loadBoardFont(size, op.text);
return { ...op, text: wrapText(op.text, op.w - WRAP_SLACK, boardMeasure(size)) };
}

class OpError extends Error {
constructor(message: string, public data?: any) { super(message); }
}
Expand Down Expand Up @@ -473,7 +483,10 @@ class LiveClient {
if (op.op === "snapshot") result = await renderSnapshot(this.c, op, agent);
else if (op.op === "point_at") result = this.pointAt(op);
else if (op.op === "write_handwriting") result = (await import("./solve")).onWriteOp(op, agent); // preview or write (solve/)
else if (op.op === "start_voice_text" || op.op === "stop_voice_text") result = await (await import("./voice/board")).onVoiceOp(op); // the board's microphone
else {
// `add_text` with a width: break the lines to fit it, measured with the board's font (voice/wrap.ts).
if (op.op === "add_text" && typeof op.w === "number" && op.w > 0 && typeof op.text === "string") op = await wrapForBoard(op);
try {
result = JSON.parse(this.c.board.live_apply(JSON.stringify(op), agent));
} catch (e) {
Expand Down
11 changes: 6 additions & 5 deletions apps/board/src/modes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export const TOOLBAR_ITEMS: { id: ToolbarItem; icon: IconName; label: string; ke
{ id: "text", icon: "text", label: "Text", key: "T", kind: "tool" },
{ id: "shape", icon: "rect", label: "Shapes and tables", key: "S", kind: "tool" },
{ id: "stamp", icon: "stamp", label: "Stamps", key: "K", kind: "tool" },
{ id: "voice", icon: "voiceText", label: "Voice text", kind: "tool" },
{ id: "rect", icon: "rect", label: "Rectangle", key: "R", kind: "tool" },
{ id: "ellipse", icon: "ellipse", label: "Ellipse", key: "O", kind: "tool" },
{ id: "line", icon: "line", label: "Line", key: "N", kind: "tool" },
Expand Down Expand Up @@ -108,7 +109,7 @@ export const CHROME_ITEMS: { id: ChromeKey; label: string }[] = [
export const ALLOWED_TOOLS: Record<Mode, ToolbarItem[]> = {
prepare: TOOLBAR_ITEMS.map((t) => t.id).filter((t) => t !== "exit"),
teach: TOOLBAR_ITEMS.map((t) => t.id),
view: ["pager", "hand", "interact", "replay"],
view: ["pager", "hand", "interact", "replay", "voice"],
};
/** Chrome each mode may show (the student view has no editing chrome). */
export const ALLOWED_CHROME: Record<Mode, ChromeKey[]> = {
Expand All @@ -123,13 +124,13 @@ const chrome = (on: ChromeKey[]): Record<ChromeKey, boolean> =>
export const DEFAULT_MODES: ModesConfig = {
prepare: {
chrome: chrome(["switcher", "title", "pagesToggle", "history", "insert", "replay", "open", "theme", "fullscreen", "settings", "save", "ai", "overflow", "pages", "zoom", "stats", "colors", "sizes"]),
tools: ["pen", "highlighter", "eraser", "shape", "rect", "ellipse", "line", "arrow", "smartink", "text", "stamp", "lasso", "laser", "hand", "interact", "undo", "redo"],
dock: { position: "auto", orientation: "auto", minimized: false, pinned: ["shapes", "text", "stamp", "lasso"] },
tools: ["pen", "highlighter", "eraser", "shape", "rect", "ellipse", "line", "arrow", "smartink", "text", "voice", "stamp", "lasso", "laser", "hand", "interact", "undo", "redo"],
dock: { position: "auto", orientation: "auto", minimized: false, pinned: ["shapes", "text", "voice", "stamp", "lasso"] },
},
teach: {
chrome: chrome(["colors", "sizes"]),
tools: ["pen", "highlighter", "eraser", "shape", "text", "stamp", "lasso", "laser", "smartink", "undo", "pager", "exit"],
dock: { position: "auto", orientation: "auto", minimized: false, pinned: ["shapes", "text", "stamp", "lasso", "smartink", "pager", "exit"] },
tools: ["pen", "highlighter", "eraser", "shape", "text", "voice", "stamp", "lasso", "laser", "smartink", "undo", "pager", "exit"],
dock: { position: "auto", orientation: "auto", minimized: false, pinned: ["shapes", "text", "voice", "stamp", "lasso", "smartink", "pager", "exit"] },
},
view: {
chrome: chrome(["switcher", "title", "pagesToggle", "open", "theme", "fullscreen", "overflow", "pages", "zoom"]),
Expand Down
78 changes: 78 additions & 0 deletions apps/board/src/settings/defs/voiceBoard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// Settings → General → Voice on the board (the dock's Voice text tool;
// src/voice/board.ts, VoiceBoard.tsx), and its keys under Keyboard.

import { voiceBoardPrefs } from "../../voice/board";
import { voicePrefs } from "../../voice/dictation";
import { registerSettings } from "../registry";

const d = voiceBoardPrefs.defaults;
const GROUP = "Voice on the board";
const on = () => voicePrefs.read().enabled;

registerSettings([
{
id: "general.voiceBoardMode", category: "general", group: GROUP, order: 320, type: "segmented", label: "A new voice box",
description: "Write what you say on the board, or send it to your AI assistant as a question. Switch on the box any time.",
keywords: ["voice text", "speech", "dictation", "ask AI", "prompt", "board", "ভয়েস", "বোর্ডে লিখুন"],
options: [
{ value: "text", label: "Text on the board" },
{ value: "ask", label: "Ask AI" },
],
get: () => voiceBoardPrefs.read().mode,
set: (v) => voiceBoardPrefs.write({ mode: v as typeof d.mode }),
default: d.mode,
enabled: on,
},
{
id: "general.voiceBoardTalk", category: "general", group: GROUP, order: 321, type: "segmented", label: "Talking",
description: "Tap the page and talk until you finish (holding the dock button is push-to-talk too), or listen only while the dock button, the mic or Space is held.",
keywords: ["push to talk", "hold", "toggle", "walkie-talkie", "clicker", "space"],
options: [
{ value: "toggle", label: "Tap to talk" },
{ value: "hold", label: "Hold to talk" },
],
get: () => voiceBoardPrefs.read().talk,
set: (v) => voiceBoardPrefs.write({ talk: v as typeof d.talk }),
default: d.talk,
enabled: on,
},
{
id: "general.voiceBoardStyle", category: "general", group: GROUP, order: 322, type: "toggle", label: "Write it by hand",
description: "New voice text is written in handwriting, like Solve this (English). Off: typed text you can edit.",
keywords: ["handwriting", "hand-written", "style", "typed", "হাতের লেখা"],
get: () => voiceBoardPrefs.read().style === "handwriting",
set: (v) => voiceBoardPrefs.write({ style: v ? "handwriting" : "typed" }),
default: d.style === "handwriting",
enabled: on,
},
{
id: "general.voiceBoardPause", category: "general", group: GROUP, order: 323, type: "slider", label: "New line after a pause",
description: "Stop talking this long and the next words start a new line. Saying \"new line\" (নতুন লাইন) always works.",
keywords: ["pause", "silence", "line break", "new line", "বিরতি"],
min: 0, max: 5000, step: 250,
format: (v) => (v === 0 ? "Off" : `${(v / 1000).toFixed(v % 1000 ? 2 : 0).replace(/0$/, "")} s`),
get: () => voiceBoardPrefs.read().pauseMs,
set: (v) => voiceBoardPrefs.write({ pauseMs: v }),
default: d.pauseMs,
enabled: on,
},
{
id: "general.voiceBoardStudent", category: "general", group: GROUP, order: 324, type: "toggle", label: "Students may ask the AI by voice",
description: "In Student view, the Voice text tool (when added in Teaching modes) can ask the AI. Students never write on the board.",
keywords: ["student", "student view", "allow", "ছাত্র"],
get: () => voiceBoardPrefs.read().student,
set: (v) => voiceBoardPrefs.write({ student: v }),
default: d.student,
enabled: on,
},
{
id: "keyboard.voiceBoard", category: "keyboard", group: "Editing", order: 392, type: "key", label: "Voice text: listen or pause (with the tool on; hold with Hold to talk)",
keys: ["Space", "B", "."],
keywords: ["shortcut", "voice", "clicker", "presenter", "space", "push to talk"],
},
{
id: "keyboard.voiceBoardDone", category: "keyboard", group: "Editing", order: 393, type: "key", label: "Voice text: finish the box",
keys: ["Esc"],
keywords: ["shortcut", "voice", "finish", "done"],
},
]);
2 changes: 2 additions & 0 deletions apps/board/src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { type Mode, type ModeConfig, type ModesConfig, resolveMode, sanitizeMode
export type Tool =
| "pen" | "highlighter" | "eraser" | "lasso" | "hand" | "laser" | "interact" | "text"
| "rect" | "ellipse" | "line" | "arrow" | "stamp"
/** Voice text: speak and the words go on the board (voice/board.ts). */
| "voice"
/** The Shapes picker's tool; which shape is shapes.ts `currentShape()`. */
| "shape";

Expand Down
Loading
Loading