Something went wrong. Try again.
small gleam coding and persistent agent daemon with a detachable cli and a canvas ui forked from okami.mom/albedo
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208"""Canned replies for a UI review of the web client, served by fake_provider.py.
The last user message picks one by keyword: d3, hostile, hang, slow, fail, tool, edit,make an artifact, think, code, table, long. Anything else gets a short markdown answer.
python3 test/e2e/fake_provider.py test/manual/ux/replies.py"""
from fake_provider import Reply, error, python, text
MD = """## what i found
The **tiled board** keeps every window mounted, and a move only changes *where* it shows.
- splits hold any tile: a window, tabs, a canvas- a `section` is a tile with a name - unnamed ones stay plain - named ones get a slim header- notes tie to a passage and follow it
> a quote, to see how block quotes sit next to lists
1. first2. second, with a [link](https://example.com) and `inline code`3. third
That's the short version (\u30fb\u03c9\u30fb)"""
CODE = """Here's the helper in three languages.
```tsexport function clamp(value: number, low: number, high: number): number { return Math.min(Math.max(value, low), high);}```
```pythondef clamp(value, low, high): return min(max(value, low), high)```
```gleampub fn clamp(value: Int, low: Int, high: Int) -> Int { int.min(int.max(value, low), high)}```
And one very long line, to see how wide code scrolls:
```tsconst veryLongIdentifierName = someFunction(argumentOne, argumentTwo, argumentThree, argumentFour, argumentFive);```"""
WRAP = "a longer note that wraps across the cell "TABLE = "| file | added | removed | note |\n|---|---:|---:|---|\n" + "\n".join( f"| web/src/lib/tiles/file{i}.ts | {7 * i} | {3 * i} | {WRAP * (1 + i % 3)}|" for i in range(1, 9))
PARAGRAPH = ( "This paragraph is here to make the chat long, so passages can scroll far " "out of sight and notes on them pile up at the edge. ") * 4
def long_text(parts: int) -> str: return "\n\n".join(f"### part {i}\n\n{PARAGRAPH}" for i in range(1, parts + 1))
TOOL = """import platformfor i in range(3): print('step', i, platform.system())"""
JOBS = """quiet = run("sleep", "600")chatty = run("python3", "-u", "-c", "import time\\nfor i in range(600): print(i); time.sleep(1)")done = run("echo", "done")print(await done.text()) # read, so its end does not wake the session"""
AGENTS = """model = (await agents.models())[0]for task, name in [("hi", "resting"), ("hang please", "working")]: await agents.self.spawn(task, name=name, model=model)done = await agents.self.spawn("hi", name="closed", model=model)await done.close()print('started 3 agents, closed one')"""
ARTIFACT = """page = '<h1 style="font-family: system-ui">a page from the fake model</h1>'made = await artifacts.create("fake page", page)await artifacts.update(made["id"], page.replace("page", "second page"))print("made", made["id"])"""
SCROLL_ARTIFACT = """page = '<!doctype html><meta name="viewport" content="width=device-width,initial-scale=1"><body style="margin:24px;font:16px system-ui;background:var(--albedo-bg);color:var(--albedo-text)"><h1>Touch scrolling</h1>'page += ''.join(f'<p>Scrollable row {n}</p>' for n in range(100))page += '<p id="end">End of the artifact</p></body>'made = await artifacts.create("scrollable page", page)print("made", made["id"])"""
EDIT = """from pathlib import PathPath('notes.md').write_text('# notes\\n\\nwritten by the fake model\\n')Path('src/app.ts').write_text(Path('src/app.ts').read_text().replace('hello', 'hello, board'))print('edited 2 files')"""
ARTIFACT_D3 = """page = \'\'\'<!doctype html><meta charset="utf-8"><body style="font-family: system-ui; margin: 16px"><h3>d3 from a CDN</h3><svg id="chart" width="320" height="120"></svg><p id="api">asking /api…</p><script src="https://cdn.jsdelivr.net/npm/d3@7"></script><script>const data = [4, 8, 15, 16, 23, 42];d3.select("#chart").selectAll("rect").data(data).join("rect") .attr("x", (d, i) => i * 52).attr("y", (d) => 120 - d * 2.5) .attr("width", 44).attr("height", (d) => d * 2.5).attr("fill", "#6928bd");const say = (text) => (document.getElementById("api").textContent = text);fetch("/api/sessions", { credentials: "include" }) .then((r) => say("/api answered " + r.status)) .catch((e) => say("/api refused: " + e.message));</script>\'\'\'made = await artifacts.create("d3 page", page)print("made", made["id"])"""
HOSTILE = """## hostile content, as a fetched page could carry it
Every payload below tries to set `window.__pwned`. A safe client shows them as text.
<img src=x onerror="window.__pwned='img onerror'"><svg><animate onbegin="window.__pwned='svg onbegin'" attributeName=x dur=1s><a href="javascript:window.__pwned='raw link'">raw link</a>
[markdown link](javascript:window.__pwned='md%20link') and 
<details open ontoggle="window.__pwned='details ontoggle'">x</details>
| cell ||---|| <img src=x onerror="window.__pwned='table img'"> |
Maths still draws: $e^{i\\pi} + 1 = 0$, and a diagram:
```mermaidgraph TD A["<img src=x onerror=window.__pwned='diagram label'>"] --> B{choice} B --> C((done))```
and one whose labels hold angle brackets on purpose:
```mermaidgraph LR V["Vec<String>"] --> R["Result<T, E>"] R --> L["a < b"]```
```tsconst safe = "code blocks still highlight and copy";```"""
def last_user_text(request: dict) -> str: for message in reversed(request.get("messages", [])): if message.get("role") == "user": content = message.get("content") if isinstance(content, list): content = " ".join( part.get("text", "") for part in content if isinstance(part, dict) ) return content or "" return ""
def script(request: dict) -> Reply: messages = request.get("messages", []) if messages and messages[-1].get("role") == "tool": return text("Done: the cell ran, its output is above.\n\n" + MD) ask = last_user_text(request).lower() if "d3" in ask: return python(ARTIFACT_D3) if "hostile" in ask: return text(HOSTILE) if "hang" in ask: return text("", hang=True) if "slow" in ask: # about twenty seconds of streaming, ending on a whole paragraph return text(long_text(3), delay=0.15) if "fail" in ask: return error(500, "the fake model failed on purpose") if "tool" in ask: return python(TOOL) if "start jobs" in ask: return python(JOBS) if "start agents" in ask: return python(AGENTS) if "scrollable artifact" in ask: return python(SCROLL_ARTIFACT) if "make an artifact" in ask: return python(ARTIFACT) if "edit" in ask: return python(EDIT) if "think" in ask: return text( MD, reasoning="Let me think about which tile this belongs in. " * 20 ) if "code" in ask: return text(CODE) if "table" in ask: return text(TABLE) if "long" in ask: return text(long_text(30)) return text(MD)