Files
Reims-Go/frontend/src/lib/bridgeContract.ts
T
NwflowerandClaude Opus 5.5 fa3e1e2889 feat: add plugin views and expand the sandboxed page bridge
Plugins can add pages to the sidebar, VM tabs, Settings and dialogs. Their
pages can now use host forms and navigation, VM and settings access,
authorized file I/O, task progress, controlled HTTP requests, events and
private storage.

Plugin pages cannot change allow_ai_access, which stays the user's per-VM
consent. Closing a page cancels its unfinished tasks, and running plugin
tasks no longer block changing the data folder.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-02 23:11:23 -07:00

91 lines
2.5 KiB
TypeScript

// Plugin UI bridge contract, bridgeApi 1.0 (see docs/plugin-architecture.md).
//
// Sandboxed plugin views and panels talk to the host only through these
// postMessage envelopes. Stable methods and events are implemented and covered
// by the compatibility promise; experimental ones are part of the published
// shape but the host answers them with an "experimental" error until they are
// promoted. Permissions and rate limits are enforced in Go
// (internal/plugin/contract.go BridgeMethodCatalog); a Go test keeps the method
// lists here and there identical.
export const BRIDGE_API_VERSION = '1.0.0' as const
export const BRIDGE_METHODS = [
'hello',
'i18n.getBundle',
'ui.notify',
'ui.confirm',
'ui.copy',
'ui.openExternal',
'ui.showForm',
'ui.setTitle',
'ui.setBadge',
'ui.openView',
'ui.close',
'ui.navigate',
'vm.list',
'vm.get',
'command.invoke',
'settings.get',
'settings.set',
'storage.get',
'storage.set',
'storage.list',
'storage.delete',
'file.pick',
'file.save',
'file.read',
'file.write',
'task.start',
'task.update',
'task.finish',
'net.fetch',
'events.subscribe',
'events.unsubscribe',
] as const
export const BRIDGE_METHODS_EXPERIMENTAL = [] as const
export const BRIDGE_EVENTS = [
'theme.changed',
'locale.changed',
'vm.stateChanged',
'view.visibilityChanged',
'task.updated',
] as const
export const BRIDGE_EVENTS_EXPERIMENTAL = [] as const
export type BridgeMethod = (typeof BRIDGE_METHODS)[number] | (typeof BRIDGE_METHODS_EXPERIMENTAL)[number]
export type BridgeEventName = (typeof BRIDGE_EVENTS)[number] | (typeof BRIDGE_EVENTS_EXPERIMENTAL)[number]
/** Plugin → host request. `id` is chosen by the plugin and echoed in the result. */
export interface BridgeRequest {
type: 'reims:rpc'
id: string
method: BridgeMethod
params?: Record<string, unknown>
}
/** Host → plugin response to one request. */
export type BridgeResult =
| { type: 'reims:rpc-result'; id: string; ok: true; result: unknown }
| { type: 'reims:rpc-result'; id: string; ok: false; error: string }
/** Host → plugin event. Theme and locale events are always delivered; the others only after `events.subscribe`. */
export interface BridgeEvent {
type: 'reims:event'
event: BridgeEventName
data: unknown
}
/** Result of `hello`, the first call a view or panel makes. */
export interface BridgeHello {
bridgeApi: string
uiApi: string
/** Stable host features, e.g. `bridge.vm.list`; feature-detect instead of comparing versions. */
features: string[]
locale: string
dir: 'ltr' | 'rtl'
}