UI Extensions
The host owns the app shell, navigation, and chat skeleton. Plugins extend it in four ways: attach Compose content to slots, render tool results with tool result renderers, declare plugin pages and composer actions, and write custom message cards. All plugin UI is Compose built with the shared design module; there is no declarative UI language, no resources, and no custom Activity.
UI declaration and compatibility
UI extensions require the manifest ui block:
"ui": { "apiLevel": 3 }| Check | Rule | On failure |
|---|---|---|
ui.apiLevel | Must be within 1..HOST_UI_API_LEVEL (3); the current SDK is level 3 | Install warning; the plugin's Compose UI is disabled, the plugin still loads |
ui.kotlin | When present, must match the host Kotlin major/minor version (e.g. "2.4") | The plugin's UI is disabled |
ui.compose | When present, must equal the host Compose runtime version exactly, not the BOM version | The plugin's UI is disabled |
When UI is disabled, slot bindings, pages, composer actions, and tool result renderers do not render; tools, skills, prompts, and hooks keep working. Leave ui.kotlin and ui.compose out unless you have a reason to pin them.
Slots
A slot is a named content area inside an existing host card. ui(host) returns a PluginUiContributions whose bindings attach Compose content to slot ids.
public object SlotIds {
public const val TOOL_CARD_PREFIX: String = "tool.card.content:"
public const val CHAT_MESSAGE_PREFIX: String = "chat.message:"
public fun toolCard(toolName: String): String
public fun chatMessage(customType: String): String
public fun matches(slotId: String): Boolean
}| Slot id | Where it renders | State |
|---|---|---|
tool.card.content:<toolName> | Content area of the tool call card for that tool | ToolCardSlotState |
chat.message:<customType> | Content area of a custom message card of that type | CustomMessageSlotState |
public interface SlotBinding {
public val slotId: String
public val priority: Int
public val content: SlotContent
}
public fun slotBinding(slotId: String, priority: Int = 0, content: SlotContent): SlotBinding
public interface SlotContent {
@Composable
public fun render(state: SlotState)
}
public fun composeSlot(render: @Composable (SlotState) -> Unit): SlotContentOnly one binding renders per slot: the highest priority wins, and ties are broken by plugin registration order. When no binding is renderable the host falls back to its default view.
Slot state types:
public interface SlotState
public data object NoSlotState : SlotState
public interface ToolCardSlotState : SlotState {
public val callId: String
public val toolName: String
public val args: JsonObject
public val result: PluginToolResult?
}
public interface CustomMessageSlotState : SlotState {
public val messageId: String
public val customType: String
public val payload: JsonObject
}Example: a card for the plugin's own tool.
override fun ui(host: PluginHost): PluginUiContributions = object : PluginUiContributions {
override val bindings = listOf(
slotBinding(
slotId = SlotIds.toolCard("sync_files"),
content = composeSlot { state ->
val card = state as? ToolCardSlotState ?: return@composeSlot
SyncCard(
args = card.args,
result = card.result,
onOpen = { host.ui().openPage("sync") },
)
},
),
)
override val pages = listOf(syncPage(host))
}Tool result renderers
Slots match one exact tool name. Tool result renderers render results from MCP tools, built-in tools, or families of plugin tools, matched by source, server, exact name, or name prefix.
public value class ToolResultSource private constructor(public val wire: String) {
public companion object {
public val PLUGIN: ToolResultSource
public val MCP: ToolResultSource
public val BUILTIN: ToolResultSource
}
}
public interface ToolResultMatch {
public val source: ToolResultSource?
public val server: String?
public val tool: String?
public val toolPrefix: String?
public fun matches(source: ToolResultSource, server: String?, tool: String): Boolean
public fun specificity(): Int
}
public fun toolResultMatch(
source: ToolResultSource? = null,
server: String? = null,
tool: String? = null,
toolPrefix: String? = null,
): ToolResultMatch
public interface ToolResultRendererContributor {
public val toolResultRenderers: List<ToolResultRenderer>
}
public interface ToolResultRenderer {
public val id: String
public val priority: Int
public val match: ToolResultMatch
@Composable public fun content(state: ToolResultState)
}
public fun toolResultRenderer(
id: String,
match: ToolResultMatch,
priority: Int = 0,
content: @Composable (ToolResultState) -> Unit,
): ToolResultRenderer
public interface ToolResultState {
public val callId: String
public val toolName: String
public val source: ToolResultSource
public val server: String?
public val arguments: JsonObject
public val result: PluginToolResult?
public val structuredContent: JsonElement?
}Return the renderer list by making the ui() result implement ToolResultRendererContributor:
override fun ui(host: PluginHost): PluginUiContributions =
object : PluginUiContributions, ToolResultRendererContributor {
override val bindings = emptyList<SlotBinding>()
override val toolResultRenderers = listOf(
toolResultRenderer(
id = "route-card",
match = toolResultMatch(
source = ToolResultSource.MCP,
server = "maps",
toolPrefix = "route_",
),
) { state ->
val structured = state.structuredContent as? JsonObject
RouteCard(
summary = structured?.get("summary")?.jsonPrimitive?.contentOrNull
?: state.result?.text.orEmpty(),
)
},
)
}Match rules:
source:PLUGIN,MCP, orBUILTIN; omitted matches any.server: the MCP server name as configured by the user.tool: exact tool name;toolPrefix: name prefix. They can be combined.- One renderer per result: higher
priorityfirst, then the more specific match, then registration order. - When no renderer matches, the plugin is disabled, or its UI is incompatible, the host uses the default tool card. Do not throw or
requireinside a renderer.
ToolResultState fields: callId and toolName identify the call; MCP tools invoked through tool_execute are restored to the real MCP tool identity. structuredContent is the structured payload persisted by the host (up to 256 KiB) and stays available after reopening the session; it never enters the model context. Use it for display data instead of stuffing JSON into details.
Plugin pages
A plugin page is a full Compose screen owned by the plugin. Pages are declared as PluginUiContributions.pages:
public interface PluginPage {
public val id: String
public val title: LocalizedText
public val icon: IconRef?
@Composable public fun content()
}
public fun pluginPage(
id: String,
title: LocalizedText,
icon: IconRef? = null,
content: @Composable () -> Unit,
): PluginPage
public interface PluginUiContributions {
public val bindings: List<SlotBinding>
public val pages: List<PluginPage> get() = emptyList()
public val composerActions: List<ComposerAction> get() = emptyList()
public companion object {
public val None: PluginUiContributions
}
}
public interface ComposerAction {
public val id: String
public val label: LocalizedText
public val icon: IconRef?
}
public fun composerAction(id: String, label: LocalizedText, icon: IconRef? = null): ComposerActionPage ids are ^[a-z][a-z0-9_.-]*$. A plugin can only open its own pages.
Opening and closing pages:
host.ui().openPage("home")
host.ui().openPageWithArguments(
pageId = "detail",
arguments = buildJsonObject { put("id", "42") },
newTask = false,
)
host.ui().closePage(buildJsonObject { put("saved", true) })| Call | Behavior |
|---|---|
openPage(pageId) | Pushes the page into the current navigation stack |
openPageWithArguments(..., newTask = false) | Pushes with JSON arguments |
openPageWithArguments(..., newTask = true) | Opens in a dedicated host-proxied window, suited to scanning, camera, or long flows |
openPageSheet(pageId, arguments) | Presents the page as a bottom sheet over the chat; the same content, no navigation push |
closePage(result?) | Closes the page or sheet and returns an optional JSON result |
Page context:
public interface PluginPageContext {
public val pageId: String
public val arguments: JsonObject
public val presentation: PluginPagePresentation
}
public value class PluginPagePresentation private constructor(public val wire: String) {
public companion object {
public val PAGE: PluginPagePresentation
public val SHEET: PluginPagePresentation
}
}
public val LocalPluginPageContext: ProvidableCompositionLocal<PluginPageContext?>Read host.ui().pageContext() or LocalPluginPageContext.current inside page content; both are null outside a plugin page. Check presentation to distinguish a sheet from a page. Only one plugin page sheet can be open at a time; DdSheet inside a page sheet is allowed and closes first.
A page example:
private fun syncPage(host: PluginHost) = pluginPage(
id = "sync",
title = localizedText("Sync", "同步"),
icon = assetIcon("asset:icon.png"),
) {
val colors = soraColors()
var status by remember { mutableStateOf<SyncStatus?>(null) }
var busy by remember { mutableStateOf(false) }
LaunchedEffect(Unit) {
status = loadStatus()
}
Column(
modifier = Modifier
.fillMaxSize()
.verticalScroll(rememberScrollState())
.padding(
start = DdSpacing.Xl,
end = DdSpacing.Xl,
top = DdSpacing.Md,
bottom = DdSpacing.Xxl,
),
verticalArrangement = Arrangement.spacedBy(DdSpacing.Lg),
) {
DdGroupCard {
Column(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = DdSpacing.Card, vertical = DdSpacing.Sm),
) {
DdStatusRow(
label = host.text(localizedText("Service", "服务")),
value = if (status?.connected == true) "Connected" else "Not connected",
tone = if (status?.connected == true) DdStatusTone.SUCCESS else DdStatusTone.NEUTRAL,
busy = busy,
)
}
}
if (status?.error != null) {
DdNoticeBar(
text = status.error,
tone = DdNoticeTone.DANGER,
actionLabel = "Retry",
onAction = { /* rerun the failed action */ },
)
}
DdPrimaryButton(
text = "Sync now",
onClick = { /* start sync */ },
enabled = !busy,
)
}
}Page behavior:
- Pages can call every declared host service. Prefer
host.ui()confirm/prompt/pickers over Material dialogs. host.ui().openPageonly accepts the plugin's own page ids; usecomponents().startActivity(pluginActivityOptions(...))when you need a dedicated window from a tool or a non-page context.- Page state lives in Compose; state that must survive the process belongs in
host.settings()or files underhost.dataDir. Do not write secrets to plain files; usehost.secrets(). - After a page action changes tools, skills, or pages, call
host.requestContributionsRefresh(); busy sessions update after the current round. - After the page leaves, the host cancels page coroutines (
LaunchedEffect). Long-running work belongs onhost.scope. - Do not add a title bar: the host renders a 64 dp top bar above the page.
Composer actions
composerAction(id, label, icon?) adds a chip to the chat composer. The chip opens the plugin's page matching the action id when one exists, otherwise its first page. Use it for one or two high-value entry points; do not mirror every tool in the UI.
Custom message cards
Write a card into a session with a customType; the card renders through chat.message:<customType>:
host.chat().sendMessage(
sessionId = call.sessionId,
text = "Sync finished",
options = chatMessageOptions(
triggerTurn = false,
display = chatDisplay(
customType = "sync.card",
payload = buildJsonObject {
put("title", "Sync finished")
put("files", 12)
},
text = "Sync finished, 12 files",
),
),
)Or write only the card with postCustomMessage(...). Cards are persisted in the session and restored after reopening; a card delivered while a tool runs renders inline in that turn. See Runtime API → Custom messages and cards for delivery options and ChatSendResult.
Interaction and pickers
host.ui() provides host-styled dialogs and system pickers. They need a foreground page or chat context; calling them from the background can return null or false.
| Method | Returns | Description |
|---|---|---|
confirm(uiConfirmRequest(title, message?, confirmLabel?, cancelLabel?, destructive)) | Boolean | Confirmation dialog; destructive uses the danger color |
prompt(uiPromptRequest(title, message?, initial, placeholder?, multiline)) | String? | Text input; cancel returns null |
choose(uiChooseRequest(title, options, message?)) | String? | Single-choice list; returns the selected UiChoice.id |
pickDate(uiDatePickRequest(initialMs?, minMs?, maxMs?)) | Long? | Date picker |
pickTime(uiTimePickRequest(initialHour?, initialMinute?, is24Hour)) | Int? | Time picker, returns hour * 60 + minute |
pickFiles(uiFilePickRequest(mimeTypes, multiple, maxCount)) | List<PluginPickedFile> | System file picker; cancel returns an empty list |
pickImage(uiImagePickRequest(source = UiImageSource.GALLERY/CAMERA, frontCamera)) | PluginPickedFile? | Gallery or camera |
scanQr() | String? | Scan a code and return its text |
pickDirectory() | String? | Pick a directory |
snackbar(message, actionLabel?, action?) | — | In-page light feedback with one optional action |
shareFiles(paths, mimeType?) | — | Share files readable by the plugin |
openUrl(url) / share(shareRequest(...)) / toast(message) | — | Open a link, share text, light Toast |
isDark | Boolean | Whether the current theme is dark |
PluginPickedFile carries path, uri, name, sizeBytes, and mimeType. The host requests camera and microphone permissions itself: declare camera / microphone in the manifest permissions with the ui capability.
val picked = host.ui().pickImage(uiImagePickRequest(source = UiImageSource.CAMERA))
val note = host.ui().prompt(uiPromptRequest(title = "Note", placeholder = "Optional")) ?: return
host.ui().snackbar("Imported", actionLabel = "View") { host.ui().openPage("sync") }Design system
Plugin UI uses io.github.sadami3066.sora.design (artifact design 1.1.0), the same components as the app. plugin-api already carries it through api(), so the template declares no explicit dependency; official plugins pin it explicitly with compileOnly("io.github.sadami3066.sora:design:1.1.0").
Components
| Component | Purpose |
|---|---|
DdGroupCard | Rounded group card (20 dp radius, hairline between rows) |
DdListRow | Row inside a card: title, subtitle, value, icon, chevron, trailing content |
DdSectionLabel | Section label |
DdPrimaryButton | Primary action (accent fill, one per screen) |
DdTextAction | Text button for secondary actions |
DdTextField / DdTextArea | Single-line and multi-line inputs |
DdSwitch / DdChip / DdSegmented | Toggle, filter chip, segmented control |
DdSheet + DdSheetHeader | Bottom sheet and header |
DdDialog | Centered dialog |
DdMenu / DdMenuItem | Dropdown menu |
DdEmptyState / DdLoadingBlock / DdSpinner | Empty, loading, and progress states |
DdProgressBar / DdSlider | Determinate or indeterminate progress and continuous values |
DdHairline / DdRowDivider | Dividers |
DdStatusRow + DdStatusTone | Status summary row: NEUTRAL, ACCENT, SUCCESS, WARNING, DANGER |
DdNoticeBar + DdNoticeTone | Inline notice: INFO, SUCCESS, WARNING, DANGER, optional action |
DdMarkdown | Markdown rendering with links, images, code copy |
DdHtmlText / DdHtmlBlocks / DdWebView | Restricted HTML and embedded web content |
DdImage / DdRemoteImage / DdImageViewer | Local, remote, and full-screen images |
DdPullToRefresh | Pull-to-refresh container |
DdSnackbarHost | In-page light messages |
DdFileRow / DdInfoTooltip / DdExpandToggle | File row, inline info, expand/collapse |
DdSwipeRow + DdSwipeAction | Swipe actions on rows |
DdDatePicker / DdTimePicker | Date and time picker sheets |
DdSearchField / DdDropdown / DdAvatar / DdIconBox / DdTypingDots | Search, dropdown, avatar, icon container, typing indicator |
DdPageScaffold | Page scaffold used by host pages |
DdTheme / SoraTheme / soraColors() | Palettes and color access |
DdType / DdSpacing / DdShapes / DdMotion / DdIcons | Type scale, spacing, shapes, motion, icons |
Colors, type, spacing
val colors = soraColors() // SoraColors
colors.ink; colors.inkSecondary; colors.inkTertiary
colors.paper; colors.surface; colors.raised
colors.accent; colors.accentSoft; colors.onAccent
colors.danger; colors.success; colors.warning
colors.hairline; colors.wash; colors.composer; colors.scrimUse DdType styles instead of raw sizes: wordmark, display, pageTitle, heading, body, bodySmall, label, button. Use DdSpacing instead of hardcoded dp: ScreenHorizontal (24), Section (20), Card and RowHorizontal (18), Xl (20), Xxl (24), Lg (16), Md (12), Sm (8), Xs (4), Xxs (2).
The design system is a shared language, not a suggestion: do not hardcode colors or font sizes, and do not use Material 3 Card/Button/Switch/OutlinedTextField directly — they look inconsistent with the rest of the app.
Layout guidance
Plugin pages are their own scroll containers. The host already provides a 64 dp top bar, so the page starts with content, not a title.
- Page padding:
DdSpacing.Xl(20 dp) horizontal,DdSpacing.Md(12 dp) top,DdSpacing.Xxl(24 dp) bottom;Arrangement.spacedBy(DdSpacing.Lg)between groups. DdGroupCarddraws only the card surface: custom content inside it needsModifier.fillMaxWidth().padding(horizontal = DdSpacing.Card)(18 dp) so text does not touch the edges.DdListRowalready carries that padding throughLocalDdRowHorizontalPadding, andDdNoticeBarhas its own — do not wrap them again.- One visual focus per screen: a status card first, then actions, then details. At most one
DdPrimaryButton; secondary actions use text buttons or menus. - States must be stable while refreshing: keep the previous values visible and mark only the affected row
busy; do not clear the page into a loading state. - Show errors inline where they happen (
DdNoticeBarwith danger tone and a retry action), not only as a Toast. Empty and loading states useDdEmptyStateandDdLoadingBlock.
Column(
modifier = Modifier
.fillMaxSize()
.verticalScroll(rememberScrollState())
.padding(
start = DdSpacing.Xl,
end = DdSpacing.Xl,
top = DdSpacing.Md,
bottom = DdSpacing.Xxl,
),
verticalArrangement = Arrangement.spacedBy(DdSpacing.Lg),
) {
StatusCard(host, status)
if (status.error != null) {
DdNoticeBar(status.error, tone = DdNoticeTone.DANGER, actionLabel = "Retry") { retry() }
}
DdProgressBar(progress = if (busy) percent else null)
}Card best practices
- A tool card answers three questions: what ran, what happened, and what can the user do next. Put the outcome in the first line and keep raw output behind an expand action.
- Build cards from
DdGroupCard,DdListRow, andDdStatusRow; show errors withDdNoticeBarand files withDdFileRow. - Limited height: cards live inside the conversation. Show the summary plus a few rows and use
DdExpandTogglefor the rest; do not nest scrollable containers. - Media: load remote images with
host.images().load(url, maxEdgePx)and render withDdRemoteImage; full screen usesDdImageViewer. Images stay in host memory and the private cache — never write card images to shared storage. - Interaction: tapping the card body may open a page sheet; put explicit actions in text buttons. Never require a tap to complete a tool result.
- Do not build a capability only inside UI: the agent must still be able to do the same thing through a tool. UI is an optional path for people, not a gate for automation.
- Motion: use
DdMotionvalues and respectLocalDdMotionEnabled; animate only opacity and scale, and never cause layout jumps. - Copy: write for the user, not the developer. Pair Chinese and English, avoid CLI names, file paths, and raw version numbers, and put genuinely necessary details behind
DdInfoTooltip. Icons come fromDdIcons, never emoji.
