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
19 changes: 18 additions & 1 deletion apps/tui/src/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
jobTimesDir,
probeLatest,
probeLogs,
probeStatus,
probeMessages, probeStatus,
probeVersion,
probeWorker,
readJobTimes,
Expand Down Expand Up @@ -89,6 +89,7 @@ export class Controller {
void this.refreshLogs();
void this.refreshVersion();
void this.refreshNetwork();
void this.refreshMessages();
}, 0);
const every = (ms: number, fn: () => void) => {
const t = setInterval(fn, ms);
Expand All @@ -104,6 +105,7 @@ export class Controller {
every(3000, () => this.refreshWorker());
every(6000, () => this.state.tab === "node" && void this.refreshLogs());
every(30_000, () => void this.refreshStatus());
every(5 * 60_000, () => void this.refreshMessages());
every(30_000, () => (this.state.tab === "network" ? void this.refreshNetwork() : undefined));
every(120_000, () => (this.state.tab !== "network" ? void this.refreshNetwork() : undefined));
every(60_000, () => void this.refreshAccount());
Expand Down Expand Up @@ -185,6 +187,16 @@ export class Controller {
});
}

/** Messages people sent to this node (`c0mpute dm read --json`). */
refreshMessages(): Promise<void> {
return this.once("messages", async () => {
const messages = await probeMessages(c0mputeBin());
const before = this.state.node.messages?.total ?? 0;
this.set({ node: { ...this.state.node, messages } });
if (messages.total > before && before > 0) this.toast(`${messages.total - before} new message(s) for this node: m shows them`);
});
}

refreshVersion(): Promise<void> {
return this.once("version", async () => {
const bin = c0mputeBin();
Expand Down Expand Up @@ -783,6 +795,11 @@ export class Controller {
this.set({ nodePanel: this.state.nodePanel === "bench" ? "roles" : "bench" });
}

toggleMessages(): void {
this.set({ nodePanel: this.state.nodePanel === "messages" ? "roles" : "messages" });
if (this.state.nodePanel === "messages") void this.refreshMessages();
}

scrollNode(delta: number): void {
this.set({ nodeScroll: Math.max(0, this.state.nodeScroll + delta) });
}
Expand Down
10 changes: 10 additions & 0 deletions apps/tui/src/demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,16 @@ export function demoState(): AppState {
{ time: "11:59:40", level: "WARN", message: "c0mpute_core::diffusion: load gate: not bidding on diffusion.txt2img" },
],
logSource: "journalctl -u c0mpute-worker",
messages: {
address: "4f1c9a2e7b3d5c8f0a6e2b4d9c1f7a3e5b8d0c2f4a6e8b1d3f5a7c9e2b4d6f8a",
total: 2,
fresh: 1,
messages: [
{ id: "m1", from: "9a1b", name: "9a1b2c3d", text: "Hi! Your node is fast on qwen2.5:7b, thanks for running it.", created_at: Math.floor(NOW / 1000) - 7200, via: "mailbox" },
{ id: "m2", from: "c0ff", name: "riotcoder", text: "Your node fails most inference jobs: the buyer cannot reach it. Is outbound TCP blocked?", created_at: Math.floor(NOW / 1000) - 300, via: "direct" },
],
error: null,
},
},
net: {
status: {
Expand Down
2 changes: 2 additions & 0 deletions apps/tui/src/keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ export function handleKey(ctl: Controller, e: KeyEvent): "quit" | void {
void ctl.refreshStatus();
void ctl.refreshLogs();
void ctl.refreshVersion();
void ctl.refreshMessages();
ctl.toast("re-checking the node (c0mpute status --json)…");
} else if (is(e, "b")) ctl.toggleBench();
else if (is(e, "m")) ctl.toggleMessages();
else if (is(e, "up", "k")) ctl.scrollNode(-1);
else if (is(e, "down", "j")) ctl.scrollNode(1);
else if (is(e, "pageup")) ctl.scrollNode(-10);
Expand Down
45 changes: 45 additions & 0 deletions apps/tui/src/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,50 @@ export interface NodeSnapshot {
jobTimes: JobTime[];
logs: LogLine[];
logSource: string;
/** Messages people sent to this node (`c0mpute dm read --json`). */
messages: NodeMessages | null;
}

/** One message sent to this node. */
export interface NodeMessage {
id: string;
from: string;
name: string;
text: string;
created_at: number;
via: string;
}

/** `c0mpute dm read --json`: messages people sent to this node with `c0mpute dm send <node>`. */
export interface NodeMessages {
address: string | null;
total: number;
fresh: number;
messages: NodeMessage[];
error: string | null;
}

export function parseMessagesJson(text: string): NodeMessages | null {
try {
const v = JSON.parse(text.trim().split("\n").filter((l) => l.startsWith("{")).pop() ?? "") as {
address?: string; total?: number; new?: number; messages?: NodeMessage[];
};
if (!v || !Array.isArray(v.messages)) return null;
return { address: v.address ?? null, total: v.total ?? v.messages.length, fresh: v.new ?? 0, messages: v.messages, error: null };
} catch {
return null;
}
}

export async function probeMessages(bin: string): Promise<NodeMessages> {
const r = await run(bin, ["dm", "read", "--json", "--limit", "30"], 60_000);
const parsed = r.code === 0 ? parseMessagesJson(r.stdout) : null;
if (parsed) return parsed;
const last = (r.stderr || r.stdout || "").trim().split("\n").slice(-1)[0] ?? "";
const error = /unrecognized subcommand|unexpected argument/.test(r.stderr)
? "this c0mpute is older than 0.3.74: c0mpute update adds node messages"
: last || "c0mpute dm read failed";
return { address: null, total: 0, fresh: 0, messages: [], error };
}

export function emptyNode(cliPath = "c0mpute"): NodeSnapshot {
Expand All @@ -329,6 +373,7 @@ export function emptyNode(cliPath = "c0mpute"): NodeSnapshot {
jobTimes: [],
logs: [],
logSource: "",
messages: null,
};
}

Expand Down
2 changes: 1 addition & 1 deletion apps/tui/src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export interface AppState {
jobSel: number;
node: NodeSnapshot;
bench: BenchState;
nodePanel: "roles" | "bench";
nodePanel: "roles" | "bench" | "messages";
nodeScroll: number;
net: { status: Loadable<StatusPayload>; nodes: Loadable<NodesPayload>; pricing: Loadable<PricingPayload> };
netPanel: "nodes" | "prices";
Expand Down
1 change: 1 addition & 0 deletions apps/tui/src/views/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export function tabKeys(state: AppState): { key: string; label: string }[] {
return [
{ key: "r", label: "re-check" },
{ key: "b", label: state.nodePanel === "bench" ? "roles" : "bench" },
{ key: "m", label: state.nodePanel === "messages" ? "roles" : "messages" },
{ key: "↑↓", label: "scroll" },
];
case "network":
Expand Down
45 changes: 44 additions & 1 deletion apps/tui/src/views/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ export function summaryRows(node: NodeSnapshot, state: AppState, theme: Theme):
rows.push({ label: "earned", value: `$${Number(me.balance.earned_spendable_usd).toFixed(4)} spendable from your nodes · balance $${Number(me.balance.spendable_usd).toFixed(2)}`, color: theme.accent });
}
const b = state.bench.bench;
const msgs = node.messages;
rows.push(
!msgs
? { label: "messages", value: "checking…", color: theme.muted }
: msgs.error
? { label: "messages", value: msgs.error, color: theme.muted }
: msgs.total === 0
? { label: "messages", value: "none yet · people reach you with c0mpute dm send <node-id>", color: theme.muted }
: { label: "messages", value: `${msgs.total}${msgs.fresh ? ` (${msgs.fresh} new)` : ""} · latest from ${msgs.messages[msgs.messages.length - 1]?.name ?? "?"} · m shows them`, color: theme.accent },
);
rows.push({ label: "bench", value: b ? `score ${b.score.toLocaleString("en-US")}${b.metadata.quick ? " (quick run, not advertised)" : ""} · b shows it` : "no score: c0mpute bench", color: b ? theme.accent : theme.muted });
return rows;
}
Expand Down Expand Up @@ -112,6 +122,38 @@ export function roleLines(node: NodeSnapshot, width: number, theme: Theme): Line
return out;
}

/** Messages people sent to this node, newest last (`c0mpute dm read`). */
export function messageLines(node: NodeSnapshot, width: number, theme: Theme, now: number): Line[] {
const m = node.messages;
if (!m) return [{ text: "asking c0mpute dm read…", fg: theme.muted }];
if (m.error) return wrapBlock(m.error, width, "").map((t) => ({ text: t, fg: theme.warning }));
const out: Line[] = [];
if (m.address) out.push({ text: `this node's DM address ${m.address.slice(0, 16)}…`, fg: theme.muted });
if (!m.messages.length) {
out.push({ text: "" });
for (const t of wrapBlock("No messages yet. Anyone can message whoever runs this node with `c0mpute dm send <node-id> \"...\"`; a contact email (`c0mpute contact <email>`) shows on c0mpute.com/nodes too.", width, ""))
out.push({ text: t, fg: theme.muted });
return out;
}
for (const msg of m.messages) {
out.push({ text: "" });
const age = Math.max(0, Math.floor(now / 1000) - msg.created_at);
out.push({ text: `${msg.name} · ${duration(age)} ago · ${msg.via}`, fg: theme.accent, bold: true });
for (const t of wrapBlock(msg.text, width, " ")) out.push({ text: t, fg: theme.foreground });
}
out.push({ text: "" });
out.push({ text: "reply: c0mpute dm send <their address> \"...\" · r refreshes · m goes back", fg: theme.muted });
return out;
}

function messagesPanel(parent: Container, state: AppState, theme: Theme): void {
panel(parent, theme, "Messages", { subtitle: "m: back · r: refresh" }, (p) => {
p.draw((surface) => {
drawLines(surface, messageLines(state.node, surface.width - 1, theme, state.now), state.nodeScroll, theme, true);
});
});
}

function benchPanel(parent: Container, state: AppState, theme: Theme): void {
const report = state.bench.bench;
panel(
Expand Down Expand Up @@ -182,7 +224,8 @@ export function renderNode(ui: Container, state: AppState, theme: Theme, h: Node
});
const roles = (parent: Container) => {
if (state.nodePanel === "bench") return benchPanel(parent, state, theme);
panel(parent, theme, "Roles", { subtitle: "b: bench" }, (p) => {
if (state.nodePanel === "messages") return messagesPanel(parent, state, theme);
panel(parent, theme, "Roles", { subtitle: "b: bench · m: messages" }, (p) => {
p.draw((surface) => {
drawLines(surface, roleLines(node, surface.width - 1, theme), state.nodeScroll, theme, false);
p.ctx.hit({ rect: surface.hitRect(), onScroll: (d) => h.onScrollRoles?.(d * 2) });
Expand Down
17 changes: 17 additions & 0 deletions apps/web/src/app/nodes/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,16 @@ export default async function NodesPage() {
<td className="py-2 pr-3">
{n.name ? <span className="accent font-bold">{n.name}</span> : <span className="text-[var(--color-dim)]">unnamed</span>}
<span className="block font-mono text-[var(--color-dim)]">{n.id}</span>
{n.contact && /^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z0-9-]+$/.test(n.contact) && (
<a href={`mailto:${n.contact}`} className="block text-[var(--color-dim)] !border-0" title="The operator's contact for questions about this node">
{n.contact}
</a>
)}
{n.dm && (
<span className="block font-mono text-[var(--color-dim)]" title="Message whoever runs this node (end-to-end encrypted)">
c0mpute dm send {n.id} &quot;…&quot;
</span>
)}
{n.donates?.includes("crowdgpt") && (
<Link href="/plugins#crowdgpt" className="block text-[var(--color-dim)] !border-0" title="Donates idle compute to CrowdGPT when it has no paid work">
donates idle to CrowdGPT
Expand Down Expand Up @@ -279,6 +289,13 @@ $ c0mpute name # check what is set`}</CodeBlock>
who gets paid: earnings go to the payout address set on the node
(<code>infernet payout set</code>), never to a name. Needs c0mpute 0.2.64 or newer (<code>c0mpute update</code>).
</p>
<p className="text-sm leading-7" id="contact">
Add a contact email too, so people who use your node (and the
network&apos;s maintainers, if it starts failing jobs) can reach you.
It is optional and shown publicly under your node&apos;s name:
</p>
<CodeBlock>{`$ c0mpute contact ops@example.com # set it, then restart the worker
$ curl -fsSL https://c0mpute.com/install.sh | sh -s -- --contact ops@example.com`}</CodeBlock>
{p.operators.length > 0 && (
<table id="operators" className="w-full text-left border-collapse text-xs">
<thead className="text-[var(--color-dim)]">
Expand Down
8 changes: 8 additions & 0 deletions apps/web/src/lib/nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ export interface NodeRow {
ref: string | null;
/** The operator's nickname (`c0mpute name`); absent on nodes older than 0.2.64. */
name?: string | null;
/**
* The email the operator offers for questions about this node (`c0mpute
* contact`), public by their choice; the aggregator passes only plain
* addresses. Absent when unset and on nodes older than 0.3.74.
*/
contact?: string | null;
/** The node's secure-chat address: message whoever runs it with `c0mpute dm send <id>` (0.3.74+). */
dm?: string | null;
/** The operator's listing; absent on nodes older than 0.2.35. */
pricing?: Pricing | null;
/**
Expand Down
Loading