/** Protocol version of the bridge. */ export const PROTOCOL: 1 export interface Theme { mode: 'light' | 'dark' /** Design tokens of the app, applied as --wk- CSS variables. */ tokens: Record } export interface PageContext { pluginId: string version: string /** "/", e.g. "pages/links". */ mount: string locale: string /** The user's workspace role: viewer, contributor, admin or owner. For what the page offers; the plugin's backend gets the role WeKnora checked. */ role: string theme: Theme /** What the mount passes: knowledgeBaseId for kbTabs. */ context: Record } export interface Response { status: number body: T } export interface RequestOptions { /** Reject non-2xx answers (default true). */ throwOnError?: boolean } export interface Bridge { context: PageContext request(method: string, path: string, body?: unknown, opts?: RequestOptions): Promise> get(path: string, opts?: RequestOptions): Promise> post(path: string, body?: unknown, opts?: RequestOptions): Promise> put(path: string, body?: unknown, opts?: RequestOptions): Promise> delete(path: string, opts?: RequestOptions): Promise> toast(message: string, theme?: 'info' | 'success' | 'warning' | 'error'): Promise confirm(message: string, title?: string): Promise navigate(path: string): Promise resize(height: number): Promise close(): Promise on(name: 'theme', fn: (theme: Theme) => void): () => void on(name: 'locale', fn: (locale: string) => void): () => void /** The mount's context changed (another knowledge base). */ on(name: 'init', fn: (context: PageContext) => void): () => void } export interface ConnectOptions { autoResize?: boolean applyTheme?: boolean timeout?: number window?: Window } export class BridgeError extends Error { status?: number } export function connect(options?: ConnectOptions): Promise export function applyTheme(theme: Theme, doc?: Document): void