omfp/sdk
Hooks over the daemon for widgets and window modules. Types come with the module; the protocol methods are at omfp://protocol/methods.
The widget and its state
Section titled “The widget and its state”| Export | What it gives |
|---|---|
useWidget() |
{ instance, reference, workspaceId } of the calling widget. |
useStored(key, initial) |
[value, set, loaded]: JSON state per workspace, instance and key, shared live by every window, kept across restarts. set(next | (prev) => next); set(null) deletes the key; loaded is false until it arrived (value is then initial). |
useAnswer() |
The chat card’s answer: { state, value, submit(value), cancel() } (omfp://docs/cards). |
useCommand(command) |
Registers a : command while mounted (omfp://docs/keys). |
useContextMenu({ on, items }) |
Adds context menu items while mounted (omfp://docs/keys). |
SCOPE_ATTRIBUTE |
"data-omfp-scope": put it on your root to own the commands registered with that scope. |
Calling the daemon
Section titled “Calling the daemon”| Export | What it gives |
|---|---|
useCall() |
call(method, params): any protocol method. |
useCall(method, params) |
{ data, error, refreshing, refresh }: calls on mount, when params change (compared as JSON) and on refresh(); params null calls nothing. A remount shows the last result at once with refreshing: true; a failure keeps data and sets error. |
useMethod(name) |
A function calling the workspace method name that the init file defines (ctx.methods.define). |
useJob(command, { key? }) |
A command the daemon runs for this widget instance (omfp://docs/jobs). |
useJobs(workspaceId?) |
{ jobs, error, loaded, run(name), kill(name), enable(name, enabled) }: the workspace’s declared jobs, live. |
useTerminal(command, { cwd?, cols?, rows?, key? }) |
{ id, state, status, refreshing, runs, input(data), resize(cols, rows), screen(options?), kill() }: an interactive PTY session followed by every window (omfp://docs/jobs). |
useToolRun(toolCallId | { match, threadId? }) |
A tool run of the selected thread (or the latest whose command matches): { toolCallId, toolName, status, output, lines, isError }. |
useMcp(server, { workspaceId? }) |
{ tools, error, refreshing, refresh, call(tool, args?) } of the workspace’s MCP server. |
useMcpTool(server, tool, args, { workspaceId? }) |
useCall("mcp.call", …): { data, error, refreshing, refresh }; args null calls nothing. |
mcpText(result) |
The text blocks of an MCP result, joined with newlines. |
useFile(path, { follow? }) |
{ status, file, error, refreshing, reload, save }: a file of the workspace (status: loading, ready, missing, error), checked every 2 s unless follow: false. A path outside the folder is read-only. save(content, expectedHash?) resolves { ok: true, file } or { ok: false, conflict, error }. |
useFileUrl(path) |
A URL of the file’s raw bytes for <img>, <video>, <audio>, fetch: any size, byte ranges; ?v=<hash> reloads it, ?rev=HEAD gives HEAD’s version. Never print or send it out of the window. |
parseYaml(text) |
Promise<{ ok: true, documents } | { ok: false, message, line, column }>. |
Threads, workspaces, the window
Section titled “Threads, workspaces, the window”| Export | What it gives |
|---|---|
useIndex() |
Workspaces, threads, theme and settings (the index topic), models (how many models pi can use) and widgets (those the user’s init file declares). |
useThreads(), useThreadSummary(threadId) |
Thread summaries by id; one thread’s (title, process state, workspace). |
useThread(threadId) |
{ state, closed }: a thread’s full state (transcript, tools, queue, pending interactions). |
useThreadCost(threadId) |
{ session, subagents } in US dollars, as the header shows. |
useBackground(threadId) |
What omfp:background shows: { rows, sections, running, stop(jobId), clearFinished(), opened(row) }. |
useRunningInBackground(threadId) |
How many of the thread’s background commands run. |
useWorkspaces(), useWorkspace(workspaceId) |
Workspaces by id; { workspace } (name, path, folders), live. |
useViews(workspaceId) |
The workspace’s views manifest, keymap and widget folders (the views/<id> topic). |
useCurrentWorkspaceId() |
The workspace this window works in. |
useActiveView(viewIds), chooseView(host, viewId) |
The view the window shows for the selected thread, and switching it. |
useTopic(topic) |
Follows a topic (index, thread/<id>, views/<id>, job/<id>, terminal/<id>) while mounted. |
useSnapshot(select) |
select(snapshot) over the window’s model, re-rendering when the result changes by identity: return a part of the snapshot, never a new object. |
useConnection() |
The connection status. |
useHost() |
The window’s host (client, window, commands), for chooseView, requestLogin, registerCommand. |
useWindowState(key) |
[value, set] of a window key (below). |
useTranscriptView() |
In the widget of the chat’s transcriptRail slot (ctx.shell.slot("transcriptRail", …), drawn over the transcript’s right edge): outline (the message rows: row, role, text, at), rows, current, matches, subscribe((position, byUser) => …), topRow(), scrollToRow(row, focus); undefined elsewhere. omfp:rail is one. |
Actions
Section titled “Actions”| Export | What it does |
|---|---|
useThreadActions() |
select, rename, archive, stop, restart, sendDraft(), createDraft(created?) (the draft’s thread, its message, if any, the first one), compact(threadId, instructions?), … |
useOpenFile() |
openFile(path, { line?, diff? }): opens a file in a tab of the main slot (else a panel); a bare or partial name finds the file. |
useMissingFile(path, missing, { line?, diff? }) |
While missing, finds the file path names and opens it or lets the user pick. |
useFileTabs(workspaceId) |
{ tabs, widgets, active, select(id), close(path), closeTab(id) }: this window’s tabs of the main slot. |
useNotify() |
notify({ title, body, threadId?, url?, tag?, urgency? }) (omfp://docs/notifications). |
useReportError() |
report(error): an error toast, kept in :messages. Use it in the catch of every user action. |
useReportSuccess() |
report(text): a success toast for the result of a user action. |
useAnnounce() |
announce(message) for screen readers. |
useConversationActions() |
{ copy(threadId), copyMessage(view), export(threadId) }: a conversation as Markdown. |
useUrlActions() |
{ open(url), copy(url) }. |
useSettings(), useSetSettings() |
The daemon’s effective settings, live; set(patch) changes them until restart (omfp://docs/settings). |
callUser(host, method, params?) |
Calls a daemon-wide method of the user’s init.ts (user.call); the method learns this window as its caller. |
onThreadSignal(host, threadId, name, listener) |
Hears a plugin’s ctx.threads.signal(threadId, name, data): listener(data) while this window follows the thread; returns its removal. |
usePathSources() |
{ complete(path) } for the kit’s PathField: directories on the daemon’s machine. |
ThreadLink |
<Markdown text={…} threadLink={ThreadLink} />: renders omfp://thread/<id> links as the chat does. |
Window keys
Section titled “Window keys”Read with useWindowState(KEY); the set writes a request.
| Export | What it holds |
|---|---|
SELECTED_THREAD |
The thread id this window shows. |
DRAFT_THREAD |
{ workspaceId } of the draft thread being written, else undefined. |
FRAME_LAYOUT |
"wide", "narrow" or "mobile": read it to give way on a phone; never set it. |
REVEAL_WIDGET |
{ reference, nonce, instance? } (a new nonce per request): shows that widget; with instance, only the node whose instance prop is it (omfp://docs/views, Reveals). |
OPEN_JOB |
{ workspaceId, job, nonce }: opens a declared job’s runs in omfp:jobs (reveal omfp:jobs too). |
OPEN_BACKGROUND_JOB |
{ threadId, jobId, nonce }: opens a background command’s row in omfp:background once that thread shows (reveal omfp:background too). |
FOCUS_COMPOSER |
The thread whose composer takes the focus once it shows. |
MCP in a widget
Section titled “MCP in a widget”useMcp and useMcpTool reach the workspace’s MCP servers (as omfp:mcp lists them) from the daemon, no thread
needed. On unauthorized, send /mcp login <name> in a thread of the workspace (Reauthorize in omfp:mcp); an
unknown server is not_found.
import { Card, EmptyState, Log } from "omfp/kit";import { mcpText, useMcpTool } from "omfp/sdk";
export default function Issues() { const issues = useMcpTool("linear", "list_issues", { limit: 10 }); if (issues.error !== undefined) return <EmptyState icon="inbox" title="Linear failed">{String(issues.error)}</EmptyState>; return <Card title="Linear issues"><Log lines={mcpText(issues.data).split("\n")} /></Card>;}