Implementation:AI QL Tuui renderer ipc facade
| Knowledge Sources | |
|---|---|
| Domains | IPC, Renderer, MCP, MCPB |
| Last Updated | 2026-10-24 00:00 GMT |
Overview
Concrete tool for wrapping preload IPC channels into typed renderer-side facades for sampling, elicitation, command events, file transfer, and MCP server initialization, provided by the tuui Electron application.
Description
This module provides named facade objects that wrap window.mainApi calls:
- SamplingTransfer —
request(callback)listens for sampling requests;response(channel, response)sends back the result. - ElicitationTransfer —
request(callback)listens for elicitation requests;response(channel, response)sends back the result. - CommandEvent —
request(callback)listens for command selections;response(response)sends the user's selection to main. - FileTransfer —
request(file)sends a .mcpb file to main;response(count)listens for transfer results. - McpEvent —
init(configs)merges user config for MCPB manifests and invokesmsgMcpServersInit;stop()stops all servers;watch(callback)listens for init progress. - Utils — Static helpers for app info, API tokens, file dialogs, external links, etc.
Usage
Import these facades in renderer code when: handling MCP sampling/elicitation requests, sending command picker results, transferring bundle files, initializing MCP servers with merged user config, or invoking utility IPC calls.
Code Reference
Source Location
- Repository: tuui
- File: src/renderer/utils/index.ts
Signature
export const SamplingTransfer: {
request: (callback: IpcSamplingRequestCallback) => Promise<void>
response: (channel: string, response: SamplingResponse) => Promise<void>
}
export const ElicitationTransfer: {
request: (callback: IpcElicitRequestCallback) => Promise<void>
response: (channel: string, response: ElicitResponse) => Promise<void>
}
export const CommandEvent: {
request: (callback: IpcCommandRequestCallback) => Promise<void>
response: (response: CommandResponse) => Promise<void>
}
export const FileTransfer: {
request: (file: IpcFileTransferRequest) => Promise<void>
response: (count: number) => Promise<IpcFileTransferResponse[]>
}
export const McpEvent: {
init: (configs: McpServerApi) => Promise<McpInitResponse | undefined>
stop: () => Promise<void>
watch: (callback: IpcMcpInitRequestCallback) => Promise<void>
}
export default class Utils {
static getCurrentLocale(): string
static getAppInfo(): Promise<any>
static getApiToken(cli: string): Promise<string>
static getDxtUrl(): Promise<any>
static openExternal(url: string): Promise<void>
static openFile(type: string): Promise<any>
// ... etc.
}
Import
import {
SamplingTransfer, ElicitationTransfer, CommandEvent,
FileTransfer, McpEvent, Utils
} from '@/renderer/utils'
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| configs | McpServerApi | Yes (McpEvent.init) | Full MCPAPI object with metadata for each server |
| callback | IpcSamplingRequestCallback | Yes (SamplingTransfer.request) | (_event, request) handler |
| channel | string | Yes (response) | UUID-based response channel from the request |
| response | ElicitResponse | Yes (response) | Result to send back to main |
| file | IpcFileTransferRequest | Yes (FileTransfer.request) | { name, data: ArrayBuffer } |
Outputs
| Name | Type | Description |
|---|---|---|
| McpEvent.init | undefined> | { status: 'success' } or { status: 'error', error } |
| side effect | window.mainApi.send/on/invoke | IPC calls to main process |
Usage Examples
Handle Sampling Request
import { SamplingTransfer } from '@/renderer/utils'
SamplingTransfer.request((_event, { request, responseChannel }) => {
// Build a chat completion from the sampling request
const session = createSessionFromSampling(request)
createCompletion(session, request).then(() => {
const response = extractLastAssistantMessage(session)
SamplingTransfer.response(responseChannel, response)
})
})
Initialize MCP Servers with User Config
import { McpEvent } from '@/renderer/utils'
const servers = window.mcpServers.get()
const result = await McpEvent.init(servers)
// For each metadata__mcpb_manifest entry, user_config values from
// dxtStore are merged with manifest defaults before sending to main
Send Command Picker Result
import { CommandEvent } from '@/renderer/utils'
CommandEvent.response({
prompt: 'Translate to French',
id: 'cached-text-uuid'
})
Related Pages
Implements Principle
- Principle:AI_QL_Tuui_MCP_Sampling
- Principle:AI_QL_Tuui_MCP_Elicitation
- Principle:AI_QL_Tuui_MCPB_Bundle_Packaging
- Principle:AI_QL_Tuui_Global_Shortcut_Command_Picker